The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252371 lines
6.4MB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifdef __JUCE_JUCEHEADER__
  19. #error
  20. #endif
  21. /*** Start of inlined file: juce_TargetPlatform.h ***/
  22. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  23. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  24. #if (defined (_WIN32) || defined (_WIN64))
  25. #define JUCE_WIN32 1
  26. #define JUCE_WINDOWS 1
  27. #elif defined (LINUX) || defined (__linux__)
  28. #define JUCE_LINUX 1
  29. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  30. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  31. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  32. #define JUCE_IPHONE 1
  33. #else
  34. #define JUCE_MAC 1
  35. #endif
  36. #else
  37. #error "Unknown platform!"
  38. #endif
  39. #if JUCE_WINDOWS
  40. #ifdef _MSC_VER
  41. #ifdef _WIN64
  42. #define JUCE_64BIT 1
  43. #else
  44. #define JUCE_32BIT 1
  45. #endif
  46. #endif
  47. #ifdef _DEBUG
  48. #define JUCE_DEBUG 1
  49. #endif
  50. #ifdef __MINGW32__
  51. #define JUCE_MINGW 1
  52. #endif
  53. #define JUCE_LITTLE_ENDIAN 1
  54. #define JUCE_INTEL 1
  55. #endif
  56. #if JUCE_MAC
  57. #ifndef NDEBUG
  58. #define JUCE_DEBUG 1
  59. #endif
  60. #ifdef __LITTLE_ENDIAN__
  61. #define JUCE_LITTLE_ENDIAN 1
  62. #else
  63. #define JUCE_BIG_ENDIAN 1
  64. #endif
  65. #if defined (__ppc__) || defined (__ppc64__)
  66. #define JUCE_PPC 1
  67. #undef MAC_OS_X_VERSION_MAX_ALLOWED
  68. #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_4
  69. #else
  70. #define JUCE_INTEL 1
  71. #endif
  72. #ifdef __LP64__
  73. #define JUCE_64BIT 1
  74. #else
  75. #define JUCE_32BIT 1
  76. #endif
  77. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  78. #error "Building for OSX 10.3 is no longer supported!"
  79. #endif
  80. #ifndef MAC_OS_X_VERSION_10_5
  81. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  82. #endif
  83. #endif
  84. #if JUCE_IPHONE
  85. #ifndef NDEBUG
  86. #define JUCE_DEBUG 1
  87. #endif
  88. #ifdef __LITTLE_ENDIAN__
  89. #define JUCE_LITTLE_ENDIAN 1
  90. #else
  91. #define JUCE_BIG_ENDIAN 1
  92. #endif
  93. #endif
  94. #if JUCE_LINUX
  95. #ifdef _DEBUG
  96. #define JUCE_DEBUG 1
  97. #endif
  98. // Allow override for big-endian Linux platforms
  99. #ifndef JUCE_BIG_ENDIAN
  100. #define JUCE_LITTLE_ENDIAN 1
  101. #endif
  102. #if defined (__LP64__) || defined (_LP64)
  103. #define JUCE_64BIT 1
  104. #else
  105. #define JUCE_32BIT 1
  106. #endif
  107. #define JUCE_INTEL 1
  108. #endif
  109. // Compiler type macros.
  110. #ifdef __GNUC__
  111. #define JUCE_GCC 1
  112. #elif defined (_MSC_VER)
  113. #define JUCE_MSVC 1
  114. #if _MSC_VER >= 1400
  115. #define JUCE_USE_INTRINSICS 1
  116. #endif
  117. #else
  118. #error unknown compiler
  119. #endif
  120. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  121. /*** End of inlined file: juce_TargetPlatform.h ***/
  122. // FORCE_AMALGAMATOR_INCLUDE
  123. /*** Start of inlined file: juce_Config.h ***/
  124. #ifndef __JUCE_CONFIG_JUCEHEADER__
  125. #define __JUCE_CONFIG_JUCEHEADER__
  126. #ifndef JUCE_NAMESPACE
  127. #define JUCE_NAMESPACE juce
  128. #endif
  129. #ifndef JUCE_FORCE_DEBUG
  130. //#define JUCE_FORCE_DEBUG 1
  131. #endif
  132. #ifndef JUCE_LOG_ASSERTIONS
  133. // #define JUCE_LOG_ASSERTIONS 1
  134. #endif
  135. #ifndef JUCE_ASIO
  136. #define JUCE_ASIO 0
  137. #endif
  138. #ifndef JUCE_WASAPI
  139. // #define JUCE_WASAPI 1
  140. #endif
  141. #ifndef JUCE_DIRECTSOUND
  142. #define JUCE_DIRECTSOUND 1
  143. #endif
  144. #ifndef JUCE_ALSA
  145. #define JUCE_ALSA 1
  146. #endif
  147. #ifndef JUCE_JACK
  148. #define JUCE_JACK 1
  149. #endif
  150. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  151. #define JUCE_QUICKTIME 0
  152. #endif
  153. #if (JUCE_IPHONE || JUCE_LINUX) && JUCE_QUICKTIME
  154. #undef JUCE_QUICKTIME
  155. #endif
  156. #ifndef JUCE_OPENGL
  157. #define JUCE_OPENGL 1
  158. #endif
  159. #ifndef JUCE_USE_FLAC
  160. #define JUCE_USE_FLAC 1
  161. #endif
  162. #ifndef JUCE_USE_OGGVORBIS
  163. #define JUCE_USE_OGGVORBIS 1
  164. #endif
  165. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  166. #define JUCE_USE_CDBURNER 0
  167. #endif
  168. #ifndef JUCE_USE_CDREADER
  169. #define JUCE_USE_CDREADER 1
  170. #endif
  171. #if (JUCE_QUICKTIME || JUCE_WINDOWS) && ! defined (JUCE_USE_CAMERA)
  172. // #define JUCE_USE_CAMERA 1
  173. #endif
  174. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  175. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  176. #endif
  177. #ifndef JUCE_USE_XINERAMA
  178. #define JUCE_USE_XINERAMA 1
  179. #endif
  180. #ifndef JUCE_USE_XSHM
  181. #define JUCE_USE_XSHM 1
  182. #endif
  183. #ifndef JUCE_USE_XRENDER
  184. //#define JUCE_USE_XRENDER 1
  185. #endif
  186. #ifndef JUCE_USE_XCURSOR
  187. #define JUCE_USE_XCURSOR 1
  188. #endif
  189. #ifndef JUCE_PLUGINHOST_VST
  190. // #define JUCE_PLUGINHOST_VST 1
  191. #endif
  192. #ifndef JUCE_PLUGINHOST_AU
  193. // #define JUCE_PLUGINHOST_AU 1
  194. #endif
  195. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  196. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  197. #endif
  198. #ifndef JUCE_WEB_BROWSER
  199. #define JUCE_WEB_BROWSER 0
  200. #endif
  201. #ifndef JUCE_SUPPORT_CARBON
  202. #define JUCE_SUPPORT_CARBON 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_ZLIB_CODE
  205. #define JUCE_INCLUDE_ZLIB_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_FLAC_CODE
  208. #define JUCE_INCLUDE_FLAC_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  211. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  212. #endif
  213. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  214. #define JUCE_INCLUDE_PNGLIB_CODE 1
  215. #endif
  216. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  217. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  218. #endif
  219. #ifndef JUCE_CHECK_MEMORY_LEAKS
  220. #define JUCE_CHECK_MEMORY_LEAKS 1
  221. #endif
  222. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  223. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  224. #endif
  225. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  226. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  227. #undef JUCE_QUICKTIME
  228. #define JUCE_QUICKTIME 0
  229. #undef JUCE_OPENGL
  230. #define JUCE_OPENGL 0
  231. #undef JUCE_USE_CDBURNER
  232. #define JUCE_USE_CDBURNER 0
  233. #undef JUCE_USE_CDREADER
  234. #define JUCE_USE_CDREADER 0
  235. #undef JUCE_WEB_BROWSER
  236. #define JUCE_WEB_BROWSER 0
  237. #undef JUCE_PLUGINHOST_AU
  238. #define JUCE_PLUGINHOST_AU 0
  239. #undef JUCE_PLUGINHOST_VST
  240. #define JUCE_PLUGINHOST_VST 0
  241. #endif
  242. #endif
  243. /*** End of inlined file: juce_Config.h ***/
  244. // FORCE_AMALGAMATOR_INCLUDE
  245. #ifndef JUCE_BUILD_CORE
  246. #define JUCE_BUILD_CORE 1
  247. #endif
  248. #ifndef JUCE_BUILD_MISC
  249. #define JUCE_BUILD_MISC 1
  250. #endif
  251. #ifndef JUCE_BUILD_GUI
  252. #define JUCE_BUILD_GUI 1
  253. #endif
  254. #ifndef JUCE_BUILD_NATIVE
  255. #define JUCE_BUILD_NATIVE 1
  256. #endif
  257. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  258. #undef JUCE_BUILD_MISC
  259. #undef JUCE_BUILD_GUI
  260. #endif
  261. //==============================================================================
  262. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  263. #if JUCE_WINDOWS
  264. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  265. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  266. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  267. #ifndef STRICT
  268. #define STRICT 1
  269. #endif
  270. #undef WIN32_LEAN_AND_MEAN
  271. #define WIN32_LEAN_AND_MEAN 1
  272. #ifdef _MSC_VER
  273. #pragma warning (push)
  274. #pragma warning (disable : 4100 4201 4514 4312 4995)
  275. #endif
  276. #define _WIN32_WINNT 0x0500
  277. #define _UNICODE 1
  278. #define UNICODE 1
  279. #ifndef _WIN32_IE
  280. #define _WIN32_IE 0x0400
  281. #endif
  282. #include <windows.h>
  283. #include <windowsx.h>
  284. #include <commdlg.h>
  285. #include <shellapi.h>
  286. #include <mmsystem.h>
  287. #include <vfw.h>
  288. #include <tchar.h>
  289. #include <stddef.h>
  290. #include <ctime>
  291. #include <wininet.h>
  292. #include <nb30.h>
  293. #include <iphlpapi.h>
  294. #include <mapi.h>
  295. #include <float.h>
  296. #include <process.h>
  297. #include <Exdisp.h>
  298. #include <exdispid.h>
  299. #include <shlobj.h>
  300. #if ! JUCE_MINGW
  301. #include <crtdbg.h>
  302. #include <comutil.h>
  303. #endif
  304. #if JUCE_OPENGL
  305. #include <gl/gl.h>
  306. #endif
  307. #undef PACKED
  308. #if JUCE_ASIO
  309. #include "iasiodrv.h"
  310. #endif
  311. #if JUCE_USE_CDBURNER
  312. #include <imapi.h>
  313. #include <imapierror.h>
  314. #endif
  315. #if JUCE_USE_CAMERA
  316. #include <dshow.h>
  317. #include <qedit.h>
  318. #include <dshowasf.h>
  319. #endif
  320. #if JUCE_WASAPI
  321. #include <MMReg.h>
  322. #include <mmdeviceapi.h>
  323. #include <Audioclient.h>
  324. #include <Avrt.h>
  325. #include <functiondiscoverykeys.h>
  326. #endif
  327. #if JUCE_QUICKTIME
  328. #include <Movies.h>
  329. #include <QTML.h>
  330. #include <QuickTimeComponents.h>
  331. #include <MediaHandlers.h>
  332. #include <ImageCodec.h>
  333. #import <QTOLibrary.dll>
  334. #import <QTOControl.dll>
  335. #endif
  336. #ifdef _MSC_VER
  337. #pragma warning (pop)
  338. #endif
  339. template <class T>
  340. class ComSmartPtr
  341. {
  342. public:
  343. ComSmartPtr() throw() : p (0) {}
  344. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  345. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  346. ~ComSmartPtr() { if (p != 0) p->Release(); }
  347. operator T*() const throw() { return p; }
  348. T& operator*() const throw() { return *p; }
  349. T** operator&() throw() { return &p; }
  350. T* operator->() const throw() { return p; }
  351. T* operator= (T* const newP)
  352. {
  353. if (newP != 0)
  354. newP->AddRef();
  355. if (p != 0)
  356. p->Release();
  357. p = newP;
  358. return newP;
  359. }
  360. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  361. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  362. {
  363. #ifndef __MINGW32__
  364. operator= (0);
  365. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  366. #else
  367. return S_FALSE;
  368. #endif
  369. }
  370. T* p;
  371. };
  372. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  373. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  374. #elif JUCE_LINUX
  375. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  376. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  377. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  378. #include <sched.h>
  379. #include <pthread.h>
  380. #include <sys/time.h>
  381. #include <errno.h>
  382. #include <sys/stat.h>
  383. #include <sys/dir.h>
  384. #include <sys/ptrace.h>
  385. #include <sys/vfs.h>
  386. #include <sys/wait.h>
  387. #include <fnmatch.h>
  388. #include <utime.h>
  389. #include <pwd.h>
  390. #include <fcntl.h>
  391. #include <dlfcn.h>
  392. #include <netdb.h>
  393. #include <arpa/inet.h>
  394. #include <netinet/in.h>
  395. #include <sys/types.h>
  396. #include <sys/ioctl.h>
  397. #include <sys/socket.h>
  398. #include <linux/if.h>
  399. #include <sys/sysinfo.h>
  400. #include <sys/file.h>
  401. #include <signal.h>
  402. #include <ft2build.h>
  403. #include FT_FREETYPE_H
  404. #include <X11/Xlib.h>
  405. #include <X11/Xatom.h>
  406. #include <X11/Xresource.h>
  407. #include <X11/Xutil.h>
  408. #include <X11/Xmd.h>
  409. #include <X11/keysym.h>
  410. #include <X11/cursorfont.h>
  411. #if JUCE_USE_XINERAMA
  412. #include <X11/extensions/Xinerama.h>
  413. #endif
  414. #if JUCE_USE_XSHM
  415. #include <X11/extensions/XShm.h>
  416. #include <sys/shm.h>
  417. #include <sys/ipc.h>
  418. #endif
  419. #if JUCE_USE_XRENDER
  420. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  421. #include <X11/extensions/Xrender.h>
  422. #include <X11/extensions/Xcomposite.h>
  423. #endif
  424. #if JUCE_USE_XCURSOR
  425. // If you're missing this header, try installing the libxcursor-dev package
  426. #include <X11/Xcursor/Xcursor.h>
  427. #endif
  428. #if JUCE_OPENGL
  429. #include <GL/glx.h>
  430. #endif
  431. #undef KeyPress
  432. #if JUCE_ALSA
  433. #include <alsa/asoundlib.h>
  434. #endif
  435. #if JUCE_JACK
  436. #include <jack/jack.h>
  437. //#include <jack/transport.h>
  438. #endif
  439. #undef SIZEOF
  440. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  441. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  442. #elif JUCE_MAC || JUCE_IPHONE
  443. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  444. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  445. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  446. #define USE_COREGRAPHICS_RENDERING 1
  447. #if JUCE_IPHONE
  448. #import <Foundation/Foundation.h>
  449. #import <UIKit/UIKit.h>
  450. #import <AudioToolbox/AudioToolbox.h>
  451. #import <AVFoundation/AVFoundation.h>
  452. #import <CoreData/CoreData.h>
  453. #import <MobileCoreServices/MobileCoreServices.h>
  454. #import <QuartzCore/QuartzCore.h>
  455. #include <sys/fcntl.h>
  456. #if JUCE_OPENGL
  457. #include <OpenGLES/ES1/gl.h>
  458. #include <OpenGLES/ES1/glext.h>
  459. #endif
  460. #else
  461. #import <Cocoa/Cocoa.h>
  462. #import <CoreAudio/HostTime.h>
  463. #import <CoreAudio/AudioHardware.h>
  464. #import <CoreMIDI/MIDIServices.h>
  465. #import <QTKit/QTKit.h>
  466. #import <WebKit/WebKit.h>
  467. #import <DiscRecording/DiscRecording.h>
  468. #import <IOKit/IOKitLib.h>
  469. #import <IOKit/IOCFPlugIn.h>
  470. #import <IOKit/hid/IOHIDLib.h>
  471. #import <IOKit/hid/IOHIDKeys.h>
  472. #import <IOKit/pwr_mgt/IOPMLib.h>
  473. #include <Carbon/Carbon.h>
  474. #include <sys/dir.h>
  475. #include <sys/socket.h>
  476. #endif
  477. #include <sys/sysctl.h>
  478. #include <sys/stat.h>
  479. #include <sys/param.h>
  480. #include <sys/mount.h>
  481. #include <fnmatch.h>
  482. #include <utime.h>
  483. #include <dlfcn.h>
  484. #include <ifaddrs.h>
  485. #include <net/if_dl.h>
  486. #include <mach/mach_time.h>
  487. #if MACOS_10_4_OR_EARLIER
  488. #include <GLUT/glut.h>
  489. #endif
  490. #if ! CGFLOAT_DEFINED
  491. #define CGFloat float
  492. #endif
  493. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  494. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  495. #else
  496. #error "Unknown platform!"
  497. #endif
  498. #endif
  499. //==============================================================================
  500. #define DONT_SET_USING_JUCE_NAMESPACE 1
  501. #undef max
  502. #undef min
  503. #define NO_DUMMY_DECL
  504. #if JUCE_BUILD_NATIVE
  505. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  506. #endif
  507. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  508. #pragma warning (disable: 4309 4305)
  509. #endif
  510. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  511. BEGIN_JUCE_NAMESPACE
  512. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  513. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  514. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  515. class CarbonViewWrapperComponent : public Component,
  516. public ComponentMovementWatcher,
  517. public Timer
  518. {
  519. public:
  520. CarbonViewWrapperComponent()
  521. : ComponentMovementWatcher (this),
  522. wrapperWindow (0),
  523. embeddedView (0),
  524. recursiveResize (false)
  525. {
  526. }
  527. virtual ~CarbonViewWrapperComponent()
  528. {
  529. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  530. }
  531. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  532. virtual void removeView (HIViewRef embeddedView) = 0;
  533. virtual void mouseDown (int x, int y) {}
  534. virtual void paint() {}
  535. virtual bool getEmbeddedViewSize (int& w, int& h)
  536. {
  537. if (embeddedView == 0)
  538. return false;
  539. HIRect bounds;
  540. HIViewGetBounds (embeddedView, &bounds);
  541. w = jmax (1, roundToInt (bounds.size.width));
  542. h = jmax (1, roundToInt (bounds.size.height));
  543. return true;
  544. }
  545. void createWindow()
  546. {
  547. if (wrapperWindow == 0)
  548. {
  549. Rect r;
  550. r.left = getScreenX();
  551. r.top = getScreenY();
  552. r.right = r.left + getWidth();
  553. r.bottom = r.top + getHeight();
  554. CreateNewWindow (kDocumentWindowClass,
  555. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  556. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  557. &r, &wrapperWindow);
  558. jassert (wrapperWindow != 0);
  559. if (wrapperWindow == 0)
  560. return;
  561. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  562. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  563. [ownerWindow addChildWindow: carbonWindow
  564. ordered: NSWindowAbove];
  565. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  566. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  567. { kEventClassWindow, kEventWindowHandleDeactivate } };
  568. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  569. InstallWindowEventHandler (wrapperWindow, upp,
  570. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  571. windowEventTypes, this, &eventHandlerRef);
  572. setOurSizeToEmbeddedViewSize();
  573. setEmbeddedWindowToOurSize();
  574. creationTime = Time::getCurrentTime();
  575. }
  576. }
  577. void deleteWindow()
  578. {
  579. removeView (embeddedView);
  580. embeddedView = 0;
  581. if (wrapperWindow != 0)
  582. {
  583. RemoveEventHandler (eventHandlerRef);
  584. DisposeWindow (wrapperWindow);
  585. wrapperWindow = 0;
  586. }
  587. }
  588. void setOurSizeToEmbeddedViewSize()
  589. {
  590. int w, h;
  591. if (getEmbeddedViewSize (w, h))
  592. {
  593. if (w != getWidth() || h != getHeight())
  594. {
  595. startTimer (50);
  596. setSize (w, h);
  597. if (getParentComponent() != 0)
  598. getParentComponent()->setSize (w, h);
  599. }
  600. else
  601. {
  602. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  603. }
  604. }
  605. else
  606. {
  607. stopTimer();
  608. }
  609. }
  610. void setEmbeddedWindowToOurSize()
  611. {
  612. if (! recursiveResize)
  613. {
  614. recursiveResize = true;
  615. if (embeddedView != 0)
  616. {
  617. HIRect r;
  618. r.origin.x = 0;
  619. r.origin.y = 0;
  620. r.size.width = (float) getWidth();
  621. r.size.height = (float) getHeight();
  622. HIViewSetFrame (embeddedView, &r);
  623. }
  624. if (wrapperWindow != 0)
  625. {
  626. Rect wr;
  627. wr.left = getScreenX();
  628. wr.top = getScreenY();
  629. wr.right = wr.left + getWidth();
  630. wr.bottom = wr.top + getHeight();
  631. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  632. ShowWindow (wrapperWindow);
  633. }
  634. recursiveResize = false;
  635. }
  636. }
  637. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  638. {
  639. setEmbeddedWindowToOurSize();
  640. }
  641. void componentPeerChanged()
  642. {
  643. deleteWindow();
  644. createWindow();
  645. }
  646. void componentVisibilityChanged (Component&)
  647. {
  648. if (isShowing())
  649. createWindow();
  650. else
  651. deleteWindow();
  652. setEmbeddedWindowToOurSize();
  653. }
  654. static void recursiveHIViewRepaint (HIViewRef view)
  655. {
  656. HIViewSetNeedsDisplay (view, true);
  657. HIViewRef child = HIViewGetFirstSubview (view);
  658. while (child != 0)
  659. {
  660. recursiveHIViewRepaint (child);
  661. child = HIViewGetNextView (child);
  662. }
  663. }
  664. void timerCallback()
  665. {
  666. setOurSizeToEmbeddedViewSize();
  667. // To avoid strange overpainting problems when the UI is first opened, we'll
  668. // repaint it a few times during the first second that it's on-screen..
  669. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  670. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  671. }
  672. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  673. EventRef event)
  674. {
  675. switch (GetEventKind (event))
  676. {
  677. case kEventWindowHandleDeactivate:
  678. ActivateWindow (wrapperWindow, TRUE);
  679. break;
  680. case kEventWindowGetClickActivation:
  681. {
  682. getTopLevelComponent()->toFront (false);
  683. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  684. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  685. sizeof (ClickActivationResult), &howToHandleClick);
  686. HIViewSetNeedsDisplay (embeddedView, true);
  687. }
  688. break;
  689. }
  690. return noErr;
  691. }
  692. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  693. EventRef event, void* userData)
  694. {
  695. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  696. }
  697. protected:
  698. WindowRef wrapperWindow;
  699. HIViewRef embeddedView;
  700. bool recursiveResize;
  701. Time creationTime;
  702. EventHandlerRef eventHandlerRef;
  703. };
  704. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  705. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  706. END_JUCE_NAMESPACE
  707. #endif
  708. #define JUCE_AMALGAMATED_TEMPLATE 1
  709. //==============================================================================
  710. #if JUCE_BUILD_CORE
  711. /*** Start of inlined file: juce_FileLogger.cpp ***/
  712. BEGIN_JUCE_NAMESPACE
  713. FileLogger::FileLogger (const File& logFile_,
  714. const String& welcomeMessage,
  715. const int maxInitialFileSizeBytes)
  716. : logFile (logFile_)
  717. {
  718. if (maxInitialFileSizeBytes >= 0)
  719. trimFileSize (maxInitialFileSizeBytes);
  720. if (! logFile_.exists())
  721. {
  722. // do this so that the parent directories get created..
  723. logFile_.create();
  724. }
  725. logStream = logFile_.createOutputStream (256);
  726. jassert (logStream != 0);
  727. String welcome;
  728. welcome << "\r\n**********************************************************\r\n"
  729. << welcomeMessage
  730. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  731. << "\r\n";
  732. logMessage (welcome);
  733. }
  734. FileLogger::~FileLogger()
  735. {
  736. }
  737. void FileLogger::logMessage (const String& message)
  738. {
  739. if (logStream != 0)
  740. {
  741. DBG (message);
  742. const ScopedLock sl (logLock);
  743. (*logStream) << message << "\r\n";
  744. logStream->flush();
  745. }
  746. }
  747. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  748. {
  749. if (maxFileSizeBytes <= 0)
  750. {
  751. logFile.deleteFile();
  752. }
  753. else
  754. {
  755. const int64 fileSize = logFile.getSize();
  756. if (fileSize > maxFileSizeBytes)
  757. {
  758. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  759. jassert (in != 0);
  760. if (in != 0)
  761. {
  762. in->setPosition (fileSize - maxFileSizeBytes);
  763. String content;
  764. {
  765. MemoryBlock contentToSave;
  766. contentToSave.setSize (maxFileSizeBytes + 4);
  767. contentToSave.fillWith (0);
  768. in->read (contentToSave.getData(), maxFileSizeBytes);
  769. in = 0;
  770. content = contentToSave.toString();
  771. }
  772. int newStart = 0;
  773. while (newStart < fileSize
  774. && content[newStart] != '\n'
  775. && content[newStart] != '\r')
  776. ++newStart;
  777. logFile.deleteFile();
  778. logFile.appendText (content.substring (newStart), false, false);
  779. }
  780. }
  781. }
  782. }
  783. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  784. const String& logFileName,
  785. const String& welcomeMessage,
  786. const int maxInitialFileSizeBytes)
  787. {
  788. #if JUCE_MAC
  789. File logFile ("~/Library/Logs");
  790. logFile = logFile.getChildFile (logFileSubDirectoryName)
  791. .getChildFile (logFileName);
  792. #else
  793. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  794. if (logFile.isDirectory())
  795. {
  796. logFile = logFile.getChildFile (logFileSubDirectoryName)
  797. .getChildFile (logFileName);
  798. }
  799. #endif
  800. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  801. }
  802. END_JUCE_NAMESPACE
  803. /*** End of inlined file: juce_FileLogger.cpp ***/
  804. /*** Start of inlined file: juce_Logger.cpp ***/
  805. BEGIN_JUCE_NAMESPACE
  806. Logger::Logger()
  807. {
  808. }
  809. Logger::~Logger()
  810. {
  811. }
  812. static Logger* currentLogger = 0;
  813. void Logger::setCurrentLogger (Logger* const newLogger,
  814. const bool deleteOldLogger)
  815. {
  816. Logger* const oldLogger = currentLogger;
  817. currentLogger = newLogger;
  818. if (deleteOldLogger)
  819. delete oldLogger;
  820. }
  821. void Logger::writeToLog (const String& message)
  822. {
  823. if (currentLogger != 0)
  824. currentLogger->logMessage (message);
  825. else
  826. outputDebugString (message);
  827. }
  828. #if JUCE_LOG_ASSERTIONS
  829. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  830. {
  831. String m ("JUCE Assertion failure in ");
  832. m << filename << ", line " << lineNum;
  833. Logger::writeToLog (m);
  834. }
  835. #endif
  836. END_JUCE_NAMESPACE
  837. /*** End of inlined file: juce_Logger.cpp ***/
  838. /*** Start of inlined file: juce_Random.cpp ***/
  839. BEGIN_JUCE_NAMESPACE
  840. Random::Random (const int64 seedValue) throw()
  841. : seed (seedValue)
  842. {
  843. }
  844. Random::~Random() throw()
  845. {
  846. }
  847. void Random::setSeed (const int64 newSeed) throw()
  848. {
  849. seed = newSeed;
  850. }
  851. void Random::combineSeed (const int64 seedValue) throw()
  852. {
  853. seed ^= nextInt64() ^ seedValue;
  854. }
  855. void Random::setSeedRandomly()
  856. {
  857. combineSeed ((int64) (pointer_sized_int) this);
  858. combineSeed (Time::getMillisecondCounter());
  859. combineSeed (Time::getHighResolutionTicks());
  860. combineSeed (Time::getHighResolutionTicksPerSecond());
  861. combineSeed (Time::currentTimeMillis());
  862. }
  863. int Random::nextInt() throw()
  864. {
  865. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  866. return (int) (seed >> 16);
  867. }
  868. int Random::nextInt (const int maxValue) throw()
  869. {
  870. jassert (maxValue > 0);
  871. return (nextInt() & 0x7fffffff) % maxValue;
  872. }
  873. int64 Random::nextInt64() throw()
  874. {
  875. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  876. }
  877. bool Random::nextBool() throw()
  878. {
  879. return (nextInt() & 0x80000000) != 0;
  880. }
  881. float Random::nextFloat() throw()
  882. {
  883. return static_cast <uint32> (nextInt()) / (float) 0xffffffff;
  884. }
  885. double Random::nextDouble() throw()
  886. {
  887. return static_cast <uint32> (nextInt()) / (double) 0xffffffff;
  888. }
  889. const BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
  890. {
  891. BigInteger n;
  892. do
  893. {
  894. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  895. }
  896. while (n >= maximumValue);
  897. return n;
  898. }
  899. void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits)
  900. {
  901. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  902. while ((startBit & 31) != 0 && numBits > 0)
  903. {
  904. arrayToChange.setBit (startBit++, nextBool());
  905. --numBits;
  906. }
  907. while (numBits >= 32)
  908. {
  909. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  910. startBit += 32;
  911. numBits -= 32;
  912. }
  913. while (--numBits >= 0)
  914. arrayToChange.setBit (startBit + numBits, nextBool());
  915. }
  916. Random& Random::getSystemRandom() throw()
  917. {
  918. static Random sysRand (1);
  919. return sysRand;
  920. }
  921. END_JUCE_NAMESPACE
  922. /*** End of inlined file: juce_Random.cpp ***/
  923. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  924. BEGIN_JUCE_NAMESPACE
  925. RelativeTime::RelativeTime (const double seconds_) throw()
  926. : seconds (seconds_)
  927. {
  928. }
  929. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  930. : seconds (other.seconds)
  931. {
  932. }
  933. RelativeTime::~RelativeTime() throw()
  934. {
  935. }
  936. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  937. {
  938. return RelativeTime (milliseconds * 0.001);
  939. }
  940. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  941. {
  942. return RelativeTime (milliseconds * 0.001);
  943. }
  944. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  945. {
  946. return RelativeTime (numberOfMinutes * 60.0);
  947. }
  948. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  949. {
  950. return RelativeTime (numberOfHours * (60.0 * 60.0));
  951. }
  952. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  953. {
  954. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  955. }
  956. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  957. {
  958. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  959. }
  960. int64 RelativeTime::inMilliseconds() const throw()
  961. {
  962. return (int64)(seconds * 1000.0);
  963. }
  964. double RelativeTime::inMinutes() const throw()
  965. {
  966. return seconds / 60.0;
  967. }
  968. double RelativeTime::inHours() const throw()
  969. {
  970. return seconds / (60.0 * 60.0);
  971. }
  972. double RelativeTime::inDays() const throw()
  973. {
  974. return seconds / (60.0 * 60.0 * 24.0);
  975. }
  976. double RelativeTime::inWeeks() const throw()
  977. {
  978. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  979. }
  980. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  981. {
  982. if (seconds < 0.001 && seconds > -0.001)
  983. return returnValueForZeroTime;
  984. String result;
  985. if (seconds < 0)
  986. result = "-";
  987. int fieldsShown = 0;
  988. int n = abs ((int) inWeeks());
  989. if (n > 0)
  990. {
  991. result << n << ((n == 1) ? TRANS(" week ")
  992. : TRANS(" weeks "));
  993. ++fieldsShown;
  994. }
  995. n = abs ((int) inDays()) % 7;
  996. if (n > 0)
  997. {
  998. result << n << ((n == 1) ? TRANS(" day ")
  999. : TRANS(" days "));
  1000. ++fieldsShown;
  1001. }
  1002. if (fieldsShown < 2)
  1003. {
  1004. n = abs ((int) inHours()) % 24;
  1005. if (n > 0)
  1006. {
  1007. result << n << ((n == 1) ? TRANS(" hr ")
  1008. : TRANS(" hrs "));
  1009. ++fieldsShown;
  1010. }
  1011. if (fieldsShown < 2)
  1012. {
  1013. n = abs ((int) inMinutes()) % 60;
  1014. if (n > 0)
  1015. {
  1016. result << n << ((n == 1) ? TRANS(" min ")
  1017. : TRANS(" mins "));
  1018. ++fieldsShown;
  1019. }
  1020. if (fieldsShown < 2)
  1021. {
  1022. n = abs ((int) inSeconds()) % 60;
  1023. if (n > 0)
  1024. {
  1025. result << n << ((n == 1) ? TRANS(" sec ")
  1026. : TRANS(" secs "));
  1027. ++fieldsShown;
  1028. }
  1029. if (fieldsShown < 1)
  1030. {
  1031. n = abs ((int) inMilliseconds()) % 1000;
  1032. if (n > 0)
  1033. {
  1034. result << n << TRANS(" ms");
  1035. ++fieldsShown;
  1036. }
  1037. }
  1038. }
  1039. }
  1040. }
  1041. return result.trimEnd();
  1042. }
  1043. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1044. {
  1045. seconds = other.seconds;
  1046. return *this;
  1047. }
  1048. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1049. {
  1050. return seconds == other.seconds;
  1051. }
  1052. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1053. {
  1054. return seconds != other.seconds;
  1055. }
  1056. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1057. {
  1058. return seconds > other.seconds;
  1059. }
  1060. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1061. {
  1062. return seconds < other.seconds;
  1063. }
  1064. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1065. {
  1066. return seconds >= other.seconds;
  1067. }
  1068. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1069. {
  1070. return seconds <= other.seconds;
  1071. }
  1072. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1073. {
  1074. return RelativeTime (seconds + timeToAdd.seconds);
  1075. }
  1076. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1077. {
  1078. return RelativeTime (seconds - timeToSubtract.seconds);
  1079. }
  1080. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1081. {
  1082. return RelativeTime (seconds + secondsToAdd);
  1083. }
  1084. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1085. {
  1086. return RelativeTime (seconds - secondsToSubtract);
  1087. }
  1088. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1089. {
  1090. seconds += timeToAdd.seconds;
  1091. return *this;
  1092. }
  1093. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1094. {
  1095. seconds -= timeToSubtract.seconds;
  1096. return *this;
  1097. }
  1098. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1099. {
  1100. seconds += secondsToAdd;
  1101. return *this;
  1102. }
  1103. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1104. {
  1105. seconds -= secondsToSubtract;
  1106. return *this;
  1107. }
  1108. END_JUCE_NAMESPACE
  1109. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1110. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1111. BEGIN_JUCE_NAMESPACE
  1112. const String SystemStats::getJUCEVersion() throw()
  1113. {
  1114. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1115. + "." + String (JUCE_MINOR_VERSION)
  1116. + "." + String (JUCE_BUILDNUMBER);
  1117. }
  1118. const StringArray SystemStats::getMACAddressStrings()
  1119. {
  1120. int64 macAddresses [16];
  1121. const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
  1122. StringArray s;
  1123. for (int i = 0; i < numAddresses; ++i)
  1124. {
  1125. s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
  1126. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
  1127. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
  1128. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
  1129. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
  1130. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
  1131. }
  1132. return s;
  1133. }
  1134. static bool juceInitialisedNonGUI = false;
  1135. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1136. {
  1137. if (! juceInitialisedNonGUI)
  1138. {
  1139. #if JUCE_MAC || JUCE_IPHONE
  1140. const ScopedAutoReleasePool pool;
  1141. #endif
  1142. #ifdef JUCE_DEBUG
  1143. {
  1144. // Some simple test code to keep an eye on things and make sure these functions
  1145. // work ok on all platforms. Let me know if any of these assertions fail!
  1146. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1147. char a1[7];
  1148. jassert (numElementsInArray(a1) == 7);
  1149. int a2[3];
  1150. jassert (numElementsInArray(a2) == 3);
  1151. int n = 1;
  1152. Atomic::increment (n);
  1153. jassert (Atomic::incrementAndReturn (n) == 3);
  1154. Atomic::decrement (n);
  1155. jassert (Atomic::decrementAndReturn (n) == 1);
  1156. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1157. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1158. // Some quick stream tests..
  1159. int randomInt = Random::getSystemRandom().nextInt();
  1160. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1161. double randomDouble = Random::getSystemRandom().nextDouble();
  1162. String randomString;
  1163. for (int i = 50; --i >= 0;)
  1164. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1165. MemoryOutputStream mo;
  1166. mo.writeInt (randomInt);
  1167. mo.writeIntBigEndian (randomInt);
  1168. mo.writeCompressedInt (randomInt);
  1169. mo.writeString (randomString);
  1170. mo.writeInt64 (randomInt64);
  1171. mo.writeInt64BigEndian (randomInt64);
  1172. mo.writeDouble (randomDouble);
  1173. mo.writeDoubleBigEndian (randomDouble);
  1174. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1175. jassert (mi.readInt() == randomInt);
  1176. jassert (mi.readIntBigEndian() == randomInt);
  1177. jassert (mi.readCompressedInt() == randomInt);
  1178. jassert (mi.readString() == randomString);
  1179. jassert (mi.readInt64() == randomInt64);
  1180. jassert (mi.readInt64BigEndian() == randomInt64);
  1181. jassert (mi.readDouble() == randomDouble);
  1182. jassert (mi.readDoubleBigEndian() == randomDouble);
  1183. }
  1184. #endif
  1185. // Now the real initialisation..
  1186. juceInitialisedNonGUI = true;
  1187. DBG (SystemStats::getJUCEVersion());
  1188. SystemStats::initialiseStats();
  1189. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1190. }
  1191. }
  1192. #if JUCE_WINDOWS
  1193. // This is imported from the sockets code..
  1194. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1195. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1196. #endif
  1197. #if JUCE_DEBUG
  1198. extern void juce_CheckForDanglingStreams();
  1199. #endif
  1200. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1201. {
  1202. if (juceInitialisedNonGUI)
  1203. {
  1204. #if JUCE_MAC || JUCE_IPHONE
  1205. const ScopedAutoReleasePool pool;
  1206. #endif
  1207. #if JUCE_WINDOWS
  1208. // need to shut down sockets if they were used..
  1209. if (juce_CloseWin32SocketLib != 0)
  1210. (*juce_CloseWin32SocketLib)();
  1211. #endif
  1212. LocalisedStrings::setCurrentMappings (0);
  1213. Thread::stopAllThreads (3000);
  1214. #if JUCE_DEBUG
  1215. juce_CheckForDanglingStreams();
  1216. #endif
  1217. juceInitialisedNonGUI = false;
  1218. }
  1219. }
  1220. #ifdef JUCE_DLL
  1221. void* juce_Malloc (const int size)
  1222. {
  1223. return malloc (size);
  1224. }
  1225. void* juce_Calloc (const int size)
  1226. {
  1227. return calloc (1, size);
  1228. }
  1229. void* juce_Realloc (void* const block, const int size)
  1230. {
  1231. return realloc (block, size);
  1232. }
  1233. void juce_Free (void* const block)
  1234. {
  1235. free (block);
  1236. }
  1237. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1238. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1239. {
  1240. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1241. }
  1242. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1243. {
  1244. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1245. }
  1246. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1247. {
  1248. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1249. }
  1250. void juce_DebugFree (void* const block)
  1251. {
  1252. _free_dbg (block, _NORMAL_BLOCK);
  1253. }
  1254. #endif
  1255. #endif
  1256. END_JUCE_NAMESPACE
  1257. /*** End of inlined file: juce_SystemStats.cpp ***/
  1258. /*** Start of inlined file: juce_Time.cpp ***/
  1259. #ifdef _MSC_VER
  1260. #pragma warning (disable: 4514)
  1261. #pragma warning (push)
  1262. #endif
  1263. #ifndef JUCE_WINDOWS
  1264. #include <sys/time.h>
  1265. #else
  1266. #include <ctime>
  1267. #endif
  1268. #include <sys/timeb.h>
  1269. BEGIN_JUCE_NAMESPACE
  1270. #ifdef _MSC_VER
  1271. #pragma warning (pop)
  1272. #ifdef _INC_TIME_INL
  1273. #define USE_NEW_SECURE_TIME_FNS
  1274. #endif
  1275. #endif
  1276. namespace TimeHelpers
  1277. {
  1278. static struct tm millisToLocal (const int64 millis) throw()
  1279. {
  1280. struct tm result;
  1281. const int64 seconds = millis / 1000;
  1282. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1283. {
  1284. // use extended maths for dates beyond 1970 to 2037..
  1285. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1286. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1287. const int days = (int) (jdm / literal64bit (86400));
  1288. const int a = 32044 + days;
  1289. const int b = (4 * a + 3) / 146097;
  1290. const int c = a - (b * 146097) / 4;
  1291. const int d = (4 * c + 3) / 1461;
  1292. const int e = c - (d * 1461) / 4;
  1293. const int m = (5 * e + 2) / 153;
  1294. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1295. result.tm_mon = m + 2 - 12 * (m / 10);
  1296. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1297. result.tm_wday = (days + 1) % 7;
  1298. result.tm_yday = -1;
  1299. int t = (int) (jdm % literal64bit (86400));
  1300. result.tm_hour = t / 3600;
  1301. t %= 3600;
  1302. result.tm_min = t / 60;
  1303. result.tm_sec = t % 60;
  1304. result.tm_isdst = -1;
  1305. }
  1306. else
  1307. {
  1308. time_t now = static_cast <time_t> (seconds);
  1309. #if JUCE_WINDOWS
  1310. #ifdef USE_NEW_SECURE_TIME_FNS
  1311. if (now >= 0 && now <= 0x793406fff)
  1312. localtime_s (&result, &now);
  1313. else
  1314. zeromem (&result, sizeof (result));
  1315. #else
  1316. result = *localtime (&now);
  1317. #endif
  1318. #else
  1319. // more thread-safe
  1320. localtime_r (&now, &result);
  1321. #endif
  1322. }
  1323. return result;
  1324. }
  1325. static int extendedModulo (const int64 value, const int modulo) throw()
  1326. {
  1327. return (int) (value >= 0 ? (value % modulo)
  1328. : (value - ((value / modulo) + 1) * modulo));
  1329. }
  1330. static uint32 lastMSCounterValue = 0;
  1331. }
  1332. Time::Time() throw()
  1333. : millisSinceEpoch (0)
  1334. {
  1335. }
  1336. Time::Time (const Time& other) throw()
  1337. : millisSinceEpoch (other.millisSinceEpoch)
  1338. {
  1339. }
  1340. Time::Time (const int64 ms) throw()
  1341. : millisSinceEpoch (ms)
  1342. {
  1343. }
  1344. Time::Time (const int year,
  1345. const int month,
  1346. const int day,
  1347. const int hours,
  1348. const int minutes,
  1349. const int seconds,
  1350. const int milliseconds,
  1351. const bool useLocalTime) throw()
  1352. {
  1353. jassert (year > 100); // year must be a 4-digit version
  1354. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1355. {
  1356. // use extended maths for dates beyond 1970 to 2037..
  1357. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1358. : 0;
  1359. const int a = (13 - month) / 12;
  1360. const int y = year + 4800 - a;
  1361. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1362. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1363. - 32045;
  1364. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1365. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1366. + milliseconds;
  1367. }
  1368. else
  1369. {
  1370. struct tm t;
  1371. t.tm_year = year - 1900;
  1372. t.tm_mon = month;
  1373. t.tm_mday = day;
  1374. t.tm_hour = hours;
  1375. t.tm_min = minutes;
  1376. t.tm_sec = seconds;
  1377. t.tm_isdst = -1;
  1378. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1379. if (millisSinceEpoch < 0)
  1380. millisSinceEpoch = 0;
  1381. else
  1382. millisSinceEpoch += milliseconds;
  1383. }
  1384. }
  1385. Time::~Time() throw()
  1386. {
  1387. }
  1388. Time& Time::operator= (const Time& other) throw()
  1389. {
  1390. millisSinceEpoch = other.millisSinceEpoch;
  1391. return *this;
  1392. }
  1393. int64 Time::currentTimeMillis() throw()
  1394. {
  1395. static uint32 lastCounterResult = 0xffffffff;
  1396. static int64 correction = 0;
  1397. const uint32 now = getMillisecondCounter();
  1398. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1399. if (now < lastCounterResult)
  1400. {
  1401. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1402. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1403. {
  1404. // get the time once using normal library calls, and store the difference needed to
  1405. // turn the millisecond counter into a real time.
  1406. #if JUCE_WINDOWS
  1407. struct _timeb t;
  1408. #ifdef USE_NEW_SECURE_TIME_FNS
  1409. _ftime_s (&t);
  1410. #else
  1411. _ftime (&t);
  1412. #endif
  1413. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1414. #else
  1415. struct timeval tv;
  1416. struct timezone tz;
  1417. gettimeofday (&tv, &tz);
  1418. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1419. #endif
  1420. }
  1421. }
  1422. lastCounterResult = now;
  1423. return correction + now;
  1424. }
  1425. uint32 juce_millisecondsSinceStartup() throw();
  1426. uint32 Time::getMillisecondCounter() throw()
  1427. {
  1428. const uint32 now = juce_millisecondsSinceStartup();
  1429. if (now < TimeHelpers::lastMSCounterValue)
  1430. {
  1431. // in multi-threaded apps this might be called concurrently, so
  1432. // make sure that our last counter value only increases and doesn't
  1433. // go backwards..
  1434. if (now < TimeHelpers::lastMSCounterValue - 1000)
  1435. TimeHelpers::lastMSCounterValue = now;
  1436. }
  1437. else
  1438. {
  1439. TimeHelpers::lastMSCounterValue = now;
  1440. }
  1441. return now;
  1442. }
  1443. uint32 Time::getApproximateMillisecondCounter() throw()
  1444. {
  1445. jassert (TimeHelpers::lastMSCounterValue != 0);
  1446. return TimeHelpers::lastMSCounterValue;
  1447. }
  1448. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1449. {
  1450. for (;;)
  1451. {
  1452. const uint32 now = getMillisecondCounter();
  1453. if (now >= targetTime)
  1454. break;
  1455. const int toWait = targetTime - now;
  1456. if (toWait > 2)
  1457. {
  1458. Thread::sleep (jmin (20, toWait >> 1));
  1459. }
  1460. else
  1461. {
  1462. // xxx should consider using mutex_pause on the mac as it apparently
  1463. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1464. for (int i = 10; --i >= 0;)
  1465. Thread::yield();
  1466. }
  1467. }
  1468. }
  1469. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1470. {
  1471. return ticks / (double) getHighResolutionTicksPerSecond();
  1472. }
  1473. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1474. {
  1475. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1476. }
  1477. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1478. {
  1479. return Time (currentTimeMillis());
  1480. }
  1481. const String Time::toString (const bool includeDate,
  1482. const bool includeTime,
  1483. const bool includeSeconds,
  1484. const bool use24HourClock) const throw()
  1485. {
  1486. String result;
  1487. if (includeDate)
  1488. {
  1489. result << getDayOfMonth() << ' '
  1490. << getMonthName (true) << ' '
  1491. << getYear();
  1492. if (includeTime)
  1493. result << ' ';
  1494. }
  1495. if (includeTime)
  1496. {
  1497. const int mins = getMinutes();
  1498. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1499. << (mins < 10 ? ":0" : ":") << mins;
  1500. if (includeSeconds)
  1501. {
  1502. const int secs = getSeconds();
  1503. result << (secs < 10 ? ":0" : ":") << secs;
  1504. }
  1505. if (! use24HourClock)
  1506. result << (isAfternoon() ? "pm" : "am");
  1507. }
  1508. return result.trimEnd();
  1509. }
  1510. const String Time::formatted (const juce_wchar* const format) const throw()
  1511. {
  1512. String buffer;
  1513. int bufferSize = 128;
  1514. buffer.preallocateStorage (bufferSize);
  1515. struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  1516. while (CharacterFunctions::ftime (static_cast <juce_wchar*> (buffer), bufferSize, format, &t) <= 0)
  1517. {
  1518. bufferSize += 128;
  1519. buffer.preallocateStorage (bufferSize);
  1520. }
  1521. return buffer;
  1522. }
  1523. int Time::getYear() const throw()
  1524. {
  1525. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900;
  1526. }
  1527. int Time::getMonth() const throw()
  1528. {
  1529. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon;
  1530. }
  1531. int Time::getDayOfMonth() const throw()
  1532. {
  1533. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday;
  1534. }
  1535. int Time::getDayOfWeek() const throw()
  1536. {
  1537. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday;
  1538. }
  1539. int Time::getHours() const throw()
  1540. {
  1541. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour;
  1542. }
  1543. int Time::getHoursInAmPmFormat() const throw()
  1544. {
  1545. const int hours = getHours();
  1546. if (hours == 0)
  1547. return 12;
  1548. else if (hours <= 12)
  1549. return hours;
  1550. else
  1551. return hours - 12;
  1552. }
  1553. bool Time::isAfternoon() const throw()
  1554. {
  1555. return getHours() >= 12;
  1556. }
  1557. int Time::getMinutes() const throw()
  1558. {
  1559. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min;
  1560. }
  1561. int Time::getSeconds() const throw()
  1562. {
  1563. return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60);
  1564. }
  1565. int Time::getMilliseconds() const throw()
  1566. {
  1567. return TimeHelpers::extendedModulo (millisSinceEpoch, 1000);
  1568. }
  1569. bool Time::isDaylightSavingTime() const throw()
  1570. {
  1571. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  1572. }
  1573. const String Time::getTimeZone() const throw()
  1574. {
  1575. String zone[2];
  1576. #if JUCE_WINDOWS
  1577. _tzset();
  1578. #ifdef USE_NEW_SECURE_TIME_FNS
  1579. {
  1580. char name [128];
  1581. size_t length;
  1582. for (int i = 0; i < 2; ++i)
  1583. {
  1584. zeromem (name, sizeof (name));
  1585. _get_tzname (&length, name, 127, i);
  1586. zone[i] = name;
  1587. }
  1588. }
  1589. #else
  1590. const char** const zonePtr = (const char**) _tzname;
  1591. zone[0] = zonePtr[0];
  1592. zone[1] = zonePtr[1];
  1593. #endif
  1594. #else
  1595. tzset();
  1596. const char** const zonePtr = (const char**) tzname;
  1597. zone[0] = zonePtr[0];
  1598. zone[1] = zonePtr[1];
  1599. #endif
  1600. if (isDaylightSavingTime())
  1601. {
  1602. zone[0] = zone[1];
  1603. if (zone[0].length() > 3
  1604. && zone[0].containsIgnoreCase ("daylight")
  1605. && zone[0].contains ("GMT"))
  1606. zone[0] = "BST";
  1607. }
  1608. return zone[0].substring (0, 3);
  1609. }
  1610. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1611. {
  1612. return getMonthName (getMonth(), threeLetterVersion);
  1613. }
  1614. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1615. {
  1616. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1617. }
  1618. const String Time::getMonthName (int monthNumber, const bool threeLetterVersion) throw()
  1619. {
  1620. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1621. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1622. monthNumber %= 12;
  1623. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1624. : longMonthNames [monthNumber]);
  1625. }
  1626. const String Time::getWeekdayName (int day, const bool threeLetterVersion) throw()
  1627. {
  1628. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1629. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1630. day %= 7;
  1631. return TRANS (threeLetterVersion ? shortDayNames [day]
  1632. : longDayNames [day]);
  1633. }
  1634. END_JUCE_NAMESPACE
  1635. /*** End of inlined file: juce_Time.cpp ***/
  1636. /*** Start of inlined file: juce_BitArray.cpp ***/
  1637. BEGIN_JUCE_NAMESPACE
  1638. BigInteger::BigInteger()
  1639. : numValues (4),
  1640. highestBit (-1),
  1641. negative (false)
  1642. {
  1643. values.calloc (numValues + 1);
  1644. }
  1645. BigInteger::BigInteger (const int value)
  1646. : numValues (4),
  1647. highestBit (31),
  1648. negative (value < 0)
  1649. {
  1650. values.calloc (numValues + 1);
  1651. values[0] = abs (value);
  1652. highestBit = getHighestBit();
  1653. }
  1654. BigInteger::BigInteger (int64 value)
  1655. : numValues (4),
  1656. highestBit (63),
  1657. negative (value < 0)
  1658. {
  1659. values.calloc (numValues + 1);
  1660. if (value < 0)
  1661. value = -value;
  1662. values[0] = (unsigned int) value;
  1663. values[1] = (unsigned int) (value >> 32);
  1664. highestBit = getHighestBit();
  1665. }
  1666. BigInteger::BigInteger (const unsigned int value)
  1667. : numValues (4),
  1668. highestBit (31),
  1669. negative (false)
  1670. {
  1671. values.calloc (numValues + 1);
  1672. values[0] = value;
  1673. highestBit = getHighestBit();
  1674. }
  1675. BigInteger::BigInteger (const BigInteger& other)
  1676. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1677. highestBit (other.getHighestBit()),
  1678. negative (other.negative)
  1679. {
  1680. values.malloc (numValues + 1);
  1681. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1682. }
  1683. BigInteger::~BigInteger()
  1684. {
  1685. }
  1686. void BigInteger::swapWith (BigInteger& other) throw()
  1687. {
  1688. values.swapWith (other.values);
  1689. swapVariables (numValues, other.numValues);
  1690. swapVariables (highestBit, other.highestBit);
  1691. swapVariables (negative, other.negative);
  1692. }
  1693. BigInteger& BigInteger::operator= (const BigInteger& other)
  1694. {
  1695. if (this != &other)
  1696. {
  1697. highestBit = other.getHighestBit();
  1698. numValues = jmax (4, (highestBit >> 5) + 1);
  1699. negative = other.negative;
  1700. values.malloc (numValues + 1);
  1701. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1702. }
  1703. return *this;
  1704. }
  1705. void BigInteger::ensureSize (const int numVals)
  1706. {
  1707. if (numVals + 2 >= numValues)
  1708. {
  1709. int oldSize = numValues;
  1710. numValues = ((numVals + 2) * 3) / 2;
  1711. values.realloc (numValues + 1);
  1712. while (oldSize < numValues)
  1713. values [oldSize++] = 0;
  1714. }
  1715. }
  1716. bool BigInteger::operator[] (const int bit) const throw()
  1717. {
  1718. return bit <= highestBit && bit >= 0
  1719. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1720. }
  1721. int BigInteger::toInteger() const throw()
  1722. {
  1723. const int n = (int) (values[0] & 0x7fffffff);
  1724. return negative ? -n : n;
  1725. }
  1726. const BigInteger BigInteger::getBitRange (int startBit, int numBits) const
  1727. {
  1728. BigInteger r;
  1729. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  1730. r.ensureSize (numBits >> 5);
  1731. r.highestBit = numBits;
  1732. int i = 0;
  1733. while (numBits > 0)
  1734. {
  1735. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  1736. numBits -= 32;
  1737. startBit += 32;
  1738. }
  1739. r.highestBit = r.getHighestBit();
  1740. return r;
  1741. }
  1742. int BigInteger::getBitRangeAsInt (const int startBit, int numBits) const throw()
  1743. {
  1744. if (numBits > 32)
  1745. {
  1746. jassertfalse // use getBitRange() if you need more than 32 bits..
  1747. numBits = 32;
  1748. }
  1749. numBits = jmin (numBits, highestBit + 1 - startBit);
  1750. if (numBits <= 0)
  1751. return 0;
  1752. const int pos = startBit >> 5;
  1753. const int offset = startBit & 31;
  1754. const int endSpace = 32 - numBits;
  1755. uint32 n = ((uint32) values [pos]) >> offset;
  1756. if (offset > endSpace)
  1757. n |= ((uint32) values [pos + 1]) << (32 - offset);
  1758. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  1759. }
  1760. void BigInteger::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet)
  1761. {
  1762. if (numBits > 32)
  1763. {
  1764. jassertfalse
  1765. numBits = 32;
  1766. }
  1767. for (int i = 0; i < numBits; ++i)
  1768. {
  1769. setBit (startBit + i, (valueToSet & 1) != 0);
  1770. valueToSet >>= 1;
  1771. }
  1772. }
  1773. void BigInteger::clear()
  1774. {
  1775. if (numValues > 16)
  1776. {
  1777. numValues = 4;
  1778. values.calloc (numValues + 1);
  1779. }
  1780. else
  1781. {
  1782. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1783. }
  1784. highestBit = -1;
  1785. negative = false;
  1786. }
  1787. void BigInteger::setBit (const int bit)
  1788. {
  1789. if (bit >= 0)
  1790. {
  1791. if (bit > highestBit)
  1792. {
  1793. ensureSize (bit >> 5);
  1794. highestBit = bit;
  1795. }
  1796. values [bit >> 5] |= (1 << (bit & 31));
  1797. }
  1798. }
  1799. void BigInteger::setBit (const int bit, const bool shouldBeSet)
  1800. {
  1801. if (shouldBeSet)
  1802. setBit (bit);
  1803. else
  1804. clearBit (bit);
  1805. }
  1806. void BigInteger::clearBit (const int bit) throw()
  1807. {
  1808. if (bit >= 0 && bit <= highestBit)
  1809. values [bit >> 5] &= ~(1 << (bit & 31));
  1810. }
  1811. void BigInteger::setRange (int startBit, int numBits, const bool shouldBeSet)
  1812. {
  1813. while (--numBits >= 0)
  1814. setBit (startBit++, shouldBeSet);
  1815. }
  1816. void BigInteger::insertBit (const int bit, const bool shouldBeSet)
  1817. {
  1818. if (bit >= 0)
  1819. shiftBits (1, bit);
  1820. setBit (bit, shouldBeSet);
  1821. }
  1822. bool BigInteger::isZero() const throw()
  1823. {
  1824. return getHighestBit() < 0;
  1825. }
  1826. bool BigInteger::isOne() const throw()
  1827. {
  1828. return getHighestBit() == 0 && ! negative;
  1829. }
  1830. bool BigInteger::isNegative() const throw()
  1831. {
  1832. return negative && ! isZero();
  1833. }
  1834. void BigInteger::setNegative (const bool neg) throw()
  1835. {
  1836. negative = neg;
  1837. }
  1838. void BigInteger::negate() throw()
  1839. {
  1840. negative = (! negative) && ! isZero();
  1841. }
  1842. int BigInteger::countNumberOfSetBits() const throw()
  1843. {
  1844. int total = 0;
  1845. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  1846. {
  1847. unsigned int n = values[i];
  1848. if (n == 0xffffffff)
  1849. {
  1850. total += 32;
  1851. }
  1852. else
  1853. {
  1854. while (n != 0)
  1855. {
  1856. total += (n & 1);
  1857. n >>= 1;
  1858. }
  1859. }
  1860. }
  1861. return total;
  1862. }
  1863. int BigInteger::getHighestBit() const throw()
  1864. {
  1865. for (int i = highestBit + 1; --i >= 0;)
  1866. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1867. return i;
  1868. return -1;
  1869. }
  1870. int BigInteger::findNextSetBit (int i) const throw()
  1871. {
  1872. for (; i <= highestBit; ++i)
  1873. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1874. return i;
  1875. return -1;
  1876. }
  1877. int BigInteger::findNextClearBit (int i) const throw()
  1878. {
  1879. for (; i <= highestBit; ++i)
  1880. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  1881. break;
  1882. return i;
  1883. }
  1884. BigInteger& BigInteger::operator+= (const BigInteger& other)
  1885. {
  1886. if (other.isNegative())
  1887. return operator-= (-other);
  1888. if (isNegative())
  1889. {
  1890. if (compareAbsolute (other) < 0)
  1891. {
  1892. BigInteger temp (*this);
  1893. temp.negate();
  1894. *this = other;
  1895. operator-= (temp);
  1896. }
  1897. else
  1898. {
  1899. negate();
  1900. operator-= (other);
  1901. negate();
  1902. }
  1903. }
  1904. else
  1905. {
  1906. if (other.highestBit > highestBit)
  1907. highestBit = other.highestBit;
  1908. ++highestBit;
  1909. const int numInts = (highestBit >> 5) + 1;
  1910. ensureSize (numInts);
  1911. int64 remainder = 0;
  1912. for (int i = 0; i <= numInts; ++i)
  1913. {
  1914. if (i < numValues)
  1915. remainder += values[i];
  1916. if (i < other.numValues)
  1917. remainder += other.values[i];
  1918. values[i] = (unsigned int) remainder;
  1919. remainder >>= 32;
  1920. }
  1921. jassert (remainder == 0);
  1922. highestBit = getHighestBit();
  1923. }
  1924. return *this;
  1925. }
  1926. BigInteger& BigInteger::operator-= (const BigInteger& other)
  1927. {
  1928. if (other.isNegative())
  1929. return operator+= (-other);
  1930. if (! isNegative())
  1931. {
  1932. if (compareAbsolute (other) < 0)
  1933. {
  1934. BigInteger temp (other);
  1935. swapWith (temp);
  1936. operator-= (temp);
  1937. negate();
  1938. return *this;
  1939. }
  1940. }
  1941. else
  1942. {
  1943. negate();
  1944. operator+= (other);
  1945. negate();
  1946. return *this;
  1947. }
  1948. const int numInts = (highestBit >> 5) + 1;
  1949. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1950. int64 amountToSubtract = 0;
  1951. for (int i = 0; i <= numInts; ++i)
  1952. {
  1953. if (i <= maxOtherInts)
  1954. amountToSubtract += (int64) other.values[i];
  1955. if (values[i] >= amountToSubtract)
  1956. {
  1957. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1958. amountToSubtract = 0;
  1959. }
  1960. else
  1961. {
  1962. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1963. values[i] = (unsigned int) n;
  1964. amountToSubtract = 1;
  1965. }
  1966. }
  1967. return *this;
  1968. }
  1969. BigInteger& BigInteger::operator*= (const BigInteger& other)
  1970. {
  1971. BigInteger total;
  1972. highestBit = getHighestBit();
  1973. const bool wasNegative = isNegative();
  1974. setNegative (false);
  1975. for (int i = 0; i <= highestBit; ++i)
  1976. {
  1977. if (operator[](i))
  1978. {
  1979. BigInteger n (other);
  1980. n.setNegative (false);
  1981. n <<= i;
  1982. total += n;
  1983. }
  1984. }
  1985. total.setNegative (wasNegative ^ other.isNegative());
  1986. swapWith (total);
  1987. return *this;
  1988. }
  1989. void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
  1990. {
  1991. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1992. const int divHB = divisor.getHighestBit();
  1993. const int ourHB = getHighestBit();
  1994. if (divHB < 0 || ourHB < 0)
  1995. {
  1996. // division by zero
  1997. remainder.clear();
  1998. clear();
  1999. }
  2000. else
  2001. {
  2002. const bool wasNegative = isNegative();
  2003. swapWith (remainder);
  2004. remainder.setNegative (false);
  2005. clear();
  2006. BigInteger temp (divisor);
  2007. temp.setNegative (false);
  2008. int leftShift = ourHB - divHB;
  2009. temp <<= leftShift;
  2010. while (leftShift >= 0)
  2011. {
  2012. if (remainder.compareAbsolute (temp) >= 0)
  2013. {
  2014. remainder -= temp;
  2015. setBit (leftShift);
  2016. }
  2017. if (--leftShift >= 0)
  2018. temp >>= 1;
  2019. }
  2020. negative = wasNegative ^ divisor.isNegative();
  2021. remainder.setNegative (wasNegative);
  2022. }
  2023. }
  2024. BigInteger& BigInteger::operator/= (const BigInteger& other)
  2025. {
  2026. BigInteger remainder;
  2027. divideBy (other, remainder);
  2028. return *this;
  2029. }
  2030. BigInteger& BigInteger::operator|= (const BigInteger& other)
  2031. {
  2032. // this operation doesn't take into account negative values..
  2033. jassert (isNegative() == other.isNegative());
  2034. if (other.highestBit >= 0)
  2035. {
  2036. ensureSize (other.highestBit >> 5);
  2037. int n = (other.highestBit >> 5) + 1;
  2038. while (--n >= 0)
  2039. values[n] |= other.values[n];
  2040. if (other.highestBit > highestBit)
  2041. highestBit = other.highestBit;
  2042. highestBit = getHighestBit();
  2043. }
  2044. return *this;
  2045. }
  2046. BigInteger& BigInteger::operator&= (const BigInteger& other)
  2047. {
  2048. // this operation doesn't take into account negative values..
  2049. jassert (isNegative() == other.isNegative());
  2050. int n = numValues;
  2051. while (n > other.numValues)
  2052. values[--n] = 0;
  2053. while (--n >= 0)
  2054. values[n] &= other.values[n];
  2055. if (other.highestBit < highestBit)
  2056. highestBit = other.highestBit;
  2057. highestBit = getHighestBit();
  2058. return *this;
  2059. }
  2060. BigInteger& BigInteger::operator^= (const BigInteger& other)
  2061. {
  2062. // this operation will only work with the absolute values
  2063. jassert (isNegative() == other.isNegative());
  2064. if (other.highestBit >= 0)
  2065. {
  2066. ensureSize (other.highestBit >> 5);
  2067. int n = (other.highestBit >> 5) + 1;
  2068. while (--n >= 0)
  2069. values[n] ^= other.values[n];
  2070. if (other.highestBit > highestBit)
  2071. highestBit = other.highestBit;
  2072. highestBit = getHighestBit();
  2073. }
  2074. return *this;
  2075. }
  2076. BigInteger& BigInteger::operator%= (const BigInteger& divisor)
  2077. {
  2078. BigInteger remainder;
  2079. divideBy (divisor, remainder);
  2080. swapWith (remainder);
  2081. return *this;
  2082. }
  2083. BigInteger& BigInteger::operator<<= (int numBitsToShift)
  2084. {
  2085. shiftBits (numBitsToShift, 0);
  2086. return *this;
  2087. }
  2088. BigInteger& BigInteger::operator>>= (int numBitsToShift)
  2089. {
  2090. return operator<<= (-numBitsToShift);
  2091. }
  2092. BigInteger& BigInteger::operator++() { return operator+= (1); }
  2093. BigInteger& BigInteger::operator--() { return operator-= (1); }
  2094. const BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
  2095. const BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
  2096. const BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
  2097. const BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
  2098. const BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
  2099. const BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
  2100. const BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
  2101. const BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
  2102. const BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
  2103. const BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
  2104. const BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
  2105. const BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
  2106. const BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
  2107. int BigInteger::compare (const BigInteger& other) const throw()
  2108. {
  2109. if (isNegative() == other.isNegative())
  2110. {
  2111. const int absComp = compareAbsolute (other);
  2112. return isNegative() ? -absComp : absComp;
  2113. }
  2114. else
  2115. {
  2116. return isNegative() ? -1 : 1;
  2117. }
  2118. }
  2119. int BigInteger::compareAbsolute (const BigInteger& other) const throw()
  2120. {
  2121. const int h1 = getHighestBit();
  2122. const int h2 = other.getHighestBit();
  2123. if (h1 > h2)
  2124. return 1;
  2125. else if (h1 < h2)
  2126. return -1;
  2127. for (int i = (h1 >> 5) + 1; --i >= 0;)
  2128. if (values[i] != other.values[i])
  2129. return (values[i] > other.values[i]) ? 1 : -1;
  2130. return 0;
  2131. }
  2132. bool BigInteger::operator== (const BigInteger& other) const throw() { return compare (other) == 0; }
  2133. bool BigInteger::operator!= (const BigInteger& other) const throw() { return compare (other) != 0; }
  2134. bool BigInteger::operator< (const BigInteger& other) const throw() { return compare (other) < 0; }
  2135. bool BigInteger::operator<= (const BigInteger& other) const throw() { return compare (other) <= 0; }
  2136. bool BigInteger::operator> (const BigInteger& other) const throw() { return compare (other) > 0; }
  2137. bool BigInteger::operator>= (const BigInteger& other) const throw() { return compare (other) >= 0; }
  2138. void BigInteger::shiftBits (int bits, const int startBit)
  2139. {
  2140. if (highestBit < 0)
  2141. return;
  2142. if (startBit > 0)
  2143. {
  2144. if (bits < 0)
  2145. {
  2146. // right shift
  2147. for (int i = startBit; i <= highestBit; ++i)
  2148. setBit (i, operator[] (i - bits));
  2149. highestBit = getHighestBit();
  2150. }
  2151. else if (bits > 0)
  2152. {
  2153. // left shift
  2154. for (int i = highestBit + 1; --i >= startBit;)
  2155. setBit (i + bits, operator[] (i));
  2156. while (--bits >= 0)
  2157. clearBit (bits + startBit);
  2158. }
  2159. }
  2160. else
  2161. {
  2162. if (bits < 0)
  2163. {
  2164. // right shift
  2165. bits = -bits;
  2166. if (bits > highestBit)
  2167. {
  2168. clear();
  2169. }
  2170. else
  2171. {
  2172. const int wordsToMove = bits >> 5;
  2173. int top = 1 + (highestBit >> 5) - wordsToMove;
  2174. highestBit -= bits;
  2175. if (wordsToMove > 0)
  2176. {
  2177. int i;
  2178. for (i = 0; i < top; ++i)
  2179. values [i] = values [i + wordsToMove];
  2180. for (i = 0; i < wordsToMove; ++i)
  2181. values [top + i] = 0;
  2182. bits &= 31;
  2183. }
  2184. if (bits != 0)
  2185. {
  2186. const int invBits = 32 - bits;
  2187. --top;
  2188. for (int i = 0; i < top; ++i)
  2189. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2190. values[top] = (values[top] >> bits);
  2191. }
  2192. highestBit = getHighestBit();
  2193. }
  2194. }
  2195. else if (bits > 0)
  2196. {
  2197. // left shift
  2198. ensureSize (((highestBit + bits) >> 5) + 1);
  2199. const int wordsToMove = bits >> 5;
  2200. int top = 1 + (highestBit >> 5);
  2201. highestBit += bits;
  2202. if (wordsToMove > 0)
  2203. {
  2204. int i;
  2205. for (i = top; --i >= 0;)
  2206. values [i + wordsToMove] = values [i];
  2207. for (i = 0; i < wordsToMove; ++i)
  2208. values [i] = 0;
  2209. bits &= 31;
  2210. }
  2211. if (bits != 0)
  2212. {
  2213. const int invBits = 32 - bits;
  2214. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2215. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2216. values [wordsToMove] = values [wordsToMove] << bits;
  2217. }
  2218. highestBit = getHighestBit();
  2219. }
  2220. }
  2221. }
  2222. const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
  2223. {
  2224. while (! m->isZero())
  2225. {
  2226. if (n->compareAbsolute (*m) > 0)
  2227. swapVariables (m, n);
  2228. *m -= *n;
  2229. }
  2230. return *n;
  2231. }
  2232. const BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
  2233. {
  2234. BigInteger m (*this);
  2235. while (! n.isZero())
  2236. {
  2237. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2238. return simpleGCD (&m, &n);
  2239. BigInteger temp1 (m), temp2;
  2240. temp1.divideBy (n, temp2);
  2241. m = n;
  2242. n = temp2;
  2243. }
  2244. return m;
  2245. }
  2246. void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
  2247. {
  2248. BigInteger exp (exponent);
  2249. exp %= modulus;
  2250. BigInteger value (1);
  2251. swapWith (value);
  2252. value %= modulus;
  2253. while (! exp.isZero())
  2254. {
  2255. if (exp [0])
  2256. {
  2257. operator*= (value);
  2258. operator%= (modulus);
  2259. }
  2260. value *= value;
  2261. value %= modulus;
  2262. exp >>= 1;
  2263. }
  2264. }
  2265. void BigInteger::inverseModulo (const BigInteger& modulus)
  2266. {
  2267. if (modulus.isOne() || modulus.isNegative())
  2268. {
  2269. clear();
  2270. return;
  2271. }
  2272. if (isNegative() || compareAbsolute (modulus) >= 0)
  2273. operator%= (modulus);
  2274. if (isOne())
  2275. return;
  2276. if (! (*this)[0])
  2277. {
  2278. // not invertible
  2279. clear();
  2280. return;
  2281. }
  2282. BigInteger a1 (modulus);
  2283. BigInteger a2 (*this);
  2284. BigInteger b1 (modulus);
  2285. BigInteger b2 (1);
  2286. while (! a2.isOne())
  2287. {
  2288. BigInteger temp1, temp2, multiplier (a1);
  2289. multiplier.divideBy (a2, temp1);
  2290. temp1 = a2;
  2291. temp1 *= multiplier;
  2292. temp2 = a1;
  2293. temp2 -= temp1;
  2294. a1 = a2;
  2295. a2 = temp2;
  2296. temp1 = b2;
  2297. temp1 *= multiplier;
  2298. temp2 = b1;
  2299. temp2 -= temp1;
  2300. b1 = b2;
  2301. b2 = temp2;
  2302. }
  2303. while (b2.isNegative())
  2304. b2 += modulus;
  2305. b2 %= modulus;
  2306. swapWith (b2);
  2307. }
  2308. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value)
  2309. {
  2310. return stream << value.toString (10);
  2311. }
  2312. const String BigInteger::toString (const int base, const int minimumNumCharacters) const
  2313. {
  2314. String s;
  2315. BigInteger v (*this);
  2316. if (base == 2 || base == 8 || base == 16)
  2317. {
  2318. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2319. static const char* const hexDigits = "0123456789abcdef";
  2320. for (;;)
  2321. {
  2322. const int remainder = v.getBitRangeAsInt (0, bits);
  2323. v >>= bits;
  2324. if (remainder == 0 && v.isZero())
  2325. break;
  2326. s = String::charToString (hexDigits [remainder]) + s;
  2327. }
  2328. }
  2329. else if (base == 10)
  2330. {
  2331. const BigInteger ten (10);
  2332. BigInteger remainder;
  2333. for (;;)
  2334. {
  2335. v.divideBy (ten, remainder);
  2336. if (remainder.isZero() && v.isZero())
  2337. break;
  2338. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2339. }
  2340. }
  2341. else
  2342. {
  2343. jassertfalse // can't do the specified base!
  2344. return String::empty;
  2345. }
  2346. s = s.paddedLeft ('0', minimumNumCharacters);
  2347. return isNegative() ? "-" + s : s;
  2348. }
  2349. void BigInteger::parseString (const String& text, const int base)
  2350. {
  2351. clear();
  2352. const juce_wchar* t = text;
  2353. if (base == 2 || base == 8 || base == 16)
  2354. {
  2355. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2356. for (;;)
  2357. {
  2358. const juce_wchar c = *t++;
  2359. const int digit = CharacterFunctions::getHexDigitValue (c);
  2360. if (((unsigned int) digit) < (unsigned int) base)
  2361. {
  2362. operator<<= (bits);
  2363. operator+= (digit);
  2364. }
  2365. else if (c == 0)
  2366. {
  2367. break;
  2368. }
  2369. }
  2370. }
  2371. else if (base == 10)
  2372. {
  2373. const BigInteger ten ((unsigned int) 10);
  2374. for (;;)
  2375. {
  2376. const juce_wchar c = *t++;
  2377. if (c >= '0' && c <= '9')
  2378. {
  2379. operator*= (ten);
  2380. operator+= ((int) (c - '0'));
  2381. }
  2382. else if (c == 0)
  2383. {
  2384. break;
  2385. }
  2386. }
  2387. }
  2388. setNegative (text.trimStart().startsWithChar ('-'));
  2389. }
  2390. const MemoryBlock BigInteger::toMemoryBlock() const
  2391. {
  2392. const int numBytes = (getHighestBit() + 8) >> 3;
  2393. MemoryBlock mb ((size_t) numBytes);
  2394. for (int i = 0; i < numBytes; ++i)
  2395. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2396. return mb;
  2397. }
  2398. void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
  2399. {
  2400. clear();
  2401. for (int i = (int) data.getSize(); --i >= 0;)
  2402. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2403. }
  2404. END_JUCE_NAMESPACE
  2405. /*** End of inlined file: juce_BitArray.cpp ***/
  2406. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2407. BEGIN_JUCE_NAMESPACE
  2408. MemoryBlock::MemoryBlock() throw()
  2409. : size (0)
  2410. {
  2411. }
  2412. MemoryBlock::MemoryBlock (const size_t initialSize,
  2413. const bool initialiseToZero) throw()
  2414. {
  2415. if (initialSize > 0)
  2416. {
  2417. size = initialSize;
  2418. data.allocate (initialSize, initialiseToZero);
  2419. }
  2420. else
  2421. {
  2422. size = 0;
  2423. }
  2424. }
  2425. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2426. : size (other.size)
  2427. {
  2428. if (size > 0)
  2429. {
  2430. jassert (other.data != 0);
  2431. data.malloc (size);
  2432. memcpy (data, other.data, size);
  2433. }
  2434. }
  2435. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2436. const size_t sizeInBytes) throw()
  2437. : size (jmax ((size_t) 0, sizeInBytes))
  2438. {
  2439. jassert (sizeInBytes >= 0);
  2440. if (size > 0)
  2441. {
  2442. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2443. data.malloc (size);
  2444. if (dataToInitialiseFrom != 0)
  2445. memcpy (data, dataToInitialiseFrom, size);
  2446. }
  2447. }
  2448. MemoryBlock::~MemoryBlock() throw()
  2449. {
  2450. jassert (size >= 0); // should never happen
  2451. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2452. }
  2453. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2454. {
  2455. if (this != &other)
  2456. {
  2457. setSize (other.size, false);
  2458. memcpy (data, other.data, size);
  2459. }
  2460. return *this;
  2461. }
  2462. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2463. {
  2464. return matches (other.data, other.size);
  2465. }
  2466. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2467. {
  2468. return ! operator== (other);
  2469. }
  2470. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2471. {
  2472. return size == dataSize
  2473. && memcmp (data, dataToCompare, size) == 0;
  2474. }
  2475. // this will resize the block to this size
  2476. void MemoryBlock::setSize (const size_t newSize,
  2477. const bool initialiseToZero) throw()
  2478. {
  2479. if (size != newSize)
  2480. {
  2481. if (newSize <= 0)
  2482. {
  2483. data.free();
  2484. size = 0;
  2485. }
  2486. else
  2487. {
  2488. if (data != 0)
  2489. {
  2490. data.realloc (newSize);
  2491. if (initialiseToZero && (newSize > size))
  2492. zeromem (data + size, newSize - size);
  2493. }
  2494. else
  2495. {
  2496. data.allocate (newSize, initialiseToZero);
  2497. }
  2498. size = newSize;
  2499. }
  2500. }
  2501. }
  2502. void MemoryBlock::ensureSize (const size_t minimumSize,
  2503. const bool initialiseToZero) throw()
  2504. {
  2505. if (size < minimumSize)
  2506. setSize (minimumSize, initialiseToZero);
  2507. }
  2508. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2509. {
  2510. swapVariables (size, other.size);
  2511. data.swapWith (other.data);
  2512. }
  2513. void MemoryBlock::fillWith (const uint8 value) throw()
  2514. {
  2515. memset (data, (int) value, size);
  2516. }
  2517. void MemoryBlock::append (const void* const srcData,
  2518. const size_t numBytes) throw()
  2519. {
  2520. if (numBytes > 0)
  2521. {
  2522. const size_t oldSize = size;
  2523. setSize (size + numBytes);
  2524. memcpy (data + oldSize, srcData, numBytes);
  2525. }
  2526. }
  2527. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2528. {
  2529. const char* d = static_cast<const char*> (src);
  2530. if (offset < 0)
  2531. {
  2532. d -= offset;
  2533. num -= offset;
  2534. offset = 0;
  2535. }
  2536. if (offset + num > size)
  2537. num = size - offset;
  2538. if (num > 0)
  2539. memcpy (data + offset, d, num);
  2540. }
  2541. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2542. {
  2543. char* d = static_cast<char*> (dst);
  2544. if (offset < 0)
  2545. {
  2546. zeromem (d, -offset);
  2547. d -= offset;
  2548. num += offset;
  2549. offset = 0;
  2550. }
  2551. if (offset + num > size)
  2552. {
  2553. const size_t newNum = size - offset;
  2554. zeromem (d + newNum, num - newNum);
  2555. num = newNum;
  2556. }
  2557. if (num > 0)
  2558. memcpy (d, data + offset, num);
  2559. }
  2560. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2561. {
  2562. if (startByte < 0)
  2563. {
  2564. numBytesToRemove += startByte;
  2565. startByte = 0;
  2566. }
  2567. if (startByte + numBytesToRemove >= size)
  2568. {
  2569. setSize (startByte);
  2570. }
  2571. else if (numBytesToRemove > 0)
  2572. {
  2573. memmove (data + startByte,
  2574. data + startByte + numBytesToRemove,
  2575. size - (startByte + numBytesToRemove));
  2576. setSize (size - numBytesToRemove);
  2577. }
  2578. }
  2579. const String MemoryBlock::toString() const throw()
  2580. {
  2581. return String (static_cast <const char*> (getData()), size);
  2582. }
  2583. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2584. {
  2585. int res = 0;
  2586. size_t byte = bitRangeStart >> 3;
  2587. int offsetInByte = (int) bitRangeStart & 7;
  2588. size_t bitsSoFar = 0;
  2589. while (numBits > 0 && (size_t) byte < size)
  2590. {
  2591. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2592. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2593. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2594. bitsSoFar += bitsThisTime;
  2595. numBits -= bitsThisTime;
  2596. ++byte;
  2597. offsetInByte = 0;
  2598. }
  2599. return res;
  2600. }
  2601. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2602. {
  2603. size_t byte = bitRangeStart >> 3;
  2604. int offsetInByte = (int) bitRangeStart & 7;
  2605. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2606. while (numBits > 0 && (size_t) byte < size)
  2607. {
  2608. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2609. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2610. const unsigned int tempBits = bitsToSet << offsetInByte;
  2611. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2612. ++byte;
  2613. numBits -= bitsThisTime;
  2614. bitsToSet >>= bitsThisTime;
  2615. mask >>= bitsThisTime;
  2616. offsetInByte = 0;
  2617. }
  2618. }
  2619. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2620. {
  2621. ensureSize (hex.length() >> 1);
  2622. char* dest = data;
  2623. int i = 0;
  2624. for (;;)
  2625. {
  2626. int byte = 0;
  2627. for (int loop = 2; --loop >= 0;)
  2628. {
  2629. byte <<= 4;
  2630. for (;;)
  2631. {
  2632. const juce_wchar c = hex [i++];
  2633. if (c >= '0' && c <= '9')
  2634. {
  2635. byte |= c - '0';
  2636. break;
  2637. }
  2638. else if (c >= 'a' && c <= 'z')
  2639. {
  2640. byte |= c - ('a' - 10);
  2641. break;
  2642. }
  2643. else if (c >= 'A' && c <= 'Z')
  2644. {
  2645. byte |= c - ('A' - 10);
  2646. break;
  2647. }
  2648. else if (c == 0)
  2649. {
  2650. setSize (static_cast <size_t> (dest - data));
  2651. return;
  2652. }
  2653. }
  2654. }
  2655. *dest++ = (char) byte;
  2656. }
  2657. }
  2658. static const char* const encodingTable
  2659. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2660. const String MemoryBlock::toBase64Encoding() const throw()
  2661. {
  2662. const size_t numChars = ((size << 3) + 5) / 6;
  2663. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2664. const int initialLen = destString.length();
  2665. destString.preallocateStorage (initialLen + 2 + numChars);
  2666. juce_wchar* d = destString;
  2667. d += initialLen;
  2668. *d++ = '.';
  2669. for (size_t i = 0; i < numChars; ++i)
  2670. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2671. *d++ = 0;
  2672. return destString;
  2673. }
  2674. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2675. {
  2676. const int startPos = s.indexOfChar ('.') + 1;
  2677. if (startPos <= 0)
  2678. return false;
  2679. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2680. setSize (numBytesNeeded, true);
  2681. const int numChars = s.length() - startPos;
  2682. const juce_wchar* srcChars = s;
  2683. srcChars += startPos;
  2684. int pos = 0;
  2685. for (int i = 0; i < numChars; ++i)
  2686. {
  2687. const char c = (char) srcChars[i];
  2688. for (int j = 0; j < 64; ++j)
  2689. {
  2690. if (encodingTable[j] == c)
  2691. {
  2692. setBitRange (pos, 6, j);
  2693. pos += 6;
  2694. break;
  2695. }
  2696. }
  2697. }
  2698. return true;
  2699. }
  2700. END_JUCE_NAMESPACE
  2701. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2702. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2703. BEGIN_JUCE_NAMESPACE
  2704. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2705. : properties (ignoreCaseOfKeyNames),
  2706. fallbackProperties (0),
  2707. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2708. {
  2709. }
  2710. PropertySet::PropertySet (const PropertySet& other) throw()
  2711. : properties (other.properties),
  2712. fallbackProperties (other.fallbackProperties),
  2713. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2714. {
  2715. }
  2716. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2717. {
  2718. properties = other.properties;
  2719. fallbackProperties = other.fallbackProperties;
  2720. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2721. propertyChanged();
  2722. return *this;
  2723. }
  2724. PropertySet::~PropertySet()
  2725. {
  2726. }
  2727. void PropertySet::clear()
  2728. {
  2729. const ScopedLock sl (lock);
  2730. if (properties.size() > 0)
  2731. {
  2732. properties.clear();
  2733. propertyChanged();
  2734. }
  2735. }
  2736. const String PropertySet::getValue (const String& keyName,
  2737. const String& defaultValue) const throw()
  2738. {
  2739. const ScopedLock sl (lock);
  2740. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2741. if (index >= 0)
  2742. return properties.getAllValues() [index];
  2743. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2744. : defaultValue;
  2745. }
  2746. int PropertySet::getIntValue (const String& keyName,
  2747. const int defaultValue) const throw()
  2748. {
  2749. const ScopedLock sl (lock);
  2750. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2751. if (index >= 0)
  2752. return properties.getAllValues() [index].getIntValue();
  2753. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2754. : defaultValue;
  2755. }
  2756. double PropertySet::getDoubleValue (const String& keyName,
  2757. const double defaultValue) const throw()
  2758. {
  2759. const ScopedLock sl (lock);
  2760. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2761. if (index >= 0)
  2762. return properties.getAllValues()[index].getDoubleValue();
  2763. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2764. : defaultValue;
  2765. }
  2766. bool PropertySet::getBoolValue (const String& keyName,
  2767. const bool defaultValue) const throw()
  2768. {
  2769. const ScopedLock sl (lock);
  2770. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2771. if (index >= 0)
  2772. return properties.getAllValues() [index].getIntValue() != 0;
  2773. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2774. : defaultValue;
  2775. }
  2776. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2777. {
  2778. XmlDocument doc (getValue (keyName));
  2779. return doc.getDocumentElement();
  2780. }
  2781. void PropertySet::setValue (const String& keyName,
  2782. const String& value) throw()
  2783. {
  2784. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2785. if (keyName.isNotEmpty())
  2786. {
  2787. const ScopedLock sl (lock);
  2788. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2789. if (index < 0 || properties.getAllValues() [index] != value)
  2790. {
  2791. properties.set (keyName, value);
  2792. propertyChanged();
  2793. }
  2794. }
  2795. }
  2796. void PropertySet::removeValue (const String& keyName) throw()
  2797. {
  2798. if (keyName.isNotEmpty())
  2799. {
  2800. const ScopedLock sl (lock);
  2801. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2802. if (index >= 0)
  2803. {
  2804. properties.remove (keyName);
  2805. propertyChanged();
  2806. }
  2807. }
  2808. }
  2809. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2810. {
  2811. setValue (keyName, String (value));
  2812. }
  2813. void PropertySet::setValue (const String& keyName, const int value) throw()
  2814. {
  2815. setValue (keyName, String (value));
  2816. }
  2817. void PropertySet::setValue (const String& keyName, const double value) throw()
  2818. {
  2819. setValue (keyName, String (value));
  2820. }
  2821. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2822. {
  2823. setValue (keyName, String (value ? "1" : "0"));
  2824. }
  2825. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2826. {
  2827. setValue (keyName, (xml == 0) ? String::empty
  2828. : xml->createDocument (String::empty, true));
  2829. }
  2830. bool PropertySet::containsKey (const String& keyName) const throw()
  2831. {
  2832. const ScopedLock sl (lock);
  2833. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2834. }
  2835. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2836. {
  2837. const ScopedLock sl (lock);
  2838. fallbackProperties = fallbackProperties_;
  2839. }
  2840. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2841. {
  2842. const ScopedLock sl (lock);
  2843. XmlElement* const xml = new XmlElement (nodeName);
  2844. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2845. {
  2846. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2847. e->setAttribute ("name", properties.getAllKeys()[i]);
  2848. e->setAttribute ("val", properties.getAllValues()[i]);
  2849. }
  2850. return xml;
  2851. }
  2852. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2853. {
  2854. const ScopedLock sl (lock);
  2855. clear();
  2856. forEachXmlChildElementWithTagName (xml, e, "VALUE")
  2857. {
  2858. if (e->hasAttribute ("name")
  2859. && e->hasAttribute ("val"))
  2860. {
  2861. properties.set (e->getStringAttribute ("name"),
  2862. e->getStringAttribute ("val"));
  2863. }
  2864. }
  2865. if (properties.size() > 0)
  2866. propertyChanged();
  2867. }
  2868. void PropertySet::propertyChanged()
  2869. {
  2870. }
  2871. END_JUCE_NAMESPACE
  2872. /*** End of inlined file: juce_PropertySet.cpp ***/
  2873. /*** Start of inlined file: juce_Variant.cpp ***/
  2874. BEGIN_JUCE_NAMESPACE
  2875. var::var() throw()
  2876. : type (voidType)
  2877. {
  2878. value.doubleValue = 0;
  2879. }
  2880. var::~var() throw()
  2881. {
  2882. if (type == stringType)
  2883. delete value.stringValue;
  2884. else if (type == objectType && value.objectValue != 0)
  2885. value.objectValue->decReferenceCount();
  2886. }
  2887. const var var::null;
  2888. var::var (const var& valueToCopy)
  2889. : type (valueToCopy.type),
  2890. value (valueToCopy.value)
  2891. {
  2892. if (type == stringType)
  2893. value.stringValue = new String (*(value.stringValue));
  2894. else if (type == objectType && value.objectValue != 0)
  2895. value.objectValue->incReferenceCount();
  2896. }
  2897. var::var (const int value_) throw()
  2898. : type (intType)
  2899. {
  2900. value.intValue = value_;
  2901. }
  2902. var::var (const bool value_) throw()
  2903. : type (boolType)
  2904. {
  2905. value.boolValue = value_;
  2906. }
  2907. var::var (const double value_) throw()
  2908. : type (doubleType)
  2909. {
  2910. value.doubleValue = value_;
  2911. }
  2912. var::var (const String& value_)
  2913. : type (stringType)
  2914. {
  2915. value.stringValue = new String (value_);
  2916. }
  2917. var::var (const char* const value_)
  2918. : type (stringType)
  2919. {
  2920. value.stringValue = new String (value_);
  2921. }
  2922. var::var (const juce_wchar* const value_)
  2923. : type (stringType)
  2924. {
  2925. value.stringValue = new String (value_);
  2926. }
  2927. var::var (DynamicObject* const object)
  2928. : type (objectType)
  2929. {
  2930. value.objectValue = object;
  2931. if (object != 0)
  2932. object->incReferenceCount();
  2933. }
  2934. var::var (MethodFunction method_) throw()
  2935. : type (methodType)
  2936. {
  2937. value.methodValue = method_;
  2938. }
  2939. void var::swapWith (var& other) throw()
  2940. {
  2941. swapVariables (type, other.type);
  2942. swapVariables (value, other.value);
  2943. }
  2944. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2945. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2946. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2947. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2948. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2949. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2950. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2951. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2952. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2953. var::operator int() const
  2954. {
  2955. switch (type)
  2956. {
  2957. case voidType: break;
  2958. case intType: return value.intValue;
  2959. case boolType: return value.boolValue ? 1 : 0;
  2960. case doubleType: return static_cast <int> (value.doubleValue);
  2961. case stringType: return value.stringValue->getIntValue();
  2962. case objectType: break;
  2963. default: jassertfalse; break;
  2964. }
  2965. return 0;
  2966. }
  2967. var::operator bool() const
  2968. {
  2969. switch (type)
  2970. {
  2971. case voidType: break;
  2972. case intType: return value.intValue != 0;
  2973. case boolType: return value.boolValue;
  2974. case doubleType: return value.doubleValue != 0;
  2975. case stringType: return value.stringValue->getIntValue() != 0
  2976. || value.stringValue->trim().equalsIgnoreCase ("true")
  2977. || value.stringValue->trim().equalsIgnoreCase ("yes");
  2978. case objectType: return value.objectValue != 0;
  2979. default: jassertfalse; break;
  2980. }
  2981. return false;
  2982. }
  2983. var::operator float() const
  2984. {
  2985. return (float) operator double();
  2986. }
  2987. var::operator double() const
  2988. {
  2989. switch (type)
  2990. {
  2991. case voidType: break;
  2992. case intType: return value.intValue;
  2993. case boolType: return value.boolValue ? 1.0 : 0.0;
  2994. case doubleType: return value.doubleValue;
  2995. case stringType: return value.stringValue->getDoubleValue();
  2996. case objectType: break;
  2997. default: jassertfalse; break;
  2998. }
  2999. return 0.0;
  3000. }
  3001. const String var::toString() const
  3002. {
  3003. switch (type)
  3004. {
  3005. case voidType: return String::empty;
  3006. case intType: return String (value.intValue);
  3007. case boolType: return String::charToString (value.boolValue ? '1' : '0');
  3008. case doubleType: return String (value.doubleValue);
  3009. case stringType: return *(value.stringValue);
  3010. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  3011. case methodType: return "Method";
  3012. default: jassertfalse; break;
  3013. }
  3014. return String::empty;
  3015. }
  3016. var::operator const String() const
  3017. {
  3018. return toString();
  3019. }
  3020. DynamicObject* var::getObject() const
  3021. {
  3022. return type == objectType ? value.objectValue : 0;
  3023. }
  3024. bool var::equals (const var& other) const throw()
  3025. {
  3026. switch (type)
  3027. {
  3028. case voidType: return other.isVoid();
  3029. case intType: return value.intValue == static_cast <int> (other);
  3030. case boolType: return value.boolValue == static_cast <bool> (other);
  3031. case doubleType: return value.doubleValue == static_cast <double> (other);
  3032. case stringType: return (*(value.stringValue)) == other.toString();
  3033. case objectType: return value.objectValue == other.getObject();
  3034. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  3035. default: jassertfalse; break;
  3036. }
  3037. return false;
  3038. }
  3039. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  3040. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  3041. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  3042. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3043. void var::writeToStream (OutputStream& output) const
  3044. {
  3045. switch (type)
  3046. {
  3047. case voidType: output.writeCompressedInt (0); break;
  3048. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3049. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3050. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3051. case stringType:
  3052. {
  3053. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3054. output.writeCompressedInt (len + 1);
  3055. output.writeByte (5);
  3056. HeapBlock<char> temp (len);
  3057. value.stringValue->copyToUTF8 (temp, len);
  3058. output.write (temp, len);
  3059. break;
  3060. }
  3061. case objectType:
  3062. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3063. default: jassertfalse; break; // Is this a corrupted object?
  3064. }
  3065. }
  3066. const var var::readFromStream (InputStream& input)
  3067. {
  3068. const int numBytes = input.readCompressedInt();
  3069. if (numBytes > 0)
  3070. {
  3071. switch (input.readByte())
  3072. {
  3073. case 1: return var (input.readInt());
  3074. case 2: return var (true);
  3075. case 3: return var (false);
  3076. case 4: return var (input.readDouble());
  3077. case 5:
  3078. {
  3079. MemoryBlock mb;
  3080. input.readIntoMemoryBlock (mb, numBytes - 1);
  3081. return var (String::fromUTF8 (static_cast <const char*> (mb.getData()), (int) mb.getSize()));
  3082. }
  3083. default: input.skipNextBytes (numBytes - 1); break;
  3084. }
  3085. }
  3086. return var::null;
  3087. }
  3088. const var var::operator[] (const var::identifier& propertyName) const
  3089. {
  3090. if (type == objectType && value.objectValue != 0)
  3091. return value.objectValue->getProperty (propertyName);
  3092. return var::null;
  3093. }
  3094. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3095. {
  3096. if (type == objectType && value.objectValue != 0)
  3097. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3098. return var::null;
  3099. }
  3100. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3101. {
  3102. if (isMethod())
  3103. {
  3104. DynamicObject* const target = targetObject.getObject();
  3105. if (target != 0)
  3106. return (target->*(value.methodValue)) (arguments, numArguments);
  3107. }
  3108. return var::null;
  3109. }
  3110. const var var::call (const var::identifier& method) const
  3111. {
  3112. return invoke (method, 0, 0);
  3113. }
  3114. const var var::call (const var::identifier& method, const var& arg1) const
  3115. {
  3116. return invoke (method, &arg1, 1);
  3117. }
  3118. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3119. {
  3120. var args[] = { arg1, arg2 };
  3121. return invoke (method, args, 2);
  3122. }
  3123. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3124. {
  3125. var args[] = { arg1, arg2, arg3 };
  3126. return invoke (method, args, 3);
  3127. }
  3128. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3129. {
  3130. var args[] = { arg1, arg2, arg3, arg4 };
  3131. return invoke (method, args, 4);
  3132. }
  3133. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3134. {
  3135. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3136. return invoke (method, args, 5);
  3137. }
  3138. var::identifier::identifier() throw()
  3139. : hashCode (0)
  3140. {
  3141. }
  3142. var::identifier::identifier (const String& name_)
  3143. : name (name_),
  3144. hashCode (name_.hashCode())
  3145. {
  3146. /* An identifier string must be suitable for use as a script variable or XML
  3147. attribute, so it can only contain this limited set of characters.. */
  3148. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3149. }
  3150. var::identifier::identifier (const char* const name_)
  3151. : name (name_),
  3152. hashCode (name.hashCode())
  3153. {
  3154. /* An identifier string must be suitable for use as a script variable or XML
  3155. attribute, so it can only contain this limited set of characters.. */
  3156. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3157. }
  3158. var::identifier::~identifier()
  3159. {
  3160. }
  3161. END_JUCE_NAMESPACE
  3162. /*** End of inlined file: juce_Variant.cpp ***/
  3163. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3164. BEGIN_JUCE_NAMESPACE
  3165. NamedValueSet::NamedValue::NamedValue() throw()
  3166. {
  3167. }
  3168. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3169. : name (name_), value (value_)
  3170. {
  3171. }
  3172. NamedValueSet::NamedValueSet() throw()
  3173. {
  3174. }
  3175. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3176. : values (other.values)
  3177. {
  3178. }
  3179. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3180. {
  3181. values = other.values;
  3182. return *this;
  3183. }
  3184. NamedValueSet::~NamedValueSet()
  3185. {
  3186. }
  3187. int NamedValueSet::size() const throw()
  3188. {
  3189. return values.size();
  3190. }
  3191. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3192. {
  3193. for (int i = values.size(); --i >= 0;)
  3194. {
  3195. const NamedValue& v = values.getReference(i);
  3196. if (v.name == name)
  3197. return v.value;
  3198. }
  3199. return var::null;
  3200. }
  3201. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3202. {
  3203. const var* v = getItem (name);
  3204. return v != 0 ? *v : defaultReturnValue;
  3205. }
  3206. var* NamedValueSet::getItem (const var::identifier& name) const
  3207. {
  3208. for (int i = values.size(); --i >= 0;)
  3209. {
  3210. NamedValue& v = values.getReference(i);
  3211. if (v.name == name)
  3212. return &(v.value);
  3213. }
  3214. return 0;
  3215. }
  3216. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3217. {
  3218. for (int i = values.size(); --i >= 0;)
  3219. {
  3220. NamedValue& v = values.getReference(i);
  3221. if (v.name == name)
  3222. {
  3223. if (v.value == newValue)
  3224. return false;
  3225. v.value = newValue;
  3226. return true;
  3227. }
  3228. }
  3229. values.add (NamedValue (name, newValue));
  3230. return true;
  3231. }
  3232. bool NamedValueSet::contains (const var::identifier& name) const
  3233. {
  3234. return getItem (name) != 0;
  3235. }
  3236. bool NamedValueSet::remove (const var::identifier& name)
  3237. {
  3238. for (int i = values.size(); --i >= 0;)
  3239. {
  3240. if (values.getReference(i).name == name)
  3241. {
  3242. values.remove (i);
  3243. return true;
  3244. }
  3245. }
  3246. return false;
  3247. }
  3248. const var::identifier NamedValueSet::getName (int index) const
  3249. {
  3250. jassert (((unsigned int) index) < (unsigned int) values.size());
  3251. return values [index].name;
  3252. }
  3253. void NamedValueSet::clear()
  3254. {
  3255. values.clear();
  3256. }
  3257. END_JUCE_NAMESPACE
  3258. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3259. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3260. BEGIN_JUCE_NAMESPACE
  3261. DynamicObject::DynamicObject()
  3262. {
  3263. }
  3264. DynamicObject::~DynamicObject()
  3265. {
  3266. }
  3267. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3268. {
  3269. var* const v = properties.getItem (propertyName);
  3270. return v != 0 && ! v->isMethod();
  3271. }
  3272. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3273. {
  3274. return properties [propertyName];
  3275. }
  3276. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3277. {
  3278. properties.set (propertyName, newValue);
  3279. }
  3280. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3281. {
  3282. properties.remove (propertyName);
  3283. }
  3284. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3285. {
  3286. return getProperty (methodName).isMethod();
  3287. }
  3288. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3289. const var* parameters,
  3290. int numParameters)
  3291. {
  3292. return properties [methodName].invoke (var (this), parameters, numParameters);
  3293. }
  3294. void DynamicObject::setMethod (const var::identifier& name,
  3295. var::MethodFunction methodFunction)
  3296. {
  3297. properties.set (name, var (methodFunction));
  3298. }
  3299. void DynamicObject::clear()
  3300. {
  3301. properties.clear();
  3302. }
  3303. END_JUCE_NAMESPACE
  3304. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3305. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3306. BEGIN_JUCE_NAMESPACE
  3307. BlowFish::BlowFish (const void* const keyData, const int keyBytes)
  3308. {
  3309. jassert (keyData != 0);
  3310. jassert (keyBytes > 0);
  3311. static const uint32 initialPValues [18] =
  3312. {
  3313. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3314. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3315. 0x9216d5d9, 0x8979fb1b
  3316. };
  3317. static const uint32 initialSValues [4 * 256] =
  3318. {
  3319. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3320. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3321. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3322. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3323. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3324. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3325. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3326. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3327. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3328. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3329. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3330. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3331. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3332. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3333. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3334. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3335. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3336. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3337. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3338. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3339. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3340. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3341. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3342. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3343. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3344. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3345. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3346. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3347. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3348. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3349. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3350. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3351. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3352. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3353. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3354. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3355. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3356. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3357. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3358. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3359. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3360. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3361. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3362. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3363. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3364. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3365. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3366. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3367. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3368. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3369. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3370. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3371. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3372. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3373. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3374. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3375. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3376. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3377. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3378. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3379. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3380. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3381. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3382. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3383. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3384. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3385. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3386. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3387. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3388. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3389. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3390. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3391. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3392. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3393. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3394. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3395. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3396. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3397. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3398. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3399. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3400. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3401. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3402. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3403. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3404. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3405. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3406. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3407. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3408. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3409. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3410. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3411. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3412. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3413. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3414. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3415. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3416. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3417. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3418. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3419. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3420. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3421. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3422. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3423. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3424. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3425. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3426. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3427. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3428. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3429. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3430. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3431. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3432. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3433. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3434. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3435. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3436. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3437. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3438. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3439. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3440. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3441. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3442. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3443. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3444. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3445. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3446. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3447. };
  3448. memcpy (p, initialPValues, sizeof (p));
  3449. int i, j = 0;
  3450. for (i = 4; --i >= 0;)
  3451. {
  3452. s[i].malloc (256);
  3453. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3454. }
  3455. for (i = 0; i < 18; ++i)
  3456. {
  3457. uint32 d = 0;
  3458. for (int k = 0; k < 4; ++k)
  3459. {
  3460. d = (d << 8) | static_cast <const uint8*> (keyData)[j];
  3461. if (++j >= keyBytes)
  3462. j = 0;
  3463. }
  3464. p[i] = initialPValues[i] ^ d;
  3465. }
  3466. uint32 l = 0, r = 0;
  3467. for (i = 0; i < 18; i += 2)
  3468. {
  3469. encrypt (l, r);
  3470. p[i] = l;
  3471. p[i + 1] = r;
  3472. }
  3473. for (i = 0; i < 4; ++i)
  3474. {
  3475. for (j = 0; j < 256; j += 2)
  3476. {
  3477. encrypt (l, r);
  3478. s[i][j] = l;
  3479. s[i][j + 1] = r;
  3480. }
  3481. }
  3482. }
  3483. BlowFish::BlowFish (const BlowFish& other)
  3484. {
  3485. for (int i = 4; --i >= 0;)
  3486. s[i].malloc (256);
  3487. operator= (other);
  3488. }
  3489. BlowFish& BlowFish::operator= (const BlowFish& other)
  3490. {
  3491. memcpy (p, other.p, sizeof (p));
  3492. for (int i = 4; --i >= 0;)
  3493. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3494. return *this;
  3495. }
  3496. BlowFish::~BlowFish()
  3497. {
  3498. }
  3499. uint32 BlowFish::F (const uint32 x) const throw()
  3500. {
  3501. return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff])
  3502. ^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff];
  3503. }
  3504. void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
  3505. {
  3506. uint32 l = data1;
  3507. uint32 r = data2;
  3508. for (int i = 0; i < 16; ++i)
  3509. {
  3510. l ^= p[i];
  3511. r ^= F(l);
  3512. swapVariables (l, r);
  3513. }
  3514. data1 = r ^ p[17];
  3515. data2 = l ^ p[16];
  3516. }
  3517. void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
  3518. {
  3519. uint32 l = data1;
  3520. uint32 r = data2;
  3521. for (int i = 17; i > 1; --i)
  3522. {
  3523. l ^= p[i];
  3524. r ^= F(l);
  3525. swapVariables (l, r);
  3526. }
  3527. data1 = r ^ p[0];
  3528. data2 = l ^ p[1];
  3529. }
  3530. END_JUCE_NAMESPACE
  3531. /*** End of inlined file: juce_BlowFish.cpp ***/
  3532. /*** Start of inlined file: juce_MD5.cpp ***/
  3533. BEGIN_JUCE_NAMESPACE
  3534. MD5::MD5()
  3535. {
  3536. zerostruct (result);
  3537. }
  3538. MD5::MD5 (const MD5& other)
  3539. {
  3540. memcpy (result, other.result, sizeof (result));
  3541. }
  3542. MD5& MD5::operator= (const MD5& other)
  3543. {
  3544. memcpy (result, other.result, sizeof (result));
  3545. return *this;
  3546. }
  3547. MD5::MD5 (const MemoryBlock& data)
  3548. {
  3549. ProcessContext context;
  3550. context.processBlock (data.getData(), data.getSize());
  3551. context.finish (result);
  3552. }
  3553. MD5::MD5 (const void* data, const size_t numBytes)
  3554. {
  3555. ProcessContext context;
  3556. context.processBlock (data, numBytes);
  3557. context.finish (result);
  3558. }
  3559. MD5::MD5 (const String& text)
  3560. {
  3561. ProcessContext context;
  3562. const int len = text.length();
  3563. const juce_wchar* const t = text;
  3564. for (int i = 0; i < len; ++i)
  3565. {
  3566. // force the string into integer-sized unicode characters, to try to make it
  3567. // get the same results on all platforms + compilers.
  3568. uint32 unicodeChar = ByteOrder::swapIfBigEndian ((uint32) t[i]);
  3569. context.processBlock (&unicodeChar, sizeof (unicodeChar));
  3570. }
  3571. context.finish (result);
  3572. }
  3573. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3574. {
  3575. ProcessContext context;
  3576. if (numBytesToRead < 0)
  3577. numBytesToRead = std::numeric_limits<int64>::max();
  3578. while (numBytesToRead > 0)
  3579. {
  3580. uint8 tempBuffer [512];
  3581. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3582. if (bytesRead <= 0)
  3583. break;
  3584. numBytesToRead -= bytesRead;
  3585. context.processBlock (tempBuffer, bytesRead);
  3586. }
  3587. context.finish (result);
  3588. }
  3589. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3590. {
  3591. processStream (input, numBytesToRead);
  3592. }
  3593. MD5::MD5 (const File& file)
  3594. {
  3595. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3596. if (fin != 0)
  3597. processStream (*fin, -1);
  3598. else
  3599. zerostruct (result);
  3600. }
  3601. MD5::~MD5()
  3602. {
  3603. }
  3604. namespace MD5Functions
  3605. {
  3606. static void encode (void* const output, const void* const input, const int numBytes) throw()
  3607. {
  3608. for (int i = 0; i < (numBytes >> 2); ++i)
  3609. static_cast<uint32*> (output)[i] = ByteOrder::swapIfBigEndian (static_cast<const uint32*> (input) [i]);
  3610. }
  3611. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3612. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3613. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3614. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3615. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3616. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3617. {
  3618. a += F (b, c, d) + x + ac;
  3619. a = rotateLeft (a, s) + b;
  3620. }
  3621. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3622. {
  3623. a += G (b, c, d) + x + ac;
  3624. a = rotateLeft (a, s) + b;
  3625. }
  3626. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3627. {
  3628. a += H (b, c, d) + x + ac;
  3629. a = rotateLeft (a, s) + b;
  3630. }
  3631. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3632. {
  3633. a += I (b, c, d) + x + ac;
  3634. a = rotateLeft (a, s) + b;
  3635. }
  3636. }
  3637. MD5::ProcessContext::ProcessContext()
  3638. {
  3639. state[0] = 0x67452301;
  3640. state[1] = 0xefcdab89;
  3641. state[2] = 0x98badcfe;
  3642. state[3] = 0x10325476;
  3643. count[0] = 0;
  3644. count[1] = 0;
  3645. }
  3646. void MD5::ProcessContext::processBlock (const void* const data, const size_t dataSize)
  3647. {
  3648. int bufferPos = ((count[0] >> 3) & 0x3F);
  3649. count[0] += (uint32) (dataSize << 3);
  3650. if (count[0] < ((uint32) dataSize << 3))
  3651. count[1]++;
  3652. count[1] += (uint32) (dataSize >> 29);
  3653. const size_t spaceLeft = 64 - bufferPos;
  3654. size_t i = 0;
  3655. if (dataSize >= spaceLeft)
  3656. {
  3657. memcpy (buffer + bufferPos, data, spaceLeft);
  3658. transform (buffer);
  3659. for (i = spaceLeft; i + 64 <= dataSize; i += 64)
  3660. transform (static_cast <const char*> (data) + i);
  3661. bufferPos = 0;
  3662. }
  3663. memcpy (buffer + bufferPos, static_cast <const char*> (data) + i, dataSize - i);
  3664. }
  3665. void MD5::ProcessContext::finish (void* const result)
  3666. {
  3667. unsigned char encodedLength[8];
  3668. MD5Functions::encode (encodedLength, count, 8);
  3669. // Pad out to 56 mod 64.
  3670. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3671. const int paddingLength = (index < 56) ? (56 - index)
  3672. : (120 - index);
  3673. uint8 paddingBuffer [64];
  3674. zeromem (paddingBuffer, paddingLength);
  3675. paddingBuffer [0] = 0x80;
  3676. processBlock (paddingBuffer, paddingLength);
  3677. processBlock (encodedLength, 8);
  3678. MD5Functions::encode (result, state, 16);
  3679. zerostruct (buffer);
  3680. }
  3681. void MD5::ProcessContext::transform (const void* const bufferToTransform)
  3682. {
  3683. using namespace MD5Functions;
  3684. uint32 a = state[0];
  3685. uint32 b = state[1];
  3686. uint32 c = state[2];
  3687. uint32 d = state[3];
  3688. uint32 x[16];
  3689. encode (x, bufferToTransform, 64);
  3690. enum Constants
  3691. {
  3692. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3693. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3694. };
  3695. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); FF (d, a, b, c, x[ 1], S12, 0xe8c7b756);
  3696. FF (c, d, a, b, x[ 2], S13, 0x242070db); FF (b, c, d, a, x[ 3], S14, 0xc1bdceee);
  3697. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); FF (d, a, b, c, x[ 5], S12, 0x4787c62a);
  3698. FF (c, d, a, b, x[ 6], S13, 0xa8304613); FF (b, c, d, a, x[ 7], S14, 0xfd469501);
  3699. FF (a, b, c, d, x[ 8], S11, 0x698098d8); FF (d, a, b, c, x[ 9], S12, 0x8b44f7af);
  3700. FF (c, d, a, b, x[10], S13, 0xffff5bb1); FF (b, c, d, a, x[11], S14, 0x895cd7be);
  3701. FF (a, b, c, d, x[12], S11, 0x6b901122); FF (d, a, b, c, x[13], S12, 0xfd987193);
  3702. FF (c, d, a, b, x[14], S13, 0xa679438e); FF (b, c, d, a, x[15], S14, 0x49b40821);
  3703. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); GG (d, a, b, c, x[ 6], S22, 0xc040b340);
  3704. GG (c, d, a, b, x[11], S23, 0x265e5a51); GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa);
  3705. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); GG (d, a, b, c, x[10], S22, 0x02441453);
  3706. GG (c, d, a, b, x[15], S23, 0xd8a1e681); GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8);
  3707. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); GG (d, a, b, c, x[14], S22, 0xc33707d6);
  3708. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); GG (b, c, d, a, x[ 8], S24, 0x455a14ed);
  3709. GG (a, b, c, d, x[13], S21, 0xa9e3e905); GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8);
  3710. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); GG (b, c, d, a, x[12], S24, 0x8d2a4c8a);
  3711. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); HH (d, a, b, c, x[ 8], S32, 0x8771f681);
  3712. HH (c, d, a, b, x[11], S33, 0x6d9d6122); HH (b, c, d, a, x[14], S34, 0xfde5380c);
  3713. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9);
  3714. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); HH (b, c, d, a, x[10], S34, 0xbebfbc70);
  3715. HH (a, b, c, d, x[13], S31, 0x289b7ec6); HH (d, a, b, c, x[ 0], S32, 0xeaa127fa);
  3716. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); HH (b, c, d, a, x[ 6], S34, 0x04881d05);
  3717. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); HH (d, a, b, c, x[12], S32, 0xe6db99e5);
  3718. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); HH (b, c, d, a, x[ 2], S34, 0xc4ac5665);
  3719. II (a, b, c, d, x[ 0], S41, 0xf4292244); II (d, a, b, c, x[ 7], S42, 0x432aff97);
  3720. II (c, d, a, b, x[14], S43, 0xab9423a7); II (b, c, d, a, x[ 5], S44, 0xfc93a039);
  3721. II (a, b, c, d, x[12], S41, 0x655b59c3); II (d, a, b, c, x[ 3], S42, 0x8f0ccc92);
  3722. II (c, d, a, b, x[10], S43, 0xffeff47d); II (b, c, d, a, x[ 1], S44, 0x85845dd1);
  3723. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); II (d, a, b, c, x[15], S42, 0xfe2ce6e0);
  3724. II (c, d, a, b, x[ 6], S43, 0xa3014314); II (b, c, d, a, x[13], S44, 0x4e0811a1);
  3725. II (a, b, c, d, x[ 4], S41, 0xf7537e82); II (d, a, b, c, x[11], S42, 0xbd3af235);
  3726. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); II (b, c, d, a, x[ 9], S44, 0xeb86d391);
  3727. state[0] += a;
  3728. state[1] += b;
  3729. state[2] += c;
  3730. state[3] += d;
  3731. zerostruct (x);
  3732. }
  3733. const MemoryBlock MD5::getRawChecksumData() const
  3734. {
  3735. return MemoryBlock (result, sizeof (result));
  3736. }
  3737. const String MD5::toHexString() const
  3738. {
  3739. return String::toHexString (result, sizeof (result), 0);
  3740. }
  3741. bool MD5::operator== (const MD5& other) const
  3742. {
  3743. return memcmp (result, other.result, sizeof (result)) == 0;
  3744. }
  3745. bool MD5::operator!= (const MD5& other) const
  3746. {
  3747. return ! operator== (other);
  3748. }
  3749. END_JUCE_NAMESPACE
  3750. /*** End of inlined file: juce_MD5.cpp ***/
  3751. /*** Start of inlined file: juce_Primes.cpp ***/
  3752. BEGIN_JUCE_NAMESPACE
  3753. namespace PrimesHelpers
  3754. {
  3755. static void createSmallSieve (const int numBits, BigInteger& result)
  3756. {
  3757. result.setBit (numBits);
  3758. result.clearBit (numBits); // to enlarge the array
  3759. result.setBit (0);
  3760. int n = 2;
  3761. do
  3762. {
  3763. for (int i = n + n; i < numBits; i += n)
  3764. result.setBit (i);
  3765. n = result.findNextClearBit (n + 1);
  3766. }
  3767. while (n <= (numBits >> 1));
  3768. }
  3769. static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
  3770. const BigInteger& smallSieve, const int smallSieveSize)
  3771. {
  3772. jassert (! base[0]); // must be even!
  3773. result.setBit (numBits);
  3774. result.clearBit (numBits); // to enlarge the array
  3775. int index = smallSieve.findNextClearBit (0);
  3776. do
  3777. {
  3778. const int prime = (index << 1) + 1;
  3779. BigInteger r (base), remainder;
  3780. r.divideBy (prime, remainder);
  3781. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3782. if (r.isZero())
  3783. i += prime;
  3784. if ((i & 1) == 0)
  3785. i += prime;
  3786. i = (i - 1) >> 1;
  3787. while (i < numBits)
  3788. {
  3789. result.setBit (i);
  3790. i += prime;
  3791. }
  3792. index = smallSieve.findNextClearBit (index + 1);
  3793. }
  3794. while (index < smallSieveSize);
  3795. }
  3796. static bool findCandidate (const BigInteger& base, const BigInteger& sieve,
  3797. const int numBits, BigInteger& result, const int certainty)
  3798. {
  3799. for (int i = 0; i < numBits; ++i)
  3800. {
  3801. if (! sieve[i])
  3802. {
  3803. result = base + (unsigned int) ((i << 1) + 1);
  3804. if (Primes::isProbablyPrime (result, certainty))
  3805. return true;
  3806. }
  3807. }
  3808. return false;
  3809. }
  3810. static bool passesMillerRabin (const BigInteger& n, int iterations)
  3811. {
  3812. const BigInteger one (1), two (2);
  3813. const BigInteger nMinusOne (n - one);
  3814. BigInteger d (nMinusOne);
  3815. const int s = d.findNextSetBit (0);
  3816. d >>= s;
  3817. BigInteger smallPrimes;
  3818. int numBitsInSmallPrimes = 0;
  3819. for (;;)
  3820. {
  3821. numBitsInSmallPrimes += 256;
  3822. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3823. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3824. if (numPrimesFound > iterations + 1)
  3825. break;
  3826. }
  3827. int smallPrime = 2;
  3828. while (--iterations >= 0)
  3829. {
  3830. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3831. BigInteger r (smallPrime);
  3832. r.exponentModulo (d, n);
  3833. if (r != one && r != nMinusOne)
  3834. {
  3835. for (int j = 0; j < s; ++j)
  3836. {
  3837. r.exponentModulo (two, n);
  3838. if (r == nMinusOne)
  3839. break;
  3840. }
  3841. if (r != nMinusOne)
  3842. return false;
  3843. }
  3844. }
  3845. return true;
  3846. }
  3847. }
  3848. const BigInteger Primes::createProbablePrime (const int bitLength,
  3849. const int certainty,
  3850. const int* randomSeeds,
  3851. int numRandomSeeds)
  3852. {
  3853. using namespace PrimesHelpers;
  3854. int defaultSeeds [16];
  3855. if (numRandomSeeds <= 0)
  3856. {
  3857. randomSeeds = defaultSeeds;
  3858. numRandomSeeds = numElementsInArray (defaultSeeds);
  3859. Random r (0);
  3860. for (int j = 10; --j >= 0;)
  3861. {
  3862. r.setSeedRandomly();
  3863. for (int i = numRandomSeeds; --i >= 0;)
  3864. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3865. }
  3866. }
  3867. BigInteger smallSieve;
  3868. const int smallSieveSize = 15000;
  3869. createSmallSieve (smallSieveSize, smallSieve);
  3870. BigInteger p;
  3871. for (int i = numRandomSeeds; --i >= 0;)
  3872. {
  3873. BigInteger p2;
  3874. Random r (randomSeeds[i]);
  3875. r.fillBitsRandomly (p2, 0, bitLength);
  3876. p ^= p2;
  3877. }
  3878. p.setBit (bitLength - 1);
  3879. p.clearBit (0);
  3880. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3881. while (p.getHighestBit() < bitLength)
  3882. {
  3883. p += 2 * searchLen;
  3884. BigInteger sieve;
  3885. bigSieve (p, searchLen, sieve,
  3886. smallSieve, smallSieveSize);
  3887. BigInteger candidate;
  3888. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3889. return candidate;
  3890. }
  3891. jassertfalse
  3892. return BigInteger();
  3893. }
  3894. bool Primes::isProbablyPrime (const BigInteger& number, const int certainty)
  3895. {
  3896. using namespace PrimesHelpers;
  3897. if (! number[0])
  3898. return false;
  3899. if (number.getHighestBit() <= 10)
  3900. {
  3901. const int num = number.getBitRangeAsInt (0, 10);
  3902. for (int i = num / 2; --i > 1;)
  3903. if (num % i == 0)
  3904. return false;
  3905. return true;
  3906. }
  3907. else
  3908. {
  3909. if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1)
  3910. return false;
  3911. return passesMillerRabin (number, certainty);
  3912. }
  3913. }
  3914. END_JUCE_NAMESPACE
  3915. /*** End of inlined file: juce_Primes.cpp ***/
  3916. /*** Start of inlined file: juce_RSAKey.cpp ***/
  3917. BEGIN_JUCE_NAMESPACE
  3918. RSAKey::RSAKey()
  3919. {
  3920. }
  3921. RSAKey::RSAKey (const String& s)
  3922. {
  3923. if (s.containsChar (','))
  3924. {
  3925. part1.parseString (s.upToFirstOccurrenceOf (",", false, false), 16);
  3926. part2.parseString (s.fromFirstOccurrenceOf (",", false, false), 16);
  3927. }
  3928. else
  3929. {
  3930. // the string needs to be two hex numbers, comma-separated..
  3931. jassertfalse;
  3932. }
  3933. }
  3934. RSAKey::~RSAKey()
  3935. {
  3936. }
  3937. const String RSAKey::toString() const
  3938. {
  3939. return part1.toString (16) + "," + part2.toString (16);
  3940. }
  3941. bool RSAKey::applyToValue (BigInteger& value) const
  3942. {
  3943. if (part1.isZero() || part2.isZero() || value <= 0)
  3944. {
  3945. jassertfalse // using an uninitialised key
  3946. value.clear();
  3947. return false;
  3948. }
  3949. BigInteger result;
  3950. while (! value.isZero())
  3951. {
  3952. result *= part2;
  3953. BigInteger remainder;
  3954. value.divideBy (part2, remainder);
  3955. remainder.exponentModulo (part1, part2);
  3956. result += remainder;
  3957. }
  3958. value.swapWith (result);
  3959. return true;
  3960. }
  3961. static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q)
  3962. {
  3963. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3964. // are fast to divide + multiply
  3965. for (int i = 2; i <= 65536; i *= 2)
  3966. {
  3967. const BigInteger e (1 + i);
  3968. if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())
  3969. return e;
  3970. }
  3971. BigInteger e (4);
  3972. while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()))
  3973. ++e;
  3974. return e;
  3975. }
  3976. void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey,
  3977. const int numBits, const int* randomSeeds, const int numRandomSeeds)
  3978. {
  3979. jassert (numBits > 16); // not much point using less than this..
  3980. BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  3981. BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  3982. const BigInteger n (p * q);
  3983. const BigInteger m (--p * --q);
  3984. const BigInteger e (findBestCommonDivisor (p, q));
  3985. BigInteger d (e);
  3986. d.inverseModulo (m);
  3987. publicKey.part1 = e;
  3988. publicKey.part2 = n;
  3989. privateKey.part1 = d;
  3990. privateKey.part2 = n;
  3991. }
  3992. END_JUCE_NAMESPACE
  3993. /*** End of inlined file: juce_RSAKey.cpp ***/
  3994. /*** Start of inlined file: juce_InputStream.cpp ***/
  3995. BEGIN_JUCE_NAMESPACE
  3996. char InputStream::readByte()
  3997. {
  3998. char temp = 0;
  3999. read (&temp, 1);
  4000. return temp;
  4001. }
  4002. bool InputStream::readBool()
  4003. {
  4004. return readByte() != 0;
  4005. }
  4006. short InputStream::readShort()
  4007. {
  4008. char temp[2];
  4009. if (read (temp, 2) == 2)
  4010. return (short) ByteOrder::littleEndianShort (temp);
  4011. return 0;
  4012. }
  4013. short InputStream::readShortBigEndian()
  4014. {
  4015. char temp[2];
  4016. if (read (temp, 2) == 2)
  4017. return (short) ByteOrder::bigEndianShort (temp);
  4018. return 0;
  4019. }
  4020. int InputStream::readInt()
  4021. {
  4022. char temp[4];
  4023. if (read (temp, 4) == 4)
  4024. return (int) ByteOrder::littleEndianInt (temp);
  4025. return 0;
  4026. }
  4027. int InputStream::readIntBigEndian()
  4028. {
  4029. char temp[4];
  4030. if (read (temp, 4) == 4)
  4031. return (int) ByteOrder::bigEndianInt (temp);
  4032. return 0;
  4033. }
  4034. int InputStream::readCompressedInt()
  4035. {
  4036. const unsigned char sizeByte = readByte();
  4037. if (sizeByte == 0)
  4038. return 0;
  4039. const int numBytes = (sizeByte & 0x7f);
  4040. if (numBytes > 4)
  4041. {
  4042. jassertfalse // trying to read corrupt data - this method must only be used
  4043. // to read data that was written by OutputStream::writeCompressedInt()
  4044. return 0;
  4045. }
  4046. char bytes[4] = { 0, 0, 0, 0 };
  4047. if (read (bytes, numBytes) != numBytes)
  4048. return 0;
  4049. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4050. return (sizeByte >> 7) ? -num : num;
  4051. }
  4052. int64 InputStream::readInt64()
  4053. {
  4054. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4055. if (read (n.asBytes, 8) == 8)
  4056. return (int64) ByteOrder::swapIfBigEndian (n.asInt64);
  4057. return 0;
  4058. }
  4059. int64 InputStream::readInt64BigEndian()
  4060. {
  4061. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4062. if (read (n.asBytes, 8) == 8)
  4063. return (int64) ByteOrder::swapIfLittleEndian (n.asInt64);
  4064. return 0;
  4065. }
  4066. float InputStream::readFloat()
  4067. {
  4068. // the union below relies on these types being the same size...
  4069. static_jassert (sizeof (int32) == sizeof (float));
  4070. union { int32 asInt; float asFloat; } n;
  4071. n.asInt = (int32) readInt();
  4072. return n.asFloat;
  4073. }
  4074. float InputStream::readFloatBigEndian()
  4075. {
  4076. union { int32 asInt; float asFloat; } n;
  4077. n.asInt = (int32) readIntBigEndian();
  4078. return n.asFloat;
  4079. }
  4080. double InputStream::readDouble()
  4081. {
  4082. union { int64 asInt; double asDouble; } n;
  4083. n.asInt = readInt64();
  4084. return n.asDouble;
  4085. }
  4086. double InputStream::readDoubleBigEndian()
  4087. {
  4088. union { int64 asInt; double asDouble; } n;
  4089. n.asInt = readInt64BigEndian();
  4090. return n.asDouble;
  4091. }
  4092. const String InputStream::readString()
  4093. {
  4094. MemoryBlock buffer (256);
  4095. char* data = static_cast<char*> (buffer.getData());
  4096. size_t i = 0;
  4097. while ((data[i] = readByte()) != 0)
  4098. {
  4099. if (++i >= buffer.getSize())
  4100. {
  4101. buffer.setSize (buffer.getSize() + 512);
  4102. data = static_cast<char*> (buffer.getData());
  4103. }
  4104. }
  4105. return String::fromUTF8 (data, (int) i);
  4106. }
  4107. const String InputStream::readNextLine()
  4108. {
  4109. MemoryBlock buffer (256);
  4110. char* data = static_cast<char*> (buffer.getData());
  4111. size_t i = 0;
  4112. while ((data[i] = readByte()) != 0)
  4113. {
  4114. if (data[i] == '\n')
  4115. break;
  4116. if (data[i] == '\r')
  4117. {
  4118. const int64 lastPos = getPosition();
  4119. if (readByte() != '\n')
  4120. setPosition (lastPos);
  4121. break;
  4122. }
  4123. if (++i >= buffer.getSize())
  4124. {
  4125. buffer.setSize (buffer.getSize() + 512);
  4126. data = static_cast<char*> (buffer.getData());
  4127. }
  4128. }
  4129. return String::fromUTF8 (data, (int) i);
  4130. }
  4131. int InputStream::readIntoMemoryBlock (MemoryBlock& block, int numBytes)
  4132. {
  4133. const int64 totalLength = getTotalLength();
  4134. if (totalLength >= 0)
  4135. {
  4136. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4137. totalLength - getPosition());
  4138. if (numBytes < 0)
  4139. numBytes = totalBytesRemaining;
  4140. else if (numBytes > 0)
  4141. numBytes = jmin (numBytes, totalBytesRemaining);
  4142. else
  4143. return 0;
  4144. }
  4145. const size_t originalBlockSize = block.getSize();
  4146. int totalBytesRead = 0;
  4147. if (numBytes > 0)
  4148. {
  4149. // know how many bytes we want, so we can resize the block first..
  4150. block.setSize (originalBlockSize + numBytes, false);
  4151. totalBytesRead = read (static_cast<char*> (block.getData()) + originalBlockSize, numBytes);
  4152. }
  4153. else
  4154. {
  4155. // read until end of stram..
  4156. const int chunkSize = 32768;
  4157. for (;;)
  4158. {
  4159. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4160. const int bytesJustIn = read (static_cast<char*> (block.getData())
  4161. + originalBlockSize
  4162. + totalBytesRead,
  4163. chunkSize);
  4164. if (bytesJustIn == 0)
  4165. break;
  4166. totalBytesRead += bytesJustIn;
  4167. }
  4168. }
  4169. // trim off any excess left at the end
  4170. block.setSize (originalBlockSize + totalBytesRead, false);
  4171. return totalBytesRead;
  4172. }
  4173. const String InputStream::readEntireStreamAsString()
  4174. {
  4175. MemoryBlock mb;
  4176. const int size = readIntoMemoryBlock (mb);
  4177. return String::createStringFromData (static_cast<const char*> (mb.getData()), size);
  4178. }
  4179. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4180. {
  4181. if (numBytesToSkip > 0)
  4182. {
  4183. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4184. HeapBlock<char> temp (skipBufferSize);
  4185. while (numBytesToSkip > 0 && ! isExhausted())
  4186. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4187. }
  4188. }
  4189. END_JUCE_NAMESPACE
  4190. /*** End of inlined file: juce_InputStream.cpp ***/
  4191. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4192. BEGIN_JUCE_NAMESPACE
  4193. #if JUCE_DEBUG
  4194. static CriticalSection activeStreamLock;
  4195. static VoidArray activeStreams;
  4196. void juce_CheckForDanglingStreams()
  4197. {
  4198. /*
  4199. It's always a bad idea to leak any object, but if you're leaking output
  4200. streams, then there's a good chance that you're failing to flush a file
  4201. to disk properly, which could result in corrupted data and other similar
  4202. nastiness..
  4203. */
  4204. jassert (activeStreams.size() == 0);
  4205. };
  4206. #endif
  4207. OutputStream::OutputStream()
  4208. {
  4209. #if JUCE_DEBUG
  4210. const ScopedLock sl (activeStreamLock);
  4211. activeStreams.add (this);
  4212. #endif
  4213. }
  4214. OutputStream::~OutputStream()
  4215. {
  4216. #if JUCE_DEBUG
  4217. const ScopedLock sl (activeStreamLock);
  4218. activeStreams.removeValue (this);
  4219. #endif
  4220. }
  4221. void OutputStream::writeBool (const bool b)
  4222. {
  4223. writeByte (b ? (char) 1
  4224. : (char) 0);
  4225. }
  4226. void OutputStream::writeByte (char byte)
  4227. {
  4228. write (&byte, 1);
  4229. }
  4230. void OutputStream::writeShort (short value)
  4231. {
  4232. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4233. write (&v, 2);
  4234. }
  4235. void OutputStream::writeShortBigEndian (short value)
  4236. {
  4237. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4238. write (&v, 2);
  4239. }
  4240. void OutputStream::writeInt (int value)
  4241. {
  4242. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4243. write (&v, 4);
  4244. }
  4245. void OutputStream::writeIntBigEndian (int value)
  4246. {
  4247. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4248. write (&v, 4);
  4249. }
  4250. void OutputStream::writeCompressedInt (int value)
  4251. {
  4252. unsigned int un = (value < 0) ? (unsigned int) -value
  4253. : (unsigned int) value;
  4254. uint8 data[5];
  4255. int num = 0;
  4256. while (un > 0)
  4257. {
  4258. data[++num] = (uint8) un;
  4259. un >>= 8;
  4260. }
  4261. data[0] = (uint8) num;
  4262. if (value < 0)
  4263. data[0] |= 0x80;
  4264. write (data, num + 1);
  4265. }
  4266. void OutputStream::writeInt64 (int64 value)
  4267. {
  4268. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4269. write (&v, 8);
  4270. }
  4271. void OutputStream::writeInt64BigEndian (int64 value)
  4272. {
  4273. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4274. write (&v, 8);
  4275. }
  4276. void OutputStream::writeFloat (float value)
  4277. {
  4278. union { int asInt; float asFloat; } n;
  4279. n.asFloat = value;
  4280. writeInt (n.asInt);
  4281. }
  4282. void OutputStream::writeFloatBigEndian (float value)
  4283. {
  4284. union { int asInt; float asFloat; } n;
  4285. n.asFloat = value;
  4286. writeIntBigEndian (n.asInt);
  4287. }
  4288. void OutputStream::writeDouble (double value)
  4289. {
  4290. union { int64 asInt; double asDouble; } n;
  4291. n.asDouble = value;
  4292. writeInt64 (n.asInt);
  4293. }
  4294. void OutputStream::writeDoubleBigEndian (double value)
  4295. {
  4296. union { int64 asInt; double asDouble; } n;
  4297. n.asDouble = value;
  4298. writeInt64BigEndian (n.asInt);
  4299. }
  4300. void OutputStream::writeString (const String& text)
  4301. {
  4302. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4303. // if lots of large, persistent strings were to be written to streams).
  4304. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4305. HeapBlock<char> temp (numBytes);
  4306. text.copyToUTF8 (temp, numBytes);
  4307. write (temp, numBytes);
  4308. }
  4309. void OutputStream::writeText (const String& text, const bool asUnicode,
  4310. const bool writeUnicodeHeaderBytes)
  4311. {
  4312. if (asUnicode)
  4313. {
  4314. if (writeUnicodeHeaderBytes)
  4315. write ("\x0ff\x0fe", 2);
  4316. const juce_wchar* src = text;
  4317. bool lastCharWasReturn = false;
  4318. while (*src != 0)
  4319. {
  4320. if (*src == L'\n' && ! lastCharWasReturn)
  4321. writeShort ((short) L'\r');
  4322. lastCharWasReturn = (*src == L'\r');
  4323. writeShort ((short) *src++);
  4324. }
  4325. }
  4326. else
  4327. {
  4328. const char* src = text.toUTF8();
  4329. const char* t = src;
  4330. for (;;)
  4331. {
  4332. if (*t == '\n')
  4333. {
  4334. if (t > src)
  4335. write (src, (int) (t - src));
  4336. write ("\r\n", 2);
  4337. src = t + 1;
  4338. }
  4339. else if (*t == '\r')
  4340. {
  4341. if (t[1] == '\n')
  4342. ++t;
  4343. }
  4344. else if (*t == 0)
  4345. {
  4346. if (t > src)
  4347. write (src, (int) (t - src));
  4348. break;
  4349. }
  4350. ++t;
  4351. }
  4352. }
  4353. }
  4354. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4355. {
  4356. if (numBytesToWrite < 0)
  4357. numBytesToWrite = 0x7fffffff;
  4358. int numWritten = 0;
  4359. while (numBytesToWrite > 0 && ! source.isExhausted())
  4360. {
  4361. char buffer [8192];
  4362. const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4363. if (num == 0)
  4364. break;
  4365. write (buffer, num);
  4366. numBytesToWrite -= num;
  4367. numWritten += num;
  4368. }
  4369. return numWritten;
  4370. }
  4371. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4372. {
  4373. return stream << String (number);
  4374. }
  4375. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4376. {
  4377. return stream << String (number);
  4378. }
  4379. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4380. {
  4381. stream.writeByte (character);
  4382. return stream;
  4383. }
  4384. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4385. {
  4386. stream.write (text, (int) strlen (text));
  4387. return stream;
  4388. }
  4389. END_JUCE_NAMESPACE
  4390. /*** End of inlined file: juce_OutputStream.cpp ***/
  4391. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4392. BEGIN_JUCE_NAMESPACE
  4393. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4394. bool* isDirectory, bool* isHidden, int64* fileSize,
  4395. Time* modTime, Time* creationTime, bool* isReadOnly);
  4396. bool juce_findFileNext (void* handle, String& resultFile,
  4397. bool* isDirectory, bool* isHidden, int64* fileSize,
  4398. Time* modTime, Time* creationTime, bool* isReadOnly);
  4399. void juce_findFileClose (void* handle);
  4400. DirectoryIterator::DirectoryIterator (const File& directory,
  4401. bool isRecursive,
  4402. const String& wc,
  4403. const int whatToLookFor_)
  4404. : wildCard (wc),
  4405. index (-1),
  4406. whatToLookFor (whatToLookFor_)
  4407. {
  4408. // you have to specify the type of files you're looking for!
  4409. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4410. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4411. String path (directory.getFullPathName());
  4412. if (! path.endsWithChar (File::separator))
  4413. path += File::separator;
  4414. String filename;
  4415. bool isDirectory, isHidden;
  4416. void* const handle = juce_findFileStart (path,
  4417. isRecursive ? "*" : wc,
  4418. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4419. if (handle != 0)
  4420. {
  4421. do
  4422. {
  4423. if (! filename.containsOnly ("."))
  4424. {
  4425. bool addToList = false;
  4426. if (isDirectory)
  4427. {
  4428. if (isRecursive
  4429. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4430. || ! isHidden))
  4431. {
  4432. dirsFound.add (File (path + filename, 0));
  4433. }
  4434. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4435. }
  4436. else
  4437. {
  4438. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4439. }
  4440. // if it's recursive, we're not relying on the OS iterator
  4441. // to do the wildcard match, so do it now..
  4442. if (isRecursive && addToList)
  4443. addToList = filename.matchesWildcard (wc, true);
  4444. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4445. addToList = ! isHidden;
  4446. if (addToList)
  4447. filesFound.add (File (path + filename, 0));
  4448. }
  4449. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4450. juce_findFileClose (handle);
  4451. }
  4452. }
  4453. DirectoryIterator::~DirectoryIterator()
  4454. {
  4455. }
  4456. bool DirectoryIterator::next()
  4457. {
  4458. if (subIterator != 0)
  4459. {
  4460. if (subIterator->next())
  4461. return true;
  4462. subIterator = 0;
  4463. }
  4464. if (index >= filesFound.size() + dirsFound.size() - 1)
  4465. return false;
  4466. ++index;
  4467. if (index >= filesFound.size())
  4468. {
  4469. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4470. true, wildCard, whatToLookFor);
  4471. return next();
  4472. }
  4473. return true;
  4474. }
  4475. const File DirectoryIterator::getFile() const
  4476. {
  4477. if (subIterator != 0)
  4478. return subIterator->getFile();
  4479. return filesFound [index];
  4480. }
  4481. float DirectoryIterator::getEstimatedProgress() const
  4482. {
  4483. if (filesFound.size() + dirsFound.size() == 0)
  4484. {
  4485. return 0.0f;
  4486. }
  4487. else
  4488. {
  4489. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4490. : (float) index;
  4491. return detailedIndex / (filesFound.size() + dirsFound.size());
  4492. }
  4493. }
  4494. END_JUCE_NAMESPACE
  4495. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4496. /*** Start of inlined file: juce_File.cpp ***/
  4497. #ifdef _MSC_VER
  4498. #pragma warning (disable: 4514)
  4499. #pragma warning (push)
  4500. #endif
  4501. #if ! JUCE_WINDOWS
  4502. #include <pwd.h>
  4503. #endif
  4504. BEGIN_JUCE_NAMESPACE
  4505. #ifdef _MSC_VER
  4506. #pragma warning (pop)
  4507. #endif
  4508. void* juce_fileOpen (const String& path, bool forWriting);
  4509. void juce_fileClose (void* handle);
  4510. int juce_fileWrite (void* handle, const void* buffer, int size);
  4511. int64 juce_fileGetPosition (void* handle);
  4512. int64 juce_fileSetPosition (void* handle, int64 pos);
  4513. void juce_fileFlush (void* handle);
  4514. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4515. bool juce_isDirectory (const String& fileName);
  4516. int64 juce_getFileSize (const String& fileName);
  4517. bool juce_canWriteToFile (const String& fileName);
  4518. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4519. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4520. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4521. bool juce_deleteFile (const String& fileName);
  4522. bool juce_copyFile (const String& source, const String& dest);
  4523. bool juce_moveFile (const String& source, const String& dest);
  4524. // this must also create all paths involved in the directory.
  4525. void juce_createDirectory (const String& fileName);
  4526. bool juce_launchFile (const String& fileName, const String& parameters);
  4527. const StringArray juce_getFileSystemRoots();
  4528. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4529. // starts a directory search operation with a wildcard, returning a handle for
  4530. // use in calls to juce_findFileNext.
  4531. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4532. // the other pointers, if non-null, are set based on the properties of the file.
  4533. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4534. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4535. Time* creationTime, bool* isReadOnly);
  4536. // returns false when no more files are found
  4537. bool juce_findFileNext (void* handle, String& resultFile,
  4538. bool* isDirectory, bool* isHidden, int64* fileSize,
  4539. Time* modTime, Time* creationTime, bool* isReadOnly);
  4540. void juce_findFileClose (void* handle);
  4541. static const String juce_addTrailingSeparator (const String& path)
  4542. {
  4543. return path.endsWithChar (File::separator) ? path
  4544. : path + File::separator;
  4545. }
  4546. static const String parseAbsolutePath (String path)
  4547. {
  4548. if (path.isEmpty())
  4549. return String::empty;
  4550. #if JUCE_WINDOWS
  4551. // Windows..
  4552. path = path.replaceCharacter ('/', '\\');
  4553. if (path.startsWithChar (File::separator))
  4554. {
  4555. if (path[1] != File::separator)
  4556. {
  4557. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4558. If you're trying to parse a string that may be either a relative path or an absolute path,
  4559. you MUST provide a context against which the partial path can be evaluated - you can do
  4560. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4561. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4562. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4563. */
  4564. jassertfalse
  4565. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4566. }
  4567. }
  4568. else if (path.indexOfChar (':') < 0)
  4569. {
  4570. if (path.isEmpty())
  4571. return String::empty;
  4572. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4573. If you're trying to parse a string that may be either a relative path or an absolute path,
  4574. you MUST provide a context against which the partial path can be evaluated - you can do
  4575. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4576. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4577. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4578. */
  4579. jassertfalse
  4580. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4581. }
  4582. #else
  4583. // Mac or Linux..
  4584. path = path.replaceCharacter ('\\', '/');
  4585. if (path.startsWithChar ('~'))
  4586. {
  4587. const char* homeDir = 0;
  4588. if (path[1] == File::separator || path[1] == 0)
  4589. {
  4590. // expand a name of the form "~/abc"
  4591. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4592. + path.substring (1);
  4593. }
  4594. else
  4595. {
  4596. // expand a name of type "~dave/abc"
  4597. const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false));
  4598. struct passwd* const pw = getpwnam (userName.toUTF8());
  4599. if (pw != 0)
  4600. {
  4601. String home (homeDir);
  4602. if (home.endsWithChar (File::separator))
  4603. home [home.length() - 1] = 0;
  4604. path = String (pw->pw_dir)
  4605. + path.substring (userName.length());
  4606. }
  4607. }
  4608. }
  4609. else if (! path.startsWithChar (File::separator))
  4610. {
  4611. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4612. If you're trying to parse a string that may be either a relative path or an absolute path,
  4613. you MUST provide a context against which the partial path can be evaluated - you can do
  4614. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4615. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4616. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4617. */
  4618. jassert (path.startsWith ("./") || path.startsWith ("../")); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4619. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4620. }
  4621. #endif
  4622. int len = path.length();
  4623. while (--len > 0 && path [len] == File::separator)
  4624. path [len] = 0;
  4625. return path;
  4626. }
  4627. const File File::nonexistent;
  4628. File::File (const String& fullPathName)
  4629. : fullPath (parseAbsolutePath (fullPathName))
  4630. {
  4631. }
  4632. File::File (const String& path, int)
  4633. : fullPath (path)
  4634. {
  4635. }
  4636. const File File::createFileWithoutCheckingPath (const String& path)
  4637. {
  4638. return File (path, 0);
  4639. }
  4640. File::File (const File& other)
  4641. : fullPath (other.fullPath)
  4642. {
  4643. }
  4644. File& File::operator= (const String& newPath)
  4645. {
  4646. fullPath = parseAbsolutePath (newPath);
  4647. return *this;
  4648. }
  4649. File& File::operator= (const File& other)
  4650. {
  4651. fullPath = other.fullPath;
  4652. return *this;
  4653. }
  4654. #if JUCE_LINUX
  4655. #define NAMES_ARE_CASE_SENSITIVE 1
  4656. #endif
  4657. bool File::areFileNamesCaseSensitive()
  4658. {
  4659. #if NAMES_ARE_CASE_SENSITIVE
  4660. return true;
  4661. #else
  4662. return false;
  4663. #endif
  4664. }
  4665. bool File::operator== (const File& other) const
  4666. {
  4667. // case-insensitive on Windows, but not on linux.
  4668. #if NAMES_ARE_CASE_SENSITIVE
  4669. return fullPath == other.fullPath;
  4670. #else
  4671. return fullPath.equalsIgnoreCase (other.fullPath);
  4672. #endif
  4673. }
  4674. bool File::operator!= (const File& other) const
  4675. {
  4676. return ! operator== (other);
  4677. }
  4678. bool File::exists() const
  4679. {
  4680. return juce_fileExists (fullPath, false);
  4681. }
  4682. bool File::existsAsFile() const
  4683. {
  4684. return juce_fileExists (fullPath, true);
  4685. }
  4686. bool File::isDirectory() const
  4687. {
  4688. return juce_isDirectory (fullPath);
  4689. }
  4690. bool File::hasWriteAccess() const
  4691. {
  4692. if (exists())
  4693. return juce_canWriteToFile (fullPath);
  4694. #if ! JUCE_WINDOWS
  4695. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4696. return getParentDirectory().hasWriteAccess();
  4697. else
  4698. return false;
  4699. #else
  4700. // on windows, it seems that even read-only directories can still be written into,
  4701. // so checking the parent directory's permissions would return the wrong result..
  4702. else
  4703. return true;
  4704. #endif
  4705. }
  4706. bool File::setReadOnly (const bool shouldBeReadOnly,
  4707. const bool applyRecursively) const
  4708. {
  4709. bool worked = true;
  4710. if (applyRecursively && isDirectory())
  4711. {
  4712. Array <File> subFiles;
  4713. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4714. for (int i = subFiles.size(); --i >= 0;)
  4715. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4716. }
  4717. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4718. }
  4719. bool File::deleteFile() const
  4720. {
  4721. return (! exists())
  4722. || juce_deleteFile (fullPath);
  4723. }
  4724. bool File::deleteRecursively() const
  4725. {
  4726. bool worked = true;
  4727. if (isDirectory())
  4728. {
  4729. Array<File> subFiles;
  4730. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4731. for (int i = subFiles.size(); --i >= 0;)
  4732. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4733. }
  4734. return deleteFile() && worked;
  4735. }
  4736. bool File::moveFileTo (const File& newFile) const
  4737. {
  4738. if (newFile.fullPath == fullPath)
  4739. return true;
  4740. #if ! NAMES_ARE_CASE_SENSITIVE
  4741. if (*this != newFile)
  4742. #endif
  4743. if (! newFile.deleteFile())
  4744. return false;
  4745. return juce_moveFile (fullPath, newFile.fullPath);
  4746. }
  4747. bool File::copyFileTo (const File& newFile) const
  4748. {
  4749. if (*this == newFile)
  4750. return true;
  4751. if (! newFile.deleteFile())
  4752. return false;
  4753. return juce_copyFile (fullPath, newFile.fullPath);
  4754. }
  4755. bool File::copyDirectoryTo (const File& newDirectory) const
  4756. {
  4757. if (isDirectory() && newDirectory.createDirectory())
  4758. {
  4759. Array<File> subFiles;
  4760. findChildFiles (subFiles, File::findFiles, false);
  4761. int i;
  4762. for (i = 0; i < subFiles.size(); ++i)
  4763. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4764. return false;
  4765. subFiles.clear();
  4766. findChildFiles (subFiles, File::findDirectories, false);
  4767. for (i = 0; i < subFiles.size(); ++i)
  4768. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4769. return false;
  4770. return true;
  4771. }
  4772. return false;
  4773. }
  4774. const String File::getPathUpToLastSlash() const
  4775. {
  4776. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4777. if (lastSlash > 0)
  4778. return fullPath.substring (0, lastSlash);
  4779. else if (lastSlash == 0)
  4780. return separatorString;
  4781. else
  4782. return fullPath;
  4783. }
  4784. const File File::getParentDirectory() const
  4785. {
  4786. return File (getPathUpToLastSlash());
  4787. }
  4788. const String File::getFileName() const
  4789. {
  4790. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4791. }
  4792. int File::hashCode() const
  4793. {
  4794. return fullPath.hashCode();
  4795. }
  4796. int64 File::hashCode64() const
  4797. {
  4798. return fullPath.hashCode64();
  4799. }
  4800. const String File::getFileNameWithoutExtension() const
  4801. {
  4802. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4803. const int lastDot = fullPath.lastIndexOfChar ('.');
  4804. if (lastDot > lastSlash)
  4805. return fullPath.substring (lastSlash, lastDot);
  4806. else
  4807. return fullPath.substring (lastSlash);
  4808. }
  4809. bool File::isAChildOf (const File& potentialParent) const
  4810. {
  4811. if (potentialParent == File::nonexistent)
  4812. return false;
  4813. const String ourPath (getPathUpToLastSlash());
  4814. #if NAMES_ARE_CASE_SENSITIVE
  4815. if (potentialParent.fullPath == ourPath)
  4816. #else
  4817. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4818. #endif
  4819. {
  4820. return true;
  4821. }
  4822. else if (potentialParent.fullPath.length() >= ourPath.length())
  4823. {
  4824. return false;
  4825. }
  4826. else
  4827. {
  4828. return getParentDirectory().isAChildOf (potentialParent);
  4829. }
  4830. }
  4831. bool File::isAbsolutePath (const String& path)
  4832. {
  4833. return path.startsWithChar ('/') || path.startsWithChar ('\\')
  4834. #if JUCE_WINDOWS
  4835. || (path.isNotEmpty() && path[1] == ':');
  4836. #else
  4837. || path.startsWithChar ('~');
  4838. #endif
  4839. }
  4840. const File File::getChildFile (String relativePath) const
  4841. {
  4842. if (isAbsolutePath (relativePath))
  4843. {
  4844. // the path is really absolute..
  4845. return File (relativePath);
  4846. }
  4847. else
  4848. {
  4849. // it's relative, so remove any ../ or ./ bits at the start.
  4850. String path (fullPath);
  4851. if (relativePath[0] == '.')
  4852. {
  4853. #if JUCE_WINDOWS
  4854. relativePath = relativePath.replaceCharacter ('/', '\\').trimStart();
  4855. #else
  4856. relativePath = relativePath.replaceCharacter ('\\', '/').trimStart();
  4857. #endif
  4858. while (relativePath[0] == '.')
  4859. {
  4860. if (relativePath[1] == '.')
  4861. {
  4862. if (relativePath [2] == 0 || relativePath[2] == separator)
  4863. {
  4864. const int lastSlash = path.lastIndexOfChar (separator);
  4865. if (lastSlash >= 0)
  4866. path = path.substring (0, lastSlash);
  4867. relativePath = relativePath.substring (3);
  4868. }
  4869. else
  4870. {
  4871. break;
  4872. }
  4873. }
  4874. else if (relativePath[1] == separator)
  4875. {
  4876. relativePath = relativePath.substring (2);
  4877. }
  4878. else
  4879. {
  4880. break;
  4881. }
  4882. }
  4883. }
  4884. return File (juce_addTrailingSeparator (path) + relativePath);
  4885. }
  4886. }
  4887. const File File::getSiblingFile (const String& fileName) const
  4888. {
  4889. return getParentDirectory().getChildFile (fileName);
  4890. }
  4891. int64 File::getSize() const
  4892. {
  4893. return juce_getFileSize (fullPath);
  4894. }
  4895. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4896. {
  4897. if (bytes == 1)
  4898. {
  4899. return "1 byte";
  4900. }
  4901. else if (bytes < 1024)
  4902. {
  4903. return String ((int) bytes) + " bytes";
  4904. }
  4905. else if (bytes < 1024 * 1024)
  4906. {
  4907. return String (bytes / 1024.0, 1) + " KB";
  4908. }
  4909. else if (bytes < 1024 * 1024 * 1024)
  4910. {
  4911. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4912. }
  4913. else
  4914. {
  4915. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4916. }
  4917. }
  4918. bool File::create() const
  4919. {
  4920. if (! exists())
  4921. {
  4922. const File parentDir (getParentDirectory());
  4923. if (parentDir == *this || ! parentDir.createDirectory())
  4924. return false;
  4925. void* const fh = juce_fileOpen (fullPath, true);
  4926. if (fh == 0)
  4927. return false;
  4928. juce_fileClose (fh);
  4929. }
  4930. return true;
  4931. }
  4932. bool File::createDirectory() const
  4933. {
  4934. if (! isDirectory())
  4935. {
  4936. const File parentDir (getParentDirectory());
  4937. if (parentDir == *this || ! parentDir.createDirectory())
  4938. return false;
  4939. String dir (fullPath);
  4940. while (dir.endsWithChar (separator))
  4941. dir [dir.length() - 1] = 0;
  4942. juce_createDirectory (dir);
  4943. return isDirectory();
  4944. }
  4945. return true;
  4946. }
  4947. const Time File::getCreationTime() const
  4948. {
  4949. int64 m, a, c;
  4950. juce_getFileTimes (fullPath, m, a, c);
  4951. return Time (c);
  4952. }
  4953. bool File::setCreationTime (const Time& t) const
  4954. {
  4955. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  4956. }
  4957. const Time File::getLastModificationTime() const
  4958. {
  4959. int64 m, a, c;
  4960. juce_getFileTimes (fullPath, m, a, c);
  4961. return Time (m);
  4962. }
  4963. bool File::setLastModificationTime (const Time& t) const
  4964. {
  4965. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  4966. }
  4967. const Time File::getLastAccessTime() const
  4968. {
  4969. int64 m, a, c;
  4970. juce_getFileTimes (fullPath, m, a, c);
  4971. return Time (a);
  4972. }
  4973. bool File::setLastAccessTime (const Time& t) const
  4974. {
  4975. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  4976. }
  4977. bool File::loadFileAsData (MemoryBlock& destBlock) const
  4978. {
  4979. if (! existsAsFile())
  4980. return false;
  4981. FileInputStream in (*this);
  4982. return getSize() == in.readIntoMemoryBlock (destBlock);
  4983. }
  4984. const String File::loadFileAsString() const
  4985. {
  4986. if (! existsAsFile())
  4987. return String::empty;
  4988. FileInputStream in (*this);
  4989. return in.readEntireStreamAsString();
  4990. }
  4991. static inline bool fileTypeMatches (const int whatToLookFor,
  4992. const bool isDir,
  4993. const bool isHidden)
  4994. {
  4995. return (whatToLookFor & (isDir ? File::findDirectories
  4996. : File::findFiles)) != 0
  4997. && ((! isHidden)
  4998. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  4999. }
  5000. int File::findChildFiles (Array<File>& results,
  5001. const int whatToLookFor,
  5002. const bool searchRecursively,
  5003. const String& wildCardPattern) const
  5004. {
  5005. // you have to specify the type of files you're looking for!
  5006. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5007. int total = 0;
  5008. // find child files or directories in this directory first..
  5009. if (isDirectory())
  5010. {
  5011. const String path (juce_addTrailingSeparator (fullPath));
  5012. String filename;
  5013. bool itemIsDirectory, itemIsHidden;
  5014. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5015. &itemIsDirectory, &itemIsHidden,
  5016. 0, 0, 0, 0);
  5017. if (handle != 0)
  5018. {
  5019. do
  5020. {
  5021. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5022. && ! filename.containsOnly ("."))
  5023. {
  5024. results.add (File (path + filename, 0));
  5025. ++total;
  5026. }
  5027. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5028. juce_findFileClose (handle);
  5029. }
  5030. }
  5031. else
  5032. {
  5033. // trying to search for files inside a non-directory?
  5034. //jassertfalse
  5035. }
  5036. // and recurse down if required.
  5037. if (searchRecursively)
  5038. {
  5039. Array<File> subDirectories;
  5040. findChildFiles (subDirectories, File::findDirectories, false);
  5041. for (int i = 0; i < subDirectories.size(); ++i)
  5042. {
  5043. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5044. true, wildCardPattern);
  5045. }
  5046. }
  5047. return total;
  5048. }
  5049. int File::getNumberOfChildFiles (const int whatToLookFor,
  5050. const String& wildCardPattern) const
  5051. {
  5052. // you have to specify the type of files you're looking for!
  5053. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5054. int count = 0;
  5055. if (isDirectory())
  5056. {
  5057. String filename;
  5058. bool itemIsDirectory, itemIsHidden;
  5059. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5060. &itemIsDirectory, &itemIsHidden,
  5061. 0, 0, 0, 0);
  5062. if (handle != 0)
  5063. {
  5064. do
  5065. {
  5066. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5067. && ! filename.containsOnly ("."))
  5068. {
  5069. ++count;
  5070. }
  5071. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5072. juce_findFileClose (handle);
  5073. }
  5074. }
  5075. else
  5076. {
  5077. // trying to search for files inside a non-directory?
  5078. jassertfalse
  5079. }
  5080. return count;
  5081. }
  5082. bool File::containsSubDirectories() const
  5083. {
  5084. bool result = false;
  5085. if (isDirectory())
  5086. {
  5087. String filename;
  5088. bool itemIsDirectory, itemIsHidden;
  5089. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5090. "*", filename,
  5091. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5092. if (handle != 0)
  5093. {
  5094. do
  5095. {
  5096. if (itemIsDirectory)
  5097. {
  5098. result = true;
  5099. break;
  5100. }
  5101. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5102. juce_findFileClose (handle);
  5103. }
  5104. }
  5105. return result;
  5106. }
  5107. const File File::getNonexistentChildFile (const String& prefix_,
  5108. const String& suffix,
  5109. bool putNumbersInBrackets) const
  5110. {
  5111. File f (getChildFile (prefix_ + suffix));
  5112. if (f.exists())
  5113. {
  5114. int num = 2;
  5115. String prefix (prefix_);
  5116. // remove any bracketed numbers that may already be on the end..
  5117. if (prefix.trim().endsWithChar (')'))
  5118. {
  5119. putNumbersInBrackets = true;
  5120. const int openBracks = prefix.lastIndexOfChar ('(');
  5121. const int closeBracks = prefix.lastIndexOfChar (')');
  5122. if (openBracks > 0
  5123. && closeBracks > openBracks
  5124. && prefix.substring (openBracks + 1, closeBracks).containsOnly ("0123456789"))
  5125. {
  5126. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5127. prefix = prefix.substring (0, openBracks);
  5128. }
  5129. }
  5130. // also use brackets if it ends in a digit.
  5131. putNumbersInBrackets = putNumbersInBrackets
  5132. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5133. do
  5134. {
  5135. if (putNumbersInBrackets)
  5136. f = getChildFile (prefix + '(' + String (num++) + ')' + suffix);
  5137. else
  5138. f = getChildFile (prefix + String (num++) + suffix);
  5139. } while (f.exists());
  5140. }
  5141. return f;
  5142. }
  5143. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5144. {
  5145. if (exists())
  5146. {
  5147. return getParentDirectory()
  5148. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5149. getFileExtension(),
  5150. putNumbersInBrackets);
  5151. }
  5152. else
  5153. {
  5154. return *this;
  5155. }
  5156. }
  5157. const String File::getFileExtension() const
  5158. {
  5159. String ext;
  5160. if (! isDirectory())
  5161. {
  5162. const int indexOfDot = fullPath.lastIndexOfChar ('.');
  5163. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5164. ext = fullPath.substring (indexOfDot);
  5165. }
  5166. return ext;
  5167. }
  5168. bool File::hasFileExtension (const String& possibleSuffix) const
  5169. {
  5170. if (possibleSuffix.isEmpty())
  5171. return fullPath.lastIndexOfChar ('.') <= fullPath.lastIndexOfChar (separator);
  5172. const int semicolon = possibleSuffix.indexOfChar (0, ';');
  5173. if (semicolon >= 0)
  5174. {
  5175. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5176. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5177. }
  5178. else
  5179. {
  5180. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5181. {
  5182. if (possibleSuffix.startsWithChar ('.'))
  5183. return true;
  5184. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5185. if (dotPos >= 0)
  5186. return fullPath [dotPos] == '.';
  5187. }
  5188. }
  5189. return false;
  5190. }
  5191. const File File::withFileExtension (const String& newExtension) const
  5192. {
  5193. if (fullPath.isEmpty())
  5194. return File::nonexistent;
  5195. String filePart (getFileName());
  5196. int i = filePart.lastIndexOfChar ('.');
  5197. if (i >= 0)
  5198. filePart = filePart.substring (0, i);
  5199. if (newExtension.isNotEmpty() && ! newExtension.startsWithChar ('.'))
  5200. filePart << '.';
  5201. return getSiblingFile (filePart + newExtension);
  5202. }
  5203. bool File::startAsProcess (const String& parameters) const
  5204. {
  5205. return exists() && juce_launchFile (fullPath, parameters);
  5206. }
  5207. FileInputStream* File::createInputStream() const
  5208. {
  5209. if (existsAsFile())
  5210. return new FileInputStream (*this);
  5211. return 0;
  5212. }
  5213. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5214. {
  5215. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5216. if (out->failedToOpen())
  5217. return 0;
  5218. return out.release();
  5219. }
  5220. bool File::appendData (const void* const dataToAppend,
  5221. const int numberOfBytes) const
  5222. {
  5223. if (numberOfBytes > 0)
  5224. {
  5225. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5226. if (out == 0)
  5227. return false;
  5228. out->write (dataToAppend, numberOfBytes);
  5229. }
  5230. return true;
  5231. }
  5232. bool File::replaceWithData (const void* const dataToWrite,
  5233. const int numberOfBytes) const
  5234. {
  5235. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5236. if (numberOfBytes <= 0)
  5237. return deleteFile();
  5238. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5239. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5240. return tempFile.overwriteTargetFileWithTemporary();
  5241. }
  5242. bool File::appendText (const String& text,
  5243. const bool asUnicode,
  5244. const bool writeUnicodeHeaderBytes) const
  5245. {
  5246. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5247. if (out != 0)
  5248. {
  5249. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5250. return true;
  5251. }
  5252. return false;
  5253. }
  5254. bool File::replaceWithText (const String& textToWrite,
  5255. const bool asUnicode,
  5256. const bool writeUnicodeHeaderBytes) const
  5257. {
  5258. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5259. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5260. return tempFile.overwriteTargetFileWithTemporary();
  5261. }
  5262. const String File::createLegalPathName (const String& original)
  5263. {
  5264. String s (original);
  5265. String start;
  5266. if (s[1] == ':')
  5267. {
  5268. start = s.substring (0, 2);
  5269. s = s.substring (2);
  5270. }
  5271. return start + s.removeCharacters ("\"#@,;:<>*^|?")
  5272. .substring (0, 1024);
  5273. }
  5274. const String File::createLegalFileName (const String& original)
  5275. {
  5276. String s (original.removeCharacters ("\"#@,;:<>*^|?\\/"));
  5277. const int maxLength = 128; // only the length of the filename, not the whole path
  5278. const int len = s.length();
  5279. if (len > maxLength)
  5280. {
  5281. const int lastDot = s.lastIndexOfChar ('.');
  5282. if (lastDot > jmax (0, len - 12))
  5283. {
  5284. s = s.substring (0, maxLength - (len - lastDot))
  5285. + s.substring (lastDot);
  5286. }
  5287. else
  5288. {
  5289. s = s.substring (0, maxLength);
  5290. }
  5291. }
  5292. return s;
  5293. }
  5294. const String File::getRelativePathFrom (const File& dir) const
  5295. {
  5296. String thisPath (fullPath);
  5297. {
  5298. int len = thisPath.length();
  5299. while (--len >= 0 && thisPath [len] == File::separator)
  5300. thisPath [len] = 0;
  5301. }
  5302. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5303. : dir.fullPath));
  5304. const int len = jmin (thisPath.length(), dirPath.length());
  5305. int commonBitLength = 0;
  5306. for (int i = 0; i < len; ++i)
  5307. {
  5308. #if NAMES_ARE_CASE_SENSITIVE
  5309. if (thisPath[i] != dirPath[i])
  5310. #else
  5311. if (CharacterFunctions::toLowerCase (thisPath[i])
  5312. != CharacterFunctions::toLowerCase (dirPath[i]))
  5313. #endif
  5314. {
  5315. break;
  5316. }
  5317. ++commonBitLength;
  5318. }
  5319. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5320. --commonBitLength;
  5321. // if the only common bit is the root, then just return the full path..
  5322. if (commonBitLength <= 0
  5323. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5324. return fullPath;
  5325. thisPath = thisPath.substring (commonBitLength);
  5326. dirPath = dirPath.substring (commonBitLength);
  5327. while (dirPath.isNotEmpty())
  5328. {
  5329. #if JUCE_WINDOWS
  5330. thisPath = "..\\" + thisPath;
  5331. #else
  5332. thisPath = "../" + thisPath;
  5333. #endif
  5334. const int sep = dirPath.indexOfChar (separator);
  5335. if (sep >= 0)
  5336. dirPath = dirPath.substring (sep + 1);
  5337. else
  5338. dirPath = String::empty;
  5339. }
  5340. return thisPath;
  5341. }
  5342. void File::findFileSystemRoots (Array<File>& destArray)
  5343. {
  5344. const StringArray roots (juce_getFileSystemRoots());
  5345. for (int i = 0; i < roots.size(); ++i)
  5346. destArray.add (File (roots[i]));
  5347. }
  5348. const String File::getVolumeLabel() const
  5349. {
  5350. int serialNum;
  5351. return juce_getVolumeLabel (fullPath, serialNum);
  5352. }
  5353. int File::getVolumeSerialNumber() const
  5354. {
  5355. int serialNum;
  5356. juce_getVolumeLabel (fullPath, serialNum);
  5357. return serialNum;
  5358. }
  5359. const File File::createTempFile (const String& fileNameEnding)
  5360. {
  5361. const File tempFile (getSpecialLocation (tempDirectory)
  5362. .getChildFile ("temp_" + String (Random::getSystemRandom().nextInt()))
  5363. .withFileExtension (fileNameEnding));
  5364. if (tempFile.exists())
  5365. return createTempFile (fileNameEnding);
  5366. else
  5367. return tempFile;
  5368. }
  5369. END_JUCE_NAMESPACE
  5370. /*** End of inlined file: juce_File.cpp ***/
  5371. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5372. BEGIN_JUCE_NAMESPACE
  5373. void* juce_fileOpen (const String& path, bool forWriting);
  5374. void juce_fileClose (void* handle);
  5375. int juce_fileRead (void* handle, void* buffer, int size);
  5376. int64 juce_fileSetPosition (void* handle, int64 pos);
  5377. FileInputStream::FileInputStream (const File& f)
  5378. : file (f),
  5379. currentPosition (0),
  5380. needToSeek (true)
  5381. {
  5382. totalSize = f.getSize();
  5383. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5384. }
  5385. FileInputStream::~FileInputStream()
  5386. {
  5387. juce_fileClose (fileHandle);
  5388. }
  5389. int64 FileInputStream::getTotalLength()
  5390. {
  5391. return totalSize;
  5392. }
  5393. int FileInputStream::read (void* buffer, int bytesToRead)
  5394. {
  5395. int num = 0;
  5396. if (needToSeek)
  5397. {
  5398. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5399. return 0;
  5400. needToSeek = false;
  5401. }
  5402. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5403. currentPosition += num;
  5404. return num;
  5405. }
  5406. bool FileInputStream::isExhausted()
  5407. {
  5408. return currentPosition >= totalSize;
  5409. }
  5410. int64 FileInputStream::getPosition()
  5411. {
  5412. return currentPosition;
  5413. }
  5414. bool FileInputStream::setPosition (int64 pos)
  5415. {
  5416. pos = jlimit ((int64) 0, totalSize, pos);
  5417. needToSeek |= (currentPosition != pos);
  5418. currentPosition = pos;
  5419. return true;
  5420. }
  5421. END_JUCE_NAMESPACE
  5422. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5423. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5424. BEGIN_JUCE_NAMESPACE
  5425. void* juce_fileOpen (const String& path, bool forWriting);
  5426. void juce_fileClose (void* handle);
  5427. int juce_fileWrite (void* handle, const void* buffer, int size);
  5428. void juce_fileFlush (void* handle);
  5429. int64 juce_fileGetPosition (void* handle);
  5430. int64 juce_fileSetPosition (void* handle, int64 pos);
  5431. FileOutputStream::FileOutputStream (const File& f,
  5432. const int bufferSize_)
  5433. : file (f),
  5434. bufferSize (bufferSize_),
  5435. bytesInBuffer (0)
  5436. {
  5437. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5438. if (fileHandle != 0)
  5439. {
  5440. currentPosition = juce_fileGetPosition (fileHandle);
  5441. if (currentPosition < 0)
  5442. {
  5443. jassertfalse
  5444. juce_fileClose (fileHandle);
  5445. fileHandle = 0;
  5446. }
  5447. }
  5448. buffer.malloc (jmax (bufferSize_, 16));
  5449. }
  5450. FileOutputStream::~FileOutputStream()
  5451. {
  5452. flush();
  5453. juce_fileClose (fileHandle);
  5454. }
  5455. int64 FileOutputStream::getPosition()
  5456. {
  5457. return currentPosition;
  5458. }
  5459. bool FileOutputStream::setPosition (int64 newPosition)
  5460. {
  5461. if (newPosition != currentPosition)
  5462. {
  5463. flush();
  5464. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5465. }
  5466. return newPosition == currentPosition;
  5467. }
  5468. void FileOutputStream::flush()
  5469. {
  5470. if (bytesInBuffer > 0)
  5471. {
  5472. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5473. bytesInBuffer = 0;
  5474. }
  5475. juce_fileFlush (fileHandle);
  5476. }
  5477. bool FileOutputStream::write (const void* const src, const int numBytes)
  5478. {
  5479. if (bytesInBuffer + numBytes < bufferSize)
  5480. {
  5481. memcpy (buffer + bytesInBuffer, src, numBytes);
  5482. bytesInBuffer += numBytes;
  5483. currentPosition += numBytes;
  5484. }
  5485. else
  5486. {
  5487. if (bytesInBuffer > 0)
  5488. {
  5489. // flush the reservoir
  5490. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5491. bytesInBuffer = 0;
  5492. if (! wroteOk)
  5493. return false;
  5494. }
  5495. if (numBytes < bufferSize)
  5496. {
  5497. memcpy (buffer + bytesInBuffer, src, numBytes);
  5498. bytesInBuffer += numBytes;
  5499. currentPosition += numBytes;
  5500. }
  5501. else
  5502. {
  5503. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5504. currentPosition += bytesWritten;
  5505. return bytesWritten == numBytes;
  5506. }
  5507. }
  5508. return true;
  5509. }
  5510. END_JUCE_NAMESPACE
  5511. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5512. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5513. BEGIN_JUCE_NAMESPACE
  5514. FileSearchPath::FileSearchPath()
  5515. {
  5516. }
  5517. FileSearchPath::FileSearchPath (const String& path)
  5518. {
  5519. init (path);
  5520. }
  5521. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5522. : directories (other.directories)
  5523. {
  5524. }
  5525. FileSearchPath::~FileSearchPath()
  5526. {
  5527. }
  5528. FileSearchPath& FileSearchPath::operator= (const String& path)
  5529. {
  5530. init (path);
  5531. return *this;
  5532. }
  5533. void FileSearchPath::init (const String& path)
  5534. {
  5535. directories.clear();
  5536. directories.addTokens (path, ";", "\"");
  5537. directories.trim();
  5538. directories.removeEmptyStrings();
  5539. for (int i = directories.size(); --i >= 0;)
  5540. directories.set (i, directories[i].unquoted());
  5541. }
  5542. int FileSearchPath::getNumPaths() const
  5543. {
  5544. return directories.size();
  5545. }
  5546. const File FileSearchPath::operator[] (const int index) const
  5547. {
  5548. return File (directories [index]);
  5549. }
  5550. const String FileSearchPath::toString() const
  5551. {
  5552. StringArray directories2 (directories);
  5553. for (int i = directories2.size(); --i >= 0;)
  5554. if (directories2[i].containsChar (';'))
  5555. directories2.set (i, directories2[i].quoted());
  5556. return directories2.joinIntoString (";");
  5557. }
  5558. void FileSearchPath::add (const File& dir, const int insertIndex)
  5559. {
  5560. directories.insert (insertIndex, dir.getFullPathName());
  5561. }
  5562. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5563. {
  5564. for (int i = 0; i < directories.size(); ++i)
  5565. if (File (directories[i]) == dir)
  5566. return;
  5567. add (dir);
  5568. }
  5569. void FileSearchPath::remove (const int index)
  5570. {
  5571. directories.remove (index);
  5572. }
  5573. void FileSearchPath::addPath (const FileSearchPath& other)
  5574. {
  5575. for (int i = 0; i < other.getNumPaths(); ++i)
  5576. addIfNotAlreadyThere (other[i]);
  5577. }
  5578. void FileSearchPath::removeRedundantPaths()
  5579. {
  5580. for (int i = directories.size(); --i >= 0;)
  5581. {
  5582. const File d1 (directories[i]);
  5583. for (int j = directories.size(); --j >= 0;)
  5584. {
  5585. const File d2 (directories[j]);
  5586. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5587. {
  5588. directories.remove (i);
  5589. break;
  5590. }
  5591. }
  5592. }
  5593. }
  5594. void FileSearchPath::removeNonExistentPaths()
  5595. {
  5596. for (int i = directories.size(); --i >= 0;)
  5597. if (! File (directories[i]).isDirectory())
  5598. directories.remove (i);
  5599. }
  5600. int FileSearchPath::findChildFiles (Array<File>& results,
  5601. const int whatToLookFor,
  5602. const bool searchRecursively,
  5603. const String& wildCardPattern) const
  5604. {
  5605. int total = 0;
  5606. for (int i = 0; i < directories.size(); ++i)
  5607. total += operator[] (i).findChildFiles (results,
  5608. whatToLookFor,
  5609. searchRecursively,
  5610. wildCardPattern);
  5611. return total;
  5612. }
  5613. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5614. const bool checkRecursively) const
  5615. {
  5616. for (int i = directories.size(); --i >= 0;)
  5617. {
  5618. const File d (directories[i]);
  5619. if (checkRecursively)
  5620. {
  5621. if (fileToCheck.isAChildOf (d))
  5622. return true;
  5623. }
  5624. else
  5625. {
  5626. if (fileToCheck.getParentDirectory() == d)
  5627. return true;
  5628. }
  5629. }
  5630. return false;
  5631. }
  5632. END_JUCE_NAMESPACE
  5633. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5634. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5635. BEGIN_JUCE_NAMESPACE
  5636. NamedPipe::NamedPipe()
  5637. : internal (0)
  5638. {
  5639. }
  5640. NamedPipe::~NamedPipe()
  5641. {
  5642. close();
  5643. }
  5644. bool NamedPipe::openExisting (const String& pipeName)
  5645. {
  5646. currentPipeName = pipeName;
  5647. return openInternal (pipeName, false);
  5648. }
  5649. bool NamedPipe::createNewPipe (const String& pipeName)
  5650. {
  5651. currentPipeName = pipeName;
  5652. return openInternal (pipeName, true);
  5653. }
  5654. bool NamedPipe::isOpen() const
  5655. {
  5656. return internal != 0;
  5657. }
  5658. const String NamedPipe::getName() const
  5659. {
  5660. return currentPipeName;
  5661. }
  5662. // other methods for this class are implemented in the platform-specific files
  5663. END_JUCE_NAMESPACE
  5664. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5665. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5666. BEGIN_JUCE_NAMESPACE
  5667. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5668. {
  5669. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5670. "temp_" + String (Random::getSystemRandom().nextInt()),
  5671. suffix,
  5672. optionFlags);
  5673. }
  5674. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5675. : targetFile (targetFile_)
  5676. {
  5677. // If you use this constructor, you need to give it a valid target file!
  5678. jassert (targetFile != File::nonexistent);
  5679. createTempFile (targetFile.getParentDirectory(),
  5680. targetFile.getFileNameWithoutExtension() + "_temp" + String (Random::getSystemRandom().nextInt()),
  5681. targetFile.getFileExtension(),
  5682. optionFlags);
  5683. }
  5684. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5685. const String& suffix, const int optionFlags)
  5686. {
  5687. if ((optionFlags & useHiddenFile) != 0)
  5688. name = "." + name;
  5689. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5690. }
  5691. TemporaryFile::~TemporaryFile()
  5692. {
  5693. // Have a few attempts at deleting the file before giving up..
  5694. for (int i = 5; --i >= 0;)
  5695. {
  5696. if (temporaryFile.deleteFile())
  5697. return;
  5698. Thread::sleep (50);
  5699. }
  5700. // Failed to delete our temporary file! Check that you've deleted all the
  5701. // file output streams that were using it!
  5702. jassertfalse;
  5703. }
  5704. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5705. {
  5706. // This method only works if you created this object with the constructor
  5707. // that takes a target file!
  5708. jassert (targetFile != File::nonexistent);
  5709. if (temporaryFile.exists())
  5710. {
  5711. // Have a few attempts at overwriting the file before giving up..
  5712. for (int i = 5; --i >= 0;)
  5713. {
  5714. if (temporaryFile.moveFileTo (targetFile))
  5715. return true;
  5716. Thread::sleep (100);
  5717. }
  5718. }
  5719. else
  5720. {
  5721. // There's no temporary file to use. If your write failed, you should
  5722. // probably check, and not bother calling this method.
  5723. jassertfalse
  5724. }
  5725. return false;
  5726. }
  5727. END_JUCE_NAMESPACE
  5728. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5729. /*** Start of inlined file: juce_Socket.cpp ***/
  5730. #if JUCE_WINDOWS
  5731. #include <winsock2.h>
  5732. #ifdef _MSC_VER
  5733. #pragma warning (disable : 4127 4389 4018)
  5734. #endif
  5735. #else
  5736. #if JUCE_LINUX
  5737. #include <sys/types.h>
  5738. #include <sys/socket.h>
  5739. #include <sys/errno.h>
  5740. #include <unistd.h>
  5741. #include <netinet/in.h>
  5742. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5743. #include <CoreServices/CoreServices.h>
  5744. #endif
  5745. #include <fcntl.h>
  5746. #include <netdb.h>
  5747. #include <arpa/inet.h>
  5748. #include <netinet/tcp.h>
  5749. #endif
  5750. BEGIN_JUCE_NAMESPACE
  5751. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5752. typedef socklen_t juce_socklen_t;
  5753. #else
  5754. typedef int juce_socklen_t;
  5755. #endif
  5756. #if JUCE_WINDOWS
  5757. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5758. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5759. static void initWin32Sockets()
  5760. {
  5761. static CriticalSection lock;
  5762. const ScopedLock sl (lock);
  5763. if (juce_CloseWin32SocketLib == 0)
  5764. {
  5765. WSADATA wsaData;
  5766. const WORD wVersionRequested = MAKEWORD (1, 1);
  5767. WSAStartup (wVersionRequested, &wsaData);
  5768. juce_CloseWin32SocketLib = &WSACleanup;
  5769. }
  5770. }
  5771. #endif
  5772. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5773. {
  5774. const int sndBufSize = 65536;
  5775. const int rcvBufSize = 65536;
  5776. const int one = 1;
  5777. return handle > 0
  5778. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5779. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5780. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5781. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5782. }
  5783. static bool bindSocketToPort (const int handle, const int port) throw()
  5784. {
  5785. if (handle <= 0 || port <= 0)
  5786. return false;
  5787. struct sockaddr_in servTmpAddr;
  5788. zerostruct (servTmpAddr);
  5789. servTmpAddr.sin_family = PF_INET;
  5790. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5791. servTmpAddr.sin_port = htons ((uint16) port);
  5792. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5793. }
  5794. static int readSocket (const int handle,
  5795. void* const destBuffer, const int maxBytesToRead,
  5796. bool volatile& connected,
  5797. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5798. {
  5799. int bytesRead = 0;
  5800. while (bytesRead < maxBytesToRead)
  5801. {
  5802. int bytesThisTime;
  5803. #if JUCE_WINDOWS
  5804. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5805. #else
  5806. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5807. && errno == EINTR
  5808. && connected)
  5809. {
  5810. }
  5811. #endif
  5812. if (bytesThisTime <= 0 || ! connected)
  5813. {
  5814. if (bytesRead == 0)
  5815. bytesRead = -1;
  5816. break;
  5817. }
  5818. bytesRead += bytesThisTime;
  5819. if (! blockUntilSpecifiedAmountHasArrived)
  5820. break;
  5821. }
  5822. return bytesRead;
  5823. }
  5824. static int waitForReadiness (const int handle, const bool forReading,
  5825. const int timeoutMsecs) throw()
  5826. {
  5827. struct timeval timeout;
  5828. struct timeval* timeoutp;
  5829. if (timeoutMsecs >= 0)
  5830. {
  5831. timeout.tv_sec = timeoutMsecs / 1000;
  5832. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5833. timeoutp = &timeout;
  5834. }
  5835. else
  5836. {
  5837. timeoutp = 0;
  5838. }
  5839. fd_set rset, wset;
  5840. FD_ZERO (&rset);
  5841. FD_SET (handle, &rset);
  5842. FD_ZERO (&wset);
  5843. FD_SET (handle, &wset);
  5844. fd_set* const prset = forReading ? &rset : 0;
  5845. fd_set* const pwset = forReading ? 0 : &wset;
  5846. #if JUCE_WINDOWS
  5847. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5848. return -1;
  5849. #else
  5850. {
  5851. int result;
  5852. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5853. && errno == EINTR)
  5854. {
  5855. }
  5856. if (result < 0)
  5857. return -1;
  5858. }
  5859. #endif
  5860. {
  5861. int opt;
  5862. juce_socklen_t len = sizeof (opt);
  5863. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5864. || opt != 0)
  5865. return -1;
  5866. }
  5867. if ((forReading && FD_ISSET (handle, &rset))
  5868. || ((! forReading) && FD_ISSET (handle, &wset)))
  5869. return 1;
  5870. return 0;
  5871. }
  5872. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5873. {
  5874. #if JUCE_WINDOWS
  5875. u_long nonBlocking = shouldBlock ? 0 : 1;
  5876. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5877. return false;
  5878. #else
  5879. int socketFlags = fcntl (handle, F_GETFL, 0);
  5880. if (socketFlags == -1)
  5881. return false;
  5882. if (shouldBlock)
  5883. socketFlags &= ~O_NONBLOCK;
  5884. else
  5885. socketFlags |= O_NONBLOCK;
  5886. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5887. return false;
  5888. #endif
  5889. return true;
  5890. }
  5891. static bool connectSocket (int volatile& handle,
  5892. const bool isDatagram,
  5893. void** serverAddress,
  5894. const String& hostName,
  5895. const int portNumber,
  5896. const int timeOutMillisecs) throw()
  5897. {
  5898. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  5899. if (hostEnt == 0)
  5900. return false;
  5901. struct in_addr targetAddress;
  5902. memcpy (&targetAddress.s_addr,
  5903. *(hostEnt->h_addr_list),
  5904. sizeof (targetAddress.s_addr));
  5905. struct sockaddr_in servTmpAddr;
  5906. zerostruct (servTmpAddr);
  5907. servTmpAddr.sin_family = PF_INET;
  5908. servTmpAddr.sin_addr = targetAddress;
  5909. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5910. if (handle < 0)
  5911. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5912. if (handle < 0)
  5913. return false;
  5914. if (isDatagram)
  5915. {
  5916. *serverAddress = new struct sockaddr_in();
  5917. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5918. return true;
  5919. }
  5920. setSocketBlockingState (handle, false);
  5921. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  5922. if (result < 0)
  5923. {
  5924. #if JUCE_WINDOWS
  5925. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  5926. #else
  5927. if (errno == EINPROGRESS)
  5928. #endif
  5929. {
  5930. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  5931. {
  5932. setSocketBlockingState (handle, true);
  5933. return false;
  5934. }
  5935. }
  5936. }
  5937. setSocketBlockingState (handle, true);
  5938. resetSocketOptions (handle, false, false);
  5939. return true;
  5940. }
  5941. StreamingSocket::StreamingSocket()
  5942. : portNumber (0),
  5943. handle (-1),
  5944. connected (false),
  5945. isListener (false)
  5946. {
  5947. #if JUCE_WINDOWS
  5948. initWin32Sockets();
  5949. #endif
  5950. }
  5951. StreamingSocket::StreamingSocket (const String& hostName_,
  5952. const int portNumber_,
  5953. const int handle_)
  5954. : hostName (hostName_),
  5955. portNumber (portNumber_),
  5956. handle (handle_),
  5957. connected (true),
  5958. isListener (false)
  5959. {
  5960. #if JUCE_WINDOWS
  5961. initWin32Sockets();
  5962. #endif
  5963. resetSocketOptions (handle_, false, false);
  5964. }
  5965. StreamingSocket::~StreamingSocket()
  5966. {
  5967. close();
  5968. }
  5969. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  5970. {
  5971. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  5972. : -1;
  5973. }
  5974. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  5975. {
  5976. if (isListener || ! connected)
  5977. return -1;
  5978. #if JUCE_WINDOWS
  5979. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  5980. #else
  5981. int result;
  5982. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  5983. && errno == EINTR)
  5984. {
  5985. }
  5986. return result;
  5987. #endif
  5988. }
  5989. int StreamingSocket::waitUntilReady (const bool readyForReading,
  5990. const int timeoutMsecs) const
  5991. {
  5992. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  5993. : -1;
  5994. }
  5995. bool StreamingSocket::bindToPort (const int port)
  5996. {
  5997. return bindSocketToPort (handle, port);
  5998. }
  5999. bool StreamingSocket::connect (const String& remoteHostName,
  6000. const int remotePortNumber,
  6001. const int timeOutMillisecs)
  6002. {
  6003. if (isListener)
  6004. {
  6005. jassertfalse // a listener socket can't connect to another one!
  6006. return false;
  6007. }
  6008. if (connected)
  6009. close();
  6010. hostName = remoteHostName;
  6011. portNumber = remotePortNumber;
  6012. isListener = false;
  6013. connected = connectSocket (handle, false, 0, remoteHostName,
  6014. remotePortNumber, timeOutMillisecs);
  6015. if (! (connected && resetSocketOptions (handle, false, false)))
  6016. {
  6017. close();
  6018. return false;
  6019. }
  6020. return true;
  6021. }
  6022. void StreamingSocket::close()
  6023. {
  6024. #if JUCE_WINDOWS
  6025. closesocket (handle);
  6026. connected = false;
  6027. #else
  6028. if (connected)
  6029. {
  6030. connected = false;
  6031. if (isListener)
  6032. {
  6033. // need to do this to interrupt the accept() function..
  6034. StreamingSocket temp;
  6035. temp.connect ("localhost", portNumber, 1000);
  6036. }
  6037. }
  6038. ::close (handle);
  6039. #endif
  6040. hostName = String::empty;
  6041. portNumber = 0;
  6042. handle = -1;
  6043. isListener = false;
  6044. }
  6045. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6046. {
  6047. if (connected)
  6048. close();
  6049. hostName = "listener";
  6050. portNumber = newPortNumber;
  6051. isListener = true;
  6052. struct sockaddr_in servTmpAddr;
  6053. zerostruct (servTmpAddr);
  6054. servTmpAddr.sin_family = PF_INET;
  6055. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6056. if (localHostName.isNotEmpty())
  6057. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6058. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6059. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6060. if (handle < 0)
  6061. return false;
  6062. const int reuse = 1;
  6063. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6064. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6065. || listen (handle, SOMAXCONN) < 0)
  6066. {
  6067. close();
  6068. return false;
  6069. }
  6070. connected = true;
  6071. return true;
  6072. }
  6073. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6074. {
  6075. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6076. // prepare this socket as a listener.
  6077. if (connected && isListener)
  6078. {
  6079. struct sockaddr address;
  6080. juce_socklen_t len = sizeof (sockaddr);
  6081. const int newSocket = (int) accept (handle, &address, &len);
  6082. if (newSocket >= 0 && connected)
  6083. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6084. portNumber, newSocket);
  6085. }
  6086. return 0;
  6087. }
  6088. bool StreamingSocket::isLocal() const throw()
  6089. {
  6090. return hostName == "127.0.0.1";
  6091. }
  6092. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6093. : portNumber (0),
  6094. handle (-1),
  6095. connected (true),
  6096. allowBroadcast (allowBroadcast_),
  6097. serverAddress (0)
  6098. {
  6099. #if JUCE_WINDOWS
  6100. initWin32Sockets();
  6101. #endif
  6102. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6103. bindToPort (localPortNumber);
  6104. }
  6105. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6106. const int handle_, const int localPortNumber)
  6107. : hostName (hostName_),
  6108. portNumber (portNumber_),
  6109. handle (handle_),
  6110. connected (true),
  6111. allowBroadcast (false),
  6112. serverAddress (0)
  6113. {
  6114. #if JUCE_WINDOWS
  6115. initWin32Sockets();
  6116. #endif
  6117. resetSocketOptions (handle_, true, allowBroadcast);
  6118. bindToPort (localPortNumber);
  6119. }
  6120. DatagramSocket::~DatagramSocket()
  6121. {
  6122. close();
  6123. delete ((struct sockaddr_in*) serverAddress);
  6124. serverAddress = 0;
  6125. }
  6126. void DatagramSocket::close()
  6127. {
  6128. #if JUCE_WINDOWS
  6129. closesocket (handle);
  6130. connected = false;
  6131. #else
  6132. connected = false;
  6133. ::close (handle);
  6134. #endif
  6135. hostName = String::empty;
  6136. portNumber = 0;
  6137. handle = -1;
  6138. }
  6139. bool DatagramSocket::bindToPort (const int port)
  6140. {
  6141. return bindSocketToPort (handle, port);
  6142. }
  6143. bool DatagramSocket::connect (const String& remoteHostName,
  6144. const int remotePortNumber,
  6145. const int timeOutMillisecs)
  6146. {
  6147. if (connected)
  6148. close();
  6149. hostName = remoteHostName;
  6150. portNumber = remotePortNumber;
  6151. connected = connectSocket (handle, true, &serverAddress,
  6152. remoteHostName, remotePortNumber,
  6153. timeOutMillisecs);
  6154. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6155. {
  6156. close();
  6157. return false;
  6158. }
  6159. return true;
  6160. }
  6161. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6162. {
  6163. struct sockaddr address;
  6164. juce_socklen_t len = sizeof (sockaddr);
  6165. while (waitUntilReady (true, -1) == 1)
  6166. {
  6167. char buf[1];
  6168. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6169. {
  6170. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6171. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6172. -1, -1);
  6173. }
  6174. }
  6175. return 0;
  6176. }
  6177. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6178. const int timeoutMsecs) const
  6179. {
  6180. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6181. : -1;
  6182. }
  6183. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6184. {
  6185. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6186. : -1;
  6187. }
  6188. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6189. {
  6190. // You need to call connect() first to set the server address..
  6191. jassert (serverAddress != 0 && connected);
  6192. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6193. numBytesToWrite, 0,
  6194. (const struct sockaddr*) serverAddress,
  6195. sizeof (struct sockaddr_in))
  6196. : -1;
  6197. }
  6198. bool DatagramSocket::isLocal() const throw()
  6199. {
  6200. return hostName == "127.0.0.1";
  6201. }
  6202. END_JUCE_NAMESPACE
  6203. /*** End of inlined file: juce_Socket.cpp ***/
  6204. /*** Start of inlined file: juce_URL.cpp ***/
  6205. BEGIN_JUCE_NAMESPACE
  6206. URL::URL()
  6207. {
  6208. }
  6209. URL::URL (const String& url_)
  6210. : url (url_)
  6211. {
  6212. int i = url.indexOfChar ('?');
  6213. if (i >= 0)
  6214. {
  6215. do
  6216. {
  6217. const int nextAmp = url.indexOfChar (i + 1, '&');
  6218. const int equalsPos = url.indexOfChar (i + 1, '=');
  6219. if (equalsPos > i + 1)
  6220. {
  6221. if (nextAmp < 0)
  6222. {
  6223. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6224. removeEscapeChars (url.substring (equalsPos + 1)));
  6225. }
  6226. else if (nextAmp > 0 && equalsPos < nextAmp)
  6227. {
  6228. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6229. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6230. }
  6231. }
  6232. i = nextAmp;
  6233. }
  6234. while (i >= 0);
  6235. url = url.upToFirstOccurrenceOf ("?", false, false);
  6236. }
  6237. }
  6238. URL::URL (const URL& other)
  6239. : url (other.url),
  6240. postData (other.postData),
  6241. parameters (other.parameters),
  6242. filesToUpload (other.filesToUpload),
  6243. mimeTypes (other.mimeTypes)
  6244. {
  6245. }
  6246. URL& URL::operator= (const URL& other)
  6247. {
  6248. url = other.url;
  6249. postData = other.postData;
  6250. parameters = other.parameters;
  6251. filesToUpload = other.filesToUpload;
  6252. mimeTypes = other.mimeTypes;
  6253. return *this;
  6254. }
  6255. URL::~URL()
  6256. {
  6257. }
  6258. static const String getMangledParameters (const StringPairArray& parameters)
  6259. {
  6260. String p;
  6261. for (int i = 0; i < parameters.size(); ++i)
  6262. {
  6263. if (i > 0)
  6264. p += '&';
  6265. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6266. << '='
  6267. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6268. }
  6269. return p;
  6270. }
  6271. const String URL::toString (const bool includeGetParameters) const
  6272. {
  6273. if (includeGetParameters && parameters.size() > 0)
  6274. return url + "?" + getMangledParameters (parameters);
  6275. else
  6276. return url;
  6277. }
  6278. bool URL::isWellFormed() const
  6279. {
  6280. //xxx TODO
  6281. return url.isNotEmpty();
  6282. }
  6283. static int findStartOfDomain (const String& url)
  6284. {
  6285. int i = 0;
  6286. while (CharacterFunctions::isLetterOrDigit (url[i])
  6287. || CharacterFunctions::indexOfChar (L"+-.", url[i], false) >= 0)
  6288. ++i;
  6289. return url[i] == ':' ? i + 1 : 0;
  6290. }
  6291. const String URL::getDomain() const
  6292. {
  6293. int start = findStartOfDomain (url);
  6294. while (url[start] == '/')
  6295. ++start;
  6296. const int end1 = url.indexOfChar (start, '/');
  6297. const int end2 = url.indexOfChar (start, ':');
  6298. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6299. : jmin (end1, end2);
  6300. return url.substring (start, end);
  6301. }
  6302. const String URL::getSubPath() const
  6303. {
  6304. int start = findStartOfDomain (url);
  6305. while (url[start] == '/')
  6306. ++start;
  6307. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6308. return startOfPath <= 0 ? String::empty
  6309. : url.substring (startOfPath);
  6310. }
  6311. const String URL::getScheme() const
  6312. {
  6313. return url.substring (0, findStartOfDomain (url) - 1);
  6314. }
  6315. const URL URL::withNewSubPath (const String& newPath) const
  6316. {
  6317. int start = findStartOfDomain (url);
  6318. while (url[start] == '/')
  6319. ++start;
  6320. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6321. URL u (*this);
  6322. if (startOfPath > 0)
  6323. u.url = url.substring (0, startOfPath);
  6324. if (! u.url.endsWithChar ('/'))
  6325. u.url << '/';
  6326. if (newPath.startsWithChar ('/'))
  6327. u.url << newPath.substring (1);
  6328. else
  6329. u.url << newPath;
  6330. return u;
  6331. }
  6332. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6333. {
  6334. if (possibleURL.startsWithIgnoreCase ("http:")
  6335. || possibleURL.startsWithIgnoreCase ("ftp:"))
  6336. return true;
  6337. if (possibleURL.startsWithIgnoreCase ("file:")
  6338. || possibleURL.containsChar ('@')
  6339. || possibleURL.endsWithChar ('.')
  6340. || (! possibleURL.containsChar ('.')))
  6341. return false;
  6342. if (possibleURL.startsWithIgnoreCase ("www.")
  6343. && possibleURL.substring (5).containsChar ('.'))
  6344. return true;
  6345. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6346. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6347. if ((possibleURL + "/").containsIgnoreCase ("." + String (commonTLDs[i]) + "/"))
  6348. return true;
  6349. return false;
  6350. }
  6351. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6352. {
  6353. const int atSign = possibleEmailAddress.indexOfChar ('@');
  6354. return atSign > 0
  6355. && possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1)
  6356. && (! possibleEmailAddress.endsWithChar ('.'));
  6357. }
  6358. void* juce_openInternetFile (const String& url,
  6359. const String& headers,
  6360. const MemoryBlock& optionalPostData,
  6361. const bool isPost,
  6362. URL::OpenStreamProgressCallback* callback,
  6363. void* callbackContext,
  6364. int timeOutMs);
  6365. void juce_closeInternetFile (void* handle);
  6366. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6367. int juce_seekInInternetFile (void* handle, int newPosition);
  6368. int64 juce_getInternetFileContentLength (void* handle);
  6369. class WebInputStream : public InputStream
  6370. {
  6371. public:
  6372. WebInputStream (const URL& url,
  6373. const bool isPost_,
  6374. URL::OpenStreamProgressCallback* const progressCallback_,
  6375. void* const progressCallbackContext_,
  6376. const String& extraHeaders,
  6377. int timeOutMs_)
  6378. : position (0),
  6379. finished (false),
  6380. isPost (isPost_),
  6381. progressCallback (progressCallback_),
  6382. progressCallbackContext (progressCallbackContext_),
  6383. timeOutMs (timeOutMs_)
  6384. {
  6385. server = url.toString (! isPost);
  6386. if (isPost_)
  6387. createHeadersAndPostData (url);
  6388. headers += extraHeaders;
  6389. if (! headers.endsWithChar ('\n'))
  6390. headers << "\r\n";
  6391. handle = juce_openInternetFile (server, headers, postData, isPost,
  6392. progressCallback_, progressCallbackContext_,
  6393. timeOutMs);
  6394. }
  6395. ~WebInputStream()
  6396. {
  6397. juce_closeInternetFile (handle);
  6398. }
  6399. bool isError() const
  6400. {
  6401. return handle == 0;
  6402. }
  6403. int64 getTotalLength()
  6404. {
  6405. return juce_getInternetFileContentLength (handle);
  6406. }
  6407. bool isExhausted()
  6408. {
  6409. return finished;
  6410. }
  6411. int read (void* dest, int bytes)
  6412. {
  6413. if (finished || isError())
  6414. {
  6415. return 0;
  6416. }
  6417. else
  6418. {
  6419. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6420. position += bytesRead;
  6421. if (bytesRead == 0)
  6422. finished = true;
  6423. return bytesRead;
  6424. }
  6425. }
  6426. int64 getPosition()
  6427. {
  6428. return position;
  6429. }
  6430. bool setPosition (int64 wantedPos)
  6431. {
  6432. if (wantedPos != position)
  6433. {
  6434. finished = false;
  6435. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6436. if (actualPos == wantedPos)
  6437. {
  6438. position = wantedPos;
  6439. }
  6440. else
  6441. {
  6442. if (wantedPos < position)
  6443. {
  6444. juce_closeInternetFile (handle);
  6445. position = 0;
  6446. finished = false;
  6447. handle = juce_openInternetFile (server, headers, postData, isPost,
  6448. progressCallback, progressCallbackContext,
  6449. timeOutMs);
  6450. }
  6451. skipNextBytes (wantedPos - position);
  6452. }
  6453. }
  6454. return true;
  6455. }
  6456. juce_UseDebuggingNewOperator
  6457. private:
  6458. String server, headers;
  6459. MemoryBlock postData;
  6460. int64 position;
  6461. bool finished;
  6462. const bool isPost;
  6463. void* handle;
  6464. URL::OpenStreamProgressCallback* const progressCallback;
  6465. void* const progressCallbackContext;
  6466. const int timeOutMs;
  6467. void createHeadersAndPostData (const URL& url)
  6468. {
  6469. if (url.getFilesToUpload().size() > 0)
  6470. {
  6471. // need to upload some files, so do it as multi-part...
  6472. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6473. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6474. appendUTF8ToPostData ("--" + boundary);
  6475. int i;
  6476. for (i = 0; i < url.getParameters().size(); ++i)
  6477. {
  6478. String s;
  6479. s << "\r\nContent-Disposition: form-data; name=\""
  6480. << url.getParameters().getAllKeys() [i]
  6481. << "\"\r\n\r\n"
  6482. << url.getParameters().getAllValues() [i]
  6483. << "\r\n--"
  6484. << boundary;
  6485. appendUTF8ToPostData (s);
  6486. }
  6487. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6488. {
  6489. const File f (url.getFilesToUpload().getAllValues() [i]);
  6490. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6491. String s;
  6492. s << "\r\nContent-Disposition: form-data; name=\""
  6493. << paramName
  6494. << "\"; filename=\""
  6495. << f.getFileName()
  6496. << "\"\r\n";
  6497. const String mimeType (url.getMimeTypesOfUploadFiles()
  6498. .getValue (paramName, String::empty));
  6499. if (mimeType.isNotEmpty())
  6500. s << "Content-Type: " << mimeType << "\r\n";
  6501. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6502. appendUTF8ToPostData (s);
  6503. f.loadFileAsData (postData);
  6504. s = "\r\n--" + boundary;
  6505. appendUTF8ToPostData (s);
  6506. }
  6507. appendUTF8ToPostData ("--\r\n");
  6508. }
  6509. else
  6510. {
  6511. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6512. appendUTF8ToPostData (url.getPostData());
  6513. // just a short text attachment, so use simple url encoding..
  6514. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6515. + String ((unsigned int) postData.getSize())
  6516. + "\r\n";
  6517. }
  6518. }
  6519. void appendUTF8ToPostData (const String& text)
  6520. {
  6521. postData.append (text.toUTF8(),
  6522. (int) strlen (text.toUTF8()));
  6523. }
  6524. WebInputStream (const WebInputStream&);
  6525. WebInputStream& operator= (const WebInputStream&);
  6526. };
  6527. InputStream* URL::createInputStream (const bool usePostCommand,
  6528. OpenStreamProgressCallback* const progressCallback,
  6529. void* const progressCallbackContext,
  6530. const String& extraHeaders,
  6531. const int timeOutMs) const
  6532. {
  6533. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6534. progressCallback, progressCallbackContext,
  6535. extraHeaders,
  6536. timeOutMs));
  6537. return wi->isError() ? 0 : wi.release();
  6538. }
  6539. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6540. const bool usePostCommand) const
  6541. {
  6542. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6543. if (in != 0)
  6544. {
  6545. in->readIntoMemoryBlock (destData, -1);
  6546. return true;
  6547. }
  6548. return false;
  6549. }
  6550. const String URL::readEntireTextStream (const bool usePostCommand) const
  6551. {
  6552. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6553. if (in != 0)
  6554. return in->readEntireStreamAsString();
  6555. return String::empty;
  6556. }
  6557. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6558. {
  6559. XmlDocument doc (readEntireTextStream (usePostCommand));
  6560. return doc.getDocumentElement();
  6561. }
  6562. const URL URL::withParameter (const String& parameterName,
  6563. const String& parameterValue) const
  6564. {
  6565. URL u (*this);
  6566. u.parameters.set (parameterName, parameterValue);
  6567. return u;
  6568. }
  6569. const URL URL::withFileToUpload (const String& parameterName,
  6570. const File& fileToUpload,
  6571. const String& mimeType) const
  6572. {
  6573. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6574. URL u (*this);
  6575. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6576. u.mimeTypes.set (parameterName, mimeType);
  6577. return u;
  6578. }
  6579. const URL URL::withPOSTData (const String& postData_) const
  6580. {
  6581. URL u (*this);
  6582. u.postData = postData_;
  6583. return u;
  6584. }
  6585. const StringPairArray& URL::getParameters() const
  6586. {
  6587. return parameters;
  6588. }
  6589. const StringPairArray& URL::getFilesToUpload() const
  6590. {
  6591. return filesToUpload;
  6592. }
  6593. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6594. {
  6595. return mimeTypes;
  6596. }
  6597. const String URL::removeEscapeChars (const String& s)
  6598. {
  6599. String result (s.replaceCharacter ('+', ' '));
  6600. int nextPercent = 0;
  6601. for (;;)
  6602. {
  6603. nextPercent = result.indexOfChar (nextPercent, '%');
  6604. if (nextPercent < 0)
  6605. break;
  6606. juce_wchar replacementChar = result.substring (nextPercent + 1, nextPercent + 3).getHexValue32();
  6607. result = result.replaceSection (nextPercent, 3, String::charToString (replacementChar));
  6608. ++nextPercent;
  6609. }
  6610. return result;
  6611. }
  6612. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6613. {
  6614. String result;
  6615. result.preallocateStorage (s.length() + 8);
  6616. const char* utf8 = s.toUTF8();
  6617. const char* legalChars = isParameter ? "_-.*!'()"
  6618. : "_-$.*!'(),";
  6619. while (*utf8 != 0)
  6620. {
  6621. const char c = *utf8++;
  6622. if (CharacterFunctions::isLetterOrDigit (c)
  6623. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6624. {
  6625. result << c;
  6626. }
  6627. else
  6628. {
  6629. const int v = (int) (uint8) c;
  6630. result << (v < 0x10 ? "%0" : "%") << String::toHexString (v);
  6631. }
  6632. }
  6633. return result;
  6634. }
  6635. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6636. bool URL::launchInDefaultBrowser() const
  6637. {
  6638. String u (toString (true));
  6639. if (u.containsChar ('@') && ! u.containsChar (':'))
  6640. u = "mailto:" + u;
  6641. return juce_launchFile (u, String::empty);
  6642. }
  6643. END_JUCE_NAMESPACE
  6644. /*** End of inlined file: juce_URL.cpp ***/
  6645. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6646. BEGIN_JUCE_NAMESPACE
  6647. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6648. const int bufferSize_,
  6649. const bool deleteSourceWhenDestroyed)
  6650. : source (source_),
  6651. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6652. bufferSize (jmax (256, bufferSize_)),
  6653. position (source_->getPosition()),
  6654. lastReadPos (0),
  6655. bufferOverlap (128)
  6656. {
  6657. const int sourceSize = (int) source_->getTotalLength();
  6658. if (sourceSize >= 0)
  6659. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6660. bufferStart = position;
  6661. buffer.malloc (bufferSize);
  6662. }
  6663. BufferedInputStream::~BufferedInputStream()
  6664. {
  6665. }
  6666. int64 BufferedInputStream::getTotalLength()
  6667. {
  6668. return source->getTotalLength();
  6669. }
  6670. int64 BufferedInputStream::getPosition()
  6671. {
  6672. return position;
  6673. }
  6674. bool BufferedInputStream::setPosition (int64 newPosition)
  6675. {
  6676. position = jmax ((int64) 0, newPosition);
  6677. return true;
  6678. }
  6679. bool BufferedInputStream::isExhausted()
  6680. {
  6681. return (position >= lastReadPos)
  6682. && source->isExhausted();
  6683. }
  6684. void BufferedInputStream::ensureBuffered()
  6685. {
  6686. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6687. if (position < bufferStart || position >= bufferEndOverlap)
  6688. {
  6689. int bytesRead;
  6690. if (position < lastReadPos
  6691. && position >= bufferEndOverlap
  6692. && position >= bufferStart)
  6693. {
  6694. const int bytesToKeep = (int) (lastReadPos - position);
  6695. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6696. bufferStart = position;
  6697. bytesRead = source->read (buffer + bytesToKeep,
  6698. bufferSize - bytesToKeep);
  6699. lastReadPos += bytesRead;
  6700. bytesRead += bytesToKeep;
  6701. }
  6702. else
  6703. {
  6704. bufferStart = position;
  6705. source->setPosition (bufferStart);
  6706. bytesRead = source->read (buffer, bufferSize);
  6707. lastReadPos = bufferStart + bytesRead;
  6708. }
  6709. while (bytesRead < bufferSize)
  6710. buffer [bytesRead++] = 0;
  6711. }
  6712. }
  6713. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6714. {
  6715. if (position >= bufferStart
  6716. && position + maxBytesToRead <= lastReadPos)
  6717. {
  6718. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6719. position += maxBytesToRead;
  6720. return maxBytesToRead;
  6721. }
  6722. else
  6723. {
  6724. if (position < bufferStart || position >= lastReadPos)
  6725. ensureBuffered();
  6726. int bytesRead = 0;
  6727. while (maxBytesToRead > 0)
  6728. {
  6729. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6730. if (bytesAvailable > 0)
  6731. {
  6732. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6733. maxBytesToRead -= bytesAvailable;
  6734. bytesRead += bytesAvailable;
  6735. position += bytesAvailable;
  6736. destBuffer = static_cast <char*> (destBuffer) + bytesAvailable;
  6737. }
  6738. const int64 oldLastReadPos = lastReadPos;
  6739. ensureBuffered();
  6740. if (oldLastReadPos == lastReadPos)
  6741. break; // if ensureBuffered() failed to read any more data, bail out
  6742. if (isExhausted())
  6743. break;
  6744. }
  6745. return bytesRead;
  6746. }
  6747. }
  6748. const String BufferedInputStream::readString()
  6749. {
  6750. if (position >= bufferStart
  6751. && position < lastReadPos)
  6752. {
  6753. const int maxChars = (int) (lastReadPos - position);
  6754. const char* const src = buffer + (int) (position - bufferStart);
  6755. for (int i = 0; i < maxChars; ++i)
  6756. {
  6757. if (src[i] == 0)
  6758. {
  6759. position += i + 1;
  6760. return String::fromUTF8 (src, i);
  6761. }
  6762. }
  6763. }
  6764. return InputStream::readString();
  6765. }
  6766. END_JUCE_NAMESPACE
  6767. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6768. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6769. BEGIN_JUCE_NAMESPACE
  6770. FileInputSource::FileInputSource (const File& file_)
  6771. : file (file_)
  6772. {
  6773. }
  6774. FileInputSource::~FileInputSource()
  6775. {
  6776. }
  6777. InputStream* FileInputSource::createInputStream()
  6778. {
  6779. return file.createInputStream();
  6780. }
  6781. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6782. {
  6783. return file.getSiblingFile (relatedItemPath).createInputStream();
  6784. }
  6785. int64 FileInputSource::hashCode() const
  6786. {
  6787. return file.hashCode();
  6788. }
  6789. END_JUCE_NAMESPACE
  6790. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6791. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6792. BEGIN_JUCE_NAMESPACE
  6793. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6794. const size_t sourceDataSize,
  6795. const bool keepInternalCopy)
  6796. : data (static_cast <const char*> (sourceData)),
  6797. dataSize (sourceDataSize),
  6798. position (0)
  6799. {
  6800. if (keepInternalCopy)
  6801. {
  6802. internalCopy.append (data, sourceDataSize);
  6803. data = static_cast <const char*> (internalCopy.getData());
  6804. }
  6805. }
  6806. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  6807. const bool keepInternalCopy)
  6808. : data (static_cast <const char*> (sourceData.getData())),
  6809. dataSize (sourceData.getSize()),
  6810. position (0)
  6811. {
  6812. if (keepInternalCopy)
  6813. {
  6814. internalCopy = sourceData;
  6815. data = static_cast <const char*> (internalCopy.getData());
  6816. }
  6817. }
  6818. MemoryInputStream::~MemoryInputStream()
  6819. {
  6820. }
  6821. int64 MemoryInputStream::getTotalLength()
  6822. {
  6823. return dataSize;
  6824. }
  6825. int MemoryInputStream::read (void* const buffer, const int howMany)
  6826. {
  6827. jassert (howMany >= 0);
  6828. const int num = jmin (howMany, (int) (dataSize - position));
  6829. memcpy (buffer, data + position, num);
  6830. position += num;
  6831. return (int) num;
  6832. }
  6833. bool MemoryInputStream::isExhausted()
  6834. {
  6835. return (position >= dataSize);
  6836. }
  6837. bool MemoryInputStream::setPosition (const int64 pos)
  6838. {
  6839. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6840. return true;
  6841. }
  6842. int64 MemoryInputStream::getPosition()
  6843. {
  6844. return position;
  6845. }
  6846. END_JUCE_NAMESPACE
  6847. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  6848. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  6849. BEGIN_JUCE_NAMESPACE
  6850. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6851. const size_t blockSizeToIncreaseBy,
  6852. MemoryBlock* const memoryBlockToWriteTo)
  6853. : data (memoryBlockToWriteTo),
  6854. position (0),
  6855. size (0),
  6856. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6857. {
  6858. if (data == 0)
  6859. dataToDelete = data = new MemoryBlock (initialSize);
  6860. else
  6861. data->setSize (initialSize, false);
  6862. }
  6863. MemoryOutputStream::~MemoryOutputStream()
  6864. {
  6865. flush();
  6866. }
  6867. void MemoryOutputStream::flush()
  6868. {
  6869. if (dataToDelete == 0)
  6870. data->setSize (size, false);
  6871. }
  6872. void MemoryOutputStream::reset() throw()
  6873. {
  6874. position = 0;
  6875. size = 0;
  6876. }
  6877. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  6878. {
  6879. if (howMany > 0)
  6880. {
  6881. size_t storageNeeded = position + howMany;
  6882. if (storageNeeded >= data->getSize())
  6883. {
  6884. // if we need more space, increase the block by at least 10%..
  6885. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6886. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6887. data->ensureSize (storageNeeded);
  6888. }
  6889. data->copyFrom (buffer, (int) position, howMany);
  6890. position += howMany;
  6891. size = jmax (size, position);
  6892. }
  6893. return true;
  6894. }
  6895. const char* MemoryOutputStream::getData() const throw()
  6896. {
  6897. char* const d = static_cast <char*> (data->getData());
  6898. if (data->getSize() > size)
  6899. d [size] = 0;
  6900. return d;
  6901. }
  6902. bool MemoryOutputStream::setPosition (int64 newPosition)
  6903. {
  6904. if (newPosition <= (int64) size)
  6905. {
  6906. // ok to seek backwards
  6907. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6908. return true;
  6909. }
  6910. else
  6911. {
  6912. // trying to make it bigger isn't a good thing to do..
  6913. return false;
  6914. }
  6915. }
  6916. const String MemoryOutputStream::toUTF8() const
  6917. {
  6918. return String (getData(), getDataSize());
  6919. }
  6920. END_JUCE_NAMESPACE
  6921. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  6922. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  6923. BEGIN_JUCE_NAMESPACE
  6924. SubregionStream::SubregionStream (InputStream* const sourceStream,
  6925. const int64 startPositionInSourceStream_,
  6926. const int64 lengthOfSourceStream_,
  6927. const bool deleteSourceWhenDestroyed) throw()
  6928. : source (sourceStream),
  6929. startPositionInSourceStream (startPositionInSourceStream_),
  6930. lengthOfSourceStream (lengthOfSourceStream_)
  6931. {
  6932. if (deleteSourceWhenDestroyed)
  6933. sourceToDelete = source;
  6934. setPosition (0);
  6935. }
  6936. SubregionStream::~SubregionStream() throw()
  6937. {
  6938. }
  6939. int64 SubregionStream::getTotalLength()
  6940. {
  6941. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  6942. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  6943. : srcLen;
  6944. }
  6945. int64 SubregionStream::getPosition()
  6946. {
  6947. return source->getPosition() - startPositionInSourceStream;
  6948. }
  6949. bool SubregionStream::setPosition (int64 newPosition)
  6950. {
  6951. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  6952. }
  6953. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  6954. {
  6955. if (lengthOfSourceStream < 0)
  6956. {
  6957. return source->read (destBuffer, maxBytesToRead);
  6958. }
  6959. else
  6960. {
  6961. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  6962. if (maxBytesToRead <= 0)
  6963. return 0;
  6964. return source->read (destBuffer, maxBytesToRead);
  6965. }
  6966. }
  6967. bool SubregionStream::isExhausted()
  6968. {
  6969. if (lengthOfSourceStream >= 0)
  6970. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  6971. else
  6972. return source->isExhausted();
  6973. }
  6974. END_JUCE_NAMESPACE
  6975. /*** End of inlined file: juce_SubregionStream.cpp ***/
  6976. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  6977. BEGIN_JUCE_NAMESPACE
  6978. PerformanceCounter::PerformanceCounter (const String& name_,
  6979. int runsPerPrintout,
  6980. const File& loggingFile)
  6981. : name (name_),
  6982. numRuns (0),
  6983. runsPerPrint (runsPerPrintout),
  6984. totalTime (0),
  6985. outputFile (loggingFile)
  6986. {
  6987. if (outputFile != File::nonexistent)
  6988. {
  6989. String s ("**** Counter for \"");
  6990. s << name_ << "\" started at: "
  6991. << Time::getCurrentTime().toString (true, true)
  6992. << "\r\n";
  6993. outputFile.appendText (s, false, false);
  6994. }
  6995. }
  6996. PerformanceCounter::~PerformanceCounter()
  6997. {
  6998. printStatistics();
  6999. }
  7000. void PerformanceCounter::start()
  7001. {
  7002. started = Time::getHighResolutionTicks();
  7003. }
  7004. void PerformanceCounter::stop()
  7005. {
  7006. const int64 now = Time::getHighResolutionTicks();
  7007. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7008. if (++numRuns == runsPerPrint)
  7009. printStatistics();
  7010. }
  7011. void PerformanceCounter::printStatistics()
  7012. {
  7013. if (numRuns > 0)
  7014. {
  7015. String s ("Performance count for \"");
  7016. s << name << "\" - average over " << numRuns << " run(s) = ";
  7017. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7018. if (micros > 10000)
  7019. s << (micros/1000) << " millisecs";
  7020. else
  7021. s << micros << " microsecs";
  7022. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7023. Logger::outputDebugString (s);
  7024. s << "\r\n";
  7025. if (outputFile != File::nonexistent)
  7026. outputFile.appendText (s, false, false);
  7027. numRuns = 0;
  7028. totalTime = 0;
  7029. }
  7030. }
  7031. END_JUCE_NAMESPACE
  7032. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7033. /*** Start of inlined file: juce_Uuid.cpp ***/
  7034. BEGIN_JUCE_NAMESPACE
  7035. Uuid::Uuid()
  7036. {
  7037. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7038. // to make it very very unlikely that two UUIDs will ever be the same..
  7039. static int64 macAddresses[2];
  7040. static bool hasCheckedMacAddresses = false;
  7041. if (! hasCheckedMacAddresses)
  7042. {
  7043. hasCheckedMacAddresses = true;
  7044. SystemStats::getMACAddresses (macAddresses, 2);
  7045. }
  7046. value.asInt64[0] = macAddresses[0];
  7047. value.asInt64[1] = macAddresses[1];
  7048. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7049. // whose seed will carry over between calls to this method.
  7050. Random r (macAddresses[0] ^ macAddresses[1]
  7051. ^ Random::getSystemRandom().nextInt64());
  7052. for (int i = 4; --i >= 0;)
  7053. {
  7054. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7055. value.asInt[i] ^= r.nextInt();
  7056. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7057. }
  7058. }
  7059. Uuid::~Uuid() throw()
  7060. {
  7061. }
  7062. Uuid::Uuid (const Uuid& other)
  7063. : value (other.value)
  7064. {
  7065. }
  7066. Uuid& Uuid::operator= (const Uuid& other)
  7067. {
  7068. value = other.value;
  7069. return *this;
  7070. }
  7071. bool Uuid::operator== (const Uuid& other) const
  7072. {
  7073. return value.asInt64[0] == other.value.asInt64[0]
  7074. && value.asInt64[1] == other.value.asInt64[1];
  7075. }
  7076. bool Uuid::operator!= (const Uuid& other) const
  7077. {
  7078. return ! operator== (other);
  7079. }
  7080. bool Uuid::isNull() const throw()
  7081. {
  7082. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7083. }
  7084. const String Uuid::toString() const
  7085. {
  7086. return String::toHexString (value.asBytes, sizeof (value.asBytes), 0);
  7087. }
  7088. Uuid::Uuid (const String& uuidString)
  7089. {
  7090. operator= (uuidString);
  7091. }
  7092. Uuid& Uuid::operator= (const String& uuidString)
  7093. {
  7094. MemoryBlock mb;
  7095. mb.loadFromHexString (uuidString);
  7096. mb.ensureSize (sizeof (value.asBytes), true);
  7097. mb.copyTo (value.asBytes, 0, sizeof (value.asBytes));
  7098. return *this;
  7099. }
  7100. Uuid::Uuid (const uint8* const rawData)
  7101. {
  7102. operator= (rawData);
  7103. }
  7104. Uuid& Uuid::operator= (const uint8* const rawData)
  7105. {
  7106. if (rawData != 0)
  7107. memcpy (value.asBytes, rawData, sizeof (value.asBytes));
  7108. else
  7109. zeromem (value.asBytes, sizeof (value.asBytes));
  7110. return *this;
  7111. }
  7112. END_JUCE_NAMESPACE
  7113. /*** End of inlined file: juce_Uuid.cpp ***/
  7114. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7115. BEGIN_JUCE_NAMESPACE
  7116. class ZipFile::ZipEntryInfo
  7117. {
  7118. public:
  7119. ZipFile::ZipEntry entry;
  7120. int streamOffset;
  7121. int compressedSize;
  7122. bool compressed;
  7123. };
  7124. class ZipFile::ZipInputStream : public InputStream
  7125. {
  7126. public:
  7127. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7128. : file (file_),
  7129. zipEntryInfo (zei),
  7130. pos (0),
  7131. headerSize (0),
  7132. inputStream (0)
  7133. {
  7134. inputStream = file_.inputStream;
  7135. if (file_.inputSource != 0)
  7136. {
  7137. inputStream = file.inputSource->createInputStream();
  7138. }
  7139. else
  7140. {
  7141. #ifdef JUCE_DEBUG
  7142. file_.numOpenStreams++;
  7143. #endif
  7144. }
  7145. char buffer [30];
  7146. if (inputStream != 0
  7147. && inputStream->setPosition (zei.streamOffset)
  7148. && inputStream->read (buffer, 30) == 30
  7149. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7150. {
  7151. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7152. + ByteOrder::littleEndianShort (buffer + 28);
  7153. }
  7154. }
  7155. ~ZipInputStream() throw()
  7156. {
  7157. #ifdef JUCE_DEBUG
  7158. if (inputStream != 0 && inputStream == file.inputStream)
  7159. file.numOpenStreams--;
  7160. #endif
  7161. if (inputStream != file.inputStream)
  7162. delete inputStream;
  7163. }
  7164. int64 getTotalLength() throw()
  7165. {
  7166. return zipEntryInfo.compressedSize;
  7167. }
  7168. int read (void* buffer, int howMany) throw()
  7169. {
  7170. if (headerSize <= 0)
  7171. return 0;
  7172. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7173. if (inputStream == 0)
  7174. return 0;
  7175. int num;
  7176. if (inputStream == file.inputStream)
  7177. {
  7178. const ScopedLock sl (file.lock);
  7179. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7180. num = inputStream->read (buffer, howMany);
  7181. }
  7182. else
  7183. {
  7184. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7185. num = inputStream->read (buffer, howMany);
  7186. }
  7187. pos += num;
  7188. return num;
  7189. }
  7190. bool isExhausted() throw()
  7191. {
  7192. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7193. }
  7194. int64 getPosition() throw()
  7195. {
  7196. return pos;
  7197. }
  7198. bool setPosition (int64 newPos) throw()
  7199. {
  7200. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7201. return true;
  7202. }
  7203. private:
  7204. ZipFile& file;
  7205. ZipEntryInfo zipEntryInfo;
  7206. int64 pos;
  7207. int headerSize;
  7208. InputStream* inputStream;
  7209. ZipInputStream (const ZipInputStream&);
  7210. ZipInputStream& operator= (const ZipInputStream&);
  7211. };
  7212. ZipFile::ZipFile (InputStream* const source_,
  7213. const bool deleteStreamWhenDestroyed) throw()
  7214. : inputStream (source_)
  7215. #ifdef JUCE_DEBUG
  7216. , numOpenStreams (0)
  7217. #endif
  7218. {
  7219. if (deleteStreamWhenDestroyed)
  7220. streamToDelete = inputStream;
  7221. init();
  7222. }
  7223. ZipFile::ZipFile (const File& file)
  7224. : inputStream (0)
  7225. #ifdef JUCE_DEBUG
  7226. , numOpenStreams (0)
  7227. #endif
  7228. {
  7229. inputSource = new FileInputSource (file);
  7230. init();
  7231. }
  7232. ZipFile::ZipFile (InputSource* const inputSource_)
  7233. : inputStream (0),
  7234. inputSource (inputSource_)
  7235. #ifdef JUCE_DEBUG
  7236. , numOpenStreams (0)
  7237. #endif
  7238. {
  7239. init();
  7240. }
  7241. ZipFile::~ZipFile() throw()
  7242. {
  7243. #ifdef JUCE_DEBUG
  7244. entries.clear();
  7245. // If you hit this assertion, it means you've created a stream to read
  7246. // one of the items in the zipfile, but you've forgotten to delete that
  7247. // stream object before deleting the file.. Streams can't be kept open
  7248. // after the file is deleted because they need to share the input
  7249. // stream that the file uses to read itself.
  7250. jassert (numOpenStreams == 0);
  7251. #endif
  7252. }
  7253. int ZipFile::getNumEntries() const throw()
  7254. {
  7255. return entries.size();
  7256. }
  7257. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7258. {
  7259. ZipEntryInfo* const zei = entries [index];
  7260. return zei != 0 ? &(zei->entry) : 0;
  7261. }
  7262. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7263. {
  7264. for (int i = 0; i < entries.size(); ++i)
  7265. if (entries.getUnchecked (i)->entry.filename == fileName)
  7266. return i;
  7267. return -1;
  7268. }
  7269. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7270. {
  7271. return getEntry (getIndexOfFileName (fileName));
  7272. }
  7273. InputStream* ZipFile::createStreamForEntry (const int index)
  7274. {
  7275. ZipEntryInfo* const zei = entries[index];
  7276. InputStream* stream = 0;
  7277. if (zei != 0)
  7278. {
  7279. stream = new ZipInputStream (*this, *zei);
  7280. if (zei->compressed)
  7281. {
  7282. stream = new GZIPDecompressorInputStream (stream, true, true,
  7283. zei->entry.uncompressedSize);
  7284. // (much faster to unzip in big blocks using a buffer..)
  7285. stream = new BufferedInputStream (stream, 32768, true);
  7286. }
  7287. }
  7288. return stream;
  7289. }
  7290. class ZipFile::ZipFilenameComparator
  7291. {
  7292. public:
  7293. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7294. {
  7295. return first->entry.filename.compare (second->entry.filename);
  7296. }
  7297. };
  7298. void ZipFile::sortEntriesByFilename()
  7299. {
  7300. ZipFilenameComparator sorter;
  7301. entries.sort (sorter);
  7302. }
  7303. void ZipFile::init()
  7304. {
  7305. ScopedPointer <InputStream> toDelete;
  7306. InputStream* in = inputStream;
  7307. if (inputSource != 0)
  7308. {
  7309. in = inputSource->createInputStream();
  7310. toDelete = in;
  7311. }
  7312. if (in != 0)
  7313. {
  7314. int numEntries = 0;
  7315. int pos = findEndOfZipEntryTable (in, numEntries);
  7316. if (pos >= 0 && pos < in->getTotalLength())
  7317. {
  7318. const int size = (int) (in->getTotalLength() - pos);
  7319. in->setPosition (pos);
  7320. MemoryBlock headerData;
  7321. if (in->readIntoMemoryBlock (headerData, size) == size)
  7322. {
  7323. pos = 0;
  7324. for (int i = 0; i < numEntries; ++i)
  7325. {
  7326. if (pos + 46 > size)
  7327. break;
  7328. const char* const buffer = static_cast <const char*> (headerData.getData()) + pos;
  7329. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7330. if (pos + 46 + fileNameLen > size)
  7331. break;
  7332. ZipEntryInfo* const zei = new ZipEntryInfo();
  7333. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7334. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7335. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7336. const int year = 1980 + (date >> 9);
  7337. const int month = ((date >> 5) & 15) - 1;
  7338. const int day = date & 31;
  7339. const int hours = time >> 11;
  7340. const int minutes = (time >> 5) & 63;
  7341. const int seconds = (time & 31) << 1;
  7342. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7343. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7344. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7345. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7346. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7347. entries.add (zei);
  7348. pos += 46 + fileNameLen
  7349. + ByteOrder::littleEndianShort (buffer + 30)
  7350. + ByteOrder::littleEndianShort (buffer + 32);
  7351. }
  7352. }
  7353. }
  7354. }
  7355. }
  7356. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7357. {
  7358. BufferedInputStream in (input, 8192, false);
  7359. in.setPosition (in.getTotalLength());
  7360. int64 pos = in.getPosition();
  7361. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7362. char buffer [32];
  7363. zeromem (buffer, sizeof (buffer));
  7364. while (pos > lowestPos)
  7365. {
  7366. in.setPosition (pos - 22);
  7367. pos = in.getPosition();
  7368. memcpy (buffer + 22, buffer, 4);
  7369. if (in.read (buffer, 22) != 22)
  7370. return 0;
  7371. for (int i = 0; i < 22; ++i)
  7372. {
  7373. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7374. {
  7375. in.setPosition (pos + i);
  7376. in.read (buffer, 22);
  7377. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7378. return ByteOrder::littleEndianInt (buffer + 16);
  7379. }
  7380. }
  7381. }
  7382. return 0;
  7383. }
  7384. void ZipFile::uncompressTo (const File& targetDirectory,
  7385. const bool shouldOverwriteFiles)
  7386. {
  7387. for (int i = 0; i < entries.size(); ++i)
  7388. {
  7389. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7390. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7391. if (zei.filename.endsWithChar ('/'))
  7392. {
  7393. targetFile.createDirectory(); // (entry is a directory, not a file)
  7394. }
  7395. else
  7396. {
  7397. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7398. if (in != 0)
  7399. {
  7400. if (shouldOverwriteFiles)
  7401. targetFile.deleteFile();
  7402. if ((! targetFile.exists())
  7403. && targetFile.getParentDirectory().createDirectory())
  7404. {
  7405. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7406. if (out != 0)
  7407. {
  7408. out->writeFromInputStream (*in, -1);
  7409. out = 0;
  7410. targetFile.setCreationTime (zei.fileTime);
  7411. targetFile.setLastModificationTime (zei.fileTime);
  7412. targetFile.setLastAccessTime (zei.fileTime);
  7413. }
  7414. }
  7415. }
  7416. }
  7417. }
  7418. }
  7419. END_JUCE_NAMESPACE
  7420. /*** End of inlined file: juce_ZipFile.cpp ***/
  7421. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7422. #ifdef _MSC_VER
  7423. #pragma warning (disable: 4514 4996)
  7424. #pragma warning (push)
  7425. #endif
  7426. #include <cwctype>
  7427. #include <cctype>
  7428. #include <ctime>
  7429. #ifdef _MSC_VER
  7430. #pragma warning (pop)
  7431. #endif
  7432. BEGIN_JUCE_NAMESPACE
  7433. int CharacterFunctions::length (const char* const s) throw()
  7434. {
  7435. return (int) strlen (s);
  7436. }
  7437. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7438. {
  7439. return (int) wcslen (s);
  7440. }
  7441. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7442. {
  7443. strncpy (dest, src, maxChars);
  7444. }
  7445. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7446. {
  7447. wcsncpy (dest, src, maxChars);
  7448. }
  7449. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7450. {
  7451. mbstowcs (dest, src, maxChars);
  7452. }
  7453. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7454. {
  7455. wcstombs (dest, src, maxChars);
  7456. }
  7457. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7458. {
  7459. return (int) wcstombs (0, src, 0);
  7460. }
  7461. void CharacterFunctions::append (char* dest, const char* src) throw()
  7462. {
  7463. strcat (dest, src);
  7464. }
  7465. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7466. {
  7467. wcscat (dest, src);
  7468. }
  7469. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7470. {
  7471. return strcmp (s1, s2);
  7472. }
  7473. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7474. {
  7475. jassert (s1 != 0 && s2 != 0);
  7476. return wcscmp (s1, s2);
  7477. }
  7478. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7479. {
  7480. jassert (s1 != 0 && s2 != 0);
  7481. return strncmp (s1, s2, maxChars);
  7482. }
  7483. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7484. {
  7485. jassert (s1 != 0 && s2 != 0);
  7486. return wcsncmp (s1, s2, maxChars);
  7487. }
  7488. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7489. {
  7490. jassert (s1 != 0 && s2 != 0);
  7491. for (;;)
  7492. {
  7493. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7494. if (diff != 0)
  7495. return diff;
  7496. else if (*s1 == 0)
  7497. break;
  7498. ++s1;
  7499. ++s2;
  7500. }
  7501. return 0;
  7502. }
  7503. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7504. {
  7505. return -compare (s2, s1);
  7506. }
  7507. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7508. {
  7509. jassert (s1 != 0 && s2 != 0);
  7510. #if JUCE_WIN32
  7511. return stricmp (s1, s2);
  7512. #else
  7513. return strcasecmp (s1, s2);
  7514. #endif
  7515. }
  7516. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7517. {
  7518. jassert (s1 != 0 && s2 != 0);
  7519. #if JUCE_WIN32
  7520. return _wcsicmp (s1, s2);
  7521. #else
  7522. for (;;)
  7523. {
  7524. if (*s1 != *s2)
  7525. {
  7526. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7527. if (diff != 0)
  7528. return diff < 0 ? -1 : 1;
  7529. }
  7530. else if (*s1 == 0)
  7531. break;
  7532. ++s1;
  7533. ++s2;
  7534. }
  7535. return 0;
  7536. #endif
  7537. }
  7538. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const char* s2) throw()
  7539. {
  7540. jassert (s1 != 0 && s2 != 0);
  7541. for (;;)
  7542. {
  7543. if (*s1 != *s2)
  7544. {
  7545. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7546. if (diff != 0)
  7547. return diff < 0 ? -1 : 1;
  7548. }
  7549. else if (*s1 == 0)
  7550. break;
  7551. ++s1;
  7552. ++s2;
  7553. }
  7554. return 0;
  7555. }
  7556. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7557. {
  7558. jassert (s1 != 0 && s2 != 0);
  7559. #if JUCE_WIN32
  7560. return strnicmp (s1, s2, maxChars);
  7561. #else
  7562. return strncasecmp (s1, s2, maxChars);
  7563. #endif
  7564. }
  7565. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7566. {
  7567. jassert (s1 != 0 && s2 != 0);
  7568. #if JUCE_WIN32
  7569. return _wcsnicmp (s1, s2, maxChars);
  7570. #else
  7571. while (--maxChars >= 0)
  7572. {
  7573. if (*s1 != *s2)
  7574. {
  7575. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7576. if (diff != 0)
  7577. return diff < 0 ? -1 : 1;
  7578. }
  7579. else if (*s1 == 0)
  7580. break;
  7581. ++s1;
  7582. ++s2;
  7583. }
  7584. return 0;
  7585. #endif
  7586. }
  7587. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7588. {
  7589. return strstr (haystack, needle);
  7590. }
  7591. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7592. {
  7593. return wcsstr (haystack, needle);
  7594. }
  7595. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7596. {
  7597. if (haystack != 0)
  7598. {
  7599. int i = 0;
  7600. if (ignoreCase)
  7601. {
  7602. const char n1 = toLowerCase (needle);
  7603. const char n2 = toUpperCase (needle);
  7604. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7605. {
  7606. while (haystack[i] != 0)
  7607. {
  7608. if (haystack[i] == n1 || haystack[i] == n2)
  7609. return i;
  7610. ++i;
  7611. }
  7612. return -1;
  7613. }
  7614. jassert (n1 == needle);
  7615. }
  7616. while (haystack[i] != 0)
  7617. {
  7618. if (haystack[i] == needle)
  7619. return i;
  7620. ++i;
  7621. }
  7622. }
  7623. return -1;
  7624. }
  7625. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7626. {
  7627. if (haystack != 0)
  7628. {
  7629. int i = 0;
  7630. if (ignoreCase)
  7631. {
  7632. const juce_wchar n1 = toLowerCase (needle);
  7633. const juce_wchar n2 = toUpperCase (needle);
  7634. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7635. {
  7636. while (haystack[i] != 0)
  7637. {
  7638. if (haystack[i] == n1 || haystack[i] == n2)
  7639. return i;
  7640. ++i;
  7641. }
  7642. return -1;
  7643. }
  7644. jassert (n1 == needle);
  7645. }
  7646. while (haystack[i] != 0)
  7647. {
  7648. if (haystack[i] == needle)
  7649. return i;
  7650. ++i;
  7651. }
  7652. }
  7653. return -1;
  7654. }
  7655. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7656. {
  7657. jassert (haystack != 0);
  7658. int i = 0;
  7659. while (haystack[i] != 0)
  7660. {
  7661. if (haystack[i] == needle)
  7662. return i;
  7663. ++i;
  7664. }
  7665. return -1;
  7666. }
  7667. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7668. {
  7669. jassert (haystack != 0);
  7670. int i = 0;
  7671. while (haystack[i] != 0)
  7672. {
  7673. if (haystack[i] == needle)
  7674. return i;
  7675. ++i;
  7676. }
  7677. return -1;
  7678. }
  7679. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7680. {
  7681. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7682. }
  7683. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7684. {
  7685. if (allowedChars == 0)
  7686. return 0;
  7687. int i = 0;
  7688. for (;;)
  7689. {
  7690. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7691. break;
  7692. ++i;
  7693. }
  7694. return i;
  7695. }
  7696. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7697. {
  7698. return (int) strftime (dest, maxChars, format, tm);
  7699. }
  7700. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7701. {
  7702. return (int) wcsftime (dest, maxChars, format, tm);
  7703. }
  7704. int CharacterFunctions::getIntValue (const char* const s) throw()
  7705. {
  7706. return atoi (s);
  7707. }
  7708. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7709. {
  7710. #if JUCE_WIN32
  7711. return _wtoi (s);
  7712. #else
  7713. int v = 0;
  7714. while (isWhitespace (*s))
  7715. ++s;
  7716. const bool isNeg = *s == '-';
  7717. if (isNeg)
  7718. ++s;
  7719. for (;;)
  7720. {
  7721. const wchar_t c = *s++;
  7722. if (c >= '0' && c <= '9')
  7723. v = v * 10 + (int) (c - '0');
  7724. else
  7725. break;
  7726. }
  7727. return isNeg ? -v : v;
  7728. #endif
  7729. }
  7730. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7731. {
  7732. #if JUCE_LINUX
  7733. return atoll (s);
  7734. #elif defined (JUCE_WIN32)
  7735. return _atoi64 (s);
  7736. #else
  7737. int64 v = 0;
  7738. while (isWhitespace (*s))
  7739. ++s;
  7740. const bool isNeg = *s == '-';
  7741. if (isNeg)
  7742. ++s;
  7743. for (;;)
  7744. {
  7745. const char c = *s++;
  7746. if (c >= '0' && c <= '9')
  7747. v = v * 10 + (int64) (c - '0');
  7748. else
  7749. break;
  7750. }
  7751. return isNeg ? -v : v;
  7752. #endif
  7753. }
  7754. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7755. {
  7756. #if JUCE_WIN32
  7757. return _wtoi64 (s);
  7758. #else
  7759. int64 v = 0;
  7760. while (isWhitespace (*s))
  7761. ++s;
  7762. const bool isNeg = *s == '-';
  7763. if (isNeg)
  7764. ++s;
  7765. for (;;)
  7766. {
  7767. const juce_wchar c = *s++;
  7768. if (c >= '0' && c <= '9')
  7769. v = v * 10 + (int64) (c - '0');
  7770. else
  7771. break;
  7772. }
  7773. return isNeg ? -v : v;
  7774. #endif
  7775. }
  7776. static double juce_mulexp10 (const double value, int exponent) throw()
  7777. {
  7778. if (exponent == 0)
  7779. return value;
  7780. if (value == 0)
  7781. return 0;
  7782. const bool negative = (exponent < 0);
  7783. if (negative)
  7784. exponent = -exponent;
  7785. double result = 1.0, power = 10.0;
  7786. for (int bit = 1; exponent != 0; bit <<= 1)
  7787. {
  7788. if ((exponent & bit) != 0)
  7789. {
  7790. exponent ^= bit;
  7791. result *= power;
  7792. if (exponent == 0)
  7793. break;
  7794. }
  7795. power *= power;
  7796. }
  7797. return negative ? (value / result) : (value * result);
  7798. }
  7799. template <class CharType>
  7800. double juce_atof (const CharType* const original) throw()
  7801. {
  7802. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7803. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7804. int exponent = 0, decPointIndex = 0, digit = 0;
  7805. int lastDigit = 0, numSignificantDigits = 0;
  7806. bool isNegative = false, digitsFound = false;
  7807. const int maxSignificantDigits = 15 + 2;
  7808. const CharType* s = original;
  7809. while (CharacterFunctions::isWhitespace (*s))
  7810. ++s;
  7811. switch (*s)
  7812. {
  7813. case '-': isNegative = true; // fall-through..
  7814. case '+': ++s;
  7815. }
  7816. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7817. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  7818. for (;;)
  7819. {
  7820. if (CharacterFunctions::isDigit (*s))
  7821. {
  7822. lastDigit = digit;
  7823. digit = *s++ - '0';
  7824. digitsFound = true;
  7825. if (decPointIndex != 0)
  7826. exponentAdjustment[1]++;
  7827. if (numSignificantDigits == 0 && digit == 0)
  7828. continue;
  7829. if (++numSignificantDigits > maxSignificantDigits)
  7830. {
  7831. if (digit > 5)
  7832. ++accumulator [decPointIndex];
  7833. else if (digit == 5 && (lastDigit & 1) != 0)
  7834. ++accumulator [decPointIndex];
  7835. if (decPointIndex > 0)
  7836. exponentAdjustment[1]--;
  7837. else
  7838. exponentAdjustment[0]++;
  7839. while (CharacterFunctions::isDigit (*s))
  7840. {
  7841. ++s;
  7842. if (decPointIndex == 0)
  7843. exponentAdjustment[0]++;
  7844. }
  7845. }
  7846. else
  7847. {
  7848. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  7849. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7850. {
  7851. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7852. + accumulator [decPointIndex];
  7853. accumulator [decPointIndex] = 0;
  7854. exponentAccumulator [decPointIndex] = 0;
  7855. }
  7856. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7857. exponentAccumulator [decPointIndex]++;
  7858. }
  7859. }
  7860. else if (decPointIndex == 0 && *s == '.')
  7861. {
  7862. ++s;
  7863. decPointIndex = 1;
  7864. if (numSignificantDigits > maxSignificantDigits)
  7865. {
  7866. while (CharacterFunctions::isDigit (*s))
  7867. ++s;
  7868. break;
  7869. }
  7870. }
  7871. else
  7872. {
  7873. break;
  7874. }
  7875. }
  7876. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7877. if (decPointIndex != 0)
  7878. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7879. if ((*s == 'e' || *s == 'E') && digitsFound)
  7880. {
  7881. bool negativeExponent = false;
  7882. switch (*++s)
  7883. {
  7884. case '-': negativeExponent = true; // fall-through..
  7885. case '+': ++s;
  7886. }
  7887. while (CharacterFunctions::isDigit (*s))
  7888. exponent = (exponent * 10) + (*s++ - '0');
  7889. if (negativeExponent)
  7890. exponent = -exponent;
  7891. }
  7892. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7893. if (decPointIndex != 0)
  7894. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7895. return isNegative ? -r : r;
  7896. }
  7897. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7898. {
  7899. return juce_atof <char> (s);
  7900. }
  7901. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7902. {
  7903. return juce_atof <juce_wchar> (s);
  7904. }
  7905. char CharacterFunctions::toUpperCase (const char character) throw()
  7906. {
  7907. return (char) toupper (character);
  7908. }
  7909. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7910. {
  7911. return towupper (character);
  7912. }
  7913. void CharacterFunctions::toUpperCase (char* s) throw()
  7914. {
  7915. #if JUCE_WIN32
  7916. strupr (s);
  7917. #else
  7918. while (*s != 0)
  7919. {
  7920. *s = toUpperCase (*s);
  7921. ++s;
  7922. }
  7923. #endif
  7924. }
  7925. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  7926. {
  7927. #if JUCE_WIN32
  7928. _wcsupr (s);
  7929. #else
  7930. while (*s != 0)
  7931. {
  7932. *s = toUpperCase (*s);
  7933. ++s;
  7934. }
  7935. #endif
  7936. }
  7937. bool CharacterFunctions::isUpperCase (const char character) throw()
  7938. {
  7939. return isupper (character) != 0;
  7940. }
  7941. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  7942. {
  7943. #if JUCE_WIN32
  7944. return iswupper (character) != 0;
  7945. #else
  7946. return toLowerCase (character) != character;
  7947. #endif
  7948. }
  7949. char CharacterFunctions::toLowerCase (const char character) throw()
  7950. {
  7951. return (char) tolower (character);
  7952. }
  7953. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  7954. {
  7955. return towlower (character);
  7956. }
  7957. void CharacterFunctions::toLowerCase (char* s) throw()
  7958. {
  7959. #if JUCE_WIN32
  7960. strlwr (s);
  7961. #else
  7962. while (*s != 0)
  7963. {
  7964. *s = toLowerCase (*s);
  7965. ++s;
  7966. }
  7967. #endif
  7968. }
  7969. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  7970. {
  7971. #if JUCE_WIN32
  7972. _wcslwr (s);
  7973. #else
  7974. while (*s != 0)
  7975. {
  7976. *s = toLowerCase (*s);
  7977. ++s;
  7978. }
  7979. #endif
  7980. }
  7981. bool CharacterFunctions::isLowerCase (const char character) throw()
  7982. {
  7983. return islower (character) != 0;
  7984. }
  7985. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  7986. {
  7987. #if JUCE_WIN32
  7988. return iswlower (character) != 0;
  7989. #else
  7990. return toUpperCase (character) != character;
  7991. #endif
  7992. }
  7993. bool CharacterFunctions::isWhitespace (const char character) throw()
  7994. {
  7995. return character == ' ' || (character <= 13 && character >= 9);
  7996. }
  7997. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  7998. {
  7999. return iswspace (character) != 0;
  8000. }
  8001. bool CharacterFunctions::isDigit (const char character) throw()
  8002. {
  8003. return (character >= '0' && character <= '9');
  8004. }
  8005. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8006. {
  8007. return iswdigit (character) != 0;
  8008. }
  8009. bool CharacterFunctions::isLetter (const char character) throw()
  8010. {
  8011. return (character >= 'a' && character <= 'z')
  8012. || (character >= 'A' && character <= 'Z');
  8013. }
  8014. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8015. {
  8016. return iswalpha (character) != 0;
  8017. }
  8018. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8019. {
  8020. return (character >= 'a' && character <= 'z')
  8021. || (character >= 'A' && character <= 'Z')
  8022. || (character >= '0' && character <= '9');
  8023. }
  8024. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8025. {
  8026. return iswalnum (character) != 0;
  8027. }
  8028. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8029. {
  8030. if (digit >= '0' && digit <= '9')
  8031. return digit - '0';
  8032. else if (digit >= 'a' && digit <= 'f')
  8033. return digit - ('a' - 10);
  8034. else if (digit >= 'A' && digit <= 'F')
  8035. return digit - ('A' - 10);
  8036. return -1;
  8037. }
  8038. END_JUCE_NAMESPACE
  8039. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8040. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8041. BEGIN_JUCE_NAMESPACE
  8042. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8043. {
  8044. loadFromText (fileContents);
  8045. }
  8046. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8047. {
  8048. loadFromText (fileToLoad.loadFileAsString());
  8049. }
  8050. LocalisedStrings::~LocalisedStrings()
  8051. {
  8052. }
  8053. const String LocalisedStrings::translate (const String& text) const
  8054. {
  8055. return translations.getValue (text, text);
  8056. }
  8057. static int findCloseQuote (const String& text, int startPos)
  8058. {
  8059. tchar lastChar = 0;
  8060. for (;;)
  8061. {
  8062. const tchar c = text [startPos];
  8063. if (c == 0 || (c == '"' && lastChar != '\\'))
  8064. break;
  8065. lastChar = c;
  8066. ++startPos;
  8067. }
  8068. return startPos;
  8069. }
  8070. static const String unescapeString (const String& s)
  8071. {
  8072. return s.replace ("\\\"", "\"")
  8073. .replace ("\\\'", "\'")
  8074. .replace ("\\t", "\t")
  8075. .replace ("\\r", "\r")
  8076. .replace ("\\n", "\n");
  8077. }
  8078. void LocalisedStrings::loadFromText (const String& fileContents)
  8079. {
  8080. StringArray lines;
  8081. lines.addLines (fileContents);
  8082. for (int i = 0; i < lines.size(); ++i)
  8083. {
  8084. String line (lines[i].trim());
  8085. if (line.startsWithChar ('"'))
  8086. {
  8087. int closeQuote = findCloseQuote (line, 1);
  8088. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8089. if (originalText.isNotEmpty())
  8090. {
  8091. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8092. closeQuote = findCloseQuote (line, openingQuote + 1);
  8093. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8094. if (newText.isNotEmpty())
  8095. translations.set (originalText, newText);
  8096. }
  8097. }
  8098. else if (line.startsWithIgnoreCase ("language:"))
  8099. {
  8100. languageName = line.substring (9).trim();
  8101. }
  8102. else if (line.startsWithIgnoreCase ("countries:"))
  8103. {
  8104. countryCodes.addTokens (line.substring (10).trim(), true);
  8105. countryCodes.trim();
  8106. countryCodes.removeEmptyStrings();
  8107. }
  8108. }
  8109. }
  8110. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8111. {
  8112. translations.setIgnoresCase (shouldIgnoreCase);
  8113. }
  8114. static CriticalSection currentMappingsLock;
  8115. static LocalisedStrings* currentMappings = 0;
  8116. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8117. {
  8118. const ScopedLock sl (currentMappingsLock);
  8119. delete currentMappings;
  8120. currentMappings = newTranslations;
  8121. }
  8122. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8123. {
  8124. return currentMappings;
  8125. }
  8126. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8127. {
  8128. const ScopedLock sl (currentMappingsLock);
  8129. if (currentMappings != 0)
  8130. return currentMappings->translate (text);
  8131. return text;
  8132. }
  8133. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8134. {
  8135. return translateWithCurrentMappings (String (text));
  8136. }
  8137. END_JUCE_NAMESPACE
  8138. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8139. /*** Start of inlined file: juce_String.cpp ***/
  8140. #ifdef _MSC_VER
  8141. #pragma warning (push)
  8142. #pragma warning (disable: 4514)
  8143. #endif
  8144. #include <locale>
  8145. #if JUCE_MSVC
  8146. #include <float.h>
  8147. #endif
  8148. BEGIN_JUCE_NAMESPACE
  8149. #ifdef _MSC_VER
  8150. #pragma warning (pop)
  8151. #endif
  8152. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8153. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8154. #endif
  8155. class StringHolder
  8156. {
  8157. public:
  8158. StringHolder()
  8159. : refCount (0x3fffffff), allocatedNumChars (0)
  8160. {
  8161. text[0] = 0;
  8162. }
  8163. static juce_wchar* create (const size_t numChars)
  8164. {
  8165. StringHolder* const s = reinterpret_cast <StringHolder*> (new char [sizeof (StringHolder) + numChars * sizeof (juce_wchar)]);
  8166. s->refCount = 0;
  8167. s->allocatedNumChars = numChars;
  8168. return &(s->text[0]);
  8169. }
  8170. static inline juce_wchar* getEmpty() throw()
  8171. {
  8172. return &(empty.text[0]);
  8173. }
  8174. static void retain (juce_wchar* const text) throw()
  8175. {
  8176. Atomic::increment (bufferFromText (text)->refCount);
  8177. }
  8178. static inline void release (StringHolder* const b) throw()
  8179. {
  8180. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8181. delete[] reinterpret_cast <char*> (b);
  8182. }
  8183. static void release (juce_wchar* const text) throw()
  8184. {
  8185. release (bufferFromText (text));
  8186. }
  8187. static juce_wchar* makeUnique (juce_wchar* const text)
  8188. {
  8189. StringHolder* const b = bufferFromText (text);
  8190. if (b->refCount <= 0)
  8191. return text;
  8192. juce_wchar* const newText = create (b->allocatedNumChars);
  8193. copyChars (newText, text, b->allocatedNumChars);
  8194. release (b);
  8195. return newText;
  8196. }
  8197. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8198. {
  8199. StringHolder* const b = bufferFromText (text);
  8200. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8201. return text;
  8202. juce_wchar* const newText = create (jmax (b->allocatedNumChars, numChars));
  8203. copyChars (newText, text, b->allocatedNumChars);
  8204. release (b);
  8205. return newText;
  8206. }
  8207. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8208. {
  8209. return bufferFromText (text)->allocatedNumChars;
  8210. }
  8211. static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw()
  8212. {
  8213. memcpy (dest, src, numChars * sizeof (juce_wchar));
  8214. dest [numChars] = 0;
  8215. }
  8216. int refCount;
  8217. size_t allocatedNumChars;
  8218. juce_wchar text[1];
  8219. static StringHolder empty;
  8220. private:
  8221. static inline StringHolder* bufferFromText (void* const text) throw()
  8222. {
  8223. // (Can't use offsetof() here because of warnings about this not being a POD)
  8224. return reinterpret_cast <StringHolder*> (static_cast <char*> (text)
  8225. - (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
  8226. }
  8227. };
  8228. StringHolder StringHolder::empty;
  8229. const String String::empty;
  8230. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8231. {
  8232. jassert (t[numChars] == 0); // must have a null terminator
  8233. text = StringHolder::create (numChars);
  8234. StringHolder::copyChars (text, t, numChars);
  8235. }
  8236. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8237. {
  8238. if (numExtraChars > 0)
  8239. {
  8240. const int oldLen = length();
  8241. const int newTotalLen = oldLen + numExtraChars;
  8242. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8243. StringHolder::copyChars (text + oldLen, newText, numExtraChars);
  8244. }
  8245. }
  8246. void String::preallocateStorage (const size_t numChars)
  8247. {
  8248. text = StringHolder::makeUniqueWithSize (text, numChars);
  8249. }
  8250. String::String() throw()
  8251. : text (StringHolder::getEmpty())
  8252. {
  8253. }
  8254. String::~String() throw()
  8255. {
  8256. StringHolder::release (text);
  8257. }
  8258. String::String (const String& other) throw()
  8259. : text (other.text)
  8260. {
  8261. StringHolder::retain (text);
  8262. }
  8263. void String::swapWith (String& other) throw()
  8264. {
  8265. swapVariables (text, other.text);
  8266. }
  8267. String& String::operator= (const String& other) throw()
  8268. {
  8269. juce_wchar* const newText = other.text;
  8270. StringHolder::retain (newText);
  8271. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8272. return *this;
  8273. }
  8274. String::String (const size_t numChars, const int /*dummyVariable*/)
  8275. : text (StringHolder::create (numChars))
  8276. {
  8277. }
  8278. String::String (const String& stringToCopy, const size_t charsToAllocate)
  8279. {
  8280. const size_t otherSize = StringHolder::getAllocatedNumChars (stringToCopy.text);
  8281. text = StringHolder::create (jmax (charsToAllocate, otherSize));
  8282. StringHolder::copyChars (text, stringToCopy.text, otherSize);
  8283. }
  8284. String::String (const char* const t)
  8285. {
  8286. if (t != 0 && *t != 0)
  8287. {
  8288. const int len = CharacterFunctions::length (t);
  8289. text = StringHolder::create (len);
  8290. CharacterFunctions::copy (text, t, len + 1);
  8291. }
  8292. else
  8293. {
  8294. text = StringHolder::getEmpty();
  8295. }
  8296. }
  8297. String::String (const juce_wchar* const t)
  8298. {
  8299. if (t != 0 && *t != 0)
  8300. {
  8301. const int len = CharacterFunctions::length (t);
  8302. text = StringHolder::create (len);
  8303. StringHolder::copyChars (text, t, len);
  8304. }
  8305. else
  8306. {
  8307. text = StringHolder::getEmpty();
  8308. }
  8309. }
  8310. String::String (const char* const t, const size_t maxChars)
  8311. {
  8312. int i;
  8313. for (i = 0; (size_t) i < maxChars; ++i)
  8314. if (t[i] == 0)
  8315. break;
  8316. if (i > 0)
  8317. {
  8318. text = StringHolder::create (i);
  8319. CharacterFunctions::copy (text, t, i);
  8320. text[i] = 0;
  8321. }
  8322. else
  8323. {
  8324. text = StringHolder::getEmpty();
  8325. }
  8326. }
  8327. String::String (const juce_wchar* const t, const size_t maxChars)
  8328. {
  8329. int i;
  8330. for (i = 0; (size_t) i < maxChars; ++i)
  8331. if (t[i] == 0)
  8332. break;
  8333. if (i > 0)
  8334. {
  8335. text = StringHolder::create (i);
  8336. StringHolder::copyChars (text, t, i);
  8337. }
  8338. else
  8339. {
  8340. text = StringHolder::getEmpty();
  8341. }
  8342. }
  8343. const String String::charToString (const juce_wchar character)
  8344. {
  8345. String result ((size_t) 1, (int) 0);
  8346. result.text[0] = character;
  8347. result.text[1] = 0;
  8348. return result;
  8349. }
  8350. namespace NumberToStringConverters
  8351. {
  8352. // pass in a pointer to the END of a buffer..
  8353. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8354. {
  8355. *--t = 0;
  8356. int64 v = (n >= 0) ? n : -n;
  8357. do
  8358. {
  8359. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8360. v /= 10;
  8361. } while (v > 0);
  8362. if (n < 0)
  8363. *--t = '-';
  8364. return t;
  8365. }
  8366. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8367. {
  8368. *--t = 0;
  8369. do
  8370. {
  8371. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8372. v /= 10;
  8373. } while (v > 0);
  8374. return t;
  8375. }
  8376. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8377. {
  8378. if (n == (int) 0x80000000) // (would cause an overflow)
  8379. return int64ToString (t, n);
  8380. *--t = 0;
  8381. int v = abs (n);
  8382. do
  8383. {
  8384. *--t = (juce_wchar) ('0' + (v % 10));
  8385. v /= 10;
  8386. } while (v > 0);
  8387. if (n < 0)
  8388. *--t = '-';
  8389. return t;
  8390. }
  8391. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8392. {
  8393. *--t = 0;
  8394. do
  8395. {
  8396. *--t = (juce_wchar) ('0' + (v % 10));
  8397. v /= 10;
  8398. } while (v > 0);
  8399. return t;
  8400. }
  8401. static juce_wchar getDecimalPoint()
  8402. {
  8403. #if JUCE_WINDOWS && _MSC_VER < 1400
  8404. static juce_wchar dp = std::_USE (std::locale(), std::numpunct <wchar_t>).decimal_point();
  8405. #else
  8406. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8407. #endif
  8408. return dp;
  8409. }
  8410. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8411. {
  8412. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8413. {
  8414. juce_wchar* const end = buffer + numChars;
  8415. juce_wchar* t = end;
  8416. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8417. *--t = (juce_wchar) 0;
  8418. while (numDecPlaces >= 0 || v > 0)
  8419. {
  8420. if (numDecPlaces == 0)
  8421. *--t = getDecimalPoint();
  8422. *--t = (juce_wchar) ('0' + (v % 10));
  8423. v /= 10;
  8424. --numDecPlaces;
  8425. }
  8426. if (n < 0)
  8427. *--t = '-';
  8428. len = end - t - 1;
  8429. return t;
  8430. }
  8431. else
  8432. {
  8433. #if JUCE_WIN32
  8434. #if _MSC_VER <= 1400
  8435. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8436. #else
  8437. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8438. #endif
  8439. #else
  8440. len = swprintf (buffer, numChars, L"%.9g", n);
  8441. #endif
  8442. return buffer;
  8443. }
  8444. }
  8445. }
  8446. String::String (const int number)
  8447. {
  8448. juce_wchar buffer [16];
  8449. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8450. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8451. createInternal (start, end - start - 1);
  8452. }
  8453. String::String (const unsigned int number)
  8454. {
  8455. juce_wchar buffer [16];
  8456. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8457. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8458. createInternal (start, end - start - 1);
  8459. }
  8460. String::String (const short number)
  8461. {
  8462. juce_wchar buffer [16];
  8463. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8464. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8465. createInternal (start, end - start - 1);
  8466. }
  8467. String::String (const unsigned short number)
  8468. {
  8469. juce_wchar buffer [16];
  8470. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8471. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8472. createInternal (start, end - start - 1);
  8473. }
  8474. String::String (const int64 number)
  8475. {
  8476. juce_wchar buffer [32];
  8477. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8478. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8479. createInternal (start, end - start - 1);
  8480. }
  8481. String::String (const uint64 number)
  8482. {
  8483. juce_wchar buffer [32];
  8484. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8485. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8486. createInternal (start, end - start - 1);
  8487. }
  8488. String::String (const float number, const int numberOfDecimalPlaces)
  8489. {
  8490. juce_wchar buffer [48];
  8491. size_t len;
  8492. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8493. createInternal (start, len);
  8494. }
  8495. String::String (const double number, const int numberOfDecimalPlaces)
  8496. {
  8497. juce_wchar buffer [48];
  8498. size_t len;
  8499. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8500. createInternal (start, len);
  8501. }
  8502. int String::length() const throw()
  8503. {
  8504. return CharacterFunctions::length (text);
  8505. }
  8506. int String::hashCode() const throw()
  8507. {
  8508. const juce_wchar* t = text;
  8509. int result = 0;
  8510. while (*t != (juce_wchar) 0)
  8511. result = 31 * result + *t++;
  8512. return result;
  8513. }
  8514. int64 String::hashCode64() const throw()
  8515. {
  8516. const juce_wchar* t = text;
  8517. int64 result = 0;
  8518. while (*t != (juce_wchar) 0)
  8519. result = 101 * result + *t++;
  8520. return result;
  8521. }
  8522. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8523. {
  8524. return string1.compare (string2) == 0;
  8525. }
  8526. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8527. {
  8528. return string1.compare (string2) == 0;
  8529. }
  8530. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8531. {
  8532. return string1.compare (string2) == 0;
  8533. }
  8534. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8535. {
  8536. return string1.compare (string2) != 0;
  8537. }
  8538. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8539. {
  8540. return string1.compare (string2) != 0;
  8541. }
  8542. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8543. {
  8544. return string1.compare (string2) != 0;
  8545. }
  8546. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8547. {
  8548. return string1.compare (string2) > 0;
  8549. }
  8550. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8551. {
  8552. return string1.compare (string2) < 0;
  8553. }
  8554. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8555. {
  8556. return string1.compare (string2) >= 0;
  8557. }
  8558. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8559. {
  8560. return string1.compare (string2) <= 0;
  8561. }
  8562. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8563. {
  8564. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8565. : isEmpty();
  8566. }
  8567. bool String::equalsIgnoreCase (const char* t) const throw()
  8568. {
  8569. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8570. : isEmpty();
  8571. }
  8572. bool String::equalsIgnoreCase (const String& other) const throw()
  8573. {
  8574. return text == other.text
  8575. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8576. }
  8577. int String::compare (const String& other) const throw()
  8578. {
  8579. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8580. }
  8581. int String::compare (const char* other) const throw()
  8582. {
  8583. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8584. }
  8585. int String::compare (const juce_wchar* other) const throw()
  8586. {
  8587. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8588. }
  8589. int String::compareIgnoreCase (const String& other) const throw()
  8590. {
  8591. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8592. }
  8593. int String::compareLexicographically (const String& other) const throw()
  8594. {
  8595. const juce_wchar* s1 = text;
  8596. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8597. ++s1;
  8598. const juce_wchar* s2 = other.text;
  8599. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8600. ++s2;
  8601. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8602. }
  8603. String& String::operator+= (const juce_wchar* const t)
  8604. {
  8605. if (t != 0)
  8606. appendInternal (t, CharacterFunctions::length (t));
  8607. return *this;
  8608. }
  8609. String& String::operator+= (const String& other)
  8610. {
  8611. if (isEmpty())
  8612. operator= (other);
  8613. else
  8614. appendInternal (other.text, other.length());
  8615. return *this;
  8616. }
  8617. String& String::operator+= (const char ch)
  8618. {
  8619. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8620. return operator+= (static_cast <const juce_wchar*> (asString));
  8621. }
  8622. String& String::operator+= (const juce_wchar ch)
  8623. {
  8624. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8625. return operator+= (static_cast <const juce_wchar*> (asString));
  8626. }
  8627. String& String::operator+= (const int number)
  8628. {
  8629. juce_wchar buffer [16];
  8630. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8631. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8632. appendInternal (start, (int) (end - start));
  8633. return *this;
  8634. }
  8635. String& String::operator+= (const unsigned int number)
  8636. {
  8637. juce_wchar buffer [16];
  8638. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8639. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8640. appendInternal (start, (int) (end - start));
  8641. return *this;
  8642. }
  8643. void String::append (const juce_wchar* const other, const int howMany)
  8644. {
  8645. if (howMany > 0)
  8646. {
  8647. int i;
  8648. for (i = 0; i < howMany; ++i)
  8649. if (other[i] == 0)
  8650. break;
  8651. appendInternal (other, i);
  8652. }
  8653. }
  8654. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8655. {
  8656. String s (string1);
  8657. return s += string2;
  8658. }
  8659. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8660. {
  8661. String s (string1);
  8662. return s += string2;
  8663. }
  8664. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8665. {
  8666. return String::charToString (string1) + string2;
  8667. }
  8668. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8669. {
  8670. return String::charToString (string1) + string2;
  8671. }
  8672. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8673. {
  8674. return string1 += string2;
  8675. }
  8676. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8677. {
  8678. return string1 += string2;
  8679. }
  8680. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8681. {
  8682. return string1 += string2;
  8683. }
  8684. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8685. {
  8686. return string1 += string2;
  8687. }
  8688. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8689. {
  8690. return string1 += string2;
  8691. }
  8692. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8693. {
  8694. return string1 += characterToAppend;
  8695. }
  8696. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8697. {
  8698. return string1 += characterToAppend;
  8699. }
  8700. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8701. {
  8702. return string1 += string2;
  8703. }
  8704. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8705. {
  8706. return string1 += string2;
  8707. }
  8708. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8709. {
  8710. return string1 += string2;
  8711. }
  8712. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8713. {
  8714. return string1 += (int) number;
  8715. }
  8716. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8717. {
  8718. return string1 += number;
  8719. }
  8720. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8721. {
  8722. return string1 += number;
  8723. }
  8724. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8725. {
  8726. return string1 += (int) number;
  8727. }
  8728. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8729. {
  8730. return string1 += (unsigned int) number;
  8731. }
  8732. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8733. {
  8734. return string1 += String (number);
  8735. }
  8736. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8737. {
  8738. return string1 += String (number);
  8739. }
  8740. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8741. {
  8742. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8743. // if lots of large, persistent strings were to be written to streams).
  8744. const int numBytes = text.getNumBytesAsUTF8();
  8745. HeapBlock<char> temp (numBytes + 1);
  8746. text.copyToUTF8 (temp, numBytes + 1);
  8747. stream.write (temp, numBytes);
  8748. return stream;
  8749. }
  8750. int String::indexOfChar (const juce_wchar character) const throw()
  8751. {
  8752. const juce_wchar* t = text;
  8753. for (;;)
  8754. {
  8755. if (*t == character)
  8756. return (int) (t - text);
  8757. if (*t++ == 0)
  8758. return -1;
  8759. }
  8760. }
  8761. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8762. {
  8763. for (int i = length(); --i >= 0;)
  8764. if (text[i] == character)
  8765. return i;
  8766. return -1;
  8767. }
  8768. int String::indexOf (const String& t) const throw()
  8769. {
  8770. const juce_wchar* const r = CharacterFunctions::find (text, t.text);
  8771. return r == 0 ? -1 : (int) (r - text);
  8772. }
  8773. int String::indexOfChar (const int startIndex,
  8774. const juce_wchar character) const throw()
  8775. {
  8776. if (startIndex > 0 && startIndex >= length())
  8777. return -1;
  8778. const juce_wchar* t = text + jmax (0, startIndex);
  8779. for (;;)
  8780. {
  8781. if (*t == character)
  8782. return (int) (t - text);
  8783. if (*t == 0)
  8784. return -1;
  8785. ++t;
  8786. }
  8787. }
  8788. int String::indexOfAnyOf (const String& charactersToLookFor,
  8789. const int startIndex,
  8790. const bool ignoreCase) const throw()
  8791. {
  8792. if (startIndex > 0 && startIndex >= length())
  8793. return -1;
  8794. const juce_wchar* t = text + jmax (0, startIndex);
  8795. while (*t != 0)
  8796. {
  8797. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, *t, ignoreCase) >= 0)
  8798. return (int) (t - text);
  8799. ++t;
  8800. }
  8801. return -1;
  8802. }
  8803. int String::indexOf (const int startIndex, const String& other) const throw()
  8804. {
  8805. if (startIndex > 0 && startIndex >= length())
  8806. return -1;
  8807. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other.text);
  8808. return found == 0 ? -1 : (int) (found - text);
  8809. }
  8810. int String::indexOfIgnoreCase (const String& other) const throw()
  8811. {
  8812. if (other.isNotEmpty())
  8813. {
  8814. const int len = other.length();
  8815. const int end = length() - len;
  8816. for (int i = 0; i <= end; ++i)
  8817. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8818. return i;
  8819. }
  8820. return -1;
  8821. }
  8822. int String::indexOfIgnoreCase (const int startIndex, const String& other) const throw()
  8823. {
  8824. if (other.isNotEmpty())
  8825. {
  8826. const int len = other.length();
  8827. const int end = length() - len;
  8828. for (int i = jmax (0, startIndex); i <= end; ++i)
  8829. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8830. return i;
  8831. }
  8832. return -1;
  8833. }
  8834. int String::lastIndexOf (const String& other) const throw()
  8835. {
  8836. if (other.isNotEmpty())
  8837. {
  8838. const int len = other.length();
  8839. int i = length() - len;
  8840. if (i >= 0)
  8841. {
  8842. const juce_wchar* n = text + i;
  8843. while (i >= 0)
  8844. {
  8845. if (CharacterFunctions::compare (n--, other.text, len) == 0)
  8846. return i;
  8847. --i;
  8848. }
  8849. }
  8850. }
  8851. return -1;
  8852. }
  8853. int String::lastIndexOfIgnoreCase (const String& other) const throw()
  8854. {
  8855. if (other.isNotEmpty())
  8856. {
  8857. const int len = other.length();
  8858. int i = length() - len;
  8859. if (i >= 0)
  8860. {
  8861. const juce_wchar* n = text + i;
  8862. while (i >= 0)
  8863. {
  8864. if (CharacterFunctions::compareIgnoreCase (n--, other.text, len) == 0)
  8865. return i;
  8866. --i;
  8867. }
  8868. }
  8869. }
  8870. return -1;
  8871. }
  8872. int String::lastIndexOfAnyOf (const String& charactersToLookFor, const bool ignoreCase) const throw()
  8873. {
  8874. for (int i = length(); --i >= 0;)
  8875. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, text[i], ignoreCase) >= 0)
  8876. return i;
  8877. return -1;
  8878. }
  8879. bool String::contains (const String& other) const throw()
  8880. {
  8881. return indexOf (other) >= 0;
  8882. }
  8883. bool String::containsChar (const juce_wchar character) const throw()
  8884. {
  8885. const juce_wchar* t = text;
  8886. for (;;)
  8887. {
  8888. if (*t == 0)
  8889. return false;
  8890. if (*t == character)
  8891. return true;
  8892. ++t;
  8893. }
  8894. }
  8895. bool String::containsIgnoreCase (const String& t) const throw()
  8896. {
  8897. return indexOfIgnoreCase (t) >= 0;
  8898. }
  8899. int String::indexOfWholeWord (const String& word) const throw()
  8900. {
  8901. if (word.isNotEmpty())
  8902. {
  8903. const int wordLen = word.length();
  8904. const int end = length() - wordLen;
  8905. const juce_wchar* t = text;
  8906. for (int i = 0; i <= end; ++i)
  8907. {
  8908. if (CharacterFunctions::compare (t, word.text, wordLen) == 0
  8909. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8910. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8911. {
  8912. return i;
  8913. }
  8914. ++t;
  8915. }
  8916. }
  8917. return -1;
  8918. }
  8919. int String::indexOfWholeWordIgnoreCase (const String& word) const throw()
  8920. {
  8921. if (word.isNotEmpty())
  8922. {
  8923. const int wordLen = word.length();
  8924. const int end = length() - wordLen;
  8925. const juce_wchar* t = text;
  8926. for (int i = 0; i <= end; ++i)
  8927. {
  8928. if (CharacterFunctions::compareIgnoreCase (t, word.text, wordLen) == 0
  8929. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8930. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8931. {
  8932. return i;
  8933. }
  8934. ++t;
  8935. }
  8936. }
  8937. return -1;
  8938. }
  8939. bool String::containsWholeWord (const String& wordToLookFor) const throw()
  8940. {
  8941. return indexOfWholeWord (wordToLookFor) >= 0;
  8942. }
  8943. bool String::containsWholeWordIgnoreCase (const String& wordToLookFor) const throw()
  8944. {
  8945. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  8946. }
  8947. static int indexOfMatch (const juce_wchar* const wildcard,
  8948. const juce_wchar* const test,
  8949. const bool ignoreCase) throw()
  8950. {
  8951. int start = 0;
  8952. while (test [start] != 0)
  8953. {
  8954. int i = 0;
  8955. for (;;)
  8956. {
  8957. const juce_wchar wc = wildcard [i];
  8958. const juce_wchar c = test [i + start];
  8959. if (wc == c
  8960. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  8961. || (wc == '?' && c != 0))
  8962. {
  8963. if (wc == 0)
  8964. return start;
  8965. ++i;
  8966. }
  8967. else
  8968. {
  8969. if (wc == '*' && (wildcard [i + 1] == 0
  8970. || indexOfMatch (wildcard + i + 1,
  8971. test + start + i,
  8972. ignoreCase) >= 0))
  8973. {
  8974. return start;
  8975. }
  8976. break;
  8977. }
  8978. }
  8979. ++start;
  8980. }
  8981. return -1;
  8982. }
  8983. bool String::matchesWildcard (const String& wildcard, const bool ignoreCase) const throw()
  8984. {
  8985. int i = 0;
  8986. for (;;)
  8987. {
  8988. const juce_wchar wc = wildcard.text [i];
  8989. const juce_wchar c = text [i];
  8990. if (wc == c
  8991. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  8992. || (wc == '?' && c != 0))
  8993. {
  8994. if (wc == 0)
  8995. return true;
  8996. ++i;
  8997. }
  8998. else
  8999. {
  9000. return wc == '*' && (wildcard [i + 1] == 0
  9001. || indexOfMatch (wildcard.text + i + 1,
  9002. text + i,
  9003. ignoreCase) >= 0);
  9004. }
  9005. }
  9006. }
  9007. const String String::repeatedString (const String& stringToRepeat, int numberOfTimesToRepeat)
  9008. {
  9009. const int len = stringToRepeat.length();
  9010. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  9011. juce_wchar* n = result.text;
  9012. *n = 0;
  9013. while (--numberOfTimesToRepeat >= 0)
  9014. {
  9015. StringHolder::copyChars (n, stringToRepeat.text, len);
  9016. n += len;
  9017. }
  9018. return result;
  9019. }
  9020. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9021. {
  9022. jassert (padCharacter != 0);
  9023. const int len = length();
  9024. if (len >= minimumLength || padCharacter == 0)
  9025. return *this;
  9026. String result ((size_t) minimumLength + 1, (int) 0);
  9027. juce_wchar* n = result.text;
  9028. minimumLength -= len;
  9029. while (--minimumLength >= 0)
  9030. *n++ = padCharacter;
  9031. StringHolder::copyChars (n, text, len);
  9032. return result;
  9033. }
  9034. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9035. {
  9036. jassert (padCharacter != 0);
  9037. const int len = length();
  9038. if (len >= minimumLength || padCharacter == 0)
  9039. return *this;
  9040. String result (*this, (size_t) minimumLength);
  9041. juce_wchar* n = result.text + len;
  9042. minimumLength -= len;
  9043. while (--minimumLength >= 0)
  9044. *n++ = padCharacter;
  9045. *n = 0;
  9046. return result;
  9047. }
  9048. const String String::replaceSection (int index, int numCharsToReplace, const String& stringToInsert) const
  9049. {
  9050. if (index < 0)
  9051. {
  9052. // a negative index to replace from?
  9053. jassertfalse
  9054. index = 0;
  9055. }
  9056. if (numCharsToReplace < 0)
  9057. {
  9058. // replacing a negative number of characters?
  9059. numCharsToReplace = 0;
  9060. jassertfalse;
  9061. }
  9062. const int len = length();
  9063. if (index + numCharsToReplace > len)
  9064. {
  9065. if (index > len)
  9066. {
  9067. // replacing beyond the end of the string?
  9068. index = len;
  9069. jassertfalse
  9070. }
  9071. numCharsToReplace = len - index;
  9072. }
  9073. const int newStringLen = stringToInsert.length();
  9074. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9075. if (newTotalLen <= 0)
  9076. return String::empty;
  9077. String result ((size_t) newTotalLen, (int) 0);
  9078. StringHolder::copyChars (result.text, text, index);
  9079. if (newStringLen > 0)
  9080. StringHolder::copyChars (result.text + index, stringToInsert.text, newStringLen);
  9081. const int endStringLen = newTotalLen - (index + newStringLen);
  9082. if (endStringLen > 0)
  9083. StringHolder::copyChars (result.text + (index + newStringLen),
  9084. text + (index + numCharsToReplace),
  9085. endStringLen);
  9086. return result;
  9087. }
  9088. const String String::replace (const String& stringToReplace, const String& stringToInsert, const bool ignoreCase) const
  9089. {
  9090. const int stringToReplaceLen = stringToReplace.length();
  9091. const int stringToInsertLen = stringToInsert.length();
  9092. int i = 0;
  9093. String result (*this);
  9094. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9095. : result.indexOf (i, stringToReplace))) >= 0)
  9096. {
  9097. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9098. i += stringToInsertLen;
  9099. }
  9100. return result;
  9101. }
  9102. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  9103. {
  9104. const int index = indexOfChar (charToReplace);
  9105. if (index < 0)
  9106. return *this;
  9107. String result (*this, size_t());
  9108. juce_wchar* t = result.text + index;
  9109. while (*t != 0)
  9110. {
  9111. if (*t == charToReplace)
  9112. *t = charToInsert;
  9113. ++t;
  9114. }
  9115. return result;
  9116. }
  9117. const String String::replaceCharacters (const String& charactersToReplace,
  9118. const String& charactersToInsertInstead) const
  9119. {
  9120. String result (*this, size_t());
  9121. juce_wchar* t = result.text;
  9122. const int len2 = charactersToInsertInstead.length();
  9123. // the two strings passed in are supposed to be the same length!
  9124. jassert (len2 == charactersToReplace.length());
  9125. while (*t != 0)
  9126. {
  9127. const int index = charactersToReplace.indexOfChar (*t);
  9128. if (((unsigned int) index) < (unsigned int) len2)
  9129. *t = charactersToInsertInstead [index];
  9130. ++t;
  9131. }
  9132. return result;
  9133. }
  9134. bool String::startsWith (const String& other) const throw()
  9135. {
  9136. return CharacterFunctions::compare (text, other.text, other.length()) == 0;
  9137. }
  9138. bool String::startsWithIgnoreCase (const String& other) const throw()
  9139. {
  9140. return CharacterFunctions::compareIgnoreCase (text, other.text, other.length()) == 0;
  9141. }
  9142. bool String::startsWithChar (const juce_wchar character) const throw()
  9143. {
  9144. jassert (character != 0); // strings can't contain a null character!
  9145. return text[0] == character;
  9146. }
  9147. bool String::endsWithChar (const juce_wchar character) const throw()
  9148. {
  9149. jassert (character != 0); // strings can't contain a null character!
  9150. return text[0] != 0
  9151. && text [length() - 1] == character;
  9152. }
  9153. bool String::endsWith (const String& other) const throw()
  9154. {
  9155. const int thisLen = length();
  9156. const int otherLen = other.length();
  9157. return thisLen >= otherLen
  9158. && CharacterFunctions::compare (text + thisLen - otherLen, other.text) == 0;
  9159. }
  9160. bool String::endsWithIgnoreCase (const String& other) const throw()
  9161. {
  9162. const int thisLen = length();
  9163. const int otherLen = other.length();
  9164. return thisLen >= otherLen
  9165. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other.text) == 0;
  9166. }
  9167. const String String::toUpperCase() const
  9168. {
  9169. String result (*this, size_t());
  9170. CharacterFunctions::toUpperCase (result.text);
  9171. return result;
  9172. }
  9173. const String String::toLowerCase() const
  9174. {
  9175. String result (*this, size_t());
  9176. CharacterFunctions::toLowerCase (result.text);
  9177. return result;
  9178. }
  9179. juce_wchar& String::operator[] (const int index)
  9180. {
  9181. jassert (((unsigned int) index) <= (unsigned int) length());
  9182. text = StringHolder::makeUnique (text);
  9183. return text [index];
  9184. }
  9185. juce_wchar String::getLastCharacter() const throw()
  9186. {
  9187. return isEmpty() ? juce_wchar() : text [length() - 1];
  9188. }
  9189. const String String::substring (int start, int end) const
  9190. {
  9191. if (start < 0)
  9192. start = 0;
  9193. else if (end <= start)
  9194. return empty;
  9195. int len = 0;
  9196. while (len <= end && text [len] != 0)
  9197. ++len;
  9198. if (end >= len)
  9199. {
  9200. if (start == 0)
  9201. return *this;
  9202. end = len;
  9203. }
  9204. return String (text + start, end - start);
  9205. }
  9206. const String String::substring (const int start) const
  9207. {
  9208. if (start <= 0)
  9209. return *this;
  9210. const int len = length();
  9211. if (start >= len)
  9212. return empty;
  9213. return String (text + start, len - start);
  9214. }
  9215. const String String::dropLastCharacters (const int numberToDrop) const
  9216. {
  9217. return String (text, jmax (0, length() - numberToDrop));
  9218. }
  9219. const String String::getLastCharacters (const int numCharacters) const
  9220. {
  9221. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9222. }
  9223. const String String::fromFirstOccurrenceOf (const String& sub,
  9224. const bool includeSubString,
  9225. const bool ignoreCase) const
  9226. {
  9227. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9228. : indexOf (sub);
  9229. if (i < 0)
  9230. return empty;
  9231. return substring (includeSubString ? i : i + sub.length());
  9232. }
  9233. const String String::fromLastOccurrenceOf (const String& sub,
  9234. const bool includeSubString,
  9235. const bool ignoreCase) const
  9236. {
  9237. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9238. : lastIndexOf (sub);
  9239. if (i < 0)
  9240. return *this;
  9241. return substring (includeSubString ? i : i + sub.length());
  9242. }
  9243. const String String::upToFirstOccurrenceOf (const String& sub,
  9244. const bool includeSubString,
  9245. const bool ignoreCase) const
  9246. {
  9247. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9248. : indexOf (sub);
  9249. if (i < 0)
  9250. return *this;
  9251. return substring (0, includeSubString ? i + sub.length() : i);
  9252. }
  9253. const String String::upToLastOccurrenceOf (const String& sub,
  9254. const bool includeSubString,
  9255. const bool ignoreCase) const
  9256. {
  9257. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9258. : lastIndexOf (sub);
  9259. if (i < 0)
  9260. return *this;
  9261. return substring (0, includeSubString ? i + sub.length() : i);
  9262. }
  9263. bool String::isQuotedString() const
  9264. {
  9265. const String trimmed (trimStart());
  9266. return trimmed[0] == '"'
  9267. || trimmed[0] == '\'';
  9268. }
  9269. const String String::unquoted() const
  9270. {
  9271. String s (*this);
  9272. if (s.text[0] == '"' || s.text[0] == '\'')
  9273. s = s.substring (1);
  9274. const int lastCharIndex = s.length() - 1;
  9275. if (lastCharIndex >= 0
  9276. && (s [lastCharIndex] == '"' || s[lastCharIndex] == '\''))
  9277. s [lastCharIndex] = 0;
  9278. return s;
  9279. }
  9280. const String String::quoted (const juce_wchar quoteCharacter) const
  9281. {
  9282. if (isEmpty())
  9283. return charToString (quoteCharacter) + quoteCharacter;
  9284. String t (*this);
  9285. if (! t.startsWithChar (quoteCharacter))
  9286. t = charToString (quoteCharacter) + t;
  9287. if (! t.endsWithChar (quoteCharacter))
  9288. t += quoteCharacter;
  9289. return t;
  9290. }
  9291. const String String::trim() const
  9292. {
  9293. if (isEmpty())
  9294. return empty;
  9295. int start = 0;
  9296. while (CharacterFunctions::isWhitespace (text [start]))
  9297. ++start;
  9298. const int len = length();
  9299. int end = len - 1;
  9300. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9301. --end;
  9302. ++end;
  9303. if (end <= start)
  9304. return empty;
  9305. else if (start > 0 || end < len)
  9306. return String (text + start, end - start);
  9307. return *this;
  9308. }
  9309. const String String::trimStart() const
  9310. {
  9311. if (isEmpty())
  9312. return empty;
  9313. const juce_wchar* t = text;
  9314. while (CharacterFunctions::isWhitespace (*t))
  9315. ++t;
  9316. if (t == text)
  9317. return *this;
  9318. return String (t);
  9319. }
  9320. const String String::trimEnd() const
  9321. {
  9322. if (isEmpty())
  9323. return empty;
  9324. const juce_wchar* endT = text + (length() - 1);
  9325. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9326. --endT;
  9327. return String (text, (int) (++endT - text));
  9328. }
  9329. const String String::trimCharactersAtStart (const String& charactersToTrim) const
  9330. {
  9331. const juce_wchar* t = text;
  9332. while (charactersToTrim.containsChar (*t))
  9333. ++t;
  9334. if (t == text)
  9335. return *this;
  9336. return String (t);
  9337. }
  9338. const String String::trimCharactersAtEnd (const String& charactersToTrim) const
  9339. {
  9340. if (isEmpty())
  9341. return empty;
  9342. const juce_wchar* endT = text + (length() - 1);
  9343. while (endT >= text && charactersToTrim.containsChar (*endT))
  9344. --endT;
  9345. return String (text, (int) (++endT - text));
  9346. }
  9347. const String String::retainCharacters (const String& charactersToRetain) const
  9348. {
  9349. if (isEmpty())
  9350. return empty;
  9351. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9352. juce_wchar* dst = result.text;
  9353. const juce_wchar* src = text;
  9354. while (*src != 0)
  9355. {
  9356. if (charactersToRetain.containsChar (*src))
  9357. *dst++ = *src;
  9358. ++src;
  9359. }
  9360. *dst = 0;
  9361. return result;
  9362. }
  9363. const String String::removeCharacters (const String& charactersToRemove) const
  9364. {
  9365. if (isEmpty())
  9366. return empty;
  9367. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9368. juce_wchar* dst = result.text;
  9369. const juce_wchar* src = text;
  9370. while (*src != 0)
  9371. {
  9372. if (! charactersToRemove.containsChar (*src))
  9373. *dst++ = *src;
  9374. ++src;
  9375. }
  9376. *dst = 0;
  9377. return result;
  9378. }
  9379. const String String::initialSectionContainingOnly (const String& permittedCharacters) const
  9380. {
  9381. int i = 0;
  9382. for (;;)
  9383. {
  9384. if (! permittedCharacters.containsChar (text[i]))
  9385. break;
  9386. ++i;
  9387. }
  9388. return substring (0, i);
  9389. }
  9390. const String String::initialSectionNotContaining (const String& charactersToStopAt) const
  9391. {
  9392. const juce_wchar* const t = text;
  9393. int i = 0;
  9394. while (t[i] != 0)
  9395. {
  9396. if (charactersToStopAt.containsChar (t[i]))
  9397. return String (text, i);
  9398. ++i;
  9399. }
  9400. return empty;
  9401. }
  9402. bool String::containsOnly (const String& chars) const throw()
  9403. {
  9404. const juce_wchar* t = text;
  9405. while (*t != 0)
  9406. if (! chars.containsChar (*t++))
  9407. return false;
  9408. return true;
  9409. }
  9410. bool String::containsAnyOf (const String& chars) const throw()
  9411. {
  9412. const juce_wchar* t = text;
  9413. while (*t != 0)
  9414. if (chars.containsChar (*t++))
  9415. return true;
  9416. return false;
  9417. }
  9418. bool String::containsNonWhitespaceChars() const throw()
  9419. {
  9420. const juce_wchar* t = text;
  9421. while (*t != 0)
  9422. if (! CharacterFunctions::isWhitespace (*t++))
  9423. return true;
  9424. return false;
  9425. }
  9426. const String String::formatted (const juce_wchar* const pf, ... )
  9427. {
  9428. jassert (pf != 0);
  9429. va_list args;
  9430. va_start (args, pf);
  9431. size_t bufferSize = 256;
  9432. String result (bufferSize, (int) 0);
  9433. result.text[0] = 0;
  9434. for (;;)
  9435. {
  9436. #if JUCE_LINUX && JUCE_64BIT
  9437. va_list tempArgs;
  9438. va_copy (tempArgs, args);
  9439. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, tempArgs);
  9440. va_end (tempArgs);
  9441. #elif JUCE_WINDOWS
  9442. #ifdef _MSC_VER
  9443. #pragma warning (push)
  9444. #pragma warning (disable: 4996)
  9445. #endif
  9446. const int num = (int) _vsnwprintf (result.text, bufferSize - 1, pf, args);
  9447. #ifdef _MSC_VER
  9448. #pragma warning (pop)
  9449. #endif
  9450. #else
  9451. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, args);
  9452. #endif
  9453. if (num > 0)
  9454. return result;
  9455. bufferSize += 256;
  9456. if (num == 0 || bufferSize > 65536) // the upper limit is a sanity check to avoid situations where vprintf repeatedly
  9457. break; // returns -1 because of an error rather than because it needs more space.
  9458. result.preallocateStorage (bufferSize);
  9459. }
  9460. return empty;
  9461. }
  9462. int String::getIntValue() const throw()
  9463. {
  9464. return CharacterFunctions::getIntValue (text);
  9465. }
  9466. int String::getTrailingIntValue() const throw()
  9467. {
  9468. int n = 0;
  9469. int mult = 1;
  9470. const juce_wchar* t = text + length();
  9471. while (--t >= text)
  9472. {
  9473. const juce_wchar c = *t;
  9474. if (! CharacterFunctions::isDigit (c))
  9475. {
  9476. if (c == '-')
  9477. n = -n;
  9478. break;
  9479. }
  9480. n += mult * (c - '0');
  9481. mult *= 10;
  9482. }
  9483. return n;
  9484. }
  9485. int64 String::getLargeIntValue() const throw()
  9486. {
  9487. return CharacterFunctions::getInt64Value (text);
  9488. }
  9489. float String::getFloatValue() const throw()
  9490. {
  9491. return (float) CharacterFunctions::getDoubleValue (text);
  9492. }
  9493. double String::getDoubleValue() const throw()
  9494. {
  9495. return CharacterFunctions::getDoubleValue (text);
  9496. }
  9497. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9498. const String String::toHexString (const int number)
  9499. {
  9500. juce_wchar buffer[32];
  9501. juce_wchar* const end = buffer + 32;
  9502. juce_wchar* t = end;
  9503. *--t = 0;
  9504. unsigned int v = (unsigned int) number;
  9505. do
  9506. {
  9507. *--t = hexDigits [v & 15];
  9508. v >>= 4;
  9509. } while (v != 0);
  9510. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9511. }
  9512. const String String::toHexString (const int64 number)
  9513. {
  9514. juce_wchar buffer[32];
  9515. juce_wchar* const end = buffer + 32;
  9516. juce_wchar* t = end;
  9517. *--t = 0;
  9518. uint64 v = (uint64) number;
  9519. do
  9520. {
  9521. *--t = hexDigits [(int) (v & 15)];
  9522. v >>= 4;
  9523. } while (v != 0);
  9524. return String (t, (int) (((char*) end) - (char*) t));
  9525. }
  9526. const String String::toHexString (const short number)
  9527. {
  9528. return toHexString ((int) (unsigned short) number);
  9529. }
  9530. const String String::toHexString (const unsigned char* data,
  9531. const int size,
  9532. const int groupSize)
  9533. {
  9534. if (size <= 0)
  9535. return empty;
  9536. int numChars = (size * 2) + 2;
  9537. if (groupSize > 0)
  9538. numChars += size / groupSize;
  9539. String s ((size_t) numChars, (int) 0);
  9540. juce_wchar* d = s.text;
  9541. for (int i = 0; i < size; ++i)
  9542. {
  9543. *d++ = hexDigits [(*data) >> 4];
  9544. *d++ = hexDigits [(*data) & 0xf];
  9545. ++data;
  9546. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9547. *d++ = ' ';
  9548. }
  9549. *d = 0;
  9550. return s;
  9551. }
  9552. int String::getHexValue32() const throw()
  9553. {
  9554. int result = 0;
  9555. const juce_wchar* c = text;
  9556. for (;;)
  9557. {
  9558. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9559. if (hexValue >= 0)
  9560. result = (result << 4) | hexValue;
  9561. else if (*c == 0)
  9562. break;
  9563. ++c;
  9564. }
  9565. return result;
  9566. }
  9567. int64 String::getHexValue64() const throw()
  9568. {
  9569. int64 result = 0;
  9570. const juce_wchar* c = text;
  9571. for (;;)
  9572. {
  9573. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9574. if (hexValue >= 0)
  9575. result = (result << 4) | hexValue;
  9576. else if (*c == 0)
  9577. break;
  9578. ++c;
  9579. }
  9580. return result;
  9581. }
  9582. const String String::createStringFromData (const void* const data_, const int size)
  9583. {
  9584. const char* const data = static_cast <const char*> (data_);
  9585. if (size <= 0 || data == 0)
  9586. {
  9587. return empty;
  9588. }
  9589. else if (size < 2)
  9590. {
  9591. return charToString (data[0]);
  9592. }
  9593. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9594. || (data[0] == (char)-1 && data[1] == (char)-2))
  9595. {
  9596. // assume it's 16-bit unicode
  9597. const bool bigEndian = (data[0] == (char)-2);
  9598. const int numChars = size / 2 - 1;
  9599. String result;
  9600. result.preallocateStorage (numChars + 2);
  9601. const uint16* const src = (const uint16*) (data + 2);
  9602. juce_wchar* const dst = const_cast <juce_wchar*> (static_cast <const juce_wchar*> (result));
  9603. if (bigEndian)
  9604. {
  9605. for (int i = 0; i < numChars; ++i)
  9606. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9607. }
  9608. else
  9609. {
  9610. for (int i = 0; i < numChars; ++i)
  9611. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9612. }
  9613. dst [numChars] = 0;
  9614. return result;
  9615. }
  9616. else
  9617. {
  9618. return String::fromUTF8 (data, size);
  9619. }
  9620. }
  9621. const char* String::toUTF8() const
  9622. {
  9623. if (isEmpty())
  9624. {
  9625. return reinterpret_cast <const char*> (text);
  9626. }
  9627. else
  9628. {
  9629. const int currentLen = length() + 1;
  9630. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9631. String* const mutableThis = const_cast <String*> (this);
  9632. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9633. char* const otherCopy = reinterpret_cast <char*> (text + currentLen);
  9634. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9635. return otherCopy;
  9636. }
  9637. }
  9638. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9639. {
  9640. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9641. int num = 0, index = 0;
  9642. for (;;)
  9643. {
  9644. const uint32 c = (uint32) text [index++];
  9645. if (c >= 0x80)
  9646. {
  9647. int numExtraBytes = 1;
  9648. if (c >= 0x800)
  9649. {
  9650. ++numExtraBytes;
  9651. if (c >= 0x10000)
  9652. {
  9653. ++numExtraBytes;
  9654. if (c >= 0x200000)
  9655. {
  9656. ++numExtraBytes;
  9657. if (c >= 0x4000000)
  9658. ++numExtraBytes;
  9659. }
  9660. }
  9661. }
  9662. if (buffer != 0)
  9663. {
  9664. if (num + numExtraBytes >= maxBufferSizeBytes)
  9665. {
  9666. buffer [num++] = 0;
  9667. break;
  9668. }
  9669. else
  9670. {
  9671. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9672. while (--numExtraBytes >= 0)
  9673. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9674. }
  9675. }
  9676. else
  9677. {
  9678. num += numExtraBytes + 1;
  9679. }
  9680. }
  9681. else
  9682. {
  9683. if (buffer != 0)
  9684. {
  9685. if (num + 1 >= maxBufferSizeBytes)
  9686. {
  9687. buffer [num++] = 0;
  9688. break;
  9689. }
  9690. buffer [num] = (uint8) c;
  9691. }
  9692. ++num;
  9693. }
  9694. if (c == 0)
  9695. break;
  9696. }
  9697. return num;
  9698. }
  9699. int String::getNumBytesAsUTF8() const throw()
  9700. {
  9701. int num = 0;
  9702. const juce_wchar* t = text;
  9703. for (;;)
  9704. {
  9705. const uint32 c = (uint32) *t;
  9706. if (c >= 0x80)
  9707. {
  9708. ++num;
  9709. if (c >= 0x800)
  9710. {
  9711. ++num;
  9712. if (c >= 0x10000)
  9713. {
  9714. ++num;
  9715. if (c >= 0x200000)
  9716. {
  9717. ++num;
  9718. if (c >= 0x4000000)
  9719. ++num;
  9720. }
  9721. }
  9722. }
  9723. }
  9724. else if (c == 0)
  9725. break;
  9726. ++num;
  9727. ++t;
  9728. }
  9729. return num;
  9730. }
  9731. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9732. {
  9733. if (buffer == 0)
  9734. return empty;
  9735. if (bufferSizeBytes < 0)
  9736. bufferSizeBytes = std::numeric_limits<int>::max();
  9737. size_t numBytes;
  9738. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9739. if (buffer [numBytes] == 0)
  9740. break;
  9741. String result ((size_t) numBytes + 1, (int) 0);
  9742. juce_wchar* dest = result.text;
  9743. size_t i = 0;
  9744. while (i < numBytes)
  9745. {
  9746. const char c = buffer [i++];
  9747. if (c < 0)
  9748. {
  9749. unsigned int mask = 0x7f;
  9750. int bit = 0x40;
  9751. int numExtraValues = 0;
  9752. while (bit != 0 && (c & bit) != 0)
  9753. {
  9754. bit >>= 1;
  9755. mask >>= 1;
  9756. ++numExtraValues;
  9757. }
  9758. int n = (mask & (unsigned char) c);
  9759. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9760. {
  9761. const char nextByte = buffer[i];
  9762. if ((nextByte & 0xc0) != 0x80)
  9763. break;
  9764. n <<= 6;
  9765. n |= (nextByte & 0x3f);
  9766. ++i;
  9767. }
  9768. *dest++ = (juce_wchar) n;
  9769. }
  9770. else
  9771. {
  9772. *dest++ = (juce_wchar) c;
  9773. }
  9774. }
  9775. *dest = 0;
  9776. return result;
  9777. }
  9778. const char* String::toCString() const
  9779. {
  9780. if (isEmpty())
  9781. {
  9782. return reinterpret_cast <const char*> (text);
  9783. }
  9784. else
  9785. {
  9786. const int len = length();
  9787. String* const mutableThis = const_cast <String*> (this);
  9788. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9789. char* otherCopy = reinterpret_cast <char*> (text + len + 1);
  9790. CharacterFunctions::copy (otherCopy, text, len);
  9791. otherCopy [len] = 0;
  9792. return otherCopy;
  9793. }
  9794. }
  9795. #ifdef _MSC_VER
  9796. #pragma warning (disable: 4514 4996)
  9797. #pragma warning (push)
  9798. #endif
  9799. int String::getNumBytesAsCString() const throw()
  9800. {
  9801. return (int) wcstombs (0, text, 0);
  9802. }
  9803. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9804. {
  9805. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9806. if (destBuffer != 0 && numBytes >= 0)
  9807. destBuffer [numBytes] = 0;
  9808. return numBytes;
  9809. }
  9810. #ifdef _MSC_VER
  9811. #pragma warning (pop)
  9812. #endif
  9813. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  9814. {
  9815. StringHolder::copyChars (destBuffer, text, jmin (maxCharsToCopy, length()));
  9816. }
  9817. String::Concatenator::Concatenator (String& stringToAppendTo)
  9818. : result (stringToAppendTo),
  9819. nextIndex (stringToAppendTo.length())
  9820. {
  9821. }
  9822. String::Concatenator::~Concatenator()
  9823. {
  9824. }
  9825. void String::Concatenator::append (const String& s)
  9826. {
  9827. const int len = s.length();
  9828. if (len > 0)
  9829. {
  9830. result.preallocateStorage (nextIndex + len);
  9831. s.copyToUnicode (static_cast <juce_wchar*> (result) + nextIndex, len);
  9832. nextIndex += len;
  9833. }
  9834. }
  9835. END_JUCE_NAMESPACE
  9836. /*** End of inlined file: juce_String.cpp ***/
  9837. /*** Start of inlined file: juce_StringArray.cpp ***/
  9838. BEGIN_JUCE_NAMESPACE
  9839. StringArray::StringArray() throw()
  9840. {
  9841. }
  9842. StringArray::StringArray (const StringArray& other)
  9843. : strings (other.strings)
  9844. {
  9845. }
  9846. StringArray::StringArray (const String& firstValue)
  9847. {
  9848. strings.add (firstValue);
  9849. }
  9850. StringArray::StringArray (const juce_wchar** const initialStrings,
  9851. const int numberOfStrings)
  9852. {
  9853. for (int i = 0; i < numberOfStrings; ++i)
  9854. strings.add (initialStrings [i]);
  9855. }
  9856. StringArray::StringArray (const char** const initialStrings,
  9857. const int numberOfStrings)
  9858. {
  9859. for (int i = 0; i < numberOfStrings; ++i)
  9860. strings.add (initialStrings [i]);
  9861. }
  9862. StringArray::StringArray (const juce_wchar** const initialStrings)
  9863. {
  9864. int i = 0;
  9865. while (initialStrings[i] != 0)
  9866. strings.add (initialStrings [i++]);
  9867. }
  9868. StringArray::StringArray (const char** const initialStrings)
  9869. {
  9870. int i = 0;
  9871. while (initialStrings[i] != 0)
  9872. strings.add (initialStrings [i++]);
  9873. }
  9874. StringArray& StringArray::operator= (const StringArray& other)
  9875. {
  9876. strings = other.strings;
  9877. return *this;
  9878. }
  9879. StringArray::~StringArray()
  9880. {
  9881. }
  9882. bool StringArray::operator== (const StringArray& other) const throw()
  9883. {
  9884. if (other.size() != size())
  9885. return false;
  9886. for (int i = size(); --i >= 0;)
  9887. if (other.strings.getReference(i) != strings.getReference(i))
  9888. return false;
  9889. return true;
  9890. }
  9891. bool StringArray::operator!= (const StringArray& other) const throw()
  9892. {
  9893. return ! operator== (other);
  9894. }
  9895. void StringArray::clear()
  9896. {
  9897. strings.clear();
  9898. }
  9899. const String& StringArray::operator[] (const int index) const throw()
  9900. {
  9901. if (((unsigned int) index) < (unsigned int) strings.size())
  9902. return strings.getReference (index);
  9903. return String::empty;
  9904. }
  9905. void StringArray::add (const String& newString)
  9906. {
  9907. strings.add (newString);
  9908. }
  9909. void StringArray::insert (const int index, const String& newString)
  9910. {
  9911. strings.insert (index, newString);
  9912. }
  9913. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  9914. {
  9915. if (! contains (newString, ignoreCase))
  9916. add (newString);
  9917. }
  9918. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  9919. {
  9920. if (startIndex < 0)
  9921. {
  9922. jassertfalse
  9923. startIndex = 0;
  9924. }
  9925. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  9926. numElementsToAdd = otherArray.size() - startIndex;
  9927. while (--numElementsToAdd >= 0)
  9928. strings.add (otherArray.strings.getReference (startIndex++));
  9929. }
  9930. void StringArray::set (const int index, const String& newString)
  9931. {
  9932. strings.set (index, newString);
  9933. }
  9934. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  9935. {
  9936. if (ignoreCase)
  9937. {
  9938. for (int i = size(); --i >= 0;)
  9939. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  9940. return true;
  9941. }
  9942. else
  9943. {
  9944. for (int i = size(); --i >= 0;)
  9945. if (stringToLookFor == strings.getReference(i))
  9946. return true;
  9947. }
  9948. return false;
  9949. }
  9950. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  9951. {
  9952. if (i < 0)
  9953. i = 0;
  9954. const int numElements = size();
  9955. if (ignoreCase)
  9956. {
  9957. while (i < numElements)
  9958. {
  9959. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  9960. return i;
  9961. ++i;
  9962. }
  9963. }
  9964. else
  9965. {
  9966. while (i < numElements)
  9967. {
  9968. if (stringToLookFor == strings.getReference (i))
  9969. return i;
  9970. ++i;
  9971. }
  9972. }
  9973. return -1;
  9974. }
  9975. void StringArray::remove (const int index)
  9976. {
  9977. strings.remove (index);
  9978. }
  9979. void StringArray::removeString (const String& stringToRemove,
  9980. const bool ignoreCase)
  9981. {
  9982. if (ignoreCase)
  9983. {
  9984. for (int i = size(); --i >= 0;)
  9985. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  9986. strings.remove (i);
  9987. }
  9988. else
  9989. {
  9990. for (int i = size(); --i >= 0;)
  9991. if (stringToRemove == strings.getReference (i))
  9992. strings.remove (i);
  9993. }
  9994. }
  9995. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  9996. {
  9997. if (removeWhitespaceStrings)
  9998. {
  9999. for (int i = size(); --i >= 0;)
  10000. if (! strings.getReference(i).containsNonWhitespaceChars())
  10001. strings.remove (i);
  10002. }
  10003. else
  10004. {
  10005. for (int i = size(); --i >= 0;)
  10006. if (strings.getReference(i).isEmpty())
  10007. strings.remove (i);
  10008. }
  10009. }
  10010. void StringArray::trim()
  10011. {
  10012. for (int i = size(); --i >= 0;)
  10013. {
  10014. String& s = strings.getReference(i);
  10015. s = s.trim();
  10016. }
  10017. }
  10018. class InternalStringArrayComparator_CaseSensitive
  10019. {
  10020. public:
  10021. static int compareElements (String& first, String& second) { return first.compare (second); }
  10022. };
  10023. class InternalStringArrayComparator_CaseInsensitive
  10024. {
  10025. public:
  10026. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10027. };
  10028. void StringArray::sort (const bool ignoreCase)
  10029. {
  10030. if (ignoreCase)
  10031. {
  10032. InternalStringArrayComparator_CaseInsensitive comp;
  10033. strings.sort (comp);
  10034. }
  10035. else
  10036. {
  10037. InternalStringArrayComparator_CaseSensitive comp;
  10038. strings.sort (comp);
  10039. }
  10040. }
  10041. void StringArray::move (const int currentIndex, int newIndex) throw()
  10042. {
  10043. strings.move (currentIndex, newIndex);
  10044. }
  10045. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10046. {
  10047. const int last = (numberToJoin < 0) ? size()
  10048. : jmin (size(), start + numberToJoin);
  10049. if (start < 0)
  10050. start = 0;
  10051. if (start >= last)
  10052. return String::empty;
  10053. if (start == last - 1)
  10054. return strings.getReference (start);
  10055. const int separatorLen = separator.length();
  10056. int charsNeeded = separatorLen * (last - start - 1);
  10057. for (int i = start; i < last; ++i)
  10058. charsNeeded += strings.getReference(i).length();
  10059. String result;
  10060. result.preallocateStorage (charsNeeded);
  10061. juce_wchar* dest = result;
  10062. while (start < last)
  10063. {
  10064. const String& s = strings.getReference (start);
  10065. const int len = s.length();
  10066. if (len > 0)
  10067. {
  10068. s.copyToUnicode (dest, len);
  10069. dest += len;
  10070. }
  10071. if (++start < last && separatorLen > 0)
  10072. {
  10073. separator.copyToUnicode (dest, separatorLen);
  10074. dest += separatorLen;
  10075. }
  10076. }
  10077. *dest = 0;
  10078. return result;
  10079. }
  10080. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  10081. {
  10082. return addTokens (text, " \n\r\t", preserveQuotedStrings ? "\"" : "");
  10083. }
  10084. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  10085. {
  10086. int num = 0;
  10087. if (text.isNotEmpty())
  10088. {
  10089. bool insideQuotes = false;
  10090. juce_wchar currentQuoteChar = 0;
  10091. int i = 0;
  10092. int tokenStart = 0;
  10093. for (;;)
  10094. {
  10095. const juce_wchar c = text[i];
  10096. const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c));
  10097. if (! isBreak)
  10098. {
  10099. if (quoteCharacters.containsChar (c))
  10100. {
  10101. if (insideQuotes)
  10102. {
  10103. // only break out of quotes-mode if we find a matching quote to the
  10104. // one that we opened with..
  10105. if (currentQuoteChar == c)
  10106. insideQuotes = false;
  10107. }
  10108. else
  10109. {
  10110. insideQuotes = true;
  10111. currentQuoteChar = c;
  10112. }
  10113. }
  10114. }
  10115. else
  10116. {
  10117. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  10118. ++num;
  10119. tokenStart = i + 1;
  10120. }
  10121. if (c == 0)
  10122. break;
  10123. ++i;
  10124. }
  10125. }
  10126. return num;
  10127. }
  10128. int StringArray::addLines (const String& sourceText)
  10129. {
  10130. int numLines = 0;
  10131. const juce_wchar* text = sourceText;
  10132. while (*text != 0)
  10133. {
  10134. const juce_wchar* const startOfLine = text;
  10135. while (*text != 0)
  10136. {
  10137. if (*text == '\r')
  10138. {
  10139. ++text;
  10140. if (*text == '\n')
  10141. ++text;
  10142. break;
  10143. }
  10144. if (*text == '\n')
  10145. {
  10146. ++text;
  10147. break;
  10148. }
  10149. ++text;
  10150. }
  10151. const juce_wchar* endOfLine = text;
  10152. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10153. --endOfLine;
  10154. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10155. --endOfLine;
  10156. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10157. ++numLines;
  10158. }
  10159. return numLines;
  10160. }
  10161. void StringArray::removeDuplicates (const bool ignoreCase)
  10162. {
  10163. for (int i = 0; i < size() - 1; ++i)
  10164. {
  10165. const String s (strings.getReference(i));
  10166. int nextIndex = i + 1;
  10167. for (;;)
  10168. {
  10169. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10170. if (nextIndex < 0)
  10171. break;
  10172. strings.remove (nextIndex);
  10173. }
  10174. }
  10175. }
  10176. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10177. const bool appendNumberToFirstInstance,
  10178. const juce_wchar* preNumberString,
  10179. const juce_wchar* postNumberString)
  10180. {
  10181. if (preNumberString == 0)
  10182. preNumberString = T(" (");
  10183. if (postNumberString == 0)
  10184. postNumberString = T(")");
  10185. for (int i = 0; i < size() - 1; ++i)
  10186. {
  10187. String& s = strings.getReference(i);
  10188. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10189. if (nextIndex >= 0)
  10190. {
  10191. const String original (s);
  10192. int number = 0;
  10193. if (appendNumberToFirstInstance)
  10194. s = original + preNumberString + String (++number) + postNumberString;
  10195. else
  10196. ++number;
  10197. while (nextIndex >= 0)
  10198. {
  10199. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10200. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10201. }
  10202. }
  10203. }
  10204. }
  10205. void StringArray::minimiseStorageOverheads()
  10206. {
  10207. strings.minimiseStorageOverheads();
  10208. }
  10209. END_JUCE_NAMESPACE
  10210. /*** End of inlined file: juce_StringArray.cpp ***/
  10211. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10212. BEGIN_JUCE_NAMESPACE
  10213. StringPairArray::StringPairArray (const bool ignoreCase_)
  10214. : ignoreCase (ignoreCase_)
  10215. {
  10216. }
  10217. StringPairArray::StringPairArray (const StringPairArray& other)
  10218. : keys (other.keys),
  10219. values (other.values),
  10220. ignoreCase (other.ignoreCase)
  10221. {
  10222. }
  10223. StringPairArray::~StringPairArray()
  10224. {
  10225. }
  10226. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  10227. {
  10228. keys = other.keys;
  10229. values = other.values;
  10230. return *this;
  10231. }
  10232. bool StringPairArray::operator== (const StringPairArray& other) const
  10233. {
  10234. for (int i = keys.size(); --i >= 0;)
  10235. if (other [keys[i]] != values[i])
  10236. return false;
  10237. return true;
  10238. }
  10239. bool StringPairArray::operator!= (const StringPairArray& other) const
  10240. {
  10241. return ! operator== (other);
  10242. }
  10243. const String& StringPairArray::operator[] (const String& key) const
  10244. {
  10245. return values [keys.indexOf (key, ignoreCase)];
  10246. }
  10247. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10248. {
  10249. const int i = keys.indexOf (key, ignoreCase);
  10250. if (i >= 0)
  10251. return values[i];
  10252. return defaultReturnValue;
  10253. }
  10254. void StringPairArray::set (const String& key, const String& value)
  10255. {
  10256. const int i = keys.indexOf (key, ignoreCase);
  10257. if (i >= 0)
  10258. {
  10259. values.set (i, value);
  10260. }
  10261. else
  10262. {
  10263. keys.add (key);
  10264. values.add (value);
  10265. }
  10266. }
  10267. void StringPairArray::addArray (const StringPairArray& other)
  10268. {
  10269. for (int i = 0; i < other.size(); ++i)
  10270. set (other.keys[i], other.values[i]);
  10271. }
  10272. void StringPairArray::clear()
  10273. {
  10274. keys.clear();
  10275. values.clear();
  10276. }
  10277. void StringPairArray::remove (const String& key)
  10278. {
  10279. remove (keys.indexOf (key, ignoreCase));
  10280. }
  10281. void StringPairArray::remove (const int index)
  10282. {
  10283. keys.remove (index);
  10284. values.remove (index);
  10285. }
  10286. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  10287. {
  10288. ignoreCase = shouldIgnoreCase;
  10289. }
  10290. const String StringPairArray::getDescription() const
  10291. {
  10292. String s;
  10293. for (int i = 0; i < keys.size(); ++i)
  10294. {
  10295. s << keys[i] << " = " << values[i];
  10296. if (i < keys.size())
  10297. s << ", ";
  10298. }
  10299. return s;
  10300. }
  10301. void StringPairArray::minimiseStorageOverheads()
  10302. {
  10303. keys.minimiseStorageOverheads();
  10304. values.minimiseStorageOverheads();
  10305. }
  10306. END_JUCE_NAMESPACE
  10307. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10308. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10309. BEGIN_JUCE_NAMESPACE
  10310. XmlDocument::XmlDocument (const String& documentText)
  10311. : originalText (documentText),
  10312. ignoreEmptyTextElements (true)
  10313. {
  10314. }
  10315. XmlDocument::XmlDocument (const File& file)
  10316. {
  10317. inputSource = new FileInputSource (file);
  10318. }
  10319. XmlDocument::~XmlDocument()
  10320. {
  10321. }
  10322. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10323. {
  10324. inputSource = newSource;
  10325. }
  10326. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10327. {
  10328. ignoreEmptyTextElements = shouldBeIgnored;
  10329. }
  10330. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10331. {
  10332. return CharacterFunctions::isLetterOrDigit (c)
  10333. || c == '_' || c == '-' || c == ':' || c == '.';
  10334. }
  10335. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10336. {
  10337. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10338. : isXmlIdentifierCharSlow (c);
  10339. }
  10340. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10341. {
  10342. String textToParse (originalText);
  10343. if (textToParse.isEmpty() && inputSource != 0)
  10344. {
  10345. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10346. if (in != 0)
  10347. {
  10348. MemoryBlock data;
  10349. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10350. if (data.getSize() >= 2
  10351. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10352. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10353. {
  10354. textToParse = String::createStringFromData (static_cast <const char*> (data.getData()), (int) data.getSize());
  10355. }
  10356. else
  10357. {
  10358. textToParse = String::fromUTF8 (static_cast <const char*> (data.getData()), (int) data.getSize());
  10359. }
  10360. if (! onlyReadOuterDocumentElement)
  10361. originalText = textToParse;
  10362. }
  10363. }
  10364. input = textToParse;
  10365. lastError = String::empty;
  10366. errorOccurred = false;
  10367. outOfData = false;
  10368. needToLoadDTD = true;
  10369. for (int i = 0; i < 128; ++i)
  10370. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10371. if (textToParse.isEmpty())
  10372. {
  10373. lastError = "not enough input";
  10374. }
  10375. else
  10376. {
  10377. skipHeader();
  10378. if (input != 0)
  10379. {
  10380. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10381. if (! errorOccurred)
  10382. return result.release();
  10383. }
  10384. else
  10385. {
  10386. lastError = "incorrect xml header";
  10387. }
  10388. }
  10389. return 0;
  10390. }
  10391. const String& XmlDocument::getLastParseError() const throw()
  10392. {
  10393. return lastError;
  10394. }
  10395. void XmlDocument::setLastError (const String& desc, const bool carryOn)
  10396. {
  10397. lastError = desc;
  10398. errorOccurred = ! carryOn;
  10399. }
  10400. const String XmlDocument::getFileContents (const String& filename) const
  10401. {
  10402. if (inputSource != 0)
  10403. {
  10404. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10405. if (in != 0)
  10406. return in->readEntireStreamAsString();
  10407. }
  10408. return String::empty;
  10409. }
  10410. juce_wchar XmlDocument::readNextChar() throw()
  10411. {
  10412. if (*input != 0)
  10413. {
  10414. return *input++;
  10415. }
  10416. else
  10417. {
  10418. outOfData = true;
  10419. return 0;
  10420. }
  10421. }
  10422. int XmlDocument::findNextTokenLength() throw()
  10423. {
  10424. int len = 0;
  10425. juce_wchar c = *input;
  10426. while (isXmlIdentifierChar (c))
  10427. c = input [++len];
  10428. return len;
  10429. }
  10430. void XmlDocument::skipHeader()
  10431. {
  10432. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10433. if (found != 0)
  10434. {
  10435. input = found;
  10436. input = CharacterFunctions::find (input, T("?>"));
  10437. if (input == 0)
  10438. return;
  10439. input += 2;
  10440. }
  10441. skipNextWhiteSpace();
  10442. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10443. if (docType == 0)
  10444. return;
  10445. input = docType + 9;
  10446. int n = 1;
  10447. while (n > 0)
  10448. {
  10449. const juce_wchar c = readNextChar();
  10450. if (outOfData)
  10451. return;
  10452. if (c == '<')
  10453. ++n;
  10454. else if (c == '>')
  10455. --n;
  10456. }
  10457. docType += 9;
  10458. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10459. }
  10460. void XmlDocument::skipNextWhiteSpace()
  10461. {
  10462. for (;;)
  10463. {
  10464. juce_wchar c = *input;
  10465. while (CharacterFunctions::isWhitespace (c))
  10466. c = *++input;
  10467. if (c == 0)
  10468. {
  10469. outOfData = true;
  10470. break;
  10471. }
  10472. else if (c == '<')
  10473. {
  10474. if (input[1] == '!'
  10475. && input[2] == '-'
  10476. && input[3] == '-')
  10477. {
  10478. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10479. if (closeComment == 0)
  10480. {
  10481. outOfData = true;
  10482. break;
  10483. }
  10484. input = closeComment + 3;
  10485. continue;
  10486. }
  10487. else if (input[1] == '?')
  10488. {
  10489. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10490. if (closeBracket == 0)
  10491. {
  10492. outOfData = true;
  10493. break;
  10494. }
  10495. input = closeBracket + 2;
  10496. continue;
  10497. }
  10498. }
  10499. break;
  10500. }
  10501. }
  10502. void XmlDocument::readQuotedString (String& result)
  10503. {
  10504. const juce_wchar quote = readNextChar();
  10505. while (! outOfData)
  10506. {
  10507. const juce_wchar c = readNextChar();
  10508. if (c == quote)
  10509. break;
  10510. if (c == '&')
  10511. {
  10512. --input;
  10513. readEntity (result);
  10514. }
  10515. else
  10516. {
  10517. --input;
  10518. const juce_wchar* const start = input;
  10519. for (;;)
  10520. {
  10521. const juce_wchar character = *input;
  10522. if (character == quote)
  10523. {
  10524. result.append (start, (int) (input - start));
  10525. ++input;
  10526. return;
  10527. }
  10528. else if (character == '&')
  10529. {
  10530. result.append (start, (int) (input - start));
  10531. break;
  10532. }
  10533. else if (character == 0)
  10534. {
  10535. outOfData = true;
  10536. setLastError ("unmatched quotes", false);
  10537. break;
  10538. }
  10539. ++input;
  10540. }
  10541. }
  10542. }
  10543. }
  10544. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
  10545. {
  10546. XmlElement* node = 0;
  10547. skipNextWhiteSpace();
  10548. if (outOfData)
  10549. return 0;
  10550. input = CharacterFunctions::find (input, T("<"));
  10551. if (input != 0)
  10552. {
  10553. ++input;
  10554. int tagLen = findNextTokenLength();
  10555. if (tagLen == 0)
  10556. {
  10557. // no tag name - but allow for a gap after the '<' before giving an error
  10558. skipNextWhiteSpace();
  10559. tagLen = findNextTokenLength();
  10560. if (tagLen == 0)
  10561. {
  10562. setLastError ("tag name missing", false);
  10563. return node;
  10564. }
  10565. }
  10566. node = new XmlElement (String (input, tagLen));
  10567. input += tagLen;
  10568. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10569. // look for attributes
  10570. for (;;)
  10571. {
  10572. skipNextWhiteSpace();
  10573. const juce_wchar c = *input;
  10574. // empty tag..
  10575. if (c == '/' && input[1] == '>')
  10576. {
  10577. input += 2;
  10578. break;
  10579. }
  10580. // parse the guts of the element..
  10581. if (c == '>')
  10582. {
  10583. ++input;
  10584. skipNextWhiteSpace();
  10585. if (alsoParseSubElements)
  10586. readChildElements (node);
  10587. break;
  10588. }
  10589. // get an attribute..
  10590. if (isXmlIdentifierChar (c))
  10591. {
  10592. const int attNameLen = findNextTokenLength();
  10593. if (attNameLen > 0)
  10594. {
  10595. const juce_wchar* attNameStart = input;
  10596. input += attNameLen;
  10597. skipNextWhiteSpace();
  10598. if (readNextChar() == '=')
  10599. {
  10600. skipNextWhiteSpace();
  10601. const juce_wchar nextChar = *input;
  10602. if (nextChar == '"' || nextChar == '\'')
  10603. {
  10604. XmlElement::XmlAttributeNode* const newAtt
  10605. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10606. String::empty);
  10607. readQuotedString (newAtt->value);
  10608. if (lastAttribute == 0)
  10609. node->attributes = newAtt;
  10610. else
  10611. lastAttribute->next = newAtt;
  10612. lastAttribute = newAtt;
  10613. continue;
  10614. }
  10615. }
  10616. }
  10617. }
  10618. else
  10619. {
  10620. if (! outOfData)
  10621. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10622. }
  10623. break;
  10624. }
  10625. }
  10626. return node;
  10627. }
  10628. void XmlDocument::readChildElements (XmlElement* parent)
  10629. {
  10630. XmlElement* lastChildNode = 0;
  10631. for (;;)
  10632. {
  10633. skipNextWhiteSpace();
  10634. if (outOfData)
  10635. {
  10636. setLastError ("unmatched tags", false);
  10637. break;
  10638. }
  10639. if (*input == '<')
  10640. {
  10641. if (input[1] == '/')
  10642. {
  10643. // our close tag..
  10644. input = CharacterFunctions::find (input, T(">"));
  10645. ++input;
  10646. break;
  10647. }
  10648. else if (input[1] == '!'
  10649. && input[2] == '['
  10650. && input[3] == 'C'
  10651. && input[4] == 'D'
  10652. && input[5] == 'A'
  10653. && input[6] == 'T'
  10654. && input[7] == 'A'
  10655. && input[8] == '[')
  10656. {
  10657. input += 9;
  10658. const juce_wchar* const inputStart = input;
  10659. int len = 0;
  10660. for (;;)
  10661. {
  10662. if (*input == 0)
  10663. {
  10664. setLastError ("unterminated CDATA section", false);
  10665. outOfData = true;
  10666. break;
  10667. }
  10668. else if (input[0] == ']'
  10669. && input[1] == ']'
  10670. && input[2] == '>')
  10671. {
  10672. input += 3;
  10673. break;
  10674. }
  10675. ++input;
  10676. ++len;
  10677. }
  10678. XmlElement* const e = new XmlElement ((int) 0);
  10679. e->setText (String (inputStart, len));
  10680. if (lastChildNode != 0)
  10681. lastChildNode->nextElement = e;
  10682. else
  10683. parent->addChildElement (e);
  10684. lastChildNode = e;
  10685. }
  10686. else
  10687. {
  10688. // this is some other element, so parse and add it..
  10689. XmlElement* const n = readNextElement (true);
  10690. if (n != 0)
  10691. {
  10692. if (lastChildNode == 0)
  10693. parent->addChildElement (n);
  10694. else
  10695. lastChildNode->nextElement = n;
  10696. lastChildNode = n;
  10697. }
  10698. else
  10699. {
  10700. return;
  10701. }
  10702. }
  10703. }
  10704. else
  10705. {
  10706. // read character block..
  10707. XmlElement* const e = new XmlElement ((int)0);
  10708. if (lastChildNode != 0)
  10709. lastChildNode->nextElement = e;
  10710. else
  10711. parent->addChildElement (e);
  10712. lastChildNode = e;
  10713. String textElementContent;
  10714. for (;;)
  10715. {
  10716. const juce_wchar c = *input;
  10717. if (c == '<')
  10718. break;
  10719. if (c == 0)
  10720. {
  10721. setLastError ("unmatched tags", false);
  10722. outOfData = true;
  10723. return;
  10724. }
  10725. if (c == '&')
  10726. {
  10727. String entity;
  10728. readEntity (entity);
  10729. if (entity.startsWithChar ('<') && entity [1] != 0)
  10730. {
  10731. const juce_wchar* const oldInput = input;
  10732. const bool oldOutOfData = outOfData;
  10733. input = entity;
  10734. outOfData = false;
  10735. for (;;)
  10736. {
  10737. XmlElement* const n = readNextElement (true);
  10738. if (n == 0)
  10739. break;
  10740. if (lastChildNode == 0)
  10741. parent->addChildElement (n);
  10742. else
  10743. lastChildNode->nextElement = n;
  10744. lastChildNode = n;
  10745. }
  10746. input = oldInput;
  10747. outOfData = oldOutOfData;
  10748. }
  10749. else
  10750. {
  10751. textElementContent += entity;
  10752. }
  10753. }
  10754. else
  10755. {
  10756. const juce_wchar* start = input;
  10757. int len = 0;
  10758. for (;;)
  10759. {
  10760. const juce_wchar nextChar = *input;
  10761. if (nextChar == '<' || nextChar == '&')
  10762. {
  10763. break;
  10764. }
  10765. else if (nextChar == 0)
  10766. {
  10767. setLastError ("unmatched tags", false);
  10768. outOfData = true;
  10769. return;
  10770. }
  10771. ++input;
  10772. ++len;
  10773. }
  10774. textElementContent.append (start, len);
  10775. }
  10776. }
  10777. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10778. : textElementContent.isNotEmpty())
  10779. e->setText (textElementContent);
  10780. }
  10781. }
  10782. }
  10783. void XmlDocument::readEntity (String& result)
  10784. {
  10785. // skip over the ampersand
  10786. ++input;
  10787. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10788. {
  10789. input += 4;
  10790. result += '&';
  10791. }
  10792. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10793. {
  10794. input += 5;
  10795. result += '"';
  10796. }
  10797. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  10798. {
  10799. input += 5;
  10800. result += '\'';
  10801. }
  10802. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  10803. {
  10804. input += 3;
  10805. result += '<';
  10806. }
  10807. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  10808. {
  10809. input += 3;
  10810. result += '>';
  10811. }
  10812. else if (*input == '#')
  10813. {
  10814. int charCode = 0;
  10815. ++input;
  10816. if (*input == 'x' || *input == 'X')
  10817. {
  10818. ++input;
  10819. int numChars = 0;
  10820. while (input[0] != ';')
  10821. {
  10822. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  10823. if (hexValue < 0 || ++numChars > 8)
  10824. {
  10825. setLastError ("illegal escape sequence", true);
  10826. break;
  10827. }
  10828. charCode = (charCode << 4) | hexValue;
  10829. ++input;
  10830. }
  10831. ++input;
  10832. }
  10833. else if (input[0] >= '0' && input[0] <= '9')
  10834. {
  10835. int numChars = 0;
  10836. while (input[0] != ';')
  10837. {
  10838. if (++numChars > 12)
  10839. {
  10840. setLastError ("illegal escape sequence", true);
  10841. break;
  10842. }
  10843. charCode = charCode * 10 + (input[0] - '0');
  10844. ++input;
  10845. }
  10846. ++input;
  10847. }
  10848. else
  10849. {
  10850. setLastError ("illegal escape sequence", true);
  10851. result += '&';
  10852. return;
  10853. }
  10854. result << (juce_wchar) charCode;
  10855. }
  10856. else
  10857. {
  10858. const juce_wchar* const entityNameStart = input;
  10859. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  10860. if (closingSemiColon == 0)
  10861. {
  10862. outOfData = true;
  10863. result += '&';
  10864. }
  10865. else
  10866. {
  10867. input = closingSemiColon + 1;
  10868. result += expandExternalEntity (String (entityNameStart,
  10869. (int) (closingSemiColon - entityNameStart)));
  10870. }
  10871. }
  10872. }
  10873. const String XmlDocument::expandEntity (const String& ent)
  10874. {
  10875. if (ent.equalsIgnoreCase ("amp"))
  10876. return String::charToString ('&');
  10877. if (ent.equalsIgnoreCase ("quot"))
  10878. return String::charToString ('"');
  10879. if (ent.equalsIgnoreCase ("apos"))
  10880. return String::charToString ('\'');
  10881. if (ent.equalsIgnoreCase ("lt"))
  10882. return String::charToString ('<');
  10883. if (ent.equalsIgnoreCase ("gt"))
  10884. return String::charToString ('>');
  10885. if (ent[0] == '#')
  10886. {
  10887. if (ent[1] == 'x' || ent[1] == 'X')
  10888. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  10889. if (ent[1] >= '0' && ent[1] <= '9')
  10890. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  10891. setLastError ("illegal escape sequence", false);
  10892. return String::charToString ('&');
  10893. }
  10894. return expandExternalEntity (ent);
  10895. }
  10896. const String XmlDocument::expandExternalEntity (const String& entity)
  10897. {
  10898. if (needToLoadDTD)
  10899. {
  10900. if (dtdText.isNotEmpty())
  10901. {
  10902. while (dtdText.endsWithChar ('>'))
  10903. dtdText = dtdText.dropLastCharacters (1);
  10904. tokenisedDTD.addTokens (dtdText, true);
  10905. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase ("system")
  10906. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  10907. {
  10908. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  10909. tokenisedDTD.clear();
  10910. tokenisedDTD.addTokens (getFileContents (fn), true);
  10911. }
  10912. else
  10913. {
  10914. tokenisedDTD.clear();
  10915. const int openBracket = dtdText.indexOfChar ('[');
  10916. if (openBracket > 0)
  10917. {
  10918. const int closeBracket = dtdText.lastIndexOfChar (']');
  10919. if (closeBracket > openBracket)
  10920. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  10921. closeBracket), true);
  10922. }
  10923. }
  10924. for (int i = tokenisedDTD.size(); --i >= 0;)
  10925. {
  10926. if (tokenisedDTD[i].startsWithChar ('%')
  10927. && tokenisedDTD[i].endsWithChar (';'))
  10928. {
  10929. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  10930. StringArray newToks;
  10931. newToks.addTokens (parsed, true);
  10932. tokenisedDTD.remove (i);
  10933. for (int j = newToks.size(); --j >= 0;)
  10934. tokenisedDTD.insert (i, newToks[j]);
  10935. }
  10936. }
  10937. }
  10938. needToLoadDTD = false;
  10939. }
  10940. for (int i = 0; i < tokenisedDTD.size(); ++i)
  10941. {
  10942. if (tokenisedDTD[i] == entity)
  10943. {
  10944. if (tokenisedDTD[i - 1].equalsIgnoreCase ("<!entity"))
  10945. {
  10946. String ent (tokenisedDTD [i + 1]);
  10947. while (ent.endsWithChar ('>'))
  10948. ent = ent.dropLastCharacters (1);
  10949. ent = ent.trim().unquoted();
  10950. // check for sub-entities..
  10951. int ampersand = ent.indexOfChar ('&');
  10952. while (ampersand >= 0)
  10953. {
  10954. const int semiColon = ent.indexOf (i + 1, ";");
  10955. if (semiColon < 0)
  10956. {
  10957. setLastError ("entity without terminating semi-colon", false);
  10958. break;
  10959. }
  10960. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  10961. ent = ent.substring (0, ampersand)
  10962. + resolved
  10963. + ent.substring (semiColon + 1);
  10964. ampersand = ent.indexOfChar (semiColon + 1, '&');
  10965. }
  10966. return ent;
  10967. }
  10968. }
  10969. }
  10970. setLastError ("unknown entity", true);
  10971. return entity;
  10972. }
  10973. const String XmlDocument::getParameterEntity (const String& entity)
  10974. {
  10975. for (int i = 0; i < tokenisedDTD.size(); ++i)
  10976. {
  10977. if (tokenisedDTD[i] == entity)
  10978. {
  10979. if (tokenisedDTD [i - 1] == "%"
  10980. && tokenisedDTD [i - 2].equalsIgnoreCase ("<!entity"))
  10981. {
  10982. String ent (tokenisedDTD [i + 1]);
  10983. while (ent.endsWithChar ('>'))
  10984. ent = ent.dropLastCharacters (1);
  10985. if (ent.equalsIgnoreCase ("system"))
  10986. {
  10987. String filename (tokenisedDTD [i + 2]);
  10988. while (filename.endsWithChar ('>'))
  10989. filename = filename.dropLastCharacters (1);
  10990. return getFileContents (filename);
  10991. }
  10992. else
  10993. {
  10994. return ent.trim().unquoted();
  10995. }
  10996. }
  10997. }
  10998. }
  10999. return entity;
  11000. }
  11001. END_JUCE_NAMESPACE
  11002. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11003. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11004. BEGIN_JUCE_NAMESPACE
  11005. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11006. : name (other.name),
  11007. value (other.value),
  11008. next (0)
  11009. {
  11010. }
  11011. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_, const String& value_) throw()
  11012. : name (name_),
  11013. value (value_),
  11014. next (0)
  11015. {
  11016. }
  11017. XmlElement::XmlElement (const String& tagName_) throw()
  11018. : tagName (tagName_),
  11019. firstChildElement (0),
  11020. nextElement (0),
  11021. attributes (0)
  11022. {
  11023. // the tag name mustn't be empty, or it'll look like a text element!
  11024. jassert (tagName_.containsNonWhitespaceChars())
  11025. // The tag can't contain spaces or other characters that would create invalid XML!
  11026. jassert (! tagName_.containsAnyOf (" <>/&"));
  11027. }
  11028. XmlElement::XmlElement (int /*dummy*/) throw()
  11029. : firstChildElement (0),
  11030. nextElement (0),
  11031. attributes (0)
  11032. {
  11033. }
  11034. XmlElement::XmlElement (const XmlElement& other) throw()
  11035. : tagName (other.tagName),
  11036. firstChildElement (0),
  11037. nextElement (0),
  11038. attributes (0)
  11039. {
  11040. copyChildrenAndAttributesFrom (other);
  11041. }
  11042. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11043. {
  11044. if (this != &other)
  11045. {
  11046. removeAllAttributes();
  11047. deleteAllChildElements();
  11048. tagName = other.tagName;
  11049. copyChildrenAndAttributesFrom (other);
  11050. }
  11051. return *this;
  11052. }
  11053. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11054. {
  11055. XmlElement* child = other.firstChildElement;
  11056. XmlElement* lastChild = 0;
  11057. while (child != 0)
  11058. {
  11059. XmlElement* const copiedChild = new XmlElement (*child);
  11060. if (lastChild != 0)
  11061. lastChild->nextElement = copiedChild;
  11062. else
  11063. firstChildElement = copiedChild;
  11064. lastChild = copiedChild;
  11065. child = child->nextElement;
  11066. }
  11067. const XmlAttributeNode* att = other.attributes;
  11068. XmlAttributeNode* lastAtt = 0;
  11069. while (att != 0)
  11070. {
  11071. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11072. if (lastAtt != 0)
  11073. lastAtt->next = newAtt;
  11074. else
  11075. attributes = newAtt;
  11076. lastAtt = newAtt;
  11077. att = att->next;
  11078. }
  11079. }
  11080. XmlElement::~XmlElement() throw()
  11081. {
  11082. XmlElement* child = firstChildElement;
  11083. while (child != 0)
  11084. {
  11085. XmlElement* const nextChild = child->nextElement;
  11086. delete child;
  11087. child = nextChild;
  11088. }
  11089. XmlAttributeNode* att = attributes;
  11090. while (att != 0)
  11091. {
  11092. XmlAttributeNode* const nextAtt = att->next;
  11093. delete att;
  11094. att = nextAtt;
  11095. }
  11096. }
  11097. namespace XmlOutputFunctions
  11098. {
  11099. static bool isLegalXmlChar (const uint32 c) throw()
  11100. {
  11101. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11102. return c < sizeof (legalChars) * 8
  11103. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11104. }
  11105. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11106. {
  11107. const juce_wchar* t = text;
  11108. for (;;)
  11109. {
  11110. const juce_wchar character = *t++;
  11111. if (character == 0)
  11112. {
  11113. break;
  11114. }
  11115. else if (isLegalXmlChar ((uint32) character))
  11116. {
  11117. outputStream << (char) character;
  11118. }
  11119. else
  11120. {
  11121. switch (character)
  11122. {
  11123. case '&': outputStream << "&amp;"; break;
  11124. case '"': outputStream << "&quot;"; break;
  11125. case '>': outputStream << "&gt;"; break;
  11126. case '<': outputStream << "&lt;"; break;
  11127. case '\n':
  11128. if (changeNewLines)
  11129. outputStream << "&#10;";
  11130. else
  11131. outputStream << (char) character;
  11132. break;
  11133. case '\r':
  11134. if (changeNewLines)
  11135. outputStream << "&#13;";
  11136. else
  11137. outputStream << (char) character;
  11138. break;
  11139. default:
  11140. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11141. break;
  11142. }
  11143. }
  11144. }
  11145. }
  11146. static void writeSpaces (OutputStream& out, int numSpaces)
  11147. {
  11148. if (numSpaces > 0)
  11149. {
  11150. const char* const blanks = " ";
  11151. const int blankSize = (int) sizeof (blanks) - 1;
  11152. while (numSpaces > blankSize)
  11153. {
  11154. out.write (blanks, blankSize);
  11155. numSpaces -= blankSize;
  11156. }
  11157. out.write (blanks, numSpaces);
  11158. }
  11159. }
  11160. }
  11161. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11162. const int indentationLevel,
  11163. const int lineWrapLength) const
  11164. {
  11165. using namespace XmlOutputFunctions;
  11166. writeSpaces (outputStream, indentationLevel);
  11167. if (! isTextElement())
  11168. {
  11169. outputStream.writeByte ('<');
  11170. outputStream << tagName;
  11171. const int attIndent = indentationLevel + tagName.length() + 1;
  11172. int lineLen = 0;
  11173. const XmlAttributeNode* att = attributes;
  11174. while (att != 0)
  11175. {
  11176. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11177. {
  11178. outputStream.write ("\r\n", 2);
  11179. writeSpaces (outputStream, attIndent);
  11180. lineLen = 0;
  11181. }
  11182. const int64 startPos = outputStream.getPosition();
  11183. outputStream.writeByte (' ');
  11184. outputStream << att->name;
  11185. outputStream.write ("=\"", 2);
  11186. escapeIllegalXmlChars (outputStream, att->value, true);
  11187. outputStream.writeByte ('"');
  11188. lineLen += (int) (outputStream.getPosition() - startPos);
  11189. att = att->next;
  11190. }
  11191. if (firstChildElement != 0)
  11192. {
  11193. XmlElement* child = firstChildElement;
  11194. if (child->nextElement == 0 && child->isTextElement())
  11195. {
  11196. outputStream.writeByte ('>');
  11197. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11198. }
  11199. else
  11200. {
  11201. if (indentationLevel >= 0)
  11202. outputStream.write (">\r\n", 3);
  11203. else
  11204. outputStream.writeByte ('>');
  11205. bool lastWasTextNode = false;
  11206. while (child != 0)
  11207. {
  11208. if (child->isTextElement())
  11209. {
  11210. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11211. writeSpaces (outputStream, indentationLevel + 2);
  11212. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11213. lastWasTextNode = true;
  11214. }
  11215. else
  11216. {
  11217. if (indentationLevel >= 0)
  11218. {
  11219. if (lastWasTextNode)
  11220. outputStream.write ("\r\n", 2);
  11221. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11222. }
  11223. else
  11224. {
  11225. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11226. }
  11227. lastWasTextNode = false;
  11228. }
  11229. child = child->nextElement;
  11230. }
  11231. if (indentationLevel >= 0)
  11232. {
  11233. if (lastWasTextNode)
  11234. outputStream.write ("\r\n", 2);
  11235. writeSpaces (outputStream, indentationLevel);
  11236. }
  11237. }
  11238. outputStream.write ("</", 2);
  11239. outputStream << tagName;
  11240. if (indentationLevel >= 0)
  11241. outputStream.write (">\r\n", 3);
  11242. else
  11243. outputStream.writeByte ('>');
  11244. }
  11245. else
  11246. {
  11247. if (indentationLevel >= 0)
  11248. outputStream.write ("/>\r\n", 4);
  11249. else
  11250. outputStream.write ("/>", 2);
  11251. }
  11252. }
  11253. else
  11254. {
  11255. if (indentationLevel >= 0)
  11256. writeSpaces (outputStream, indentationLevel + 2);
  11257. escapeIllegalXmlChars (outputStream, getText(), false);
  11258. }
  11259. }
  11260. const String XmlElement::createDocument (const String& dtdToUse,
  11261. const bool allOnOneLine,
  11262. const bool includeXmlHeader,
  11263. const String& encodingType,
  11264. const int lineWrapLength) const
  11265. {
  11266. MemoryOutputStream mem (2048, 4096);
  11267. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11268. return mem.toUTF8();
  11269. }
  11270. void XmlElement::writeToStream (OutputStream& output,
  11271. const String& dtdToUse,
  11272. const bool allOnOneLine,
  11273. const bool includeXmlHeader,
  11274. const String& encodingType,
  11275. const int lineWrapLength) const
  11276. {
  11277. if (includeXmlHeader)
  11278. output << "<?xml version=\"1.0\" encoding=\"" << encodingType
  11279. << (allOnOneLine ? "\"?> " : "\"?>\r\n\r\n");
  11280. if (dtdToUse.isNotEmpty())
  11281. output << dtdToUse << (allOnOneLine ? " " : "\r\n");
  11282. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11283. }
  11284. bool XmlElement::writeToFile (const File& file,
  11285. const String& dtdToUse,
  11286. const String& encodingType,
  11287. const int lineWrapLength) const
  11288. {
  11289. if (file.hasWriteAccess())
  11290. {
  11291. TemporaryFile tempFile (file);
  11292. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11293. if (out != 0)
  11294. {
  11295. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11296. out = 0;
  11297. return tempFile.overwriteTargetFileWithTemporary();
  11298. }
  11299. }
  11300. return false;
  11301. }
  11302. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11303. {
  11304. #ifdef JUCE_DEBUG
  11305. // if debugging, check that the case is actually the same, because
  11306. // valid xml is case-sensitive, and although this lets it pass, it's
  11307. // better not to..
  11308. if (tagName.equalsIgnoreCase (tagNameWanted))
  11309. {
  11310. jassert (tagName == tagNameWanted);
  11311. return true;
  11312. }
  11313. else
  11314. {
  11315. return false;
  11316. }
  11317. #else
  11318. return tagName.equalsIgnoreCase (tagNameWanted);
  11319. #endif
  11320. }
  11321. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11322. {
  11323. XmlElement* e = nextElement;
  11324. while (e != 0 && ! e->hasTagName (requiredTagName))
  11325. e = e->nextElement;
  11326. return e;
  11327. }
  11328. int XmlElement::getNumAttributes() const throw()
  11329. {
  11330. const XmlAttributeNode* att = attributes;
  11331. int count = 0;
  11332. while (att != 0)
  11333. {
  11334. att = att->next;
  11335. ++count;
  11336. }
  11337. return count;
  11338. }
  11339. const String& XmlElement::getAttributeName (const int index) const throw()
  11340. {
  11341. const XmlAttributeNode* att = attributes;
  11342. int count = 0;
  11343. while (att != 0)
  11344. {
  11345. if (count == index)
  11346. return att->name;
  11347. att = att->next;
  11348. ++count;
  11349. }
  11350. return String::empty;
  11351. }
  11352. const String& XmlElement::getAttributeValue (const int index) const throw()
  11353. {
  11354. const XmlAttributeNode* att = attributes;
  11355. int count = 0;
  11356. while (att != 0)
  11357. {
  11358. if (count == index)
  11359. return att->value;
  11360. att = att->next;
  11361. ++count;
  11362. }
  11363. return String::empty;
  11364. }
  11365. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11366. {
  11367. const XmlAttributeNode* att = attributes;
  11368. while (att != 0)
  11369. {
  11370. if (att->name.equalsIgnoreCase (attributeName))
  11371. return true;
  11372. att = att->next;
  11373. }
  11374. return false;
  11375. }
  11376. const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
  11377. {
  11378. const XmlAttributeNode* att = attributes;
  11379. while (att != 0)
  11380. {
  11381. if (att->name.equalsIgnoreCase (attributeName))
  11382. return att->value;
  11383. att = att->next;
  11384. }
  11385. return String::empty;
  11386. }
  11387. const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
  11388. {
  11389. const XmlAttributeNode* att = attributes;
  11390. while (att != 0)
  11391. {
  11392. if (att->name.equalsIgnoreCase (attributeName))
  11393. return att->value;
  11394. att = att->next;
  11395. }
  11396. return defaultReturnValue;
  11397. }
  11398. int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
  11399. {
  11400. const XmlAttributeNode* att = attributes;
  11401. while (att != 0)
  11402. {
  11403. if (att->name.equalsIgnoreCase (attributeName))
  11404. return att->value.getIntValue();
  11405. att = att->next;
  11406. }
  11407. return defaultReturnValue;
  11408. }
  11409. double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
  11410. {
  11411. const XmlAttributeNode* att = attributes;
  11412. while (att != 0)
  11413. {
  11414. if (att->name.equalsIgnoreCase (attributeName))
  11415. return att->value.getDoubleValue();
  11416. att = att->next;
  11417. }
  11418. return defaultReturnValue;
  11419. }
  11420. bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
  11421. {
  11422. const XmlAttributeNode* att = attributes;
  11423. while (att != 0)
  11424. {
  11425. if (att->name.equalsIgnoreCase (attributeName))
  11426. {
  11427. juce_wchar firstChar = att->value[0];
  11428. if (CharacterFunctions::isWhitespace (firstChar))
  11429. firstChar = att->value.trimStart() [0];
  11430. return firstChar == '1'
  11431. || firstChar == 't'
  11432. || firstChar == 'y'
  11433. || firstChar == 'T'
  11434. || firstChar == 'Y';
  11435. }
  11436. att = att->next;
  11437. }
  11438. return defaultReturnValue;
  11439. }
  11440. bool XmlElement::compareAttribute (const String& attributeName,
  11441. const String& stringToCompareAgainst,
  11442. const bool ignoreCase) const throw()
  11443. {
  11444. const XmlAttributeNode* att = attributes;
  11445. while (att != 0)
  11446. {
  11447. if (att->name.equalsIgnoreCase (attributeName))
  11448. {
  11449. if (ignoreCase)
  11450. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11451. else
  11452. return att->value == stringToCompareAgainst;
  11453. }
  11454. att = att->next;
  11455. }
  11456. return false;
  11457. }
  11458. void XmlElement::setAttribute (const String& attributeName, const String& value)
  11459. {
  11460. #ifdef JUCE_DEBUG
  11461. // check the identifier being passed in is legal..
  11462. const juce_wchar* t = attributeName;
  11463. while (*t != 0)
  11464. {
  11465. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11466. || *t == '_'
  11467. || *t == '-'
  11468. || *t == ':');
  11469. ++t;
  11470. }
  11471. #endif
  11472. if (attributes == 0)
  11473. {
  11474. attributes = new XmlAttributeNode (attributeName, value);
  11475. }
  11476. else
  11477. {
  11478. XmlAttributeNode* att = attributes;
  11479. for (;;)
  11480. {
  11481. if (att->name.equalsIgnoreCase (attributeName))
  11482. {
  11483. att->value = value;
  11484. break;
  11485. }
  11486. else if (att->next == 0)
  11487. {
  11488. att->next = new XmlAttributeNode (attributeName, value);
  11489. break;
  11490. }
  11491. att = att->next;
  11492. }
  11493. }
  11494. }
  11495. void XmlElement::setAttribute (const String& attributeName, const int number)
  11496. {
  11497. setAttribute (attributeName, String (number));
  11498. }
  11499. void XmlElement::setAttribute (const String& attributeName, const double number)
  11500. {
  11501. setAttribute (attributeName, String (number));
  11502. }
  11503. void XmlElement::removeAttribute (const String& attributeName) throw()
  11504. {
  11505. XmlAttributeNode* att = attributes;
  11506. XmlAttributeNode* lastAtt = 0;
  11507. while (att != 0)
  11508. {
  11509. if (att->name.equalsIgnoreCase (attributeName))
  11510. {
  11511. if (lastAtt == 0)
  11512. attributes = att->next;
  11513. else
  11514. lastAtt->next = att->next;
  11515. delete att;
  11516. break;
  11517. }
  11518. lastAtt = att;
  11519. att = att->next;
  11520. }
  11521. }
  11522. void XmlElement::removeAllAttributes() throw()
  11523. {
  11524. while (attributes != 0)
  11525. {
  11526. XmlAttributeNode* const nextAtt = attributes->next;
  11527. delete attributes;
  11528. attributes = nextAtt;
  11529. }
  11530. }
  11531. int XmlElement::getNumChildElements() const throw()
  11532. {
  11533. int count = 0;
  11534. const XmlElement* child = firstChildElement;
  11535. while (child != 0)
  11536. {
  11537. ++count;
  11538. child = child->nextElement;
  11539. }
  11540. return count;
  11541. }
  11542. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11543. {
  11544. int count = 0;
  11545. XmlElement* child = firstChildElement;
  11546. while (child != 0 && count < index)
  11547. {
  11548. child = child->nextElement;
  11549. ++count;
  11550. }
  11551. return child;
  11552. }
  11553. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11554. {
  11555. XmlElement* child = firstChildElement;
  11556. while (child != 0)
  11557. {
  11558. if (child->hasTagName (childName))
  11559. break;
  11560. child = child->nextElement;
  11561. }
  11562. return child;
  11563. }
  11564. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11565. {
  11566. if (newNode != 0)
  11567. {
  11568. if (firstChildElement == 0)
  11569. {
  11570. firstChildElement = newNode;
  11571. }
  11572. else
  11573. {
  11574. XmlElement* child = firstChildElement;
  11575. while (child->nextElement != 0)
  11576. child = child->nextElement;
  11577. child->nextElement = newNode;
  11578. // if this is non-zero, then something's probably
  11579. // gone wrong..
  11580. jassert (newNode->nextElement == 0);
  11581. }
  11582. }
  11583. }
  11584. void XmlElement::insertChildElement (XmlElement* const newNode,
  11585. int indexToInsertAt) throw()
  11586. {
  11587. if (newNode != 0)
  11588. {
  11589. removeChildElement (newNode, false);
  11590. if (indexToInsertAt == 0)
  11591. {
  11592. newNode->nextElement = firstChildElement;
  11593. firstChildElement = newNode;
  11594. }
  11595. else
  11596. {
  11597. if (firstChildElement == 0)
  11598. {
  11599. firstChildElement = newNode;
  11600. }
  11601. else
  11602. {
  11603. if (indexToInsertAt < 0)
  11604. indexToInsertAt = std::numeric_limits<int>::max();
  11605. XmlElement* child = firstChildElement;
  11606. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11607. child = child->nextElement;
  11608. newNode->nextElement = child->nextElement;
  11609. child->nextElement = newNode;
  11610. }
  11611. }
  11612. }
  11613. }
  11614. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11615. {
  11616. XmlElement* const newElement = new XmlElement (tagName);
  11617. addChildElement (newElement);
  11618. return newElement;
  11619. }
  11620. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11621. XmlElement* const newNode) throw()
  11622. {
  11623. if (newNode != 0)
  11624. {
  11625. XmlElement* child = firstChildElement;
  11626. XmlElement* previousNode = 0;
  11627. while (child != 0)
  11628. {
  11629. if (child == currentChildElement)
  11630. {
  11631. if (child != newNode)
  11632. {
  11633. if (previousNode == 0)
  11634. firstChildElement = newNode;
  11635. else
  11636. previousNode->nextElement = newNode;
  11637. newNode->nextElement = child->nextElement;
  11638. delete child;
  11639. }
  11640. return true;
  11641. }
  11642. previousNode = child;
  11643. child = child->nextElement;
  11644. }
  11645. }
  11646. return false;
  11647. }
  11648. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11649. const bool shouldDeleteTheChild) throw()
  11650. {
  11651. if (childToRemove != 0)
  11652. {
  11653. if (firstChildElement == childToRemove)
  11654. {
  11655. firstChildElement = childToRemove->nextElement;
  11656. childToRemove->nextElement = 0;
  11657. }
  11658. else
  11659. {
  11660. XmlElement* child = firstChildElement;
  11661. XmlElement* last = 0;
  11662. while (child != 0)
  11663. {
  11664. if (child == childToRemove)
  11665. {
  11666. if (last == 0)
  11667. firstChildElement = child->nextElement;
  11668. else
  11669. last->nextElement = child->nextElement;
  11670. childToRemove->nextElement = 0;
  11671. break;
  11672. }
  11673. last = child;
  11674. child = child->nextElement;
  11675. }
  11676. }
  11677. if (shouldDeleteTheChild)
  11678. delete childToRemove;
  11679. }
  11680. }
  11681. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11682. const bool ignoreOrderOfAttributes) const throw()
  11683. {
  11684. if (this != other)
  11685. {
  11686. if (other == 0 || tagName != other->tagName)
  11687. {
  11688. return false;
  11689. }
  11690. if (ignoreOrderOfAttributes)
  11691. {
  11692. int totalAtts = 0;
  11693. const XmlAttributeNode* att = attributes;
  11694. while (att != 0)
  11695. {
  11696. if (! other->compareAttribute (att->name, att->value))
  11697. return false;
  11698. att = att->next;
  11699. ++totalAtts;
  11700. }
  11701. if (totalAtts != other->getNumAttributes())
  11702. return false;
  11703. }
  11704. else
  11705. {
  11706. const XmlAttributeNode* thisAtt = attributes;
  11707. const XmlAttributeNode* otherAtt = other->attributes;
  11708. for (;;)
  11709. {
  11710. if (thisAtt == 0 || otherAtt == 0)
  11711. {
  11712. if (thisAtt == otherAtt) // both 0, so it's a match
  11713. break;
  11714. return false;
  11715. }
  11716. if (thisAtt->name != otherAtt->name
  11717. || thisAtt->value != otherAtt->value)
  11718. {
  11719. return false;
  11720. }
  11721. thisAtt = thisAtt->next;
  11722. otherAtt = otherAtt->next;
  11723. }
  11724. }
  11725. const XmlElement* thisChild = firstChildElement;
  11726. const XmlElement* otherChild = other->firstChildElement;
  11727. for (;;)
  11728. {
  11729. if (thisChild == 0 || otherChild == 0)
  11730. {
  11731. if (thisChild == otherChild) // both 0, so it's a match
  11732. break;
  11733. return false;
  11734. }
  11735. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11736. return false;
  11737. thisChild = thisChild->nextElement;
  11738. otherChild = otherChild->nextElement;
  11739. }
  11740. }
  11741. return true;
  11742. }
  11743. void XmlElement::deleteAllChildElements() throw()
  11744. {
  11745. while (firstChildElement != 0)
  11746. {
  11747. XmlElement* const nextChild = firstChildElement->nextElement;
  11748. delete firstChildElement;
  11749. firstChildElement = nextChild;
  11750. }
  11751. }
  11752. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11753. {
  11754. XmlElement* child = firstChildElement;
  11755. while (child != 0)
  11756. {
  11757. if (child->hasTagName (name))
  11758. {
  11759. XmlElement* const nextChild = child->nextElement;
  11760. removeChildElement (child, true);
  11761. child = nextChild;
  11762. }
  11763. else
  11764. {
  11765. child = child->nextElement;
  11766. }
  11767. }
  11768. }
  11769. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  11770. {
  11771. const XmlElement* child = firstChildElement;
  11772. while (child != 0)
  11773. {
  11774. if (child == possibleChild)
  11775. return true;
  11776. child = child->nextElement;
  11777. }
  11778. return false;
  11779. }
  11780. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  11781. {
  11782. if (this == elementToLookFor || elementToLookFor == 0)
  11783. return 0;
  11784. XmlElement* child = firstChildElement;
  11785. while (child != 0)
  11786. {
  11787. if (elementToLookFor == child)
  11788. return this;
  11789. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  11790. if (found != 0)
  11791. return found;
  11792. child = child->nextElement;
  11793. }
  11794. return 0;
  11795. }
  11796. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  11797. {
  11798. XmlElement* e = firstChildElement;
  11799. while (e != 0)
  11800. {
  11801. *elems++ = e;
  11802. e = e->nextElement;
  11803. }
  11804. }
  11805. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  11806. {
  11807. XmlElement* e = firstChildElement = elems[0];
  11808. for (int i = 1; i < num; ++i)
  11809. {
  11810. e->nextElement = elems[i];
  11811. e = e->nextElement;
  11812. }
  11813. e->nextElement = 0;
  11814. }
  11815. bool XmlElement::isTextElement() const throw()
  11816. {
  11817. return tagName.isEmpty();
  11818. }
  11819. static const juce_wchar* const juce_xmltextContentAttributeName = T("text");
  11820. const String XmlElement::getText() const throw()
  11821. {
  11822. jassert (isTextElement()); // you're trying to get the text from an element that
  11823. // isn't actually a text element.. If this contains text sub-nodes, you
  11824. // probably want to use getAllSubText instead.
  11825. return getStringAttribute (juce_xmltextContentAttributeName);
  11826. }
  11827. void XmlElement::setText (const String& newText) throw()
  11828. {
  11829. if (isTextElement())
  11830. {
  11831. setAttribute (juce_xmltextContentAttributeName, newText);
  11832. }
  11833. else
  11834. {
  11835. jassertfalse // you can only change the text in a text element, not a normal one.
  11836. }
  11837. }
  11838. const String XmlElement::getAllSubText() const throw()
  11839. {
  11840. String result;
  11841. String::Concatenator concatenator (result);
  11842. const XmlElement* child = firstChildElement;
  11843. while (child != 0)
  11844. {
  11845. if (child->isTextElement())
  11846. concatenator.append (child->getText());
  11847. child = child->nextElement;
  11848. }
  11849. return result;
  11850. }
  11851. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  11852. const String& defaultReturnValue) const throw()
  11853. {
  11854. const XmlElement* const child = getChildByName (childTagName);
  11855. if (child != 0)
  11856. return child->getAllSubText();
  11857. return defaultReturnValue;
  11858. }
  11859. XmlElement* XmlElement::createTextElement (const String& text) throw()
  11860. {
  11861. XmlElement* const e = new XmlElement ((int) 0);
  11862. e->setAttribute (juce_xmltextContentAttributeName, text);
  11863. return e;
  11864. }
  11865. void XmlElement::addTextElement (const String& text) throw()
  11866. {
  11867. addChildElement (createTextElement (text));
  11868. }
  11869. void XmlElement::deleteAllTextElements() throw()
  11870. {
  11871. XmlElement* child = firstChildElement;
  11872. while (child != 0)
  11873. {
  11874. XmlElement* const next = child->nextElement;
  11875. if (child->isTextElement())
  11876. removeChildElement (child, true);
  11877. child = next;
  11878. }
  11879. }
  11880. END_JUCE_NAMESPACE
  11881. /*** End of inlined file: juce_XmlElement.cpp ***/
  11882. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  11883. BEGIN_JUCE_NAMESPACE
  11884. ReadWriteLock::ReadWriteLock() throw()
  11885. : numWaitingWriters (0),
  11886. numWriters (0),
  11887. writerThreadId (0)
  11888. {
  11889. }
  11890. ReadWriteLock::~ReadWriteLock() throw()
  11891. {
  11892. jassert (readerThreads.size() == 0);
  11893. jassert (numWriters == 0);
  11894. }
  11895. void ReadWriteLock::enterRead() const throw()
  11896. {
  11897. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11898. const ScopedLock sl (accessLock);
  11899. for (;;)
  11900. {
  11901. jassert (readerThreads.size() % 2 == 0);
  11902. int i;
  11903. for (i = 0; i < readerThreads.size(); i += 2)
  11904. if (readerThreads.getUnchecked(i) == threadId)
  11905. break;
  11906. if (i < readerThreads.size()
  11907. || numWriters + numWaitingWriters == 0
  11908. || (threadId == writerThreadId && numWriters > 0))
  11909. {
  11910. if (i < readerThreads.size())
  11911. {
  11912. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  11913. }
  11914. else
  11915. {
  11916. readerThreads.add (threadId);
  11917. readerThreads.add ((Thread::ThreadID) 1);
  11918. }
  11919. return;
  11920. }
  11921. const ScopedUnlock ul (accessLock);
  11922. waitEvent.wait (100);
  11923. }
  11924. }
  11925. void ReadWriteLock::exitRead() const throw()
  11926. {
  11927. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11928. const ScopedLock sl (accessLock);
  11929. for (int i = 0; i < readerThreads.size(); i += 2)
  11930. {
  11931. if (readerThreads.getUnchecked(i) == threadId)
  11932. {
  11933. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  11934. if (newCount == 0)
  11935. {
  11936. readerThreads.removeRange (i, 2);
  11937. waitEvent.signal();
  11938. }
  11939. else
  11940. {
  11941. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  11942. }
  11943. return;
  11944. }
  11945. }
  11946. jassertfalse // unlocking a lock that wasn't locked..
  11947. }
  11948. void ReadWriteLock::enterWrite() const throw()
  11949. {
  11950. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11951. const ScopedLock sl (accessLock);
  11952. for (;;)
  11953. {
  11954. if (readerThreads.size() + numWriters == 0
  11955. || threadId == writerThreadId
  11956. || (readerThreads.size() == 2
  11957. && readerThreads.getUnchecked(0) == threadId))
  11958. {
  11959. writerThreadId = threadId;
  11960. ++numWriters;
  11961. break;
  11962. }
  11963. ++numWaitingWriters;
  11964. accessLock.exit();
  11965. waitEvent.wait (100);
  11966. accessLock.enter();
  11967. --numWaitingWriters;
  11968. }
  11969. }
  11970. bool ReadWriteLock::tryEnterWrite() const throw()
  11971. {
  11972. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11973. const ScopedLock sl (accessLock);
  11974. if (readerThreads.size() + numWriters == 0
  11975. || threadId == writerThreadId
  11976. || (readerThreads.size() == 2
  11977. && readerThreads.getUnchecked(0) == threadId))
  11978. {
  11979. writerThreadId = threadId;
  11980. ++numWriters;
  11981. return true;
  11982. }
  11983. return false;
  11984. }
  11985. void ReadWriteLock::exitWrite() const throw()
  11986. {
  11987. const ScopedLock sl (accessLock);
  11988. // check this thread actually had the lock..
  11989. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  11990. if (--numWriters == 0)
  11991. {
  11992. writerThreadId = 0;
  11993. waitEvent.signal();
  11994. }
  11995. }
  11996. END_JUCE_NAMESPACE
  11997. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  11998. /*** Start of inlined file: juce_Thread.cpp ***/
  11999. BEGIN_JUCE_NAMESPACE
  12000. // these functions are implemented in the platform-specific code.
  12001. void* juce_createThread (void* userData);
  12002. void juce_killThread (void* handle);
  12003. bool juce_setThreadPriority (void* handle, int priority);
  12004. void juce_setCurrentThreadName (const String& name);
  12005. #if JUCE_WIN32
  12006. void juce_CloseThreadHandle (void* handle);
  12007. #endif
  12008. void Thread::threadEntryPoint (Thread* const thread)
  12009. {
  12010. {
  12011. const ScopedLock sl (runningThreadsLock);
  12012. runningThreads.add (thread);
  12013. }
  12014. JUCE_TRY
  12015. {
  12016. thread->threadId_ = Thread::getCurrentThreadId();
  12017. if (thread->threadName_.isNotEmpty())
  12018. juce_setCurrentThreadName (thread->threadName_);
  12019. if (thread->startSuspensionEvent_.wait (10000))
  12020. {
  12021. if (thread->affinityMask_ != 0)
  12022. setCurrentThreadAffinityMask (thread->affinityMask_);
  12023. thread->run();
  12024. }
  12025. }
  12026. JUCE_CATCH_ALL_ASSERT
  12027. {
  12028. const ScopedLock sl (runningThreadsLock);
  12029. jassert (runningThreads.contains (thread));
  12030. runningThreads.removeValue (thread);
  12031. }
  12032. #if JUCE_WIN32
  12033. juce_CloseThreadHandle (thread->threadHandle_);
  12034. #endif
  12035. thread->threadHandle_ = 0;
  12036. thread->threadId_ = 0;
  12037. }
  12038. // used to wrap the incoming call from the platform-specific code
  12039. void JUCE_API juce_threadEntryPoint (void* userData)
  12040. {
  12041. Thread::threadEntryPoint (static_cast <Thread*> (userData));
  12042. }
  12043. Thread::Thread (const String& threadName)
  12044. : threadName_ (threadName),
  12045. threadHandle_ (0),
  12046. threadPriority_ (5),
  12047. threadId_ (0),
  12048. affinityMask_ (0),
  12049. threadShouldExit_ (false)
  12050. {
  12051. }
  12052. Thread::~Thread()
  12053. {
  12054. stopThread (100);
  12055. }
  12056. void Thread::startThread()
  12057. {
  12058. const ScopedLock sl (startStopLock);
  12059. threadShouldExit_ = false;
  12060. if (threadHandle_ == 0)
  12061. {
  12062. threadHandle_ = juce_createThread (this);
  12063. juce_setThreadPriority (threadHandle_, threadPriority_);
  12064. startSuspensionEvent_.signal();
  12065. }
  12066. }
  12067. void Thread::startThread (const int priority)
  12068. {
  12069. const ScopedLock sl (startStopLock);
  12070. if (threadHandle_ == 0)
  12071. {
  12072. threadPriority_ = priority;
  12073. startThread();
  12074. }
  12075. else
  12076. {
  12077. setPriority (priority);
  12078. }
  12079. }
  12080. bool Thread::isThreadRunning() const
  12081. {
  12082. return threadHandle_ != 0;
  12083. }
  12084. void Thread::signalThreadShouldExit()
  12085. {
  12086. threadShouldExit_ = true;
  12087. }
  12088. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12089. {
  12090. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12091. jassert (getThreadId() != getCurrentThreadId());
  12092. const int sleepMsPerIteration = 5;
  12093. int count = timeOutMilliseconds / sleepMsPerIteration;
  12094. while (isThreadRunning())
  12095. {
  12096. if (timeOutMilliseconds > 0 && --count < 0)
  12097. return false;
  12098. sleep (sleepMsPerIteration);
  12099. }
  12100. return true;
  12101. }
  12102. void Thread::stopThread (const int timeOutMilliseconds)
  12103. {
  12104. // agh! You can't stop the thread that's calling this method! How on earth
  12105. // would that work??
  12106. jassert (getCurrentThreadId() != getThreadId());
  12107. const ScopedLock sl (startStopLock);
  12108. if (isThreadRunning())
  12109. {
  12110. signalThreadShouldExit();
  12111. notify();
  12112. if (timeOutMilliseconds != 0)
  12113. waitForThreadToExit (timeOutMilliseconds);
  12114. if (isThreadRunning())
  12115. {
  12116. // very bad karma if this point is reached, as
  12117. // there are bound to be locks and events left in
  12118. // silly states when a thread is killed by force..
  12119. jassertfalse
  12120. Logger::writeToLog ("!! killing thread by force !!");
  12121. juce_killThread (threadHandle_);
  12122. threadHandle_ = 0;
  12123. threadId_ = 0;
  12124. const ScopedLock sl2 (runningThreadsLock);
  12125. runningThreads.removeValue (this);
  12126. }
  12127. }
  12128. }
  12129. bool Thread::setPriority (const int priority)
  12130. {
  12131. const ScopedLock sl (startStopLock);
  12132. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12133. if (worked)
  12134. threadPriority_ = priority;
  12135. return worked;
  12136. }
  12137. bool Thread::setCurrentThreadPriority (const int priority)
  12138. {
  12139. return juce_setThreadPriority (0, priority);
  12140. }
  12141. void Thread::setAffinityMask (const uint32 affinityMask)
  12142. {
  12143. affinityMask_ = affinityMask;
  12144. }
  12145. bool Thread::wait (const int timeOutMilliseconds) const
  12146. {
  12147. return defaultEvent_.wait (timeOutMilliseconds);
  12148. }
  12149. void Thread::notify() const
  12150. {
  12151. defaultEvent_.signal();
  12152. }
  12153. int Thread::getNumRunningThreads()
  12154. {
  12155. return runningThreads.size();
  12156. }
  12157. Thread* Thread::getCurrentThread()
  12158. {
  12159. const ThreadID thisId = getCurrentThreadId();
  12160. const ScopedLock sl (runningThreadsLock);
  12161. for (int i = runningThreads.size(); --i >= 0;)
  12162. {
  12163. Thread* const t = runningThreads.getUnchecked(i);
  12164. if (t->threadId_ == thisId)
  12165. return t;
  12166. }
  12167. return 0;
  12168. }
  12169. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12170. {
  12171. {
  12172. const ScopedLock sl (runningThreadsLock);
  12173. for (int i = runningThreads.size(); --i >= 0;)
  12174. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12175. }
  12176. for (;;)
  12177. {
  12178. Thread* firstThread;
  12179. {
  12180. const ScopedLock sl (runningThreadsLock);
  12181. firstThread = runningThreads.getFirst();
  12182. }
  12183. if (firstThread == 0)
  12184. break;
  12185. firstThread->stopThread (timeOutMilliseconds);
  12186. }
  12187. }
  12188. Array<Thread*> Thread::runningThreads;
  12189. CriticalSection Thread::runningThreadsLock;
  12190. END_JUCE_NAMESPACE
  12191. /*** End of inlined file: juce_Thread.cpp ***/
  12192. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12193. BEGIN_JUCE_NAMESPACE
  12194. ThreadPoolJob::ThreadPoolJob (const String& name)
  12195. : jobName (name),
  12196. pool (0),
  12197. shouldStop (false),
  12198. isActive (false),
  12199. shouldBeDeleted (false)
  12200. {
  12201. }
  12202. ThreadPoolJob::~ThreadPoolJob()
  12203. {
  12204. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12205. // to remove it first!
  12206. jassert (pool == 0 || ! pool->contains (this));
  12207. }
  12208. const String ThreadPoolJob::getJobName() const
  12209. {
  12210. return jobName;
  12211. }
  12212. void ThreadPoolJob::setJobName (const String& newName)
  12213. {
  12214. jobName = newName;
  12215. }
  12216. void ThreadPoolJob::signalJobShouldExit()
  12217. {
  12218. shouldStop = true;
  12219. }
  12220. class ThreadPool::ThreadPoolThread : public Thread
  12221. {
  12222. public:
  12223. ThreadPoolThread (ThreadPool& pool_)
  12224. : Thread ("Pool"),
  12225. pool (pool_),
  12226. busy (false)
  12227. {
  12228. }
  12229. ~ThreadPoolThread()
  12230. {
  12231. }
  12232. void run()
  12233. {
  12234. while (! threadShouldExit())
  12235. {
  12236. if (! pool.runNextJob())
  12237. wait (500);
  12238. }
  12239. }
  12240. private:
  12241. ThreadPool& pool;
  12242. bool volatile busy;
  12243. ThreadPoolThread (const ThreadPoolThread&);
  12244. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12245. };
  12246. ThreadPool::ThreadPool (const int numThreads,
  12247. const bool startThreadsOnlyWhenNeeded,
  12248. const int stopThreadsWhenNotUsedTimeoutMs)
  12249. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12250. priority (5)
  12251. {
  12252. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12253. for (int i = jmax (1, numThreads); --i >= 0;)
  12254. threads.add (new ThreadPoolThread (*this));
  12255. if (! startThreadsOnlyWhenNeeded)
  12256. for (int i = threads.size(); --i >= 0;)
  12257. threads.getUnchecked(i)->startThread (priority);
  12258. }
  12259. ThreadPool::~ThreadPool()
  12260. {
  12261. removeAllJobs (true, 4000);
  12262. int i;
  12263. for (i = threads.size(); --i >= 0;)
  12264. threads.getUnchecked(i)->signalThreadShouldExit();
  12265. for (i = threads.size(); --i >= 0;)
  12266. threads.getUnchecked(i)->stopThread (500);
  12267. }
  12268. void ThreadPool::addJob (ThreadPoolJob* const job)
  12269. {
  12270. jassert (job != 0);
  12271. jassert (job->pool == 0);
  12272. if (job->pool == 0)
  12273. {
  12274. job->pool = this;
  12275. job->shouldStop = false;
  12276. job->isActive = false;
  12277. {
  12278. const ScopedLock sl (lock);
  12279. jobs.add (job);
  12280. int numRunning = 0;
  12281. for (int i = threads.size(); --i >= 0;)
  12282. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12283. ++numRunning;
  12284. if (numRunning < threads.size())
  12285. {
  12286. bool startedOne = false;
  12287. int n = 1000;
  12288. while (--n >= 0 && ! startedOne)
  12289. {
  12290. for (int i = threads.size(); --i >= 0;)
  12291. {
  12292. if (! threads.getUnchecked(i)->isThreadRunning())
  12293. {
  12294. threads.getUnchecked(i)->startThread (priority);
  12295. startedOne = true;
  12296. break;
  12297. }
  12298. }
  12299. if (! startedOne)
  12300. Thread::sleep (2);
  12301. }
  12302. }
  12303. }
  12304. for (int i = threads.size(); --i >= 0;)
  12305. threads.getUnchecked(i)->notify();
  12306. }
  12307. }
  12308. int ThreadPool::getNumJobs() const
  12309. {
  12310. return jobs.size();
  12311. }
  12312. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12313. {
  12314. const ScopedLock sl (lock);
  12315. return jobs [index];
  12316. }
  12317. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12318. {
  12319. const ScopedLock sl (lock);
  12320. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12321. }
  12322. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12323. {
  12324. const ScopedLock sl (lock);
  12325. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12326. }
  12327. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12328. const int timeOutMs) const
  12329. {
  12330. if (job != 0)
  12331. {
  12332. const uint32 start = Time::getMillisecondCounter();
  12333. while (contains (job))
  12334. {
  12335. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12336. return false;
  12337. jobFinishedSignal.wait (2);
  12338. }
  12339. }
  12340. return true;
  12341. }
  12342. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12343. const bool interruptIfRunning,
  12344. const int timeOutMs)
  12345. {
  12346. bool dontWait = true;
  12347. if (job != 0)
  12348. {
  12349. const ScopedLock sl (lock);
  12350. if (jobs.contains (job))
  12351. {
  12352. if (job->isActive)
  12353. {
  12354. if (interruptIfRunning)
  12355. job->signalJobShouldExit();
  12356. dontWait = false;
  12357. }
  12358. else
  12359. {
  12360. jobs.removeValue (job);
  12361. }
  12362. }
  12363. }
  12364. return dontWait || waitForJobToFinish (job, timeOutMs);
  12365. }
  12366. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12367. const int timeOutMs,
  12368. const bool deleteInactiveJobs,
  12369. ThreadPool::JobSelector* selectedJobsToRemove)
  12370. {
  12371. Array <ThreadPoolJob*> jobsToWaitFor;
  12372. {
  12373. const ScopedLock sl (lock);
  12374. for (int i = jobs.size(); --i >= 0;)
  12375. {
  12376. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12377. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12378. {
  12379. if (job->isActive)
  12380. {
  12381. jobsToWaitFor.add (job);
  12382. if (interruptRunningJobs)
  12383. job->signalJobShouldExit();
  12384. }
  12385. else
  12386. {
  12387. jobs.remove (i);
  12388. if (deleteInactiveJobs)
  12389. delete job;
  12390. }
  12391. }
  12392. }
  12393. }
  12394. const uint32 start = Time::getMillisecondCounter();
  12395. for (;;)
  12396. {
  12397. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12398. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12399. jobsToWaitFor.remove (i);
  12400. if (jobsToWaitFor.size() == 0)
  12401. break;
  12402. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12403. return false;
  12404. jobFinishedSignal.wait (20);
  12405. }
  12406. return true;
  12407. }
  12408. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12409. {
  12410. StringArray s;
  12411. const ScopedLock sl (lock);
  12412. for (int i = 0; i < jobs.size(); ++i)
  12413. {
  12414. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12415. if (job->isActive || ! onlyReturnActiveJobs)
  12416. s.add (job->getJobName());
  12417. }
  12418. return s;
  12419. }
  12420. bool ThreadPool::setThreadPriorities (const int newPriority)
  12421. {
  12422. bool ok = true;
  12423. if (priority != newPriority)
  12424. {
  12425. priority = newPriority;
  12426. for (int i = threads.size(); --i >= 0;)
  12427. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12428. ok = false;
  12429. }
  12430. return ok;
  12431. }
  12432. bool ThreadPool::runNextJob()
  12433. {
  12434. ThreadPoolJob* job = 0;
  12435. {
  12436. const ScopedLock sl (lock);
  12437. for (int i = 0; i < jobs.size(); ++i)
  12438. {
  12439. job = jobs[i];
  12440. if (job != 0 && ! (job->isActive || job->shouldStop))
  12441. break;
  12442. job = 0;
  12443. }
  12444. if (job != 0)
  12445. job->isActive = true;
  12446. }
  12447. if (job != 0)
  12448. {
  12449. JUCE_TRY
  12450. {
  12451. ThreadPoolJob::JobStatus result = job->runJob();
  12452. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12453. const ScopedLock sl (lock);
  12454. if (jobs.contains (job))
  12455. {
  12456. job->isActive = false;
  12457. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12458. {
  12459. job->pool = 0;
  12460. job->shouldStop = true;
  12461. jobs.removeValue (job);
  12462. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12463. delete job;
  12464. jobFinishedSignal.signal();
  12465. }
  12466. else
  12467. {
  12468. // move the job to the end of the queue if it wants another go
  12469. jobs.move (jobs.indexOf (job), -1);
  12470. }
  12471. }
  12472. }
  12473. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12474. catch (...)
  12475. {
  12476. const ScopedLock sl (lock);
  12477. jobs.removeValue (job);
  12478. }
  12479. #endif
  12480. }
  12481. else
  12482. {
  12483. if (threadStopTimeout > 0
  12484. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12485. {
  12486. const ScopedLock sl (lock);
  12487. if (jobs.size() == 0)
  12488. for (int i = threads.size(); --i >= 0;)
  12489. threads.getUnchecked(i)->signalThreadShouldExit();
  12490. }
  12491. else
  12492. {
  12493. return false;
  12494. }
  12495. }
  12496. return true;
  12497. }
  12498. END_JUCE_NAMESPACE
  12499. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12500. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12501. BEGIN_JUCE_NAMESPACE
  12502. TimeSliceThread::TimeSliceThread (const String& threadName)
  12503. : Thread (threadName),
  12504. index (0),
  12505. clientBeingCalled (0),
  12506. clientsChanged (false)
  12507. {
  12508. }
  12509. TimeSliceThread::~TimeSliceThread()
  12510. {
  12511. stopThread (2000);
  12512. }
  12513. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12514. {
  12515. const ScopedLock sl (listLock);
  12516. clients.addIfNotAlreadyThere (client);
  12517. clientsChanged = true;
  12518. notify();
  12519. }
  12520. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12521. {
  12522. const ScopedLock sl1 (listLock);
  12523. clientsChanged = true;
  12524. // if there's a chance we're in the middle of calling this client, we need to
  12525. // also lock the outer lock..
  12526. if (clientBeingCalled == client)
  12527. {
  12528. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12529. const ScopedLock sl2 (callbackLock);
  12530. const ScopedLock sl3 (listLock);
  12531. clients.removeValue (client);
  12532. }
  12533. else
  12534. {
  12535. clients.removeValue (client);
  12536. }
  12537. }
  12538. int TimeSliceThread::getNumClients() const
  12539. {
  12540. return clients.size();
  12541. }
  12542. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12543. {
  12544. const ScopedLock sl (listLock);
  12545. return clients [i];
  12546. }
  12547. void TimeSliceThread::run()
  12548. {
  12549. int numCallsSinceBusy = 0;
  12550. while (! threadShouldExit())
  12551. {
  12552. int timeToWait = 500;
  12553. {
  12554. const ScopedLock sl (callbackLock);
  12555. {
  12556. const ScopedLock sl2 (listLock);
  12557. if (clients.size() > 0)
  12558. {
  12559. index = (index + 1) % clients.size();
  12560. clientBeingCalled = clients [index];
  12561. }
  12562. else
  12563. {
  12564. index = 0;
  12565. clientBeingCalled = 0;
  12566. }
  12567. if (clientsChanged)
  12568. {
  12569. clientsChanged = false;
  12570. numCallsSinceBusy = 0;
  12571. }
  12572. }
  12573. if (clientBeingCalled != 0)
  12574. {
  12575. if (clientBeingCalled->useTimeSlice())
  12576. numCallsSinceBusy = 0;
  12577. else
  12578. ++numCallsSinceBusy;
  12579. if (numCallsSinceBusy >= clients.size())
  12580. timeToWait = 500;
  12581. else if (index == 0)
  12582. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12583. else
  12584. timeToWait = 0;
  12585. }
  12586. }
  12587. if (timeToWait > 0)
  12588. wait (timeToWait);
  12589. }
  12590. }
  12591. END_JUCE_NAMESPACE
  12592. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12593. #endif
  12594. #if JUCE_BUILD_MISC
  12595. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12596. BEGIN_JUCE_NAMESPACE
  12597. class ValueTreeSetPropertyAction : public UndoableAction
  12598. {
  12599. public:
  12600. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12601. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12602. : target (target_), name (name_), newValue (newValue_),
  12603. isAddingNewProperty (isAddingNewProperty_),
  12604. isDeletingProperty (isDeletingProperty_)
  12605. {
  12606. if (! isAddingNewProperty)
  12607. oldValue = target_->getProperty (name_);
  12608. }
  12609. ~ValueTreeSetPropertyAction() {}
  12610. bool perform()
  12611. {
  12612. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12613. if (isDeletingProperty)
  12614. target->removeProperty (name, 0);
  12615. else
  12616. target->setProperty (name, newValue, 0);
  12617. return true;
  12618. }
  12619. bool undo()
  12620. {
  12621. if (isAddingNewProperty)
  12622. target->removeProperty (name, 0);
  12623. else
  12624. target->setProperty (name, oldValue, 0);
  12625. return true;
  12626. }
  12627. int getSizeInUnits()
  12628. {
  12629. return (int) sizeof (*this); //xxx should be more accurate
  12630. }
  12631. private:
  12632. const ValueTree::SharedObjectPtr target;
  12633. const var::identifier name;
  12634. const var newValue;
  12635. var oldValue;
  12636. const bool isAddingNewProperty, isDeletingProperty;
  12637. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12638. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12639. };
  12640. class ValueTreeChildChangeAction : public UndoableAction
  12641. {
  12642. public:
  12643. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12644. const ValueTree::SharedObjectPtr& newChild_)
  12645. : target (target_),
  12646. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12647. childIndex (childIndex_),
  12648. isDeleting (newChild_ == 0)
  12649. {
  12650. jassert (child != 0);
  12651. }
  12652. ~ValueTreeChildChangeAction() {}
  12653. bool perform()
  12654. {
  12655. if (isDeleting)
  12656. target->removeChild (childIndex, 0);
  12657. else
  12658. target->addChild (child, childIndex, 0);
  12659. return true;
  12660. }
  12661. bool undo()
  12662. {
  12663. if (isDeleting)
  12664. target->addChild (child, childIndex, 0);
  12665. else
  12666. target->removeChild (childIndex, 0);
  12667. return true;
  12668. }
  12669. int getSizeInUnits()
  12670. {
  12671. return (int) sizeof (*this); //xxx should be more accurate
  12672. }
  12673. private:
  12674. const ValueTree::SharedObjectPtr target, child;
  12675. const int childIndex;
  12676. const bool isDeleting;
  12677. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12678. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12679. };
  12680. ValueTree::SharedObject::SharedObject (const String& type_)
  12681. : type (type_), parent (0)
  12682. {
  12683. }
  12684. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12685. : type (other.type), properties (other.properties), parent (0)
  12686. {
  12687. for (int i = 0; i < other.children.size(); ++i)
  12688. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12689. }
  12690. ValueTree::SharedObject::~SharedObject()
  12691. {
  12692. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12693. for (int i = children.size(); --i >= 0;)
  12694. {
  12695. const SharedObjectPtr c (children.getUnchecked(i));
  12696. c->parent = 0;
  12697. children.remove (i);
  12698. c->sendParentChangeMessage();
  12699. }
  12700. }
  12701. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12702. {
  12703. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12704. {
  12705. ValueTree* const v = valueTreesWithListeners[i];
  12706. if (v != 0)
  12707. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12708. }
  12709. }
  12710. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12711. {
  12712. ValueTree tree (this);
  12713. ValueTree::SharedObject* t = this;
  12714. while (t != 0)
  12715. {
  12716. t->sendPropertyChangeMessage (tree, property);
  12717. t = t->parent;
  12718. }
  12719. }
  12720. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12721. {
  12722. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12723. {
  12724. ValueTree* const v = valueTreesWithListeners[i];
  12725. if (v != 0)
  12726. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12727. }
  12728. }
  12729. void ValueTree::SharedObject::sendChildChangeMessage()
  12730. {
  12731. ValueTree tree (this);
  12732. ValueTree::SharedObject* t = this;
  12733. while (t != 0)
  12734. {
  12735. t->sendChildChangeMessage (tree);
  12736. t = t->parent;
  12737. }
  12738. }
  12739. void ValueTree::SharedObject::sendParentChangeMessage()
  12740. {
  12741. ValueTree tree (this);
  12742. int i;
  12743. for (i = children.size(); --i >= 0;)
  12744. {
  12745. SharedObject* const t = children[i];
  12746. if (t != 0)
  12747. t->sendParentChangeMessage();
  12748. }
  12749. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12750. {
  12751. ValueTree* const v = valueTreesWithListeners[i];
  12752. if (v != 0)
  12753. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12754. }
  12755. }
  12756. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12757. {
  12758. return properties [name];
  12759. }
  12760. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12761. {
  12762. if (undoManager == 0)
  12763. {
  12764. if (properties.set (name, newValue))
  12765. sendPropertyChangeMessage (name);
  12766. }
  12767. else
  12768. {
  12769. var* const existingValue = properties.getItem (name);
  12770. if (existingValue != 0)
  12771. {
  12772. if (*existingValue != newValue)
  12773. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  12774. }
  12775. else
  12776. {
  12777. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  12778. }
  12779. }
  12780. }
  12781. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12782. {
  12783. return properties.contains (name);
  12784. }
  12785. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12786. {
  12787. if (undoManager == 0)
  12788. {
  12789. if (properties.remove (name))
  12790. sendPropertyChangeMessage (name);
  12791. }
  12792. else
  12793. {
  12794. if (properties.contains (name))
  12795. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  12796. }
  12797. }
  12798. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12799. {
  12800. if (undoManager == 0)
  12801. {
  12802. while (properties.size() > 0)
  12803. {
  12804. const var::identifier name (properties.getName (properties.size() - 1));
  12805. properties.remove (name);
  12806. sendPropertyChangeMessage (name);
  12807. }
  12808. }
  12809. else
  12810. {
  12811. for (int i = properties.size(); --i >= 0;)
  12812. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  12813. }
  12814. }
  12815. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12816. {
  12817. for (int i = 0; i < children.size(); ++i)
  12818. if (children.getUnchecked(i)->type == typeToMatch)
  12819. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12820. return ValueTree::invalid;
  12821. }
  12822. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12823. {
  12824. for (int i = 0; i < children.size(); ++i)
  12825. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12826. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12827. return ValueTree::invalid;
  12828. }
  12829. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12830. {
  12831. const SharedObject* p = parent;
  12832. while (p != 0)
  12833. {
  12834. if (p == possibleParent)
  12835. return true;
  12836. p = p->parent;
  12837. }
  12838. return false;
  12839. }
  12840. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12841. {
  12842. if (child != 0 && child->parent != this)
  12843. {
  12844. if (child != this && ! isAChildOf (child))
  12845. {
  12846. // You should always make sure that a child is removed from its previous parent before
  12847. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12848. // undomanager should be used when removing it from its current parent..
  12849. jassert (child->parent == 0);
  12850. if (child->parent != 0)
  12851. {
  12852. jassert (child->parent->children.indexOf (child) >= 0);
  12853. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12854. }
  12855. if (undoManager == 0)
  12856. {
  12857. children.insert (index, child);
  12858. child->parent = this;
  12859. sendChildChangeMessage();
  12860. child->sendParentChangeMessage();
  12861. }
  12862. else
  12863. {
  12864. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  12865. }
  12866. }
  12867. else
  12868. {
  12869. // You're attempting to create a recursive loop! A node
  12870. // can't be a child of one of its own children!
  12871. jassertfalse
  12872. }
  12873. }
  12874. }
  12875. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12876. {
  12877. const SharedObjectPtr child (children [childIndex]);
  12878. if (child != 0)
  12879. {
  12880. if (undoManager == 0)
  12881. {
  12882. children.remove (childIndex);
  12883. child->parent = 0;
  12884. sendChildChangeMessage();
  12885. child->sendParentChangeMessage();
  12886. }
  12887. else
  12888. {
  12889. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  12890. }
  12891. }
  12892. }
  12893. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  12894. {
  12895. while (children.size() > 0)
  12896. removeChild (children.size() - 1, undoManager);
  12897. }
  12898. ValueTree ValueTree::invalid ((ValueTree::SharedObject*) 0);
  12899. ValueTree::ValueTree (const String& type_)
  12900. : object (new ValueTree::SharedObject (type_))
  12901. {
  12902. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  12903. }
  12904. ValueTree::ValueTree (SharedObject* const object_)
  12905. : object (object_)
  12906. {
  12907. }
  12908. ValueTree::ValueTree (const ValueTree& other)
  12909. : object (other.object)
  12910. {
  12911. }
  12912. ValueTree& ValueTree::operator= (const ValueTree& other)
  12913. {
  12914. if (listeners.size() > 0)
  12915. {
  12916. if (object != 0)
  12917. object->valueTreesWithListeners.removeValue (this);
  12918. if (other.object != 0)
  12919. other.object->valueTreesWithListeners.add (this);
  12920. }
  12921. object = other.object;
  12922. return *this;
  12923. }
  12924. ValueTree::~ValueTree()
  12925. {
  12926. if (listeners.size() > 0 && object != 0)
  12927. object->valueTreesWithListeners.removeValue (this);
  12928. }
  12929. bool ValueTree::operator== (const ValueTree& other) const
  12930. {
  12931. return object == other.object;
  12932. }
  12933. bool ValueTree::operator!= (const ValueTree& other) const
  12934. {
  12935. return object != other.object;
  12936. }
  12937. ValueTree ValueTree::createCopy() const
  12938. {
  12939. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  12940. }
  12941. bool ValueTree::hasType (const String& typeName) const
  12942. {
  12943. return object != 0 && object->type == typeName;
  12944. }
  12945. const String ValueTree::getType() const
  12946. {
  12947. return object != 0 ? object->type : String::empty;
  12948. }
  12949. ValueTree ValueTree::getParent() const
  12950. {
  12951. return ValueTree (object != 0 ? object->parent : (SharedObject*) 0);
  12952. }
  12953. const var& ValueTree::operator[] (const var::identifier& name) const
  12954. {
  12955. return object == 0 ? var::null : object->getProperty (name);
  12956. }
  12957. const var& ValueTree::getProperty (const var::identifier& name) const
  12958. {
  12959. return object == 0 ? var::null : object->getProperty (name);
  12960. }
  12961. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12962. {
  12963. jassert (name.name.isNotEmpty());
  12964. if (object != 0 && name.name.isNotEmpty())
  12965. object->setProperty (name, newValue, undoManager);
  12966. }
  12967. bool ValueTree::hasProperty (const var::identifier& name) const
  12968. {
  12969. return object != 0 && object->hasProperty (name);
  12970. }
  12971. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12972. {
  12973. if (object != 0)
  12974. object->removeProperty (name, undoManager);
  12975. }
  12976. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  12977. {
  12978. if (object != 0)
  12979. object->removeAllProperties (undoManager);
  12980. }
  12981. int ValueTree::getNumProperties() const
  12982. {
  12983. return object == 0 ? 0 : object->properties.size();
  12984. }
  12985. const var::identifier ValueTree::getPropertyName (int index) const
  12986. {
  12987. return (object == 0) ? var::identifier()
  12988. : object->properties.getName (index);
  12989. }
  12990. class ValueTreePropertyValueSource : public Value::ValueSource,
  12991. public ValueTree::Listener
  12992. {
  12993. public:
  12994. ValueTreePropertyValueSource (const ValueTree& tree_,
  12995. const var::identifier& property_,
  12996. UndoManager* const undoManager_)
  12997. : tree (tree_),
  12998. property (property_),
  12999. undoManager (undoManager_)
  13000. {
  13001. tree.addListener (this);
  13002. }
  13003. ~ValueTreePropertyValueSource()
  13004. {
  13005. tree.removeListener (this);
  13006. }
  13007. const var getValue() const
  13008. {
  13009. return tree [property];
  13010. }
  13011. void setValue (const var& newValue)
  13012. {
  13013. tree.setProperty (property, newValue, undoManager);
  13014. }
  13015. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13016. {
  13017. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13018. sendChangeMessage (false);
  13019. }
  13020. void valueTreeChildrenChanged (ValueTree&) {}
  13021. void valueTreeParentChanged (ValueTree&) {}
  13022. private:
  13023. ValueTree tree;
  13024. const var::identifier property;
  13025. UndoManager* const undoManager;
  13026. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13027. };
  13028. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13029. {
  13030. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13031. }
  13032. int ValueTree::getNumChildren() const
  13033. {
  13034. return object == 0 ? 0 : object->children.size();
  13035. }
  13036. ValueTree ValueTree::getChild (int index) const
  13037. {
  13038. return ValueTree (object != 0 ? (SharedObject*) object->children [index] : (SharedObject*) 0);
  13039. }
  13040. ValueTree ValueTree::getChildWithName (const String& type) const
  13041. {
  13042. return object != 0 ? object->getChildWithName (type) : ValueTree::invalid;
  13043. }
  13044. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13045. {
  13046. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree::invalid;
  13047. }
  13048. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13049. {
  13050. return object != 0 && object->isAChildOf (possibleParent.object);
  13051. }
  13052. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13053. {
  13054. if (object != 0)
  13055. object->addChild (child.object, index, undoManager);
  13056. }
  13057. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13058. {
  13059. if (object != 0)
  13060. object->removeChild (childIndex, undoManager);
  13061. }
  13062. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13063. {
  13064. if (object != 0)
  13065. object->removeChild (object->children.indexOf (child.object), undoManager);
  13066. }
  13067. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13068. {
  13069. if (object != 0)
  13070. object->removeAllChildren (undoManager);
  13071. }
  13072. void ValueTree::addListener (Listener* listener)
  13073. {
  13074. if (listener != 0)
  13075. {
  13076. if (listeners.size() == 0 && object != 0)
  13077. object->valueTreesWithListeners.add (this);
  13078. listeners.add (listener);
  13079. }
  13080. }
  13081. void ValueTree::removeListener (Listener* listener)
  13082. {
  13083. listeners.remove (listener);
  13084. if (listeners.size() == 0 && object != 0)
  13085. object->valueTreesWithListeners.removeValue (this);
  13086. }
  13087. XmlElement* ValueTree::SharedObject::createXml() const
  13088. {
  13089. XmlElement* xml = new XmlElement (type);
  13090. int i;
  13091. for (i = 0; i < properties.size(); ++i)
  13092. {
  13093. var::identifier name (properties.getName(i));
  13094. const var& v = properties [name];
  13095. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13096. xml->setAttribute (name.name, v.toString());
  13097. }
  13098. for (i = 0; i < children.size(); ++i)
  13099. xml->addChildElement (children.getUnchecked(i)->createXml());
  13100. return xml;
  13101. }
  13102. XmlElement* ValueTree::createXml() const
  13103. {
  13104. return object != 0 ? object->createXml() : 0;
  13105. }
  13106. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13107. {
  13108. ValueTree v (xml.getTagName());
  13109. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13110. for (int i = 0; i < numAtts; ++i)
  13111. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13112. forEachXmlChildElement (xml, e)
  13113. {
  13114. v.addChild (fromXml (*e), -1, 0);
  13115. }
  13116. return v;
  13117. }
  13118. void ValueTree::writeToStream (OutputStream& output)
  13119. {
  13120. output.writeString (getType());
  13121. const int numProps = getNumProperties();
  13122. output.writeCompressedInt (numProps);
  13123. int i;
  13124. for (i = 0; i < numProps; ++i)
  13125. {
  13126. const var::identifier name (getPropertyName(i));
  13127. output.writeString (name.name);
  13128. getProperty(name).writeToStream (output);
  13129. }
  13130. const int numChildren = getNumChildren();
  13131. output.writeCompressedInt (numChildren);
  13132. for (i = 0; i < numChildren; ++i)
  13133. getChild (i).writeToStream (output);
  13134. }
  13135. ValueTree ValueTree::readFromStream (InputStream& input)
  13136. {
  13137. String type (input.readString());
  13138. if (type.isEmpty())
  13139. return ValueTree::invalid;
  13140. ValueTree v (type);
  13141. const int numProps = input.readCompressedInt();
  13142. if (numProps < 0)
  13143. {
  13144. jassertfalse // trying to read corrupted data!
  13145. return v;
  13146. }
  13147. int i;
  13148. for (i = 0; i < numProps; ++i)
  13149. {
  13150. const String name (input.readString());
  13151. jassert (name.isNotEmpty());
  13152. const var value (var::readFromStream (input));
  13153. v.setProperty (name, value, 0);
  13154. }
  13155. const int numChildren = input.readCompressedInt();
  13156. for (i = 0; i < numChildren; ++i)
  13157. v.addChild (readFromStream (input), -1, 0);
  13158. return v;
  13159. }
  13160. END_JUCE_NAMESPACE
  13161. /*** End of inlined file: juce_ValueTree.cpp ***/
  13162. /*** Start of inlined file: juce_Value.cpp ***/
  13163. BEGIN_JUCE_NAMESPACE
  13164. Value::ValueSource::ValueSource()
  13165. {
  13166. }
  13167. Value::ValueSource::~ValueSource()
  13168. {
  13169. }
  13170. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13171. {
  13172. if (synchronous)
  13173. {
  13174. for (int i = valuesWithListeners.size(); --i >= 0;)
  13175. {
  13176. Value* const v = valuesWithListeners[i];
  13177. if (v != 0)
  13178. v->callListeners();
  13179. }
  13180. }
  13181. else
  13182. {
  13183. triggerAsyncUpdate();
  13184. }
  13185. }
  13186. void Value::ValueSource::handleAsyncUpdate()
  13187. {
  13188. sendChangeMessage (true);
  13189. }
  13190. class SimpleValueSource : public Value::ValueSource
  13191. {
  13192. public:
  13193. SimpleValueSource()
  13194. {
  13195. }
  13196. SimpleValueSource (const var& initialValue)
  13197. : value (initialValue)
  13198. {
  13199. }
  13200. ~SimpleValueSource()
  13201. {
  13202. }
  13203. const var getValue() const
  13204. {
  13205. return value;
  13206. }
  13207. void setValue (const var& newValue)
  13208. {
  13209. if (newValue != value)
  13210. {
  13211. value = newValue;
  13212. sendChangeMessage (false);
  13213. }
  13214. }
  13215. private:
  13216. var value;
  13217. SimpleValueSource (const SimpleValueSource&);
  13218. SimpleValueSource& operator= (const SimpleValueSource&);
  13219. };
  13220. Value::Value()
  13221. : value (new SimpleValueSource())
  13222. {
  13223. }
  13224. Value::Value (ValueSource* const value_)
  13225. : value (value_)
  13226. {
  13227. jassert (value_ != 0);
  13228. }
  13229. Value::Value (const var& initialValue)
  13230. : value (new SimpleValueSource (initialValue))
  13231. {
  13232. }
  13233. Value::Value (const Value& other)
  13234. : value (other.value)
  13235. {
  13236. }
  13237. Value& Value::operator= (const Value& other)
  13238. {
  13239. value = other.value;
  13240. return *this;
  13241. }
  13242. Value::~Value()
  13243. {
  13244. if (listeners.size() > 0)
  13245. value->valuesWithListeners.removeValue (this);
  13246. }
  13247. const var Value::getValue() const
  13248. {
  13249. return value->getValue();
  13250. }
  13251. Value::operator const var() const
  13252. {
  13253. return getValue();
  13254. }
  13255. void Value::setValue (const var& newValue)
  13256. {
  13257. value->setValue (newValue);
  13258. }
  13259. const String Value::toString() const
  13260. {
  13261. return value->getValue().toString();
  13262. }
  13263. Value& Value::operator= (const var& newValue)
  13264. {
  13265. value->setValue (newValue);
  13266. return *this;
  13267. }
  13268. void Value::referTo (const Value& valueToReferTo)
  13269. {
  13270. if (valueToReferTo.value != value)
  13271. {
  13272. if (listeners.size() > 0)
  13273. {
  13274. value->valuesWithListeners.removeValue (this);
  13275. valueToReferTo.value->valuesWithListeners.add (this);
  13276. }
  13277. value = valueToReferTo.value;
  13278. callListeners();
  13279. }
  13280. }
  13281. bool Value::refersToSameSourceAs (const Value& other) const
  13282. {
  13283. return value == other.value;
  13284. }
  13285. bool Value::operator== (const Value& other) const
  13286. {
  13287. return value == other.value || value->getValue() == other.getValue();
  13288. }
  13289. bool Value::operator!= (const Value& other) const
  13290. {
  13291. return value != other.value && value->getValue() != other.getValue();
  13292. }
  13293. void Value::addListener (Listener* const listener)
  13294. {
  13295. if (listener != 0)
  13296. {
  13297. if (listeners.size() == 0)
  13298. value->valuesWithListeners.add (this);
  13299. listeners.add (listener);
  13300. }
  13301. }
  13302. void Value::removeListener (Listener* const listener)
  13303. {
  13304. listeners.remove (listener);
  13305. if (listeners.size() == 0)
  13306. value->valuesWithListeners.removeValue (this);
  13307. }
  13308. void Value::callListeners()
  13309. {
  13310. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13311. listeners.call (&Listener::valueChanged, v);
  13312. }
  13313. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13314. {
  13315. return stream << value.toString();
  13316. }
  13317. END_JUCE_NAMESPACE
  13318. /*** End of inlined file: juce_Value.cpp ***/
  13319. /*** Start of inlined file: juce_Application.cpp ***/
  13320. #if JUCE_MSVC
  13321. #pragma warning (push)
  13322. #pragma warning (disable: 4245 4514 4100)
  13323. #include <crtdbg.h>
  13324. #pragma warning (pop)
  13325. #endif
  13326. BEGIN_JUCE_NAMESPACE
  13327. void juce_setCurrentThreadName (const String& name);
  13328. static JUCEApplication* appInstance = 0;
  13329. JUCEApplication::JUCEApplication()
  13330. : appReturnValue (0),
  13331. stillInitialising (true)
  13332. {
  13333. }
  13334. JUCEApplication::~JUCEApplication()
  13335. {
  13336. if (appLock != 0)
  13337. {
  13338. appLock->exit();
  13339. appLock = 0;
  13340. }
  13341. }
  13342. JUCEApplication* JUCEApplication::getInstance() throw()
  13343. {
  13344. return appInstance;
  13345. }
  13346. bool JUCEApplication::isInitialising() const throw()
  13347. {
  13348. return stillInitialising;
  13349. }
  13350. const String JUCEApplication::getApplicationVersion()
  13351. {
  13352. return String::empty;
  13353. }
  13354. bool JUCEApplication::moreThanOneInstanceAllowed()
  13355. {
  13356. return true;
  13357. }
  13358. void JUCEApplication::anotherInstanceStarted (const String&)
  13359. {
  13360. }
  13361. void JUCEApplication::systemRequestedQuit()
  13362. {
  13363. quit();
  13364. }
  13365. void JUCEApplication::quit()
  13366. {
  13367. MessageManager::getInstance()->stopDispatchLoop();
  13368. }
  13369. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13370. {
  13371. appReturnValue = newReturnValue;
  13372. }
  13373. void JUCEApplication::unhandledException (const std::exception*,
  13374. const String&,
  13375. const int)
  13376. {
  13377. jassertfalse
  13378. }
  13379. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13380. const char* const sourceFile,
  13381. const int lineNumber)
  13382. {
  13383. if (appInstance != 0)
  13384. appInstance->unhandledException (e, sourceFile, lineNumber);
  13385. }
  13386. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13387. {
  13388. return 0;
  13389. }
  13390. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13391. {
  13392. commands.add (StandardApplicationCommandIDs::quit);
  13393. }
  13394. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13395. {
  13396. if (commandID == StandardApplicationCommandIDs::quit)
  13397. {
  13398. result.setInfo (TRANS("Quit"),
  13399. TRANS("Quits the application"),
  13400. "Application",
  13401. 0);
  13402. result.defaultKeypresses.add (KeyPress ('q', ModifierKeys::commandModifier, 0));
  13403. }
  13404. }
  13405. bool JUCEApplication::perform (const InvocationInfo& info)
  13406. {
  13407. if (info.commandID == StandardApplicationCommandIDs::quit)
  13408. {
  13409. systemRequestedQuit();
  13410. return true;
  13411. }
  13412. return false;
  13413. }
  13414. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13415. {
  13416. if (! app->initialiseApp (commandLine))
  13417. return 0;
  13418. // now loop until a quit message is received..
  13419. JUCE_TRY
  13420. {
  13421. MessageManager::getInstance()->runDispatchLoop();
  13422. }
  13423. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13424. catch (const std::exception& e)
  13425. {
  13426. app->unhandledException (&e, __FILE__, __LINE__);
  13427. }
  13428. catch (...)
  13429. {
  13430. app->unhandledException (0, __FILE__, __LINE__);
  13431. }
  13432. #endif
  13433. return shutdownAppAndClearUp();
  13434. }
  13435. bool JUCEApplication::initialiseApp (String& commandLine)
  13436. {
  13437. jassert (appInstance == 0);
  13438. appInstance = this;
  13439. commandLineParameters = commandLine.trim();
  13440. commandLine = String::empty;
  13441. initialiseJuce_GUI();
  13442. #if ! JUCE_IPHONE
  13443. jassert (appLock == 0); // initialiseApp must only be called once!
  13444. if (! moreThanOneInstanceAllowed())
  13445. {
  13446. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13447. if (! appLock->enter(0))
  13448. {
  13449. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13450. delete appInstance;
  13451. appInstance = 0;
  13452. DBG ("Another instance is running - quitting...");
  13453. return false;
  13454. }
  13455. }
  13456. #endif
  13457. // let the app do its setting-up..
  13458. initialise (commandLineParameters);
  13459. // register for broadcast new app messages
  13460. MessageManager::getInstance()->registerBroadcastListener (this);
  13461. stillInitialising = false;
  13462. return true;
  13463. }
  13464. int JUCEApplication::shutdownAppAndClearUp()
  13465. {
  13466. jassert (appInstance != 0);
  13467. ScopedPointer<JUCEApplication> app (appInstance);
  13468. int returnValue = 0;
  13469. MessageManager::getInstance()->deregisterBroadcastListener (static_cast <JUCEApplication*> (app));
  13470. static bool reentrancyCheck = false;
  13471. if (! reentrancyCheck)
  13472. {
  13473. reentrancyCheck = true;
  13474. JUCE_TRY
  13475. {
  13476. // give the app a chance to clean up..
  13477. app->shutdown();
  13478. }
  13479. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13480. catch (const std::exception& e)
  13481. {
  13482. app->unhandledException (&e, __FILE__, __LINE__);
  13483. }
  13484. catch (...)
  13485. {
  13486. app->unhandledException (0, __FILE__, __LINE__);
  13487. }
  13488. #endif
  13489. JUCE_TRY
  13490. {
  13491. shutdownJuce_GUI();
  13492. returnValue = app->getApplicationReturnValue();
  13493. appInstance = 0;
  13494. app = 0;
  13495. }
  13496. JUCE_CATCH_ALL_ASSERT
  13497. reentrancyCheck = false;
  13498. }
  13499. return returnValue;
  13500. }
  13501. #if JUCE_IPHONE
  13502. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13503. #endif
  13504. #if ! JUCE_WINDOWS
  13505. extern const char* juce_Argv0;
  13506. #endif
  13507. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13508. {
  13509. #if ! JUCE_WINDOWS
  13510. juce_Argv0 = argv[0];
  13511. #endif
  13512. #if JUCE_IPHONE
  13513. const ScopedAutoReleasePool pool;
  13514. return juce_IPhoneMain (argc, argv, newApp);
  13515. #else
  13516. #if JUCE_MAC
  13517. const ScopedAutoReleasePool pool;
  13518. #endif
  13519. String cmd;
  13520. for (int i = 1; i < argc; ++i)
  13521. cmd << argv[i] << ' ';
  13522. return JUCEApplication::main (cmd, newApp);
  13523. #endif
  13524. }
  13525. void JUCEApplication::actionListenerCallback (const String& message)
  13526. {
  13527. if (message.startsWith (getApplicationName() + "/"))
  13528. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13529. }
  13530. static bool juceInitialisedGUI = false;
  13531. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13532. {
  13533. if (! juceInitialisedGUI)
  13534. {
  13535. #if JUCE_MAC || JUCE_IPHONE
  13536. const ScopedAutoReleasePool pool;
  13537. #endif
  13538. juceInitialisedGUI = true;
  13539. initialiseJuce_NonGUI();
  13540. MessageManager::getInstance();
  13541. LookAndFeel::setDefaultLookAndFeel (0);
  13542. juce_setCurrentThreadName ("Juce Message Thread");
  13543. #if JUCE_WINDOWS && JUCE_DEBUG
  13544. // This section is just for catching people who mess up their project settings and
  13545. // turn RTTI off..
  13546. try
  13547. {
  13548. TextButton tb (String::empty);
  13549. Component* c = &tb;
  13550. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13551. c = dynamic_cast <Button*> (c);
  13552. }
  13553. catch (...)
  13554. {
  13555. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13556. // got as far as this catch statement, then why haven't you got exception catching
  13557. // turned on in the debugger???
  13558. jassertfalse
  13559. }
  13560. #endif
  13561. }
  13562. }
  13563. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13564. {
  13565. if (juceInitialisedGUI)
  13566. {
  13567. #if JUCE_MAC
  13568. const ScopedAutoReleasePool pool;
  13569. #endif
  13570. {
  13571. DeletedAtShutdown::deleteAll();
  13572. LookAndFeel::clearDefaultLookAndFeel();
  13573. }
  13574. delete MessageManager::getInstance();
  13575. shutdownJuce_NonGUI();
  13576. juceInitialisedGUI = false;
  13577. }
  13578. }
  13579. END_JUCE_NAMESPACE
  13580. /*** End of inlined file: juce_Application.cpp ***/
  13581. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13582. BEGIN_JUCE_NAMESPACE
  13583. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13584. : commandID (commandID_),
  13585. flags (0)
  13586. {
  13587. }
  13588. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13589. const String& description_,
  13590. const String& categoryName_,
  13591. const int flags_) throw()
  13592. {
  13593. shortName = shortName_;
  13594. description = description_;
  13595. categoryName = categoryName_;
  13596. flags = flags_;
  13597. }
  13598. void ApplicationCommandInfo::setActive (const bool b) throw()
  13599. {
  13600. if (b)
  13601. flags &= ~isDisabled;
  13602. else
  13603. flags |= isDisabled;
  13604. }
  13605. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13606. {
  13607. if (b)
  13608. flags |= isTicked;
  13609. else
  13610. flags &= ~isTicked;
  13611. }
  13612. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13613. {
  13614. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13615. }
  13616. END_JUCE_NAMESPACE
  13617. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13618. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13619. BEGIN_JUCE_NAMESPACE
  13620. ApplicationCommandManager::ApplicationCommandManager()
  13621. : firstTarget (0)
  13622. {
  13623. keyMappings = new KeyPressMappingSet (this);
  13624. Desktop::getInstance().addFocusChangeListener (this);
  13625. }
  13626. ApplicationCommandManager::~ApplicationCommandManager()
  13627. {
  13628. Desktop::getInstance().removeFocusChangeListener (this);
  13629. keyMappings = 0;
  13630. }
  13631. void ApplicationCommandManager::clearCommands()
  13632. {
  13633. commands.clear();
  13634. keyMappings->clearAllKeyPresses();
  13635. triggerAsyncUpdate();
  13636. }
  13637. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13638. {
  13639. // zero isn't a valid command ID!
  13640. jassert (newCommand.commandID != 0);
  13641. // the name isn't optional!
  13642. jassert (newCommand.shortName.isNotEmpty());
  13643. if (getCommandForID (newCommand.commandID) == 0)
  13644. {
  13645. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13646. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13647. commands.add (newInfo);
  13648. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13649. triggerAsyncUpdate();
  13650. }
  13651. else
  13652. {
  13653. // trying to re-register the same command with different parameters?
  13654. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13655. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13656. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13657. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13658. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13659. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13660. }
  13661. }
  13662. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13663. {
  13664. if (target != 0)
  13665. {
  13666. Array <CommandID> commandIDs;
  13667. target->getAllCommands (commandIDs);
  13668. for (int i = 0; i < commandIDs.size(); ++i)
  13669. {
  13670. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13671. target->getCommandInfo (info.commandID, info);
  13672. registerCommand (info);
  13673. }
  13674. }
  13675. }
  13676. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13677. {
  13678. for (int i = commands.size(); --i >= 0;)
  13679. {
  13680. if (commands.getUnchecked (i)->commandID == commandID)
  13681. {
  13682. commands.remove (i);
  13683. triggerAsyncUpdate();
  13684. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13685. for (int j = keys.size(); --j >= 0;)
  13686. keyMappings->removeKeyPress (keys.getReference (j));
  13687. }
  13688. }
  13689. }
  13690. void ApplicationCommandManager::commandStatusChanged()
  13691. {
  13692. triggerAsyncUpdate();
  13693. }
  13694. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13695. {
  13696. for (int i = commands.size(); --i >= 0;)
  13697. if (commands.getUnchecked(i)->commandID == commandID)
  13698. return commands.getUnchecked(i);
  13699. return 0;
  13700. }
  13701. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13702. {
  13703. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13704. return (ci != 0) ? ci->shortName : String::empty;
  13705. }
  13706. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13707. {
  13708. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13709. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13710. : String::empty;
  13711. }
  13712. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13713. {
  13714. StringArray s;
  13715. for (int i = 0; i < commands.size(); ++i)
  13716. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13717. return s;
  13718. }
  13719. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13720. {
  13721. Array <CommandID> results;
  13722. for (int i = 0; i < commands.size(); ++i)
  13723. if (commands.getUnchecked(i)->categoryName == categoryName)
  13724. results.add (commands.getUnchecked(i)->commandID);
  13725. return results;
  13726. }
  13727. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13728. {
  13729. ApplicationCommandTarget::InvocationInfo info (commandID);
  13730. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13731. return invoke (info, asynchronously);
  13732. }
  13733. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13734. {
  13735. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13736. // manager first..
  13737. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13738. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13739. if (target == 0)
  13740. return false;
  13741. ApplicationCommandInfo commandInfo (0);
  13742. target->getCommandInfo (info_.commandID, commandInfo);
  13743. ApplicationCommandTarget::InvocationInfo info (info_);
  13744. info.commandFlags = commandInfo.flags;
  13745. sendListenerInvokeCallback (info);
  13746. const bool ok = target->invoke (info, asynchronously);
  13747. commandStatusChanged();
  13748. return ok;
  13749. }
  13750. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13751. {
  13752. return firstTarget != 0 ? firstTarget
  13753. : findDefaultComponentTarget();
  13754. }
  13755. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13756. {
  13757. firstTarget = newTarget;
  13758. }
  13759. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13760. ApplicationCommandInfo& upToDateInfo)
  13761. {
  13762. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13763. if (target == 0)
  13764. target = JUCEApplication::getInstance();
  13765. if (target != 0)
  13766. target = target->getTargetForCommand (commandID);
  13767. if (target != 0)
  13768. target->getCommandInfo (commandID, upToDateInfo);
  13769. return target;
  13770. }
  13771. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13772. {
  13773. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13774. if (target == 0 && c != 0)
  13775. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13776. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13777. return target;
  13778. }
  13779. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13780. {
  13781. Component* c = Component::getCurrentlyFocusedComponent();
  13782. if (c == 0)
  13783. {
  13784. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13785. if (activeWindow != 0)
  13786. {
  13787. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13788. if (c == 0)
  13789. c = activeWindow;
  13790. }
  13791. }
  13792. if (c == 0 && Process::isForegroundProcess())
  13793. {
  13794. // getting a bit desperate now - try all desktop comps..
  13795. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13796. {
  13797. ApplicationCommandTarget* const target
  13798. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13799. ->getPeer()->getLastFocusedSubcomponent());
  13800. if (target != 0)
  13801. return target;
  13802. }
  13803. }
  13804. if (c != 0)
  13805. {
  13806. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13807. // if we're focused on a ResizableWindow, chances are that it's the content
  13808. // component that really should get the event. And if not, the event will
  13809. // still be passed up to the top level window anyway, so let's send it to the
  13810. // content comp.
  13811. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13812. c = resizableWindow->getContentComponent();
  13813. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13814. if (target != 0)
  13815. return target;
  13816. }
  13817. return JUCEApplication::getInstance();
  13818. }
  13819. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13820. {
  13821. listeners.add (listener);
  13822. }
  13823. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13824. {
  13825. listeners.remove (listener);
  13826. }
  13827. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13828. {
  13829. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13830. }
  13831. void ApplicationCommandManager::handleAsyncUpdate()
  13832. {
  13833. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13834. }
  13835. void ApplicationCommandManager::globalFocusChanged (Component*)
  13836. {
  13837. commandStatusChanged();
  13838. }
  13839. END_JUCE_NAMESPACE
  13840. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13841. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13842. BEGIN_JUCE_NAMESPACE
  13843. ApplicationCommandTarget::ApplicationCommandTarget()
  13844. {
  13845. }
  13846. ApplicationCommandTarget::~ApplicationCommandTarget()
  13847. {
  13848. messageInvoker = 0;
  13849. }
  13850. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13851. {
  13852. if (isCommandActive (info.commandID))
  13853. {
  13854. if (async)
  13855. {
  13856. if (messageInvoker == 0)
  13857. messageInvoker = new CommandTargetMessageInvoker (this);
  13858. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13859. return true;
  13860. }
  13861. else
  13862. {
  13863. const bool success = perform (info);
  13864. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13865. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13866. // returns the command's info.
  13867. return success;
  13868. }
  13869. }
  13870. return false;
  13871. }
  13872. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13873. {
  13874. Component* c = dynamic_cast <Component*> (this);
  13875. if (c != 0)
  13876. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13877. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13878. return 0;
  13879. }
  13880. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13881. {
  13882. ApplicationCommandTarget* target = this;
  13883. int depth = 0;
  13884. while (target != 0)
  13885. {
  13886. Array <CommandID> commandIDs;
  13887. target->getAllCommands (commandIDs);
  13888. if (commandIDs.contains (commandID))
  13889. return target;
  13890. target = target->getNextCommandTarget();
  13891. ++depth;
  13892. jassert (depth < 100); // could be a recursive command chain??
  13893. jassert (target != this); // definitely a recursive command chain!
  13894. if (depth > 100 || target == this)
  13895. break;
  13896. }
  13897. if (target == 0)
  13898. {
  13899. target = JUCEApplication::getInstance();
  13900. if (target != 0)
  13901. {
  13902. Array <CommandID> commandIDs;
  13903. target->getAllCommands (commandIDs);
  13904. if (commandIDs.contains (commandID))
  13905. return target;
  13906. }
  13907. }
  13908. return 0;
  13909. }
  13910. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  13911. {
  13912. ApplicationCommandInfo info (commandID);
  13913. info.flags = ApplicationCommandInfo::isDisabled;
  13914. getCommandInfo (commandID, info);
  13915. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  13916. }
  13917. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  13918. {
  13919. ApplicationCommandTarget* target = this;
  13920. int depth = 0;
  13921. while (target != 0)
  13922. {
  13923. if (target->tryToInvoke (info, async))
  13924. return true;
  13925. target = target->getNextCommandTarget();
  13926. ++depth;
  13927. jassert (depth < 100); // could be a recursive command chain??
  13928. jassert (target != this); // definitely a recursive command chain!
  13929. if (depth > 100 || target == this)
  13930. break;
  13931. }
  13932. if (target == 0)
  13933. {
  13934. target = JUCEApplication::getInstance();
  13935. if (target != 0)
  13936. return target->tryToInvoke (info, async);
  13937. }
  13938. return false;
  13939. }
  13940. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13941. {
  13942. ApplicationCommandTarget::InvocationInfo info (commandID);
  13943. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13944. return invoke (info, asynchronously);
  13945. }
  13946. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  13947. : commandID (commandID_),
  13948. commandFlags (0),
  13949. invocationMethod (direct),
  13950. originatingComponent (0),
  13951. isKeyDown (false),
  13952. millisecsSinceKeyPressed (0)
  13953. {
  13954. }
  13955. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  13956. : owner (owner_)
  13957. {
  13958. }
  13959. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  13960. {
  13961. }
  13962. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  13963. {
  13964. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  13965. owner->tryToInvoke (*info, false);
  13966. }
  13967. END_JUCE_NAMESPACE
  13968. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13969. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  13970. BEGIN_JUCE_NAMESPACE
  13971. juce_ImplementSingleton (ApplicationProperties)
  13972. ApplicationProperties::ApplicationProperties() throw()
  13973. : msBeforeSaving (3000),
  13974. options (PropertiesFile::storeAsBinary),
  13975. commonSettingsAreReadOnly (0)
  13976. {
  13977. }
  13978. ApplicationProperties::~ApplicationProperties()
  13979. {
  13980. closeFiles();
  13981. clearSingletonInstance();
  13982. }
  13983. void ApplicationProperties::setStorageParameters (const String& applicationName,
  13984. const String& fileNameSuffix,
  13985. const String& folderName_,
  13986. const int millisecondsBeforeSaving,
  13987. const int propertiesFileOptions) throw()
  13988. {
  13989. appName = applicationName;
  13990. fileSuffix = fileNameSuffix;
  13991. folderName = folderName_;
  13992. msBeforeSaving = millisecondsBeforeSaving;
  13993. options = propertiesFileOptions;
  13994. }
  13995. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  13996. const bool testCommonSettings,
  13997. const bool showWarningDialogOnFailure)
  13998. {
  13999. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14000. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14001. if (! (userOk && commonOk))
  14002. {
  14003. if (showWarningDialogOnFailure)
  14004. {
  14005. String filenames;
  14006. if (userProps != 0 && ! userOk)
  14007. filenames << '\n' << userProps->getFile().getFullPathName();
  14008. if (commonProps != 0 && ! commonOk)
  14009. filenames << '\n' << commonProps->getFile().getFullPathName();
  14010. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14011. appName + TRANS(" - Unable to save settings"),
  14012. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14013. + appName + TRANS(" needs to be able to write to the following files:\n")
  14014. + filenames
  14015. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14016. }
  14017. return false;
  14018. }
  14019. return true;
  14020. }
  14021. void ApplicationProperties::openFiles() throw()
  14022. {
  14023. // You need to call setStorageParameters() before trying to get hold of the
  14024. // properties!
  14025. jassert (appName.isNotEmpty());
  14026. if (appName.isNotEmpty())
  14027. {
  14028. if (userProps == 0)
  14029. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14030. false, msBeforeSaving, options);
  14031. if (commonProps == 0)
  14032. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14033. true, msBeforeSaving, options);
  14034. userProps->setFallbackPropertySet (commonProps);
  14035. }
  14036. }
  14037. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14038. {
  14039. if (userProps == 0)
  14040. openFiles();
  14041. return userProps;
  14042. }
  14043. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14044. {
  14045. if (commonProps == 0)
  14046. openFiles();
  14047. if (returnUserPropsIfReadOnly)
  14048. {
  14049. if (commonSettingsAreReadOnly == 0)
  14050. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14051. if (commonSettingsAreReadOnly > 0)
  14052. return userProps;
  14053. }
  14054. return commonProps;
  14055. }
  14056. bool ApplicationProperties::saveIfNeeded()
  14057. {
  14058. return (userProps == 0 || userProps->saveIfNeeded())
  14059. && (commonProps == 0 || commonProps->saveIfNeeded());
  14060. }
  14061. void ApplicationProperties::closeFiles()
  14062. {
  14063. userProps = 0;
  14064. commonProps = 0;
  14065. }
  14066. END_JUCE_NAMESPACE
  14067. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14068. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14069. BEGIN_JUCE_NAMESPACE
  14070. static VoidArray objectsToDelete;
  14071. static CriticalSection lock;
  14072. DeletedAtShutdown::DeletedAtShutdown()
  14073. {
  14074. const ScopedLock sl (lock);
  14075. objectsToDelete.add (this);
  14076. }
  14077. DeletedAtShutdown::~DeletedAtShutdown()
  14078. {
  14079. const ScopedLock sl (lock);
  14080. objectsToDelete.removeValue (this);
  14081. }
  14082. void DeletedAtShutdown::deleteAll()
  14083. {
  14084. // make a local copy of the array, so it can't get into a loop if something
  14085. // creates another DeletedAtShutdown object during its destructor.
  14086. VoidArray localCopy;
  14087. {
  14088. const ScopedLock sl (lock);
  14089. localCopy = objectsToDelete;
  14090. }
  14091. for (int i = localCopy.size(); --i >= 0;)
  14092. {
  14093. JUCE_TRY
  14094. {
  14095. DeletedAtShutdown* deletee = static_cast <DeletedAtShutdown*> (localCopy.getUnchecked(i));
  14096. // double-check that it's not already been deleted during another object's destructor.
  14097. {
  14098. const ScopedLock sl (lock);
  14099. if (! objectsToDelete.contains (deletee))
  14100. deletee = 0;
  14101. }
  14102. delete deletee;
  14103. }
  14104. JUCE_CATCH_EXCEPTION
  14105. }
  14106. // if no objects got re-created during shutdown, this should have been emptied by their
  14107. // destructors
  14108. jassert (objectsToDelete.size() == 0);
  14109. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14110. }
  14111. END_JUCE_NAMESPACE
  14112. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14113. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14114. BEGIN_JUCE_NAMESPACE
  14115. namespace PropertyFileConstants
  14116. {
  14117. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14118. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14119. static const char* const fileTag = "PROPERTIES";
  14120. static const char* const valueTag = "VALUE";
  14121. static const char* const nameAttribute = "name";
  14122. static const char* const valueAttribute = "val";
  14123. }
  14124. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving,
  14125. const int options_, InterProcessLock* const processLock_)
  14126. : PropertySet (ignoreCaseOfKeyNames),
  14127. file (f),
  14128. timerInterval (millisecondsBeforeSaving),
  14129. options (options_),
  14130. loadedOk (false),
  14131. needsWriting (false),
  14132. processLock (processLock_)
  14133. {
  14134. // You need to correctly specify just one storage format for the file
  14135. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14136. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14137. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14138. ProcessScopedLock pl (getProcessLock());
  14139. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14140. if (fileStream != 0)
  14141. {
  14142. int magicNumber = fileStream->readInt();
  14143. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14144. {
  14145. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14146. magicNumber = PropertyFileConstants::magicNumber;
  14147. }
  14148. if (magicNumber == PropertyFileConstants::magicNumber)
  14149. {
  14150. loadedOk = true;
  14151. BufferedInputStream in (fileStream.release(), 2048, true);
  14152. int numValues = in.readInt();
  14153. while (--numValues >= 0 && ! in.isExhausted())
  14154. {
  14155. const String key (in.readString());
  14156. const String value (in.readString());
  14157. jassert (key.isNotEmpty());
  14158. if (key.isNotEmpty())
  14159. getAllProperties().set (key, value);
  14160. }
  14161. }
  14162. else
  14163. {
  14164. // Not a binary props file - let's see if it's XML..
  14165. fileStream = 0;
  14166. XmlDocument parser (f);
  14167. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14168. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14169. {
  14170. doc = parser.getDocumentElement();
  14171. if (doc != 0)
  14172. {
  14173. loadedOk = true;
  14174. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14175. {
  14176. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14177. if (name.isNotEmpty())
  14178. {
  14179. getAllProperties().set (name,
  14180. e->getFirstChildElement() != 0
  14181. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14182. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14183. }
  14184. }
  14185. }
  14186. else
  14187. {
  14188. // must be a pretty broken XML file we're trying to parse here,
  14189. // or a sign that this object needs an InterProcessLock,
  14190. // or just a failure reading the file. This last reason is why
  14191. // we don't jassertfalse here.
  14192. }
  14193. }
  14194. }
  14195. }
  14196. else
  14197. {
  14198. loadedOk = ! f.exists();
  14199. }
  14200. }
  14201. PropertiesFile::~PropertiesFile()
  14202. {
  14203. if (! saveIfNeeded())
  14204. jassertfalse;
  14205. }
  14206. PropertiesFile::ProcessScopedLock PropertiesFile::getProcessLock() const
  14207. {
  14208. return ProcessScopedLock (processLock != 0 ? new InterProcessLock::ScopedLockType (*processLock) : 0);
  14209. }
  14210. bool PropertiesFile::saveIfNeeded()
  14211. {
  14212. const ScopedLock sl (getLock());
  14213. return (! needsWriting) || save();
  14214. }
  14215. bool PropertiesFile::needsToBeSaved() const
  14216. {
  14217. const ScopedLock sl (getLock());
  14218. return needsWriting;
  14219. }
  14220. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14221. {
  14222. const ScopedLock sl (getLock());
  14223. needsWriting = needsToBeSaved;
  14224. }
  14225. bool PropertiesFile::save()
  14226. {
  14227. const ScopedLock sl (getLock());
  14228. stopTimer();
  14229. if (file == File::nonexistent
  14230. || file.isDirectory()
  14231. || ! file.getParentDirectory().createDirectory())
  14232. return false;
  14233. if ((options & storeAsXML) != 0)
  14234. {
  14235. XmlElement doc (PropertyFileConstants::fileTag);
  14236. for (int i = 0; i < getAllProperties().size(); ++i)
  14237. {
  14238. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14239. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14240. // if the value seems to contain xml, store it as such..
  14241. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14242. XmlElement* const childElement = xmlContent.getDocumentElement();
  14243. if (childElement != 0)
  14244. e->addChildElement (childElement);
  14245. else
  14246. e->setAttribute (PropertyFileConstants::valueAttribute,
  14247. getAllProperties().getAllValues() [i]);
  14248. }
  14249. ProcessScopedLock pl (getProcessLock());
  14250. if (doc.writeToFile (file, String::empty))
  14251. {
  14252. needsWriting = false;
  14253. return true;
  14254. }
  14255. }
  14256. else
  14257. {
  14258. ProcessScopedLock pl (getProcessLock());
  14259. TemporaryFile tempFile (file);
  14260. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14261. if (out != 0)
  14262. {
  14263. if ((options & storeAsCompressedBinary) != 0)
  14264. {
  14265. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14266. out->flush();
  14267. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14268. }
  14269. else
  14270. {
  14271. // have you set up the storage option flags correctly?
  14272. jassert ((options & storeAsBinary) != 0);
  14273. out->writeInt (PropertyFileConstants::magicNumber);
  14274. }
  14275. const int numProperties = getAllProperties().size();
  14276. out->writeInt (numProperties);
  14277. for (int i = 0; i < numProperties; ++i)
  14278. {
  14279. out->writeString (getAllProperties().getAllKeys() [i]);
  14280. out->writeString (getAllProperties().getAllValues() [i]);
  14281. }
  14282. out = 0;
  14283. if (tempFile.overwriteTargetFileWithTemporary())
  14284. {
  14285. needsWriting = false;
  14286. return true;
  14287. }
  14288. }
  14289. }
  14290. return false;
  14291. }
  14292. void PropertiesFile::timerCallback()
  14293. {
  14294. saveIfNeeded();
  14295. }
  14296. void PropertiesFile::propertyChanged()
  14297. {
  14298. sendChangeMessage (this);
  14299. needsWriting = true;
  14300. if (timerInterval > 0)
  14301. startTimer (timerInterval);
  14302. else if (timerInterval == 0)
  14303. saveIfNeeded();
  14304. }
  14305. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14306. const String& fileNameSuffix,
  14307. const String& folderName,
  14308. const bool commonToAllUsers)
  14309. {
  14310. // mustn't have illegal characters in this name..
  14311. jassert (applicationName == File::createLegalFileName (applicationName));
  14312. #if JUCE_MAC || JUCE_IPHONE
  14313. File dir (commonToAllUsers ? "/Library/Preferences"
  14314. : "~/Library/Preferences");
  14315. if (folderName.isNotEmpty())
  14316. dir = dir.getChildFile (folderName);
  14317. #endif
  14318. #ifdef JUCE_LINUX
  14319. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14320. + (folderName.isNotEmpty() ? folderName
  14321. : ("." + applicationName)));
  14322. #endif
  14323. #if JUCE_WIN32
  14324. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14325. : File::userApplicationDataDirectory));
  14326. if (dir == File::nonexistent)
  14327. return File::nonexistent;
  14328. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14329. : applicationName);
  14330. #endif
  14331. return dir.getChildFile (applicationName)
  14332. .withFileExtension (fileNameSuffix);
  14333. }
  14334. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14335. const String& fileNameSuffix,
  14336. const String& folderName,
  14337. const bool commonToAllUsers,
  14338. const int millisecondsBeforeSaving,
  14339. const int propertiesFileOptions,
  14340. InterProcessLock *processLock_)
  14341. {
  14342. const File file (getDefaultAppSettingsFile (applicationName,
  14343. fileNameSuffix,
  14344. folderName,
  14345. commonToAllUsers));
  14346. jassert (file != File::nonexistent);
  14347. if (file == File::nonexistent)
  14348. return 0;
  14349. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions,processLock_);
  14350. }
  14351. END_JUCE_NAMESPACE
  14352. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14353. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14354. BEGIN_JUCE_NAMESPACE
  14355. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14356. const String& fileWildcard_,
  14357. const String& openFileDialogTitle_,
  14358. const String& saveFileDialogTitle_)
  14359. : changedSinceSave (false),
  14360. fileExtension (fileExtension_),
  14361. fileWildcard (fileWildcard_),
  14362. openFileDialogTitle (openFileDialogTitle_),
  14363. saveFileDialogTitle (saveFileDialogTitle_)
  14364. {
  14365. }
  14366. FileBasedDocument::~FileBasedDocument()
  14367. {
  14368. }
  14369. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14370. {
  14371. changedSinceSave = hasChanged;
  14372. }
  14373. void FileBasedDocument::changed()
  14374. {
  14375. changedSinceSave = true;
  14376. sendChangeMessage (this);
  14377. }
  14378. void FileBasedDocument::setFile (const File& newFile)
  14379. {
  14380. if (documentFile != newFile)
  14381. {
  14382. documentFile = newFile;
  14383. changedSinceSave = true;
  14384. }
  14385. }
  14386. bool FileBasedDocument::loadFrom (const File& newFile,
  14387. const bool showMessageOnFailure)
  14388. {
  14389. MouseCursor::showWaitCursor();
  14390. const File oldFile (documentFile);
  14391. documentFile = newFile;
  14392. String error;
  14393. if (newFile.existsAsFile())
  14394. {
  14395. error = loadDocument (newFile);
  14396. if (error.isEmpty())
  14397. {
  14398. setChangedFlag (false);
  14399. MouseCursor::hideWaitCursor();
  14400. setLastDocumentOpened (newFile);
  14401. return true;
  14402. }
  14403. }
  14404. else
  14405. {
  14406. error = "The file doesn't exist";
  14407. }
  14408. documentFile = oldFile;
  14409. MouseCursor::hideWaitCursor();
  14410. if (showMessageOnFailure)
  14411. {
  14412. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14413. TRANS("Failed to open file..."),
  14414. TRANS("There was an error while trying to load the file:\n\n")
  14415. + newFile.getFullPathName()
  14416. + "\n\n"
  14417. + error);
  14418. }
  14419. return false;
  14420. }
  14421. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14422. {
  14423. FileChooser fc (openFileDialogTitle,
  14424. getLastDocumentOpened(),
  14425. fileWildcard);
  14426. if (fc.browseForFileToOpen())
  14427. return loadFrom (fc.getResult(), showMessageOnFailure);
  14428. return false;
  14429. }
  14430. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14431. const bool showMessageOnFailure)
  14432. {
  14433. return saveAs (documentFile,
  14434. false,
  14435. askUserForFileIfNotSpecified,
  14436. showMessageOnFailure);
  14437. }
  14438. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14439. const bool warnAboutOverwritingExistingFiles,
  14440. const bool askUserForFileIfNotSpecified,
  14441. const bool showMessageOnFailure)
  14442. {
  14443. if (newFile == File::nonexistent)
  14444. {
  14445. if (askUserForFileIfNotSpecified)
  14446. {
  14447. return saveAsInteractive (true);
  14448. }
  14449. else
  14450. {
  14451. // can't save to an unspecified file
  14452. jassertfalse
  14453. return failedToWriteToFile;
  14454. }
  14455. }
  14456. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14457. {
  14458. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14459. TRANS("File already exists"),
  14460. TRANS("There's already a file called:\n\n")
  14461. + newFile.getFullPathName()
  14462. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14463. TRANS("overwrite"),
  14464. TRANS("cancel")))
  14465. {
  14466. return userCancelledSave;
  14467. }
  14468. }
  14469. MouseCursor::showWaitCursor();
  14470. const File oldFile (documentFile);
  14471. documentFile = newFile;
  14472. String error (saveDocument (newFile));
  14473. if (error.isEmpty())
  14474. {
  14475. setChangedFlag (false);
  14476. MouseCursor::hideWaitCursor();
  14477. return savedOk;
  14478. }
  14479. documentFile = oldFile;
  14480. MouseCursor::hideWaitCursor();
  14481. if (showMessageOnFailure)
  14482. {
  14483. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14484. TRANS("Error writing to file..."),
  14485. TRANS("An error occurred while trying to save \"")
  14486. + getDocumentTitle()
  14487. + TRANS("\" to the file:\n\n")
  14488. + newFile.getFullPathName()
  14489. + "\n\n"
  14490. + error);
  14491. }
  14492. return failedToWriteToFile;
  14493. }
  14494. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14495. {
  14496. if (! hasChangedSinceSaved())
  14497. return savedOk;
  14498. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14499. TRANS("Closing document..."),
  14500. TRANS("Do you want to save the changes to \"")
  14501. + getDocumentTitle() + "\"?",
  14502. TRANS("save"),
  14503. TRANS("discard changes"),
  14504. TRANS("cancel"));
  14505. if (r == 1)
  14506. {
  14507. // save changes
  14508. return save (true, true);
  14509. }
  14510. else if (r == 2)
  14511. {
  14512. // discard changes
  14513. return savedOk;
  14514. }
  14515. return userCancelledSave;
  14516. }
  14517. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14518. {
  14519. File f;
  14520. if (documentFile.existsAsFile())
  14521. f = documentFile;
  14522. else
  14523. f = getLastDocumentOpened();
  14524. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14525. if (legalFilename.isEmpty())
  14526. legalFilename = "unnamed";
  14527. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14528. f = f.getSiblingFile (legalFilename);
  14529. else
  14530. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14531. f = f.withFileExtension (fileExtension)
  14532. .getNonexistentSibling (true);
  14533. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14534. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14535. {
  14536. setLastDocumentOpened (fc.getResult());
  14537. File chosen (fc.getResult());
  14538. if (chosen.getFileExtension().isEmpty())
  14539. {
  14540. chosen = chosen.withFileExtension (fileExtension);
  14541. if (chosen.exists())
  14542. {
  14543. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14544. TRANS("File already exists"),
  14545. TRANS("There's already a file called:")
  14546. + "\n\n" + chosen.getFullPathName()
  14547. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  14548. TRANS("overwrite"),
  14549. TRANS("cancel")))
  14550. {
  14551. return userCancelledSave;
  14552. }
  14553. }
  14554. }
  14555. return saveAs (chosen, false, false, true);
  14556. }
  14557. return userCancelledSave;
  14558. }
  14559. END_JUCE_NAMESPACE
  14560. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14561. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14562. BEGIN_JUCE_NAMESPACE
  14563. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14564. : maxNumberOfItems (10)
  14565. {
  14566. }
  14567. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14568. {
  14569. }
  14570. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14571. {
  14572. maxNumberOfItems = jmax (1, newMaxNumber);
  14573. while (getNumFiles() > maxNumberOfItems)
  14574. files.remove (getNumFiles() - 1);
  14575. }
  14576. int RecentlyOpenedFilesList::getNumFiles() const
  14577. {
  14578. return files.size();
  14579. }
  14580. const File RecentlyOpenedFilesList::getFile (const int index) const
  14581. {
  14582. return File (files [index]);
  14583. }
  14584. void RecentlyOpenedFilesList::clear()
  14585. {
  14586. files.clear();
  14587. }
  14588. void RecentlyOpenedFilesList::addFile (const File& file)
  14589. {
  14590. const String path (file.getFullPathName());
  14591. files.removeString (path, true);
  14592. files.insert (0, path);
  14593. setMaxNumberOfItems (maxNumberOfItems);
  14594. }
  14595. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14596. {
  14597. for (int i = getNumFiles(); --i >= 0;)
  14598. if (! getFile(i).exists())
  14599. files.remove (i);
  14600. }
  14601. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14602. const int baseItemId,
  14603. const bool showFullPaths,
  14604. const bool dontAddNonExistentFiles,
  14605. const File** filesToAvoid)
  14606. {
  14607. int num = 0;
  14608. for (int i = 0; i < getNumFiles(); ++i)
  14609. {
  14610. const File f (getFile(i));
  14611. if ((! dontAddNonExistentFiles) || f.exists())
  14612. {
  14613. bool needsAvoiding = false;
  14614. if (filesToAvoid != 0)
  14615. {
  14616. const File** avoid = filesToAvoid;
  14617. while (*avoid != 0)
  14618. {
  14619. if (f == **avoid)
  14620. {
  14621. needsAvoiding = true;
  14622. break;
  14623. }
  14624. ++avoid;
  14625. }
  14626. }
  14627. if (! needsAvoiding)
  14628. {
  14629. menuToAddTo.addItem (baseItemId + i,
  14630. showFullPaths ? f.getFullPathName()
  14631. : f.getFileName());
  14632. ++num;
  14633. }
  14634. }
  14635. }
  14636. return num;
  14637. }
  14638. const String RecentlyOpenedFilesList::toString() const
  14639. {
  14640. return files.joinIntoString ("\n");
  14641. }
  14642. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14643. {
  14644. clear();
  14645. files.addLines (stringifiedVersion);
  14646. setMaxNumberOfItems (maxNumberOfItems);
  14647. }
  14648. END_JUCE_NAMESPACE
  14649. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14650. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14651. BEGIN_JUCE_NAMESPACE
  14652. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14653. const int minimumTransactions)
  14654. : totalUnitsStored (0),
  14655. nextIndex (0),
  14656. newTransaction (true),
  14657. reentrancyCheck (false)
  14658. {
  14659. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14660. minimumTransactions);
  14661. }
  14662. UndoManager::~UndoManager()
  14663. {
  14664. clearUndoHistory();
  14665. }
  14666. void UndoManager::clearUndoHistory()
  14667. {
  14668. transactions.clear();
  14669. transactionNames.clear();
  14670. totalUnitsStored = 0;
  14671. nextIndex = 0;
  14672. sendChangeMessage (this);
  14673. }
  14674. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14675. {
  14676. return totalUnitsStored;
  14677. }
  14678. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14679. const int minimumTransactions)
  14680. {
  14681. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14682. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14683. }
  14684. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14685. {
  14686. if (command != 0)
  14687. {
  14688. if (actionName.isNotEmpty())
  14689. currentTransactionName = actionName;
  14690. if (reentrancyCheck)
  14691. {
  14692. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14693. // undo() methods, or else these actions won't actually get done.
  14694. return false;
  14695. }
  14696. else
  14697. {
  14698. bool success = false;
  14699. JUCE_TRY
  14700. {
  14701. success = command->perform();
  14702. }
  14703. JUCE_CATCH_EXCEPTION
  14704. jassert (success);
  14705. if (success)
  14706. {
  14707. if (nextIndex > 0 && ! newTransaction)
  14708. {
  14709. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14710. jassert (commandSet != 0);
  14711. if (commandSet == 0)
  14712. return false;
  14713. commandSet->add (command);
  14714. }
  14715. else
  14716. {
  14717. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14718. commandSet->add (command);
  14719. transactions.insert (nextIndex, commandSet);
  14720. transactionNames.insert (nextIndex, currentTransactionName);
  14721. ++nextIndex;
  14722. }
  14723. totalUnitsStored += command->getSizeInUnits();
  14724. newTransaction = false;
  14725. }
  14726. while (nextIndex < transactions.size())
  14727. {
  14728. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14729. for (int i = lastSet->size(); --i >= 0;)
  14730. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14731. transactions.removeLast();
  14732. transactionNames.remove (transactionNames.size() - 1);
  14733. }
  14734. while (nextIndex > 0
  14735. && totalUnitsStored > maxNumUnitsToKeep
  14736. && transactions.size() > minimumTransactionsToKeep)
  14737. {
  14738. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14739. for (int i = firstSet->size(); --i >= 0;)
  14740. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14741. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14742. transactions.remove (0);
  14743. transactionNames.remove (0);
  14744. --nextIndex;
  14745. }
  14746. sendChangeMessage (this);
  14747. return success;
  14748. }
  14749. }
  14750. return false;
  14751. }
  14752. void UndoManager::beginNewTransaction (const String& actionName)
  14753. {
  14754. newTransaction = true;
  14755. currentTransactionName = actionName;
  14756. }
  14757. void UndoManager::setCurrentTransactionName (const String& newName)
  14758. {
  14759. currentTransactionName = newName;
  14760. }
  14761. bool UndoManager::canUndo() const
  14762. {
  14763. return nextIndex > 0;
  14764. }
  14765. bool UndoManager::canRedo() const
  14766. {
  14767. return nextIndex < transactions.size();
  14768. }
  14769. const String UndoManager::getUndoDescription() const
  14770. {
  14771. return transactionNames [nextIndex - 1];
  14772. }
  14773. const String UndoManager::getRedoDescription() const
  14774. {
  14775. return transactionNames [nextIndex];
  14776. }
  14777. bool UndoManager::undo()
  14778. {
  14779. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14780. if (commandSet == 0)
  14781. return false;
  14782. reentrancyCheck = true;
  14783. bool failed = false;
  14784. for (int i = commandSet->size(); --i >= 0;)
  14785. {
  14786. if (! commandSet->getUnchecked(i)->undo())
  14787. {
  14788. jassertfalse
  14789. failed = true;
  14790. break;
  14791. }
  14792. }
  14793. reentrancyCheck = false;
  14794. if (failed)
  14795. {
  14796. clearUndoHistory();
  14797. }
  14798. else
  14799. {
  14800. --nextIndex;
  14801. }
  14802. beginNewTransaction();
  14803. sendChangeMessage (this);
  14804. return true;
  14805. }
  14806. bool UndoManager::redo()
  14807. {
  14808. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14809. if (commandSet == 0)
  14810. return false;
  14811. reentrancyCheck = true;
  14812. bool failed = false;
  14813. for (int i = 0; i < commandSet->size(); ++i)
  14814. {
  14815. if (! commandSet->getUnchecked(i)->perform())
  14816. {
  14817. jassertfalse
  14818. failed = true;
  14819. break;
  14820. }
  14821. }
  14822. reentrancyCheck = false;
  14823. if (failed)
  14824. {
  14825. clearUndoHistory();
  14826. }
  14827. else
  14828. {
  14829. ++nextIndex;
  14830. }
  14831. beginNewTransaction();
  14832. sendChangeMessage (this);
  14833. return true;
  14834. }
  14835. bool UndoManager::undoCurrentTransactionOnly()
  14836. {
  14837. return newTransaction ? false
  14838. : undo();
  14839. }
  14840. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14841. {
  14842. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14843. if (commandSet != 0 && ! newTransaction)
  14844. {
  14845. for (int i = 0; i < commandSet->size(); ++i)
  14846. actionsFound.add (commandSet->getUnchecked(i));
  14847. }
  14848. }
  14849. int UndoManager::getNumActionsInCurrentTransaction() const
  14850. {
  14851. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14852. if (commandSet != 0 && ! newTransaction)
  14853. return commandSet->size();
  14854. return 0;
  14855. }
  14856. END_JUCE_NAMESPACE
  14857. /*** End of inlined file: juce_UndoManager.cpp ***/
  14858. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14859. BEGIN_JUCE_NAMESPACE
  14860. static const char* const aiffFormatName = "AIFF file";
  14861. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14862. class AiffAudioFormatReader : public AudioFormatReader
  14863. {
  14864. public:
  14865. int bytesPerFrame;
  14866. int64 dataChunkStart;
  14867. bool littleEndian;
  14868. AiffAudioFormatReader (InputStream* in)
  14869. : AudioFormatReader (in, TRANS (aiffFormatName))
  14870. {
  14871. if (input->readInt() == chunkName ("FORM"))
  14872. {
  14873. const int len = input->readIntBigEndian();
  14874. const int64 end = input->getPosition() + len;
  14875. const int nextType = input->readInt();
  14876. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14877. {
  14878. bool hasGotVer = false;
  14879. bool hasGotData = false;
  14880. bool hasGotType = false;
  14881. while (input->getPosition() < end)
  14882. {
  14883. const int type = input->readInt();
  14884. const uint32 length = (uint32) input->readIntBigEndian();
  14885. const int64 chunkEnd = input->getPosition() + length;
  14886. if (type == chunkName ("FVER"))
  14887. {
  14888. hasGotVer = true;
  14889. const int ver = input->readIntBigEndian();
  14890. if (ver != 0 && ver != (int)0xa2805140)
  14891. break;
  14892. }
  14893. else if (type == chunkName ("COMM"))
  14894. {
  14895. hasGotType = true;
  14896. numChannels = (unsigned int)input->readShortBigEndian();
  14897. lengthInSamples = input->readIntBigEndian();
  14898. bitsPerSample = input->readShortBigEndian();
  14899. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  14900. unsigned char sampleRateBytes[10];
  14901. input->read (sampleRateBytes, 10);
  14902. const int byte0 = sampleRateBytes[0];
  14903. if ((byte0 & 0x80) != 0
  14904. || byte0 <= 0x3F || byte0 > 0x40
  14905. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  14906. break;
  14907. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  14908. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  14909. sampleRate = (int) sampRate;
  14910. if (length <= 18)
  14911. {
  14912. // some types don't have a chunk large enough to include a compression
  14913. // type, so assume it's just big-endian pcm
  14914. littleEndian = false;
  14915. }
  14916. else
  14917. {
  14918. const int compType = input->readInt();
  14919. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  14920. {
  14921. littleEndian = false;
  14922. }
  14923. else if (compType == chunkName ("sowt"))
  14924. {
  14925. littleEndian = true;
  14926. }
  14927. else
  14928. {
  14929. sampleRate = 0;
  14930. break;
  14931. }
  14932. }
  14933. }
  14934. else if (type == chunkName ("SSND"))
  14935. {
  14936. hasGotData = true;
  14937. const int offset = input->readIntBigEndian();
  14938. dataChunkStart = input->getPosition() + 4 + offset;
  14939. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  14940. }
  14941. else if ((hasGotVer && hasGotData && hasGotType)
  14942. || chunkEnd < input->getPosition()
  14943. || input->isExhausted())
  14944. {
  14945. break;
  14946. }
  14947. input->setPosition (chunkEnd);
  14948. }
  14949. }
  14950. }
  14951. }
  14952. ~AiffAudioFormatReader()
  14953. {
  14954. }
  14955. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  14956. int64 startSampleInFile, int numSamples)
  14957. {
  14958. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  14959. if (samplesAvailable < numSamples)
  14960. {
  14961. for (int i = numDestChannels; --i >= 0;)
  14962. if (destSamples[i] != 0)
  14963. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  14964. numSamples = (int) samplesAvailable;
  14965. }
  14966. if (numSamples <= 0)
  14967. return true;
  14968. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  14969. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  14970. char tempBuffer [tempBufSize];
  14971. while (numSamples > 0)
  14972. {
  14973. int* left = destSamples[0];
  14974. if (left != 0)
  14975. left += startOffsetInDestBuffer;
  14976. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  14977. if (right != 0)
  14978. right += startOffsetInDestBuffer;
  14979. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  14980. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  14981. if (bytesRead < numThisTime * bytesPerFrame)
  14982. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  14983. if (bitsPerSample == 16)
  14984. {
  14985. if (littleEndian)
  14986. {
  14987. const short* src = (const short*) tempBuffer;
  14988. if (numChannels > 1)
  14989. {
  14990. if (left == 0)
  14991. {
  14992. for (int i = numThisTime; --i >= 0;)
  14993. {
  14994. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  14995. ++src;
  14996. }
  14997. }
  14998. else if (right == 0)
  14999. {
  15000. for (int i = numThisTime; --i >= 0;)
  15001. {
  15002. ++src;
  15003. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15004. }
  15005. }
  15006. else
  15007. {
  15008. for (int i = numThisTime; --i >= 0;)
  15009. {
  15010. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15011. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15012. }
  15013. }
  15014. }
  15015. else
  15016. {
  15017. for (int i = numThisTime; --i >= 0;)
  15018. {
  15019. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15020. }
  15021. }
  15022. }
  15023. else
  15024. {
  15025. const char* src = (const char*) tempBuffer;
  15026. if (numChannels > 1)
  15027. {
  15028. if (left == 0)
  15029. {
  15030. for (int i = numThisTime; --i >= 0;)
  15031. {
  15032. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15033. src += 4;
  15034. }
  15035. }
  15036. else if (right == 0)
  15037. {
  15038. for (int i = numThisTime; --i >= 0;)
  15039. {
  15040. src += 2;
  15041. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15042. src += 2;
  15043. }
  15044. }
  15045. else
  15046. {
  15047. for (int i = numThisTime; --i >= 0;)
  15048. {
  15049. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15050. src += 2;
  15051. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15052. src += 2;
  15053. }
  15054. }
  15055. }
  15056. else
  15057. {
  15058. for (int i = numThisTime; --i >= 0;)
  15059. {
  15060. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15061. src += 2;
  15062. }
  15063. }
  15064. }
  15065. }
  15066. else if (bitsPerSample == 24)
  15067. {
  15068. const char* src = (const char*)tempBuffer;
  15069. if (littleEndian)
  15070. {
  15071. if (numChannels > 1)
  15072. {
  15073. if (left == 0)
  15074. {
  15075. for (int i = numThisTime; --i >= 0;)
  15076. {
  15077. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15078. src += 6;
  15079. }
  15080. }
  15081. else if (right == 0)
  15082. {
  15083. for (int i = numThisTime; --i >= 0;)
  15084. {
  15085. src += 3;
  15086. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15087. src += 3;
  15088. }
  15089. }
  15090. else
  15091. {
  15092. for (int i = numThisTime; --i >= 0;)
  15093. {
  15094. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15095. src += 3;
  15096. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15097. src += 3;
  15098. }
  15099. }
  15100. }
  15101. else
  15102. {
  15103. for (int i = numThisTime; --i >= 0;)
  15104. {
  15105. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15106. src += 3;
  15107. }
  15108. }
  15109. }
  15110. else
  15111. {
  15112. if (numChannels > 1)
  15113. {
  15114. if (left == 0)
  15115. {
  15116. for (int i = numThisTime; --i >= 0;)
  15117. {
  15118. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15119. src += 6;
  15120. }
  15121. }
  15122. else if (right == 0)
  15123. {
  15124. for (int i = numThisTime; --i >= 0;)
  15125. {
  15126. src += 3;
  15127. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15128. src += 3;
  15129. }
  15130. }
  15131. else
  15132. {
  15133. for (int i = numThisTime; --i >= 0;)
  15134. {
  15135. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15136. src += 3;
  15137. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15138. src += 3;
  15139. }
  15140. }
  15141. }
  15142. else
  15143. {
  15144. for (int i = numThisTime; --i >= 0;)
  15145. {
  15146. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15147. src += 3;
  15148. }
  15149. }
  15150. }
  15151. }
  15152. else if (bitsPerSample == 32)
  15153. {
  15154. const unsigned int* src = (const unsigned int*) tempBuffer;
  15155. unsigned int* l = (unsigned int*) left;
  15156. unsigned int* r = (unsigned int*) right;
  15157. if (littleEndian)
  15158. {
  15159. if (numChannels > 1)
  15160. {
  15161. if (l == 0)
  15162. {
  15163. for (int i = numThisTime; --i >= 0;)
  15164. {
  15165. ++src;
  15166. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15167. }
  15168. }
  15169. else if (r == 0)
  15170. {
  15171. for (int i = numThisTime; --i >= 0;)
  15172. {
  15173. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15174. ++src;
  15175. }
  15176. }
  15177. else
  15178. {
  15179. for (int i = numThisTime; --i >= 0;)
  15180. {
  15181. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15182. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15183. }
  15184. }
  15185. }
  15186. else
  15187. {
  15188. for (int i = numThisTime; --i >= 0;)
  15189. {
  15190. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15191. }
  15192. }
  15193. }
  15194. else
  15195. {
  15196. if (numChannels > 1)
  15197. {
  15198. if (l == 0)
  15199. {
  15200. for (int i = numThisTime; --i >= 0;)
  15201. {
  15202. ++src;
  15203. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15204. }
  15205. }
  15206. else if (r == 0)
  15207. {
  15208. for (int i = numThisTime; --i >= 0;)
  15209. {
  15210. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15211. ++src;
  15212. }
  15213. }
  15214. else
  15215. {
  15216. for (int i = numThisTime; --i >= 0;)
  15217. {
  15218. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15219. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15220. }
  15221. }
  15222. }
  15223. else
  15224. {
  15225. for (int i = numThisTime; --i >= 0;)
  15226. {
  15227. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15228. }
  15229. }
  15230. }
  15231. left = (int*) l;
  15232. right = (int*) r;
  15233. }
  15234. else if (bitsPerSample == 8)
  15235. {
  15236. const char* src = (const char*) tempBuffer;
  15237. if (numChannels > 1)
  15238. {
  15239. if (left == 0)
  15240. {
  15241. for (int i = numThisTime; --i >= 0;)
  15242. {
  15243. *right++ = ((int) *src++) << 24;
  15244. ++src;
  15245. }
  15246. }
  15247. else if (right == 0)
  15248. {
  15249. for (int i = numThisTime; --i >= 0;)
  15250. {
  15251. ++src;
  15252. *left++ = ((int) *src++) << 24;
  15253. }
  15254. }
  15255. else
  15256. {
  15257. for (int i = numThisTime; --i >= 0;)
  15258. {
  15259. *left++ = ((int) *src++) << 24;
  15260. *right++ = ((int) *src++) << 24;
  15261. }
  15262. }
  15263. }
  15264. else
  15265. {
  15266. for (int i = numThisTime; --i >= 0;)
  15267. {
  15268. *left++ = ((int) *src++) << 24;
  15269. }
  15270. }
  15271. }
  15272. startOffsetInDestBuffer += numThisTime;
  15273. numSamples -= numThisTime;
  15274. }
  15275. if (numSamples > 0)
  15276. {
  15277. for (int i = numDestChannels; --i >= 0;)
  15278. if (destSamples[i] != 0)
  15279. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15280. sizeof (int) * numSamples);
  15281. }
  15282. return true;
  15283. }
  15284. juce_UseDebuggingNewOperator
  15285. private:
  15286. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15287. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15288. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15289. };
  15290. class AiffAudioFormatWriter : public AudioFormatWriter
  15291. {
  15292. MemoryBlock tempBlock;
  15293. uint32 lengthInSamples, bytesWritten;
  15294. int64 headerPosition;
  15295. bool writeFailed;
  15296. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15297. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15298. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15299. void writeHeader()
  15300. {
  15301. const bool couldSeekOk = output->setPosition (headerPosition);
  15302. (void) couldSeekOk;
  15303. // if this fails, you've given it an output stream that can't seek! It needs
  15304. // to be able to seek back to write the header
  15305. jassert (couldSeekOk);
  15306. const int headerLen = 54;
  15307. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15308. audioBytes += (audioBytes & 1);
  15309. output->writeInt (chunkName ("FORM"));
  15310. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15311. output->writeInt (chunkName ("AIFF"));
  15312. output->writeInt (chunkName ("COMM"));
  15313. output->writeIntBigEndian (18);
  15314. output->writeShortBigEndian ((short) numChannels);
  15315. output->writeIntBigEndian (lengthInSamples);
  15316. output->writeShortBigEndian ((short) bitsPerSample);
  15317. uint8 sampleRateBytes[10];
  15318. zeromem (sampleRateBytes, 10);
  15319. if (sampleRate <= 1)
  15320. {
  15321. sampleRateBytes[0] = 0x3f;
  15322. sampleRateBytes[1] = 0xff;
  15323. sampleRateBytes[2] = 0x80;
  15324. }
  15325. else
  15326. {
  15327. int mask = 0x40000000;
  15328. sampleRateBytes[0] = 0x40;
  15329. if (sampleRate >= mask)
  15330. {
  15331. jassertfalse
  15332. sampleRateBytes[1] = 0x1d;
  15333. }
  15334. else
  15335. {
  15336. int n = (int) sampleRate;
  15337. int i;
  15338. for (i = 0; i <= 32 ; ++i)
  15339. {
  15340. if ((n & mask) != 0)
  15341. break;
  15342. mask >>= 1;
  15343. }
  15344. n = n << (i + 1);
  15345. sampleRateBytes[1] = (uint8) (29 - i);
  15346. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15347. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15348. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15349. sampleRateBytes[5] = (uint8) (n & 0xff);
  15350. }
  15351. }
  15352. output->write (sampleRateBytes, 10);
  15353. output->writeInt (chunkName ("SSND"));
  15354. output->writeIntBigEndian (audioBytes + 8);
  15355. output->writeInt (0);
  15356. output->writeInt (0);
  15357. jassert (output->getPosition() == headerLen);
  15358. }
  15359. public:
  15360. AiffAudioFormatWriter (OutputStream* out,
  15361. const double sampleRate_,
  15362. const unsigned int chans,
  15363. const int bits)
  15364. : AudioFormatWriter (out,
  15365. TRANS (aiffFormatName),
  15366. sampleRate_,
  15367. chans,
  15368. bits),
  15369. lengthInSamples (0),
  15370. bytesWritten (0),
  15371. writeFailed (false)
  15372. {
  15373. headerPosition = out->getPosition();
  15374. writeHeader();
  15375. }
  15376. ~AiffAudioFormatWriter()
  15377. {
  15378. if ((bytesWritten & 1) != 0)
  15379. output->writeByte (0);
  15380. writeHeader();
  15381. }
  15382. bool write (const int** data, int numSamples)
  15383. {
  15384. if (writeFailed)
  15385. return false;
  15386. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15387. tempBlock.ensureSize (bytes, false);
  15388. char* buffer = (char*) tempBlock.getData();
  15389. const int* left = data[0];
  15390. const int* right = data[1];
  15391. if (right == 0)
  15392. right = left;
  15393. if (bitsPerSample == 16)
  15394. {
  15395. short* b = (short*) buffer;
  15396. if (numChannels > 1)
  15397. {
  15398. for (int i = numSamples; --i >= 0;)
  15399. {
  15400. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15401. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15402. }
  15403. }
  15404. else
  15405. {
  15406. for (int i = numSamples; --i >= 0;)
  15407. {
  15408. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15409. }
  15410. }
  15411. }
  15412. else if (bitsPerSample == 24)
  15413. {
  15414. char* b = (char*) buffer;
  15415. if (numChannels > 1)
  15416. {
  15417. for (int i = numSamples; --i >= 0;)
  15418. {
  15419. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15420. b += 3;
  15421. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15422. b += 3;
  15423. }
  15424. }
  15425. else
  15426. {
  15427. for (int i = numSamples; --i >= 0;)
  15428. {
  15429. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15430. b += 3;
  15431. }
  15432. }
  15433. }
  15434. else if (bitsPerSample == 32)
  15435. {
  15436. uint32* b = (uint32*) buffer;
  15437. if (numChannels > 1)
  15438. {
  15439. for (int i = numSamples; --i >= 0;)
  15440. {
  15441. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15442. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15443. }
  15444. }
  15445. else
  15446. {
  15447. for (int i = numSamples; --i >= 0;)
  15448. {
  15449. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15450. }
  15451. }
  15452. }
  15453. else if (bitsPerSample == 8)
  15454. {
  15455. char* b = (char*) buffer;
  15456. if (numChannels > 1)
  15457. {
  15458. for (int i = numSamples; --i >= 0;)
  15459. {
  15460. *b++ = (char) (*left++ >> 24);
  15461. *b++ = (char) (*right++ >> 24);
  15462. }
  15463. }
  15464. else
  15465. {
  15466. for (int i = numSamples; --i >= 0;)
  15467. {
  15468. *b++ = (char) (*left++ >> 24);
  15469. }
  15470. }
  15471. }
  15472. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15473. || ! output->write (buffer, bytes))
  15474. {
  15475. // failed to write to disk, so let's try writing the header.
  15476. // If it's just run out of disk space, then if it does manage
  15477. // to write the header, we'll still have a useable file..
  15478. writeHeader();
  15479. writeFailed = true;
  15480. return false;
  15481. }
  15482. else
  15483. {
  15484. bytesWritten += bytes;
  15485. lengthInSamples += numSamples;
  15486. return true;
  15487. }
  15488. }
  15489. juce_UseDebuggingNewOperator
  15490. };
  15491. AiffAudioFormat::AiffAudioFormat()
  15492. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15493. {
  15494. }
  15495. AiffAudioFormat::~AiffAudioFormat()
  15496. {
  15497. }
  15498. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15499. {
  15500. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15501. return Array <int> (rates);
  15502. }
  15503. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15504. {
  15505. const int depths[] = { 8, 16, 24, 0 };
  15506. return Array <int> (depths);
  15507. }
  15508. bool AiffAudioFormat::canDoStereo()
  15509. {
  15510. return true;
  15511. }
  15512. bool AiffAudioFormat::canDoMono()
  15513. {
  15514. return true;
  15515. }
  15516. #if JUCE_MAC
  15517. bool AiffAudioFormat::canHandleFile (const File& f)
  15518. {
  15519. if (AudioFormat::canHandleFile (f))
  15520. return true;
  15521. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15522. return type == 'AIFF' || type == 'AIFC'
  15523. || type == 'aiff' || type == 'aifc';
  15524. }
  15525. #endif
  15526. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15527. const bool deleteStreamIfOpeningFails)
  15528. {
  15529. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15530. if (w->sampleRate != 0)
  15531. return w.release();
  15532. if (! deleteStreamIfOpeningFails)
  15533. w->input = 0;
  15534. return 0;
  15535. }
  15536. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15537. double sampleRate,
  15538. unsigned int chans,
  15539. int bitsPerSample,
  15540. const StringPairArray& /*metadataValues*/,
  15541. int /*qualityOptionIndex*/)
  15542. {
  15543. if (getPossibleBitDepths().contains (bitsPerSample))
  15544. {
  15545. return new AiffAudioFormatWriter (out,
  15546. sampleRate,
  15547. chans,
  15548. bitsPerSample);
  15549. }
  15550. return 0;
  15551. }
  15552. END_JUCE_NAMESPACE
  15553. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15554. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15555. BEGIN_JUCE_NAMESPACE
  15556. #if JUCE_MAC && JUCE_USE_CDREADER
  15557. // Mac version doesn't need any native code because it's all done with files..
  15558. // Windows + Linux versions are in the platform-dependent code sections.
  15559. static void findCDs (Array<File>& cds)
  15560. {
  15561. File volumes ("/Volumes");
  15562. volumes.findChildFiles (cds, File::findDirectories, false);
  15563. for (int i = cds.size(); --i >= 0;)
  15564. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15565. cds.remove (i);
  15566. }
  15567. const StringArray AudioCDReader::getAvailableCDNames()
  15568. {
  15569. Array<File> cds;
  15570. findCDs (cds);
  15571. StringArray names;
  15572. for (int i = 0; i < cds.size(); ++i)
  15573. names.add (cds.getReference(i).getFileName());
  15574. return names;
  15575. }
  15576. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15577. {
  15578. Array<File> cds;
  15579. findCDs (cds);
  15580. if (cds[index] != File::nonexistent)
  15581. return new AudioCDReader (cds[index]);
  15582. else
  15583. return 0;
  15584. }
  15585. AudioCDReader::AudioCDReader (const File& volume)
  15586. : AudioFormatReader (0, "CD Audio"),
  15587. volumeDir (volume),
  15588. currentReaderTrack (-1),
  15589. reader (0)
  15590. {
  15591. sampleRate = 44100.0;
  15592. bitsPerSample = 16;
  15593. numChannels = 2;
  15594. usesFloatingPointData = false;
  15595. refreshTrackLengths();
  15596. }
  15597. AudioCDReader::~AudioCDReader()
  15598. {
  15599. }
  15600. static int getTrackNumber (const File& file)
  15601. {
  15602. return file.getFileName()
  15603. .initialSectionContainingOnly ("0123456789")
  15604. .getIntValue();
  15605. }
  15606. int AudioCDReader::compareElements (const File& first, const File& second)
  15607. {
  15608. const int firstTrack = getTrackNumber (first);
  15609. const int secondTrack = getTrackNumber (second);
  15610. jassert (firstTrack > 0 && secondTrack > 0);
  15611. return firstTrack - secondTrack;
  15612. }
  15613. void AudioCDReader::refreshTrackLengths()
  15614. {
  15615. tracks.clear();
  15616. trackStartSamples.clear();
  15617. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, "*.aiff");
  15618. tracks.sort (*this);
  15619. AiffAudioFormat format;
  15620. int sample = 0;
  15621. for (int i = 0; i < tracks.size(); ++i)
  15622. {
  15623. trackStartSamples.add (sample);
  15624. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15625. if (in != 0)
  15626. {
  15627. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15628. if (r != 0)
  15629. sample += (int) r->lengthInSamples;
  15630. }
  15631. }
  15632. trackStartSamples.add (sample);
  15633. lengthInSamples = sample;
  15634. }
  15635. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15636. int64 startSampleInFile, int numSamples)
  15637. {
  15638. while (numSamples > 0)
  15639. {
  15640. int track = -1;
  15641. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15642. {
  15643. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15644. {
  15645. track = i;
  15646. break;
  15647. }
  15648. }
  15649. if (track < 0)
  15650. return false;
  15651. if (track != currentReaderTrack)
  15652. {
  15653. reader = 0;
  15654. FileInputStream* const in = tracks [track].createInputStream();
  15655. if (in != 0)
  15656. {
  15657. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15658. AiffAudioFormat format;
  15659. reader = format.createReaderFor (bin, true);
  15660. if (reader == 0)
  15661. currentReaderTrack = -1;
  15662. else
  15663. currentReaderTrack = track;
  15664. }
  15665. }
  15666. if (reader == 0)
  15667. return false;
  15668. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15669. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15670. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15671. numSamples -= numAvailable;
  15672. startSampleInFile += numAvailable;
  15673. }
  15674. return true;
  15675. }
  15676. bool AudioCDReader::isCDStillPresent() const
  15677. {
  15678. return volumeDir.exists();
  15679. }
  15680. int AudioCDReader::getNumTracks() const
  15681. {
  15682. return tracks.size();
  15683. }
  15684. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15685. {
  15686. return trackStartSamples [trackNum];
  15687. }
  15688. bool AudioCDReader::isTrackAudio (int trackNum) const
  15689. {
  15690. return tracks [trackNum] != File::nonexistent;
  15691. }
  15692. void AudioCDReader::enableIndexScanning (bool b)
  15693. {
  15694. // any way to do this on a Mac??
  15695. }
  15696. int AudioCDReader::getLastIndex() const
  15697. {
  15698. return 0;
  15699. }
  15700. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15701. {
  15702. return Array <int>();
  15703. }
  15704. int AudioCDReader::getCDDBId()
  15705. {
  15706. return 0; //xxx
  15707. }
  15708. #endif
  15709. END_JUCE_NAMESPACE
  15710. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15711. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15712. BEGIN_JUCE_NAMESPACE
  15713. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15714. const String& formatName_)
  15715. : sampleRate (0),
  15716. bitsPerSample (0),
  15717. lengthInSamples (0),
  15718. numChannels (0),
  15719. usesFloatingPointData (false),
  15720. input (in),
  15721. formatName (formatName_)
  15722. {
  15723. }
  15724. AudioFormatReader::~AudioFormatReader()
  15725. {
  15726. delete input;
  15727. }
  15728. bool AudioFormatReader::read (int** destSamples,
  15729. int numDestChannels,
  15730. int64 startSampleInSource,
  15731. int numSamplesToRead,
  15732. const bool fillLeftoverChannelsWithCopies)
  15733. {
  15734. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15735. int startOffsetInDestBuffer = 0;
  15736. if (startSampleInSource < 0)
  15737. {
  15738. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15739. for (int i = numDestChannels; --i >= 0;)
  15740. if (destSamples[i] != 0)
  15741. zeromem (destSamples[i], sizeof (int) * silence);
  15742. startOffsetInDestBuffer += silence;
  15743. numSamplesToRead -= silence;
  15744. startSampleInSource = 0;
  15745. }
  15746. if (numSamplesToRead <= 0)
  15747. return true;
  15748. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15749. startSampleInSource, numSamplesToRead))
  15750. return false;
  15751. if (numDestChannels > (int) numChannels)
  15752. {
  15753. if (fillLeftoverChannelsWithCopies)
  15754. {
  15755. int* lastFullChannel = destSamples[0];
  15756. for (int i = numDestChannels; --i > 0;)
  15757. {
  15758. if (destSamples[i] != 0)
  15759. {
  15760. lastFullChannel = destSamples[i];
  15761. break;
  15762. }
  15763. }
  15764. if (lastFullChannel != 0)
  15765. for (int i = numChannels; i < numDestChannels; ++i)
  15766. if (destSamples[i] != 0)
  15767. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15768. }
  15769. else
  15770. {
  15771. for (int i = numChannels; i < numDestChannels; ++i)
  15772. if (destSamples[i] != 0)
  15773. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15774. }
  15775. }
  15776. return true;
  15777. }
  15778. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15779. {
  15780. float mn = buffer[0];
  15781. float mx = mn;
  15782. for (int i = 1; i < num; ++i)
  15783. {
  15784. const float s = buffer[i];
  15785. if (s > mx) mx = s;
  15786. if (s < mn) mn = s;
  15787. }
  15788. maxVal = mx;
  15789. minVal = mn;
  15790. }
  15791. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15792. int64 numSamples,
  15793. float& lowestLeft, float& highestLeft,
  15794. float& lowestRight, float& highestRight)
  15795. {
  15796. if (numSamples <= 0)
  15797. {
  15798. lowestLeft = 0;
  15799. lowestRight = 0;
  15800. highestLeft = 0;
  15801. highestRight = 0;
  15802. return;
  15803. }
  15804. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15805. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15806. int* tempBuffer[3];
  15807. tempBuffer[0] = (int*) tempSpace.getData();
  15808. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15809. tempBuffer[2] = 0;
  15810. if (usesFloatingPointData)
  15811. {
  15812. float lmin = 1.0e6f;
  15813. float lmax = -lmin;
  15814. float rmin = lmin;
  15815. float rmax = lmax;
  15816. while (numSamples > 0)
  15817. {
  15818. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15819. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15820. numSamples -= numToDo;
  15821. startSampleInFile += numToDo;
  15822. float bufmin, bufmax;
  15823. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15824. lmin = jmin (lmin, bufmin);
  15825. lmax = jmax (lmax, bufmax);
  15826. if (numChannels > 1)
  15827. {
  15828. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15829. rmin = jmin (rmin, bufmin);
  15830. rmax = jmax (rmax, bufmax);
  15831. }
  15832. }
  15833. if (numChannels <= 1)
  15834. {
  15835. rmax = lmax;
  15836. rmin = lmin;
  15837. }
  15838. lowestLeft = lmin;
  15839. highestLeft = lmax;
  15840. lowestRight = rmin;
  15841. highestRight = rmax;
  15842. }
  15843. else
  15844. {
  15845. int lmax = std::numeric_limits<int>::min();
  15846. int lmin = std::numeric_limits<int>::max();
  15847. int rmax = std::numeric_limits<int>::min();
  15848. int rmin = std::numeric_limits<int>::max();
  15849. while (numSamples > 0)
  15850. {
  15851. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15852. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15853. numSamples -= numToDo;
  15854. startSampleInFile += numToDo;
  15855. for (int j = numChannels; --j >= 0;)
  15856. {
  15857. int bufMax = std::numeric_limits<int>::min();
  15858. int bufMin = std::numeric_limits<int>::max();
  15859. const int* const b = tempBuffer[j];
  15860. for (int i = 0; i < numToDo; ++i)
  15861. {
  15862. const int samp = b[i];
  15863. if (samp < bufMin)
  15864. bufMin = samp;
  15865. if (samp > bufMax)
  15866. bufMax = samp;
  15867. }
  15868. if (j == 0)
  15869. {
  15870. lmax = jmax (lmax, bufMax);
  15871. lmin = jmin (lmin, bufMin);
  15872. }
  15873. else
  15874. {
  15875. rmax = jmax (rmax, bufMax);
  15876. rmin = jmin (rmin, bufMin);
  15877. }
  15878. }
  15879. }
  15880. if (numChannels <= 1)
  15881. {
  15882. rmax = lmax;
  15883. rmin = lmin;
  15884. }
  15885. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15886. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15887. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15888. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15889. }
  15890. }
  15891. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15892. int64 numSamplesToSearch,
  15893. const double magnitudeRangeMinimum,
  15894. const double magnitudeRangeMaximum,
  15895. const int minimumConsecutiveSamples)
  15896. {
  15897. if (numSamplesToSearch == 0)
  15898. return -1;
  15899. const int bufferSize = 4096;
  15900. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15901. int* tempBuffer[3];
  15902. tempBuffer[0] = (int*) tempSpace.getData();
  15903. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15904. tempBuffer[2] = 0;
  15905. int consecutive = 0;
  15906. int64 firstMatchPos = -1;
  15907. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  15908. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  15909. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  15910. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  15911. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  15912. while (numSamplesToSearch != 0)
  15913. {
  15914. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  15915. int64 bufferStart = startSample;
  15916. if (numSamplesToSearch < 0)
  15917. bufferStart -= numThisTime;
  15918. if (bufferStart >= (int) lengthInSamples)
  15919. break;
  15920. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  15921. int num = numThisTime;
  15922. while (--num >= 0)
  15923. {
  15924. if (numSamplesToSearch < 0)
  15925. --startSample;
  15926. bool matches = false;
  15927. const int index = (int) (startSample - bufferStart);
  15928. if (usesFloatingPointData)
  15929. {
  15930. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  15931. if (sample1 >= magnitudeRangeMinimum
  15932. && sample1 <= magnitudeRangeMaximum)
  15933. {
  15934. matches = true;
  15935. }
  15936. else if (numChannels > 1)
  15937. {
  15938. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  15939. matches = (sample2 >= magnitudeRangeMinimum
  15940. && sample2 <= magnitudeRangeMaximum);
  15941. }
  15942. }
  15943. else
  15944. {
  15945. const int sample1 = abs (tempBuffer[0] [index]);
  15946. if (sample1 >= intMagnitudeRangeMinimum
  15947. && sample1 <= intMagnitudeRangeMaximum)
  15948. {
  15949. matches = true;
  15950. }
  15951. else if (numChannels > 1)
  15952. {
  15953. const int sample2 = abs (tempBuffer[1][index]);
  15954. matches = (sample2 >= intMagnitudeRangeMinimum
  15955. && sample2 <= intMagnitudeRangeMaximum);
  15956. }
  15957. }
  15958. if (matches)
  15959. {
  15960. if (firstMatchPos < 0)
  15961. firstMatchPos = startSample;
  15962. if (++consecutive >= minimumConsecutiveSamples)
  15963. {
  15964. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  15965. return -1;
  15966. return firstMatchPos;
  15967. }
  15968. }
  15969. else
  15970. {
  15971. consecutive = 0;
  15972. firstMatchPos = -1;
  15973. }
  15974. if (numSamplesToSearch > 0)
  15975. ++startSample;
  15976. }
  15977. if (numSamplesToSearch > 0)
  15978. numSamplesToSearch -= numThisTime;
  15979. else
  15980. numSamplesToSearch += numThisTime;
  15981. }
  15982. return -1;
  15983. }
  15984. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  15985. const String& formatName_,
  15986. const double rate,
  15987. const unsigned int numChannels_,
  15988. const unsigned int bitsPerSample_)
  15989. : sampleRate (rate),
  15990. numChannels (numChannels_),
  15991. bitsPerSample (bitsPerSample_),
  15992. usesFloatingPointData (false),
  15993. output (out),
  15994. formatName (formatName_)
  15995. {
  15996. }
  15997. AudioFormatWriter::~AudioFormatWriter()
  15998. {
  15999. delete output;
  16000. }
  16001. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16002. int64 startSample,
  16003. int64 numSamplesToRead)
  16004. {
  16005. const int bufferSize = 16384;
  16006. const int maxChans = 128;
  16007. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16008. int* buffers [maxChans];
  16009. for (int i = maxChans; --i >= 0;)
  16010. buffers[i] = 0;
  16011. if (numSamplesToRead < 0)
  16012. numSamplesToRead = reader.lengthInSamples;
  16013. while (numSamplesToRead > 0)
  16014. {
  16015. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16016. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16017. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16018. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16019. return false;
  16020. if (reader.usesFloatingPointData != isFloatingPoint())
  16021. {
  16022. int** bufferChan = buffers;
  16023. while (*bufferChan != 0)
  16024. {
  16025. int* b = *bufferChan++;
  16026. if (isFloatingPoint())
  16027. {
  16028. // int -> float
  16029. const double factor = 1.0 / std::numeric_limits<int>::max();
  16030. for (int i = 0; i < numToDo; ++i)
  16031. ((float*) b)[i] = (float) (factor * b[i]);
  16032. }
  16033. else
  16034. {
  16035. // float -> int
  16036. for (int i = 0; i < numToDo; ++i)
  16037. {
  16038. const double samp = *(const float*) b;
  16039. if (samp <= -1.0)
  16040. *b++ = std::numeric_limits<int>::min();
  16041. else if (samp >= 1.0)
  16042. *b++ = std::numeric_limits<int>::max();
  16043. else
  16044. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16045. }
  16046. }
  16047. }
  16048. }
  16049. if (! write ((const int**) buffers, numToDo))
  16050. return false;
  16051. numSamplesToRead -= numToDo;
  16052. startSample += numToDo;
  16053. }
  16054. return true;
  16055. }
  16056. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16057. int numSamplesToRead,
  16058. const int samplesPerBlock)
  16059. {
  16060. const int maxChans = 128;
  16061. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16062. int* buffers [maxChans];
  16063. while (numSamplesToRead > 0)
  16064. {
  16065. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16066. AudioSourceChannelInfo info;
  16067. info.buffer = &tempBuffer;
  16068. info.startSample = 0;
  16069. info.numSamples = numToDo;
  16070. info.clearActiveBufferRegion();
  16071. source.getNextAudioBlock (info);
  16072. int i;
  16073. for (i = maxChans; --i >= 0;)
  16074. buffers[i] = 0;
  16075. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16076. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16077. if (! isFloatingPoint())
  16078. {
  16079. int** bufferChan = buffers;
  16080. while (*bufferChan != 0)
  16081. {
  16082. int* b = *bufferChan++;
  16083. // float -> int
  16084. for (int j = numToDo; --j >= 0;)
  16085. {
  16086. const double samp = *(const float*) b;
  16087. if (samp <= -1.0)
  16088. *b++ = std::numeric_limits<int>::min();
  16089. else if (samp >= 1.0)
  16090. *b++ = std::numeric_limits<int>::max();
  16091. else
  16092. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16093. }
  16094. }
  16095. }
  16096. if (! write ((const int**) buffers, numToDo))
  16097. return false;
  16098. numSamplesToRead -= numToDo;
  16099. }
  16100. return true;
  16101. }
  16102. AudioFormat::AudioFormat (const String& name,
  16103. const juce_wchar** const extensions)
  16104. : formatName (name),
  16105. fileExtensions (extensions)
  16106. {
  16107. }
  16108. AudioFormat::~AudioFormat()
  16109. {
  16110. }
  16111. const String& AudioFormat::getFormatName() const
  16112. {
  16113. return formatName;
  16114. }
  16115. const StringArray& AudioFormat::getFileExtensions() const
  16116. {
  16117. return fileExtensions;
  16118. }
  16119. bool AudioFormat::canHandleFile (const File& f)
  16120. {
  16121. for (int i = 0; i < fileExtensions.size(); ++i)
  16122. if (f.hasFileExtension (fileExtensions[i]))
  16123. return true;
  16124. return false;
  16125. }
  16126. bool AudioFormat::isCompressed()
  16127. {
  16128. return false;
  16129. }
  16130. const StringArray AudioFormat::getQualityOptions()
  16131. {
  16132. return StringArray();
  16133. }
  16134. END_JUCE_NAMESPACE
  16135. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16136. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16137. BEGIN_JUCE_NAMESPACE
  16138. AudioFormatManager::AudioFormatManager()
  16139. : defaultFormatIndex (0)
  16140. {
  16141. }
  16142. AudioFormatManager::~AudioFormatManager()
  16143. {
  16144. clearFormats();
  16145. clearSingletonInstance();
  16146. }
  16147. juce_ImplementSingleton (AudioFormatManager);
  16148. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16149. const bool makeThisTheDefaultFormat)
  16150. {
  16151. jassert (newFormat != 0);
  16152. if (newFormat != 0)
  16153. {
  16154. #ifdef JUCE_DEBUG
  16155. for (int i = getNumKnownFormats(); --i >= 0;)
  16156. {
  16157. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16158. {
  16159. jassertfalse // trying to add the same format twice!
  16160. }
  16161. }
  16162. #endif
  16163. if (makeThisTheDefaultFormat)
  16164. defaultFormatIndex = knownFormats.size();
  16165. knownFormats.add (newFormat);
  16166. }
  16167. }
  16168. void AudioFormatManager::registerBasicFormats()
  16169. {
  16170. #if JUCE_MAC
  16171. registerFormat (new AiffAudioFormat(), true);
  16172. registerFormat (new WavAudioFormat(), false);
  16173. #else
  16174. registerFormat (new WavAudioFormat(), true);
  16175. registerFormat (new AiffAudioFormat(), false);
  16176. #endif
  16177. #if JUCE_USE_FLAC
  16178. registerFormat (new FlacAudioFormat(), false);
  16179. #endif
  16180. #if JUCE_USE_OGGVORBIS
  16181. registerFormat (new OggVorbisAudioFormat(), false);
  16182. #endif
  16183. }
  16184. void AudioFormatManager::clearFormats()
  16185. {
  16186. for (int i = getNumKnownFormats(); --i >= 0;)
  16187. delete getKnownFormat(i);
  16188. knownFormats.clear();
  16189. defaultFormatIndex = 0;
  16190. }
  16191. int AudioFormatManager::getNumKnownFormats() const
  16192. {
  16193. return knownFormats.size();
  16194. }
  16195. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16196. {
  16197. return (AudioFormat*) knownFormats [index];
  16198. }
  16199. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16200. {
  16201. return getKnownFormat (defaultFormatIndex);
  16202. }
  16203. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16204. {
  16205. String e (fileExtension);
  16206. if (! e.startsWithChar ('.'))
  16207. e = "." + e;
  16208. for (int i = 0; i < getNumKnownFormats(); ++i)
  16209. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16210. return getKnownFormat(i);
  16211. return 0;
  16212. }
  16213. const String AudioFormatManager::getWildcardForAllFormats() const
  16214. {
  16215. StringArray allExtensions;
  16216. int i;
  16217. for (i = 0; i < getNumKnownFormats(); ++i)
  16218. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16219. allExtensions.trim();
  16220. allExtensions.removeEmptyStrings();
  16221. String s;
  16222. for (i = 0; i < allExtensions.size(); ++i)
  16223. {
  16224. s << '*';
  16225. if (! allExtensions[i].startsWithChar ('.'))
  16226. s << '.';
  16227. s << allExtensions[i];
  16228. if (i < allExtensions.size() - 1)
  16229. s << ';';
  16230. }
  16231. return s;
  16232. }
  16233. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16234. {
  16235. // you need to actually register some formats before the manager can
  16236. // use them to open a file!
  16237. jassert (knownFormats.size() > 0);
  16238. for (int i = 0; i < getNumKnownFormats(); ++i)
  16239. {
  16240. AudioFormat* const af = getKnownFormat(i);
  16241. if (af->canHandleFile (file))
  16242. {
  16243. InputStream* const in = file.createInputStream();
  16244. if (in != 0)
  16245. {
  16246. AudioFormatReader* const r = af->createReaderFor (in, true);
  16247. if (r != 0)
  16248. return r;
  16249. }
  16250. }
  16251. }
  16252. return 0;
  16253. }
  16254. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16255. {
  16256. // you need to actually register some formats before the manager can
  16257. // use them to open a file!
  16258. jassert (knownFormats.size() > 0);
  16259. ScopedPointer <InputStream> in (audioFileStream);
  16260. if (in != 0)
  16261. {
  16262. const int64 originalStreamPos = in->getPosition();
  16263. for (int i = 0; i < getNumKnownFormats(); ++i)
  16264. {
  16265. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16266. if (r != 0)
  16267. {
  16268. in.release();
  16269. return r;
  16270. }
  16271. in->setPosition (originalStreamPos);
  16272. // the stream that is passed-in must be capable of being repositioned so
  16273. // that all the formats can have a go at opening it.
  16274. jassert (in->getPosition() == originalStreamPos);
  16275. }
  16276. }
  16277. return 0;
  16278. }
  16279. END_JUCE_NAMESPACE
  16280. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16281. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16282. BEGIN_JUCE_NAMESPACE
  16283. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16284. const int64 startSample_,
  16285. const int64 length_,
  16286. const bool deleteSourceWhenDeleted_)
  16287. : AudioFormatReader (0, source_->getFormatName()),
  16288. source (source_),
  16289. startSample (startSample_),
  16290. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16291. {
  16292. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16293. sampleRate = source->sampleRate;
  16294. bitsPerSample = source->bitsPerSample;
  16295. lengthInSamples = length;
  16296. numChannels = source->numChannels;
  16297. usesFloatingPointData = source->usesFloatingPointData;
  16298. }
  16299. AudioSubsectionReader::~AudioSubsectionReader()
  16300. {
  16301. if (deleteSourceWhenDeleted)
  16302. delete source;
  16303. }
  16304. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16305. int64 startSampleInFile, int numSamples)
  16306. {
  16307. if (startSampleInFile + numSamples > length)
  16308. {
  16309. for (int i = numDestChannels; --i >= 0;)
  16310. if (destSamples[i] != 0)
  16311. zeromem (destSamples[i], sizeof (int) * numSamples);
  16312. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16313. if (numSamples <= 0)
  16314. return true;
  16315. }
  16316. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16317. startSampleInFile + startSample, numSamples);
  16318. }
  16319. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16320. int64 numSamples,
  16321. float& lowestLeft,
  16322. float& highestLeft,
  16323. float& lowestRight,
  16324. float& highestRight)
  16325. {
  16326. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16327. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16328. source->readMaxLevels (startSampleInFile + startSample,
  16329. numSamples,
  16330. lowestLeft,
  16331. highestLeft,
  16332. lowestRight,
  16333. highestRight);
  16334. }
  16335. END_JUCE_NAMESPACE
  16336. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16337. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16338. BEGIN_JUCE_NAMESPACE
  16339. const int timeBeforeDeletingReader = 2000;
  16340. struct AudioThumbnailDataFormat
  16341. {
  16342. char thumbnailMagic[4];
  16343. int samplesPerThumbSample;
  16344. int64 totalSamples; // source samples
  16345. int64 numFinishedSamples; // source samples
  16346. int numThumbnailSamples;
  16347. int numChannels;
  16348. int sampleRate;
  16349. char future[16];
  16350. char data[1];
  16351. void swapEndiannessIfNeeded() throw()
  16352. {
  16353. #if JUCE_BIG_ENDIAN
  16354. flip (samplesPerThumbSample);
  16355. flip (totalSamples);
  16356. flip (numFinishedSamples);
  16357. flip (numThumbnailSamples);
  16358. flip (numChannels);
  16359. flip (sampleRate);
  16360. #endif
  16361. }
  16362. private:
  16363. #if JUCE_BIG_ENDIAN
  16364. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16365. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16366. #endif
  16367. };
  16368. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16369. AudioFormatManager& formatManagerToUse_,
  16370. AudioThumbnailCache& cacheToUse)
  16371. : formatManagerToUse (formatManagerToUse_),
  16372. cache (cacheToUse),
  16373. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16374. {
  16375. clear();
  16376. }
  16377. AudioThumbnail::~AudioThumbnail()
  16378. {
  16379. cache.removeThumbnail (this);
  16380. const ScopedLock sl (readerLock);
  16381. reader = 0;
  16382. }
  16383. void AudioThumbnail::setSource (InputSource* const newSource)
  16384. {
  16385. cache.removeThumbnail (this);
  16386. timerCallback(); // stops the timer and deletes the reader
  16387. source = newSource;
  16388. clear();
  16389. if (newSource != 0
  16390. && ! (cache.loadThumb (*this, newSource->hashCode())
  16391. && isFullyLoaded()))
  16392. {
  16393. {
  16394. const ScopedLock sl (readerLock);
  16395. reader = createReader();
  16396. }
  16397. if (reader != 0)
  16398. {
  16399. initialiseFromAudioFile (*reader);
  16400. cache.addThumbnail (this);
  16401. }
  16402. }
  16403. sendChangeMessage (this);
  16404. }
  16405. bool AudioThumbnail::useTimeSlice()
  16406. {
  16407. const ScopedLock sl (readerLock);
  16408. if (isFullyLoaded())
  16409. {
  16410. if (reader != 0)
  16411. startTimer (timeBeforeDeletingReader);
  16412. cache.removeThumbnail (this);
  16413. return false;
  16414. }
  16415. if (reader == 0)
  16416. reader = createReader();
  16417. if (reader != 0)
  16418. {
  16419. readNextBlockFromAudioFile (*reader);
  16420. stopTimer();
  16421. sendChangeMessage (this);
  16422. const bool justFinished = isFullyLoaded();
  16423. if (justFinished)
  16424. cache.storeThumb (*this, source->hashCode());
  16425. return ! justFinished;
  16426. }
  16427. return false;
  16428. }
  16429. AudioFormatReader* AudioThumbnail::createReader() const
  16430. {
  16431. if (source != 0)
  16432. {
  16433. InputStream* const audioFileStream = source->createInputStream();
  16434. if (audioFileStream != 0)
  16435. return formatManagerToUse.createReaderFor (audioFileStream);
  16436. }
  16437. return 0;
  16438. }
  16439. void AudioThumbnail::timerCallback()
  16440. {
  16441. stopTimer();
  16442. const ScopedLock sl (readerLock);
  16443. reader = 0;
  16444. }
  16445. void AudioThumbnail::clear()
  16446. {
  16447. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16448. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16449. d->thumbnailMagic[0] = 'j';
  16450. d->thumbnailMagic[1] = 'a';
  16451. d->thumbnailMagic[2] = 't';
  16452. d->thumbnailMagic[3] = 'm';
  16453. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16454. d->totalSamples = 0;
  16455. d->numFinishedSamples = 0;
  16456. d->numThumbnailSamples = 0;
  16457. d->numChannels = 0;
  16458. d->sampleRate = 0;
  16459. numSamplesCached = 0;
  16460. cacheNeedsRefilling = true;
  16461. }
  16462. void AudioThumbnail::loadFrom (InputStream& input)
  16463. {
  16464. const ScopedLock sl (readerLock);
  16465. data.setSize (0);
  16466. input.readIntoMemoryBlock (data);
  16467. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16468. d->swapEndiannessIfNeeded();
  16469. if (! (d->thumbnailMagic[0] == 'j'
  16470. && d->thumbnailMagic[1] == 'a'
  16471. && d->thumbnailMagic[2] == 't'
  16472. && d->thumbnailMagic[3] == 'm'))
  16473. {
  16474. clear();
  16475. }
  16476. numSamplesCached = 0;
  16477. cacheNeedsRefilling = true;
  16478. }
  16479. void AudioThumbnail::saveTo (OutputStream& output) const
  16480. {
  16481. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16482. d->swapEndiannessIfNeeded();
  16483. output.write (data.getData(), (int) data.getSize());
  16484. d->swapEndiannessIfNeeded();
  16485. }
  16486. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16487. {
  16488. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16489. d->totalSamples = fileReader.lengthInSamples;
  16490. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16491. d->numFinishedSamples = 0;
  16492. d->sampleRate = roundToInt (fileReader.sampleRate);
  16493. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16494. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16495. d = (AudioThumbnailDataFormat*) data.getData();
  16496. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16497. return d->totalSamples > 0;
  16498. }
  16499. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16500. {
  16501. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16502. if (d->numFinishedSamples < d->totalSamples)
  16503. {
  16504. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16505. generateSection (fileReader,
  16506. d->numFinishedSamples,
  16507. numToDo);
  16508. d->numFinishedSamples += numToDo;
  16509. }
  16510. cacheNeedsRefilling = true;
  16511. return (d->numFinishedSamples < d->totalSamples);
  16512. }
  16513. int AudioThumbnail::getNumChannels() const throw()
  16514. {
  16515. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16516. jassert (d != 0);
  16517. return d->numChannels;
  16518. }
  16519. double AudioThumbnail::getTotalLength() const throw()
  16520. {
  16521. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16522. jassert (d != 0);
  16523. if (d->sampleRate > 0)
  16524. return d->totalSamples / (double)d->sampleRate;
  16525. else
  16526. return 0.0;
  16527. }
  16528. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16529. int64 startSample,
  16530. int numSamples)
  16531. {
  16532. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16533. jassert (d != 0);
  16534. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16535. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16536. char* l = getChannelData (0);
  16537. char* r = getChannelData (1);
  16538. for (int i = firstDataPos; i < lastDataPos; ++i)
  16539. {
  16540. const int sourceStart = i * d->samplesPerThumbSample;
  16541. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16542. float lowestLeft, highestLeft, lowestRight, highestRight;
  16543. fileReader.readMaxLevels (sourceStart,
  16544. sourceEnd - sourceStart,
  16545. lowestLeft,
  16546. highestLeft,
  16547. lowestRight,
  16548. highestRight);
  16549. int n = i * 2;
  16550. if (r != 0)
  16551. {
  16552. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16553. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16554. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16555. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16556. }
  16557. else
  16558. {
  16559. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16560. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16561. }
  16562. }
  16563. }
  16564. char* AudioThumbnail::getChannelData (int channel) const
  16565. {
  16566. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16567. jassert (d != 0);
  16568. if (channel >= 0 && channel < d->numChannels)
  16569. return d->data + (channel * 2 * d->numThumbnailSamples);
  16570. return 0;
  16571. }
  16572. bool AudioThumbnail::isFullyLoaded() const throw()
  16573. {
  16574. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16575. jassert (d != 0);
  16576. return d->numFinishedSamples >= d->totalSamples;
  16577. }
  16578. void AudioThumbnail::refillCache (const int numSamples,
  16579. double startTime,
  16580. const double timePerPixel)
  16581. {
  16582. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16583. jassert (d != 0);
  16584. if (numSamples <= 0
  16585. || timePerPixel <= 0.0
  16586. || d->sampleRate <= 0)
  16587. {
  16588. numSamplesCached = 0;
  16589. cacheNeedsRefilling = true;
  16590. return;
  16591. }
  16592. if (numSamples == numSamplesCached
  16593. && numChannelsCached == d->numChannels
  16594. && startTime == cachedStart
  16595. && timePerPixel == cachedTimePerPixel
  16596. && ! cacheNeedsRefilling)
  16597. {
  16598. return;
  16599. }
  16600. numSamplesCached = numSamples;
  16601. numChannelsCached = d->numChannels;
  16602. cachedStart = startTime;
  16603. cachedTimePerPixel = timePerPixel;
  16604. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16605. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16606. const ScopedLock sl (readerLock);
  16607. cacheNeedsRefilling = false;
  16608. if (needExtraDetail && reader == 0)
  16609. reader = createReader();
  16610. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16611. {
  16612. startTimer (timeBeforeDeletingReader);
  16613. char* cacheData = static_cast <char*> (cachedLevels.getData());
  16614. int sample = roundToInt (startTime * d->sampleRate);
  16615. for (int i = numSamples; --i >= 0;)
  16616. {
  16617. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16618. if (sample >= 0)
  16619. {
  16620. if (sample >= reader->lengthInSamples)
  16621. break;
  16622. float lmin, lmax, rmin, rmax;
  16623. reader->readMaxLevels (sample,
  16624. jmax (1, nextSample - sample),
  16625. lmin, lmax, rmin, rmax);
  16626. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16627. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16628. if (numChannelsCached > 1)
  16629. {
  16630. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16631. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16632. }
  16633. cacheData += 2 * numChannelsCached;
  16634. }
  16635. startTime += timePerPixel;
  16636. sample = nextSample;
  16637. }
  16638. }
  16639. else
  16640. {
  16641. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16642. {
  16643. char* const channelData = getChannelData (channelNum);
  16644. char* cacheData = static_cast <char*> (cachedLevels.getData()) + channelNum * 2;
  16645. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16646. startTime = cachedStart;
  16647. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16648. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16649. for (int i = numSamples; --i >= 0;)
  16650. {
  16651. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16652. if (sample >= 0 && channelData != 0)
  16653. {
  16654. char mx = -128;
  16655. char mn = 127;
  16656. while (sample <= nextSample)
  16657. {
  16658. if (sample >= numFinished)
  16659. break;
  16660. const int n = sample << 1;
  16661. const char sampMin = channelData [n];
  16662. const char sampMax = channelData [n + 1];
  16663. if (sampMin < mn)
  16664. mn = sampMin;
  16665. if (sampMax > mx)
  16666. mx = sampMax;
  16667. ++sample;
  16668. }
  16669. if (mn <= mx)
  16670. {
  16671. cacheData[0] = mn;
  16672. cacheData[1] = mx;
  16673. }
  16674. else
  16675. {
  16676. cacheData[0] = 1;
  16677. cacheData[1] = 0;
  16678. }
  16679. }
  16680. else
  16681. {
  16682. cacheData[0] = 1;
  16683. cacheData[1] = 0;
  16684. }
  16685. cacheData += numChannelsCached * 2;
  16686. startTime += timePerPixel;
  16687. sample = nextSample;
  16688. }
  16689. }
  16690. }
  16691. }
  16692. void AudioThumbnail::drawChannel (Graphics& g,
  16693. int x, int y, int w, int h,
  16694. double startTime,
  16695. double endTime,
  16696. int channelNum,
  16697. const float verticalZoomFactor)
  16698. {
  16699. refillCache (w, startTime, (endTime - startTime) / w);
  16700. if (numSamplesCached >= w
  16701. && channelNum >= 0
  16702. && channelNum < numChannelsCached)
  16703. {
  16704. const float topY = (float) y;
  16705. const float bottomY = topY + h;
  16706. const float midY = topY + h * 0.5f;
  16707. const float vscale = verticalZoomFactor * h / 256.0f;
  16708. const Rectangle<int> clip (g.getClipBounds());
  16709. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16710. w -= skipLeft;
  16711. x += skipLeft;
  16712. const char* cacheData = static_cast <const char*> (cachedLevels.getData())
  16713. + (channelNum << 1)
  16714. + skipLeft * (numChannelsCached << 1);
  16715. while (--w >= 0)
  16716. {
  16717. const char mn = cacheData[0];
  16718. const char mx = cacheData[1];
  16719. cacheData += numChannelsCached << 1;
  16720. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16721. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16722. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16723. ++x;
  16724. if (x >= clip.getRight())
  16725. break;
  16726. }
  16727. }
  16728. }
  16729. END_JUCE_NAMESPACE
  16730. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16731. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16732. BEGIN_JUCE_NAMESPACE
  16733. struct ThumbnailCacheEntry
  16734. {
  16735. int64 hash;
  16736. uint32 lastUsed;
  16737. MemoryBlock data;
  16738. juce_UseDebuggingNewOperator
  16739. };
  16740. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16741. : TimeSliceThread ("thumb cache"),
  16742. maxNumThumbsToStore (maxNumThumbsToStore_)
  16743. {
  16744. startThread (2);
  16745. }
  16746. AudioThumbnailCache::~AudioThumbnailCache()
  16747. {
  16748. }
  16749. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16750. {
  16751. for (int i = thumbs.size(); --i >= 0;)
  16752. {
  16753. if (thumbs[i]->hash == hashCode)
  16754. {
  16755. MemoryInputStream in (thumbs[i]->data, false);
  16756. thumb.loadFrom (in);
  16757. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16758. return true;
  16759. }
  16760. }
  16761. return false;
  16762. }
  16763. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16764. const int64 hashCode)
  16765. {
  16766. MemoryOutputStream out;
  16767. thumb.saveTo (out);
  16768. ThumbnailCacheEntry* te = 0;
  16769. for (int i = thumbs.size(); --i >= 0;)
  16770. {
  16771. if (thumbs[i]->hash == hashCode)
  16772. {
  16773. te = thumbs[i];
  16774. break;
  16775. }
  16776. }
  16777. if (te == 0)
  16778. {
  16779. te = new ThumbnailCacheEntry();
  16780. te->hash = hashCode;
  16781. if (thumbs.size() < maxNumThumbsToStore)
  16782. {
  16783. thumbs.add (te);
  16784. }
  16785. else
  16786. {
  16787. int oldest = 0;
  16788. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16789. int i;
  16790. for (i = thumbs.size(); --i >= 0;)
  16791. if (thumbs[i]->lastUsed < oldestTime)
  16792. oldest = i;
  16793. thumbs.set (i, te);
  16794. }
  16795. }
  16796. te->lastUsed = Time::getMillisecondCounter();
  16797. te->data.setSize (0);
  16798. te->data.append (out.getData(), out.getDataSize());
  16799. }
  16800. void AudioThumbnailCache::clear()
  16801. {
  16802. thumbs.clear();
  16803. }
  16804. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16805. {
  16806. addTimeSliceClient (thumb);
  16807. }
  16808. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16809. {
  16810. removeTimeSliceClient (thumb);
  16811. }
  16812. END_JUCE_NAMESPACE
  16813. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16814. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16815. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16816. #if ! JUCE_WINDOWS
  16817. #include <QuickTime/Movies.h>
  16818. #include <QuickTime/QTML.h>
  16819. #include <QuickTime/QuickTimeComponents.h>
  16820. #include <QuickTime/MediaHandlers.h>
  16821. #include <QuickTime/ImageCodec.h>
  16822. #else
  16823. #if JUCE_MSVC
  16824. #pragma warning (push)
  16825. #pragma warning (disable : 4100)
  16826. #endif
  16827. #include <Movies.h>
  16828. #include <QTML.h>
  16829. #include <QuickTimeComponents.h>
  16830. #include <MediaHandlers.h>
  16831. #include <ImageCodec.h>
  16832. #if JUCE_MSVC
  16833. #pragma warning (pop)
  16834. #endif
  16835. #endif
  16836. BEGIN_JUCE_NAMESPACE
  16837. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16838. static const char* const quickTimeFormatName = "QuickTime file";
  16839. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16840. class QTAudioReader : public AudioFormatReader
  16841. {
  16842. public:
  16843. QTAudioReader (InputStream* const input_, const int trackNum_)
  16844. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16845. ok (false),
  16846. movie (0),
  16847. trackNum (trackNum_),
  16848. lastSampleRead (0),
  16849. lastThreadId (0),
  16850. extractor (0),
  16851. dataHandle (0)
  16852. {
  16853. bufferList.calloc (256, 1);
  16854. #ifdef WIN32
  16855. if (InitializeQTML (0) != noErr)
  16856. return;
  16857. #endif
  16858. if (EnterMovies() != noErr)
  16859. return;
  16860. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16861. if (! opened)
  16862. return;
  16863. {
  16864. const int numTracks = GetMovieTrackCount (movie);
  16865. int trackCount = 0;
  16866. for (int i = 1; i <= numTracks; ++i)
  16867. {
  16868. track = GetMovieIndTrack (movie, i);
  16869. media = GetTrackMedia (track);
  16870. OSType mediaType;
  16871. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16872. if (mediaType == SoundMediaType
  16873. && trackCount++ == trackNum_)
  16874. {
  16875. ok = true;
  16876. break;
  16877. }
  16878. }
  16879. }
  16880. if (! ok)
  16881. return;
  16882. ok = false;
  16883. lengthInSamples = GetMediaDecodeDuration (media);
  16884. usesFloatingPointData = false;
  16885. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16886. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16887. / GetMediaTimeScale (media);
  16888. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16889. unsigned long output_layout_size;
  16890. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16891. kQTPropertyClass_MovieAudioExtraction_Audio,
  16892. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16893. 0, &output_layout_size, 0);
  16894. if (err != noErr)
  16895. return;
  16896. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  16897. qt_audio_channel_layout.calloc (output_layout_size, 1);
  16898. err = MovieAudioExtractionGetProperty (extractor,
  16899. kQTPropertyClass_MovieAudioExtraction_Audio,
  16900. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16901. output_layout_size, qt_audio_channel_layout, 0);
  16902. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  16903. err = MovieAudioExtractionSetProperty (extractor,
  16904. kQTPropertyClass_MovieAudioExtraction_Audio,
  16905. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16906. output_layout_size,
  16907. qt_audio_channel_layout);
  16908. err = MovieAudioExtractionGetProperty (extractor,
  16909. kQTPropertyClass_MovieAudioExtraction_Audio,
  16910. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16911. sizeof (inputStreamDesc),
  16912. &inputStreamDesc, 0);
  16913. if (err != noErr)
  16914. return;
  16915. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  16916. | kAudioFormatFlagIsPacked
  16917. | kAudioFormatFlagsNativeEndian;
  16918. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  16919. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  16920. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  16921. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  16922. err = MovieAudioExtractionSetProperty (extractor,
  16923. kQTPropertyClass_MovieAudioExtraction_Audio,
  16924. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16925. sizeof (inputStreamDesc),
  16926. &inputStreamDesc);
  16927. if (err != noErr)
  16928. return;
  16929. Boolean allChannelsDiscrete = false;
  16930. err = MovieAudioExtractionSetProperty (extractor,
  16931. kQTPropertyClass_MovieAudioExtraction_Movie,
  16932. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  16933. sizeof (allChannelsDiscrete),
  16934. &allChannelsDiscrete);
  16935. if (err != noErr)
  16936. return;
  16937. bufferList->mNumberBuffers = 1;
  16938. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  16939. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  16940. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  16941. sampleRate = inputStreamDesc.mSampleRate;
  16942. bitsPerSample = 16;
  16943. numChannels = inputStreamDesc.mChannelsPerFrame;
  16944. detachThread();
  16945. ok = true;
  16946. }
  16947. ~QTAudioReader()
  16948. {
  16949. if (dataHandle != 0)
  16950. DisposeHandle (dataHandle);
  16951. if (extractor != 0)
  16952. {
  16953. MovieAudioExtractionEnd (extractor);
  16954. extractor = 0;
  16955. }
  16956. checkThreadIsAttached();
  16957. DisposeMovie (movie);
  16958. juce_free (bufferList->mBuffers[0].mData);
  16959. #if JUCE_MAC
  16960. ExitMoviesOnThread ();
  16961. #endif
  16962. }
  16963. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16964. int64 startSampleInFile, int numSamples)
  16965. {
  16966. checkThreadIsAttached();
  16967. while (numSamples > 0)
  16968. {
  16969. if (! loadFrame ((int) startSampleInFile))
  16970. return false;
  16971. const int numToDo = jmin (numSamples, samplesPerFrame);
  16972. for (int j = numDestChannels; --j >= 0;)
  16973. {
  16974. if (destSamples[j] != 0)
  16975. {
  16976. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  16977. for (int i = 0; i < numToDo; ++i)
  16978. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  16979. }
  16980. }
  16981. startOffsetInDestBuffer += numToDo;
  16982. startSampleInFile += numToDo;
  16983. numSamples -= numToDo;
  16984. }
  16985. detachThread();
  16986. return true;
  16987. }
  16988. bool loadFrame (const int sampleNum)
  16989. {
  16990. if (lastSampleRead != sampleNum)
  16991. {
  16992. TimeRecord time;
  16993. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  16994. time.base = 0;
  16995. time.value.hi = 0;
  16996. time.value.lo = (UInt32) sampleNum;
  16997. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  16998. kQTPropertyClass_MovieAudioExtraction_Movie,
  16999. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17000. sizeof (time), &time);
  17001. if (err != noErr)
  17002. return false;
  17003. }
  17004. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17005. UInt32 outFlags = 0;
  17006. UInt32 actualNumSamples = samplesPerFrame;
  17007. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17008. bufferList, &outFlags);
  17009. lastSampleRead = sampleNum + samplesPerFrame;
  17010. return err == noErr;
  17011. }
  17012. juce_UseDebuggingNewOperator
  17013. bool ok;
  17014. private:
  17015. Movie movie;
  17016. Media media;
  17017. Track track;
  17018. const int trackNum;
  17019. double trackUnitsPerFrame;
  17020. int samplesPerFrame;
  17021. int lastSampleRead;
  17022. Thread::ThreadID lastThreadId;
  17023. MovieAudioExtractionRef extractor;
  17024. AudioStreamBasicDescription inputStreamDesc;
  17025. HeapBlock <AudioBufferList> bufferList;
  17026. Handle dataHandle;
  17027. void checkThreadIsAttached()
  17028. {
  17029. #if JUCE_MAC
  17030. if (Thread::getCurrentThreadId() != lastThreadId)
  17031. EnterMoviesOnThread (0);
  17032. AttachMovieToCurrentThread (movie);
  17033. #endif
  17034. }
  17035. void detachThread()
  17036. {
  17037. #if JUCE_MAC
  17038. DetachMovieFromCurrentThread (movie);
  17039. #endif
  17040. }
  17041. QTAudioReader (const QTAudioReader&);
  17042. QTAudioReader& operator= (const QTAudioReader&);
  17043. };
  17044. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17045. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17046. {
  17047. }
  17048. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17049. {
  17050. }
  17051. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17052. {
  17053. return Array<int>();
  17054. }
  17055. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17056. {
  17057. return Array<int>();
  17058. }
  17059. bool QuickTimeAudioFormat::canDoStereo()
  17060. {
  17061. return true;
  17062. }
  17063. bool QuickTimeAudioFormat::canDoMono()
  17064. {
  17065. return true;
  17066. }
  17067. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17068. const bool deleteStreamIfOpeningFails)
  17069. {
  17070. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17071. if (r->ok)
  17072. return r.release();
  17073. if (! deleteStreamIfOpeningFails)
  17074. r->input = 0;
  17075. return 0;
  17076. }
  17077. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17078. double /*sampleRateToUse*/,
  17079. unsigned int /*numberOfChannels*/,
  17080. int /*bitsPerSample*/,
  17081. const StringPairArray& /*metadataValues*/,
  17082. int /*qualityOptionIndex*/)
  17083. {
  17084. jassertfalse // not yet implemented!
  17085. return 0;
  17086. }
  17087. END_JUCE_NAMESPACE
  17088. #endif
  17089. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17090. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17091. BEGIN_JUCE_NAMESPACE
  17092. static const char* const wavFormatName = "WAV file";
  17093. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17094. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17095. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17096. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17097. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17098. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17099. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17100. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17101. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17102. const String& originator,
  17103. const String& originatorRef,
  17104. const Time& date,
  17105. const int64 timeReferenceSamples,
  17106. const String& codingHistory)
  17107. {
  17108. StringPairArray m;
  17109. m.set (bwavDescription, description);
  17110. m.set (bwavOriginator, originator);
  17111. m.set (bwavOriginatorRef, originatorRef);
  17112. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17113. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17114. m.set (bwavTimeReference, String (timeReferenceSamples));
  17115. m.set (bwavCodingHistory, codingHistory);
  17116. return m;
  17117. }
  17118. #if JUCE_MSVC
  17119. #pragma pack (push, 1)
  17120. #define PACKED
  17121. #elif JUCE_GCC
  17122. #define PACKED __attribute__((packed))
  17123. #else
  17124. #define PACKED
  17125. #endif
  17126. struct BWAVChunk
  17127. {
  17128. char description [256];
  17129. char originator [32];
  17130. char originatorRef [32];
  17131. char originationDate [10];
  17132. char originationTime [8];
  17133. uint32 timeRefLow;
  17134. uint32 timeRefHigh;
  17135. uint16 version;
  17136. uint8 umid[64];
  17137. uint8 reserved[190];
  17138. char codingHistory[1];
  17139. void copyTo (StringPairArray& values) const
  17140. {
  17141. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17142. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17143. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17144. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17145. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17146. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17147. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17148. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17149. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17150. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17151. }
  17152. static MemoryBlock createFrom (const StringPairArray& values)
  17153. {
  17154. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17155. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17156. data.fillWith (0);
  17157. BWAVChunk* b = (BWAVChunk*) data.getData();
  17158. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17159. // as they get called in the right order..
  17160. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17161. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17162. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17163. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17164. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17165. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17166. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17167. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17168. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17169. if (b->description[0] != 0
  17170. || b->originator[0] != 0
  17171. || b->originationDate[0] != 0
  17172. || b->originationTime[0] != 0
  17173. || b->codingHistory[0] != 0
  17174. || time != 0)
  17175. {
  17176. return data;
  17177. }
  17178. return MemoryBlock();
  17179. }
  17180. } PACKED;
  17181. struct SMPLChunk
  17182. {
  17183. struct SampleLoop
  17184. {
  17185. uint32 identifier;
  17186. uint32 type;
  17187. uint32 start;
  17188. uint32 end;
  17189. uint32 fraction;
  17190. uint32 playCount;
  17191. } PACKED;
  17192. uint32 manufacturer;
  17193. uint32 product;
  17194. uint32 samplePeriod;
  17195. uint32 midiUnityNote;
  17196. uint32 midiPitchFraction;
  17197. uint32 smpteFormat;
  17198. uint32 smpteOffset;
  17199. uint32 numSampleLoops;
  17200. uint32 samplerData;
  17201. SampleLoop loops[1];
  17202. void copyTo (StringPairArray& values, const int totalSize) const
  17203. {
  17204. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17205. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17206. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17207. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17208. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17209. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17210. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17211. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17212. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17213. for (uint32 i = 0; i < numSampleLoops; ++i)
  17214. {
  17215. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17216. break;
  17217. const String prefix ("Loop" + String(i));
  17218. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17219. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17220. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17221. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17222. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17223. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17224. }
  17225. }
  17226. static MemoryBlock createFrom (const StringPairArray& values)
  17227. {
  17228. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17229. if (numLoops <= 0)
  17230. return MemoryBlock();
  17231. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17232. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17233. data.fillWith (0);
  17234. SMPLChunk* s = (SMPLChunk*) data.getData();
  17235. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17236. // as they get called in the right order..
  17237. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17238. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17239. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17240. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17241. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17242. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17243. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17244. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17245. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17246. for (int i = 0; i < numLoops; ++i)
  17247. {
  17248. const String prefix ("Loop" + String(i));
  17249. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17250. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17251. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17252. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17253. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17254. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17255. }
  17256. return data;
  17257. }
  17258. } PACKED;
  17259. struct ExtensibleWavSubFormat
  17260. {
  17261. uint32 data1;
  17262. uint16 data2;
  17263. uint16 data3;
  17264. uint8 data4[8];
  17265. } PACKED;
  17266. #if JUCE_MSVC
  17267. #pragma pack (pop)
  17268. #endif
  17269. #undef PACKED
  17270. class WavAudioFormatReader : public AudioFormatReader
  17271. {
  17272. int bytesPerFrame;
  17273. int64 dataChunkStart, dataLength;
  17274. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17275. WavAudioFormatReader (const WavAudioFormatReader&);
  17276. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17277. public:
  17278. int64 bwavChunkStart, bwavSize;
  17279. WavAudioFormatReader (InputStream* const in)
  17280. : AudioFormatReader (in, TRANS (wavFormatName)),
  17281. dataLength (0),
  17282. bwavChunkStart (0),
  17283. bwavSize (0)
  17284. {
  17285. if (input->readInt() == chunkName ("RIFF"))
  17286. {
  17287. const uint32 len = (uint32) input->readInt();
  17288. const int64 end = input->getPosition() + len;
  17289. bool hasGotType = false;
  17290. bool hasGotData = false;
  17291. if (input->readInt() == chunkName ("WAVE"))
  17292. {
  17293. while (input->getPosition() < end
  17294. && ! input->isExhausted())
  17295. {
  17296. const int chunkType = input->readInt();
  17297. uint32 length = (uint32) input->readInt();
  17298. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17299. if (chunkType == chunkName ("fmt "))
  17300. {
  17301. // read the format chunk
  17302. const unsigned short format = input->readShort();
  17303. const short numChans = input->readShort();
  17304. sampleRate = input->readInt();
  17305. const int bytesPerSec = input->readInt();
  17306. numChannels = numChans;
  17307. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17308. bitsPerSample = 8 * bytesPerFrame / numChans;
  17309. if (format == 3)
  17310. {
  17311. usesFloatingPointData = true;
  17312. }
  17313. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17314. {
  17315. if (length < 40) // too short
  17316. {
  17317. bytesPerFrame = 0;
  17318. }
  17319. else
  17320. {
  17321. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17322. ExtensibleWavSubFormat subFormat;
  17323. subFormat.data1 = input->readInt();
  17324. subFormat.data2 = input->readShort();
  17325. subFormat.data3 = input->readShort();
  17326. input->read (subFormat.data4, sizeof (subFormat.data4));
  17327. const ExtensibleWavSubFormat pcmFormat
  17328. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17329. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17330. {
  17331. const ExtensibleWavSubFormat ambisonicFormat
  17332. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17333. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17334. bytesPerFrame = 0;
  17335. }
  17336. }
  17337. }
  17338. else if (format != 1)
  17339. {
  17340. bytesPerFrame = 0;
  17341. }
  17342. hasGotType = true;
  17343. }
  17344. else if (chunkType == chunkName ("data"))
  17345. {
  17346. // get the data chunk's position
  17347. dataLength = length;
  17348. dataChunkStart = input->getPosition();
  17349. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17350. hasGotData = true;
  17351. }
  17352. else if (chunkType == chunkName ("bext"))
  17353. {
  17354. bwavChunkStart = input->getPosition();
  17355. bwavSize = length;
  17356. // Broadcast-wav extension chunk..
  17357. HeapBlock <BWAVChunk> bwav;
  17358. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17359. input->read (bwav, length);
  17360. bwav->copyTo (metadataValues);
  17361. }
  17362. else if (chunkType == chunkName ("smpl"))
  17363. {
  17364. HeapBlock <SMPLChunk> smpl;
  17365. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17366. input->read (smpl, length);
  17367. smpl->copyTo (metadataValues, length);
  17368. }
  17369. else if (chunkEnd <= input->getPosition())
  17370. {
  17371. break;
  17372. }
  17373. input->setPosition (chunkEnd);
  17374. }
  17375. }
  17376. }
  17377. }
  17378. ~WavAudioFormatReader()
  17379. {
  17380. }
  17381. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17382. int64 startSampleInFile, int numSamples)
  17383. {
  17384. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17385. if (samplesAvailable < numSamples)
  17386. {
  17387. for (int i = numDestChannels; --i >= 0;)
  17388. if (destSamples[i] != 0)
  17389. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17390. numSamples = (int) samplesAvailable;
  17391. }
  17392. if (numSamples <= 0)
  17393. return true;
  17394. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17395. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17396. char tempBuffer [tempBufSize];
  17397. while (numSamples > 0)
  17398. {
  17399. int* left = destSamples[0];
  17400. if (left != 0)
  17401. left += startOffsetInDestBuffer;
  17402. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17403. if (right != 0)
  17404. right += startOffsetInDestBuffer;
  17405. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17406. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17407. if (bytesRead < numThisTime * bytesPerFrame)
  17408. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17409. if (bitsPerSample == 16)
  17410. {
  17411. const short* src = reinterpret_cast <const short*> (tempBuffer);
  17412. if (numChannels > 1)
  17413. {
  17414. if (left == 0)
  17415. {
  17416. for (int i = numThisTime; --i >= 0;)
  17417. {
  17418. ++src;
  17419. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17420. }
  17421. }
  17422. else if (right == 0)
  17423. {
  17424. for (int i = numThisTime; --i >= 0;)
  17425. {
  17426. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17427. ++src;
  17428. }
  17429. }
  17430. else
  17431. {
  17432. for (int i = numThisTime; --i >= 0;)
  17433. {
  17434. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17435. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17436. }
  17437. }
  17438. }
  17439. else
  17440. {
  17441. for (int i = numThisTime; --i >= 0;)
  17442. {
  17443. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17444. }
  17445. }
  17446. }
  17447. else if (bitsPerSample == 24)
  17448. {
  17449. const char* src = tempBuffer;
  17450. if (numChannels > 1)
  17451. {
  17452. if (left == 0)
  17453. {
  17454. for (int i = numThisTime; --i >= 0;)
  17455. {
  17456. src += 3;
  17457. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17458. src += 3;
  17459. }
  17460. }
  17461. else if (right == 0)
  17462. {
  17463. for (int i = numThisTime; --i >= 0;)
  17464. {
  17465. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17466. src += 6;
  17467. }
  17468. }
  17469. else
  17470. {
  17471. for (int i = 0; i < numThisTime; ++i)
  17472. {
  17473. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17474. src += 3;
  17475. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17476. src += 3;
  17477. }
  17478. }
  17479. }
  17480. else
  17481. {
  17482. for (int i = 0; i < numThisTime; ++i)
  17483. {
  17484. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17485. src += 3;
  17486. }
  17487. }
  17488. }
  17489. else if (bitsPerSample == 32)
  17490. {
  17491. const unsigned int* src = (const unsigned int*) tempBuffer;
  17492. unsigned int* l = (unsigned int*) left;
  17493. unsigned int* r = (unsigned int*) right;
  17494. if (numChannels > 1)
  17495. {
  17496. if (l == 0)
  17497. {
  17498. for (int i = numThisTime; --i >= 0;)
  17499. {
  17500. ++src;
  17501. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17502. }
  17503. }
  17504. else if (r == 0)
  17505. {
  17506. for (int i = numThisTime; --i >= 0;)
  17507. {
  17508. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17509. ++src;
  17510. }
  17511. }
  17512. else
  17513. {
  17514. for (int i = numThisTime; --i >= 0;)
  17515. {
  17516. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17517. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17518. }
  17519. }
  17520. }
  17521. else
  17522. {
  17523. for (int i = numThisTime; --i >= 0;)
  17524. {
  17525. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17526. }
  17527. }
  17528. left = (int*)l;
  17529. right = (int*)r;
  17530. }
  17531. else if (bitsPerSample == 8)
  17532. {
  17533. const unsigned char* src = (const unsigned char*) tempBuffer;
  17534. if (numChannels > 1)
  17535. {
  17536. if (left == 0)
  17537. {
  17538. for (int i = numThisTime; --i >= 0;)
  17539. {
  17540. ++src;
  17541. *right++ = ((int) *src++ - 128) << 24;
  17542. }
  17543. }
  17544. else if (right == 0)
  17545. {
  17546. for (int i = numThisTime; --i >= 0;)
  17547. {
  17548. *left++ = ((int) *src++ - 128) << 24;
  17549. ++src;
  17550. }
  17551. }
  17552. else
  17553. {
  17554. for (int i = numThisTime; --i >= 0;)
  17555. {
  17556. *left++ = ((int) *src++ - 128) << 24;
  17557. *right++ = ((int) *src++ - 128) << 24;
  17558. }
  17559. }
  17560. }
  17561. else
  17562. {
  17563. for (int i = numThisTime; --i >= 0;)
  17564. {
  17565. *left++ = ((int)*src++ - 128) << 24;
  17566. }
  17567. }
  17568. }
  17569. startOffsetInDestBuffer += numThisTime;
  17570. numSamples -= numThisTime;
  17571. }
  17572. if (numSamples > 0)
  17573. {
  17574. for (int i = numDestChannels; --i >= 0;)
  17575. if (destSamples[i] != 0)
  17576. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17577. sizeof (int) * numSamples);
  17578. }
  17579. return true;
  17580. }
  17581. juce_UseDebuggingNewOperator
  17582. };
  17583. class WavAudioFormatWriter : public AudioFormatWriter
  17584. {
  17585. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17586. uint32 lengthInSamples, bytesWritten;
  17587. int64 headerPosition;
  17588. bool writeFailed;
  17589. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17590. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17591. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17592. void writeHeader()
  17593. {
  17594. const bool seekedOk = output->setPosition (headerPosition);
  17595. (void) seekedOk;
  17596. // if this fails, you've given it an output stream that can't seek! It needs
  17597. // to be able to seek back to write the header
  17598. jassert (seekedOk);
  17599. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17600. output->writeInt (chunkName ("RIFF"));
  17601. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17602. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17603. output->writeInt (chunkName ("WAVE"));
  17604. output->writeInt (chunkName ("fmt "));
  17605. output->writeInt (16);
  17606. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17607. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17608. output->writeShort ((short) numChannels);
  17609. output->writeInt ((int) sampleRate);
  17610. output->writeInt (bytesPerFrame * (int) sampleRate);
  17611. output->writeShort ((short) bytesPerFrame);
  17612. output->writeShort ((short) bitsPerSample);
  17613. if (bwavChunk.getSize() > 0)
  17614. {
  17615. output->writeInt (chunkName ("bext"));
  17616. output->writeInt ((int) bwavChunk.getSize());
  17617. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17618. }
  17619. if (smplChunk.getSize() > 0)
  17620. {
  17621. output->writeInt (chunkName ("smpl"));
  17622. output->writeInt ((int) smplChunk.getSize());
  17623. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17624. }
  17625. output->writeInt (chunkName ("data"));
  17626. output->writeInt (lengthInSamples * bytesPerFrame);
  17627. usesFloatingPointData = (bitsPerSample == 32);
  17628. }
  17629. public:
  17630. WavAudioFormatWriter (OutputStream* const out,
  17631. const double sampleRate_,
  17632. const unsigned int numChannels_,
  17633. const int bits,
  17634. const StringPairArray& metadataValues)
  17635. : AudioFormatWriter (out,
  17636. TRANS (wavFormatName),
  17637. sampleRate_,
  17638. numChannels_,
  17639. bits),
  17640. lengthInSamples (0),
  17641. bytesWritten (0),
  17642. writeFailed (false)
  17643. {
  17644. if (metadataValues.size() > 0)
  17645. {
  17646. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17647. smplChunk = SMPLChunk::createFrom (metadataValues);
  17648. }
  17649. headerPosition = out->getPosition();
  17650. writeHeader();
  17651. }
  17652. ~WavAudioFormatWriter()
  17653. {
  17654. writeHeader();
  17655. }
  17656. bool write (const int** data, int numSamples)
  17657. {
  17658. if (writeFailed)
  17659. return false;
  17660. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17661. tempBlock.ensureSize (bytes, false);
  17662. char* buffer = static_cast <char*> (tempBlock.getData());
  17663. const int* left = data[0];
  17664. const int* right = data[1];
  17665. if (right == 0)
  17666. right = left;
  17667. if (bitsPerSample == 16)
  17668. {
  17669. short* b = (short*) buffer;
  17670. if (numChannels > 1)
  17671. {
  17672. for (int i = numSamples; --i >= 0;)
  17673. {
  17674. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17675. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17676. }
  17677. }
  17678. else
  17679. {
  17680. for (int i = numSamples; --i >= 0;)
  17681. {
  17682. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17683. }
  17684. }
  17685. }
  17686. else if (bitsPerSample == 24)
  17687. {
  17688. char* b = buffer;
  17689. if (numChannels > 1)
  17690. {
  17691. for (int i = numSamples; --i >= 0;)
  17692. {
  17693. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17694. b += 3;
  17695. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17696. b += 3;
  17697. }
  17698. }
  17699. else
  17700. {
  17701. for (int i = numSamples; --i >= 0;)
  17702. {
  17703. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17704. b += 3;
  17705. }
  17706. }
  17707. }
  17708. else if (bitsPerSample == 32)
  17709. {
  17710. unsigned int* b = (unsigned int*) buffer;
  17711. if (numChannels > 1)
  17712. {
  17713. for (int i = numSamples; --i >= 0;)
  17714. {
  17715. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17716. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17717. }
  17718. }
  17719. else
  17720. {
  17721. for (int i = numSamples; --i >= 0;)
  17722. {
  17723. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17724. }
  17725. }
  17726. }
  17727. else if (bitsPerSample == 8)
  17728. {
  17729. unsigned char* b = (unsigned char*) buffer;
  17730. if (numChannels > 1)
  17731. {
  17732. for (int i = numSamples; --i >= 0;)
  17733. {
  17734. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17735. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17736. }
  17737. }
  17738. else
  17739. {
  17740. for (int i = numSamples; --i >= 0;)
  17741. {
  17742. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17743. }
  17744. }
  17745. }
  17746. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17747. || ! output->write (buffer, bytes))
  17748. {
  17749. // failed to write to disk, so let's try writing the header.
  17750. // If it's just run out of disk space, then if it does manage
  17751. // to write the header, we'll still have a useable file..
  17752. writeHeader();
  17753. writeFailed = true;
  17754. return false;
  17755. }
  17756. else
  17757. {
  17758. bytesWritten += bytes;
  17759. lengthInSamples += numSamples;
  17760. return true;
  17761. }
  17762. }
  17763. juce_UseDebuggingNewOperator
  17764. };
  17765. WavAudioFormat::WavAudioFormat()
  17766. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17767. {
  17768. }
  17769. WavAudioFormat::~WavAudioFormat()
  17770. {
  17771. }
  17772. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17773. {
  17774. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17775. return Array <int> (rates);
  17776. }
  17777. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17778. {
  17779. const int depths[] = { 8, 16, 24, 32, 0 };
  17780. return Array <int> (depths);
  17781. }
  17782. bool WavAudioFormat::canDoStereo()
  17783. {
  17784. return true;
  17785. }
  17786. bool WavAudioFormat::canDoMono()
  17787. {
  17788. return true;
  17789. }
  17790. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17791. const bool deleteStreamIfOpeningFails)
  17792. {
  17793. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17794. if (r->sampleRate != 0)
  17795. return r.release();
  17796. if (! deleteStreamIfOpeningFails)
  17797. r->input = 0;
  17798. return 0;
  17799. }
  17800. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17801. double sampleRate,
  17802. unsigned int numChannels,
  17803. int bitsPerSample,
  17804. const StringPairArray& metadataValues,
  17805. int /*qualityOptionIndex*/)
  17806. {
  17807. if (getPossibleBitDepths().contains (bitsPerSample))
  17808. {
  17809. return new WavAudioFormatWriter (out,
  17810. sampleRate,
  17811. numChannels,
  17812. bitsPerSample,
  17813. metadataValues);
  17814. }
  17815. return 0;
  17816. }
  17817. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17818. {
  17819. TemporaryFile tempFile (file);
  17820. WavAudioFormat wav;
  17821. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17822. if (reader != 0)
  17823. {
  17824. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17825. if (outStream != 0)
  17826. {
  17827. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17828. reader->numChannels, reader->bitsPerSample,
  17829. metadata, 0));
  17830. if (writer != 0)
  17831. {
  17832. outStream.release();
  17833. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17834. writer = 0;
  17835. reader = 0;
  17836. return ok && tempFile.overwriteTargetFileWithTemporary();
  17837. }
  17838. }
  17839. }
  17840. return false;
  17841. }
  17842. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17843. {
  17844. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17845. if (reader != 0)
  17846. {
  17847. const int64 bwavPos = reader->bwavChunkStart;
  17848. const int64 bwavSize = reader->bwavSize;
  17849. reader = 0;
  17850. if (bwavSize > 0)
  17851. {
  17852. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17853. if (chunk.getSize() <= (size_t) bwavSize)
  17854. {
  17855. // the new one will fit in the space available, so write it directly..
  17856. const int64 oldSize = wavFile.getSize();
  17857. {
  17858. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17859. out->setPosition (bwavPos);
  17860. out->write (chunk.getData(), (int) chunk.getSize());
  17861. out->setPosition (oldSize);
  17862. }
  17863. jassert (wavFile.getSize() == oldSize);
  17864. return true;
  17865. }
  17866. }
  17867. }
  17868. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17869. }
  17870. END_JUCE_NAMESPACE
  17871. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17872. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17873. BEGIN_JUCE_NAMESPACE
  17874. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17875. const bool deleteReaderWhenThisIsDeleted)
  17876. : reader (reader_),
  17877. deleteReader (deleteReaderWhenThisIsDeleted),
  17878. nextPlayPos (0),
  17879. looping (false)
  17880. {
  17881. jassert (reader != 0);
  17882. }
  17883. AudioFormatReaderSource::~AudioFormatReaderSource()
  17884. {
  17885. releaseResources();
  17886. if (deleteReader)
  17887. delete reader;
  17888. }
  17889. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17890. {
  17891. nextPlayPos = newPosition;
  17892. }
  17893. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17894. {
  17895. looping = shouldLoop;
  17896. }
  17897. int AudioFormatReaderSource::getNextReadPosition() const
  17898. {
  17899. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  17900. : nextPlayPos;
  17901. }
  17902. int AudioFormatReaderSource::getTotalLength() const
  17903. {
  17904. return (int) reader->lengthInSamples;
  17905. }
  17906. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  17907. double /*sampleRate*/)
  17908. {
  17909. }
  17910. void AudioFormatReaderSource::releaseResources()
  17911. {
  17912. }
  17913. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  17914. {
  17915. if (info.numSamples > 0)
  17916. {
  17917. const int start = nextPlayPos;
  17918. if (looping)
  17919. {
  17920. const int newStart = start % (int) reader->lengthInSamples;
  17921. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  17922. if (newEnd > newStart)
  17923. {
  17924. info.buffer->readFromAudioReader (reader,
  17925. info.startSample,
  17926. newEnd - newStart,
  17927. newStart,
  17928. true, true);
  17929. }
  17930. else
  17931. {
  17932. const int endSamps = (int) reader->lengthInSamples - newStart;
  17933. info.buffer->readFromAudioReader (reader,
  17934. info.startSample,
  17935. endSamps,
  17936. newStart,
  17937. true, true);
  17938. info.buffer->readFromAudioReader (reader,
  17939. info.startSample + endSamps,
  17940. newEnd,
  17941. 0,
  17942. true, true);
  17943. }
  17944. nextPlayPos = newEnd;
  17945. }
  17946. else
  17947. {
  17948. info.buffer->readFromAudioReader (reader,
  17949. info.startSample,
  17950. info.numSamples,
  17951. start,
  17952. true, true);
  17953. nextPlayPos += info.numSamples;
  17954. }
  17955. }
  17956. }
  17957. END_JUCE_NAMESPACE
  17958. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17959. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  17960. BEGIN_JUCE_NAMESPACE
  17961. AudioSourcePlayer::AudioSourcePlayer()
  17962. : source (0),
  17963. sampleRate (0),
  17964. bufferSize (0),
  17965. tempBuffer (2, 8),
  17966. lastGain (1.0f),
  17967. gain (1.0f)
  17968. {
  17969. }
  17970. AudioSourcePlayer::~AudioSourcePlayer()
  17971. {
  17972. setSource (0);
  17973. }
  17974. void AudioSourcePlayer::setSource (AudioSource* newSource)
  17975. {
  17976. if (source != newSource)
  17977. {
  17978. AudioSource* const oldSource = source;
  17979. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  17980. newSource->prepareToPlay (bufferSize, sampleRate);
  17981. {
  17982. const ScopedLock sl (readLock);
  17983. source = newSource;
  17984. }
  17985. if (oldSource != 0)
  17986. oldSource->releaseResources();
  17987. }
  17988. }
  17989. void AudioSourcePlayer::setGain (const float newGain) throw()
  17990. {
  17991. gain = newGain;
  17992. }
  17993. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  17994. int totalNumInputChannels,
  17995. float** outputChannelData,
  17996. int totalNumOutputChannels,
  17997. int numSamples)
  17998. {
  17999. // these should have been prepared by audioDeviceAboutToStart()...
  18000. jassert (sampleRate > 0 && bufferSize > 0);
  18001. const ScopedLock sl (readLock);
  18002. if (source != 0)
  18003. {
  18004. AudioSourceChannelInfo info;
  18005. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18006. // messy stuff needed to compact the channels down into an array
  18007. // of non-zero pointers..
  18008. for (i = 0; i < totalNumInputChannels; ++i)
  18009. {
  18010. if (inputChannelData[i] != 0)
  18011. {
  18012. inputChans [numInputs++] = inputChannelData[i];
  18013. if (numInputs >= numElementsInArray (inputChans))
  18014. break;
  18015. }
  18016. }
  18017. for (i = 0; i < totalNumOutputChannels; ++i)
  18018. {
  18019. if (outputChannelData[i] != 0)
  18020. {
  18021. outputChans [numOutputs++] = outputChannelData[i];
  18022. if (numOutputs >= numElementsInArray (outputChans))
  18023. break;
  18024. }
  18025. }
  18026. if (numInputs > numOutputs)
  18027. {
  18028. // if there aren't enough output channels for the number of
  18029. // inputs, we need to create some temporary extra ones (can't
  18030. // use the input data in case it gets written to)
  18031. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18032. false, false, true);
  18033. for (i = 0; i < numOutputs; ++i)
  18034. {
  18035. channels[numActiveChans] = outputChans[i];
  18036. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18037. ++numActiveChans;
  18038. }
  18039. for (i = numOutputs; i < numInputs; ++i)
  18040. {
  18041. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18042. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18043. ++numActiveChans;
  18044. }
  18045. }
  18046. else
  18047. {
  18048. for (i = 0; i < numInputs; ++i)
  18049. {
  18050. channels[numActiveChans] = outputChans[i];
  18051. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18052. ++numActiveChans;
  18053. }
  18054. for (i = numInputs; i < numOutputs; ++i)
  18055. {
  18056. channels[numActiveChans] = outputChans[i];
  18057. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18058. ++numActiveChans;
  18059. }
  18060. }
  18061. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18062. info.buffer = &buffer;
  18063. info.startSample = 0;
  18064. info.numSamples = numSamples;
  18065. source->getNextAudioBlock (info);
  18066. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18067. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18068. lastGain = gain;
  18069. }
  18070. else
  18071. {
  18072. for (int i = 0; i < totalNumOutputChannels; ++i)
  18073. if (outputChannelData[i] != 0)
  18074. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18075. }
  18076. }
  18077. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18078. {
  18079. sampleRate = device->getCurrentSampleRate();
  18080. bufferSize = device->getCurrentBufferSizeSamples();
  18081. zeromem (channels, sizeof (channels));
  18082. if (source != 0)
  18083. source->prepareToPlay (bufferSize, sampleRate);
  18084. }
  18085. void AudioSourcePlayer::audioDeviceStopped()
  18086. {
  18087. if (source != 0)
  18088. source->releaseResources();
  18089. sampleRate = 0.0;
  18090. bufferSize = 0;
  18091. tempBuffer.setSize (2, 8);
  18092. }
  18093. END_JUCE_NAMESPACE
  18094. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18095. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18096. BEGIN_JUCE_NAMESPACE
  18097. AudioTransportSource::AudioTransportSource()
  18098. : source (0),
  18099. resamplerSource (0),
  18100. bufferingSource (0),
  18101. positionableSource (0),
  18102. masterSource (0),
  18103. gain (1.0f),
  18104. lastGain (1.0f),
  18105. playing (false),
  18106. stopped (true),
  18107. sampleRate (44100.0),
  18108. sourceSampleRate (0.0),
  18109. blockSize (128),
  18110. readAheadBufferSize (0),
  18111. isPrepared (false),
  18112. inputStreamEOF (false)
  18113. {
  18114. }
  18115. AudioTransportSource::~AudioTransportSource()
  18116. {
  18117. setSource (0);
  18118. releaseResources();
  18119. }
  18120. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18121. int readAheadBufferSize_,
  18122. double sourceSampleRateToCorrectFor)
  18123. {
  18124. if (source == newSource)
  18125. {
  18126. if (source == 0)
  18127. return;
  18128. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18129. }
  18130. readAheadBufferSize = readAheadBufferSize_;
  18131. sourceSampleRate = sourceSampleRateToCorrectFor;
  18132. ResamplingAudioSource* newResamplerSource = 0;
  18133. BufferingAudioSource* newBufferingSource = 0;
  18134. PositionableAudioSource* newPositionableSource = 0;
  18135. AudioSource* newMasterSource = 0;
  18136. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18137. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18138. AudioSource* oldMasterSource = masterSource;
  18139. if (newSource != 0)
  18140. {
  18141. newPositionableSource = newSource;
  18142. if (readAheadBufferSize_ > 0)
  18143. newPositionableSource = newBufferingSource
  18144. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18145. newPositionableSource->setNextReadPosition (0);
  18146. if (sourceSampleRateToCorrectFor != 0)
  18147. newMasterSource = newResamplerSource
  18148. = new ResamplingAudioSource (newPositionableSource, false);
  18149. else
  18150. newMasterSource = newPositionableSource;
  18151. if (isPrepared)
  18152. {
  18153. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18154. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18155. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18156. }
  18157. }
  18158. {
  18159. const ScopedLock sl (callbackLock);
  18160. source = newSource;
  18161. resamplerSource = newResamplerSource;
  18162. bufferingSource = newBufferingSource;
  18163. masterSource = newMasterSource;
  18164. positionableSource = newPositionableSource;
  18165. playing = false;
  18166. }
  18167. if (oldMasterSource != 0)
  18168. oldMasterSource->releaseResources();
  18169. }
  18170. void AudioTransportSource::start()
  18171. {
  18172. if ((! playing) && masterSource != 0)
  18173. {
  18174. {
  18175. const ScopedLock sl (callbackLock);
  18176. playing = true;
  18177. stopped = false;
  18178. inputStreamEOF = false;
  18179. }
  18180. sendChangeMessage (this);
  18181. }
  18182. }
  18183. void AudioTransportSource::stop()
  18184. {
  18185. if (playing)
  18186. {
  18187. {
  18188. const ScopedLock sl (callbackLock);
  18189. playing = false;
  18190. }
  18191. int n = 500;
  18192. while (--n >= 0 && ! stopped)
  18193. Thread::sleep (2);
  18194. sendChangeMessage (this);
  18195. }
  18196. }
  18197. void AudioTransportSource::setPosition (double newPosition)
  18198. {
  18199. if (sampleRate > 0.0)
  18200. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18201. }
  18202. double AudioTransportSource::getCurrentPosition() const
  18203. {
  18204. if (sampleRate > 0.0)
  18205. return getNextReadPosition() / sampleRate;
  18206. else
  18207. return 0.0;
  18208. }
  18209. void AudioTransportSource::setNextReadPosition (int newPosition)
  18210. {
  18211. if (positionableSource != 0)
  18212. {
  18213. if (sampleRate > 0 && sourceSampleRate > 0)
  18214. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18215. positionableSource->setNextReadPosition (newPosition);
  18216. }
  18217. }
  18218. int AudioTransportSource::getNextReadPosition() const
  18219. {
  18220. if (positionableSource != 0)
  18221. {
  18222. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18223. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18224. }
  18225. return 0;
  18226. }
  18227. int AudioTransportSource::getTotalLength() const
  18228. {
  18229. const ScopedLock sl (callbackLock);
  18230. if (positionableSource != 0)
  18231. {
  18232. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18233. return roundToInt (positionableSource->getTotalLength() * ratio);
  18234. }
  18235. return 0;
  18236. }
  18237. bool AudioTransportSource::isLooping() const
  18238. {
  18239. const ScopedLock sl (callbackLock);
  18240. return positionableSource != 0
  18241. && positionableSource->isLooping();
  18242. }
  18243. void AudioTransportSource::setGain (const float newGain) throw()
  18244. {
  18245. gain = newGain;
  18246. }
  18247. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18248. double sampleRate_)
  18249. {
  18250. const ScopedLock sl (callbackLock);
  18251. sampleRate = sampleRate_;
  18252. blockSize = samplesPerBlockExpected;
  18253. if (masterSource != 0)
  18254. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18255. if (resamplerSource != 0 && sourceSampleRate != 0)
  18256. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18257. isPrepared = true;
  18258. }
  18259. void AudioTransportSource::releaseResources()
  18260. {
  18261. const ScopedLock sl (callbackLock);
  18262. if (masterSource != 0)
  18263. masterSource->releaseResources();
  18264. isPrepared = false;
  18265. }
  18266. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18267. {
  18268. const ScopedLock sl (callbackLock);
  18269. inputStreamEOF = false;
  18270. if (masterSource != 0 && ! stopped)
  18271. {
  18272. masterSource->getNextAudioBlock (info);
  18273. if (! playing)
  18274. {
  18275. // just stopped playing, so fade out the last block..
  18276. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18277. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18278. if (info.numSamples > 256)
  18279. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18280. }
  18281. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18282. && ! positionableSource->isLooping())
  18283. {
  18284. playing = false;
  18285. inputStreamEOF = true;
  18286. sendChangeMessage (this);
  18287. }
  18288. stopped = ! playing;
  18289. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18290. {
  18291. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18292. lastGain, gain);
  18293. }
  18294. }
  18295. else
  18296. {
  18297. info.clearActiveBufferRegion();
  18298. stopped = true;
  18299. }
  18300. lastGain = gain;
  18301. }
  18302. END_JUCE_NAMESPACE
  18303. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18304. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18305. BEGIN_JUCE_NAMESPACE
  18306. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18307. public Thread,
  18308. private Timer
  18309. {
  18310. public:
  18311. SharedBufferingAudioSourceThread()
  18312. : Thread ("Audio Buffer")
  18313. {
  18314. }
  18315. ~SharedBufferingAudioSourceThread()
  18316. {
  18317. stopThread (10000);
  18318. clearSingletonInstance();
  18319. }
  18320. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18321. void addSource (BufferingAudioSource* source)
  18322. {
  18323. const ScopedLock sl (lock);
  18324. if (! sources.contains (source))
  18325. {
  18326. sources.add (source);
  18327. startThread();
  18328. stopTimer();
  18329. }
  18330. notify();
  18331. }
  18332. void removeSource (BufferingAudioSource* source)
  18333. {
  18334. const ScopedLock sl (lock);
  18335. sources.removeValue (source);
  18336. if (sources.size() == 0)
  18337. startTimer (5000);
  18338. }
  18339. private:
  18340. Array <BufferingAudioSource*> sources;
  18341. CriticalSection lock;
  18342. void run()
  18343. {
  18344. while (! threadShouldExit())
  18345. {
  18346. bool busy = false;
  18347. for (int i = sources.size(); --i >= 0;)
  18348. {
  18349. if (threadShouldExit())
  18350. return;
  18351. const ScopedLock sl (lock);
  18352. BufferingAudioSource* const b = sources[i];
  18353. if (b != 0 && b->readNextBufferChunk())
  18354. busy = true;
  18355. }
  18356. if (! busy)
  18357. wait (500);
  18358. }
  18359. }
  18360. void timerCallback()
  18361. {
  18362. stopTimer();
  18363. if (sources.size() == 0)
  18364. deleteInstance();
  18365. }
  18366. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18367. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18368. };
  18369. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18370. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18371. const bool deleteSourceWhenDeleted_,
  18372. int numberOfSamplesToBuffer_)
  18373. : source (source_),
  18374. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18375. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18376. buffer (2, 0),
  18377. bufferValidStart (0),
  18378. bufferValidEnd (0),
  18379. nextPlayPos (0),
  18380. wasSourceLooping (false)
  18381. {
  18382. jassert (source_ != 0);
  18383. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18384. // not using a larger buffer..
  18385. }
  18386. BufferingAudioSource::~BufferingAudioSource()
  18387. {
  18388. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18389. if (thread != 0)
  18390. thread->removeSource (this);
  18391. if (deleteSourceWhenDeleted)
  18392. delete source;
  18393. }
  18394. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18395. {
  18396. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18397. sampleRate = sampleRate_;
  18398. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18399. buffer.clear();
  18400. bufferValidStart = 0;
  18401. bufferValidEnd = 0;
  18402. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18403. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18404. buffer.getNumSamples() / 2))
  18405. {
  18406. SharedBufferingAudioSourceThread::getInstance()->notify();
  18407. Thread::sleep (5);
  18408. }
  18409. }
  18410. void BufferingAudioSource::releaseResources()
  18411. {
  18412. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18413. if (thread != 0)
  18414. thread->removeSource (this);
  18415. buffer.setSize (2, 0);
  18416. source->releaseResources();
  18417. }
  18418. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18419. {
  18420. const ScopedLock sl (bufferStartPosLock);
  18421. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18422. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18423. if (validStart == validEnd)
  18424. {
  18425. // total cache miss
  18426. info.clearActiveBufferRegion();
  18427. }
  18428. else
  18429. {
  18430. if (validStart > 0)
  18431. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18432. if (validEnd < info.numSamples)
  18433. info.buffer->clear (info.startSample + validEnd,
  18434. info.numSamples - validEnd); // partial cache miss at end
  18435. if (validStart < validEnd)
  18436. {
  18437. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18438. {
  18439. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18440. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18441. if (startBufferIndex < endBufferIndex)
  18442. {
  18443. info.buffer->copyFrom (chan, info.startSample + validStart,
  18444. buffer,
  18445. chan, startBufferIndex,
  18446. validEnd - validStart);
  18447. }
  18448. else
  18449. {
  18450. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18451. info.buffer->copyFrom (chan, info.startSample + validStart,
  18452. buffer,
  18453. chan, startBufferIndex,
  18454. initialSize);
  18455. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18456. buffer,
  18457. chan, 0,
  18458. (validEnd - validStart) - initialSize);
  18459. }
  18460. }
  18461. }
  18462. nextPlayPos += info.numSamples;
  18463. if (source->isLooping() && nextPlayPos > 0)
  18464. nextPlayPos %= source->getTotalLength();
  18465. }
  18466. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18467. if (thread != 0)
  18468. thread->notify();
  18469. }
  18470. int BufferingAudioSource::getNextReadPosition() const
  18471. {
  18472. return (source->isLooping() && nextPlayPos > 0)
  18473. ? nextPlayPos % source->getTotalLength()
  18474. : nextPlayPos;
  18475. }
  18476. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18477. {
  18478. const ScopedLock sl (bufferStartPosLock);
  18479. nextPlayPos = newPosition;
  18480. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18481. if (thread != 0)
  18482. thread->notify();
  18483. }
  18484. bool BufferingAudioSource::readNextBufferChunk()
  18485. {
  18486. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18487. {
  18488. const ScopedLock sl (bufferStartPosLock);
  18489. if (wasSourceLooping != isLooping())
  18490. {
  18491. wasSourceLooping = isLooping();
  18492. bufferValidStart = 0;
  18493. bufferValidEnd = 0;
  18494. }
  18495. newBVS = jmax (0, nextPlayPos);
  18496. newBVE = newBVS + buffer.getNumSamples() - 4;
  18497. sectionToReadStart = 0;
  18498. sectionToReadEnd = 0;
  18499. const int maxChunkSize = 2048;
  18500. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18501. {
  18502. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18503. sectionToReadStart = newBVS;
  18504. sectionToReadEnd = newBVE;
  18505. bufferValidStart = 0;
  18506. bufferValidEnd = 0;
  18507. }
  18508. else if (abs (newBVS - bufferValidStart) > 512
  18509. || abs (newBVE - bufferValidEnd) > 512)
  18510. {
  18511. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18512. sectionToReadStart = bufferValidEnd;
  18513. sectionToReadEnd = newBVE;
  18514. bufferValidStart = newBVS;
  18515. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18516. }
  18517. }
  18518. if (sectionToReadStart != sectionToReadEnd)
  18519. {
  18520. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18521. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18522. if (bufferIndexStart < bufferIndexEnd)
  18523. {
  18524. readBufferSection (sectionToReadStart,
  18525. sectionToReadEnd - sectionToReadStart,
  18526. bufferIndexStart);
  18527. }
  18528. else
  18529. {
  18530. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18531. readBufferSection (sectionToReadStart,
  18532. initialSize,
  18533. bufferIndexStart);
  18534. readBufferSection (sectionToReadStart + initialSize,
  18535. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18536. 0);
  18537. }
  18538. const ScopedLock sl2 (bufferStartPosLock);
  18539. bufferValidStart = newBVS;
  18540. bufferValidEnd = newBVE;
  18541. return true;
  18542. }
  18543. else
  18544. {
  18545. return false;
  18546. }
  18547. }
  18548. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18549. {
  18550. if (source->getNextReadPosition() != start)
  18551. source->setNextReadPosition (start);
  18552. AudioSourceChannelInfo info;
  18553. info.buffer = &buffer;
  18554. info.startSample = bufferOffset;
  18555. info.numSamples = length;
  18556. source->getNextAudioBlock (info);
  18557. }
  18558. END_JUCE_NAMESPACE
  18559. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18560. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18561. BEGIN_JUCE_NAMESPACE
  18562. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18563. const bool deleteSourceWhenDeleted_)
  18564. : requiredNumberOfChannels (2),
  18565. source (source_),
  18566. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18567. buffer (2, 16)
  18568. {
  18569. remappedInfo.buffer = &buffer;
  18570. remappedInfo.startSample = 0;
  18571. }
  18572. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18573. {
  18574. if (deleteSourceWhenDeleted)
  18575. delete source;
  18576. }
  18577. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18578. {
  18579. const ScopedLock sl (lock);
  18580. requiredNumberOfChannels = requiredNumberOfChannels_;
  18581. }
  18582. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18583. {
  18584. const ScopedLock sl (lock);
  18585. remappedInputs.clear();
  18586. remappedOutputs.clear();
  18587. }
  18588. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18589. {
  18590. const ScopedLock sl (lock);
  18591. while (remappedInputs.size() < destIndex)
  18592. remappedInputs.add (-1);
  18593. remappedInputs.set (destIndex, sourceIndex);
  18594. }
  18595. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18596. {
  18597. const ScopedLock sl (lock);
  18598. while (remappedOutputs.size() < sourceIndex)
  18599. remappedOutputs.add (-1);
  18600. remappedOutputs.set (sourceIndex, destIndex);
  18601. }
  18602. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18603. {
  18604. const ScopedLock sl (lock);
  18605. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18606. return remappedInputs.getUnchecked (inputChannelIndex);
  18607. return -1;
  18608. }
  18609. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18610. {
  18611. const ScopedLock sl (lock);
  18612. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18613. return remappedOutputs .getUnchecked (outputChannelIndex);
  18614. return -1;
  18615. }
  18616. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18617. {
  18618. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18619. }
  18620. void ChannelRemappingAudioSource::releaseResources()
  18621. {
  18622. source->releaseResources();
  18623. }
  18624. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18625. {
  18626. const ScopedLock sl (lock);
  18627. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18628. const int numChans = bufferToFill.buffer->getNumChannels();
  18629. int i;
  18630. for (i = 0; i < buffer.getNumChannels(); ++i)
  18631. {
  18632. const int remappedChan = getRemappedInputChannel (i);
  18633. if (remappedChan >= 0 && remappedChan < numChans)
  18634. {
  18635. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18636. remappedChan,
  18637. bufferToFill.startSample,
  18638. bufferToFill.numSamples);
  18639. }
  18640. else
  18641. {
  18642. buffer.clear (i, 0, bufferToFill.numSamples);
  18643. }
  18644. }
  18645. remappedInfo.numSamples = bufferToFill.numSamples;
  18646. source->getNextAudioBlock (remappedInfo);
  18647. bufferToFill.clearActiveBufferRegion();
  18648. for (i = 0; i < requiredNumberOfChannels; ++i)
  18649. {
  18650. const int remappedChan = getRemappedOutputChannel (i);
  18651. if (remappedChan >= 0 && remappedChan < numChans)
  18652. {
  18653. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18654. buffer, i, 0, bufferToFill.numSamples);
  18655. }
  18656. }
  18657. }
  18658. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18659. {
  18660. XmlElement* e = new XmlElement ("MAPPINGS");
  18661. String ins, outs;
  18662. int i;
  18663. const ScopedLock sl (lock);
  18664. for (i = 0; i < remappedInputs.size(); ++i)
  18665. ins << remappedInputs.getUnchecked(i) << ' ';
  18666. for (i = 0; i < remappedOutputs.size(); ++i)
  18667. outs << remappedOutputs.getUnchecked(i) << ' ';
  18668. e->setAttribute ("inputs", ins.trimEnd());
  18669. e->setAttribute ("outputs", outs.trimEnd());
  18670. return e;
  18671. }
  18672. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18673. {
  18674. if (e.hasTagName ("MAPPINGS"))
  18675. {
  18676. const ScopedLock sl (lock);
  18677. clearAllMappings();
  18678. StringArray ins, outs;
  18679. ins.addTokens (e.getStringAttribute ("inputs"), false);
  18680. outs.addTokens (e.getStringAttribute ("outputs"), false);
  18681. int i;
  18682. for (i = 0; i < ins.size(); ++i)
  18683. remappedInputs.add (ins[i].getIntValue());
  18684. for (i = 0; i < outs.size(); ++i)
  18685. remappedOutputs.add (outs[i].getIntValue());
  18686. }
  18687. }
  18688. END_JUCE_NAMESPACE
  18689. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18690. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18691. BEGIN_JUCE_NAMESPACE
  18692. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18693. const bool deleteInputWhenDeleted_)
  18694. : input (inputSource),
  18695. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18696. {
  18697. jassert (inputSource != 0);
  18698. for (int i = 2; --i >= 0;)
  18699. iirFilters.add (new IIRFilter());
  18700. }
  18701. IIRFilterAudioSource::~IIRFilterAudioSource()
  18702. {
  18703. if (deleteInputWhenDeleted)
  18704. delete input;
  18705. }
  18706. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18707. {
  18708. for (int i = iirFilters.size(); --i >= 0;)
  18709. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18710. }
  18711. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18712. {
  18713. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18714. for (int i = iirFilters.size(); --i >= 0;)
  18715. iirFilters.getUnchecked(i)->reset();
  18716. }
  18717. void IIRFilterAudioSource::releaseResources()
  18718. {
  18719. input->releaseResources();
  18720. }
  18721. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18722. {
  18723. input->getNextAudioBlock (bufferToFill);
  18724. const int numChannels = bufferToFill.buffer->getNumChannels();
  18725. while (numChannels > iirFilters.size())
  18726. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18727. for (int i = 0; i < numChannels; ++i)
  18728. iirFilters.getUnchecked(i)
  18729. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18730. bufferToFill.numSamples);
  18731. }
  18732. END_JUCE_NAMESPACE
  18733. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18734. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18735. BEGIN_JUCE_NAMESPACE
  18736. MixerAudioSource::MixerAudioSource()
  18737. : tempBuffer (2, 0),
  18738. currentSampleRate (0.0),
  18739. bufferSizeExpected (0)
  18740. {
  18741. }
  18742. MixerAudioSource::~MixerAudioSource()
  18743. {
  18744. removeAllInputs();
  18745. }
  18746. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18747. {
  18748. if (input != 0 && ! inputs.contains (input))
  18749. {
  18750. double localRate;
  18751. int localBufferSize;
  18752. {
  18753. const ScopedLock sl (lock);
  18754. localRate = currentSampleRate;
  18755. localBufferSize = bufferSizeExpected;
  18756. }
  18757. if (localRate != 0.0)
  18758. input->prepareToPlay (localBufferSize, localRate);
  18759. const ScopedLock sl (lock);
  18760. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18761. inputs.add (input);
  18762. }
  18763. }
  18764. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18765. {
  18766. if (input != 0)
  18767. {
  18768. int index;
  18769. {
  18770. const ScopedLock sl (lock);
  18771. index = inputs.indexOf (input);
  18772. if (index >= 0)
  18773. {
  18774. inputsToDelete.shiftBits (index, 1);
  18775. inputs.remove (index);
  18776. }
  18777. }
  18778. if (index >= 0)
  18779. {
  18780. input->releaseResources();
  18781. if (deleteInput)
  18782. delete input;
  18783. }
  18784. }
  18785. }
  18786. void MixerAudioSource::removeAllInputs()
  18787. {
  18788. VoidArray inputsCopy;
  18789. BigInteger inputsToDeleteCopy;
  18790. {
  18791. const ScopedLock sl (lock);
  18792. inputsCopy = inputs;
  18793. inputsToDeleteCopy = inputsToDelete;
  18794. }
  18795. for (int i = inputsCopy.size(); --i >= 0;)
  18796. if (inputsToDeleteCopy[i])
  18797. delete (AudioSource*) inputsCopy[i];
  18798. }
  18799. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18800. {
  18801. tempBuffer.setSize (2, samplesPerBlockExpected);
  18802. const ScopedLock sl (lock);
  18803. currentSampleRate = sampleRate;
  18804. bufferSizeExpected = samplesPerBlockExpected;
  18805. for (int i = inputs.size(); --i >= 0;)
  18806. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18807. sampleRate);
  18808. }
  18809. void MixerAudioSource::releaseResources()
  18810. {
  18811. const ScopedLock sl (lock);
  18812. for (int i = inputs.size(); --i >= 0;)
  18813. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18814. tempBuffer.setSize (2, 0);
  18815. currentSampleRate = 0;
  18816. bufferSizeExpected = 0;
  18817. }
  18818. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18819. {
  18820. const ScopedLock sl (lock);
  18821. if (inputs.size() > 0)
  18822. {
  18823. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18824. if (inputs.size() > 1)
  18825. {
  18826. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18827. info.buffer->getNumSamples());
  18828. AudioSourceChannelInfo info2;
  18829. info2.buffer = &tempBuffer;
  18830. info2.numSamples = info.numSamples;
  18831. info2.startSample = 0;
  18832. for (int i = 1; i < inputs.size(); ++i)
  18833. {
  18834. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18835. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18836. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18837. }
  18838. }
  18839. }
  18840. else
  18841. {
  18842. info.clearActiveBufferRegion();
  18843. }
  18844. }
  18845. END_JUCE_NAMESPACE
  18846. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18847. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18848. BEGIN_JUCE_NAMESPACE
  18849. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18850. const bool deleteInputWhenDeleted_)
  18851. : input (inputSource),
  18852. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18853. ratio (1.0),
  18854. lastRatio (1.0),
  18855. buffer (2, 0),
  18856. sampsInBuffer (0)
  18857. {
  18858. jassert (input != 0);
  18859. }
  18860. ResamplingAudioSource::~ResamplingAudioSource()
  18861. {
  18862. if (deleteInputWhenDeleted)
  18863. delete input;
  18864. }
  18865. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18866. {
  18867. jassert (samplesInPerOutputSample > 0);
  18868. const ScopedLock sl (ratioLock);
  18869. ratio = jmax (0.0, samplesInPerOutputSample);
  18870. }
  18871. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18872. double sampleRate)
  18873. {
  18874. const ScopedLock sl (ratioLock);
  18875. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18876. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18877. buffer.clear();
  18878. sampsInBuffer = 0;
  18879. bufferPos = 0;
  18880. subSampleOffset = 0.0;
  18881. createLowPass (ratio);
  18882. resetFilters();
  18883. }
  18884. void ResamplingAudioSource::releaseResources()
  18885. {
  18886. input->releaseResources();
  18887. buffer.setSize (2, 0);
  18888. }
  18889. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18890. {
  18891. const ScopedLock sl (ratioLock);
  18892. if (lastRatio != ratio)
  18893. {
  18894. createLowPass (ratio);
  18895. lastRatio = ratio;
  18896. }
  18897. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  18898. int bufferSize = buffer.getNumSamples();
  18899. if (bufferSize < sampsNeeded + 8)
  18900. {
  18901. bufferPos %= bufferSize;
  18902. bufferSize = sampsNeeded + 32;
  18903. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  18904. }
  18905. bufferPos %= bufferSize;
  18906. int endOfBufferPos = bufferPos + sampsInBuffer;
  18907. while (sampsNeeded > sampsInBuffer)
  18908. {
  18909. endOfBufferPos %= bufferSize;
  18910. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  18911. bufferSize - endOfBufferPos);
  18912. AudioSourceChannelInfo readInfo;
  18913. readInfo.buffer = &buffer;
  18914. readInfo.numSamples = numToDo;
  18915. readInfo.startSample = endOfBufferPos;
  18916. input->getNextAudioBlock (readInfo);
  18917. if (ratio > 1.0001)
  18918. {
  18919. // for down-sampling, pre-apply the filter..
  18920. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18921. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  18922. }
  18923. sampsInBuffer += numToDo;
  18924. endOfBufferPos += numToDo;
  18925. }
  18926. float* dl = info.buffer->getSampleData (0, info.startSample);
  18927. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  18928. const float* const bl = buffer.getSampleData (0, 0);
  18929. const float* const br = buffer.getSampleData (1, 0);
  18930. int nextPos = (bufferPos + 1) % bufferSize;
  18931. for (int m = info.numSamples; --m >= 0;)
  18932. {
  18933. const float alpha = (float) subSampleOffset;
  18934. const float invAlpha = 1.0f - alpha;
  18935. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  18936. if (dr != 0)
  18937. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  18938. subSampleOffset += ratio;
  18939. jassert (sampsInBuffer > 0);
  18940. while (subSampleOffset >= 1.0)
  18941. {
  18942. if (++bufferPos >= bufferSize)
  18943. bufferPos = 0;
  18944. --sampsInBuffer;
  18945. nextPos = (bufferPos + 1) % bufferSize;
  18946. subSampleOffset -= 1.0;
  18947. }
  18948. }
  18949. if (ratio < 0.9999)
  18950. {
  18951. // for up-sampling, apply the filter after transposing..
  18952. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18953. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  18954. }
  18955. else if (ratio <= 1.0001)
  18956. {
  18957. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  18958. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18959. {
  18960. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  18961. FilterState& fs = filterStates[i];
  18962. if (info.numSamples > 1)
  18963. {
  18964. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  18965. }
  18966. else
  18967. {
  18968. fs.y2 = fs.y1;
  18969. fs.x2 = fs.x1;
  18970. }
  18971. fs.y1 = fs.x1 = *endOfBuffer;
  18972. }
  18973. }
  18974. jassert (sampsInBuffer >= 0);
  18975. }
  18976. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  18977. {
  18978. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  18979. : 0.5 * frequencyRatio;
  18980. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  18981. const double nSquared = n * n;
  18982. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  18983. setFilterCoefficients (c1,
  18984. c1 * 2.0f,
  18985. c1,
  18986. 1.0,
  18987. c1 * 2.0 * (1.0 - nSquared),
  18988. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  18989. }
  18990. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  18991. {
  18992. const double a = 1.0 / c4;
  18993. c1 *= a;
  18994. c2 *= a;
  18995. c3 *= a;
  18996. c5 *= a;
  18997. c6 *= a;
  18998. coefficients[0] = c1;
  18999. coefficients[1] = c2;
  19000. coefficients[2] = c3;
  19001. coefficients[3] = c4;
  19002. coefficients[4] = c5;
  19003. coefficients[5] = c6;
  19004. }
  19005. void ResamplingAudioSource::resetFilters()
  19006. {
  19007. zeromem (filterStates, sizeof (filterStates));
  19008. }
  19009. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19010. {
  19011. while (--num >= 0)
  19012. {
  19013. const double in = *samples;
  19014. double out = coefficients[0] * in
  19015. + coefficients[1] * fs.x1
  19016. + coefficients[2] * fs.x2
  19017. - coefficients[4] * fs.y1
  19018. - coefficients[5] * fs.y2;
  19019. #if JUCE_INTEL
  19020. if (! (out < -1.0e-8 || out > 1.0e-8))
  19021. out = 0;
  19022. #endif
  19023. fs.x2 = fs.x1;
  19024. fs.x1 = in;
  19025. fs.y2 = fs.y1;
  19026. fs.y1 = out;
  19027. *samples++ = (float) out;
  19028. }
  19029. }
  19030. END_JUCE_NAMESPACE
  19031. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19032. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19033. BEGIN_JUCE_NAMESPACE
  19034. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19035. : frequency (1000.0),
  19036. sampleRate (44100.0),
  19037. currentPhase (0.0),
  19038. phasePerSample (0.0),
  19039. amplitude (0.5f)
  19040. {
  19041. }
  19042. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19043. {
  19044. }
  19045. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19046. {
  19047. amplitude = newAmplitude;
  19048. }
  19049. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19050. {
  19051. frequency = newFrequencyHz;
  19052. phasePerSample = 0.0;
  19053. }
  19054. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19055. double sampleRate_)
  19056. {
  19057. currentPhase = 0.0;
  19058. phasePerSample = 0.0;
  19059. sampleRate = sampleRate_;
  19060. }
  19061. void ToneGeneratorAudioSource::releaseResources()
  19062. {
  19063. }
  19064. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19065. {
  19066. if (phasePerSample == 0.0)
  19067. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19068. for (int i = 0; i < info.numSamples; ++i)
  19069. {
  19070. const float sample = amplitude * (float) sin (currentPhase);
  19071. currentPhase += phasePerSample;
  19072. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19073. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19074. }
  19075. }
  19076. END_JUCE_NAMESPACE
  19077. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19078. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19079. BEGIN_JUCE_NAMESPACE
  19080. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19081. : sampleRate (0),
  19082. bufferSize (0),
  19083. useDefaultInputChannels (true),
  19084. useDefaultOutputChannels (true)
  19085. {
  19086. }
  19087. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19088. {
  19089. return outputDeviceName == other.outputDeviceName
  19090. && inputDeviceName == other.inputDeviceName
  19091. && sampleRate == other.sampleRate
  19092. && bufferSize == other.bufferSize
  19093. && inputChannels == other.inputChannels
  19094. && useDefaultInputChannels == other.useDefaultInputChannels
  19095. && outputChannels == other.outputChannels
  19096. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19097. }
  19098. AudioDeviceManager::AudioDeviceManager()
  19099. : currentAudioDevice (0),
  19100. numInputChansNeeded (0),
  19101. numOutputChansNeeded (2),
  19102. listNeedsScanning (true),
  19103. useInputNames (false),
  19104. inputLevelMeasurementEnabledCount (0),
  19105. inputLevel (0),
  19106. tempBuffer (2, 2),
  19107. defaultMidiOutput (0),
  19108. cpuUsageMs (0),
  19109. timeToCpuScale (0)
  19110. {
  19111. callbackHandler.owner = this;
  19112. }
  19113. AudioDeviceManager::~AudioDeviceManager()
  19114. {
  19115. currentAudioDevice = 0;
  19116. defaultMidiOutput = 0;
  19117. }
  19118. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19119. {
  19120. if (availableDeviceTypes.size() == 0)
  19121. {
  19122. createAudioDeviceTypes (availableDeviceTypes);
  19123. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19124. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19125. if (availableDeviceTypes.size() > 0)
  19126. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19127. }
  19128. }
  19129. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19130. {
  19131. scanDevicesIfNeeded();
  19132. return availableDeviceTypes;
  19133. }
  19134. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19135. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19136. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19137. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19138. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19139. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19140. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19141. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19142. {
  19143. #if JUCE_WINDOWS
  19144. #if JUCE_WASAPI
  19145. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19146. list.add (juce_createAudioIODeviceType_WASAPI());
  19147. #endif
  19148. #if JUCE_DIRECTSOUND
  19149. list.add (juce_createAudioIODeviceType_DirectSound());
  19150. #endif
  19151. #if JUCE_ASIO
  19152. list.add (juce_createAudioIODeviceType_ASIO());
  19153. #endif
  19154. #endif
  19155. #if JUCE_MAC
  19156. list.add (juce_createAudioIODeviceType_CoreAudio());
  19157. #endif
  19158. #if JUCE_IPHONE
  19159. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19160. #endif
  19161. #if JUCE_LINUX && JUCE_ALSA
  19162. list.add (juce_createAudioIODeviceType_ALSA());
  19163. #endif
  19164. #if JUCE_LINUX && JUCE_JACK
  19165. list.add (juce_createAudioIODeviceType_JACK());
  19166. #endif
  19167. }
  19168. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19169. const int numOutputChannelsNeeded,
  19170. const XmlElement* const e,
  19171. const bool selectDefaultDeviceOnFailure,
  19172. const String& preferredDefaultDeviceName,
  19173. const AudioDeviceSetup* preferredSetupOptions)
  19174. {
  19175. scanDevicesIfNeeded();
  19176. numInputChansNeeded = numInputChannelsNeeded;
  19177. numOutputChansNeeded = numOutputChannelsNeeded;
  19178. if (e != 0 && e->hasTagName ("DEVICESETUP"))
  19179. {
  19180. lastExplicitSettings = new XmlElement (*e);
  19181. String error;
  19182. AudioDeviceSetup setup;
  19183. if (preferredSetupOptions != 0)
  19184. setup = *preferredSetupOptions;
  19185. if (e->getStringAttribute ("audioDeviceName").isNotEmpty())
  19186. {
  19187. setup.inputDeviceName = setup.outputDeviceName
  19188. = e->getStringAttribute ("audioDeviceName");
  19189. }
  19190. else
  19191. {
  19192. setup.inputDeviceName = e->getStringAttribute ("audioInputDeviceName");
  19193. setup.outputDeviceName = e->getStringAttribute ("audioOutputDeviceName");
  19194. }
  19195. currentDeviceType = e->getStringAttribute ("deviceType");
  19196. if (currentDeviceType.isEmpty())
  19197. {
  19198. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19199. if (type != 0)
  19200. currentDeviceType = type->getTypeName();
  19201. else if (availableDeviceTypes.size() > 0)
  19202. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19203. }
  19204. setup.bufferSize = e->getIntAttribute ("audioDeviceBufferSize");
  19205. setup.sampleRate = e->getDoubleAttribute ("audioDeviceRate");
  19206. setup.inputChannels.parseString (e->getStringAttribute ("audioDeviceInChans", "11"), 2);
  19207. setup.outputChannels.parseString (e->getStringAttribute ("audioDeviceOutChans", "11"), 2);
  19208. setup.useDefaultInputChannels = ! e->hasAttribute ("audioDeviceInChans");
  19209. setup.useDefaultOutputChannels = ! e->hasAttribute ("audioDeviceOutChans");
  19210. error = setAudioDeviceSetup (setup, true);
  19211. midiInsFromXml.clear();
  19212. forEachXmlChildElementWithTagName (*e, c, "MIDIINPUT")
  19213. midiInsFromXml.add (c->getStringAttribute ("name"));
  19214. const StringArray allMidiIns (MidiInput::getDevices());
  19215. for (int i = allMidiIns.size(); --i >= 0;)
  19216. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19217. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19218. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19219. false, preferredDefaultDeviceName);
  19220. setDefaultMidiOutput (e->getStringAttribute ("defaultMidiOutput"));
  19221. return error;
  19222. }
  19223. else
  19224. {
  19225. AudioDeviceSetup setup;
  19226. if (preferredSetupOptions != 0)
  19227. {
  19228. setup = *preferredSetupOptions;
  19229. }
  19230. else if (preferredDefaultDeviceName.isNotEmpty())
  19231. {
  19232. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19233. {
  19234. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19235. StringArray outs (type->getDeviceNames (false));
  19236. int i;
  19237. for (i = 0; i < outs.size(); ++i)
  19238. {
  19239. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19240. {
  19241. setup.outputDeviceName = outs[i];
  19242. break;
  19243. }
  19244. }
  19245. StringArray ins (type->getDeviceNames (true));
  19246. for (i = 0; i < ins.size(); ++i)
  19247. {
  19248. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19249. {
  19250. setup.inputDeviceName = ins[i];
  19251. break;
  19252. }
  19253. }
  19254. }
  19255. }
  19256. insertDefaultDeviceNames (setup);
  19257. return setAudioDeviceSetup (setup, false);
  19258. }
  19259. }
  19260. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19261. {
  19262. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19263. if (type != 0)
  19264. {
  19265. if (setup.outputDeviceName.isEmpty())
  19266. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19267. if (setup.inputDeviceName.isEmpty())
  19268. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19269. }
  19270. }
  19271. XmlElement* AudioDeviceManager::createStateXml() const
  19272. {
  19273. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19274. }
  19275. void AudioDeviceManager::scanDevicesIfNeeded()
  19276. {
  19277. if (listNeedsScanning)
  19278. {
  19279. listNeedsScanning = false;
  19280. createDeviceTypesIfNeeded();
  19281. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19282. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19283. }
  19284. }
  19285. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19286. {
  19287. scanDevicesIfNeeded();
  19288. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19289. {
  19290. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19291. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19292. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19293. {
  19294. return type;
  19295. }
  19296. }
  19297. return 0;
  19298. }
  19299. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19300. {
  19301. setup = currentSetup;
  19302. }
  19303. void AudioDeviceManager::deleteCurrentDevice()
  19304. {
  19305. currentAudioDevice = 0;
  19306. currentSetup.inputDeviceName = String::empty;
  19307. currentSetup.outputDeviceName = String::empty;
  19308. }
  19309. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19310. const bool treatAsChosenDevice)
  19311. {
  19312. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19313. {
  19314. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19315. && currentDeviceType != type)
  19316. {
  19317. currentDeviceType = type;
  19318. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19319. insertDefaultDeviceNames (s);
  19320. setAudioDeviceSetup (s, treatAsChosenDevice);
  19321. sendChangeMessage (this);
  19322. break;
  19323. }
  19324. }
  19325. }
  19326. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19327. {
  19328. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19329. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19330. return availableDeviceTypes[i];
  19331. return availableDeviceTypes[0];
  19332. }
  19333. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19334. const bool treatAsChosenDevice)
  19335. {
  19336. jassert (&newSetup != &currentSetup); // this will have no effect
  19337. if (newSetup == currentSetup && currentAudioDevice != 0)
  19338. return String::empty;
  19339. if (! (newSetup == currentSetup))
  19340. sendChangeMessage (this);
  19341. stopDevice();
  19342. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19343. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19344. String error;
  19345. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19346. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19347. {
  19348. deleteCurrentDevice();
  19349. if (treatAsChosenDevice)
  19350. updateXml();
  19351. return String::empty;
  19352. }
  19353. if (currentSetup.inputDeviceName != newInputDeviceName
  19354. || currentSetup.outputDeviceName != newOutputDeviceName
  19355. || currentAudioDevice == 0)
  19356. {
  19357. deleteCurrentDevice();
  19358. scanDevicesIfNeeded();
  19359. if (newOutputDeviceName.isNotEmpty()
  19360. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19361. {
  19362. return "No such device: " + newOutputDeviceName;
  19363. }
  19364. if (newInputDeviceName.isNotEmpty()
  19365. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19366. {
  19367. return "No such device: " + newInputDeviceName;
  19368. }
  19369. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19370. if (currentAudioDevice == 0)
  19371. error = "Can't open the audio device!\n\nThis may be because another application is currently using the same device - if so, you should close any other applications and try again!";
  19372. else
  19373. error = currentAudioDevice->getLastError();
  19374. if (error.isNotEmpty())
  19375. {
  19376. deleteCurrentDevice();
  19377. return error;
  19378. }
  19379. if (newSetup.useDefaultInputChannels)
  19380. {
  19381. inputChannels.clear();
  19382. inputChannels.setRange (0, numInputChansNeeded, true);
  19383. }
  19384. if (newSetup.useDefaultOutputChannels)
  19385. {
  19386. outputChannels.clear();
  19387. outputChannels.setRange (0, numOutputChansNeeded, true);
  19388. }
  19389. if (newInputDeviceName.isEmpty())
  19390. inputChannels.clear();
  19391. if (newOutputDeviceName.isEmpty())
  19392. outputChannels.clear();
  19393. }
  19394. if (! newSetup.useDefaultInputChannels)
  19395. inputChannels = newSetup.inputChannels;
  19396. if (! newSetup.useDefaultOutputChannels)
  19397. outputChannels = newSetup.outputChannels;
  19398. currentSetup = newSetup;
  19399. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19400. error = currentAudioDevice->open (inputChannels,
  19401. outputChannels,
  19402. currentSetup.sampleRate,
  19403. currentSetup.bufferSize);
  19404. if (error.isEmpty())
  19405. {
  19406. currentDeviceType = currentAudioDevice->getTypeName();
  19407. currentAudioDevice->start (&callbackHandler);
  19408. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19409. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19410. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19411. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19412. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19413. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19414. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19415. if (treatAsChosenDevice)
  19416. updateXml();
  19417. }
  19418. else
  19419. {
  19420. deleteCurrentDevice();
  19421. }
  19422. return error;
  19423. }
  19424. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19425. {
  19426. jassert (currentAudioDevice != 0);
  19427. if (rate > 0)
  19428. {
  19429. bool ok = false;
  19430. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19431. {
  19432. const double sr = currentAudioDevice->getSampleRate (i);
  19433. if (sr == rate)
  19434. ok = true;
  19435. }
  19436. if (! ok)
  19437. rate = 0;
  19438. }
  19439. if (rate == 0)
  19440. {
  19441. double lowestAbove44 = 0.0;
  19442. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19443. {
  19444. const double sr = currentAudioDevice->getSampleRate (i);
  19445. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19446. lowestAbove44 = sr;
  19447. }
  19448. if (lowestAbove44 == 0.0)
  19449. rate = currentAudioDevice->getSampleRate (0);
  19450. else
  19451. rate = lowestAbove44;
  19452. }
  19453. return rate;
  19454. }
  19455. void AudioDeviceManager::stopDevice()
  19456. {
  19457. if (currentAudioDevice != 0)
  19458. currentAudioDevice->stop();
  19459. testSound = 0;
  19460. }
  19461. void AudioDeviceManager::closeAudioDevice()
  19462. {
  19463. stopDevice();
  19464. currentAudioDevice = 0;
  19465. }
  19466. void AudioDeviceManager::restartLastAudioDevice()
  19467. {
  19468. if (currentAudioDevice == 0)
  19469. {
  19470. if (currentSetup.inputDeviceName.isEmpty()
  19471. && currentSetup.outputDeviceName.isEmpty())
  19472. {
  19473. // This method will only reload the last device that was running
  19474. // before closeAudioDevice() was called - you need to actually open
  19475. // one first, with setAudioDevice().
  19476. jassertfalse
  19477. return;
  19478. }
  19479. AudioDeviceSetup s (currentSetup);
  19480. setAudioDeviceSetup (s, false);
  19481. }
  19482. }
  19483. void AudioDeviceManager::updateXml()
  19484. {
  19485. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19486. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19487. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19488. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19489. if (currentAudioDevice != 0)
  19490. {
  19491. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19492. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19493. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19494. if (! currentSetup.useDefaultInputChannels)
  19495. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19496. if (! currentSetup.useDefaultOutputChannels)
  19497. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19498. }
  19499. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19500. {
  19501. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19502. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19503. }
  19504. if (midiInsFromXml.size() > 0)
  19505. {
  19506. // Add any midi devices that have been enabled before, but which aren't currently
  19507. // open because the device has been disconnected.
  19508. const StringArray availableMidiDevices (MidiInput::getDevices());
  19509. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19510. {
  19511. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19512. {
  19513. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19514. m->setAttribute ("name", midiInsFromXml[i]);
  19515. }
  19516. }
  19517. }
  19518. if (defaultMidiOutputName.isNotEmpty())
  19519. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19520. }
  19521. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19522. {
  19523. {
  19524. const ScopedLock sl (audioCallbackLock);
  19525. if (callbacks.contains (newCallback))
  19526. return;
  19527. }
  19528. if (currentAudioDevice != 0 && newCallback != 0)
  19529. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19530. const ScopedLock sl (audioCallbackLock);
  19531. callbacks.add (newCallback);
  19532. }
  19533. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19534. {
  19535. if (callback != 0)
  19536. {
  19537. bool needsDeinitialising = currentAudioDevice != 0;
  19538. {
  19539. const ScopedLock sl (audioCallbackLock);
  19540. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19541. callbacks.removeValue (callback);
  19542. }
  19543. if (needsDeinitialising)
  19544. callback->audioDeviceStopped();
  19545. }
  19546. }
  19547. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19548. int numInputChannels,
  19549. float** outputChannelData,
  19550. int numOutputChannels,
  19551. int numSamples)
  19552. {
  19553. const ScopedLock sl (audioCallbackLock);
  19554. if (inputLevelMeasurementEnabledCount > 0)
  19555. {
  19556. for (int j = 0; j < numSamples; ++j)
  19557. {
  19558. float s = 0;
  19559. for (int i = 0; i < numInputChannels; ++i)
  19560. s += fabsf (inputChannelData[i][j]);
  19561. s /= numInputChannels;
  19562. const double decayFactor = 0.99992;
  19563. if (s > inputLevel)
  19564. inputLevel = s;
  19565. else if (inputLevel > 0.001f)
  19566. inputLevel *= decayFactor;
  19567. else
  19568. inputLevel = 0;
  19569. }
  19570. }
  19571. if (callbacks.size() > 0)
  19572. {
  19573. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19574. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19575. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19576. outputChannelData, numOutputChannels, numSamples);
  19577. float** const tempChans = tempBuffer.getArrayOfChannels();
  19578. for (int i = callbacks.size(); --i > 0;)
  19579. {
  19580. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19581. tempChans, numOutputChannels, numSamples);
  19582. for (int chan = 0; chan < numOutputChannels; ++chan)
  19583. {
  19584. const float* const src = tempChans [chan];
  19585. float* const dst = outputChannelData [chan];
  19586. if (src != 0 && dst != 0)
  19587. for (int j = 0; j < numSamples; ++j)
  19588. dst[j] += src[j];
  19589. }
  19590. }
  19591. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19592. const double filterAmount = 0.2;
  19593. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19594. }
  19595. else
  19596. {
  19597. for (int i = 0; i < numOutputChannels; ++i)
  19598. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19599. }
  19600. if (testSound != 0)
  19601. {
  19602. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19603. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19604. for (int i = 0; i < numOutputChannels; ++i)
  19605. for (int j = 0; j < numSamps; ++j)
  19606. outputChannelData [i][j] += src[j];
  19607. testSoundPosition += numSamps;
  19608. if (testSoundPosition >= testSound->getNumSamples())
  19609. testSound = 0;
  19610. }
  19611. }
  19612. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19613. {
  19614. cpuUsageMs = 0;
  19615. const double sampleRate = device->getCurrentSampleRate();
  19616. const int blockSize = device->getCurrentBufferSizeSamples();
  19617. if (sampleRate > 0.0 && blockSize > 0)
  19618. {
  19619. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19620. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19621. }
  19622. {
  19623. const ScopedLock sl (audioCallbackLock);
  19624. for (int i = callbacks.size(); --i >= 0;)
  19625. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19626. }
  19627. sendChangeMessage (this);
  19628. }
  19629. void AudioDeviceManager::audioDeviceStoppedInt()
  19630. {
  19631. cpuUsageMs = 0;
  19632. timeToCpuScale = 0;
  19633. sendChangeMessage (this);
  19634. const ScopedLock sl (audioCallbackLock);
  19635. for (int i = callbacks.size(); --i >= 0;)
  19636. callbacks.getUnchecked(i)->audioDeviceStopped();
  19637. }
  19638. double AudioDeviceManager::getCpuUsage() const
  19639. {
  19640. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19641. }
  19642. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19643. const bool enabled)
  19644. {
  19645. if (enabled != isMidiInputEnabled (name))
  19646. {
  19647. if (enabled)
  19648. {
  19649. const int index = MidiInput::getDevices().indexOf (name);
  19650. if (index >= 0)
  19651. {
  19652. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19653. if (min != 0)
  19654. {
  19655. enabledMidiInputs.add (min);
  19656. min->start();
  19657. }
  19658. }
  19659. }
  19660. else
  19661. {
  19662. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19663. if (enabledMidiInputs[i]->getName() == name)
  19664. enabledMidiInputs.remove (i);
  19665. }
  19666. updateXml();
  19667. sendChangeMessage (this);
  19668. }
  19669. }
  19670. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19671. {
  19672. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19673. if (enabledMidiInputs[i]->getName() == name)
  19674. return true;
  19675. return false;
  19676. }
  19677. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19678. MidiInputCallback* callback)
  19679. {
  19680. removeMidiInputCallback (name, callback);
  19681. if (name.isEmpty())
  19682. {
  19683. midiCallbacks.add (callback);
  19684. midiCallbackDevices.add (0);
  19685. }
  19686. else
  19687. {
  19688. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19689. {
  19690. if (enabledMidiInputs[i]->getName() == name)
  19691. {
  19692. const ScopedLock sl (midiCallbackLock);
  19693. midiCallbacks.add (callback);
  19694. midiCallbackDevices.add (enabledMidiInputs[i]);
  19695. break;
  19696. }
  19697. }
  19698. }
  19699. }
  19700. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19701. MidiInputCallback* /*callback*/)
  19702. {
  19703. const ScopedLock sl (midiCallbackLock);
  19704. for (int i = midiCallbacks.size(); --i >= 0;)
  19705. {
  19706. String devName;
  19707. if (midiCallbackDevices.getUnchecked(i) != 0)
  19708. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19709. if (devName == name)
  19710. {
  19711. midiCallbacks.remove (i);
  19712. midiCallbackDevices.remove (i);
  19713. }
  19714. }
  19715. }
  19716. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19717. const MidiMessage& message)
  19718. {
  19719. if (! message.isActiveSense())
  19720. {
  19721. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19722. const ScopedLock sl (midiCallbackLock);
  19723. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19724. {
  19725. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19726. if (md == source || (md == 0 && isDefaultSource))
  19727. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19728. }
  19729. }
  19730. }
  19731. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19732. {
  19733. if (defaultMidiOutputName != deviceName)
  19734. {
  19735. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19736. {
  19737. const ScopedLock sl (audioCallbackLock);
  19738. oldCallbacks = callbacks;
  19739. callbacks.clear();
  19740. }
  19741. if (currentAudioDevice != 0)
  19742. for (int i = oldCallbacks.size(); --i >= 0;)
  19743. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19744. defaultMidiOutput = 0;
  19745. defaultMidiOutputName = deviceName;
  19746. if (deviceName.isNotEmpty())
  19747. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19748. if (currentAudioDevice != 0)
  19749. for (int i = oldCallbacks.size(); --i >= 0;)
  19750. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19751. {
  19752. const ScopedLock sl (audioCallbackLock);
  19753. callbacks = oldCallbacks;
  19754. }
  19755. updateXml();
  19756. sendChangeMessage (this);
  19757. }
  19758. }
  19759. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19760. int numInputChannels,
  19761. float** outputChannelData,
  19762. int numOutputChannels,
  19763. int numSamples)
  19764. {
  19765. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19766. }
  19767. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19768. {
  19769. owner->audioDeviceAboutToStartInt (device);
  19770. }
  19771. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19772. {
  19773. owner->audioDeviceStoppedInt();
  19774. }
  19775. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19776. {
  19777. owner->handleIncomingMidiMessageInt (source, message);
  19778. }
  19779. void AudioDeviceManager::playTestSound()
  19780. {
  19781. { // cunningly nested to swap, unlock and delete in that order.
  19782. ScopedPointer <AudioSampleBuffer> oldSound;
  19783. {
  19784. const ScopedLock sl (audioCallbackLock);
  19785. oldSound = testSound;
  19786. }
  19787. }
  19788. testSoundPosition = 0;
  19789. if (currentAudioDevice != 0)
  19790. {
  19791. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19792. const int soundLength = (int) sampleRate;
  19793. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19794. float* samples = newSound->getSampleData (0);
  19795. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19796. const float amplitude = 0.5f;
  19797. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19798. for (int i = 0; i < soundLength; ++i)
  19799. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19800. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19801. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19802. const ScopedLock sl (audioCallbackLock);
  19803. testSound = newSound;
  19804. }
  19805. }
  19806. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19807. {
  19808. const ScopedLock sl (audioCallbackLock);
  19809. if (enableMeasurement)
  19810. ++inputLevelMeasurementEnabledCount;
  19811. else
  19812. --inputLevelMeasurementEnabledCount;
  19813. inputLevel = 0;
  19814. }
  19815. double AudioDeviceManager::getCurrentInputLevel() const
  19816. {
  19817. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19818. return inputLevel;
  19819. }
  19820. END_JUCE_NAMESPACE
  19821. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19822. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19823. BEGIN_JUCE_NAMESPACE
  19824. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19825. : name (deviceName),
  19826. typeName (typeName_)
  19827. {
  19828. }
  19829. AudioIODevice::~AudioIODevice()
  19830. {
  19831. }
  19832. bool AudioIODevice::hasControlPanel() const
  19833. {
  19834. return false;
  19835. }
  19836. bool AudioIODevice::showControlPanel()
  19837. {
  19838. jassertfalse // this should only be called for devices which return true from
  19839. // their hasControlPanel() method.
  19840. return false;
  19841. }
  19842. END_JUCE_NAMESPACE
  19843. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19844. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19845. BEGIN_JUCE_NAMESPACE
  19846. AudioIODeviceType::AudioIODeviceType (const String& name)
  19847. : typeName (name)
  19848. {
  19849. }
  19850. AudioIODeviceType::~AudioIODeviceType()
  19851. {
  19852. }
  19853. END_JUCE_NAMESPACE
  19854. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19855. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19856. BEGIN_JUCE_NAMESPACE
  19857. MidiOutput::MidiOutput()
  19858. : Thread ("midi out"),
  19859. internal (0),
  19860. firstMessage (0)
  19861. {
  19862. }
  19863. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19864. const double sampleNumber)
  19865. : message (data, len, sampleNumber)
  19866. {
  19867. }
  19868. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19869. const double millisecondCounterToStartAt,
  19870. double samplesPerSecondForBuffer)
  19871. {
  19872. // You've got to call startBackgroundThread() for this to actually work..
  19873. jassert (isThreadRunning());
  19874. // this needs to be a value in the future - RTFM for this method!
  19875. jassert (millisecondCounterToStartAt > 0);
  19876. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19877. MidiBuffer::Iterator i (buffer);
  19878. const uint8* data;
  19879. int len, time;
  19880. while (i.getNextEvent (data, len, time))
  19881. {
  19882. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19883. PendingMessage* const m
  19884. = new PendingMessage (data, len, eventTime);
  19885. const ScopedLock sl (lock);
  19886. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19887. {
  19888. m->next = firstMessage;
  19889. firstMessage = m;
  19890. }
  19891. else
  19892. {
  19893. PendingMessage* mm = firstMessage;
  19894. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19895. mm = mm->next;
  19896. m->next = mm->next;
  19897. mm->next = m;
  19898. }
  19899. }
  19900. notify();
  19901. }
  19902. void MidiOutput::clearAllPendingMessages()
  19903. {
  19904. const ScopedLock sl (lock);
  19905. while (firstMessage != 0)
  19906. {
  19907. PendingMessage* const m = firstMessage;
  19908. firstMessage = firstMessage->next;
  19909. delete m;
  19910. }
  19911. }
  19912. void MidiOutput::startBackgroundThread()
  19913. {
  19914. startThread (9);
  19915. }
  19916. void MidiOutput::stopBackgroundThread()
  19917. {
  19918. stopThread (5000);
  19919. }
  19920. void MidiOutput::run()
  19921. {
  19922. while (! threadShouldExit())
  19923. {
  19924. uint32 now = Time::getMillisecondCounter();
  19925. uint32 eventTime = 0;
  19926. uint32 timeToWait = 500;
  19927. PendingMessage* message;
  19928. {
  19929. const ScopedLock sl (lock);
  19930. message = firstMessage;
  19931. if (message != 0)
  19932. {
  19933. eventTime = roundToInt (message->message.getTimeStamp());
  19934. if (eventTime > now + 20)
  19935. {
  19936. timeToWait = eventTime - (now + 20);
  19937. message = 0;
  19938. }
  19939. else
  19940. {
  19941. firstMessage = message->next;
  19942. }
  19943. }
  19944. }
  19945. if (message != 0)
  19946. {
  19947. if (eventTime > now)
  19948. {
  19949. Time::waitForMillisecondCounter (eventTime);
  19950. if (threadShouldExit())
  19951. break;
  19952. }
  19953. if (eventTime > now - 200)
  19954. sendMessageNow (message->message);
  19955. delete message;
  19956. }
  19957. else
  19958. {
  19959. jassert (timeToWait < 1000 * 30);
  19960. wait (timeToWait);
  19961. }
  19962. }
  19963. clearAllPendingMessages();
  19964. }
  19965. END_JUCE_NAMESPACE
  19966. /*** End of inlined file: juce_MidiOutput.cpp ***/
  19967. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  19968. BEGIN_JUCE_NAMESPACE
  19969. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19970. {
  19971. const double maxVal = (double) 0x7fff;
  19972. char* intData = static_cast <char*> (dest);
  19973. if (dest != (void*) source || destBytesPerSample <= 4)
  19974. {
  19975. for (int i = 0; i < numSamples; ++i)
  19976. {
  19977. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19978. intData += destBytesPerSample;
  19979. }
  19980. }
  19981. else
  19982. {
  19983. intData += destBytesPerSample * numSamples;
  19984. for (int i = numSamples; --i >= 0;)
  19985. {
  19986. intData -= destBytesPerSample;
  19987. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19988. }
  19989. }
  19990. }
  19991. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19992. {
  19993. const double maxVal = (double) 0x7fff;
  19994. char* intData = static_cast <char*> (dest);
  19995. if (dest != (void*) source || destBytesPerSample <= 4)
  19996. {
  19997. for (int i = 0; i < numSamples; ++i)
  19998. {
  19999. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20000. intData += destBytesPerSample;
  20001. }
  20002. }
  20003. else
  20004. {
  20005. intData += destBytesPerSample * numSamples;
  20006. for (int i = numSamples; --i >= 0;)
  20007. {
  20008. intData -= destBytesPerSample;
  20009. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20010. }
  20011. }
  20012. }
  20013. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20014. {
  20015. const double maxVal = (double) 0x7fffff;
  20016. char* intData = static_cast <char*> (dest);
  20017. if (dest != (void*) source || destBytesPerSample <= 4)
  20018. {
  20019. for (int i = 0; i < numSamples; ++i)
  20020. {
  20021. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20022. intData += destBytesPerSample;
  20023. }
  20024. }
  20025. else
  20026. {
  20027. intData += destBytesPerSample * numSamples;
  20028. for (int i = numSamples; --i >= 0;)
  20029. {
  20030. intData -= destBytesPerSample;
  20031. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20032. }
  20033. }
  20034. }
  20035. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20036. {
  20037. const double maxVal = (double) 0x7fffff;
  20038. char* intData = static_cast <char*> (dest);
  20039. if (dest != (void*) source || destBytesPerSample <= 4)
  20040. {
  20041. for (int i = 0; i < numSamples; ++i)
  20042. {
  20043. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20044. intData += destBytesPerSample;
  20045. }
  20046. }
  20047. else
  20048. {
  20049. intData += destBytesPerSample * numSamples;
  20050. for (int i = numSamples; --i >= 0;)
  20051. {
  20052. intData -= destBytesPerSample;
  20053. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20054. }
  20055. }
  20056. }
  20057. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20058. {
  20059. const double maxVal = (double) 0x7fffffff;
  20060. char* intData = static_cast <char*> (dest);
  20061. if (dest != (void*) source || destBytesPerSample <= 4)
  20062. {
  20063. for (int i = 0; i < numSamples; ++i)
  20064. {
  20065. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20066. intData += destBytesPerSample;
  20067. }
  20068. }
  20069. else
  20070. {
  20071. intData += destBytesPerSample * numSamples;
  20072. for (int i = numSamples; --i >= 0;)
  20073. {
  20074. intData -= destBytesPerSample;
  20075. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20076. }
  20077. }
  20078. }
  20079. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20080. {
  20081. const double maxVal = (double) 0x7fffffff;
  20082. char* intData = static_cast <char*> (dest);
  20083. if (dest != (void*) source || destBytesPerSample <= 4)
  20084. {
  20085. for (int i = 0; i < numSamples; ++i)
  20086. {
  20087. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20088. intData += destBytesPerSample;
  20089. }
  20090. }
  20091. else
  20092. {
  20093. intData += destBytesPerSample * numSamples;
  20094. for (int i = numSamples; --i >= 0;)
  20095. {
  20096. intData -= destBytesPerSample;
  20097. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20098. }
  20099. }
  20100. }
  20101. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20102. {
  20103. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20104. char* d = static_cast <char*> (dest);
  20105. for (int i = 0; i < numSamples; ++i)
  20106. {
  20107. *(float*) d = source[i];
  20108. #if JUCE_BIG_ENDIAN
  20109. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20110. #endif
  20111. d += destBytesPerSample;
  20112. }
  20113. }
  20114. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20115. {
  20116. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20117. char* d = static_cast <char*> (dest);
  20118. for (int i = 0; i < numSamples; ++i)
  20119. {
  20120. *(float*) d = source[i];
  20121. #if JUCE_LITTLE_ENDIAN
  20122. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20123. #endif
  20124. d += destBytesPerSample;
  20125. }
  20126. }
  20127. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20128. {
  20129. const float scale = 1.0f / 0x7fff;
  20130. const char* intData = static_cast <const char*> (source);
  20131. if (source != (void*) dest || srcBytesPerSample >= 4)
  20132. {
  20133. for (int i = 0; i < numSamples; ++i)
  20134. {
  20135. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20136. intData += srcBytesPerSample;
  20137. }
  20138. }
  20139. else
  20140. {
  20141. intData += srcBytesPerSample * numSamples;
  20142. for (int i = numSamples; --i >= 0;)
  20143. {
  20144. intData -= srcBytesPerSample;
  20145. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20146. }
  20147. }
  20148. }
  20149. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20150. {
  20151. const float scale = 1.0f / 0x7fff;
  20152. const char* intData = static_cast <const char*> (source);
  20153. if (source != (void*) dest || srcBytesPerSample >= 4)
  20154. {
  20155. for (int i = 0; i < numSamples; ++i)
  20156. {
  20157. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20158. intData += srcBytesPerSample;
  20159. }
  20160. }
  20161. else
  20162. {
  20163. intData += srcBytesPerSample * numSamples;
  20164. for (int i = numSamples; --i >= 0;)
  20165. {
  20166. intData -= srcBytesPerSample;
  20167. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20168. }
  20169. }
  20170. }
  20171. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20172. {
  20173. const float scale = 1.0f / 0x7fffff;
  20174. const char* intData = static_cast <const char*> (source);
  20175. if (source != (void*) dest || srcBytesPerSample >= 4)
  20176. {
  20177. for (int i = 0; i < numSamples; ++i)
  20178. {
  20179. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20180. intData += srcBytesPerSample;
  20181. }
  20182. }
  20183. else
  20184. {
  20185. intData += srcBytesPerSample * numSamples;
  20186. for (int i = numSamples; --i >= 0;)
  20187. {
  20188. intData -= srcBytesPerSample;
  20189. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20190. }
  20191. }
  20192. }
  20193. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20194. {
  20195. const float scale = 1.0f / 0x7fffff;
  20196. const char* intData = static_cast <const char*> (source);
  20197. if (source != (void*) dest || srcBytesPerSample >= 4)
  20198. {
  20199. for (int i = 0; i < numSamples; ++i)
  20200. {
  20201. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20202. intData += srcBytesPerSample;
  20203. }
  20204. }
  20205. else
  20206. {
  20207. intData += srcBytesPerSample * numSamples;
  20208. for (int i = numSamples; --i >= 0;)
  20209. {
  20210. intData -= srcBytesPerSample;
  20211. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20212. }
  20213. }
  20214. }
  20215. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20216. {
  20217. const float scale = 1.0f / 0x7fffffff;
  20218. const char* intData = static_cast <const char*> (source);
  20219. if (source != (void*) dest || srcBytesPerSample >= 4)
  20220. {
  20221. for (int i = 0; i < numSamples; ++i)
  20222. {
  20223. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20224. intData += srcBytesPerSample;
  20225. }
  20226. }
  20227. else
  20228. {
  20229. intData += srcBytesPerSample * numSamples;
  20230. for (int i = numSamples; --i >= 0;)
  20231. {
  20232. intData -= srcBytesPerSample;
  20233. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20234. }
  20235. }
  20236. }
  20237. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20238. {
  20239. const float scale = 1.0f / 0x7fffffff;
  20240. const char* intData = static_cast <const char*> (source);
  20241. if (source != (void*) dest || srcBytesPerSample >= 4)
  20242. {
  20243. for (int i = 0; i < numSamples; ++i)
  20244. {
  20245. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20246. intData += srcBytesPerSample;
  20247. }
  20248. }
  20249. else
  20250. {
  20251. intData += srcBytesPerSample * numSamples;
  20252. for (int i = numSamples; --i >= 0;)
  20253. {
  20254. intData -= srcBytesPerSample;
  20255. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20256. }
  20257. }
  20258. }
  20259. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20260. {
  20261. const char* s = static_cast <const char*> (source);
  20262. for (int i = 0; i < numSamples; ++i)
  20263. {
  20264. dest[i] = *(float*)s;
  20265. #if JUCE_BIG_ENDIAN
  20266. uint32* const d = (uint32*) (dest + i);
  20267. *d = ByteOrder::swap (*d);
  20268. #endif
  20269. s += srcBytesPerSample;
  20270. }
  20271. }
  20272. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20273. {
  20274. const char* s = static_cast <const char*> (source);
  20275. for (int i = 0; i < numSamples; ++i)
  20276. {
  20277. dest[i] = *(float*)s;
  20278. #if JUCE_LITTLE_ENDIAN
  20279. uint32* const d = (uint32*) (dest + i);
  20280. *d = ByteOrder::swap (*d);
  20281. #endif
  20282. s += srcBytesPerSample;
  20283. }
  20284. }
  20285. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20286. const float* const source,
  20287. void* const dest,
  20288. const int numSamples)
  20289. {
  20290. switch (destFormat)
  20291. {
  20292. case int16LE:
  20293. convertFloatToInt16LE (source, dest, numSamples);
  20294. break;
  20295. case int16BE:
  20296. convertFloatToInt16BE (source, dest, numSamples);
  20297. break;
  20298. case int24LE:
  20299. convertFloatToInt24LE (source, dest, numSamples);
  20300. break;
  20301. case int24BE:
  20302. convertFloatToInt24BE (source, dest, numSamples);
  20303. break;
  20304. case int32LE:
  20305. convertFloatToInt32LE (source, dest, numSamples);
  20306. break;
  20307. case int32BE:
  20308. convertFloatToInt32BE (source, dest, numSamples);
  20309. break;
  20310. case float32LE:
  20311. convertFloatToFloat32LE (source, dest, numSamples);
  20312. break;
  20313. case float32BE:
  20314. convertFloatToFloat32BE (source, dest, numSamples);
  20315. break;
  20316. default:
  20317. jassertfalse
  20318. break;
  20319. }
  20320. }
  20321. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20322. const void* const source,
  20323. float* const dest,
  20324. const int numSamples)
  20325. {
  20326. switch (sourceFormat)
  20327. {
  20328. case int16LE:
  20329. convertInt16LEToFloat (source, dest, numSamples);
  20330. break;
  20331. case int16BE:
  20332. convertInt16BEToFloat (source, dest, numSamples);
  20333. break;
  20334. case int24LE:
  20335. convertInt24LEToFloat (source, dest, numSamples);
  20336. break;
  20337. case int24BE:
  20338. convertInt24BEToFloat (source, dest, numSamples);
  20339. break;
  20340. case int32LE:
  20341. convertInt32LEToFloat (source, dest, numSamples);
  20342. break;
  20343. case int32BE:
  20344. convertInt32BEToFloat (source, dest, numSamples);
  20345. break;
  20346. case float32LE:
  20347. convertFloat32LEToFloat (source, dest, numSamples);
  20348. break;
  20349. case float32BE:
  20350. convertFloat32BEToFloat (source, dest, numSamples);
  20351. break;
  20352. default:
  20353. jassertfalse
  20354. break;
  20355. }
  20356. }
  20357. void AudioDataConverters::interleaveSamples (const float** const source,
  20358. float* const dest,
  20359. const int numSamples,
  20360. const int numChannels)
  20361. {
  20362. for (int chan = 0; chan < numChannels; ++chan)
  20363. {
  20364. int i = chan;
  20365. const float* src = source [chan];
  20366. for (int j = 0; j < numSamples; ++j)
  20367. {
  20368. dest [i] = src [j];
  20369. i += numChannels;
  20370. }
  20371. }
  20372. }
  20373. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20374. float** const dest,
  20375. const int numSamples,
  20376. const int numChannels)
  20377. {
  20378. for (int chan = 0; chan < numChannels; ++chan)
  20379. {
  20380. int i = chan;
  20381. float* dst = dest [chan];
  20382. for (int j = 0; j < numSamples; ++j)
  20383. {
  20384. dst [j] = source [i];
  20385. i += numChannels;
  20386. }
  20387. }
  20388. }
  20389. END_JUCE_NAMESPACE
  20390. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20391. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20392. BEGIN_JUCE_NAMESPACE
  20393. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20394. const int numSamples) throw()
  20395. : numChannels (numChannels_),
  20396. size (numSamples)
  20397. {
  20398. jassert (numSamples >= 0);
  20399. jassert (numChannels_ > 0);
  20400. allocateData();
  20401. }
  20402. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20403. : numChannels (other.numChannels),
  20404. size (other.size)
  20405. {
  20406. allocateData();
  20407. const size_t numBytes = size * sizeof (float);
  20408. for (int i = 0; i < numChannels; ++i)
  20409. memcpy (channels[i], other.channels[i], numBytes);
  20410. }
  20411. void AudioSampleBuffer::allocateData()
  20412. {
  20413. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20414. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20415. allocatedData.malloc (allocatedBytes);
  20416. channels = reinterpret_cast <float**> (allocatedData.getData());
  20417. float* chan = (float*) (allocatedData + channelListSize);
  20418. for (int i = 0; i < numChannels; ++i)
  20419. {
  20420. channels[i] = chan;
  20421. chan += size;
  20422. }
  20423. channels [numChannels] = 0;
  20424. }
  20425. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20426. const int numChannels_,
  20427. const int numSamples) throw()
  20428. : numChannels (numChannels_),
  20429. size (numSamples),
  20430. allocatedBytes (0)
  20431. {
  20432. jassert (numChannels_ > 0);
  20433. allocateChannels (dataToReferTo);
  20434. }
  20435. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20436. const int newNumChannels,
  20437. const int newNumSamples) throw()
  20438. {
  20439. jassert (newNumChannels > 0);
  20440. allocatedBytes = 0;
  20441. allocatedData.free();
  20442. numChannels = newNumChannels;
  20443. size = newNumSamples;
  20444. allocateChannels (dataToReferTo);
  20445. }
  20446. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20447. {
  20448. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20449. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20450. {
  20451. channels = static_cast <float**> (preallocatedChannelSpace);
  20452. }
  20453. else
  20454. {
  20455. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20456. channels = reinterpret_cast <float**> (allocatedData.getData());
  20457. }
  20458. for (int i = 0; i < numChannels; ++i)
  20459. {
  20460. // you have to pass in the same number of valid pointers as numChannels
  20461. jassert (dataToReferTo[i] != 0);
  20462. channels[i] = dataToReferTo[i];
  20463. }
  20464. channels [numChannels] = 0;
  20465. }
  20466. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20467. {
  20468. if (this != &other)
  20469. {
  20470. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20471. const size_t numBytes = size * sizeof (float);
  20472. for (int i = 0; i < numChannels; ++i)
  20473. memcpy (channels[i], other.channels[i], numBytes);
  20474. }
  20475. return *this;
  20476. }
  20477. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20478. {
  20479. }
  20480. void AudioSampleBuffer::setSize (const int newNumChannels,
  20481. const int newNumSamples,
  20482. const bool keepExistingContent,
  20483. const bool clearExtraSpace,
  20484. const bool avoidReallocating) throw()
  20485. {
  20486. jassert (newNumChannels > 0);
  20487. if (newNumSamples != size || newNumChannels != numChannels)
  20488. {
  20489. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20490. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20491. if (keepExistingContent)
  20492. {
  20493. HeapBlock <char> newData;
  20494. newData.allocate (newTotalBytes, clearExtraSpace);
  20495. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20496. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20497. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20498. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20499. for (int i = 0; i < numChansToCopy; ++i)
  20500. {
  20501. memcpy (newChan, channels[i], numBytesToCopy);
  20502. newChannels[i] = newChan;
  20503. newChan += newNumSamples;
  20504. }
  20505. allocatedData.swapWith (newData);
  20506. allocatedBytes = (int) newTotalBytes;
  20507. channels = newChannels;
  20508. }
  20509. else
  20510. {
  20511. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20512. {
  20513. if (clearExtraSpace)
  20514. zeromem (allocatedData, newTotalBytes);
  20515. }
  20516. else
  20517. {
  20518. allocatedBytes = newTotalBytes;
  20519. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20520. channels = reinterpret_cast <float**> (allocatedData.getData());
  20521. }
  20522. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20523. for (int i = 0; i < newNumChannels; ++i)
  20524. {
  20525. channels[i] = chan;
  20526. chan += newNumSamples;
  20527. }
  20528. }
  20529. channels [newNumChannels] = 0;
  20530. size = newNumSamples;
  20531. numChannels = newNumChannels;
  20532. }
  20533. }
  20534. void AudioSampleBuffer::clear() throw()
  20535. {
  20536. for (int i = 0; i < numChannels; ++i)
  20537. zeromem (channels[i], size * sizeof (float));
  20538. }
  20539. void AudioSampleBuffer::clear (const int startSample,
  20540. const int numSamples) throw()
  20541. {
  20542. jassert (startSample >= 0 && startSample + numSamples <= size);
  20543. for (int i = 0; i < numChannels; ++i)
  20544. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20545. }
  20546. void AudioSampleBuffer::clear (const int channel,
  20547. const int startSample,
  20548. const int numSamples) throw()
  20549. {
  20550. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20551. jassert (startSample >= 0 && startSample + numSamples <= size);
  20552. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20553. }
  20554. void AudioSampleBuffer::applyGain (const int channel,
  20555. const int startSample,
  20556. int numSamples,
  20557. const float gain) throw()
  20558. {
  20559. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20560. jassert (startSample >= 0 && startSample + numSamples <= size);
  20561. if (gain != 1.0f)
  20562. {
  20563. float* d = channels [channel] + startSample;
  20564. if (gain == 0.0f)
  20565. {
  20566. zeromem (d, sizeof (float) * numSamples);
  20567. }
  20568. else
  20569. {
  20570. while (--numSamples >= 0)
  20571. *d++ *= gain;
  20572. }
  20573. }
  20574. }
  20575. void AudioSampleBuffer::applyGainRamp (const int channel,
  20576. const int startSample,
  20577. int numSamples,
  20578. float startGain,
  20579. float endGain) throw()
  20580. {
  20581. if (startGain == endGain)
  20582. {
  20583. applyGain (channel, startSample, numSamples, startGain);
  20584. }
  20585. else
  20586. {
  20587. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20588. jassert (startSample >= 0 && startSample + numSamples <= size);
  20589. const float increment = (endGain - startGain) / numSamples;
  20590. float* d = channels [channel] + startSample;
  20591. while (--numSamples >= 0)
  20592. {
  20593. *d++ *= startGain;
  20594. startGain += increment;
  20595. }
  20596. }
  20597. }
  20598. void AudioSampleBuffer::applyGain (const int startSample,
  20599. const int numSamples,
  20600. const float gain) throw()
  20601. {
  20602. for (int i = 0; i < numChannels; ++i)
  20603. applyGain (i, startSample, numSamples, gain);
  20604. }
  20605. void AudioSampleBuffer::addFrom (const int destChannel,
  20606. const int destStartSample,
  20607. const AudioSampleBuffer& source,
  20608. const int sourceChannel,
  20609. const int sourceStartSample,
  20610. int numSamples,
  20611. const float gain) throw()
  20612. {
  20613. jassert (&source != this || sourceChannel != destChannel);
  20614. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20615. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20616. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20617. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20618. if (gain != 0.0f && numSamples > 0)
  20619. {
  20620. float* d = channels [destChannel] + destStartSample;
  20621. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20622. if (gain != 1.0f)
  20623. {
  20624. while (--numSamples >= 0)
  20625. *d++ += gain * *s++;
  20626. }
  20627. else
  20628. {
  20629. while (--numSamples >= 0)
  20630. *d++ += *s++;
  20631. }
  20632. }
  20633. }
  20634. void AudioSampleBuffer::addFrom (const int destChannel,
  20635. const int destStartSample,
  20636. const float* source,
  20637. int numSamples,
  20638. const float gain) throw()
  20639. {
  20640. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20641. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20642. jassert (source != 0);
  20643. if (gain != 0.0f && numSamples > 0)
  20644. {
  20645. float* d = channels [destChannel] + destStartSample;
  20646. if (gain != 1.0f)
  20647. {
  20648. while (--numSamples >= 0)
  20649. *d++ += gain * *source++;
  20650. }
  20651. else
  20652. {
  20653. while (--numSamples >= 0)
  20654. *d++ += *source++;
  20655. }
  20656. }
  20657. }
  20658. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20659. const int destStartSample,
  20660. const float* source,
  20661. int numSamples,
  20662. float startGain,
  20663. const float endGain) throw()
  20664. {
  20665. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20666. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20667. jassert (source != 0);
  20668. if (startGain == endGain)
  20669. {
  20670. addFrom (destChannel,
  20671. destStartSample,
  20672. source,
  20673. numSamples,
  20674. startGain);
  20675. }
  20676. else
  20677. {
  20678. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20679. {
  20680. const float increment = (endGain - startGain) / numSamples;
  20681. float* d = channels [destChannel] + destStartSample;
  20682. while (--numSamples >= 0)
  20683. {
  20684. *d++ += startGain * *source++;
  20685. startGain += increment;
  20686. }
  20687. }
  20688. }
  20689. }
  20690. void AudioSampleBuffer::copyFrom (const int destChannel,
  20691. const int destStartSample,
  20692. const AudioSampleBuffer& source,
  20693. const int sourceChannel,
  20694. const int sourceStartSample,
  20695. int numSamples) throw()
  20696. {
  20697. jassert (&source != this || sourceChannel != destChannel);
  20698. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20699. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20700. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20701. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20702. if (numSamples > 0)
  20703. {
  20704. memcpy (channels [destChannel] + destStartSample,
  20705. source.channels [sourceChannel] + sourceStartSample,
  20706. sizeof (float) * numSamples);
  20707. }
  20708. }
  20709. void AudioSampleBuffer::copyFrom (const int destChannel,
  20710. const int destStartSample,
  20711. const float* source,
  20712. int numSamples) throw()
  20713. {
  20714. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20715. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20716. jassert (source != 0);
  20717. if (numSamples > 0)
  20718. {
  20719. memcpy (channels [destChannel] + destStartSample,
  20720. source,
  20721. sizeof (float) * numSamples);
  20722. }
  20723. }
  20724. void AudioSampleBuffer::copyFrom (const int destChannel,
  20725. const int destStartSample,
  20726. const float* source,
  20727. int numSamples,
  20728. const float gain) throw()
  20729. {
  20730. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20731. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20732. jassert (source != 0);
  20733. if (numSamples > 0)
  20734. {
  20735. float* d = channels [destChannel] + destStartSample;
  20736. if (gain != 1.0f)
  20737. {
  20738. if (gain == 0)
  20739. {
  20740. zeromem (d, sizeof (float) * numSamples);
  20741. }
  20742. else
  20743. {
  20744. while (--numSamples >= 0)
  20745. *d++ = gain * *source++;
  20746. }
  20747. }
  20748. else
  20749. {
  20750. memcpy (d, source, sizeof (float) * numSamples);
  20751. }
  20752. }
  20753. }
  20754. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20755. const int destStartSample,
  20756. const float* source,
  20757. int numSamples,
  20758. float startGain,
  20759. float endGain) throw()
  20760. {
  20761. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20762. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20763. jassert (source != 0);
  20764. if (startGain == endGain)
  20765. {
  20766. copyFrom (destChannel,
  20767. destStartSample,
  20768. source,
  20769. numSamples,
  20770. startGain);
  20771. }
  20772. else
  20773. {
  20774. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20775. {
  20776. const float increment = (endGain - startGain) / numSamples;
  20777. float* d = channels [destChannel] + destStartSample;
  20778. while (--numSamples >= 0)
  20779. {
  20780. *d++ = startGain * *source++;
  20781. startGain += increment;
  20782. }
  20783. }
  20784. }
  20785. }
  20786. void AudioSampleBuffer::findMinMax (const int channel,
  20787. const int startSample,
  20788. int numSamples,
  20789. float& minVal,
  20790. float& maxVal) const throw()
  20791. {
  20792. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20793. jassert (startSample >= 0 && startSample + numSamples <= size);
  20794. if (numSamples <= 0)
  20795. {
  20796. minVal = 0.0f;
  20797. maxVal = 0.0f;
  20798. }
  20799. else
  20800. {
  20801. const float* d = channels [channel] + startSample;
  20802. float mn = *d++;
  20803. float mx = mn;
  20804. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20805. {
  20806. const float samp = *d++;
  20807. if (samp > mx)
  20808. mx = samp;
  20809. if (samp < mn)
  20810. mn = samp;
  20811. }
  20812. maxVal = mx;
  20813. minVal = mn;
  20814. }
  20815. }
  20816. float AudioSampleBuffer::getMagnitude (const int channel,
  20817. const int startSample,
  20818. const int numSamples) const throw()
  20819. {
  20820. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20821. jassert (startSample >= 0 && startSample + numSamples <= size);
  20822. float mn, mx;
  20823. findMinMax (channel, startSample, numSamples, mn, mx);
  20824. return jmax (mn, -mn, mx, -mx);
  20825. }
  20826. float AudioSampleBuffer::getMagnitude (const int startSample,
  20827. const int numSamples) const throw()
  20828. {
  20829. float mag = 0.0f;
  20830. for (int i = 0; i < numChannels; ++i)
  20831. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20832. return mag;
  20833. }
  20834. float AudioSampleBuffer::getRMSLevel (const int channel,
  20835. const int startSample,
  20836. const int numSamples) const throw()
  20837. {
  20838. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20839. jassert (startSample >= 0 && startSample + numSamples <= size);
  20840. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20841. return 0.0f;
  20842. const float* const data = channels [channel] + startSample;
  20843. double sum = 0.0;
  20844. for (int i = 0; i < numSamples; ++i)
  20845. {
  20846. const float sample = data [i];
  20847. sum += sample * sample;
  20848. }
  20849. return (float) sqrt (sum / numSamples);
  20850. }
  20851. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20852. const int startSample,
  20853. const int numSamples,
  20854. const int readerStartSample,
  20855. const bool useLeftChan,
  20856. const bool useRightChan) throw()
  20857. {
  20858. jassert (reader != 0);
  20859. jassert (startSample >= 0 && startSample + numSamples <= size);
  20860. if (numSamples > 0)
  20861. {
  20862. int* chans[3];
  20863. if (useLeftChan == useRightChan)
  20864. {
  20865. chans[0] = (int*) getSampleData (0, startSample);
  20866. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20867. }
  20868. else if (useLeftChan || (reader->numChannels == 1))
  20869. {
  20870. chans[0] = (int*) getSampleData (0, startSample);
  20871. chans[1] = 0;
  20872. }
  20873. else if (useRightChan)
  20874. {
  20875. chans[0] = 0;
  20876. chans[1] = (int*) getSampleData (0, startSample);
  20877. }
  20878. chans[2] = 0;
  20879. reader->read (chans, 2, readerStartSample, numSamples, true);
  20880. if (! reader->usesFloatingPointData)
  20881. {
  20882. for (int j = 0; j < 2; ++j)
  20883. {
  20884. float* const d = (float*) (chans[j]);
  20885. if (d != 0)
  20886. {
  20887. const float multiplier = 1.0f / 0x7fffffff;
  20888. for (int i = 0; i < numSamples; ++i)
  20889. d[i] = *(int*)(d + i) * multiplier;
  20890. }
  20891. }
  20892. }
  20893. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20894. {
  20895. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20896. memcpy (getSampleData (1, startSample),
  20897. getSampleData (0, startSample),
  20898. sizeof (float) * numSamples);
  20899. }
  20900. }
  20901. }
  20902. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  20903. const int startSample,
  20904. const int numSamples) const throw()
  20905. {
  20906. jassert (startSample >= 0 && startSample + numSamples <= size);
  20907. if (numSamples > 0)
  20908. {
  20909. int* chans [3];
  20910. if (writer->isFloatingPoint())
  20911. {
  20912. chans[0] = (int*) getSampleData (0, startSample);
  20913. if (numChannels > 1)
  20914. chans[1] = (int*) getSampleData (1, startSample);
  20915. else
  20916. chans[1] = 0;
  20917. chans[2] = 0;
  20918. writer->write ((const int**) chans, numSamples);
  20919. }
  20920. else
  20921. {
  20922. HeapBlock <int> tempBuffer (numSamples * 2);
  20923. chans[0] = tempBuffer;
  20924. if (numChannels > 1)
  20925. chans[1] = chans[0] + numSamples;
  20926. else
  20927. chans[1] = 0;
  20928. chans[2] = 0;
  20929. for (int j = 0; j < 2; ++j)
  20930. {
  20931. int* const dest = chans[j];
  20932. if (dest != 0)
  20933. {
  20934. const float* const src = channels [j] + startSample;
  20935. for (int i = 0; i < numSamples; ++i)
  20936. {
  20937. const double samp = src[i];
  20938. if (samp <= -1.0)
  20939. dest[i] = std::numeric_limits<int>::min();
  20940. else if (samp >= 1.0)
  20941. dest[i] = std::numeric_limits<int>::max();
  20942. else
  20943. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  20944. }
  20945. }
  20946. }
  20947. writer->write ((const int**) chans, numSamples);
  20948. }
  20949. }
  20950. }
  20951. END_JUCE_NAMESPACE
  20952. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  20953. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  20954. BEGIN_JUCE_NAMESPACE
  20955. IIRFilter::IIRFilter()
  20956. : active (false)
  20957. {
  20958. reset();
  20959. }
  20960. IIRFilter::IIRFilter (const IIRFilter& other)
  20961. : active (other.active)
  20962. {
  20963. const ScopedLock sl (other.processLock);
  20964. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  20965. reset();
  20966. }
  20967. IIRFilter::~IIRFilter()
  20968. {
  20969. }
  20970. void IIRFilter::reset() throw()
  20971. {
  20972. const ScopedLock sl (processLock);
  20973. x1 = 0;
  20974. x2 = 0;
  20975. y1 = 0;
  20976. y2 = 0;
  20977. }
  20978. float IIRFilter::processSingleSampleRaw (const float in) throw()
  20979. {
  20980. float out = coefficients[0] * in
  20981. + coefficients[1] * x1
  20982. + coefficients[2] * x2
  20983. - coefficients[4] * y1
  20984. - coefficients[5] * y2;
  20985. #if JUCE_INTEL
  20986. if (! (out < -1.0e-8 || out > 1.0e-8))
  20987. out = 0;
  20988. #endif
  20989. x2 = x1;
  20990. x1 = in;
  20991. y2 = y1;
  20992. y1 = out;
  20993. return out;
  20994. }
  20995. void IIRFilter::processSamples (float* const samples,
  20996. const int numSamples) throw()
  20997. {
  20998. const ScopedLock sl (processLock);
  20999. if (active)
  21000. {
  21001. for (int i = 0; i < numSamples; ++i)
  21002. {
  21003. const float in = samples[i];
  21004. float out = coefficients[0] * in
  21005. + coefficients[1] * x1
  21006. + coefficients[2] * x2
  21007. - coefficients[4] * y1
  21008. - coefficients[5] * y2;
  21009. #if JUCE_INTEL
  21010. if (! (out < -1.0e-8 || out > 1.0e-8))
  21011. out = 0;
  21012. #endif
  21013. x2 = x1;
  21014. x1 = in;
  21015. y2 = y1;
  21016. y1 = out;
  21017. samples[i] = out;
  21018. }
  21019. }
  21020. }
  21021. void IIRFilter::makeLowPass (const double sampleRate,
  21022. const double frequency) throw()
  21023. {
  21024. jassert (sampleRate > 0);
  21025. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21026. const double nSquared = n * n;
  21027. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21028. setCoefficients (c1,
  21029. c1 * 2.0f,
  21030. c1,
  21031. 1.0,
  21032. c1 * 2.0 * (1.0 - nSquared),
  21033. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21034. }
  21035. void IIRFilter::makeHighPass (const double sampleRate,
  21036. const double frequency) throw()
  21037. {
  21038. const double n = tan (double_Pi * frequency / sampleRate);
  21039. const double nSquared = n * n;
  21040. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21041. setCoefficients (c1,
  21042. c1 * -2.0f,
  21043. c1,
  21044. 1.0,
  21045. c1 * 2.0 * (nSquared - 1.0),
  21046. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21047. }
  21048. void IIRFilter::makeLowShelf (const double sampleRate,
  21049. const double cutOffFrequency,
  21050. const double Q,
  21051. const float gainFactor) throw()
  21052. {
  21053. jassert (sampleRate > 0);
  21054. jassert (Q > 0);
  21055. const double A = jmax (0.0f, gainFactor);
  21056. const double aminus1 = A - 1.0;
  21057. const double aplus1 = A + 1.0;
  21058. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21059. const double coso = cos (omega);
  21060. const double beta = sin (omega) * sqrt (A) / Q;
  21061. const double aminus1TimesCoso = aminus1 * coso;
  21062. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21063. A * 2.0 * (aminus1 - aplus1 * coso),
  21064. A * (aplus1 - aminus1TimesCoso - beta),
  21065. aplus1 + aminus1TimesCoso + beta,
  21066. -2.0 * (aminus1 + aplus1 * coso),
  21067. aplus1 + aminus1TimesCoso - beta);
  21068. }
  21069. void IIRFilter::makeHighShelf (const double sampleRate,
  21070. const double cutOffFrequency,
  21071. const double Q,
  21072. const float gainFactor) throw()
  21073. {
  21074. jassert (sampleRate > 0);
  21075. jassert (Q > 0);
  21076. const double A = jmax (0.0f, gainFactor);
  21077. const double aminus1 = A - 1.0;
  21078. const double aplus1 = A + 1.0;
  21079. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21080. const double coso = cos (omega);
  21081. const double beta = sin (omega) * sqrt (A) / Q;
  21082. const double aminus1TimesCoso = aminus1 * coso;
  21083. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21084. A * -2.0 * (aminus1 + aplus1 * coso),
  21085. A * (aplus1 + aminus1TimesCoso - beta),
  21086. aplus1 - aminus1TimesCoso + beta,
  21087. 2.0 * (aminus1 - aplus1 * coso),
  21088. aplus1 - aminus1TimesCoso - beta);
  21089. }
  21090. void IIRFilter::makeBandPass (const double sampleRate,
  21091. const double centreFrequency,
  21092. const double Q,
  21093. const float gainFactor) throw()
  21094. {
  21095. jassert (sampleRate > 0);
  21096. jassert (Q > 0);
  21097. const double A = jmax (0.0f, gainFactor);
  21098. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21099. const double alpha = 0.5 * sin (omega) / Q;
  21100. const double c2 = -2.0 * cos (omega);
  21101. const double alphaTimesA = alpha * A;
  21102. const double alphaOverA = alpha / A;
  21103. setCoefficients (1.0 + alphaTimesA,
  21104. c2,
  21105. 1.0 - alphaTimesA,
  21106. 1.0 + alphaOverA,
  21107. c2,
  21108. 1.0 - alphaOverA);
  21109. }
  21110. void IIRFilter::makeInactive() throw()
  21111. {
  21112. const ScopedLock sl (processLock);
  21113. active = false;
  21114. }
  21115. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21116. {
  21117. const ScopedLock sl (processLock);
  21118. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21119. active = other.active;
  21120. }
  21121. void IIRFilter::setCoefficients (double c1,
  21122. double c2,
  21123. double c3,
  21124. double c4,
  21125. double c5,
  21126. double c6) throw()
  21127. {
  21128. const double a = 1.0 / c4;
  21129. c1 *= a;
  21130. c2 *= a;
  21131. c3 *= a;
  21132. c5 *= a;
  21133. c6 *= a;
  21134. const ScopedLock sl (processLock);
  21135. coefficients[0] = (float) c1;
  21136. coefficients[1] = (float) c2;
  21137. coefficients[2] = (float) c3;
  21138. coefficients[3] = (float) c4;
  21139. coefficients[4] = (float) c5;
  21140. coefficients[5] = (float) c6;
  21141. active = true;
  21142. }
  21143. END_JUCE_NAMESPACE
  21144. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21145. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21146. BEGIN_JUCE_NAMESPACE
  21147. MidiBuffer::MidiBuffer() throw()
  21148. : bytesUsed (0)
  21149. {
  21150. }
  21151. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21152. : bytesUsed (0)
  21153. {
  21154. addEvent (message, 0);
  21155. }
  21156. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21157. : data (other.data),
  21158. bytesUsed (other.bytesUsed)
  21159. {
  21160. }
  21161. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21162. {
  21163. bytesUsed = other.bytesUsed;
  21164. data = other.data;
  21165. return *this;
  21166. }
  21167. void MidiBuffer::swapWith (MidiBuffer& other)
  21168. {
  21169. data.swapWith (other.data);
  21170. swapVariables <int> (bytesUsed, other.bytesUsed);
  21171. }
  21172. MidiBuffer::~MidiBuffer() throw()
  21173. {
  21174. }
  21175. inline uint8* MidiBuffer::getData() const throw()
  21176. {
  21177. return static_cast <uint8*> (data.getData());
  21178. }
  21179. inline int MidiBuffer::getEventTime (const void* const d) throw()
  21180. {
  21181. return *static_cast <const int*> (d);
  21182. }
  21183. inline uint16 MidiBuffer::getEventDataSize (const void* const d) throw()
  21184. {
  21185. return *reinterpret_cast <const uint16*> (static_cast <const char*> (d) + sizeof (int));
  21186. }
  21187. inline uint16 MidiBuffer::getEventTotalSize (const void* const d) throw()
  21188. {
  21189. return getEventDataSize (d) + sizeof (int) + sizeof (uint16);
  21190. }
  21191. void MidiBuffer::clear() throw()
  21192. {
  21193. bytesUsed = 0;
  21194. }
  21195. void MidiBuffer::clear (const int startSample,
  21196. const int numSamples) throw()
  21197. {
  21198. uint8* const start = findEventAfter (getData(), startSample - 1);
  21199. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21200. if (end > start)
  21201. {
  21202. const int bytesToMove = bytesUsed - (int) (end - getData());
  21203. if (bytesToMove > 0)
  21204. memmove (start, end, bytesToMove);
  21205. bytesUsed -= (int) (end - start);
  21206. }
  21207. }
  21208. void MidiBuffer::addEvent (const MidiMessage& m,
  21209. const int sampleNumber) throw()
  21210. {
  21211. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21212. }
  21213. static int findActualEventLength (const uint8* const data,
  21214. const int maxBytes) throw()
  21215. {
  21216. unsigned int byte = (unsigned int) *data;
  21217. int size = 0;
  21218. if (byte == 0xf0 || byte == 0xf7)
  21219. {
  21220. const uint8* d = data + 1;
  21221. while (d < data + maxBytes)
  21222. if (*d++ == 0xf7)
  21223. break;
  21224. size = (int) (d - data);
  21225. }
  21226. else if (byte == 0xff)
  21227. {
  21228. int n;
  21229. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21230. size = jmin (maxBytes, n + 2 + bytesLeft);
  21231. }
  21232. else if (byte >= 0x80)
  21233. {
  21234. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21235. }
  21236. return size;
  21237. }
  21238. void MidiBuffer::addEvent (const uint8* const newData,
  21239. const int maxBytes,
  21240. const int sampleNumber) throw()
  21241. {
  21242. const int numBytes = findActualEventLength (newData, maxBytes);
  21243. if (numBytes > 0)
  21244. {
  21245. int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16);
  21246. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21247. uint8* d = findEventAfter (getData(), sampleNumber);
  21248. const int bytesToMove = bytesUsed - (int) (d - getData());
  21249. if (bytesToMove > 0)
  21250. memmove (d + numBytes + sizeof (int) + sizeof (uint16), d, bytesToMove);
  21251. *reinterpret_cast <int*> (d) = sampleNumber;
  21252. d += sizeof (int);
  21253. *reinterpret_cast <uint16*> (d) = (uint16) numBytes;
  21254. d += sizeof (uint16);
  21255. memcpy (d, newData, numBytes);
  21256. bytesUsed += numBytes + sizeof (int) + sizeof (uint16);
  21257. }
  21258. }
  21259. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21260. const int startSample,
  21261. const int numSamples,
  21262. const int sampleDeltaToAdd) throw()
  21263. {
  21264. Iterator i (otherBuffer);
  21265. i.setNextSamplePosition (startSample);
  21266. const uint8* eventData;
  21267. int eventSize, position;
  21268. while (i.getNextEvent (eventData, eventSize, position)
  21269. && (position < startSample + numSamples || numSamples < 0))
  21270. {
  21271. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21272. }
  21273. }
  21274. bool MidiBuffer::isEmpty() const throw()
  21275. {
  21276. return bytesUsed == 0;
  21277. }
  21278. int MidiBuffer::getNumEvents() const throw()
  21279. {
  21280. int n = 0;
  21281. const uint8* d = getData();
  21282. const uint8* const end = d + bytesUsed;
  21283. while (d < end)
  21284. {
  21285. d += getEventTotalSize (d);
  21286. ++n;
  21287. }
  21288. return n;
  21289. }
  21290. int MidiBuffer::getFirstEventTime() const throw()
  21291. {
  21292. return bytesUsed > 0 ? getEventTime (data.getData()) : 0;
  21293. }
  21294. int MidiBuffer::getLastEventTime() const throw()
  21295. {
  21296. if (bytesUsed == 0)
  21297. return 0;
  21298. const uint8* d = getData();
  21299. const uint8* const endData = d + bytesUsed;
  21300. for (;;)
  21301. {
  21302. const uint8* const nextOne = d + getEventTotalSize (d);
  21303. if (nextOne >= endData)
  21304. return getEventTime (d);
  21305. d = nextOne;
  21306. }
  21307. }
  21308. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21309. {
  21310. const uint8* const endData = getData() + bytesUsed;
  21311. while (d < endData && getEventTime (d) <= samplePosition)
  21312. d += getEventTotalSize (d);
  21313. return d;
  21314. }
  21315. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21316. : buffer (buffer_),
  21317. data (buffer_.getData())
  21318. {
  21319. }
  21320. MidiBuffer::Iterator::~Iterator() throw()
  21321. {
  21322. }
  21323. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21324. {
  21325. data = buffer.getData();
  21326. const uint8* dataEnd = data + buffer.bytesUsed;
  21327. while (data < dataEnd && getEventTime (data) < samplePosition)
  21328. data += getEventTotalSize (data);
  21329. }
  21330. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw()
  21331. {
  21332. if (data >= buffer.getData() + buffer.bytesUsed)
  21333. return false;
  21334. samplePosition = getEventTime (data);
  21335. numBytes = getEventDataSize (data);
  21336. data += sizeof (int) + sizeof (uint16);
  21337. midiData = data;
  21338. data += numBytes;
  21339. return true;
  21340. }
  21341. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePosition) throw()
  21342. {
  21343. if (data >= buffer.getData() + buffer.bytesUsed)
  21344. return false;
  21345. samplePosition = getEventTime (data);
  21346. const int numBytes = getEventDataSize (data);
  21347. data += sizeof (int) + sizeof (uint16);
  21348. result = MidiMessage (data, numBytes, samplePosition);
  21349. data += numBytes;
  21350. return true;
  21351. }
  21352. END_JUCE_NAMESPACE
  21353. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21354. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21355. BEGIN_JUCE_NAMESPACE
  21356. namespace MidiFileHelpers
  21357. {
  21358. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21359. {
  21360. unsigned int buffer = v & 0x7F;
  21361. while ((v >>= 7) != 0)
  21362. {
  21363. buffer <<= 8;
  21364. buffer |= ((v & 0x7F) | 0x80);
  21365. }
  21366. for (;;)
  21367. {
  21368. out.writeByte ((char) buffer);
  21369. if (buffer & 0x80)
  21370. buffer >>= 8;
  21371. else
  21372. break;
  21373. }
  21374. }
  21375. static bool parseMidiHeader (const uint8* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21376. {
  21377. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21378. data += 4;
  21379. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21380. {
  21381. bool ok = false;
  21382. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21383. {
  21384. for (int i = 0; i < 8; ++i)
  21385. {
  21386. ch = ByteOrder::bigEndianInt (data);
  21387. data += 4;
  21388. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21389. {
  21390. ok = true;
  21391. break;
  21392. }
  21393. }
  21394. }
  21395. if (! ok)
  21396. return false;
  21397. }
  21398. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21399. data += 4;
  21400. fileType = (short) ByteOrder::bigEndianShort (data);
  21401. data += 2;
  21402. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21403. data += 2;
  21404. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21405. data += 2;
  21406. bytesRemaining -= 6;
  21407. data += bytesRemaining;
  21408. return true;
  21409. }
  21410. static double convertTicksToSeconds (const double time,
  21411. const MidiMessageSequence& tempoEvents,
  21412. const int timeFormat)
  21413. {
  21414. if (timeFormat > 0)
  21415. {
  21416. int numer = 4, denom = 4;
  21417. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21418. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21419. double secsPerTick = 0.5 * tickLen;
  21420. const int numEvents = tempoEvents.getNumEvents();
  21421. for (int i = 0; i < numEvents; ++i)
  21422. {
  21423. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21424. if (time <= m.getTimeStamp())
  21425. break;
  21426. if (timeFormat > 0)
  21427. {
  21428. correctedTempoTime = correctedTempoTime
  21429. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21430. }
  21431. else
  21432. {
  21433. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21434. }
  21435. tempoTime = m.getTimeStamp();
  21436. if (m.isTempoMetaEvent())
  21437. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21438. else if (m.isTimeSignatureMetaEvent())
  21439. m.getTimeSignatureInfo (numer, denom);
  21440. while (i + 1 < numEvents)
  21441. {
  21442. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21443. if (m2.getTimeStamp() == tempoTime)
  21444. {
  21445. ++i;
  21446. if (m2.isTempoMetaEvent())
  21447. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21448. else if (m2.isTimeSignatureMetaEvent())
  21449. m2.getTimeSignatureInfo (numer, denom);
  21450. }
  21451. else
  21452. {
  21453. break;
  21454. }
  21455. }
  21456. }
  21457. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21458. }
  21459. else
  21460. {
  21461. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21462. }
  21463. }
  21464. }
  21465. MidiFile::MidiFile()
  21466. : timeFormat ((short) (unsigned short) 0xe728)
  21467. {
  21468. }
  21469. MidiFile::~MidiFile()
  21470. {
  21471. clear();
  21472. }
  21473. void MidiFile::clear()
  21474. {
  21475. tracks.clear();
  21476. }
  21477. int MidiFile::getNumTracks() const throw()
  21478. {
  21479. return tracks.size();
  21480. }
  21481. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21482. {
  21483. return tracks [index];
  21484. }
  21485. void MidiFile::addTrack (const MidiMessageSequence& trackSequence)
  21486. {
  21487. tracks.add (new MidiMessageSequence (trackSequence));
  21488. }
  21489. short MidiFile::getTimeFormat() const throw()
  21490. {
  21491. return timeFormat;
  21492. }
  21493. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21494. {
  21495. timeFormat = (short) ticks;
  21496. }
  21497. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21498. const int subframeResolution) throw()
  21499. {
  21500. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21501. }
  21502. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21503. {
  21504. for (int i = tracks.size(); --i >= 0;)
  21505. {
  21506. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21507. for (int j = 0; j < numEvents; ++j)
  21508. {
  21509. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21510. if (m.isTempoMetaEvent())
  21511. tempoChangeEvents.addEvent (m);
  21512. }
  21513. }
  21514. }
  21515. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21516. {
  21517. for (int i = tracks.size(); --i >= 0;)
  21518. {
  21519. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21520. for (int j = 0; j < numEvents; ++j)
  21521. {
  21522. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21523. if (m.isTimeSignatureMetaEvent())
  21524. timeSigEvents.addEvent (m);
  21525. }
  21526. }
  21527. }
  21528. double MidiFile::getLastTimestamp() const
  21529. {
  21530. double t = 0.0;
  21531. for (int i = tracks.size(); --i >= 0;)
  21532. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21533. return t;
  21534. }
  21535. bool MidiFile::readFrom (InputStream& sourceStream)
  21536. {
  21537. clear();
  21538. MemoryBlock data;
  21539. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21540. // (put a sanity-check on the file size, as midi files are generally small)
  21541. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21542. {
  21543. size_t size = data.getSize();
  21544. const uint8* d = static_cast <const uint8*> (data.getData());
  21545. short fileType, expectedTracks;
  21546. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21547. {
  21548. size -= (int) (d - static_cast <const uint8*> (data.getData()));
  21549. int track = 0;
  21550. while (size > 0 && track < expectedTracks)
  21551. {
  21552. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21553. d += 4;
  21554. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21555. d += 4;
  21556. if (chunkSize <= 0)
  21557. break;
  21558. if (size < 0)
  21559. return false;
  21560. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21561. {
  21562. readNextTrack (d, chunkSize);
  21563. }
  21564. size -= chunkSize + 8;
  21565. d += chunkSize;
  21566. ++track;
  21567. }
  21568. return true;
  21569. }
  21570. }
  21571. return false;
  21572. }
  21573. // a comparator that puts all the note-offs before note-ons that have the same time
  21574. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21575. const MidiMessageSequence::MidiEventHolder* const second)
  21576. {
  21577. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21578. if (diff == 0)
  21579. {
  21580. if (first->message.isNoteOff() && second->message.isNoteOn())
  21581. return -1;
  21582. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21583. return 1;
  21584. else
  21585. return 0;
  21586. }
  21587. else
  21588. {
  21589. return (diff > 0) ? 1 : -1;
  21590. }
  21591. }
  21592. void MidiFile::readNextTrack (const uint8* data, int size)
  21593. {
  21594. double time = 0;
  21595. char lastStatusByte = 0;
  21596. MidiMessageSequence result;
  21597. while (size > 0)
  21598. {
  21599. int bytesUsed;
  21600. const int delay = MidiMessage::readVariableLengthVal (data, bytesUsed);
  21601. data += bytesUsed;
  21602. size -= bytesUsed;
  21603. time += delay;
  21604. int messSize = 0;
  21605. const MidiMessage mm (data, size, messSize, lastStatusByte, time);
  21606. if (messSize <= 0)
  21607. break;
  21608. size -= messSize;
  21609. data += messSize;
  21610. result.addEvent (mm);
  21611. const char firstByte = *(mm.getRawData());
  21612. if ((firstByte & 0xf0) != 0xf0)
  21613. lastStatusByte = firstByte;
  21614. }
  21615. // use a sort that puts all the note-offs before note-ons that have the same time
  21616. result.list.sort (*this, true);
  21617. result.updateMatchedPairs();
  21618. addTrack (result);
  21619. }
  21620. void MidiFile::convertTimestampTicksToSeconds()
  21621. {
  21622. MidiMessageSequence tempoEvents;
  21623. findAllTempoEvents (tempoEvents);
  21624. findAllTimeSigEvents (tempoEvents);
  21625. for (int i = 0; i < tracks.size(); ++i)
  21626. {
  21627. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21628. for (int j = ms.getNumEvents(); --j >= 0;)
  21629. {
  21630. MidiMessage& m = ms.getEventPointer(j)->message;
  21631. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21632. tempoEvents,
  21633. timeFormat));
  21634. }
  21635. }
  21636. }
  21637. bool MidiFile::writeTo (OutputStream& out)
  21638. {
  21639. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21640. out.writeIntBigEndian (6);
  21641. out.writeShortBigEndian (1); // type
  21642. out.writeShortBigEndian ((short) tracks.size());
  21643. out.writeShortBigEndian (timeFormat);
  21644. for (int i = 0; i < tracks.size(); ++i)
  21645. writeTrack (out, i);
  21646. out.flush();
  21647. return true;
  21648. }
  21649. void MidiFile::writeTrack (OutputStream& mainOut,
  21650. const int trackNum)
  21651. {
  21652. MemoryOutputStream out;
  21653. const MidiMessageSequence& ms = *tracks[trackNum];
  21654. int lastTick = 0;
  21655. char lastStatusByte = 0;
  21656. for (int i = 0; i < ms.getNumEvents(); ++i)
  21657. {
  21658. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21659. const int tick = roundToInt (mm.getTimeStamp());
  21660. const int delta = jmax (0, tick - lastTick);
  21661. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21662. lastTick = tick;
  21663. const char statusByte = *(mm.getRawData());
  21664. if ((statusByte == lastStatusByte)
  21665. && ((statusByte & 0xf0) != 0xf0)
  21666. && i > 0
  21667. && mm.getRawDataSize() > 1)
  21668. {
  21669. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21670. }
  21671. else
  21672. {
  21673. out.write (mm.getRawData(), mm.getRawDataSize());
  21674. }
  21675. lastStatusByte = statusByte;
  21676. }
  21677. out.writeByte (0);
  21678. const MidiMessage m (MidiMessage::endOfTrack());
  21679. out.write (m.getRawData(),
  21680. m.getRawDataSize());
  21681. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21682. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21683. mainOut.write (out.getData(), (int) out.getDataSize());
  21684. }
  21685. END_JUCE_NAMESPACE
  21686. /*** End of inlined file: juce_MidiFile.cpp ***/
  21687. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21688. BEGIN_JUCE_NAMESPACE
  21689. MidiKeyboardState::MidiKeyboardState()
  21690. {
  21691. zerostruct (noteStates);
  21692. }
  21693. MidiKeyboardState::~MidiKeyboardState()
  21694. {
  21695. }
  21696. void MidiKeyboardState::reset()
  21697. {
  21698. const ScopedLock sl (lock);
  21699. zerostruct (noteStates);
  21700. eventsToAdd.clear();
  21701. }
  21702. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21703. {
  21704. jassert (midiChannel >= 0 && midiChannel <= 16);
  21705. return ((unsigned int) n) < 128
  21706. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21707. }
  21708. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21709. {
  21710. return ((unsigned int) n) < 128
  21711. && (noteStates[n] & midiChannelMask) != 0;
  21712. }
  21713. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21714. {
  21715. jassert (midiChannel >= 0 && midiChannel <= 16);
  21716. jassert (((unsigned int) midiNoteNumber) < 128);
  21717. const ScopedLock sl (lock);
  21718. if (((unsigned int) midiNoteNumber) < 128)
  21719. {
  21720. const int timeNow = (int) Time::getMillisecondCounter();
  21721. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21722. eventsToAdd.clear (0, timeNow - 500);
  21723. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21724. }
  21725. }
  21726. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21727. {
  21728. if (((unsigned int) midiNoteNumber) < 128)
  21729. {
  21730. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21731. for (int i = listeners.size(); --i >= 0;)
  21732. listeners.getUnchecked(i)->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21733. }
  21734. }
  21735. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21736. {
  21737. const ScopedLock sl (lock);
  21738. if (isNoteOn (midiChannel, midiNoteNumber))
  21739. {
  21740. const int timeNow = (int) Time::getMillisecondCounter();
  21741. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21742. eventsToAdd.clear (0, timeNow - 500);
  21743. noteOffInternal (midiChannel, midiNoteNumber);
  21744. }
  21745. }
  21746. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21747. {
  21748. if (isNoteOn (midiChannel, midiNoteNumber))
  21749. {
  21750. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21751. for (int i = listeners.size(); --i >= 0;)
  21752. listeners.getUnchecked(i)->handleNoteOff (this, midiChannel, midiNoteNumber);
  21753. }
  21754. }
  21755. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21756. {
  21757. const ScopedLock sl (lock);
  21758. if (midiChannel <= 0)
  21759. {
  21760. for (int i = 1; i <= 16; ++i)
  21761. allNotesOff (i);
  21762. }
  21763. else
  21764. {
  21765. for (int i = 0; i < 128; ++i)
  21766. noteOff (midiChannel, i);
  21767. }
  21768. }
  21769. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21770. {
  21771. if (message.isNoteOn())
  21772. {
  21773. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21774. }
  21775. else if (message.isNoteOff())
  21776. {
  21777. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21778. }
  21779. else if (message.isAllNotesOff())
  21780. {
  21781. for (int i = 0; i < 128; ++i)
  21782. noteOffInternal (message.getChannel(), i);
  21783. }
  21784. }
  21785. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21786. const int startSample,
  21787. const int numSamples,
  21788. const bool injectIndirectEvents)
  21789. {
  21790. MidiBuffer::Iterator i (buffer);
  21791. MidiMessage message (0xf4, 0.0);
  21792. int time;
  21793. const ScopedLock sl (lock);
  21794. while (i.getNextEvent (message, time))
  21795. processNextMidiEvent (message);
  21796. if (injectIndirectEvents)
  21797. {
  21798. MidiBuffer::Iterator i2 (eventsToAdd);
  21799. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21800. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21801. while (i2.getNextEvent (message, time))
  21802. {
  21803. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21804. buffer.addEvent (message, startSample + pos);
  21805. }
  21806. }
  21807. eventsToAdd.clear();
  21808. }
  21809. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21810. {
  21811. const ScopedLock sl (lock);
  21812. listeners.addIfNotAlreadyThere (listener);
  21813. }
  21814. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21815. {
  21816. const ScopedLock sl (lock);
  21817. listeners.removeValue (listener);
  21818. }
  21819. END_JUCE_NAMESPACE
  21820. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21821. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21822. BEGIN_JUCE_NAMESPACE
  21823. int MidiMessage::readVariableLengthVal (const uint8* data,
  21824. int& numBytesUsed) throw()
  21825. {
  21826. numBytesUsed = 0;
  21827. int v = 0;
  21828. int i;
  21829. do
  21830. {
  21831. i = (int) *data++;
  21832. if (++numBytesUsed > 6)
  21833. break;
  21834. v = (v << 7) + (i & 0x7f);
  21835. } while (i & 0x80);
  21836. return v;
  21837. }
  21838. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21839. {
  21840. // this method only works for valid starting bytes of a short midi message
  21841. jassert (firstByte >= 0x80
  21842. && firstByte != 0xf0
  21843. && firstByte != 0xf7);
  21844. static const char messageLengths[] =
  21845. {
  21846. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21847. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21848. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21849. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21850. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21851. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21852. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21853. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21854. };
  21855. return messageLengths [firstByte & 0x7f];
  21856. }
  21857. MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
  21858. : timeStamp (t),
  21859. size (dataSize)
  21860. {
  21861. jassert (dataSize > 0);
  21862. if (dataSize <= 4)
  21863. data = static_cast<uint8*> (preallocatedData.asBytes);
  21864. else
  21865. data = static_cast<uint8*> (juce_malloc (dataSize));
  21866. memcpy (data, d, dataSize);
  21867. // check that the length matches the data..
  21868. jassert (size > 3 || data[0] >= 0xf0 || getMessageLengthFromFirstByte (data[0]) == size);
  21869. }
  21870. MidiMessage::MidiMessage (const int byte1, const double t) throw()
  21871. : timeStamp (t),
  21872. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21873. size (1)
  21874. {
  21875. data[0] = (uint8) byte1;
  21876. // check that the length matches the data..
  21877. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21878. }
  21879. MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) throw()
  21880. : timeStamp (t),
  21881. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21882. size (2)
  21883. {
  21884. data[0] = (uint8) byte1;
  21885. data[1] = (uint8) byte2;
  21886. // check that the length matches the data..
  21887. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21888. }
  21889. MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) throw()
  21890. : timeStamp (t),
  21891. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21892. size (3)
  21893. {
  21894. data[0] = (uint8) byte1;
  21895. data[1] = (uint8) byte2;
  21896. data[2] = (uint8) byte3;
  21897. // check that the length matches the data..
  21898. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  21899. }
  21900. MidiMessage::MidiMessage (const MidiMessage& other)
  21901. : timeStamp (other.timeStamp),
  21902. size (other.size)
  21903. {
  21904. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21905. {
  21906. data = static_cast<uint8*> (juce_malloc (size));
  21907. memcpy (data, other.data, size);
  21908. }
  21909. else
  21910. {
  21911. data = static_cast<uint8*> (preallocatedData.asBytes);
  21912. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21913. }
  21914. }
  21915. MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
  21916. : timeStamp (newTimeStamp),
  21917. size (other.size)
  21918. {
  21919. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21920. {
  21921. data = static_cast<uint8*> (juce_malloc (size));
  21922. memcpy (data, other.data, size);
  21923. }
  21924. else
  21925. {
  21926. data = static_cast<uint8*> (preallocatedData.asBytes);
  21927. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21928. }
  21929. }
  21930. MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uint8 lastStatusByte, double t)
  21931. : timeStamp (t),
  21932. data (static_cast<uint8*> (preallocatedData.asBytes))
  21933. {
  21934. const uint8* src = static_cast <const uint8*> (src_);
  21935. unsigned int byte = (unsigned int) *src;
  21936. if (byte < 0x80)
  21937. {
  21938. byte = (unsigned int) (uint8) lastStatusByte;
  21939. numBytesUsed = -1;
  21940. }
  21941. else
  21942. {
  21943. numBytesUsed = 0;
  21944. --sz;
  21945. ++src;
  21946. }
  21947. if (byte >= 0x80)
  21948. {
  21949. if (byte == 0xf0)
  21950. {
  21951. const uint8* d = src;
  21952. while (d < src + sz)
  21953. {
  21954. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  21955. {
  21956. if (*d == 0xf7) // include an 0xf7 if we hit one
  21957. ++d;
  21958. break;
  21959. }
  21960. ++d;
  21961. }
  21962. size = 1 + (int) (d - src);
  21963. data = static_cast<uint8*> (juce_malloc (size));
  21964. *data = (uint8) byte;
  21965. memcpy (data + 1, src, size - 1);
  21966. }
  21967. else if (byte == 0xff)
  21968. {
  21969. int n;
  21970. const int bytesLeft = readVariableLengthVal (src + 1, n);
  21971. size = jmin (sz + 1, n + 2 + bytesLeft);
  21972. data = static_cast<uint8*> (juce_malloc (size));
  21973. *data = (uint8) byte;
  21974. memcpy (data + 1, src, size - 1);
  21975. }
  21976. else
  21977. {
  21978. preallocatedData.asInt32 = 0;
  21979. size = getMessageLengthFromFirstByte ((uint8) byte);
  21980. data[0] = (uint8) byte;
  21981. if (size > 1)
  21982. {
  21983. data[1] = src[0];
  21984. if (size > 2)
  21985. data[2] = src[1];
  21986. }
  21987. }
  21988. numBytesUsed += size;
  21989. }
  21990. else
  21991. {
  21992. preallocatedData.asInt32 = 0;
  21993. size = 0;
  21994. }
  21995. }
  21996. MidiMessage& MidiMessage::operator= (const MidiMessage& other)
  21997. {
  21998. if (this != &other)
  21999. {
  22000. timeStamp = other.timeStamp;
  22001. size = other.size;
  22002. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22003. juce_free (data);
  22004. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  22005. {
  22006. data = static_cast<uint8*> (juce_malloc (size));
  22007. memcpy (data, other.data, size);
  22008. }
  22009. else
  22010. {
  22011. data = static_cast<uint8*> (preallocatedData.asBytes);
  22012. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  22013. }
  22014. }
  22015. return *this;
  22016. }
  22017. MidiMessage::~MidiMessage()
  22018. {
  22019. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22020. juce_free (data);
  22021. }
  22022. int MidiMessage::getChannel() const throw()
  22023. {
  22024. if ((data[0] & 0xf0) != 0xf0)
  22025. return (data[0] & 0xf) + 1;
  22026. else
  22027. return 0;
  22028. }
  22029. bool MidiMessage::isForChannel (const int channel) const throw()
  22030. {
  22031. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22032. return ((data[0] & 0xf) == channel - 1)
  22033. && ((data[0] & 0xf0) != 0xf0);
  22034. }
  22035. void MidiMessage::setChannel (const int channel) throw()
  22036. {
  22037. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22038. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22039. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22040. | (uint8)(channel - 1));
  22041. }
  22042. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22043. {
  22044. return ((data[0] & 0xf0) == 0x90)
  22045. && (returnTrueForVelocity0 || data[2] != 0);
  22046. }
  22047. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22048. {
  22049. return ((data[0] & 0xf0) == 0x80)
  22050. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22051. }
  22052. bool MidiMessage::isNoteOnOrOff() const throw()
  22053. {
  22054. const int d = data[0] & 0xf0;
  22055. return (d == 0x90) || (d == 0x80);
  22056. }
  22057. int MidiMessage::getNoteNumber() const throw()
  22058. {
  22059. return data[1];
  22060. }
  22061. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22062. {
  22063. if (isNoteOnOrOff())
  22064. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22065. }
  22066. uint8 MidiMessage::getVelocity() const throw()
  22067. {
  22068. if (isNoteOnOrOff())
  22069. return data[2];
  22070. else
  22071. return 0;
  22072. }
  22073. float MidiMessage::getFloatVelocity() const throw()
  22074. {
  22075. return getVelocity() * (1.0f / 127.0f);
  22076. }
  22077. void MidiMessage::setVelocity (const float newVelocity) throw()
  22078. {
  22079. if (isNoteOnOrOff())
  22080. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22081. }
  22082. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22083. {
  22084. if (isNoteOnOrOff())
  22085. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22086. }
  22087. bool MidiMessage::isAftertouch() const throw()
  22088. {
  22089. return (data[0] & 0xf0) == 0xa0;
  22090. }
  22091. int MidiMessage::getAfterTouchValue() const throw()
  22092. {
  22093. return data[2];
  22094. }
  22095. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22096. const int noteNum,
  22097. const int aftertouchValue) throw()
  22098. {
  22099. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22100. jassert (((unsigned int) noteNum) <= 127);
  22101. jassert (((unsigned int) aftertouchValue) <= 127);
  22102. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22103. noteNum & 0x7f,
  22104. aftertouchValue & 0x7f);
  22105. }
  22106. bool MidiMessage::isChannelPressure() const throw()
  22107. {
  22108. return (data[0] & 0xf0) == 0xd0;
  22109. }
  22110. int MidiMessage::getChannelPressureValue() const throw()
  22111. {
  22112. jassert (isChannelPressure());
  22113. return data[1];
  22114. }
  22115. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22116. const int pressure) throw()
  22117. {
  22118. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22119. jassert (((unsigned int) pressure) <= 127);
  22120. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22121. pressure & 0x7f);
  22122. }
  22123. bool MidiMessage::isProgramChange() const throw()
  22124. {
  22125. return (data[0] & 0xf0) == 0xc0;
  22126. }
  22127. int MidiMessage::getProgramChangeNumber() const throw()
  22128. {
  22129. return data[1];
  22130. }
  22131. const MidiMessage MidiMessage::programChange (const int channel,
  22132. const int programNumber) throw()
  22133. {
  22134. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22135. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22136. programNumber & 0x7f);
  22137. }
  22138. bool MidiMessage::isPitchWheel() const throw()
  22139. {
  22140. return (data[0] & 0xf0) == 0xe0;
  22141. }
  22142. int MidiMessage::getPitchWheelValue() const throw()
  22143. {
  22144. return data[1] | (data[2] << 7);
  22145. }
  22146. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22147. const int position) throw()
  22148. {
  22149. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22150. jassert (((unsigned int) position) <= 0x3fff);
  22151. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22152. position & 127,
  22153. (position >> 7) & 127);
  22154. }
  22155. bool MidiMessage::isController() const throw()
  22156. {
  22157. return (data[0] & 0xf0) == 0xb0;
  22158. }
  22159. int MidiMessage::getControllerNumber() const throw()
  22160. {
  22161. jassert (isController());
  22162. return data[1];
  22163. }
  22164. int MidiMessage::getControllerValue() const throw()
  22165. {
  22166. jassert (isController());
  22167. return data[2];
  22168. }
  22169. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22170. const int controllerType,
  22171. const int value) throw()
  22172. {
  22173. // the channel must be between 1 and 16 inclusive
  22174. jassert (channel > 0 && channel <= 16);
  22175. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22176. controllerType & 127,
  22177. value & 127);
  22178. }
  22179. const MidiMessage MidiMessage::noteOn (const int channel,
  22180. const int noteNumber,
  22181. const float velocity) throw()
  22182. {
  22183. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22184. }
  22185. const MidiMessage MidiMessage::noteOn (const int channel,
  22186. const int noteNumber,
  22187. const uint8 velocity) throw()
  22188. {
  22189. jassert (channel > 0 && channel <= 16);
  22190. jassert (((unsigned int) noteNumber) <= 127);
  22191. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22192. noteNumber & 127,
  22193. jlimit (0, 127, roundToInt (velocity)));
  22194. }
  22195. const MidiMessage MidiMessage::noteOff (const int channel,
  22196. const int noteNumber) throw()
  22197. {
  22198. jassert (channel > 0 && channel <= 16);
  22199. jassert (((unsigned int) noteNumber) <= 127);
  22200. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22201. }
  22202. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22203. {
  22204. jassert (channel > 0 && channel <= 16);
  22205. return controllerEvent (channel, 123, 0);
  22206. }
  22207. bool MidiMessage::isAllNotesOff() const throw()
  22208. {
  22209. return (data[0] & 0xf0) == 0xb0
  22210. && data[1] == 123;
  22211. }
  22212. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22213. {
  22214. return controllerEvent (channel, 120, 0);
  22215. }
  22216. bool MidiMessage::isAllSoundOff() const throw()
  22217. {
  22218. return (data[0] & 0xf0) == 0xb0
  22219. && data[1] == 120;
  22220. }
  22221. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22222. {
  22223. return controllerEvent (channel, 121, 0);
  22224. }
  22225. const MidiMessage MidiMessage::masterVolume (const float volume)
  22226. {
  22227. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22228. uint8 buf[8];
  22229. buf[0] = 0xf0;
  22230. buf[1] = 0x7f;
  22231. buf[2] = 0x7f;
  22232. buf[3] = 0x04;
  22233. buf[4] = 0x01;
  22234. buf[5] = (uint8) (vol & 0x7f);
  22235. buf[6] = (uint8) (vol >> 7);
  22236. buf[7] = 0xf7;
  22237. return MidiMessage (buf, 8);
  22238. }
  22239. bool MidiMessage::isSysEx() const throw()
  22240. {
  22241. return *data == 0xf0;
  22242. }
  22243. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData, const int dataSize)
  22244. {
  22245. MemoryBlock mm (dataSize + 2);
  22246. uint8* const m = static_cast <uint8*> (mm.getData());
  22247. m[0] = 0xf0;
  22248. memcpy (m + 1, sysexData, dataSize);
  22249. m[dataSize + 1] = 0xf7;
  22250. return MidiMessage (m, dataSize + 2);
  22251. }
  22252. const uint8* MidiMessage::getSysExData() const throw()
  22253. {
  22254. return (isSysEx()) ? getRawData() + 1 : 0;
  22255. }
  22256. int MidiMessage::getSysExDataSize() const throw()
  22257. {
  22258. return (isSysEx()) ? size - 2 : 0;
  22259. }
  22260. bool MidiMessage::isMetaEvent() const throw()
  22261. {
  22262. return *data == 0xff;
  22263. }
  22264. bool MidiMessage::isActiveSense() const throw()
  22265. {
  22266. return *data == 0xfe;
  22267. }
  22268. int MidiMessage::getMetaEventType() const throw()
  22269. {
  22270. if (*data != 0xff)
  22271. return -1;
  22272. else
  22273. return data[1];
  22274. }
  22275. int MidiMessage::getMetaEventLength() const throw()
  22276. {
  22277. if (*data == 0xff)
  22278. {
  22279. int n;
  22280. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22281. }
  22282. return 0;
  22283. }
  22284. const uint8* MidiMessage::getMetaEventData() const throw()
  22285. {
  22286. int n;
  22287. const uint8* d = data + 2;
  22288. readVariableLengthVal (d, n);
  22289. return d + n;
  22290. }
  22291. bool MidiMessage::isTrackMetaEvent() const throw()
  22292. {
  22293. return getMetaEventType() == 0;
  22294. }
  22295. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22296. {
  22297. return getMetaEventType() == 47;
  22298. }
  22299. bool MidiMessage::isTextMetaEvent() const throw()
  22300. {
  22301. const int t = getMetaEventType();
  22302. return t > 0 && t < 16;
  22303. }
  22304. const String MidiMessage::getTextFromTextMetaEvent() const
  22305. {
  22306. return String (reinterpret_cast <const char*> (getMetaEventData()), getMetaEventLength());
  22307. }
  22308. bool MidiMessage::isTrackNameEvent() const throw()
  22309. {
  22310. return (data[1] == 3)
  22311. && (*data == 0xff);
  22312. }
  22313. bool MidiMessage::isTempoMetaEvent() const throw()
  22314. {
  22315. return (data[1] == 81)
  22316. && (*data == 0xff);
  22317. }
  22318. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22319. {
  22320. return (data[1] == 0x20)
  22321. && (*data == 0xff)
  22322. && (data[2] == 1);
  22323. }
  22324. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22325. {
  22326. return data[3] + 1;
  22327. }
  22328. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22329. {
  22330. if (! isTempoMetaEvent())
  22331. return 0.0;
  22332. const uint8* const d = getMetaEventData();
  22333. return (((unsigned int) d[0] << 16)
  22334. | ((unsigned int) d[1] << 8)
  22335. | d[2])
  22336. / 1000000.0;
  22337. }
  22338. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22339. {
  22340. if (timeFormat > 0)
  22341. {
  22342. if (! isTempoMetaEvent())
  22343. return 0.5 / timeFormat;
  22344. return getTempoSecondsPerQuarterNote() / timeFormat;
  22345. }
  22346. else
  22347. {
  22348. const int frameCode = (-timeFormat) >> 8;
  22349. double framesPerSecond;
  22350. switch (frameCode)
  22351. {
  22352. case 24: framesPerSecond = 24.0; break;
  22353. case 25: framesPerSecond = 25.0; break;
  22354. case 29: framesPerSecond = 29.97; break;
  22355. case 30: framesPerSecond = 30.0; break;
  22356. default: framesPerSecond = 30.0; break;
  22357. }
  22358. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22359. }
  22360. }
  22361. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22362. {
  22363. uint8 d[8];
  22364. d[0] = 0xff;
  22365. d[1] = 81;
  22366. d[2] = 3;
  22367. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22368. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22369. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22370. return MidiMessage (d, 6, 0.0);
  22371. }
  22372. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22373. {
  22374. return (data[1] == 0x58)
  22375. && (*data == (uint8) 0xff);
  22376. }
  22377. void MidiMessage::getTimeSignatureInfo (int& numerator, int& denominator) const throw()
  22378. {
  22379. if (isTimeSignatureMetaEvent())
  22380. {
  22381. const uint8* const d = getMetaEventData();
  22382. numerator = d[0];
  22383. denominator = 1 << d[1];
  22384. }
  22385. else
  22386. {
  22387. numerator = 4;
  22388. denominator = 4;
  22389. }
  22390. }
  22391. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator, const int denominator)
  22392. {
  22393. uint8 d[8];
  22394. d[0] = 0xff;
  22395. d[1] = 0x58;
  22396. d[2] = 0x04;
  22397. d[3] = (uint8) numerator;
  22398. int n = 1;
  22399. int powerOfTwo = 0;
  22400. while (n < denominator)
  22401. {
  22402. n <<= 1;
  22403. ++powerOfTwo;
  22404. }
  22405. d[4] = (uint8) powerOfTwo;
  22406. d[5] = 0x01;
  22407. d[6] = 96;
  22408. return MidiMessage (d, 7, 0.0);
  22409. }
  22410. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22411. {
  22412. uint8 d[8];
  22413. d[0] = 0xff;
  22414. d[1] = 0x20;
  22415. d[2] = 0x01;
  22416. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22417. return MidiMessage (d, 4, 0.0);
  22418. }
  22419. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22420. {
  22421. return getMetaEventType() == 89;
  22422. }
  22423. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22424. {
  22425. return (int) *getMetaEventData();
  22426. }
  22427. const MidiMessage MidiMessage::endOfTrack() throw()
  22428. {
  22429. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22430. }
  22431. bool MidiMessage::isSongPositionPointer() const throw()
  22432. {
  22433. return *data == 0xf2;
  22434. }
  22435. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22436. {
  22437. return data[1] | (data[2] << 7);
  22438. }
  22439. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22440. {
  22441. return MidiMessage (0xf2,
  22442. positionInMidiBeats & 127,
  22443. (positionInMidiBeats >> 7) & 127);
  22444. }
  22445. bool MidiMessage::isMidiStart() const throw()
  22446. {
  22447. return *data == 0xfa;
  22448. }
  22449. const MidiMessage MidiMessage::midiStart() throw()
  22450. {
  22451. return MidiMessage (0xfa);
  22452. }
  22453. bool MidiMessage::isMidiContinue() const throw()
  22454. {
  22455. return *data == 0xfb;
  22456. }
  22457. const MidiMessage MidiMessage::midiContinue() throw()
  22458. {
  22459. return MidiMessage (0xfb);
  22460. }
  22461. bool MidiMessage::isMidiStop() const throw()
  22462. {
  22463. return *data == 0xfc;
  22464. }
  22465. const MidiMessage MidiMessage::midiStop() throw()
  22466. {
  22467. return MidiMessage (0xfc);
  22468. }
  22469. bool MidiMessage::isMidiClock() const throw()
  22470. {
  22471. return *data == 0xf8;
  22472. }
  22473. const MidiMessage MidiMessage::midiClock() throw()
  22474. {
  22475. return MidiMessage (0xf8);
  22476. }
  22477. bool MidiMessage::isQuarterFrame() const throw()
  22478. {
  22479. return *data == 0xf1;
  22480. }
  22481. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22482. {
  22483. return ((int) data[1]) >> 4;
  22484. }
  22485. int MidiMessage::getQuarterFrameValue() const throw()
  22486. {
  22487. return ((int) data[1]) & 0x0f;
  22488. }
  22489. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22490. const int value) throw()
  22491. {
  22492. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22493. }
  22494. bool MidiMessage::isFullFrame() const throw()
  22495. {
  22496. return data[0] == 0xf0
  22497. && data[1] == 0x7f
  22498. && size >= 10
  22499. && data[3] == 0x01
  22500. && data[4] == 0x01;
  22501. }
  22502. void MidiMessage::getFullFrameParameters (int& hours,
  22503. int& minutes,
  22504. int& seconds,
  22505. int& frames,
  22506. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22507. {
  22508. jassert (isFullFrame());
  22509. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22510. hours = data[5] & 0x1f;
  22511. minutes = data[6];
  22512. seconds = data[7];
  22513. frames = data[8];
  22514. }
  22515. const MidiMessage MidiMessage::fullFrame (const int hours,
  22516. const int minutes,
  22517. const int seconds,
  22518. const int frames,
  22519. MidiMessage::SmpteTimecodeType timecodeType)
  22520. {
  22521. uint8 d[10];
  22522. d[0] = 0xf0;
  22523. d[1] = 0x7f;
  22524. d[2] = 0x7f;
  22525. d[3] = 0x01;
  22526. d[4] = 0x01;
  22527. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22528. d[6] = (uint8) minutes;
  22529. d[7] = (uint8) seconds;
  22530. d[8] = (uint8) frames;
  22531. d[9] = 0xf7;
  22532. return MidiMessage (d, 10, 0.0);
  22533. }
  22534. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22535. {
  22536. return data[0] == 0xf0
  22537. && data[1] == 0x7f
  22538. && data[3] == 0x06
  22539. && size > 5;
  22540. }
  22541. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22542. {
  22543. jassert (isMidiMachineControlMessage());
  22544. return (MidiMachineControlCommand) data[4];
  22545. }
  22546. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22547. {
  22548. uint8 d[6];
  22549. d[0] = 0xf0;
  22550. d[1] = 0x7f;
  22551. d[2] = 0x00;
  22552. d[3] = 0x06;
  22553. d[4] = (uint8) command;
  22554. d[5] = 0xf7;
  22555. return MidiMessage (d, 6, 0.0);
  22556. }
  22557. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22558. int& minutes,
  22559. int& seconds,
  22560. int& frames) const throw()
  22561. {
  22562. if (size >= 12
  22563. && data[0] == 0xf0
  22564. && data[1] == 0x7f
  22565. && data[3] == 0x06
  22566. && data[4] == 0x44
  22567. && data[5] == 0x06
  22568. && data[6] == 0x01)
  22569. {
  22570. hours = data[7] % 24; // (that some machines send out hours > 24)
  22571. minutes = data[8];
  22572. seconds = data[9];
  22573. frames = data[10];
  22574. return true;
  22575. }
  22576. return false;
  22577. }
  22578. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22579. int minutes,
  22580. int seconds,
  22581. int frames)
  22582. {
  22583. uint8 d[12];
  22584. d[0] = 0xf0;
  22585. d[1] = 0x7f;
  22586. d[2] = 0x00;
  22587. d[3] = 0x06;
  22588. d[4] = 0x44;
  22589. d[5] = 0x06;
  22590. d[6] = 0x01;
  22591. d[7] = (uint8) hours;
  22592. d[8] = (uint8) minutes;
  22593. d[9] = (uint8) seconds;
  22594. d[10] = (uint8) frames;
  22595. d[11] = 0xf7;
  22596. return MidiMessage (d, 12, 0.0);
  22597. }
  22598. const String MidiMessage::getMidiNoteName (int note,
  22599. bool useSharps,
  22600. bool includeOctaveNumber,
  22601. int octaveNumForMiddleC) throw()
  22602. {
  22603. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22604. "F", "F#", "G", "G#", "A",
  22605. "A#", "B" };
  22606. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22607. "F", "Gb", "G", "Ab", "A",
  22608. "Bb", "B" };
  22609. if (((unsigned int) note) < 128)
  22610. {
  22611. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22612. : flatNoteNames [note % 12]);
  22613. if (includeOctaveNumber)
  22614. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22615. else
  22616. return s;
  22617. }
  22618. return String::empty;
  22619. }
  22620. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22621. {
  22622. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22623. return 440.0 * pow (2.0, noteNumber / 12.0);
  22624. }
  22625. const String MidiMessage::getGMInstrumentName (int n) throw()
  22626. {
  22627. const char *names[] =
  22628. {
  22629. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22630. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22631. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22632. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22633. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22634. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22635. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22636. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22637. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22638. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22639. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22640. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22641. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22642. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22643. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22644. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22645. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22646. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22647. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22648. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22649. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22650. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22651. "Applause", "Gunshot"
  22652. };
  22653. return (((unsigned int) n) < 128) ? names[n]
  22654. : (const char*)0;
  22655. }
  22656. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22657. {
  22658. const char* names[] =
  22659. {
  22660. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22661. "Bass", "Strings", "Ensemble", "Brass",
  22662. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22663. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22664. };
  22665. return (((unsigned int) n) <= 15) ? names[n]
  22666. : (const char*)0;
  22667. }
  22668. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22669. {
  22670. const char* names[] =
  22671. {
  22672. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22673. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22674. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22675. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22676. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22677. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22678. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22679. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22680. "Mute Triangle", "Open Triangle"
  22681. };
  22682. return (n >= 35 && n <= 81) ? names [n - 35]
  22683. : (const char*)0;
  22684. }
  22685. const String MidiMessage::getControllerName (int n) throw()
  22686. {
  22687. const char* names[] =
  22688. {
  22689. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22690. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22691. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22692. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22693. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22694. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22695. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22696. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22697. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22698. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22699. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22700. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22701. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22702. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22703. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22704. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22705. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22706. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22707. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22709. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22710. "Poly Operation"
  22711. };
  22712. return (((unsigned int) n) < 128) ? names[n]
  22713. : (const char*)0;
  22714. }
  22715. END_JUCE_NAMESPACE
  22716. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22717. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22718. BEGIN_JUCE_NAMESPACE
  22719. MidiMessageCollector::MidiMessageCollector()
  22720. : lastCallbackTime (0),
  22721. sampleRate (44100.0001)
  22722. {
  22723. }
  22724. MidiMessageCollector::~MidiMessageCollector()
  22725. {
  22726. }
  22727. void MidiMessageCollector::reset (const double sampleRate_)
  22728. {
  22729. jassert (sampleRate_ > 0);
  22730. const ScopedLock sl (midiCallbackLock);
  22731. sampleRate = sampleRate_;
  22732. incomingMessages.clear();
  22733. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22734. }
  22735. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22736. {
  22737. // you need to call reset() to set the correct sample rate before using this object
  22738. jassert (sampleRate != 44100.0001);
  22739. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22740. // for details of what the number should be.
  22741. jassert (message.getTimeStamp() != 0);
  22742. const ScopedLock sl (midiCallbackLock);
  22743. const int sampleNumber
  22744. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22745. incomingMessages.addEvent (message, sampleNumber);
  22746. // if the messages don't get used for over a second, we'd better
  22747. // get rid of any old ones to avoid the queue getting too big
  22748. if (sampleNumber > sampleRate)
  22749. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22750. }
  22751. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22752. const int numSamples)
  22753. {
  22754. // you need to call reset() to set the correct sample rate before using this object
  22755. jassert (sampleRate != 44100.0001);
  22756. const double timeNow = Time::getMillisecondCounterHiRes();
  22757. const double msElapsed = timeNow - lastCallbackTime;
  22758. const ScopedLock sl (midiCallbackLock);
  22759. lastCallbackTime = timeNow;
  22760. if (! incomingMessages.isEmpty())
  22761. {
  22762. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22763. int startSample = 0;
  22764. int scale = 1 << 16;
  22765. const uint8* midiData;
  22766. int numBytes, samplePosition;
  22767. MidiBuffer::Iterator iter (incomingMessages);
  22768. if (numSourceSamples > numSamples)
  22769. {
  22770. // if our list of events is longer than the buffer we're being
  22771. // asked for, scale them down to squeeze them all in..
  22772. const int maxBlockLengthToUse = numSamples << 5;
  22773. if (numSourceSamples > maxBlockLengthToUse)
  22774. {
  22775. startSample = numSourceSamples - maxBlockLengthToUse;
  22776. numSourceSamples = maxBlockLengthToUse;
  22777. iter.setNextSamplePosition (startSample);
  22778. }
  22779. scale = (numSamples << 10) / numSourceSamples;
  22780. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22781. {
  22782. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22783. destBuffer.addEvent (midiData, numBytes,
  22784. jlimit (0, numSamples - 1, samplePosition));
  22785. }
  22786. }
  22787. else
  22788. {
  22789. // if our event list is shorter than the number we need, put them
  22790. // towards the end of the buffer
  22791. startSample = numSamples - numSourceSamples;
  22792. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22793. {
  22794. destBuffer.addEvent (midiData, numBytes,
  22795. jlimit (0, numSamples - 1, samplePosition + startSample));
  22796. }
  22797. }
  22798. incomingMessages.clear();
  22799. }
  22800. }
  22801. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22802. {
  22803. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22804. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22805. addMessageToQueue (m);
  22806. }
  22807. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22808. {
  22809. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22810. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22811. addMessageToQueue (m);
  22812. }
  22813. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22814. {
  22815. addMessageToQueue (message);
  22816. }
  22817. END_JUCE_NAMESPACE
  22818. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22819. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22820. BEGIN_JUCE_NAMESPACE
  22821. MidiMessageSequence::MidiMessageSequence()
  22822. {
  22823. }
  22824. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22825. {
  22826. list.ensureStorageAllocated (other.list.size());
  22827. for (int i = 0; i < other.list.size(); ++i)
  22828. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22829. }
  22830. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22831. {
  22832. MidiMessageSequence otherCopy (other);
  22833. swapWith (otherCopy);
  22834. return *this;
  22835. }
  22836. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22837. {
  22838. list.swapWithArray (other.list);
  22839. }
  22840. MidiMessageSequence::~MidiMessageSequence()
  22841. {
  22842. }
  22843. void MidiMessageSequence::clear()
  22844. {
  22845. list.clear();
  22846. }
  22847. int MidiMessageSequence::getNumEvents() const
  22848. {
  22849. return list.size();
  22850. }
  22851. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22852. {
  22853. return list [index];
  22854. }
  22855. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22856. {
  22857. const MidiEventHolder* const meh = list [index];
  22858. if (meh != 0 && meh->noteOffObject != 0)
  22859. return meh->noteOffObject->message.getTimeStamp();
  22860. else
  22861. return 0.0;
  22862. }
  22863. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22864. {
  22865. const MidiEventHolder* const meh = list [index];
  22866. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22867. }
  22868. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22869. {
  22870. return list.indexOf (event);
  22871. }
  22872. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22873. {
  22874. const int numEvents = list.size();
  22875. int i;
  22876. for (i = 0; i < numEvents; ++i)
  22877. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  22878. break;
  22879. return i;
  22880. }
  22881. double MidiMessageSequence::getStartTime() const
  22882. {
  22883. if (list.size() > 0)
  22884. return list.getUnchecked(0)->message.getTimeStamp();
  22885. else
  22886. return 0;
  22887. }
  22888. double MidiMessageSequence::getEndTime() const
  22889. {
  22890. if (list.size() > 0)
  22891. return list.getLast()->message.getTimeStamp();
  22892. else
  22893. return 0;
  22894. }
  22895. double MidiMessageSequence::getEventTime (const int index) const
  22896. {
  22897. if (((unsigned int) index) < (unsigned int) list.size())
  22898. return list.getUnchecked (index)->message.getTimeStamp();
  22899. return 0.0;
  22900. }
  22901. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  22902. double timeAdjustment)
  22903. {
  22904. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  22905. timeAdjustment += newMessage.getTimeStamp();
  22906. newOne->message.setTimeStamp (timeAdjustment);
  22907. int i;
  22908. for (i = list.size(); --i >= 0;)
  22909. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  22910. break;
  22911. list.insert (i + 1, newOne);
  22912. }
  22913. void MidiMessageSequence::deleteEvent (const int index,
  22914. const bool deleteMatchingNoteUp)
  22915. {
  22916. if (((unsigned int) index) < (unsigned int) list.size())
  22917. {
  22918. if (deleteMatchingNoteUp)
  22919. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  22920. list.remove (index);
  22921. }
  22922. }
  22923. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  22924. double timeAdjustment,
  22925. double firstAllowableTime,
  22926. double endOfAllowableDestTimes)
  22927. {
  22928. firstAllowableTime -= timeAdjustment;
  22929. endOfAllowableDestTimes -= timeAdjustment;
  22930. for (int i = 0; i < other.list.size(); ++i)
  22931. {
  22932. const MidiMessage& m = other.list.getUnchecked(i)->message;
  22933. const double t = m.getTimeStamp();
  22934. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  22935. {
  22936. MidiEventHolder* const newOne = new MidiEventHolder (m);
  22937. newOne->message.setTimeStamp (timeAdjustment + t);
  22938. list.add (newOne);
  22939. }
  22940. }
  22941. sort();
  22942. }
  22943. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  22944. const MidiMessageSequence::MidiEventHolder* const second) throw()
  22945. {
  22946. const double diff = first->message.getTimeStamp()
  22947. - second->message.getTimeStamp();
  22948. return (diff > 0) - (diff < 0);
  22949. }
  22950. void MidiMessageSequence::sort()
  22951. {
  22952. list.sort (*this, true);
  22953. }
  22954. void MidiMessageSequence::updateMatchedPairs()
  22955. {
  22956. for (int i = 0; i < list.size(); ++i)
  22957. {
  22958. const MidiMessage& m1 = list.getUnchecked(i)->message;
  22959. if (m1.isNoteOn())
  22960. {
  22961. list.getUnchecked(i)->noteOffObject = 0;
  22962. const int note = m1.getNoteNumber();
  22963. const int chan = m1.getChannel();
  22964. const int len = list.size();
  22965. for (int j = i + 1; j < len; ++j)
  22966. {
  22967. const MidiMessage& m = list.getUnchecked(j)->message;
  22968. if (m.getNoteNumber() == note && m.getChannel() == chan)
  22969. {
  22970. if (m.isNoteOff())
  22971. {
  22972. list.getUnchecked(i)->noteOffObject = list[j];
  22973. break;
  22974. }
  22975. else if (m.isNoteOn())
  22976. {
  22977. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  22978. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  22979. list.getUnchecked(i)->noteOffObject = list[j];
  22980. break;
  22981. }
  22982. }
  22983. }
  22984. }
  22985. }
  22986. }
  22987. void MidiMessageSequence::addTimeToMessages (const double delta)
  22988. {
  22989. for (int i = list.size(); --i >= 0;)
  22990. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  22991. + delta);
  22992. }
  22993. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  22994. MidiMessageSequence& destSequence,
  22995. const bool alsoIncludeMetaEvents) const
  22996. {
  22997. for (int i = 0; i < list.size(); ++i)
  22998. {
  22999. const MidiMessage& mm = list.getUnchecked(i)->message;
  23000. if (mm.isForChannel (channelNumberToExtract)
  23001. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23002. {
  23003. destSequence.addEvent (mm);
  23004. }
  23005. }
  23006. }
  23007. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23008. {
  23009. for (int i = 0; i < list.size(); ++i)
  23010. {
  23011. const MidiMessage& mm = list.getUnchecked(i)->message;
  23012. if (mm.isSysEx())
  23013. destSequence.addEvent (mm);
  23014. }
  23015. }
  23016. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23017. {
  23018. for (int i = list.size(); --i >= 0;)
  23019. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23020. list.remove(i);
  23021. }
  23022. void MidiMessageSequence::deleteSysExMessages()
  23023. {
  23024. for (int i = list.size(); --i >= 0;)
  23025. if (list.getUnchecked(i)->message.isSysEx())
  23026. list.remove(i);
  23027. }
  23028. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23029. const double time,
  23030. OwnedArray<MidiMessage>& dest)
  23031. {
  23032. bool doneProg = false;
  23033. bool donePitchWheel = false;
  23034. Array <int> doneControllers;
  23035. doneControllers.ensureStorageAllocated (32);
  23036. for (int i = list.size(); --i >= 0;)
  23037. {
  23038. const MidiMessage& mm = list.getUnchecked(i)->message;
  23039. if (mm.isForChannel (channelNumber)
  23040. && mm.getTimeStamp() <= time)
  23041. {
  23042. if (mm.isProgramChange())
  23043. {
  23044. if (! doneProg)
  23045. {
  23046. dest.add (new MidiMessage (mm, 0.0));
  23047. doneProg = true;
  23048. }
  23049. }
  23050. else if (mm.isController())
  23051. {
  23052. if (! doneControllers.contains (mm.getControllerNumber()))
  23053. {
  23054. dest.add (new MidiMessage (mm, 0.0));
  23055. doneControllers.add (mm.getControllerNumber());
  23056. }
  23057. }
  23058. else if (mm.isPitchWheel())
  23059. {
  23060. if (! donePitchWheel)
  23061. {
  23062. dest.add (new MidiMessage (mm, 0.0));
  23063. donePitchWheel = true;
  23064. }
  23065. }
  23066. }
  23067. }
  23068. }
  23069. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23070. : message (message_),
  23071. noteOffObject (0)
  23072. {
  23073. }
  23074. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23075. {
  23076. }
  23077. END_JUCE_NAMESPACE
  23078. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23079. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23080. BEGIN_JUCE_NAMESPACE
  23081. AudioPluginFormat::AudioPluginFormat() throw()
  23082. {
  23083. }
  23084. AudioPluginFormat::~AudioPluginFormat()
  23085. {
  23086. }
  23087. END_JUCE_NAMESPACE
  23088. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23089. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23090. BEGIN_JUCE_NAMESPACE
  23091. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23092. {
  23093. }
  23094. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23095. {
  23096. clearSingletonInstance();
  23097. }
  23098. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23099. void AudioPluginFormatManager::addDefaultFormats()
  23100. {
  23101. #ifdef JUCE_DEBUG
  23102. // you should only call this method once!
  23103. for (int i = formats.size(); --i >= 0;)
  23104. {
  23105. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23106. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23107. #endif
  23108. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23109. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23110. #endif
  23111. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23112. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23113. #endif
  23114. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23115. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23116. #endif
  23117. }
  23118. #endif
  23119. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23120. formats.add (new AudioUnitPluginFormat());
  23121. #endif
  23122. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23123. formats.add (new VSTPluginFormat());
  23124. #endif
  23125. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23126. formats.add (new DirectXPluginFormat());
  23127. #endif
  23128. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23129. formats.add (new LADSPAPluginFormat());
  23130. #endif
  23131. }
  23132. int AudioPluginFormatManager::getNumFormats() throw()
  23133. {
  23134. return formats.size();
  23135. }
  23136. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23137. {
  23138. return formats [index];
  23139. }
  23140. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23141. {
  23142. formats.add (format);
  23143. }
  23144. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23145. String& errorMessage) const
  23146. {
  23147. AudioPluginInstance* result = 0;
  23148. for (int i = 0; i < formats.size(); ++i)
  23149. {
  23150. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23151. if (result != 0)
  23152. break;
  23153. }
  23154. if (result == 0)
  23155. {
  23156. if (! doesPluginStillExist (description))
  23157. errorMessage = TRANS ("This plug-in file no longer exists");
  23158. else
  23159. errorMessage = TRANS ("This plug-in failed to load correctly");
  23160. }
  23161. return result;
  23162. }
  23163. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23164. {
  23165. for (int i = 0; i < formats.size(); ++i)
  23166. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23167. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23168. return false;
  23169. }
  23170. END_JUCE_NAMESPACE
  23171. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23172. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23173. #define JUCE_PLUGIN_HOST 1
  23174. BEGIN_JUCE_NAMESPACE
  23175. AudioPluginInstance::AudioPluginInstance()
  23176. {
  23177. }
  23178. AudioPluginInstance::~AudioPluginInstance()
  23179. {
  23180. }
  23181. END_JUCE_NAMESPACE
  23182. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23183. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23184. BEGIN_JUCE_NAMESPACE
  23185. KnownPluginList::KnownPluginList()
  23186. {
  23187. }
  23188. KnownPluginList::~KnownPluginList()
  23189. {
  23190. }
  23191. void KnownPluginList::clear()
  23192. {
  23193. if (types.size() > 0)
  23194. {
  23195. types.clear();
  23196. sendChangeMessage (this);
  23197. }
  23198. }
  23199. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23200. {
  23201. for (int i = 0; i < types.size(); ++i)
  23202. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23203. return types.getUnchecked(i);
  23204. return 0;
  23205. }
  23206. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23207. {
  23208. for (int i = 0; i < types.size(); ++i)
  23209. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23210. return types.getUnchecked(i);
  23211. return 0;
  23212. }
  23213. bool KnownPluginList::addType (const PluginDescription& type)
  23214. {
  23215. for (int i = types.size(); --i >= 0;)
  23216. {
  23217. if (types.getUnchecked(i)->isDuplicateOf (type))
  23218. {
  23219. // strange - found a duplicate plugin with different info..
  23220. jassert (types.getUnchecked(i)->name == type.name);
  23221. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23222. *types.getUnchecked(i) = type;
  23223. return false;
  23224. }
  23225. }
  23226. types.add (new PluginDescription (type));
  23227. sendChangeMessage (this);
  23228. return true;
  23229. }
  23230. void KnownPluginList::removeType (const int index) throw()
  23231. {
  23232. types.remove (index);
  23233. sendChangeMessage (this);
  23234. }
  23235. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23236. {
  23237. if (fileOrIdentifier.startsWithChar ('/')
  23238. || fileOrIdentifier[1] == ':')
  23239. {
  23240. return File (fileOrIdentifier).getLastModificationTime();
  23241. }
  23242. return Time (0);
  23243. }
  23244. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23245. {
  23246. return t1 != t2 || t1 == Time (0);
  23247. }
  23248. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23249. {
  23250. if (getTypeForFile (fileOrIdentifier) == 0)
  23251. return false;
  23252. for (int i = types.size(); --i >= 0;)
  23253. {
  23254. const PluginDescription* const d = types.getUnchecked(i);
  23255. if (d->fileOrIdentifier == fileOrIdentifier
  23256. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23257. {
  23258. return false;
  23259. }
  23260. }
  23261. return true;
  23262. }
  23263. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23264. const bool dontRescanIfAlreadyInList,
  23265. OwnedArray <PluginDescription>& typesFound,
  23266. AudioPluginFormat& format)
  23267. {
  23268. bool addedOne = false;
  23269. if (dontRescanIfAlreadyInList
  23270. && getTypeForFile (fileOrIdentifier) != 0)
  23271. {
  23272. bool needsRescanning = false;
  23273. for (int i = types.size(); --i >= 0;)
  23274. {
  23275. const PluginDescription* const d = types.getUnchecked(i);
  23276. if (d->fileOrIdentifier == fileOrIdentifier)
  23277. {
  23278. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23279. needsRescanning = true;
  23280. else
  23281. typesFound.add (new PluginDescription (*d));
  23282. }
  23283. }
  23284. if (! needsRescanning)
  23285. return false;
  23286. }
  23287. OwnedArray <PluginDescription> found;
  23288. format.findAllTypesForFile (found, fileOrIdentifier);
  23289. for (int i = 0; i < found.size(); ++i)
  23290. {
  23291. PluginDescription* const desc = found.getUnchecked(i);
  23292. jassert (desc != 0);
  23293. if (addType (*desc))
  23294. addedOne = true;
  23295. typesFound.add (new PluginDescription (*desc));
  23296. }
  23297. return addedOne;
  23298. }
  23299. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23300. OwnedArray <PluginDescription>& typesFound)
  23301. {
  23302. for (int i = 0; i < files.size(); ++i)
  23303. {
  23304. bool loaded = false;
  23305. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23306. {
  23307. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23308. if (scanAndAddFile (files[i], true, typesFound, *format))
  23309. loaded = true;
  23310. }
  23311. if (! loaded)
  23312. {
  23313. const File f (files[i]);
  23314. if (f.isDirectory())
  23315. {
  23316. StringArray s;
  23317. {
  23318. Array<File> subFiles;
  23319. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23320. for (int j = 0; j < subFiles.size(); ++j)
  23321. s.add (subFiles.getReference(j).getFullPathName());
  23322. }
  23323. scanAndAddDragAndDroppedFiles (s, typesFound);
  23324. }
  23325. }
  23326. }
  23327. }
  23328. class PluginSorter
  23329. {
  23330. public:
  23331. KnownPluginList::SortMethod method;
  23332. PluginSorter() throw() {}
  23333. int compareElements (const PluginDescription* const first,
  23334. const PluginDescription* const second) const throw()
  23335. {
  23336. int diff = 0;
  23337. if (method == KnownPluginList::sortByCategory)
  23338. diff = first->category.compareLexicographically (second->category);
  23339. else if (method == KnownPluginList::sortByManufacturer)
  23340. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23341. else if (method == KnownPluginList::sortByFileSystemLocation)
  23342. diff = first->fileOrIdentifier.replaceCharacter ('\\', '/')
  23343. .upToLastOccurrenceOf ("/", false, false)
  23344. .compare (second->fileOrIdentifier.replaceCharacter ('\\', '/')
  23345. .upToLastOccurrenceOf ("/", false, false));
  23346. if (diff == 0)
  23347. diff = first->name.compareLexicographically (second->name);
  23348. return diff;
  23349. }
  23350. };
  23351. void KnownPluginList::sort (const SortMethod method)
  23352. {
  23353. if (method != defaultOrder)
  23354. {
  23355. PluginSorter sorter;
  23356. sorter.method = method;
  23357. types.sort (sorter, true);
  23358. sendChangeMessage (this);
  23359. }
  23360. }
  23361. XmlElement* KnownPluginList::createXml() const
  23362. {
  23363. XmlElement* const e = new XmlElement ("KNOWNPLUGINS");
  23364. for (int i = 0; i < types.size(); ++i)
  23365. e->addChildElement (types.getUnchecked(i)->createXml());
  23366. return e;
  23367. }
  23368. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23369. {
  23370. clear();
  23371. if (xml.hasTagName ("KNOWNPLUGINS"))
  23372. {
  23373. forEachXmlChildElement (xml, e)
  23374. {
  23375. PluginDescription info;
  23376. if (info.loadFromXml (*e))
  23377. addType (info);
  23378. }
  23379. }
  23380. }
  23381. const int menuIdBase = 0x324503f4;
  23382. // This is used to turn a bunch of paths into a nested menu structure.
  23383. struct PluginFilesystemTree
  23384. {
  23385. private:
  23386. String folder;
  23387. OwnedArray <PluginFilesystemTree> subFolders;
  23388. Array <PluginDescription*> plugins;
  23389. void addPlugin (PluginDescription* const pd, const String& path)
  23390. {
  23391. if (path.isEmpty())
  23392. {
  23393. plugins.add (pd);
  23394. }
  23395. else
  23396. {
  23397. const String firstSubFolder (path.upToFirstOccurrenceOf ("/", false, false));
  23398. const String remainingPath (path.fromFirstOccurrenceOf ("/", false, false));
  23399. for (int i = subFolders.size(); --i >= 0;)
  23400. {
  23401. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23402. {
  23403. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23404. return;
  23405. }
  23406. }
  23407. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23408. newFolder->folder = firstSubFolder;
  23409. subFolders.add (newFolder);
  23410. newFolder->addPlugin (pd, remainingPath);
  23411. }
  23412. }
  23413. // removes any deeply nested folders that don't contain any actual plugins
  23414. void optimise()
  23415. {
  23416. for (int i = subFolders.size(); --i >= 0;)
  23417. {
  23418. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23419. sub->optimise();
  23420. if (sub->plugins.size() == 0)
  23421. {
  23422. for (int j = 0; j < sub->subFolders.size(); ++j)
  23423. subFolders.add (sub->subFolders.getUnchecked(j));
  23424. sub->subFolders.clear (false);
  23425. subFolders.remove (i);
  23426. }
  23427. }
  23428. }
  23429. public:
  23430. void buildTree (const Array <PluginDescription*>& allPlugins)
  23431. {
  23432. for (int i = 0; i < allPlugins.size(); ++i)
  23433. {
  23434. String path (allPlugins.getUnchecked(i)
  23435. ->fileOrIdentifier.replaceCharacter ('\\', '/')
  23436. .upToLastOccurrenceOf ("/", false, false));
  23437. if (path.substring (1, 2) == ":")
  23438. path = path.substring (2);
  23439. addPlugin (allPlugins.getUnchecked(i), path);
  23440. }
  23441. optimise();
  23442. }
  23443. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23444. {
  23445. int i;
  23446. for (i = 0; i < subFolders.size(); ++i)
  23447. {
  23448. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23449. PopupMenu subMenu;
  23450. sub->addToMenu (subMenu, allPlugins);
  23451. #if JUCE_MAC
  23452. // avoid the special AU formatting nonsense on Mac..
  23453. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (":", false, false), subMenu);
  23454. #else
  23455. m.addSubMenu (sub->folder, subMenu);
  23456. #endif
  23457. }
  23458. for (i = 0; i < plugins.size(); ++i)
  23459. {
  23460. PluginDescription* const plugin = plugins.getUnchecked(i);
  23461. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23462. plugin->name, true, false);
  23463. }
  23464. }
  23465. };
  23466. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23467. {
  23468. Array <PluginDescription*> sorted;
  23469. {
  23470. PluginSorter sorter;
  23471. sorter.method = sortMethod;
  23472. for (int i = 0; i < types.size(); ++i)
  23473. sorted.addSorted (sorter, types.getUnchecked(i));
  23474. }
  23475. if (sortMethod == sortByCategory
  23476. || sortMethod == sortByManufacturer)
  23477. {
  23478. String lastSubMenuName;
  23479. PopupMenu sub;
  23480. for (int i = 0; i < sorted.size(); ++i)
  23481. {
  23482. const PluginDescription* const pd = sorted.getUnchecked(i);
  23483. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23484. : pd->manufacturerName);
  23485. if (! thisSubMenuName.containsNonWhitespaceChars())
  23486. thisSubMenuName = "Other";
  23487. if (thisSubMenuName != lastSubMenuName)
  23488. {
  23489. if (sub.getNumItems() > 0)
  23490. {
  23491. menu.addSubMenu (lastSubMenuName, sub);
  23492. sub.clear();
  23493. }
  23494. lastSubMenuName = thisSubMenuName;
  23495. }
  23496. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23497. }
  23498. if (sub.getNumItems() > 0)
  23499. menu.addSubMenu (lastSubMenuName, sub);
  23500. }
  23501. else if (sortMethod == sortByFileSystemLocation)
  23502. {
  23503. PluginFilesystemTree root;
  23504. root.buildTree (sorted);
  23505. root.addToMenu (menu, types);
  23506. }
  23507. else
  23508. {
  23509. for (int i = 0; i < sorted.size(); ++i)
  23510. {
  23511. const PluginDescription* const pd = sorted.getUnchecked(i);
  23512. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23513. }
  23514. }
  23515. }
  23516. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23517. {
  23518. const int i = menuResultCode - menuIdBase;
  23519. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23520. }
  23521. END_JUCE_NAMESPACE
  23522. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23523. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23524. BEGIN_JUCE_NAMESPACE
  23525. PluginDescription::PluginDescription() throw()
  23526. : uid (0),
  23527. isInstrument (false),
  23528. numInputChannels (0),
  23529. numOutputChannels (0)
  23530. {
  23531. }
  23532. PluginDescription::~PluginDescription() throw()
  23533. {
  23534. }
  23535. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23536. : name (other.name),
  23537. pluginFormatName (other.pluginFormatName),
  23538. category (other.category),
  23539. manufacturerName (other.manufacturerName),
  23540. version (other.version),
  23541. fileOrIdentifier (other.fileOrIdentifier),
  23542. lastFileModTime (other.lastFileModTime),
  23543. uid (other.uid),
  23544. isInstrument (other.isInstrument),
  23545. numInputChannels (other.numInputChannels),
  23546. numOutputChannels (other.numOutputChannels)
  23547. {
  23548. }
  23549. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23550. {
  23551. name = other.name;
  23552. pluginFormatName = other.pluginFormatName;
  23553. category = other.category;
  23554. manufacturerName = other.manufacturerName;
  23555. version = other.version;
  23556. fileOrIdentifier = other.fileOrIdentifier;
  23557. uid = other.uid;
  23558. isInstrument = other.isInstrument;
  23559. lastFileModTime = other.lastFileModTime;
  23560. numInputChannels = other.numInputChannels;
  23561. numOutputChannels = other.numOutputChannels;
  23562. return *this;
  23563. }
  23564. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23565. {
  23566. return fileOrIdentifier == other.fileOrIdentifier
  23567. && uid == other.uid;
  23568. }
  23569. const String PluginDescription::createIdentifierString() const throw()
  23570. {
  23571. return pluginFormatName
  23572. + "-" + name
  23573. + "-" + String::toHexString (fileOrIdentifier.hashCode())
  23574. + "-" + String::toHexString (uid);
  23575. }
  23576. XmlElement* PluginDescription::createXml() const
  23577. {
  23578. XmlElement* const e = new XmlElement ("PLUGIN");
  23579. e->setAttribute ("name", name);
  23580. e->setAttribute ("format", pluginFormatName);
  23581. e->setAttribute ("category", category);
  23582. e->setAttribute ("manufacturer", manufacturerName);
  23583. e->setAttribute ("version", version);
  23584. e->setAttribute ("file", fileOrIdentifier);
  23585. e->setAttribute ("uid", String::toHexString (uid));
  23586. e->setAttribute ("isInstrument", isInstrument);
  23587. e->setAttribute ("fileTime", String::toHexString (lastFileModTime.toMilliseconds()));
  23588. e->setAttribute ("numInputs", numInputChannels);
  23589. e->setAttribute ("numOutputs", numOutputChannels);
  23590. return e;
  23591. }
  23592. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23593. {
  23594. if (xml.hasTagName ("PLUGIN"))
  23595. {
  23596. name = xml.getStringAttribute ("name");
  23597. pluginFormatName = xml.getStringAttribute ("format");
  23598. category = xml.getStringAttribute ("category");
  23599. manufacturerName = xml.getStringAttribute ("manufacturer");
  23600. version = xml.getStringAttribute ("version");
  23601. fileOrIdentifier = xml.getStringAttribute ("file");
  23602. uid = xml.getStringAttribute ("uid").getHexValue32();
  23603. isInstrument = xml.getBoolAttribute ("isInstrument", false);
  23604. lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64());
  23605. numInputChannels = xml.getIntAttribute ("numInputs");
  23606. numOutputChannels = xml.getIntAttribute ("numOutputs");
  23607. return true;
  23608. }
  23609. return false;
  23610. }
  23611. END_JUCE_NAMESPACE
  23612. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23613. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23614. BEGIN_JUCE_NAMESPACE
  23615. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23616. AudioPluginFormat& formatToLookFor,
  23617. FileSearchPath directoriesToSearch,
  23618. const bool recursive,
  23619. const File& deadMansPedalFile_)
  23620. : list (listToAddTo),
  23621. format (formatToLookFor),
  23622. deadMansPedalFile (deadMansPedalFile_),
  23623. nextIndex (0),
  23624. progress (0)
  23625. {
  23626. directoriesToSearch.removeRedundantPaths();
  23627. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23628. // If any plugins have crashed recently when being loaded, move them to the
  23629. // end of the list to give the others a chance to load correctly..
  23630. const StringArray crashedPlugins (getDeadMansPedalFile());
  23631. for (int i = 0; i < crashedPlugins.size(); ++i)
  23632. {
  23633. const String f = crashedPlugins[i];
  23634. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23635. if (f == filesOrIdentifiersToScan[j])
  23636. filesOrIdentifiersToScan.move (j, -1);
  23637. }
  23638. }
  23639. PluginDirectoryScanner::~PluginDirectoryScanner()
  23640. {
  23641. }
  23642. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23643. {
  23644. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23645. }
  23646. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23647. {
  23648. String file (filesOrIdentifiersToScan [nextIndex]);
  23649. if (file.isNotEmpty())
  23650. {
  23651. if (! list.isListingUpToDate (file))
  23652. {
  23653. OwnedArray <PluginDescription> typesFound;
  23654. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23655. StringArray crashedPlugins (getDeadMansPedalFile());
  23656. crashedPlugins.removeString (file);
  23657. crashedPlugins.add (file);
  23658. setDeadMansPedalFile (crashedPlugins);
  23659. list.scanAndAddFile (file,
  23660. dontRescanIfAlreadyInList,
  23661. typesFound,
  23662. format);
  23663. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23664. crashedPlugins.removeString (file);
  23665. setDeadMansPedalFile (crashedPlugins);
  23666. if (typesFound.size() == 0)
  23667. failedFiles.add (file);
  23668. }
  23669. ++nextIndex;
  23670. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23671. }
  23672. return nextIndex < filesOrIdentifiersToScan.size();
  23673. }
  23674. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23675. {
  23676. StringArray lines;
  23677. if (deadMansPedalFile != File::nonexistent)
  23678. {
  23679. lines.addLines (deadMansPedalFile.loadFileAsString());
  23680. lines.removeEmptyStrings();
  23681. }
  23682. return lines;
  23683. }
  23684. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23685. {
  23686. if (deadMansPedalFile != File::nonexistent)
  23687. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23688. }
  23689. END_JUCE_NAMESPACE
  23690. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23691. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23692. BEGIN_JUCE_NAMESPACE
  23693. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23694. const File& deadMansPedalFile_,
  23695. PropertiesFile* const propertiesToUse_)
  23696. : list (listToEdit),
  23697. deadMansPedalFile (deadMansPedalFile_),
  23698. propertiesToUse (propertiesToUse_)
  23699. {
  23700. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23701. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23702. optionsButton->addButtonListener (this);
  23703. optionsButton->setTriggeredOnMouseDown (true);
  23704. setSize (400, 600);
  23705. list.addChangeListener (this);
  23706. }
  23707. PluginListComponent::~PluginListComponent()
  23708. {
  23709. list.removeChangeListener (this);
  23710. deleteAllChildren();
  23711. }
  23712. void PluginListComponent::resized()
  23713. {
  23714. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23715. optionsButton->changeWidthToFitText (24);
  23716. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23717. }
  23718. void PluginListComponent::changeListenerCallback (void*)
  23719. {
  23720. listBox->updateContent();
  23721. listBox->repaint();
  23722. }
  23723. int PluginListComponent::getNumRows()
  23724. {
  23725. return list.getNumTypes();
  23726. }
  23727. void PluginListComponent::paintListBoxItem (int row,
  23728. Graphics& g,
  23729. int width, int height,
  23730. bool rowIsSelected)
  23731. {
  23732. if (rowIsSelected)
  23733. g.fillAll (findColour (TextEditor::highlightColourId));
  23734. const PluginDescription* const pd = list.getType (row);
  23735. if (pd != 0)
  23736. {
  23737. GlyphArrangement ga;
  23738. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23739. g.setColour (Colours::black);
  23740. ga.draw (g);
  23741. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  23742. String desc;
  23743. desc << pd->pluginFormatName
  23744. << (pd->isInstrument ? " instrument" : " effect")
  23745. << " - "
  23746. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23747. << " / "
  23748. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23749. if (pd->manufacturerName.isNotEmpty())
  23750. desc << " - " << pd->manufacturerName;
  23751. if (pd->version.isNotEmpty())
  23752. desc << " - " << pd->version;
  23753. if (pd->category.isNotEmpty())
  23754. desc << " - category: '" << pd->category << '\'';
  23755. g.setColour (Colours::grey);
  23756. ga.clear();
  23757. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, bb.getRight() + 10.0f, height * 0.8f, width - bb.getRight() - 12.0f, true);
  23758. ga.draw (g);
  23759. }
  23760. }
  23761. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23762. {
  23763. list.removeType (lastRowSelected);
  23764. }
  23765. void PluginListComponent::buttonClicked (Button* b)
  23766. {
  23767. if (optionsButton == b)
  23768. {
  23769. PopupMenu menu;
  23770. menu.addItem (1, TRANS("Clear list"));
  23771. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23772. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23773. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23774. menu.addSeparator();
  23775. menu.addItem (2, TRANS("Sort alphabetically"));
  23776. menu.addItem (3, TRANS("Sort by category"));
  23777. menu.addItem (4, TRANS("Sort by manufacturer"));
  23778. menu.addSeparator();
  23779. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23780. {
  23781. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23782. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23783. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23784. }
  23785. const int r = menu.showAt (optionsButton);
  23786. if (r == 1)
  23787. {
  23788. list.clear();
  23789. }
  23790. else if (r == 2)
  23791. {
  23792. list.sort (KnownPluginList::sortAlphabetically);
  23793. }
  23794. else if (r == 3)
  23795. {
  23796. list.sort (KnownPluginList::sortByCategory);
  23797. }
  23798. else if (r == 4)
  23799. {
  23800. list.sort (KnownPluginList::sortByManufacturer);
  23801. }
  23802. else if (r == 5)
  23803. {
  23804. const SparseSet <int> selected (listBox->getSelectedRows());
  23805. for (int i = list.getNumTypes(); --i >= 0;)
  23806. if (selected.contains (i))
  23807. list.removeType (i);
  23808. }
  23809. else if (r == 6)
  23810. {
  23811. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23812. if (desc != 0)
  23813. {
  23814. if (File (desc->fileOrIdentifier).existsAsFile())
  23815. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23816. }
  23817. }
  23818. else if (r == 7)
  23819. {
  23820. for (int i = list.getNumTypes(); --i >= 0;)
  23821. {
  23822. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23823. {
  23824. list.removeType (i);
  23825. }
  23826. }
  23827. }
  23828. else if (r != 0)
  23829. {
  23830. typeToScan = r - 10;
  23831. startTimer (1);
  23832. }
  23833. }
  23834. }
  23835. void PluginListComponent::timerCallback()
  23836. {
  23837. stopTimer();
  23838. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23839. }
  23840. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23841. {
  23842. return true;
  23843. }
  23844. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23845. {
  23846. OwnedArray <PluginDescription> typesFound;
  23847. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23848. }
  23849. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23850. {
  23851. if (format == 0)
  23852. return;
  23853. FileSearchPath path (format->getDefaultLocationsToSearch());
  23854. if (propertiesToUse != 0)
  23855. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23856. {
  23857. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23858. FileSearchPathListComponent pathList;
  23859. pathList.setSize (500, 300);
  23860. pathList.setPath (path);
  23861. aw.addCustomComponent (&pathList);
  23862. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23863. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23864. if (aw.runModalLoop() == 0)
  23865. return;
  23866. path = pathList.getPath();
  23867. }
  23868. if (propertiesToUse != 0)
  23869. {
  23870. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23871. propertiesToUse->saveIfNeeded();
  23872. }
  23873. double progress = 0.0;
  23874. AlertWindow aw (TRANS("Scanning for plugins..."),
  23875. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23876. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23877. aw.addProgressBarComponent (progress);
  23878. aw.enterModalState();
  23879. MessageManager::getInstance()->runDispatchLoopUntil (300);
  23880. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  23881. for (;;)
  23882. {
  23883. aw.setMessage (TRANS("Testing:\n\n")
  23884. + scanner.getNextPluginFileThatWillBeScanned());
  23885. MessageManager::getInstance()->runDispatchLoopUntil (20);
  23886. if (! scanner.scanNextFile (true))
  23887. break;
  23888. if (! aw.isCurrentlyModal())
  23889. break;
  23890. progress = scanner.getProgress();
  23891. }
  23892. if (scanner.getFailedFiles().size() > 0)
  23893. {
  23894. StringArray shortNames;
  23895. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  23896. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  23897. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  23898. TRANS("Scan complete"),
  23899. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  23900. + shortNames.joinIntoString (", "));
  23901. }
  23902. }
  23903. END_JUCE_NAMESPACE
  23904. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  23905. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  23906. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  23907. #include <AudioUnit/AudioUnit.h>
  23908. #include <AudioUnit/AUCocoaUIView.h>
  23909. #include <CoreAudioKit/AUGenericView.h>
  23910. #if JUCE_SUPPORT_CARBON
  23911. #include <AudioToolbox/AudioUnitUtilities.h>
  23912. #include <AudioUnit/AudioUnitCarbonView.h>
  23913. #endif
  23914. BEGIN_JUCE_NAMESPACE
  23915. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  23916. #endif
  23917. #if JUCE_MAC
  23918. // Change this to disable logging of various activities
  23919. #ifndef AU_LOGGING
  23920. #define AU_LOGGING 1
  23921. #endif
  23922. #if AU_LOGGING
  23923. #define log(a) Logger::writeToLog(a);
  23924. #else
  23925. #define log(a)
  23926. #endif
  23927. static int insideCallback = 0;
  23928. static const String osTypeToString (OSType type)
  23929. {
  23930. char s[4];
  23931. s[0] = (char) (((uint32) type) >> 24);
  23932. s[1] = (char) (((uint32) type) >> 16);
  23933. s[2] = (char) (((uint32) type) >> 8);
  23934. s[3] = (char) ((uint32) type);
  23935. return String (s, 4);
  23936. }
  23937. static OSType stringToOSType (const String& s1)
  23938. {
  23939. const String s (s1 + " ");
  23940. return (((OSType) (unsigned char) s[0]) << 24)
  23941. | (((OSType) (unsigned char) s[1]) << 16)
  23942. | (((OSType) (unsigned char) s[2]) << 8)
  23943. | ((OSType) (unsigned char) s[3]);
  23944. }
  23945. static const char* auIdentifierPrefix = "AudioUnit:";
  23946. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  23947. {
  23948. jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong..
  23949. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  23950. String s (auIdentifierPrefix);
  23951. if (desc.componentType == kAudioUnitType_MusicDevice)
  23952. s << "Synths/";
  23953. else if (desc.componentType == kAudioUnitType_MusicEffect
  23954. || desc.componentType == kAudioUnitType_Effect)
  23955. s << "Effects/";
  23956. else if (desc.componentType == kAudioUnitType_Generator)
  23957. s << "Generators/";
  23958. else if (desc.componentType == kAudioUnitType_Panner)
  23959. s << "Panners/";
  23960. s << osTypeToString (desc.componentType) << ","
  23961. << osTypeToString (desc.componentSubType) << ","
  23962. << osTypeToString (desc.componentManufacturer);
  23963. return s;
  23964. }
  23965. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  23966. {
  23967. Handle componentNameHandle = NewHandle (sizeof (void*));
  23968. Handle componentInfoHandle = NewHandle (sizeof (void*));
  23969. if (componentNameHandle != 0 && componentInfoHandle != 0)
  23970. {
  23971. ComponentDescription desc;
  23972. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  23973. {
  23974. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  23975. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  23976. if (nameString != 0 && nameString[0] != 0)
  23977. {
  23978. const String all ((const char*) nameString + 1, nameString[0]);
  23979. DBG ("name: "+ all);
  23980. manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim();
  23981. name = all.fromFirstOccurrenceOf (":", false, false).trim();
  23982. }
  23983. if (infoString != 0 && infoString[0] != 0)
  23984. {
  23985. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  23986. }
  23987. if (name.isEmpty())
  23988. name = "<Unknown>";
  23989. }
  23990. DisposeHandle (componentNameHandle);
  23991. DisposeHandle (componentInfoHandle);
  23992. }
  23993. }
  23994. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  23995. String& name, String& version, String& manufacturer)
  23996. {
  23997. zerostruct (desc);
  23998. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  23999. {
  24000. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'),
  24001. fileOrIdentifier.lastIndexOfChar ('/')) + 1));
  24002. StringArray tokens;
  24003. tokens.addTokens (s, ",", String::empty);
  24004. tokens.trim();
  24005. tokens.removeEmptyStrings();
  24006. if (tokens.size() == 3)
  24007. {
  24008. desc.componentType = stringToOSType (tokens[0]);
  24009. desc.componentSubType = stringToOSType (tokens[1]);
  24010. desc.componentManufacturer = stringToOSType (tokens[2]);
  24011. ComponentRecord* comp = FindNextComponent (0, &desc);
  24012. if (comp != 0)
  24013. {
  24014. getAUDetails (comp, name, manufacturer);
  24015. return true;
  24016. }
  24017. }
  24018. }
  24019. return false;
  24020. }
  24021. class AudioUnitPluginWindowCarbon;
  24022. class AudioUnitPluginWindowCocoa;
  24023. class AudioUnitPluginInstance : public AudioPluginInstance
  24024. {
  24025. public:
  24026. ~AudioUnitPluginInstance();
  24027. // AudioPluginInstance methods:
  24028. void fillInPluginDescription (PluginDescription& desc) const
  24029. {
  24030. desc.name = pluginName;
  24031. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24032. desc.uid = ((int) componentDesc.componentType)
  24033. ^ ((int) componentDesc.componentSubType)
  24034. ^ ((int) componentDesc.componentManufacturer);
  24035. desc.lastFileModTime = 0;
  24036. desc.pluginFormatName = "AudioUnit";
  24037. desc.category = getCategory();
  24038. desc.manufacturerName = manufacturer;
  24039. desc.version = version;
  24040. desc.numInputChannels = getNumInputChannels();
  24041. desc.numOutputChannels = getNumOutputChannels();
  24042. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24043. }
  24044. const String getName() const { return pluginName; }
  24045. bool acceptsMidi() const { return wantsMidiMessages; }
  24046. bool producesMidi() const { return false; }
  24047. // AudioProcessor methods:
  24048. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24049. void releaseResources();
  24050. void processBlock (AudioSampleBuffer& buffer,
  24051. MidiBuffer& midiMessages);
  24052. AudioProcessorEditor* createEditor();
  24053. const String getInputChannelName (const int index) const;
  24054. bool isInputChannelStereoPair (int index) const;
  24055. const String getOutputChannelName (const int index) const;
  24056. bool isOutputChannelStereoPair (int index) const;
  24057. int getNumParameters();
  24058. float getParameter (int index);
  24059. void setParameter (int index, float newValue);
  24060. const String getParameterName (int index);
  24061. const String getParameterText (int index);
  24062. bool isParameterAutomatable (int index) const;
  24063. int getNumPrograms();
  24064. int getCurrentProgram();
  24065. void setCurrentProgram (int index);
  24066. const String getProgramName (int index);
  24067. void changeProgramName (int index, const String& newName);
  24068. void getStateInformation (MemoryBlock& destData);
  24069. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24070. void setStateInformation (const void* data, int sizeInBytes);
  24071. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24072. juce_UseDebuggingNewOperator
  24073. private:
  24074. friend class AudioUnitPluginWindowCarbon;
  24075. friend class AudioUnitPluginWindowCocoa;
  24076. friend class AudioUnitPluginFormat;
  24077. ComponentDescription componentDesc;
  24078. String pluginName, manufacturer, version;
  24079. String fileOrIdentifier;
  24080. CriticalSection lock;
  24081. bool initialised, wantsMidiMessages, wasPlaying;
  24082. HeapBlock <AudioBufferList> outputBufferList;
  24083. AudioTimeStamp timeStamp;
  24084. AudioSampleBuffer* currentBuffer;
  24085. AudioUnit audioUnit;
  24086. Array <int> parameterIds;
  24087. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24088. void initialise();
  24089. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24090. const AudioTimeStamp* inTimeStamp,
  24091. UInt32 inBusNumber,
  24092. UInt32 inNumberFrames,
  24093. AudioBufferList* ioData) const;
  24094. static OSStatus renderGetInputCallback (void* inRefCon,
  24095. AudioUnitRenderActionFlags* ioActionFlags,
  24096. const AudioTimeStamp* inTimeStamp,
  24097. UInt32 inBusNumber,
  24098. UInt32 inNumberFrames,
  24099. AudioBufferList* ioData)
  24100. {
  24101. return ((AudioUnitPluginInstance*) inRefCon)
  24102. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24103. }
  24104. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24105. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24106. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24107. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24108. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24109. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24110. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24111. {
  24112. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24113. }
  24114. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24115. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24116. Float64* outCurrentMeasureDownBeat)
  24117. {
  24118. return ((AudioUnitPluginInstance*) inHostUserData)
  24119. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24120. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24121. }
  24122. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24123. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24124. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24125. {
  24126. return ((AudioUnitPluginInstance*) inHostUserData)
  24127. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24128. outCurrentSampleInTimeLine, outIsCycling,
  24129. outCycleStartBeat, outCycleEndBeat);
  24130. }
  24131. void getNumChannels (int& numIns, int& numOuts)
  24132. {
  24133. numIns = 0;
  24134. numOuts = 0;
  24135. AUChannelInfo supportedChannels [128];
  24136. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24137. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24138. 0, supportedChannels, &supportedChannelsSize) == noErr
  24139. && supportedChannelsSize > 0)
  24140. {
  24141. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24142. {
  24143. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24144. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24145. }
  24146. }
  24147. else
  24148. {
  24149. // (this really means the plugin will take any number of ins/outs as long
  24150. // as they are the same)
  24151. numIns = numOuts = 2;
  24152. }
  24153. }
  24154. const String getCategory() const;
  24155. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24156. };
  24157. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24158. : fileOrIdentifier (fileOrIdentifier),
  24159. initialised (false),
  24160. wantsMidiMessages (false),
  24161. audioUnit (0),
  24162. currentBuffer (0)
  24163. {
  24164. try
  24165. {
  24166. ++insideCallback;
  24167. log ("Opening AU: " + fileOrIdentifier);
  24168. if (getComponentDescFromFile (fileOrIdentifier))
  24169. {
  24170. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24171. if (comp != 0)
  24172. {
  24173. audioUnit = (AudioUnit) OpenComponent (comp);
  24174. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24175. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24176. }
  24177. }
  24178. --insideCallback;
  24179. }
  24180. catch (...)
  24181. {
  24182. --insideCallback;
  24183. }
  24184. }
  24185. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24186. {
  24187. const ScopedLock sl (lock);
  24188. jassert (insideCallback == 0);
  24189. if (audioUnit != 0)
  24190. {
  24191. AudioUnitUninitialize (audioUnit);
  24192. CloseComponent (audioUnit);
  24193. audioUnit = 0;
  24194. }
  24195. }
  24196. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24197. {
  24198. zerostruct (componentDesc);
  24199. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24200. return true;
  24201. const File file (fileOrIdentifier);
  24202. if (! file.hasFileExtension (".component"))
  24203. return false;
  24204. const char* const utf8 = fileOrIdentifier.toUTF8();
  24205. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24206. strlen (utf8), file.isDirectory());
  24207. if (url != 0)
  24208. {
  24209. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24210. CFRelease (url);
  24211. if (bundleRef != 0)
  24212. {
  24213. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24214. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24215. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24216. if (pluginName.isEmpty())
  24217. pluginName = file.getFileNameWithoutExtension();
  24218. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24219. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24220. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24221. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24222. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24223. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24224. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24225. UseResFile (resFileId);
  24226. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24227. {
  24228. Handle h = Get1IndResource ('thng', i);
  24229. if (h != 0)
  24230. {
  24231. HLock (h);
  24232. const uint32* const types = (const uint32*) *h;
  24233. if (types[0] == kAudioUnitType_MusicDevice
  24234. || types[0] == kAudioUnitType_MusicEffect
  24235. || types[0] == kAudioUnitType_Effect
  24236. || types[0] == kAudioUnitType_Generator
  24237. || types[0] == kAudioUnitType_Panner)
  24238. {
  24239. componentDesc.componentType = types[0];
  24240. componentDesc.componentSubType = types[1];
  24241. componentDesc.componentManufacturer = types[2];
  24242. break;
  24243. }
  24244. HUnlock (h);
  24245. ReleaseResource (h);
  24246. }
  24247. }
  24248. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24249. CFRelease (bundleRef);
  24250. }
  24251. }
  24252. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24253. }
  24254. void AudioUnitPluginInstance::initialise()
  24255. {
  24256. if (initialised || audioUnit == 0)
  24257. return;
  24258. log ("Initialising AU: " + pluginName);
  24259. parameterIds.clear();
  24260. {
  24261. UInt32 paramListSize = 0;
  24262. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24263. 0, 0, &paramListSize);
  24264. if (paramListSize > 0)
  24265. {
  24266. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24267. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24268. 0, &parameterIds.getReference(0), &paramListSize);
  24269. }
  24270. }
  24271. {
  24272. AURenderCallbackStruct info;
  24273. zerostruct (info);
  24274. info.inputProcRefCon = this;
  24275. info.inputProc = renderGetInputCallback;
  24276. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24277. 0, &info, sizeof (info));
  24278. }
  24279. {
  24280. HostCallbackInfo info;
  24281. zerostruct (info);
  24282. info.hostUserData = this;
  24283. info.beatAndTempoProc = getBeatAndTempoCallback;
  24284. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24285. info.transportStateProc = getTransportStateCallback;
  24286. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24287. 0, &info, sizeof (info));
  24288. }
  24289. int numIns, numOuts;
  24290. getNumChannels (numIns, numOuts);
  24291. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24292. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24293. setLatencySamples (0);
  24294. }
  24295. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24296. int samplesPerBlockExpected)
  24297. {
  24298. initialise();
  24299. if (initialised)
  24300. {
  24301. int numIns, numOuts;
  24302. getNumChannels (numIns, numOuts);
  24303. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24304. Float64 latencySecs = 0.0;
  24305. UInt32 latencySize = sizeof (latencySecs);
  24306. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24307. 0, &latencySecs, &latencySize);
  24308. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24309. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24310. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24311. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24312. AudioStreamBasicDescription stream;
  24313. zerostruct (stream);
  24314. stream.mSampleRate = sampleRate_;
  24315. stream.mFormatID = kAudioFormatLinearPCM;
  24316. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24317. stream.mFramesPerPacket = 1;
  24318. stream.mBytesPerPacket = 4;
  24319. stream.mBytesPerFrame = 4;
  24320. stream.mBitsPerChannel = 32;
  24321. stream.mChannelsPerFrame = numIns;
  24322. OSStatus err = AudioUnitSetProperty (audioUnit,
  24323. kAudioUnitProperty_StreamFormat,
  24324. kAudioUnitScope_Input,
  24325. 0, &stream, sizeof (stream));
  24326. stream.mChannelsPerFrame = numOuts;
  24327. err = AudioUnitSetProperty (audioUnit,
  24328. kAudioUnitProperty_StreamFormat,
  24329. kAudioUnitScope_Output,
  24330. 0, &stream, sizeof (stream));
  24331. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24332. outputBufferList->mNumberBuffers = numOuts;
  24333. for (int i = numOuts; --i >= 0;)
  24334. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24335. zerostruct (timeStamp);
  24336. timeStamp.mSampleTime = 0;
  24337. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24338. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24339. currentBuffer = 0;
  24340. wasPlaying = false;
  24341. }
  24342. }
  24343. void AudioUnitPluginInstance::releaseResources()
  24344. {
  24345. if (initialised)
  24346. {
  24347. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24348. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24349. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24350. outputBufferList.free();
  24351. currentBuffer = 0;
  24352. }
  24353. }
  24354. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24355. const AudioTimeStamp* inTimeStamp,
  24356. UInt32 inBusNumber,
  24357. UInt32 inNumberFrames,
  24358. AudioBufferList* ioData) const
  24359. {
  24360. if (inBusNumber == 0
  24361. && currentBuffer != 0)
  24362. {
  24363. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24364. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24365. {
  24366. if (i < currentBuffer->getNumChannels())
  24367. {
  24368. memcpy (ioData->mBuffers[i].mData,
  24369. currentBuffer->getSampleData (i, 0),
  24370. sizeof (float) * inNumberFrames);
  24371. }
  24372. else
  24373. {
  24374. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24375. }
  24376. }
  24377. }
  24378. return noErr;
  24379. }
  24380. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24381. MidiBuffer& midiMessages)
  24382. {
  24383. const int numSamples = buffer.getNumSamples();
  24384. if (initialised)
  24385. {
  24386. AudioUnitRenderActionFlags flags = 0;
  24387. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24388. for (int i = getNumOutputChannels(); --i >= 0;)
  24389. {
  24390. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24391. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24392. }
  24393. currentBuffer = &buffer;
  24394. if (wantsMidiMessages)
  24395. {
  24396. const uint8* midiEventData;
  24397. int midiEventSize, midiEventPosition;
  24398. MidiBuffer::Iterator i (midiMessages);
  24399. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24400. {
  24401. if (midiEventSize <= 3)
  24402. MusicDeviceMIDIEvent (audioUnit,
  24403. midiEventData[0], midiEventData[1], midiEventData[2],
  24404. midiEventPosition);
  24405. else
  24406. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24407. }
  24408. midiMessages.clear();
  24409. }
  24410. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24411. 0, numSamples, outputBufferList);
  24412. timeStamp.mSampleTime += numSamples;
  24413. }
  24414. else
  24415. {
  24416. // Not initialised, so just bypass..
  24417. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24418. buffer.clear (i, 0, buffer.getNumSamples());
  24419. }
  24420. }
  24421. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24422. {
  24423. AudioPlayHead* const ph = getPlayHead();
  24424. AudioPlayHead::CurrentPositionInfo result;
  24425. if (ph != 0 && ph->getCurrentPosition (result))
  24426. {
  24427. if (outCurrentBeat != 0)
  24428. *outCurrentBeat = result.ppqPosition;
  24429. if (outCurrentTempo != 0)
  24430. *outCurrentTempo = result.bpm;
  24431. }
  24432. else
  24433. {
  24434. if (outCurrentBeat != 0)
  24435. *outCurrentBeat = 0;
  24436. if (outCurrentTempo != 0)
  24437. *outCurrentTempo = 120.0;
  24438. }
  24439. return noErr;
  24440. }
  24441. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24442. Float32* outTimeSig_Numerator,
  24443. UInt32* outTimeSig_Denominator,
  24444. Float64* outCurrentMeasureDownBeat) const
  24445. {
  24446. AudioPlayHead* const ph = getPlayHead();
  24447. AudioPlayHead::CurrentPositionInfo result;
  24448. if (ph != 0 && ph->getCurrentPosition (result))
  24449. {
  24450. if (outTimeSig_Numerator != 0)
  24451. *outTimeSig_Numerator = result.timeSigNumerator;
  24452. if (outTimeSig_Denominator != 0)
  24453. *outTimeSig_Denominator = result.timeSigDenominator;
  24454. if (outDeltaSampleOffsetToNextBeat != 0)
  24455. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24456. if (outCurrentMeasureDownBeat != 0)
  24457. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24458. }
  24459. else
  24460. {
  24461. if (outDeltaSampleOffsetToNextBeat != 0)
  24462. *outDeltaSampleOffsetToNextBeat = 0;
  24463. if (outTimeSig_Numerator != 0)
  24464. *outTimeSig_Numerator = 4;
  24465. if (outTimeSig_Denominator != 0)
  24466. *outTimeSig_Denominator = 4;
  24467. if (outCurrentMeasureDownBeat != 0)
  24468. *outCurrentMeasureDownBeat = 0;
  24469. }
  24470. return noErr;
  24471. }
  24472. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24473. Boolean* outTransportStateChanged,
  24474. Float64* outCurrentSampleInTimeLine,
  24475. Boolean* outIsCycling,
  24476. Float64* outCycleStartBeat,
  24477. Float64* outCycleEndBeat)
  24478. {
  24479. AudioPlayHead* const ph = getPlayHead();
  24480. AudioPlayHead::CurrentPositionInfo result;
  24481. if (ph != 0 && ph->getCurrentPosition (result))
  24482. {
  24483. if (outIsPlaying != 0)
  24484. *outIsPlaying = result.isPlaying;
  24485. if (outTransportStateChanged != 0)
  24486. {
  24487. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24488. wasPlaying = result.isPlaying;
  24489. }
  24490. if (outCurrentSampleInTimeLine != 0)
  24491. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24492. if (outIsCycling != 0)
  24493. *outIsCycling = false;
  24494. if (outCycleStartBeat != 0)
  24495. *outCycleStartBeat = 0;
  24496. if (outCycleEndBeat != 0)
  24497. *outCycleEndBeat = 0;
  24498. }
  24499. else
  24500. {
  24501. if (outIsPlaying != 0)
  24502. *outIsPlaying = false;
  24503. if (outTransportStateChanged != 0)
  24504. *outTransportStateChanged = false;
  24505. if (outCurrentSampleInTimeLine != 0)
  24506. *outCurrentSampleInTimeLine = 0;
  24507. if (outIsCycling != 0)
  24508. *outIsCycling = false;
  24509. if (outCycleStartBeat != 0)
  24510. *outCycleStartBeat = 0;
  24511. if (outCycleEndBeat != 0)
  24512. *outCycleEndBeat = 0;
  24513. }
  24514. return noErr;
  24515. }
  24516. static VoidArray activeWindows;
  24517. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24518. {
  24519. public:
  24520. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24521. : AudioProcessorEditor (&plugin_),
  24522. plugin (plugin_),
  24523. wrapper (0)
  24524. {
  24525. addAndMakeVisible (wrapper = new NSViewComponent());
  24526. activeWindows.add (this);
  24527. setOpaque (true);
  24528. setVisible (true);
  24529. setSize (100, 100);
  24530. createView (createGenericViewIfNeeded);
  24531. }
  24532. ~AudioUnitPluginWindowCocoa()
  24533. {
  24534. const bool wasValid = isValid();
  24535. wrapper->setView (0);
  24536. activeWindows.removeValue (this);
  24537. if (wasValid)
  24538. plugin.editorBeingDeleted (this);
  24539. delete wrapper;
  24540. }
  24541. bool isValid() const { return wrapper->getView() != 0; }
  24542. void paint (Graphics& g)
  24543. {
  24544. g.fillAll (Colours::white);
  24545. }
  24546. void resized()
  24547. {
  24548. wrapper->setSize (getWidth(), getHeight());
  24549. }
  24550. private:
  24551. AudioUnitPluginInstance& plugin;
  24552. NSViewComponent* wrapper;
  24553. bool createView (const bool createGenericViewIfNeeded)
  24554. {
  24555. NSView* pluginView = 0;
  24556. UInt32 dataSize = 0;
  24557. Boolean isWritable = false;
  24558. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24559. 0, &dataSize, &isWritable) == noErr
  24560. && dataSize != 0
  24561. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24562. 0, &dataSize, &isWritable) == noErr)
  24563. {
  24564. HeapBlock <AudioUnitCocoaViewInfo> info;
  24565. info.calloc (dataSize, 1);
  24566. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24567. 0, info, &dataSize) == noErr)
  24568. {
  24569. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24570. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24571. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24572. Class viewClass = [viewBundle classNamed: viewClassName];
  24573. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24574. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24575. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24576. {
  24577. id factory = [[[viewClass alloc] init] autorelease];
  24578. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24579. withSize: NSMakeSize (getWidth(), getHeight())];
  24580. }
  24581. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24582. {
  24583. CFRelease (info->mCocoaAUViewClass[i]);
  24584. CFRelease (info->mCocoaAUViewBundleLocation);
  24585. }
  24586. }
  24587. }
  24588. if (createGenericViewIfNeeded && (pluginView == 0))
  24589. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24590. wrapper->setView (pluginView);
  24591. if (pluginView != 0)
  24592. setSize ([pluginView frame].size.width,
  24593. [pluginView frame].size.height);
  24594. return pluginView != 0;
  24595. }
  24596. };
  24597. #if JUCE_SUPPORT_CARBON
  24598. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24599. {
  24600. public:
  24601. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24602. : AudioProcessorEditor (&plugin_),
  24603. plugin (plugin_),
  24604. viewComponent (0)
  24605. {
  24606. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24607. activeWindows.add (this);
  24608. setOpaque (true);
  24609. setVisible (true);
  24610. setSize (400, 300);
  24611. ComponentDescription viewList [16];
  24612. UInt32 viewListSize = sizeof (viewList);
  24613. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24614. 0, &viewList, &viewListSize);
  24615. componentRecord = FindNextComponent (0, &viewList[0]);
  24616. }
  24617. ~AudioUnitPluginWindowCarbon()
  24618. {
  24619. innerWrapper = 0;
  24620. activeWindows.removeValue (this);
  24621. if (isValid())
  24622. plugin.editorBeingDeleted (this);
  24623. }
  24624. bool isValid() const throw() { return componentRecord != 0; }
  24625. void paint (Graphics& g)
  24626. {
  24627. g.fillAll (Colours::black);
  24628. }
  24629. void resized()
  24630. {
  24631. innerWrapper->setSize (getWidth(), getHeight());
  24632. }
  24633. bool keyStateChanged (bool)
  24634. {
  24635. return false;
  24636. }
  24637. bool keyPressed (const KeyPress&)
  24638. {
  24639. return false;
  24640. }
  24641. void broughtToFront()
  24642. {
  24643. activeWindows.removeValue (this);
  24644. activeWindows.add (this);
  24645. }
  24646. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24647. AudioUnitCarbonView getViewComponent()
  24648. {
  24649. if (viewComponent == 0 && componentRecord != 0)
  24650. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24651. return viewComponent;
  24652. }
  24653. void closeViewComponent()
  24654. {
  24655. if (viewComponent != 0)
  24656. {
  24657. CloseComponent (viewComponent);
  24658. viewComponent = 0;
  24659. }
  24660. }
  24661. juce_UseDebuggingNewOperator
  24662. private:
  24663. AudioUnitPluginInstance& plugin;
  24664. ComponentRecord* componentRecord;
  24665. AudioUnitCarbonView viewComponent;
  24666. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24667. {
  24668. public:
  24669. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24670. : owner (owner_)
  24671. {
  24672. }
  24673. ~InnerWrapperComponent()
  24674. {
  24675. deleteWindow();
  24676. }
  24677. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24678. {
  24679. log ("Opening AU GUI: " + owner->plugin.getName());
  24680. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24681. if (viewComponent == 0)
  24682. return 0;
  24683. Float32Point pos = { 0, 0 };
  24684. Float32Point size = { 250, 200 };
  24685. HIViewRef pluginView = 0;
  24686. AudioUnitCarbonViewCreate (viewComponent,
  24687. owner->getAudioUnit(),
  24688. windowRef,
  24689. rootView,
  24690. &pos,
  24691. &size,
  24692. (ControlRef*) &pluginView);
  24693. return pluginView;
  24694. }
  24695. void removeView (HIViewRef)
  24696. {
  24697. log ("Closing AU GUI: " + owner->plugin.getName());
  24698. owner->closeViewComponent();
  24699. }
  24700. private:
  24701. AudioUnitPluginWindowCarbon* const owner;
  24702. };
  24703. friend class InnerWrapperComponent;
  24704. ScopedPointer<InnerWrapperComponent> innerWrapper;
  24705. };
  24706. #endif
  24707. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24708. {
  24709. ScopedPointer<AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24710. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24711. w = 0;
  24712. #if JUCE_SUPPORT_CARBON
  24713. if (w == 0)
  24714. {
  24715. w = new AudioUnitPluginWindowCarbon (*this);
  24716. if (! static_cast <AudioUnitPluginWindowCarbon*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24717. w = 0;
  24718. }
  24719. #endif
  24720. if (w == 0)
  24721. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24722. return w.release();
  24723. }
  24724. const String AudioUnitPluginInstance::getCategory() const
  24725. {
  24726. const char* result = 0;
  24727. switch (componentDesc.componentType)
  24728. {
  24729. case kAudioUnitType_Effect:
  24730. case kAudioUnitType_MusicEffect:
  24731. result = "Effect";
  24732. break;
  24733. case kAudioUnitType_MusicDevice:
  24734. result = "Synth";
  24735. break;
  24736. case kAudioUnitType_Generator:
  24737. result = "Generator";
  24738. break;
  24739. case kAudioUnitType_Panner:
  24740. result = "Panner";
  24741. break;
  24742. default:
  24743. break;
  24744. }
  24745. return result;
  24746. }
  24747. int AudioUnitPluginInstance::getNumParameters()
  24748. {
  24749. return parameterIds.size();
  24750. }
  24751. float AudioUnitPluginInstance::getParameter (int index)
  24752. {
  24753. const ScopedLock sl (lock);
  24754. Float32 value = 0.0f;
  24755. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24756. {
  24757. AudioUnitGetParameter (audioUnit,
  24758. (UInt32) parameterIds.getUnchecked (index),
  24759. kAudioUnitScope_Global, 0,
  24760. &value);
  24761. }
  24762. return value;
  24763. }
  24764. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24765. {
  24766. const ScopedLock sl (lock);
  24767. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24768. {
  24769. AudioUnitSetParameter (audioUnit,
  24770. (UInt32) parameterIds.getUnchecked (index),
  24771. kAudioUnitScope_Global, 0,
  24772. newValue, 0);
  24773. }
  24774. }
  24775. const String AudioUnitPluginInstance::getParameterName (int index)
  24776. {
  24777. AudioUnitParameterInfo info;
  24778. zerostruct (info);
  24779. UInt32 sz = sizeof (info);
  24780. String name;
  24781. if (AudioUnitGetProperty (audioUnit,
  24782. kAudioUnitProperty_ParameterInfo,
  24783. kAudioUnitScope_Global,
  24784. parameterIds [index], &info, &sz) == noErr)
  24785. {
  24786. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24787. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24788. else
  24789. name = String (info.name, sizeof (info.name));
  24790. }
  24791. return name;
  24792. }
  24793. const String AudioUnitPluginInstance::getParameterText (int index)
  24794. {
  24795. return String (getParameter (index));
  24796. }
  24797. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24798. {
  24799. AudioUnitParameterInfo info;
  24800. UInt32 sz = sizeof (info);
  24801. if (AudioUnitGetProperty (audioUnit,
  24802. kAudioUnitProperty_ParameterInfo,
  24803. kAudioUnitScope_Global,
  24804. parameterIds [index], &info, &sz) == noErr)
  24805. {
  24806. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24807. }
  24808. return true;
  24809. }
  24810. int AudioUnitPluginInstance::getNumPrograms()
  24811. {
  24812. CFArrayRef presets;
  24813. UInt32 sz = sizeof (CFArrayRef);
  24814. int num = 0;
  24815. if (AudioUnitGetProperty (audioUnit,
  24816. kAudioUnitProperty_FactoryPresets,
  24817. kAudioUnitScope_Global,
  24818. 0, &presets, &sz) == noErr)
  24819. {
  24820. num = (int) CFArrayGetCount (presets);
  24821. CFRelease (presets);
  24822. }
  24823. return num;
  24824. }
  24825. int AudioUnitPluginInstance::getCurrentProgram()
  24826. {
  24827. AUPreset current;
  24828. current.presetNumber = 0;
  24829. UInt32 sz = sizeof (AUPreset);
  24830. AudioUnitGetProperty (audioUnit,
  24831. kAudioUnitProperty_FactoryPresets,
  24832. kAudioUnitScope_Global,
  24833. 0, &current, &sz);
  24834. return current.presetNumber;
  24835. }
  24836. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24837. {
  24838. AUPreset current;
  24839. current.presetNumber = newIndex;
  24840. current.presetName = 0;
  24841. AudioUnitSetProperty (audioUnit,
  24842. kAudioUnitProperty_FactoryPresets,
  24843. kAudioUnitScope_Global,
  24844. 0, &current, sizeof (AUPreset));
  24845. }
  24846. const String AudioUnitPluginInstance::getProgramName (int index)
  24847. {
  24848. String s;
  24849. CFArrayRef presets;
  24850. UInt32 sz = sizeof (CFArrayRef);
  24851. if (AudioUnitGetProperty (audioUnit,
  24852. kAudioUnitProperty_FactoryPresets,
  24853. kAudioUnitScope_Global,
  24854. 0, &presets, &sz) == noErr)
  24855. {
  24856. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24857. {
  24858. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24859. if (p != 0 && p->presetNumber == index)
  24860. {
  24861. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24862. break;
  24863. }
  24864. }
  24865. CFRelease (presets);
  24866. }
  24867. return s;
  24868. }
  24869. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24870. {
  24871. jassertfalse // xxx not implemented!
  24872. }
  24873. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24874. {
  24875. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24876. return "Input " + String (index + 1);
  24877. return String::empty;
  24878. }
  24879. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  24880. {
  24881. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  24882. return false;
  24883. return true;
  24884. }
  24885. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  24886. {
  24887. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  24888. return "Output " + String (index + 1);
  24889. return String::empty;
  24890. }
  24891. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  24892. {
  24893. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  24894. return false;
  24895. return true;
  24896. }
  24897. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  24898. {
  24899. getCurrentProgramStateInformation (destData);
  24900. }
  24901. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  24902. {
  24903. CFPropertyListRef propertyList = 0;
  24904. UInt32 sz = sizeof (CFPropertyListRef);
  24905. if (AudioUnitGetProperty (audioUnit,
  24906. kAudioUnitProperty_ClassInfo,
  24907. kAudioUnitScope_Global,
  24908. 0, &propertyList, &sz) == noErr)
  24909. {
  24910. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  24911. CFWriteStreamOpen (stream);
  24912. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  24913. CFWriteStreamClose (stream);
  24914. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  24915. destData.setSize (bytesWritten);
  24916. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  24917. CFRelease (data);
  24918. CFRelease (stream);
  24919. CFRelease (propertyList);
  24920. }
  24921. }
  24922. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  24923. {
  24924. setCurrentProgramStateInformation (data, sizeInBytes);
  24925. }
  24926. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  24927. {
  24928. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  24929. (const UInt8*) data,
  24930. sizeInBytes,
  24931. kCFAllocatorNull);
  24932. CFReadStreamOpen (stream);
  24933. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  24934. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  24935. stream,
  24936. 0,
  24937. kCFPropertyListImmutable,
  24938. &format,
  24939. 0);
  24940. CFRelease (stream);
  24941. if (propertyList != 0)
  24942. AudioUnitSetProperty (audioUnit,
  24943. kAudioUnitProperty_ClassInfo,
  24944. kAudioUnitScope_Global,
  24945. 0, &propertyList, sizeof (propertyList));
  24946. }
  24947. AudioUnitPluginFormat::AudioUnitPluginFormat()
  24948. {
  24949. }
  24950. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  24951. {
  24952. }
  24953. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  24954. const String& fileOrIdentifier)
  24955. {
  24956. if (! fileMightContainThisPluginType (fileOrIdentifier))
  24957. return;
  24958. PluginDescription desc;
  24959. desc.fileOrIdentifier = fileOrIdentifier;
  24960. desc.uid = 0;
  24961. try
  24962. {
  24963. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  24964. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  24965. if (auInstance != 0)
  24966. {
  24967. auInstance->fillInPluginDescription (desc);
  24968. results.add (new PluginDescription (desc));
  24969. }
  24970. }
  24971. catch (...)
  24972. {
  24973. // crashed while loading...
  24974. }
  24975. }
  24976. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  24977. {
  24978. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  24979. {
  24980. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  24981. if (result->audioUnit != 0)
  24982. {
  24983. result->initialise();
  24984. return result.release();
  24985. }
  24986. }
  24987. return 0;
  24988. }
  24989. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  24990. const bool /*recursive*/)
  24991. {
  24992. StringArray result;
  24993. ComponentRecord* comp = 0;
  24994. ComponentDescription desc;
  24995. zerostruct (desc);
  24996. for (;;)
  24997. {
  24998. zerostruct (desc);
  24999. comp = FindNextComponent (comp, &desc);
  25000. if (comp == 0)
  25001. break;
  25002. GetComponentInfo (comp, &desc, 0, 0, 0);
  25003. if (desc.componentType == kAudioUnitType_MusicDevice
  25004. || desc.componentType == kAudioUnitType_MusicEffect
  25005. || desc.componentType == kAudioUnitType_Effect
  25006. || desc.componentType == kAudioUnitType_Generator
  25007. || desc.componentType == kAudioUnitType_Panner)
  25008. {
  25009. const String s (createAUPluginIdentifier (desc));
  25010. DBG (s);
  25011. result.add (s);
  25012. }
  25013. }
  25014. return result;
  25015. }
  25016. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25017. {
  25018. ComponentDescription desc;
  25019. String name, version, manufacturer;
  25020. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25021. return FindNextComponent (0, &desc) != 0;
  25022. const File f (fileOrIdentifier);
  25023. return f.hasFileExtension (".component")
  25024. && f.isDirectory();
  25025. }
  25026. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25027. {
  25028. ComponentDescription desc;
  25029. String name, version, manufacturer;
  25030. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25031. if (name.isEmpty())
  25032. name = fileOrIdentifier;
  25033. return name;
  25034. }
  25035. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25036. {
  25037. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25038. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25039. else
  25040. return File (desc.fileOrIdentifier).exists();
  25041. }
  25042. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25043. {
  25044. return FileSearchPath ("/(Default AudioUnit locations)");
  25045. }
  25046. #endif
  25047. END_JUCE_NAMESPACE
  25048. #undef log
  25049. #endif
  25050. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25051. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25052. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25053. #define JUCE_MAC_VST_INCLUDED 1
  25054. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25055. #if JUCE_PLUGINHOST_VST
  25056. #if (defined (_WIN32) || defined (_WIN64))
  25057. #undef _WIN32_WINNT
  25058. #define _WIN32_WINNT 0x500
  25059. #undef STRICT
  25060. #define STRICT
  25061. #include <windows.h>
  25062. #include <float.h>
  25063. #pragma warning (disable : 4312 4355)
  25064. #elif defined (LINUX) || defined (__linux__)
  25065. #include <float.h>
  25066. #include <sys/time.h>
  25067. #include <X11/Xlib.h>
  25068. #include <X11/Xutil.h>
  25069. #include <X11/Xatom.h>
  25070. #undef Font
  25071. #undef KeyPress
  25072. #undef Drawable
  25073. #undef Time
  25074. #else
  25075. #ifndef JUCE_MAC_VST_INCLUDED
  25076. // On the mac, this file needs to be compiled indirectly, by using
  25077. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25078. #error
  25079. #endif
  25080. #include <Cocoa/Cocoa.h>
  25081. #include <Carbon/Carbon.h>
  25082. #endif
  25083. #if ! (JUCE_MAC && JUCE_64BIT)
  25084. BEGIN_JUCE_NAMESPACE
  25085. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25086. #endif
  25087. #undef PRAGMA_ALIGN_SUPPORTED
  25088. #define VST_FORCE_DEPRECATED 0
  25089. #ifdef _MSC_VER
  25090. #pragma warning (push)
  25091. #pragma warning (disable: 4996)
  25092. #endif
  25093. #include "pluginterfaces/vst2.x/aeffectx.h"
  25094. #ifdef _MSC_VER
  25095. #pragma warning (pop)
  25096. #endif
  25097. #if JUCE_LINUX
  25098. #define Font JUCE_NAMESPACE::Font
  25099. #define KeyPress JUCE_NAMESPACE::KeyPress
  25100. #define Drawable JUCE_NAMESPACE::Drawable
  25101. #define Time JUCE_NAMESPACE::Time
  25102. #endif
  25103. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25104. #ifdef __aeffect__
  25105. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25106. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25107. class VSTMidiEventList
  25108. {
  25109. public:
  25110. VSTMidiEventList()
  25111. : numEventsUsed (0), numEventsAllocated (0)
  25112. {
  25113. }
  25114. ~VSTMidiEventList()
  25115. {
  25116. freeEvents();
  25117. }
  25118. void clear()
  25119. {
  25120. numEventsUsed = 0;
  25121. if (events != 0)
  25122. events->numEvents = 0;
  25123. }
  25124. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25125. {
  25126. ensureSize (numEventsUsed + 1);
  25127. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25128. events->numEvents = ++numEventsUsed;
  25129. if (numBytes <= 4)
  25130. {
  25131. if (e->type == kVstSysExType)
  25132. {
  25133. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25134. e->type = kVstMidiType;
  25135. e->byteSize = sizeof (VstMidiEvent);
  25136. e->noteLength = 0;
  25137. e->noteOffset = 0;
  25138. e->detune = 0;
  25139. e->noteOffVelocity = 0;
  25140. }
  25141. e->deltaFrames = frameOffset;
  25142. memcpy (e->midiData, midiData, numBytes);
  25143. }
  25144. else
  25145. {
  25146. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25147. if (se->type == kVstSysExType)
  25148. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25149. else
  25150. se->sysexDump = (char*) juce_malloc (numBytes);
  25151. memcpy (se->sysexDump, midiData, numBytes);
  25152. se->type = kVstSysExType;
  25153. se->byteSize = sizeof (VstMidiSysexEvent);
  25154. se->deltaFrames = frameOffset;
  25155. se->flags = 0;
  25156. se->dumpBytes = numBytes;
  25157. se->resvd1 = 0;
  25158. se->resvd2 = 0;
  25159. }
  25160. }
  25161. // Handy method to pull the events out of an event buffer supplied by the host
  25162. // or plugin.
  25163. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25164. {
  25165. for (int i = 0; i < events->numEvents; ++i)
  25166. {
  25167. const VstEvent* const e = events->events[i];
  25168. if (e != 0)
  25169. {
  25170. if (e->type == kVstMidiType)
  25171. {
  25172. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25173. 4, e->deltaFrames);
  25174. }
  25175. else if (e->type == kVstSysExType)
  25176. {
  25177. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25178. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25179. e->deltaFrames);
  25180. }
  25181. }
  25182. }
  25183. }
  25184. void ensureSize (int numEventsNeeded)
  25185. {
  25186. if (numEventsNeeded > numEventsAllocated)
  25187. {
  25188. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25189. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25190. if (events == 0)
  25191. events.calloc (size, 1);
  25192. else
  25193. events.realloc (size, 1);
  25194. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25195. {
  25196. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25197. (int) sizeof (VstMidiSysexEvent)));
  25198. e->type = kVstMidiType;
  25199. e->byteSize = sizeof (VstMidiEvent);
  25200. events->events[i] = (VstEvent*) e;
  25201. }
  25202. numEventsAllocated = numEventsNeeded;
  25203. }
  25204. }
  25205. void freeEvents()
  25206. {
  25207. if (events != 0)
  25208. {
  25209. for (int i = numEventsAllocated; --i >= 0;)
  25210. {
  25211. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25212. if (e->type == kVstSysExType)
  25213. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25214. juce_free (e);
  25215. }
  25216. events.free();
  25217. numEventsUsed = 0;
  25218. numEventsAllocated = 0;
  25219. }
  25220. }
  25221. HeapBlock <VstEvents> events;
  25222. private:
  25223. int numEventsUsed, numEventsAllocated;
  25224. };
  25225. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25226. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25227. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25228. #if ! JUCE_WIN32
  25229. static void _fpreset() {}
  25230. static void _clearfp() {}
  25231. #endif
  25232. extern void juce_callAnyTimersSynchronously();
  25233. const int fxbVersionNum = 1;
  25234. struct fxProgram
  25235. {
  25236. long chunkMagic; // 'CcnK'
  25237. long byteSize; // of this chunk, excl. magic + byteSize
  25238. long fxMagic; // 'FxCk'
  25239. long version;
  25240. long fxID; // fx unique id
  25241. long fxVersion;
  25242. long numParams;
  25243. char prgName[28];
  25244. float params[1]; // variable no. of parameters
  25245. };
  25246. struct fxSet
  25247. {
  25248. long chunkMagic; // 'CcnK'
  25249. long byteSize; // of this chunk, excl. magic + byteSize
  25250. long fxMagic; // 'FxBk'
  25251. long version;
  25252. long fxID; // fx unique id
  25253. long fxVersion;
  25254. long numPrograms;
  25255. char future[128];
  25256. fxProgram programs[1]; // variable no. of programs
  25257. };
  25258. struct fxChunkSet
  25259. {
  25260. long chunkMagic; // 'CcnK'
  25261. long byteSize; // of this chunk, excl. magic + byteSize
  25262. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25263. long version;
  25264. long fxID; // fx unique id
  25265. long fxVersion;
  25266. long numPrograms;
  25267. char future[128];
  25268. long chunkSize;
  25269. char chunk[8]; // variable
  25270. };
  25271. struct fxProgramSet
  25272. {
  25273. long chunkMagic; // 'CcnK'
  25274. long byteSize; // of this chunk, excl. magic + byteSize
  25275. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25276. long version;
  25277. long fxID; // fx unique id
  25278. long fxVersion;
  25279. long numPrograms;
  25280. char name[28];
  25281. long chunkSize;
  25282. char chunk[8]; // variable
  25283. };
  25284. static long vst_swap (const long x) throw()
  25285. {
  25286. #ifdef JUCE_LITTLE_ENDIAN
  25287. return (long) ByteOrder::swap ((uint32) x);
  25288. #else
  25289. return x;
  25290. #endif
  25291. }
  25292. static float vst_swapFloat (const float x) throw()
  25293. {
  25294. #ifdef JUCE_LITTLE_ENDIAN
  25295. union { uint32 asInt; float asFloat; } n;
  25296. n.asFloat = x;
  25297. n.asInt = ByteOrder::swap (n.asInt);
  25298. return n.asFloat;
  25299. #else
  25300. return x;
  25301. #endif
  25302. }
  25303. typedef AEffect* (*MainCall) (audioMasterCallback);
  25304. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25305. static int shellUIDToCreate = 0;
  25306. static int insideVSTCallback = 0;
  25307. class VSTPluginWindow;
  25308. // Change this to disable logging of various VST activities
  25309. #ifndef VST_LOGGING
  25310. #define VST_LOGGING 1
  25311. #endif
  25312. #if VST_LOGGING
  25313. #define log(a) Logger::writeToLog(a);
  25314. #else
  25315. #define log(a)
  25316. #endif
  25317. #if JUCE_MAC && JUCE_PPC
  25318. static void* NewCFMFromMachO (void* const machofp) throw()
  25319. {
  25320. void* result = juce_malloc (8);
  25321. ((void**) result)[0] = machofp;
  25322. ((void**) result)[1] = result;
  25323. return result;
  25324. }
  25325. #endif
  25326. #if JUCE_LINUX
  25327. extern Display* display;
  25328. extern XContext improbableNumber;
  25329. typedef void (*EventProcPtr) (XEvent* ev);
  25330. static bool xErrorTriggered;
  25331. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25332. {
  25333. xErrorTriggered = true;
  25334. return 0;
  25335. }
  25336. static int getPropertyFromXWindow (Window handle, Atom atom)
  25337. {
  25338. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25339. xErrorTriggered = false;
  25340. int userSize;
  25341. unsigned long bytes, userCount;
  25342. unsigned char* data;
  25343. Atom userType;
  25344. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25345. &userType, &userSize, &userCount, &bytes, &data);
  25346. XSetErrorHandler (oldErrorHandler);
  25347. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25348. : 0;
  25349. }
  25350. static Window getChildWindow (Window windowToCheck)
  25351. {
  25352. Window rootWindow, parentWindow;
  25353. Window* childWindows;
  25354. unsigned int numChildren;
  25355. XQueryTree (display,
  25356. windowToCheck,
  25357. &rootWindow,
  25358. &parentWindow,
  25359. &childWindows,
  25360. &numChildren);
  25361. if (numChildren > 0)
  25362. return childWindows [0];
  25363. return 0;
  25364. }
  25365. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25366. {
  25367. if (e.mods.isLeftButtonDown())
  25368. {
  25369. ev.xbutton.button = Button1;
  25370. ev.xbutton.state |= Button1Mask;
  25371. }
  25372. else if (e.mods.isRightButtonDown())
  25373. {
  25374. ev.xbutton.button = Button3;
  25375. ev.xbutton.state |= Button3Mask;
  25376. }
  25377. else if (e.mods.isMiddleButtonDown())
  25378. {
  25379. ev.xbutton.button = Button2;
  25380. ev.xbutton.state |= Button2Mask;
  25381. }
  25382. }
  25383. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25384. {
  25385. if (e.mods.isLeftButtonDown())
  25386. ev.xmotion.state |= Button1Mask;
  25387. else if (e.mods.isRightButtonDown())
  25388. ev.xmotion.state |= Button3Mask;
  25389. else if (e.mods.isMiddleButtonDown())
  25390. ev.xmotion.state |= Button2Mask;
  25391. }
  25392. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25393. {
  25394. if (e.mods.isLeftButtonDown())
  25395. ev.xcrossing.state |= Button1Mask;
  25396. else if (e.mods.isRightButtonDown())
  25397. ev.xcrossing.state |= Button3Mask;
  25398. else if (e.mods.isMiddleButtonDown())
  25399. ev.xcrossing.state |= Button2Mask;
  25400. }
  25401. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25402. {
  25403. if (increment < 0)
  25404. {
  25405. ev.xbutton.button = Button5;
  25406. ev.xbutton.state |= Button5Mask;
  25407. }
  25408. else if (increment > 0)
  25409. {
  25410. ev.xbutton.button = Button4;
  25411. ev.xbutton.state |= Button4Mask;
  25412. }
  25413. }
  25414. #endif
  25415. static VoidArray activeModules;
  25416. class ModuleHandle : public ReferenceCountedObject
  25417. {
  25418. public:
  25419. File file;
  25420. MainCall moduleMain;
  25421. String pluginName;
  25422. static ModuleHandle* findOrCreateModule (const File& file)
  25423. {
  25424. for (int i = activeModules.size(); --i >= 0;)
  25425. {
  25426. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25427. if (module->file == file)
  25428. return module;
  25429. }
  25430. _fpreset(); // (doesn't do any harm)
  25431. ++insideVSTCallback;
  25432. shellUIDToCreate = 0;
  25433. log ("Attempting to load VST: " + file.getFullPathName());
  25434. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25435. if (! m->open())
  25436. m = 0;
  25437. --insideVSTCallback;
  25438. _fpreset(); // (doesn't do any harm)
  25439. return m.release();
  25440. }
  25441. ModuleHandle (const File& file_)
  25442. : file (file_),
  25443. moduleMain (0),
  25444. #if JUCE_WIN32 || JUCE_LINUX
  25445. hModule (0)
  25446. #elif JUCE_MAC
  25447. fragId (0),
  25448. resHandle (0),
  25449. bundleRef (0),
  25450. resFileId (0)
  25451. #endif
  25452. {
  25453. activeModules.add (this);
  25454. #if JUCE_WIN32 || JUCE_LINUX
  25455. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25456. #elif JUCE_MAC
  25457. FSRef ref;
  25458. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25459. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25460. #endif
  25461. }
  25462. ~ModuleHandle()
  25463. {
  25464. activeModules.removeValue (this);
  25465. close();
  25466. }
  25467. juce_UseDebuggingNewOperator
  25468. #if JUCE_WIN32 || JUCE_LINUX
  25469. void* hModule;
  25470. String fullParentDirectoryPathName;
  25471. bool open()
  25472. {
  25473. #if JUCE_WIN32
  25474. static bool timePeriodSet = false;
  25475. if (! timePeriodSet)
  25476. {
  25477. timePeriodSet = true;
  25478. timeBeginPeriod (2);
  25479. }
  25480. #endif
  25481. pluginName = file.getFileNameWithoutExtension();
  25482. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25483. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25484. if (moduleMain == 0)
  25485. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25486. return moduleMain != 0;
  25487. }
  25488. void close()
  25489. {
  25490. _fpreset(); // (doesn't do any harm)
  25491. PlatformUtilities::freeDynamicLibrary (hModule);
  25492. }
  25493. void closeEffect (AEffect* eff)
  25494. {
  25495. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25496. }
  25497. #else
  25498. CFragConnectionID fragId;
  25499. Handle resHandle;
  25500. CFBundleRef bundleRef;
  25501. FSSpec parentDirFSSpec;
  25502. short resFileId;
  25503. bool open()
  25504. {
  25505. bool ok = false;
  25506. const String filename (file.getFullPathName());
  25507. if (file.hasFileExtension (".vst"))
  25508. {
  25509. const char* const utf8 = filename.toUTF8();
  25510. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25511. strlen (utf8), file.isDirectory());
  25512. if (url != 0)
  25513. {
  25514. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25515. CFRelease (url);
  25516. if (bundleRef != 0)
  25517. {
  25518. if (CFBundleLoadExecutable (bundleRef))
  25519. {
  25520. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25521. if (moduleMain == 0)
  25522. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25523. if (moduleMain != 0)
  25524. {
  25525. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25526. if (name != 0)
  25527. {
  25528. if (CFGetTypeID (name) == CFStringGetTypeID())
  25529. {
  25530. char buffer[1024];
  25531. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25532. pluginName = buffer;
  25533. }
  25534. }
  25535. if (pluginName.isEmpty())
  25536. pluginName = file.getFileNameWithoutExtension();
  25537. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25538. ok = true;
  25539. }
  25540. }
  25541. if (! ok)
  25542. {
  25543. CFBundleUnloadExecutable (bundleRef);
  25544. CFRelease (bundleRef);
  25545. bundleRef = 0;
  25546. }
  25547. }
  25548. }
  25549. }
  25550. #if JUCE_PPC
  25551. else
  25552. {
  25553. FSRef fn;
  25554. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25555. {
  25556. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25557. if (resFileId != -1)
  25558. {
  25559. const int numEffs = Count1Resources ('aEff');
  25560. for (int i = 0; i < numEffs; ++i)
  25561. {
  25562. resHandle = Get1IndResource ('aEff', i + 1);
  25563. if (resHandle != 0)
  25564. {
  25565. OSType type;
  25566. Str255 name;
  25567. SInt16 id;
  25568. GetResInfo (resHandle, &id, &type, name);
  25569. pluginName = String ((const char*) name + 1, name[0]);
  25570. DetachResource (resHandle);
  25571. HLock (resHandle);
  25572. Ptr ptr;
  25573. Str255 errorText;
  25574. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25575. name, kPrivateCFragCopy,
  25576. &fragId, &ptr, errorText);
  25577. if (err == noErr)
  25578. {
  25579. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25580. ok = true;
  25581. }
  25582. else
  25583. {
  25584. HUnlock (resHandle);
  25585. }
  25586. break;
  25587. }
  25588. }
  25589. if (! ok)
  25590. CloseResFile (resFileId);
  25591. }
  25592. }
  25593. }
  25594. #endif
  25595. return ok;
  25596. }
  25597. void close()
  25598. {
  25599. #if JUCE_PPC
  25600. if (fragId != 0)
  25601. {
  25602. if (moduleMain != 0)
  25603. disposeMachOFromCFM ((void*) moduleMain);
  25604. CloseConnection (&fragId);
  25605. HUnlock (resHandle);
  25606. if (resFileId != 0)
  25607. CloseResFile (resFileId);
  25608. }
  25609. else
  25610. #endif
  25611. if (bundleRef != 0)
  25612. {
  25613. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25614. if (CFGetRetainCount (bundleRef) == 1)
  25615. CFBundleUnloadExecutable (bundleRef);
  25616. if (CFGetRetainCount (bundleRef) > 0)
  25617. CFRelease (bundleRef);
  25618. }
  25619. }
  25620. void closeEffect (AEffect* eff)
  25621. {
  25622. #if JUCE_PPC
  25623. if (fragId != 0)
  25624. {
  25625. VoidArray thingsToDelete;
  25626. thingsToDelete.add ((void*) eff->dispatcher);
  25627. thingsToDelete.add ((void*) eff->process);
  25628. thingsToDelete.add ((void*) eff->setParameter);
  25629. thingsToDelete.add ((void*) eff->getParameter);
  25630. thingsToDelete.add ((void*) eff->processReplacing);
  25631. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25632. for (int i = thingsToDelete.size(); --i >= 0;)
  25633. disposeMachOFromCFM (thingsToDelete[i]);
  25634. }
  25635. else
  25636. #endif
  25637. {
  25638. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25639. }
  25640. }
  25641. #if JUCE_PPC
  25642. static void* newMachOFromCFM (void* cfmfp)
  25643. {
  25644. if (cfmfp == 0)
  25645. return 0;
  25646. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25647. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25648. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25649. mfp[2] = 0x800c0000;
  25650. mfp[3] = 0x804c0004;
  25651. mfp[4] = 0x7c0903a6;
  25652. mfp[5] = 0x4e800420;
  25653. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25654. return mfp;
  25655. }
  25656. static void disposeMachOFromCFM (void* ptr)
  25657. {
  25658. juce_free (ptr);
  25659. }
  25660. void coerceAEffectFunctionCalls (AEffect* eff)
  25661. {
  25662. if (fragId != 0)
  25663. {
  25664. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25665. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25666. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25667. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25668. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25669. }
  25670. }
  25671. #endif
  25672. #endif
  25673. };
  25674. class VSTPluginInstance : public AudioPluginInstance,
  25675. private Timer,
  25676. private AsyncUpdater
  25677. {
  25678. public:
  25679. ~VSTPluginInstance();
  25680. // AudioPluginInstance methods:
  25681. void fillInPluginDescription (PluginDescription& desc) const
  25682. {
  25683. desc.name = name;
  25684. desc.fileOrIdentifier = module->file.getFullPathName();
  25685. desc.uid = getUID();
  25686. desc.lastFileModTime = module->file.getLastModificationTime();
  25687. desc.pluginFormatName = "VST";
  25688. desc.category = getCategory();
  25689. {
  25690. char buffer [kVstMaxVendorStrLen + 8];
  25691. zerostruct (buffer);
  25692. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25693. desc.manufacturerName = buffer;
  25694. }
  25695. desc.version = getVersion();
  25696. desc.numInputChannels = getNumInputChannels();
  25697. desc.numOutputChannels = getNumOutputChannels();
  25698. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25699. }
  25700. const String getName() const { return name; }
  25701. int getUID() const throw();
  25702. bool acceptsMidi() const { return wantsMidiMessages; }
  25703. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25704. // AudioProcessor methods:
  25705. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25706. void releaseResources();
  25707. void processBlock (AudioSampleBuffer& buffer,
  25708. MidiBuffer& midiMessages);
  25709. AudioProcessorEditor* createEditor();
  25710. const String getInputChannelName (const int index) const;
  25711. bool isInputChannelStereoPair (int index) const;
  25712. const String getOutputChannelName (const int index) const;
  25713. bool isOutputChannelStereoPair (int index) const;
  25714. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25715. float getParameter (int index);
  25716. void setParameter (int index, float newValue);
  25717. const String getParameterName (int index);
  25718. const String getParameterText (int index);
  25719. bool isParameterAutomatable (int index) const;
  25720. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25721. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25722. void setCurrentProgram (int index);
  25723. const String getProgramName (int index);
  25724. void changeProgramName (int index, const String& newName);
  25725. void getStateInformation (MemoryBlock& destData);
  25726. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25727. void setStateInformation (const void* data, int sizeInBytes);
  25728. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25729. void timerCallback();
  25730. void handleAsyncUpdate();
  25731. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25732. juce_UseDebuggingNewOperator
  25733. private:
  25734. friend class VSTPluginWindow;
  25735. friend class VSTPluginFormat;
  25736. AEffect* effect;
  25737. String name;
  25738. CriticalSection lock;
  25739. bool wantsMidiMessages, initialised, isPowerOn;
  25740. mutable StringArray programNames;
  25741. AudioSampleBuffer tempBuffer;
  25742. CriticalSection midiInLock;
  25743. MidiBuffer incomingMidi;
  25744. VSTMidiEventList midiEventsToSend;
  25745. VstTimeInfo vstHostTime;
  25746. HeapBlock <float*> channels;
  25747. ReferenceCountedObjectPtr <ModuleHandle> module;
  25748. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25749. bool restoreProgramSettings (const fxProgram* const prog);
  25750. const String getCurrentProgramName();
  25751. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25752. void updateStoredProgramNames();
  25753. void initialise();
  25754. void handleMidiFromPlugin (const VstEvents* const events);
  25755. void createTempParameterStore (MemoryBlock& dest);
  25756. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25757. const String getParameterLabel (int index) const;
  25758. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25759. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25760. void setChunkData (const char* data, int size, bool isPreset);
  25761. bool loadFromFXBFile (const void* data, int numBytes);
  25762. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25763. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25764. const String getVersion() const throw();
  25765. const String getCategory() const throw();
  25766. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25767. void setPower (const bool on);
  25768. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25769. };
  25770. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25771. : effect (0),
  25772. wantsMidiMessages (false),
  25773. initialised (false),
  25774. isPowerOn (false),
  25775. tempBuffer (1, 1),
  25776. module (module_)
  25777. {
  25778. try
  25779. {
  25780. _fpreset();
  25781. ++insideVSTCallback;
  25782. name = module->pluginName;
  25783. log ("Creating VST instance: " + name);
  25784. #if JUCE_MAC
  25785. if (module->resFileId != 0)
  25786. UseResFile (module->resFileId);
  25787. #if JUCE_PPC
  25788. if (module->fragId != 0)
  25789. {
  25790. static void* audioMasterCoerced = 0;
  25791. if (audioMasterCoerced == 0)
  25792. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25793. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25794. }
  25795. else
  25796. #endif
  25797. #endif
  25798. {
  25799. effect = module->moduleMain (&audioMaster);
  25800. }
  25801. --insideVSTCallback;
  25802. if (effect != 0 && effect->magic == kEffectMagic)
  25803. {
  25804. #if JUCE_PPC
  25805. module->coerceAEffectFunctionCalls (effect);
  25806. #endif
  25807. jassert (effect->resvd2 == 0);
  25808. jassert (effect->object != 0);
  25809. _fpreset(); // some dodgy plugs fuck around with this
  25810. }
  25811. else
  25812. {
  25813. effect = 0;
  25814. }
  25815. }
  25816. catch (...)
  25817. {
  25818. --insideVSTCallback;
  25819. }
  25820. }
  25821. VSTPluginInstance::~VSTPluginInstance()
  25822. {
  25823. {
  25824. const ScopedLock sl (lock);
  25825. jassert (insideVSTCallback == 0);
  25826. if (effect != 0 && effect->magic == kEffectMagic)
  25827. {
  25828. try
  25829. {
  25830. #if JUCE_MAC
  25831. if (module->resFileId != 0)
  25832. UseResFile (module->resFileId);
  25833. #endif
  25834. // Must delete any editors before deleting the plugin instance!
  25835. jassert (getActiveEditor() == 0);
  25836. _fpreset(); // some dodgy plugs fuck around with this
  25837. module->closeEffect (effect);
  25838. }
  25839. catch (...)
  25840. {}
  25841. }
  25842. module = 0;
  25843. effect = 0;
  25844. }
  25845. }
  25846. void VSTPluginInstance::initialise()
  25847. {
  25848. if (initialised || effect == 0)
  25849. return;
  25850. log ("Initialising VST: " + module->pluginName);
  25851. initialised = true;
  25852. dispatch (effIdentify, 0, 0, 0, 0);
  25853. // this code would ask the plugin for its name, but so few plugins
  25854. // actually bother implementing this correctly, that it's better to
  25855. // just ignore it and use the file name instead.
  25856. if (getSampleRate() > 0)
  25857. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25858. if (getBlockSize() > 0)
  25859. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25860. dispatch (effOpen, 0, 0, 0, 0);
  25861. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25862. getSampleRate(), getBlockSize());
  25863. if (getNumPrograms() > 1)
  25864. setCurrentProgram (0);
  25865. else
  25866. dispatch (effSetProgram, 0, 0, 0, 0);
  25867. int i;
  25868. for (i = effect->numInputs; --i >= 0;)
  25869. dispatch (effConnectInput, i, 1, 0, 0);
  25870. for (i = effect->numOutputs; --i >= 0;)
  25871. dispatch (effConnectOutput, i, 1, 0, 0);
  25872. updateStoredProgramNames();
  25873. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25874. setLatencySamples (effect->initialDelay);
  25875. }
  25876. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  25877. int samplesPerBlockExpected)
  25878. {
  25879. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25880. sampleRate_, samplesPerBlockExpected);
  25881. setLatencySamples (effect->initialDelay);
  25882. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  25883. vstHostTime.tempo = 120.0;
  25884. vstHostTime.timeSigNumerator = 4;
  25885. vstHostTime.timeSigDenominator = 4;
  25886. vstHostTime.sampleRate = sampleRate_;
  25887. vstHostTime.samplePos = 0;
  25888. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  25889. initialise();
  25890. if (initialised)
  25891. {
  25892. wantsMidiMessages = wantsMidiMessages
  25893. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  25894. if (wantsMidiMessages)
  25895. midiEventsToSend.ensureSize (256);
  25896. else
  25897. midiEventsToSend.freeEvents();
  25898. incomingMidi.clear();
  25899. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  25900. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  25901. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  25902. if (! isPowerOn)
  25903. setPower (true);
  25904. // dodgy hack to force some plugins to initialise the sample rate..
  25905. if ((! hasEditor()) && getNumParameters() > 0)
  25906. {
  25907. const float old = getParameter (0);
  25908. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  25909. setParameter (0, old);
  25910. }
  25911. dispatch (effStartProcess, 0, 0, 0, 0);
  25912. }
  25913. }
  25914. void VSTPluginInstance::releaseResources()
  25915. {
  25916. if (initialised)
  25917. {
  25918. dispatch (effStopProcess, 0, 0, 0, 0);
  25919. setPower (false);
  25920. }
  25921. tempBuffer.setSize (1, 1);
  25922. incomingMidi.clear();
  25923. midiEventsToSend.freeEvents();
  25924. channels.free();
  25925. }
  25926. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  25927. MidiBuffer& midiMessages)
  25928. {
  25929. const int numSamples = buffer.getNumSamples();
  25930. if (initialised)
  25931. {
  25932. AudioPlayHead* playHead = getPlayHead();
  25933. if (playHead != 0)
  25934. {
  25935. AudioPlayHead::CurrentPositionInfo position;
  25936. playHead->getCurrentPosition (position);
  25937. vstHostTime.tempo = position.bpm;
  25938. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  25939. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  25940. vstHostTime.ppqPos = position.ppqPosition;
  25941. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  25942. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  25943. if (position.isPlaying)
  25944. vstHostTime.flags |= kVstTransportPlaying;
  25945. else
  25946. vstHostTime.flags &= ~kVstTransportPlaying;
  25947. }
  25948. #if JUCE_WIN32
  25949. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  25950. #elif JUCE_LINUX
  25951. timeval micro;
  25952. gettimeofday (&micro, 0);
  25953. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  25954. #elif JUCE_MAC
  25955. UnsignedWide micro;
  25956. Microseconds (&micro);
  25957. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  25958. #endif
  25959. if (wantsMidiMessages)
  25960. {
  25961. midiEventsToSend.clear();
  25962. midiEventsToSend.ensureSize (1);
  25963. MidiBuffer::Iterator iter (midiMessages);
  25964. const uint8* midiData;
  25965. int numBytesOfMidiData, samplePosition;
  25966. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  25967. {
  25968. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  25969. jlimit (0, numSamples - 1, samplePosition));
  25970. }
  25971. try
  25972. {
  25973. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  25974. }
  25975. catch (...)
  25976. {}
  25977. }
  25978. int i;
  25979. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  25980. for (i = 0; i < maxChans; ++i)
  25981. channels[i] = buffer.getSampleData (i);
  25982. channels [maxChans] = 0;
  25983. _clearfp();
  25984. if ((effect->flags & effFlagsCanReplacing) != 0)
  25985. {
  25986. try
  25987. {
  25988. effect->processReplacing (effect, channels, channels, numSamples);
  25989. }
  25990. catch (...)
  25991. {}
  25992. }
  25993. else
  25994. {
  25995. tempBuffer.setSize (effect->numOutputs, numSamples);
  25996. tempBuffer.clear();
  25997. float* outs [64];
  25998. for (i = effect->numOutputs; --i >= 0;)
  25999. outs[i] = tempBuffer.getSampleData (i);
  26000. outs [effect->numOutputs] = 0;
  26001. try
  26002. {
  26003. effect->process (effect, channels, outs, numSamples);
  26004. }
  26005. catch (...)
  26006. {}
  26007. for (i = effect->numOutputs; --i >= 0;)
  26008. buffer.copyFrom (i, 0, outs[i], numSamples);
  26009. }
  26010. }
  26011. else
  26012. {
  26013. // Not initialised, so just bypass..
  26014. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26015. buffer.clear (i, 0, buffer.getNumSamples());
  26016. }
  26017. {
  26018. // copy any incoming midi..
  26019. const ScopedLock sl (midiInLock);
  26020. midiMessages = incomingMidi;
  26021. incomingMidi.clear();
  26022. }
  26023. }
  26024. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26025. {
  26026. if (events != 0)
  26027. {
  26028. const ScopedLock sl (midiInLock);
  26029. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26030. }
  26031. }
  26032. static Array <VSTPluginWindow*> activeVSTWindows;
  26033. class VSTPluginWindow : public AudioProcessorEditor,
  26034. #if ! JUCE_MAC
  26035. public ComponentMovementWatcher,
  26036. #endif
  26037. public Timer
  26038. {
  26039. public:
  26040. VSTPluginWindow (VSTPluginInstance& plugin_)
  26041. : AudioProcessorEditor (&plugin_),
  26042. #if ! JUCE_MAC
  26043. ComponentMovementWatcher (this),
  26044. #endif
  26045. plugin (plugin_),
  26046. isOpen (false),
  26047. wasShowing (false),
  26048. pluginRefusesToResize (false),
  26049. pluginWantsKeys (false),
  26050. alreadyInside (false),
  26051. recursiveResize (false)
  26052. {
  26053. #if JUCE_WIN32
  26054. sizeCheckCount = 0;
  26055. pluginHWND = 0;
  26056. #elif JUCE_LINUX
  26057. pluginWindow = None;
  26058. pluginProc = None;
  26059. #else
  26060. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26061. #endif
  26062. activeVSTWindows.add (this);
  26063. setSize (1, 1);
  26064. setOpaque (true);
  26065. setVisible (true);
  26066. }
  26067. ~VSTPluginWindow()
  26068. {
  26069. #if JUCE_MAC
  26070. innerWrapper = 0;
  26071. #else
  26072. closePluginWindow();
  26073. #endif
  26074. activeVSTWindows.removeValue (this);
  26075. plugin.editorBeingDeleted (this);
  26076. }
  26077. #if ! JUCE_MAC
  26078. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26079. {
  26080. if (recursiveResize)
  26081. return;
  26082. Component* const topComp = getTopLevelComponent();
  26083. if (topComp->getPeer() != 0)
  26084. {
  26085. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26086. recursiveResize = true;
  26087. #if JUCE_WIN32
  26088. if (pluginHWND != 0)
  26089. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26090. #elif JUCE_LINUX
  26091. if (pluginWindow != 0)
  26092. {
  26093. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26094. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26095. XMapRaised (display, pluginWindow);
  26096. }
  26097. #endif
  26098. recursiveResize = false;
  26099. }
  26100. }
  26101. void componentVisibilityChanged (Component&)
  26102. {
  26103. const bool isShowingNow = isShowing();
  26104. if (wasShowing != isShowingNow)
  26105. {
  26106. wasShowing = isShowingNow;
  26107. if (isShowingNow)
  26108. openPluginWindow();
  26109. else
  26110. closePluginWindow();
  26111. }
  26112. componentMovedOrResized (true, true);
  26113. }
  26114. void componentPeerChanged()
  26115. {
  26116. closePluginWindow();
  26117. openPluginWindow();
  26118. }
  26119. #endif
  26120. bool keyStateChanged (bool)
  26121. {
  26122. return pluginWantsKeys;
  26123. }
  26124. bool keyPressed (const KeyPress&)
  26125. {
  26126. return pluginWantsKeys;
  26127. }
  26128. #if JUCE_MAC
  26129. void paint (Graphics& g)
  26130. {
  26131. g.fillAll (Colours::black);
  26132. }
  26133. #else
  26134. void paint (Graphics& g)
  26135. {
  26136. if (isOpen)
  26137. {
  26138. ComponentPeer* const peer = getPeer();
  26139. if (peer != 0)
  26140. {
  26141. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26142. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26143. #if JUCE_LINUX
  26144. if (pluginWindow != 0)
  26145. {
  26146. const Rectangle<int> clip (g.getClipBounds());
  26147. XEvent ev;
  26148. zerostruct (ev);
  26149. ev.xexpose.type = Expose;
  26150. ev.xexpose.display = display;
  26151. ev.xexpose.window = pluginWindow;
  26152. ev.xexpose.x = clip.getX();
  26153. ev.xexpose.y = clip.getY();
  26154. ev.xexpose.width = clip.getWidth();
  26155. ev.xexpose.height = clip.getHeight();
  26156. sendEventToChild (&ev);
  26157. }
  26158. #endif
  26159. }
  26160. }
  26161. else
  26162. {
  26163. g.fillAll (Colours::black);
  26164. }
  26165. }
  26166. #endif
  26167. void timerCallback()
  26168. {
  26169. #if JUCE_WIN32
  26170. if (--sizeCheckCount <= 0)
  26171. {
  26172. sizeCheckCount = 10;
  26173. checkPluginWindowSize();
  26174. }
  26175. #endif
  26176. try
  26177. {
  26178. static bool reentrant = false;
  26179. if (! reentrant)
  26180. {
  26181. reentrant = true;
  26182. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26183. reentrant = false;
  26184. }
  26185. }
  26186. catch (...)
  26187. {}
  26188. }
  26189. void mouseDown (const MouseEvent& e)
  26190. {
  26191. #if JUCE_LINUX
  26192. if (pluginWindow == 0)
  26193. return;
  26194. toFront (true);
  26195. XEvent ev;
  26196. zerostruct (ev);
  26197. ev.xbutton.display = display;
  26198. ev.xbutton.type = ButtonPress;
  26199. ev.xbutton.window = pluginWindow;
  26200. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26201. ev.xbutton.time = CurrentTime;
  26202. ev.xbutton.x = e.x;
  26203. ev.xbutton.y = e.y;
  26204. ev.xbutton.x_root = e.getScreenX();
  26205. ev.xbutton.y_root = e.getScreenY();
  26206. translateJuceToXButtonModifiers (e, ev);
  26207. sendEventToChild (&ev);
  26208. #elif JUCE_WIN32
  26209. (void) e;
  26210. toFront (true);
  26211. #endif
  26212. }
  26213. void broughtToFront()
  26214. {
  26215. activeVSTWindows.removeValue (this);
  26216. activeVSTWindows.add (this);
  26217. #if JUCE_MAC
  26218. dispatch (effEditTop, 0, 0, 0, 0);
  26219. #endif
  26220. }
  26221. juce_UseDebuggingNewOperator
  26222. private:
  26223. VSTPluginInstance& plugin;
  26224. bool isOpen, wasShowing, recursiveResize;
  26225. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26226. #if JUCE_WIN32
  26227. HWND pluginHWND;
  26228. void* originalWndProc;
  26229. int sizeCheckCount;
  26230. #elif JUCE_LINUX
  26231. Window pluginWindow;
  26232. EventProcPtr pluginProc;
  26233. #endif
  26234. #if JUCE_MAC
  26235. void openPluginWindow (WindowRef parentWindow)
  26236. {
  26237. if (isOpen || parentWindow == 0)
  26238. return;
  26239. isOpen = true;
  26240. ERect* rect = 0;
  26241. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26242. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26243. // do this before and after like in the steinberg example
  26244. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26245. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26246. // Install keyboard hooks
  26247. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26248. // double-check it's not too tiny
  26249. int w = 250, h = 150;
  26250. if (rect != 0)
  26251. {
  26252. w = rect->right - rect->left;
  26253. h = rect->bottom - rect->top;
  26254. if (w == 0 || h == 0)
  26255. {
  26256. w = 250;
  26257. h = 150;
  26258. }
  26259. }
  26260. w = jmax (w, 32);
  26261. h = jmax (h, 32);
  26262. setSize (w, h);
  26263. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26264. repaint();
  26265. }
  26266. #else
  26267. void openPluginWindow()
  26268. {
  26269. if (isOpen || getWindowHandle() == 0)
  26270. return;
  26271. log ("Opening VST UI: " + plugin.name);
  26272. isOpen = true;
  26273. ERect* rect = 0;
  26274. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26275. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26276. // do this before and after like in the steinberg example
  26277. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26278. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26279. // Install keyboard hooks
  26280. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26281. #if JUCE_WIN32
  26282. originalWndProc = 0;
  26283. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26284. if (pluginHWND == 0)
  26285. {
  26286. isOpen = false;
  26287. setSize (300, 150);
  26288. return;
  26289. }
  26290. #pragma warning (push)
  26291. #pragma warning (disable: 4244)
  26292. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26293. if (! pluginWantsKeys)
  26294. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) vstHookWndProc);
  26295. #pragma warning (pop)
  26296. int w, h;
  26297. RECT r;
  26298. GetWindowRect (pluginHWND, &r);
  26299. w = r.right - r.left;
  26300. h = r.bottom - r.top;
  26301. if (rect != 0)
  26302. {
  26303. const int rw = rect->right - rect->left;
  26304. const int rh = rect->bottom - rect->top;
  26305. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26306. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26307. {
  26308. // very dodgy logic to decide which size is right.
  26309. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26310. {
  26311. SetWindowPos (pluginHWND, 0,
  26312. 0, 0, rw, rh,
  26313. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26314. GetWindowRect (pluginHWND, &r);
  26315. w = r.right - r.left;
  26316. h = r.bottom - r.top;
  26317. pluginRefusesToResize = (w != rw) || (h != rh);
  26318. w = rw;
  26319. h = rh;
  26320. }
  26321. }
  26322. }
  26323. #elif JUCE_LINUX
  26324. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26325. if (pluginWindow != 0)
  26326. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26327. XInternAtom (display, "_XEventProc", False));
  26328. int w = 250, h = 150;
  26329. if (rect != 0)
  26330. {
  26331. w = rect->right - rect->left;
  26332. h = rect->bottom - rect->top;
  26333. if (w == 0 || h == 0)
  26334. {
  26335. w = 250;
  26336. h = 150;
  26337. }
  26338. }
  26339. if (pluginWindow != 0)
  26340. XMapRaised (display, pluginWindow);
  26341. #endif
  26342. // double-check it's not too tiny
  26343. w = jmax (w, 32);
  26344. h = jmax (h, 32);
  26345. setSize (w, h);
  26346. #if JUCE_WIN32
  26347. checkPluginWindowSize();
  26348. #endif
  26349. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26350. repaint();
  26351. }
  26352. #endif
  26353. #if ! JUCE_MAC
  26354. void closePluginWindow()
  26355. {
  26356. if (isOpen)
  26357. {
  26358. log ("Closing VST UI: " + plugin.getName());
  26359. isOpen = false;
  26360. dispatch (effEditClose, 0, 0, 0, 0);
  26361. #if JUCE_WIN32
  26362. #pragma warning (push)
  26363. #pragma warning (disable: 4244)
  26364. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26365. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) originalWndProc);
  26366. #pragma warning (pop)
  26367. stopTimer();
  26368. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26369. DestroyWindow (pluginHWND);
  26370. pluginHWND = 0;
  26371. #elif JUCE_LINUX
  26372. stopTimer();
  26373. pluginWindow = 0;
  26374. pluginProc = 0;
  26375. #endif
  26376. }
  26377. }
  26378. #endif
  26379. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26380. {
  26381. return plugin.dispatch (opcode, index, value, ptr, opt);
  26382. }
  26383. #if JUCE_WIN32
  26384. void checkPluginWindowSize() throw()
  26385. {
  26386. RECT r;
  26387. GetWindowRect (pluginHWND, &r);
  26388. const int w = r.right - r.left;
  26389. const int h = r.bottom - r.top;
  26390. if (isShowing() && w > 0 && h > 0
  26391. && (w != getWidth() || h != getHeight())
  26392. && ! pluginRefusesToResize)
  26393. {
  26394. setSize (w, h);
  26395. sizeCheckCount = 0;
  26396. }
  26397. }
  26398. // hooks to get keyboard events from VST windows..
  26399. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26400. {
  26401. for (int i = activeVSTWindows.size(); --i >= 0;)
  26402. {
  26403. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26404. if (w->pluginHWND == hW)
  26405. {
  26406. if (message == WM_CHAR
  26407. || message == WM_KEYDOWN
  26408. || message == WM_SYSKEYDOWN
  26409. || message == WM_KEYUP
  26410. || message == WM_SYSKEYUP
  26411. || message == WM_APPCOMMAND)
  26412. {
  26413. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26414. message, wParam, lParam);
  26415. }
  26416. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26417. (HWND) w->pluginHWND,
  26418. message,
  26419. wParam,
  26420. lParam);
  26421. }
  26422. }
  26423. return DefWindowProc (hW, message, wParam, lParam);
  26424. }
  26425. #endif
  26426. #if JUCE_LINUX
  26427. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26428. void sendEventToChild (XEvent* event)
  26429. {
  26430. if (pluginProc != 0)
  26431. {
  26432. // if the plugin publishes an event procedure, pass the event directly..
  26433. pluginProc (event);
  26434. }
  26435. else if (pluginWindow != 0)
  26436. {
  26437. // if the plugin has a window, then send the event to the window so that
  26438. // its message thread will pick it up..
  26439. XSendEvent (display, pluginWindow, False, 0L, event);
  26440. XFlush (display);
  26441. }
  26442. }
  26443. void mouseEnter (const MouseEvent& e)
  26444. {
  26445. if (pluginWindow != 0)
  26446. {
  26447. XEvent ev;
  26448. zerostruct (ev);
  26449. ev.xcrossing.display = display;
  26450. ev.xcrossing.type = EnterNotify;
  26451. ev.xcrossing.window = pluginWindow;
  26452. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26453. ev.xcrossing.time = CurrentTime;
  26454. ev.xcrossing.x = e.x;
  26455. ev.xcrossing.y = e.y;
  26456. ev.xcrossing.x_root = e.getScreenX();
  26457. ev.xcrossing.y_root = e.getScreenY();
  26458. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26459. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26460. translateJuceToXCrossingModifiers (e, ev);
  26461. sendEventToChild (&ev);
  26462. }
  26463. }
  26464. void mouseExit (const MouseEvent& e)
  26465. {
  26466. if (pluginWindow != 0)
  26467. {
  26468. XEvent ev;
  26469. zerostruct (ev);
  26470. ev.xcrossing.display = display;
  26471. ev.xcrossing.type = LeaveNotify;
  26472. ev.xcrossing.window = pluginWindow;
  26473. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26474. ev.xcrossing.time = CurrentTime;
  26475. ev.xcrossing.x = e.x;
  26476. ev.xcrossing.y = e.y;
  26477. ev.xcrossing.x_root = e.getScreenX();
  26478. ev.xcrossing.y_root = e.getScreenY();
  26479. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26480. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26481. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26482. translateJuceToXCrossingModifiers (e, ev);
  26483. sendEventToChild (&ev);
  26484. }
  26485. }
  26486. void mouseMove (const MouseEvent& e)
  26487. {
  26488. if (pluginWindow != 0)
  26489. {
  26490. XEvent ev;
  26491. zerostruct (ev);
  26492. ev.xmotion.display = display;
  26493. ev.xmotion.type = MotionNotify;
  26494. ev.xmotion.window = pluginWindow;
  26495. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26496. ev.xmotion.time = CurrentTime;
  26497. ev.xmotion.is_hint = NotifyNormal;
  26498. ev.xmotion.x = e.x;
  26499. ev.xmotion.y = e.y;
  26500. ev.xmotion.x_root = e.getScreenX();
  26501. ev.xmotion.y_root = e.getScreenY();
  26502. sendEventToChild (&ev);
  26503. }
  26504. }
  26505. void mouseDrag (const MouseEvent& e)
  26506. {
  26507. if (pluginWindow != 0)
  26508. {
  26509. XEvent ev;
  26510. zerostruct (ev);
  26511. ev.xmotion.display = display;
  26512. ev.xmotion.type = MotionNotify;
  26513. ev.xmotion.window = pluginWindow;
  26514. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26515. ev.xmotion.time = CurrentTime;
  26516. ev.xmotion.x = e.x ;
  26517. ev.xmotion.y = e.y;
  26518. ev.xmotion.x_root = e.getScreenX();
  26519. ev.xmotion.y_root = e.getScreenY();
  26520. ev.xmotion.is_hint = NotifyNormal;
  26521. translateJuceToXMotionModifiers (e, ev);
  26522. sendEventToChild (&ev);
  26523. }
  26524. }
  26525. void mouseUp (const MouseEvent& e)
  26526. {
  26527. if (pluginWindow != 0)
  26528. {
  26529. XEvent ev;
  26530. zerostruct (ev);
  26531. ev.xbutton.display = display;
  26532. ev.xbutton.type = ButtonRelease;
  26533. ev.xbutton.window = pluginWindow;
  26534. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26535. ev.xbutton.time = CurrentTime;
  26536. ev.xbutton.x = e.x;
  26537. ev.xbutton.y = e.y;
  26538. ev.xbutton.x_root = e.getScreenX();
  26539. ev.xbutton.y_root = e.getScreenY();
  26540. translateJuceToXButtonModifiers (e, ev);
  26541. sendEventToChild (&ev);
  26542. }
  26543. }
  26544. void mouseWheelMove (const MouseEvent& e,
  26545. float incrementX,
  26546. float incrementY)
  26547. {
  26548. if (pluginWindow != 0)
  26549. {
  26550. XEvent ev;
  26551. zerostruct (ev);
  26552. ev.xbutton.display = display;
  26553. ev.xbutton.type = ButtonPress;
  26554. ev.xbutton.window = pluginWindow;
  26555. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26556. ev.xbutton.time = CurrentTime;
  26557. ev.xbutton.x = e.x;
  26558. ev.xbutton.y = e.y;
  26559. ev.xbutton.x_root = e.getScreenX();
  26560. ev.xbutton.y_root = e.getScreenY();
  26561. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26562. sendEventToChild (&ev);
  26563. // TODO - put a usleep here ?
  26564. ev.xbutton.type = ButtonRelease;
  26565. sendEventToChild (&ev);
  26566. }
  26567. }
  26568. #endif
  26569. #if JUCE_MAC
  26570. #if ! JUCE_SUPPORT_CARBON
  26571. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26572. #endif
  26573. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26574. {
  26575. public:
  26576. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26577. : owner (owner_),
  26578. alreadyInside (false)
  26579. {
  26580. }
  26581. ~InnerWrapperComponent()
  26582. {
  26583. deleteWindow();
  26584. }
  26585. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26586. {
  26587. owner->openPluginWindow (windowRef);
  26588. return 0;
  26589. }
  26590. void removeView (HIViewRef)
  26591. {
  26592. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26593. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26594. }
  26595. bool getEmbeddedViewSize (int& w, int& h)
  26596. {
  26597. ERect* rect = 0;
  26598. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26599. w = rect->right - rect->left;
  26600. h = rect->bottom - rect->top;
  26601. return true;
  26602. }
  26603. void mouseDown (int x, int y)
  26604. {
  26605. if (! alreadyInside)
  26606. {
  26607. alreadyInside = true;
  26608. getTopLevelComponent()->toFront (true);
  26609. owner->dispatch (effEditMouse, x, y, 0, 0);
  26610. alreadyInside = false;
  26611. }
  26612. else
  26613. {
  26614. PostEvent (::mouseDown, 0);
  26615. }
  26616. }
  26617. void paint()
  26618. {
  26619. ComponentPeer* const peer = getPeer();
  26620. if (peer != 0)
  26621. {
  26622. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26623. ERect r;
  26624. r.left = pos.getX();
  26625. r.right = r.left + getWidth();
  26626. r.top = pos.getY();
  26627. r.bottom = r.top + getHeight();
  26628. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26629. }
  26630. }
  26631. private:
  26632. VSTPluginWindow* const owner;
  26633. bool alreadyInside;
  26634. };
  26635. friend class InnerWrapperComponent;
  26636. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26637. void resized()
  26638. {
  26639. innerWrapper->setSize (getWidth(), getHeight());
  26640. }
  26641. #endif
  26642. };
  26643. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26644. {
  26645. if (hasEditor())
  26646. return new VSTPluginWindow (*this);
  26647. return 0;
  26648. }
  26649. void VSTPluginInstance::handleAsyncUpdate()
  26650. {
  26651. // indicates that something about the plugin has changed..
  26652. updateHostDisplay();
  26653. }
  26654. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26655. {
  26656. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26657. {
  26658. changeProgramName (getCurrentProgram(), prog->prgName);
  26659. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26660. setParameter (i, vst_swapFloat (prog->params[i]));
  26661. return true;
  26662. }
  26663. return false;
  26664. }
  26665. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26666. const int dataSize)
  26667. {
  26668. if (dataSize < 28)
  26669. return false;
  26670. const fxSet* const set = (const fxSet*) data;
  26671. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26672. || vst_swap (set->version) > fxbVersionNum)
  26673. return false;
  26674. if (vst_swap (set->fxMagic) == 'FxBk')
  26675. {
  26676. // bank of programs
  26677. if (vst_swap (set->numPrograms) >= 0)
  26678. {
  26679. const int oldProg = getCurrentProgram();
  26680. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26681. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26682. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26683. {
  26684. if (i != oldProg)
  26685. {
  26686. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26687. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26688. return false;
  26689. if (vst_swap (set->numPrograms) > 0)
  26690. setCurrentProgram (i);
  26691. if (! restoreProgramSettings (prog))
  26692. return false;
  26693. }
  26694. }
  26695. if (vst_swap (set->numPrograms) > 0)
  26696. setCurrentProgram (oldProg);
  26697. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26698. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26699. return false;
  26700. if (! restoreProgramSettings (prog))
  26701. return false;
  26702. }
  26703. }
  26704. else if (vst_swap (set->fxMagic) == 'FxCk')
  26705. {
  26706. // single program
  26707. const fxProgram* const prog = (const fxProgram*) data;
  26708. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26709. return false;
  26710. changeProgramName (getCurrentProgram(), prog->prgName);
  26711. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26712. setParameter (i, vst_swapFloat (prog->params[i]));
  26713. }
  26714. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26715. {
  26716. // non-preset chunk
  26717. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26718. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26719. return false;
  26720. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26721. }
  26722. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26723. {
  26724. // preset chunk
  26725. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26726. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26727. return false;
  26728. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26729. changeProgramName (getCurrentProgram(), cset->name);
  26730. }
  26731. else
  26732. {
  26733. return false;
  26734. }
  26735. return true;
  26736. }
  26737. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26738. {
  26739. const int numParams = getNumParameters();
  26740. prog->chunkMagic = vst_swap ('CcnK');
  26741. prog->byteSize = 0;
  26742. prog->fxMagic = vst_swap ('FxCk');
  26743. prog->version = vst_swap (fxbVersionNum);
  26744. prog->fxID = vst_swap (getUID());
  26745. prog->fxVersion = vst_swap (getVersionNumber());
  26746. prog->numParams = vst_swap (numParams);
  26747. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26748. for (int i = 0; i < numParams; ++i)
  26749. prog->params[i] = vst_swapFloat (getParameter (i));
  26750. }
  26751. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26752. {
  26753. const int numPrograms = getNumPrograms();
  26754. const int numParams = getNumParameters();
  26755. if (usesChunks())
  26756. {
  26757. if (isFXB)
  26758. {
  26759. MemoryBlock chunk;
  26760. getChunkData (chunk, false, maxSizeMB);
  26761. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26762. dest.setSize (totalLen, true);
  26763. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26764. set->chunkMagic = vst_swap ('CcnK');
  26765. set->byteSize = 0;
  26766. set->fxMagic = vst_swap ('FBCh');
  26767. set->version = vst_swap (fxbVersionNum);
  26768. set->fxID = vst_swap (getUID());
  26769. set->fxVersion = vst_swap (getVersionNumber());
  26770. set->numPrograms = vst_swap (numPrograms);
  26771. set->chunkSize = vst_swap ((long) chunk.getSize());
  26772. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26773. }
  26774. else
  26775. {
  26776. MemoryBlock chunk;
  26777. getChunkData (chunk, true, maxSizeMB);
  26778. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26779. dest.setSize (totalLen, true);
  26780. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26781. set->chunkMagic = vst_swap ('CcnK');
  26782. set->byteSize = 0;
  26783. set->fxMagic = vst_swap ('FPCh');
  26784. set->version = vst_swap (fxbVersionNum);
  26785. set->fxID = vst_swap (getUID());
  26786. set->fxVersion = vst_swap (getVersionNumber());
  26787. set->numPrograms = vst_swap (numPrograms);
  26788. set->chunkSize = vst_swap ((long) chunk.getSize());
  26789. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26790. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26791. }
  26792. }
  26793. else
  26794. {
  26795. if (isFXB)
  26796. {
  26797. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26798. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26799. dest.setSize (len, true);
  26800. fxSet* const set = (fxSet*) dest.getData();
  26801. set->chunkMagic = vst_swap ('CcnK');
  26802. set->byteSize = 0;
  26803. set->fxMagic = vst_swap ('FxBk');
  26804. set->version = vst_swap (fxbVersionNum);
  26805. set->fxID = vst_swap (getUID());
  26806. set->fxVersion = vst_swap (getVersionNumber());
  26807. set->numPrograms = vst_swap (numPrograms);
  26808. const int oldProgram = getCurrentProgram();
  26809. MemoryBlock oldSettings;
  26810. createTempParameterStore (oldSettings);
  26811. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26812. for (int i = 0; i < numPrograms; ++i)
  26813. {
  26814. if (i != oldProgram)
  26815. {
  26816. setCurrentProgram (i);
  26817. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26818. }
  26819. }
  26820. setCurrentProgram (oldProgram);
  26821. restoreFromTempParameterStore (oldSettings);
  26822. }
  26823. else
  26824. {
  26825. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26826. dest.setSize (totalLen, true);
  26827. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26828. }
  26829. }
  26830. return true;
  26831. }
  26832. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26833. {
  26834. if (usesChunks())
  26835. {
  26836. void* data = 0;
  26837. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26838. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26839. {
  26840. mb.setSize (bytes);
  26841. mb.copyFrom (data, 0, bytes);
  26842. }
  26843. }
  26844. }
  26845. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26846. {
  26847. if (size > 0 && usesChunks())
  26848. {
  26849. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26850. if (! isPreset)
  26851. updateStoredProgramNames();
  26852. }
  26853. }
  26854. void VSTPluginInstance::timerCallback()
  26855. {
  26856. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26857. stopTimer();
  26858. }
  26859. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26860. {
  26861. const ScopedLock sl (lock);
  26862. ++insideVSTCallback;
  26863. int result = 0;
  26864. try
  26865. {
  26866. if (effect != 0)
  26867. {
  26868. #if JUCE_MAC
  26869. if (module->resFileId != 0)
  26870. UseResFile (module->resFileId);
  26871. CGrafPtr oldPort;
  26872. if (getActiveEditor() != 0)
  26873. {
  26874. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26875. GetPort (&oldPort);
  26876. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  26877. SetOrigin (-pos.getX(), -pos.getY());
  26878. }
  26879. #endif
  26880. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  26881. #if JUCE_MAC
  26882. if (getActiveEditor() != 0)
  26883. SetPort (oldPort);
  26884. module->resFileId = CurResFile();
  26885. #endif
  26886. --insideVSTCallback;
  26887. return result;
  26888. }
  26889. }
  26890. catch (...)
  26891. {
  26892. }
  26893. --insideVSTCallback;
  26894. return result;
  26895. }
  26896. // handles non plugin-specific callbacks..
  26897. static const int defaultVSTSampleRateValue = 16384;
  26898. static const int defaultVSTBlockSizeValue = 512;
  26899. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26900. {
  26901. (void) index;
  26902. (void) value;
  26903. (void) opt;
  26904. switch (opcode)
  26905. {
  26906. case audioMasterCanDo:
  26907. {
  26908. static const char* canDos[] = { "supplyIdle",
  26909. "sendVstEvents",
  26910. "sendVstMidiEvent",
  26911. "sendVstTimeInfo",
  26912. "receiveVstEvents",
  26913. "receiveVstMidiEvent",
  26914. "supportShell",
  26915. "shellCategory" };
  26916. for (int i = 0; i < numElementsInArray (canDos); ++i)
  26917. if (strcmp (canDos[i], (const char*) ptr) == 0)
  26918. return 1;
  26919. return 0;
  26920. }
  26921. case audioMasterVersion:
  26922. return 0x2400;
  26923. case audioMasterCurrentId:
  26924. return shellUIDToCreate;
  26925. case audioMasterGetNumAutomatableParameters:
  26926. return 0;
  26927. case audioMasterGetAutomationState:
  26928. return 1;
  26929. case audioMasterGetVendorVersion:
  26930. return 0x0101;
  26931. case audioMasterGetVendorString:
  26932. case audioMasterGetProductString:
  26933. {
  26934. String hostName ("Juce VST Host");
  26935. if (JUCEApplication::getInstance() != 0)
  26936. hostName = JUCEApplication::getInstance()->getApplicationName();
  26937. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  26938. }
  26939. break;
  26940. case audioMasterGetSampleRate:
  26941. return (VstIntPtr) defaultVSTSampleRateValue;
  26942. case audioMasterGetBlockSize:
  26943. return (VstIntPtr) defaultVSTBlockSizeValue;
  26944. case audioMasterSetOutputSampleRate:
  26945. return 0;
  26946. default:
  26947. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  26948. break;
  26949. }
  26950. return 0;
  26951. }
  26952. // handles callbacks for a specific plugin
  26953. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26954. {
  26955. switch (opcode)
  26956. {
  26957. case audioMasterAutomate:
  26958. sendParamChangeMessageToListeners (index, opt);
  26959. break;
  26960. case audioMasterProcessEvents:
  26961. handleMidiFromPlugin ((const VstEvents*) ptr);
  26962. break;
  26963. case audioMasterGetTime:
  26964. #ifdef _MSC_VER
  26965. #pragma warning (push)
  26966. #pragma warning (disable: 4311)
  26967. #endif
  26968. return (VstIntPtr) &vstHostTime;
  26969. #ifdef _MSC_VER
  26970. #pragma warning (pop)
  26971. #endif
  26972. break;
  26973. case audioMasterIdle:
  26974. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  26975. {
  26976. ++insideVSTCallback;
  26977. #if JUCE_MAC
  26978. if (getActiveEditor() != 0)
  26979. dispatch (effEditIdle, 0, 0, 0, 0);
  26980. #endif
  26981. juce_callAnyTimersSynchronously();
  26982. handleUpdateNowIfNeeded();
  26983. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  26984. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  26985. --insideVSTCallback;
  26986. }
  26987. break;
  26988. case audioMasterUpdateDisplay:
  26989. triggerAsyncUpdate();
  26990. break;
  26991. case audioMasterTempoAt:
  26992. // returns (10000 * bpm)
  26993. break;
  26994. case audioMasterNeedIdle:
  26995. startTimer (50);
  26996. break;
  26997. case audioMasterSizeWindow:
  26998. if (getActiveEditor() != 0)
  26999. getActiveEditor()->setSize (index, value);
  27000. return 1;
  27001. case audioMasterGetSampleRate:
  27002. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27003. case audioMasterGetBlockSize:
  27004. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27005. case audioMasterWantMidi:
  27006. wantsMidiMessages = true;
  27007. break;
  27008. case audioMasterGetDirectory:
  27009. #if JUCE_MAC
  27010. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27011. #else
  27012. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27013. #endif
  27014. case audioMasterGetAutomationState:
  27015. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27016. break;
  27017. // none of these are handled (yet)..
  27018. case audioMasterBeginEdit:
  27019. case audioMasterEndEdit:
  27020. case audioMasterSetTime:
  27021. case audioMasterPinConnected:
  27022. case audioMasterGetParameterQuantization:
  27023. case audioMasterIOChanged:
  27024. case audioMasterGetInputLatency:
  27025. case audioMasterGetOutputLatency:
  27026. case audioMasterGetPreviousPlug:
  27027. case audioMasterGetNextPlug:
  27028. case audioMasterWillReplaceOrAccumulate:
  27029. case audioMasterGetCurrentProcessLevel:
  27030. case audioMasterOfflineStart:
  27031. case audioMasterOfflineRead:
  27032. case audioMasterOfflineWrite:
  27033. case audioMasterOfflineGetCurrentPass:
  27034. case audioMasterOfflineGetCurrentMetaPass:
  27035. case audioMasterVendorSpecific:
  27036. case audioMasterSetIcon:
  27037. case audioMasterGetLanguage:
  27038. case audioMasterOpenWindow:
  27039. case audioMasterCloseWindow:
  27040. break;
  27041. default:
  27042. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27043. }
  27044. return 0;
  27045. }
  27046. // entry point for all callbacks from the plugin
  27047. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27048. {
  27049. try
  27050. {
  27051. if (effect != 0 && effect->resvd2 != 0)
  27052. {
  27053. return ((VSTPluginInstance*)(effect->resvd2))
  27054. ->handleCallback (opcode, index, value, ptr, opt);
  27055. }
  27056. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27057. }
  27058. catch (...)
  27059. {
  27060. return 0;
  27061. }
  27062. }
  27063. const String VSTPluginInstance::getVersion() const throw()
  27064. {
  27065. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27066. String s;
  27067. if (v == 0 || v == -1)
  27068. v = getVersionNumber();
  27069. if (v != 0)
  27070. {
  27071. int versionBits[4];
  27072. int n = 0;
  27073. while (v != 0)
  27074. {
  27075. versionBits [n++] = (v & 0xff);
  27076. v >>= 8;
  27077. }
  27078. s << 'V';
  27079. while (n > 0)
  27080. {
  27081. s << versionBits [--n];
  27082. if (n > 0)
  27083. s << '.';
  27084. }
  27085. }
  27086. return s;
  27087. }
  27088. int VSTPluginInstance::getUID() const throw()
  27089. {
  27090. int uid = effect != 0 ? effect->uniqueID : 0;
  27091. if (uid == 0)
  27092. uid = module->file.hashCode();
  27093. return uid;
  27094. }
  27095. const String VSTPluginInstance::getCategory() const throw()
  27096. {
  27097. const char* result = 0;
  27098. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27099. {
  27100. case kPlugCategEffect:
  27101. result = "Effect";
  27102. break;
  27103. case kPlugCategSynth:
  27104. result = "Synth";
  27105. break;
  27106. case kPlugCategAnalysis:
  27107. result = "Anaylsis";
  27108. break;
  27109. case kPlugCategMastering:
  27110. result = "Mastering";
  27111. break;
  27112. case kPlugCategSpacializer:
  27113. result = "Spacial";
  27114. break;
  27115. case kPlugCategRoomFx:
  27116. result = "Reverb";
  27117. break;
  27118. case kPlugSurroundFx:
  27119. result = "Surround";
  27120. break;
  27121. case kPlugCategRestoration:
  27122. result = "Restoration";
  27123. break;
  27124. case kPlugCategGenerator:
  27125. result = "Tone generation";
  27126. break;
  27127. default:
  27128. break;
  27129. }
  27130. return result;
  27131. }
  27132. float VSTPluginInstance::getParameter (int index)
  27133. {
  27134. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27135. {
  27136. try
  27137. {
  27138. const ScopedLock sl (lock);
  27139. return effect->getParameter (effect, index);
  27140. }
  27141. catch (...)
  27142. {
  27143. }
  27144. }
  27145. return 0.0f;
  27146. }
  27147. void VSTPluginInstance::setParameter (int index, float newValue)
  27148. {
  27149. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27150. {
  27151. try
  27152. {
  27153. const ScopedLock sl (lock);
  27154. if (effect->getParameter (effect, index) != newValue)
  27155. effect->setParameter (effect, index, newValue);
  27156. }
  27157. catch (...)
  27158. {
  27159. }
  27160. }
  27161. }
  27162. const String VSTPluginInstance::getParameterName (int index)
  27163. {
  27164. if (effect != 0)
  27165. {
  27166. jassert (index >= 0 && index < effect->numParams);
  27167. char nm [256];
  27168. zerostruct (nm);
  27169. dispatch (effGetParamName, index, 0, nm, 0);
  27170. return String (nm).trim();
  27171. }
  27172. return String::empty;
  27173. }
  27174. const String VSTPluginInstance::getParameterLabel (int index) const
  27175. {
  27176. if (effect != 0)
  27177. {
  27178. jassert (index >= 0 && index < effect->numParams);
  27179. char nm [256];
  27180. zerostruct (nm);
  27181. dispatch (effGetParamLabel, index, 0, nm, 0);
  27182. return String (nm).trim();
  27183. }
  27184. return String::empty;
  27185. }
  27186. const String VSTPluginInstance::getParameterText (int index)
  27187. {
  27188. if (effect != 0)
  27189. {
  27190. jassert (index >= 0 && index < effect->numParams);
  27191. char nm [256];
  27192. zerostruct (nm);
  27193. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27194. return String (nm).trim();
  27195. }
  27196. return String::empty;
  27197. }
  27198. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27199. {
  27200. if (effect != 0)
  27201. {
  27202. jassert (index >= 0 && index < effect->numParams);
  27203. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27204. }
  27205. return false;
  27206. }
  27207. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27208. {
  27209. dest.setSize (64 + 4 * getNumParameters());
  27210. dest.fillWith (0);
  27211. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27212. float* const p = (float*) (((char*) dest.getData()) + 64);
  27213. for (int i = 0; i < getNumParameters(); ++i)
  27214. p[i] = getParameter(i);
  27215. }
  27216. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27217. {
  27218. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27219. float* p = (float*) (((char*) m.getData()) + 64);
  27220. for (int i = 0; i < getNumParameters(); ++i)
  27221. setParameter (i, p[i]);
  27222. }
  27223. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27224. {
  27225. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27226. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27227. }
  27228. const String VSTPluginInstance::getProgramName (int index)
  27229. {
  27230. if (index == getCurrentProgram())
  27231. {
  27232. return getCurrentProgramName();
  27233. }
  27234. else if (effect != 0)
  27235. {
  27236. char nm [256];
  27237. zerostruct (nm);
  27238. if (dispatch (effGetProgramNameIndexed,
  27239. jlimit (0, getNumPrograms(), index),
  27240. -1, nm, 0) != 0)
  27241. {
  27242. return String (nm).trim();
  27243. }
  27244. }
  27245. return programNames [index];
  27246. }
  27247. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27248. {
  27249. if (index == getCurrentProgram())
  27250. {
  27251. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27252. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27253. }
  27254. else
  27255. {
  27256. jassertfalse // xxx not implemented!
  27257. }
  27258. }
  27259. void VSTPluginInstance::updateStoredProgramNames()
  27260. {
  27261. if (effect != 0 && getNumPrograms() > 0)
  27262. {
  27263. char nm [256];
  27264. zerostruct (nm);
  27265. // only do this if the plugin can't use indexed names..
  27266. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27267. {
  27268. const int oldProgram = getCurrentProgram();
  27269. MemoryBlock oldSettings;
  27270. createTempParameterStore (oldSettings);
  27271. for (int i = 0; i < getNumPrograms(); ++i)
  27272. {
  27273. setCurrentProgram (i);
  27274. getCurrentProgramName(); // (this updates the list)
  27275. }
  27276. setCurrentProgram (oldProgram);
  27277. restoreFromTempParameterStore (oldSettings);
  27278. }
  27279. }
  27280. }
  27281. const String VSTPluginInstance::getCurrentProgramName()
  27282. {
  27283. if (effect != 0)
  27284. {
  27285. char nm [256];
  27286. zerostruct (nm);
  27287. dispatch (effGetProgramName, 0, 0, nm, 0);
  27288. const int index = getCurrentProgram();
  27289. if (programNames[index].isEmpty())
  27290. {
  27291. while (programNames.size() < index)
  27292. programNames.add (String::empty);
  27293. programNames.set (index, String (nm).trim());
  27294. }
  27295. return String (nm).trim();
  27296. }
  27297. return String::empty;
  27298. }
  27299. const String VSTPluginInstance::getInputChannelName (const int index) const
  27300. {
  27301. if (index >= 0 && index < getNumInputChannels())
  27302. {
  27303. VstPinProperties pinProps;
  27304. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27305. return String (pinProps.label, sizeof (pinProps.label));
  27306. }
  27307. return String::empty;
  27308. }
  27309. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27310. {
  27311. if (index < 0 || index >= getNumInputChannels())
  27312. return false;
  27313. VstPinProperties pinProps;
  27314. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27315. return (pinProps.flags & kVstPinIsStereo) != 0;
  27316. return true;
  27317. }
  27318. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27319. {
  27320. if (index >= 0 && index < getNumOutputChannels())
  27321. {
  27322. VstPinProperties pinProps;
  27323. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27324. return String (pinProps.label, sizeof (pinProps.label));
  27325. }
  27326. return String::empty;
  27327. }
  27328. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27329. {
  27330. if (index < 0 || index >= getNumOutputChannels())
  27331. return false;
  27332. VstPinProperties pinProps;
  27333. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27334. return (pinProps.flags & kVstPinIsStereo) != 0;
  27335. return true;
  27336. }
  27337. void VSTPluginInstance::setPower (const bool on)
  27338. {
  27339. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27340. isPowerOn = on;
  27341. }
  27342. const int defaultMaxSizeMB = 64;
  27343. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27344. {
  27345. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27346. }
  27347. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27348. {
  27349. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27350. }
  27351. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27352. {
  27353. loadFromFXBFile (data, sizeInBytes);
  27354. }
  27355. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27356. {
  27357. loadFromFXBFile (data, sizeInBytes);
  27358. }
  27359. VSTPluginFormat::VSTPluginFormat()
  27360. {
  27361. }
  27362. VSTPluginFormat::~VSTPluginFormat()
  27363. {
  27364. }
  27365. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27366. const String& fileOrIdentifier)
  27367. {
  27368. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27369. return;
  27370. PluginDescription desc;
  27371. desc.fileOrIdentifier = fileOrIdentifier;
  27372. desc.uid = 0;
  27373. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27374. if (instance == 0)
  27375. return;
  27376. try
  27377. {
  27378. #if JUCE_MAC
  27379. if (instance->module->resFileId != 0)
  27380. UseResFile (instance->module->resFileId);
  27381. #endif
  27382. instance->fillInPluginDescription (desc);
  27383. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27384. if (category != kPlugCategShell)
  27385. {
  27386. // Normal plugin...
  27387. results.add (new PluginDescription (desc));
  27388. ++insideVSTCallback;
  27389. instance->dispatch (effOpen, 0, 0, 0, 0);
  27390. --insideVSTCallback;
  27391. }
  27392. else
  27393. {
  27394. // It's a shell plugin, so iterate all the subtypes...
  27395. char shellEffectName [64];
  27396. for (;;)
  27397. {
  27398. zerostruct (shellEffectName);
  27399. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27400. if (uid == 0)
  27401. {
  27402. break;
  27403. }
  27404. else
  27405. {
  27406. desc.uid = uid;
  27407. desc.name = shellEffectName;
  27408. bool alreadyThere = false;
  27409. for (int i = results.size(); --i >= 0;)
  27410. {
  27411. PluginDescription* const d = results.getUnchecked(i);
  27412. if (d->isDuplicateOf (desc))
  27413. {
  27414. alreadyThere = true;
  27415. break;
  27416. }
  27417. }
  27418. if (! alreadyThere)
  27419. results.add (new PluginDescription (desc));
  27420. }
  27421. }
  27422. }
  27423. }
  27424. catch (...)
  27425. {
  27426. // crashed while loading...
  27427. }
  27428. }
  27429. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27430. {
  27431. ScopedPointer <VSTPluginInstance> result;
  27432. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27433. {
  27434. File file (desc.fileOrIdentifier);
  27435. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27436. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27437. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27438. if (module != 0)
  27439. {
  27440. shellUIDToCreate = desc.uid;
  27441. result = new VSTPluginInstance (module);
  27442. if (result->effect != 0)
  27443. {
  27444. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27445. result->initialise();
  27446. }
  27447. else
  27448. {
  27449. result = 0;
  27450. }
  27451. }
  27452. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27453. }
  27454. return result.release();
  27455. }
  27456. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27457. {
  27458. const File f (fileOrIdentifier);
  27459. #if JUCE_MAC
  27460. if (f.isDirectory() && f.hasFileExtension (".vst"))
  27461. return true;
  27462. #if JUCE_PPC
  27463. FSRef fileRef;
  27464. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27465. {
  27466. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27467. if (resFileId != -1)
  27468. {
  27469. const int numEffects = Count1Resources ('aEff');
  27470. CloseResFile (resFileId);
  27471. if (numEffects > 0)
  27472. return true;
  27473. }
  27474. }
  27475. #endif
  27476. return false;
  27477. #elif JUCE_WIN32
  27478. return f.existsAsFile()
  27479. && f.hasFileExtension (".dll");
  27480. #elif JUCE_LINUX
  27481. return f.existsAsFile()
  27482. && f.hasFileExtension (".so");
  27483. #endif
  27484. }
  27485. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27486. {
  27487. return fileOrIdentifier;
  27488. }
  27489. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27490. {
  27491. return File (desc.fileOrIdentifier).exists();
  27492. }
  27493. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27494. {
  27495. StringArray results;
  27496. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27497. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27498. return results;
  27499. }
  27500. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27501. {
  27502. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27503. // .component or .vst directories.
  27504. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27505. while (iter.next())
  27506. {
  27507. const File f (iter.getFile());
  27508. bool isPlugin = false;
  27509. if (fileMightContainThisPluginType (f.getFullPathName()))
  27510. {
  27511. isPlugin = true;
  27512. results.add (f.getFullPathName());
  27513. }
  27514. if (recursive && (! isPlugin) && f.isDirectory())
  27515. recursiveFileSearch (results, f, true);
  27516. }
  27517. }
  27518. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27519. {
  27520. #if JUCE_MAC
  27521. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27522. #elif JUCE_WIN32
  27523. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27524. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27525. #elif JUCE_LINUX
  27526. return FileSearchPath ("/usr/lib/vst");
  27527. #endif
  27528. }
  27529. END_JUCE_NAMESPACE
  27530. #endif
  27531. #undef log
  27532. #endif
  27533. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27534. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27535. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27536. BEGIN_JUCE_NAMESPACE
  27537. AudioProcessor::AudioProcessor()
  27538. : playHead (0),
  27539. activeEditor (0),
  27540. sampleRate (0),
  27541. blockSize (0),
  27542. numInputChannels (0),
  27543. numOutputChannels (0),
  27544. latencySamples (0),
  27545. suspended (false),
  27546. nonRealtime (false)
  27547. {
  27548. }
  27549. AudioProcessor::~AudioProcessor()
  27550. {
  27551. // ooh, nasty - the editor should have been deleted before the filter
  27552. // that it refers to is deleted..
  27553. jassert (activeEditor == 0);
  27554. #ifdef JUCE_DEBUG
  27555. // This will fail if you've called beginParameterChangeGesture() for one
  27556. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27557. jassert (changingParams.countNumberOfSetBits() == 0);
  27558. #endif
  27559. }
  27560. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27561. {
  27562. playHead = newPlayHead;
  27563. }
  27564. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27565. {
  27566. const ScopedLock sl (listenerLock);
  27567. listeners.addIfNotAlreadyThere (newListener);
  27568. }
  27569. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27570. {
  27571. const ScopedLock sl (listenerLock);
  27572. listeners.removeValue (listenerToRemove);
  27573. }
  27574. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27575. const int numOuts,
  27576. const double sampleRate_,
  27577. const int blockSize_) throw()
  27578. {
  27579. numInputChannels = numIns;
  27580. numOutputChannels = numOuts;
  27581. sampleRate = sampleRate_;
  27582. blockSize = blockSize_;
  27583. }
  27584. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27585. {
  27586. nonRealtime = nonRealtime_;
  27587. }
  27588. void AudioProcessor::setLatencySamples (const int newLatency)
  27589. {
  27590. if (latencySamples != newLatency)
  27591. {
  27592. latencySamples = newLatency;
  27593. updateHostDisplay();
  27594. }
  27595. }
  27596. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27597. const float newValue)
  27598. {
  27599. setParameter (parameterIndex, newValue);
  27600. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27601. }
  27602. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27603. {
  27604. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27605. for (int i = listeners.size(); --i >= 0;)
  27606. {
  27607. AudioProcessorListener* l;
  27608. {
  27609. const ScopedLock sl (listenerLock);
  27610. l = (AudioProcessorListener*) listeners [i];
  27611. }
  27612. if (l != 0)
  27613. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27614. }
  27615. }
  27616. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27617. {
  27618. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27619. #ifdef JUCE_DEBUG
  27620. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27621. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27622. jassert (! changingParams [parameterIndex]);
  27623. changingParams.setBit (parameterIndex);
  27624. #endif
  27625. for (int i = listeners.size(); --i >= 0;)
  27626. {
  27627. AudioProcessorListener* l;
  27628. {
  27629. const ScopedLock sl (listenerLock);
  27630. l = (AudioProcessorListener*) listeners [i];
  27631. }
  27632. if (l != 0)
  27633. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27634. }
  27635. }
  27636. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27637. {
  27638. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27639. #ifdef JUCE_DEBUG
  27640. // This means you've called endParameterChangeGesture without having previously called
  27641. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27642. // calls matched correctly.
  27643. jassert (changingParams [parameterIndex]);
  27644. changingParams.clearBit (parameterIndex);
  27645. #endif
  27646. for (int i = listeners.size(); --i >= 0;)
  27647. {
  27648. AudioProcessorListener* l;
  27649. {
  27650. const ScopedLock sl (listenerLock);
  27651. l = (AudioProcessorListener*) listeners [i];
  27652. }
  27653. if (l != 0)
  27654. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27655. }
  27656. }
  27657. void AudioProcessor::updateHostDisplay()
  27658. {
  27659. for (int i = listeners.size(); --i >= 0;)
  27660. {
  27661. AudioProcessorListener* l;
  27662. {
  27663. const ScopedLock sl (listenerLock);
  27664. l = (AudioProcessorListener*) listeners [i];
  27665. }
  27666. if (l != 0)
  27667. l->audioProcessorChanged (this);
  27668. }
  27669. }
  27670. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27671. {
  27672. return true;
  27673. }
  27674. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27675. {
  27676. return false;
  27677. }
  27678. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27679. {
  27680. const ScopedLock sl (callbackLock);
  27681. suspended = shouldBeSuspended;
  27682. }
  27683. void AudioProcessor::reset()
  27684. {
  27685. }
  27686. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27687. {
  27688. const ScopedLock sl (callbackLock);
  27689. jassert (activeEditor == editor);
  27690. if (activeEditor == editor)
  27691. activeEditor = 0;
  27692. }
  27693. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27694. {
  27695. if (activeEditor != 0)
  27696. return activeEditor;
  27697. AudioProcessorEditor* const ed = createEditor();
  27698. if (ed != 0)
  27699. {
  27700. // you must give your editor comp a size before returning it..
  27701. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27702. const ScopedLock sl (callbackLock);
  27703. activeEditor = ed;
  27704. }
  27705. return ed;
  27706. }
  27707. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27708. {
  27709. getStateInformation (destData);
  27710. }
  27711. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27712. {
  27713. setStateInformation (data, sizeInBytes);
  27714. }
  27715. // magic number to identify memory blocks that we've stored as XML
  27716. const uint32 magicXmlNumber = 0x21324356;
  27717. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27718. JUCE_NAMESPACE::MemoryBlock& destData)
  27719. {
  27720. const String xmlString (xml.createDocument (String::empty, true, false));
  27721. const int stringLength = xmlString.getNumBytesAsUTF8();
  27722. destData.setSize (stringLength + 10);
  27723. char* const d = (char*) destData.getData();
  27724. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27725. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27726. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27727. }
  27728. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27729. const int sizeInBytes)
  27730. {
  27731. if (sizeInBytes > 8
  27732. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27733. {
  27734. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27735. if (stringLength > 0)
  27736. {
  27737. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27738. jmin ((sizeInBytes - 8), stringLength)));
  27739. return doc.getDocumentElement();
  27740. }
  27741. }
  27742. return 0;
  27743. }
  27744. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27745. {
  27746. }
  27747. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27748. {
  27749. }
  27750. bool AudioPlayHead::CurrentPositionInfo::operator== (const CurrentPositionInfo& other) const throw()
  27751. {
  27752. return timeInSeconds == other.timeInSeconds
  27753. && ppqPosition == other.ppqPosition
  27754. && editOriginTime == other.editOriginTime
  27755. && ppqPositionOfLastBarStart == other.ppqPositionOfLastBarStart
  27756. && frameRate == other.frameRate
  27757. && isPlaying == other.isPlaying
  27758. && isRecording == other.isRecording
  27759. && bpm == other.bpm
  27760. && timeSigNumerator == other.timeSigNumerator
  27761. && timeSigDenominator == other.timeSigDenominator;
  27762. }
  27763. bool AudioPlayHead::CurrentPositionInfo::operator!= (const CurrentPositionInfo& other) const throw()
  27764. {
  27765. return ! operator== (other);
  27766. }
  27767. void AudioPlayHead::CurrentPositionInfo::resetToDefault()
  27768. {
  27769. zerostruct (*this);
  27770. timeSigNumerator = 4;
  27771. timeSigDenominator = 4;
  27772. bpm = 120;
  27773. }
  27774. END_JUCE_NAMESPACE
  27775. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27776. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27777. BEGIN_JUCE_NAMESPACE
  27778. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27779. : owner (owner_)
  27780. {
  27781. // the filter must be valid..
  27782. jassert (owner != 0);
  27783. }
  27784. AudioProcessorEditor::~AudioProcessorEditor()
  27785. {
  27786. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27787. // filter for some reason..
  27788. jassert (owner->getActiveEditor() != this);
  27789. }
  27790. END_JUCE_NAMESPACE
  27791. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27792. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27793. BEGIN_JUCE_NAMESPACE
  27794. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27795. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27796. : id (id_),
  27797. processor (processor_),
  27798. isPrepared (false)
  27799. {
  27800. jassert (processor_ != 0);
  27801. }
  27802. AudioProcessorGraph::Node::~Node()
  27803. {
  27804. delete processor;
  27805. }
  27806. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27807. AudioProcessorGraph* const graph)
  27808. {
  27809. if (! isPrepared)
  27810. {
  27811. isPrepared = true;
  27812. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27813. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27814. if (ioProc != 0)
  27815. ioProc->setParentGraph (graph);
  27816. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27817. processor->getNumOutputChannels(),
  27818. sampleRate, blockSize);
  27819. processor->prepareToPlay (sampleRate, blockSize);
  27820. }
  27821. }
  27822. void AudioProcessorGraph::Node::unprepare()
  27823. {
  27824. if (isPrepared)
  27825. {
  27826. isPrepared = false;
  27827. processor->releaseResources();
  27828. }
  27829. }
  27830. AudioProcessorGraph::AudioProcessorGraph()
  27831. : lastNodeId (0),
  27832. renderingBuffers (1, 1),
  27833. currentAudioOutputBuffer (1, 1)
  27834. {
  27835. }
  27836. AudioProcessorGraph::~AudioProcessorGraph()
  27837. {
  27838. clearRenderingSequence();
  27839. clear();
  27840. }
  27841. const String AudioProcessorGraph::getName() const
  27842. {
  27843. return "Audio Graph";
  27844. }
  27845. void AudioProcessorGraph::clear()
  27846. {
  27847. nodes.clear();
  27848. connections.clear();
  27849. triggerAsyncUpdate();
  27850. }
  27851. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27852. {
  27853. for (int i = nodes.size(); --i >= 0;)
  27854. if (nodes.getUnchecked(i)->id == nodeId)
  27855. return nodes.getUnchecked(i);
  27856. return 0;
  27857. }
  27858. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27859. uint32 nodeId)
  27860. {
  27861. if (newProcessor == 0)
  27862. {
  27863. jassertfalse
  27864. return 0;
  27865. }
  27866. if (nodeId == 0)
  27867. {
  27868. nodeId = ++lastNodeId;
  27869. }
  27870. else
  27871. {
  27872. // you can't add a node with an id that already exists in the graph..
  27873. jassert (getNodeForId (nodeId) == 0);
  27874. removeNode (nodeId);
  27875. }
  27876. lastNodeId = nodeId;
  27877. Node* const n = new Node (nodeId, newProcessor);
  27878. nodes.add (n);
  27879. triggerAsyncUpdate();
  27880. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27881. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27882. if (ioProc != 0)
  27883. ioProc->setParentGraph (this);
  27884. return n;
  27885. }
  27886. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27887. {
  27888. disconnectNode (nodeId);
  27889. for (int i = nodes.size(); --i >= 0;)
  27890. {
  27891. if (nodes.getUnchecked(i)->id == nodeId)
  27892. {
  27893. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27894. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27895. if (ioProc != 0)
  27896. ioProc->setParentGraph (0);
  27897. nodes.remove (i);
  27898. triggerAsyncUpdate();
  27899. return true;
  27900. }
  27901. }
  27902. return false;
  27903. }
  27904. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  27905. const int sourceChannelIndex,
  27906. const uint32 destNodeId,
  27907. const int destChannelIndex) const
  27908. {
  27909. for (int i = connections.size(); --i >= 0;)
  27910. {
  27911. const Connection* const c = connections.getUnchecked(i);
  27912. if (c->sourceNodeId == sourceNodeId
  27913. && c->destNodeId == destNodeId
  27914. && c->sourceChannelIndex == sourceChannelIndex
  27915. && c->destChannelIndex == destChannelIndex)
  27916. {
  27917. return c;
  27918. }
  27919. }
  27920. return 0;
  27921. }
  27922. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  27923. const uint32 possibleDestNodeId) const
  27924. {
  27925. for (int i = connections.size(); --i >= 0;)
  27926. {
  27927. const Connection* const c = connections.getUnchecked(i);
  27928. if (c->sourceNodeId == possibleSourceNodeId
  27929. && c->destNodeId == possibleDestNodeId)
  27930. {
  27931. return true;
  27932. }
  27933. }
  27934. return false;
  27935. }
  27936. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  27937. const int sourceChannelIndex,
  27938. const uint32 destNodeId,
  27939. const int destChannelIndex) const
  27940. {
  27941. if (sourceChannelIndex < 0
  27942. || destChannelIndex < 0
  27943. || sourceNodeId == destNodeId
  27944. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  27945. return false;
  27946. const Node* const source = getNodeForId (sourceNodeId);
  27947. if (source == 0
  27948. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  27949. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  27950. return false;
  27951. const Node* const dest = getNodeForId (destNodeId);
  27952. if (dest == 0
  27953. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  27954. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  27955. return false;
  27956. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  27957. destNodeId, destChannelIndex) == 0;
  27958. }
  27959. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  27960. const int sourceChannelIndex,
  27961. const uint32 destNodeId,
  27962. const int destChannelIndex)
  27963. {
  27964. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  27965. return false;
  27966. Connection* const c = new Connection();
  27967. c->sourceNodeId = sourceNodeId;
  27968. c->sourceChannelIndex = sourceChannelIndex;
  27969. c->destNodeId = destNodeId;
  27970. c->destChannelIndex = destChannelIndex;
  27971. connections.add (c);
  27972. triggerAsyncUpdate();
  27973. return true;
  27974. }
  27975. void AudioProcessorGraph::removeConnection (const int index)
  27976. {
  27977. connections.remove (index);
  27978. triggerAsyncUpdate();
  27979. }
  27980. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  27981. const uint32 destNodeId, const int destChannelIndex)
  27982. {
  27983. bool doneAnything = false;
  27984. for (int i = connections.size(); --i >= 0;)
  27985. {
  27986. const Connection* const c = connections.getUnchecked(i);
  27987. if (c->sourceNodeId == sourceNodeId
  27988. && c->destNodeId == destNodeId
  27989. && c->sourceChannelIndex == sourceChannelIndex
  27990. && c->destChannelIndex == destChannelIndex)
  27991. {
  27992. removeConnection (i);
  27993. doneAnything = true;
  27994. triggerAsyncUpdate();
  27995. }
  27996. }
  27997. return doneAnything;
  27998. }
  27999. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28000. {
  28001. bool doneAnything = false;
  28002. for (int i = connections.size(); --i >= 0;)
  28003. {
  28004. const Connection* const c = connections.getUnchecked(i);
  28005. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28006. {
  28007. removeConnection (i);
  28008. doneAnything = true;
  28009. triggerAsyncUpdate();
  28010. }
  28011. }
  28012. return doneAnything;
  28013. }
  28014. bool AudioProcessorGraph::removeIllegalConnections()
  28015. {
  28016. bool doneAnything = false;
  28017. for (int i = connections.size(); --i >= 0;)
  28018. {
  28019. const Connection* const c = connections.getUnchecked(i);
  28020. const Node* const source = getNodeForId (c->sourceNodeId);
  28021. const Node* const dest = getNodeForId (c->destNodeId);
  28022. if (source == 0 || dest == 0
  28023. || (c->sourceChannelIndex != midiChannelIndex
  28024. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28025. || (c->sourceChannelIndex == midiChannelIndex
  28026. && ! source->processor->producesMidi())
  28027. || (c->destChannelIndex != midiChannelIndex
  28028. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28029. || (c->destChannelIndex == midiChannelIndex
  28030. && ! dest->processor->acceptsMidi()))
  28031. {
  28032. removeConnection (i);
  28033. doneAnything = true;
  28034. triggerAsyncUpdate();
  28035. }
  28036. }
  28037. return doneAnything;
  28038. }
  28039. namespace GraphRenderingOps
  28040. {
  28041. class AudioGraphRenderingOp
  28042. {
  28043. public:
  28044. AudioGraphRenderingOp() {}
  28045. virtual ~AudioGraphRenderingOp() {}
  28046. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28047. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28048. const int numSamples) = 0;
  28049. juce_UseDebuggingNewOperator
  28050. };
  28051. class ClearChannelOp : public AudioGraphRenderingOp
  28052. {
  28053. public:
  28054. ClearChannelOp (const int channelNum_)
  28055. : channelNum (channelNum_)
  28056. {}
  28057. ~ClearChannelOp() {}
  28058. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28059. {
  28060. sharedBufferChans.clear (channelNum, 0, numSamples);
  28061. }
  28062. private:
  28063. const int channelNum;
  28064. ClearChannelOp (const ClearChannelOp&);
  28065. ClearChannelOp& operator= (const ClearChannelOp&);
  28066. };
  28067. class CopyChannelOp : public AudioGraphRenderingOp
  28068. {
  28069. public:
  28070. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28071. : srcChannelNum (srcChannelNum_),
  28072. dstChannelNum (dstChannelNum_)
  28073. {}
  28074. ~CopyChannelOp() {}
  28075. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28076. {
  28077. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28078. }
  28079. private:
  28080. const int srcChannelNum, dstChannelNum;
  28081. CopyChannelOp (const CopyChannelOp&);
  28082. CopyChannelOp& operator= (const CopyChannelOp&);
  28083. };
  28084. class AddChannelOp : public AudioGraphRenderingOp
  28085. {
  28086. public:
  28087. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28088. : srcChannelNum (srcChannelNum_),
  28089. dstChannelNum (dstChannelNum_)
  28090. {}
  28091. ~AddChannelOp() {}
  28092. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28093. {
  28094. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28095. }
  28096. private:
  28097. const int srcChannelNum, dstChannelNum;
  28098. AddChannelOp (const AddChannelOp&);
  28099. AddChannelOp& operator= (const AddChannelOp&);
  28100. };
  28101. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28102. {
  28103. public:
  28104. ClearMidiBufferOp (const int bufferNum_)
  28105. : bufferNum (bufferNum_)
  28106. {}
  28107. ~ClearMidiBufferOp() {}
  28108. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28109. {
  28110. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28111. }
  28112. private:
  28113. const int bufferNum;
  28114. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28115. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28116. };
  28117. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28118. {
  28119. public:
  28120. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28121. : srcBufferNum (srcBufferNum_),
  28122. dstBufferNum (dstBufferNum_)
  28123. {}
  28124. ~CopyMidiBufferOp() {}
  28125. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28126. {
  28127. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28128. }
  28129. private:
  28130. const int srcBufferNum, dstBufferNum;
  28131. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28132. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28133. };
  28134. class AddMidiBufferOp : public AudioGraphRenderingOp
  28135. {
  28136. public:
  28137. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28138. : srcBufferNum (srcBufferNum_),
  28139. dstBufferNum (dstBufferNum_)
  28140. {}
  28141. ~AddMidiBufferOp() {}
  28142. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28143. {
  28144. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28145. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28146. }
  28147. private:
  28148. const int srcBufferNum, dstBufferNum;
  28149. AddMidiBufferOp (const AddMidiBufferOp&);
  28150. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28151. };
  28152. class ProcessBufferOp : public AudioGraphRenderingOp
  28153. {
  28154. public:
  28155. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28156. const Array <int>& audioChannelsToUse_,
  28157. const int totalChans_,
  28158. const int midiBufferToUse_)
  28159. : node (node_),
  28160. processor (node_->processor),
  28161. audioChannelsToUse (audioChannelsToUse_),
  28162. totalChans (jmax (1, totalChans_)),
  28163. midiBufferToUse (midiBufferToUse_)
  28164. {
  28165. channels.calloc (totalChans);
  28166. while (audioChannelsToUse.size() < totalChans)
  28167. audioChannelsToUse.add (0);
  28168. }
  28169. ~ProcessBufferOp()
  28170. {
  28171. }
  28172. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28173. {
  28174. for (int i = totalChans; --i >= 0;)
  28175. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28176. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28177. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28178. }
  28179. const AudioProcessorGraph::Node::Ptr node;
  28180. AudioProcessor* const processor;
  28181. private:
  28182. Array <int> audioChannelsToUse;
  28183. HeapBlock <float*> channels;
  28184. int totalChans;
  28185. int midiBufferToUse;
  28186. ProcessBufferOp (const ProcessBufferOp&);
  28187. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28188. };
  28189. class RenderingOpSequenceCalculator
  28190. {
  28191. public:
  28192. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28193. const VoidArray& orderedNodes_,
  28194. VoidArray& renderingOps)
  28195. : graph (graph_),
  28196. orderedNodes (orderedNodes_)
  28197. {
  28198. nodeIds.add (-2); // first buffer is read-only zeros
  28199. channels.add (0);
  28200. midiNodeIds.add (-2);
  28201. for (int i = 0; i < orderedNodes.size(); ++i)
  28202. {
  28203. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28204. renderingOps, i);
  28205. markAnyUnusedBuffersAsFree (i);
  28206. }
  28207. }
  28208. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28209. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28210. juce_UseDebuggingNewOperator
  28211. private:
  28212. AudioProcessorGraph& graph;
  28213. const VoidArray& orderedNodes;
  28214. Array <int> nodeIds, channels, midiNodeIds;
  28215. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28216. VoidArray& renderingOps,
  28217. const int ourRenderingIndex)
  28218. {
  28219. const int numIns = node->processor->getNumInputChannels();
  28220. const int numOuts = node->processor->getNumOutputChannels();
  28221. const int totalChans = jmax (numIns, numOuts);
  28222. Array <int> audioChannelsToUse;
  28223. int midiBufferToUse = -1;
  28224. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28225. {
  28226. // get a list of all the inputs to this node
  28227. Array <int> sourceNodes, sourceOutputChans;
  28228. for (int i = graph.getNumConnections(); --i >= 0;)
  28229. {
  28230. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28231. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28232. {
  28233. sourceNodes.add (c->sourceNodeId);
  28234. sourceOutputChans.add (c->sourceChannelIndex);
  28235. }
  28236. }
  28237. int bufIndex = -1;
  28238. if (sourceNodes.size() == 0)
  28239. {
  28240. // unconnected input channel
  28241. if (inputChan >= numOuts)
  28242. {
  28243. bufIndex = getReadOnlyEmptyBuffer();
  28244. jassert (bufIndex >= 0);
  28245. }
  28246. else
  28247. {
  28248. bufIndex = getFreeBuffer (false);
  28249. renderingOps.add (new ClearChannelOp (bufIndex));
  28250. }
  28251. }
  28252. else if (sourceNodes.size() == 1)
  28253. {
  28254. // channel with a straightforward single input..
  28255. const int srcNode = sourceNodes.getUnchecked(0);
  28256. const int srcChan = sourceOutputChans.getUnchecked(0);
  28257. bufIndex = getBufferContaining (srcNode, srcChan);
  28258. if (bufIndex < 0)
  28259. {
  28260. // if not found, this is probably a feedback loop
  28261. bufIndex = getReadOnlyEmptyBuffer();
  28262. jassert (bufIndex >= 0);
  28263. }
  28264. if (inputChan < numOuts
  28265. && isBufferNeededLater (ourRenderingIndex,
  28266. inputChan,
  28267. srcNode, srcChan))
  28268. {
  28269. // can't mess up this channel because it's needed later by another node, so we
  28270. // need to use a copy of it..
  28271. const int newFreeBuffer = getFreeBuffer (false);
  28272. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28273. bufIndex = newFreeBuffer;
  28274. }
  28275. }
  28276. else
  28277. {
  28278. // channel with a mix of several inputs..
  28279. // try to find a re-usable channel from our inputs..
  28280. int reusableInputIndex = -1;
  28281. for (int i = 0; i < sourceNodes.size(); ++i)
  28282. {
  28283. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28284. sourceOutputChans.getUnchecked(i));
  28285. if (sourceBufIndex >= 0
  28286. && ! isBufferNeededLater (ourRenderingIndex,
  28287. inputChan,
  28288. sourceNodes.getUnchecked(i),
  28289. sourceOutputChans.getUnchecked(i)))
  28290. {
  28291. // we've found one of our input chans that can be re-used..
  28292. reusableInputIndex = i;
  28293. bufIndex = sourceBufIndex;
  28294. break;
  28295. }
  28296. }
  28297. if (reusableInputIndex < 0)
  28298. {
  28299. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28300. bufIndex = getFreeBuffer (false);
  28301. jassert (bufIndex != 0);
  28302. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28303. sourceOutputChans.getUnchecked (0));
  28304. if (srcIndex < 0)
  28305. {
  28306. // if not found, this is probably a feedback loop
  28307. renderingOps.add (new ClearChannelOp (bufIndex));
  28308. }
  28309. else
  28310. {
  28311. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28312. }
  28313. reusableInputIndex = 0;
  28314. }
  28315. for (int j = 0; j < sourceNodes.size(); ++j)
  28316. {
  28317. if (j != reusableInputIndex)
  28318. {
  28319. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28320. sourceOutputChans.getUnchecked(j));
  28321. if (srcIndex >= 0)
  28322. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28323. }
  28324. }
  28325. }
  28326. jassert (bufIndex >= 0);
  28327. audioChannelsToUse.add (bufIndex);
  28328. if (inputChan < numOuts)
  28329. markBufferAsContaining (bufIndex, node->id, inputChan);
  28330. }
  28331. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28332. {
  28333. const int bufIndex = getFreeBuffer (false);
  28334. jassert (bufIndex != 0);
  28335. audioChannelsToUse.add (bufIndex);
  28336. markBufferAsContaining (bufIndex, node->id, outputChan);
  28337. }
  28338. // Now the same thing for midi..
  28339. Array <int> midiSourceNodes;
  28340. for (int i = graph.getNumConnections(); --i >= 0;)
  28341. {
  28342. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28343. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28344. midiSourceNodes.add (c->sourceNodeId);
  28345. }
  28346. if (midiSourceNodes.size() == 0)
  28347. {
  28348. // No midi inputs..
  28349. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28350. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28351. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28352. }
  28353. else if (midiSourceNodes.size() == 1)
  28354. {
  28355. // One midi input..
  28356. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28357. AudioProcessorGraph::midiChannelIndex);
  28358. if (midiBufferToUse >= 0)
  28359. {
  28360. if (isBufferNeededLater (ourRenderingIndex,
  28361. AudioProcessorGraph::midiChannelIndex,
  28362. midiSourceNodes.getUnchecked(0),
  28363. AudioProcessorGraph::midiChannelIndex))
  28364. {
  28365. // can't mess up this channel because it's needed later by another node, so we
  28366. // need to use a copy of it..
  28367. const int newFreeBuffer = getFreeBuffer (true);
  28368. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28369. midiBufferToUse = newFreeBuffer;
  28370. }
  28371. }
  28372. else
  28373. {
  28374. // probably a feedback loop, so just use an empty one..
  28375. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28376. }
  28377. }
  28378. else
  28379. {
  28380. // More than one midi input being mixed..
  28381. int reusableInputIndex = -1;
  28382. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28383. {
  28384. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28385. AudioProcessorGraph::midiChannelIndex);
  28386. if (sourceBufIndex >= 0
  28387. && ! isBufferNeededLater (ourRenderingIndex,
  28388. AudioProcessorGraph::midiChannelIndex,
  28389. midiSourceNodes.getUnchecked(i),
  28390. AudioProcessorGraph::midiChannelIndex))
  28391. {
  28392. // we've found one of our input buffers that can be re-used..
  28393. reusableInputIndex = i;
  28394. midiBufferToUse = sourceBufIndex;
  28395. break;
  28396. }
  28397. }
  28398. if (reusableInputIndex < 0)
  28399. {
  28400. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28401. midiBufferToUse = getFreeBuffer (true);
  28402. jassert (midiBufferToUse >= 0);
  28403. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28404. AudioProcessorGraph::midiChannelIndex);
  28405. if (srcIndex >= 0)
  28406. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28407. else
  28408. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28409. reusableInputIndex = 0;
  28410. }
  28411. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28412. {
  28413. if (j != reusableInputIndex)
  28414. {
  28415. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28416. AudioProcessorGraph::midiChannelIndex);
  28417. if (srcIndex >= 0)
  28418. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28419. }
  28420. }
  28421. }
  28422. if (node->processor->producesMidi())
  28423. markBufferAsContaining (midiBufferToUse, node->id,
  28424. AudioProcessorGraph::midiChannelIndex);
  28425. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28426. totalChans, midiBufferToUse));
  28427. }
  28428. int getFreeBuffer (const bool forMidi)
  28429. {
  28430. if (forMidi)
  28431. {
  28432. for (int i = 1; i < midiNodeIds.size(); ++i)
  28433. if (midiNodeIds.getUnchecked(i) < 0)
  28434. return i;
  28435. midiNodeIds.add (-1);
  28436. return midiNodeIds.size() - 1;
  28437. }
  28438. else
  28439. {
  28440. for (int i = 1; i < nodeIds.size(); ++i)
  28441. if (nodeIds.getUnchecked(i) < 0)
  28442. return i;
  28443. nodeIds.add (-1);
  28444. channels.add (0);
  28445. return nodeIds.size() - 1;
  28446. }
  28447. }
  28448. int getReadOnlyEmptyBuffer() const
  28449. {
  28450. return 0;
  28451. }
  28452. int getBufferContaining (const int nodeId, const int outputChannel) const
  28453. {
  28454. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28455. {
  28456. for (int i = midiNodeIds.size(); --i >= 0;)
  28457. if (midiNodeIds.getUnchecked(i) == nodeId)
  28458. return i;
  28459. }
  28460. else
  28461. {
  28462. for (int i = nodeIds.size(); --i >= 0;)
  28463. if (nodeIds.getUnchecked(i) == nodeId
  28464. && channels.getUnchecked(i) == outputChannel)
  28465. return i;
  28466. }
  28467. return -1;
  28468. }
  28469. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28470. {
  28471. int i;
  28472. for (i = 0; i < nodeIds.size(); ++i)
  28473. {
  28474. if (nodeIds.getUnchecked(i) >= 0
  28475. && ! isBufferNeededLater (stepIndex, -1,
  28476. nodeIds.getUnchecked(i),
  28477. channels.getUnchecked(i)))
  28478. {
  28479. nodeIds.set (i, -1);
  28480. }
  28481. }
  28482. for (i = 0; i < midiNodeIds.size(); ++i)
  28483. {
  28484. if (midiNodeIds.getUnchecked(i) >= 0
  28485. && ! isBufferNeededLater (stepIndex, -1,
  28486. midiNodeIds.getUnchecked(i),
  28487. AudioProcessorGraph::midiChannelIndex))
  28488. {
  28489. midiNodeIds.set (i, -1);
  28490. }
  28491. }
  28492. }
  28493. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28494. int inputChannelOfIndexToIgnore,
  28495. const int nodeId,
  28496. const int outputChanIndex) const
  28497. {
  28498. while (stepIndexToSearchFrom < orderedNodes.size())
  28499. {
  28500. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28501. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28502. {
  28503. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28504. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28505. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28506. return true;
  28507. }
  28508. else
  28509. {
  28510. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28511. if (i != inputChannelOfIndexToIgnore
  28512. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28513. node->id, i) != 0)
  28514. return true;
  28515. }
  28516. inputChannelOfIndexToIgnore = -1;
  28517. ++stepIndexToSearchFrom;
  28518. }
  28519. return false;
  28520. }
  28521. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28522. {
  28523. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28524. {
  28525. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28526. midiNodeIds.set (bufferNum, nodeId);
  28527. }
  28528. else
  28529. {
  28530. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28531. nodeIds.set (bufferNum, nodeId);
  28532. channels.set (bufferNum, outputIndex);
  28533. }
  28534. }
  28535. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28536. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28537. };
  28538. }
  28539. void AudioProcessorGraph::clearRenderingSequence()
  28540. {
  28541. const ScopedLock sl (renderLock);
  28542. for (int i = renderingOps.size(); --i >= 0;)
  28543. {
  28544. GraphRenderingOps::AudioGraphRenderingOp* const r
  28545. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28546. renderingOps.remove (i);
  28547. delete r;
  28548. }
  28549. }
  28550. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28551. const uint32 possibleDestinationId,
  28552. const int recursionCheck) const
  28553. {
  28554. if (recursionCheck > 0)
  28555. {
  28556. for (int i = connections.size(); --i >= 0;)
  28557. {
  28558. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28559. if (c->destNodeId == possibleDestinationId
  28560. && (c->sourceNodeId == possibleInputId
  28561. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28562. return true;
  28563. }
  28564. }
  28565. return false;
  28566. }
  28567. void AudioProcessorGraph::buildRenderingSequence()
  28568. {
  28569. VoidArray newRenderingOps;
  28570. int numRenderingBuffersNeeded = 2;
  28571. int numMidiBuffersNeeded = 1;
  28572. {
  28573. MessageManagerLock mml;
  28574. VoidArray orderedNodes;
  28575. int i;
  28576. for (i = 0; i < nodes.size(); ++i)
  28577. {
  28578. Node* const node = nodes.getUnchecked(i);
  28579. node->prepare (getSampleRate(), getBlockSize(), this);
  28580. int j = 0;
  28581. for (; j < orderedNodes.size(); ++j)
  28582. if (isAnInputTo (node->id,
  28583. ((Node*) orderedNodes.getUnchecked (j))->id,
  28584. nodes.size() + 1))
  28585. break;
  28586. orderedNodes.insert (j, node);
  28587. }
  28588. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28589. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28590. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28591. }
  28592. VoidArray oldRenderingOps (renderingOps);
  28593. {
  28594. // swap over to the new rendering sequence..
  28595. const ScopedLock sl (renderLock);
  28596. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28597. renderingBuffers.clear();
  28598. for (int i = midiBuffers.size(); --i >= 0;)
  28599. midiBuffers.getUnchecked(i)->clear();
  28600. while (midiBuffers.size() < numMidiBuffersNeeded)
  28601. midiBuffers.add (new MidiBuffer());
  28602. renderingOps = newRenderingOps;
  28603. }
  28604. for (int i = oldRenderingOps.size(); --i >= 0;)
  28605. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28606. }
  28607. void AudioProcessorGraph::handleAsyncUpdate()
  28608. {
  28609. buildRenderingSequence();
  28610. }
  28611. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28612. {
  28613. currentAudioInputBuffer = 0;
  28614. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28615. currentMidiInputBuffer = 0;
  28616. currentMidiOutputBuffer.clear();
  28617. clearRenderingSequence();
  28618. buildRenderingSequence();
  28619. }
  28620. void AudioProcessorGraph::releaseResources()
  28621. {
  28622. for (int i = 0; i < nodes.size(); ++i)
  28623. nodes.getUnchecked(i)->unprepare();
  28624. renderingBuffers.setSize (1, 1);
  28625. midiBuffers.clear();
  28626. currentAudioInputBuffer = 0;
  28627. currentAudioOutputBuffer.setSize (1, 1);
  28628. currentMidiInputBuffer = 0;
  28629. currentMidiOutputBuffer.clear();
  28630. }
  28631. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28632. {
  28633. const int numSamples = buffer.getNumSamples();
  28634. const ScopedLock sl (renderLock);
  28635. currentAudioInputBuffer = &buffer;
  28636. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28637. currentAudioOutputBuffer.clear();
  28638. currentMidiInputBuffer = &midiMessages;
  28639. currentMidiOutputBuffer.clear();
  28640. int i;
  28641. for (i = 0; i < renderingOps.size(); ++i)
  28642. {
  28643. GraphRenderingOps::AudioGraphRenderingOp* const op
  28644. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28645. op->perform (renderingBuffers, midiBuffers, numSamples);
  28646. }
  28647. for (i = 0; i < buffer.getNumChannels(); ++i)
  28648. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28649. midiMessages.clear();
  28650. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28651. }
  28652. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28653. {
  28654. return "Input " + String (channelIndex + 1);
  28655. }
  28656. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28657. {
  28658. return "Output " + String (channelIndex + 1);
  28659. }
  28660. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28661. {
  28662. return true;
  28663. }
  28664. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28665. {
  28666. return true;
  28667. }
  28668. bool AudioProcessorGraph::acceptsMidi() const
  28669. {
  28670. return true;
  28671. }
  28672. bool AudioProcessorGraph::producesMidi() const
  28673. {
  28674. return true;
  28675. }
  28676. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28677. {
  28678. }
  28679. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28680. {
  28681. }
  28682. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28683. : type (type_),
  28684. graph (0)
  28685. {
  28686. }
  28687. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28688. {
  28689. }
  28690. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28691. {
  28692. switch (type)
  28693. {
  28694. case audioOutputNode:
  28695. return "Audio Output";
  28696. case audioInputNode:
  28697. return "Audio Input";
  28698. case midiOutputNode:
  28699. return "Midi Output";
  28700. case midiInputNode:
  28701. return "Midi Input";
  28702. default:
  28703. break;
  28704. }
  28705. return String::empty;
  28706. }
  28707. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28708. {
  28709. d.name = getName();
  28710. d.uid = d.name.hashCode();
  28711. d.category = "I/O devices";
  28712. d.pluginFormatName = "Internal";
  28713. d.manufacturerName = "Raw Material Software";
  28714. d.version = "1.0";
  28715. d.isInstrument = false;
  28716. d.numInputChannels = getNumInputChannels();
  28717. if (type == audioOutputNode && graph != 0)
  28718. d.numInputChannels = graph->getNumInputChannels();
  28719. d.numOutputChannels = getNumOutputChannels();
  28720. if (type == audioInputNode && graph != 0)
  28721. d.numOutputChannels = graph->getNumOutputChannels();
  28722. }
  28723. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28724. {
  28725. jassert (graph != 0);
  28726. }
  28727. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28728. {
  28729. }
  28730. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28731. MidiBuffer& midiMessages)
  28732. {
  28733. jassert (graph != 0);
  28734. switch (type)
  28735. {
  28736. case audioOutputNode:
  28737. {
  28738. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28739. buffer.getNumChannels()); --i >= 0;)
  28740. {
  28741. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28742. }
  28743. break;
  28744. }
  28745. case audioInputNode:
  28746. {
  28747. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28748. buffer.getNumChannels()); --i >= 0;)
  28749. {
  28750. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28751. }
  28752. break;
  28753. }
  28754. case midiOutputNode:
  28755. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28756. break;
  28757. case midiInputNode:
  28758. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28759. break;
  28760. default:
  28761. break;
  28762. }
  28763. }
  28764. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28765. {
  28766. return type == midiOutputNode;
  28767. }
  28768. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28769. {
  28770. return type == midiInputNode;
  28771. }
  28772. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28773. {
  28774. switch (type)
  28775. {
  28776. case audioOutputNode:
  28777. return "Output " + String (channelIndex + 1);
  28778. case midiOutputNode:
  28779. return "Midi Output";
  28780. default:
  28781. break;
  28782. }
  28783. return String::empty;
  28784. }
  28785. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28786. {
  28787. switch (type)
  28788. {
  28789. case audioInputNode:
  28790. return "Input " + String (channelIndex + 1);
  28791. case midiInputNode:
  28792. return "Midi Input";
  28793. default:
  28794. break;
  28795. }
  28796. return String::empty;
  28797. }
  28798. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28799. {
  28800. return type == audioInputNode || type == audioOutputNode;
  28801. }
  28802. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28803. {
  28804. return isInputChannelStereoPair (index);
  28805. }
  28806. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28807. {
  28808. return type == audioInputNode || type == midiInputNode;
  28809. }
  28810. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28811. {
  28812. return type == audioOutputNode || type == midiOutputNode;
  28813. }
  28814. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28815. {
  28816. return 0;
  28817. }
  28818. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28819. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28820. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28821. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28822. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28823. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28824. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28825. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28826. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28827. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28828. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28829. {
  28830. }
  28831. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28832. {
  28833. }
  28834. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28835. {
  28836. graph = newGraph;
  28837. if (graph != 0)
  28838. {
  28839. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28840. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28841. getSampleRate(),
  28842. getBlockSize());
  28843. updateHostDisplay();
  28844. }
  28845. }
  28846. END_JUCE_NAMESPACE
  28847. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28848. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28849. BEGIN_JUCE_NAMESPACE
  28850. AudioProcessorPlayer::AudioProcessorPlayer()
  28851. : processor (0),
  28852. sampleRate (0),
  28853. blockSize (0),
  28854. isPrepared (false),
  28855. numInputChans (0),
  28856. numOutputChans (0),
  28857. tempBuffer (1, 1)
  28858. {
  28859. }
  28860. AudioProcessorPlayer::~AudioProcessorPlayer()
  28861. {
  28862. setProcessor (0);
  28863. }
  28864. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28865. {
  28866. if (processor != processorToPlay)
  28867. {
  28868. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28869. {
  28870. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28871. sampleRate, blockSize);
  28872. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28873. }
  28874. AudioProcessor* oldOne;
  28875. {
  28876. const ScopedLock sl (lock);
  28877. oldOne = isPrepared ? processor : 0;
  28878. processor = processorToPlay;
  28879. isPrepared = true;
  28880. }
  28881. if (oldOne != 0)
  28882. oldOne->releaseResources();
  28883. }
  28884. }
  28885. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28886. int numInputChannels,
  28887. float** outputChannelData,
  28888. int numOutputChannels,
  28889. int numSamples)
  28890. {
  28891. // these should have been prepared by audioDeviceAboutToStart()...
  28892. jassert (sampleRate > 0 && blockSize > 0);
  28893. incomingMidi.clear();
  28894. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28895. int i, totalNumChans = 0;
  28896. if (numInputChannels > numOutputChannels)
  28897. {
  28898. // if there aren't enough output channels for the number of
  28899. // inputs, we need to create some temporary extra ones (can't
  28900. // use the input data in case it gets written to)
  28901. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  28902. false, false, true);
  28903. for (i = 0; i < numOutputChannels; ++i)
  28904. {
  28905. channels[totalNumChans] = outputChannelData[i];
  28906. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28907. ++totalNumChans;
  28908. }
  28909. for (i = numOutputChannels; i < numInputChannels; ++i)
  28910. {
  28911. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  28912. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28913. ++totalNumChans;
  28914. }
  28915. }
  28916. else
  28917. {
  28918. for (i = 0; i < numInputChannels; ++i)
  28919. {
  28920. channels[totalNumChans] = outputChannelData[i];
  28921. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28922. ++totalNumChans;
  28923. }
  28924. for (i = numInputChannels; i < numOutputChannels; ++i)
  28925. {
  28926. channels[totalNumChans] = outputChannelData[i];
  28927. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  28928. ++totalNumChans;
  28929. }
  28930. }
  28931. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  28932. const ScopedLock sl (lock);
  28933. if (processor != 0)
  28934. processor->processBlock (buffer, incomingMidi);
  28935. }
  28936. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  28937. {
  28938. const ScopedLock sl (lock);
  28939. sampleRate = device->getCurrentSampleRate();
  28940. blockSize = device->getCurrentBufferSizeSamples();
  28941. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  28942. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  28943. messageCollector.reset (sampleRate);
  28944. zeromem (channels, sizeof (channels));
  28945. if (processor != 0)
  28946. {
  28947. if (isPrepared)
  28948. processor->releaseResources();
  28949. AudioProcessor* const oldProcessor = processor;
  28950. setProcessor (0);
  28951. setProcessor (oldProcessor);
  28952. }
  28953. }
  28954. void AudioProcessorPlayer::audioDeviceStopped()
  28955. {
  28956. const ScopedLock sl (lock);
  28957. if (processor != 0 && isPrepared)
  28958. processor->releaseResources();
  28959. sampleRate = 0.0;
  28960. blockSize = 0;
  28961. isPrepared = false;
  28962. tempBuffer.setSize (1, 1);
  28963. }
  28964. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  28965. {
  28966. messageCollector.addMessageToQueue (message);
  28967. }
  28968. END_JUCE_NAMESPACE
  28969. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28970. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  28971. BEGIN_JUCE_NAMESPACE
  28972. class ProcessorParameterPropertyComp : public PropertyComponent,
  28973. public AudioProcessorListener,
  28974. public AsyncUpdater
  28975. {
  28976. public:
  28977. ProcessorParameterPropertyComp (const String& name,
  28978. AudioProcessor* const owner_,
  28979. const int index_)
  28980. : PropertyComponent (name),
  28981. owner (owner_),
  28982. index (index_)
  28983. {
  28984. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  28985. owner_->addListener (this);
  28986. }
  28987. ~ProcessorParameterPropertyComp()
  28988. {
  28989. owner->removeListener (this);
  28990. deleteAllChildren();
  28991. }
  28992. void refresh()
  28993. {
  28994. slider->setValue (owner->getParameter (index), false);
  28995. }
  28996. void audioProcessorChanged (AudioProcessor*) {}
  28997. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  28998. {
  28999. if (parameterIndex == index)
  29000. triggerAsyncUpdate();
  29001. }
  29002. void handleAsyncUpdate()
  29003. {
  29004. refresh();
  29005. }
  29006. juce_UseDebuggingNewOperator
  29007. private:
  29008. AudioProcessor* const owner;
  29009. const int index;
  29010. Slider* slider;
  29011. class ParamSlider : public Slider
  29012. {
  29013. public:
  29014. ParamSlider (AudioProcessor* const owner_, const int index_)
  29015. : Slider (String::empty),
  29016. owner (owner_),
  29017. index (index_)
  29018. {
  29019. setRange (0.0, 1.0, 0.0);
  29020. setSliderStyle (Slider::LinearBar);
  29021. setTextBoxIsEditable (false);
  29022. setScrollWheelEnabled (false);
  29023. }
  29024. ~ParamSlider()
  29025. {
  29026. }
  29027. void valueChanged()
  29028. {
  29029. const float newVal = (float) getValue();
  29030. if (owner->getParameter (index) != newVal)
  29031. owner->setParameter (index, newVal);
  29032. }
  29033. const String getTextFromValue (double /*value*/)
  29034. {
  29035. return owner->getParameterText (index);
  29036. }
  29037. juce_UseDebuggingNewOperator
  29038. private:
  29039. AudioProcessor* const owner;
  29040. const int index;
  29041. ParamSlider (const ParamSlider&);
  29042. ParamSlider& operator= (const ParamSlider&);
  29043. };
  29044. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29045. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29046. };
  29047. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29048. : AudioProcessorEditor (owner_)
  29049. {
  29050. setOpaque (true);
  29051. addAndMakeVisible (panel = new PropertyPanel());
  29052. Array <PropertyComponent*> params;
  29053. const int numParams = owner_->getNumParameters();
  29054. int totalHeight = 0;
  29055. for (int i = 0; i < numParams; ++i)
  29056. {
  29057. String name (owner_->getParameterName (i));
  29058. if (name.trim().isEmpty())
  29059. name = "Unnamed";
  29060. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29061. params.add (pc);
  29062. totalHeight += pc->getPreferredHeight();
  29063. }
  29064. panel->addProperties (params);
  29065. setSize (400, jlimit (25, 400, totalHeight));
  29066. }
  29067. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29068. {
  29069. deleteAllChildren();
  29070. }
  29071. void GenericAudioProcessorEditor::paint (Graphics& g)
  29072. {
  29073. g.fillAll (Colours::white);
  29074. }
  29075. void GenericAudioProcessorEditor::resized()
  29076. {
  29077. panel->setSize (getWidth(), getHeight());
  29078. }
  29079. END_JUCE_NAMESPACE
  29080. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29081. /*** Start of inlined file: juce_Sampler.cpp ***/
  29082. BEGIN_JUCE_NAMESPACE
  29083. SamplerSound::SamplerSound (const String& name_,
  29084. AudioFormatReader& source,
  29085. const BigInteger& midiNotes_,
  29086. const int midiNoteForNormalPitch,
  29087. const double attackTimeSecs,
  29088. const double releaseTimeSecs,
  29089. const double maxSampleLengthSeconds)
  29090. : name (name_),
  29091. midiNotes (midiNotes_),
  29092. midiRootNote (midiNoteForNormalPitch)
  29093. {
  29094. sourceSampleRate = source.sampleRate;
  29095. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29096. {
  29097. length = 0;
  29098. attackSamples = 0;
  29099. releaseSamples = 0;
  29100. }
  29101. else
  29102. {
  29103. length = jmin ((int) source.lengthInSamples,
  29104. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29105. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29106. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29107. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29108. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29109. }
  29110. }
  29111. SamplerSound::~SamplerSound()
  29112. {
  29113. }
  29114. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29115. {
  29116. return midiNotes [midiNoteNumber];
  29117. }
  29118. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29119. {
  29120. return true;
  29121. }
  29122. SamplerVoice::SamplerVoice()
  29123. : pitchRatio (0.0),
  29124. sourceSamplePosition (0.0),
  29125. lgain (0.0f),
  29126. rgain (0.0f),
  29127. isInAttack (false),
  29128. isInRelease (false)
  29129. {
  29130. }
  29131. SamplerVoice::~SamplerVoice()
  29132. {
  29133. }
  29134. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29135. {
  29136. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29137. }
  29138. void SamplerVoice::startNote (const int midiNoteNumber,
  29139. const float velocity,
  29140. SynthesiserSound* s,
  29141. const int /*currentPitchWheelPosition*/)
  29142. {
  29143. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29144. jassert (sound != 0); // this object can only play SamplerSounds!
  29145. if (sound != 0)
  29146. {
  29147. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29148. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29149. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29150. sourceSamplePosition = 0.0;
  29151. lgain = velocity;
  29152. rgain = velocity;
  29153. isInAttack = (sound->attackSamples > 0);
  29154. isInRelease = false;
  29155. if (isInAttack)
  29156. {
  29157. attackReleaseLevel = 0.0f;
  29158. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29159. }
  29160. else
  29161. {
  29162. attackReleaseLevel = 1.0f;
  29163. attackDelta = 0.0f;
  29164. }
  29165. if (sound->releaseSamples > 0)
  29166. {
  29167. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29168. }
  29169. else
  29170. {
  29171. releaseDelta = 0.0f;
  29172. }
  29173. }
  29174. }
  29175. void SamplerVoice::stopNote (const bool allowTailOff)
  29176. {
  29177. if (allowTailOff)
  29178. {
  29179. isInAttack = false;
  29180. isInRelease = true;
  29181. }
  29182. else
  29183. {
  29184. clearCurrentNote();
  29185. }
  29186. }
  29187. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29188. {
  29189. }
  29190. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29191. const int /*newValue*/)
  29192. {
  29193. }
  29194. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29195. {
  29196. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29197. if (playingSound != 0)
  29198. {
  29199. const float* const inL = playingSound->data->getSampleData (0, 0);
  29200. const float* const inR = playingSound->data->getNumChannels() > 1
  29201. ? playingSound->data->getSampleData (1, 0) : 0;
  29202. float* outL = outputBuffer.getSampleData (0, startSample);
  29203. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29204. while (--numSamples >= 0)
  29205. {
  29206. const int pos = (int) sourceSamplePosition;
  29207. const float alpha = (float) (sourceSamplePosition - pos);
  29208. const float invAlpha = 1.0f - alpha;
  29209. // just using a very simple linear interpolation here..
  29210. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29211. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29212. : l;
  29213. l *= lgain;
  29214. r *= rgain;
  29215. if (isInAttack)
  29216. {
  29217. l *= attackReleaseLevel;
  29218. r *= attackReleaseLevel;
  29219. attackReleaseLevel += attackDelta;
  29220. if (attackReleaseLevel >= 1.0f)
  29221. {
  29222. attackReleaseLevel = 1.0f;
  29223. isInAttack = false;
  29224. }
  29225. }
  29226. else if (isInRelease)
  29227. {
  29228. l *= attackReleaseLevel;
  29229. r *= attackReleaseLevel;
  29230. attackReleaseLevel += releaseDelta;
  29231. if (attackReleaseLevel <= 0.0f)
  29232. {
  29233. stopNote (false);
  29234. break;
  29235. }
  29236. }
  29237. if (outR != 0)
  29238. {
  29239. *outL++ += l;
  29240. *outR++ += r;
  29241. }
  29242. else
  29243. {
  29244. *outL++ += (l + r) * 0.5f;
  29245. }
  29246. sourceSamplePosition += pitchRatio;
  29247. if (sourceSamplePosition > playingSound->length)
  29248. {
  29249. stopNote (false);
  29250. break;
  29251. }
  29252. }
  29253. }
  29254. }
  29255. END_JUCE_NAMESPACE
  29256. /*** End of inlined file: juce_Sampler.cpp ***/
  29257. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29258. BEGIN_JUCE_NAMESPACE
  29259. SynthesiserSound::SynthesiserSound()
  29260. {
  29261. }
  29262. SynthesiserSound::~SynthesiserSound()
  29263. {
  29264. }
  29265. SynthesiserVoice::SynthesiserVoice()
  29266. : currentSampleRate (44100.0),
  29267. currentlyPlayingNote (-1),
  29268. noteOnTime (0),
  29269. currentlyPlayingSound (0)
  29270. {
  29271. }
  29272. SynthesiserVoice::~SynthesiserVoice()
  29273. {
  29274. }
  29275. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29276. {
  29277. return currentlyPlayingSound != 0
  29278. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29279. }
  29280. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29281. {
  29282. currentSampleRate = newRate;
  29283. }
  29284. void SynthesiserVoice::clearCurrentNote()
  29285. {
  29286. currentlyPlayingNote = -1;
  29287. currentlyPlayingSound = 0;
  29288. }
  29289. Synthesiser::Synthesiser()
  29290. : sampleRate (0),
  29291. lastNoteOnCounter (0),
  29292. shouldStealNotes (true)
  29293. {
  29294. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29295. lastPitchWheelValues[i] = 0x2000;
  29296. }
  29297. Synthesiser::~Synthesiser()
  29298. {
  29299. }
  29300. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29301. {
  29302. const ScopedLock sl (lock);
  29303. return voices [index];
  29304. }
  29305. void Synthesiser::clearVoices()
  29306. {
  29307. const ScopedLock sl (lock);
  29308. voices.clear();
  29309. }
  29310. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29311. {
  29312. const ScopedLock sl (lock);
  29313. voices.add (newVoice);
  29314. }
  29315. void Synthesiser::removeVoice (const int index)
  29316. {
  29317. const ScopedLock sl (lock);
  29318. voices.remove (index);
  29319. }
  29320. void Synthesiser::clearSounds()
  29321. {
  29322. const ScopedLock sl (lock);
  29323. sounds.clear();
  29324. }
  29325. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29326. {
  29327. const ScopedLock sl (lock);
  29328. sounds.add (newSound);
  29329. }
  29330. void Synthesiser::removeSound (const int index)
  29331. {
  29332. const ScopedLock sl (lock);
  29333. sounds.remove (index);
  29334. }
  29335. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29336. {
  29337. shouldStealNotes = shouldStealNotes_;
  29338. }
  29339. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29340. {
  29341. if (sampleRate != newRate)
  29342. {
  29343. const ScopedLock sl (lock);
  29344. allNotesOff (0, false);
  29345. sampleRate = newRate;
  29346. for (int i = voices.size(); --i >= 0;)
  29347. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29348. }
  29349. }
  29350. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29351. const MidiBuffer& midiData,
  29352. int startSample,
  29353. int numSamples)
  29354. {
  29355. // must set the sample rate before using this!
  29356. jassert (sampleRate != 0);
  29357. const ScopedLock sl (lock);
  29358. MidiBuffer::Iterator midiIterator (midiData);
  29359. midiIterator.setNextSamplePosition (startSample);
  29360. MidiMessage m (0xf4, 0.0);
  29361. while (numSamples > 0)
  29362. {
  29363. int midiEventPos;
  29364. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29365. && midiEventPos < startSample + numSamples;
  29366. const int numThisTime = useEvent ? midiEventPos - startSample
  29367. : numSamples;
  29368. if (numThisTime > 0)
  29369. {
  29370. for (int i = voices.size(); --i >= 0;)
  29371. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29372. }
  29373. if (useEvent)
  29374. {
  29375. if (m.isNoteOn())
  29376. {
  29377. const int channel = m.getChannel();
  29378. noteOn (channel,
  29379. m.getNoteNumber(),
  29380. m.getFloatVelocity());
  29381. }
  29382. else if (m.isNoteOff())
  29383. {
  29384. noteOff (m.getChannel(),
  29385. m.getNoteNumber(),
  29386. true);
  29387. }
  29388. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29389. {
  29390. allNotesOff (m.getChannel(), true);
  29391. }
  29392. else if (m.isPitchWheel())
  29393. {
  29394. const int channel = m.getChannel();
  29395. const int wheelPos = m.getPitchWheelValue();
  29396. lastPitchWheelValues [channel - 1] = wheelPos;
  29397. handlePitchWheel (channel, wheelPos);
  29398. }
  29399. else if (m.isController())
  29400. {
  29401. handleController (m.getChannel(),
  29402. m.getControllerNumber(),
  29403. m.getControllerValue());
  29404. }
  29405. }
  29406. startSample += numThisTime;
  29407. numSamples -= numThisTime;
  29408. }
  29409. }
  29410. void Synthesiser::noteOn (const int midiChannel,
  29411. const int midiNoteNumber,
  29412. const float velocity)
  29413. {
  29414. const ScopedLock sl (lock);
  29415. for (int i = sounds.size(); --i >= 0;)
  29416. {
  29417. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29418. if (sound->appliesToNote (midiNoteNumber)
  29419. && sound->appliesToChannel (midiChannel))
  29420. {
  29421. startVoice (findFreeVoice (sound, shouldStealNotes),
  29422. sound, midiChannel, midiNoteNumber, velocity);
  29423. }
  29424. }
  29425. }
  29426. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29427. SynthesiserSound* const sound,
  29428. const int midiChannel,
  29429. const int midiNoteNumber,
  29430. const float velocity)
  29431. {
  29432. if (voice != 0 && sound != 0)
  29433. {
  29434. if (voice->currentlyPlayingSound != 0)
  29435. voice->stopNote (false);
  29436. voice->startNote (midiNoteNumber,
  29437. velocity,
  29438. sound,
  29439. lastPitchWheelValues [midiChannel - 1]);
  29440. voice->currentlyPlayingNote = midiNoteNumber;
  29441. voice->noteOnTime = ++lastNoteOnCounter;
  29442. voice->currentlyPlayingSound = sound;
  29443. }
  29444. }
  29445. void Synthesiser::noteOff (const int midiChannel,
  29446. const int midiNoteNumber,
  29447. const bool allowTailOff)
  29448. {
  29449. const ScopedLock sl (lock);
  29450. for (int i = voices.size(); --i >= 0;)
  29451. {
  29452. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29453. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29454. {
  29455. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29456. if (sound != 0
  29457. && sound->appliesToNote (midiNoteNumber)
  29458. && sound->appliesToChannel (midiChannel))
  29459. {
  29460. voice->stopNote (allowTailOff);
  29461. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29462. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29463. }
  29464. }
  29465. }
  29466. }
  29467. void Synthesiser::allNotesOff (const int midiChannel,
  29468. const bool allowTailOff)
  29469. {
  29470. const ScopedLock sl (lock);
  29471. for (int i = voices.size(); --i >= 0;)
  29472. {
  29473. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29474. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29475. voice->stopNote (allowTailOff);
  29476. }
  29477. }
  29478. void Synthesiser::handlePitchWheel (const int midiChannel,
  29479. const int wheelValue)
  29480. {
  29481. const ScopedLock sl (lock);
  29482. for (int i = voices.size(); --i >= 0;)
  29483. {
  29484. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29485. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29486. {
  29487. voice->pitchWheelMoved (wheelValue);
  29488. }
  29489. }
  29490. }
  29491. void Synthesiser::handleController (const int midiChannel,
  29492. const int controllerNumber,
  29493. const int controllerValue)
  29494. {
  29495. const ScopedLock sl (lock);
  29496. for (int i = voices.size(); --i >= 0;)
  29497. {
  29498. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29499. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29500. voice->controllerMoved (controllerNumber, controllerValue);
  29501. }
  29502. }
  29503. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29504. const bool stealIfNoneAvailable) const
  29505. {
  29506. const ScopedLock sl (lock);
  29507. for (int i = voices.size(); --i >= 0;)
  29508. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29509. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29510. return voices.getUnchecked (i);
  29511. if (stealIfNoneAvailable)
  29512. {
  29513. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29514. SynthesiserVoice* oldest = 0;
  29515. for (int i = voices.size(); --i >= 0;)
  29516. {
  29517. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29518. if (voice->canPlaySound (soundToPlay)
  29519. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29520. oldest = voice;
  29521. }
  29522. jassert (oldest != 0);
  29523. return oldest;
  29524. }
  29525. return 0;
  29526. }
  29527. END_JUCE_NAMESPACE
  29528. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29529. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29530. BEGIN_JUCE_NAMESPACE
  29531. ActionBroadcaster::ActionBroadcaster() throw()
  29532. {
  29533. // are you trying to create this object before or after juce has been intialised??
  29534. jassert (MessageManager::instance != 0);
  29535. }
  29536. ActionBroadcaster::~ActionBroadcaster()
  29537. {
  29538. // all event-based objects must be deleted BEFORE juce is shut down!
  29539. jassert (MessageManager::instance != 0);
  29540. }
  29541. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29542. {
  29543. actionListenerList.addActionListener (listener);
  29544. }
  29545. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29546. {
  29547. jassert (actionListenerList.isValidMessageListener());
  29548. if (actionListenerList.isValidMessageListener())
  29549. actionListenerList.removeActionListener (listener);
  29550. }
  29551. void ActionBroadcaster::removeAllActionListeners()
  29552. {
  29553. actionListenerList.removeAllActionListeners();
  29554. }
  29555. void ActionBroadcaster::sendActionMessage (const String& message) const
  29556. {
  29557. actionListenerList.sendActionMessage (message);
  29558. }
  29559. END_JUCE_NAMESPACE
  29560. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29561. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29562. BEGIN_JUCE_NAMESPACE
  29563. // special message of our own with a string in it
  29564. class ActionMessage : public Message
  29565. {
  29566. public:
  29567. const String message;
  29568. ActionMessage (const String& messageText,
  29569. void* const listener_) throw()
  29570. : message (messageText)
  29571. {
  29572. pointerParameter = listener_;
  29573. }
  29574. ~ActionMessage() throw()
  29575. {
  29576. }
  29577. private:
  29578. ActionMessage (const ActionMessage&);
  29579. ActionMessage& operator= (const ActionMessage&);
  29580. };
  29581. ActionListenerList::ActionListenerList() throw()
  29582. {
  29583. }
  29584. ActionListenerList::~ActionListenerList() throw()
  29585. {
  29586. }
  29587. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29588. {
  29589. const ScopedLock sl (actionListenerLock_);
  29590. jassert (listener != 0);
  29591. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29592. if (listener != 0)
  29593. actionListeners_.add (listener);
  29594. }
  29595. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29596. {
  29597. const ScopedLock sl (actionListenerLock_);
  29598. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29599. actionListeners_.removeValue (listener);
  29600. }
  29601. void ActionListenerList::removeAllActionListeners() throw()
  29602. {
  29603. const ScopedLock sl (actionListenerLock_);
  29604. actionListeners_.clear();
  29605. }
  29606. void ActionListenerList::sendActionMessage (const String& message) const
  29607. {
  29608. const ScopedLock sl (actionListenerLock_);
  29609. for (int i = actionListeners_.size(); --i >= 0;)
  29610. {
  29611. postMessage (new ActionMessage (message,
  29612. (ActionListener*) actionListeners_.getUnchecked(i)));
  29613. }
  29614. }
  29615. void ActionListenerList::handleMessage (const Message& message)
  29616. {
  29617. const ActionMessage& am = (const ActionMessage&) message;
  29618. if (actionListeners_.contains (am.pointerParameter))
  29619. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29620. }
  29621. END_JUCE_NAMESPACE
  29622. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29623. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29624. BEGIN_JUCE_NAMESPACE
  29625. AsyncUpdater::AsyncUpdater() throw()
  29626. : asyncMessagePending (false)
  29627. {
  29628. internalAsyncHandler.owner = this;
  29629. }
  29630. AsyncUpdater::~AsyncUpdater()
  29631. {
  29632. }
  29633. void AsyncUpdater::triggerAsyncUpdate() throw()
  29634. {
  29635. if (! asyncMessagePending)
  29636. {
  29637. asyncMessagePending = true;
  29638. internalAsyncHandler.postMessage (new Message());
  29639. }
  29640. }
  29641. void AsyncUpdater::cancelPendingUpdate() throw()
  29642. {
  29643. asyncMessagePending = false;
  29644. }
  29645. void AsyncUpdater::handleUpdateNowIfNeeded()
  29646. {
  29647. if (asyncMessagePending)
  29648. {
  29649. asyncMessagePending = false;
  29650. handleAsyncUpdate();
  29651. }
  29652. }
  29653. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29654. {
  29655. owner->handleUpdateNowIfNeeded();
  29656. }
  29657. END_JUCE_NAMESPACE
  29658. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29659. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29660. BEGIN_JUCE_NAMESPACE
  29661. ChangeBroadcaster::ChangeBroadcaster() throw()
  29662. {
  29663. // are you trying to create this object before or after juce has been intialised??
  29664. jassert (MessageManager::instance != 0);
  29665. }
  29666. ChangeBroadcaster::~ChangeBroadcaster()
  29667. {
  29668. // all event-based objects must be deleted BEFORE juce is shut down!
  29669. jassert (MessageManager::instance != 0);
  29670. }
  29671. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29672. {
  29673. changeListenerList.addChangeListener (listener);
  29674. }
  29675. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29676. {
  29677. jassert (changeListenerList.isValidMessageListener());
  29678. if (changeListenerList.isValidMessageListener())
  29679. changeListenerList.removeChangeListener (listener);
  29680. }
  29681. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29682. {
  29683. changeListenerList.removeAllChangeListeners();
  29684. }
  29685. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29686. {
  29687. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29688. }
  29689. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29690. {
  29691. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29692. }
  29693. void ChangeBroadcaster::dispatchPendingMessages()
  29694. {
  29695. changeListenerList.dispatchPendingMessages();
  29696. }
  29697. END_JUCE_NAMESPACE
  29698. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29699. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29700. BEGIN_JUCE_NAMESPACE
  29701. ChangeListenerList::ChangeListenerList() throw()
  29702. : lastChangedObject (0),
  29703. messagePending (false)
  29704. {
  29705. }
  29706. ChangeListenerList::~ChangeListenerList() throw()
  29707. {
  29708. }
  29709. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29710. {
  29711. const ScopedLock sl (lock);
  29712. jassert (listener != 0);
  29713. if (listener != 0)
  29714. listeners.add (listener);
  29715. }
  29716. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29717. {
  29718. const ScopedLock sl (lock);
  29719. listeners.removeValue (listener);
  29720. }
  29721. void ChangeListenerList::removeAllChangeListeners() throw()
  29722. {
  29723. const ScopedLock sl (lock);
  29724. listeners.clear();
  29725. }
  29726. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29727. {
  29728. const ScopedLock sl (lock);
  29729. if ((! messagePending) && (listeners.size() > 0))
  29730. {
  29731. lastChangedObject = objectThatHasChanged;
  29732. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29733. messagePending = true;
  29734. }
  29735. }
  29736. void ChangeListenerList::handleMessage (const Message& message)
  29737. {
  29738. sendSynchronousChangeMessage (message.pointerParameter);
  29739. }
  29740. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29741. {
  29742. const ScopedLock sl (lock);
  29743. messagePending = false;
  29744. for (int i = listeners.size(); --i >= 0;)
  29745. {
  29746. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29747. {
  29748. const ScopedUnlock tempUnlocker (lock);
  29749. l->changeListenerCallback (objectThatHasChanged);
  29750. }
  29751. i = jmin (i, listeners.size());
  29752. }
  29753. }
  29754. void ChangeListenerList::dispatchPendingMessages()
  29755. {
  29756. if (messagePending)
  29757. sendSynchronousChangeMessage (lastChangedObject);
  29758. }
  29759. END_JUCE_NAMESPACE
  29760. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29761. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29762. BEGIN_JUCE_NAMESPACE
  29763. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29764. const uint32 magicMessageHeaderNumber)
  29765. : Thread ("Juce IPC connection"),
  29766. callbackConnectionState (false),
  29767. useMessageThread (callbacksOnMessageThread),
  29768. magicMessageHeader (magicMessageHeaderNumber),
  29769. pipeReceiveMessageTimeout (-1)
  29770. {
  29771. }
  29772. InterprocessConnection::~InterprocessConnection()
  29773. {
  29774. callbackConnectionState = false;
  29775. disconnect();
  29776. }
  29777. bool InterprocessConnection::connectToSocket (const String& hostName,
  29778. const int portNumber,
  29779. const int timeOutMillisecs)
  29780. {
  29781. disconnect();
  29782. const ScopedLock sl (pipeAndSocketLock);
  29783. socket = new StreamingSocket();
  29784. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29785. {
  29786. connectionMadeInt();
  29787. startThread();
  29788. return true;
  29789. }
  29790. else
  29791. {
  29792. socket = 0;
  29793. return false;
  29794. }
  29795. }
  29796. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29797. const int pipeReceiveMessageTimeoutMs)
  29798. {
  29799. disconnect();
  29800. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29801. if (newPipe->openExisting (pipeName))
  29802. {
  29803. const ScopedLock sl (pipeAndSocketLock);
  29804. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29805. initialiseWithPipe (newPipe.release());
  29806. return true;
  29807. }
  29808. return false;
  29809. }
  29810. bool InterprocessConnection::createPipe (const String& pipeName,
  29811. const int pipeReceiveMessageTimeoutMs)
  29812. {
  29813. disconnect();
  29814. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29815. if (newPipe->createNewPipe (pipeName))
  29816. {
  29817. const ScopedLock sl (pipeAndSocketLock);
  29818. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29819. initialiseWithPipe (newPipe.release());
  29820. return true;
  29821. }
  29822. return false;
  29823. }
  29824. void InterprocessConnection::disconnect()
  29825. {
  29826. if (socket != 0)
  29827. socket->close();
  29828. if (pipe != 0)
  29829. {
  29830. pipe->cancelPendingReads();
  29831. pipe->close();
  29832. }
  29833. stopThread (4000);
  29834. {
  29835. const ScopedLock sl (pipeAndSocketLock);
  29836. socket = 0;
  29837. pipe = 0;
  29838. }
  29839. connectionLostInt();
  29840. }
  29841. bool InterprocessConnection::isConnected() const
  29842. {
  29843. const ScopedLock sl (pipeAndSocketLock);
  29844. return ((socket != 0 && socket->isConnected())
  29845. || (pipe != 0 && pipe->isOpen()))
  29846. && isThreadRunning();
  29847. }
  29848. const String InterprocessConnection::getConnectedHostName() const
  29849. {
  29850. if (pipe != 0)
  29851. {
  29852. return "localhost";
  29853. }
  29854. else if (socket != 0)
  29855. {
  29856. if (! socket->isLocal())
  29857. return socket->getHostName();
  29858. return "localhost";
  29859. }
  29860. return String::empty;
  29861. }
  29862. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29863. {
  29864. uint32 messageHeader[2];
  29865. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29866. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29867. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29868. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29869. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29870. size_t bytesWritten = 0;
  29871. const ScopedLock sl (pipeAndSocketLock);
  29872. if (socket != 0)
  29873. {
  29874. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29875. }
  29876. else if (pipe != 0)
  29877. {
  29878. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29879. }
  29880. if (bytesWritten < 0)
  29881. {
  29882. // error..
  29883. return false;
  29884. }
  29885. return (bytesWritten == messageData.getSize());
  29886. }
  29887. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29888. {
  29889. jassert (socket == 0);
  29890. socket = socket_;
  29891. connectionMadeInt();
  29892. startThread();
  29893. }
  29894. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29895. {
  29896. jassert (pipe == 0);
  29897. pipe = pipe_;
  29898. connectionMadeInt();
  29899. startThread();
  29900. }
  29901. const int messageMagicNumber = 0xb734128b;
  29902. void InterprocessConnection::handleMessage (const Message& message)
  29903. {
  29904. if (message.intParameter1 == messageMagicNumber)
  29905. {
  29906. switch (message.intParameter2)
  29907. {
  29908. case 0:
  29909. {
  29910. ScopedPointer <MemoryBlock> data (static_cast <MemoryBlock*> (message.pointerParameter));
  29911. messageReceived (*data);
  29912. break;
  29913. }
  29914. case 1:
  29915. connectionMade();
  29916. break;
  29917. case 2:
  29918. connectionLost();
  29919. break;
  29920. }
  29921. }
  29922. }
  29923. void InterprocessConnection::connectionMadeInt()
  29924. {
  29925. if (! callbackConnectionState)
  29926. {
  29927. callbackConnectionState = true;
  29928. if (useMessageThread)
  29929. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  29930. else
  29931. connectionMade();
  29932. }
  29933. }
  29934. void InterprocessConnection::connectionLostInt()
  29935. {
  29936. if (callbackConnectionState)
  29937. {
  29938. callbackConnectionState = false;
  29939. if (useMessageThread)
  29940. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  29941. else
  29942. connectionLost();
  29943. }
  29944. }
  29945. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  29946. {
  29947. jassert (callbackConnectionState);
  29948. if (useMessageThread)
  29949. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  29950. else
  29951. messageReceived (data);
  29952. }
  29953. bool InterprocessConnection::readNextMessageInt()
  29954. {
  29955. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  29956. uint32 messageHeader[2];
  29957. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  29958. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  29959. if (bytes == sizeof (messageHeader)
  29960. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  29961. {
  29962. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  29963. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  29964. {
  29965. MemoryBlock messageData (bytesInMessage, true);
  29966. int bytesRead = 0;
  29967. while (bytesInMessage > 0)
  29968. {
  29969. if (threadShouldExit())
  29970. return false;
  29971. const int numThisTime = jmin (bytesInMessage, 65536);
  29972. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  29973. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  29974. if (bytesIn <= 0)
  29975. break;
  29976. bytesRead += bytesIn;
  29977. bytesInMessage -= bytesIn;
  29978. }
  29979. if (bytesRead >= 0)
  29980. deliverDataInt (messageData);
  29981. }
  29982. }
  29983. else if (bytes < 0)
  29984. {
  29985. {
  29986. const ScopedLock sl (pipeAndSocketLock);
  29987. socket = 0;
  29988. }
  29989. connectionLostInt();
  29990. return false;
  29991. }
  29992. return true;
  29993. }
  29994. void InterprocessConnection::run()
  29995. {
  29996. while (! threadShouldExit())
  29997. {
  29998. if (socket != 0)
  29999. {
  30000. const int ready = socket->waitUntilReady (true, 0);
  30001. if (ready < 0)
  30002. {
  30003. {
  30004. const ScopedLock sl (pipeAndSocketLock);
  30005. socket = 0;
  30006. }
  30007. connectionLostInt();
  30008. break;
  30009. }
  30010. else if (ready > 0)
  30011. {
  30012. if (! readNextMessageInt())
  30013. break;
  30014. }
  30015. else
  30016. {
  30017. Thread::sleep (2);
  30018. }
  30019. }
  30020. else if (pipe != 0)
  30021. {
  30022. if (! pipe->isOpen())
  30023. {
  30024. {
  30025. const ScopedLock sl (pipeAndSocketLock);
  30026. pipe = 0;
  30027. }
  30028. connectionLostInt();
  30029. break;
  30030. }
  30031. else
  30032. {
  30033. if (! readNextMessageInt())
  30034. break;
  30035. }
  30036. }
  30037. else
  30038. {
  30039. break;
  30040. }
  30041. }
  30042. }
  30043. END_JUCE_NAMESPACE
  30044. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30045. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30046. BEGIN_JUCE_NAMESPACE
  30047. InterprocessConnectionServer::InterprocessConnectionServer()
  30048. : Thread ("Juce IPC server")
  30049. {
  30050. }
  30051. InterprocessConnectionServer::~InterprocessConnectionServer()
  30052. {
  30053. stop();
  30054. }
  30055. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30056. {
  30057. stop();
  30058. socket = new StreamingSocket();
  30059. if (socket->createListener (portNumber))
  30060. {
  30061. startThread();
  30062. return true;
  30063. }
  30064. socket = 0;
  30065. return false;
  30066. }
  30067. void InterprocessConnectionServer::stop()
  30068. {
  30069. signalThreadShouldExit();
  30070. if (socket != 0)
  30071. socket->close();
  30072. stopThread (4000);
  30073. socket = 0;
  30074. }
  30075. void InterprocessConnectionServer::run()
  30076. {
  30077. while ((! threadShouldExit()) && socket != 0)
  30078. {
  30079. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30080. if (clientSocket != 0)
  30081. {
  30082. InterprocessConnection* newConnection = createConnectionObject();
  30083. if (newConnection != 0)
  30084. newConnection->initialiseWithSocket (clientSocket.release());
  30085. }
  30086. }
  30087. }
  30088. END_JUCE_NAMESPACE
  30089. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30090. /*** Start of inlined file: juce_Message.cpp ***/
  30091. BEGIN_JUCE_NAMESPACE
  30092. Message::Message() throw()
  30093. {
  30094. }
  30095. Message::~Message() throw()
  30096. {
  30097. }
  30098. Message::Message (const int intParameter1_,
  30099. const int intParameter2_,
  30100. const int intParameter3_,
  30101. void* const pointerParameter_) throw()
  30102. : intParameter1 (intParameter1_),
  30103. intParameter2 (intParameter2_),
  30104. intParameter3 (intParameter3_),
  30105. pointerParameter (pointerParameter_)
  30106. {
  30107. }
  30108. END_JUCE_NAMESPACE
  30109. /*** End of inlined file: juce_Message.cpp ***/
  30110. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30111. BEGIN_JUCE_NAMESPACE
  30112. MessageListener::MessageListener() throw()
  30113. {
  30114. // are you trying to create a messagelistener before or after juce has been intialised??
  30115. jassert (MessageManager::instance != 0);
  30116. if (MessageManager::instance != 0)
  30117. MessageManager::instance->messageListeners.add (this);
  30118. }
  30119. MessageListener::~MessageListener()
  30120. {
  30121. if (MessageManager::instance != 0)
  30122. MessageManager::instance->messageListeners.removeValue (this);
  30123. }
  30124. void MessageListener::postMessage (Message* const message) const throw()
  30125. {
  30126. message->messageRecipient = const_cast <MessageListener*> (this);
  30127. if (MessageManager::instance == 0)
  30128. MessageManager::getInstance();
  30129. MessageManager::instance->postMessageToQueue (message);
  30130. }
  30131. bool MessageListener::isValidMessageListener() const throw()
  30132. {
  30133. return (MessageManager::instance != 0)
  30134. && MessageManager::instance->messageListeners.contains (this);
  30135. }
  30136. END_JUCE_NAMESPACE
  30137. /*** End of inlined file: juce_MessageListener.cpp ***/
  30138. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30139. BEGIN_JUCE_NAMESPACE
  30140. // platform-specific functions..
  30141. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30142. bool juce_postMessageToSystemQueue (void* message);
  30143. MessageManager* MessageManager::instance = 0;
  30144. static const int quitMessageId = 0xfffff321;
  30145. MessageManager::MessageManager() throw()
  30146. : quitMessagePosted (false),
  30147. quitMessageReceived (false),
  30148. threadWithLock (0)
  30149. {
  30150. messageThreadId = Thread::getCurrentThreadId();
  30151. }
  30152. MessageManager::~MessageManager() throw()
  30153. {
  30154. broadcastListeners = 0;
  30155. doPlatformSpecificShutdown();
  30156. jassert (instance == this);
  30157. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30158. }
  30159. MessageManager* MessageManager::getInstance() throw()
  30160. {
  30161. if (instance == 0)
  30162. {
  30163. instance = new MessageManager();
  30164. doPlatformSpecificInitialisation();
  30165. }
  30166. return instance;
  30167. }
  30168. void MessageManager::postMessageToQueue (Message* const message)
  30169. {
  30170. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30171. delete message;
  30172. }
  30173. CallbackMessage::CallbackMessage() throw() {}
  30174. CallbackMessage::~CallbackMessage() throw() {}
  30175. void CallbackMessage::post()
  30176. {
  30177. if (MessageManager::instance != 0)
  30178. MessageManager::instance->postCallbackMessage (this);
  30179. }
  30180. void MessageManager::postCallbackMessage (Message* const message)
  30181. {
  30182. message->messageRecipient = 0;
  30183. postMessageToQueue (message);
  30184. }
  30185. // not for public use..
  30186. void MessageManager::deliverMessage (void* const message)
  30187. {
  30188. const ScopedPointer <Message> m (static_cast <Message*> (message));
  30189. MessageListener* const recipient = m->messageRecipient;
  30190. JUCE_TRY
  30191. {
  30192. if (messageListeners.contains (recipient))
  30193. {
  30194. recipient->handleMessage (*m);
  30195. }
  30196. else if (recipient == 0)
  30197. {
  30198. if (m->intParameter1 == quitMessageId)
  30199. {
  30200. quitMessageReceived = true;
  30201. }
  30202. else
  30203. {
  30204. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> (static_cast <Message*> (m));
  30205. if (cm != 0)
  30206. cm->messageCallback();
  30207. }
  30208. }
  30209. }
  30210. JUCE_CATCH_EXCEPTION
  30211. }
  30212. #if ! (JUCE_MAC || JUCE_IPHONE)
  30213. void MessageManager::runDispatchLoop()
  30214. {
  30215. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30216. runDispatchLoopUntil (-1);
  30217. }
  30218. void MessageManager::stopDispatchLoop()
  30219. {
  30220. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30221. m->messageRecipient = 0;
  30222. postMessageToQueue (m);
  30223. quitMessagePosted = true;
  30224. }
  30225. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30226. {
  30227. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30228. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30229. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30230. && ! quitMessageReceived)
  30231. {
  30232. JUCE_TRY
  30233. {
  30234. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30235. {
  30236. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30237. if (msToWait > 0)
  30238. Thread::sleep (jmin (5, msToWait));
  30239. }
  30240. }
  30241. JUCE_CATCH_EXCEPTION
  30242. }
  30243. return ! quitMessageReceived;
  30244. }
  30245. #endif
  30246. void MessageManager::deliverBroadcastMessage (const String& value)
  30247. {
  30248. if (broadcastListeners != 0)
  30249. broadcastListeners->sendActionMessage (value);
  30250. }
  30251. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30252. {
  30253. if (broadcastListeners == 0)
  30254. broadcastListeners = new ActionListenerList();
  30255. broadcastListeners->addActionListener (listener);
  30256. }
  30257. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30258. {
  30259. if (broadcastListeners != 0)
  30260. broadcastListeners->removeActionListener (listener);
  30261. }
  30262. bool MessageManager::isThisTheMessageThread() const throw()
  30263. {
  30264. return Thread::getCurrentThreadId() == messageThreadId;
  30265. }
  30266. void MessageManager::setCurrentThreadAsMessageThread()
  30267. {
  30268. if (messageThreadId != Thread::getCurrentThreadId())
  30269. {
  30270. messageThreadId = Thread::getCurrentThreadId();
  30271. // This is needed on windows to make sure the message window is created by this thread
  30272. doPlatformSpecificShutdown();
  30273. doPlatformSpecificInitialisation();
  30274. }
  30275. }
  30276. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30277. {
  30278. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30279. return thisThread == messageThreadId || thisThread == threadWithLock;
  30280. }
  30281. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30282. {
  30283. public:
  30284. SharedEvents() {}
  30285. ~SharedEvents() {}
  30286. WaitableEvent lockedEvent, releaseEvent;
  30287. private:
  30288. SharedEvents (const SharedEvents&);
  30289. SharedEvents& operator= (const SharedEvents&);
  30290. };
  30291. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30292. {
  30293. public:
  30294. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30295. ~BlockingMessage() throw() {}
  30296. void messageCallback()
  30297. {
  30298. events->lockedEvent.signal();
  30299. events->releaseEvent.wait();
  30300. }
  30301. juce_UseDebuggingNewOperator
  30302. private:
  30303. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30304. BlockingMessage (const BlockingMessage&);
  30305. BlockingMessage& operator= (const BlockingMessage&);
  30306. };
  30307. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30308. : sharedEvents (0),
  30309. locked (false)
  30310. {
  30311. init (threadToCheck, 0);
  30312. }
  30313. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30314. : sharedEvents (0),
  30315. locked (false)
  30316. {
  30317. init (0, jobToCheckForExitSignal);
  30318. }
  30319. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30320. {
  30321. if (MessageManager::instance != 0)
  30322. {
  30323. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30324. {
  30325. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30326. }
  30327. else
  30328. {
  30329. if (threadToCheck == 0 && job == 0)
  30330. {
  30331. MessageManager::instance->lockingLock.enter();
  30332. }
  30333. else
  30334. {
  30335. while (! MessageManager::instance->lockingLock.tryEnter())
  30336. {
  30337. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30338. || (job != 0 && job->shouldExit()))
  30339. return;
  30340. Thread::sleep (1);
  30341. }
  30342. }
  30343. sharedEvents = new SharedEvents();
  30344. sharedEvents->incReferenceCount();
  30345. (new BlockingMessage (sharedEvents))->post();
  30346. while (! sharedEvents->lockedEvent.wait (50))
  30347. {
  30348. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30349. || (job != 0 && job->shouldExit()))
  30350. {
  30351. sharedEvents->releaseEvent.signal();
  30352. sharedEvents->decReferenceCount();
  30353. sharedEvents = 0;
  30354. MessageManager::instance->lockingLock.exit();
  30355. return;
  30356. }
  30357. }
  30358. jassert (MessageManager::instance->threadWithLock == 0);
  30359. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30360. locked = true;
  30361. }
  30362. }
  30363. }
  30364. MessageManagerLock::~MessageManagerLock() throw()
  30365. {
  30366. if (sharedEvents != 0)
  30367. {
  30368. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30369. sharedEvents->releaseEvent.signal();
  30370. sharedEvents->decReferenceCount();
  30371. if (MessageManager::instance != 0)
  30372. {
  30373. MessageManager::instance->threadWithLock = 0;
  30374. MessageManager::instance->lockingLock.exit();
  30375. }
  30376. }
  30377. }
  30378. END_JUCE_NAMESPACE
  30379. /*** End of inlined file: juce_MessageManager.cpp ***/
  30380. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30381. BEGIN_JUCE_NAMESPACE
  30382. class MultiTimer::MultiTimerCallback : public Timer
  30383. {
  30384. public:
  30385. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30386. : timerId (timerId_),
  30387. owner (owner_)
  30388. {
  30389. }
  30390. ~MultiTimerCallback()
  30391. {
  30392. }
  30393. void timerCallback()
  30394. {
  30395. owner.timerCallback (timerId);
  30396. }
  30397. const int timerId;
  30398. private:
  30399. MultiTimer& owner;
  30400. };
  30401. MultiTimer::MultiTimer() throw()
  30402. {
  30403. }
  30404. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30405. {
  30406. }
  30407. MultiTimer::~MultiTimer()
  30408. {
  30409. const ScopedLock sl (timerListLock);
  30410. timers.clear();
  30411. }
  30412. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30413. {
  30414. const ScopedLock sl (timerListLock);
  30415. for (int i = timers.size(); --i >= 0;)
  30416. {
  30417. MultiTimerCallback* const t = timers.getUnchecked(i);
  30418. if (t->timerId == timerId)
  30419. {
  30420. t->startTimer (intervalInMilliseconds);
  30421. return;
  30422. }
  30423. }
  30424. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30425. timers.add (newTimer);
  30426. newTimer->startTimer (intervalInMilliseconds);
  30427. }
  30428. void MultiTimer::stopTimer (const int timerId) throw()
  30429. {
  30430. const ScopedLock sl (timerListLock);
  30431. for (int i = timers.size(); --i >= 0;)
  30432. {
  30433. MultiTimerCallback* const t = timers.getUnchecked(i);
  30434. if (t->timerId == timerId)
  30435. t->stopTimer();
  30436. }
  30437. }
  30438. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30439. {
  30440. const ScopedLock sl (timerListLock);
  30441. for (int i = timers.size(); --i >= 0;)
  30442. {
  30443. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30444. if (t->timerId == timerId)
  30445. return t->isTimerRunning();
  30446. }
  30447. return false;
  30448. }
  30449. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30450. {
  30451. const ScopedLock sl (timerListLock);
  30452. for (int i = timers.size(); --i >= 0;)
  30453. {
  30454. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30455. if (t->timerId == timerId)
  30456. return t->getTimerInterval();
  30457. }
  30458. return 0;
  30459. }
  30460. END_JUCE_NAMESPACE
  30461. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30462. /*** Start of inlined file: juce_Timer.cpp ***/
  30463. BEGIN_JUCE_NAMESPACE
  30464. class InternalTimerThread : private Thread,
  30465. private MessageListener,
  30466. private DeletedAtShutdown,
  30467. private AsyncUpdater
  30468. {
  30469. public:
  30470. InternalTimerThread()
  30471. : Thread ("Juce Timer"),
  30472. firstTimer (0),
  30473. callbackNeeded (false)
  30474. {
  30475. triggerAsyncUpdate();
  30476. }
  30477. ~InternalTimerThread() throw()
  30478. {
  30479. stopThread (4000);
  30480. jassert (instance == this || instance == 0);
  30481. if (instance == this)
  30482. instance = 0;
  30483. }
  30484. void run()
  30485. {
  30486. uint32 lastTime = Time::getMillisecondCounter();
  30487. while (! threadShouldExit())
  30488. {
  30489. const uint32 now = Time::getMillisecondCounter();
  30490. if (now <= lastTime)
  30491. {
  30492. wait (2);
  30493. continue;
  30494. }
  30495. const int elapsed = now - lastTime;
  30496. lastTime = now;
  30497. int timeUntilFirstTimer = 1000;
  30498. {
  30499. const ScopedLock sl (lock);
  30500. decrementAllCounters (elapsed);
  30501. if (firstTimer != 0)
  30502. timeUntilFirstTimer = firstTimer->countdownMs;
  30503. }
  30504. if (timeUntilFirstTimer <= 0)
  30505. {
  30506. if (callbackNeeded.set (true))
  30507. {
  30508. postMessage (new Message());
  30509. const uint32 messageDeliveryTimeout = now + 2000;
  30510. while (callbackNeeded.get())
  30511. {
  30512. wait (4);
  30513. if (threadShouldExit())
  30514. return;
  30515. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30516. break;
  30517. }
  30518. }
  30519. }
  30520. else
  30521. {
  30522. // don't wait for too long because running this loop also helps keep the
  30523. // Time::getApproximateMillisecondTimer value stay up-to-date
  30524. wait (jlimit (1, 50, timeUntilFirstTimer));
  30525. }
  30526. }
  30527. }
  30528. void callTimers()
  30529. {
  30530. const ScopedLock sl (lock);
  30531. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30532. {
  30533. Timer* const t = firstTimer;
  30534. t->countdownMs = t->periodMs;
  30535. removeTimer (t);
  30536. addTimer (t);
  30537. const ScopedUnlock ul (lock);
  30538. JUCE_TRY
  30539. {
  30540. t->timerCallback();
  30541. }
  30542. JUCE_CATCH_EXCEPTION
  30543. }
  30544. callbackNeeded.set (false);
  30545. }
  30546. void handleMessage (const Message&)
  30547. {
  30548. callTimers();
  30549. }
  30550. void callTimersSynchronously()
  30551. {
  30552. if (! isThreadRunning())
  30553. {
  30554. // (This is relied on by some plugins in cases where the MM has
  30555. // had to restart and the async callback never started)
  30556. cancelPendingUpdate();
  30557. triggerAsyncUpdate();
  30558. }
  30559. callTimers();
  30560. }
  30561. static void callAnyTimersSynchronously()
  30562. {
  30563. if (InternalTimerThread::instance != 0)
  30564. InternalTimerThread::instance->callTimersSynchronously();
  30565. }
  30566. static inline void add (Timer* const tim) throw()
  30567. {
  30568. if (instance == 0)
  30569. instance = new InternalTimerThread();
  30570. const ScopedLock sl (instance->lock);
  30571. instance->addTimer (tim);
  30572. }
  30573. static inline void remove (Timer* const tim) throw()
  30574. {
  30575. if (instance != 0)
  30576. {
  30577. const ScopedLock sl (instance->lock);
  30578. instance->removeTimer (tim);
  30579. }
  30580. }
  30581. static inline void resetCounter (Timer* const tim,
  30582. const int newCounter) throw()
  30583. {
  30584. if (instance != 0)
  30585. {
  30586. tim->countdownMs = newCounter;
  30587. tim->periodMs = newCounter;
  30588. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30589. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30590. {
  30591. const ScopedLock sl (instance->lock);
  30592. instance->removeTimer (tim);
  30593. instance->addTimer (tim);
  30594. }
  30595. }
  30596. }
  30597. private:
  30598. friend class Timer;
  30599. static InternalTimerThread* instance;
  30600. static CriticalSection lock;
  30601. Timer* volatile firstTimer;
  30602. class AtomicBool
  30603. {
  30604. public:
  30605. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30606. ~AtomicBool() throw() {}
  30607. bool get() const throw() { return value != 0; }
  30608. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30609. private:
  30610. int32 value;
  30611. AtomicBool (const AtomicBool&);
  30612. AtomicBool& operator= (const AtomicBool&);
  30613. };
  30614. AtomicBool callbackNeeded;
  30615. void addTimer (Timer* const t) throw()
  30616. {
  30617. #ifdef JUCE_DEBUG
  30618. Timer* tt = firstTimer;
  30619. while (tt != 0)
  30620. {
  30621. // trying to add a timer that's already here - shouldn't get to this point,
  30622. // so if you get this assertion, let me know!
  30623. jassert (tt != t);
  30624. tt = tt->next;
  30625. }
  30626. jassert (t->previous == 0 && t->next == 0);
  30627. #endif
  30628. Timer* i = firstTimer;
  30629. if (i == 0 || i->countdownMs > t->countdownMs)
  30630. {
  30631. t->next = firstTimer;
  30632. firstTimer = t;
  30633. }
  30634. else
  30635. {
  30636. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30637. i = i->next;
  30638. jassert (i != 0);
  30639. t->next = i->next;
  30640. t->previous = i;
  30641. i->next = t;
  30642. }
  30643. if (t->next != 0)
  30644. t->next->previous = t;
  30645. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30646. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30647. notify();
  30648. }
  30649. void removeTimer (Timer* const t) throw()
  30650. {
  30651. #ifdef JUCE_DEBUG
  30652. Timer* tt = firstTimer;
  30653. bool found = false;
  30654. while (tt != 0)
  30655. {
  30656. if (tt == t)
  30657. {
  30658. found = true;
  30659. break;
  30660. }
  30661. tt = tt->next;
  30662. }
  30663. // trying to remove a timer that's not here - shouldn't get to this point,
  30664. // so if you get this assertion, let me know!
  30665. jassert (found);
  30666. #endif
  30667. if (t->previous != 0)
  30668. {
  30669. jassert (firstTimer != t);
  30670. t->previous->next = t->next;
  30671. }
  30672. else
  30673. {
  30674. jassert (firstTimer == t);
  30675. firstTimer = t->next;
  30676. }
  30677. if (t->next != 0)
  30678. t->next->previous = t->previous;
  30679. t->next = 0;
  30680. t->previous = 0;
  30681. }
  30682. void decrementAllCounters (const int numMillisecs) const
  30683. {
  30684. Timer* t = firstTimer;
  30685. while (t != 0)
  30686. {
  30687. t->countdownMs -= numMillisecs;
  30688. t = t->next;
  30689. }
  30690. }
  30691. void handleAsyncUpdate()
  30692. {
  30693. startThread (7);
  30694. }
  30695. InternalTimerThread (const InternalTimerThread&);
  30696. InternalTimerThread& operator= (const InternalTimerThread&);
  30697. };
  30698. InternalTimerThread* InternalTimerThread::instance = 0;
  30699. CriticalSection InternalTimerThread::lock;
  30700. void juce_callAnyTimersSynchronously()
  30701. {
  30702. InternalTimerThread::callAnyTimersSynchronously();
  30703. }
  30704. #ifdef JUCE_DEBUG
  30705. static SortedSet <Timer*> activeTimers;
  30706. #endif
  30707. Timer::Timer() throw()
  30708. : countdownMs (0),
  30709. periodMs (0),
  30710. previous (0),
  30711. next (0)
  30712. {
  30713. #ifdef JUCE_DEBUG
  30714. activeTimers.add (this);
  30715. #endif
  30716. }
  30717. Timer::Timer (const Timer&) throw()
  30718. : countdownMs (0),
  30719. periodMs (0),
  30720. previous (0),
  30721. next (0)
  30722. {
  30723. #ifdef JUCE_DEBUG
  30724. activeTimers.add (this);
  30725. #endif
  30726. }
  30727. Timer::~Timer()
  30728. {
  30729. stopTimer();
  30730. #ifdef JUCE_DEBUG
  30731. activeTimers.removeValue (this);
  30732. #endif
  30733. }
  30734. void Timer::startTimer (const int interval) throw()
  30735. {
  30736. const ScopedLock sl (InternalTimerThread::lock);
  30737. #ifdef JUCE_DEBUG
  30738. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30739. jassert (activeTimers.contains (this));
  30740. #endif
  30741. if (periodMs == 0)
  30742. {
  30743. countdownMs = interval;
  30744. periodMs = jmax (1, interval);
  30745. InternalTimerThread::add (this);
  30746. }
  30747. else
  30748. {
  30749. InternalTimerThread::resetCounter (this, interval);
  30750. }
  30751. }
  30752. void Timer::stopTimer() throw()
  30753. {
  30754. const ScopedLock sl (InternalTimerThread::lock);
  30755. #ifdef JUCE_DEBUG
  30756. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30757. jassert (activeTimers.contains (this));
  30758. #endif
  30759. if (periodMs > 0)
  30760. {
  30761. InternalTimerThread::remove (this);
  30762. periodMs = 0;
  30763. }
  30764. }
  30765. END_JUCE_NAMESPACE
  30766. /*** End of inlined file: juce_Timer.cpp ***/
  30767. #endif
  30768. #if JUCE_BUILD_GUI
  30769. /*** Start of inlined file: juce_Component.cpp ***/
  30770. BEGIN_JUCE_NAMESPACE
  30771. Component* Component::currentlyFocusedComponent = 0;
  30772. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30773. static Array <int> modalReturnValues;
  30774. enum ComponentMessageNumbers
  30775. {
  30776. customCommandMessage = 0x7fff0001,
  30777. exitModalStateMessage = 0x7fff0002
  30778. };
  30779. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30780. static uint32 nextComponentUID = 0;
  30781. Component::Component()
  30782. : parentComponent_ (0),
  30783. componentUID (++nextComponentUID),
  30784. numDeepMouseListeners (0),
  30785. lookAndFeel_ (0),
  30786. effect_ (0),
  30787. bufferedImage_ (0),
  30788. mouseListeners_ (0),
  30789. keyListeners_ (0),
  30790. componentFlags_ (0)
  30791. {
  30792. }
  30793. Component::Component (const String& name)
  30794. : componentName_ (name),
  30795. parentComponent_ (0),
  30796. componentUID (++nextComponentUID),
  30797. numDeepMouseListeners (0),
  30798. lookAndFeel_ (0),
  30799. effect_ (0),
  30800. bufferedImage_ (0),
  30801. mouseListeners_ (0),
  30802. keyListeners_ (0),
  30803. componentFlags_ (0)
  30804. {
  30805. }
  30806. Component::~Component()
  30807. {
  30808. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30809. if (parentComponent_ != 0)
  30810. {
  30811. parentComponent_->removeChildComponent (this);
  30812. }
  30813. else if ((currentlyFocusedComponent == this)
  30814. || isParentOf (currentlyFocusedComponent))
  30815. {
  30816. giveAwayFocus();
  30817. }
  30818. if (flags.hasHeavyweightPeerFlag)
  30819. removeFromDesktop();
  30820. modalComponentStack.removeValue (this);
  30821. for (int i = childComponentList_.size(); --i >= 0;)
  30822. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30823. delete bufferedImage_;
  30824. delete mouseListeners_;
  30825. delete keyListeners_;
  30826. }
  30827. void Component::setName (const String& name)
  30828. {
  30829. // if component methods are being called from threads other than the message
  30830. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30831. checkMessageManagerIsLocked
  30832. if (componentName_ != name)
  30833. {
  30834. componentName_ = name;
  30835. if (flags.hasHeavyweightPeerFlag)
  30836. {
  30837. ComponentPeer* const peer = getPeer();
  30838. jassert (peer != 0);
  30839. if (peer != 0)
  30840. peer->setTitle (name);
  30841. }
  30842. BailOutChecker checker (this);
  30843. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30844. }
  30845. }
  30846. void Component::setVisible (bool shouldBeVisible)
  30847. {
  30848. if (flags.visibleFlag != shouldBeVisible)
  30849. {
  30850. // if component methods are being called from threads other than the message
  30851. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30852. checkMessageManagerIsLocked
  30853. SafePointer<Component> safePointer (this);
  30854. flags.visibleFlag = shouldBeVisible;
  30855. internalRepaint (0, 0, getWidth(), getHeight());
  30856. sendFakeMouseMove();
  30857. if (! shouldBeVisible)
  30858. {
  30859. if (currentlyFocusedComponent == this
  30860. || isParentOf (currentlyFocusedComponent))
  30861. {
  30862. if (parentComponent_ != 0)
  30863. parentComponent_->grabKeyboardFocus();
  30864. else
  30865. giveAwayFocus();
  30866. }
  30867. }
  30868. if (safePointer != 0)
  30869. {
  30870. sendVisibilityChangeMessage();
  30871. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30872. {
  30873. ComponentPeer* const peer = getPeer();
  30874. jassert (peer != 0);
  30875. if (peer != 0)
  30876. {
  30877. peer->setVisible (shouldBeVisible);
  30878. internalHierarchyChanged();
  30879. }
  30880. }
  30881. }
  30882. }
  30883. }
  30884. void Component::visibilityChanged()
  30885. {
  30886. }
  30887. void Component::sendVisibilityChangeMessage()
  30888. {
  30889. BailOutChecker checker (this);
  30890. visibilityChanged();
  30891. if (! checker.shouldBailOut())
  30892. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  30893. }
  30894. bool Component::isShowing() const
  30895. {
  30896. if (flags.visibleFlag)
  30897. {
  30898. if (parentComponent_ != 0)
  30899. {
  30900. return parentComponent_->isShowing();
  30901. }
  30902. else
  30903. {
  30904. const ComponentPeer* const peer = getPeer();
  30905. return peer != 0 && ! peer->isMinimised();
  30906. }
  30907. }
  30908. return false;
  30909. }
  30910. class FadeOutProxyComponent : public Component,
  30911. public Timer
  30912. {
  30913. public:
  30914. FadeOutProxyComponent (Component* comp,
  30915. const int fadeLengthMs,
  30916. const int deltaXToMove,
  30917. const int deltaYToMove,
  30918. const float scaleFactorAtEnd)
  30919. : lastTime (0),
  30920. alpha (1.0f),
  30921. scale (1.0f)
  30922. {
  30923. image = comp->createComponentSnapshot (comp->getLocalBounds());
  30924. setBounds (comp->getBounds());
  30925. comp->getParentComponent()->addAndMakeVisible (this);
  30926. toBehind (comp);
  30927. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  30928. centreX = comp->getX() + comp->getWidth() * 0.5f;
  30929. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  30930. centreY = comp->getY() + comp->getHeight() * 0.5f;
  30931. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  30932. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  30933. setInterceptsMouseClicks (false, false);
  30934. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  30935. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  30936. }
  30937. ~FadeOutProxyComponent()
  30938. {
  30939. delete image;
  30940. }
  30941. void paint (Graphics& g)
  30942. {
  30943. g.setOpacity (alpha);
  30944. g.drawImage (image,
  30945. 0, 0, getWidth(), getHeight(),
  30946. 0, 0, image->getWidth(), image->getHeight());
  30947. }
  30948. void timerCallback()
  30949. {
  30950. const uint32 now = Time::getMillisecondCounter();
  30951. if (lastTime == 0)
  30952. lastTime = now;
  30953. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  30954. lastTime = now;
  30955. alpha += alphaChangePerMs * msPassed;
  30956. if (alpha > 0)
  30957. {
  30958. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  30959. {
  30960. centreX += xChangePerMs * msPassed;
  30961. centreY += yChangePerMs * msPassed;
  30962. scale += scaleChangePerMs * msPassed;
  30963. const int w = roundToInt (image->getWidth() * scale);
  30964. const int h = roundToInt (image->getHeight() * scale);
  30965. setBounds (roundToInt (centreX) - w / 2,
  30966. roundToInt (centreY) - h / 2,
  30967. w, h);
  30968. }
  30969. repaint();
  30970. }
  30971. else
  30972. {
  30973. delete this;
  30974. }
  30975. }
  30976. juce_UseDebuggingNewOperator
  30977. private:
  30978. Image* image;
  30979. uint32 lastTime;
  30980. float alpha, alphaChangePerMs;
  30981. float centreX, xChangePerMs;
  30982. float centreY, yChangePerMs;
  30983. float scale, scaleChangePerMs;
  30984. FadeOutProxyComponent (const FadeOutProxyComponent&);
  30985. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  30986. };
  30987. void Component::fadeOutComponent (const int millisecondsToFade,
  30988. const int deltaXToMove,
  30989. const int deltaYToMove,
  30990. const float scaleFactorAtEnd)
  30991. {
  30992. //xxx won't work for comps without parents
  30993. if (isShowing() && millisecondsToFade > 0)
  30994. new FadeOutProxyComponent (this, millisecondsToFade,
  30995. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  30996. setVisible (false);
  30997. }
  30998. bool Component::isValidComponent() const
  30999. {
  31000. return (this != 0) && isValidMessageListener();
  31001. }
  31002. void* Component::getWindowHandle() const
  31003. {
  31004. const ComponentPeer* const peer = getPeer();
  31005. if (peer != 0)
  31006. return peer->getNativeHandle();
  31007. return 0;
  31008. }
  31009. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31010. {
  31011. // if component methods are being called from threads other than the message
  31012. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31013. checkMessageManagerIsLocked
  31014. if (isOpaque())
  31015. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31016. else
  31017. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31018. int currentStyleFlags = 0;
  31019. // don't use getPeer(), so that we only get the peer that's specifically
  31020. // for this comp, and not for one of its parents.
  31021. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31022. if (peer != 0)
  31023. currentStyleFlags = peer->getStyleFlags();
  31024. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31025. {
  31026. SafePointer<Component> safePointer (this);
  31027. #if JUCE_LINUX
  31028. // it's wise to give the component a non-zero size before
  31029. // putting it on the desktop, as X windows get confused by this, and
  31030. // a (1, 1) minimum size is enforced here.
  31031. setSize (jmax (1, getWidth()),
  31032. jmax (1, getHeight()));
  31033. #endif
  31034. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31035. bool wasFullscreen = false;
  31036. bool wasMinimised = false;
  31037. ComponentBoundsConstrainer* currentConstainer = 0;
  31038. Rectangle<int> oldNonFullScreenBounds;
  31039. if (peer != 0)
  31040. {
  31041. wasFullscreen = peer->isFullScreen();
  31042. wasMinimised = peer->isMinimised();
  31043. currentConstainer = peer->getConstrainer();
  31044. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31045. removeFromDesktop();
  31046. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31047. }
  31048. if (parentComponent_ != 0)
  31049. parentComponent_->removeChildComponent (this);
  31050. if (safePointer != 0)
  31051. {
  31052. flags.hasHeavyweightPeerFlag = true;
  31053. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31054. Desktop::getInstance().addDesktopComponent (this);
  31055. bounds_.setPosition (topLeft);
  31056. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31057. peer->setVisible (isVisible());
  31058. if (wasFullscreen)
  31059. {
  31060. peer->setFullScreen (true);
  31061. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31062. }
  31063. if (wasMinimised)
  31064. peer->setMinimised (true);
  31065. if (isAlwaysOnTop())
  31066. peer->setAlwaysOnTop (true);
  31067. peer->setConstrainer (currentConstainer);
  31068. repaint();
  31069. }
  31070. internalHierarchyChanged();
  31071. }
  31072. }
  31073. void Component::removeFromDesktop()
  31074. {
  31075. // if component methods are being called from threads other than the message
  31076. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31077. checkMessageManagerIsLocked
  31078. if (flags.hasHeavyweightPeerFlag)
  31079. {
  31080. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31081. flags.hasHeavyweightPeerFlag = false;
  31082. jassert (peer != 0);
  31083. delete peer;
  31084. Desktop::getInstance().removeDesktopComponent (this);
  31085. }
  31086. }
  31087. bool Component::isOnDesktop() const throw()
  31088. {
  31089. return flags.hasHeavyweightPeerFlag;
  31090. }
  31091. void Component::userTriedToCloseWindow()
  31092. {
  31093. /* This means that the user's trying to get rid of your window with the 'close window' system
  31094. menu option (on windows) or possibly the task manager - you should really handle this
  31095. and delete or hide your component in an appropriate way.
  31096. If you want to ignore the event and don't want to trigger this assertion, just override
  31097. this method and do nothing.
  31098. */
  31099. jassertfalse
  31100. }
  31101. void Component::minimisationStateChanged (bool)
  31102. {
  31103. }
  31104. void Component::setOpaque (const bool shouldBeOpaque)
  31105. {
  31106. if (shouldBeOpaque != flags.opaqueFlag)
  31107. {
  31108. flags.opaqueFlag = shouldBeOpaque;
  31109. if (flags.hasHeavyweightPeerFlag)
  31110. {
  31111. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31112. if (peer != 0)
  31113. {
  31114. // to make it recreate the heavyweight window
  31115. addToDesktop (peer->getStyleFlags());
  31116. }
  31117. }
  31118. repaint();
  31119. }
  31120. }
  31121. bool Component::isOpaque() const throw()
  31122. {
  31123. return flags.opaqueFlag;
  31124. }
  31125. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31126. {
  31127. if (shouldBeBuffered != flags.bufferToImageFlag)
  31128. {
  31129. deleteAndZero (bufferedImage_);
  31130. flags.bufferToImageFlag = shouldBeBuffered;
  31131. }
  31132. }
  31133. void Component::toFront (const bool setAsForeground)
  31134. {
  31135. // if component methods are being called from threads other than the message
  31136. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31137. checkMessageManagerIsLocked
  31138. if (flags.hasHeavyweightPeerFlag)
  31139. {
  31140. ComponentPeer* const peer = getPeer();
  31141. if (peer != 0)
  31142. {
  31143. peer->toFront (setAsForeground);
  31144. if (setAsForeground && ! hasKeyboardFocus (true))
  31145. grabKeyboardFocus();
  31146. }
  31147. }
  31148. else if (parentComponent_ != 0)
  31149. {
  31150. if (parentComponent_->childComponentList_.getLast() != this)
  31151. {
  31152. const int index = parentComponent_->childComponentList_.indexOf (this);
  31153. if (index >= 0)
  31154. {
  31155. int insertIndex = -1;
  31156. if (! flags.alwaysOnTopFlag)
  31157. {
  31158. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31159. while (insertIndex > 0
  31160. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31161. {
  31162. --insertIndex;
  31163. }
  31164. }
  31165. if (index != insertIndex)
  31166. {
  31167. parentComponent_->childComponentList_.move (index, insertIndex);
  31168. sendFakeMouseMove();
  31169. repaintParent();
  31170. }
  31171. }
  31172. }
  31173. if (setAsForeground)
  31174. {
  31175. internalBroughtToFront();
  31176. grabKeyboardFocus();
  31177. }
  31178. }
  31179. }
  31180. void Component::toBehind (Component* const other)
  31181. {
  31182. if (other != 0)
  31183. {
  31184. // the two components must belong to the same parent..
  31185. jassert (parentComponent_ == other->parentComponent_);
  31186. if (parentComponent_ != 0)
  31187. {
  31188. const int index = parentComponent_->childComponentList_.indexOf (this);
  31189. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31190. if (index >= 0
  31191. && otherIndex >= 0
  31192. && index != otherIndex - 1
  31193. && other != this)
  31194. {
  31195. if (index < otherIndex)
  31196. --otherIndex;
  31197. parentComponent_->childComponentList_.move (index, otherIndex);
  31198. sendFakeMouseMove();
  31199. repaintParent();
  31200. }
  31201. }
  31202. else if (isOnDesktop())
  31203. {
  31204. jassert (other->isOnDesktop());
  31205. if (other->isOnDesktop())
  31206. {
  31207. ComponentPeer* const us = getPeer();
  31208. ComponentPeer* const them = other->getPeer();
  31209. jassert (us != 0 && them != 0);
  31210. if (us != 0 && them != 0)
  31211. us->toBehind (them);
  31212. }
  31213. }
  31214. }
  31215. }
  31216. void Component::toBack()
  31217. {
  31218. if (isOnDesktop())
  31219. {
  31220. jassertfalse //xxx need to add this to native window
  31221. }
  31222. else if (parentComponent_ != 0
  31223. && parentComponent_->childComponentList_.getFirst() != this)
  31224. {
  31225. const int index = parentComponent_->childComponentList_.indexOf (this);
  31226. if (index > 0)
  31227. {
  31228. int insertIndex = 0;
  31229. if (flags.alwaysOnTopFlag)
  31230. {
  31231. while (insertIndex < parentComponent_->childComponentList_.size()
  31232. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31233. {
  31234. ++insertIndex;
  31235. }
  31236. }
  31237. if (index != insertIndex)
  31238. {
  31239. parentComponent_->childComponentList_.move (index, insertIndex);
  31240. sendFakeMouseMove();
  31241. repaintParent();
  31242. }
  31243. }
  31244. }
  31245. }
  31246. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31247. {
  31248. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31249. {
  31250. flags.alwaysOnTopFlag = shouldStayOnTop;
  31251. if (isOnDesktop())
  31252. {
  31253. ComponentPeer* const peer = getPeer();
  31254. jassert (peer != 0);
  31255. if (peer != 0)
  31256. {
  31257. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31258. {
  31259. // some kinds of peer can't change their always-on-top status, so
  31260. // for these, we'll need to create a new window
  31261. const int oldFlags = peer->getStyleFlags();
  31262. removeFromDesktop();
  31263. addToDesktop (oldFlags);
  31264. }
  31265. }
  31266. }
  31267. if (shouldStayOnTop)
  31268. toFront (false);
  31269. internalHierarchyChanged();
  31270. }
  31271. }
  31272. bool Component::isAlwaysOnTop() const throw()
  31273. {
  31274. return flags.alwaysOnTopFlag;
  31275. }
  31276. int Component::proportionOfWidth (const float proportion) const throw()
  31277. {
  31278. return roundToInt (proportion * bounds_.getWidth());
  31279. }
  31280. int Component::proportionOfHeight (const float proportion) const throw()
  31281. {
  31282. return roundToInt (proportion * bounds_.getHeight());
  31283. }
  31284. int Component::getParentWidth() const throw()
  31285. {
  31286. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31287. : getParentMonitorArea().getWidth();
  31288. }
  31289. int Component::getParentHeight() const throw()
  31290. {
  31291. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31292. : getParentMonitorArea().getHeight();
  31293. }
  31294. int Component::getScreenX() const
  31295. {
  31296. return getScreenPosition().getX();
  31297. }
  31298. int Component::getScreenY() const
  31299. {
  31300. return getScreenPosition().getY();
  31301. }
  31302. const Point<int> Component::getScreenPosition() const
  31303. {
  31304. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31305. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31306. : getPosition());
  31307. }
  31308. const Rectangle<int> Component::getScreenBounds() const
  31309. {
  31310. return bounds_.withPosition (getScreenPosition());
  31311. }
  31312. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31313. {
  31314. const Component* c = this;
  31315. Point<int> p (relativePosition);
  31316. do
  31317. {
  31318. if (c->flags.hasHeavyweightPeerFlag)
  31319. return c->getPeer()->relativePositionToGlobal (p);
  31320. p += c->getPosition();
  31321. c = c->parentComponent_;
  31322. }
  31323. while (c != 0);
  31324. return p;
  31325. }
  31326. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31327. {
  31328. if (flags.hasHeavyweightPeerFlag)
  31329. {
  31330. return getPeer()->globalPositionToRelative (screenPosition);
  31331. }
  31332. else
  31333. {
  31334. if (parentComponent_ != 0)
  31335. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31336. return screenPosition - getPosition();
  31337. }
  31338. }
  31339. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31340. {
  31341. Point<int> p (positionRelativeToThis);
  31342. if (targetComponent != 0)
  31343. {
  31344. const Component* c = this;
  31345. do
  31346. {
  31347. if (c == targetComponent)
  31348. return p;
  31349. if (c->flags.hasHeavyweightPeerFlag)
  31350. {
  31351. p = c->getPeer()->relativePositionToGlobal (p);
  31352. break;
  31353. }
  31354. p += c->getPosition();
  31355. c = c->parentComponent_;
  31356. }
  31357. while (c != 0);
  31358. p = targetComponent->globalPositionToRelative (p);
  31359. }
  31360. return p;
  31361. }
  31362. void Component::setBounds (int x, int y, int w, int h)
  31363. {
  31364. // if component methods are being called from threads other than the message
  31365. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31366. checkMessageManagerIsLocked
  31367. if (w < 0) w = 0;
  31368. if (h < 0) h = 0;
  31369. const bool wasResized = (getWidth() != w || getHeight() != h);
  31370. const bool wasMoved = (getX() != x || getY() != y);
  31371. #ifdef JUCE_DEBUG
  31372. // It's a very bad idea to try to resize a window during its paint() method!
  31373. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31374. #endif
  31375. if (wasMoved || wasResized)
  31376. {
  31377. if (flags.visibleFlag)
  31378. {
  31379. // send a fake mouse move to trigger enter/exit messages if needed..
  31380. sendFakeMouseMove();
  31381. if (! flags.hasHeavyweightPeerFlag)
  31382. repaintParent();
  31383. }
  31384. bounds_.setBounds (x, y, w, h);
  31385. if (wasResized)
  31386. repaint();
  31387. else if (! flags.hasHeavyweightPeerFlag)
  31388. repaintParent();
  31389. if (flags.hasHeavyweightPeerFlag)
  31390. {
  31391. ComponentPeer* const peer = getPeer();
  31392. if (peer != 0)
  31393. {
  31394. if (wasMoved && wasResized)
  31395. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31396. else if (wasMoved)
  31397. peer->setPosition (getX(), getY());
  31398. else if (wasResized)
  31399. peer->setSize (getWidth(), getHeight());
  31400. }
  31401. }
  31402. sendMovedResizedMessages (wasMoved, wasResized);
  31403. }
  31404. }
  31405. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31406. {
  31407. JUCE_TRY
  31408. {
  31409. if (wasMoved)
  31410. moved();
  31411. if (wasResized)
  31412. {
  31413. resized();
  31414. for (int i = childComponentList_.size(); --i >= 0;)
  31415. {
  31416. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31417. i = jmin (i, childComponentList_.size());
  31418. }
  31419. }
  31420. BailOutChecker checker (this);
  31421. if (parentComponent_ != 0)
  31422. parentComponent_->childBoundsChanged (this);
  31423. if (! checker.shouldBailOut())
  31424. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31425. *this, wasMoved, wasResized);
  31426. }
  31427. JUCE_CATCH_EXCEPTION
  31428. }
  31429. void Component::setSize (const int w, const int h)
  31430. {
  31431. setBounds (getX(), getY(), w, h);
  31432. }
  31433. void Component::setTopLeftPosition (const int x, const int y)
  31434. {
  31435. setBounds (x, y, getWidth(), getHeight());
  31436. }
  31437. void Component::setTopRightPosition (const int x, const int y)
  31438. {
  31439. setTopLeftPosition (x - getWidth(), y);
  31440. }
  31441. void Component::setBounds (const Rectangle<int>& r)
  31442. {
  31443. setBounds (r.getX(),
  31444. r.getY(),
  31445. r.getWidth(),
  31446. r.getHeight());
  31447. }
  31448. void Component::setBoundsRelative (const float x, const float y,
  31449. const float w, const float h)
  31450. {
  31451. const int pw = getParentWidth();
  31452. const int ph = getParentHeight();
  31453. setBounds (roundToInt (x * pw),
  31454. roundToInt (y * ph),
  31455. roundToInt (w * pw),
  31456. roundToInt (h * ph));
  31457. }
  31458. void Component::setCentrePosition (const int x, const int y)
  31459. {
  31460. setTopLeftPosition (x - getWidth() / 2,
  31461. y - getHeight() / 2);
  31462. }
  31463. void Component::setCentreRelative (const float x, const float y)
  31464. {
  31465. setCentrePosition (roundToInt (getParentWidth() * x),
  31466. roundToInt (getParentHeight() * y));
  31467. }
  31468. void Component::centreWithSize (const int width, const int height)
  31469. {
  31470. setBounds ((getParentWidth() - width) / 2,
  31471. (getParentHeight() - height) / 2,
  31472. width,
  31473. height);
  31474. }
  31475. void Component::setBoundsInset (const BorderSize& borders)
  31476. {
  31477. setBounds (borders.getLeft(),
  31478. borders.getTop(),
  31479. getParentWidth() - (borders.getLeftAndRight()),
  31480. getParentHeight() - (borders.getTopAndBottom()));
  31481. }
  31482. void Component::setBoundsToFit (int x, int y, int width, int height,
  31483. const Justification& justification,
  31484. const bool onlyReduceInSize)
  31485. {
  31486. // it's no good calling this method unless both the component and
  31487. // target rectangle have a finite size.
  31488. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31489. if (getWidth() > 0 && getHeight() > 0
  31490. && width > 0 && height > 0)
  31491. {
  31492. int newW, newH;
  31493. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31494. {
  31495. newW = getWidth();
  31496. newH = getHeight();
  31497. }
  31498. else
  31499. {
  31500. const double imageRatio = getHeight() / (double) getWidth();
  31501. const double targetRatio = height / (double) width;
  31502. if (imageRatio <= targetRatio)
  31503. {
  31504. newW = width;
  31505. newH = jmin (height, roundToInt (newW * imageRatio));
  31506. }
  31507. else
  31508. {
  31509. newH = height;
  31510. newW = jmin (width, roundToInt (newH / imageRatio));
  31511. }
  31512. }
  31513. if (newW > 0 && newH > 0)
  31514. {
  31515. int newX, newY;
  31516. justification.applyToRectangle (newX, newY, newW, newH,
  31517. x, y, width, height);
  31518. setBounds (newX, newY, newW, newH);
  31519. }
  31520. }
  31521. }
  31522. bool Component::hitTest (int x, int y)
  31523. {
  31524. if (! flags.ignoresMouseClicksFlag)
  31525. return true;
  31526. if (flags.allowChildMouseClicksFlag)
  31527. {
  31528. for (int i = getNumChildComponents(); --i >= 0;)
  31529. {
  31530. Component* const c = getChildComponent (i);
  31531. if (c->isVisible()
  31532. && c->bounds_.contains (x, y)
  31533. && c->hitTest (x - c->getX(),
  31534. y - c->getY()))
  31535. {
  31536. return true;
  31537. }
  31538. }
  31539. }
  31540. return false;
  31541. }
  31542. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31543. const bool allowClicksOnChildComponents) throw()
  31544. {
  31545. flags.ignoresMouseClicksFlag = ! allowClicks;
  31546. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31547. }
  31548. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31549. bool& allowsClicksOnChildComponents) const throw()
  31550. {
  31551. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31552. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31553. }
  31554. bool Component::contains (const int x, const int y)
  31555. {
  31556. if (((unsigned int) x) < (unsigned int) getWidth()
  31557. && ((unsigned int) y) < (unsigned int) getHeight()
  31558. && hitTest (x, y))
  31559. {
  31560. if (parentComponent_ != 0)
  31561. {
  31562. return parentComponent_->contains (x + getX(),
  31563. y + getY());
  31564. }
  31565. else if (flags.hasHeavyweightPeerFlag)
  31566. {
  31567. const ComponentPeer* const peer = getPeer();
  31568. if (peer != 0)
  31569. return peer->contains (Point<int> (x, y), true);
  31570. }
  31571. }
  31572. return false;
  31573. }
  31574. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31575. {
  31576. if (! contains (x, y))
  31577. return false;
  31578. Component* p = this;
  31579. while (p->parentComponent_ != 0)
  31580. {
  31581. x += p->getX();
  31582. y += p->getY();
  31583. p = p->parentComponent_;
  31584. }
  31585. const Component* const c = p->getComponentAt (x, y);
  31586. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31587. }
  31588. Component* Component::getComponentAt (const Point<int>& position)
  31589. {
  31590. return getComponentAt (position.getX(), position.getY());
  31591. }
  31592. Component* Component::getComponentAt (const int x, const int y)
  31593. {
  31594. if (flags.visibleFlag
  31595. && ((unsigned int) x) < (unsigned int) getWidth()
  31596. && ((unsigned int) y) < (unsigned int) getHeight()
  31597. && hitTest (x, y))
  31598. {
  31599. for (int i = childComponentList_.size(); --i >= 0;)
  31600. {
  31601. Component* const child = childComponentList_.getUnchecked(i);
  31602. Component* const c = child->getComponentAt (x - child->getX(),
  31603. y - child->getY());
  31604. if (c != 0)
  31605. return c;
  31606. }
  31607. return this;
  31608. }
  31609. return 0;
  31610. }
  31611. void Component::addChildComponent (Component* const child, int zOrder)
  31612. {
  31613. // if component methods are being called from threads other than the message
  31614. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31615. checkMessageManagerIsLocked
  31616. if (child != 0 && child->parentComponent_ != this)
  31617. {
  31618. if (child->parentComponent_ != 0)
  31619. child->parentComponent_->removeChildComponent (child);
  31620. else
  31621. child->removeFromDesktop();
  31622. child->parentComponent_ = this;
  31623. if (child->isVisible())
  31624. child->repaintParent();
  31625. if (! child->isAlwaysOnTop())
  31626. {
  31627. if (zOrder < 0 || zOrder > childComponentList_.size())
  31628. zOrder = childComponentList_.size();
  31629. while (zOrder > 0)
  31630. {
  31631. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31632. break;
  31633. --zOrder;
  31634. }
  31635. }
  31636. childComponentList_.insert (zOrder, child);
  31637. child->internalHierarchyChanged();
  31638. internalChildrenChanged();
  31639. }
  31640. }
  31641. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31642. {
  31643. if (child != 0)
  31644. {
  31645. child->setVisible (true);
  31646. addChildComponent (child, zOrder);
  31647. }
  31648. }
  31649. void Component::removeChildComponent (Component* const child)
  31650. {
  31651. removeChildComponent (childComponentList_.indexOf (child));
  31652. }
  31653. Component* Component::removeChildComponent (const int index)
  31654. {
  31655. // if component methods are being called from threads other than the message
  31656. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31657. checkMessageManagerIsLocked
  31658. Component* const child = childComponentList_ [index];
  31659. if (child != 0)
  31660. {
  31661. sendFakeMouseMove();
  31662. child->repaintParent();
  31663. childComponentList_.remove (index);
  31664. child->parentComponent_ = 0;
  31665. JUCE_TRY
  31666. {
  31667. if ((currentlyFocusedComponent == child)
  31668. || child->isParentOf (currentlyFocusedComponent))
  31669. {
  31670. // get rid first to force the grabKeyboardFocus to change to us.
  31671. giveAwayFocus();
  31672. grabKeyboardFocus();
  31673. }
  31674. }
  31675. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31676. catch (const std::exception& e)
  31677. {
  31678. currentlyFocusedComponent = 0;
  31679. Desktop::getInstance().triggerFocusCallback();
  31680. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31681. }
  31682. catch (...)
  31683. {
  31684. currentlyFocusedComponent = 0;
  31685. Desktop::getInstance().triggerFocusCallback();
  31686. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31687. }
  31688. #endif
  31689. child->internalHierarchyChanged();
  31690. internalChildrenChanged();
  31691. }
  31692. return child;
  31693. }
  31694. void Component::removeAllChildren()
  31695. {
  31696. while (childComponentList_.size() > 0)
  31697. removeChildComponent (childComponentList_.size() - 1);
  31698. }
  31699. void Component::deleteAllChildren()
  31700. {
  31701. while (childComponentList_.size() > 0)
  31702. delete (removeChildComponent (childComponentList_.size() - 1));
  31703. }
  31704. int Component::getNumChildComponents() const throw()
  31705. {
  31706. return childComponentList_.size();
  31707. }
  31708. Component* Component::getChildComponent (const int index) const throw()
  31709. {
  31710. return childComponentList_ [index];
  31711. }
  31712. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31713. {
  31714. return childComponentList_.indexOf (const_cast <Component*> (child));
  31715. }
  31716. Component* Component::getTopLevelComponent() const throw()
  31717. {
  31718. const Component* comp = this;
  31719. while (comp->parentComponent_ != 0)
  31720. comp = comp->parentComponent_;
  31721. return const_cast <Component*> (comp);
  31722. }
  31723. bool Component::isParentOf (const Component* possibleChild) const throw()
  31724. {
  31725. if (! possibleChild->isValidComponent())
  31726. {
  31727. jassert (possibleChild == 0);
  31728. return false;
  31729. }
  31730. while (possibleChild != 0)
  31731. {
  31732. possibleChild = possibleChild->parentComponent_;
  31733. if (possibleChild == this)
  31734. return true;
  31735. }
  31736. return false;
  31737. }
  31738. void Component::parentHierarchyChanged()
  31739. {
  31740. }
  31741. void Component::childrenChanged()
  31742. {
  31743. }
  31744. void Component::internalChildrenChanged()
  31745. {
  31746. if (componentListeners.isEmpty())
  31747. {
  31748. childrenChanged();
  31749. }
  31750. else
  31751. {
  31752. BailOutChecker checker (this);
  31753. childrenChanged();
  31754. if (! checker.shouldBailOut())
  31755. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31756. }
  31757. }
  31758. void Component::internalHierarchyChanged()
  31759. {
  31760. BailOutChecker checker (this);
  31761. parentHierarchyChanged();
  31762. if (checker.shouldBailOut())
  31763. return;
  31764. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31765. if (checker.shouldBailOut())
  31766. return;
  31767. for (int i = childComponentList_.size(); --i >= 0;)
  31768. {
  31769. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31770. if (checker.shouldBailOut())
  31771. {
  31772. // you really shouldn't delete the parent component during a callback telling you
  31773. // that it's changed..
  31774. jassertfalse;
  31775. return;
  31776. }
  31777. i = jmin (i, childComponentList_.size());
  31778. }
  31779. }
  31780. void* Component::runModalLoopCallback (void* userData)
  31781. {
  31782. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  31783. }
  31784. int Component::runModalLoop()
  31785. {
  31786. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31787. {
  31788. // use a callback so this can be called from non-gui threads
  31789. return (int) (pointer_sized_int)
  31790. MessageManager::getInstance()
  31791. ->callFunctionOnMessageThread (&runModalLoopCallback, this);
  31792. }
  31793. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31794. if (! isCurrentlyModal())
  31795. enterModalState();
  31796. JUCE_TRY
  31797. {
  31798. while (flags.currentlyModalFlag && flags.visibleFlag)
  31799. {
  31800. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31801. break;
  31802. // check whether this component was deleted during the last message
  31803. if (! isValidMessageListener())
  31804. break;
  31805. }
  31806. }
  31807. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31808. catch (const std::exception& e)
  31809. {
  31810. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31811. return 0;
  31812. }
  31813. catch (...)
  31814. {
  31815. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31816. return 0;
  31817. }
  31818. #endif
  31819. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31820. int returnValue = 0;
  31821. if (modalIndex >= 0)
  31822. {
  31823. modalComponentReturnValueKeys.remove (modalIndex);
  31824. returnValue = modalReturnValues.remove (modalIndex);
  31825. }
  31826. modalComponentStack.removeValue (this);
  31827. if (prevFocused != 0)
  31828. prevFocused->grabKeyboardFocus();
  31829. return returnValue;
  31830. }
  31831. void Component::enterModalState (const bool takeKeyboardFocus_)
  31832. {
  31833. // if component methods are being called from threads other than the message
  31834. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31835. checkMessageManagerIsLocked
  31836. // Check for an attempt to make a component modal when it already is!
  31837. // This can cause nasty problems..
  31838. jassert (! flags.currentlyModalFlag);
  31839. if (! isCurrentlyModal())
  31840. {
  31841. modalComponentStack.add (this);
  31842. modalComponentReturnValueKeys.add (this);
  31843. modalReturnValues.add (0);
  31844. flags.currentlyModalFlag = true;
  31845. setVisible (true);
  31846. if (takeKeyboardFocus_)
  31847. grabKeyboardFocus();
  31848. }
  31849. }
  31850. void Component::exitModalState (const int returnValue)
  31851. {
  31852. if (isCurrentlyModal())
  31853. {
  31854. if (MessageManager::getInstance()->isThisTheMessageThread())
  31855. {
  31856. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31857. if (modalIndex >= 0)
  31858. {
  31859. modalReturnValues.set (modalIndex, returnValue);
  31860. }
  31861. else
  31862. {
  31863. modalComponentReturnValueKeys.add (this);
  31864. modalReturnValues.add (returnValue);
  31865. }
  31866. modalComponentStack.removeValue (this);
  31867. flags.currentlyModalFlag = false;
  31868. bringModalComponentToFront();
  31869. }
  31870. else
  31871. {
  31872. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31873. }
  31874. }
  31875. }
  31876. bool Component::isCurrentlyModal() const throw()
  31877. {
  31878. return flags.currentlyModalFlag
  31879. && getCurrentlyModalComponent() == this;
  31880. }
  31881. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31882. {
  31883. Component* const mc = getCurrentlyModalComponent();
  31884. return mc != 0
  31885. && mc != this
  31886. && (! mc->isParentOf (this))
  31887. && ! mc->canModalEventBeSentToComponent (this);
  31888. }
  31889. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31890. {
  31891. return modalComponentStack.size();
  31892. }
  31893. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31894. {
  31895. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31896. return c->isValidComponent() ? c : 0;
  31897. }
  31898. void Component::bringModalComponentToFront()
  31899. {
  31900. ComponentPeer* lastOne = 0;
  31901. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31902. {
  31903. Component* const c = getCurrentlyModalComponent (i);
  31904. if (c == 0)
  31905. break;
  31906. ComponentPeer* peer = c->getPeer();
  31907. if (peer != 0 && peer != lastOne)
  31908. {
  31909. if (lastOne == 0)
  31910. {
  31911. peer->toFront (true);
  31912. peer->grabFocus();
  31913. }
  31914. else
  31915. peer->toBehind (lastOne);
  31916. lastOne = peer;
  31917. }
  31918. }
  31919. }
  31920. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  31921. {
  31922. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  31923. }
  31924. bool Component::isBroughtToFrontOnMouseClick() const throw()
  31925. {
  31926. return flags.bringToFrontOnClickFlag;
  31927. }
  31928. void Component::setMouseCursor (const MouseCursor& cursor)
  31929. {
  31930. if (cursor_ != cursor)
  31931. {
  31932. cursor_ = cursor;
  31933. if (flags.visibleFlag)
  31934. updateMouseCursor();
  31935. }
  31936. }
  31937. const MouseCursor Component::getMouseCursor()
  31938. {
  31939. return cursor_;
  31940. }
  31941. void Component::updateMouseCursor() const
  31942. {
  31943. sendFakeMouseMove();
  31944. }
  31945. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  31946. {
  31947. flags.repaintOnMouseActivityFlag = shouldRepaint;
  31948. }
  31949. void Component::repaintParent()
  31950. {
  31951. if (flags.visibleFlag)
  31952. internalRepaint (0, 0, getWidth(), getHeight());
  31953. }
  31954. void Component::repaint()
  31955. {
  31956. repaint (0, 0, getWidth(), getHeight());
  31957. }
  31958. void Component::repaint (const int x, const int y,
  31959. const int w, const int h)
  31960. {
  31961. deleteAndZero (bufferedImage_);
  31962. if (flags.visibleFlag)
  31963. internalRepaint (x, y, w, h);
  31964. }
  31965. void Component::internalRepaint (int x, int y, int w, int h)
  31966. {
  31967. // if component methods are being called from threads other than the message
  31968. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31969. checkMessageManagerIsLocked
  31970. if (x < 0)
  31971. {
  31972. w += x;
  31973. x = 0;
  31974. }
  31975. if (x + w > getWidth())
  31976. w = getWidth() - x;
  31977. if (w > 0)
  31978. {
  31979. if (y < 0)
  31980. {
  31981. h += y;
  31982. y = 0;
  31983. }
  31984. if (y + h > getHeight())
  31985. h = getHeight() - y;
  31986. if (h > 0)
  31987. {
  31988. if (parentComponent_ != 0)
  31989. {
  31990. x += getX();
  31991. y += getY();
  31992. if (parentComponent_->flags.visibleFlag)
  31993. parentComponent_->internalRepaint (x, y, w, h);
  31994. }
  31995. else if (flags.hasHeavyweightPeerFlag)
  31996. {
  31997. ComponentPeer* const peer = getPeer();
  31998. if (peer != 0)
  31999. peer->repaint (x, y, w, h);
  32000. }
  32001. }
  32002. }
  32003. }
  32004. void Component::renderComponent (Graphics& g)
  32005. {
  32006. const Rectangle<int> clipBounds (g.getClipBounds());
  32007. g.saveState();
  32008. clipObscuredRegions (g, clipBounds, 0, 0);
  32009. if (! g.isClipEmpty())
  32010. {
  32011. if (flags.bufferToImageFlag)
  32012. {
  32013. if (bufferedImage_ == 0)
  32014. {
  32015. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32016. getWidth(), getHeight(), ! flags.opaqueFlag);
  32017. Graphics imG (*bufferedImage_);
  32018. paint (imG);
  32019. }
  32020. g.setColour (Colours::black);
  32021. g.drawImageAt (bufferedImage_, 0, 0);
  32022. }
  32023. else
  32024. {
  32025. paint (g);
  32026. }
  32027. }
  32028. g.restoreState();
  32029. for (int i = 0; i < childComponentList_.size(); ++i)
  32030. {
  32031. Component* const child = childComponentList_.getUnchecked (i);
  32032. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32033. {
  32034. g.saveState();
  32035. if (g.reduceClipRegion (child->getX(), child->getY(),
  32036. child->getWidth(), child->getHeight()))
  32037. {
  32038. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32039. {
  32040. const Component* const sibling = childComponentList_.getUnchecked (j);
  32041. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32042. g.excludeClipRegion (sibling->getBounds());
  32043. }
  32044. if (! g.isClipEmpty())
  32045. {
  32046. g.setOrigin (child->getX(), child->getY());
  32047. child->paintEntireComponent (g);
  32048. }
  32049. }
  32050. g.restoreState();
  32051. }
  32052. }
  32053. g.saveState();
  32054. paintOverChildren (g);
  32055. g.restoreState();
  32056. }
  32057. void Component::paintEntireComponent (Graphics& g)
  32058. {
  32059. jassert (! g.isClipEmpty());
  32060. #ifdef JUCE_DEBUG
  32061. flags.isInsidePaintCall = true;
  32062. #endif
  32063. if (effect_ != 0)
  32064. {
  32065. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32066. getWidth(), getHeight(),
  32067. ! flags.opaqueFlag));
  32068. {
  32069. Graphics g2 (*effectImage);
  32070. renderComponent (g2);
  32071. }
  32072. effect_->applyEffect (*effectImage, g);
  32073. }
  32074. else
  32075. {
  32076. renderComponent (g);
  32077. }
  32078. #ifdef JUCE_DEBUG
  32079. flags.isInsidePaintCall = false;
  32080. #endif
  32081. }
  32082. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32083. const bool clipImageToComponentBounds)
  32084. {
  32085. Rectangle<int> r (areaToGrab);
  32086. if (clipImageToComponentBounds)
  32087. r = r.getIntersection (getLocalBounds());
  32088. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32089. jmax (1, r.getWidth()),
  32090. jmax (1, r.getHeight()),
  32091. true));
  32092. Graphics imageContext (*componentImage);
  32093. imageContext.setOrigin (-r.getX(), -r.getY());
  32094. paintEntireComponent (imageContext);
  32095. return componentImage.release();
  32096. }
  32097. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32098. {
  32099. if (effect_ != effect)
  32100. {
  32101. effect_ = effect;
  32102. repaint();
  32103. }
  32104. }
  32105. LookAndFeel& Component::getLookAndFeel() const throw()
  32106. {
  32107. const Component* c = this;
  32108. do
  32109. {
  32110. if (c->lookAndFeel_ != 0)
  32111. return *(c->lookAndFeel_);
  32112. c = c->parentComponent_;
  32113. }
  32114. while (c != 0);
  32115. return LookAndFeel::getDefaultLookAndFeel();
  32116. }
  32117. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32118. {
  32119. if (lookAndFeel_ != newLookAndFeel)
  32120. {
  32121. lookAndFeel_ = newLookAndFeel;
  32122. sendLookAndFeelChange();
  32123. }
  32124. }
  32125. void Component::lookAndFeelChanged()
  32126. {
  32127. }
  32128. void Component::sendLookAndFeelChange()
  32129. {
  32130. repaint();
  32131. lookAndFeelChanged();
  32132. // (it's not a great idea to do anything that would delete this component
  32133. // during the lookAndFeelChanged() callback)
  32134. jassert (isValidComponent());
  32135. SafePointer<Component> safePointer (this);
  32136. for (int i = childComponentList_.size(); --i >= 0;)
  32137. {
  32138. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32139. if (safePointer == 0)
  32140. return;
  32141. i = jmin (i, childComponentList_.size());
  32142. }
  32143. }
  32144. static const var::identifier getColourPropertyId (const int colourId)
  32145. {
  32146. String s;
  32147. s.preallocateStorage (18);
  32148. s << "jcclr_" << String::toHexString (colourId);
  32149. return s;
  32150. }
  32151. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32152. {
  32153. var* v = properties.getItem (getColourPropertyId (colourId));
  32154. if (v != 0)
  32155. return Colour ((int) *v);
  32156. if (inheritFromParent && parentComponent_ != 0)
  32157. return parentComponent_->findColour (colourId, true);
  32158. return getLookAndFeel().findColour (colourId);
  32159. }
  32160. bool Component::isColourSpecified (const int colourId) const
  32161. {
  32162. return properties.contains (getColourPropertyId (colourId));
  32163. }
  32164. void Component::removeColour (const int colourId)
  32165. {
  32166. if (properties.remove (getColourPropertyId (colourId)))
  32167. colourChanged();
  32168. }
  32169. void Component::setColour (const int colourId, const Colour& colour)
  32170. {
  32171. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32172. colourChanged();
  32173. }
  32174. void Component::copyAllExplicitColoursTo (Component& target) const
  32175. {
  32176. bool changed = false;
  32177. for (int i = properties.size(); --i >= 0;)
  32178. {
  32179. const var::identifier name (properties.getName(i));
  32180. if (name.name.startsWith ("jcclr_"))
  32181. if (target.properties.set (name, properties [name]))
  32182. changed = true;
  32183. }
  32184. if (changed)
  32185. target.colourChanged();
  32186. }
  32187. void Component::colourChanged()
  32188. {
  32189. }
  32190. const Rectangle<int> Component::getLocalBounds() const throw()
  32191. {
  32192. return Rectangle<int> (0, 0, getWidth(), getHeight());
  32193. }
  32194. const Rectangle<int> Component::getUnclippedArea() const
  32195. {
  32196. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32197. Component* p = parentComponent_;
  32198. int px = getX();
  32199. int py = getY();
  32200. while (p != 0)
  32201. {
  32202. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32203. return Rectangle<int>();
  32204. px += p->getX();
  32205. py += p->getY();
  32206. p = p->parentComponent_;
  32207. }
  32208. return Rectangle<int> (x, y, w, h);
  32209. }
  32210. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32211. const int deltaX, const int deltaY) const
  32212. {
  32213. for (int i = childComponentList_.size(); --i >= 0;)
  32214. {
  32215. const Component* const c = childComponentList_.getUnchecked(i);
  32216. if (c->isVisible())
  32217. {
  32218. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32219. if (! newClip.isEmpty())
  32220. {
  32221. if (c->isOpaque())
  32222. {
  32223. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32224. }
  32225. else
  32226. {
  32227. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32228. c->getX() + deltaX,
  32229. c->getY() + deltaY);
  32230. }
  32231. }
  32232. }
  32233. }
  32234. }
  32235. void Component::getVisibleArea (RectangleList& result, const bool includeSiblings) const
  32236. {
  32237. result.clear();
  32238. const Rectangle<int> unclipped (getUnclippedArea());
  32239. if (! unclipped.isEmpty())
  32240. {
  32241. result.add (unclipped);
  32242. if (includeSiblings)
  32243. {
  32244. const Component* const c = getTopLevelComponent();
  32245. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32246. c->getLocalBounds(), this);
  32247. }
  32248. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32249. result.consolidate();
  32250. }
  32251. }
  32252. void Component::subtractObscuredRegions (RectangleList& result,
  32253. const Point<int>& delta,
  32254. const Rectangle<int>& clipRect,
  32255. const Component* const compToAvoid) const
  32256. {
  32257. for (int i = childComponentList_.size(); --i >= 0;)
  32258. {
  32259. const Component* const c = childComponentList_.getUnchecked(i);
  32260. if (c != compToAvoid && c->isVisible())
  32261. {
  32262. if (c->isOpaque())
  32263. {
  32264. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32265. childBounds.translate (delta.getX(), delta.getY());
  32266. result.subtract (childBounds);
  32267. }
  32268. else
  32269. {
  32270. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32271. newClip.translate (-c->getX(), -c->getY());
  32272. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32273. newClip, compToAvoid);
  32274. }
  32275. }
  32276. }
  32277. }
  32278. void Component::mouseEnter (const MouseEvent&)
  32279. {
  32280. // base class does nothing
  32281. }
  32282. void Component::mouseExit (const MouseEvent&)
  32283. {
  32284. // base class does nothing
  32285. }
  32286. void Component::mouseDown (const MouseEvent&)
  32287. {
  32288. // base class does nothing
  32289. }
  32290. void Component::mouseUp (const MouseEvent&)
  32291. {
  32292. // base class does nothing
  32293. }
  32294. void Component::mouseDrag (const MouseEvent&)
  32295. {
  32296. // base class does nothing
  32297. }
  32298. void Component::mouseMove (const MouseEvent&)
  32299. {
  32300. // base class does nothing
  32301. }
  32302. void Component::mouseDoubleClick (const MouseEvent&)
  32303. {
  32304. // base class does nothing
  32305. }
  32306. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32307. {
  32308. // the base class just passes this event up to its parent..
  32309. if (parentComponent_ != 0)
  32310. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32311. wheelIncrementX, wheelIncrementY);
  32312. }
  32313. void Component::resized()
  32314. {
  32315. // base class does nothing
  32316. }
  32317. void Component::moved()
  32318. {
  32319. // base class does nothing
  32320. }
  32321. void Component::childBoundsChanged (Component*)
  32322. {
  32323. // base class does nothing
  32324. }
  32325. void Component::parentSizeChanged()
  32326. {
  32327. // base class does nothing
  32328. }
  32329. void Component::addComponentListener (ComponentListener* const newListener)
  32330. {
  32331. jassert (isValidComponent());
  32332. componentListeners.add (newListener);
  32333. }
  32334. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32335. {
  32336. jassert (isValidComponent());
  32337. componentListeners.remove (listenerToRemove);
  32338. }
  32339. void Component::inputAttemptWhenModal()
  32340. {
  32341. bringModalComponentToFront();
  32342. getLookAndFeel().playAlertSound();
  32343. }
  32344. bool Component::canModalEventBeSentToComponent (const Component*)
  32345. {
  32346. return false;
  32347. }
  32348. void Component::internalModalInputAttempt()
  32349. {
  32350. Component* const current = getCurrentlyModalComponent();
  32351. if (current != 0)
  32352. current->inputAttemptWhenModal();
  32353. }
  32354. void Component::paint (Graphics&)
  32355. {
  32356. // all painting is done in the subclasses
  32357. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32358. }
  32359. void Component::paintOverChildren (Graphics&)
  32360. {
  32361. // all painting is done in the subclasses
  32362. }
  32363. void Component::handleMessage (const Message& message)
  32364. {
  32365. if (message.intParameter1 == exitModalStateMessage)
  32366. {
  32367. exitModalState (message.intParameter2);
  32368. }
  32369. else if (message.intParameter1 == customCommandMessage)
  32370. {
  32371. handleCommandMessage (message.intParameter2);
  32372. }
  32373. }
  32374. void Component::postCommandMessage (const int commandId)
  32375. {
  32376. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32377. }
  32378. void Component::handleCommandMessage (int)
  32379. {
  32380. // used by subclasses
  32381. }
  32382. void Component::addMouseListener (MouseListener* const newListener,
  32383. const bool wantsEventsForAllNestedChildComponents)
  32384. {
  32385. // if component methods are being called from threads other than the message
  32386. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32387. checkMessageManagerIsLocked
  32388. if (mouseListeners_ == 0)
  32389. mouseListeners_ = new VoidArray();
  32390. if (! mouseListeners_->contains (newListener))
  32391. {
  32392. if (wantsEventsForAllNestedChildComponents)
  32393. {
  32394. mouseListeners_->insert (0, newListener);
  32395. ++numDeepMouseListeners;
  32396. }
  32397. else
  32398. {
  32399. mouseListeners_->add (newListener);
  32400. }
  32401. }
  32402. }
  32403. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32404. {
  32405. // if component methods are being called from threads other than the message
  32406. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32407. checkMessageManagerIsLocked
  32408. if (mouseListeners_ != 0)
  32409. {
  32410. const int index = mouseListeners_->indexOf (listenerToRemove);
  32411. if (index >= 0)
  32412. {
  32413. if (index < numDeepMouseListeners)
  32414. --numDeepMouseListeners;
  32415. mouseListeners_->remove (index);
  32416. }
  32417. }
  32418. }
  32419. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32420. {
  32421. if (isCurrentlyBlockedByAnotherModalComponent())
  32422. {
  32423. // if something else is modal, always just show a normal mouse cursor
  32424. source.showMouseCursor (MouseCursor::NormalCursor);
  32425. return;
  32426. }
  32427. if (! flags.mouseInsideFlag)
  32428. {
  32429. flags.mouseInsideFlag = true;
  32430. flags.mouseOverFlag = true;
  32431. flags.draggingFlag = false;
  32432. BailOutChecker checker (this);
  32433. if (flags.repaintOnMouseActivityFlag)
  32434. repaint();
  32435. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32436. this, time, relativePos,
  32437. time, 0, false);
  32438. mouseEnter (me);
  32439. if (checker.shouldBailOut())
  32440. return;
  32441. Desktop::getInstance().resetTimer();
  32442. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32443. if (checker.shouldBailOut())
  32444. return;
  32445. if (mouseListeners_ != 0)
  32446. {
  32447. for (int i = mouseListeners_->size(); --i >= 0;)
  32448. {
  32449. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32450. if (checker.shouldBailOut())
  32451. return;
  32452. i = jmin (i, mouseListeners_->size());
  32453. }
  32454. }
  32455. Component* p = parentComponent_;
  32456. while (p != 0)
  32457. {
  32458. if (p->numDeepMouseListeners > 0)
  32459. {
  32460. BailOutChecker checker (this, p);
  32461. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32462. {
  32463. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32464. if (checker.shouldBailOut())
  32465. return;
  32466. i = jmin (i, p->numDeepMouseListeners);
  32467. }
  32468. }
  32469. p = p->parentComponent_;
  32470. }
  32471. }
  32472. }
  32473. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32474. {
  32475. BailOutChecker checker (this);
  32476. if (flags.draggingFlag)
  32477. {
  32478. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32479. if (checker.shouldBailOut())
  32480. return;
  32481. }
  32482. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32483. {
  32484. flags.mouseInsideFlag = false;
  32485. flags.mouseOverFlag = false;
  32486. flags.draggingFlag = false;
  32487. if (flags.repaintOnMouseActivityFlag)
  32488. repaint();
  32489. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32490. this, time, relativePos,
  32491. time, 0, false);
  32492. mouseExit (me);
  32493. if (checker.shouldBailOut())
  32494. return;
  32495. Desktop::getInstance().resetTimer();
  32496. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32497. if (checker.shouldBailOut())
  32498. return;
  32499. if (mouseListeners_ != 0)
  32500. {
  32501. for (int i = mouseListeners_->size(); --i >= 0;)
  32502. {
  32503. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32504. if (checker.shouldBailOut())
  32505. return;
  32506. i = jmin (i, mouseListeners_->size());
  32507. }
  32508. }
  32509. Component* p = parentComponent_;
  32510. while (p != 0)
  32511. {
  32512. if (p->numDeepMouseListeners > 0)
  32513. {
  32514. BailOutChecker checker (this, p);
  32515. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32516. {
  32517. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32518. if (checker.shouldBailOut())
  32519. return;
  32520. i = jmin (i, p->numDeepMouseListeners);
  32521. }
  32522. }
  32523. p = p->parentComponent_;
  32524. }
  32525. }
  32526. }
  32527. class InternalDragRepeater : public Timer
  32528. {
  32529. public:
  32530. InternalDragRepeater()
  32531. {}
  32532. ~InternalDragRepeater()
  32533. {
  32534. clearSingletonInstance();
  32535. }
  32536. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32537. void timerCallback()
  32538. {
  32539. Desktop& desktop = Desktop::getInstance();
  32540. int numMiceDown = 0;
  32541. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32542. {
  32543. MouseInputSource* const source = desktop.getMouseSource(i);
  32544. if (source->isDragging())
  32545. {
  32546. source->triggerFakeMove();
  32547. ++numMiceDown;
  32548. }
  32549. }
  32550. if (numMiceDown == 0)
  32551. deleteInstance();
  32552. }
  32553. juce_UseDebuggingNewOperator
  32554. private:
  32555. InternalDragRepeater (const InternalDragRepeater&);
  32556. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32557. };
  32558. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32559. void Component::beginDragAutoRepeat (const int interval)
  32560. {
  32561. if (interval > 0)
  32562. {
  32563. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32564. InternalDragRepeater::getInstance()->startTimer (interval);
  32565. }
  32566. else
  32567. {
  32568. InternalDragRepeater::deleteInstance();
  32569. }
  32570. }
  32571. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32572. {
  32573. Desktop& desktop = Desktop::getInstance();
  32574. BailOutChecker checker (this);
  32575. if (isCurrentlyBlockedByAnotherModalComponent())
  32576. {
  32577. internalModalInputAttempt();
  32578. if (checker.shouldBailOut())
  32579. return;
  32580. // If processing the input attempt has exited the modal loop, we'll allow the event
  32581. // to be delivered..
  32582. if (isCurrentlyBlockedByAnotherModalComponent())
  32583. {
  32584. // allow blocked mouse-events to go to global listeners..
  32585. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32586. this, time, relativePos, time,
  32587. source.getNumberOfMultipleClicks(), false);
  32588. desktop.resetTimer();
  32589. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32590. return;
  32591. }
  32592. }
  32593. {
  32594. Component* c = this;
  32595. while (c != 0)
  32596. {
  32597. if (c->isBroughtToFrontOnMouseClick())
  32598. {
  32599. c->toFront (true);
  32600. if (checker.shouldBailOut())
  32601. return;
  32602. }
  32603. c = c->parentComponent_;
  32604. }
  32605. }
  32606. if (! flags.dontFocusOnMouseClickFlag)
  32607. {
  32608. grabFocusInternal (focusChangedByMouseClick);
  32609. if (checker.shouldBailOut())
  32610. return;
  32611. }
  32612. flags.draggingFlag = true;
  32613. flags.mouseOverFlag = true;
  32614. if (flags.repaintOnMouseActivityFlag)
  32615. repaint();
  32616. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32617. this, time, relativePos, time,
  32618. source.getNumberOfMultipleClicks(), false);
  32619. mouseDown (me);
  32620. if (checker.shouldBailOut())
  32621. return;
  32622. desktop.resetTimer();
  32623. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32624. if (checker.shouldBailOut())
  32625. return;
  32626. if (mouseListeners_ != 0)
  32627. {
  32628. for (int i = mouseListeners_->size(); --i >= 0;)
  32629. {
  32630. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32631. if (checker.shouldBailOut())
  32632. return;
  32633. i = jmin (i, mouseListeners_->size());
  32634. }
  32635. }
  32636. Component* p = parentComponent_;
  32637. while (p != 0)
  32638. {
  32639. if (p->numDeepMouseListeners > 0)
  32640. {
  32641. BailOutChecker checker (this, p);
  32642. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32643. {
  32644. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32645. if (checker.shouldBailOut())
  32646. return;
  32647. i = jmin (i, p->numDeepMouseListeners);
  32648. }
  32649. }
  32650. p = p->parentComponent_;
  32651. }
  32652. }
  32653. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32654. {
  32655. if (flags.draggingFlag)
  32656. {
  32657. Desktop& desktop = Desktop::getInstance();
  32658. flags.draggingFlag = false;
  32659. BailOutChecker checker (this);
  32660. if (flags.repaintOnMouseActivityFlag)
  32661. repaint();
  32662. const MouseEvent me (source, relativePos,
  32663. oldModifiers, this, time,
  32664. globalPositionToRelative (source.getLastMouseDownPosition()),
  32665. source.getLastMouseDownTime(),
  32666. source.getNumberOfMultipleClicks(),
  32667. source.hasMouseMovedSignificantlySincePressed());
  32668. mouseUp (me);
  32669. if (checker.shouldBailOut())
  32670. return;
  32671. desktop.resetTimer();
  32672. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32673. if (checker.shouldBailOut())
  32674. return;
  32675. if (mouseListeners_ != 0)
  32676. {
  32677. for (int i = mouseListeners_->size(); --i >= 0;)
  32678. {
  32679. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32680. if (checker.shouldBailOut())
  32681. return;
  32682. i = jmin (i, mouseListeners_->size());
  32683. }
  32684. }
  32685. {
  32686. Component* p = parentComponent_;
  32687. while (p != 0)
  32688. {
  32689. if (p->numDeepMouseListeners > 0)
  32690. {
  32691. BailOutChecker checker (this, p);
  32692. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32693. {
  32694. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  32695. if (checker.shouldBailOut())
  32696. return;
  32697. i = jmin (i, p->numDeepMouseListeners);
  32698. }
  32699. }
  32700. p = p->parentComponent_;
  32701. }
  32702. }
  32703. // check for double-click
  32704. if (me.getNumberOfClicks() >= 2)
  32705. {
  32706. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32707. mouseDoubleClick (me);
  32708. if (checker.shouldBailOut())
  32709. return;
  32710. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32711. if (checker.shouldBailOut())
  32712. return;
  32713. for (int i = numListeners; --i >= 0;)
  32714. {
  32715. if (checker.shouldBailOut())
  32716. return;
  32717. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32718. if (ml != 0)
  32719. ml->mouseDoubleClick (me);
  32720. }
  32721. if (checker.shouldBailOut())
  32722. return;
  32723. Component* p = parentComponent_;
  32724. while (p != 0)
  32725. {
  32726. if (p->numDeepMouseListeners > 0)
  32727. {
  32728. BailOutChecker checker (this, p);
  32729. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32730. {
  32731. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  32732. if (checker.shouldBailOut())
  32733. return;
  32734. i = jmin (i, p->numDeepMouseListeners);
  32735. }
  32736. }
  32737. p = p->parentComponent_;
  32738. }
  32739. }
  32740. }
  32741. }
  32742. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32743. {
  32744. if (flags.draggingFlag)
  32745. {
  32746. Desktop& desktop = Desktop::getInstance();
  32747. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32748. BailOutChecker checker (this);
  32749. const MouseEvent me (source, relativePos,
  32750. source.getCurrentModifiers(), this, time,
  32751. globalPositionToRelative (source.getLastMouseDownPosition()),
  32752. source.getLastMouseDownTime(),
  32753. source.getNumberOfMultipleClicks(),
  32754. source.hasMouseMovedSignificantlySincePressed());
  32755. mouseDrag (me);
  32756. if (checker.shouldBailOut())
  32757. return;
  32758. desktop.resetTimer();
  32759. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32760. if (checker.shouldBailOut())
  32761. return;
  32762. if (mouseListeners_ != 0)
  32763. {
  32764. for (int i = mouseListeners_->size(); --i >= 0;)
  32765. {
  32766. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32767. if (checker.shouldBailOut())
  32768. return;
  32769. i = jmin (i, mouseListeners_->size());
  32770. }
  32771. }
  32772. Component* p = parentComponent_;
  32773. while (p != 0)
  32774. {
  32775. if (p->numDeepMouseListeners > 0)
  32776. {
  32777. BailOutChecker checker (this, p);
  32778. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32779. {
  32780. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  32781. if (checker.shouldBailOut())
  32782. return;
  32783. i = jmin (i, p->numDeepMouseListeners);
  32784. }
  32785. }
  32786. p = p->parentComponent_;
  32787. }
  32788. }
  32789. }
  32790. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32791. {
  32792. Desktop& desktop = Desktop::getInstance();
  32793. BailOutChecker checker (this);
  32794. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32795. this, time, relativePos,
  32796. time, 0, false);
  32797. if (isCurrentlyBlockedByAnotherModalComponent())
  32798. {
  32799. // allow blocked mouse-events to go to global listeners..
  32800. desktop.sendMouseMove();
  32801. }
  32802. else
  32803. {
  32804. flags.mouseOverFlag = true;
  32805. mouseMove (me);
  32806. if (checker.shouldBailOut())
  32807. return;
  32808. desktop.resetTimer();
  32809. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32810. if (checker.shouldBailOut())
  32811. return;
  32812. if (mouseListeners_ != 0)
  32813. {
  32814. for (int i = mouseListeners_->size(); --i >= 0;)
  32815. {
  32816. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32817. if (checker.shouldBailOut())
  32818. return;
  32819. i = jmin (i, mouseListeners_->size());
  32820. }
  32821. }
  32822. Component* p = parentComponent_;
  32823. while (p != 0)
  32824. {
  32825. if (p->numDeepMouseListeners > 0)
  32826. {
  32827. BailOutChecker checker (this, p);
  32828. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32829. {
  32830. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  32831. if (checker.shouldBailOut())
  32832. return;
  32833. i = jmin (i, p->numDeepMouseListeners);
  32834. }
  32835. }
  32836. p = p->parentComponent_;
  32837. }
  32838. }
  32839. }
  32840. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32841. const Time& time, const float amountX, const float amountY)
  32842. {
  32843. Desktop& desktop = Desktop::getInstance();
  32844. BailOutChecker checker (this);
  32845. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32846. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32847. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32848. this, time, relativePos, time, 0, false);
  32849. if (isCurrentlyBlockedByAnotherModalComponent())
  32850. {
  32851. // allow blocked mouse-events to go to global listeners..
  32852. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32853. }
  32854. else
  32855. {
  32856. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32857. if (checker.shouldBailOut())
  32858. return;
  32859. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32860. if (checker.shouldBailOut())
  32861. return;
  32862. if (mouseListeners_ != 0)
  32863. {
  32864. for (int i = mouseListeners_->size(); --i >= 0;)
  32865. {
  32866. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32867. if (checker.shouldBailOut())
  32868. return;
  32869. i = jmin (i, mouseListeners_->size());
  32870. }
  32871. }
  32872. Component* p = parentComponent_;
  32873. while (p != 0)
  32874. {
  32875. if (p->numDeepMouseListeners > 0)
  32876. {
  32877. BailOutChecker checker (this, p);
  32878. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32879. {
  32880. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32881. if (checker.shouldBailOut())
  32882. return;
  32883. i = jmin (i, p->numDeepMouseListeners);
  32884. }
  32885. }
  32886. p = p->parentComponent_;
  32887. }
  32888. }
  32889. }
  32890. void Component::sendFakeMouseMove() const
  32891. {
  32892. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32893. }
  32894. void Component::broughtToFront()
  32895. {
  32896. }
  32897. void Component::internalBroughtToFront()
  32898. {
  32899. if (! isValidComponent())
  32900. return;
  32901. if (flags.hasHeavyweightPeerFlag)
  32902. Desktop::getInstance().componentBroughtToFront (this);
  32903. BailOutChecker checker (this);
  32904. broughtToFront();
  32905. if (checker.shouldBailOut())
  32906. return;
  32907. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  32908. if (checker.shouldBailOut())
  32909. return;
  32910. // When brought to the front and there's a modal component blocking this one,
  32911. // we need to bring the modal one to the front instead..
  32912. Component* const cm = getCurrentlyModalComponent();
  32913. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  32914. bringModalComponentToFront();
  32915. }
  32916. void Component::focusGained (FocusChangeType)
  32917. {
  32918. // base class does nothing
  32919. }
  32920. void Component::internalFocusGain (const FocusChangeType cause)
  32921. {
  32922. SafePointer<Component> safePointer (this);
  32923. focusGained (cause);
  32924. if (safePointer != 0)
  32925. internalChildFocusChange (cause);
  32926. }
  32927. void Component::focusLost (FocusChangeType)
  32928. {
  32929. // base class does nothing
  32930. }
  32931. void Component::internalFocusLoss (const FocusChangeType cause)
  32932. {
  32933. SafePointer<Component> safePointer (this);
  32934. focusLost (focusChangedDirectly);
  32935. if (safePointer != 0)
  32936. internalChildFocusChange (cause);
  32937. }
  32938. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  32939. {
  32940. // base class does nothing
  32941. }
  32942. void Component::internalChildFocusChange (FocusChangeType cause)
  32943. {
  32944. const bool childIsNowFocused = hasKeyboardFocus (true);
  32945. if (flags.childCompFocusedFlag != childIsNowFocused)
  32946. {
  32947. flags.childCompFocusedFlag = childIsNowFocused;
  32948. SafePointer<Component> safePointer (this);
  32949. focusOfChildComponentChanged (cause);
  32950. if (safePointer == 0)
  32951. return;
  32952. }
  32953. if (parentComponent_ != 0)
  32954. parentComponent_->internalChildFocusChange (cause);
  32955. }
  32956. bool Component::isEnabled() const throw()
  32957. {
  32958. return (! flags.isDisabledFlag)
  32959. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  32960. }
  32961. void Component::setEnabled (const bool shouldBeEnabled)
  32962. {
  32963. if (flags.isDisabledFlag == shouldBeEnabled)
  32964. {
  32965. flags.isDisabledFlag = ! shouldBeEnabled;
  32966. // if any parent components are disabled, setting our flag won't make a difference,
  32967. // so no need to send a change message
  32968. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  32969. sendEnablementChangeMessage();
  32970. }
  32971. }
  32972. void Component::sendEnablementChangeMessage()
  32973. {
  32974. SafePointer<Component> safePointer (this);
  32975. enablementChanged();
  32976. if (safePointer == 0)
  32977. return;
  32978. for (int i = getNumChildComponents(); --i >= 0;)
  32979. {
  32980. Component* const c = getChildComponent (i);
  32981. if (c != 0)
  32982. {
  32983. c->sendEnablementChangeMessage();
  32984. if (safePointer == 0)
  32985. return;
  32986. }
  32987. }
  32988. }
  32989. void Component::enablementChanged()
  32990. {
  32991. }
  32992. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  32993. {
  32994. flags.wantsFocusFlag = wantsFocus;
  32995. }
  32996. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  32997. {
  32998. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  32999. }
  33000. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33001. {
  33002. return ! flags.dontFocusOnMouseClickFlag;
  33003. }
  33004. bool Component::getWantsKeyboardFocus() const throw()
  33005. {
  33006. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33007. }
  33008. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33009. {
  33010. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33011. }
  33012. bool Component::isFocusContainer() const throw()
  33013. {
  33014. return flags.isFocusContainerFlag;
  33015. }
  33016. int Component::getExplicitFocusOrder() const
  33017. {
  33018. return properties ["_jexfo"];
  33019. }
  33020. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33021. {
  33022. properties.set ("_jexfo", newFocusOrderIndex);
  33023. }
  33024. KeyboardFocusTraverser* Component::createFocusTraverser()
  33025. {
  33026. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33027. return new KeyboardFocusTraverser();
  33028. return parentComponent_->createFocusTraverser();
  33029. }
  33030. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33031. {
  33032. // give the focus to this component
  33033. if (currentlyFocusedComponent != this)
  33034. {
  33035. JUCE_TRY
  33036. {
  33037. // get the focus onto our desktop window
  33038. ComponentPeer* const peer = getPeer();
  33039. if (peer != 0)
  33040. {
  33041. SafePointer<Component> safePointer (this);
  33042. peer->grabFocus();
  33043. if (peer->isFocused() && currentlyFocusedComponent != this)
  33044. {
  33045. Component* const componentLosingFocus = currentlyFocusedComponent;
  33046. currentlyFocusedComponent = this;
  33047. Desktop::getInstance().triggerFocusCallback();
  33048. // call this after setting currentlyFocusedComponent so that the one that's
  33049. // losing it has a chance to see where focus is going
  33050. if (componentLosingFocus->isValidComponent())
  33051. componentLosingFocus->internalFocusLoss (cause);
  33052. if (currentlyFocusedComponent == this)
  33053. {
  33054. focusGained (cause);
  33055. if (safePointer != 0)
  33056. internalChildFocusChange (cause);
  33057. }
  33058. }
  33059. }
  33060. }
  33061. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33062. catch (const std::exception& e)
  33063. {
  33064. currentlyFocusedComponent = 0;
  33065. Desktop::getInstance().triggerFocusCallback();
  33066. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33067. }
  33068. catch (...)
  33069. {
  33070. currentlyFocusedComponent = 0;
  33071. Desktop::getInstance().triggerFocusCallback();
  33072. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33073. }
  33074. #endif
  33075. }
  33076. }
  33077. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33078. {
  33079. if (isShowing())
  33080. {
  33081. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33082. {
  33083. takeKeyboardFocus (cause);
  33084. }
  33085. else
  33086. {
  33087. if (isParentOf (currentlyFocusedComponent)
  33088. && currentlyFocusedComponent->isShowing())
  33089. {
  33090. // do nothing if the focused component is actually a child of ours..
  33091. }
  33092. else
  33093. {
  33094. // find the default child component..
  33095. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33096. if (traverser != 0)
  33097. {
  33098. Component* const defaultComp = traverser->getDefaultComponent (this);
  33099. traverser = 0;
  33100. if (defaultComp != 0)
  33101. {
  33102. defaultComp->grabFocusInternal (cause, false);
  33103. return;
  33104. }
  33105. }
  33106. if (canTryParent && parentComponent_ != 0)
  33107. {
  33108. // if no children want it and we're allowed to try our parent comp,
  33109. // then pass up to parent, which will try our siblings.
  33110. parentComponent_->grabFocusInternal (cause, true);
  33111. }
  33112. }
  33113. }
  33114. }
  33115. }
  33116. void Component::grabKeyboardFocus()
  33117. {
  33118. // if component methods are being called from threads other than the message
  33119. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33120. checkMessageManagerIsLocked
  33121. grabFocusInternal (focusChangedDirectly);
  33122. }
  33123. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33124. {
  33125. // if component methods are being called from threads other than the message
  33126. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33127. checkMessageManagerIsLocked
  33128. if (parentComponent_ != 0)
  33129. {
  33130. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33131. if (traverser != 0)
  33132. {
  33133. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33134. : traverser->getPreviousComponent (this);
  33135. traverser = 0;
  33136. if (nextComp != 0)
  33137. {
  33138. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33139. {
  33140. SafePointer<Component> safePointer (this);
  33141. internalModalInputAttempt();
  33142. if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33143. return;
  33144. }
  33145. nextComp->grabFocusInternal (focusChangedByTabKey);
  33146. return;
  33147. }
  33148. }
  33149. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33150. }
  33151. }
  33152. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33153. {
  33154. return (currentlyFocusedComponent == this)
  33155. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33156. }
  33157. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33158. {
  33159. return currentlyFocusedComponent;
  33160. }
  33161. void Component::giveAwayFocus()
  33162. {
  33163. // use a copy so we can clear the value before the call
  33164. Component* const componentLosingFocus = currentlyFocusedComponent;
  33165. currentlyFocusedComponent = 0;
  33166. Desktop::getInstance().triggerFocusCallback();
  33167. if (componentLosingFocus->isValidComponent())
  33168. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33169. }
  33170. bool Component::isMouseOver() const throw()
  33171. {
  33172. return flags.mouseOverFlag;
  33173. }
  33174. bool Component::isMouseButtonDown() const throw()
  33175. {
  33176. return flags.draggingFlag;
  33177. }
  33178. bool Component::isMouseOverOrDragging() const throw()
  33179. {
  33180. return flags.mouseOverFlag || flags.draggingFlag;
  33181. }
  33182. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33183. {
  33184. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33185. }
  33186. const Point<int> Component::getMouseXYRelative() const
  33187. {
  33188. return globalPositionToRelative (Desktop::getMousePosition());
  33189. }
  33190. const Rectangle<int> Component::getParentMonitorArea() const
  33191. {
  33192. return Desktop::getInstance()
  33193. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33194. getHeight() / 2)));
  33195. }
  33196. void Component::addKeyListener (KeyListener* const newListener)
  33197. {
  33198. if (keyListeners_ == 0)
  33199. keyListeners_ = new VoidArray();
  33200. keyListeners_->addIfNotAlreadyThere (newListener);
  33201. }
  33202. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33203. {
  33204. if (keyListeners_ != 0)
  33205. keyListeners_->removeValue (listenerToRemove);
  33206. }
  33207. bool Component::keyPressed (const KeyPress&)
  33208. {
  33209. return false;
  33210. }
  33211. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33212. {
  33213. return false;
  33214. }
  33215. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33216. {
  33217. if (parentComponent_ != 0)
  33218. parentComponent_->modifierKeysChanged (modifiers);
  33219. }
  33220. void Component::internalModifierKeysChanged()
  33221. {
  33222. sendFakeMouseMove();
  33223. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33224. }
  33225. ComponentPeer* Component::getPeer() const
  33226. {
  33227. if (flags.hasHeavyweightPeerFlag)
  33228. return ComponentPeer::getPeerFor (this);
  33229. else if (parentComponent_ != 0)
  33230. return parentComponent_->getPeer();
  33231. else
  33232. return 0;
  33233. }
  33234. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33235. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33236. {
  33237. jassert (component1 != 0);
  33238. }
  33239. bool Component::BailOutChecker::shouldBailOut() const throw()
  33240. {
  33241. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33242. }
  33243. END_JUCE_NAMESPACE
  33244. /*** End of inlined file: juce_Component.cpp ***/
  33245. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33246. BEGIN_JUCE_NAMESPACE
  33247. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33248. void ComponentListener::componentBroughtToFront (Component&) {}
  33249. void ComponentListener::componentVisibilityChanged (Component&) {}
  33250. void ComponentListener::componentChildrenChanged (Component&) {}
  33251. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33252. void ComponentListener::componentNameChanged (Component&) {}
  33253. void ComponentListener::componentBeingDeleted (Component&) {}
  33254. END_JUCE_NAMESPACE
  33255. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33256. /*** Start of inlined file: juce_Desktop.cpp ***/
  33257. BEGIN_JUCE_NAMESPACE
  33258. Desktop::Desktop()
  33259. : mouseClickCounter (0),
  33260. kioskModeComponent (0)
  33261. {
  33262. createMouseInputSources();
  33263. refreshMonitorSizes();
  33264. }
  33265. Desktop::~Desktop()
  33266. {
  33267. jassert (instance == this);
  33268. instance = 0;
  33269. // doh! If you don't delete all your windows before exiting, you're going to
  33270. // be leaking memory!
  33271. jassert (desktopComponents.size() == 0);
  33272. }
  33273. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33274. {
  33275. if (instance == 0)
  33276. instance = new Desktop();
  33277. return *instance;
  33278. }
  33279. Desktop* Desktop::instance = 0;
  33280. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33281. const bool clipToWorkArea);
  33282. void Desktop::refreshMonitorSizes()
  33283. {
  33284. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33285. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33286. monitorCoordsClipped.clear();
  33287. monitorCoordsUnclipped.clear();
  33288. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33289. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33290. jassert (monitorCoordsClipped.size() > 0
  33291. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33292. if (oldClipped != monitorCoordsClipped
  33293. || oldUnclipped != monitorCoordsUnclipped)
  33294. {
  33295. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33296. {
  33297. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33298. if (p != 0)
  33299. p->handleScreenSizeChange();
  33300. }
  33301. }
  33302. }
  33303. int Desktop::getNumDisplayMonitors() const throw()
  33304. {
  33305. return monitorCoordsClipped.size();
  33306. }
  33307. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33308. {
  33309. return clippedToWorkArea ? monitorCoordsClipped [index]
  33310. : monitorCoordsUnclipped [index];
  33311. }
  33312. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33313. {
  33314. RectangleList rl;
  33315. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33316. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33317. return rl;
  33318. }
  33319. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33320. {
  33321. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33322. }
  33323. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33324. {
  33325. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33326. double bestDistance = 1.0e10;
  33327. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33328. {
  33329. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33330. if (rect.contains (position))
  33331. return rect;
  33332. const double distance = rect.getCentre().getDistanceFrom (position);
  33333. if (distance < bestDistance)
  33334. {
  33335. bestDistance = distance;
  33336. best = rect;
  33337. }
  33338. }
  33339. return best;
  33340. }
  33341. int Desktop::getNumComponents() const throw()
  33342. {
  33343. return desktopComponents.size();
  33344. }
  33345. Component* Desktop::getComponent (const int index) const throw()
  33346. {
  33347. return desktopComponents [index];
  33348. }
  33349. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33350. {
  33351. for (int i = desktopComponents.size(); --i >= 0;)
  33352. {
  33353. Component* const c = desktopComponents.getUnchecked(i);
  33354. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33355. if (c->contains (relative.getX(), relative.getY()))
  33356. return c->getComponentAt (relative.getX(), relative.getY());
  33357. }
  33358. return 0;
  33359. }
  33360. void Desktop::addDesktopComponent (Component* const c)
  33361. {
  33362. jassert (c != 0);
  33363. jassert (! desktopComponents.contains (c));
  33364. desktopComponents.addIfNotAlreadyThere (c);
  33365. }
  33366. void Desktop::removeDesktopComponent (Component* const c)
  33367. {
  33368. desktopComponents.removeValue (c);
  33369. }
  33370. void Desktop::componentBroughtToFront (Component* const c)
  33371. {
  33372. const int index = desktopComponents.indexOf (c);
  33373. jassert (index >= 0);
  33374. if (index >= 0)
  33375. {
  33376. int newIndex = -1;
  33377. if (! c->isAlwaysOnTop())
  33378. {
  33379. newIndex = desktopComponents.size();
  33380. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33381. --newIndex;
  33382. --newIndex;
  33383. }
  33384. desktopComponents.move (index, newIndex);
  33385. }
  33386. }
  33387. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33388. {
  33389. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33390. }
  33391. int Desktop::getMouseButtonClickCounter() throw()
  33392. {
  33393. return getInstance().mouseClickCounter;
  33394. }
  33395. void Desktop::incrementMouseClickCounter() throw()
  33396. {
  33397. ++mouseClickCounter;
  33398. }
  33399. int Desktop::getNumDraggingMouseSources() const throw()
  33400. {
  33401. int num = 0;
  33402. for (int i = mouseSources.size(); --i >= 0;)
  33403. if (mouseSources.getUnchecked(i)->isDragging())
  33404. ++num;
  33405. return num;
  33406. }
  33407. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33408. {
  33409. int num = 0;
  33410. for (int i = mouseSources.size(); --i >= 0;)
  33411. {
  33412. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33413. if (mi->isDragging())
  33414. {
  33415. if (index == num)
  33416. return mi;
  33417. ++num;
  33418. }
  33419. }
  33420. return 0;
  33421. }
  33422. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33423. {
  33424. focusListeners.add (listener);
  33425. }
  33426. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33427. {
  33428. focusListeners.remove (listener);
  33429. }
  33430. void Desktop::triggerFocusCallback()
  33431. {
  33432. triggerAsyncUpdate();
  33433. }
  33434. void Desktop::handleAsyncUpdate()
  33435. {
  33436. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33437. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33438. }
  33439. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33440. {
  33441. mouseListeners.add (listener);
  33442. resetTimer();
  33443. }
  33444. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33445. {
  33446. mouseListeners.remove (listener);
  33447. resetTimer();
  33448. }
  33449. void Desktop::timerCallback()
  33450. {
  33451. if (lastFakeMouseMove != getMousePosition())
  33452. sendMouseMove();
  33453. }
  33454. void Desktop::sendMouseMove()
  33455. {
  33456. if (! mouseListeners.isEmpty())
  33457. {
  33458. startTimer (20);
  33459. lastFakeMouseMove = getMousePosition();
  33460. Component* const target = findComponentAt (lastFakeMouseMove);
  33461. if (target != 0)
  33462. {
  33463. Component::BailOutChecker checker (target);
  33464. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33465. const Time now (Time::getCurrentTime());
  33466. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33467. target, now, pos, now, 0, false);
  33468. if (me.mods.isAnyMouseButtonDown())
  33469. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33470. else
  33471. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33472. }
  33473. }
  33474. }
  33475. void Desktop::resetTimer()
  33476. {
  33477. if (mouseListeners.size() == 0)
  33478. stopTimer();
  33479. else
  33480. startTimer (100);
  33481. lastFakeMouseMove = getMousePosition();
  33482. }
  33483. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33484. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33485. {
  33486. if (kioskModeComponent != componentToUse)
  33487. {
  33488. // agh! Don't delete a component without first stopping it being the kiosk comp
  33489. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33490. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33491. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33492. if (kioskModeComponent->isValidComponent())
  33493. {
  33494. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33495. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33496. }
  33497. kioskModeComponent = componentToUse;
  33498. if (kioskModeComponent != 0)
  33499. {
  33500. jassert (kioskModeComponent->isValidComponent());
  33501. // Only components that are already on the desktop can be put into kiosk mode!
  33502. jassert (kioskModeComponent->isOnDesktop());
  33503. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33504. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33505. }
  33506. }
  33507. }
  33508. END_JUCE_NAMESPACE
  33509. /*** End of inlined file: juce_Desktop.cpp ***/
  33510. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33511. BEGIN_JUCE_NAMESPACE
  33512. ArrowButton::ArrowButton (const String& name,
  33513. float arrowDirectionInRadians,
  33514. const Colour& arrowColour)
  33515. : Button (name),
  33516. colour (arrowColour)
  33517. {
  33518. path.lineTo (0.0f, 1.0f);
  33519. path.lineTo (1.0f, 0.5f);
  33520. path.closeSubPath();
  33521. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33522. 0.5f, 0.5f));
  33523. setComponentEffect (&shadow);
  33524. buttonStateChanged();
  33525. }
  33526. ArrowButton::~ArrowButton()
  33527. {
  33528. }
  33529. void ArrowButton::paintButton (Graphics& g,
  33530. bool /*isMouseOverButton*/,
  33531. bool /*isButtonDown*/)
  33532. {
  33533. g.setColour (colour);
  33534. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33535. (float) offset,
  33536. (float) (getWidth() - 3),
  33537. (float) (getHeight() - 3),
  33538. false));
  33539. }
  33540. void ArrowButton::buttonStateChanged()
  33541. {
  33542. offset = (isDown()) ? 1 : 0;
  33543. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33544. 0.3f, -1, 0);
  33545. }
  33546. END_JUCE_NAMESPACE
  33547. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33548. /*** Start of inlined file: juce_Button.cpp ***/
  33549. BEGIN_JUCE_NAMESPACE
  33550. class Button::RepeatTimer : public Timer
  33551. {
  33552. public:
  33553. RepeatTimer (Button& owner_) : owner (owner_) {}
  33554. void timerCallback() { owner.repeatTimerCallback(); }
  33555. juce_UseDebuggingNewOperator
  33556. private:
  33557. Button& owner;
  33558. RepeatTimer (const RepeatTimer&);
  33559. RepeatTimer& operator= (const RepeatTimer&);
  33560. };
  33561. Button::Button (const String& name)
  33562. : Component (name),
  33563. text (name),
  33564. buttonPressTime (0),
  33565. lastTimeCallbackTime (0),
  33566. commandManagerToUse (0),
  33567. autoRepeatDelay (-1),
  33568. autoRepeatSpeed (0),
  33569. autoRepeatMinimumDelay (-1),
  33570. radioGroupId (0),
  33571. commandID (0),
  33572. connectedEdgeFlags (0),
  33573. buttonState (buttonNormal),
  33574. lastToggleState (false),
  33575. clickTogglesState (false),
  33576. needsToRelease (false),
  33577. needsRepainting (false),
  33578. isKeyDown (false),
  33579. triggerOnMouseDown (false),
  33580. generateTooltip (false)
  33581. {
  33582. setWantsKeyboardFocus (true);
  33583. isOn.addListener (this);
  33584. }
  33585. Button::~Button()
  33586. {
  33587. isOn.removeListener (this);
  33588. if (commandManagerToUse != 0)
  33589. commandManagerToUse->removeListener (this);
  33590. repeatTimer = 0;
  33591. clearShortcuts();
  33592. }
  33593. void Button::setButtonText (const String& newText)
  33594. {
  33595. if (text != newText)
  33596. {
  33597. text = newText;
  33598. repaint();
  33599. }
  33600. }
  33601. void Button::setTooltip (const String& newTooltip)
  33602. {
  33603. SettableTooltipClient::setTooltip (newTooltip);
  33604. generateTooltip = false;
  33605. }
  33606. const String Button::getTooltip()
  33607. {
  33608. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33609. {
  33610. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33611. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33612. for (int i = 0; i < keyPresses.size(); ++i)
  33613. {
  33614. const String key (keyPresses.getReference(i).getTextDescription());
  33615. tt << " [";
  33616. if (key.length() == 1)
  33617. tt << TRANS("shortcut") << ": '" << key << "']";
  33618. else
  33619. tt << key << ']';
  33620. }
  33621. return tt;
  33622. }
  33623. return SettableTooltipClient::getTooltip();
  33624. }
  33625. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33626. {
  33627. if (connectedEdgeFlags != connectedEdgeFlags_)
  33628. {
  33629. connectedEdgeFlags = connectedEdgeFlags_;
  33630. repaint();
  33631. }
  33632. }
  33633. void Button::setToggleState (const bool shouldBeOn,
  33634. const bool sendChangeNotification)
  33635. {
  33636. if (shouldBeOn != lastToggleState)
  33637. {
  33638. isOn = shouldBeOn;
  33639. lastToggleState = shouldBeOn;
  33640. repaint();
  33641. if (sendChangeNotification)
  33642. {
  33643. Component::SafePointer<Component> deletionWatcher (this);
  33644. sendClickMessage (ModifierKeys());
  33645. if (deletionWatcher == 0)
  33646. return;
  33647. }
  33648. if (lastToggleState)
  33649. turnOffOtherButtonsInGroup (sendChangeNotification);
  33650. }
  33651. }
  33652. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33653. {
  33654. clickTogglesState = shouldToggle;
  33655. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33656. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33657. // it is that this button represents, and the button will update its state to reflect this
  33658. // in the applicationCommandListChanged() method.
  33659. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33660. }
  33661. bool Button::getClickingTogglesState() const throw()
  33662. {
  33663. return clickTogglesState;
  33664. }
  33665. void Button::valueChanged (Value& value)
  33666. {
  33667. if (value.refersToSameSourceAs (isOn))
  33668. setToggleState (isOn.getValue(), true);
  33669. }
  33670. void Button::setRadioGroupId (const int newGroupId)
  33671. {
  33672. if (radioGroupId != newGroupId)
  33673. {
  33674. radioGroupId = newGroupId;
  33675. if (lastToggleState)
  33676. turnOffOtherButtonsInGroup (true);
  33677. }
  33678. }
  33679. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33680. {
  33681. Component* const p = getParentComponent();
  33682. if (p != 0 && radioGroupId != 0)
  33683. {
  33684. Component::SafePointer<Component> deletionWatcher (this);
  33685. for (int i = p->getNumChildComponents(); --i >= 0;)
  33686. {
  33687. Component* const c = p->getChildComponent (i);
  33688. if (c != this)
  33689. {
  33690. Button* const b = dynamic_cast <Button*> (c);
  33691. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33692. {
  33693. b->setToggleState (false, sendChangeNotification);
  33694. if (deletionWatcher == 0)
  33695. return;
  33696. }
  33697. }
  33698. }
  33699. }
  33700. }
  33701. void Button::enablementChanged()
  33702. {
  33703. updateState (0);
  33704. repaint();
  33705. }
  33706. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33707. {
  33708. ButtonState state = buttonNormal;
  33709. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33710. {
  33711. Point<int> mousePos;
  33712. if (e == 0)
  33713. mousePos = getMouseXYRelative();
  33714. else
  33715. mousePos = e->getEventRelativeTo (this).getPosition();
  33716. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33717. const bool down = isMouseButtonDown();
  33718. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33719. state = buttonDown;
  33720. else if (over)
  33721. state = buttonOver;
  33722. }
  33723. setState (state);
  33724. return state;
  33725. }
  33726. void Button::setState (const ButtonState newState)
  33727. {
  33728. if (buttonState != newState)
  33729. {
  33730. buttonState = newState;
  33731. repaint();
  33732. if (buttonState == buttonDown)
  33733. {
  33734. buttonPressTime = Time::getApproximateMillisecondCounter();
  33735. lastTimeCallbackTime = buttonPressTime;
  33736. }
  33737. sendStateMessage();
  33738. }
  33739. }
  33740. bool Button::isDown() const throw()
  33741. {
  33742. return buttonState == buttonDown;
  33743. }
  33744. bool Button::isOver() const throw()
  33745. {
  33746. return buttonState != buttonNormal;
  33747. }
  33748. void Button::buttonStateChanged()
  33749. {
  33750. }
  33751. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33752. {
  33753. const uint32 now = Time::getApproximateMillisecondCounter();
  33754. return now > buttonPressTime ? now - buttonPressTime : 0;
  33755. }
  33756. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33757. {
  33758. triggerOnMouseDown = isTriggeredOnMouseDown;
  33759. }
  33760. void Button::clicked()
  33761. {
  33762. }
  33763. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33764. {
  33765. clicked();
  33766. }
  33767. static const int clickMessageId = 0x2f3f4f99;
  33768. void Button::triggerClick()
  33769. {
  33770. postCommandMessage (clickMessageId);
  33771. }
  33772. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33773. {
  33774. if (clickTogglesState)
  33775. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33776. sendClickMessage (modifiers);
  33777. }
  33778. void Button::flashButtonState()
  33779. {
  33780. if (isEnabled())
  33781. {
  33782. needsToRelease = true;
  33783. setState (buttonDown);
  33784. getRepeatTimer().startTimer (100);
  33785. }
  33786. }
  33787. void Button::handleCommandMessage (int commandId)
  33788. {
  33789. if (commandId == clickMessageId)
  33790. {
  33791. if (isEnabled())
  33792. {
  33793. flashButtonState();
  33794. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33795. }
  33796. }
  33797. else
  33798. {
  33799. Component::handleCommandMessage (commandId);
  33800. }
  33801. }
  33802. void Button::addButtonListener (ButtonListener* const newListener)
  33803. {
  33804. buttonListeners.add (newListener);
  33805. }
  33806. void Button::removeButtonListener (ButtonListener* const listener)
  33807. {
  33808. buttonListeners.remove (listener);
  33809. }
  33810. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33811. {
  33812. Component::BailOutChecker checker (this);
  33813. if (commandManagerToUse != 0 && commandID != 0)
  33814. {
  33815. ApplicationCommandTarget::InvocationInfo info (commandID);
  33816. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33817. info.originatingComponent = this;
  33818. commandManagerToUse->invoke (info, true);
  33819. }
  33820. clicked (modifiers);
  33821. if (! checker.shouldBailOut())
  33822. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33823. }
  33824. void Button::sendStateMessage()
  33825. {
  33826. Component::BailOutChecker checker (this);
  33827. buttonStateChanged();
  33828. if (! checker.shouldBailOut())
  33829. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33830. }
  33831. void Button::paint (Graphics& g)
  33832. {
  33833. if (needsToRelease && isEnabled())
  33834. {
  33835. needsToRelease = false;
  33836. needsRepainting = true;
  33837. }
  33838. paintButton (g, isOver(), isDown());
  33839. }
  33840. void Button::mouseEnter (const MouseEvent& e)
  33841. {
  33842. updateState (&e);
  33843. }
  33844. void Button::mouseExit (const MouseEvent& e)
  33845. {
  33846. updateState (&e);
  33847. }
  33848. void Button::mouseDown (const MouseEvent& e)
  33849. {
  33850. updateState (&e);
  33851. if (isDown())
  33852. {
  33853. if (autoRepeatDelay >= 0)
  33854. getRepeatTimer().startTimer (autoRepeatDelay);
  33855. if (triggerOnMouseDown)
  33856. internalClickCallback (e.mods);
  33857. }
  33858. }
  33859. void Button::mouseUp (const MouseEvent& e)
  33860. {
  33861. const bool wasDown = isDown();
  33862. updateState (&e);
  33863. if (wasDown && isOver() && ! triggerOnMouseDown)
  33864. internalClickCallback (e.mods);
  33865. }
  33866. void Button::mouseDrag (const MouseEvent& e)
  33867. {
  33868. const ButtonState oldState = buttonState;
  33869. updateState (&e);
  33870. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33871. getRepeatTimer().startTimer (autoRepeatSpeed);
  33872. }
  33873. void Button::focusGained (FocusChangeType)
  33874. {
  33875. updateState (0);
  33876. repaint();
  33877. }
  33878. void Button::focusLost (FocusChangeType)
  33879. {
  33880. updateState (0);
  33881. repaint();
  33882. }
  33883. void Button::setVisible (bool shouldBeVisible)
  33884. {
  33885. if (shouldBeVisible != isVisible())
  33886. {
  33887. Component::setVisible (shouldBeVisible);
  33888. if (! shouldBeVisible)
  33889. needsToRelease = false;
  33890. updateState (0);
  33891. }
  33892. else
  33893. {
  33894. Component::setVisible (shouldBeVisible);
  33895. }
  33896. }
  33897. void Button::parentHierarchyChanged()
  33898. {
  33899. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33900. if (newKeySource != keySource.getComponent())
  33901. {
  33902. if (keySource != 0)
  33903. keySource->removeKeyListener (this);
  33904. keySource = newKeySource;
  33905. if (keySource != 0)
  33906. keySource->addKeyListener (this);
  33907. }
  33908. }
  33909. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  33910. const int commandID_,
  33911. const bool generateTooltip_)
  33912. {
  33913. commandID = commandID_;
  33914. generateTooltip = generateTooltip_;
  33915. if (commandManagerToUse != commandManagerToUse_)
  33916. {
  33917. if (commandManagerToUse != 0)
  33918. commandManagerToUse->removeListener (this);
  33919. commandManagerToUse = commandManagerToUse_;
  33920. if (commandManagerToUse != 0)
  33921. commandManagerToUse->addListener (this);
  33922. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33923. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33924. // it is that this button represents, and the button will update its state to reflect this
  33925. // in the applicationCommandListChanged() method.
  33926. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33927. }
  33928. if (commandManagerToUse != 0)
  33929. applicationCommandListChanged();
  33930. else
  33931. setEnabled (true);
  33932. }
  33933. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  33934. {
  33935. if (info.commandID == commandID
  33936. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  33937. {
  33938. flashButtonState();
  33939. }
  33940. }
  33941. void Button::applicationCommandListChanged()
  33942. {
  33943. if (commandManagerToUse != 0)
  33944. {
  33945. ApplicationCommandInfo info (0);
  33946. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  33947. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  33948. if (target != 0)
  33949. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  33950. }
  33951. }
  33952. void Button::addShortcut (const KeyPress& key)
  33953. {
  33954. if (key.isValid())
  33955. {
  33956. jassert (! isRegisteredForShortcut (key)); // already registered!
  33957. shortcuts.add (key);
  33958. parentHierarchyChanged();
  33959. }
  33960. }
  33961. void Button::clearShortcuts()
  33962. {
  33963. shortcuts.clear();
  33964. parentHierarchyChanged();
  33965. }
  33966. bool Button::isShortcutPressed() const
  33967. {
  33968. if (! isCurrentlyBlockedByAnotherModalComponent())
  33969. {
  33970. for (int i = shortcuts.size(); --i >= 0;)
  33971. if (shortcuts.getReference(i).isCurrentlyDown())
  33972. return true;
  33973. }
  33974. return false;
  33975. }
  33976. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  33977. {
  33978. for (int i = shortcuts.size(); --i >= 0;)
  33979. if (key == shortcuts.getReference(i))
  33980. return true;
  33981. return false;
  33982. }
  33983. bool Button::keyStateChanged (const bool, Component*)
  33984. {
  33985. if (! isEnabled())
  33986. return false;
  33987. const bool wasDown = isKeyDown;
  33988. isKeyDown = isShortcutPressed();
  33989. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  33990. getRepeatTimer().startTimer (autoRepeatDelay);
  33991. updateState (0);
  33992. if (isEnabled() && wasDown && ! isKeyDown)
  33993. {
  33994. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33995. // (return immediately - this button may now have been deleted)
  33996. return true;
  33997. }
  33998. return wasDown || isKeyDown;
  33999. }
  34000. bool Button::keyPressed (const KeyPress&, Component*)
  34001. {
  34002. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34003. return isShortcutPressed();
  34004. }
  34005. bool Button::keyPressed (const KeyPress& key)
  34006. {
  34007. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34008. {
  34009. triggerClick();
  34010. return true;
  34011. }
  34012. return false;
  34013. }
  34014. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34015. const int repeatMillisecs,
  34016. const int minimumDelayInMillisecs) throw()
  34017. {
  34018. autoRepeatDelay = initialDelayMillisecs;
  34019. autoRepeatSpeed = repeatMillisecs;
  34020. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34021. }
  34022. void Button::repeatTimerCallback()
  34023. {
  34024. if (needsRepainting)
  34025. {
  34026. getRepeatTimer().stopTimer();
  34027. updateState (0);
  34028. needsRepainting = false;
  34029. }
  34030. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34031. {
  34032. int repeatSpeed = autoRepeatSpeed;
  34033. if (autoRepeatMinimumDelay >= 0)
  34034. {
  34035. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34036. timeHeldDown *= timeHeldDown;
  34037. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34038. }
  34039. repeatSpeed = jmax (1, repeatSpeed);
  34040. getRepeatTimer().startTimer (repeatSpeed);
  34041. const uint32 now = Time::getApproximateMillisecondCounter();
  34042. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34043. lastTimeCallbackTime = now;
  34044. Component::SafePointer<Component> deletionWatcher (this);
  34045. for (int i = numTimesToCallback; --i >= 0;)
  34046. {
  34047. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34048. if (deletionWatcher == 0 || ! isDown())
  34049. return;
  34050. }
  34051. }
  34052. else if (! needsToRelease)
  34053. {
  34054. getRepeatTimer().stopTimer();
  34055. }
  34056. }
  34057. Button::RepeatTimer& Button::getRepeatTimer()
  34058. {
  34059. if (repeatTimer == 0)
  34060. repeatTimer = new RepeatTimer (*this);
  34061. return *repeatTimer;
  34062. }
  34063. END_JUCE_NAMESPACE
  34064. /*** End of inlined file: juce_Button.cpp ***/
  34065. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34066. BEGIN_JUCE_NAMESPACE
  34067. DrawableButton::DrawableButton (const String& name,
  34068. const DrawableButton::ButtonStyle buttonStyle)
  34069. : Button (name),
  34070. style (buttonStyle),
  34071. edgeIndent (3)
  34072. {
  34073. if (buttonStyle == ImageOnButtonBackground)
  34074. {
  34075. backgroundOff = Colour (0xffbbbbff);
  34076. backgroundOn = Colour (0xff3333ff);
  34077. }
  34078. else
  34079. {
  34080. backgroundOff = Colours::transparentBlack;
  34081. backgroundOn = Colour (0xaabbbbff);
  34082. }
  34083. }
  34084. DrawableButton::~DrawableButton()
  34085. {
  34086. deleteImages();
  34087. }
  34088. void DrawableButton::deleteImages()
  34089. {
  34090. }
  34091. void DrawableButton::setImages (const Drawable* normal,
  34092. const Drawable* over,
  34093. const Drawable* down,
  34094. const Drawable* disabled,
  34095. const Drawable* normalOn,
  34096. const Drawable* overOn,
  34097. const Drawable* downOn,
  34098. const Drawable* disabledOn)
  34099. {
  34100. deleteImages();
  34101. jassert (normal != 0); // you really need to give it at least a normal image..
  34102. if (normal != 0)
  34103. normalImage = normal->createCopy();
  34104. if (over != 0)
  34105. overImage = over->createCopy();
  34106. if (down != 0)
  34107. downImage = down->createCopy();
  34108. if (disabled != 0)
  34109. disabledImage = disabled->createCopy();
  34110. if (normalOn != 0)
  34111. normalImageOn = normalOn->createCopy();
  34112. if (overOn != 0)
  34113. overImageOn = overOn->createCopy();
  34114. if (downOn != 0)
  34115. downImageOn = downOn->createCopy();
  34116. if (disabledOn != 0)
  34117. disabledImageOn = disabledOn->createCopy();
  34118. repaint();
  34119. }
  34120. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34121. {
  34122. if (style != newStyle)
  34123. {
  34124. style = newStyle;
  34125. repaint();
  34126. }
  34127. }
  34128. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34129. const Colour& toggledOnColour)
  34130. {
  34131. if (backgroundOff != toggledOffColour
  34132. || backgroundOn != toggledOnColour)
  34133. {
  34134. backgroundOff = toggledOffColour;
  34135. backgroundOn = toggledOnColour;
  34136. repaint();
  34137. }
  34138. }
  34139. const Colour& DrawableButton::getBackgroundColour() const throw()
  34140. {
  34141. return getToggleState() ? backgroundOn
  34142. : backgroundOff;
  34143. }
  34144. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34145. {
  34146. edgeIndent = numPixelsIndent;
  34147. repaint();
  34148. }
  34149. void DrawableButton::paintButton (Graphics& g,
  34150. bool isMouseOverButton,
  34151. bool isButtonDown)
  34152. {
  34153. Rectangle<int> imageSpace;
  34154. if (style == ImageOnButtonBackground)
  34155. {
  34156. const int insetX = getWidth() / 4;
  34157. const int insetY = getHeight() / 4;
  34158. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34159. getLookAndFeel().drawButtonBackground (g, *this,
  34160. getBackgroundColour(),
  34161. isMouseOverButton,
  34162. isButtonDown);
  34163. }
  34164. else
  34165. {
  34166. g.fillAll (getBackgroundColour());
  34167. const int textH = (style == ImageAboveTextLabel)
  34168. ? jmin (16, proportionOfHeight (0.25f))
  34169. : 0;
  34170. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34171. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34172. imageSpace.setBounds (indentX, indentY,
  34173. getWidth() - indentX * 2,
  34174. getHeight() - indentY * 2 - textH);
  34175. if (textH > 0)
  34176. {
  34177. g.setFont ((float) textH);
  34178. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34179. g.drawFittedText (getButtonText(),
  34180. 2, getHeight() - textH - 1,
  34181. getWidth() - 4, textH,
  34182. Justification::centred, 1);
  34183. }
  34184. }
  34185. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34186. g.setOpacity (1.0f);
  34187. const Drawable* imageToDraw = 0;
  34188. if (isEnabled())
  34189. {
  34190. imageToDraw = getCurrentImage();
  34191. }
  34192. else
  34193. {
  34194. imageToDraw = getToggleState() ? disabledImageOn
  34195. : disabledImage;
  34196. if (imageToDraw == 0)
  34197. {
  34198. g.setOpacity (0.4f);
  34199. imageToDraw = getNormalImage();
  34200. }
  34201. }
  34202. if (imageToDraw != 0)
  34203. {
  34204. if (style == ImageRaw)
  34205. {
  34206. imageToDraw->draw (g, 1.0f);
  34207. }
  34208. else
  34209. {
  34210. imageToDraw->drawWithin (g,
  34211. imageSpace.getX(),
  34212. imageSpace.getY(),
  34213. imageSpace.getWidth(),
  34214. imageSpace.getHeight(),
  34215. RectanglePlacement::centred,
  34216. 1.0f);
  34217. }
  34218. }
  34219. }
  34220. const Drawable* DrawableButton::getCurrentImage() const throw()
  34221. {
  34222. if (isDown())
  34223. return getDownImage();
  34224. if (isOver())
  34225. return getOverImage();
  34226. return getNormalImage();
  34227. }
  34228. const Drawable* DrawableButton::getNormalImage() const throw()
  34229. {
  34230. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34231. : normalImage;
  34232. }
  34233. const Drawable* DrawableButton::getOverImage() const throw()
  34234. {
  34235. const Drawable* d = normalImage;
  34236. if (getToggleState())
  34237. {
  34238. if (overImageOn != 0)
  34239. d = overImageOn;
  34240. else if (normalImageOn != 0)
  34241. d = normalImageOn;
  34242. else if (overImage != 0)
  34243. d = overImage;
  34244. }
  34245. else
  34246. {
  34247. if (overImage != 0)
  34248. d = overImage;
  34249. }
  34250. return d;
  34251. }
  34252. const Drawable* DrawableButton::getDownImage() const throw()
  34253. {
  34254. const Drawable* d = normalImage;
  34255. if (getToggleState())
  34256. {
  34257. if (downImageOn != 0)
  34258. d = downImageOn;
  34259. else if (overImageOn != 0)
  34260. d = overImageOn;
  34261. else if (normalImageOn != 0)
  34262. d = normalImageOn;
  34263. else if (downImage != 0)
  34264. d = downImage;
  34265. else
  34266. d = getOverImage();
  34267. }
  34268. else
  34269. {
  34270. if (downImage != 0)
  34271. d = downImage;
  34272. else
  34273. d = getOverImage();
  34274. }
  34275. return d;
  34276. }
  34277. END_JUCE_NAMESPACE
  34278. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34279. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34280. BEGIN_JUCE_NAMESPACE
  34281. HyperlinkButton::HyperlinkButton (const String& linkText,
  34282. const URL& linkURL)
  34283. : Button (linkText),
  34284. url (linkURL),
  34285. font (14.0f, Font::underlined),
  34286. resizeFont (true),
  34287. justification (Justification::centred)
  34288. {
  34289. setMouseCursor (MouseCursor::PointingHandCursor);
  34290. setTooltip (linkURL.toString (false));
  34291. }
  34292. HyperlinkButton::~HyperlinkButton()
  34293. {
  34294. }
  34295. void HyperlinkButton::setFont (const Font& newFont,
  34296. const bool resizeToMatchComponentHeight,
  34297. const Justification& justificationType)
  34298. {
  34299. font = newFont;
  34300. resizeFont = resizeToMatchComponentHeight;
  34301. justification = justificationType;
  34302. repaint();
  34303. }
  34304. void HyperlinkButton::setURL (const URL& newURL) throw()
  34305. {
  34306. url = newURL;
  34307. setTooltip (newURL.toString (false));
  34308. }
  34309. const Font HyperlinkButton::getFontToUse() const
  34310. {
  34311. Font f (font);
  34312. if (resizeFont)
  34313. f.setHeight (getHeight() * 0.7f);
  34314. return f;
  34315. }
  34316. void HyperlinkButton::changeWidthToFitText()
  34317. {
  34318. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34319. }
  34320. void HyperlinkButton::colourChanged()
  34321. {
  34322. repaint();
  34323. }
  34324. void HyperlinkButton::clicked()
  34325. {
  34326. if (url.isWellFormed())
  34327. url.launchInDefaultBrowser();
  34328. }
  34329. void HyperlinkButton::paintButton (Graphics& g,
  34330. bool isMouseOverButton,
  34331. bool isButtonDown)
  34332. {
  34333. const Colour textColour (findColour (textColourId));
  34334. if (isEnabled())
  34335. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34336. : textColour);
  34337. else
  34338. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34339. g.setFont (getFontToUse());
  34340. g.drawText (getButtonText(),
  34341. 2, 0, getWidth() - 2, getHeight(),
  34342. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34343. true);
  34344. }
  34345. END_JUCE_NAMESPACE
  34346. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34347. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34348. BEGIN_JUCE_NAMESPACE
  34349. ImageButton::ImageButton (const String& text_)
  34350. : Button (text_),
  34351. scaleImageToFit (true),
  34352. preserveProportions (true),
  34353. alphaThreshold (0),
  34354. imageX (0),
  34355. imageY (0),
  34356. imageW (0),
  34357. imageH (0),
  34358. normalImage (0),
  34359. overImage (0),
  34360. downImage (0)
  34361. {
  34362. }
  34363. ImageButton::~ImageButton()
  34364. {
  34365. deleteImages();
  34366. }
  34367. void ImageButton::deleteImages()
  34368. {
  34369. ImageCache::releaseOrDelete (normalImage);
  34370. ImageCache::releaseOrDelete (overImage);
  34371. ImageCache::releaseOrDelete (downImage);
  34372. }
  34373. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34374. const bool rescaleImagesWhenButtonSizeChanges,
  34375. const bool preserveImageProportions,
  34376. Image* const normalImage_,
  34377. const float imageOpacityWhenNormal,
  34378. const Colour& overlayColourWhenNormal,
  34379. Image* const overImage_,
  34380. const float imageOpacityWhenOver,
  34381. const Colour& overlayColourWhenOver,
  34382. Image* const downImage_,
  34383. const float imageOpacityWhenDown,
  34384. const Colour& overlayColourWhenDown,
  34385. const float hitTestAlphaThreshold)
  34386. {
  34387. deleteImages();
  34388. normalImage = normalImage_;
  34389. overImage = overImage_;
  34390. downImage = downImage_;
  34391. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34392. {
  34393. imageW = normalImage->getWidth();
  34394. imageH = normalImage->getHeight();
  34395. setSize (imageW, imageH);
  34396. }
  34397. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34398. preserveProportions = preserveImageProportions;
  34399. normalOpacity = imageOpacityWhenNormal;
  34400. normalOverlay = overlayColourWhenNormal;
  34401. overOpacity = imageOpacityWhenOver;
  34402. overOverlay = overlayColourWhenOver;
  34403. downOpacity = imageOpacityWhenDown;
  34404. downOverlay = overlayColourWhenDown;
  34405. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34406. repaint();
  34407. }
  34408. Image* ImageButton::getCurrentImage() const
  34409. {
  34410. if (isDown() || getToggleState())
  34411. return getDownImage();
  34412. if (isOver())
  34413. return getOverImage();
  34414. return getNormalImage();
  34415. }
  34416. Image* ImageButton::getNormalImage() const throw()
  34417. {
  34418. return normalImage;
  34419. }
  34420. Image* ImageButton::getOverImage() const throw()
  34421. {
  34422. return (overImage != 0) ? overImage
  34423. : normalImage;
  34424. }
  34425. Image* ImageButton::getDownImage() const throw()
  34426. {
  34427. return (downImage != 0) ? downImage
  34428. : getOverImage();
  34429. }
  34430. void ImageButton::paintButton (Graphics& g,
  34431. bool isMouseOverButton,
  34432. bool isButtonDown)
  34433. {
  34434. if (! isEnabled())
  34435. {
  34436. isMouseOverButton = false;
  34437. isButtonDown = false;
  34438. }
  34439. Image* const im = getCurrentImage();
  34440. if (im != 0)
  34441. {
  34442. const int iw = im->getWidth();
  34443. const int ih = im->getHeight();
  34444. imageW = getWidth();
  34445. imageH = getHeight();
  34446. imageX = (imageW - iw) >> 1;
  34447. imageY = (imageH - ih) >> 1;
  34448. if (scaleImageToFit)
  34449. {
  34450. if (preserveProportions)
  34451. {
  34452. int newW, newH;
  34453. const float imRatio = ih / (float)iw;
  34454. const float destRatio = imageH / (float)imageW;
  34455. if (imRatio > destRatio)
  34456. {
  34457. newW = roundToInt (imageH / imRatio);
  34458. newH = imageH;
  34459. }
  34460. else
  34461. {
  34462. newW = imageW;
  34463. newH = roundToInt (imageW * imRatio);
  34464. }
  34465. imageX = (imageW - newW) / 2;
  34466. imageY = (imageH - newH) / 2;
  34467. imageW = newW;
  34468. imageH = newH;
  34469. }
  34470. else
  34471. {
  34472. imageX = 0;
  34473. imageY = 0;
  34474. }
  34475. }
  34476. if (! scaleImageToFit)
  34477. {
  34478. imageW = iw;
  34479. imageH = ih;
  34480. }
  34481. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34482. isButtonDown ? downOverlay
  34483. : (isMouseOverButton ? overOverlay
  34484. : normalOverlay),
  34485. isButtonDown ? downOpacity
  34486. : (isMouseOverButton ? overOpacity
  34487. : normalOpacity),
  34488. *this);
  34489. }
  34490. }
  34491. bool ImageButton::hitTest (int x, int y)
  34492. {
  34493. if (alphaThreshold == 0)
  34494. return true;
  34495. Image* const im = getCurrentImage();
  34496. return im == 0
  34497. || (imageW > 0 && imageH > 0
  34498. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34499. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34500. }
  34501. END_JUCE_NAMESPACE
  34502. /*** End of inlined file: juce_ImageButton.cpp ***/
  34503. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34504. BEGIN_JUCE_NAMESPACE
  34505. ShapeButton::ShapeButton (const String& text_,
  34506. const Colour& normalColour_,
  34507. const Colour& overColour_,
  34508. const Colour& downColour_)
  34509. : Button (text_),
  34510. normalColour (normalColour_),
  34511. overColour (overColour_),
  34512. downColour (downColour_),
  34513. maintainShapeProportions (false),
  34514. outlineWidth (0.0f)
  34515. {
  34516. }
  34517. ShapeButton::~ShapeButton()
  34518. {
  34519. }
  34520. void ShapeButton::setColours (const Colour& newNormalColour,
  34521. const Colour& newOverColour,
  34522. const Colour& newDownColour)
  34523. {
  34524. normalColour = newNormalColour;
  34525. overColour = newOverColour;
  34526. downColour = newDownColour;
  34527. }
  34528. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34529. const float newOutlineWidth)
  34530. {
  34531. outlineColour = newOutlineColour;
  34532. outlineWidth = newOutlineWidth;
  34533. }
  34534. void ShapeButton::setShape (const Path& newShape,
  34535. const bool resizeNowToFitThisShape,
  34536. const bool maintainShapeProportions_,
  34537. const bool hasShadow)
  34538. {
  34539. shape = newShape;
  34540. maintainShapeProportions = maintainShapeProportions_;
  34541. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34542. setComponentEffect ((hasShadow) ? &shadow : 0);
  34543. if (resizeNowToFitThisShape)
  34544. {
  34545. Rectangle<float> bounds (shape.getBounds());
  34546. if (hasShadow)
  34547. bounds.expand (4.0f, 4.0f);
  34548. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34549. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34550. 1 + (int) (bounds.getHeight() + outlineWidth));
  34551. }
  34552. }
  34553. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34554. {
  34555. if (! isEnabled())
  34556. {
  34557. isMouseOverButton = false;
  34558. isButtonDown = false;
  34559. }
  34560. g.setColour ((isButtonDown) ? downColour
  34561. : (isMouseOverButton) ? overColour
  34562. : normalColour);
  34563. int w = getWidth();
  34564. int h = getHeight();
  34565. if (getComponentEffect() != 0)
  34566. {
  34567. w -= 4;
  34568. h -= 4;
  34569. }
  34570. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34571. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34572. w - offset - outlineWidth,
  34573. h - offset - outlineWidth,
  34574. maintainShapeProportions));
  34575. g.fillPath (shape, trans);
  34576. if (outlineWidth > 0.0f)
  34577. {
  34578. g.setColour (outlineColour);
  34579. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34580. }
  34581. }
  34582. END_JUCE_NAMESPACE
  34583. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34584. /*** Start of inlined file: juce_TextButton.cpp ***/
  34585. BEGIN_JUCE_NAMESPACE
  34586. TextButton::TextButton (const String& name,
  34587. const String& toolTip)
  34588. : Button (name)
  34589. {
  34590. setTooltip (toolTip);
  34591. }
  34592. TextButton::~TextButton()
  34593. {
  34594. }
  34595. void TextButton::paintButton (Graphics& g,
  34596. bool isMouseOverButton,
  34597. bool isButtonDown)
  34598. {
  34599. getLookAndFeel().drawButtonBackground (g, *this,
  34600. findColour (getToggleState() ? buttonOnColourId
  34601. : buttonColourId),
  34602. isMouseOverButton,
  34603. isButtonDown);
  34604. getLookAndFeel().drawButtonText (g, *this,
  34605. isMouseOverButton,
  34606. isButtonDown);
  34607. }
  34608. void TextButton::colourChanged()
  34609. {
  34610. repaint();
  34611. }
  34612. const Font TextButton::getFont()
  34613. {
  34614. return Font (jmin (15.0f, getHeight() * 0.6f));
  34615. }
  34616. void TextButton::changeWidthToFitText (const int newHeight)
  34617. {
  34618. if (newHeight >= 0)
  34619. setSize (jmax (1, getWidth()), newHeight);
  34620. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34621. getHeight());
  34622. }
  34623. END_JUCE_NAMESPACE
  34624. /*** End of inlined file: juce_TextButton.cpp ***/
  34625. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34626. BEGIN_JUCE_NAMESPACE
  34627. ToggleButton::ToggleButton (const String& buttonText)
  34628. : Button (buttonText)
  34629. {
  34630. setClickingTogglesState (true);
  34631. }
  34632. ToggleButton::~ToggleButton()
  34633. {
  34634. }
  34635. void ToggleButton::paintButton (Graphics& g,
  34636. bool isMouseOverButton,
  34637. bool isButtonDown)
  34638. {
  34639. getLookAndFeel().drawToggleButton (g, *this,
  34640. isMouseOverButton,
  34641. isButtonDown);
  34642. }
  34643. void ToggleButton::changeWidthToFitText()
  34644. {
  34645. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34646. }
  34647. void ToggleButton::colourChanged()
  34648. {
  34649. repaint();
  34650. }
  34651. END_JUCE_NAMESPACE
  34652. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34653. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34654. BEGIN_JUCE_NAMESPACE
  34655. ToolbarButton::ToolbarButton (const int itemId_,
  34656. const String& buttonText,
  34657. Drawable* const normalImage_,
  34658. Drawable* const toggledOnImage_)
  34659. : ToolbarItemComponent (itemId_, buttonText, true),
  34660. normalImage (normalImage_),
  34661. toggledOnImage (toggledOnImage_)
  34662. {
  34663. }
  34664. ToolbarButton::~ToolbarButton()
  34665. {
  34666. }
  34667. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34668. bool /*isToolbarVertical*/,
  34669. int& preferredSize,
  34670. int& minSize, int& maxSize)
  34671. {
  34672. preferredSize = minSize = maxSize = toolbarDepth;
  34673. return true;
  34674. }
  34675. void ToolbarButton::paintButtonArea (Graphics& g,
  34676. int width, int height,
  34677. bool /*isMouseOver*/,
  34678. bool /*isMouseDown*/)
  34679. {
  34680. Drawable* d = normalImage;
  34681. if (getToggleState() && toggledOnImage != 0)
  34682. d = toggledOnImage;
  34683. if (! isEnabled())
  34684. {
  34685. Image im (Image::ARGB, width, height, true);
  34686. Graphics g2 (im);
  34687. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34688. im.desaturate();
  34689. g.drawImageAt (&im, 0, 0);
  34690. }
  34691. else
  34692. {
  34693. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34694. }
  34695. }
  34696. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34697. {
  34698. }
  34699. END_JUCE_NAMESPACE
  34700. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34701. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34702. BEGIN_JUCE_NAMESPACE
  34703. class CodeDocumentLine
  34704. {
  34705. public:
  34706. CodeDocumentLine (const tchar* const line_,
  34707. const int lineLength_,
  34708. const int numNewLineChars,
  34709. const int lineStartInFile_)
  34710. : line (line_, lineLength_),
  34711. lineStartInFile (lineStartInFile_),
  34712. lineLength (lineLength_),
  34713. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34714. {
  34715. }
  34716. ~CodeDocumentLine()
  34717. {
  34718. }
  34719. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34720. {
  34721. const juce_wchar* const t = text;
  34722. int pos = 0;
  34723. while (t [pos] != 0)
  34724. {
  34725. const int startOfLine = pos;
  34726. int numNewLineChars = 0;
  34727. while (t[pos] != 0)
  34728. {
  34729. if (t[pos] == '\r')
  34730. {
  34731. ++numNewLineChars;
  34732. ++pos;
  34733. if (t[pos] == '\n')
  34734. {
  34735. ++numNewLineChars;
  34736. ++pos;
  34737. }
  34738. break;
  34739. }
  34740. if (t[pos] == '\n')
  34741. {
  34742. ++numNewLineChars;
  34743. ++pos;
  34744. break;
  34745. }
  34746. ++pos;
  34747. }
  34748. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34749. numNewLineChars, startOfLine));
  34750. }
  34751. jassert (pos == text.length());
  34752. }
  34753. bool endsWithLineBreak() const throw()
  34754. {
  34755. return lineLengthWithoutNewLines != lineLength;
  34756. }
  34757. void updateLength() throw()
  34758. {
  34759. lineLengthWithoutNewLines = lineLength = line.length();
  34760. while (lineLengthWithoutNewLines > 0
  34761. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34762. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34763. {
  34764. --lineLengthWithoutNewLines;
  34765. }
  34766. }
  34767. String line;
  34768. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34769. };
  34770. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34771. : document (document_),
  34772. currentLine (document_->lines[0]),
  34773. line (0),
  34774. position (0)
  34775. {
  34776. }
  34777. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34778. : document (other.document),
  34779. currentLine (other.currentLine),
  34780. line (other.line),
  34781. position (other.position)
  34782. {
  34783. }
  34784. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34785. {
  34786. document = other.document;
  34787. currentLine = other.currentLine;
  34788. line = other.line;
  34789. position = other.position;
  34790. return *this;
  34791. }
  34792. CodeDocument::Iterator::~Iterator() throw()
  34793. {
  34794. }
  34795. juce_wchar CodeDocument::Iterator::nextChar()
  34796. {
  34797. if (currentLine == 0)
  34798. return 0;
  34799. jassert (currentLine == document->lines.getUnchecked (line));
  34800. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34801. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34802. {
  34803. ++line;
  34804. currentLine = document->lines [line];
  34805. }
  34806. return result;
  34807. }
  34808. void CodeDocument::Iterator::skip()
  34809. {
  34810. if (currentLine != 0)
  34811. {
  34812. jassert (currentLine == document->lines.getUnchecked (line));
  34813. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34814. {
  34815. ++line;
  34816. currentLine = document->lines [line];
  34817. }
  34818. }
  34819. }
  34820. void CodeDocument::Iterator::skipToEndOfLine()
  34821. {
  34822. if (currentLine != 0)
  34823. {
  34824. jassert (currentLine == document->lines.getUnchecked (line));
  34825. ++line;
  34826. currentLine = document->lines [line];
  34827. if (currentLine != 0)
  34828. position = currentLine->lineStartInFile;
  34829. else
  34830. position = document->getNumCharacters();
  34831. }
  34832. }
  34833. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34834. {
  34835. if (currentLine == 0)
  34836. return 0;
  34837. jassert (currentLine == document->lines.getUnchecked (line));
  34838. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34839. }
  34840. void CodeDocument::Iterator::skipWhitespace()
  34841. {
  34842. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34843. skip();
  34844. }
  34845. bool CodeDocument::Iterator::isEOF() const throw()
  34846. {
  34847. return currentLine == 0;
  34848. }
  34849. CodeDocument::Position::Position() throw()
  34850. : owner (0), characterPos (0), line (0),
  34851. indexInLine (0), positionMaintained (false)
  34852. {
  34853. }
  34854. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34855. const int line_, const int indexInLine_) throw()
  34856. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34857. characterPos (0), line (line_),
  34858. indexInLine (indexInLine_), positionMaintained (false)
  34859. {
  34860. setLineAndIndex (line_, indexInLine_);
  34861. }
  34862. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34863. const int characterPos_) throw()
  34864. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34865. positionMaintained (false)
  34866. {
  34867. setPosition (characterPos_);
  34868. }
  34869. CodeDocument::Position::Position (const Position& other) throw()
  34870. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34871. indexInLine (other.indexInLine), positionMaintained (false)
  34872. {
  34873. jassert (*this == other);
  34874. }
  34875. CodeDocument::Position::~Position() throw()
  34876. {
  34877. setPositionMaintained (false);
  34878. }
  34879. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34880. {
  34881. if (this != &other)
  34882. {
  34883. const bool wasPositionMaintained = positionMaintained;
  34884. if (owner != other.owner)
  34885. setPositionMaintained (false);
  34886. owner = other.owner;
  34887. line = other.line;
  34888. indexInLine = other.indexInLine;
  34889. characterPos = other.characterPos;
  34890. setPositionMaintained (wasPositionMaintained);
  34891. jassert (*this == other);
  34892. }
  34893. return *this;
  34894. }
  34895. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34896. {
  34897. jassert ((characterPos == other.characterPos)
  34898. == (line == other.line && indexInLine == other.indexInLine));
  34899. return characterPos == other.characterPos
  34900. && line == other.line
  34901. && indexInLine == other.indexInLine
  34902. && owner == other.owner;
  34903. }
  34904. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  34905. {
  34906. return ! operator== (other);
  34907. }
  34908. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  34909. {
  34910. jassert (owner != 0);
  34911. if (owner->lines.size() == 0)
  34912. {
  34913. line = 0;
  34914. indexInLine = 0;
  34915. characterPos = 0;
  34916. }
  34917. else
  34918. {
  34919. if (newLine >= owner->lines.size())
  34920. {
  34921. line = owner->lines.size() - 1;
  34922. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34923. jassert (l != 0);
  34924. indexInLine = l->lineLengthWithoutNewLines;
  34925. characterPos = l->lineStartInFile + indexInLine;
  34926. }
  34927. else
  34928. {
  34929. line = jmax (0, newLine);
  34930. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34931. jassert (l != 0);
  34932. if (l->lineLengthWithoutNewLines > 0)
  34933. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  34934. else
  34935. indexInLine = 0;
  34936. characterPos = l->lineStartInFile + indexInLine;
  34937. }
  34938. }
  34939. }
  34940. void CodeDocument::Position::setPosition (const int newPosition) throw()
  34941. {
  34942. jassert (owner != 0);
  34943. line = 0;
  34944. indexInLine = 0;
  34945. characterPos = 0;
  34946. if (newPosition > 0)
  34947. {
  34948. int lineStart = 0;
  34949. int lineEnd = owner->lines.size();
  34950. for (;;)
  34951. {
  34952. if (lineEnd - lineStart < 4)
  34953. {
  34954. for (int i = lineStart; i < lineEnd; ++i)
  34955. {
  34956. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  34957. int index = newPosition - l->lineStartInFile;
  34958. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  34959. {
  34960. line = i;
  34961. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  34962. characterPos = l->lineStartInFile + indexInLine;
  34963. }
  34964. }
  34965. break;
  34966. }
  34967. else
  34968. {
  34969. const int midIndex = (lineStart + lineEnd + 1) / 2;
  34970. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  34971. if (newPosition >= mid->lineStartInFile)
  34972. lineStart = midIndex;
  34973. else
  34974. lineEnd = midIndex;
  34975. }
  34976. }
  34977. }
  34978. }
  34979. void CodeDocument::Position::moveBy (int characterDelta) throw()
  34980. {
  34981. jassert (owner != 0);
  34982. if (characterDelta == 1)
  34983. {
  34984. setPosition (getPosition());
  34985. // If moving right, make sure we don't get stuck between the \r and \n characters..
  34986. if (line < owner->lines.size())
  34987. {
  34988. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34989. if (indexInLine + characterDelta < l->lineLength
  34990. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  34991. ++characterDelta;
  34992. }
  34993. }
  34994. setPosition (characterPos + characterDelta);
  34995. }
  34996. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  34997. {
  34998. CodeDocument::Position p (*this);
  34999. p.moveBy (characterDelta);
  35000. return p;
  35001. }
  35002. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35003. {
  35004. CodeDocument::Position p (*this);
  35005. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35006. return p;
  35007. }
  35008. const tchar CodeDocument::Position::getCharacter() const throw()
  35009. {
  35010. const CodeDocumentLine* const l = owner->lines [line];
  35011. return l == 0 ? 0 : l->line [getIndexInLine()];
  35012. }
  35013. const String CodeDocument::Position::getLineText() const throw()
  35014. {
  35015. const CodeDocumentLine* const l = owner->lines [line];
  35016. return l == 0 ? String::empty : l->line;
  35017. }
  35018. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35019. {
  35020. if (isMaintained != positionMaintained)
  35021. {
  35022. positionMaintained = isMaintained;
  35023. if (owner != 0)
  35024. {
  35025. if (isMaintained)
  35026. {
  35027. jassert (! owner->positionsToMaintain.contains (this));
  35028. owner->positionsToMaintain.add (this);
  35029. }
  35030. else
  35031. {
  35032. jassert (owner->positionsToMaintain.contains (this));
  35033. owner->positionsToMaintain.removeValue (this);
  35034. }
  35035. }
  35036. }
  35037. }
  35038. CodeDocument::CodeDocument()
  35039. : undoManager (std::numeric_limits<int>::max(), 10000),
  35040. currentActionIndex (0),
  35041. indexOfSavedState (-1),
  35042. maximumLineLength (-1),
  35043. newLineChars ("\r\n")
  35044. {
  35045. }
  35046. CodeDocument::~CodeDocument()
  35047. {
  35048. }
  35049. const String CodeDocument::getAllContent() const throw()
  35050. {
  35051. return getTextBetween (Position (this, 0),
  35052. Position (this, lines.size(), 0));
  35053. }
  35054. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35055. {
  35056. if (end.getPosition() <= start.getPosition())
  35057. return String::empty;
  35058. const int startLine = start.getLineNumber();
  35059. const int endLine = end.getLineNumber();
  35060. if (startLine == endLine)
  35061. {
  35062. CodeDocumentLine* const line = lines [startLine];
  35063. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35064. }
  35065. String result;
  35066. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35067. String::Concatenator concatenator (result);
  35068. const int maxLine = jmin (lines.size() - 1, endLine);
  35069. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35070. {
  35071. const CodeDocumentLine* line = lines.getUnchecked(i);
  35072. int len = line->lineLength;
  35073. if (i == startLine)
  35074. {
  35075. const int index = start.getIndexInLine();
  35076. concatenator.append (line->line.substring (index, len));
  35077. }
  35078. else if (i == endLine)
  35079. {
  35080. len = end.getIndexInLine();
  35081. concatenator.append (line->line.substring (0, len));
  35082. }
  35083. else
  35084. {
  35085. concatenator.append (line->line);
  35086. }
  35087. }
  35088. return result;
  35089. }
  35090. int CodeDocument::getNumCharacters() const throw()
  35091. {
  35092. const CodeDocumentLine* const lastLine = lines.getLast();
  35093. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35094. }
  35095. const String CodeDocument::getLine (const int lineIndex) const throw()
  35096. {
  35097. const CodeDocumentLine* const line = lines [lineIndex];
  35098. return (line == 0) ? String::empty : line->line;
  35099. }
  35100. int CodeDocument::getMaximumLineLength() throw()
  35101. {
  35102. if (maximumLineLength < 0)
  35103. {
  35104. maximumLineLength = 0;
  35105. for (int i = lines.size(); --i >= 0;)
  35106. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35107. }
  35108. return maximumLineLength;
  35109. }
  35110. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35111. {
  35112. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35113. }
  35114. void CodeDocument::insertText (const Position& position, const String& text)
  35115. {
  35116. insert (text, position.getPosition(), true);
  35117. }
  35118. void CodeDocument::replaceAllContent (const String& newContent)
  35119. {
  35120. remove (0, getNumCharacters(), true);
  35121. insert (newContent, 0, true);
  35122. }
  35123. bool CodeDocument::loadFromStream (InputStream& stream)
  35124. {
  35125. replaceAllContent (stream.readEntireStreamAsString());
  35126. setSavePoint();
  35127. clearUndoHistory();
  35128. return true;
  35129. }
  35130. bool CodeDocument::writeToStream (OutputStream& stream)
  35131. {
  35132. for (int i = 0; i < lines.size(); ++i)
  35133. {
  35134. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35135. const char* utf8 = temp.toUTF8();
  35136. if (! stream.write (utf8, (int) strlen (utf8)))
  35137. return false;
  35138. }
  35139. return true;
  35140. }
  35141. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35142. {
  35143. jassert (newLine == "\r\n" || newLine == "\n" || newLine == "\r");
  35144. newLineChars = newLine;
  35145. }
  35146. void CodeDocument::newTransaction()
  35147. {
  35148. undoManager.beginNewTransaction (String::empty);
  35149. }
  35150. void CodeDocument::undo()
  35151. {
  35152. newTransaction();
  35153. undoManager.undo();
  35154. }
  35155. void CodeDocument::redo()
  35156. {
  35157. undoManager.redo();
  35158. }
  35159. void CodeDocument::clearUndoHistory()
  35160. {
  35161. undoManager.clearUndoHistory();
  35162. }
  35163. void CodeDocument::setSavePoint() throw()
  35164. {
  35165. indexOfSavedState = currentActionIndex;
  35166. }
  35167. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35168. {
  35169. return currentActionIndex != indexOfSavedState;
  35170. }
  35171. static int getCodeCharacterCategory (const tchar character) throw()
  35172. {
  35173. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35174. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35175. }
  35176. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35177. {
  35178. Position p (position);
  35179. const int maxDistance = 256;
  35180. int i = 0;
  35181. while (i < maxDistance
  35182. && CharacterFunctions::isWhitespace (p.getCharacter())
  35183. && (i == 0 || (p.getCharacter() != '\n'
  35184. && p.getCharacter() != '\r')))
  35185. {
  35186. ++i;
  35187. p.moveBy (1);
  35188. }
  35189. if (i == 0)
  35190. {
  35191. const int type = getCodeCharacterCategory (p.getCharacter());
  35192. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35193. {
  35194. ++i;
  35195. p.moveBy (1);
  35196. }
  35197. while (i < maxDistance
  35198. && CharacterFunctions::isWhitespace (p.getCharacter())
  35199. && (i == 0 || (p.getCharacter() != '\n'
  35200. && p.getCharacter() != '\r')))
  35201. {
  35202. ++i;
  35203. p.moveBy (1);
  35204. }
  35205. }
  35206. return p;
  35207. }
  35208. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35209. {
  35210. Position p (position);
  35211. const int maxDistance = 256;
  35212. int i = 0;
  35213. bool stoppedAtLineStart = false;
  35214. while (i < maxDistance)
  35215. {
  35216. const tchar c = p.movedBy (-1).getCharacter();
  35217. if (c == '\r' || c == '\n')
  35218. {
  35219. stoppedAtLineStart = true;
  35220. if (i > 0)
  35221. break;
  35222. }
  35223. if (! CharacterFunctions::isWhitespace (c))
  35224. break;
  35225. p.moveBy (-1);
  35226. ++i;
  35227. }
  35228. if (i < maxDistance && ! stoppedAtLineStart)
  35229. {
  35230. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35231. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35232. {
  35233. p.moveBy (-1);
  35234. ++i;
  35235. }
  35236. }
  35237. return p;
  35238. }
  35239. void CodeDocument::checkLastLineStatus()
  35240. {
  35241. while (lines.size() > 0
  35242. && lines.getLast()->lineLength == 0
  35243. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35244. {
  35245. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35246. lines.removeLast();
  35247. }
  35248. const CodeDocumentLine* const lastLine = lines.getLast();
  35249. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35250. {
  35251. // check that there's an empty line at the end if the preceding one ends in a newline..
  35252. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35253. }
  35254. }
  35255. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35256. {
  35257. listeners.add (listener);
  35258. }
  35259. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35260. {
  35261. listeners.remove (listener);
  35262. }
  35263. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35264. {
  35265. Position startPos (this, startLine, 0);
  35266. Position endPos (this, endLine, 0);
  35267. listeners.call (&Listener::codeDocumentChanged, startPos, endPos);
  35268. }
  35269. class CodeDocumentInsertAction : public UndoableAction
  35270. {
  35271. CodeDocument& owner;
  35272. const String text;
  35273. int insertPos;
  35274. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35275. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35276. public:
  35277. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35278. : owner (owner_),
  35279. text (text_),
  35280. insertPos (insertPos_)
  35281. {
  35282. }
  35283. ~CodeDocumentInsertAction() {}
  35284. bool perform()
  35285. {
  35286. owner.currentActionIndex++;
  35287. owner.insert (text, insertPos, false);
  35288. return true;
  35289. }
  35290. bool undo()
  35291. {
  35292. owner.currentActionIndex--;
  35293. owner.remove (insertPos, insertPos + text.length(), false);
  35294. return true;
  35295. }
  35296. int getSizeInUnits() { return text.length() + 32; }
  35297. };
  35298. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35299. {
  35300. if (text.isEmpty())
  35301. return;
  35302. if (undoable)
  35303. {
  35304. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35305. }
  35306. else
  35307. {
  35308. Position pos (this, insertPos);
  35309. const int firstAffectedLine = pos.getLineNumber();
  35310. int lastAffectedLine = firstAffectedLine + 1;
  35311. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35312. String textInsideOriginalLine (text);
  35313. if (firstLine != 0)
  35314. {
  35315. const int index = pos.getIndexInLine();
  35316. textInsideOriginalLine = firstLine->line.substring (0, index)
  35317. + textInsideOriginalLine
  35318. + firstLine->line.substring (index);
  35319. }
  35320. maximumLineLength = -1;
  35321. Array <CodeDocumentLine*> newLines;
  35322. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35323. jassert (newLines.size() > 0);
  35324. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35325. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35326. lines.set (firstAffectedLine, newFirstLine);
  35327. if (newLines.size() > 1)
  35328. {
  35329. for (int i = 1; i < newLines.size(); ++i)
  35330. {
  35331. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35332. lines.insert (firstAffectedLine + i, l);
  35333. }
  35334. lastAffectedLine = lines.size();
  35335. }
  35336. int i, lineStart = newFirstLine->lineStartInFile;
  35337. for (i = firstAffectedLine; i < lines.size(); ++i)
  35338. {
  35339. CodeDocumentLine* const l = lines.getUnchecked (i);
  35340. l->lineStartInFile = lineStart;
  35341. lineStart += l->lineLength;
  35342. }
  35343. checkLastLineStatus();
  35344. const int newTextLength = text.length();
  35345. for (i = 0; i < positionsToMaintain.size(); ++i)
  35346. {
  35347. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35348. if (p->getPosition() >= insertPos)
  35349. p->setPosition (p->getPosition() + newTextLength);
  35350. }
  35351. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35352. }
  35353. }
  35354. class CodeDocumentDeleteAction : public UndoableAction
  35355. {
  35356. CodeDocument& owner;
  35357. int startPos, endPos;
  35358. String removedText;
  35359. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35360. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35361. public:
  35362. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35363. : owner (owner_),
  35364. startPos (startPos_),
  35365. endPos (endPos_)
  35366. {
  35367. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35368. CodeDocument::Position (&owner, endPos));
  35369. }
  35370. ~CodeDocumentDeleteAction() {}
  35371. bool perform()
  35372. {
  35373. owner.currentActionIndex++;
  35374. owner.remove (startPos, endPos, false);
  35375. return true;
  35376. }
  35377. bool undo()
  35378. {
  35379. owner.currentActionIndex--;
  35380. owner.insert (removedText, startPos, false);
  35381. return true;
  35382. }
  35383. int getSizeInUnits() { return removedText.length() + 32; }
  35384. };
  35385. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35386. {
  35387. if (endPos <= startPos)
  35388. return;
  35389. if (undoable)
  35390. {
  35391. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35392. }
  35393. else
  35394. {
  35395. Position startPosition (this, startPos);
  35396. Position endPosition (this, endPos);
  35397. maximumLineLength = -1;
  35398. const int firstAffectedLine = startPosition.getLineNumber();
  35399. const int endLine = endPosition.getLineNumber();
  35400. int lastAffectedLine = firstAffectedLine + 1;
  35401. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35402. if (firstAffectedLine == endLine)
  35403. {
  35404. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35405. + firstLine->line.substring (endPosition.getIndexInLine());
  35406. firstLine->updateLength();
  35407. }
  35408. else
  35409. {
  35410. lastAffectedLine = lines.size();
  35411. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35412. jassert (lastLine != 0);
  35413. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35414. + lastLine->line.substring (endPosition.getIndexInLine());
  35415. firstLine->updateLength();
  35416. int numLinesToRemove = endLine - firstAffectedLine;
  35417. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35418. }
  35419. int i;
  35420. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35421. {
  35422. CodeDocumentLine* const l = lines.getUnchecked (i);
  35423. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35424. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35425. }
  35426. checkLastLineStatus();
  35427. const int totalChars = getNumCharacters();
  35428. for (i = 0; i < positionsToMaintain.size(); ++i)
  35429. {
  35430. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35431. if (p->getPosition() > startPosition.getPosition())
  35432. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35433. if (p->getPosition() > totalChars)
  35434. p->setPosition (totalChars);
  35435. }
  35436. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35437. }
  35438. }
  35439. END_JUCE_NAMESPACE
  35440. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35441. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35442. BEGIN_JUCE_NAMESPACE
  35443. class CodeEditorComponent::CaretComponent : public Component,
  35444. public Timer
  35445. {
  35446. public:
  35447. CaretComponent()
  35448. {
  35449. setAlwaysOnTop (true);
  35450. setInterceptsMouseClicks (false, false);
  35451. }
  35452. ~CaretComponent()
  35453. {
  35454. }
  35455. void paint (Graphics& g)
  35456. {
  35457. if (getParentComponent()->hasKeyboardFocus (true))
  35458. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35459. }
  35460. void timerCallback()
  35461. {
  35462. setVisible (! isVisible());
  35463. }
  35464. void updatePosition (CodeEditorComponent& owner)
  35465. {
  35466. startTimer (400);
  35467. setVisible (true);
  35468. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35469. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35470. }
  35471. private:
  35472. CaretComponent (const CaretComponent&);
  35473. CaretComponent& operator= (const CaretComponent&);
  35474. };
  35475. class CodeEditorComponent::CodeEditorLine
  35476. {
  35477. public:
  35478. CodeEditorLine() throw()
  35479. {
  35480. }
  35481. ~CodeEditorLine() throw()
  35482. {
  35483. }
  35484. bool update (CodeDocument& document, int lineNum,
  35485. CodeDocument::Iterator& source,
  35486. CodeTokeniser* analyser, const int spacesPerTab,
  35487. const CodeDocument::Position& selectionStart,
  35488. const CodeDocument::Position& selectionEnd)
  35489. {
  35490. Array <SyntaxToken> newTokens;
  35491. newTokens.ensureStorageAllocated (8);
  35492. if (analyser == 0)
  35493. {
  35494. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35495. }
  35496. else if (lineNum < document.getNumLines())
  35497. {
  35498. const CodeDocument::Position pos (&document, lineNum, 0);
  35499. createTokens (pos.getPosition(), pos.getLineText(),
  35500. source, analyser, newTokens);
  35501. }
  35502. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35503. int newHighlightStart = 0;
  35504. int newHighlightEnd = 0;
  35505. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35506. {
  35507. const String line (document.getLine (lineNum));
  35508. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35509. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35510. line, spacesPerTab);
  35511. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35512. line, spacesPerTab);
  35513. }
  35514. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35515. {
  35516. highlightColumnStart = newHighlightStart;
  35517. highlightColumnEnd = newHighlightEnd;
  35518. }
  35519. else
  35520. {
  35521. if (tokens.size() == newTokens.size())
  35522. {
  35523. bool allTheSame = true;
  35524. for (int i = newTokens.size(); --i >= 0;)
  35525. {
  35526. if (tokens.getReference(i) != newTokens.getReference(i))
  35527. {
  35528. allTheSame = false;
  35529. break;
  35530. }
  35531. }
  35532. if (allTheSame)
  35533. return false;
  35534. }
  35535. }
  35536. tokens.swapWithArray (newTokens);
  35537. return true;
  35538. }
  35539. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35540. float x, const int y, const int baselineOffset, const int lineHeight,
  35541. const Colour& highlightColour) const throw()
  35542. {
  35543. if (highlightColumnStart < highlightColumnEnd)
  35544. {
  35545. g.setColour (highlightColour);
  35546. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35547. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35548. }
  35549. int lastType = std::numeric_limits<int>::min();
  35550. for (int i = 0; i < tokens.size(); ++i)
  35551. {
  35552. SyntaxToken& token = tokens.getReference(i);
  35553. if (lastType != token.tokenType)
  35554. {
  35555. lastType = token.tokenType;
  35556. g.setColour (owner.getColourForTokenType (lastType));
  35557. }
  35558. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35559. if (i < tokens.size() - 1)
  35560. {
  35561. if (token.width < 0)
  35562. token.width = font.getStringWidthFloat (token.text);
  35563. x += token.width;
  35564. }
  35565. }
  35566. }
  35567. private:
  35568. struct SyntaxToken
  35569. {
  35570. String text;
  35571. int tokenType;
  35572. float width;
  35573. SyntaxToken (const String& text_, const int type) throw()
  35574. : text (text_), tokenType (type), width (-1.0f)
  35575. {
  35576. }
  35577. bool operator!= (const SyntaxToken& other) const throw()
  35578. {
  35579. return text != other.text || tokenType != other.tokenType;
  35580. }
  35581. };
  35582. Array <SyntaxToken> tokens;
  35583. int highlightColumnStart, highlightColumnEnd;
  35584. static void createTokens (int startPosition, const String& lineText,
  35585. CodeDocument::Iterator& source,
  35586. CodeTokeniser* analyser,
  35587. Array <SyntaxToken>& newTokens)
  35588. {
  35589. CodeDocument::Iterator lastIterator (source);
  35590. const int lineLength = lineText.length();
  35591. for (;;)
  35592. {
  35593. int tokenType = analyser->readNextToken (source);
  35594. int tokenStart = lastIterator.getPosition();
  35595. int tokenEnd = source.getPosition();
  35596. if (tokenEnd <= tokenStart)
  35597. break;
  35598. tokenEnd -= startPosition;
  35599. if (tokenEnd > 0)
  35600. {
  35601. tokenStart -= startPosition;
  35602. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35603. tokenType));
  35604. if (tokenEnd >= lineLength)
  35605. break;
  35606. }
  35607. lastIterator = source;
  35608. }
  35609. source = lastIterator;
  35610. }
  35611. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35612. {
  35613. int x = 0;
  35614. for (int i = 0; i < tokens.size(); ++i)
  35615. {
  35616. SyntaxToken& t = tokens.getReference(i);
  35617. for (;;)
  35618. {
  35619. int tabPos = t.text.indexOfChar ('\t');
  35620. if (tabPos < 0)
  35621. break;
  35622. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35623. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (" ", spacesNeeded));
  35624. }
  35625. x += t.text.length();
  35626. }
  35627. }
  35628. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35629. {
  35630. jassert (index <= line.length());
  35631. int col = 0;
  35632. for (int i = 0; i < index; ++i)
  35633. {
  35634. if (line[i] != '\t')
  35635. ++col;
  35636. else
  35637. col += spacesPerTab - (col % spacesPerTab);
  35638. }
  35639. return col;
  35640. }
  35641. };
  35642. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35643. CodeTokeniser* const codeTokeniser_)
  35644. : document (document_),
  35645. firstLineOnScreen (0),
  35646. gutter (5),
  35647. spacesPerTab (4),
  35648. lineHeight (0),
  35649. linesOnScreen (0),
  35650. columnsOnScreen (0),
  35651. scrollbarThickness (16),
  35652. columnToTryToMaintain (-1),
  35653. useSpacesForTabs (false),
  35654. xOffset (0),
  35655. codeTokeniser (codeTokeniser_)
  35656. {
  35657. caretPos = CodeDocument::Position (&document_, 0, 0);
  35658. caretPos.setPositionMaintained (true);
  35659. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35660. selectionStart.setPositionMaintained (true);
  35661. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35662. selectionEnd.setPositionMaintained (true);
  35663. setOpaque (true);
  35664. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35665. setWantsKeyboardFocus (true);
  35666. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35667. verticalScrollBar->setSingleStepSize (1.0);
  35668. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35669. horizontalScrollBar->setSingleStepSize (1.0);
  35670. addAndMakeVisible (caret = new CaretComponent());
  35671. Font f (12.0f);
  35672. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35673. setFont (f);
  35674. resetToDefaultColours();
  35675. verticalScrollBar->addListener (this);
  35676. horizontalScrollBar->addListener (this);
  35677. document.addListener (this);
  35678. }
  35679. CodeEditorComponent::~CodeEditorComponent()
  35680. {
  35681. document.removeListener (this);
  35682. deleteAllChildren();
  35683. }
  35684. void CodeEditorComponent::loadContent (const String& newContent)
  35685. {
  35686. clearCachedIterators (0);
  35687. document.replaceAllContent (newContent);
  35688. document.clearUndoHistory();
  35689. document.setSavePoint();
  35690. caretPos.setPosition (0);
  35691. selectionStart.setPosition (0);
  35692. selectionEnd.setPosition (0);
  35693. scrollToLine (0);
  35694. }
  35695. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35696. const CodeDocument::Position& affectedTextEnd)
  35697. {
  35698. clearCachedIterators (affectedTextStart.getLineNumber());
  35699. triggerAsyncUpdate();
  35700. caret->updatePosition (*this);
  35701. columnToTryToMaintain = -1;
  35702. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35703. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35704. deselectAll();
  35705. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35706. || caretPos.getPosition() < affectedTextStart.getPosition())
  35707. moveCaretTo (affectedTextStart, false);
  35708. updateScrollBars();
  35709. }
  35710. void CodeEditorComponent::resized()
  35711. {
  35712. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35713. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35714. lines.clear();
  35715. rebuildLineTokens();
  35716. caret->updatePosition (*this);
  35717. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35718. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35719. updateScrollBars();
  35720. }
  35721. void CodeEditorComponent::paint (Graphics& g)
  35722. {
  35723. handleUpdateNowIfNeeded();
  35724. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35725. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35726. g.setFont (font);
  35727. const int baselineOffset = (int) font.getAscent();
  35728. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35729. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35730. const Rectangle<int> clip (g.getClipBounds());
  35731. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35732. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35733. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35734. {
  35735. lines.getUnchecked(j)->draw (*this, g, font,
  35736. (float) (gutter - xOffset * charWidth),
  35737. lineHeight * j, baselineOffset, lineHeight,
  35738. highlightColour);
  35739. }
  35740. }
  35741. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35742. {
  35743. if (scrollbarThickness != thickness)
  35744. {
  35745. scrollbarThickness = thickness;
  35746. resized();
  35747. }
  35748. }
  35749. void CodeEditorComponent::handleAsyncUpdate()
  35750. {
  35751. rebuildLineTokens();
  35752. }
  35753. void CodeEditorComponent::rebuildLineTokens()
  35754. {
  35755. cancelPendingUpdate();
  35756. const int numNeeded = linesOnScreen + 1;
  35757. int minLineToRepaint = numNeeded;
  35758. int maxLineToRepaint = 0;
  35759. if (numNeeded != lines.size())
  35760. {
  35761. lines.clear();
  35762. for (int i = numNeeded; --i >= 0;)
  35763. lines.add (new CodeEditorLine());
  35764. minLineToRepaint = 0;
  35765. maxLineToRepaint = numNeeded;
  35766. }
  35767. jassert (numNeeded == lines.size());
  35768. CodeDocument::Iterator source (&document);
  35769. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35770. for (int i = 0; i < numNeeded; ++i)
  35771. {
  35772. CodeEditorLine* const line = lines.getUnchecked(i);
  35773. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35774. selectionStart, selectionEnd))
  35775. {
  35776. minLineToRepaint = jmin (minLineToRepaint, i);
  35777. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35778. }
  35779. }
  35780. if (minLineToRepaint <= maxLineToRepaint)
  35781. {
  35782. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35783. verticalScrollBar->getX() - gutter,
  35784. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35785. }
  35786. }
  35787. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35788. {
  35789. caretPos = newPos;
  35790. columnToTryToMaintain = -1;
  35791. if (highlighting)
  35792. {
  35793. if (dragType == notDragging)
  35794. {
  35795. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35796. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35797. dragType = draggingSelectionStart;
  35798. else
  35799. dragType = draggingSelectionEnd;
  35800. }
  35801. if (dragType == draggingSelectionStart)
  35802. {
  35803. selectionStart = caretPos;
  35804. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35805. {
  35806. const CodeDocument::Position temp (selectionStart);
  35807. selectionStart = selectionEnd;
  35808. selectionEnd = temp;
  35809. dragType = draggingSelectionEnd;
  35810. }
  35811. }
  35812. else
  35813. {
  35814. selectionEnd = caretPos;
  35815. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35816. {
  35817. const CodeDocument::Position temp (selectionStart);
  35818. selectionStart = selectionEnd;
  35819. selectionEnd = temp;
  35820. dragType = draggingSelectionStart;
  35821. }
  35822. }
  35823. triggerAsyncUpdate();
  35824. }
  35825. else
  35826. {
  35827. deselectAll();
  35828. }
  35829. caret->updatePosition (*this);
  35830. scrollToKeepCaretOnScreen();
  35831. updateScrollBars();
  35832. }
  35833. void CodeEditorComponent::deselectAll()
  35834. {
  35835. if (selectionStart != selectionEnd)
  35836. triggerAsyncUpdate();
  35837. selectionStart = caretPos;
  35838. selectionEnd = caretPos;
  35839. }
  35840. void CodeEditorComponent::updateScrollBars()
  35841. {
  35842. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35843. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35844. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35845. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35846. }
  35847. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35848. {
  35849. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35850. newFirstLineOnScreen);
  35851. if (newFirstLineOnScreen != firstLineOnScreen)
  35852. {
  35853. firstLineOnScreen = newFirstLineOnScreen;
  35854. caret->updatePosition (*this);
  35855. updateCachedIterators (firstLineOnScreen);
  35856. triggerAsyncUpdate();
  35857. }
  35858. }
  35859. void CodeEditorComponent::scrollToColumnInternal (double column)
  35860. {
  35861. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35862. if (xOffset != newOffset)
  35863. {
  35864. xOffset = newOffset;
  35865. caret->updatePosition (*this);
  35866. repaint();
  35867. }
  35868. }
  35869. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35870. {
  35871. scrollToLineInternal (newFirstLineOnScreen);
  35872. updateScrollBars();
  35873. }
  35874. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35875. {
  35876. scrollToColumnInternal (newFirstColumnOnScreen);
  35877. updateScrollBars();
  35878. }
  35879. void CodeEditorComponent::scrollBy (int deltaLines)
  35880. {
  35881. scrollToLine (firstLineOnScreen + deltaLines);
  35882. }
  35883. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35884. {
  35885. if (caretPos.getLineNumber() < firstLineOnScreen)
  35886. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35887. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35888. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35889. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35890. if (column >= xOffset + columnsOnScreen - 1)
  35891. scrollToColumn (column + 1 - columnsOnScreen);
  35892. else if (column < xOffset)
  35893. scrollToColumn (column);
  35894. }
  35895. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35896. {
  35897. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35898. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35899. roundToInt (charWidth),
  35900. lineHeight);
  35901. }
  35902. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35903. {
  35904. const int line = y / lineHeight + firstLineOnScreen;
  35905. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  35906. const int index = columnToIndex (line, column);
  35907. return CodeDocument::Position (&document, line, index);
  35908. }
  35909. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  35910. {
  35911. document.deleteSection (selectionStart, selectionEnd);
  35912. if (newText.isNotEmpty())
  35913. document.insertText (caretPos, newText);
  35914. scrollToKeepCaretOnScreen();
  35915. }
  35916. void CodeEditorComponent::insertTabAtCaret()
  35917. {
  35918. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  35919. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  35920. {
  35921. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  35922. }
  35923. if (useSpacesForTabs)
  35924. {
  35925. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35926. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  35927. insertTextAtCaret (String::repeatedString (" ", spacesNeeded));
  35928. }
  35929. else
  35930. {
  35931. insertTextAtCaret ("\t");
  35932. }
  35933. }
  35934. void CodeEditorComponent::cut()
  35935. {
  35936. insertTextAtCaret (String::empty);
  35937. }
  35938. void CodeEditorComponent::copy()
  35939. {
  35940. newTransaction();
  35941. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  35942. if (selection.isNotEmpty())
  35943. SystemClipboard::copyTextToClipboard (selection);
  35944. }
  35945. void CodeEditorComponent::copyThenCut()
  35946. {
  35947. copy();
  35948. cut();
  35949. newTransaction();
  35950. }
  35951. void CodeEditorComponent::paste()
  35952. {
  35953. newTransaction();
  35954. const String clip (SystemClipboard::getTextFromClipboard());
  35955. if (clip.isNotEmpty())
  35956. insertTextAtCaret (clip);
  35957. newTransaction();
  35958. }
  35959. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  35960. {
  35961. newTransaction();
  35962. if (moveInWholeWordSteps)
  35963. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  35964. else
  35965. moveCaretTo (caretPos.movedBy (-1), selecting);
  35966. }
  35967. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  35968. {
  35969. newTransaction();
  35970. if (moveInWholeWordSteps)
  35971. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  35972. else
  35973. moveCaretTo (caretPos.movedBy (1), selecting);
  35974. }
  35975. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  35976. {
  35977. CodeDocument::Position pos (caretPos);
  35978. const int newLineNum = pos.getLineNumber() + delta;
  35979. if (columnToTryToMaintain < 0)
  35980. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  35981. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  35982. const int colToMaintain = columnToTryToMaintain;
  35983. moveCaretTo (pos, selecting);
  35984. columnToTryToMaintain = colToMaintain;
  35985. }
  35986. void CodeEditorComponent::cursorDown (const bool selecting)
  35987. {
  35988. newTransaction();
  35989. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  35990. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  35991. else
  35992. moveLineDelta (1, selecting);
  35993. }
  35994. void CodeEditorComponent::cursorUp (const bool selecting)
  35995. {
  35996. newTransaction();
  35997. if (caretPos.getLineNumber() == 0)
  35998. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  35999. else
  36000. moveLineDelta (-1, selecting);
  36001. }
  36002. void CodeEditorComponent::pageDown (const bool selecting)
  36003. {
  36004. newTransaction();
  36005. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36006. moveLineDelta (linesOnScreen, selecting);
  36007. }
  36008. void CodeEditorComponent::pageUp (const bool selecting)
  36009. {
  36010. newTransaction();
  36011. scrollBy (-linesOnScreen);
  36012. moveLineDelta (-linesOnScreen, selecting);
  36013. }
  36014. void CodeEditorComponent::scrollUp()
  36015. {
  36016. newTransaction();
  36017. scrollBy (1);
  36018. if (caretPos.getLineNumber() < firstLineOnScreen)
  36019. moveLineDelta (1, false);
  36020. }
  36021. void CodeEditorComponent::scrollDown()
  36022. {
  36023. newTransaction();
  36024. scrollBy (-1);
  36025. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36026. moveLineDelta (-1, false);
  36027. }
  36028. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36029. {
  36030. newTransaction();
  36031. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36032. }
  36033. static int findFirstNonWhitespaceChar (const String& line) throw()
  36034. {
  36035. const int len = line.length();
  36036. for (int i = 0; i < len; ++i)
  36037. if (! CharacterFunctions::isWhitespace (line [i]))
  36038. return i;
  36039. return 0;
  36040. }
  36041. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36042. {
  36043. newTransaction();
  36044. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36045. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36046. index = 0;
  36047. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36048. }
  36049. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36050. {
  36051. newTransaction();
  36052. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36053. }
  36054. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36055. {
  36056. newTransaction();
  36057. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36058. }
  36059. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36060. {
  36061. if (moveInWholeWordSteps)
  36062. {
  36063. cut(); // in case something is already highlighted
  36064. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36065. }
  36066. else
  36067. {
  36068. if (selectionStart == selectionEnd)
  36069. selectionStart.moveBy (-1);
  36070. }
  36071. cut();
  36072. }
  36073. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36074. {
  36075. if (moveInWholeWordSteps)
  36076. {
  36077. cut(); // in case something is already highlighted
  36078. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36079. }
  36080. else
  36081. {
  36082. if (selectionStart == selectionEnd)
  36083. selectionEnd.moveBy (1);
  36084. else
  36085. newTransaction();
  36086. }
  36087. cut();
  36088. }
  36089. void CodeEditorComponent::selectAll()
  36090. {
  36091. newTransaction();
  36092. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36093. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36094. }
  36095. void CodeEditorComponent::undo()
  36096. {
  36097. document.undo();
  36098. scrollToKeepCaretOnScreen();
  36099. }
  36100. void CodeEditorComponent::redo()
  36101. {
  36102. document.redo();
  36103. scrollToKeepCaretOnScreen();
  36104. }
  36105. void CodeEditorComponent::newTransaction()
  36106. {
  36107. document.newTransaction();
  36108. startTimer (600);
  36109. }
  36110. void CodeEditorComponent::timerCallback()
  36111. {
  36112. newTransaction();
  36113. }
  36114. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36115. {
  36116. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36117. }
  36118. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36119. {
  36120. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36121. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36122. }
  36123. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36124. {
  36125. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36126. CodeDocument::Position (&document, range.getEnd()));
  36127. }
  36128. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36129. {
  36130. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36131. const bool shiftDown = key.getModifiers().isShiftDown();
  36132. if (key.isKeyCode (KeyPress::leftKey))
  36133. {
  36134. cursorLeft (moveInWholeWordSteps, shiftDown);
  36135. }
  36136. else if (key.isKeyCode (KeyPress::rightKey))
  36137. {
  36138. cursorRight (moveInWholeWordSteps, shiftDown);
  36139. }
  36140. else if (key.isKeyCode (KeyPress::upKey))
  36141. {
  36142. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36143. scrollDown();
  36144. #if JUCE_MAC
  36145. else if (key.getModifiers().isCommandDown())
  36146. goToStartOfDocument (shiftDown);
  36147. #endif
  36148. else
  36149. cursorUp (shiftDown);
  36150. }
  36151. else if (key.isKeyCode (KeyPress::downKey))
  36152. {
  36153. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36154. scrollUp();
  36155. #if JUCE_MAC
  36156. else if (key.getModifiers().isCommandDown())
  36157. goToEndOfDocument (shiftDown);
  36158. #endif
  36159. else
  36160. cursorDown (shiftDown);
  36161. }
  36162. else if (key.isKeyCode (KeyPress::pageDownKey))
  36163. {
  36164. pageDown (shiftDown);
  36165. }
  36166. else if (key.isKeyCode (KeyPress::pageUpKey))
  36167. {
  36168. pageUp (shiftDown);
  36169. }
  36170. else if (key.isKeyCode (KeyPress::homeKey))
  36171. {
  36172. if (moveInWholeWordSteps)
  36173. goToStartOfDocument (shiftDown);
  36174. else
  36175. goToStartOfLine (shiftDown);
  36176. }
  36177. else if (key.isKeyCode (KeyPress::endKey))
  36178. {
  36179. if (moveInWholeWordSteps)
  36180. goToEndOfDocument (shiftDown);
  36181. else
  36182. goToEndOfLine (shiftDown);
  36183. }
  36184. else if (key.isKeyCode (KeyPress::backspaceKey))
  36185. {
  36186. backspace (moveInWholeWordSteps);
  36187. }
  36188. else if (key.isKeyCode (KeyPress::deleteKey))
  36189. {
  36190. deleteForward (moveInWholeWordSteps);
  36191. }
  36192. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0))
  36193. {
  36194. copy();
  36195. }
  36196. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  36197. {
  36198. copyThenCut();
  36199. }
  36200. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0))
  36201. {
  36202. paste();
  36203. }
  36204. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  36205. {
  36206. undo();
  36207. }
  36208. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0)
  36209. || key == KeyPress ('z', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36210. {
  36211. redo();
  36212. }
  36213. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  36214. {
  36215. selectAll();
  36216. }
  36217. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36218. {
  36219. insertTabAtCaret();
  36220. }
  36221. else if (key == KeyPress::returnKey)
  36222. {
  36223. newTransaction();
  36224. insertTextAtCaret (document.getNewLineCharacters());
  36225. }
  36226. else if (key.isKeyCode (KeyPress::escapeKey))
  36227. {
  36228. newTransaction();
  36229. }
  36230. else if (key.getTextCharacter() >= ' ')
  36231. {
  36232. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36233. }
  36234. else
  36235. {
  36236. return false;
  36237. }
  36238. return true;
  36239. }
  36240. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36241. {
  36242. newTransaction();
  36243. dragType = notDragging;
  36244. if (! e.mods.isPopupMenu())
  36245. {
  36246. beginDragAutoRepeat (100);
  36247. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36248. }
  36249. else
  36250. {
  36251. }
  36252. }
  36253. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36254. {
  36255. if (! e.mods.isPopupMenu())
  36256. moveCaretTo (getPositionAt (e.x, e.y), true);
  36257. }
  36258. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36259. {
  36260. newTransaction();
  36261. beginDragAutoRepeat (0);
  36262. dragType = notDragging;
  36263. }
  36264. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36265. {
  36266. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36267. CodeDocument::Position tokenEnd (tokenStart);
  36268. if (e.getNumberOfClicks() > 2)
  36269. {
  36270. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36271. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36272. }
  36273. else
  36274. {
  36275. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36276. tokenEnd.moveBy (1);
  36277. tokenStart = tokenEnd;
  36278. while (tokenStart.getIndexInLine() > 0
  36279. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36280. tokenStart.moveBy (-1);
  36281. }
  36282. moveCaretTo (tokenEnd, false);
  36283. moveCaretTo (tokenStart, true);
  36284. }
  36285. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36286. {
  36287. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36288. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36289. }
  36290. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36291. {
  36292. if (scrollBarThatHasMoved == verticalScrollBar)
  36293. scrollToLineInternal ((int) newRangeStart);
  36294. else
  36295. scrollToColumnInternal (newRangeStart);
  36296. }
  36297. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36298. {
  36299. useSpacesForTabs = insertSpaces;
  36300. if (spacesPerTab != numSpaces)
  36301. {
  36302. spacesPerTab = numSpaces;
  36303. triggerAsyncUpdate();
  36304. }
  36305. }
  36306. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36307. {
  36308. const String line (document.getLine (lineNum));
  36309. jassert (index <= line.length());
  36310. int col = 0;
  36311. for (int i = 0; i < index; ++i)
  36312. {
  36313. if (line[i] != '\t')
  36314. ++col;
  36315. else
  36316. col += getTabSize() - (col % getTabSize());
  36317. }
  36318. return col;
  36319. }
  36320. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36321. {
  36322. const String line (document.getLine (lineNum));
  36323. const int lineLength = line.length();
  36324. int i, col = 0;
  36325. for (i = 0; i < lineLength; ++i)
  36326. {
  36327. if (line[i] != '\t')
  36328. ++col;
  36329. else
  36330. col += getTabSize() - (col % getTabSize());
  36331. if (col > column)
  36332. break;
  36333. }
  36334. return i;
  36335. }
  36336. void CodeEditorComponent::setFont (const Font& newFont)
  36337. {
  36338. font = newFont;
  36339. charWidth = font.getStringWidthFloat ("0");
  36340. lineHeight = roundToInt (font.getHeight());
  36341. resized();
  36342. }
  36343. void CodeEditorComponent::resetToDefaultColours()
  36344. {
  36345. coloursForTokenCategories.clear();
  36346. if (codeTokeniser != 0)
  36347. {
  36348. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36349. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36350. }
  36351. }
  36352. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36353. {
  36354. jassert (tokenType < 256);
  36355. while (coloursForTokenCategories.size() < tokenType)
  36356. coloursForTokenCategories.add (Colours::black);
  36357. coloursForTokenCategories.set (tokenType, colour);
  36358. repaint();
  36359. }
  36360. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36361. {
  36362. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36363. return findColour (CodeEditorComponent::defaultTextColourId);
  36364. return coloursForTokenCategories.getReference (tokenType);
  36365. }
  36366. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36367. {
  36368. int i;
  36369. for (i = cachedIterators.size(); --i >= 0;)
  36370. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36371. break;
  36372. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36373. }
  36374. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36375. {
  36376. const int maxNumCachedPositions = 5000;
  36377. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36378. if (cachedIterators.size() == 0)
  36379. cachedIterators.add (new CodeDocument::Iterator (&document));
  36380. if (codeTokeniser == 0)
  36381. return;
  36382. for (;;)
  36383. {
  36384. CodeDocument::Iterator* last = cachedIterators.getLast();
  36385. if (last->getLine() >= maxLineNum)
  36386. break;
  36387. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36388. cachedIterators.add (t);
  36389. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36390. for (;;)
  36391. {
  36392. codeTokeniser->readNextToken (*t);
  36393. if (t->getLine() >= targetLine)
  36394. break;
  36395. if (t->isEOF())
  36396. return;
  36397. }
  36398. }
  36399. }
  36400. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36401. {
  36402. if (codeTokeniser == 0)
  36403. return;
  36404. for (int i = cachedIterators.size(); --i >= 0;)
  36405. {
  36406. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36407. if (t->getPosition() <= position)
  36408. {
  36409. source = *t;
  36410. break;
  36411. }
  36412. }
  36413. while (source.getPosition() < position)
  36414. {
  36415. const CodeDocument::Iterator original (source);
  36416. codeTokeniser->readNextToken (source);
  36417. if (source.getPosition() > position || source.isEOF())
  36418. {
  36419. source = original;
  36420. break;
  36421. }
  36422. }
  36423. }
  36424. END_JUCE_NAMESPACE
  36425. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36426. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36427. BEGIN_JUCE_NAMESPACE
  36428. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36429. {
  36430. }
  36431. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36432. {
  36433. }
  36434. namespace CppTokeniser
  36435. {
  36436. static bool isIdentifierStart (const tchar c) throw()
  36437. {
  36438. return CharacterFunctions::isLetter (c)
  36439. || c == '_' || c == '@';
  36440. }
  36441. static bool isIdentifierBody (const tchar c) throw()
  36442. {
  36443. return CharacterFunctions::isLetter (c)
  36444. || CharacterFunctions::isDigit (c)
  36445. || c == '_' || c == '@';
  36446. }
  36447. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36448. {
  36449. static const tchar* keywords2Char[] =
  36450. { T("if"), T("do"), T("or"), 0 };
  36451. static const tchar* keywords3Char[] =
  36452. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36453. static const tchar* keywords4Char[] =
  36454. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36455. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36456. static const tchar* keywords5Char[] =
  36457. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36458. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36459. static const tchar* keywords6Char[] =
  36460. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36461. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36462. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36463. static const tchar* keywordsOther[] =
  36464. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36465. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36466. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36467. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36468. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36469. int tokenLength = 0;
  36470. tchar possibleIdentifier [19];
  36471. while (isIdentifierBody (source.peekNextChar()))
  36472. {
  36473. const tchar c = source.nextChar();
  36474. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36475. possibleIdentifier [tokenLength] = c;
  36476. ++tokenLength;
  36477. }
  36478. if (tokenLength > 1 && tokenLength <= 16)
  36479. {
  36480. possibleIdentifier [tokenLength] = 0;
  36481. const tchar** k;
  36482. switch (tokenLength)
  36483. {
  36484. case 2: k = keywords2Char; break;
  36485. case 3: k = keywords3Char; break;
  36486. case 4: k = keywords4Char; break;
  36487. case 5: k = keywords5Char; break;
  36488. case 6: k = keywords6Char; break;
  36489. default: k = keywordsOther; break;
  36490. }
  36491. int i = 0;
  36492. while (k[i] != 0)
  36493. {
  36494. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36495. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36496. ++i;
  36497. }
  36498. }
  36499. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36500. }
  36501. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36502. {
  36503. const juce_wchar c = source.peekNextChar();
  36504. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36505. source.skip();
  36506. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36507. return false;
  36508. return true;
  36509. }
  36510. static bool isHexDigit (const juce_wchar c) throw()
  36511. {
  36512. return (c >= '0' && c <= '9')
  36513. || (c >= 'a' && c <= 'f')
  36514. || (c >= 'A' && c <= 'F');
  36515. }
  36516. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36517. {
  36518. if (source.nextChar() != '0')
  36519. return false;
  36520. juce_wchar c = source.nextChar();
  36521. if (c != 'x' && c != 'X')
  36522. return false;
  36523. int numDigits = 0;
  36524. while (isHexDigit (source.peekNextChar()))
  36525. {
  36526. ++numDigits;
  36527. source.skip();
  36528. }
  36529. if (numDigits == 0)
  36530. return false;
  36531. return skipNumberSuffix (source);
  36532. }
  36533. static bool isOctalDigit (const juce_wchar c) throw()
  36534. {
  36535. return c >= '0' && c <= '7';
  36536. }
  36537. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36538. {
  36539. if (source.nextChar() != '0')
  36540. return false;
  36541. if (! isOctalDigit (source.nextChar()))
  36542. return false;
  36543. while (isOctalDigit (source.peekNextChar()))
  36544. source.skip();
  36545. return skipNumberSuffix (source);
  36546. }
  36547. static bool isDecimalDigit (const juce_wchar c) throw()
  36548. {
  36549. return c >= '0' && c <= '9';
  36550. }
  36551. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36552. {
  36553. int numChars = 0;
  36554. while (isDecimalDigit (source.peekNextChar()))
  36555. {
  36556. ++numChars;
  36557. source.skip();
  36558. }
  36559. if (numChars == 0)
  36560. return false;
  36561. return skipNumberSuffix (source);
  36562. }
  36563. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36564. {
  36565. int numDigits = 0;
  36566. while (isDecimalDigit (source.peekNextChar()))
  36567. {
  36568. source.skip();
  36569. ++numDigits;
  36570. }
  36571. const bool hasPoint = (source.peekNextChar() == '.');
  36572. if (hasPoint)
  36573. {
  36574. source.skip();
  36575. while (isDecimalDigit (source.peekNextChar()))
  36576. {
  36577. source.skip();
  36578. ++numDigits;
  36579. }
  36580. }
  36581. if (numDigits == 0)
  36582. return false;
  36583. juce_wchar c = source.peekNextChar();
  36584. const bool hasExponent = (c == 'e' || c == 'E');
  36585. if (hasExponent)
  36586. {
  36587. source.skip();
  36588. c = source.peekNextChar();
  36589. if (c == '+' || c == '-')
  36590. source.skip();
  36591. int numExpDigits = 0;
  36592. while (isDecimalDigit (source.peekNextChar()))
  36593. {
  36594. source.skip();
  36595. ++numExpDigits;
  36596. }
  36597. if (numExpDigits == 0)
  36598. return false;
  36599. }
  36600. c = source.peekNextChar();
  36601. if (c == 'f' || c == 'F')
  36602. source.skip();
  36603. else if (! (hasExponent || hasPoint))
  36604. return false;
  36605. return true;
  36606. }
  36607. static int parseNumber (CodeDocument::Iterator& source)
  36608. {
  36609. const CodeDocument::Iterator original (source);
  36610. if (parseFloatLiteral (source))
  36611. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36612. source = original;
  36613. if (parseHexLiteral (source))
  36614. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36615. source = original;
  36616. if (parseOctalLiteral (source))
  36617. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36618. source = original;
  36619. if (parseDecimalLiteral (source))
  36620. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36621. source = original;
  36622. source.skip();
  36623. return CPlusPlusCodeTokeniser::tokenType_error;
  36624. }
  36625. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36626. {
  36627. const juce_wchar quote = source.nextChar();
  36628. for (;;)
  36629. {
  36630. const juce_wchar c = source.nextChar();
  36631. if (c == quote || c == 0)
  36632. break;
  36633. if (c == '\\')
  36634. source.skip();
  36635. }
  36636. }
  36637. static void skipComment (CodeDocument::Iterator& source) throw()
  36638. {
  36639. bool lastWasStar = false;
  36640. for (;;)
  36641. {
  36642. const juce_wchar c = source.nextChar();
  36643. if (c == 0 || (c == '/' && lastWasStar))
  36644. break;
  36645. lastWasStar = (c == '*');
  36646. }
  36647. }
  36648. }
  36649. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36650. {
  36651. int result = tokenType_error;
  36652. source.skipWhitespace();
  36653. tchar firstChar = source.peekNextChar();
  36654. switch (firstChar)
  36655. {
  36656. case 0:
  36657. source.skip();
  36658. break;
  36659. case '0':
  36660. case '1':
  36661. case '2':
  36662. case '3':
  36663. case '4':
  36664. case '5':
  36665. case '6':
  36666. case '7':
  36667. case '8':
  36668. case '9':
  36669. result = CppTokeniser::parseNumber (source);
  36670. break;
  36671. case '.':
  36672. result = CppTokeniser::parseNumber (source);
  36673. if (result == tokenType_error)
  36674. result = tokenType_punctuation;
  36675. break;
  36676. case ',':
  36677. case ';':
  36678. case ':':
  36679. source.skip();
  36680. result = tokenType_punctuation;
  36681. break;
  36682. case '(':
  36683. case ')':
  36684. case '{':
  36685. case '}':
  36686. case '[':
  36687. case ']':
  36688. source.skip();
  36689. result = tokenType_bracket;
  36690. break;
  36691. case '"':
  36692. case '\'':
  36693. CppTokeniser::skipQuotedString (source);
  36694. result = tokenType_stringLiteral;
  36695. break;
  36696. case '+':
  36697. result = tokenType_operator;
  36698. source.skip();
  36699. if (source.peekNextChar() == '+')
  36700. source.skip();
  36701. else if (source.peekNextChar() == '=')
  36702. source.skip();
  36703. break;
  36704. case '-':
  36705. source.skip();
  36706. result = CppTokeniser::parseNumber (source);
  36707. if (result == tokenType_error)
  36708. {
  36709. result = tokenType_operator;
  36710. if (source.peekNextChar() == '-')
  36711. source.skip();
  36712. else if (source.peekNextChar() == '=')
  36713. source.skip();
  36714. }
  36715. break;
  36716. case '*':
  36717. case '%':
  36718. case '=':
  36719. case '!':
  36720. result = tokenType_operator;
  36721. source.skip();
  36722. if (source.peekNextChar() == '=')
  36723. source.skip();
  36724. break;
  36725. case '/':
  36726. result = tokenType_operator;
  36727. source.skip();
  36728. if (source.peekNextChar() == '=')
  36729. {
  36730. source.skip();
  36731. }
  36732. else if (source.peekNextChar() == '/')
  36733. {
  36734. result = tokenType_comment;
  36735. source.skipToEndOfLine();
  36736. }
  36737. else if (source.peekNextChar() == '*')
  36738. {
  36739. source.skip();
  36740. result = tokenType_comment;
  36741. CppTokeniser::skipComment (source);
  36742. }
  36743. break;
  36744. case '?':
  36745. case '~':
  36746. source.skip();
  36747. result = tokenType_operator;
  36748. break;
  36749. case '<':
  36750. source.skip();
  36751. result = tokenType_operator;
  36752. if (source.peekNextChar() == '=')
  36753. {
  36754. source.skip();
  36755. }
  36756. else if (source.peekNextChar() == '<')
  36757. {
  36758. source.skip();
  36759. if (source.peekNextChar() == '=')
  36760. source.skip();
  36761. }
  36762. break;
  36763. case '>':
  36764. source.skip();
  36765. result = tokenType_operator;
  36766. if (source.peekNextChar() == '=')
  36767. {
  36768. source.skip();
  36769. }
  36770. else if (source.peekNextChar() == '<')
  36771. {
  36772. source.skip();
  36773. if (source.peekNextChar() == '=')
  36774. source.skip();
  36775. }
  36776. break;
  36777. case '|':
  36778. source.skip();
  36779. result = tokenType_operator;
  36780. if (source.peekNextChar() == '=')
  36781. {
  36782. source.skip();
  36783. }
  36784. else if (source.peekNextChar() == '|')
  36785. {
  36786. source.skip();
  36787. if (source.peekNextChar() == '=')
  36788. source.skip();
  36789. }
  36790. break;
  36791. case '&':
  36792. source.skip();
  36793. result = tokenType_operator;
  36794. if (source.peekNextChar() == '=')
  36795. {
  36796. source.skip();
  36797. }
  36798. else if (source.peekNextChar() == '&')
  36799. {
  36800. source.skip();
  36801. if (source.peekNextChar() == '=')
  36802. source.skip();
  36803. }
  36804. break;
  36805. case '^':
  36806. source.skip();
  36807. result = tokenType_operator;
  36808. if (source.peekNextChar() == '=')
  36809. {
  36810. source.skip();
  36811. }
  36812. else if (source.peekNextChar() == '^')
  36813. {
  36814. source.skip();
  36815. if (source.peekNextChar() == '=')
  36816. source.skip();
  36817. }
  36818. break;
  36819. case '#':
  36820. result = tokenType_preprocessor;
  36821. source.skipToEndOfLine();
  36822. break;
  36823. default:
  36824. if (CppTokeniser::isIdentifierStart (firstChar))
  36825. result = CppTokeniser::parseIdentifier (source);
  36826. else
  36827. source.skip();
  36828. break;
  36829. }
  36830. //jassert (result != tokenType_unknown);
  36831. return result;
  36832. }
  36833. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36834. {
  36835. StringArray s;
  36836. s.add ("Error");
  36837. s.add ("Comment");
  36838. s.add ("C++ keyword");
  36839. s.add ("Identifier");
  36840. s.add ("Integer literal");
  36841. s.add ("Float literal");
  36842. s.add ("String literal");
  36843. s.add ("Operator");
  36844. s.add ("Bracket");
  36845. s.add ("Punctuation");
  36846. s.add ("Preprocessor line");
  36847. return s;
  36848. }
  36849. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36850. {
  36851. const uint32 colours[] =
  36852. {
  36853. 0xffcc0000, // error
  36854. 0xff00aa00, // comment
  36855. 0xff0000cc, // keyword
  36856. 0xff000000, // identifier
  36857. 0xff880000, // int literal
  36858. 0xff885500, // float literal
  36859. 0xff990099, // string literal
  36860. 0xff225500, // operator
  36861. 0xff000055, // bracket
  36862. 0xff004400, // punctuation
  36863. 0xff660000 // preprocessor
  36864. };
  36865. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36866. return Colour (colours [tokenType]);
  36867. return Colours::black;
  36868. }
  36869. END_JUCE_NAMESPACE
  36870. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36871. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36872. BEGIN_JUCE_NAMESPACE
  36873. ComboBox::ComboBox (const String& name)
  36874. : Component (name),
  36875. lastCurrentId (0),
  36876. isButtonDown (false),
  36877. separatorPending (false),
  36878. menuActive (false),
  36879. label (0)
  36880. {
  36881. noChoicesMessage = TRANS("(no choices)");
  36882. setRepaintsOnMouseActivity (true);
  36883. lookAndFeelChanged();
  36884. currentId.addListener (this);
  36885. }
  36886. ComboBox::~ComboBox()
  36887. {
  36888. currentId.removeListener (this);
  36889. if (menuActive)
  36890. PopupMenu::dismissAllActiveMenus();
  36891. label = 0;
  36892. deleteAllChildren();
  36893. }
  36894. void ComboBox::setEditableText (const bool isEditable)
  36895. {
  36896. label->setEditable (isEditable, isEditable, false);
  36897. setWantsKeyboardFocus (! isEditable);
  36898. resized();
  36899. }
  36900. bool ComboBox::isTextEditable() const throw()
  36901. {
  36902. return label->isEditable();
  36903. }
  36904. void ComboBox::setJustificationType (const Justification& justification) throw()
  36905. {
  36906. label->setJustificationType (justification);
  36907. }
  36908. const Justification ComboBox::getJustificationType() const throw()
  36909. {
  36910. return label->getJustificationType();
  36911. }
  36912. void ComboBox::setTooltip (const String& newTooltip)
  36913. {
  36914. SettableTooltipClient::setTooltip (newTooltip);
  36915. label->setTooltip (newTooltip);
  36916. }
  36917. void ComboBox::addItem (const String& newItemText,
  36918. const int newItemId) throw()
  36919. {
  36920. // you can't add empty strings to the list..
  36921. jassert (newItemText.isNotEmpty());
  36922. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  36923. jassert (newItemId != 0);
  36924. // you shouldn't use duplicate item IDs!
  36925. jassert (getItemForId (newItemId) == 0);
  36926. if (newItemText.isNotEmpty() && newItemId != 0)
  36927. {
  36928. if (separatorPending)
  36929. {
  36930. separatorPending = false;
  36931. ItemInfo* const item = new ItemInfo();
  36932. item->itemId = 0;
  36933. item->isEnabled = false;
  36934. item->isHeading = false;
  36935. items.add (item);
  36936. }
  36937. ItemInfo* const item = new ItemInfo();
  36938. item->name = newItemText;
  36939. item->itemId = newItemId;
  36940. item->isEnabled = true;
  36941. item->isHeading = false;
  36942. items.add (item);
  36943. }
  36944. }
  36945. void ComboBox::addSeparator() throw()
  36946. {
  36947. separatorPending = (items.size() > 0);
  36948. }
  36949. void ComboBox::addSectionHeading (const String& headingName) throw()
  36950. {
  36951. // you can't add empty strings to the list..
  36952. jassert (headingName.isNotEmpty());
  36953. if (headingName.isNotEmpty())
  36954. {
  36955. if (separatorPending)
  36956. {
  36957. separatorPending = false;
  36958. ItemInfo* const item = new ItemInfo();
  36959. item->itemId = 0;
  36960. item->isEnabled = false;
  36961. item->isHeading = false;
  36962. items.add (item);
  36963. }
  36964. ItemInfo* const item = new ItemInfo();
  36965. item->name = headingName;
  36966. item->itemId = 0;
  36967. item->isEnabled = true;
  36968. item->isHeading = true;
  36969. items.add (item);
  36970. }
  36971. }
  36972. void ComboBox::setItemEnabled (const int itemId,
  36973. const bool shouldBeEnabled) throw()
  36974. {
  36975. ItemInfo* const item = getItemForId (itemId);
  36976. if (item != 0)
  36977. item->isEnabled = shouldBeEnabled;
  36978. }
  36979. void ComboBox::changeItemText (const int itemId,
  36980. const String& newText) throw()
  36981. {
  36982. ItemInfo* const item = getItemForId (itemId);
  36983. jassert (item != 0);
  36984. if (item != 0)
  36985. item->name = newText;
  36986. }
  36987. void ComboBox::clear (const bool dontSendChangeMessage)
  36988. {
  36989. items.clear();
  36990. separatorPending = false;
  36991. if (! label->isEditable())
  36992. setSelectedItemIndex (-1, dontSendChangeMessage);
  36993. }
  36994. bool ComboBox::ItemInfo::isSeparator() const throw()
  36995. {
  36996. return name.isEmpty();
  36997. }
  36998. bool ComboBox::ItemInfo::isRealItem() const throw()
  36999. {
  37000. return ! (isHeading || name.isEmpty());
  37001. }
  37002. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37003. {
  37004. if (itemId != 0)
  37005. {
  37006. for (int i = items.size(); --i >= 0;)
  37007. if (items.getUnchecked(i)->itemId == itemId)
  37008. return items.getUnchecked(i);
  37009. }
  37010. return 0;
  37011. }
  37012. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37013. {
  37014. int n = 0;
  37015. for (int i = 0; i < items.size(); ++i)
  37016. {
  37017. ItemInfo* const item = items.getUnchecked(i);
  37018. if (item->isRealItem())
  37019. if (n++ == index)
  37020. return item;
  37021. }
  37022. return 0;
  37023. }
  37024. int ComboBox::getNumItems() const throw()
  37025. {
  37026. int n = 0;
  37027. for (int i = items.size(); --i >= 0;)
  37028. if (items.getUnchecked(i)->isRealItem())
  37029. ++n;
  37030. return n;
  37031. }
  37032. const String ComboBox::getItemText (const int index) const throw()
  37033. {
  37034. const ItemInfo* const item = getItemForIndex (index);
  37035. if (item != 0)
  37036. return item->name;
  37037. return String::empty;
  37038. }
  37039. int ComboBox::getItemId (const int index) const throw()
  37040. {
  37041. const ItemInfo* const item = getItemForIndex (index);
  37042. return (item != 0) ? item->itemId : 0;
  37043. }
  37044. int ComboBox::indexOfItemId (const int itemId) const throw()
  37045. {
  37046. int n = 0;
  37047. for (int i = 0; i < items.size(); ++i)
  37048. {
  37049. const ItemInfo* const item = items.getUnchecked(i);
  37050. if (item->isRealItem())
  37051. {
  37052. if (item->itemId == itemId)
  37053. return n;
  37054. ++n;
  37055. }
  37056. }
  37057. return -1;
  37058. }
  37059. int ComboBox::getSelectedItemIndex() const throw()
  37060. {
  37061. int index = indexOfItemId (currentId.getValue());
  37062. if (getText() != getItemText (index))
  37063. index = -1;
  37064. return index;
  37065. }
  37066. void ComboBox::setSelectedItemIndex (const int index,
  37067. const bool dontSendChangeMessage) throw()
  37068. {
  37069. setSelectedId (getItemId (index), dontSendChangeMessage);
  37070. }
  37071. int ComboBox::getSelectedId() const throw()
  37072. {
  37073. const ItemInfo* const item = getItemForId (currentId.getValue());
  37074. return (item != 0 && getText() == item->name)
  37075. ? item->itemId
  37076. : 0;
  37077. }
  37078. void ComboBox::setSelectedId (const int newItemId,
  37079. const bool dontSendChangeMessage) throw()
  37080. {
  37081. const ItemInfo* const item = getItemForId (newItemId);
  37082. const String newItemText (item != 0 ? item->name : String::empty);
  37083. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37084. {
  37085. if (! dontSendChangeMessage)
  37086. triggerAsyncUpdate();
  37087. label->setText (newItemText, false);
  37088. lastCurrentId = newItemId;
  37089. currentId = newItemId;
  37090. repaint(); // for the benefit of the 'none selected' text
  37091. }
  37092. }
  37093. void ComboBox::valueChanged (Value&)
  37094. {
  37095. if (lastCurrentId != (int) currentId.getValue())
  37096. setSelectedId (currentId.getValue(), false);
  37097. }
  37098. const String ComboBox::getText() const throw()
  37099. {
  37100. return label->getText();
  37101. }
  37102. void ComboBox::setText (const String& newText,
  37103. const bool dontSendChangeMessage) throw()
  37104. {
  37105. for (int i = items.size(); --i >= 0;)
  37106. {
  37107. const ItemInfo* const item = items.getUnchecked(i);
  37108. if (item->isRealItem()
  37109. && item->name == newText)
  37110. {
  37111. setSelectedId (item->itemId, dontSendChangeMessage);
  37112. return;
  37113. }
  37114. }
  37115. lastCurrentId = 0;
  37116. currentId = 0;
  37117. if (label->getText() != newText)
  37118. {
  37119. label->setText (newText, false);
  37120. if (! dontSendChangeMessage)
  37121. triggerAsyncUpdate();
  37122. }
  37123. repaint();
  37124. }
  37125. void ComboBox::showEditor()
  37126. {
  37127. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37128. label->showEditor();
  37129. }
  37130. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37131. {
  37132. textWhenNothingSelected = newMessage;
  37133. repaint();
  37134. }
  37135. const String ComboBox::getTextWhenNothingSelected() const throw()
  37136. {
  37137. return textWhenNothingSelected;
  37138. }
  37139. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37140. {
  37141. noChoicesMessage = newMessage;
  37142. }
  37143. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37144. {
  37145. return noChoicesMessage;
  37146. }
  37147. void ComboBox::paint (Graphics& g)
  37148. {
  37149. getLookAndFeel().drawComboBox (g,
  37150. getWidth(),
  37151. getHeight(),
  37152. isButtonDown,
  37153. label->getRight(),
  37154. 0,
  37155. getWidth() - label->getRight(),
  37156. getHeight(),
  37157. *this);
  37158. if (textWhenNothingSelected.isNotEmpty()
  37159. && label->getText().isEmpty()
  37160. && ! label->isBeingEdited())
  37161. {
  37162. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37163. g.setFont (label->getFont());
  37164. g.drawFittedText (textWhenNothingSelected,
  37165. label->getX() + 2, label->getY() + 1,
  37166. label->getWidth() - 4, label->getHeight() - 2,
  37167. label->getJustificationType(),
  37168. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37169. }
  37170. }
  37171. void ComboBox::resized()
  37172. {
  37173. if (getHeight() > 0 && getWidth() > 0)
  37174. getLookAndFeel().positionComboBoxText (*this, *label);
  37175. }
  37176. void ComboBox::enablementChanged()
  37177. {
  37178. repaint();
  37179. }
  37180. void ComboBox::lookAndFeelChanged()
  37181. {
  37182. repaint();
  37183. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37184. if (label != 0)
  37185. {
  37186. newLabel->setEditable (label->isEditable());
  37187. newLabel->setJustificationType (label->getJustificationType());
  37188. newLabel->setTooltip (label->getTooltip());
  37189. newLabel->setText (label->getText(), false);
  37190. }
  37191. label = newLabel;
  37192. addAndMakeVisible (newLabel);
  37193. newLabel->addListener (this);
  37194. newLabel->addMouseListener (this, false);
  37195. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37196. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37197. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37198. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37199. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37200. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37201. resized();
  37202. }
  37203. void ComboBox::colourChanged()
  37204. {
  37205. lookAndFeelChanged();
  37206. }
  37207. bool ComboBox::keyPressed (const KeyPress& key)
  37208. {
  37209. bool used = false;
  37210. if (key.isKeyCode (KeyPress::upKey)
  37211. || key.isKeyCode (KeyPress::leftKey))
  37212. {
  37213. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37214. used = true;
  37215. }
  37216. else if (key.isKeyCode (KeyPress::downKey)
  37217. || key.isKeyCode (KeyPress::rightKey))
  37218. {
  37219. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37220. used = true;
  37221. }
  37222. else if (key.isKeyCode (KeyPress::returnKey))
  37223. {
  37224. showPopup();
  37225. used = true;
  37226. }
  37227. return used;
  37228. }
  37229. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37230. {
  37231. // only forward key events that aren't used by this component
  37232. return isKeyDown
  37233. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37234. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37235. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37236. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37237. }
  37238. void ComboBox::focusGained (FocusChangeType)
  37239. {
  37240. repaint();
  37241. }
  37242. void ComboBox::focusLost (FocusChangeType)
  37243. {
  37244. repaint();
  37245. }
  37246. void ComboBox::labelTextChanged (Label*)
  37247. {
  37248. triggerAsyncUpdate();
  37249. }
  37250. void ComboBox::showPopup()
  37251. {
  37252. if (! menuActive)
  37253. {
  37254. const int selectedId = getSelectedId();
  37255. Component::SafePointer<Component> deletionWatcher (this);
  37256. PopupMenu menu;
  37257. menu.setLookAndFeel (&getLookAndFeel());
  37258. for (int i = 0; i < items.size(); ++i)
  37259. {
  37260. const ItemInfo* const item = items.getUnchecked(i);
  37261. if (item->isSeparator())
  37262. menu.addSeparator();
  37263. else if (item->isHeading)
  37264. menu.addSectionHeader (item->name);
  37265. else
  37266. menu.addItem (item->itemId, item->name,
  37267. item->isEnabled, item->itemId == selectedId);
  37268. }
  37269. if (items.size() == 0)
  37270. menu.addItem (1, noChoicesMessage, false);
  37271. const int itemHeight = jlimit (12, 24, getHeight());
  37272. menuActive = true;
  37273. const int resultId = menu.showAt (this, selectedId,
  37274. getWidth(), 1, itemHeight);
  37275. if (deletionWatcher == 0)
  37276. return;
  37277. menuActive = false;
  37278. if (resultId != 0)
  37279. setSelectedId (resultId);
  37280. }
  37281. }
  37282. void ComboBox::mouseDown (const MouseEvent& e)
  37283. {
  37284. beginDragAutoRepeat (300);
  37285. isButtonDown = isEnabled();
  37286. if (isButtonDown
  37287. && (e.eventComponent == this || ! label->isEditable()))
  37288. {
  37289. showPopup();
  37290. }
  37291. }
  37292. void ComboBox::mouseDrag (const MouseEvent& e)
  37293. {
  37294. beginDragAutoRepeat (50);
  37295. if (isButtonDown && ! e.mouseWasClicked())
  37296. showPopup();
  37297. }
  37298. void ComboBox::mouseUp (const MouseEvent& e2)
  37299. {
  37300. if (isButtonDown)
  37301. {
  37302. isButtonDown = false;
  37303. repaint();
  37304. const MouseEvent e (e2.getEventRelativeTo (this));
  37305. if (reallyContains (e.x, e.y, true)
  37306. && (e2.eventComponent == this || ! label->isEditable()))
  37307. {
  37308. showPopup();
  37309. }
  37310. }
  37311. }
  37312. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37313. {
  37314. listeners.add (listener);
  37315. }
  37316. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37317. {
  37318. listeners.remove (listener);
  37319. }
  37320. void ComboBox::handleAsyncUpdate()
  37321. {
  37322. Component::BailOutChecker checker (this);
  37323. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37324. }
  37325. END_JUCE_NAMESPACE
  37326. /*** End of inlined file: juce_ComboBox.cpp ***/
  37327. /*** Start of inlined file: juce_Label.cpp ***/
  37328. BEGIN_JUCE_NAMESPACE
  37329. Label::Label (const String& componentName,
  37330. const String& labelText)
  37331. : Component (componentName),
  37332. textValue (labelText),
  37333. lastTextValue (labelText),
  37334. font (15.0f),
  37335. justification (Justification::centredLeft),
  37336. ownerComponent (0),
  37337. horizontalBorderSize (5),
  37338. verticalBorderSize (1),
  37339. minimumHorizontalScale (0.7f),
  37340. editSingleClick (false),
  37341. editDoubleClick (false),
  37342. lossOfFocusDiscardsChanges (false)
  37343. {
  37344. setColour (TextEditor::textColourId, Colours::black);
  37345. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37346. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37347. textValue.addListener (this);
  37348. }
  37349. Label::~Label()
  37350. {
  37351. textValue.removeListener (this);
  37352. if (ownerComponent != 0)
  37353. ownerComponent->removeComponentListener (this);
  37354. editor = 0;
  37355. }
  37356. void Label::setText (const String& newText,
  37357. const bool broadcastChangeMessage)
  37358. {
  37359. hideEditor (true);
  37360. if (lastTextValue != newText)
  37361. {
  37362. lastTextValue = newText;
  37363. textValue = newText;
  37364. repaint();
  37365. textWasChanged();
  37366. if (ownerComponent != 0)
  37367. componentMovedOrResized (*ownerComponent, true, true);
  37368. if (broadcastChangeMessage)
  37369. callChangeListeners();
  37370. }
  37371. }
  37372. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37373. {
  37374. return (returnActiveEditorContents && isBeingEdited())
  37375. ? editor->getText()
  37376. : textValue.toString();
  37377. }
  37378. void Label::valueChanged (Value&)
  37379. {
  37380. if (lastTextValue != textValue.toString())
  37381. setText (textValue.toString(), true);
  37382. }
  37383. void Label::setFont (const Font& newFont) throw()
  37384. {
  37385. font = newFont;
  37386. repaint();
  37387. }
  37388. const Font& Label::getFont() const throw()
  37389. {
  37390. return font;
  37391. }
  37392. void Label::setEditable (const bool editOnSingleClick,
  37393. const bool editOnDoubleClick,
  37394. const bool lossOfFocusDiscardsChanges_) throw()
  37395. {
  37396. editSingleClick = editOnSingleClick;
  37397. editDoubleClick = editOnDoubleClick;
  37398. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37399. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37400. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37401. }
  37402. void Label::setJustificationType (const Justification& justification_) throw()
  37403. {
  37404. justification = justification_;
  37405. repaint();
  37406. }
  37407. void Label::setBorderSize (int h, int v)
  37408. {
  37409. horizontalBorderSize = h;
  37410. verticalBorderSize = v;
  37411. repaint();
  37412. }
  37413. Component* Label::getAttachedComponent() const
  37414. {
  37415. return static_cast<Component*> (ownerComponent);
  37416. }
  37417. void Label::attachToComponent (Component* owner,
  37418. const bool onLeft)
  37419. {
  37420. if (ownerComponent != 0)
  37421. ownerComponent->removeComponentListener (this);
  37422. ownerComponent = owner;
  37423. leftOfOwnerComp = onLeft;
  37424. if (ownerComponent != 0)
  37425. {
  37426. setVisible (owner->isVisible());
  37427. ownerComponent->addComponentListener (this);
  37428. componentParentHierarchyChanged (*ownerComponent);
  37429. componentMovedOrResized (*ownerComponent, true, true);
  37430. }
  37431. }
  37432. void Label::componentMovedOrResized (Component& component,
  37433. bool /*wasMoved*/,
  37434. bool /*wasResized*/)
  37435. {
  37436. if (leftOfOwnerComp)
  37437. {
  37438. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37439. component.getHeight());
  37440. setTopRightPosition (component.getX(), component.getY());
  37441. }
  37442. else
  37443. {
  37444. setSize (component.getWidth(),
  37445. 8 + roundToInt (getFont().getHeight()));
  37446. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37447. }
  37448. }
  37449. void Label::componentParentHierarchyChanged (Component& component)
  37450. {
  37451. if (component.getParentComponent() != 0)
  37452. component.getParentComponent()->addChildComponent (this);
  37453. }
  37454. void Label::componentVisibilityChanged (Component& component)
  37455. {
  37456. setVisible (component.isVisible());
  37457. }
  37458. void Label::textWasEdited()
  37459. {
  37460. }
  37461. void Label::textWasChanged()
  37462. {
  37463. }
  37464. void Label::showEditor()
  37465. {
  37466. if (editor == 0)
  37467. {
  37468. addAndMakeVisible (editor = createEditorComponent());
  37469. editor->setText (getText(), false);
  37470. editor->addListener (this);
  37471. editor->grabKeyboardFocus();
  37472. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37473. editor->addListener (this);
  37474. resized();
  37475. repaint();
  37476. editorShown (editor);
  37477. enterModalState();
  37478. editor->grabKeyboardFocus();
  37479. }
  37480. }
  37481. void Label::editorShown (TextEditor* /*editorComponent*/)
  37482. {
  37483. }
  37484. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37485. {
  37486. }
  37487. bool Label::updateFromTextEditorContents()
  37488. {
  37489. jassert (editor != 0);
  37490. const String newText (editor->getText());
  37491. if (textValue.toString() != newText)
  37492. {
  37493. lastTextValue = newText;
  37494. textValue = newText;
  37495. repaint();
  37496. textWasChanged();
  37497. if (ownerComponent != 0)
  37498. componentMovedOrResized (*ownerComponent, true, true);
  37499. return true;
  37500. }
  37501. return false;
  37502. }
  37503. void Label::hideEditor (const bool discardCurrentEditorContents)
  37504. {
  37505. if (editor != 0)
  37506. {
  37507. Component::SafePointer<Component> deletionChecker (this);
  37508. editorAboutToBeHidden (editor);
  37509. const bool changed = (! discardCurrentEditorContents)
  37510. && updateFromTextEditorContents();
  37511. editor = 0;
  37512. repaint();
  37513. if (changed)
  37514. textWasEdited();
  37515. if (deletionChecker != 0)
  37516. exitModalState (0);
  37517. if (changed && deletionChecker != 0)
  37518. callChangeListeners();
  37519. }
  37520. }
  37521. void Label::inputAttemptWhenModal()
  37522. {
  37523. if (editor != 0)
  37524. {
  37525. if (lossOfFocusDiscardsChanges)
  37526. textEditorEscapeKeyPressed (*editor);
  37527. else
  37528. textEditorReturnKeyPressed (*editor);
  37529. }
  37530. }
  37531. bool Label::isBeingEdited() const throw()
  37532. {
  37533. return editor != 0;
  37534. }
  37535. TextEditor* Label::createEditorComponent()
  37536. {
  37537. TextEditor* const ed = new TextEditor (getName());
  37538. ed->setFont (font);
  37539. // copy these colours from our own settings..
  37540. const int cols[] = { TextEditor::backgroundColourId,
  37541. TextEditor::textColourId,
  37542. TextEditor::highlightColourId,
  37543. TextEditor::highlightedTextColourId,
  37544. TextEditor::caretColourId,
  37545. TextEditor::outlineColourId,
  37546. TextEditor::focusedOutlineColourId,
  37547. TextEditor::shadowColourId };
  37548. for (int i = 0; i < numElementsInArray (cols); ++i)
  37549. ed->setColour (cols[i], findColour (cols[i]));
  37550. return ed;
  37551. }
  37552. void Label::paint (Graphics& g)
  37553. {
  37554. getLookAndFeel().drawLabel (g, *this);
  37555. }
  37556. void Label::mouseUp (const MouseEvent& e)
  37557. {
  37558. if (editSingleClick
  37559. && e.mouseWasClicked()
  37560. && contains (e.x, e.y)
  37561. && ! e.mods.isPopupMenu())
  37562. {
  37563. showEditor();
  37564. }
  37565. }
  37566. void Label::mouseDoubleClick (const MouseEvent& e)
  37567. {
  37568. if (editDoubleClick && ! e.mods.isPopupMenu())
  37569. showEditor();
  37570. }
  37571. void Label::resized()
  37572. {
  37573. if (editor != 0)
  37574. editor->setBoundsInset (BorderSize (0));
  37575. }
  37576. void Label::focusGained (FocusChangeType cause)
  37577. {
  37578. if (editSingleClick && cause == focusChangedByTabKey)
  37579. showEditor();
  37580. }
  37581. void Label::enablementChanged()
  37582. {
  37583. repaint();
  37584. }
  37585. void Label::colourChanged()
  37586. {
  37587. repaint();
  37588. }
  37589. void Label::setMinimumHorizontalScale (const float newScale)
  37590. {
  37591. if (minimumHorizontalScale != newScale)
  37592. {
  37593. minimumHorizontalScale = newScale;
  37594. repaint();
  37595. }
  37596. }
  37597. // We'll use a custom focus traverser here to make sure focus goes from the
  37598. // text editor to another component rather than back to the label itself.
  37599. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37600. {
  37601. public:
  37602. LabelKeyboardFocusTraverser() {}
  37603. Component* getNextComponent (Component* current)
  37604. {
  37605. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37606. ? current->getParentComponent() : current);
  37607. }
  37608. Component* getPreviousComponent (Component* current)
  37609. {
  37610. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37611. ? current->getParentComponent() : current);
  37612. }
  37613. };
  37614. KeyboardFocusTraverser* Label::createFocusTraverser()
  37615. {
  37616. return new LabelKeyboardFocusTraverser();
  37617. }
  37618. void Label::addListener (LabelListener* const listener) throw()
  37619. {
  37620. listeners.add (listener);
  37621. }
  37622. void Label::removeListener (LabelListener* const listener) throw()
  37623. {
  37624. listeners.remove (listener);
  37625. }
  37626. void Label::callChangeListeners()
  37627. {
  37628. Component::BailOutChecker checker (this);
  37629. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37630. }
  37631. void Label::textEditorTextChanged (TextEditor& ed)
  37632. {
  37633. if (editor != 0)
  37634. {
  37635. jassert (&ed == editor);
  37636. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37637. {
  37638. if (lossOfFocusDiscardsChanges)
  37639. textEditorEscapeKeyPressed (ed);
  37640. else
  37641. textEditorReturnKeyPressed (ed);
  37642. }
  37643. }
  37644. }
  37645. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37646. {
  37647. if (editor != 0)
  37648. {
  37649. jassert (&ed == editor);
  37650. (void) ed;
  37651. const bool changed = updateFromTextEditorContents();
  37652. hideEditor (true);
  37653. if (changed)
  37654. {
  37655. Component::SafePointer<Component> deletionChecker (this);
  37656. textWasEdited();
  37657. if (deletionChecker != 0)
  37658. callChangeListeners();
  37659. }
  37660. }
  37661. }
  37662. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37663. {
  37664. if (editor != 0)
  37665. {
  37666. jassert (&ed == editor);
  37667. (void) ed;
  37668. editor->setText (textValue.toString(), false);
  37669. hideEditor (true);
  37670. }
  37671. }
  37672. void Label::textEditorFocusLost (TextEditor& ed)
  37673. {
  37674. textEditorTextChanged (ed);
  37675. }
  37676. END_JUCE_NAMESPACE
  37677. /*** End of inlined file: juce_Label.cpp ***/
  37678. /*** Start of inlined file: juce_ListBox.cpp ***/
  37679. BEGIN_JUCE_NAMESPACE
  37680. class ListBoxRowComponent : public Component,
  37681. public TooltipClient
  37682. {
  37683. public:
  37684. ListBoxRowComponent (ListBox& owner_)
  37685. : owner (owner_),
  37686. row (-1),
  37687. selected (false),
  37688. isDragging (false)
  37689. {
  37690. }
  37691. ~ListBoxRowComponent()
  37692. {
  37693. deleteAllChildren();
  37694. }
  37695. void paint (Graphics& g)
  37696. {
  37697. if (owner.getModel() != 0)
  37698. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37699. }
  37700. void update (const int row_, const bool selected_)
  37701. {
  37702. if (row != row_ || selected != selected_)
  37703. {
  37704. repaint();
  37705. row = row_;
  37706. selected = selected_;
  37707. }
  37708. if (owner.getModel() != 0)
  37709. {
  37710. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37711. if (customComp != 0)
  37712. {
  37713. addAndMakeVisible (customComp);
  37714. customComp->setBounds (0, 0, getWidth(), getHeight());
  37715. for (int i = getNumChildComponents(); --i >= 0;)
  37716. if (getChildComponent (i) != customComp)
  37717. delete getChildComponent (i);
  37718. }
  37719. else
  37720. {
  37721. deleteAllChildren();
  37722. }
  37723. }
  37724. }
  37725. void mouseDown (const MouseEvent& e)
  37726. {
  37727. isDragging = false;
  37728. selectRowOnMouseUp = false;
  37729. if (isEnabled())
  37730. {
  37731. if (! selected)
  37732. {
  37733. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37734. if (owner.getModel() != 0)
  37735. owner.getModel()->listBoxItemClicked (row, e);
  37736. }
  37737. else
  37738. {
  37739. selectRowOnMouseUp = true;
  37740. }
  37741. }
  37742. }
  37743. void mouseUp (const MouseEvent& e)
  37744. {
  37745. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37746. {
  37747. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37748. if (owner.getModel() != 0)
  37749. owner.getModel()->listBoxItemClicked (row, e);
  37750. }
  37751. }
  37752. void mouseDoubleClick (const MouseEvent& e)
  37753. {
  37754. if (owner.getModel() != 0 && isEnabled())
  37755. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37756. }
  37757. void mouseDrag (const MouseEvent& e)
  37758. {
  37759. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37760. {
  37761. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37762. if (selectedRows.size() > 0)
  37763. {
  37764. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37765. if (dragDescription.isNotEmpty())
  37766. {
  37767. isDragging = true;
  37768. owner.startDragAndDrop (e, dragDescription);
  37769. }
  37770. }
  37771. }
  37772. }
  37773. void resized()
  37774. {
  37775. if (getNumChildComponents() > 0)
  37776. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37777. }
  37778. const String getTooltip()
  37779. {
  37780. if (owner.getModel() != 0)
  37781. return owner.getModel()->getTooltipForRow (row);
  37782. return String::empty;
  37783. }
  37784. juce_UseDebuggingNewOperator
  37785. bool neededFlag;
  37786. private:
  37787. ListBox& owner;
  37788. int row;
  37789. bool selected, isDragging, selectRowOnMouseUp;
  37790. ListBoxRowComponent (const ListBoxRowComponent&);
  37791. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37792. };
  37793. class ListViewport : public Viewport
  37794. {
  37795. public:
  37796. int firstIndex, firstWholeIndex, lastWholeIndex;
  37797. bool hasUpdated;
  37798. ListViewport (ListBox& owner_)
  37799. : owner (owner_)
  37800. {
  37801. setWantsKeyboardFocus (false);
  37802. setViewedComponent (new Component());
  37803. getViewedComponent()->addMouseListener (this, false);
  37804. getViewedComponent()->setWantsKeyboardFocus (false);
  37805. }
  37806. ~ListViewport()
  37807. {
  37808. getViewedComponent()->removeMouseListener (this);
  37809. getViewedComponent()->deleteAllChildren();
  37810. }
  37811. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37812. {
  37813. return static_cast <ListBoxRowComponent*>
  37814. (getViewedComponent()->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents())));
  37815. }
  37816. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37817. {
  37818. const int index = getIndexOfChildComponent (rowComponent);
  37819. const int num = getViewedComponent()->getNumChildComponents();
  37820. for (int i = num; --i >= 0;)
  37821. if (((firstIndex + i) % jmax (1, num)) == index)
  37822. return firstIndex + i;
  37823. return -1;
  37824. }
  37825. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37826. {
  37827. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37828. ? getComponentForRow (row) : 0;
  37829. }
  37830. void visibleAreaChanged (int, int, int, int)
  37831. {
  37832. updateVisibleArea (true);
  37833. if (owner.getModel() != 0)
  37834. owner.getModel()->listWasScrolled();
  37835. }
  37836. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37837. {
  37838. hasUpdated = false;
  37839. const int newX = getViewedComponent()->getX();
  37840. int newY = getViewedComponent()->getY();
  37841. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37842. const int newH = owner.totalItems * owner.getRowHeight();
  37843. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37844. newY = getMaximumVisibleHeight() - newH;
  37845. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37846. if (makeSureItUpdatesContent && ! hasUpdated)
  37847. updateContents();
  37848. }
  37849. void updateContents()
  37850. {
  37851. hasUpdated = true;
  37852. const int rowHeight = owner.getRowHeight();
  37853. if (rowHeight > 0)
  37854. {
  37855. const int y = getViewPositionY();
  37856. const int w = getViewedComponent()->getWidth();
  37857. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37858. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37859. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37860. jassert (numNeeded >= 0);
  37861. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37862. {
  37863. Component* const rowToRemove
  37864. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37865. delete rowToRemove;
  37866. }
  37867. firstIndex = y / rowHeight;
  37868. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37869. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37870. for (int i = 0; i < numNeeded; ++i)
  37871. {
  37872. const int row = i + firstIndex;
  37873. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37874. if (rowComp != 0)
  37875. {
  37876. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37877. rowComp->update (row, owner.isRowSelected (row));
  37878. }
  37879. }
  37880. }
  37881. if (owner.headerComponent != 0)
  37882. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37883. owner.outlineThickness,
  37884. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37885. getViewedComponent()->getWidth()),
  37886. owner.headerComponent->getHeight());
  37887. }
  37888. void paint (Graphics& g)
  37889. {
  37890. if (isOpaque())
  37891. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37892. }
  37893. bool keyPressed (const KeyPress& key)
  37894. {
  37895. if (key.isKeyCode (KeyPress::upKey)
  37896. || key.isKeyCode (KeyPress::downKey)
  37897. || key.isKeyCode (KeyPress::pageUpKey)
  37898. || key.isKeyCode (KeyPress::pageDownKey)
  37899. || key.isKeyCode (KeyPress::homeKey)
  37900. || key.isKeyCode (KeyPress::endKey))
  37901. {
  37902. // we want to avoid these keypresses going to the viewport, and instead allow
  37903. // them to pass up to our listbox..
  37904. return false;
  37905. }
  37906. return Viewport::keyPressed (key);
  37907. }
  37908. juce_UseDebuggingNewOperator
  37909. private:
  37910. ListBox& owner;
  37911. ListViewport (const ListViewport&);
  37912. ListViewport& operator= (const ListViewport&);
  37913. };
  37914. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  37915. : Component (name),
  37916. model (model_),
  37917. headerComponent (0),
  37918. totalItems (0),
  37919. rowHeight (22),
  37920. minimumRowWidth (0),
  37921. outlineThickness (0),
  37922. lastRowSelected (-1),
  37923. mouseMoveSelects (false),
  37924. multipleSelection (false),
  37925. hasDoneInitialUpdate (false)
  37926. {
  37927. addAndMakeVisible (viewport = new ListViewport (*this));
  37928. setWantsKeyboardFocus (true);
  37929. colourChanged();
  37930. }
  37931. ListBox::~ListBox()
  37932. {
  37933. deleteAllChildren();
  37934. }
  37935. void ListBox::setModel (ListBoxModel* const newModel)
  37936. {
  37937. if (model != newModel)
  37938. {
  37939. model = newModel;
  37940. updateContent();
  37941. }
  37942. }
  37943. void ListBox::setMultipleSelectionEnabled (bool b)
  37944. {
  37945. multipleSelection = b;
  37946. }
  37947. void ListBox::setMouseMoveSelectsRows (bool b)
  37948. {
  37949. mouseMoveSelects = b;
  37950. if (b)
  37951. addMouseListener (this, true);
  37952. }
  37953. void ListBox::paint (Graphics& g)
  37954. {
  37955. if (! hasDoneInitialUpdate)
  37956. updateContent();
  37957. g.fillAll (findColour (backgroundColourId));
  37958. }
  37959. void ListBox::paintOverChildren (Graphics& g)
  37960. {
  37961. if (outlineThickness > 0)
  37962. {
  37963. g.setColour (findColour (outlineColourId));
  37964. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  37965. }
  37966. }
  37967. void ListBox::resized()
  37968. {
  37969. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  37970. outlineThickness,
  37971. outlineThickness,
  37972. outlineThickness));
  37973. viewport->setSingleStepSizes (20, getRowHeight());
  37974. viewport->updateVisibleArea (false);
  37975. }
  37976. void ListBox::visibilityChanged()
  37977. {
  37978. viewport->updateVisibleArea (true);
  37979. }
  37980. Viewport* ListBox::getViewport() const throw()
  37981. {
  37982. return viewport;
  37983. }
  37984. void ListBox::updateContent()
  37985. {
  37986. hasDoneInitialUpdate = true;
  37987. totalItems = (model != 0) ? model->getNumRows() : 0;
  37988. bool selectionChanged = false;
  37989. if (selected [selected.size() - 1] >= totalItems)
  37990. {
  37991. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  37992. lastRowSelected = getSelectedRow (0);
  37993. selectionChanged = true;
  37994. }
  37995. viewport->updateVisibleArea (isVisible());
  37996. viewport->resized();
  37997. if (selectionChanged && model != 0)
  37998. model->selectedRowsChanged (lastRowSelected);
  37999. }
  38000. void ListBox::selectRow (const int row,
  38001. bool dontScroll,
  38002. bool deselectOthersFirst)
  38003. {
  38004. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38005. }
  38006. void ListBox::selectRowInternal (const int row,
  38007. bool dontScroll,
  38008. bool deselectOthersFirst,
  38009. bool isMouseClick)
  38010. {
  38011. if (! multipleSelection)
  38012. deselectOthersFirst = true;
  38013. if ((! isRowSelected (row))
  38014. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38015. {
  38016. if (((unsigned int) row) < (unsigned int) totalItems)
  38017. {
  38018. if (deselectOthersFirst)
  38019. selected.clear();
  38020. selected.addRange (row, 1);
  38021. if (getHeight() == 0 || getWidth() == 0)
  38022. dontScroll = true;
  38023. viewport->hasUpdated = false;
  38024. if (row < viewport->firstWholeIndex && ! dontScroll)
  38025. {
  38026. viewport->setViewPosition (viewport->getViewPositionX(),
  38027. row * getRowHeight());
  38028. }
  38029. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38030. {
  38031. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38032. if (row >= lastRowSelected + rowsOnScreen
  38033. && rowsOnScreen < totalItems - 1
  38034. && ! isMouseClick)
  38035. {
  38036. viewport->setViewPosition (viewport->getViewPositionX(),
  38037. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38038. * getRowHeight());
  38039. }
  38040. else
  38041. {
  38042. viewport->setViewPosition (viewport->getViewPositionX(),
  38043. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38044. }
  38045. }
  38046. if (! viewport->hasUpdated)
  38047. viewport->updateContents();
  38048. lastRowSelected = row;
  38049. model->selectedRowsChanged (row);
  38050. }
  38051. else
  38052. {
  38053. if (deselectOthersFirst)
  38054. deselectAllRows();
  38055. }
  38056. }
  38057. }
  38058. void ListBox::deselectRow (const int row)
  38059. {
  38060. if (selected.contains (row))
  38061. {
  38062. selected.removeRange (row, 1);
  38063. if (row == lastRowSelected)
  38064. lastRowSelected = getSelectedRow (0);
  38065. viewport->updateContents();
  38066. model->selectedRowsChanged (lastRowSelected);
  38067. }
  38068. }
  38069. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38070. const bool sendNotificationEventToModel)
  38071. {
  38072. selected = setOfRowsToBeSelected;
  38073. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38074. if (! isRowSelected (lastRowSelected))
  38075. lastRowSelected = getSelectedRow (0);
  38076. viewport->updateContents();
  38077. if ((model != 0) && sendNotificationEventToModel)
  38078. model->selectedRowsChanged (lastRowSelected);
  38079. }
  38080. const SparseSet<int> ListBox::getSelectedRows() const
  38081. {
  38082. return selected;
  38083. }
  38084. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38085. {
  38086. if (multipleSelection && (firstRow != lastRow))
  38087. {
  38088. const int numRows = totalItems - 1;
  38089. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38090. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38091. selected.addRange (jmin (firstRow, lastRow),
  38092. abs (firstRow - lastRow) + 1);
  38093. selected.removeRange (lastRow, 1);
  38094. }
  38095. selectRowInternal (lastRow, false, false, true);
  38096. }
  38097. void ListBox::flipRowSelection (const int row)
  38098. {
  38099. if (isRowSelected (row))
  38100. deselectRow (row);
  38101. else
  38102. selectRowInternal (row, false, false, true);
  38103. }
  38104. void ListBox::deselectAllRows()
  38105. {
  38106. if (! selected.isEmpty())
  38107. {
  38108. selected.clear();
  38109. lastRowSelected = -1;
  38110. viewport->updateContents();
  38111. if (model != 0)
  38112. model->selectedRowsChanged (lastRowSelected);
  38113. }
  38114. }
  38115. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38116. const ModifierKeys& mods)
  38117. {
  38118. if (multipleSelection && mods.isCommandDown())
  38119. {
  38120. flipRowSelection (row);
  38121. }
  38122. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38123. {
  38124. selectRangeOfRows (lastRowSelected, row);
  38125. }
  38126. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38127. {
  38128. selectRowInternal (row, false, true, true);
  38129. }
  38130. }
  38131. int ListBox::getNumSelectedRows() const
  38132. {
  38133. return selected.size();
  38134. }
  38135. int ListBox::getSelectedRow (const int index) const
  38136. {
  38137. return (((unsigned int) index) < (unsigned int) selected.size())
  38138. ? selected [index] : -1;
  38139. }
  38140. bool ListBox::isRowSelected (const int row) const
  38141. {
  38142. return selected.contains (row);
  38143. }
  38144. int ListBox::getLastRowSelected() const
  38145. {
  38146. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38147. }
  38148. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38149. {
  38150. if (((unsigned int) x) < (unsigned int) getWidth())
  38151. {
  38152. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38153. if (((unsigned int) row) < (unsigned int) totalItems)
  38154. return row;
  38155. }
  38156. return -1;
  38157. }
  38158. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38159. {
  38160. if (((unsigned int) x) < (unsigned int) getWidth())
  38161. {
  38162. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38163. return jlimit (0, totalItems, row);
  38164. }
  38165. return -1;
  38166. }
  38167. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38168. {
  38169. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38170. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38171. }
  38172. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38173. {
  38174. return viewport->getRowNumberOfComponent (rowComponent);
  38175. }
  38176. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38177. const bool relativeToComponentTopLeft) const throw()
  38178. {
  38179. const int rowHeight = getRowHeight();
  38180. int y = viewport->getY() + rowHeight * rowNumber;
  38181. if (relativeToComponentTopLeft)
  38182. y -= viewport->getViewPositionY();
  38183. return Rectangle<int> (viewport->getX(), y,
  38184. viewport->getViewedComponent()->getWidth(), rowHeight);
  38185. }
  38186. void ListBox::setVerticalPosition (const double proportion)
  38187. {
  38188. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38189. viewport->setViewPosition (viewport->getViewPositionX(),
  38190. jmax (0, roundToInt (proportion * offscreen)));
  38191. }
  38192. double ListBox::getVerticalPosition() const
  38193. {
  38194. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38195. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38196. : 0;
  38197. }
  38198. int ListBox::getVisibleRowWidth() const throw()
  38199. {
  38200. return viewport->getViewWidth();
  38201. }
  38202. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38203. {
  38204. if (row < viewport->firstWholeIndex)
  38205. {
  38206. viewport->setViewPosition (viewport->getViewPositionX(),
  38207. row * getRowHeight());
  38208. }
  38209. else if (row >= viewport->lastWholeIndex)
  38210. {
  38211. viewport->setViewPosition (viewport->getViewPositionX(),
  38212. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38213. }
  38214. }
  38215. bool ListBox::keyPressed (const KeyPress& key)
  38216. {
  38217. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38218. const bool multiple = multipleSelection
  38219. && (lastRowSelected >= 0)
  38220. && (key.getModifiers().isShiftDown()
  38221. || key.getModifiers().isCtrlDown()
  38222. || key.getModifiers().isCommandDown());
  38223. if (key.isKeyCode (KeyPress::upKey))
  38224. {
  38225. if (multiple)
  38226. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38227. else
  38228. selectRow (jmax (0, lastRowSelected - 1));
  38229. }
  38230. else if (key.isKeyCode (KeyPress::returnKey)
  38231. && isRowSelected (lastRowSelected))
  38232. {
  38233. if (model != 0)
  38234. model->returnKeyPressed (lastRowSelected);
  38235. }
  38236. else if (key.isKeyCode (KeyPress::pageUpKey))
  38237. {
  38238. if (multiple)
  38239. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38240. else
  38241. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38242. }
  38243. else if (key.isKeyCode (KeyPress::pageDownKey))
  38244. {
  38245. if (multiple)
  38246. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38247. else
  38248. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38249. }
  38250. else if (key.isKeyCode (KeyPress::homeKey))
  38251. {
  38252. if (multiple && key.getModifiers().isShiftDown())
  38253. selectRangeOfRows (lastRowSelected, 0);
  38254. else
  38255. selectRow (0);
  38256. }
  38257. else if (key.isKeyCode (KeyPress::endKey))
  38258. {
  38259. if (multiple && key.getModifiers().isShiftDown())
  38260. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38261. else
  38262. selectRow (totalItems - 1);
  38263. }
  38264. else if (key.isKeyCode (KeyPress::downKey))
  38265. {
  38266. if (multiple)
  38267. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38268. else
  38269. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38270. }
  38271. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38272. && isRowSelected (lastRowSelected))
  38273. {
  38274. if (model != 0)
  38275. model->deleteKeyPressed (lastRowSelected);
  38276. }
  38277. else if (multiple && key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  38278. {
  38279. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38280. }
  38281. else
  38282. {
  38283. return false;
  38284. }
  38285. return true;
  38286. }
  38287. bool ListBox::keyStateChanged (const bool isKeyDown)
  38288. {
  38289. return isKeyDown
  38290. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38291. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38292. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38293. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38294. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38295. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38296. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38297. }
  38298. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38299. {
  38300. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38301. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38302. }
  38303. void ListBox::mouseMove (const MouseEvent& e)
  38304. {
  38305. if (mouseMoveSelects)
  38306. {
  38307. const MouseEvent e2 (e.getEventRelativeTo (this));
  38308. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38309. }
  38310. }
  38311. void ListBox::mouseExit (const MouseEvent& e)
  38312. {
  38313. mouseMove (e);
  38314. }
  38315. void ListBox::mouseUp (const MouseEvent& e)
  38316. {
  38317. if (e.mouseWasClicked() && model != 0)
  38318. model->backgroundClicked();
  38319. }
  38320. void ListBox::setRowHeight (const int newHeight)
  38321. {
  38322. rowHeight = jmax (1, newHeight);
  38323. viewport->setSingleStepSizes (20, rowHeight);
  38324. updateContent();
  38325. }
  38326. int ListBox::getNumRowsOnScreen() const throw()
  38327. {
  38328. return viewport->getMaximumVisibleHeight() / rowHeight;
  38329. }
  38330. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38331. {
  38332. minimumRowWidth = newMinimumWidth;
  38333. updateContent();
  38334. }
  38335. int ListBox::getVisibleContentWidth() const throw()
  38336. {
  38337. return viewport->getMaximumVisibleWidth();
  38338. }
  38339. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38340. {
  38341. return viewport->getVerticalScrollBar();
  38342. }
  38343. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38344. {
  38345. return viewport->getHorizontalScrollBar();
  38346. }
  38347. void ListBox::colourChanged()
  38348. {
  38349. setOpaque (findColour (backgroundColourId).isOpaque());
  38350. viewport->setOpaque (isOpaque());
  38351. repaint();
  38352. }
  38353. void ListBox::setOutlineThickness (const int outlineThickness_)
  38354. {
  38355. outlineThickness = outlineThickness_;
  38356. resized();
  38357. }
  38358. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38359. {
  38360. if (headerComponent != newHeaderComponent)
  38361. {
  38362. delete headerComponent;
  38363. headerComponent = newHeaderComponent;
  38364. addAndMakeVisible (newHeaderComponent);
  38365. ListBox::resized();
  38366. }
  38367. }
  38368. void ListBox::repaintRow (const int rowNumber) throw()
  38369. {
  38370. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38371. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38372. }
  38373. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38374. {
  38375. Rectangle<int> imageArea;
  38376. const int firstRow = getRowContainingPosition (0, 0);
  38377. int i;
  38378. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38379. {
  38380. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38381. if (rowComp != 0 && isRowSelected (firstRow + i))
  38382. {
  38383. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38384. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38385. if (imageArea.isEmpty())
  38386. imageArea = rowRect;
  38387. else
  38388. imageArea = imageArea.getUnion (rowRect);
  38389. }
  38390. }
  38391. imageArea = imageArea.getIntersection (getLocalBounds());
  38392. imageX = imageArea.getX();
  38393. imageY = imageArea.getY();
  38394. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38395. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38396. {
  38397. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38398. if (rowComp != 0 && isRowSelected (firstRow + i))
  38399. {
  38400. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38401. Graphics g (*snapshot);
  38402. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38403. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38404. rowComp->paintEntireComponent (g);
  38405. }
  38406. }
  38407. return snapshot;
  38408. }
  38409. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38410. {
  38411. DragAndDropContainer* const dragContainer
  38412. = DragAndDropContainer::findParentDragContainerFor (this);
  38413. if (dragContainer != 0)
  38414. {
  38415. int x, y;
  38416. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38417. dragImage->multiplyAllAlphas (0.6f);
  38418. MouseEvent e2 (e.getEventRelativeTo (this));
  38419. const Point<int> p (x - e2.x, y - e2.y);
  38420. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38421. }
  38422. else
  38423. {
  38424. // to be able to do a drag-and-drop operation, the listbox needs to
  38425. // be inside a component which is also a DragAndDropContainer.
  38426. jassertfalse
  38427. }
  38428. }
  38429. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38430. {
  38431. (void) existingComponentToUpdate;
  38432. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38433. return 0;
  38434. }
  38435. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38436. {
  38437. }
  38438. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38439. {
  38440. }
  38441. void ListBoxModel::backgroundClicked()
  38442. {
  38443. }
  38444. void ListBoxModel::selectedRowsChanged (int)
  38445. {
  38446. }
  38447. void ListBoxModel::deleteKeyPressed (int)
  38448. {
  38449. }
  38450. void ListBoxModel::returnKeyPressed (int)
  38451. {
  38452. }
  38453. void ListBoxModel::listWasScrolled()
  38454. {
  38455. }
  38456. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38457. {
  38458. return String::empty;
  38459. }
  38460. const String ListBoxModel::getTooltipForRow (int)
  38461. {
  38462. return String::empty;
  38463. }
  38464. END_JUCE_NAMESPACE
  38465. /*** End of inlined file: juce_ListBox.cpp ***/
  38466. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38467. BEGIN_JUCE_NAMESPACE
  38468. ProgressBar::ProgressBar (double& progress_)
  38469. : progress (progress_),
  38470. displayPercentage (true),
  38471. lastCallbackTime (0)
  38472. {
  38473. currentValue = jlimit (0.0, 1.0, progress);
  38474. }
  38475. ProgressBar::~ProgressBar()
  38476. {
  38477. }
  38478. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38479. {
  38480. displayPercentage = shouldDisplayPercentage;
  38481. repaint();
  38482. }
  38483. void ProgressBar::setTextToDisplay (const String& text)
  38484. {
  38485. displayPercentage = false;
  38486. displayedMessage = text;
  38487. }
  38488. void ProgressBar::lookAndFeelChanged()
  38489. {
  38490. setOpaque (findColour (backgroundColourId).isOpaque());
  38491. }
  38492. void ProgressBar::colourChanged()
  38493. {
  38494. lookAndFeelChanged();
  38495. }
  38496. void ProgressBar::paint (Graphics& g)
  38497. {
  38498. String text;
  38499. if (displayPercentage)
  38500. {
  38501. if (currentValue >= 0 && currentValue <= 1.0)
  38502. text << roundToInt (currentValue * 100.0) << '%';
  38503. }
  38504. else
  38505. {
  38506. text = displayedMessage;
  38507. }
  38508. getLookAndFeel().drawProgressBar (g, *this,
  38509. getWidth(), getHeight(),
  38510. currentValue, text);
  38511. }
  38512. void ProgressBar::visibilityChanged()
  38513. {
  38514. if (isVisible())
  38515. startTimer (30);
  38516. else
  38517. stopTimer();
  38518. }
  38519. void ProgressBar::timerCallback()
  38520. {
  38521. double newProgress = progress;
  38522. const uint32 now = Time::getMillisecondCounter();
  38523. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38524. lastCallbackTime = now;
  38525. if (currentValue != newProgress
  38526. || newProgress < 0 || newProgress >= 1.0
  38527. || currentMessage != displayedMessage)
  38528. {
  38529. if (currentValue < newProgress
  38530. && newProgress >= 0 && newProgress < 1.0
  38531. && currentValue >= 0 && currentValue < 1.0)
  38532. {
  38533. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38534. newProgress);
  38535. }
  38536. currentValue = newProgress;
  38537. currentMessage = displayedMessage;
  38538. repaint();
  38539. }
  38540. }
  38541. END_JUCE_NAMESPACE
  38542. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38543. /*** Start of inlined file: juce_Slider.cpp ***/
  38544. BEGIN_JUCE_NAMESPACE
  38545. class SliderPopupDisplayComponent : public BubbleComponent
  38546. {
  38547. public:
  38548. SliderPopupDisplayComponent (Slider* const owner_)
  38549. : owner (owner_),
  38550. font (15.0f, Font::bold)
  38551. {
  38552. setAlwaysOnTop (true);
  38553. }
  38554. ~SliderPopupDisplayComponent()
  38555. {
  38556. }
  38557. void paintContent (Graphics& g, int w, int h)
  38558. {
  38559. g.setFont (font);
  38560. g.setColour (Colours::black);
  38561. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38562. }
  38563. void getContentSize (int& w, int& h)
  38564. {
  38565. w = font.getStringWidth (text) + 18;
  38566. h = (int) (font.getHeight() * 1.6f);
  38567. }
  38568. void updatePosition (const String& newText)
  38569. {
  38570. if (text != newText)
  38571. {
  38572. text = newText;
  38573. repaint();
  38574. }
  38575. BubbleComponent::setPosition (owner);
  38576. }
  38577. juce_UseDebuggingNewOperator
  38578. private:
  38579. Slider* owner;
  38580. Font font;
  38581. String text;
  38582. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38583. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38584. };
  38585. Slider::Slider (const String& name)
  38586. : Component (name),
  38587. lastCurrentValue (0),
  38588. lastValueMin (0),
  38589. lastValueMax (0),
  38590. minimum (0),
  38591. maximum (10),
  38592. interval (0),
  38593. skewFactor (1.0),
  38594. velocityModeSensitivity (1.0),
  38595. velocityModeOffset (0.0),
  38596. velocityModeThreshold (1),
  38597. rotaryStart (float_Pi * 1.2f),
  38598. rotaryEnd (float_Pi * 2.8f),
  38599. numDecimalPlaces (7),
  38600. sliderRegionStart (0),
  38601. sliderRegionSize (1),
  38602. sliderBeingDragged (-1),
  38603. pixelsForFullDragExtent (250),
  38604. style (LinearHorizontal),
  38605. textBoxPos (TextBoxLeft),
  38606. textBoxWidth (80),
  38607. textBoxHeight (20),
  38608. incDecButtonMode (incDecButtonsNotDraggable),
  38609. editableText (true),
  38610. doubleClickToValue (false),
  38611. isVelocityBased (false),
  38612. userKeyOverridesVelocity (true),
  38613. rotaryStop (true),
  38614. incDecButtonsSideBySide (false),
  38615. sendChangeOnlyOnRelease (false),
  38616. popupDisplayEnabled (false),
  38617. menuEnabled (false),
  38618. menuShown (false),
  38619. scrollWheelEnabled (true),
  38620. snapsToMousePos (true),
  38621. valueBox (0),
  38622. incButton (0),
  38623. decButton (0),
  38624. popupDisplay (0),
  38625. parentForPopupDisplay (0)
  38626. {
  38627. setWantsKeyboardFocus (false);
  38628. setRepaintsOnMouseActivity (true);
  38629. lookAndFeelChanged();
  38630. updateText();
  38631. currentValue.addListener (this);
  38632. valueMin.addListener (this);
  38633. valueMax.addListener (this);
  38634. }
  38635. Slider::~Slider()
  38636. {
  38637. currentValue.removeListener (this);
  38638. valueMin.removeListener (this);
  38639. valueMax.removeListener (this);
  38640. popupDisplay = 0;
  38641. deleteAllChildren();
  38642. }
  38643. void Slider::handleAsyncUpdate()
  38644. {
  38645. cancelPendingUpdate();
  38646. Component::BailOutChecker checker (this);
  38647. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38648. }
  38649. void Slider::sendDragStart()
  38650. {
  38651. startedDragging();
  38652. Component::BailOutChecker checker (this);
  38653. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38654. }
  38655. void Slider::sendDragEnd()
  38656. {
  38657. stoppedDragging();
  38658. sliderBeingDragged = -1;
  38659. Component::BailOutChecker checker (this);
  38660. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38661. }
  38662. void Slider::addListener (SliderListener* const listener)
  38663. {
  38664. listeners.add (listener);
  38665. }
  38666. void Slider::removeListener (SliderListener* const listener)
  38667. {
  38668. listeners.remove (listener);
  38669. }
  38670. void Slider::setSliderStyle (const SliderStyle newStyle)
  38671. {
  38672. if (style != newStyle)
  38673. {
  38674. style = newStyle;
  38675. repaint();
  38676. lookAndFeelChanged();
  38677. }
  38678. }
  38679. void Slider::setRotaryParameters (const float startAngleRadians,
  38680. const float endAngleRadians,
  38681. const bool stopAtEnd)
  38682. {
  38683. // make sure the values are sensible..
  38684. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38685. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38686. jassert (rotaryStart < rotaryEnd);
  38687. rotaryStart = startAngleRadians;
  38688. rotaryEnd = endAngleRadians;
  38689. rotaryStop = stopAtEnd;
  38690. }
  38691. void Slider::setVelocityBasedMode (const bool velBased)
  38692. {
  38693. isVelocityBased = velBased;
  38694. }
  38695. void Slider::setVelocityModeParameters (const double sensitivity,
  38696. const int threshold,
  38697. const double offset,
  38698. const bool userCanPressKeyToSwapMode)
  38699. {
  38700. jassert (threshold >= 0);
  38701. jassert (sensitivity > 0);
  38702. jassert (offset >= 0);
  38703. velocityModeSensitivity = sensitivity;
  38704. velocityModeOffset = offset;
  38705. velocityModeThreshold = threshold;
  38706. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38707. }
  38708. void Slider::setSkewFactor (const double factor)
  38709. {
  38710. skewFactor = factor;
  38711. }
  38712. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38713. {
  38714. if (maximum > minimum)
  38715. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38716. / (maximum - minimum));
  38717. }
  38718. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38719. {
  38720. jassert (distanceForFullScaleDrag > 0);
  38721. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38722. }
  38723. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38724. {
  38725. if (incDecButtonMode != mode)
  38726. {
  38727. incDecButtonMode = mode;
  38728. lookAndFeelChanged();
  38729. }
  38730. }
  38731. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38732. const bool isReadOnly,
  38733. const int textEntryBoxWidth,
  38734. const int textEntryBoxHeight)
  38735. {
  38736. textBoxPos = newPosition;
  38737. editableText = ! isReadOnly;
  38738. textBoxWidth = textEntryBoxWidth;
  38739. textBoxHeight = textEntryBoxHeight;
  38740. repaint();
  38741. lookAndFeelChanged();
  38742. }
  38743. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38744. {
  38745. editableText = shouldBeEditable;
  38746. if (valueBox != 0)
  38747. valueBox->setEditable (shouldBeEditable && isEnabled());
  38748. }
  38749. void Slider::showTextBox()
  38750. {
  38751. jassert (editableText); // this should probably be avoided in read-only sliders.
  38752. if (valueBox != 0)
  38753. valueBox->showEditor();
  38754. }
  38755. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38756. {
  38757. if (valueBox != 0)
  38758. {
  38759. valueBox->hideEditor (discardCurrentEditorContents);
  38760. if (discardCurrentEditorContents)
  38761. updateText();
  38762. }
  38763. }
  38764. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38765. {
  38766. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38767. }
  38768. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38769. {
  38770. snapsToMousePos = shouldSnapToMouse;
  38771. }
  38772. void Slider::setPopupDisplayEnabled (const bool enabled,
  38773. Component* const parentComponentToUse)
  38774. {
  38775. popupDisplayEnabled = enabled;
  38776. parentForPopupDisplay = parentComponentToUse;
  38777. }
  38778. void Slider::colourChanged()
  38779. {
  38780. lookAndFeelChanged();
  38781. }
  38782. void Slider::lookAndFeelChanged()
  38783. {
  38784. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38785. : getTextFromValue (currentValue.getValue()));
  38786. deleteAllChildren();
  38787. valueBox = 0;
  38788. LookAndFeel& lf = getLookAndFeel();
  38789. if (textBoxPos != NoTextBox)
  38790. {
  38791. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38792. valueBox->setWantsKeyboardFocus (false);
  38793. valueBox->setText (previousTextBoxContent, false);
  38794. valueBox->setEditable (editableText && isEnabled());
  38795. valueBox->addListener (this);
  38796. if (style == LinearBar)
  38797. valueBox->addMouseListener (this, false);
  38798. valueBox->setTooltip (getTooltip());
  38799. }
  38800. if (style == IncDecButtons)
  38801. {
  38802. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38803. incButton->addButtonListener (this);
  38804. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38805. decButton->addButtonListener (this);
  38806. if (incDecButtonMode != incDecButtonsNotDraggable)
  38807. {
  38808. incButton->addMouseListener (this, false);
  38809. decButton->addMouseListener (this, false);
  38810. }
  38811. else
  38812. {
  38813. incButton->setRepeatSpeed (300, 100, 20);
  38814. incButton->addMouseListener (decButton, false);
  38815. decButton->setRepeatSpeed (300, 100, 20);
  38816. decButton->addMouseListener (incButton, false);
  38817. }
  38818. incButton->setTooltip (getTooltip());
  38819. decButton->setTooltip (getTooltip());
  38820. }
  38821. setComponentEffect (lf.getSliderEffect());
  38822. resized();
  38823. repaint();
  38824. }
  38825. void Slider::setRange (const double newMin,
  38826. const double newMax,
  38827. const double newInt)
  38828. {
  38829. if (minimum != newMin
  38830. || maximum != newMax
  38831. || interval != newInt)
  38832. {
  38833. minimum = newMin;
  38834. maximum = newMax;
  38835. interval = newInt;
  38836. // figure out the number of DPs needed to display all values at this
  38837. // interval setting.
  38838. numDecimalPlaces = 7;
  38839. if (newInt != 0)
  38840. {
  38841. int v = abs ((int) (newInt * 10000000));
  38842. while ((v % 10) == 0)
  38843. {
  38844. --numDecimalPlaces;
  38845. v /= 10;
  38846. }
  38847. }
  38848. // keep the current values inside the new range..
  38849. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38850. {
  38851. setValue (getValue(), false, false);
  38852. }
  38853. else
  38854. {
  38855. setMinValue (getMinValue(), false, false);
  38856. setMaxValue (getMaxValue(), false, false);
  38857. }
  38858. updateText();
  38859. }
  38860. }
  38861. void Slider::triggerChangeMessage (const bool synchronous)
  38862. {
  38863. if (synchronous)
  38864. handleAsyncUpdate();
  38865. else
  38866. triggerAsyncUpdate();
  38867. valueChanged();
  38868. }
  38869. void Slider::valueChanged (Value& value)
  38870. {
  38871. if (value.refersToSameSourceAs (currentValue))
  38872. {
  38873. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38874. setValue (currentValue.getValue(), false, false);
  38875. }
  38876. else if (value.refersToSameSourceAs (valueMin))
  38877. setMinValue (valueMin.getValue(), false, false, true);
  38878. else if (value.refersToSameSourceAs (valueMax))
  38879. setMaxValue (valueMax.getValue(), false, false, true);
  38880. }
  38881. double Slider::getValue() const
  38882. {
  38883. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38884. // methods to get the two values.
  38885. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38886. return currentValue.getValue();
  38887. }
  38888. void Slider::setValue (double newValue,
  38889. const bool sendUpdateMessage,
  38890. const bool sendMessageSynchronously)
  38891. {
  38892. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38893. // methods to set the two values.
  38894. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38895. newValue = constrainedValue (newValue);
  38896. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38897. {
  38898. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38899. newValue = jlimit ((double) valueMin.getValue(),
  38900. (double) valueMax.getValue(),
  38901. newValue);
  38902. }
  38903. if (newValue != lastCurrentValue)
  38904. {
  38905. if (valueBox != 0)
  38906. valueBox->hideEditor (true);
  38907. lastCurrentValue = newValue;
  38908. currentValue = newValue;
  38909. updateText();
  38910. repaint();
  38911. if (popupDisplay != 0)
  38912. {
  38913. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38914. ->updatePosition (getTextFromValue (newValue));
  38915. popupDisplay->repaint();
  38916. }
  38917. if (sendUpdateMessage)
  38918. triggerChangeMessage (sendMessageSynchronously);
  38919. }
  38920. }
  38921. double Slider::getMinValue() const
  38922. {
  38923. // The minimum value only applies to sliders that are in two- or three-value mode.
  38924. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38925. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38926. return valueMin.getValue();
  38927. }
  38928. double Slider::getMaxValue() const
  38929. {
  38930. // The maximum value only applies to sliders that are in two- or three-value mode.
  38931. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38932. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38933. return valueMax.getValue();
  38934. }
  38935. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38936. {
  38937. // The minimum value only applies to sliders that are in two- or three-value mode.
  38938. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38939. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38940. newValue = constrainedValue (newValue);
  38941. if (style == TwoValueHorizontal || style == TwoValueVertical)
  38942. {
  38943. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  38944. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38945. newValue = jmin ((double) valueMax.getValue(), newValue);
  38946. }
  38947. else
  38948. {
  38949. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  38950. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38951. newValue = jmin (lastCurrentValue, newValue);
  38952. }
  38953. if (lastValueMin != newValue)
  38954. {
  38955. lastValueMin = newValue;
  38956. valueMin = newValue;
  38957. repaint();
  38958. if (popupDisplay != 0)
  38959. {
  38960. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38961. ->updatePosition (getTextFromValue (newValue));
  38962. popupDisplay->repaint();
  38963. }
  38964. if (sendUpdateMessage)
  38965. triggerChangeMessage (sendMessageSynchronously);
  38966. }
  38967. }
  38968. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38969. {
  38970. // The maximum value only applies to sliders that are in two- or three-value mode.
  38971. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38972. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38973. newValue = constrainedValue (newValue);
  38974. if (style == TwoValueHorizontal || style == TwoValueVertical)
  38975. {
  38976. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  38977. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38978. newValue = jmax ((double) valueMin.getValue(), newValue);
  38979. }
  38980. else
  38981. {
  38982. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  38983. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38984. newValue = jmax (lastCurrentValue, newValue);
  38985. }
  38986. if (lastValueMax != newValue)
  38987. {
  38988. lastValueMax = newValue;
  38989. valueMax = newValue;
  38990. repaint();
  38991. if (popupDisplay != 0)
  38992. {
  38993. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38994. ->updatePosition (getTextFromValue (valueMax.getValue()));
  38995. popupDisplay->repaint();
  38996. }
  38997. if (sendUpdateMessage)
  38998. triggerChangeMessage (sendMessageSynchronously);
  38999. }
  39000. }
  39001. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39002. const double valueToSetOnDoubleClick)
  39003. {
  39004. doubleClickToValue = isDoubleClickEnabled;
  39005. doubleClickReturnValue = valueToSetOnDoubleClick;
  39006. }
  39007. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39008. {
  39009. isEnabled_ = doubleClickToValue;
  39010. return doubleClickReturnValue;
  39011. }
  39012. void Slider::updateText()
  39013. {
  39014. if (valueBox != 0)
  39015. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39016. }
  39017. void Slider::setTextValueSuffix (const String& suffix)
  39018. {
  39019. if (textSuffix != suffix)
  39020. {
  39021. textSuffix = suffix;
  39022. updateText();
  39023. }
  39024. }
  39025. const String Slider::getTextFromValue (double v)
  39026. {
  39027. if (numDecimalPlaces > 0)
  39028. return String (v, numDecimalPlaces) + textSuffix;
  39029. else
  39030. return String (roundToInt (v)) + textSuffix;
  39031. }
  39032. double Slider::getValueFromText (const String& text)
  39033. {
  39034. String t (text.trimStart());
  39035. if (t.endsWith (textSuffix))
  39036. t = t.substring (0, t.length() - textSuffix.length());
  39037. while (t.startsWithChar ('+'))
  39038. t = t.substring (1).trimStart();
  39039. return t.initialSectionContainingOnly ("0123456789.,-")
  39040. .getDoubleValue();
  39041. }
  39042. double Slider::proportionOfLengthToValue (double proportion)
  39043. {
  39044. if (skewFactor != 1.0 && proportion > 0.0)
  39045. proportion = exp (log (proportion) / skewFactor);
  39046. return minimum + (maximum - minimum) * proportion;
  39047. }
  39048. double Slider::valueToProportionOfLength (double value)
  39049. {
  39050. const double n = (value - minimum) / (maximum - minimum);
  39051. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39052. }
  39053. double Slider::snapValue (double attemptedValue, const bool)
  39054. {
  39055. return attemptedValue;
  39056. }
  39057. void Slider::startedDragging()
  39058. {
  39059. }
  39060. void Slider::stoppedDragging()
  39061. {
  39062. }
  39063. void Slider::valueChanged()
  39064. {
  39065. }
  39066. void Slider::enablementChanged()
  39067. {
  39068. repaint();
  39069. }
  39070. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39071. {
  39072. menuEnabled = menuEnabled_;
  39073. }
  39074. void Slider::setScrollWheelEnabled (const bool enabled)
  39075. {
  39076. scrollWheelEnabled = enabled;
  39077. }
  39078. void Slider::labelTextChanged (Label* label)
  39079. {
  39080. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39081. if (newValue != (double) currentValue.getValue())
  39082. {
  39083. sendDragStart();
  39084. setValue (newValue, true, true);
  39085. sendDragEnd();
  39086. }
  39087. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39088. }
  39089. void Slider::buttonClicked (Button* button)
  39090. {
  39091. if (style == IncDecButtons)
  39092. {
  39093. sendDragStart();
  39094. if (button == incButton)
  39095. setValue (snapValue (getValue() + interval, false), true, true);
  39096. else if (button == decButton)
  39097. setValue (snapValue (getValue() - interval, false), true, true);
  39098. sendDragEnd();
  39099. }
  39100. }
  39101. double Slider::constrainedValue (double value) const
  39102. {
  39103. if (interval > 0)
  39104. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39105. if (value <= minimum || maximum <= minimum)
  39106. value = minimum;
  39107. else if (value >= maximum)
  39108. value = maximum;
  39109. return value;
  39110. }
  39111. float Slider::getLinearSliderPos (const double value)
  39112. {
  39113. double sliderPosProportional;
  39114. if (maximum > minimum)
  39115. {
  39116. if (value < minimum)
  39117. {
  39118. sliderPosProportional = 0.0;
  39119. }
  39120. else if (value > maximum)
  39121. {
  39122. sliderPosProportional = 1.0;
  39123. }
  39124. else
  39125. {
  39126. sliderPosProportional = valueToProportionOfLength (value);
  39127. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39128. }
  39129. }
  39130. else
  39131. {
  39132. sliderPosProportional = 0.5;
  39133. }
  39134. if (isVertical() || style == IncDecButtons)
  39135. sliderPosProportional = 1.0 - sliderPosProportional;
  39136. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39137. }
  39138. bool Slider::isHorizontal() const
  39139. {
  39140. return style == LinearHorizontal
  39141. || style == LinearBar
  39142. || style == TwoValueHorizontal
  39143. || style == ThreeValueHorizontal;
  39144. }
  39145. bool Slider::isVertical() const
  39146. {
  39147. return style == LinearVertical
  39148. || style == TwoValueVertical
  39149. || style == ThreeValueVertical;
  39150. }
  39151. bool Slider::incDecDragDirectionIsHorizontal() const
  39152. {
  39153. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39154. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39155. }
  39156. float Slider::getPositionOfValue (const double value)
  39157. {
  39158. if (isHorizontal() || isVertical())
  39159. {
  39160. return getLinearSliderPos (value);
  39161. }
  39162. else
  39163. {
  39164. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39165. return 0.0f;
  39166. }
  39167. }
  39168. void Slider::paint (Graphics& g)
  39169. {
  39170. if (style != IncDecButtons)
  39171. {
  39172. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39173. {
  39174. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39175. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39176. getLookAndFeel().drawRotarySlider (g,
  39177. sliderRect.getX(),
  39178. sliderRect.getY(),
  39179. sliderRect.getWidth(),
  39180. sliderRect.getHeight(),
  39181. sliderPos,
  39182. rotaryStart, rotaryEnd,
  39183. *this);
  39184. }
  39185. else
  39186. {
  39187. getLookAndFeel().drawLinearSlider (g,
  39188. sliderRect.getX(),
  39189. sliderRect.getY(),
  39190. sliderRect.getWidth(),
  39191. sliderRect.getHeight(),
  39192. getLinearSliderPos (lastCurrentValue),
  39193. getLinearSliderPos (lastValueMin),
  39194. getLinearSliderPos (lastValueMax),
  39195. style,
  39196. *this);
  39197. }
  39198. if (style == LinearBar && valueBox == 0)
  39199. {
  39200. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39201. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39202. }
  39203. }
  39204. }
  39205. void Slider::resized()
  39206. {
  39207. int minXSpace = 0;
  39208. int minYSpace = 0;
  39209. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39210. minXSpace = 30;
  39211. else
  39212. minYSpace = 15;
  39213. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39214. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39215. if (style == LinearBar)
  39216. {
  39217. if (valueBox != 0)
  39218. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39219. }
  39220. else
  39221. {
  39222. if (textBoxPos == NoTextBox)
  39223. {
  39224. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39225. }
  39226. else if (textBoxPos == TextBoxLeft)
  39227. {
  39228. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39229. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39230. }
  39231. else if (textBoxPos == TextBoxRight)
  39232. {
  39233. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39234. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39235. }
  39236. else if (textBoxPos == TextBoxAbove)
  39237. {
  39238. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39239. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39240. }
  39241. else if (textBoxPos == TextBoxBelow)
  39242. {
  39243. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39244. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39245. }
  39246. }
  39247. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39248. if (style == LinearBar)
  39249. {
  39250. const int barIndent = 1;
  39251. sliderRegionStart = barIndent;
  39252. sliderRegionSize = getWidth() - barIndent * 2;
  39253. sliderRect.setBounds (sliderRegionStart, barIndent,
  39254. sliderRegionSize, getHeight() - barIndent * 2);
  39255. }
  39256. else if (isHorizontal())
  39257. {
  39258. sliderRegionStart = sliderRect.getX() + indent;
  39259. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39260. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39261. sliderRegionSize, sliderRect.getHeight());
  39262. }
  39263. else if (isVertical())
  39264. {
  39265. sliderRegionStart = sliderRect.getY() + indent;
  39266. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39267. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39268. sliderRect.getWidth(), sliderRegionSize);
  39269. }
  39270. else
  39271. {
  39272. sliderRegionStart = 0;
  39273. sliderRegionSize = 100;
  39274. }
  39275. if (style == IncDecButtons)
  39276. {
  39277. Rectangle<int> buttonRect (sliderRect);
  39278. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39279. buttonRect.expand (-2, 0);
  39280. else
  39281. buttonRect.expand (0, -2);
  39282. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39283. if (incDecButtonsSideBySide)
  39284. {
  39285. decButton->setBounds (buttonRect.getX(),
  39286. buttonRect.getY(),
  39287. buttonRect.getWidth() / 2,
  39288. buttonRect.getHeight());
  39289. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39290. incButton->setBounds (buttonRect.getCentreX(),
  39291. buttonRect.getY(),
  39292. buttonRect.getWidth() / 2,
  39293. buttonRect.getHeight());
  39294. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39295. }
  39296. else
  39297. {
  39298. incButton->setBounds (buttonRect.getX(),
  39299. buttonRect.getY(),
  39300. buttonRect.getWidth(),
  39301. buttonRect.getHeight() / 2);
  39302. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39303. decButton->setBounds (buttonRect.getX(),
  39304. buttonRect.getCentreY(),
  39305. buttonRect.getWidth(),
  39306. buttonRect.getHeight() / 2);
  39307. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39308. }
  39309. }
  39310. }
  39311. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39312. {
  39313. repaint();
  39314. }
  39315. void Slider::mouseDown (const MouseEvent& e)
  39316. {
  39317. mouseWasHidden = false;
  39318. incDecDragged = false;
  39319. mouseXWhenLastDragged = e.x;
  39320. mouseYWhenLastDragged = e.y;
  39321. mouseDragStartX = e.getMouseDownX();
  39322. mouseDragStartY = e.getMouseDownY();
  39323. if (isEnabled())
  39324. {
  39325. if (e.mods.isPopupMenu() && menuEnabled)
  39326. {
  39327. menuShown = true;
  39328. PopupMenu m;
  39329. m.setLookAndFeel (&getLookAndFeel());
  39330. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39331. m.addSeparator();
  39332. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39333. {
  39334. PopupMenu rotaryMenu;
  39335. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39336. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39337. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39338. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39339. }
  39340. const int r = m.show();
  39341. if (r == 1)
  39342. {
  39343. setVelocityBasedMode (! isVelocityBased);
  39344. }
  39345. else if (r == 2)
  39346. {
  39347. setSliderStyle (Rotary);
  39348. }
  39349. else if (r == 3)
  39350. {
  39351. setSliderStyle (RotaryHorizontalDrag);
  39352. }
  39353. else if (r == 4)
  39354. {
  39355. setSliderStyle (RotaryVerticalDrag);
  39356. }
  39357. }
  39358. else if (maximum > minimum)
  39359. {
  39360. menuShown = false;
  39361. if (valueBox != 0)
  39362. valueBox->hideEditor (true);
  39363. sliderBeingDragged = 0;
  39364. if (style == TwoValueHorizontal
  39365. || style == TwoValueVertical
  39366. || style == ThreeValueHorizontal
  39367. || style == ThreeValueVertical)
  39368. {
  39369. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39370. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39371. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39372. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39373. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39374. {
  39375. if (maxPosDistance <= minPosDistance)
  39376. sliderBeingDragged = 2;
  39377. else
  39378. sliderBeingDragged = 1;
  39379. }
  39380. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39381. {
  39382. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39383. sliderBeingDragged = 1;
  39384. else if (normalPosDistance >= maxPosDistance)
  39385. sliderBeingDragged = 2;
  39386. }
  39387. }
  39388. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39389. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39390. * valueToProportionOfLength (currentValue.getValue());
  39391. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39392. : ((sliderBeingDragged == 1) ? valueMin
  39393. : currentValue)).getValue();
  39394. valueOnMouseDown = valueWhenLastDragged;
  39395. if (popupDisplayEnabled)
  39396. {
  39397. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39398. popupDisplay = popup;
  39399. if (parentForPopupDisplay != 0)
  39400. {
  39401. parentForPopupDisplay->addChildComponent (popup);
  39402. }
  39403. else
  39404. {
  39405. popup->addToDesktop (0);
  39406. }
  39407. popup->setVisible (true);
  39408. }
  39409. sendDragStart();
  39410. mouseDrag (e);
  39411. }
  39412. }
  39413. }
  39414. void Slider::mouseUp (const MouseEvent&)
  39415. {
  39416. if (isEnabled()
  39417. && (! menuShown)
  39418. && (maximum > minimum)
  39419. && (style != IncDecButtons || incDecDragged))
  39420. {
  39421. restoreMouseIfHidden();
  39422. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39423. triggerChangeMessage (false);
  39424. sendDragEnd();
  39425. popupDisplay = 0;
  39426. if (style == IncDecButtons)
  39427. {
  39428. incButton->setState (Button::buttonNormal);
  39429. decButton->setState (Button::buttonNormal);
  39430. }
  39431. }
  39432. }
  39433. void Slider::restoreMouseIfHidden()
  39434. {
  39435. if (mouseWasHidden)
  39436. {
  39437. mouseWasHidden = false;
  39438. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39439. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39440. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39441. : ((sliderBeingDragged == 1) ? getMinValue()
  39442. : (double) currentValue.getValue());
  39443. Point<int> mousePos;
  39444. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39445. {
  39446. mousePos = Desktop::getLastMouseDownPosition();
  39447. if (style == RotaryHorizontalDrag)
  39448. {
  39449. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39450. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39451. }
  39452. else
  39453. {
  39454. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39455. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39456. }
  39457. }
  39458. else
  39459. {
  39460. const int pixelPos = (int) getLinearSliderPos (pos);
  39461. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39462. isVertical() ? pixelPos : (getHeight() / 2)));
  39463. }
  39464. Desktop::setMousePosition (mousePos);
  39465. }
  39466. }
  39467. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39468. {
  39469. if (isEnabled()
  39470. && style != IncDecButtons
  39471. && style != Rotary
  39472. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39473. {
  39474. restoreMouseIfHidden();
  39475. }
  39476. }
  39477. static double smallestAngleBetween (double a1, double a2)
  39478. {
  39479. return jmin (fabs (a1 - a2),
  39480. fabs (a1 + double_Pi * 2.0 - a2),
  39481. fabs (a2 + double_Pi * 2.0 - a1));
  39482. }
  39483. void Slider::mouseDrag (const MouseEvent& e)
  39484. {
  39485. if (isEnabled()
  39486. && (! menuShown)
  39487. && (maximum > minimum))
  39488. {
  39489. if (style == Rotary)
  39490. {
  39491. int dx = e.x - sliderRect.getCentreX();
  39492. int dy = e.y - sliderRect.getCentreY();
  39493. if (dx * dx + dy * dy > 25)
  39494. {
  39495. double angle = atan2 ((double) dx, (double) -dy);
  39496. while (angle < 0.0)
  39497. angle += double_Pi * 2.0;
  39498. if (rotaryStop && ! e.mouseWasClicked())
  39499. {
  39500. if (fabs (angle - lastAngle) > double_Pi)
  39501. {
  39502. if (angle >= lastAngle)
  39503. angle -= double_Pi * 2.0;
  39504. else
  39505. angle += double_Pi * 2.0;
  39506. }
  39507. if (angle >= lastAngle)
  39508. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39509. else
  39510. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39511. }
  39512. else
  39513. {
  39514. while (angle < rotaryStart)
  39515. angle += double_Pi * 2.0;
  39516. if (angle > rotaryEnd)
  39517. {
  39518. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39519. angle = rotaryStart;
  39520. else
  39521. angle = rotaryEnd;
  39522. }
  39523. }
  39524. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39525. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39526. lastAngle = angle;
  39527. }
  39528. }
  39529. else
  39530. {
  39531. if (style == LinearBar && e.mouseWasClicked()
  39532. && valueBox != 0 && valueBox->isEditable())
  39533. return;
  39534. if (style == IncDecButtons && ! incDecDragged)
  39535. {
  39536. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39537. return;
  39538. incDecDragged = true;
  39539. mouseDragStartX = e.x;
  39540. mouseDragStartY = e.y;
  39541. }
  39542. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39543. : false))
  39544. || ((maximum - minimum) / sliderRegionSize < interval))
  39545. {
  39546. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39547. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39548. if (style == RotaryHorizontalDrag
  39549. || style == RotaryVerticalDrag
  39550. || style == IncDecButtons
  39551. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39552. && ! snapsToMousePos))
  39553. {
  39554. const int mouseDiff = (style == RotaryHorizontalDrag
  39555. || style == LinearHorizontal
  39556. || style == LinearBar
  39557. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39558. ? e.x - mouseDragStartX
  39559. : mouseDragStartY - e.y;
  39560. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39561. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39562. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39563. if (style == IncDecButtons)
  39564. {
  39565. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39566. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39567. }
  39568. }
  39569. else
  39570. {
  39571. if (isVertical())
  39572. scaledMousePos = 1.0 - scaledMousePos;
  39573. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39574. }
  39575. }
  39576. else
  39577. {
  39578. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39579. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39580. ? e.x - mouseXWhenLastDragged
  39581. : e.y - mouseYWhenLastDragged;
  39582. const double maxSpeed = jmax (200, sliderRegionSize);
  39583. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39584. if (speed != 0)
  39585. {
  39586. speed = 0.2 * velocityModeSensitivity
  39587. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39588. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39589. / maxSpeed))));
  39590. if (mouseDiff < 0)
  39591. speed = -speed;
  39592. if (isVertical() || style == RotaryVerticalDrag
  39593. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39594. speed = -speed;
  39595. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39596. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39597. e.source.enableUnboundedMouseMovement (true, false);
  39598. mouseWasHidden = true;
  39599. }
  39600. }
  39601. }
  39602. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39603. if (sliderBeingDragged == 0)
  39604. {
  39605. setValue (snapValue (valueWhenLastDragged, true),
  39606. ! sendChangeOnlyOnRelease, true);
  39607. }
  39608. else if (sliderBeingDragged == 1)
  39609. {
  39610. setMinValue (snapValue (valueWhenLastDragged, true),
  39611. ! sendChangeOnlyOnRelease, false, true);
  39612. if (e.mods.isShiftDown())
  39613. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39614. else
  39615. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39616. }
  39617. else
  39618. {
  39619. jassert (sliderBeingDragged == 2);
  39620. setMaxValue (snapValue (valueWhenLastDragged, true),
  39621. ! sendChangeOnlyOnRelease, false, true);
  39622. if (e.mods.isShiftDown())
  39623. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39624. else
  39625. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39626. }
  39627. mouseXWhenLastDragged = e.x;
  39628. mouseYWhenLastDragged = e.y;
  39629. }
  39630. }
  39631. void Slider::mouseDoubleClick (const MouseEvent&)
  39632. {
  39633. if (doubleClickToValue
  39634. && isEnabled()
  39635. && style != IncDecButtons
  39636. && minimum <= doubleClickReturnValue
  39637. && maximum >= doubleClickReturnValue)
  39638. {
  39639. sendDragStart();
  39640. setValue (doubleClickReturnValue, true, true);
  39641. sendDragEnd();
  39642. }
  39643. }
  39644. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39645. {
  39646. if (scrollWheelEnabled && isEnabled()
  39647. && style != TwoValueHorizontal
  39648. && style != TwoValueVertical)
  39649. {
  39650. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39651. {
  39652. if (valueBox != 0)
  39653. valueBox->hideEditor (false);
  39654. const double value = (double) currentValue.getValue();
  39655. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39656. const double currentPos = valueToProportionOfLength (value);
  39657. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39658. double delta = (newValue != value)
  39659. ? jmax (fabs (newValue - value), interval) : 0;
  39660. if (value > newValue)
  39661. delta = -delta;
  39662. sendDragStart();
  39663. setValue (snapValue (value + delta, false), true, true);
  39664. sendDragEnd();
  39665. }
  39666. }
  39667. else
  39668. {
  39669. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39670. }
  39671. }
  39672. void SliderListener::sliderDragStarted (Slider*)
  39673. {
  39674. }
  39675. void SliderListener::sliderDragEnded (Slider*)
  39676. {
  39677. }
  39678. END_JUCE_NAMESPACE
  39679. /*** End of inlined file: juce_Slider.cpp ***/
  39680. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39681. BEGIN_JUCE_NAMESPACE
  39682. class DragOverlayComp : public Component
  39683. {
  39684. public:
  39685. DragOverlayComp (Image* const image_)
  39686. : image (image_)
  39687. {
  39688. image->multiplyAllAlphas (0.8f);
  39689. setAlwaysOnTop (true);
  39690. }
  39691. ~DragOverlayComp()
  39692. {
  39693. }
  39694. void paint (Graphics& g)
  39695. {
  39696. g.drawImageAt (image, 0, 0);
  39697. }
  39698. private:
  39699. ScopedPointer <Image> image;
  39700. DragOverlayComp (const DragOverlayComp&);
  39701. DragOverlayComp& operator= (const DragOverlayComp&);
  39702. };
  39703. TableHeaderComponent::TableHeaderComponent()
  39704. : columnsChanged (false),
  39705. columnsResized (false),
  39706. sortChanged (false),
  39707. menuActive (true),
  39708. stretchToFit (false),
  39709. columnIdBeingResized (0),
  39710. columnIdBeingDragged (0),
  39711. columnIdUnderMouse (0),
  39712. lastDeliberateWidth (0)
  39713. {
  39714. }
  39715. TableHeaderComponent::~TableHeaderComponent()
  39716. {
  39717. dragOverlayComp = 0;
  39718. }
  39719. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39720. {
  39721. menuActive = hasMenu;
  39722. }
  39723. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39724. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39725. {
  39726. if (onlyCountVisibleColumns)
  39727. {
  39728. int num = 0;
  39729. for (int i = columns.size(); --i >= 0;)
  39730. if (columns.getUnchecked(i)->isVisible())
  39731. ++num;
  39732. return num;
  39733. }
  39734. else
  39735. {
  39736. return columns.size();
  39737. }
  39738. }
  39739. const String TableHeaderComponent::getColumnName (const int columnId) const
  39740. {
  39741. const ColumnInfo* const ci = getInfoForId (columnId);
  39742. return ci != 0 ? ci->name : String::empty;
  39743. }
  39744. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39745. {
  39746. ColumnInfo* const ci = getInfoForId (columnId);
  39747. if (ci != 0 && ci->name != newName)
  39748. {
  39749. ci->name = newName;
  39750. sendColumnsChanged();
  39751. }
  39752. }
  39753. void TableHeaderComponent::addColumn (const String& columnName,
  39754. const int columnId,
  39755. const int width,
  39756. const int minimumWidth,
  39757. const int maximumWidth,
  39758. const int propertyFlags,
  39759. const int insertIndex)
  39760. {
  39761. // can't have a duplicate or null ID!
  39762. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39763. jassert (width > 0);
  39764. ColumnInfo* const ci = new ColumnInfo();
  39765. ci->name = columnName;
  39766. ci->id = columnId;
  39767. ci->width = width;
  39768. ci->lastDeliberateWidth = width;
  39769. ci->minimumWidth = minimumWidth;
  39770. ci->maximumWidth = maximumWidth;
  39771. if (ci->maximumWidth < 0)
  39772. ci->maximumWidth = std::numeric_limits<int>::max();
  39773. jassert (ci->maximumWidth >= ci->minimumWidth);
  39774. ci->propertyFlags = propertyFlags;
  39775. columns.insert (insertIndex, ci);
  39776. sendColumnsChanged();
  39777. }
  39778. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39779. {
  39780. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39781. if (index >= 0)
  39782. {
  39783. columns.remove (index);
  39784. sortChanged = true;
  39785. sendColumnsChanged();
  39786. }
  39787. }
  39788. void TableHeaderComponent::removeAllColumns()
  39789. {
  39790. if (columns.size() > 0)
  39791. {
  39792. columns.clear();
  39793. sendColumnsChanged();
  39794. }
  39795. }
  39796. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39797. {
  39798. const int currentIndex = getIndexOfColumnId (columnId, false);
  39799. newIndex = visibleIndexToTotalIndex (newIndex);
  39800. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39801. {
  39802. columns.move (currentIndex, newIndex);
  39803. sendColumnsChanged();
  39804. }
  39805. }
  39806. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39807. {
  39808. const ColumnInfo* const ci = getInfoForId (columnId);
  39809. return ci != 0 ? ci->width : 0;
  39810. }
  39811. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39812. {
  39813. ColumnInfo* const ci = getInfoForId (columnId);
  39814. if (ci != 0 && ci->width != newWidth)
  39815. {
  39816. const int numColumns = getNumColumns (true);
  39817. ci->lastDeliberateWidth = ci->width
  39818. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39819. if (stretchToFit)
  39820. {
  39821. const int index = getIndexOfColumnId (columnId, true) + 1;
  39822. if (((unsigned int) index) < (unsigned int) numColumns)
  39823. {
  39824. const int x = getColumnPosition (index).getX();
  39825. if (lastDeliberateWidth == 0)
  39826. lastDeliberateWidth = getTotalWidth();
  39827. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39828. }
  39829. }
  39830. repaint();
  39831. columnsResized = true;
  39832. triggerAsyncUpdate();
  39833. }
  39834. }
  39835. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39836. {
  39837. int n = 0;
  39838. for (int i = 0; i < columns.size(); ++i)
  39839. {
  39840. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39841. {
  39842. if (columns.getUnchecked(i)->id == columnId)
  39843. return n;
  39844. ++n;
  39845. }
  39846. }
  39847. return -1;
  39848. }
  39849. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39850. {
  39851. if (onlyCountVisibleColumns)
  39852. index = visibleIndexToTotalIndex (index);
  39853. const ColumnInfo* const ci = columns [index];
  39854. return (ci != 0) ? ci->id : 0;
  39855. }
  39856. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39857. {
  39858. int x = 0, width = 0, n = 0;
  39859. for (int i = 0; i < columns.size(); ++i)
  39860. {
  39861. x += width;
  39862. if (columns.getUnchecked(i)->isVisible())
  39863. {
  39864. width = columns.getUnchecked(i)->width;
  39865. if (n++ == index)
  39866. break;
  39867. }
  39868. else
  39869. {
  39870. width = 0;
  39871. }
  39872. }
  39873. return Rectangle<int> (x, 0, width, getHeight());
  39874. }
  39875. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39876. {
  39877. if (xToFind >= 0)
  39878. {
  39879. int x = 0;
  39880. for (int i = 0; i < columns.size(); ++i)
  39881. {
  39882. const ColumnInfo* const ci = columns.getUnchecked(i);
  39883. if (ci->isVisible())
  39884. {
  39885. x += ci->width;
  39886. if (xToFind < x)
  39887. return ci->id;
  39888. }
  39889. }
  39890. }
  39891. return 0;
  39892. }
  39893. int TableHeaderComponent::getTotalWidth() const
  39894. {
  39895. int w = 0;
  39896. for (int i = columns.size(); --i >= 0;)
  39897. if (columns.getUnchecked(i)->isVisible())
  39898. w += columns.getUnchecked(i)->width;
  39899. return w;
  39900. }
  39901. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  39902. {
  39903. stretchToFit = shouldStretchToFit;
  39904. lastDeliberateWidth = getTotalWidth();
  39905. resized();
  39906. }
  39907. bool TableHeaderComponent::isStretchToFitActive() const
  39908. {
  39909. return stretchToFit;
  39910. }
  39911. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  39912. {
  39913. if (stretchToFit && getWidth() > 0
  39914. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  39915. {
  39916. lastDeliberateWidth = targetTotalWidth;
  39917. resizeColumnsToFit (0, targetTotalWidth);
  39918. }
  39919. }
  39920. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  39921. {
  39922. targetTotalWidth = jmax (targetTotalWidth, 0);
  39923. StretchableObjectResizer sor;
  39924. int i;
  39925. for (i = firstColumnIndex; i < columns.size(); ++i)
  39926. {
  39927. ColumnInfo* const ci = columns.getUnchecked(i);
  39928. if (ci->isVisible())
  39929. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  39930. }
  39931. sor.resizeToFit (targetTotalWidth);
  39932. int visIndex = 0;
  39933. for (i = firstColumnIndex; i < columns.size(); ++i)
  39934. {
  39935. ColumnInfo* const ci = columns.getUnchecked(i);
  39936. if (ci->isVisible())
  39937. {
  39938. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  39939. (int) floor (sor.getItemSize (visIndex++)));
  39940. if (newWidth != ci->width)
  39941. {
  39942. ci->width = newWidth;
  39943. repaint();
  39944. columnsResized = true;
  39945. triggerAsyncUpdate();
  39946. }
  39947. }
  39948. }
  39949. }
  39950. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  39951. {
  39952. ColumnInfo* const ci = getInfoForId (columnId);
  39953. if (ci != 0 && shouldBeVisible != ci->isVisible())
  39954. {
  39955. if (shouldBeVisible)
  39956. ci->propertyFlags |= visible;
  39957. else
  39958. ci->propertyFlags &= ~visible;
  39959. sendColumnsChanged();
  39960. resized();
  39961. }
  39962. }
  39963. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  39964. {
  39965. const ColumnInfo* const ci = getInfoForId (columnId);
  39966. return ci != 0 && ci->isVisible();
  39967. }
  39968. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  39969. {
  39970. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  39971. {
  39972. for (int i = columns.size(); --i >= 0;)
  39973. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  39974. ColumnInfo* const ci = getInfoForId (columnId);
  39975. if (ci != 0)
  39976. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  39977. reSortTable();
  39978. }
  39979. }
  39980. int TableHeaderComponent::getSortColumnId() const
  39981. {
  39982. for (int i = columns.size(); --i >= 0;)
  39983. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  39984. return columns.getUnchecked(i)->id;
  39985. return 0;
  39986. }
  39987. bool TableHeaderComponent::isSortedForwards() const
  39988. {
  39989. for (int i = columns.size(); --i >= 0;)
  39990. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  39991. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  39992. return true;
  39993. }
  39994. void TableHeaderComponent::reSortTable()
  39995. {
  39996. sortChanged = true;
  39997. repaint();
  39998. triggerAsyncUpdate();
  39999. }
  40000. const String TableHeaderComponent::toString() const
  40001. {
  40002. String s;
  40003. XmlElement doc ("TABLELAYOUT");
  40004. doc.setAttribute ("sortedCol", getSortColumnId());
  40005. doc.setAttribute ("sortForwards", isSortedForwards());
  40006. for (int i = 0; i < columns.size(); ++i)
  40007. {
  40008. const ColumnInfo* const ci = columns.getUnchecked (i);
  40009. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40010. e->setAttribute ("id", ci->id);
  40011. e->setAttribute ("visible", ci->isVisible());
  40012. e->setAttribute ("width", ci->width);
  40013. }
  40014. return doc.createDocument (String::empty, true, false);
  40015. }
  40016. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40017. {
  40018. XmlDocument doc (storedVersion);
  40019. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40020. int index = 0;
  40021. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40022. {
  40023. forEachXmlChildElement (*storedXml, col)
  40024. {
  40025. const int tabId = col->getIntAttribute ("id");
  40026. ColumnInfo* const ci = getInfoForId (tabId);
  40027. if (ci != 0)
  40028. {
  40029. columns.move (columns.indexOf (ci), index);
  40030. ci->width = col->getIntAttribute ("width");
  40031. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40032. }
  40033. ++index;
  40034. }
  40035. columnsResized = true;
  40036. sendColumnsChanged();
  40037. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40038. storedXml->getBoolAttribute ("sortForwards", true));
  40039. }
  40040. }
  40041. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40042. {
  40043. listeners.addIfNotAlreadyThere (newListener);
  40044. }
  40045. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40046. {
  40047. listeners.removeValue (listenerToRemove);
  40048. }
  40049. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40050. {
  40051. const ColumnInfo* const ci = getInfoForId (columnId);
  40052. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40053. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40054. }
  40055. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40056. {
  40057. for (int i = 0; i < columns.size(); ++i)
  40058. {
  40059. const ColumnInfo* const ci = columns.getUnchecked(i);
  40060. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40061. menu.addItem (ci->id, ci->name,
  40062. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40063. isColumnVisible (ci->id));
  40064. }
  40065. }
  40066. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40067. {
  40068. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40069. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40070. }
  40071. void TableHeaderComponent::paint (Graphics& g)
  40072. {
  40073. LookAndFeel& lf = getLookAndFeel();
  40074. lf.drawTableHeaderBackground (g, *this);
  40075. const Rectangle<int> clip (g.getClipBounds());
  40076. int x = 0;
  40077. for (int i = 0; i < columns.size(); ++i)
  40078. {
  40079. const ColumnInfo* const ci = columns.getUnchecked(i);
  40080. if (ci->isVisible())
  40081. {
  40082. if (x + ci->width > clip.getX()
  40083. && (ci->id != columnIdBeingDragged
  40084. || dragOverlayComp == 0
  40085. || ! dragOverlayComp->isVisible()))
  40086. {
  40087. g.saveState();
  40088. g.setOrigin (x, 0);
  40089. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40090. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40091. ci->id == columnIdUnderMouse,
  40092. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40093. ci->propertyFlags);
  40094. g.restoreState();
  40095. }
  40096. x += ci->width;
  40097. if (x >= clip.getRight())
  40098. break;
  40099. }
  40100. }
  40101. }
  40102. void TableHeaderComponent::resized()
  40103. {
  40104. }
  40105. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40106. {
  40107. updateColumnUnderMouse (e.x, e.y);
  40108. }
  40109. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40110. {
  40111. updateColumnUnderMouse (e.x, e.y);
  40112. }
  40113. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40114. {
  40115. updateColumnUnderMouse (e.x, e.y);
  40116. }
  40117. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40118. {
  40119. repaint();
  40120. columnIdBeingResized = 0;
  40121. columnIdBeingDragged = 0;
  40122. if (columnIdUnderMouse != 0)
  40123. {
  40124. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40125. if (e.mods.isPopupMenu())
  40126. columnClicked (columnIdUnderMouse, e.mods);
  40127. }
  40128. if (menuActive && e.mods.isPopupMenu())
  40129. showColumnChooserMenu (columnIdUnderMouse);
  40130. }
  40131. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40132. {
  40133. if (columnIdBeingResized == 0
  40134. && columnIdBeingDragged == 0
  40135. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40136. {
  40137. dragOverlayComp = 0;
  40138. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40139. if (columnIdBeingResized != 0)
  40140. {
  40141. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40142. initialColumnWidth = ci->width;
  40143. }
  40144. else
  40145. {
  40146. beginDrag (e);
  40147. }
  40148. }
  40149. if (columnIdBeingResized != 0)
  40150. {
  40151. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40152. if (ci != 0)
  40153. {
  40154. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40155. initialColumnWidth + e.getDistanceFromDragStartX());
  40156. if (stretchToFit)
  40157. {
  40158. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40159. int minWidthOnRight = 0;
  40160. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40161. if (columns.getUnchecked (i)->isVisible())
  40162. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40163. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40164. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40165. }
  40166. setColumnWidth (columnIdBeingResized, w);
  40167. }
  40168. }
  40169. else if (columnIdBeingDragged != 0)
  40170. {
  40171. if (e.y >= -50 && e.y < getHeight() + 50)
  40172. {
  40173. if (dragOverlayComp != 0)
  40174. {
  40175. dragOverlayComp->setVisible (true);
  40176. dragOverlayComp->setBounds (jlimit (0,
  40177. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40178. e.x - draggingColumnOffset),
  40179. 0,
  40180. dragOverlayComp->getWidth(),
  40181. getHeight());
  40182. for (int i = columns.size(); --i >= 0;)
  40183. {
  40184. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40185. int newIndex = currentIndex;
  40186. if (newIndex > 0)
  40187. {
  40188. // if the previous column isn't draggable, we can't move our column
  40189. // past it, because that'd change the undraggable column's position..
  40190. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40191. if ((previous->propertyFlags & draggable) != 0)
  40192. {
  40193. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40194. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40195. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40196. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40197. {
  40198. --newIndex;
  40199. }
  40200. }
  40201. }
  40202. if (newIndex < columns.size() - 1)
  40203. {
  40204. // if the next column isn't draggable, we can't move our column
  40205. // past it, because that'd change the undraggable column's position..
  40206. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40207. if ((nextCol->propertyFlags & draggable) != 0)
  40208. {
  40209. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40210. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40211. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40212. > abs (dragOverlayComp->getRight() - rightOfNext))
  40213. {
  40214. ++newIndex;
  40215. }
  40216. }
  40217. }
  40218. if (newIndex != currentIndex)
  40219. moveColumn (columnIdBeingDragged, newIndex);
  40220. else
  40221. break;
  40222. }
  40223. }
  40224. }
  40225. else
  40226. {
  40227. endDrag (draggingColumnOriginalIndex);
  40228. }
  40229. }
  40230. }
  40231. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40232. {
  40233. if (columnIdBeingDragged == 0)
  40234. {
  40235. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40236. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40237. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40238. {
  40239. columnIdBeingDragged = 0;
  40240. }
  40241. else
  40242. {
  40243. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40244. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40245. const int temp = columnIdBeingDragged;
  40246. columnIdBeingDragged = 0;
  40247. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40248. columnIdBeingDragged = temp;
  40249. dragOverlayComp->setBounds (columnRect);
  40250. for (int i = listeners.size(); --i >= 0;)
  40251. {
  40252. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40253. i = jmin (i, listeners.size() - 1);
  40254. }
  40255. }
  40256. }
  40257. }
  40258. void TableHeaderComponent::endDrag (const int finalIndex)
  40259. {
  40260. if (columnIdBeingDragged != 0)
  40261. {
  40262. moveColumn (columnIdBeingDragged, finalIndex);
  40263. columnIdBeingDragged = 0;
  40264. repaint();
  40265. for (int i = listeners.size(); --i >= 0;)
  40266. {
  40267. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40268. i = jmin (i, listeners.size() - 1);
  40269. }
  40270. }
  40271. }
  40272. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40273. {
  40274. mouseDrag (e);
  40275. for (int i = columns.size(); --i >= 0;)
  40276. if (columns.getUnchecked (i)->isVisible())
  40277. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40278. columnIdBeingResized = 0;
  40279. repaint();
  40280. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40281. updateColumnUnderMouse (e.x, e.y);
  40282. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40283. columnClicked (columnIdUnderMouse, e.mods);
  40284. dragOverlayComp = 0;
  40285. }
  40286. const MouseCursor TableHeaderComponent::getMouseCursor()
  40287. {
  40288. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40289. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40290. return Component::getMouseCursor();
  40291. }
  40292. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40293. {
  40294. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40295. }
  40296. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40297. {
  40298. for (int i = columns.size(); --i >= 0;)
  40299. if (columns.getUnchecked(i)->id == id)
  40300. return columns.getUnchecked(i);
  40301. return 0;
  40302. }
  40303. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40304. {
  40305. int n = 0;
  40306. for (int i = 0; i < columns.size(); ++i)
  40307. {
  40308. if (columns.getUnchecked(i)->isVisible())
  40309. {
  40310. if (n == visibleIndex)
  40311. return i;
  40312. ++n;
  40313. }
  40314. }
  40315. return -1;
  40316. }
  40317. void TableHeaderComponent::sendColumnsChanged()
  40318. {
  40319. if (stretchToFit && lastDeliberateWidth > 0)
  40320. resizeAllColumnsToFit (lastDeliberateWidth);
  40321. repaint();
  40322. columnsChanged = true;
  40323. triggerAsyncUpdate();
  40324. }
  40325. void TableHeaderComponent::handleAsyncUpdate()
  40326. {
  40327. const bool changed = columnsChanged || sortChanged;
  40328. const bool sized = columnsResized || changed;
  40329. const bool sorted = sortChanged;
  40330. columnsChanged = false;
  40331. columnsResized = false;
  40332. sortChanged = false;
  40333. if (sorted)
  40334. {
  40335. for (int i = listeners.size(); --i >= 0;)
  40336. {
  40337. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40338. i = jmin (i, listeners.size() - 1);
  40339. }
  40340. }
  40341. if (changed)
  40342. {
  40343. for (int i = listeners.size(); --i >= 0;)
  40344. {
  40345. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40346. i = jmin (i, listeners.size() - 1);
  40347. }
  40348. }
  40349. if (sized)
  40350. {
  40351. for (int i = listeners.size(); --i >= 0;)
  40352. {
  40353. listeners.getUnchecked(i)->tableColumnsResized (this);
  40354. i = jmin (i, listeners.size() - 1);
  40355. }
  40356. }
  40357. }
  40358. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40359. {
  40360. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40361. {
  40362. const int draggableDistance = 3;
  40363. int x = 0;
  40364. for (int i = 0; i < columns.size(); ++i)
  40365. {
  40366. const ColumnInfo* const ci = columns.getUnchecked(i);
  40367. if (ci->isVisible())
  40368. {
  40369. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40370. && (ci->propertyFlags & resizable) != 0)
  40371. return ci->id;
  40372. x += ci->width;
  40373. }
  40374. }
  40375. }
  40376. return 0;
  40377. }
  40378. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40379. {
  40380. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40381. ? getColumnIdAtX (x) : 0;
  40382. if (newCol != columnIdUnderMouse)
  40383. {
  40384. columnIdUnderMouse = newCol;
  40385. repaint();
  40386. }
  40387. }
  40388. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40389. {
  40390. PopupMenu m;
  40391. addMenuItems (m, columnIdClicked);
  40392. if (m.getNumItems() > 0)
  40393. {
  40394. m.setLookAndFeel (&getLookAndFeel());
  40395. const int result = m.show();
  40396. if (result != 0)
  40397. reactToMenuItem (result, columnIdClicked);
  40398. }
  40399. }
  40400. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40401. {
  40402. }
  40403. END_JUCE_NAMESPACE
  40404. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40405. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40406. BEGIN_JUCE_NAMESPACE
  40407. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40408. class TableListRowComp : public Component,
  40409. public TooltipClient
  40410. {
  40411. public:
  40412. TableListRowComp (TableListBox& owner_)
  40413. : owner (owner_),
  40414. row (-1),
  40415. isSelected (false)
  40416. {
  40417. }
  40418. ~TableListRowComp()
  40419. {
  40420. deleteAllChildren();
  40421. }
  40422. void paint (Graphics& g)
  40423. {
  40424. TableListBoxModel* const model = owner.getModel();
  40425. if (model != 0)
  40426. {
  40427. const TableHeaderComponent* const header = owner.getHeader();
  40428. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40429. const int numColumns = header->getNumColumns (true);
  40430. for (int i = 0; i < numColumns; ++i)
  40431. {
  40432. if (! columnsWithComponents [i])
  40433. {
  40434. const int columnId = header->getColumnIdOfIndex (i, true);
  40435. Rectangle<int> columnRect (header->getColumnPosition (i));
  40436. columnRect.setSize (columnRect.getWidth(), getHeight());
  40437. g.saveState();
  40438. g.reduceClipRegion (columnRect);
  40439. g.setOrigin (columnRect.getX(), 0);
  40440. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40441. g.restoreState();
  40442. }
  40443. }
  40444. }
  40445. }
  40446. void update (const int newRow, const bool isNowSelected)
  40447. {
  40448. if (newRow != row || isNowSelected != isSelected)
  40449. {
  40450. row = newRow;
  40451. isSelected = isNowSelected;
  40452. repaint();
  40453. }
  40454. if (row < owner.getNumRows())
  40455. {
  40456. jassert (row >= 0);
  40457. const var::identifier tagPropertyName ("_tableLastUseNum");
  40458. const int newTag = Random::getSystemRandom().nextInt();
  40459. const TableHeaderComponent* const header = owner.getHeader();
  40460. const int numColumns = header->getNumColumns (true);
  40461. int i;
  40462. columnsWithComponents.clear();
  40463. if (owner.getModel() != 0)
  40464. {
  40465. for (i = 0; i < numColumns; ++i)
  40466. {
  40467. const int columnId = header->getColumnIdOfIndex (i, true);
  40468. Component* const newComp
  40469. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40470. findChildComponentForColumn (columnId));
  40471. if (newComp != 0)
  40472. {
  40473. addAndMakeVisible (newComp);
  40474. newComp->getProperties().set (tagPropertyName, newTag);
  40475. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40476. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40477. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40478. columnsWithComponents.setBit (i);
  40479. }
  40480. }
  40481. }
  40482. for (i = getNumChildComponents(); --i >= 0;)
  40483. {
  40484. Component* const c = getChildComponent (i);
  40485. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40486. delete c;
  40487. }
  40488. }
  40489. else
  40490. {
  40491. columnsWithComponents.clear();
  40492. deleteAllChildren();
  40493. }
  40494. }
  40495. void resized()
  40496. {
  40497. for (int i = getNumChildComponents(); --i >= 0;)
  40498. {
  40499. Component* const c = getChildComponent (i);
  40500. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40501. if (columnId != 0)
  40502. {
  40503. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40504. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40505. }
  40506. }
  40507. }
  40508. void mouseDown (const MouseEvent& e)
  40509. {
  40510. isDragging = false;
  40511. selectRowOnMouseUp = false;
  40512. if (isEnabled())
  40513. {
  40514. if (! isSelected)
  40515. {
  40516. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40517. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40518. if (columnId != 0 && owner.getModel() != 0)
  40519. owner.getModel()->cellClicked (row, columnId, e);
  40520. }
  40521. else
  40522. {
  40523. selectRowOnMouseUp = true;
  40524. }
  40525. }
  40526. }
  40527. void mouseDrag (const MouseEvent& e)
  40528. {
  40529. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40530. {
  40531. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40532. if (selectedRows.size() > 0)
  40533. {
  40534. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40535. if (dragDescription.isNotEmpty())
  40536. {
  40537. isDragging = true;
  40538. owner.startDragAndDrop (e, dragDescription);
  40539. }
  40540. }
  40541. }
  40542. }
  40543. void mouseUp (const MouseEvent& e)
  40544. {
  40545. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40546. {
  40547. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40548. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40549. if (columnId != 0 && owner.getModel() != 0)
  40550. owner.getModel()->cellClicked (row, columnId, e);
  40551. }
  40552. }
  40553. void mouseDoubleClick (const MouseEvent& e)
  40554. {
  40555. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40556. if (columnId != 0 && owner.getModel() != 0)
  40557. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40558. }
  40559. const String getTooltip()
  40560. {
  40561. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40562. if (columnId != 0 && owner.getModel() != 0)
  40563. return owner.getModel()->getCellTooltip (row, columnId);
  40564. return String::empty;
  40565. }
  40566. juce_UseDebuggingNewOperator
  40567. private:
  40568. TableListBox& owner;
  40569. int row;
  40570. bool isSelected, isDragging, selectRowOnMouseUp;
  40571. BigInteger columnsWithComponents;
  40572. Component* findChildComponentForColumn (const int columnId) const
  40573. {
  40574. for (int i = getNumChildComponents(); --i >= 0;)
  40575. {
  40576. Component* const c = getChildComponent (i);
  40577. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40578. return c;
  40579. }
  40580. return 0;
  40581. }
  40582. TableListRowComp (const TableListRowComp&);
  40583. TableListRowComp& operator= (const TableListRowComp&);
  40584. };
  40585. class TableListBoxHeader : public TableHeaderComponent
  40586. {
  40587. public:
  40588. TableListBoxHeader (TableListBox& owner_)
  40589. : owner (owner_)
  40590. {
  40591. }
  40592. ~TableListBoxHeader()
  40593. {
  40594. }
  40595. void addMenuItems (PopupMenu& menu, int columnIdClicked)
  40596. {
  40597. if (owner.isAutoSizeMenuOptionShown())
  40598. {
  40599. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40600. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40601. menu.addSeparator();
  40602. }
  40603. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40604. }
  40605. void reactToMenuItem (int menuReturnId, int columnIdClicked)
  40606. {
  40607. if (menuReturnId == 0xf836743)
  40608. {
  40609. owner.autoSizeColumn (columnIdClicked);
  40610. }
  40611. else if (menuReturnId == 0xf836744)
  40612. {
  40613. owner.autoSizeAllColumns();
  40614. }
  40615. else
  40616. {
  40617. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40618. }
  40619. }
  40620. juce_UseDebuggingNewOperator
  40621. private:
  40622. TableListBox& owner;
  40623. TableListBoxHeader (const TableListBoxHeader&);
  40624. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40625. };
  40626. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40627. : ListBox (name, 0),
  40628. model (model_),
  40629. autoSizeOptionsShown (true)
  40630. {
  40631. ListBox::model = this;
  40632. header = new TableListBoxHeader (*this);
  40633. header->setSize (100, 28);
  40634. header->addListener (this);
  40635. setHeaderComponent (header);
  40636. }
  40637. TableListBox::~TableListBox()
  40638. {
  40639. deleteAllChildren();
  40640. }
  40641. void TableListBox::setModel (TableListBoxModel* const newModel)
  40642. {
  40643. if (model != newModel)
  40644. {
  40645. model = newModel;
  40646. updateContent();
  40647. }
  40648. }
  40649. int TableListBox::getHeaderHeight() const
  40650. {
  40651. return header->getHeight();
  40652. }
  40653. void TableListBox::setHeaderHeight (const int newHeight)
  40654. {
  40655. header->setSize (header->getWidth(), newHeight);
  40656. resized();
  40657. }
  40658. void TableListBox::autoSizeColumn (const int columnId)
  40659. {
  40660. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40661. if (width > 0)
  40662. header->setColumnWidth (columnId, width);
  40663. }
  40664. void TableListBox::autoSizeAllColumns()
  40665. {
  40666. for (int i = 0; i < header->getNumColumns (true); ++i)
  40667. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40668. }
  40669. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40670. {
  40671. autoSizeOptionsShown = shouldBeShown;
  40672. }
  40673. bool TableListBox::isAutoSizeMenuOptionShown() const
  40674. {
  40675. return autoSizeOptionsShown;
  40676. }
  40677. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40678. const int rowNumber,
  40679. const bool relativeToComponentTopLeft) const
  40680. {
  40681. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40682. if (relativeToComponentTopLeft)
  40683. headerCell.translate (header->getX(), 0);
  40684. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40685. return Rectangle<int> (headerCell.getX(), row.getY(),
  40686. headerCell.getWidth(), row.getHeight());
  40687. }
  40688. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40689. {
  40690. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40691. if (scrollbar != 0)
  40692. {
  40693. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40694. double x = scrollbar->getCurrentRangeStart();
  40695. const double w = scrollbar->getCurrentRangeSize();
  40696. if (pos.getX() < x)
  40697. x = pos.getX();
  40698. else if (pos.getRight() > x + w)
  40699. x += jmax (0.0, pos.getRight() - (x + w));
  40700. scrollbar->setCurrentRangeStart (x);
  40701. }
  40702. }
  40703. int TableListBox::getNumRows()
  40704. {
  40705. return model != 0 ? model->getNumRows() : 0;
  40706. }
  40707. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40708. {
  40709. }
  40710. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40711. {
  40712. if (existingComponentToUpdate == 0)
  40713. existingComponentToUpdate = new TableListRowComp (*this);
  40714. static_cast <TableListRowComp*> (existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40715. return existingComponentToUpdate;
  40716. }
  40717. void TableListBox::selectedRowsChanged (int row)
  40718. {
  40719. if (model != 0)
  40720. model->selectedRowsChanged (row);
  40721. }
  40722. void TableListBox::deleteKeyPressed (int row)
  40723. {
  40724. if (model != 0)
  40725. model->deleteKeyPressed (row);
  40726. }
  40727. void TableListBox::returnKeyPressed (int row)
  40728. {
  40729. if (model != 0)
  40730. model->returnKeyPressed (row);
  40731. }
  40732. void TableListBox::backgroundClicked()
  40733. {
  40734. if (model != 0)
  40735. model->backgroundClicked();
  40736. }
  40737. void TableListBox::listWasScrolled()
  40738. {
  40739. if (model != 0)
  40740. model->listWasScrolled();
  40741. }
  40742. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40743. {
  40744. setMinimumContentWidth (header->getTotalWidth());
  40745. repaint();
  40746. updateColumnComponents();
  40747. }
  40748. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40749. {
  40750. setMinimumContentWidth (header->getTotalWidth());
  40751. repaint();
  40752. updateColumnComponents();
  40753. }
  40754. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40755. {
  40756. if (model != 0)
  40757. model->sortOrderChanged (header->getSortColumnId(),
  40758. header->isSortedForwards());
  40759. }
  40760. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40761. {
  40762. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40763. repaint();
  40764. }
  40765. void TableListBox::resized()
  40766. {
  40767. ListBox::resized();
  40768. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40769. setMinimumContentWidth (header->getTotalWidth());
  40770. }
  40771. void TableListBox::updateColumnComponents() const
  40772. {
  40773. const int firstRow = getRowContainingPosition (0, 0);
  40774. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40775. {
  40776. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40777. if (rowComp != 0)
  40778. rowComp->resized();
  40779. }
  40780. }
  40781. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40782. {
  40783. }
  40784. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40785. {
  40786. }
  40787. void TableListBoxModel::backgroundClicked()
  40788. {
  40789. }
  40790. void TableListBoxModel::sortOrderChanged (int, const bool)
  40791. {
  40792. }
  40793. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40794. {
  40795. return 0;
  40796. }
  40797. void TableListBoxModel::selectedRowsChanged (int)
  40798. {
  40799. }
  40800. void TableListBoxModel::deleteKeyPressed (int)
  40801. {
  40802. }
  40803. void TableListBoxModel::returnKeyPressed (int)
  40804. {
  40805. }
  40806. void TableListBoxModel::listWasScrolled()
  40807. {
  40808. }
  40809. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40810. {
  40811. return String::empty;
  40812. }
  40813. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40814. {
  40815. return String::empty;
  40816. }
  40817. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40818. {
  40819. (void) existingComponentToUpdate;
  40820. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40821. return 0;
  40822. }
  40823. END_JUCE_NAMESPACE
  40824. /*** End of inlined file: juce_TableListBox.cpp ***/
  40825. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40826. BEGIN_JUCE_NAMESPACE
  40827. // a word or space that can't be broken down any further
  40828. struct TextAtom
  40829. {
  40830. String atomText;
  40831. float width;
  40832. uint16 numChars;
  40833. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40834. bool isNewLine() const { return atomText[0] == '\r' || atomText[0] == '\n'; }
  40835. const String getText (const tchar passwordCharacter) const
  40836. {
  40837. if (passwordCharacter == 0)
  40838. return atomText;
  40839. else
  40840. return String::repeatedString (String::charToString (passwordCharacter),
  40841. atomText.length());
  40842. }
  40843. const String getTrimmedText (const tchar passwordCharacter) const
  40844. {
  40845. if (passwordCharacter == 0)
  40846. return atomText.substring (0, numChars);
  40847. else if (isNewLine())
  40848. return String::empty;
  40849. else
  40850. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40851. }
  40852. };
  40853. // a run of text with a single font and colour
  40854. class UniformTextSection
  40855. {
  40856. public:
  40857. UniformTextSection (const String& text,
  40858. const Font& font_,
  40859. const Colour& colour_,
  40860. const tchar passwordCharacter)
  40861. : font (font_),
  40862. colour (colour_)
  40863. {
  40864. initialiseAtoms (text, passwordCharacter);
  40865. }
  40866. UniformTextSection (const UniformTextSection& other)
  40867. : font (other.font),
  40868. colour (other.colour)
  40869. {
  40870. atoms.ensureStorageAllocated (other.atoms.size());
  40871. for (int i = 0; i < other.atoms.size(); ++i)
  40872. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  40873. }
  40874. ~UniformTextSection()
  40875. {
  40876. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40877. }
  40878. void clear()
  40879. {
  40880. for (int i = atoms.size(); --i >= 0;)
  40881. delete getAtom(i);
  40882. atoms.clear();
  40883. }
  40884. int getNumAtoms() const
  40885. {
  40886. return atoms.size();
  40887. }
  40888. TextAtom* getAtom (const int index) const
  40889. {
  40890. return (TextAtom*) atoms.getUnchecked (index);
  40891. }
  40892. void append (const UniformTextSection& other, const tchar passwordCharacter)
  40893. {
  40894. if (other.atoms.size() > 0)
  40895. {
  40896. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  40897. int i = 0;
  40898. if (lastAtom != 0)
  40899. {
  40900. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  40901. {
  40902. TextAtom* const first = other.getAtom(0);
  40903. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  40904. {
  40905. lastAtom->atomText += first->atomText;
  40906. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  40907. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  40908. delete first;
  40909. ++i;
  40910. }
  40911. }
  40912. }
  40913. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  40914. while (i < other.atoms.size())
  40915. {
  40916. atoms.add (other.getAtom(i));
  40917. ++i;
  40918. }
  40919. }
  40920. }
  40921. UniformTextSection* split (const int indexToBreakAt,
  40922. const tchar passwordCharacter)
  40923. {
  40924. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  40925. font, colour,
  40926. passwordCharacter);
  40927. int index = 0;
  40928. for (int i = 0; i < atoms.size(); ++i)
  40929. {
  40930. TextAtom* const atom = getAtom(i);
  40931. const int nextIndex = index + atom->numChars;
  40932. if (index == indexToBreakAt)
  40933. {
  40934. int j;
  40935. for (j = i; j < atoms.size(); ++j)
  40936. section2->atoms.add (getAtom (j));
  40937. for (j = atoms.size(); --j >= i;)
  40938. atoms.remove (j);
  40939. break;
  40940. }
  40941. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  40942. {
  40943. TextAtom* const secondAtom = new TextAtom();
  40944. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  40945. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  40946. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  40947. section2->atoms.add (secondAtom);
  40948. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  40949. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  40950. atom->numChars = (uint16) (indexToBreakAt - index);
  40951. int j;
  40952. for (j = i + 1; j < atoms.size(); ++j)
  40953. section2->atoms.add (getAtom (j));
  40954. for (j = atoms.size(); --j > i;)
  40955. atoms.remove (j);
  40956. break;
  40957. }
  40958. index = nextIndex;
  40959. }
  40960. return section2;
  40961. }
  40962. void appendAllText (String::Concatenator& concatenator) const
  40963. {
  40964. for (int i = 0; i < atoms.size(); ++i)
  40965. concatenator.append (getAtom(i)->atomText);
  40966. }
  40967. void appendSubstring (String::Concatenator& concatenator,
  40968. const Range<int>& range) const
  40969. {
  40970. int index = 0;
  40971. for (int i = 0; i < atoms.size(); ++i)
  40972. {
  40973. const TextAtom* const atom = getAtom (i);
  40974. const int nextIndex = index + atom->numChars;
  40975. if (range.getStart() < nextIndex)
  40976. {
  40977. if (range.getEnd() <= index)
  40978. break;
  40979. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  40980. if (! r.isEmpty())
  40981. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  40982. }
  40983. index = nextIndex;
  40984. }
  40985. }
  40986. int getTotalLength() const
  40987. {
  40988. int total = 0;
  40989. for (int i = atoms.size(); --i >= 0;)
  40990. total += getAtom(i)->numChars;
  40991. return total;
  40992. }
  40993. void setFont (const Font& newFont,
  40994. const tchar passwordCharacter)
  40995. {
  40996. if (font != newFont)
  40997. {
  40998. font = newFont;
  40999. for (int i = atoms.size(); --i >= 0;)
  41000. {
  41001. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41002. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41003. }
  41004. }
  41005. }
  41006. juce_UseDebuggingNewOperator
  41007. Font font;
  41008. Colour colour;
  41009. private:
  41010. VoidArray atoms;
  41011. void initialiseAtoms (const String& textToParse,
  41012. const tchar passwordCharacter)
  41013. {
  41014. int i = 0;
  41015. const int len = textToParse.length();
  41016. const juce_wchar* const text = textToParse;
  41017. while (i < len)
  41018. {
  41019. int start = i;
  41020. // create a whitespace atom unless it starts with non-ws
  41021. if (CharacterFunctions::isWhitespace (text[i])
  41022. && text[i] != '\r'
  41023. && text[i] != '\n')
  41024. {
  41025. while (i < len
  41026. && CharacterFunctions::isWhitespace (text[i])
  41027. && text[i] != '\r'
  41028. && text[i] != '\n')
  41029. {
  41030. ++i;
  41031. }
  41032. }
  41033. else
  41034. {
  41035. if (text[i] == '\r')
  41036. {
  41037. ++i;
  41038. if ((i < len) && (text[i] == '\n'))
  41039. {
  41040. ++start;
  41041. ++i;
  41042. }
  41043. }
  41044. else if (text[i] == '\n')
  41045. {
  41046. ++i;
  41047. }
  41048. else
  41049. {
  41050. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41051. ++i;
  41052. }
  41053. }
  41054. TextAtom* const atom = new TextAtom();
  41055. atom->atomText = String (text + start, i - start);
  41056. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41057. atom->numChars = (uint16) (i - start);
  41058. atoms.add (atom);
  41059. }
  41060. }
  41061. UniformTextSection& operator= (const UniformTextSection& other);
  41062. };
  41063. class TextEditorIterator
  41064. {
  41065. public:
  41066. TextEditorIterator (const VoidArray& sections_,
  41067. const float wordWrapWidth_,
  41068. const tchar passwordCharacter_)
  41069. : indexInText (0),
  41070. lineY (0),
  41071. lineHeight (0),
  41072. maxDescent (0),
  41073. atomX (0),
  41074. atomRight (0),
  41075. atom (0),
  41076. currentSection (0),
  41077. sections (sections_),
  41078. sectionIndex (0),
  41079. atomIndex (0),
  41080. wordWrapWidth (wordWrapWidth_),
  41081. passwordCharacter (passwordCharacter_)
  41082. {
  41083. jassert (wordWrapWidth_ > 0);
  41084. if (sections.size() > 0)
  41085. {
  41086. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41087. if (currentSection != 0)
  41088. beginNewLine();
  41089. }
  41090. }
  41091. TextEditorIterator (const TextEditorIterator& other)
  41092. : indexInText (other.indexInText),
  41093. lineY (other.lineY),
  41094. lineHeight (other.lineHeight),
  41095. maxDescent (other.maxDescent),
  41096. atomX (other.atomX),
  41097. atomRight (other.atomRight),
  41098. atom (other.atom),
  41099. currentSection (other.currentSection),
  41100. sections (other.sections),
  41101. sectionIndex (other.sectionIndex),
  41102. atomIndex (other.atomIndex),
  41103. wordWrapWidth (other.wordWrapWidth),
  41104. passwordCharacter (other.passwordCharacter),
  41105. tempAtom (other.tempAtom)
  41106. {
  41107. }
  41108. ~TextEditorIterator()
  41109. {
  41110. }
  41111. bool next()
  41112. {
  41113. if (atom == &tempAtom)
  41114. {
  41115. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41116. if (numRemaining > 0)
  41117. {
  41118. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41119. atomX = 0;
  41120. if (tempAtom.numChars > 0)
  41121. lineY += lineHeight;
  41122. indexInText += tempAtom.numChars;
  41123. GlyphArrangement g;
  41124. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41125. int split;
  41126. for (split = 0; split < g.getNumGlyphs(); ++split)
  41127. if (shouldWrap (g.getGlyph (split).getRight()))
  41128. break;
  41129. if (split > 0 && split <= numRemaining)
  41130. {
  41131. tempAtom.numChars = (uint16) split;
  41132. tempAtom.width = g.getGlyph (split - 1).getRight();
  41133. atomRight = atomX + tempAtom.width;
  41134. return true;
  41135. }
  41136. }
  41137. }
  41138. bool forceNewLine = false;
  41139. if (sectionIndex >= sections.size())
  41140. {
  41141. moveToEndOfLastAtom();
  41142. return false;
  41143. }
  41144. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41145. {
  41146. if (atomIndex >= currentSection->getNumAtoms())
  41147. {
  41148. if (++sectionIndex >= sections.size())
  41149. {
  41150. moveToEndOfLastAtom();
  41151. return false;
  41152. }
  41153. atomIndex = 0;
  41154. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41155. }
  41156. else
  41157. {
  41158. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41159. if (! lastAtom->isWhitespace())
  41160. {
  41161. // handle the case where the last atom in a section is actually part of the same
  41162. // word as the first atom of the next section...
  41163. float right = atomRight + lastAtom->width;
  41164. float lineHeight2 = lineHeight;
  41165. float maxDescent2 = maxDescent;
  41166. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41167. {
  41168. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41169. if (s->getNumAtoms() == 0)
  41170. break;
  41171. const TextAtom* const nextAtom = s->getAtom (0);
  41172. if (nextAtom->isWhitespace())
  41173. break;
  41174. right += nextAtom->width;
  41175. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41176. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41177. if (shouldWrap (right))
  41178. {
  41179. lineHeight = lineHeight2;
  41180. maxDescent = maxDescent2;
  41181. forceNewLine = true;
  41182. break;
  41183. }
  41184. if (s->getNumAtoms() > 1)
  41185. break;
  41186. }
  41187. }
  41188. }
  41189. }
  41190. if (atom != 0)
  41191. {
  41192. atomX = atomRight;
  41193. indexInText += atom->numChars;
  41194. if (atom->isNewLine())
  41195. beginNewLine();
  41196. }
  41197. atom = currentSection->getAtom (atomIndex);
  41198. atomRight = atomX + atom->width;
  41199. ++atomIndex;
  41200. if (shouldWrap (atomRight) || forceNewLine)
  41201. {
  41202. if (atom->isWhitespace())
  41203. {
  41204. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41205. atomRight = jmin (atomRight, wordWrapWidth);
  41206. }
  41207. else
  41208. {
  41209. atomRight = atom->width;
  41210. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41211. {
  41212. tempAtom = *atom;
  41213. tempAtom.width = 0;
  41214. tempAtom.numChars = 0;
  41215. atom = &tempAtom;
  41216. if (atomX > 0)
  41217. beginNewLine();
  41218. return next();
  41219. }
  41220. beginNewLine();
  41221. return true;
  41222. }
  41223. }
  41224. return true;
  41225. }
  41226. void beginNewLine()
  41227. {
  41228. atomX = 0;
  41229. lineY += lineHeight;
  41230. int tempSectionIndex = sectionIndex;
  41231. int tempAtomIndex = atomIndex;
  41232. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41233. lineHeight = section->font.getHeight();
  41234. maxDescent = section->font.getDescent();
  41235. float x = (atom != 0) ? atom->width : 0;
  41236. while (! shouldWrap (x))
  41237. {
  41238. if (tempSectionIndex >= sections.size())
  41239. break;
  41240. bool checkSize = false;
  41241. if (tempAtomIndex >= section->getNumAtoms())
  41242. {
  41243. if (++tempSectionIndex >= sections.size())
  41244. break;
  41245. tempAtomIndex = 0;
  41246. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41247. checkSize = true;
  41248. }
  41249. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41250. if (nextAtom == 0)
  41251. break;
  41252. x += nextAtom->width;
  41253. if (shouldWrap (x) || nextAtom->isNewLine())
  41254. break;
  41255. if (checkSize)
  41256. {
  41257. lineHeight = jmax (lineHeight, section->font.getHeight());
  41258. maxDescent = jmax (maxDescent, section->font.getDescent());
  41259. }
  41260. ++tempAtomIndex;
  41261. }
  41262. }
  41263. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41264. {
  41265. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41266. {
  41267. if (lastSection != currentSection)
  41268. {
  41269. lastSection = currentSection;
  41270. g.setColour (currentSection->colour);
  41271. g.setFont (currentSection->font);
  41272. }
  41273. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41274. GlyphArrangement ga;
  41275. ga.addLineOfText (currentSection->font,
  41276. atom->getTrimmedText (passwordCharacter),
  41277. atomX,
  41278. (float) roundToInt (lineY + lineHeight - maxDescent));
  41279. ga.draw (g);
  41280. }
  41281. }
  41282. void drawSelection (Graphics& g,
  41283. const Range<int>& selection) const
  41284. {
  41285. const int startX = roundToInt (indexToX (selection.getStart()));
  41286. const int endX = roundToInt (indexToX (selection.getEnd()));
  41287. const int y = roundToInt (lineY);
  41288. const int nextY = roundToInt (lineY + lineHeight);
  41289. g.fillRect (startX, y, endX - startX, nextY - y);
  41290. }
  41291. void drawSelectedText (Graphics& g,
  41292. const Range<int>& selection,
  41293. const Colour& selectedTextColour) const
  41294. {
  41295. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41296. {
  41297. GlyphArrangement ga;
  41298. ga.addLineOfText (currentSection->font,
  41299. atom->getTrimmedText (passwordCharacter),
  41300. atomX,
  41301. (float) roundToInt (lineY + lineHeight - maxDescent));
  41302. if (selection.getEnd() < indexInText + atom->numChars)
  41303. {
  41304. GlyphArrangement ga2 (ga);
  41305. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41306. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41307. g.setColour (currentSection->colour);
  41308. ga2.draw (g);
  41309. }
  41310. if (selection.getStart() > indexInText)
  41311. {
  41312. GlyphArrangement ga2 (ga);
  41313. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41314. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41315. g.setColour (currentSection->colour);
  41316. ga2.draw (g);
  41317. }
  41318. g.setColour (selectedTextColour);
  41319. ga.draw (g);
  41320. }
  41321. }
  41322. float indexToX (const int indexToFind) const
  41323. {
  41324. if (indexToFind <= indexInText)
  41325. return atomX;
  41326. if (indexToFind >= indexInText + atom->numChars)
  41327. return atomRight;
  41328. GlyphArrangement g;
  41329. g.addLineOfText (currentSection->font,
  41330. atom->getText (passwordCharacter),
  41331. atomX, 0.0f);
  41332. if (indexToFind - indexInText >= g.getNumGlyphs())
  41333. return atomRight;
  41334. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41335. }
  41336. int xToIndex (const float xToFind) const
  41337. {
  41338. if (xToFind <= atomX || atom->isNewLine())
  41339. return indexInText;
  41340. if (xToFind >= atomRight)
  41341. return indexInText + atom->numChars;
  41342. GlyphArrangement g;
  41343. g.addLineOfText (currentSection->font,
  41344. atom->getText (passwordCharacter),
  41345. atomX, 0.0f);
  41346. int j;
  41347. for (j = 0; j < g.getNumGlyphs(); ++j)
  41348. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41349. break;
  41350. return indexInText + j;
  41351. }
  41352. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41353. {
  41354. while (next())
  41355. {
  41356. if (indexInText + atom->numChars > index)
  41357. {
  41358. cx = indexToX (index);
  41359. cy = lineY;
  41360. lineHeight_ = lineHeight;
  41361. return true;
  41362. }
  41363. }
  41364. cx = atomX;
  41365. cy = lineY;
  41366. lineHeight_ = lineHeight;
  41367. return false;
  41368. }
  41369. juce_UseDebuggingNewOperator
  41370. int indexInText;
  41371. float lineY, lineHeight, maxDescent;
  41372. float atomX, atomRight;
  41373. const TextAtom* atom;
  41374. const UniformTextSection* currentSection;
  41375. private:
  41376. const VoidArray& sections;
  41377. int sectionIndex, atomIndex;
  41378. const float wordWrapWidth;
  41379. const tchar passwordCharacter;
  41380. TextAtom tempAtom;
  41381. TextEditorIterator& operator= (const TextEditorIterator&);
  41382. void moveToEndOfLastAtom()
  41383. {
  41384. if (atom != 0)
  41385. {
  41386. atomX = atomRight;
  41387. if (atom->isNewLine())
  41388. {
  41389. atomX = 0.0f;
  41390. lineY += lineHeight;
  41391. }
  41392. }
  41393. }
  41394. bool shouldWrap (const float x) const
  41395. {
  41396. return (x - 0.0001f) >= wordWrapWidth;
  41397. }
  41398. };
  41399. class TextEditorInsertAction : public UndoableAction
  41400. {
  41401. TextEditor& owner;
  41402. const String text;
  41403. const int insertIndex, oldCaretPos, newCaretPos;
  41404. const Font font;
  41405. const Colour colour;
  41406. TextEditorInsertAction (const TextEditorInsertAction&);
  41407. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41408. public:
  41409. TextEditorInsertAction (TextEditor& owner_,
  41410. const String& text_,
  41411. const int insertIndex_,
  41412. const Font& font_,
  41413. const Colour& colour_,
  41414. const int oldCaretPos_,
  41415. const int newCaretPos_)
  41416. : owner (owner_),
  41417. text (text_),
  41418. insertIndex (insertIndex_),
  41419. oldCaretPos (oldCaretPos_),
  41420. newCaretPos (newCaretPos_),
  41421. font (font_),
  41422. colour (colour_)
  41423. {
  41424. }
  41425. ~TextEditorInsertAction()
  41426. {
  41427. }
  41428. bool perform()
  41429. {
  41430. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41431. return true;
  41432. }
  41433. bool undo()
  41434. {
  41435. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41436. return true;
  41437. }
  41438. int getSizeInUnits()
  41439. {
  41440. return text.length() + 16;
  41441. }
  41442. };
  41443. class TextEditorRemoveAction : public UndoableAction
  41444. {
  41445. TextEditor& owner;
  41446. const Range<int> range;
  41447. const int oldCaretPos, newCaretPos;
  41448. VoidArray removedSections;
  41449. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41450. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41451. public:
  41452. TextEditorRemoveAction (TextEditor& owner_,
  41453. const Range<int> range_,
  41454. const int oldCaretPos_,
  41455. const int newCaretPos_,
  41456. const VoidArray& removedSections_)
  41457. : owner (owner_),
  41458. range (range_),
  41459. oldCaretPos (oldCaretPos_),
  41460. newCaretPos (newCaretPos_),
  41461. removedSections (removedSections_)
  41462. {
  41463. }
  41464. ~TextEditorRemoveAction()
  41465. {
  41466. for (int i = removedSections.size(); --i >= 0;)
  41467. {
  41468. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41469. section->clear();
  41470. delete section;
  41471. }
  41472. }
  41473. bool perform()
  41474. {
  41475. owner.remove (range, 0, newCaretPos);
  41476. return true;
  41477. }
  41478. bool undo()
  41479. {
  41480. owner.reinsert (range.getStart(), removedSections);
  41481. owner.moveCursorTo (oldCaretPos, false);
  41482. return true;
  41483. }
  41484. int getSizeInUnits()
  41485. {
  41486. int n = 0;
  41487. for (int i = removedSections.size(); --i >= 0;)
  41488. {
  41489. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41490. n += section->getTotalLength();
  41491. }
  41492. return n + 16;
  41493. }
  41494. };
  41495. class TextHolderComponent : public Component,
  41496. public Timer,
  41497. public Value::Listener
  41498. {
  41499. TextEditor& owner;
  41500. TextHolderComponent (const TextHolderComponent&);
  41501. TextHolderComponent& operator= (const TextHolderComponent&);
  41502. public:
  41503. TextHolderComponent (TextEditor& owner_)
  41504. : owner (owner_)
  41505. {
  41506. setWantsKeyboardFocus (false);
  41507. setInterceptsMouseClicks (false, true);
  41508. owner.getTextValue().addListener (this);
  41509. }
  41510. ~TextHolderComponent()
  41511. {
  41512. owner.getTextValue().removeListener (this);
  41513. }
  41514. void paint (Graphics& g)
  41515. {
  41516. owner.drawContent (g);
  41517. }
  41518. void timerCallback()
  41519. {
  41520. owner.timerCallbackInt();
  41521. }
  41522. const MouseCursor getMouseCursor()
  41523. {
  41524. return owner.getMouseCursor();
  41525. }
  41526. void valueChanged (Value&)
  41527. {
  41528. owner.textWasChangedByValue();
  41529. }
  41530. };
  41531. class TextEditorViewport : public Viewport
  41532. {
  41533. TextEditor* const owner;
  41534. float lastWordWrapWidth;
  41535. TextEditorViewport (const TextEditorViewport&);
  41536. TextEditorViewport& operator= (const TextEditorViewport&);
  41537. public:
  41538. TextEditorViewport (TextEditor* const owner_)
  41539. : owner (owner_),
  41540. lastWordWrapWidth (0)
  41541. {
  41542. }
  41543. ~TextEditorViewport()
  41544. {
  41545. }
  41546. void visibleAreaChanged (int, int, int, int)
  41547. {
  41548. const float wordWrapWidth = owner->getWordWrapWidth();
  41549. if (wordWrapWidth != lastWordWrapWidth)
  41550. {
  41551. lastWordWrapWidth = wordWrapWidth;
  41552. owner->updateTextHolderSize();
  41553. }
  41554. }
  41555. };
  41556. namespace TextEditorDefs
  41557. {
  41558. const int flashSpeedIntervalMs = 380;
  41559. const int textChangeMessageId = 0x10003001;
  41560. const int returnKeyMessageId = 0x10003002;
  41561. const int escapeKeyMessageId = 0x10003003;
  41562. const int focusLossMessageId = 0x10003004;
  41563. const int maxActionsPerTransaction = 100;
  41564. }
  41565. TextEditor::TextEditor (const String& name,
  41566. const tchar passwordCharacter_)
  41567. : Component (name),
  41568. borderSize (1, 1, 1, 3),
  41569. readOnly (false),
  41570. multiline (false),
  41571. wordWrap (false),
  41572. returnKeyStartsNewLine (false),
  41573. caretVisible (true),
  41574. popupMenuEnabled (true),
  41575. selectAllTextWhenFocused (false),
  41576. scrollbarVisible (true),
  41577. wasFocused (false),
  41578. caretFlashState (true),
  41579. keepCursorOnScreen (true),
  41580. tabKeyUsed (false),
  41581. menuActive (false),
  41582. valueTextNeedsUpdating (false),
  41583. cursorX (0),
  41584. cursorY (0),
  41585. cursorHeight (0),
  41586. maxTextLength (0),
  41587. leftIndent (4),
  41588. topIndent (4),
  41589. lastTransactionTime (0),
  41590. currentFont (14.0f),
  41591. totalNumChars (0),
  41592. caretPosition (0),
  41593. passwordCharacter (passwordCharacter_),
  41594. dragType (notDragging)
  41595. {
  41596. setOpaque (true);
  41597. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41598. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41599. viewport->setWantsKeyboardFocus (false);
  41600. viewport->setScrollBarsShown (false, false);
  41601. setMouseCursor (MouseCursor::IBeamCursor);
  41602. setWantsKeyboardFocus (true);
  41603. }
  41604. TextEditor::~TextEditor()
  41605. {
  41606. textValue.referTo (Value());
  41607. clearInternal (0);
  41608. viewport = 0;
  41609. textHolder = 0;
  41610. }
  41611. void TextEditor::newTransaction()
  41612. {
  41613. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41614. undoManager.beginNewTransaction();
  41615. }
  41616. void TextEditor::doUndoRedo (const bool isRedo)
  41617. {
  41618. if (! isReadOnly())
  41619. {
  41620. if (isRedo ? undoManager.redo()
  41621. : undoManager.undo())
  41622. {
  41623. scrollToMakeSureCursorIsVisible();
  41624. repaint();
  41625. textChanged();
  41626. }
  41627. }
  41628. }
  41629. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41630. const bool shouldWordWrap)
  41631. {
  41632. multiline = shouldBeMultiLine;
  41633. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41634. setScrollbarsShown (scrollbarVisible);
  41635. viewport->setViewPosition (0, 0);
  41636. resized();
  41637. scrollToMakeSureCursorIsVisible();
  41638. }
  41639. bool TextEditor::isMultiLine() const
  41640. {
  41641. return multiline;
  41642. }
  41643. void TextEditor::setScrollbarsShown (bool enabled)
  41644. {
  41645. scrollbarVisible = enabled;
  41646. enabled = enabled && isMultiLine();
  41647. viewport->setScrollBarsShown (enabled, enabled);
  41648. }
  41649. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41650. {
  41651. readOnly = shouldBeReadOnly;
  41652. enablementChanged();
  41653. }
  41654. bool TextEditor::isReadOnly() const
  41655. {
  41656. return readOnly || ! isEnabled();
  41657. }
  41658. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41659. {
  41660. returnKeyStartsNewLine = shouldStartNewLine;
  41661. }
  41662. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41663. {
  41664. tabKeyUsed = shouldTabKeyBeUsed;
  41665. }
  41666. void TextEditor::setPopupMenuEnabled (const bool b)
  41667. {
  41668. popupMenuEnabled = b;
  41669. }
  41670. void TextEditor::setSelectAllWhenFocused (const bool b)
  41671. {
  41672. selectAllTextWhenFocused = b;
  41673. }
  41674. const Font TextEditor::getFont() const
  41675. {
  41676. return currentFont;
  41677. }
  41678. void TextEditor::setFont (const Font& newFont)
  41679. {
  41680. currentFont = newFont;
  41681. scrollToMakeSureCursorIsVisible();
  41682. }
  41683. void TextEditor::applyFontToAllText (const Font& newFont)
  41684. {
  41685. currentFont = newFont;
  41686. const Colour overallColour (findColour (textColourId));
  41687. for (int i = sections.size(); --i >= 0;)
  41688. {
  41689. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  41690. uts->setFont (newFont, passwordCharacter);
  41691. uts->colour = overallColour;
  41692. }
  41693. coalesceSimilarSections();
  41694. updateTextHolderSize();
  41695. scrollToMakeSureCursorIsVisible();
  41696. repaint();
  41697. }
  41698. void TextEditor::colourChanged()
  41699. {
  41700. setOpaque (findColour (backgroundColourId).isOpaque());
  41701. repaint();
  41702. }
  41703. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41704. {
  41705. caretVisible = shouldCaretBeVisible;
  41706. if (shouldCaretBeVisible)
  41707. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41708. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41709. : MouseCursor::NormalCursor);
  41710. }
  41711. void TextEditor::setInputRestrictions (const int maxLen,
  41712. const String& chars)
  41713. {
  41714. maxTextLength = jmax (0, maxLen);
  41715. allowedCharacters = chars;
  41716. }
  41717. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41718. {
  41719. textToShowWhenEmpty = text;
  41720. colourForTextWhenEmpty = colourToUse;
  41721. }
  41722. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  41723. {
  41724. if (passwordCharacter != newPasswordCharacter)
  41725. {
  41726. passwordCharacter = newPasswordCharacter;
  41727. resized();
  41728. repaint();
  41729. }
  41730. }
  41731. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41732. {
  41733. viewport->setScrollBarThickness (newThicknessPixels);
  41734. }
  41735. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41736. {
  41737. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41738. }
  41739. void TextEditor::clear()
  41740. {
  41741. clearInternal (0);
  41742. updateTextHolderSize();
  41743. undoManager.clearUndoHistory();
  41744. }
  41745. void TextEditor::setText (const String& newText,
  41746. const bool sendTextChangeMessage)
  41747. {
  41748. const int newLength = newText.length();
  41749. if (newLength != getTotalNumChars() || getText() != newText)
  41750. {
  41751. const int oldCursorPos = caretPosition;
  41752. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41753. clearInternal (0);
  41754. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41755. // if you're adding text with line-feeds to a single-line text editor, it
  41756. // ain't gonna look right!
  41757. jassert (multiline || ! newText.containsAnyOf ("\r\n"));
  41758. if (cursorWasAtEnd && ! isMultiLine())
  41759. moveCursorTo (getTotalNumChars(), false);
  41760. else
  41761. moveCursorTo (oldCursorPos, false);
  41762. if (sendTextChangeMessage)
  41763. textChanged();
  41764. repaint();
  41765. }
  41766. updateTextHolderSize();
  41767. scrollToMakeSureCursorIsVisible();
  41768. undoManager.clearUndoHistory();
  41769. }
  41770. Value& TextEditor::getTextValue()
  41771. {
  41772. if (valueTextNeedsUpdating)
  41773. {
  41774. valueTextNeedsUpdating = false;
  41775. textValue = getText();
  41776. }
  41777. return textValue;
  41778. }
  41779. void TextEditor::textWasChangedByValue()
  41780. {
  41781. if (textValue.getValueSource().getReferenceCount() > 1)
  41782. setText (textValue.getValue());
  41783. }
  41784. void TextEditor::textChanged()
  41785. {
  41786. updateTextHolderSize();
  41787. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41788. if (textValue.getValueSource().getReferenceCount() > 1)
  41789. {
  41790. valueTextNeedsUpdating = false;
  41791. textValue = getText();
  41792. }
  41793. }
  41794. void TextEditor::returnPressed()
  41795. {
  41796. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41797. }
  41798. void TextEditor::escapePressed()
  41799. {
  41800. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41801. }
  41802. void TextEditor::addListener (TextEditorListener* const newListener)
  41803. {
  41804. listeners.add (newListener);
  41805. }
  41806. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41807. {
  41808. listeners.remove (listenerToRemove);
  41809. }
  41810. void TextEditor::timerCallbackInt()
  41811. {
  41812. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41813. if (caretFlashState != newState)
  41814. {
  41815. caretFlashState = newState;
  41816. if (caretFlashState)
  41817. wasFocused = true;
  41818. if (caretVisible
  41819. && hasKeyboardFocus (false)
  41820. && ! isReadOnly())
  41821. {
  41822. repaintCaret();
  41823. }
  41824. }
  41825. const unsigned int now = Time::getApproximateMillisecondCounter();
  41826. if (now > lastTransactionTime + 200)
  41827. newTransaction();
  41828. }
  41829. void TextEditor::repaintCaret()
  41830. {
  41831. if (! findColour (caretColourId).isTransparent())
  41832. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41833. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41834. 4,
  41835. roundToInt (cursorHeight) + 2);
  41836. }
  41837. void TextEditor::repaintText (const Range<int>& range)
  41838. {
  41839. if (! range.isEmpty())
  41840. {
  41841. float x = 0, y = 0, lh = currentFont.getHeight();
  41842. const float wordWrapWidth = getWordWrapWidth();
  41843. if (wordWrapWidth > 0)
  41844. {
  41845. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  41846. i.getCharPosition (range.getStart(), x, y, lh);
  41847. const int y1 = (int) y;
  41848. int y2;
  41849. if (range.getEnd() >= getTotalNumChars())
  41850. {
  41851. y2 = textHolder->getHeight();
  41852. }
  41853. else
  41854. {
  41855. i.getCharPosition (range.getEnd(), x, y, lh);
  41856. y2 = (int) (y + lh * 2.0f);
  41857. }
  41858. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41859. }
  41860. }
  41861. }
  41862. void TextEditor::moveCaret (int newCaretPos)
  41863. {
  41864. if (newCaretPos < 0)
  41865. newCaretPos = 0;
  41866. else if (newCaretPos > getTotalNumChars())
  41867. newCaretPos = getTotalNumChars();
  41868. if (newCaretPos != getCaretPosition())
  41869. {
  41870. repaintCaret();
  41871. caretFlashState = true;
  41872. caretPosition = newCaretPos;
  41873. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41874. scrollToMakeSureCursorIsVisible();
  41875. repaintCaret();
  41876. }
  41877. }
  41878. void TextEditor::setCaretPosition (const int newIndex)
  41879. {
  41880. moveCursorTo (newIndex, false);
  41881. }
  41882. int TextEditor::getCaretPosition() const
  41883. {
  41884. return caretPosition;
  41885. }
  41886. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41887. const int desiredCaretY)
  41888. {
  41889. updateCaretPosition();
  41890. int vx = roundToInt (cursorX) - desiredCaretX;
  41891. int vy = roundToInt (cursorY) - desiredCaretY;
  41892. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41893. {
  41894. vx += desiredCaretX - proportionOfWidth (0.2f);
  41895. }
  41896. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41897. {
  41898. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41899. }
  41900. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  41901. if (! isMultiLine())
  41902. {
  41903. vy = viewport->getViewPositionY();
  41904. }
  41905. else
  41906. {
  41907. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  41908. const int curH = roundToInt (cursorHeight);
  41909. if (desiredCaretY < 0)
  41910. {
  41911. vy = jmax (0, desiredCaretY + vy);
  41912. }
  41913. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  41914. {
  41915. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  41916. }
  41917. }
  41918. viewport->setViewPosition (vx, vy);
  41919. }
  41920. const Rectangle<int> TextEditor::getCaretRectangle()
  41921. {
  41922. updateCaretPosition();
  41923. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  41924. roundToInt (cursorY) - viewport->getY(),
  41925. 1, roundToInt (cursorHeight));
  41926. }
  41927. float TextEditor::getWordWrapWidth() const
  41928. {
  41929. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  41930. : 1.0e10f;
  41931. }
  41932. void TextEditor::updateTextHolderSize()
  41933. {
  41934. const float wordWrapWidth = getWordWrapWidth();
  41935. if (wordWrapWidth > 0)
  41936. {
  41937. float maxWidth = 0.0f;
  41938. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  41939. while (i.next())
  41940. maxWidth = jmax (maxWidth, i.atomRight);
  41941. const int w = leftIndent + roundToInt (maxWidth);
  41942. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  41943. currentFont.getHeight()));
  41944. textHolder->setSize (w + 1, h + 1);
  41945. }
  41946. }
  41947. int TextEditor::getTextWidth() const
  41948. {
  41949. return textHolder->getWidth();
  41950. }
  41951. int TextEditor::getTextHeight() const
  41952. {
  41953. return textHolder->getHeight();
  41954. }
  41955. void TextEditor::setIndents (const int newLeftIndent,
  41956. const int newTopIndent)
  41957. {
  41958. leftIndent = newLeftIndent;
  41959. topIndent = newTopIndent;
  41960. }
  41961. void TextEditor::setBorder (const BorderSize& border)
  41962. {
  41963. borderSize = border;
  41964. resized();
  41965. }
  41966. const BorderSize TextEditor::getBorder() const
  41967. {
  41968. return borderSize;
  41969. }
  41970. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  41971. {
  41972. keepCursorOnScreen = shouldScrollToShowCursor;
  41973. }
  41974. void TextEditor::updateCaretPosition()
  41975. {
  41976. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  41977. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  41978. }
  41979. void TextEditor::scrollToMakeSureCursorIsVisible()
  41980. {
  41981. updateCaretPosition();
  41982. if (keepCursorOnScreen)
  41983. {
  41984. int x = viewport->getViewPositionX();
  41985. int y = viewport->getViewPositionY();
  41986. const int relativeCursorX = roundToInt (cursorX) - x;
  41987. const int relativeCursorY = roundToInt (cursorY) - y;
  41988. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  41989. {
  41990. x += relativeCursorX - proportionOfWidth (0.2f);
  41991. }
  41992. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41993. {
  41994. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41995. }
  41996. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  41997. if (! isMultiLine())
  41998. {
  41999. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42000. }
  42001. else
  42002. {
  42003. const int curH = roundToInt (cursorHeight);
  42004. if (relativeCursorY < 0)
  42005. {
  42006. y = jmax (0, relativeCursorY + y);
  42007. }
  42008. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42009. {
  42010. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42011. }
  42012. }
  42013. viewport->setViewPosition (x, y);
  42014. }
  42015. }
  42016. void TextEditor::moveCursorTo (const int newPosition,
  42017. const bool isSelecting)
  42018. {
  42019. if (isSelecting)
  42020. {
  42021. moveCaret (newPosition);
  42022. const Range<int> oldSelection (selection);
  42023. if (dragType == notDragging)
  42024. {
  42025. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42026. dragType = draggingSelectionStart;
  42027. else
  42028. dragType = draggingSelectionEnd;
  42029. }
  42030. if (dragType == draggingSelectionStart)
  42031. {
  42032. if (getCaretPosition() >= selection.getEnd())
  42033. dragType = draggingSelectionEnd;
  42034. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42035. }
  42036. else
  42037. {
  42038. if (getCaretPosition() < selection.getStart())
  42039. dragType = draggingSelectionStart;
  42040. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42041. }
  42042. repaintText (selection.getUnionWith (oldSelection));
  42043. }
  42044. else
  42045. {
  42046. dragType = notDragging;
  42047. repaintText (selection);
  42048. moveCaret (newPosition);
  42049. selection = Range<int>::emptyRange (getCaretPosition());
  42050. }
  42051. }
  42052. int TextEditor::getTextIndexAt (const int x,
  42053. const int y)
  42054. {
  42055. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42056. (float) (y + viewport->getViewPositionY() - topIndent));
  42057. }
  42058. void TextEditor::insertTextAtCaret (const String& newText_)
  42059. {
  42060. String newText (newText_);
  42061. if (allowedCharacters.isNotEmpty())
  42062. newText = newText.retainCharacters (allowedCharacters);
  42063. if ((! returnKeyStartsNewLine) && newText == "\n")
  42064. {
  42065. returnPressed();
  42066. return;
  42067. }
  42068. if (! isMultiLine())
  42069. newText = newText.replaceCharacters ("\r\n", " ");
  42070. else
  42071. newText = newText.replace ("\r\n", "\n");
  42072. const int newCaretPos = selection.getStart() + newText.length();
  42073. const int insertIndex = selection.getStart();
  42074. remove (selection, getUndoManager(),
  42075. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42076. if (maxTextLength > 0)
  42077. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42078. if (newText.isNotEmpty())
  42079. insert (newText,
  42080. insertIndex,
  42081. currentFont,
  42082. findColour (textColourId),
  42083. getUndoManager(),
  42084. newCaretPos);
  42085. textChanged();
  42086. }
  42087. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42088. {
  42089. moveCursorTo (newSelection.getStart(), false);
  42090. moveCursorTo (newSelection.getEnd(), true);
  42091. }
  42092. void TextEditor::copy()
  42093. {
  42094. if (passwordCharacter == 0)
  42095. {
  42096. const String selection (getHighlightedText());
  42097. if (selection.isNotEmpty())
  42098. SystemClipboard::copyTextToClipboard (selection);
  42099. }
  42100. }
  42101. void TextEditor::paste()
  42102. {
  42103. if (! isReadOnly())
  42104. {
  42105. const String clip (SystemClipboard::getTextFromClipboard());
  42106. if (clip.isNotEmpty())
  42107. insertTextAtCaret (clip);
  42108. }
  42109. }
  42110. void TextEditor::cut()
  42111. {
  42112. if (! isReadOnly())
  42113. {
  42114. moveCaret (selection.getEnd());
  42115. insertTextAtCaret (String::empty);
  42116. }
  42117. }
  42118. void TextEditor::drawContent (Graphics& g)
  42119. {
  42120. const float wordWrapWidth = getWordWrapWidth();
  42121. if (wordWrapWidth > 0)
  42122. {
  42123. g.setOrigin (leftIndent, topIndent);
  42124. const Rectangle<int> clip (g.getClipBounds());
  42125. Colour selectedTextColour;
  42126. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42127. while (i.lineY + 200.0 < clip.getY() && i.next())
  42128. {}
  42129. if (! selection.isEmpty())
  42130. {
  42131. g.setColour (findColour (highlightColourId)
  42132. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42133. selectedTextColour = findColour (highlightedTextColourId);
  42134. TextEditorIterator i2 (i);
  42135. while (i2.next() && i2.lineY < clip.getBottom())
  42136. {
  42137. if (i2.lineY + i2.lineHeight >= clip.getY()
  42138. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42139. {
  42140. i2.drawSelection (g, selection);
  42141. }
  42142. }
  42143. }
  42144. const UniformTextSection* lastSection = 0;
  42145. while (i.next() && i.lineY < clip.getBottom())
  42146. {
  42147. if (i.lineY + i.lineHeight >= clip.getY())
  42148. {
  42149. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42150. {
  42151. i.drawSelectedText (g, selection, selectedTextColour);
  42152. lastSection = 0;
  42153. }
  42154. else
  42155. {
  42156. i.draw (g, lastSection);
  42157. }
  42158. }
  42159. }
  42160. }
  42161. }
  42162. void TextEditor::paint (Graphics& g)
  42163. {
  42164. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42165. }
  42166. void TextEditor::paintOverChildren (Graphics& g)
  42167. {
  42168. if (caretFlashState
  42169. && hasKeyboardFocus (false)
  42170. && caretVisible
  42171. && ! isReadOnly())
  42172. {
  42173. g.setColour (findColour (caretColourId));
  42174. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42175. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42176. 2.0f, cursorHeight);
  42177. }
  42178. if (textToShowWhenEmpty.isNotEmpty()
  42179. && (! hasKeyboardFocus (false))
  42180. && getTotalNumChars() == 0)
  42181. {
  42182. g.setColour (colourForTextWhenEmpty);
  42183. g.setFont (getFont());
  42184. if (isMultiLine())
  42185. {
  42186. g.drawText (textToShowWhenEmpty,
  42187. 0, 0, getWidth(), getHeight(),
  42188. Justification::centred, true);
  42189. }
  42190. else
  42191. {
  42192. g.drawText (textToShowWhenEmpty,
  42193. leftIndent, topIndent,
  42194. viewport->getWidth() - leftIndent,
  42195. viewport->getHeight() - topIndent,
  42196. Justification::centredLeft, true);
  42197. }
  42198. }
  42199. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42200. }
  42201. void TextEditor::mouseDown (const MouseEvent& e)
  42202. {
  42203. beginDragAutoRepeat (100);
  42204. newTransaction();
  42205. if (wasFocused || ! selectAllTextWhenFocused)
  42206. {
  42207. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42208. {
  42209. moveCursorTo (getTextIndexAt (e.x, e.y),
  42210. e.mods.isShiftDown());
  42211. }
  42212. else
  42213. {
  42214. PopupMenu m;
  42215. m.setLookAndFeel (&getLookAndFeel());
  42216. addPopupMenuItems (m, &e);
  42217. menuActive = true;
  42218. const int result = m.show();
  42219. menuActive = false;
  42220. if (result != 0)
  42221. performPopupMenuAction (result);
  42222. }
  42223. }
  42224. }
  42225. void TextEditor::mouseDrag (const MouseEvent& e)
  42226. {
  42227. if (wasFocused || ! selectAllTextWhenFocused)
  42228. {
  42229. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42230. {
  42231. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42232. }
  42233. }
  42234. }
  42235. void TextEditor::mouseUp (const MouseEvent& e)
  42236. {
  42237. newTransaction();
  42238. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42239. if (wasFocused || ! selectAllTextWhenFocused)
  42240. {
  42241. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42242. {
  42243. moveCaret (getTextIndexAt (e.x, e.y));
  42244. }
  42245. }
  42246. wasFocused = true;
  42247. }
  42248. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42249. {
  42250. int tokenEnd = getTextIndexAt (e.x, e.y);
  42251. int tokenStart = tokenEnd;
  42252. if (e.getNumberOfClicks() > 3)
  42253. {
  42254. tokenStart = 0;
  42255. tokenEnd = getTotalNumChars();
  42256. }
  42257. else
  42258. {
  42259. const String t (getText());
  42260. const int totalLength = getTotalNumChars();
  42261. while (tokenEnd < totalLength)
  42262. {
  42263. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42264. ++tokenEnd;
  42265. else
  42266. break;
  42267. }
  42268. tokenStart = tokenEnd;
  42269. while (tokenStart > 0)
  42270. {
  42271. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42272. --tokenStart;
  42273. else
  42274. break;
  42275. }
  42276. if (e.getNumberOfClicks() > 2)
  42277. {
  42278. while (tokenEnd < totalLength)
  42279. {
  42280. if (t [tokenEnd] != '\r' && t [tokenEnd] != '\n')
  42281. ++tokenEnd;
  42282. else
  42283. break;
  42284. }
  42285. while (tokenStart > 0)
  42286. {
  42287. if (t [tokenStart - 1] != '\r' && t [tokenStart - 1] != '\n')
  42288. --tokenStart;
  42289. else
  42290. break;
  42291. }
  42292. }
  42293. }
  42294. moveCursorTo (tokenEnd, false);
  42295. moveCursorTo (tokenStart, true);
  42296. }
  42297. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42298. {
  42299. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42300. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42301. }
  42302. bool TextEditor::keyPressed (const KeyPress& key)
  42303. {
  42304. if (isReadOnly() && key != KeyPress ('c', ModifierKeys::commandModifier, 0))
  42305. return false;
  42306. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42307. if (key.isKeyCode (KeyPress::leftKey)
  42308. || key.isKeyCode (KeyPress::upKey))
  42309. {
  42310. newTransaction();
  42311. int newPos;
  42312. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42313. newPos = indexAtPosition (cursorX, cursorY - 1);
  42314. else if (moveInWholeWordSteps)
  42315. newPos = findWordBreakBefore (getCaretPosition());
  42316. else
  42317. newPos = getCaretPosition() - 1;
  42318. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42319. }
  42320. else if (key.isKeyCode (KeyPress::rightKey)
  42321. || key.isKeyCode (KeyPress::downKey))
  42322. {
  42323. newTransaction();
  42324. int newPos;
  42325. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42326. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42327. else if (moveInWholeWordSteps)
  42328. newPos = findWordBreakAfter (getCaretPosition());
  42329. else
  42330. newPos = getCaretPosition() + 1;
  42331. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42332. }
  42333. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42334. {
  42335. newTransaction();
  42336. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42337. key.getModifiers().isShiftDown());
  42338. }
  42339. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42340. {
  42341. newTransaction();
  42342. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42343. key.getModifiers().isShiftDown());
  42344. }
  42345. else if (key.isKeyCode (KeyPress::homeKey))
  42346. {
  42347. newTransaction();
  42348. if (isMultiLine() && ! moveInWholeWordSteps)
  42349. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42350. key.getModifiers().isShiftDown());
  42351. else
  42352. moveCursorTo (0, key.getModifiers().isShiftDown());
  42353. }
  42354. else if (key.isKeyCode (KeyPress::endKey))
  42355. {
  42356. newTransaction();
  42357. if (isMultiLine() && ! moveInWholeWordSteps)
  42358. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42359. key.getModifiers().isShiftDown());
  42360. else
  42361. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42362. }
  42363. else if (key.isKeyCode (KeyPress::backspaceKey))
  42364. {
  42365. if (moveInWholeWordSteps)
  42366. {
  42367. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42368. }
  42369. else
  42370. {
  42371. if (selection.isEmpty() && selection.getStart() > 0)
  42372. selection.setStart (selection.getEnd() - 1);
  42373. }
  42374. cut();
  42375. }
  42376. else if (key.isKeyCode (KeyPress::deleteKey))
  42377. {
  42378. if (key.getModifiers().isShiftDown())
  42379. copy();
  42380. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42381. selection.setEnd (selection.getStart() + 1);
  42382. cut();
  42383. }
  42384. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0)
  42385. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42386. {
  42387. newTransaction();
  42388. copy();
  42389. }
  42390. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  42391. {
  42392. newTransaction();
  42393. copy();
  42394. cut();
  42395. }
  42396. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0)
  42397. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42398. {
  42399. newTransaction();
  42400. paste();
  42401. }
  42402. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  42403. {
  42404. newTransaction();
  42405. doUndoRedo (false);
  42406. }
  42407. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0))
  42408. {
  42409. newTransaction();
  42410. doUndoRedo (true);
  42411. }
  42412. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  42413. {
  42414. newTransaction();
  42415. moveCursorTo (getTotalNumChars(), false);
  42416. moveCursorTo (0, true);
  42417. }
  42418. else if (key == KeyPress::returnKey)
  42419. {
  42420. newTransaction();
  42421. insertTextAtCaret ("\n");
  42422. }
  42423. else if (key.isKeyCode (KeyPress::escapeKey))
  42424. {
  42425. newTransaction();
  42426. moveCursorTo (getCaretPosition(), false);
  42427. escapePressed();
  42428. }
  42429. else if (key.getTextCharacter() >= ' '
  42430. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42431. {
  42432. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42433. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42434. }
  42435. else
  42436. {
  42437. return false;
  42438. }
  42439. return true;
  42440. }
  42441. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42442. {
  42443. if (! isKeyDown)
  42444. return false;
  42445. #if JUCE_WIN32
  42446. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42447. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42448. #endif
  42449. // (overridden to avoid forwarding key events to the parent)
  42450. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42451. }
  42452. const int baseMenuItemID = 0x7fff0000;
  42453. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42454. {
  42455. const bool writable = ! isReadOnly();
  42456. if (passwordCharacter == 0)
  42457. {
  42458. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42459. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42460. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42461. }
  42462. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42463. m.addSeparator();
  42464. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42465. m.addSeparator();
  42466. if (getUndoManager() != 0)
  42467. {
  42468. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42469. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42470. }
  42471. }
  42472. void TextEditor::performPopupMenuAction (const int menuItemID)
  42473. {
  42474. switch (menuItemID)
  42475. {
  42476. case baseMenuItemID + 1:
  42477. copy();
  42478. cut();
  42479. break;
  42480. case baseMenuItemID + 2:
  42481. copy();
  42482. break;
  42483. case baseMenuItemID + 3:
  42484. paste();
  42485. break;
  42486. case baseMenuItemID + 4:
  42487. cut();
  42488. break;
  42489. case baseMenuItemID + 5:
  42490. moveCursorTo (getTotalNumChars(), false);
  42491. moveCursorTo (0, true);
  42492. break;
  42493. case baseMenuItemID + 6:
  42494. doUndoRedo (false);
  42495. break;
  42496. case baseMenuItemID + 7:
  42497. doUndoRedo (true);
  42498. break;
  42499. default:
  42500. break;
  42501. }
  42502. }
  42503. void TextEditor::focusGained (FocusChangeType)
  42504. {
  42505. newTransaction();
  42506. caretFlashState = true;
  42507. if (selectAllTextWhenFocused)
  42508. {
  42509. moveCursorTo (0, false);
  42510. moveCursorTo (getTotalNumChars(), true);
  42511. }
  42512. repaint();
  42513. if (caretVisible)
  42514. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42515. ComponentPeer* const peer = getPeer();
  42516. if (peer != 0 && ! isReadOnly())
  42517. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42518. }
  42519. void TextEditor::focusLost (FocusChangeType)
  42520. {
  42521. newTransaction();
  42522. wasFocused = false;
  42523. textHolder->stopTimer();
  42524. caretFlashState = false;
  42525. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42526. repaint();
  42527. }
  42528. void TextEditor::resized()
  42529. {
  42530. viewport->setBoundsInset (borderSize);
  42531. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42532. updateTextHolderSize();
  42533. if (! isMultiLine())
  42534. {
  42535. scrollToMakeSureCursorIsVisible();
  42536. }
  42537. else
  42538. {
  42539. updateCaretPosition();
  42540. }
  42541. }
  42542. void TextEditor::handleCommandMessage (const int commandId)
  42543. {
  42544. Component::BailOutChecker checker (this);
  42545. switch (commandId)
  42546. {
  42547. case TextEditorDefs::textChangeMessageId:
  42548. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42549. break;
  42550. case TextEditorDefs::returnKeyMessageId:
  42551. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42552. break;
  42553. case TextEditorDefs::escapeKeyMessageId:
  42554. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42555. break;
  42556. case TextEditorDefs::focusLossMessageId:
  42557. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42558. break;
  42559. default:
  42560. jassertfalse
  42561. break;
  42562. }
  42563. }
  42564. void TextEditor::enablementChanged()
  42565. {
  42566. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42567. : MouseCursor::IBeamCursor);
  42568. repaint();
  42569. }
  42570. UndoManager* TextEditor::getUndoManager() throw()
  42571. {
  42572. return isReadOnly() ? &undoManager : 0;
  42573. }
  42574. void TextEditor::clearInternal (UndoManager* const um)
  42575. {
  42576. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42577. }
  42578. void TextEditor::insert (const String& text,
  42579. const int insertIndex,
  42580. const Font& font,
  42581. const Colour& colour,
  42582. UndoManager* const um,
  42583. const int caretPositionToMoveTo)
  42584. {
  42585. if (text.isNotEmpty())
  42586. {
  42587. if (um != 0)
  42588. {
  42589. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42590. newTransaction();
  42591. um->perform (new TextEditorInsertAction (*this,
  42592. text,
  42593. insertIndex,
  42594. font,
  42595. colour,
  42596. caretPosition,
  42597. caretPositionToMoveTo));
  42598. }
  42599. else
  42600. {
  42601. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42602. // a line gets moved due to word wrap
  42603. int index = 0;
  42604. int nextIndex = 0;
  42605. for (int i = 0; i < sections.size(); ++i)
  42606. {
  42607. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42608. if (insertIndex == index)
  42609. {
  42610. sections.insert (i, new UniformTextSection (text,
  42611. font, colour,
  42612. passwordCharacter));
  42613. break;
  42614. }
  42615. else if (insertIndex > index && insertIndex < nextIndex)
  42616. {
  42617. splitSection (i, insertIndex - index);
  42618. sections.insert (i + 1, new UniformTextSection (text,
  42619. font, colour,
  42620. passwordCharacter));
  42621. break;
  42622. }
  42623. index = nextIndex;
  42624. }
  42625. if (nextIndex == insertIndex)
  42626. sections.add (new UniformTextSection (text,
  42627. font, colour,
  42628. passwordCharacter));
  42629. coalesceSimilarSections();
  42630. totalNumChars = -1;
  42631. valueTextNeedsUpdating = true;
  42632. moveCursorTo (caretPositionToMoveTo, false);
  42633. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42634. }
  42635. }
  42636. }
  42637. void TextEditor::reinsert (const int insertIndex,
  42638. const VoidArray& sectionsToInsert)
  42639. {
  42640. int index = 0;
  42641. int nextIndex = 0;
  42642. for (int i = 0; i < sections.size(); ++i)
  42643. {
  42644. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42645. if (insertIndex == index)
  42646. {
  42647. for (int j = sectionsToInsert.size(); --j >= 0;)
  42648. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42649. break;
  42650. }
  42651. else if (insertIndex > index && insertIndex < nextIndex)
  42652. {
  42653. splitSection (i, insertIndex - index);
  42654. for (int j = sectionsToInsert.size(); --j >= 0;)
  42655. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42656. break;
  42657. }
  42658. index = nextIndex;
  42659. }
  42660. if (nextIndex == insertIndex)
  42661. {
  42662. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42663. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42664. }
  42665. coalesceSimilarSections();
  42666. totalNumChars = -1;
  42667. valueTextNeedsUpdating = true;
  42668. }
  42669. void TextEditor::remove (const Range<int>& range,
  42670. UndoManager* const um,
  42671. const int caretPositionToMoveTo)
  42672. {
  42673. if (! range.isEmpty())
  42674. {
  42675. int index = 0;
  42676. for (int i = 0; i < sections.size(); ++i)
  42677. {
  42678. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  42679. if (range.getStart() > index && range.getStart() < nextIndex)
  42680. {
  42681. splitSection (i, range.getStart() - index);
  42682. --i;
  42683. }
  42684. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42685. {
  42686. splitSection (i, range.getEnd() - index);
  42687. --i;
  42688. }
  42689. else
  42690. {
  42691. index = nextIndex;
  42692. if (index > range.getEnd())
  42693. break;
  42694. }
  42695. }
  42696. index = 0;
  42697. if (um != 0)
  42698. {
  42699. VoidArray removedSections;
  42700. for (int i = 0; i < sections.size(); ++i)
  42701. {
  42702. if (range.getEnd() <= range.getStart())
  42703. break;
  42704. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42705. const int nextIndex = index + section->getTotalLength();
  42706. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42707. removedSections.add (new UniformTextSection (*section));
  42708. index = nextIndex;
  42709. }
  42710. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42711. newTransaction();
  42712. um->perform (new TextEditorRemoveAction (*this,
  42713. range,
  42714. caretPosition,
  42715. caretPositionToMoveTo,
  42716. removedSections));
  42717. }
  42718. else
  42719. {
  42720. Range<int> remainingRange (range);
  42721. for (int i = 0; i < sections.size(); ++i)
  42722. {
  42723. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42724. const int nextIndex = index + section->getTotalLength();
  42725. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42726. {
  42727. sections.remove(i);
  42728. section->clear();
  42729. delete section;
  42730. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42731. if (remainingRange.isEmpty())
  42732. break;
  42733. --i;
  42734. }
  42735. else
  42736. {
  42737. index = nextIndex;
  42738. }
  42739. }
  42740. coalesceSimilarSections();
  42741. totalNumChars = -1;
  42742. valueTextNeedsUpdating = true;
  42743. moveCursorTo (caretPositionToMoveTo, false);
  42744. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42745. }
  42746. }
  42747. }
  42748. const String TextEditor::getText() const
  42749. {
  42750. String t;
  42751. t.preallocateStorage (getTotalNumChars());
  42752. String::Concatenator concatenator (t);
  42753. for (int i = 0; i < sections.size(); ++i)
  42754. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  42755. return t;
  42756. }
  42757. const String TextEditor::getTextInRange (const Range<int>& range) const
  42758. {
  42759. String t;
  42760. if (! range.isEmpty())
  42761. {
  42762. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42763. String::Concatenator concatenator (t);
  42764. int index = 0;
  42765. for (int i = 0; i < sections.size(); ++i)
  42766. {
  42767. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  42768. const int nextIndex = index + s->getTotalLength();
  42769. if (range.getStart() < nextIndex)
  42770. {
  42771. if (range.getEnd() <= index)
  42772. break;
  42773. s->appendSubstring (concatenator, range - index);
  42774. }
  42775. index = nextIndex;
  42776. }
  42777. }
  42778. return t;
  42779. }
  42780. const String TextEditor::getHighlightedText() const
  42781. {
  42782. return getTextInRange (selection);
  42783. }
  42784. int TextEditor::getTotalNumChars() const
  42785. {
  42786. if (totalNumChars < 0)
  42787. {
  42788. totalNumChars = 0;
  42789. for (int i = sections.size(); --i >= 0;)
  42790. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42791. }
  42792. return totalNumChars;
  42793. }
  42794. bool TextEditor::isEmpty() const
  42795. {
  42796. return getTotalNumChars() == 0;
  42797. }
  42798. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42799. {
  42800. const float wordWrapWidth = getWordWrapWidth();
  42801. if (wordWrapWidth > 0 && sections.size() > 0)
  42802. {
  42803. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42804. i.getCharPosition (index, cx, cy, lineHeight);
  42805. }
  42806. else
  42807. {
  42808. cx = cy = 0;
  42809. lineHeight = currentFont.getHeight();
  42810. }
  42811. }
  42812. int TextEditor::indexAtPosition (const float x, const float y)
  42813. {
  42814. const float wordWrapWidth = getWordWrapWidth();
  42815. if (wordWrapWidth > 0)
  42816. {
  42817. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42818. while (i.next())
  42819. {
  42820. if (i.lineY + i.lineHeight > y)
  42821. {
  42822. if (i.lineY > y)
  42823. return jmax (0, i.indexInText - 1);
  42824. if (i.atomX >= x)
  42825. return i.indexInText;
  42826. if (x < i.atomRight)
  42827. return i.xToIndex (x);
  42828. }
  42829. }
  42830. }
  42831. return getTotalNumChars();
  42832. }
  42833. static int getCharacterCategory (const tchar character)
  42834. {
  42835. return CharacterFunctions::isLetterOrDigit (character)
  42836. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42837. }
  42838. int TextEditor::findWordBreakAfter (const int position) const
  42839. {
  42840. const String t (getTextInRange (Range<int> (position, position + 512)));
  42841. const int totalLength = t.length();
  42842. int i = 0;
  42843. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42844. ++i;
  42845. const int type = getCharacterCategory (t[i]);
  42846. while (i < totalLength && type == getCharacterCategory (t[i]))
  42847. ++i;
  42848. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42849. ++i;
  42850. return position + i;
  42851. }
  42852. int TextEditor::findWordBreakBefore (const int position) const
  42853. {
  42854. if (position <= 0)
  42855. return 0;
  42856. const int startOfBuffer = jmax (0, position - 512);
  42857. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42858. int i = position - startOfBuffer;
  42859. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42860. --i;
  42861. if (i > 0)
  42862. {
  42863. const int type = getCharacterCategory (t [i - 1]);
  42864. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42865. --i;
  42866. }
  42867. jassert (startOfBuffer + i >= 0);
  42868. return startOfBuffer + i;
  42869. }
  42870. void TextEditor::splitSection (const int sectionIndex,
  42871. const int charToSplitAt)
  42872. {
  42873. jassert (sections[sectionIndex] != 0);
  42874. sections.insert (sectionIndex + 1,
  42875. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  42876. ->split (charToSplitAt, passwordCharacter));
  42877. }
  42878. void TextEditor::coalesceSimilarSections()
  42879. {
  42880. for (int i = 0; i < sections.size() - 1; ++i)
  42881. {
  42882. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  42883. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  42884. if (s1->font == s2->font
  42885. && s1->colour == s2->colour)
  42886. {
  42887. s1->append (*s2, passwordCharacter);
  42888. sections.remove (i + 1);
  42889. delete s2;
  42890. --i;
  42891. }
  42892. }
  42893. }
  42894. END_JUCE_NAMESPACE
  42895. /*** End of inlined file: juce_TextEditor.cpp ***/
  42896. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42897. BEGIN_JUCE_NAMESPACE
  42898. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  42899. class ToolbarSpacerComp : public ToolbarItemComponent
  42900. {
  42901. public:
  42902. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42903. : ToolbarItemComponent (itemId_, String::empty, false),
  42904. fixedSize (fixedSize_),
  42905. drawBar (drawBar_)
  42906. {
  42907. }
  42908. ~ToolbarSpacerComp()
  42909. {
  42910. }
  42911. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  42912. int& preferredSize, int& minSize, int& maxSize)
  42913. {
  42914. if (fixedSize <= 0)
  42915. {
  42916. preferredSize = toolbarThickness * 2;
  42917. minSize = 4;
  42918. maxSize = 32768;
  42919. }
  42920. else
  42921. {
  42922. maxSize = roundToInt (toolbarThickness * fixedSize);
  42923. minSize = drawBar ? maxSize : jmin (4, maxSize);
  42924. preferredSize = maxSize;
  42925. if (getEditingMode() == editableOnPalette)
  42926. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  42927. }
  42928. return true;
  42929. }
  42930. void paintButtonArea (Graphics&, int, int, bool, bool)
  42931. {
  42932. }
  42933. void contentAreaChanged (const Rectangle<int>&)
  42934. {
  42935. }
  42936. int getResizeOrder() const throw()
  42937. {
  42938. return fixedSize <= 0 ? 0 : 1;
  42939. }
  42940. void paint (Graphics& g)
  42941. {
  42942. const int w = getWidth();
  42943. const int h = getHeight();
  42944. if (drawBar)
  42945. {
  42946. g.setColour (findColour (Toolbar::separatorColourId, true));
  42947. const float thickness = 0.2f;
  42948. if (isToolbarVertical())
  42949. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  42950. else
  42951. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  42952. }
  42953. if (getEditingMode() != normalMode && ! drawBar)
  42954. {
  42955. g.setColour (findColour (Toolbar::separatorColourId, true));
  42956. const int indentX = jmin (2, (w - 3) / 2);
  42957. const int indentY = jmin (2, (h - 3) / 2);
  42958. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  42959. if (fixedSize <= 0)
  42960. {
  42961. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  42962. if (isToolbarVertical())
  42963. {
  42964. x1 = w * 0.5f;
  42965. y1 = h * 0.4f;
  42966. x2 = x1;
  42967. y2 = indentX * 2.0f;
  42968. x3 = x1;
  42969. y3 = h * 0.6f;
  42970. x4 = x1;
  42971. y4 = h - y2;
  42972. hw = w * 0.15f;
  42973. hl = w * 0.2f;
  42974. }
  42975. else
  42976. {
  42977. x1 = w * 0.4f;
  42978. y1 = h * 0.5f;
  42979. x2 = indentX * 2.0f;
  42980. y2 = y1;
  42981. x3 = w * 0.6f;
  42982. y3 = y1;
  42983. x4 = w - x2;
  42984. y4 = y1;
  42985. hw = h * 0.15f;
  42986. hl = h * 0.2f;
  42987. }
  42988. Path p;
  42989. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  42990. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  42991. g.fillPath (p);
  42992. }
  42993. }
  42994. }
  42995. juce_UseDebuggingNewOperator
  42996. private:
  42997. const float fixedSize;
  42998. const bool drawBar;
  42999. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43000. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43001. };
  43002. class MissingItemsComponent : public PopupMenuCustomComponent
  43003. {
  43004. public:
  43005. MissingItemsComponent (Toolbar& owner_, const int height_)
  43006. : PopupMenuCustomComponent (true),
  43007. owner (owner_),
  43008. height (height_)
  43009. {
  43010. for (int i = owner_.items.size(); --i >= 0;)
  43011. {
  43012. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43013. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43014. {
  43015. oldIndexes.insert (0, i);
  43016. addAndMakeVisible (tc, 0);
  43017. }
  43018. }
  43019. layout (400);
  43020. }
  43021. ~MissingItemsComponent()
  43022. {
  43023. // deleting the toolbar while its menu it open??
  43024. jassert (owner.isValidComponent());
  43025. for (int i = 0; i < getNumChildComponents(); ++i)
  43026. {
  43027. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43028. if (tc != 0)
  43029. {
  43030. tc->setVisible (false);
  43031. const int index = oldIndexes.remove (i);
  43032. owner.addChildComponent (tc, index);
  43033. --i;
  43034. }
  43035. }
  43036. owner.resized();
  43037. }
  43038. void layout (const int preferredWidth)
  43039. {
  43040. const int indent = 8;
  43041. int x = indent;
  43042. int y = indent;
  43043. int maxX = 0;
  43044. for (int i = 0; i < getNumChildComponents(); ++i)
  43045. {
  43046. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43047. if (tc != 0)
  43048. {
  43049. int preferredSize = 1, minSize = 1, maxSize = 1;
  43050. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43051. {
  43052. if (x + preferredSize > preferredWidth && x > indent)
  43053. {
  43054. x = indent;
  43055. y += height;
  43056. }
  43057. tc->setBounds (x, y, preferredSize, height);
  43058. x += preferredSize;
  43059. maxX = jmax (maxX, x);
  43060. }
  43061. }
  43062. }
  43063. setSize (maxX + 8, y + height + 8);
  43064. }
  43065. void getIdealSize (int& idealWidth, int& idealHeight)
  43066. {
  43067. idealWidth = getWidth();
  43068. idealHeight = getHeight();
  43069. }
  43070. juce_UseDebuggingNewOperator
  43071. private:
  43072. Toolbar& owner;
  43073. const int height;
  43074. Array <int> oldIndexes;
  43075. MissingItemsComponent (const MissingItemsComponent&);
  43076. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43077. };
  43078. Toolbar::Toolbar()
  43079. : vertical (false),
  43080. isEditingActive (false),
  43081. toolbarStyle (Toolbar::iconsOnly)
  43082. {
  43083. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43084. missingItemsButton->setAlwaysOnTop (true);
  43085. missingItemsButton->addButtonListener (this);
  43086. }
  43087. Toolbar::~Toolbar()
  43088. {
  43089. animator.cancelAllAnimations (true);
  43090. deleteAllChildren();
  43091. }
  43092. void Toolbar::setVertical (const bool shouldBeVertical)
  43093. {
  43094. if (vertical != shouldBeVertical)
  43095. {
  43096. vertical = shouldBeVertical;
  43097. resized();
  43098. }
  43099. }
  43100. void Toolbar::clear()
  43101. {
  43102. for (int i = items.size(); --i >= 0;)
  43103. {
  43104. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43105. items.remove (i);
  43106. delete tc;
  43107. }
  43108. resized();
  43109. }
  43110. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43111. {
  43112. if (itemId == ToolbarItemFactory::separatorBarId)
  43113. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43114. else if (itemId == ToolbarItemFactory::spacerId)
  43115. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43116. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43117. return new ToolbarSpacerComp (itemId, 0, false);
  43118. return factory.createItem (itemId);
  43119. }
  43120. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43121. const int itemId,
  43122. const int insertIndex)
  43123. {
  43124. // An ID can't be zero - this might indicate a mistake somewhere?
  43125. jassert (itemId != 0);
  43126. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43127. if (tc != 0)
  43128. {
  43129. #ifdef JUCE_DEBUG
  43130. Array <int> allowedIds;
  43131. factory.getAllToolbarItemIds (allowedIds);
  43132. // If your factory can create an item for a given ID, it must also return
  43133. // that ID from its getAllToolbarItemIds() method!
  43134. jassert (allowedIds.contains (itemId));
  43135. #endif
  43136. items.insert (insertIndex, tc);
  43137. addAndMakeVisible (tc, insertIndex);
  43138. }
  43139. }
  43140. void Toolbar::addItem (ToolbarItemFactory& factory,
  43141. const int itemId,
  43142. const int insertIndex)
  43143. {
  43144. addItemInternal (factory, itemId, insertIndex);
  43145. resized();
  43146. }
  43147. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43148. {
  43149. Array <int> ids;
  43150. factoryToUse.getDefaultItemSet (ids);
  43151. clear();
  43152. for (int i = 0; i < ids.size(); ++i)
  43153. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43154. resized();
  43155. }
  43156. void Toolbar::removeToolbarItem (const int itemIndex)
  43157. {
  43158. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43159. if (tc != 0)
  43160. {
  43161. items.removeValue (tc);
  43162. delete tc;
  43163. resized();
  43164. }
  43165. }
  43166. int Toolbar::getNumItems() const throw()
  43167. {
  43168. return items.size();
  43169. }
  43170. int Toolbar::getItemId (const int itemIndex) const throw()
  43171. {
  43172. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43173. return tc != 0 ? tc->getItemId() : 0;
  43174. }
  43175. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43176. {
  43177. return items [itemIndex];
  43178. }
  43179. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43180. {
  43181. for (;;)
  43182. {
  43183. index += delta;
  43184. ToolbarItemComponent* const tc = getItemComponent (index);
  43185. if (tc == 0)
  43186. break;
  43187. if (tc->isActive)
  43188. return tc;
  43189. }
  43190. return 0;
  43191. }
  43192. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43193. {
  43194. if (toolbarStyle != newStyle)
  43195. {
  43196. toolbarStyle = newStyle;
  43197. updateAllItemPositions (false);
  43198. }
  43199. }
  43200. const String Toolbar::toString() const
  43201. {
  43202. String s ("TB:");
  43203. for (int i = 0; i < getNumItems(); ++i)
  43204. s << getItemId(i) << ' ';
  43205. return s.trimEnd();
  43206. }
  43207. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43208. const String& savedVersion)
  43209. {
  43210. if (! savedVersion.startsWith ("TB:"))
  43211. return false;
  43212. StringArray tokens;
  43213. tokens.addTokens (savedVersion.substring (3), false);
  43214. clear();
  43215. for (int i = 0; i < tokens.size(); ++i)
  43216. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43217. resized();
  43218. return true;
  43219. }
  43220. void Toolbar::paint (Graphics& g)
  43221. {
  43222. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43223. }
  43224. int Toolbar::getThickness() const throw()
  43225. {
  43226. return vertical ? getWidth() : getHeight();
  43227. }
  43228. int Toolbar::getLength() const throw()
  43229. {
  43230. return vertical ? getHeight() : getWidth();
  43231. }
  43232. void Toolbar::setEditingActive (const bool active)
  43233. {
  43234. if (isEditingActive != active)
  43235. {
  43236. isEditingActive = active;
  43237. updateAllItemPositions (false);
  43238. }
  43239. }
  43240. void Toolbar::resized()
  43241. {
  43242. updateAllItemPositions (false);
  43243. }
  43244. void Toolbar::updateAllItemPositions (const bool animate)
  43245. {
  43246. if (getWidth() > 0 && getHeight() > 0)
  43247. {
  43248. StretchableObjectResizer resizer;
  43249. int i;
  43250. for (i = 0; i < items.size(); ++i)
  43251. {
  43252. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43253. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43254. : ToolbarItemComponent::normalMode);
  43255. tc->setStyle (toolbarStyle);
  43256. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43257. int preferredSize = 1, minSize = 1, maxSize = 1;
  43258. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43259. preferredSize, minSize, maxSize))
  43260. {
  43261. tc->isActive = true;
  43262. resizer.addItem (preferredSize, minSize, maxSize,
  43263. spacer != 0 ? spacer->getResizeOrder() : 2);
  43264. }
  43265. else
  43266. {
  43267. tc->isActive = false;
  43268. tc->setVisible (false);
  43269. }
  43270. }
  43271. resizer.resizeToFit (getLength());
  43272. int totalLength = 0;
  43273. for (i = 0; i < resizer.getNumItems(); ++i)
  43274. totalLength += (int) resizer.getItemSize (i);
  43275. const bool itemsOffTheEnd = totalLength > getLength();
  43276. const int extrasButtonSize = getThickness() / 2;
  43277. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43278. missingItemsButton->setVisible (itemsOffTheEnd);
  43279. missingItemsButton->setEnabled (! isEditingActive);
  43280. if (vertical)
  43281. missingItemsButton->setCentrePosition (getWidth() / 2,
  43282. getHeight() - 4 - extrasButtonSize / 2);
  43283. else
  43284. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43285. getHeight() / 2);
  43286. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43287. : missingItemsButton->getX()) - 4
  43288. : getLength();
  43289. int pos = 0, activeIndex = 0;
  43290. for (i = 0; i < items.size(); ++i)
  43291. {
  43292. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43293. if (tc->isActive)
  43294. {
  43295. const int size = (int) resizer.getItemSize (activeIndex++);
  43296. Rectangle<int> newBounds;
  43297. if (vertical)
  43298. newBounds.setBounds (0, pos, getWidth(), size);
  43299. else
  43300. newBounds.setBounds (pos, 0, size, getHeight());
  43301. if (animate)
  43302. {
  43303. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43304. }
  43305. else
  43306. {
  43307. animator.cancelAnimation (tc, false);
  43308. tc->setBounds (newBounds);
  43309. }
  43310. pos += size;
  43311. tc->setVisible (pos <= maxLength
  43312. && ((! tc->isBeingDragged)
  43313. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43314. }
  43315. }
  43316. }
  43317. }
  43318. void Toolbar::buttonClicked (Button*)
  43319. {
  43320. jassert (missingItemsButton->isShowing());
  43321. if (missingItemsButton->isShowing())
  43322. {
  43323. PopupMenu m;
  43324. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43325. m.showAt (missingItemsButton);
  43326. }
  43327. }
  43328. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43329. Component* /*sourceComponent*/)
  43330. {
  43331. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43332. }
  43333. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43334. {
  43335. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43336. if (tc != 0)
  43337. {
  43338. if (getNumItems() == 0)
  43339. {
  43340. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43341. {
  43342. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43343. if (palette != 0)
  43344. palette->replaceComponent (tc);
  43345. }
  43346. else
  43347. {
  43348. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43349. }
  43350. items.add (tc);
  43351. addChildComponent (tc);
  43352. updateAllItemPositions (false);
  43353. }
  43354. else
  43355. {
  43356. for (int i = getNumItems(); --i >= 0;)
  43357. {
  43358. int currentIndex = getIndexOfChildComponent (tc);
  43359. if (currentIndex < 0)
  43360. {
  43361. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43362. {
  43363. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43364. if (palette != 0)
  43365. palette->replaceComponent (tc);
  43366. }
  43367. else
  43368. {
  43369. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43370. }
  43371. items.add (tc);
  43372. addChildComponent (tc);
  43373. currentIndex = getIndexOfChildComponent (tc);
  43374. updateAllItemPositions (true);
  43375. }
  43376. int newIndex = currentIndex;
  43377. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43378. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43379. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43380. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43381. if (prev != 0)
  43382. {
  43383. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43384. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43385. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43386. {
  43387. newIndex = getIndexOfChildComponent (prev);
  43388. }
  43389. }
  43390. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43391. if (next != 0)
  43392. {
  43393. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43394. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43395. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43396. {
  43397. newIndex = getIndexOfChildComponent (next) + 1;
  43398. }
  43399. }
  43400. if (newIndex != currentIndex)
  43401. {
  43402. items.removeValue (tc);
  43403. removeChildComponent (tc);
  43404. addChildComponent (tc, newIndex);
  43405. items.insert (newIndex, tc);
  43406. updateAllItemPositions (true);
  43407. }
  43408. else
  43409. {
  43410. break;
  43411. }
  43412. }
  43413. }
  43414. }
  43415. }
  43416. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43417. {
  43418. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43419. if (tc != 0)
  43420. {
  43421. if (isParentOf (tc))
  43422. {
  43423. items.removeValue (tc);
  43424. removeChildComponent (tc);
  43425. updateAllItemPositions (true);
  43426. }
  43427. }
  43428. }
  43429. void Toolbar::itemDropped (const String&, Component*, int, int)
  43430. {
  43431. }
  43432. void Toolbar::mouseDown (const MouseEvent& e)
  43433. {
  43434. if (e.mods.isPopupMenu())
  43435. {
  43436. }
  43437. }
  43438. class ToolbarCustomisationDialog : public DialogWindow
  43439. {
  43440. public:
  43441. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43442. Toolbar* const toolbar_,
  43443. const int optionFlags)
  43444. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43445. toolbar (toolbar_)
  43446. {
  43447. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43448. setResizable (true, true);
  43449. setResizeLimits (400, 300, 1500, 1000);
  43450. positionNearBar();
  43451. }
  43452. ~ToolbarCustomisationDialog()
  43453. {
  43454. setContentComponent (0, true);
  43455. }
  43456. void closeButtonPressed()
  43457. {
  43458. setVisible (false);
  43459. }
  43460. bool canModalEventBeSentToComponent (const Component* comp)
  43461. {
  43462. return toolbar->isParentOf (comp);
  43463. }
  43464. void positionNearBar()
  43465. {
  43466. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43467. const int tbx = toolbar->getScreenX();
  43468. const int tby = toolbar->getScreenY();
  43469. const int gap = 8;
  43470. int x, y;
  43471. if (toolbar->isVertical())
  43472. {
  43473. y = tby;
  43474. if (tbx > screenSize.getCentreX())
  43475. x = tbx - getWidth() - gap;
  43476. else
  43477. x = tbx + toolbar->getWidth() + gap;
  43478. }
  43479. else
  43480. {
  43481. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43482. if (tby > screenSize.getCentreY())
  43483. y = tby - getHeight() - gap;
  43484. else
  43485. y = tby + toolbar->getHeight() + gap;
  43486. }
  43487. setTopLeftPosition (x, y);
  43488. }
  43489. private:
  43490. Toolbar* const toolbar;
  43491. class CustomiserPanel : public Component,
  43492. private ComboBoxListener,
  43493. private ButtonListener
  43494. {
  43495. public:
  43496. CustomiserPanel (ToolbarItemFactory& factory_,
  43497. Toolbar* const toolbar_,
  43498. const int optionFlags)
  43499. : factory (factory_),
  43500. toolbar (toolbar_),
  43501. styleBox (0),
  43502. defaultButton (0)
  43503. {
  43504. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43505. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43506. | Toolbar::allowIconsWithTextChoice
  43507. | Toolbar::allowTextOnlyChoice)) != 0)
  43508. {
  43509. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43510. styleBox->setEditableText (false);
  43511. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43512. styleBox->addItem (TRANS("Show icons only"), 1);
  43513. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43514. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43515. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43516. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43517. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43518. styleBox->setSelectedId (1);
  43519. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43520. styleBox->setSelectedId (2);
  43521. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43522. styleBox->setSelectedId (3);
  43523. styleBox->addListener (this);
  43524. }
  43525. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43526. {
  43527. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43528. defaultButton->addButtonListener (this);
  43529. }
  43530. addAndMakeVisible (instructions = new Label (String::empty,
  43531. TRANS ("You can drag the items above and drop them onto a toolbar to add them.\n\nItems on the toolbar can also be dragged around to change their order, or dragged off the edge to delete them.")));
  43532. instructions->setFont (Font (13.0f));
  43533. setSize (500, 300);
  43534. }
  43535. ~CustomiserPanel()
  43536. {
  43537. deleteAllChildren();
  43538. }
  43539. void comboBoxChanged (ComboBox*)
  43540. {
  43541. if (styleBox->getSelectedId() == 1)
  43542. toolbar->setStyle (Toolbar::iconsOnly);
  43543. else if (styleBox->getSelectedId() == 2)
  43544. toolbar->setStyle (Toolbar::iconsWithText);
  43545. else if (styleBox->getSelectedId() == 3)
  43546. toolbar->setStyle (Toolbar::textOnly);
  43547. palette->resized(); // to make it update the styles
  43548. }
  43549. void buttonClicked (Button*)
  43550. {
  43551. toolbar->addDefaultItems (factory);
  43552. }
  43553. void paint (Graphics& g)
  43554. {
  43555. Colour background;
  43556. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43557. if (dw != 0)
  43558. background = dw->getBackgroundColour();
  43559. g.setColour (background.contrasting().withAlpha (0.3f));
  43560. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43561. }
  43562. void resized()
  43563. {
  43564. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43565. if (styleBox != 0)
  43566. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43567. if (defaultButton != 0)
  43568. {
  43569. defaultButton->changeWidthToFitText (22);
  43570. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43571. }
  43572. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43573. }
  43574. private:
  43575. ToolbarItemFactory& factory;
  43576. Toolbar* const toolbar;
  43577. Label* instructions;
  43578. ToolbarItemPalette* palette;
  43579. ComboBox* styleBox;
  43580. TextButton* defaultButton;
  43581. };
  43582. };
  43583. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43584. {
  43585. setEditingActive (true);
  43586. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43587. dw.runModalLoop();
  43588. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43589. setEditingActive (false);
  43590. }
  43591. END_JUCE_NAMESPACE
  43592. /*** End of inlined file: juce_Toolbar.cpp ***/
  43593. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43594. BEGIN_JUCE_NAMESPACE
  43595. ToolbarItemFactory::ToolbarItemFactory()
  43596. {
  43597. }
  43598. ToolbarItemFactory::~ToolbarItemFactory()
  43599. {
  43600. }
  43601. class ItemDragAndDropOverlayComponent : public Component
  43602. {
  43603. public:
  43604. ItemDragAndDropOverlayComponent()
  43605. : isDragging (false)
  43606. {
  43607. setAlwaysOnTop (true);
  43608. setRepaintsOnMouseActivity (true);
  43609. setMouseCursor (MouseCursor::DraggingHandCursor);
  43610. }
  43611. ~ItemDragAndDropOverlayComponent()
  43612. {
  43613. }
  43614. void paint (Graphics& g)
  43615. {
  43616. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43617. if (isMouseOverOrDragging()
  43618. && tc != 0
  43619. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43620. {
  43621. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43622. g.drawRect (0, 0, getWidth(), getHeight(),
  43623. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43624. }
  43625. }
  43626. void mouseDown (const MouseEvent& e)
  43627. {
  43628. isDragging = false;
  43629. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43630. if (tc != 0)
  43631. {
  43632. tc->dragOffsetX = e.x;
  43633. tc->dragOffsetY = e.y;
  43634. }
  43635. }
  43636. void mouseDrag (const MouseEvent& e)
  43637. {
  43638. if (! (isDragging || e.mouseWasClicked()))
  43639. {
  43640. isDragging = true;
  43641. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43642. if (dnd != 0)
  43643. {
  43644. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43645. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43646. if (tc != 0)
  43647. {
  43648. tc->isBeingDragged = true;
  43649. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43650. tc->setVisible (false);
  43651. }
  43652. }
  43653. }
  43654. }
  43655. void mouseUp (const MouseEvent&)
  43656. {
  43657. isDragging = false;
  43658. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43659. if (tc != 0)
  43660. {
  43661. tc->isBeingDragged = false;
  43662. Toolbar* const tb = tc->getToolbar();
  43663. if (tb != 0)
  43664. tb->updateAllItemPositions (true);
  43665. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43666. delete tc;
  43667. }
  43668. }
  43669. void parentSizeChanged()
  43670. {
  43671. setBounds (0, 0, getParentWidth(), getParentHeight());
  43672. }
  43673. juce_UseDebuggingNewOperator
  43674. private:
  43675. bool isDragging;
  43676. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43677. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43678. };
  43679. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43680. const String& labelText,
  43681. const bool isBeingUsedAsAButton_)
  43682. : Button (labelText),
  43683. itemId (itemId_),
  43684. mode (normalMode),
  43685. toolbarStyle (Toolbar::iconsOnly),
  43686. dragOffsetX (0),
  43687. dragOffsetY (0),
  43688. isActive (true),
  43689. isBeingDragged (false),
  43690. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43691. {
  43692. // Your item ID can't be 0!
  43693. jassert (itemId_ != 0);
  43694. }
  43695. ToolbarItemComponent::~ToolbarItemComponent()
  43696. {
  43697. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43698. overlayComp = 0;
  43699. }
  43700. Toolbar* ToolbarItemComponent::getToolbar() const
  43701. {
  43702. return dynamic_cast <Toolbar*> (getParentComponent());
  43703. }
  43704. bool ToolbarItemComponent::isToolbarVertical() const
  43705. {
  43706. const Toolbar* const t = getToolbar();
  43707. return t != 0 && t->isVertical();
  43708. }
  43709. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43710. {
  43711. if (toolbarStyle != newStyle)
  43712. {
  43713. toolbarStyle = newStyle;
  43714. repaint();
  43715. resized();
  43716. }
  43717. }
  43718. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43719. {
  43720. if (isBeingUsedAsAButton)
  43721. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43722. isMouseOver, isMouseDown, *this);
  43723. if (toolbarStyle != Toolbar::iconsOnly)
  43724. {
  43725. const int indent = contentArea.getX();
  43726. int y = indent;
  43727. int h = getHeight() - indent * 2;
  43728. if (toolbarStyle == Toolbar::iconsWithText)
  43729. {
  43730. y = contentArea.getBottom() + indent / 2;
  43731. h -= contentArea.getHeight();
  43732. }
  43733. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43734. getButtonText(), *this);
  43735. }
  43736. if (! contentArea.isEmpty())
  43737. {
  43738. g.saveState();
  43739. g.setOrigin (contentArea.getX(), contentArea.getY());
  43740. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43741. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43742. g.restoreState();
  43743. }
  43744. }
  43745. void ToolbarItemComponent::resized()
  43746. {
  43747. if (toolbarStyle != Toolbar::textOnly)
  43748. {
  43749. const int indent = jmin (proportionOfWidth (0.08f),
  43750. proportionOfHeight (0.08f));
  43751. contentArea = Rectangle<int> (indent, indent,
  43752. getWidth() - indent * 2,
  43753. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43754. : (getHeight() - indent * 2));
  43755. }
  43756. else
  43757. {
  43758. contentArea = Rectangle<int>();
  43759. }
  43760. contentAreaChanged (contentArea);
  43761. }
  43762. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43763. {
  43764. if (mode != newMode)
  43765. {
  43766. mode = newMode;
  43767. repaint();
  43768. if (mode == normalMode)
  43769. {
  43770. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43771. overlayComp = 0;
  43772. }
  43773. else if (overlayComp == 0)
  43774. {
  43775. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43776. overlayComp->parentSizeChanged();
  43777. }
  43778. resized();
  43779. }
  43780. }
  43781. END_JUCE_NAMESPACE
  43782. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43783. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43784. BEGIN_JUCE_NAMESPACE
  43785. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43786. Toolbar* const toolbar_)
  43787. : factory (factory_),
  43788. toolbar (toolbar_)
  43789. {
  43790. Component* const itemHolder = new Component();
  43791. Array <int> allIds;
  43792. factory_.getAllToolbarItemIds (allIds);
  43793. for (int i = 0; i < allIds.size(); ++i)
  43794. {
  43795. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43796. jassert (tc != 0);
  43797. if (tc != 0)
  43798. {
  43799. itemHolder->addAndMakeVisible (tc);
  43800. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43801. }
  43802. }
  43803. viewport = new Viewport();
  43804. viewport->setViewedComponent (itemHolder);
  43805. addAndMakeVisible (viewport);
  43806. }
  43807. ToolbarItemPalette::~ToolbarItemPalette()
  43808. {
  43809. viewport->getViewedComponent()->deleteAllChildren();
  43810. deleteAllChildren();
  43811. }
  43812. void ToolbarItemPalette::resized()
  43813. {
  43814. viewport->setBoundsInset (BorderSize (1));
  43815. Component* const itemHolder = viewport->getViewedComponent();
  43816. const int indent = 8;
  43817. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43818. const int height = toolbar->getThickness();
  43819. int x = indent;
  43820. int y = indent;
  43821. int maxX = 0;
  43822. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43823. {
  43824. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43825. if (tc != 0)
  43826. {
  43827. tc->setStyle (toolbar->getStyle());
  43828. int preferredSize = 1, minSize = 1, maxSize = 1;
  43829. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43830. {
  43831. if (x + preferredSize > preferredWidth && x > indent)
  43832. {
  43833. x = indent;
  43834. y += height;
  43835. }
  43836. tc->setBounds (x, y, preferredSize, height);
  43837. x += preferredSize + 8;
  43838. maxX = jmax (maxX, x);
  43839. }
  43840. }
  43841. }
  43842. itemHolder->setSize (maxX, y + height + 8);
  43843. }
  43844. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43845. {
  43846. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43847. jassert (tc != 0);
  43848. if (tc != 0)
  43849. {
  43850. tc->setBounds (comp->getBounds());
  43851. tc->setStyle (toolbar->getStyle());
  43852. tc->setEditingMode (comp->getEditingMode());
  43853. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43854. }
  43855. }
  43856. END_JUCE_NAMESPACE
  43857. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43858. /*** Start of inlined file: juce_TreeView.cpp ***/
  43859. BEGIN_JUCE_NAMESPACE
  43860. class TreeViewContentComponent : public Component,
  43861. public TooltipClient
  43862. {
  43863. public:
  43864. TreeViewContentComponent (TreeView* const owner_)
  43865. : owner (owner_),
  43866. buttonUnderMouse (0),
  43867. isDragging (false)
  43868. {
  43869. }
  43870. ~TreeViewContentComponent()
  43871. {
  43872. deleteAllChildren();
  43873. }
  43874. void mouseDown (const MouseEvent& e)
  43875. {
  43876. updateButtonUnderMouse (e);
  43877. isDragging = false;
  43878. needSelectionOnMouseUp = false;
  43879. Rectangle<int> pos;
  43880. TreeViewItem* const item = findItemAt (e.y, pos);
  43881. if (item == 0)
  43882. return;
  43883. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43884. // as selection clicks)
  43885. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43886. {
  43887. if (e.x >= pos.getX() - owner->getIndentSize())
  43888. item->setOpen (! item->isOpen());
  43889. // (clicks to the left of an open/close button are ignored)
  43890. }
  43891. else
  43892. {
  43893. // mouse-down inside the body of the item..
  43894. if (! owner->isMultiSelectEnabled())
  43895. item->setSelected (true, true);
  43896. else if (item->isSelected())
  43897. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43898. else
  43899. selectBasedOnModifiers (item, e.mods);
  43900. if (e.x >= pos.getX())
  43901. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43902. }
  43903. }
  43904. void mouseUp (const MouseEvent& e)
  43905. {
  43906. updateButtonUnderMouse (e);
  43907. if (needSelectionOnMouseUp && e.mouseWasClicked())
  43908. {
  43909. Rectangle<int> pos;
  43910. TreeViewItem* const item = findItemAt (e.y, pos);
  43911. if (item != 0)
  43912. selectBasedOnModifiers (item, e.mods);
  43913. }
  43914. }
  43915. void mouseDoubleClick (const MouseEvent& e)
  43916. {
  43917. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  43918. {
  43919. Rectangle<int> pos;
  43920. TreeViewItem* const item = findItemAt (e.y, pos);
  43921. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  43922. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43923. }
  43924. }
  43925. void mouseDrag (const MouseEvent& e)
  43926. {
  43927. if (isEnabled()
  43928. && ! (isDragging || e.mouseWasClicked()
  43929. || e.getDistanceFromDragStart() < 5
  43930. || e.mods.isPopupMenu()))
  43931. {
  43932. isDragging = true;
  43933. Rectangle<int> pos;
  43934. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  43935. if (item != 0 && e.getMouseDownX() >= pos.getX())
  43936. {
  43937. const String dragDescription (item->getDragSourceDescription());
  43938. if (dragDescription.isNotEmpty())
  43939. {
  43940. DragAndDropContainer* const dragContainer
  43941. = DragAndDropContainer::findParentDragContainerFor (this);
  43942. if (dragContainer != 0)
  43943. {
  43944. pos.setSize (pos.getWidth(), item->itemHeight);
  43945. Image* dragImage = Component::createComponentSnapshot (pos, true);
  43946. dragImage->multiplyAllAlphas (0.6f);
  43947. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  43948. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  43949. }
  43950. else
  43951. {
  43952. // to be able to do a drag-and-drop operation, the treeview needs to
  43953. // be inside a component which is also a DragAndDropContainer.
  43954. jassertfalse
  43955. }
  43956. }
  43957. }
  43958. }
  43959. }
  43960. void mouseMove (const MouseEvent& e)
  43961. {
  43962. updateButtonUnderMouse (e);
  43963. }
  43964. void mouseExit (const MouseEvent& e)
  43965. {
  43966. updateButtonUnderMouse (e);
  43967. }
  43968. void paint (Graphics& g);
  43969. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  43970. static bool isMouseDraggingInChildCompOf (Component* const comp)
  43971. {
  43972. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  43973. {
  43974. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  43975. if (source->isDragging())
  43976. {
  43977. Component* const underMouse = source->getComponentUnderMouse();
  43978. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  43979. return true;
  43980. }
  43981. }
  43982. return false;
  43983. }
  43984. void updateComponents()
  43985. {
  43986. const int visibleTop = -getY();
  43987. const int visibleBottom = visibleTop + getParentHeight();
  43988. BigInteger itemsToKeep;
  43989. TreeViewItem* item = owner->rootItem;
  43990. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  43991. while (item != 0 && y < visibleBottom)
  43992. {
  43993. y += item->itemHeight;
  43994. if (y >= visibleTop)
  43995. {
  43996. const int index = rowComponentIds.indexOf (item->uid);
  43997. if (index < 0)
  43998. {
  43999. Component* const comp = item->createItemComponent();
  44000. if (comp != 0)
  44001. {
  44002. addAndMakeVisible (comp);
  44003. itemsToKeep.setBit (rowComponentItems.size());
  44004. rowComponentItems.add (item);
  44005. rowComponentIds.add (item->uid);
  44006. rowComponents.add (comp);
  44007. }
  44008. }
  44009. else
  44010. {
  44011. itemsToKeep.setBit (index);
  44012. }
  44013. }
  44014. item = item->getNextVisibleItem (true);
  44015. }
  44016. for (int i = rowComponentItems.size(); --i >= 0;)
  44017. {
  44018. Component* const comp = rowComponents.getUnchecked(i);
  44019. bool keep = false;
  44020. if (isParentOf (comp))
  44021. {
  44022. if (itemsToKeep[i])
  44023. {
  44024. const TreeViewItem* const item = rowComponentItems.getUnchecked(i);
  44025. Rectangle<int> pos (item->getItemPosition (false));
  44026. pos.setSize (pos.getWidth(), item->itemHeight);
  44027. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44028. {
  44029. keep = true;
  44030. comp->setBounds (pos);
  44031. }
  44032. }
  44033. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44034. {
  44035. keep = true;
  44036. comp->setSize (0, 0);
  44037. }
  44038. }
  44039. if (! keep)
  44040. {
  44041. delete comp;
  44042. rowComponents.remove (i);
  44043. rowComponentIds.remove (i);
  44044. rowComponentItems.remove (i);
  44045. }
  44046. }
  44047. }
  44048. void updateButtonUnderMouse (const MouseEvent& e)
  44049. {
  44050. TreeViewItem* newItem = 0;
  44051. if (owner->openCloseButtonsVisible)
  44052. {
  44053. Rectangle<int> pos;
  44054. TreeViewItem* item = findItemAt (e.y, pos);
  44055. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44056. {
  44057. newItem = item;
  44058. if (! newItem->mightContainSubItems())
  44059. newItem = 0;
  44060. }
  44061. }
  44062. if (buttonUnderMouse != newItem)
  44063. {
  44064. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44065. {
  44066. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44067. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44068. }
  44069. buttonUnderMouse = newItem;
  44070. if (buttonUnderMouse != 0)
  44071. {
  44072. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44073. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44074. }
  44075. }
  44076. }
  44077. bool isMouseOverButton (TreeViewItem* item) const throw()
  44078. {
  44079. return item == buttonUnderMouse;
  44080. }
  44081. void resized()
  44082. {
  44083. owner->itemsChanged();
  44084. }
  44085. const String getTooltip()
  44086. {
  44087. Rectangle<int> pos;
  44088. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44089. if (item != 0)
  44090. return item->getTooltip();
  44091. return owner->getTooltip();
  44092. }
  44093. juce_UseDebuggingNewOperator
  44094. private:
  44095. TreeView* const owner;
  44096. Array <TreeViewItem*> rowComponentItems;
  44097. Array <int> rowComponentIds;
  44098. Array <Component*> rowComponents;
  44099. TreeViewItem* buttonUnderMouse;
  44100. bool isDragging, needSelectionOnMouseUp;
  44101. TreeViewContentComponent (const TreeViewContentComponent&);
  44102. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44103. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44104. {
  44105. TreeViewItem* firstSelected = 0;
  44106. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44107. {
  44108. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44109. jassert (lastSelected != 0);
  44110. int rowStart = firstSelected->getRowNumberInTree();
  44111. int rowEnd = lastSelected->getRowNumberInTree();
  44112. if (rowStart > rowEnd)
  44113. swapVariables (rowStart, rowEnd);
  44114. int ourRow = item->getRowNumberInTree();
  44115. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44116. if (ourRow > otherEnd)
  44117. swapVariables (ourRow, otherEnd);
  44118. for (int i = ourRow; i <= otherEnd; ++i)
  44119. owner->getItemOnRow (i)->setSelected (true, false);
  44120. }
  44121. else
  44122. {
  44123. const bool cmd = modifiers.isCommandDown();
  44124. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44125. }
  44126. }
  44127. bool containsItem (TreeViewItem* const item) const
  44128. {
  44129. for (int i = rowComponentItems.size(); --i >= 0;)
  44130. if (rowComponentItems.getUnchecked(i) == item)
  44131. return true;
  44132. return false;
  44133. }
  44134. };
  44135. class TreeView::TreeViewport : public Viewport
  44136. {
  44137. public:
  44138. TreeViewport() throw() {}
  44139. ~TreeViewport() throw() {}
  44140. void updateComponents()
  44141. {
  44142. TreeViewContentComponent* const tvc = static_cast <TreeViewContentComponent*> (getViewedComponent());
  44143. if (tvc != 0)
  44144. tvc->updateComponents();
  44145. repaint();
  44146. }
  44147. void visibleAreaChanged (int, int, int, int)
  44148. {
  44149. updateComponents();
  44150. }
  44151. juce_UseDebuggingNewOperator
  44152. private:
  44153. TreeViewport (const TreeViewport&);
  44154. TreeViewport& operator= (const TreeViewport&);
  44155. };
  44156. TreeView::TreeView (const String& componentName)
  44157. : Component (componentName),
  44158. rootItem (0),
  44159. dragInsertPointHighlight (0),
  44160. dragTargetGroupHighlight (0),
  44161. indentSize (24),
  44162. defaultOpenness (false),
  44163. needsRecalculating (true),
  44164. rootItemVisible (true),
  44165. multiSelectEnabled (false),
  44166. openCloseButtonsVisible (true)
  44167. {
  44168. addAndMakeVisible (viewport = new TreeViewport());
  44169. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44170. viewport->setWantsKeyboardFocus (false);
  44171. setWantsKeyboardFocus (true);
  44172. }
  44173. TreeView::~TreeView()
  44174. {
  44175. if (rootItem != 0)
  44176. rootItem->setOwnerView (0);
  44177. deleteAllChildren();
  44178. }
  44179. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44180. {
  44181. if (rootItem != newRootItem)
  44182. {
  44183. if (newRootItem != 0)
  44184. {
  44185. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44186. if (newRootItem->ownerView != 0)
  44187. newRootItem->ownerView->setRootItem (0);
  44188. }
  44189. if (rootItem != 0)
  44190. rootItem->setOwnerView (0);
  44191. rootItem = newRootItem;
  44192. if (newRootItem != 0)
  44193. newRootItem->setOwnerView (this);
  44194. needsRecalculating = true;
  44195. handleAsyncUpdate();
  44196. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44197. {
  44198. rootItem->setOpen (false); // force a re-open
  44199. rootItem->setOpen (true);
  44200. }
  44201. }
  44202. }
  44203. void TreeView::deleteRootItem()
  44204. {
  44205. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44206. setRootItem (0);
  44207. }
  44208. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44209. {
  44210. rootItemVisible = shouldBeVisible;
  44211. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44212. {
  44213. rootItem->setOpen (false); // force a re-open
  44214. rootItem->setOpen (true);
  44215. }
  44216. itemsChanged();
  44217. }
  44218. void TreeView::colourChanged()
  44219. {
  44220. setOpaque (findColour (backgroundColourId).isOpaque());
  44221. repaint();
  44222. }
  44223. void TreeView::setIndentSize (const int newIndentSize)
  44224. {
  44225. if (indentSize != newIndentSize)
  44226. {
  44227. indentSize = newIndentSize;
  44228. resized();
  44229. }
  44230. }
  44231. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44232. {
  44233. if (defaultOpenness != isOpenByDefault)
  44234. {
  44235. defaultOpenness = isOpenByDefault;
  44236. itemsChanged();
  44237. }
  44238. }
  44239. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44240. {
  44241. multiSelectEnabled = canMultiSelect;
  44242. }
  44243. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44244. {
  44245. if (openCloseButtonsVisible != shouldBeVisible)
  44246. {
  44247. openCloseButtonsVisible = shouldBeVisible;
  44248. itemsChanged();
  44249. }
  44250. }
  44251. Viewport* TreeView::getViewport() const throw()
  44252. {
  44253. return viewport;
  44254. }
  44255. void TreeView::clearSelectedItems()
  44256. {
  44257. if (rootItem != 0)
  44258. rootItem->deselectAllRecursively();
  44259. }
  44260. int TreeView::getNumSelectedItems() const throw()
  44261. {
  44262. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44263. }
  44264. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44265. {
  44266. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44267. }
  44268. int TreeView::getNumRowsInTree() const
  44269. {
  44270. if (rootItem != 0)
  44271. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44272. return 0;
  44273. }
  44274. TreeViewItem* TreeView::getItemOnRow (int index) const
  44275. {
  44276. if (! rootItemVisible)
  44277. ++index;
  44278. if (rootItem != 0 && index >= 0)
  44279. return rootItem->getItemOnRow (index);
  44280. return 0;
  44281. }
  44282. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44283. {
  44284. TreeViewContentComponent* const tc = static_cast <TreeViewContentComponent*> (viewport->getViewedComponent());
  44285. Rectangle<int> pos;
  44286. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44287. }
  44288. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44289. {
  44290. if (rootItem == 0)
  44291. return 0;
  44292. return rootItem->findItemFromIdentifierString (identifierString);
  44293. }
  44294. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44295. {
  44296. XmlElement* e = 0;
  44297. if (rootItem != 0)
  44298. {
  44299. e = rootItem->getOpennessState();
  44300. if (e != 0 && alsoIncludeScrollPosition)
  44301. e->setAttribute ("scrollPos", viewport->getViewPositionY());
  44302. }
  44303. return e;
  44304. }
  44305. void TreeView::restoreOpennessState (const XmlElement& newState)
  44306. {
  44307. if (rootItem != 0)
  44308. {
  44309. rootItem->restoreOpennessState (newState);
  44310. if (newState.hasAttribute ("scrollPos"))
  44311. viewport->setViewPosition (viewport->getViewPositionX(),
  44312. newState.getIntAttribute ("scrollPos"));
  44313. }
  44314. }
  44315. void TreeView::paint (Graphics& g)
  44316. {
  44317. g.fillAll (findColour (backgroundColourId));
  44318. }
  44319. void TreeView::resized()
  44320. {
  44321. viewport->setBounds (0, 0, getWidth(), getHeight());
  44322. itemsChanged();
  44323. handleAsyncUpdate();
  44324. }
  44325. void TreeView::enablementChanged()
  44326. {
  44327. repaint();
  44328. }
  44329. void TreeView::moveSelectedRow (int delta)
  44330. {
  44331. if (delta == 0)
  44332. return;
  44333. int rowSelected = 0;
  44334. TreeViewItem* const firstSelected = getSelectedItem (0);
  44335. if (firstSelected != 0)
  44336. rowSelected = firstSelected->getRowNumberInTree();
  44337. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44338. for (;;)
  44339. {
  44340. TreeViewItem* item = getItemOnRow (rowSelected);
  44341. if (item != 0)
  44342. {
  44343. if (! item->canBeSelected())
  44344. {
  44345. // if the row we want to highlight doesn't allow it, try skipping
  44346. // to the next item..
  44347. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44348. rowSelected + (delta < 0 ? -1 : 1));
  44349. if (rowSelected != nextRowToTry)
  44350. {
  44351. rowSelected = nextRowToTry;
  44352. continue;
  44353. }
  44354. else
  44355. {
  44356. break;
  44357. }
  44358. }
  44359. item->setSelected (true, true);
  44360. scrollToKeepItemVisible (item);
  44361. }
  44362. break;
  44363. }
  44364. }
  44365. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44366. {
  44367. if (item != 0 && item->ownerView == this)
  44368. {
  44369. handleAsyncUpdate();
  44370. item = item->getDeepestOpenParentItem();
  44371. int y = item->y;
  44372. int viewTop = viewport->getViewPositionY();
  44373. if (y < viewTop)
  44374. {
  44375. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44376. }
  44377. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44378. {
  44379. viewport->setViewPosition (viewport->getViewPositionX(),
  44380. (y + item->itemHeight) - viewport->getViewHeight());
  44381. }
  44382. }
  44383. }
  44384. bool TreeView::keyPressed (const KeyPress& key)
  44385. {
  44386. if (key.isKeyCode (KeyPress::upKey))
  44387. {
  44388. moveSelectedRow (-1);
  44389. }
  44390. else if (key.isKeyCode (KeyPress::downKey))
  44391. {
  44392. moveSelectedRow (1);
  44393. }
  44394. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44395. {
  44396. if (rootItem != 0)
  44397. {
  44398. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44399. if (key.isKeyCode (KeyPress::pageUpKey))
  44400. rowsOnScreen = -rowsOnScreen;
  44401. moveSelectedRow (rowsOnScreen);
  44402. }
  44403. }
  44404. else if (key.isKeyCode (KeyPress::homeKey))
  44405. {
  44406. moveSelectedRow (-0x3fffffff);
  44407. }
  44408. else if (key.isKeyCode (KeyPress::endKey))
  44409. {
  44410. moveSelectedRow (0x3fffffff);
  44411. }
  44412. else if (key.isKeyCode (KeyPress::returnKey))
  44413. {
  44414. TreeViewItem* const firstSelected = getSelectedItem (0);
  44415. if (firstSelected != 0)
  44416. firstSelected->setOpen (! firstSelected->isOpen());
  44417. }
  44418. else if (key.isKeyCode (KeyPress::leftKey))
  44419. {
  44420. TreeViewItem* const firstSelected = getSelectedItem (0);
  44421. if (firstSelected != 0)
  44422. {
  44423. if (firstSelected->isOpen())
  44424. {
  44425. firstSelected->setOpen (false);
  44426. }
  44427. else
  44428. {
  44429. TreeViewItem* parent = firstSelected->parentItem;
  44430. if ((! rootItemVisible) && parent == rootItem)
  44431. parent = 0;
  44432. if (parent != 0)
  44433. {
  44434. parent->setSelected (true, true);
  44435. scrollToKeepItemVisible (parent);
  44436. }
  44437. }
  44438. }
  44439. }
  44440. else if (key.isKeyCode (KeyPress::rightKey))
  44441. {
  44442. TreeViewItem* const firstSelected = getSelectedItem (0);
  44443. if (firstSelected != 0)
  44444. {
  44445. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44446. moveSelectedRow (1);
  44447. else
  44448. firstSelected->setOpen (true);
  44449. }
  44450. }
  44451. else
  44452. {
  44453. return false;
  44454. }
  44455. return true;
  44456. }
  44457. void TreeView::itemsChanged() throw()
  44458. {
  44459. needsRecalculating = true;
  44460. repaint();
  44461. triggerAsyncUpdate();
  44462. }
  44463. void TreeView::handleAsyncUpdate()
  44464. {
  44465. if (needsRecalculating)
  44466. {
  44467. needsRecalculating = false;
  44468. const ScopedLock sl (nodeAlterationLock);
  44469. if (rootItem != 0)
  44470. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44471. viewport->updateComponents();
  44472. if (rootItem != 0)
  44473. {
  44474. viewport->getViewedComponent()
  44475. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44476. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44477. }
  44478. else
  44479. {
  44480. viewport->getViewedComponent()->setSize (0, 0);
  44481. }
  44482. }
  44483. }
  44484. class TreeView::InsertPointHighlight : public Component
  44485. {
  44486. public:
  44487. InsertPointHighlight()
  44488. : lastItem (0)
  44489. {
  44490. setSize (100, 12);
  44491. setAlwaysOnTop (true);
  44492. setInterceptsMouseClicks (false, false);
  44493. }
  44494. ~InsertPointHighlight() {}
  44495. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44496. {
  44497. lastItem = item;
  44498. lastIndex = insertIndex;
  44499. const int offset = getHeight() / 2;
  44500. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44501. }
  44502. void paint (Graphics& g)
  44503. {
  44504. Path p;
  44505. const float h = (float) getHeight();
  44506. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44507. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44508. p.lineTo ((float) getWidth(), h / 2.0f);
  44509. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44510. g.strokePath (p, PathStrokeType (2.0f));
  44511. }
  44512. TreeViewItem* lastItem;
  44513. int lastIndex;
  44514. private:
  44515. InsertPointHighlight (const InsertPointHighlight&);
  44516. InsertPointHighlight& operator= (const InsertPointHighlight&);
  44517. };
  44518. class TreeView::TargetGroupHighlight : public Component
  44519. {
  44520. public:
  44521. TargetGroupHighlight()
  44522. {
  44523. setAlwaysOnTop (true);
  44524. setInterceptsMouseClicks (false, false);
  44525. }
  44526. ~TargetGroupHighlight() {}
  44527. void setTargetPosition (TreeViewItem* const item) throw()
  44528. {
  44529. Rectangle<int> r (item->getItemPosition (true));
  44530. r.setHeight (item->getItemHeight());
  44531. setBounds (r);
  44532. }
  44533. void paint (Graphics& g)
  44534. {
  44535. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44536. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44537. }
  44538. private:
  44539. TargetGroupHighlight (const TargetGroupHighlight&);
  44540. TargetGroupHighlight& operator= (const TargetGroupHighlight&);
  44541. };
  44542. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44543. {
  44544. beginDragAutoRepeat (1000 / 30);
  44545. if (dragInsertPointHighlight == 0)
  44546. {
  44547. addAndMakeVisible (dragInsertPointHighlight = new InsertPointHighlight());
  44548. addAndMakeVisible (dragTargetGroupHighlight = new TargetGroupHighlight());
  44549. }
  44550. dragInsertPointHighlight->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44551. dragTargetGroupHighlight->setTargetPosition (item);
  44552. }
  44553. void TreeView::hideDragHighlight() throw()
  44554. {
  44555. deleteAndZero (dragInsertPointHighlight);
  44556. deleteAndZero (dragTargetGroupHighlight);
  44557. }
  44558. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44559. const StringArray& files, const String& sourceDescription,
  44560. Component* sourceComponent) const throw()
  44561. {
  44562. insertIndex = 0;
  44563. TreeViewItem* item = getItemAt (y);
  44564. if (item == 0)
  44565. return 0;
  44566. Rectangle<int> itemPos (item->getItemPosition (true));
  44567. insertIndex = item->getIndexInParent();
  44568. const int oldY = y;
  44569. y = itemPos.getY();
  44570. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44571. {
  44572. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44573. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44574. {
  44575. // Check if we're trying to drag into an empty group item..
  44576. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44577. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44578. {
  44579. insertIndex = 0;
  44580. x = itemPos.getX() + getIndentSize();
  44581. y = itemPos.getBottom();
  44582. return item;
  44583. }
  44584. }
  44585. }
  44586. if (oldY > itemPos.getCentreY())
  44587. {
  44588. y += item->getItemHeight();
  44589. while (item->isLastOfSiblings() && item->parentItem != 0
  44590. && item->parentItem->parentItem != 0)
  44591. {
  44592. if (x > itemPos.getX())
  44593. break;
  44594. item = item->parentItem;
  44595. itemPos = item->getItemPosition (true);
  44596. insertIndex = item->getIndexInParent();
  44597. }
  44598. ++insertIndex;
  44599. }
  44600. x = itemPos.getX();
  44601. return item->parentItem;
  44602. }
  44603. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44604. {
  44605. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44606. int insertIndex;
  44607. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44608. if (item != 0)
  44609. {
  44610. if (scrolled || dragInsertPointHighlight == 0
  44611. || dragInsertPointHighlight->lastItem != item
  44612. || dragInsertPointHighlight->lastIndex != insertIndex)
  44613. {
  44614. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44615. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44616. showDragHighlight (item, insertIndex, x, y);
  44617. else
  44618. hideDragHighlight();
  44619. }
  44620. }
  44621. else
  44622. {
  44623. hideDragHighlight();
  44624. }
  44625. }
  44626. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44627. {
  44628. hideDragHighlight();
  44629. int insertIndex;
  44630. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44631. if (item != 0)
  44632. {
  44633. if (files.size() > 0)
  44634. {
  44635. if (item->isInterestedInFileDrag (files))
  44636. item->filesDropped (files, insertIndex);
  44637. }
  44638. else
  44639. {
  44640. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44641. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44642. }
  44643. }
  44644. }
  44645. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44646. {
  44647. return true;
  44648. }
  44649. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44650. {
  44651. fileDragMove (files, x, y);
  44652. }
  44653. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44654. {
  44655. handleDrag (files, String::empty, 0, x, y);
  44656. }
  44657. void TreeView::fileDragExit (const StringArray&)
  44658. {
  44659. hideDragHighlight();
  44660. }
  44661. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44662. {
  44663. handleDrop (files, String::empty, 0, x, y);
  44664. }
  44665. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44666. {
  44667. return true;
  44668. }
  44669. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44670. {
  44671. itemDragMove (sourceDescription, sourceComponent, x, y);
  44672. }
  44673. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44674. {
  44675. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44676. }
  44677. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44678. {
  44679. hideDragHighlight();
  44680. }
  44681. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44682. {
  44683. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44684. }
  44685. void TreeViewContentComponent::paint (Graphics& g)
  44686. {
  44687. if (owner->rootItem != 0)
  44688. {
  44689. owner->handleAsyncUpdate();
  44690. if (! owner->rootItemVisible)
  44691. g.setOrigin (0, -owner->rootItem->itemHeight);
  44692. owner->rootItem->paintRecursively (g, getWidth());
  44693. }
  44694. }
  44695. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44696. {
  44697. if (owner->rootItem != 0)
  44698. {
  44699. owner->handleAsyncUpdate();
  44700. if (! owner->rootItemVisible)
  44701. y += owner->rootItem->itemHeight;
  44702. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44703. if (ti != 0)
  44704. itemPosition = ti->getItemPosition (false);
  44705. return ti;
  44706. }
  44707. return 0;
  44708. }
  44709. enum TreeViewOpenness
  44710. {
  44711. opennessDefault = 0,
  44712. opennessClosed = 1,
  44713. opennessOpen = 2
  44714. };
  44715. TreeViewItem::TreeViewItem()
  44716. : ownerView (0),
  44717. parentItem (0),
  44718. y (0),
  44719. itemHeight (0),
  44720. totalHeight (0),
  44721. selected (false),
  44722. redrawNeeded (true),
  44723. drawLinesInside (true),
  44724. drawsInLeftMargin (false),
  44725. openness (opennessDefault)
  44726. {
  44727. static int nextUID = 0;
  44728. uid = nextUID++;
  44729. }
  44730. TreeViewItem::~TreeViewItem()
  44731. {
  44732. }
  44733. const String TreeViewItem::getUniqueName() const
  44734. {
  44735. return String::empty;
  44736. }
  44737. void TreeViewItem::itemOpennessChanged (bool)
  44738. {
  44739. }
  44740. int TreeViewItem::getNumSubItems() const throw()
  44741. {
  44742. return subItems.size();
  44743. }
  44744. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44745. {
  44746. return subItems [index];
  44747. }
  44748. void TreeViewItem::clearSubItems()
  44749. {
  44750. if (subItems.size() > 0)
  44751. {
  44752. if (ownerView != 0)
  44753. {
  44754. const ScopedLock sl (ownerView->nodeAlterationLock);
  44755. subItems.clear();
  44756. treeHasChanged();
  44757. }
  44758. else
  44759. {
  44760. subItems.clear();
  44761. }
  44762. }
  44763. }
  44764. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44765. {
  44766. if (newItem != 0)
  44767. {
  44768. newItem->parentItem = this;
  44769. newItem->setOwnerView (ownerView);
  44770. newItem->y = 0;
  44771. newItem->itemHeight = newItem->getItemHeight();
  44772. newItem->totalHeight = 0;
  44773. newItem->itemWidth = newItem->getItemWidth();
  44774. newItem->totalWidth = 0;
  44775. if (ownerView != 0)
  44776. {
  44777. const ScopedLock sl (ownerView->nodeAlterationLock);
  44778. subItems.insert (insertPosition, newItem);
  44779. treeHasChanged();
  44780. if (newItem->isOpen())
  44781. newItem->itemOpennessChanged (true);
  44782. }
  44783. else
  44784. {
  44785. subItems.insert (insertPosition, newItem);
  44786. if (newItem->isOpen())
  44787. newItem->itemOpennessChanged (true);
  44788. }
  44789. }
  44790. }
  44791. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44792. {
  44793. if (ownerView != 0)
  44794. {
  44795. const ScopedLock sl (ownerView->nodeAlterationLock);
  44796. if (((unsigned int) index) < (unsigned int) subItems.size())
  44797. {
  44798. subItems.remove (index, deleteItem);
  44799. treeHasChanged();
  44800. }
  44801. }
  44802. else
  44803. {
  44804. subItems.remove (index, deleteItem);
  44805. }
  44806. }
  44807. bool TreeViewItem::isOpen() const throw()
  44808. {
  44809. if (openness == opennessDefault)
  44810. return ownerView != 0 && ownerView->defaultOpenness;
  44811. else
  44812. return openness == opennessOpen;
  44813. }
  44814. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44815. {
  44816. if (isOpen() != shouldBeOpen)
  44817. {
  44818. openness = shouldBeOpen ? opennessOpen
  44819. : opennessClosed;
  44820. treeHasChanged();
  44821. itemOpennessChanged (isOpen());
  44822. }
  44823. }
  44824. bool TreeViewItem::isSelected() const throw()
  44825. {
  44826. return selected;
  44827. }
  44828. void TreeViewItem::deselectAllRecursively()
  44829. {
  44830. setSelected (false, false);
  44831. for (int i = 0; i < subItems.size(); ++i)
  44832. subItems.getUnchecked(i)->deselectAllRecursively();
  44833. }
  44834. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44835. const bool deselectOtherItemsFirst)
  44836. {
  44837. if (shouldBeSelected && ! canBeSelected())
  44838. return;
  44839. if (deselectOtherItemsFirst)
  44840. getTopLevelItem()->deselectAllRecursively();
  44841. if (shouldBeSelected != selected)
  44842. {
  44843. selected = shouldBeSelected;
  44844. if (ownerView != 0)
  44845. ownerView->repaint();
  44846. itemSelectionChanged (shouldBeSelected);
  44847. }
  44848. }
  44849. void TreeViewItem::paintItem (Graphics&, int, int)
  44850. {
  44851. }
  44852. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44853. {
  44854. ownerView->getLookAndFeel()
  44855. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44856. }
  44857. void TreeViewItem::itemClicked (const MouseEvent&)
  44858. {
  44859. }
  44860. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44861. {
  44862. if (mightContainSubItems())
  44863. setOpen (! isOpen());
  44864. }
  44865. void TreeViewItem::itemSelectionChanged (bool)
  44866. {
  44867. }
  44868. const String TreeViewItem::getTooltip()
  44869. {
  44870. return String::empty;
  44871. }
  44872. const String TreeViewItem::getDragSourceDescription()
  44873. {
  44874. return String::empty;
  44875. }
  44876. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44877. {
  44878. return false;
  44879. }
  44880. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44881. {
  44882. }
  44883. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44884. {
  44885. return false;
  44886. }
  44887. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44888. {
  44889. }
  44890. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44891. {
  44892. const int indentX = getIndentX();
  44893. int width = itemWidth;
  44894. if (ownerView != 0 && width < 0)
  44895. width = ownerView->viewport->getViewWidth() - indentX;
  44896. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44897. if (relativeToTreeViewTopLeft)
  44898. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44899. r.getY() - ownerView->viewport->getViewPositionY());
  44900. return r;
  44901. }
  44902. void TreeViewItem::treeHasChanged() const throw()
  44903. {
  44904. if (ownerView != 0)
  44905. ownerView->itemsChanged();
  44906. }
  44907. void TreeViewItem::repaintItem() const
  44908. {
  44909. if (ownerView != 0 && areAllParentsOpen())
  44910. {
  44911. const Rectangle<int> r (getItemPosition (true));
  44912. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  44913. }
  44914. }
  44915. bool TreeViewItem::areAllParentsOpen() const throw()
  44916. {
  44917. return parentItem == 0
  44918. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  44919. }
  44920. void TreeViewItem::updatePositions (int newY)
  44921. {
  44922. y = newY;
  44923. itemHeight = getItemHeight();
  44924. totalHeight = itemHeight;
  44925. itemWidth = getItemWidth();
  44926. totalWidth = jmax (itemWidth, 0) + getIndentX();
  44927. if (isOpen())
  44928. {
  44929. newY += totalHeight;
  44930. for (int i = 0; i < subItems.size(); ++i)
  44931. {
  44932. TreeViewItem* const ti = subItems.getUnchecked(i);
  44933. ti->updatePositions (newY);
  44934. newY += ti->totalHeight;
  44935. totalHeight += ti->totalHeight;
  44936. totalWidth = jmax (totalWidth, ti->totalWidth);
  44937. }
  44938. }
  44939. }
  44940. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  44941. {
  44942. TreeViewItem* result = this;
  44943. TreeViewItem* item = this;
  44944. while (item->parentItem != 0)
  44945. {
  44946. item = item->parentItem;
  44947. if (! item->isOpen())
  44948. result = item;
  44949. }
  44950. return result;
  44951. }
  44952. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  44953. {
  44954. ownerView = newOwner;
  44955. for (int i = subItems.size(); --i >= 0;)
  44956. subItems.getUnchecked(i)->setOwnerView (newOwner);
  44957. }
  44958. int TreeViewItem::getIndentX() const throw()
  44959. {
  44960. const int indentWidth = ownerView->getIndentSize();
  44961. int x = ownerView->rootItemVisible ? indentWidth : 0;
  44962. if (! ownerView->openCloseButtonsVisible)
  44963. x -= indentWidth;
  44964. TreeViewItem* p = parentItem;
  44965. while (p != 0)
  44966. {
  44967. x += indentWidth;
  44968. p = p->parentItem;
  44969. }
  44970. return x;
  44971. }
  44972. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  44973. {
  44974. drawsInLeftMargin = canDrawInLeftMargin;
  44975. }
  44976. void TreeViewItem::paintRecursively (Graphics& g, int width)
  44977. {
  44978. jassert (ownerView != 0);
  44979. if (ownerView == 0)
  44980. return;
  44981. const int indent = getIndentX();
  44982. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  44983. g.setColour (ownerView->findColour (TreeView::linesColourId));
  44984. const float halfH = itemHeight * 0.5f;
  44985. int depth = 0;
  44986. TreeViewItem* p = parentItem;
  44987. while (p != 0)
  44988. {
  44989. ++depth;
  44990. p = p->parentItem;
  44991. }
  44992. if (! ownerView->rootItemVisible)
  44993. --depth;
  44994. const int indentWidth = ownerView->getIndentSize();
  44995. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  44996. {
  44997. float x = (depth + 0.5f) * indentWidth;
  44998. if (depth >= 0)
  44999. {
  45000. if (parentItem != 0 && parentItem->drawLinesInside)
  45001. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45002. if ((parentItem != 0 && parentItem->drawLinesInside)
  45003. || (parentItem == 0 && drawLinesInside))
  45004. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45005. }
  45006. p = parentItem;
  45007. int d = depth;
  45008. while (p != 0 && --d >= 0)
  45009. {
  45010. x -= (float) indentWidth;
  45011. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45012. && ! p->isLastOfSiblings())
  45013. {
  45014. g.drawLine (x, 0, x, (float) itemHeight);
  45015. }
  45016. p = p->parentItem;
  45017. }
  45018. if (mightContainSubItems())
  45019. {
  45020. g.saveState();
  45021. g.setOrigin (depth * indentWidth, 0);
  45022. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45023. paintOpenCloseButton (g, indentWidth, itemHeight,
  45024. static_cast <TreeViewContentComponent*> (ownerView->viewport->getViewedComponent())
  45025. ->isMouseOverButton (this));
  45026. g.restoreState();
  45027. }
  45028. }
  45029. {
  45030. g.saveState();
  45031. g.setOrigin (indent, 0);
  45032. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45033. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45034. paintItem (g, itemW, itemHeight);
  45035. g.restoreState();
  45036. }
  45037. if (isOpen())
  45038. {
  45039. const Rectangle<int> clip (g.getClipBounds());
  45040. for (int i = 0; i < subItems.size(); ++i)
  45041. {
  45042. TreeViewItem* const ti = subItems.getUnchecked(i);
  45043. const int relY = ti->y - y;
  45044. if (relY >= clip.getBottom())
  45045. break;
  45046. if (relY + ti->totalHeight >= clip.getY())
  45047. {
  45048. g.saveState();
  45049. g.setOrigin (0, relY);
  45050. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45051. ti->paintRecursively (g, width);
  45052. g.restoreState();
  45053. }
  45054. }
  45055. }
  45056. }
  45057. bool TreeViewItem::isLastOfSiblings() const throw()
  45058. {
  45059. return parentItem == 0
  45060. || parentItem->subItems.getLast() == this;
  45061. }
  45062. int TreeViewItem::getIndexInParent() const throw()
  45063. {
  45064. if (parentItem == 0)
  45065. return 0;
  45066. return parentItem->subItems.indexOf (this);
  45067. }
  45068. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45069. {
  45070. return (parentItem == 0) ? this
  45071. : parentItem->getTopLevelItem();
  45072. }
  45073. int TreeViewItem::getNumRows() const throw()
  45074. {
  45075. int num = 1;
  45076. if (isOpen())
  45077. {
  45078. for (int i = subItems.size(); --i >= 0;)
  45079. num += subItems.getUnchecked(i)->getNumRows();
  45080. }
  45081. return num;
  45082. }
  45083. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45084. {
  45085. if (index == 0)
  45086. return this;
  45087. if (index > 0 && isOpen())
  45088. {
  45089. --index;
  45090. for (int i = 0; i < subItems.size(); ++i)
  45091. {
  45092. TreeViewItem* const item = subItems.getUnchecked(i);
  45093. if (index == 0)
  45094. return item;
  45095. const int numRows = item->getNumRows();
  45096. if (numRows > index)
  45097. return item->getItemOnRow (index);
  45098. index -= numRows;
  45099. }
  45100. }
  45101. return 0;
  45102. }
  45103. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45104. {
  45105. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45106. {
  45107. const int h = itemHeight;
  45108. if (targetY < h)
  45109. return this;
  45110. if (isOpen())
  45111. {
  45112. targetY -= h;
  45113. for (int i = 0; i < subItems.size(); ++i)
  45114. {
  45115. TreeViewItem* const ti = subItems.getUnchecked(i);
  45116. if (targetY < ti->totalHeight)
  45117. return ti->findItemRecursively (targetY);
  45118. targetY -= ti->totalHeight;
  45119. }
  45120. }
  45121. }
  45122. return 0;
  45123. }
  45124. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45125. {
  45126. int total = 0;
  45127. if (isSelected())
  45128. ++total;
  45129. for (int i = subItems.size(); --i >= 0;)
  45130. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45131. return total;
  45132. }
  45133. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45134. {
  45135. if (isSelected())
  45136. {
  45137. if (index == 0)
  45138. return this;
  45139. --index;
  45140. }
  45141. if (index >= 0)
  45142. {
  45143. for (int i = 0; i < subItems.size(); ++i)
  45144. {
  45145. TreeViewItem* const item = subItems.getUnchecked(i);
  45146. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45147. if (found != 0)
  45148. return found;
  45149. index -= item->countSelectedItemsRecursively();
  45150. }
  45151. }
  45152. return 0;
  45153. }
  45154. int TreeViewItem::getRowNumberInTree() const throw()
  45155. {
  45156. if (parentItem != 0 && ownerView != 0)
  45157. {
  45158. int n = 1 + parentItem->getRowNumberInTree();
  45159. int ourIndex = parentItem->subItems.indexOf (this);
  45160. jassert (ourIndex >= 0);
  45161. while (--ourIndex >= 0)
  45162. n += parentItem->subItems [ourIndex]->getNumRows();
  45163. if (parentItem->parentItem == 0
  45164. && ! ownerView->rootItemVisible)
  45165. --n;
  45166. return n;
  45167. }
  45168. else
  45169. {
  45170. return 0;
  45171. }
  45172. }
  45173. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45174. {
  45175. drawLinesInside = drawLines;
  45176. }
  45177. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45178. {
  45179. if (recurse && isOpen() && subItems.size() > 0)
  45180. return subItems [0];
  45181. if (parentItem != 0)
  45182. {
  45183. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45184. if (nextIndex >= parentItem->subItems.size())
  45185. return parentItem->getNextVisibleItem (false);
  45186. return parentItem->subItems [nextIndex];
  45187. }
  45188. return 0;
  45189. }
  45190. const String TreeViewItem::getItemIdentifierString() const
  45191. {
  45192. String s;
  45193. if (parentItem != 0)
  45194. s = parentItem->getItemIdentifierString();
  45195. return s + "/" + getUniqueName().replaceCharacter ('/', '\\');
  45196. }
  45197. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45198. {
  45199. const String uid (getUniqueName());
  45200. if (uid == identifierString)
  45201. return this;
  45202. if (identifierString.startsWith (uid + "/"))
  45203. {
  45204. const String remainingPath (identifierString.substring (uid.length() + 1));
  45205. bool wasOpen = isOpen();
  45206. setOpen (true);
  45207. for (int i = subItems.size(); --i >= 0;)
  45208. {
  45209. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45210. if (item != 0)
  45211. return item;
  45212. }
  45213. setOpen (wasOpen);
  45214. }
  45215. return 0;
  45216. }
  45217. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45218. {
  45219. if (e.hasTagName ("CLOSED"))
  45220. {
  45221. setOpen (false);
  45222. }
  45223. else if (e.hasTagName ("OPEN"))
  45224. {
  45225. setOpen (true);
  45226. forEachXmlChildElement (e, n)
  45227. {
  45228. const String id (n->getStringAttribute ("id"));
  45229. for (int i = 0; i < subItems.size(); ++i)
  45230. {
  45231. TreeViewItem* const ti = subItems.getUnchecked(i);
  45232. if (ti->getUniqueName() == id)
  45233. {
  45234. ti->restoreOpennessState (*n);
  45235. break;
  45236. }
  45237. }
  45238. }
  45239. }
  45240. }
  45241. XmlElement* TreeViewItem::getOpennessState() const throw()
  45242. {
  45243. const String name (getUniqueName());
  45244. if (name.isNotEmpty())
  45245. {
  45246. XmlElement* e;
  45247. if (isOpen())
  45248. {
  45249. e = new XmlElement ("OPEN");
  45250. for (int i = 0; i < subItems.size(); ++i)
  45251. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45252. }
  45253. else
  45254. {
  45255. e = new XmlElement ("CLOSED");
  45256. }
  45257. e->setAttribute ("id", name);
  45258. return e;
  45259. }
  45260. else
  45261. {
  45262. // trying to save the openness for an element that has no name - this won't
  45263. // work because it needs the names to identify what to open.
  45264. jassertfalse
  45265. }
  45266. return 0;
  45267. }
  45268. END_JUCE_NAMESPACE
  45269. /*** End of inlined file: juce_TreeView.cpp ***/
  45270. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45271. BEGIN_JUCE_NAMESPACE
  45272. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45273. : fileList (listToShow)
  45274. {
  45275. }
  45276. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45277. {
  45278. }
  45279. FileBrowserListener::~FileBrowserListener()
  45280. {
  45281. }
  45282. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener)
  45283. {
  45284. listeners.add (listener);
  45285. }
  45286. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener)
  45287. {
  45288. listeners.remove (listener);
  45289. }
  45290. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45291. {
  45292. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45293. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45294. }
  45295. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45296. {
  45297. if (fileList.getDirectory().exists())
  45298. {
  45299. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45300. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45301. }
  45302. }
  45303. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45304. {
  45305. if (fileList.getDirectory().exists())
  45306. {
  45307. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45308. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45309. }
  45310. }
  45311. END_JUCE_NAMESPACE
  45312. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45313. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45314. BEGIN_JUCE_NAMESPACE
  45315. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45316. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45317. Time* creationTime, bool* isReadOnly);
  45318. bool juce_findFileNext (void* handle, String& resultFile,
  45319. bool* isDirectory, bool* isHidden, int64* fileSize,
  45320. Time* modTime, Time* creationTime, bool* isReadOnly);
  45321. void juce_findFileClose (void* handle);
  45322. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45323. TimeSliceThread& thread_)
  45324. : fileFilter (fileFilter_),
  45325. thread (thread_),
  45326. includeDirectories (false),
  45327. includeFiles (false),
  45328. ignoreHiddenFiles (true),
  45329. fileFindHandle (0),
  45330. shouldStop (true)
  45331. {
  45332. }
  45333. DirectoryContentsList::~DirectoryContentsList()
  45334. {
  45335. clear();
  45336. }
  45337. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45338. {
  45339. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45340. }
  45341. const File& DirectoryContentsList::getDirectory() const
  45342. {
  45343. return root;
  45344. }
  45345. void DirectoryContentsList::setDirectory (const File& directory,
  45346. const bool includeDirectories_,
  45347. const bool includeFiles_)
  45348. {
  45349. if (directory != root
  45350. || includeDirectories != includeDirectories_
  45351. || includeFiles != includeFiles_)
  45352. {
  45353. clear();
  45354. root = directory;
  45355. includeDirectories = includeDirectories_;
  45356. includeFiles = includeFiles_;
  45357. refresh();
  45358. }
  45359. }
  45360. void DirectoryContentsList::clear()
  45361. {
  45362. shouldStop = true;
  45363. thread.removeTimeSliceClient (this);
  45364. if (fileFindHandle != 0)
  45365. {
  45366. juce_findFileClose (fileFindHandle);
  45367. fileFindHandle = 0;
  45368. }
  45369. if (files.size() > 0)
  45370. {
  45371. files.clear();
  45372. changed();
  45373. }
  45374. }
  45375. void DirectoryContentsList::refresh()
  45376. {
  45377. clear();
  45378. if (root.isDirectory())
  45379. {
  45380. String fileFound;
  45381. bool fileFoundIsDir, isHidden, isReadOnly;
  45382. int64 fileSize;
  45383. Time modTime, creationTime;
  45384. String path (root.getFullPathName());
  45385. if (! path.endsWithChar (File::separator))
  45386. path += File::separator;
  45387. jassert (fileFindHandle == 0);
  45388. fileFindHandle = juce_findFileStart (path, "*", fileFound,
  45389. &fileFoundIsDir,
  45390. &isHidden,
  45391. &fileSize,
  45392. &modTime,
  45393. &creationTime,
  45394. &isReadOnly);
  45395. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45396. {
  45397. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45398. fileSize, modTime, creationTime, isReadOnly))
  45399. {
  45400. changed();
  45401. }
  45402. }
  45403. shouldStop = false;
  45404. thread.addTimeSliceClient (this);
  45405. }
  45406. }
  45407. int DirectoryContentsList::getNumFiles() const
  45408. {
  45409. return files.size();
  45410. }
  45411. bool DirectoryContentsList::getFileInfo (const int index,
  45412. FileInfo& result) const
  45413. {
  45414. const ScopedLock sl (fileListLock);
  45415. const FileInfo* const info = files [index];
  45416. if (info != 0)
  45417. {
  45418. result = *info;
  45419. return true;
  45420. }
  45421. return false;
  45422. }
  45423. const File DirectoryContentsList::getFile (const int index) const
  45424. {
  45425. const ScopedLock sl (fileListLock);
  45426. const FileInfo* const info = files [index];
  45427. if (info != 0)
  45428. return root.getChildFile (info->filename);
  45429. return File::nonexistent;
  45430. }
  45431. bool DirectoryContentsList::isStillLoading() const
  45432. {
  45433. return fileFindHandle != 0;
  45434. }
  45435. void DirectoryContentsList::changed()
  45436. {
  45437. sendChangeMessage (this);
  45438. }
  45439. bool DirectoryContentsList::useTimeSlice()
  45440. {
  45441. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45442. bool hasChanged = false;
  45443. for (int i = 100; --i >= 0;)
  45444. {
  45445. if (! checkNextFile (hasChanged))
  45446. {
  45447. if (hasChanged)
  45448. changed();
  45449. return false;
  45450. }
  45451. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45452. break;
  45453. }
  45454. if (hasChanged)
  45455. changed();
  45456. return true;
  45457. }
  45458. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45459. {
  45460. if (fileFindHandle != 0)
  45461. {
  45462. String fileFound;
  45463. bool fileFoundIsDir, isHidden, isReadOnly;
  45464. int64 fileSize;
  45465. Time modTime, creationTime;
  45466. if (juce_findFileNext (fileFindHandle, fileFound,
  45467. &fileFoundIsDir, &isHidden,
  45468. &fileSize,
  45469. &modTime,
  45470. &creationTime,
  45471. &isReadOnly))
  45472. {
  45473. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45474. modTime, creationTime, isReadOnly))
  45475. {
  45476. hasChanged = true;
  45477. }
  45478. return true;
  45479. }
  45480. else
  45481. {
  45482. juce_findFileClose (fileFindHandle);
  45483. fileFindHandle = 0;
  45484. }
  45485. }
  45486. return false;
  45487. }
  45488. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45489. const DirectoryContentsList::FileInfo* const second)
  45490. {
  45491. #if JUCE_WINDOWS
  45492. if (first->isDirectory != second->isDirectory)
  45493. return first->isDirectory ? -1 : 1;
  45494. #endif
  45495. return first->filename.compareIgnoreCase (second->filename);
  45496. }
  45497. bool DirectoryContentsList::addFile (const String& filename,
  45498. const bool isDir,
  45499. const bool isHidden,
  45500. const int64 fileSize,
  45501. const Time& modTime,
  45502. const Time& creationTime,
  45503. const bool isReadOnly)
  45504. {
  45505. if (filename == ".."
  45506. || filename == "."
  45507. || (ignoreHiddenFiles && isHidden))
  45508. return false;
  45509. const File file (root.getChildFile (filename));
  45510. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45511. && (fileFilter == 0
  45512. || ((! isDir) && fileFilter->isFileSuitable (file))
  45513. || (isDir && fileFilter->isDirectorySuitable (file))))
  45514. {
  45515. ScopedPointer <FileInfo> info (new FileInfo());
  45516. info->filename = filename;
  45517. info->fileSize = fileSize;
  45518. info->modificationTime = modTime;
  45519. info->creationTime = creationTime;
  45520. info->isDirectory = isDir;
  45521. info->isReadOnly = isReadOnly;
  45522. const ScopedLock sl (fileListLock);
  45523. for (int i = files.size(); --i >= 0;)
  45524. if (files.getUnchecked(i)->filename == info->filename)
  45525. return false;
  45526. files.addSorted (*this, info.release());
  45527. return true;
  45528. }
  45529. return false;
  45530. }
  45531. END_JUCE_NAMESPACE
  45532. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45533. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45534. BEGIN_JUCE_NAMESPACE
  45535. FileBrowserComponent::FileBrowserComponent (int flags_,
  45536. const File& initialFileOrDirectory,
  45537. const FileFilter* fileFilter_,
  45538. FilePreviewComponent* previewComp_)
  45539. : FileFilter (String::empty),
  45540. fileFilter (fileFilter_),
  45541. flags (flags_),
  45542. previewComp (previewComp_),
  45543. thread ("Juce FileBrowser")
  45544. {
  45545. // You need to specify one or other of the open/save flags..
  45546. jassert ((flags & (saveMode | openMode)) != 0);
  45547. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45548. // You need to specify at least one of these flags..
  45549. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45550. String filename;
  45551. if (initialFileOrDirectory == File::nonexistent)
  45552. {
  45553. currentRoot = File::getCurrentWorkingDirectory();
  45554. }
  45555. else if (initialFileOrDirectory.isDirectory())
  45556. {
  45557. currentRoot = initialFileOrDirectory;
  45558. }
  45559. else
  45560. {
  45561. chosenFiles.add (initialFileOrDirectory);
  45562. currentRoot = initialFileOrDirectory.getParentDirectory();
  45563. filename = initialFileOrDirectory.getFileName();
  45564. }
  45565. fileList = new DirectoryContentsList (this, thread);
  45566. if ((flags & useTreeView) != 0)
  45567. {
  45568. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45569. if ((flags & canSelectMultipleItems) != 0)
  45570. tree->setMultiSelectEnabled (true);
  45571. addAndMakeVisible (tree);
  45572. fileListComponent = tree;
  45573. }
  45574. else
  45575. {
  45576. FileListComponent* const list = new FileListComponent (*fileList);
  45577. list->setOutlineThickness (1);
  45578. if ((flags & canSelectMultipleItems) != 0)
  45579. list->setMultipleSelectionEnabled (true);
  45580. addAndMakeVisible (list);
  45581. fileListComponent = list;
  45582. }
  45583. fileListComponent->addListener (this);
  45584. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45585. currentPathBox->setEditableText (true);
  45586. StringArray rootNames, rootPaths;
  45587. const BigInteger separators (getRoots (rootNames, rootPaths));
  45588. for (int i = 0; i < rootNames.size(); ++i)
  45589. {
  45590. if (separators [i])
  45591. currentPathBox->addSeparator();
  45592. currentPathBox->addItem (rootNames[i], i + 1);
  45593. }
  45594. currentPathBox->addSeparator();
  45595. currentPathBox->addListener (this);
  45596. addAndMakeVisible (filenameBox = new TextEditor());
  45597. filenameBox->setMultiLine (false);
  45598. filenameBox->setSelectAllWhenFocused (true);
  45599. filenameBox->setText (filename, false);
  45600. filenameBox->addListener (this);
  45601. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45602. Label* label = new Label ("f", TRANS("file:"));
  45603. addAndMakeVisible (label);
  45604. label->attachToComponent (filenameBox, true);
  45605. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45606. goUpButton->addButtonListener (this);
  45607. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45608. if (previewComp != 0)
  45609. addAndMakeVisible (previewComp);
  45610. setRoot (currentRoot);
  45611. thread.startThread (4);
  45612. }
  45613. FileBrowserComponent::~FileBrowserComponent()
  45614. {
  45615. if (previewComp != 0)
  45616. removeChildComponent (previewComp);
  45617. deleteAllChildren();
  45618. fileList = 0;
  45619. thread.stopThread (10000);
  45620. }
  45621. void FileBrowserComponent::addListener (FileBrowserListener* const newListener)
  45622. {
  45623. listeners.add (newListener);
  45624. }
  45625. void FileBrowserComponent::removeListener (FileBrowserListener* const listener)
  45626. {
  45627. listeners.remove (listener);
  45628. }
  45629. bool FileBrowserComponent::isSaveMode() const throw()
  45630. {
  45631. return (flags & saveMode) != 0;
  45632. }
  45633. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45634. {
  45635. if (chosenFiles.size() == 0 && currentFileIsValid())
  45636. return 1;
  45637. return chosenFiles.size();
  45638. }
  45639. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45640. {
  45641. if (! filenameBox->isReadOnly())
  45642. return currentRoot.getChildFile (filenameBox->getText());
  45643. else
  45644. return chosenFiles[index];
  45645. }
  45646. bool FileBrowserComponent::currentFileIsValid() const
  45647. {
  45648. if (isSaveMode())
  45649. return ! getSelectedFile (0).isDirectory();
  45650. else
  45651. return getSelectedFile (0).exists();
  45652. }
  45653. const File FileBrowserComponent::getHighlightedFile() const throw()
  45654. {
  45655. return fileListComponent->getSelectedFile (0);
  45656. }
  45657. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45658. {
  45659. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45660. : false;
  45661. }
  45662. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45663. {
  45664. return true;
  45665. }
  45666. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45667. {
  45668. if (f.isDirectory())
  45669. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45670. return (flags & canSelectFiles) != 0 && f.exists()
  45671. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45672. }
  45673. const File FileBrowserComponent::getRoot() const
  45674. {
  45675. return currentRoot;
  45676. }
  45677. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45678. {
  45679. if (currentRoot != newRootDirectory)
  45680. {
  45681. fileListComponent->scrollToTop();
  45682. String path (newRootDirectory.getFullPathName());
  45683. if (path.isEmpty())
  45684. path += File::separator;
  45685. StringArray rootNames, rootPaths;
  45686. getRoots (rootNames, rootPaths);
  45687. if (! rootPaths.contains (path, true))
  45688. {
  45689. bool alreadyListed = false;
  45690. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45691. {
  45692. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45693. {
  45694. alreadyListed = true;
  45695. break;
  45696. }
  45697. }
  45698. if (! alreadyListed)
  45699. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45700. }
  45701. }
  45702. currentRoot = newRootDirectory;
  45703. fileList->setDirectory (currentRoot, true, true);
  45704. String currentRootName (currentRoot.getFullPathName());
  45705. if (currentRootName.isEmpty())
  45706. currentRootName += File::separator;
  45707. currentPathBox->setText (currentRootName, true);
  45708. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45709. && currentRoot.getParentDirectory() != currentRoot);
  45710. }
  45711. void FileBrowserComponent::goUp()
  45712. {
  45713. setRoot (getRoot().getParentDirectory());
  45714. }
  45715. void FileBrowserComponent::refresh()
  45716. {
  45717. fileList->refresh();
  45718. }
  45719. const String FileBrowserComponent::getActionVerb() const
  45720. {
  45721. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45722. }
  45723. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45724. {
  45725. return previewComp;
  45726. }
  45727. void FileBrowserComponent::resized()
  45728. {
  45729. getLookAndFeel()
  45730. .layoutFileBrowserComponent (*this, fileListComponent,
  45731. previewComp, currentPathBox,
  45732. filenameBox, goUpButton);
  45733. }
  45734. void FileBrowserComponent::sendListenerChangeMessage()
  45735. {
  45736. Component::BailOutChecker checker (this);
  45737. if (previewComp != 0)
  45738. previewComp->selectedFileChanged (getSelectedFile (0));
  45739. // You shouldn't delete the browser when the file gets changed!
  45740. jassert (! checker.shouldBailOut());
  45741. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45742. }
  45743. void FileBrowserComponent::selectionChanged()
  45744. {
  45745. StringArray newFilenames;
  45746. bool resetChosenFiles = true;
  45747. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45748. {
  45749. const File f (fileListComponent->getSelectedFile (i));
  45750. if (isFileOrDirSuitable (f))
  45751. {
  45752. if (resetChosenFiles)
  45753. {
  45754. chosenFiles.clear();
  45755. resetChosenFiles = false;
  45756. }
  45757. chosenFiles.add (f);
  45758. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45759. }
  45760. }
  45761. if (newFilenames.size() > 0)
  45762. filenameBox->setText (newFilenames.joinIntoString (", "), false);
  45763. sendListenerChangeMessage();
  45764. }
  45765. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45766. {
  45767. Component::BailOutChecker checker (this);
  45768. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45769. }
  45770. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45771. {
  45772. if (f.isDirectory())
  45773. {
  45774. setRoot (f);
  45775. }
  45776. else
  45777. {
  45778. Component::BailOutChecker checker (this);
  45779. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45780. }
  45781. }
  45782. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45783. {
  45784. #if JUCE_LINUX || JUCE_WINDOWS
  45785. if (key.getModifiers().isCommandDown()
  45786. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45787. {
  45788. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45789. fileList->refresh();
  45790. return true;
  45791. }
  45792. #endif
  45793. return false;
  45794. }
  45795. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45796. {
  45797. sendListenerChangeMessage();
  45798. }
  45799. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45800. {
  45801. if (filenameBox->getText().containsChar (File::separator))
  45802. {
  45803. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45804. if (f.isDirectory())
  45805. {
  45806. setRoot (f);
  45807. chosenFiles.clear();
  45808. filenameBox->setText (String::empty);
  45809. }
  45810. else
  45811. {
  45812. setRoot (f.getParentDirectory());
  45813. chosenFiles.clear();
  45814. chosenFiles.add (f);
  45815. filenameBox->setText (f.getFileName());
  45816. }
  45817. }
  45818. else
  45819. {
  45820. fileDoubleClicked (getSelectedFile (0));
  45821. }
  45822. }
  45823. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45824. {
  45825. }
  45826. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45827. {
  45828. if (! isSaveMode())
  45829. selectionChanged();
  45830. }
  45831. void FileBrowserComponent::buttonClicked (Button*)
  45832. {
  45833. goUp();
  45834. }
  45835. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45836. {
  45837. const String newText (currentPathBox->getText().trim().unquoted());
  45838. if (newText.isNotEmpty())
  45839. {
  45840. const int index = currentPathBox->getSelectedId() - 1;
  45841. StringArray rootNames, rootPaths;
  45842. getRoots (rootNames, rootPaths);
  45843. if (rootPaths [index].isNotEmpty())
  45844. {
  45845. setRoot (File (rootPaths [index]));
  45846. }
  45847. else
  45848. {
  45849. File f (newText);
  45850. for (;;)
  45851. {
  45852. if (f.isDirectory())
  45853. {
  45854. setRoot (f);
  45855. break;
  45856. }
  45857. if (f.getParentDirectory() == f)
  45858. break;
  45859. f = f.getParentDirectory();
  45860. }
  45861. }
  45862. }
  45863. }
  45864. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45865. {
  45866. BigInteger separators;
  45867. #if JUCE_WINDOWS
  45868. Array<File> roots;
  45869. File::findFileSystemRoots (roots);
  45870. rootPaths.clear();
  45871. for (int i = 0; i < roots.size(); ++i)
  45872. {
  45873. const File& drive = roots.getReference(i);
  45874. String name (drive.getFullPathName());
  45875. rootPaths.add (name);
  45876. if (drive.isOnHardDisk())
  45877. {
  45878. String volume (drive.getVolumeLabel());
  45879. if (volume.isEmpty())
  45880. volume = TRANS("Hard Drive");
  45881. name << " [" << drive.getVolumeLabel() << ']';
  45882. }
  45883. else if (drive.isOnCDRomDrive())
  45884. {
  45885. name << TRANS(" [CD/DVD drive]");
  45886. }
  45887. rootNames.add (name);
  45888. }
  45889. separators.setBit (rootPaths.size());
  45890. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45891. rootNames.add ("Documents");
  45892. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45893. rootNames.add ("Desktop");
  45894. #endif
  45895. #if JUCE_MAC
  45896. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45897. rootNames.add ("Home folder");
  45898. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45899. rootNames.add ("Documents");
  45900. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45901. rootNames.add ("Desktop");
  45902. separators.setBit (rootPaths.size());
  45903. Array <File> volumes;
  45904. File vol ("/Volumes");
  45905. vol.findChildFiles (volumes, File::findDirectories, false);
  45906. for (int i = 0; i < volumes.size(); ++i)
  45907. {
  45908. const File& volume = volumes.getReference(i);
  45909. if (volume.isDirectory() && ! volume.getFileName().startsWithChar ('.'))
  45910. {
  45911. rootPaths.add (volume.getFullPathName());
  45912. rootNames.add (volume.getFileName());
  45913. }
  45914. }
  45915. #endif
  45916. #if JUCE_LINUX
  45917. rootPaths.add ("/");
  45918. rootNames.add ("/");
  45919. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45920. rootNames.add ("Home folder");
  45921. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45922. rootNames.add ("Desktop");
  45923. #endif
  45924. return separators;
  45925. }
  45926. END_JUCE_NAMESPACE
  45927. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  45928. /*** Start of inlined file: juce_FileChooser.cpp ***/
  45929. BEGIN_JUCE_NAMESPACE
  45930. FileChooser::FileChooser (const String& chooserBoxTitle,
  45931. const File& currentFileOrDirectory,
  45932. const String& fileFilters,
  45933. const bool useNativeDialogBox_)
  45934. : title (chooserBoxTitle),
  45935. filters (fileFilters),
  45936. startingFile (currentFileOrDirectory),
  45937. useNativeDialogBox (useNativeDialogBox_)
  45938. {
  45939. #if JUCE_LINUX
  45940. useNativeDialogBox = false;
  45941. #endif
  45942. if (! fileFilters.containsNonWhitespaceChars())
  45943. filters = "*";
  45944. }
  45945. FileChooser::~FileChooser()
  45946. {
  45947. }
  45948. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  45949. {
  45950. return showDialog (false, true, false, false, false, previewComponent);
  45951. }
  45952. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  45953. {
  45954. return showDialog (false, true, false, false, true, previewComponent);
  45955. }
  45956. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  45957. {
  45958. return showDialog (true, true, false, false, true, previewComponent);
  45959. }
  45960. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  45961. {
  45962. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  45963. }
  45964. bool FileChooser::browseForDirectory()
  45965. {
  45966. return showDialog (true, false, false, false, false, 0);
  45967. }
  45968. const File FileChooser::getResult() const
  45969. {
  45970. // if you've used a multiple-file select, you should use the getResults() method
  45971. // to retrieve all the files that were chosen.
  45972. jassert (results.size() <= 1);
  45973. return results.getFirst();
  45974. }
  45975. const Array<File>& FileChooser::getResults() const
  45976. {
  45977. return results;
  45978. }
  45979. bool FileChooser::showDialog (const bool selectsDirectories,
  45980. const bool selectsFiles,
  45981. const bool isSave,
  45982. const bool warnAboutOverwritingExistingFiles,
  45983. const bool selectMultipleFiles,
  45984. FilePreviewComponent* const previewComponent)
  45985. {
  45986. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  45987. results.clear();
  45988. // the preview component needs to be the right size before you pass it in here..
  45989. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  45990. && previewComponent->getHeight() > 10));
  45991. #if JUCE_WINDOWS
  45992. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  45993. #elif JUCE_MAC
  45994. if (useNativeDialogBox && (previewComponent == 0))
  45995. #else
  45996. if (false)
  45997. #endif
  45998. {
  45999. showPlatformDialog (results, title, startingFile, filters,
  46000. selectsDirectories, selectsFiles, isSave,
  46001. warnAboutOverwritingExistingFiles,
  46002. selectMultipleFiles,
  46003. previewComponent);
  46004. }
  46005. else
  46006. {
  46007. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46008. selectsDirectories ? "*" : String::empty,
  46009. String::empty);
  46010. int flags = isSave ? FileBrowserComponent::saveMode
  46011. : FileBrowserComponent::openMode;
  46012. if (selectsFiles)
  46013. flags |= FileBrowserComponent::canSelectFiles;
  46014. if (selectsDirectories)
  46015. flags |= FileBrowserComponent::canSelectDirectories;
  46016. if (selectMultipleFiles)
  46017. flags |= FileBrowserComponent::canSelectMultipleItems;
  46018. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46019. FileChooserDialogBox box (title, String::empty,
  46020. browserComponent,
  46021. warnAboutOverwritingExistingFiles,
  46022. browserComponent.findColour (AlertWindow::backgroundColourId));
  46023. if (box.show())
  46024. {
  46025. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46026. results.add (browserComponent.getSelectedFile (i));
  46027. }
  46028. }
  46029. if (previouslyFocused != 0)
  46030. previouslyFocused->grabKeyboardFocus();
  46031. return results.size() > 0;
  46032. }
  46033. FilePreviewComponent::FilePreviewComponent()
  46034. {
  46035. }
  46036. FilePreviewComponent::~FilePreviewComponent()
  46037. {
  46038. }
  46039. END_JUCE_NAMESPACE
  46040. /*** End of inlined file: juce_FileChooser.cpp ***/
  46041. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46042. BEGIN_JUCE_NAMESPACE
  46043. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46044. const String& instructions,
  46045. FileBrowserComponent& chooserComponent,
  46046. const bool warnAboutOverwritingExistingFiles_,
  46047. const Colour& backgroundColour)
  46048. : ResizableWindow (name, backgroundColour, true),
  46049. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46050. {
  46051. content = new ContentComponent();
  46052. content->setName (name);
  46053. content->instructions = instructions;
  46054. content->chooserComponent = &chooserComponent;
  46055. content->addAndMakeVisible (&chooserComponent);
  46056. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46057. content->addAndMakeVisible (content->okButton);
  46058. content->okButton->addButtonListener (this);
  46059. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46060. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46061. content->cancelButton = new TextButton (TRANS("Cancel"));
  46062. content->addAndMakeVisible (content->cancelButton);
  46063. content->cancelButton->addButtonListener (this);
  46064. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46065. setContentComponent (content);
  46066. setResizable (true, true);
  46067. setResizeLimits (300, 300, 1200, 1000);
  46068. content->chooserComponent->addListener (this);
  46069. }
  46070. FileChooserDialogBox::~FileChooserDialogBox()
  46071. {
  46072. content->chooserComponent->removeListener (this);
  46073. }
  46074. bool FileChooserDialogBox::show (int w, int h)
  46075. {
  46076. if (w <= 0)
  46077. {
  46078. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46079. if (previewComp != 0)
  46080. w = 400 + previewComp->getWidth();
  46081. else
  46082. w = 600;
  46083. }
  46084. if (h <= 0)
  46085. h = 500;
  46086. centreWithSize (w, h);
  46087. const bool ok = (runModalLoop() != 0);
  46088. setVisible (false);
  46089. return ok;
  46090. }
  46091. void FileChooserDialogBox::buttonClicked (Button* button)
  46092. {
  46093. if (button == content->okButton)
  46094. {
  46095. if (warnAboutOverwritingExistingFiles
  46096. && content->chooserComponent->isSaveMode()
  46097. && content->chooserComponent->getSelectedFile(0).exists())
  46098. {
  46099. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46100. TRANS("File already exists"),
  46101. TRANS("There's already a file called:")
  46102. + "\n\n" + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46103. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  46104. TRANS("overwrite"),
  46105. TRANS("cancel")))
  46106. {
  46107. return;
  46108. }
  46109. }
  46110. exitModalState (1);
  46111. }
  46112. else if (button == content->cancelButton)
  46113. closeButtonPressed();
  46114. }
  46115. void FileChooserDialogBox::closeButtonPressed()
  46116. {
  46117. setVisible (false);
  46118. }
  46119. void FileChooserDialogBox::selectionChanged()
  46120. {
  46121. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46122. }
  46123. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46124. {
  46125. }
  46126. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46127. {
  46128. selectionChanged();
  46129. content->okButton->triggerClick();
  46130. }
  46131. FileChooserDialogBox::ContentComponent::ContentComponent()
  46132. {
  46133. setInterceptsMouseClicks (false, true);
  46134. }
  46135. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46136. {
  46137. delete okButton;
  46138. delete cancelButton;
  46139. }
  46140. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46141. {
  46142. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46143. text.draw (g);
  46144. }
  46145. void FileChooserDialogBox::ContentComponent::resized()
  46146. {
  46147. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46148. const Rectangle<float> bb (text.getBoundingBox (0, text.getNumGlyphs(), false));
  46149. const int y = roundToInt (bb.getBottom()) + 10;
  46150. const int buttonHeight = 26;
  46151. const int buttonY = getHeight() - buttonHeight - 8;
  46152. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46153. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46154. proportionOfWidth (0.2f), buttonHeight);
  46155. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46156. proportionOfWidth (0.2f), buttonHeight);
  46157. }
  46158. END_JUCE_NAMESPACE
  46159. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46160. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46161. BEGIN_JUCE_NAMESPACE
  46162. FileFilter::FileFilter (const String& filterDescription)
  46163. : description (filterDescription)
  46164. {
  46165. }
  46166. FileFilter::~FileFilter()
  46167. {
  46168. }
  46169. const String& FileFilter::getDescription() const throw()
  46170. {
  46171. return description;
  46172. }
  46173. END_JUCE_NAMESPACE
  46174. /*** End of inlined file: juce_FileFilter.cpp ***/
  46175. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46176. BEGIN_JUCE_NAMESPACE
  46177. Image* juce_createIconForFile (const File& file);
  46178. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46179. : ListBox (String::empty, 0),
  46180. DirectoryContentsDisplayComponent (listToShow)
  46181. {
  46182. setModel (this);
  46183. fileList.addChangeListener (this);
  46184. }
  46185. FileListComponent::~FileListComponent()
  46186. {
  46187. fileList.removeChangeListener (this);
  46188. deleteAllChildren();
  46189. }
  46190. int FileListComponent::getNumSelectedFiles() const
  46191. {
  46192. return getNumSelectedRows();
  46193. }
  46194. const File FileListComponent::getSelectedFile (int index) const
  46195. {
  46196. return fileList.getFile (getSelectedRow (index));
  46197. }
  46198. void FileListComponent::scrollToTop()
  46199. {
  46200. getVerticalScrollBar()->setCurrentRangeStart (0);
  46201. }
  46202. void FileListComponent::changeListenerCallback (void*)
  46203. {
  46204. updateContent();
  46205. if (lastDirectory != fileList.getDirectory())
  46206. {
  46207. lastDirectory = fileList.getDirectory();
  46208. deselectAllRows();
  46209. }
  46210. }
  46211. class FileListItemComponent : public Component,
  46212. public TimeSliceClient,
  46213. public AsyncUpdater
  46214. {
  46215. public:
  46216. FileListItemComponent (FileListComponent& owner_,
  46217. TimeSliceThread& thread_) throw()
  46218. : owner (owner_),
  46219. thread (thread_),
  46220. icon (0)
  46221. {
  46222. }
  46223. ~FileListItemComponent() throw()
  46224. {
  46225. thread.removeTimeSliceClient (this);
  46226. clearIcon();
  46227. }
  46228. void paint (Graphics& g)
  46229. {
  46230. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46231. file.getFileName(),
  46232. icon,
  46233. fileSize, modTime,
  46234. isDirectory, highlighted,
  46235. index);
  46236. }
  46237. void mouseDown (const MouseEvent& e)
  46238. {
  46239. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46240. owner.sendMouseClickMessage (file, e);
  46241. }
  46242. void mouseDoubleClick (const MouseEvent&)
  46243. {
  46244. owner.sendDoubleClickMessage (file);
  46245. }
  46246. void update (const File& root,
  46247. const DirectoryContentsList::FileInfo* const fileInfo,
  46248. const int index_,
  46249. const bool highlighted_) throw()
  46250. {
  46251. thread.removeTimeSliceClient (this);
  46252. if (highlighted_ != highlighted
  46253. || index_ != index)
  46254. {
  46255. index = index_;
  46256. highlighted = highlighted_;
  46257. repaint();
  46258. }
  46259. File newFile;
  46260. String newFileSize;
  46261. String newModTime;
  46262. if (fileInfo != 0)
  46263. {
  46264. newFile = root.getChildFile (fileInfo->filename);
  46265. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46266. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46267. }
  46268. if (newFile != file
  46269. || fileSize != newFileSize
  46270. || modTime != newModTime)
  46271. {
  46272. file = newFile;
  46273. fileSize = newFileSize;
  46274. modTime = newModTime;
  46275. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46276. repaint();
  46277. clearIcon();
  46278. }
  46279. if (file != File::nonexistent
  46280. && icon == 0 && ! isDirectory)
  46281. {
  46282. updateIcon (true);
  46283. if (icon == 0)
  46284. thread.addTimeSliceClient (this);
  46285. }
  46286. }
  46287. bool useTimeSlice()
  46288. {
  46289. updateIcon (false);
  46290. return false;
  46291. }
  46292. void handleAsyncUpdate()
  46293. {
  46294. repaint();
  46295. }
  46296. juce_UseDebuggingNewOperator
  46297. private:
  46298. FileListComponent& owner;
  46299. TimeSliceThread& thread;
  46300. bool highlighted;
  46301. int index;
  46302. File file;
  46303. String fileSize;
  46304. String modTime;
  46305. Image* icon;
  46306. bool isDirectory;
  46307. void clearIcon() throw()
  46308. {
  46309. ImageCache::release (icon);
  46310. icon = 0;
  46311. }
  46312. void updateIcon (const bool onlyUpdateIfCached) throw()
  46313. {
  46314. if (icon == 0)
  46315. {
  46316. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46317. Image* im = ImageCache::getFromHashCode (hashCode);
  46318. if (im == 0 && ! onlyUpdateIfCached)
  46319. {
  46320. im = juce_createIconForFile (file);
  46321. if (im != 0)
  46322. ImageCache::addImageToCache (im, hashCode);
  46323. }
  46324. if (im != 0)
  46325. {
  46326. icon = im;
  46327. triggerAsyncUpdate();
  46328. }
  46329. }
  46330. }
  46331. };
  46332. int FileListComponent::getNumRows()
  46333. {
  46334. return fileList.getNumFiles();
  46335. }
  46336. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46337. {
  46338. }
  46339. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46340. {
  46341. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46342. if (comp == 0)
  46343. {
  46344. delete existingComponentToUpdate;
  46345. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46346. }
  46347. DirectoryContentsList::FileInfo fileInfo;
  46348. if (fileList.getFileInfo (row, fileInfo))
  46349. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46350. else
  46351. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46352. return comp;
  46353. }
  46354. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46355. {
  46356. sendSelectionChangeMessage();
  46357. }
  46358. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46359. {
  46360. }
  46361. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46362. {
  46363. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46364. }
  46365. END_JUCE_NAMESPACE
  46366. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46367. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46368. BEGIN_JUCE_NAMESPACE
  46369. FilenameComponent::FilenameComponent (const String& name,
  46370. const File& currentFile,
  46371. const bool canEditFilename,
  46372. const bool isDirectory,
  46373. const bool isForSaving,
  46374. const String& fileBrowserWildcard,
  46375. const String& enforcedSuffix_,
  46376. const String& textWhenNothingSelected)
  46377. : Component (name),
  46378. maxRecentFiles (30),
  46379. isDir (isDirectory),
  46380. isSaving (isForSaving),
  46381. isFileDragOver (false),
  46382. wildcard (fileBrowserWildcard),
  46383. enforcedSuffix (enforcedSuffix_)
  46384. {
  46385. addAndMakeVisible (filenameBox = new ComboBox ("fn"));
  46386. filenameBox->setEditableText (canEditFilename);
  46387. filenameBox->addListener (this);
  46388. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46389. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46390. browseButton = 0;
  46391. setBrowseButtonText ("...");
  46392. setCurrentFile (currentFile, true);
  46393. }
  46394. FilenameComponent::~FilenameComponent()
  46395. {
  46396. deleteAllChildren();
  46397. }
  46398. void FilenameComponent::paintOverChildren (Graphics& g)
  46399. {
  46400. if (isFileDragOver)
  46401. {
  46402. g.setColour (Colours::red.withAlpha (0.2f));
  46403. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46404. }
  46405. }
  46406. void FilenameComponent::resized()
  46407. {
  46408. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46409. }
  46410. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46411. {
  46412. browseButtonText = newBrowseButtonText;
  46413. lookAndFeelChanged();
  46414. }
  46415. void FilenameComponent::lookAndFeelChanged()
  46416. {
  46417. deleteAndZero (browseButton);
  46418. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46419. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46420. resized();
  46421. browseButton->addButtonListener (this);
  46422. }
  46423. void FilenameComponent::setTooltip (const String& newTooltip)
  46424. {
  46425. SettableTooltipClient::setTooltip (newTooltip);
  46426. filenameBox->setTooltip (newTooltip);
  46427. }
  46428. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46429. {
  46430. defaultBrowseFile = newDefaultDirectory;
  46431. }
  46432. void FilenameComponent::buttonClicked (Button*)
  46433. {
  46434. FileChooser fc (TRANS("Choose a new file"),
  46435. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46436. : getCurrentFile(),
  46437. wildcard);
  46438. if (isDir ? fc.browseForDirectory()
  46439. : (isSaving ? fc.browseForFileToSave (false)
  46440. : fc.browseForFileToOpen()))
  46441. {
  46442. setCurrentFile (fc.getResult(), true);
  46443. }
  46444. }
  46445. void FilenameComponent::comboBoxChanged (ComboBox*)
  46446. {
  46447. setCurrentFile (getCurrentFile(), true);
  46448. }
  46449. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46450. {
  46451. return true;
  46452. }
  46453. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46454. {
  46455. isFileDragOver = false;
  46456. repaint();
  46457. const File f (filenames[0]);
  46458. if (f.exists() && (f.isDirectory() == isDir))
  46459. setCurrentFile (f, true);
  46460. }
  46461. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46462. {
  46463. isFileDragOver = true;
  46464. repaint();
  46465. }
  46466. void FilenameComponent::fileDragExit (const StringArray&)
  46467. {
  46468. isFileDragOver = false;
  46469. repaint();
  46470. }
  46471. const File FilenameComponent::getCurrentFile() const
  46472. {
  46473. File f (filenameBox->getText());
  46474. if (enforcedSuffix.isNotEmpty())
  46475. f = f.withFileExtension (enforcedSuffix);
  46476. return f;
  46477. }
  46478. void FilenameComponent::setCurrentFile (File newFile,
  46479. const bool addToRecentlyUsedList,
  46480. const bool sendChangeNotification)
  46481. {
  46482. if (enforcedSuffix.isNotEmpty())
  46483. newFile = newFile.withFileExtension (enforcedSuffix);
  46484. if (newFile.getFullPathName() != lastFilename)
  46485. {
  46486. lastFilename = newFile.getFullPathName();
  46487. if (addToRecentlyUsedList)
  46488. addRecentlyUsedFile (newFile);
  46489. filenameBox->setText (lastFilename, true);
  46490. if (sendChangeNotification)
  46491. triggerAsyncUpdate();
  46492. }
  46493. }
  46494. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46495. {
  46496. filenameBox->setEditableText (shouldBeEditable);
  46497. }
  46498. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46499. {
  46500. StringArray names;
  46501. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46502. names.add (filenameBox->getItemText (i));
  46503. return names;
  46504. }
  46505. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46506. {
  46507. if (filenames != getRecentlyUsedFilenames())
  46508. {
  46509. filenameBox->clear();
  46510. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46511. filenameBox->addItem (filenames[i], i + 1);
  46512. }
  46513. }
  46514. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46515. {
  46516. maxRecentFiles = jmax (1, newMaximum);
  46517. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46518. }
  46519. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46520. {
  46521. StringArray files (getRecentlyUsedFilenames());
  46522. if (file.getFullPathName().isNotEmpty())
  46523. {
  46524. files.removeString (file.getFullPathName(), true);
  46525. files.insert (0, file.getFullPathName());
  46526. setRecentlyUsedFilenames (files);
  46527. }
  46528. }
  46529. void FilenameComponent::addListener (FilenameComponentListener* const listener)
  46530. {
  46531. listeners.add (listener);
  46532. }
  46533. void FilenameComponent::removeListener (FilenameComponentListener* const listener)
  46534. {
  46535. listeners.remove (listener);
  46536. }
  46537. void FilenameComponent::handleAsyncUpdate()
  46538. {
  46539. Component::BailOutChecker checker (this);
  46540. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46541. }
  46542. END_JUCE_NAMESPACE
  46543. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46544. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46545. BEGIN_JUCE_NAMESPACE
  46546. FileSearchPathListComponent::FileSearchPathListComponent()
  46547. {
  46548. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46549. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46550. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46551. listBox->setOutlineThickness (1);
  46552. addAndMakeVisible (addButton = new TextButton ("+"));
  46553. addButton->addButtonListener (this);
  46554. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46555. addAndMakeVisible (removeButton = new TextButton ("-"));
  46556. removeButton->addButtonListener (this);
  46557. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46558. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46559. changeButton->addButtonListener (this);
  46560. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46561. upButton->addButtonListener (this);
  46562. {
  46563. Path arrowPath;
  46564. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46565. DrawablePath arrowImage;
  46566. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46567. arrowImage.setPath (arrowPath);
  46568. upButton->setImages (&arrowImage);
  46569. }
  46570. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46571. downButton->addButtonListener (this);
  46572. {
  46573. Path arrowPath;
  46574. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46575. DrawablePath arrowImage;
  46576. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46577. arrowImage.setPath (arrowPath);
  46578. downButton->setImages (&arrowImage);
  46579. }
  46580. updateButtons();
  46581. }
  46582. FileSearchPathListComponent::~FileSearchPathListComponent()
  46583. {
  46584. deleteAllChildren();
  46585. }
  46586. void FileSearchPathListComponent::updateButtons()
  46587. {
  46588. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46589. removeButton->setEnabled (anythingSelected);
  46590. changeButton->setEnabled (anythingSelected);
  46591. upButton->setEnabled (anythingSelected);
  46592. downButton->setEnabled (anythingSelected);
  46593. }
  46594. void FileSearchPathListComponent::changed()
  46595. {
  46596. listBox->updateContent();
  46597. listBox->repaint();
  46598. updateButtons();
  46599. }
  46600. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46601. {
  46602. if (newPath.toString() != path.toString())
  46603. {
  46604. path = newPath;
  46605. changed();
  46606. }
  46607. }
  46608. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46609. {
  46610. defaultBrowseTarget = newDefaultDirectory;
  46611. }
  46612. int FileSearchPathListComponent::getNumRows()
  46613. {
  46614. return path.getNumPaths();
  46615. }
  46616. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46617. {
  46618. if (rowIsSelected)
  46619. g.fillAll (findColour (TextEditor::highlightColourId));
  46620. g.setColour (findColour (ListBox::textColourId));
  46621. Font f (height * 0.7f);
  46622. f.setHorizontalScale (0.9f);
  46623. g.setFont (f);
  46624. g.drawText (path [rowNumber].getFullPathName(),
  46625. 4, 0, width - 6, height,
  46626. Justification::centredLeft, true);
  46627. }
  46628. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46629. {
  46630. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46631. {
  46632. path.remove (row);
  46633. changed();
  46634. }
  46635. }
  46636. void FileSearchPathListComponent::returnKeyPressed (int row)
  46637. {
  46638. FileChooser chooser (TRANS("Change folder..."), path [row], "*");
  46639. if (chooser.browseForDirectory())
  46640. {
  46641. path.remove (row);
  46642. path.add (chooser.getResult(), row);
  46643. changed();
  46644. }
  46645. }
  46646. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46647. {
  46648. returnKeyPressed (row);
  46649. }
  46650. void FileSearchPathListComponent::selectedRowsChanged (int)
  46651. {
  46652. updateButtons();
  46653. }
  46654. void FileSearchPathListComponent::paint (Graphics& g)
  46655. {
  46656. g.fillAll (findColour (backgroundColourId));
  46657. }
  46658. void FileSearchPathListComponent::resized()
  46659. {
  46660. const int buttonH = 22;
  46661. const int buttonY = getHeight() - buttonH - 4;
  46662. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46663. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46664. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46665. changeButton->changeWidthToFitText (buttonH);
  46666. downButton->setSize (buttonH * 2, buttonH);
  46667. upButton->setSize (buttonH * 2, buttonH);
  46668. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46669. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46670. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46671. }
  46672. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46673. {
  46674. return true;
  46675. }
  46676. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46677. {
  46678. for (int i = filenames.size(); --i >= 0;)
  46679. {
  46680. const File f (filenames[i]);
  46681. if (f.isDirectory())
  46682. {
  46683. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46684. path.add (f, row);
  46685. changed();
  46686. }
  46687. }
  46688. }
  46689. void FileSearchPathListComponent::buttonClicked (Button* button)
  46690. {
  46691. const int currentRow = listBox->getSelectedRow();
  46692. if (button == removeButton)
  46693. {
  46694. deleteKeyPressed (currentRow);
  46695. }
  46696. else if (button == addButton)
  46697. {
  46698. File start (defaultBrowseTarget);
  46699. if (start == File::nonexistent)
  46700. start = path [0];
  46701. if (start == File::nonexistent)
  46702. start = File::getCurrentWorkingDirectory();
  46703. FileChooser chooser (TRANS("Add a folder..."), start, "*");
  46704. if (chooser.browseForDirectory())
  46705. {
  46706. path.add (chooser.getResult(), currentRow);
  46707. }
  46708. }
  46709. else if (button == changeButton)
  46710. {
  46711. returnKeyPressed (currentRow);
  46712. }
  46713. else if (button == upButton)
  46714. {
  46715. if (currentRow > 0 && currentRow < path.getNumPaths())
  46716. {
  46717. const File f (path[currentRow]);
  46718. path.remove (currentRow);
  46719. path.add (f, currentRow - 1);
  46720. listBox->selectRow (currentRow - 1);
  46721. }
  46722. }
  46723. else if (button == downButton)
  46724. {
  46725. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46726. {
  46727. const File f (path[currentRow]);
  46728. path.remove (currentRow);
  46729. path.add (f, currentRow + 1);
  46730. listBox->selectRow (currentRow + 1);
  46731. }
  46732. }
  46733. changed();
  46734. }
  46735. END_JUCE_NAMESPACE
  46736. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46737. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46738. BEGIN_JUCE_NAMESPACE
  46739. Image* juce_createIconForFile (const File& file);
  46740. class FileListTreeItem : public TreeViewItem,
  46741. public TimeSliceClient,
  46742. public AsyncUpdater,
  46743. public ChangeListener
  46744. {
  46745. public:
  46746. FileListTreeItem (FileTreeComponent& owner_,
  46747. DirectoryContentsList* const parentContentsList_,
  46748. const int indexInContentsList_,
  46749. const File& file_,
  46750. TimeSliceThread& thread_)
  46751. : file (file_),
  46752. owner (owner_),
  46753. parentContentsList (parentContentsList_),
  46754. indexInContentsList (indexInContentsList_),
  46755. subContentsList (0),
  46756. canDeleteSubContentsList (false),
  46757. thread (thread_),
  46758. icon (0)
  46759. {
  46760. DirectoryContentsList::FileInfo fileInfo;
  46761. if (parentContentsList_ != 0
  46762. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46763. {
  46764. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46765. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46766. isDirectory = fileInfo.isDirectory;
  46767. }
  46768. else
  46769. {
  46770. isDirectory = true;
  46771. }
  46772. }
  46773. ~FileListTreeItem()
  46774. {
  46775. thread.removeTimeSliceClient (this);
  46776. clearSubItems();
  46777. ImageCache::release (icon);
  46778. if (canDeleteSubContentsList)
  46779. delete subContentsList;
  46780. }
  46781. bool mightContainSubItems() { return isDirectory; }
  46782. const String getUniqueName() const { return file.getFullPathName(); }
  46783. int getItemHeight() const { return 22; }
  46784. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46785. void itemOpennessChanged (bool isNowOpen)
  46786. {
  46787. if (isNowOpen)
  46788. {
  46789. clearSubItems();
  46790. isDirectory = file.isDirectory();
  46791. if (isDirectory)
  46792. {
  46793. if (subContentsList == 0)
  46794. {
  46795. jassert (parentContentsList != 0);
  46796. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46797. l->setDirectory (file, true, true);
  46798. setSubContentsList (l);
  46799. canDeleteSubContentsList = true;
  46800. }
  46801. changeListenerCallback (0);
  46802. }
  46803. }
  46804. }
  46805. void setSubContentsList (DirectoryContentsList* newList)
  46806. {
  46807. jassert (subContentsList == 0);
  46808. subContentsList = newList;
  46809. newList->addChangeListener (this);
  46810. }
  46811. void changeListenerCallback (void*)
  46812. {
  46813. clearSubItems();
  46814. if (isOpen() && subContentsList != 0)
  46815. {
  46816. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46817. {
  46818. FileListTreeItem* const item
  46819. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46820. addSubItem (item);
  46821. }
  46822. }
  46823. }
  46824. void paintItem (Graphics& g, int width, int height)
  46825. {
  46826. if (file != File::nonexistent)
  46827. {
  46828. updateIcon (true);
  46829. if (icon == 0)
  46830. thread.addTimeSliceClient (this);
  46831. }
  46832. owner.getLookAndFeel()
  46833. .drawFileBrowserRow (g, width, height,
  46834. file.getFileName(),
  46835. icon,
  46836. fileSize, modTime,
  46837. isDirectory, isSelected(),
  46838. indexInContentsList);
  46839. }
  46840. void itemClicked (const MouseEvent& e)
  46841. {
  46842. owner.sendMouseClickMessage (file, e);
  46843. }
  46844. void itemDoubleClicked (const MouseEvent& e)
  46845. {
  46846. TreeViewItem::itemDoubleClicked (e);
  46847. owner.sendDoubleClickMessage (file);
  46848. }
  46849. void itemSelectionChanged (bool)
  46850. {
  46851. owner.sendSelectionChangeMessage();
  46852. }
  46853. bool useTimeSlice()
  46854. {
  46855. updateIcon (false);
  46856. thread.removeTimeSliceClient (this);
  46857. return false;
  46858. }
  46859. void handleAsyncUpdate()
  46860. {
  46861. owner.repaint();
  46862. }
  46863. const File file;
  46864. juce_UseDebuggingNewOperator
  46865. private:
  46866. FileTreeComponent& owner;
  46867. DirectoryContentsList* parentContentsList;
  46868. int indexInContentsList;
  46869. DirectoryContentsList* subContentsList;
  46870. bool isDirectory, canDeleteSubContentsList;
  46871. TimeSliceThread& thread;
  46872. Image* icon;
  46873. String fileSize;
  46874. String modTime;
  46875. void updateIcon (const bool onlyUpdateIfCached)
  46876. {
  46877. if (icon == 0)
  46878. {
  46879. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46880. Image* im = ImageCache::getFromHashCode (hashCode);
  46881. if (im == 0 && ! onlyUpdateIfCached)
  46882. {
  46883. im = juce_createIconForFile (file);
  46884. if (im != 0)
  46885. ImageCache::addImageToCache (im, hashCode);
  46886. }
  46887. if (im != 0)
  46888. {
  46889. icon = im;
  46890. triggerAsyncUpdate();
  46891. }
  46892. }
  46893. }
  46894. };
  46895. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46896. : DirectoryContentsDisplayComponent (listToShow)
  46897. {
  46898. FileListTreeItem* const root
  46899. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46900. listToShow.getTimeSliceThread());
  46901. root->setSubContentsList (&listToShow);
  46902. setRootItemVisible (false);
  46903. setRootItem (root);
  46904. }
  46905. FileTreeComponent::~FileTreeComponent()
  46906. {
  46907. deleteRootItem();
  46908. }
  46909. const File FileTreeComponent::getSelectedFile (const int index) const
  46910. {
  46911. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  46912. if (item != 0)
  46913. return item->file;
  46914. return File::nonexistent;
  46915. }
  46916. void FileTreeComponent::scrollToTop()
  46917. {
  46918. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  46919. }
  46920. void FileTreeComponent::setDragAndDropDescription (const String& description)
  46921. {
  46922. dragAndDropDescription = description;
  46923. }
  46924. END_JUCE_NAMESPACE
  46925. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  46926. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  46927. BEGIN_JUCE_NAMESPACE
  46928. ImagePreviewComponent::ImagePreviewComponent()
  46929. {
  46930. }
  46931. ImagePreviewComponent::~ImagePreviewComponent()
  46932. {
  46933. }
  46934. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  46935. {
  46936. const int availableW = proportionOfWidth (0.97f);
  46937. const int availableH = getHeight() - 13 * 4;
  46938. const double scale = jmin (1.0,
  46939. availableW / (double) w,
  46940. availableH / (double) h);
  46941. w = roundToInt (scale * w);
  46942. h = roundToInt (scale * h);
  46943. }
  46944. void ImagePreviewComponent::selectedFileChanged (const File& file)
  46945. {
  46946. if (fileToLoad != file)
  46947. {
  46948. fileToLoad = file;
  46949. startTimer (100);
  46950. }
  46951. }
  46952. void ImagePreviewComponent::timerCallback()
  46953. {
  46954. stopTimer();
  46955. currentThumbnail = 0;
  46956. currentDetails = String::empty;
  46957. repaint();
  46958. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  46959. if (in != 0)
  46960. {
  46961. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  46962. if (format != 0)
  46963. {
  46964. currentThumbnail = format->decodeImage (*in);
  46965. if (currentThumbnail != 0)
  46966. {
  46967. int w = currentThumbnail->getWidth();
  46968. int h = currentThumbnail->getHeight();
  46969. currentDetails
  46970. << fileToLoad.getFileName() << "\n"
  46971. << format->getFormatName() << "\n"
  46972. << w << " x " << h << " pixels\n"
  46973. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  46974. getThumbSize (w, h);
  46975. currentThumbnail = currentThumbnail->createCopy (w, h);
  46976. }
  46977. }
  46978. }
  46979. }
  46980. void ImagePreviewComponent::paint (Graphics& g)
  46981. {
  46982. if (currentThumbnail != 0)
  46983. {
  46984. g.setFont (13.0f);
  46985. int w = currentThumbnail->getWidth();
  46986. int h = currentThumbnail->getHeight();
  46987. getThumbSize (w, h);
  46988. const int numLines = 4;
  46989. const int totalH = 13 * numLines + h + 4;
  46990. const int y = (getHeight() - totalH) / 2;
  46991. g.drawImageWithin (currentThumbnail,
  46992. (getWidth() - w) / 2, y, w, h,
  46993. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  46994. false);
  46995. g.drawFittedText (currentDetails,
  46996. 0, y + h + 4, getWidth(), 100,
  46997. Justification::centredTop, numLines);
  46998. }
  46999. }
  47000. END_JUCE_NAMESPACE
  47001. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47002. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47003. BEGIN_JUCE_NAMESPACE
  47004. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47005. const String& directoryWildcardPatterns,
  47006. const String& description_)
  47007. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47008. : (description_ + " (" + fileWildcardPatterns + ")"))
  47009. {
  47010. parse (fileWildcardPatterns, fileWildcards);
  47011. parse (directoryWildcardPatterns, directoryWildcards);
  47012. }
  47013. WildcardFileFilter::~WildcardFileFilter()
  47014. {
  47015. }
  47016. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47017. {
  47018. return match (file, fileWildcards);
  47019. }
  47020. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47021. {
  47022. return match (file, directoryWildcards);
  47023. }
  47024. void WildcardFileFilter::parse (const String& pattern, StringArray& result)
  47025. {
  47026. result.addTokens (pattern.toLowerCase(), ";,", "\"'");
  47027. result.trim();
  47028. result.removeEmptyStrings();
  47029. // special case for *.*, because people use it to mean "any file", but it
  47030. // would actually ignore files with no extension.
  47031. for (int i = result.size(); --i >= 0;)
  47032. if (result[i] == "*.*")
  47033. result.set (i, "*");
  47034. }
  47035. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards)
  47036. {
  47037. const String filename (file.getFileName());
  47038. for (int i = wildcards.size(); --i >= 0;)
  47039. if (filename.matchesWildcard (wildcards[i], true))
  47040. return true;
  47041. return false;
  47042. }
  47043. END_JUCE_NAMESPACE
  47044. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47045. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47046. BEGIN_JUCE_NAMESPACE
  47047. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47048. {
  47049. }
  47050. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47051. {
  47052. }
  47053. namespace KeyboardFocusHelpers
  47054. {
  47055. // This will sort a set of components, so that they are ordered in terms of
  47056. // left-to-right and then top-to-bottom.
  47057. class ScreenPositionComparator
  47058. {
  47059. public:
  47060. ScreenPositionComparator() {}
  47061. static int compareElements (const Component* const first, const Component* const second)
  47062. {
  47063. int explicitOrder1 = first->getExplicitFocusOrder();
  47064. if (explicitOrder1 <= 0)
  47065. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47066. int explicitOrder2 = second->getExplicitFocusOrder();
  47067. if (explicitOrder2 <= 0)
  47068. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47069. if (explicitOrder1 != explicitOrder2)
  47070. return explicitOrder1 - explicitOrder2;
  47071. const int diff = first->getY() - second->getY();
  47072. return (diff == 0) ? first->getX() - second->getX()
  47073. : diff;
  47074. }
  47075. };
  47076. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47077. {
  47078. if (parent->getNumChildComponents() > 0)
  47079. {
  47080. Array <Component*> localComps;
  47081. ScreenPositionComparator comparator;
  47082. int i;
  47083. for (i = parent->getNumChildComponents(); --i >= 0;)
  47084. {
  47085. Component* const c = parent->getChildComponent (i);
  47086. if (c->isVisible() && c->isEnabled())
  47087. localComps.addSorted (comparator, c);
  47088. }
  47089. for (i = 0; i < localComps.size(); ++i)
  47090. {
  47091. Component* const c = localComps.getUnchecked (i);
  47092. if (c->getWantsKeyboardFocus())
  47093. comps.add (c);
  47094. if (! c->isFocusContainer())
  47095. findAllFocusableComponents (c, comps);
  47096. }
  47097. }
  47098. }
  47099. }
  47100. static Component* getIncrementedComponent (Component* const current, const int delta)
  47101. {
  47102. Component* focusContainer = current->getParentComponent();
  47103. if (focusContainer != 0)
  47104. {
  47105. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47106. focusContainer = focusContainer->getParentComponent();
  47107. if (focusContainer != 0)
  47108. {
  47109. Array <Component*> comps;
  47110. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47111. if (comps.size() > 0)
  47112. {
  47113. const int index = comps.indexOf (current);
  47114. return comps [(index + comps.size() + delta) % comps.size()];
  47115. }
  47116. }
  47117. }
  47118. return 0;
  47119. }
  47120. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47121. {
  47122. return getIncrementedComponent (current, 1);
  47123. }
  47124. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47125. {
  47126. return getIncrementedComponent (current, -1);
  47127. }
  47128. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47129. {
  47130. Array <Component*> comps;
  47131. if (parentComponent != 0)
  47132. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47133. return comps.getFirst();
  47134. }
  47135. END_JUCE_NAMESPACE
  47136. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47137. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47138. BEGIN_JUCE_NAMESPACE
  47139. bool KeyListener::keyStateChanged (const bool, Component*)
  47140. {
  47141. return false;
  47142. }
  47143. END_JUCE_NAMESPACE
  47144. /*** End of inlined file: juce_KeyListener.cpp ***/
  47145. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47146. BEGIN_JUCE_NAMESPACE
  47147. // N.B. these two includes are put here deliberately to avoid problems with
  47148. // old GCCs failing on long include paths
  47149. const int maxKeys = 3;
  47150. class KeyMappingChangeButton : public Button
  47151. {
  47152. public:
  47153. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47154. const CommandID commandID_,
  47155. const String& keyName,
  47156. const int keyNum_)
  47157. : Button (keyName),
  47158. owner (owner_),
  47159. commandID (commandID_),
  47160. keyNum (keyNum_)
  47161. {
  47162. setWantsKeyboardFocus (false);
  47163. setTriggeredOnMouseDown (keyNum >= 0);
  47164. if (keyNum_ < 0)
  47165. setTooltip (TRANS("adds a new key-mapping"));
  47166. else
  47167. setTooltip (TRANS("click to change this key-mapping"));
  47168. }
  47169. ~KeyMappingChangeButton()
  47170. {
  47171. }
  47172. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47173. {
  47174. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47175. keyNum >= 0 ? getName() : String::empty);
  47176. }
  47177. void clicked()
  47178. {
  47179. if (keyNum >= 0)
  47180. {
  47181. // existing key clicked..
  47182. PopupMenu m;
  47183. m.addItem (1, TRANS("change this key-mapping"));
  47184. m.addSeparator();
  47185. m.addItem (2, TRANS("remove this key-mapping"));
  47186. const int res = m.show();
  47187. if (res == 1)
  47188. {
  47189. owner->assignNewKey (commandID, keyNum);
  47190. }
  47191. else if (res == 2)
  47192. {
  47193. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47194. }
  47195. }
  47196. else
  47197. {
  47198. // + button pressed..
  47199. owner->assignNewKey (commandID, -1);
  47200. }
  47201. }
  47202. void fitToContent (const int h) throw()
  47203. {
  47204. if (keyNum < 0)
  47205. {
  47206. setSize (h, h);
  47207. }
  47208. else
  47209. {
  47210. Font f (h * 0.6f);
  47211. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47212. }
  47213. }
  47214. juce_UseDebuggingNewOperator
  47215. private:
  47216. KeyMappingEditorComponent* const owner;
  47217. const CommandID commandID;
  47218. const int keyNum;
  47219. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47220. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47221. };
  47222. class KeyMappingItemComponent : public Component
  47223. {
  47224. public:
  47225. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47226. const CommandID commandID_)
  47227. : owner (owner_),
  47228. commandID (commandID_)
  47229. {
  47230. setInterceptsMouseClicks (false, true);
  47231. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47232. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47233. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47234. {
  47235. KeyMappingChangeButton* const kb
  47236. = new KeyMappingChangeButton (owner_, commandID,
  47237. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47238. kb->setEnabled (! isReadOnly);
  47239. addAndMakeVisible (kb);
  47240. }
  47241. KeyMappingChangeButton* const kb
  47242. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47243. addChildComponent (kb);
  47244. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47245. }
  47246. ~KeyMappingItemComponent()
  47247. {
  47248. deleteAllChildren();
  47249. }
  47250. void paint (Graphics& g)
  47251. {
  47252. g.setFont (getHeight() * 0.7f);
  47253. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47254. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47255. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47256. Justification::centredLeft, true);
  47257. }
  47258. void resized()
  47259. {
  47260. int x = getWidth() - 4;
  47261. for (int i = getNumChildComponents(); --i >= 0;)
  47262. {
  47263. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47264. kb->fitToContent (getHeight() - 2);
  47265. kb->setTopRightPosition (x, 1);
  47266. x -= kb->getWidth() + 5;
  47267. }
  47268. }
  47269. juce_UseDebuggingNewOperator
  47270. private:
  47271. KeyMappingEditorComponent* const owner;
  47272. const CommandID commandID;
  47273. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47274. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47275. };
  47276. class KeyMappingTreeViewItem : public TreeViewItem
  47277. {
  47278. public:
  47279. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47280. const CommandID commandID_)
  47281. : owner (owner_),
  47282. commandID (commandID_)
  47283. {
  47284. }
  47285. ~KeyMappingTreeViewItem()
  47286. {
  47287. }
  47288. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47289. bool mightContainSubItems() { return false; }
  47290. int getItemHeight() const { return 20; }
  47291. Component* createItemComponent()
  47292. {
  47293. return new KeyMappingItemComponent (owner, commandID);
  47294. }
  47295. juce_UseDebuggingNewOperator
  47296. private:
  47297. KeyMappingEditorComponent* const owner;
  47298. const CommandID commandID;
  47299. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47300. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47301. };
  47302. class KeyCategoryTreeViewItem : public TreeViewItem
  47303. {
  47304. public:
  47305. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47306. const String& name)
  47307. : owner (owner_),
  47308. categoryName (name)
  47309. {
  47310. }
  47311. ~KeyCategoryTreeViewItem()
  47312. {
  47313. }
  47314. const String getUniqueName() const { return categoryName + "_cat"; }
  47315. bool mightContainSubItems() { return true; }
  47316. int getItemHeight() const { return 28; }
  47317. void paintItem (Graphics& g, int width, int height)
  47318. {
  47319. g.setFont (height * 0.6f, Font::bold);
  47320. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47321. g.drawText (categoryName,
  47322. 2, 0, width - 2, height,
  47323. Justification::centredLeft, true);
  47324. }
  47325. void itemOpennessChanged (bool isNowOpen)
  47326. {
  47327. if (isNowOpen)
  47328. {
  47329. if (getNumSubItems() == 0)
  47330. {
  47331. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47332. for (int i = 0; i < commands.size(); ++i)
  47333. {
  47334. if (owner->shouldCommandBeIncluded (commands[i]))
  47335. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47336. }
  47337. }
  47338. }
  47339. else
  47340. {
  47341. clearSubItems();
  47342. }
  47343. }
  47344. juce_UseDebuggingNewOperator
  47345. private:
  47346. KeyMappingEditorComponent* owner;
  47347. String categoryName;
  47348. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47349. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47350. };
  47351. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47352. const bool showResetToDefaultButton)
  47353. : mappings (mappingManager)
  47354. {
  47355. jassert (mappingManager != 0); // can't be null!
  47356. mappingManager->addChangeListener (this);
  47357. setLinesDrawnForSubItems (false);
  47358. resetButton = 0;
  47359. if (showResetToDefaultButton)
  47360. {
  47361. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47362. resetButton->addButtonListener (this);
  47363. }
  47364. addAndMakeVisible (tree = new TreeView());
  47365. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47366. tree->setRootItemVisible (false);
  47367. tree->setDefaultOpenness (true);
  47368. tree->setRootItem (this);
  47369. }
  47370. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47371. {
  47372. mappings->removeChangeListener (this);
  47373. deleteAllChildren();
  47374. }
  47375. bool KeyMappingEditorComponent::mightContainSubItems()
  47376. {
  47377. return true;
  47378. }
  47379. const String KeyMappingEditorComponent::getUniqueName() const
  47380. {
  47381. return "keys";
  47382. }
  47383. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47384. const Colour& textColour)
  47385. {
  47386. setColour (backgroundColourId, mainBackground);
  47387. setColour (textColourId, textColour);
  47388. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47389. }
  47390. void KeyMappingEditorComponent::parentHierarchyChanged()
  47391. {
  47392. changeListenerCallback (0);
  47393. }
  47394. void KeyMappingEditorComponent::resized()
  47395. {
  47396. int h = getHeight();
  47397. if (resetButton != 0)
  47398. {
  47399. const int buttonHeight = 20;
  47400. h -= buttonHeight + 8;
  47401. int x = getWidth() - 8;
  47402. const int y = h + 6;
  47403. resetButton->changeWidthToFitText (buttonHeight);
  47404. resetButton->setTopRightPosition (x, y);
  47405. }
  47406. tree->setBounds (0, 0, getWidth(), h);
  47407. }
  47408. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47409. {
  47410. if (button == resetButton)
  47411. {
  47412. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47413. TRANS("Reset to defaults"),
  47414. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47415. TRANS("Reset")))
  47416. {
  47417. mappings->resetToDefaultMappings();
  47418. }
  47419. }
  47420. }
  47421. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47422. {
  47423. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47424. clearSubItems();
  47425. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47426. for (int i = 0; i < categories.size(); ++i)
  47427. {
  47428. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47429. int count = 0;
  47430. for (int j = 0; j < commands.size(); ++j)
  47431. if (shouldCommandBeIncluded (commands[j]))
  47432. ++count;
  47433. if (count > 0)
  47434. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47435. }
  47436. if (openness != 0)
  47437. tree->restoreOpennessState (*openness);
  47438. }
  47439. class KeyEntryWindow : public AlertWindow
  47440. {
  47441. public:
  47442. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47443. : AlertWindow (TRANS("New key-mapping"),
  47444. TRANS("Please press a key combination now..."),
  47445. AlertWindow::NoIcon),
  47446. owner (owner_)
  47447. {
  47448. addButton (TRANS("ok"), 1);
  47449. addButton (TRANS("cancel"), 0);
  47450. // (avoid return + escape keys getting processed by the buttons..)
  47451. for (int i = getNumChildComponents(); --i >= 0;)
  47452. getChildComponent (i)->setWantsKeyboardFocus (false);
  47453. setWantsKeyboardFocus (true);
  47454. grabKeyboardFocus();
  47455. }
  47456. ~KeyEntryWindow()
  47457. {
  47458. }
  47459. bool keyPressed (const KeyPress& key)
  47460. {
  47461. lastPress = key;
  47462. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47463. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47464. if (previousCommand != 0)
  47465. {
  47466. message << "\n\n"
  47467. << TRANS("(Currently assigned to \"")
  47468. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47469. << "\")";
  47470. }
  47471. setMessage (message);
  47472. return true;
  47473. }
  47474. bool keyStateChanged (bool)
  47475. {
  47476. return true;
  47477. }
  47478. KeyPress lastPress;
  47479. juce_UseDebuggingNewOperator
  47480. private:
  47481. KeyMappingEditorComponent* owner;
  47482. KeyEntryWindow (const KeyEntryWindow&);
  47483. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47484. };
  47485. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47486. {
  47487. KeyEntryWindow entryWindow (this);
  47488. if (entryWindow.runModalLoop() != 0)
  47489. {
  47490. entryWindow.setVisible (false);
  47491. if (entryWindow.lastPress.isValid())
  47492. {
  47493. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47494. if (previousCommand != 0)
  47495. {
  47496. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47497. TRANS("Change key-mapping"),
  47498. TRANS("This key is already assigned to the command \"")
  47499. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47500. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47501. TRANS("re-assign"),
  47502. TRANS("cancel")))
  47503. {
  47504. return;
  47505. }
  47506. }
  47507. mappings->removeKeyPress (entryWindow.lastPress);
  47508. if (index >= 0)
  47509. mappings->removeKeyPress (commandID, index);
  47510. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47511. }
  47512. }
  47513. }
  47514. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47515. {
  47516. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47517. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47518. }
  47519. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47520. {
  47521. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47522. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47523. }
  47524. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47525. {
  47526. return key.getTextDescription();
  47527. }
  47528. END_JUCE_NAMESPACE
  47529. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47530. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47531. BEGIN_JUCE_NAMESPACE
  47532. KeyPress::KeyPress() throw()
  47533. : keyCode (0),
  47534. mods (0),
  47535. textCharacter (0)
  47536. {
  47537. }
  47538. KeyPress::KeyPress (const int keyCode_,
  47539. const ModifierKeys& mods_,
  47540. const juce_wchar textCharacter_) throw()
  47541. : keyCode (keyCode_),
  47542. mods (mods_),
  47543. textCharacter (textCharacter_)
  47544. {
  47545. }
  47546. KeyPress::KeyPress (const int keyCode_) throw()
  47547. : keyCode (keyCode_),
  47548. textCharacter (0)
  47549. {
  47550. }
  47551. KeyPress::KeyPress (const KeyPress& other) throw()
  47552. : keyCode (other.keyCode),
  47553. mods (other.mods),
  47554. textCharacter (other.textCharacter)
  47555. {
  47556. }
  47557. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47558. {
  47559. keyCode = other.keyCode;
  47560. mods = other.mods;
  47561. textCharacter = other.textCharacter;
  47562. return *this;
  47563. }
  47564. bool KeyPress::operator== (const KeyPress& other) const throw()
  47565. {
  47566. return mods.getRawFlags() == other.mods.getRawFlags()
  47567. && (textCharacter == other.textCharacter
  47568. || textCharacter == 0
  47569. || other.textCharacter == 0)
  47570. && (keyCode == other.keyCode
  47571. || (keyCode < 256
  47572. && other.keyCode < 256
  47573. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  47574. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  47575. }
  47576. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47577. {
  47578. return ! operator== (other);
  47579. }
  47580. bool KeyPress::isCurrentlyDown() const
  47581. {
  47582. return isKeyCurrentlyDown (keyCode)
  47583. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47584. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47585. }
  47586. namespace KeyPressHelpers
  47587. {
  47588. struct KeyNameAndCode
  47589. {
  47590. const char* name;
  47591. int code;
  47592. };
  47593. static const KeyNameAndCode translations[] =
  47594. {
  47595. { "spacebar", KeyPress::spaceKey },
  47596. { "return", KeyPress::returnKey },
  47597. { "escape", KeyPress::escapeKey },
  47598. { "backspace", KeyPress::backspaceKey },
  47599. { "cursor left", KeyPress::leftKey },
  47600. { "cursor right", KeyPress::rightKey },
  47601. { "cursor up", KeyPress::upKey },
  47602. { "cursor down", KeyPress::downKey },
  47603. { "page up", KeyPress::pageUpKey },
  47604. { "page down", KeyPress::pageDownKey },
  47605. { "home", KeyPress::homeKey },
  47606. { "end", KeyPress::endKey },
  47607. { "delete", KeyPress::deleteKey },
  47608. { "insert", KeyPress::insertKey },
  47609. { "tab", KeyPress::tabKey },
  47610. { "play", KeyPress::playKey },
  47611. { "stop", KeyPress::stopKey },
  47612. { "fast forward", KeyPress::fastForwardKey },
  47613. { "rewind", KeyPress::rewindKey }
  47614. };
  47615. static const String numberPadPrefix() { return "numpad "; }
  47616. }
  47617. const KeyPress KeyPress::createFromDescription (const String& desc)
  47618. {
  47619. int modifiers = 0;
  47620. if (desc.containsWholeWordIgnoreCase ("ctrl")
  47621. || desc.containsWholeWordIgnoreCase ("control")
  47622. || desc.containsWholeWordIgnoreCase ("ctl"))
  47623. modifiers |= ModifierKeys::ctrlModifier;
  47624. if (desc.containsWholeWordIgnoreCase ("shift")
  47625. || desc.containsWholeWordIgnoreCase ("shft"))
  47626. modifiers |= ModifierKeys::shiftModifier;
  47627. if (desc.containsWholeWordIgnoreCase ("alt")
  47628. || desc.containsWholeWordIgnoreCase ("option"))
  47629. modifiers |= ModifierKeys::altModifier;
  47630. if (desc.containsWholeWordIgnoreCase ("command")
  47631. || desc.containsWholeWordIgnoreCase ("cmd"))
  47632. modifiers |= ModifierKeys::commandModifier;
  47633. int key = 0;
  47634. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47635. {
  47636. if (desc.containsWholeWordIgnoreCase (String (KeyPressHelpers::translations[i].name)))
  47637. {
  47638. key = KeyPressHelpers::translations[i].code;
  47639. break;
  47640. }
  47641. }
  47642. if (key == 0)
  47643. {
  47644. // see if it's a numpad key..
  47645. if (desc.containsIgnoreCase (KeyPressHelpers::numberPadPrefix()))
  47646. {
  47647. const tchar lastChar = desc.trimEnd().getLastCharacter();
  47648. if (lastChar >= '0' && lastChar <= '9')
  47649. key = numberPad0 + lastChar - '0';
  47650. else if (lastChar == '+')
  47651. key = numberPadAdd;
  47652. else if (lastChar == '-')
  47653. key = numberPadSubtract;
  47654. else if (lastChar == '*')
  47655. key = numberPadMultiply;
  47656. else if (lastChar == '/')
  47657. key = numberPadDivide;
  47658. else if (lastChar == '.')
  47659. key = numberPadDecimalPoint;
  47660. else if (lastChar == '=')
  47661. key = numberPadEquals;
  47662. else if (desc.endsWith ("separator"))
  47663. key = numberPadSeparator;
  47664. else if (desc.endsWith ("delete"))
  47665. key = numberPadDelete;
  47666. }
  47667. if (key == 0)
  47668. {
  47669. // see if it's a function key..
  47670. for (int i = 1; i <= 12; ++i)
  47671. if (desc.containsWholeWordIgnoreCase ("f" + String (i)))
  47672. key = F1Key + i - 1;
  47673. if (key == 0)
  47674. {
  47675. // give up and use the hex code..
  47676. const int hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
  47677. .toLowerCase()
  47678. .retainCharacters ("0123456789abcdef")
  47679. .getHexValue32();
  47680. if (hexCode > 0)
  47681. key = hexCode;
  47682. else
  47683. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47684. }
  47685. }
  47686. }
  47687. return KeyPress (key, ModifierKeys (modifiers), 0);
  47688. }
  47689. const String KeyPress::getTextDescription() const
  47690. {
  47691. String desc;
  47692. if (keyCode > 0)
  47693. {
  47694. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47695. // want to store it as being a slash, not shift+whatever.
  47696. if (textCharacter == '/')
  47697. return "/";
  47698. if (mods.isCtrlDown())
  47699. desc << "ctrl + ";
  47700. if (mods.isShiftDown())
  47701. desc << "shift + ";
  47702. #if JUCE_MAC
  47703. // only do this on the mac, because on Windows ctrl and command are the same,
  47704. // and this would get confusing
  47705. if (mods.isCommandDown())
  47706. desc << "command + ";
  47707. if (mods.isAltDown())
  47708. desc << "option + ";
  47709. #else
  47710. if (mods.isAltDown())
  47711. desc << "alt + ";
  47712. #endif
  47713. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47714. if (keyCode == KeyPressHelpers::translations[i].code)
  47715. return desc + KeyPressHelpers::translations[i].name;
  47716. if (keyCode >= F1Key && keyCode <= F16Key)
  47717. desc << 'F' << (1 + keyCode - F1Key);
  47718. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47719. desc << KeyPressHelpers::numberPadPrefix() << (keyCode - numberPad0);
  47720. else if (keyCode >= 33 && keyCode < 176)
  47721. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  47722. else if (keyCode == numberPadAdd)
  47723. desc << KeyPressHelpers::numberPadPrefix() << '+';
  47724. else if (keyCode == numberPadSubtract)
  47725. desc << KeyPressHelpers::numberPadPrefix() << '-';
  47726. else if (keyCode == numberPadMultiply)
  47727. desc << KeyPressHelpers::numberPadPrefix() << '*';
  47728. else if (keyCode == numberPadDivide)
  47729. desc << KeyPressHelpers::numberPadPrefix() << '/';
  47730. else if (keyCode == numberPadSeparator)
  47731. desc << KeyPressHelpers::numberPadPrefix() << "separator";
  47732. else if (keyCode == numberPadDecimalPoint)
  47733. desc << KeyPressHelpers::numberPadPrefix() << '.';
  47734. else if (keyCode == numberPadDelete)
  47735. desc << KeyPressHelpers::numberPadPrefix() << "delete";
  47736. else
  47737. desc << '#' << String::toHexString (keyCode);
  47738. }
  47739. return desc;
  47740. }
  47741. END_JUCE_NAMESPACE
  47742. /*** End of inlined file: juce_KeyPress.cpp ***/
  47743. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47744. BEGIN_JUCE_NAMESPACE
  47745. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_)
  47746. : commandManager (commandManager_)
  47747. {
  47748. // A manager is needed to get the descriptions of commands, and will be called when
  47749. // a command is invoked. So you can't leave this null..
  47750. jassert (commandManager_ != 0);
  47751. Desktop::getInstance().addFocusChangeListener (this);
  47752. }
  47753. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other)
  47754. : commandManager (other.commandManager)
  47755. {
  47756. Desktop::getInstance().addFocusChangeListener (this);
  47757. }
  47758. KeyPressMappingSet::~KeyPressMappingSet()
  47759. {
  47760. Desktop::getInstance().removeFocusChangeListener (this);
  47761. }
  47762. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const
  47763. {
  47764. for (int i = 0; i < mappings.size(); ++i)
  47765. if (mappings.getUnchecked(i)->commandID == commandID)
  47766. return mappings.getUnchecked (i)->keypresses;
  47767. return Array <KeyPress> ();
  47768. }
  47769. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47770. const KeyPress& newKeyPress,
  47771. int insertIndex)
  47772. {
  47773. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47774. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47775. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47776. && ! newKeyPress.getModifiers().isShiftDown()));
  47777. if (findCommandForKeyPress (newKeyPress) != commandID)
  47778. {
  47779. removeKeyPress (newKeyPress);
  47780. if (newKeyPress.isValid())
  47781. {
  47782. for (int i = mappings.size(); --i >= 0;)
  47783. {
  47784. if (mappings.getUnchecked(i)->commandID == commandID)
  47785. {
  47786. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47787. sendChangeMessage (this);
  47788. return;
  47789. }
  47790. }
  47791. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47792. if (ci != 0)
  47793. {
  47794. CommandMapping* const cm = new CommandMapping();
  47795. cm->commandID = commandID;
  47796. cm->keypresses.add (newKeyPress);
  47797. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47798. mappings.add (cm);
  47799. sendChangeMessage (this);
  47800. }
  47801. }
  47802. }
  47803. }
  47804. void KeyPressMappingSet::resetToDefaultMappings()
  47805. {
  47806. mappings.clear();
  47807. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47808. {
  47809. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47810. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47811. {
  47812. addKeyPress (ci->commandID,
  47813. ci->defaultKeypresses.getReference (j));
  47814. }
  47815. }
  47816. sendChangeMessage (this);
  47817. }
  47818. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID)
  47819. {
  47820. clearAllKeyPresses (commandID);
  47821. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47822. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47823. {
  47824. addKeyPress (ci->commandID,
  47825. ci->defaultKeypresses.getReference (j));
  47826. }
  47827. }
  47828. void KeyPressMappingSet::clearAllKeyPresses()
  47829. {
  47830. if (mappings.size() > 0)
  47831. {
  47832. sendChangeMessage (this);
  47833. mappings.clear();
  47834. }
  47835. }
  47836. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID)
  47837. {
  47838. for (int i = mappings.size(); --i >= 0;)
  47839. {
  47840. if (mappings.getUnchecked(i)->commandID == commandID)
  47841. {
  47842. mappings.remove (i);
  47843. sendChangeMessage (this);
  47844. }
  47845. }
  47846. }
  47847. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress)
  47848. {
  47849. if (keypress.isValid())
  47850. {
  47851. for (int i = mappings.size(); --i >= 0;)
  47852. {
  47853. CommandMapping* const cm = mappings.getUnchecked(i);
  47854. for (int j = cm->keypresses.size(); --j >= 0;)
  47855. {
  47856. if (keypress == cm->keypresses [j])
  47857. {
  47858. cm->keypresses.remove (j);
  47859. sendChangeMessage (this);
  47860. }
  47861. }
  47862. }
  47863. }
  47864. }
  47865. void KeyPressMappingSet::removeKeyPress (const CommandID commandID, const int keyPressIndex)
  47866. {
  47867. for (int i = mappings.size(); --i >= 0;)
  47868. {
  47869. if (mappings.getUnchecked(i)->commandID == commandID)
  47870. {
  47871. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47872. sendChangeMessage (this);
  47873. break;
  47874. }
  47875. }
  47876. }
  47877. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47878. {
  47879. for (int i = 0; i < mappings.size(); ++i)
  47880. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47881. return mappings.getUnchecked(i)->commandID;
  47882. return 0;
  47883. }
  47884. bool KeyPressMappingSet::containsMapping (const CommandID commandID, const KeyPress& keyPress) const throw()
  47885. {
  47886. for (int i = mappings.size(); --i >= 0;)
  47887. if (mappings.getUnchecked(i)->commandID == commandID)
  47888. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47889. return false;
  47890. }
  47891. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47892. const KeyPress& key,
  47893. const bool isKeyDown,
  47894. const int millisecsSinceKeyPressed,
  47895. Component* const originatingComponent) const
  47896. {
  47897. ApplicationCommandTarget::InvocationInfo info (commandID);
  47898. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47899. info.isKeyDown = isKeyDown;
  47900. info.keyPress = key;
  47901. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47902. info.originatingComponent = originatingComponent;
  47903. commandManager->invoke (info, false);
  47904. }
  47905. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47906. {
  47907. if (xmlVersion.hasTagName ("KEYMAPPINGS"))
  47908. {
  47909. if (xmlVersion.getBoolAttribute ("basedOnDefaults", true))
  47910. {
  47911. // if the XML was created as a set of differences from the default mappings,
  47912. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  47913. resetToDefaultMappings();
  47914. }
  47915. else
  47916. {
  47917. // if the XML was created calling createXml (false), then we need to clear all
  47918. // the keys and treat the xml as describing the entire set of mappings.
  47919. clearAllKeyPresses();
  47920. }
  47921. forEachXmlChildElement (xmlVersion, map)
  47922. {
  47923. const CommandID commandId = map->getStringAttribute ("commandId").getHexValue32();
  47924. if (commandId != 0)
  47925. {
  47926. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute ("key")));
  47927. if (map->hasTagName ("MAPPING"))
  47928. {
  47929. addKeyPress (commandId, key);
  47930. }
  47931. else if (map->hasTagName ("UNMAPPING"))
  47932. {
  47933. if (containsMapping (commandId, key))
  47934. removeKeyPress (key);
  47935. }
  47936. }
  47937. }
  47938. return true;
  47939. }
  47940. return false;
  47941. }
  47942. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  47943. {
  47944. ScopedPointer <KeyPressMappingSet> defaultSet;
  47945. if (saveDifferencesFromDefaultSet)
  47946. {
  47947. defaultSet = new KeyPressMappingSet (commandManager);
  47948. defaultSet->resetToDefaultMappings();
  47949. }
  47950. XmlElement* const doc = new XmlElement ("KEYMAPPINGS");
  47951. doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
  47952. int i;
  47953. for (i = 0; i < mappings.size(); ++i)
  47954. {
  47955. const CommandMapping* const cm = mappings.getUnchecked(i);
  47956. for (int j = 0; j < cm->keypresses.size(); ++j)
  47957. {
  47958. if (defaultSet == 0
  47959. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  47960. {
  47961. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  47962. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  47963. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  47964. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  47965. }
  47966. }
  47967. }
  47968. if (defaultSet != 0)
  47969. {
  47970. for (i = 0; i < defaultSet->mappings.size(); ++i)
  47971. {
  47972. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  47973. for (int j = 0; j < cm->keypresses.size(); ++j)
  47974. {
  47975. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  47976. {
  47977. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  47978. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  47979. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  47980. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  47981. }
  47982. }
  47983. }
  47984. }
  47985. return doc;
  47986. }
  47987. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  47988. Component* originatingComponent)
  47989. {
  47990. bool used = false;
  47991. const CommandID commandID = findCommandForKeyPress (key);
  47992. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47993. if (ci != 0
  47994. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  47995. {
  47996. ApplicationCommandInfo info (0);
  47997. if (commandManager->getTargetForCommand (commandID, info) != 0
  47998. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  47999. {
  48000. invokeCommand (commandID, key, true, 0, originatingComponent);
  48001. used = true;
  48002. }
  48003. else
  48004. {
  48005. if (originatingComponent != 0)
  48006. originatingComponent->getLookAndFeel().playAlertSound();
  48007. }
  48008. }
  48009. return used;
  48010. }
  48011. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48012. {
  48013. bool used = false;
  48014. const uint32 now = Time::getMillisecondCounter();
  48015. for (int i = mappings.size(); --i >= 0;)
  48016. {
  48017. CommandMapping* const cm = mappings.getUnchecked(i);
  48018. if (cm->wantsKeyUpDownCallbacks)
  48019. {
  48020. for (int j = cm->keypresses.size(); --j >= 0;)
  48021. {
  48022. const KeyPress key (cm->keypresses.getReference (j));
  48023. const bool isDown = key.isCurrentlyDown();
  48024. int keyPressEntryIndex = 0;
  48025. bool wasDown = false;
  48026. for (int k = keysDown.size(); --k >= 0;)
  48027. {
  48028. if (key == keysDown.getUnchecked(k)->key)
  48029. {
  48030. keyPressEntryIndex = k;
  48031. wasDown = true;
  48032. used = true;
  48033. break;
  48034. }
  48035. }
  48036. if (isDown != wasDown)
  48037. {
  48038. int millisecs = 0;
  48039. if (isDown)
  48040. {
  48041. KeyPressTime* const k = new KeyPressTime();
  48042. k->key = key;
  48043. k->timeWhenPressed = now;
  48044. keysDown.add (k);
  48045. }
  48046. else
  48047. {
  48048. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48049. if (now > pressTime)
  48050. millisecs = now - pressTime;
  48051. keysDown.remove (keyPressEntryIndex);
  48052. }
  48053. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48054. used = true;
  48055. }
  48056. }
  48057. }
  48058. }
  48059. return used;
  48060. }
  48061. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48062. {
  48063. if (focusedComponent != 0)
  48064. focusedComponent->keyStateChanged (false);
  48065. }
  48066. END_JUCE_NAMESPACE
  48067. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48068. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48069. BEGIN_JUCE_NAMESPACE
  48070. ModifierKeys::ModifierKeys (const int flags_) throw()
  48071. : flags (flags_)
  48072. {
  48073. }
  48074. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48075. : flags (other.flags)
  48076. {
  48077. }
  48078. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48079. {
  48080. flags = other.flags;
  48081. return *this;
  48082. }
  48083. ModifierKeys ModifierKeys::currentModifiers;
  48084. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48085. {
  48086. return currentModifiers;
  48087. }
  48088. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48089. {
  48090. int num = 0;
  48091. if (isLeftButtonDown()) ++num;
  48092. if (isRightButtonDown()) ++num;
  48093. if (isMiddleButtonDown()) ++num;
  48094. return num;
  48095. }
  48096. END_JUCE_NAMESPACE
  48097. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48098. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48099. BEGIN_JUCE_NAMESPACE
  48100. struct AnimationTask
  48101. {
  48102. AnimationTask (Component* const comp)
  48103. : component (comp)
  48104. {
  48105. }
  48106. Component::SafePointer<Component> component;
  48107. Rectangle<int> destination;
  48108. int msElapsed, msTotal;
  48109. double startSpeed, midSpeed, endSpeed, lastProgress;
  48110. double left, top, right, bottom;
  48111. bool useTimeslice (const int elapsed)
  48112. {
  48113. if (component == 0)
  48114. return false;
  48115. msElapsed += elapsed;
  48116. double newProgress = msElapsed / (double) msTotal;
  48117. if (newProgress >= 0 && newProgress < 1.0)
  48118. {
  48119. newProgress = timeToDistance (newProgress);
  48120. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48121. jassert (newProgress >= lastProgress);
  48122. lastProgress = newProgress;
  48123. left += (destination.getX() - left) * delta;
  48124. top += (destination.getY() - top) * delta;
  48125. right += (destination.getRight() - right) * delta;
  48126. bottom += (destination.getBottom() - bottom) * delta;
  48127. if (delta < 1.0)
  48128. {
  48129. const Rectangle<int> newBounds (roundToInt (left),
  48130. roundToInt (top),
  48131. roundToInt (right - left),
  48132. roundToInt (bottom - top));
  48133. if (newBounds != destination)
  48134. {
  48135. component->setBounds (newBounds);
  48136. return true;
  48137. }
  48138. }
  48139. }
  48140. component->setBounds (destination);
  48141. return false;
  48142. }
  48143. void moveToFinalDestination()
  48144. {
  48145. if (component != 0)
  48146. component->setBounds (destination);
  48147. }
  48148. private:
  48149. inline double timeToDistance (const double time) const
  48150. {
  48151. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48152. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48153. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48154. }
  48155. };
  48156. ComponentAnimator::ComponentAnimator()
  48157. : lastTime (0)
  48158. {
  48159. }
  48160. ComponentAnimator::~ComponentAnimator()
  48161. {
  48162. cancelAllAnimations (false);
  48163. jassert (tasks.size() == 0);
  48164. }
  48165. void* ComponentAnimator::findTaskFor (Component* const component) const
  48166. {
  48167. for (int i = tasks.size(); --i >= 0;)
  48168. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component.getComponent())
  48169. return tasks.getUnchecked(i);
  48170. return 0;
  48171. }
  48172. void ComponentAnimator::animateComponent (Component* const component,
  48173. const Rectangle<int>& finalPosition,
  48174. const int millisecondsToSpendMoving,
  48175. const double startSpeed,
  48176. const double endSpeed)
  48177. {
  48178. if (component != 0)
  48179. {
  48180. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48181. if (at == 0)
  48182. {
  48183. at = new AnimationTask (component);
  48184. tasks.add (at);
  48185. sendChangeMessage (this);
  48186. }
  48187. at->msElapsed = 0;
  48188. at->lastProgress = 0;
  48189. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48190. at->destination = finalPosition;
  48191. // the speeds must be 0 or greater!
  48192. jassert (startSpeed >= 0 && endSpeed >= 0)
  48193. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48194. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48195. at->midSpeed = invTotalDistance;
  48196. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48197. at->left = component->getX();
  48198. at->top = component->getY();
  48199. at->right = component->getRight();
  48200. at->bottom = component->getBottom();
  48201. if (! isTimerRunning())
  48202. {
  48203. lastTime = Time::getMillisecondCounter();
  48204. startTimer (1000 / 50);
  48205. }
  48206. }
  48207. }
  48208. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48209. {
  48210. for (int i = tasks.size(); --i >= 0;)
  48211. {
  48212. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48213. if (moveComponentsToTheirFinalPositions)
  48214. at->moveToFinalDestination();
  48215. delete at;
  48216. tasks.remove (i);
  48217. sendChangeMessage (this);
  48218. }
  48219. }
  48220. void ComponentAnimator::cancelAnimation (Component* const component,
  48221. const bool moveComponentToItsFinalPosition)
  48222. {
  48223. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48224. if (at != 0)
  48225. {
  48226. if (moveComponentToItsFinalPosition)
  48227. at->moveToFinalDestination();
  48228. tasks.removeValue (at);
  48229. delete at;
  48230. sendChangeMessage (this);
  48231. }
  48232. }
  48233. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48234. {
  48235. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48236. if (at != 0)
  48237. return at->destination;
  48238. else if (component != 0)
  48239. return component->getBounds();
  48240. return Rectangle<int>();
  48241. }
  48242. bool ComponentAnimator::isAnimating (Component* component) const
  48243. {
  48244. return findTaskFor (component) != 0;
  48245. }
  48246. void ComponentAnimator::timerCallback()
  48247. {
  48248. const uint32 timeNow = Time::getMillisecondCounter();
  48249. if (lastTime == 0 || lastTime == timeNow)
  48250. lastTime = timeNow;
  48251. const int elapsed = timeNow - lastTime;
  48252. for (int i = tasks.size(); --i >= 0;)
  48253. {
  48254. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48255. if (! at->useTimeslice (elapsed))
  48256. {
  48257. tasks.remove (i);
  48258. delete at;
  48259. sendChangeMessage (this);
  48260. }
  48261. }
  48262. lastTime = timeNow;
  48263. if (tasks.size() == 0)
  48264. stopTimer();
  48265. }
  48266. END_JUCE_NAMESPACE
  48267. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48268. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48269. BEGIN_JUCE_NAMESPACE
  48270. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48271. : minW (0),
  48272. maxW (0x3fffffff),
  48273. minH (0),
  48274. maxH (0x3fffffff),
  48275. minOffTop (0),
  48276. minOffLeft (0),
  48277. minOffBottom (0),
  48278. minOffRight (0),
  48279. aspectRatio (0.0)
  48280. {
  48281. }
  48282. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48283. {
  48284. }
  48285. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48286. {
  48287. minW = minimumWidth;
  48288. }
  48289. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48290. {
  48291. maxW = maximumWidth;
  48292. }
  48293. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48294. {
  48295. minH = minimumHeight;
  48296. }
  48297. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48298. {
  48299. maxH = maximumHeight;
  48300. }
  48301. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48302. {
  48303. jassert (maxW >= minimumWidth);
  48304. jassert (maxH >= minimumHeight);
  48305. jassert (minimumWidth > 0 && minimumHeight > 0);
  48306. minW = minimumWidth;
  48307. minH = minimumHeight;
  48308. if (minW > maxW)
  48309. maxW = minW;
  48310. if (minH > maxH)
  48311. maxH = minH;
  48312. }
  48313. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48314. {
  48315. jassert (maximumWidth >= minW);
  48316. jassert (maximumHeight >= minH);
  48317. jassert (maximumWidth > 0 && maximumHeight > 0);
  48318. maxW = jmax (minW, maximumWidth);
  48319. maxH = jmax (minH, maximumHeight);
  48320. }
  48321. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48322. const int minimumHeight,
  48323. const int maximumWidth,
  48324. const int maximumHeight) throw()
  48325. {
  48326. jassert (maximumWidth >= minimumWidth);
  48327. jassert (maximumHeight >= minimumHeight);
  48328. jassert (maximumWidth > 0 && maximumHeight > 0);
  48329. jassert (minimumWidth > 0 && minimumHeight > 0);
  48330. minW = jmax (0, minimumWidth);
  48331. minH = jmax (0, minimumHeight);
  48332. maxW = jmax (minW, maximumWidth);
  48333. maxH = jmax (minH, maximumHeight);
  48334. }
  48335. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48336. const int minimumWhenOffTheLeft,
  48337. const int minimumWhenOffTheBottom,
  48338. const int minimumWhenOffTheRight) throw()
  48339. {
  48340. minOffTop = minimumWhenOffTheTop;
  48341. minOffLeft = minimumWhenOffTheLeft;
  48342. minOffBottom = minimumWhenOffTheBottom;
  48343. minOffRight = minimumWhenOffTheRight;
  48344. }
  48345. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48346. {
  48347. aspectRatio = jmax (0.0, widthOverHeight);
  48348. }
  48349. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48350. {
  48351. return aspectRatio;
  48352. }
  48353. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48354. const Rectangle<int>& targetBounds,
  48355. const bool isStretchingTop,
  48356. const bool isStretchingLeft,
  48357. const bool isStretchingBottom,
  48358. const bool isStretchingRight)
  48359. {
  48360. jassert (component != 0);
  48361. Rectangle<int> limits, bounds (targetBounds);
  48362. BorderSize border;
  48363. Component* const parent = component->getParentComponent();
  48364. if (parent == 0)
  48365. {
  48366. ComponentPeer* peer = component->getPeer();
  48367. if (peer != 0)
  48368. border = peer->getFrameSize();
  48369. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48370. }
  48371. else
  48372. {
  48373. limits.setSize (parent->getWidth(), parent->getHeight());
  48374. }
  48375. border.addTo (bounds);
  48376. checkBounds (bounds,
  48377. border.addedTo (component->getBounds()), limits,
  48378. isStretchingTop, isStretchingLeft,
  48379. isStretchingBottom, isStretchingRight);
  48380. border.subtractFrom (bounds);
  48381. applyBoundsToComponent (component, bounds);
  48382. }
  48383. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48384. {
  48385. setBoundsForComponent (component, component->getBounds(),
  48386. false, false, false, false);
  48387. }
  48388. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48389. const Rectangle<int>& bounds)
  48390. {
  48391. component->setBounds (bounds);
  48392. }
  48393. void ComponentBoundsConstrainer::resizeStart()
  48394. {
  48395. }
  48396. void ComponentBoundsConstrainer::resizeEnd()
  48397. {
  48398. }
  48399. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48400. const Rectangle<int>& old,
  48401. const Rectangle<int>& limits,
  48402. const bool isStretchingTop,
  48403. const bool isStretchingLeft,
  48404. const bool isStretchingBottom,
  48405. const bool isStretchingRight)
  48406. {
  48407. int x = bounds.getX();
  48408. int y = bounds.getY();
  48409. int w = bounds.getWidth();
  48410. int h = bounds.getHeight();
  48411. // constrain the size if it's being stretched..
  48412. if (isStretchingLeft)
  48413. {
  48414. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48415. w = old.getRight() - x;
  48416. }
  48417. if (isStretchingRight)
  48418. {
  48419. w = jlimit (minW, maxW, w);
  48420. }
  48421. if (isStretchingTop)
  48422. {
  48423. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48424. h = old.getBottom() - y;
  48425. }
  48426. if (isStretchingBottom)
  48427. {
  48428. h = jlimit (minH, maxH, h);
  48429. }
  48430. // constrain the aspect ratio if one has been specified..
  48431. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48432. {
  48433. bool adjustWidth;
  48434. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48435. {
  48436. adjustWidth = true;
  48437. }
  48438. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48439. {
  48440. adjustWidth = false;
  48441. }
  48442. else
  48443. {
  48444. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48445. const double newRatio = fabs (w / (double) h);
  48446. adjustWidth = (oldRatio > newRatio);
  48447. }
  48448. if (adjustWidth)
  48449. {
  48450. w = roundToInt (h * aspectRatio);
  48451. if (w > maxW || w < minW)
  48452. {
  48453. w = jlimit (minW, maxW, w);
  48454. h = roundToInt (w / aspectRatio);
  48455. }
  48456. }
  48457. else
  48458. {
  48459. h = roundToInt (w / aspectRatio);
  48460. if (h > maxH || h < minH)
  48461. {
  48462. h = jlimit (minH, maxH, h);
  48463. w = roundToInt (h * aspectRatio);
  48464. }
  48465. }
  48466. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48467. {
  48468. x = old.getX() + (old.getWidth() - w) / 2;
  48469. }
  48470. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48471. {
  48472. y = old.getY() + (old.getHeight() - h) / 2;
  48473. }
  48474. else
  48475. {
  48476. if (isStretchingLeft)
  48477. x = old.getRight() - w;
  48478. if (isStretchingTop)
  48479. y = old.getBottom() - h;
  48480. }
  48481. }
  48482. // ...and constrain the position if limits have been set for that.
  48483. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48484. {
  48485. if (minOffTop > 0)
  48486. {
  48487. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48488. if (y < limit)
  48489. {
  48490. if (isStretchingTop)
  48491. h -= (limit - y);
  48492. y = limit;
  48493. }
  48494. }
  48495. if (minOffLeft > 0)
  48496. {
  48497. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48498. if (x < limit)
  48499. {
  48500. if (isStretchingLeft)
  48501. w -= (limit - x);
  48502. x = limit;
  48503. }
  48504. }
  48505. if (minOffBottom > 0)
  48506. {
  48507. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48508. if (y > limit)
  48509. {
  48510. if (isStretchingBottom)
  48511. h += (limit - y);
  48512. else
  48513. y = limit;
  48514. }
  48515. }
  48516. if (minOffRight > 0)
  48517. {
  48518. const int limit = limits.getRight() - jmin (minOffRight, w);
  48519. if (x > limit)
  48520. {
  48521. if (isStretchingRight)
  48522. w += (limit - x);
  48523. else
  48524. x = limit;
  48525. }
  48526. }
  48527. }
  48528. jassert (w >= 0 && h >= 0);
  48529. bounds = Rectangle<int> (x, y, w, h);
  48530. }
  48531. END_JUCE_NAMESPACE
  48532. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48533. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48534. BEGIN_JUCE_NAMESPACE
  48535. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48536. : component (component_),
  48537. lastPeer (0),
  48538. reentrant (false)
  48539. {
  48540. jassert (component != 0); // can't use this with a null pointer..
  48541. component->addComponentListener (this);
  48542. registerWithParentComps();
  48543. }
  48544. ComponentMovementWatcher::~ComponentMovementWatcher()
  48545. {
  48546. component->removeComponentListener (this);
  48547. unregister();
  48548. }
  48549. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48550. {
  48551. // agh! don't delete the target component without deleting this object first!
  48552. jassert (component != 0);
  48553. if (! reentrant)
  48554. {
  48555. reentrant = true;
  48556. ComponentPeer* const peer = component->getPeer();
  48557. if (peer != lastPeer)
  48558. {
  48559. componentPeerChanged();
  48560. if (component == 0)
  48561. return;
  48562. lastPeer = peer;
  48563. }
  48564. unregister();
  48565. registerWithParentComps();
  48566. reentrant = false;
  48567. componentMovedOrResized (*component, true, true);
  48568. }
  48569. }
  48570. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48571. {
  48572. // agh! don't delete the target component without deleting this object first!
  48573. jassert (component != 0);
  48574. if (wasMoved)
  48575. {
  48576. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48577. wasMoved = lastBounds.getPosition() != pos;
  48578. lastBounds.setPosition (pos);
  48579. }
  48580. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48581. lastBounds.setSize (component->getWidth(), component->getHeight());
  48582. if (wasMoved || wasResized)
  48583. componentMovedOrResized (wasMoved, wasResized);
  48584. }
  48585. void ComponentMovementWatcher::registerWithParentComps() throw()
  48586. {
  48587. Component* p = component->getParentComponent();
  48588. while (p != 0)
  48589. {
  48590. p->addComponentListener (this);
  48591. registeredParentComps.add (p);
  48592. p = p->getParentComponent();
  48593. }
  48594. }
  48595. void ComponentMovementWatcher::unregister() throw()
  48596. {
  48597. for (int i = registeredParentComps.size(); --i >= 0;)
  48598. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48599. registeredParentComps.clear();
  48600. }
  48601. END_JUCE_NAMESPACE
  48602. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48603. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48604. BEGIN_JUCE_NAMESPACE
  48605. GroupComponent::GroupComponent (const String& componentName,
  48606. const String& labelText)
  48607. : Component (componentName),
  48608. text (labelText),
  48609. justification (Justification::left)
  48610. {
  48611. setInterceptsMouseClicks (false, true);
  48612. }
  48613. GroupComponent::~GroupComponent()
  48614. {
  48615. }
  48616. void GroupComponent::setText (const String& newText)
  48617. {
  48618. if (text != newText)
  48619. {
  48620. text = newText;
  48621. repaint();
  48622. }
  48623. }
  48624. const String GroupComponent::getText() const
  48625. {
  48626. return text;
  48627. }
  48628. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48629. {
  48630. if (justification.getFlags() != newJustification.getFlags())
  48631. {
  48632. justification = newJustification;
  48633. repaint();
  48634. }
  48635. }
  48636. void GroupComponent::paint (Graphics& g)
  48637. {
  48638. getLookAndFeel()
  48639. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48640. text, justification,
  48641. *this);
  48642. }
  48643. void GroupComponent::enablementChanged()
  48644. {
  48645. repaint();
  48646. }
  48647. void GroupComponent::colourChanged()
  48648. {
  48649. repaint();
  48650. }
  48651. END_JUCE_NAMESPACE
  48652. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48653. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48654. BEGIN_JUCE_NAMESPACE
  48655. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48656. : DocumentWindow (String::empty, backgroundColour,
  48657. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48658. {
  48659. }
  48660. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48661. {
  48662. }
  48663. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48664. {
  48665. MultiDocumentPanel* const owner = getOwner();
  48666. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48667. if (owner != 0)
  48668. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48669. }
  48670. void MultiDocumentPanelWindow::closeButtonPressed()
  48671. {
  48672. MultiDocumentPanel* const owner = getOwner();
  48673. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48674. if (owner != 0)
  48675. owner->closeDocument (getContentComponent(), true);
  48676. }
  48677. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48678. {
  48679. DocumentWindow::activeWindowStatusChanged();
  48680. updateOrder();
  48681. }
  48682. void MultiDocumentPanelWindow::broughtToFront()
  48683. {
  48684. DocumentWindow::broughtToFront();
  48685. updateOrder();
  48686. }
  48687. void MultiDocumentPanelWindow::updateOrder()
  48688. {
  48689. MultiDocumentPanel* const owner = getOwner();
  48690. if (owner != 0)
  48691. owner->updateOrder();
  48692. }
  48693. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48694. {
  48695. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48696. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48697. }
  48698. class MDITabbedComponentInternal : public TabbedComponent
  48699. {
  48700. public:
  48701. MDITabbedComponentInternal()
  48702. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48703. {
  48704. }
  48705. ~MDITabbedComponentInternal()
  48706. {
  48707. }
  48708. void currentTabChanged (int, const String&)
  48709. {
  48710. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48711. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48712. if (owner != 0)
  48713. owner->updateOrder();
  48714. }
  48715. };
  48716. MultiDocumentPanel::MultiDocumentPanel()
  48717. : mode (MaximisedWindowsWithTabs),
  48718. tabComponent (0),
  48719. backgroundColour (Colours::lightblue),
  48720. maximumNumDocuments (0),
  48721. numDocsBeforeTabsUsed (0)
  48722. {
  48723. setOpaque (true);
  48724. }
  48725. MultiDocumentPanel::~MultiDocumentPanel()
  48726. {
  48727. closeAllDocuments (false);
  48728. }
  48729. static bool shouldDeleteComp (Component* const c)
  48730. {
  48731. return c->getProperties() ["mdiDocumentDelete_"];
  48732. }
  48733. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48734. {
  48735. while (components.size() > 0)
  48736. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48737. return false;
  48738. return true;
  48739. }
  48740. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48741. {
  48742. return new MultiDocumentPanelWindow (backgroundColour);
  48743. }
  48744. void MultiDocumentPanel::addWindow (Component* component)
  48745. {
  48746. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48747. dw->setResizable (true, false);
  48748. dw->setContentComponent (component, false, true);
  48749. dw->setName (component->getName());
  48750. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48751. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48752. int x = 4;
  48753. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48754. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48755. x += 16;
  48756. dw->setTopLeftPosition (x, x);
  48757. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48758. if (pos.toString().isNotEmpty())
  48759. dw->restoreWindowStateFromString (pos.toString());
  48760. addAndMakeVisible (dw);
  48761. dw->toFront (true);
  48762. }
  48763. bool MultiDocumentPanel::addDocument (Component* const component,
  48764. const Colour& docColour,
  48765. const bool deleteWhenRemoved)
  48766. {
  48767. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48768. // with a frame-within-a-frame! Just pass in the bare content component.
  48769. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48770. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48771. return false;
  48772. components.add (component);
  48773. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48774. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48775. component->addComponentListener (this);
  48776. if (mode == FloatingWindows)
  48777. {
  48778. if (isFullscreenWhenOneDocument())
  48779. {
  48780. if (components.size() == 1)
  48781. {
  48782. addAndMakeVisible (component);
  48783. }
  48784. else
  48785. {
  48786. if (components.size() == 2)
  48787. addWindow (components.getFirst());
  48788. addWindow (component);
  48789. }
  48790. }
  48791. else
  48792. {
  48793. addWindow (component);
  48794. }
  48795. }
  48796. else
  48797. {
  48798. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48799. {
  48800. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48801. Array <Component*> temp (components);
  48802. for (int i = 0; i < temp.size(); ++i)
  48803. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48804. resized();
  48805. }
  48806. else
  48807. {
  48808. if (tabComponent != 0)
  48809. tabComponent->addTab (component->getName(), docColour, component, false);
  48810. else
  48811. addAndMakeVisible (component);
  48812. }
  48813. setActiveDocument (component);
  48814. }
  48815. resized();
  48816. activeDocumentChanged();
  48817. return true;
  48818. }
  48819. bool MultiDocumentPanel::closeDocument (Component* component,
  48820. const bool checkItsOkToCloseFirst)
  48821. {
  48822. if (components.contains (component))
  48823. {
  48824. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48825. return false;
  48826. component->removeComponentListener (this);
  48827. const bool shouldDelete = shouldDeleteComp (component);
  48828. component->getProperties().remove ("mdiDocumentDelete_");
  48829. component->getProperties().remove ("mdiDocumentBkg_");
  48830. if (mode == FloatingWindows)
  48831. {
  48832. for (int i = getNumChildComponents(); --i >= 0;)
  48833. {
  48834. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48835. if (dw != 0 && dw->getContentComponent() == component)
  48836. {
  48837. dw->setContentComponent (0, false);
  48838. delete dw;
  48839. break;
  48840. }
  48841. }
  48842. if (shouldDelete)
  48843. delete component;
  48844. components.removeValue (component);
  48845. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48846. {
  48847. for (int i = getNumChildComponents(); --i >= 0;)
  48848. {
  48849. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48850. if (dw != 0)
  48851. {
  48852. dw->setContentComponent (0, false);
  48853. delete dw;
  48854. }
  48855. }
  48856. addAndMakeVisible (components.getFirst());
  48857. }
  48858. }
  48859. else
  48860. {
  48861. jassert (components.indexOf (component) >= 0);
  48862. if (tabComponent != 0)
  48863. {
  48864. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48865. if (tabComponent->getTabContentComponent (i) == component)
  48866. tabComponent->removeTab (i);
  48867. }
  48868. else
  48869. {
  48870. removeChildComponent (component);
  48871. }
  48872. if (shouldDelete)
  48873. delete component;
  48874. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48875. deleteAndZero (tabComponent);
  48876. components.removeValue (component);
  48877. if (components.size() > 0 && tabComponent == 0)
  48878. addAndMakeVisible (components.getFirst());
  48879. }
  48880. resized();
  48881. activeDocumentChanged();
  48882. }
  48883. else
  48884. {
  48885. jassertfalse
  48886. }
  48887. return true;
  48888. }
  48889. int MultiDocumentPanel::getNumDocuments() const throw()
  48890. {
  48891. return components.size();
  48892. }
  48893. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48894. {
  48895. return components [index];
  48896. }
  48897. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48898. {
  48899. if (mode == FloatingWindows)
  48900. {
  48901. for (int i = getNumChildComponents(); --i >= 0;)
  48902. {
  48903. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48904. if (dw != 0 && dw->isActiveWindow())
  48905. return dw->getContentComponent();
  48906. }
  48907. }
  48908. return components.getLast();
  48909. }
  48910. void MultiDocumentPanel::setActiveDocument (Component* component)
  48911. {
  48912. if (mode == FloatingWindows)
  48913. {
  48914. component = getContainerComp (component);
  48915. if (component != 0)
  48916. component->toFront (true);
  48917. }
  48918. else if (tabComponent != 0)
  48919. {
  48920. jassert (components.indexOf (component) >= 0);
  48921. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48922. {
  48923. if (tabComponent->getTabContentComponent (i) == component)
  48924. {
  48925. tabComponent->setCurrentTabIndex (i);
  48926. break;
  48927. }
  48928. }
  48929. }
  48930. else
  48931. {
  48932. component->grabKeyboardFocus();
  48933. }
  48934. }
  48935. void MultiDocumentPanel::activeDocumentChanged()
  48936. {
  48937. }
  48938. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  48939. {
  48940. maximumNumDocuments = newNumber;
  48941. }
  48942. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  48943. {
  48944. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  48945. }
  48946. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  48947. {
  48948. return numDocsBeforeTabsUsed != 0;
  48949. }
  48950. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  48951. {
  48952. if (mode != newLayoutMode)
  48953. {
  48954. mode = newLayoutMode;
  48955. if (mode == FloatingWindows)
  48956. {
  48957. deleteAndZero (tabComponent);
  48958. }
  48959. else
  48960. {
  48961. for (int i = getNumChildComponents(); --i >= 0;)
  48962. {
  48963. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48964. if (dw != 0)
  48965. {
  48966. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  48967. dw->setContentComponent (0, false);
  48968. delete dw;
  48969. }
  48970. }
  48971. }
  48972. resized();
  48973. const Array <Component*> tempComps (components);
  48974. components.clear();
  48975. for (int i = 0; i < tempComps.size(); ++i)
  48976. {
  48977. Component* const c = tempComps.getUnchecked(i);
  48978. addDocument (c,
  48979. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  48980. shouldDeleteComp (c));
  48981. }
  48982. }
  48983. }
  48984. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  48985. {
  48986. if (backgroundColour != newBackgroundColour)
  48987. {
  48988. backgroundColour = newBackgroundColour;
  48989. setOpaque (newBackgroundColour.isOpaque());
  48990. repaint();
  48991. }
  48992. }
  48993. void MultiDocumentPanel::paint (Graphics& g)
  48994. {
  48995. g.fillAll (backgroundColour);
  48996. }
  48997. void MultiDocumentPanel::resized()
  48998. {
  48999. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49000. {
  49001. for (int i = getNumChildComponents(); --i >= 0;)
  49002. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49003. }
  49004. setWantsKeyboardFocus (components.size() == 0);
  49005. }
  49006. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49007. {
  49008. if (mode == FloatingWindows)
  49009. {
  49010. for (int i = 0; i < getNumChildComponents(); ++i)
  49011. {
  49012. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49013. if (dw != 0 && dw->getContentComponent() == c)
  49014. {
  49015. c = dw;
  49016. break;
  49017. }
  49018. }
  49019. }
  49020. return c;
  49021. }
  49022. void MultiDocumentPanel::componentNameChanged (Component&)
  49023. {
  49024. if (mode == FloatingWindows)
  49025. {
  49026. for (int i = 0; i < getNumChildComponents(); ++i)
  49027. {
  49028. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49029. if (dw != 0)
  49030. dw->setName (dw->getContentComponent()->getName());
  49031. }
  49032. }
  49033. else if (tabComponent != 0)
  49034. {
  49035. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49036. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49037. }
  49038. }
  49039. void MultiDocumentPanel::updateOrder()
  49040. {
  49041. const Array <Component*> oldList (components);
  49042. if (mode == FloatingWindows)
  49043. {
  49044. components.clear();
  49045. for (int i = 0; i < getNumChildComponents(); ++i)
  49046. {
  49047. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49048. if (dw != 0)
  49049. components.add (dw->getContentComponent());
  49050. }
  49051. }
  49052. else
  49053. {
  49054. if (tabComponent != 0)
  49055. {
  49056. Component* const current = tabComponent->getCurrentContentComponent();
  49057. if (current != 0)
  49058. {
  49059. components.removeValue (current);
  49060. components.add (current);
  49061. }
  49062. }
  49063. }
  49064. if (components != oldList)
  49065. activeDocumentChanged();
  49066. }
  49067. END_JUCE_NAMESPACE
  49068. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49069. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49070. BEGIN_JUCE_NAMESPACE
  49071. ResizableBorderComponent::Zone::Zone (int zoneFlags) throw()
  49072. : zone (zoneFlags)
  49073. {
  49074. }
  49075. ResizableBorderComponent::Zone::Zone (const ResizableBorderComponent::Zone& other) throw() : zone (other.zone) {}
  49076. ResizableBorderComponent::Zone& ResizableBorderComponent::Zone::operator= (const ResizableBorderComponent::Zone& other) throw() { zone = other.zone; return *this; }
  49077. bool ResizableBorderComponent::Zone::operator== (const ResizableBorderComponent::Zone& other) const throw() { return zone == other.zone; }
  49078. bool ResizableBorderComponent::Zone::operator!= (const ResizableBorderComponent::Zone& other) const throw() { return zone != other.zone; }
  49079. const ResizableBorderComponent::Zone ResizableBorderComponent::Zone::fromPositionOnBorder (const Rectangle<int>& totalSize,
  49080. const BorderSize& border,
  49081. const Point<int>& position)
  49082. {
  49083. int z = 0;
  49084. if (totalSize.contains (position)
  49085. && ! border.subtractedFrom (totalSize).contains (position))
  49086. {
  49087. const int minW = jmax (totalSize.getWidth() / 10, jmin (10, totalSize.getWidth() / 3));
  49088. if (position.getX() < jmax (border.getLeft(), minW))
  49089. z |= left;
  49090. else if (position.getX() >= totalSize.getWidth() - jmax (border.getRight(), minW))
  49091. z |= right;
  49092. const int minH = jmax (totalSize.getHeight() / 10, jmin (10, totalSize.getHeight() / 3));
  49093. if (position.getY() < jmax (border.getTop(), minH))
  49094. z |= top;
  49095. else if (position.getY() >= totalSize.getHeight() - jmax (border.getBottom(), minH))
  49096. z |= bottom;
  49097. }
  49098. return Zone (z);
  49099. }
  49100. const MouseCursor ResizableBorderComponent::Zone::getMouseCursor() const throw()
  49101. {
  49102. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49103. switch (zone)
  49104. {
  49105. case (left | top): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49106. case top: mc = MouseCursor::TopEdgeResizeCursor; break;
  49107. case (right | top): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49108. case left: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49109. case right: mc = MouseCursor::RightEdgeResizeCursor; break;
  49110. case (left | bottom): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49111. case bottom: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49112. case (right | bottom): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49113. default: break;
  49114. }
  49115. return mc;
  49116. }
  49117. const Rectangle<int> ResizableBorderComponent::Zone::resizeRectangleBy (Rectangle<int> b, const Point<int>& offset) const throw()
  49118. {
  49119. if (isDraggingWholeObject())
  49120. return b + offset;
  49121. if (isDraggingLeftEdge())
  49122. b.setLeft (b.getX() + offset.getX());
  49123. if (isDraggingRightEdge())
  49124. b.setWidth (jmax (0, b.getWidth() + offset.getX()));
  49125. if (isDraggingTopEdge())
  49126. b.setTop (b.getY() + offset.getY());
  49127. if (isDraggingBottomEdge())
  49128. b.setHeight (jmax (0, b.getHeight() + offset.getY()));
  49129. return b;
  49130. }
  49131. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49132. ComponentBoundsConstrainer* const constrainer_)
  49133. : component (componentToResize),
  49134. constrainer (constrainer_),
  49135. borderSize (5),
  49136. mouseZone (0)
  49137. {
  49138. }
  49139. ResizableBorderComponent::~ResizableBorderComponent()
  49140. {
  49141. }
  49142. void ResizableBorderComponent::paint (Graphics& g)
  49143. {
  49144. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49145. }
  49146. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49147. {
  49148. updateMouseZone (e);
  49149. }
  49150. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49151. {
  49152. updateMouseZone (e);
  49153. }
  49154. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49155. {
  49156. if (component == 0)
  49157. {
  49158. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49159. return;
  49160. }
  49161. updateMouseZone (e);
  49162. originalBounds = component->getBounds();
  49163. if (constrainer != 0)
  49164. constrainer->resizeStart();
  49165. }
  49166. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49167. {
  49168. if (component == 0)
  49169. {
  49170. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49171. return;
  49172. }
  49173. const Rectangle<int> bounds (mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart()));
  49174. if (constrainer != 0)
  49175. constrainer->setBoundsForComponent (component, bounds,
  49176. mouseZone.isDraggingTopEdge(),
  49177. mouseZone.isDraggingLeftEdge(),
  49178. mouseZone.isDraggingBottomEdge(),
  49179. mouseZone.isDraggingRightEdge());
  49180. else
  49181. component->setBounds (bounds);
  49182. }
  49183. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49184. {
  49185. if (constrainer != 0)
  49186. constrainer->resizeEnd();
  49187. }
  49188. bool ResizableBorderComponent::hitTest (int x, int y)
  49189. {
  49190. return x < borderSize.getLeft()
  49191. || x >= getWidth() - borderSize.getRight()
  49192. || y < borderSize.getTop()
  49193. || y >= getHeight() - borderSize.getBottom();
  49194. }
  49195. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49196. {
  49197. if (borderSize != newBorderSize)
  49198. {
  49199. borderSize = newBorderSize;
  49200. repaint();
  49201. }
  49202. }
  49203. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49204. {
  49205. return borderSize;
  49206. }
  49207. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49208. {
  49209. Zone newZone (Zone::fromPositionOnBorder (getLocalBounds(), borderSize, e.getPosition()));
  49210. if (mouseZone != newZone)
  49211. {
  49212. mouseZone = newZone;
  49213. setMouseCursor (newZone.getMouseCursor());
  49214. }
  49215. }
  49216. END_JUCE_NAMESPACE
  49217. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49218. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49219. BEGIN_JUCE_NAMESPACE
  49220. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49221. ComponentBoundsConstrainer* const constrainer_)
  49222. : component (componentToResize),
  49223. constrainer (constrainer_)
  49224. {
  49225. setRepaintsOnMouseActivity (true);
  49226. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49227. }
  49228. ResizableCornerComponent::~ResizableCornerComponent()
  49229. {
  49230. }
  49231. void ResizableCornerComponent::paint (Graphics& g)
  49232. {
  49233. getLookAndFeel()
  49234. .drawCornerResizer (g, getWidth(), getHeight(),
  49235. isMouseOverOrDragging(),
  49236. isMouseButtonDown());
  49237. }
  49238. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49239. {
  49240. if (component == 0)
  49241. {
  49242. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49243. return;
  49244. }
  49245. originalBounds = component->getBounds();
  49246. if (constrainer != 0)
  49247. constrainer->resizeStart();
  49248. }
  49249. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49250. {
  49251. if (component == 0)
  49252. {
  49253. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49254. return;
  49255. }
  49256. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49257. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49258. if (constrainer != 0)
  49259. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49260. else
  49261. component->setBounds (r);
  49262. }
  49263. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49264. {
  49265. if (constrainer != 0)
  49266. constrainer->resizeStart();
  49267. }
  49268. bool ResizableCornerComponent::hitTest (int x, int y)
  49269. {
  49270. if (getWidth() <= 0)
  49271. return false;
  49272. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49273. return y >= yAtX - getHeight() / 4;
  49274. }
  49275. END_JUCE_NAMESPACE
  49276. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49277. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49278. BEGIN_JUCE_NAMESPACE
  49279. class ScrollBar::ScrollbarButton : public Button
  49280. {
  49281. public:
  49282. int direction;
  49283. ScrollbarButton (const int direction_, ScrollBar& owner_)
  49284. : Button (String::empty),
  49285. direction (direction_),
  49286. owner (owner_)
  49287. {
  49288. setWantsKeyboardFocus (false);
  49289. }
  49290. ~ScrollbarButton()
  49291. {
  49292. }
  49293. void paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  49294. {
  49295. getLookAndFeel()
  49296. .drawScrollbarButton (g, owner,
  49297. getWidth(), getHeight(),
  49298. direction,
  49299. owner.isVertical(),
  49300. isMouseOver, isMouseDown);
  49301. }
  49302. void clicked()
  49303. {
  49304. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49305. }
  49306. juce_UseDebuggingNewOperator
  49307. private:
  49308. ScrollBar& owner;
  49309. ScrollbarButton (const ScrollbarButton&);
  49310. ScrollbarButton& operator= (const ScrollbarButton&);
  49311. };
  49312. ScrollBar::ScrollBar (const bool vertical_,
  49313. const bool buttonsAreVisible)
  49314. : totalRange (0.0, 1.0),
  49315. visibleRange (0.0, 0.1),
  49316. singleStepSize (0.1),
  49317. thumbAreaStart (0),
  49318. thumbAreaSize (0),
  49319. thumbStart (0),
  49320. thumbSize (0),
  49321. initialDelayInMillisecs (100),
  49322. repeatDelayInMillisecs (50),
  49323. minimumDelayInMillisecs (10),
  49324. vertical (vertical_),
  49325. isDraggingThumb (false),
  49326. alwaysVisible (false),
  49327. upButton (0),
  49328. downButton (0)
  49329. {
  49330. setButtonVisibility (buttonsAreVisible);
  49331. setRepaintsOnMouseActivity (true);
  49332. setFocusContainer (true);
  49333. }
  49334. ScrollBar::~ScrollBar()
  49335. {
  49336. deleteAllChildren();
  49337. }
  49338. void ScrollBar::setRangeLimits (const Range<double>& newRangeLimit)
  49339. {
  49340. if (totalRange != newRangeLimit)
  49341. {
  49342. totalRange = newRangeLimit;
  49343. setCurrentRange (visibleRange);
  49344. updateThumbPosition();
  49345. }
  49346. }
  49347. void ScrollBar::setRangeLimits (const double newMinimum, const double newMaximum)
  49348. {
  49349. jassert (newMaximum >= newMinimum); // these can't be the wrong way round!
  49350. setRangeLimits (Range<double> (newMinimum, newMaximum));
  49351. }
  49352. void ScrollBar::setCurrentRange (const Range<double>& newRange)
  49353. {
  49354. const Range<double> constrainedRange (totalRange.constrainRange (newRange));
  49355. if (visibleRange != constrainedRange)
  49356. {
  49357. visibleRange = constrainedRange;
  49358. updateThumbPosition();
  49359. triggerAsyncUpdate();
  49360. }
  49361. }
  49362. void ScrollBar::setCurrentRange (const double newStart, const double newSize)
  49363. {
  49364. setCurrentRange (Range<double> (newStart, newStart + newSize));
  49365. }
  49366. void ScrollBar::setCurrentRangeStart (const double newStart)
  49367. {
  49368. setCurrentRange (visibleRange.movedToStartAt (newStart));
  49369. }
  49370. void ScrollBar::setSingleStepSize (const double newSingleStepSize)
  49371. {
  49372. singleStepSize = newSingleStepSize;
  49373. }
  49374. void ScrollBar::moveScrollbarInSteps (const int howManySteps)
  49375. {
  49376. setCurrentRange (visibleRange + howManySteps * singleStepSize);
  49377. }
  49378. void ScrollBar::moveScrollbarInPages (const int howManyPages)
  49379. {
  49380. setCurrentRange (visibleRange + howManyPages * visibleRange.getLength());
  49381. }
  49382. void ScrollBar::scrollToTop()
  49383. {
  49384. setCurrentRange (visibleRange.movedToStartAt (getMinimumRangeLimit()));
  49385. }
  49386. void ScrollBar::scrollToBottom()
  49387. {
  49388. setCurrentRange (visibleRange.movedToEndAt (getMaximumRangeLimit()));
  49389. }
  49390. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49391. const int repeatDelayInMillisecs_,
  49392. const int minimumDelayInMillisecs_)
  49393. {
  49394. initialDelayInMillisecs = initialDelayInMillisecs_;
  49395. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49396. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49397. if (upButton != 0)
  49398. {
  49399. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49400. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49401. }
  49402. }
  49403. void ScrollBar::addListener (ScrollBarListener* const listener)
  49404. {
  49405. listeners.add (listener);
  49406. }
  49407. void ScrollBar::removeListener (ScrollBarListener* const listener)
  49408. {
  49409. listeners.remove (listener);
  49410. }
  49411. void ScrollBar::handleAsyncUpdate()
  49412. {
  49413. double start = visibleRange.getStart(); // (need to use a temp variable for VC7 compatibility)
  49414. listeners.call (&ScrollBarListener::scrollBarMoved, this, start);
  49415. }
  49416. void ScrollBar::updateThumbPosition()
  49417. {
  49418. int newThumbSize = roundToInt (totalRange.getLength() > 0 ? (visibleRange.getLength() * thumbAreaSize) / totalRange.getLength()
  49419. : thumbAreaSize);
  49420. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49421. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49422. if (newThumbSize > thumbAreaSize)
  49423. newThumbSize = thumbAreaSize;
  49424. int newThumbStart = thumbAreaStart;
  49425. if (totalRange.getLength() > visibleRange.getLength())
  49426. newThumbStart += roundToInt (((visibleRange.getStart() - totalRange.getStart()) * (thumbAreaSize - newThumbSize))
  49427. / (totalRange.getLength() - visibleRange.getLength()));
  49428. setVisible (alwaysVisible || (totalRange.getLength() > visibleRange.getLength() && visibleRange.getLength() > 0.0));
  49429. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49430. {
  49431. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49432. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49433. if (vertical)
  49434. repaint (0, repaintStart, getWidth(), repaintSize);
  49435. else
  49436. repaint (repaintStart, 0, repaintSize, getHeight());
  49437. thumbStart = newThumbStart;
  49438. thumbSize = newThumbSize;
  49439. }
  49440. }
  49441. void ScrollBar::setOrientation (const bool shouldBeVertical)
  49442. {
  49443. if (vertical != shouldBeVertical)
  49444. {
  49445. vertical = shouldBeVertical;
  49446. if (upButton != 0)
  49447. {
  49448. upButton->direction = vertical ? 0 : 3;
  49449. downButton->direction = vertical ? 2 : 1;
  49450. }
  49451. updateThumbPosition();
  49452. }
  49453. }
  49454. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49455. {
  49456. delete upButton;
  49457. upButton = 0;
  49458. delete downButton;
  49459. downButton = 0;
  49460. if (buttonsAreVisible)
  49461. {
  49462. addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this));
  49463. addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this));
  49464. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49465. }
  49466. updateThumbPosition();
  49467. }
  49468. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49469. {
  49470. alwaysVisible = ! shouldHideWhenFullRange;
  49471. updateThumbPosition();
  49472. }
  49473. void ScrollBar::paint (Graphics& g)
  49474. {
  49475. if (thumbAreaSize > 0)
  49476. {
  49477. LookAndFeel& lf = getLookAndFeel();
  49478. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49479. ? thumbSize : 0;
  49480. if (vertical)
  49481. {
  49482. lf.drawScrollbar (g, *this,
  49483. 0, thumbAreaStart,
  49484. getWidth(), thumbAreaSize,
  49485. vertical,
  49486. thumbStart, thumb,
  49487. isMouseOver(), isMouseButtonDown());
  49488. }
  49489. else
  49490. {
  49491. lf.drawScrollbar (g, *this,
  49492. thumbAreaStart, 0,
  49493. thumbAreaSize, getHeight(),
  49494. vertical,
  49495. thumbStart, thumb,
  49496. isMouseOver(), isMouseButtonDown());
  49497. }
  49498. }
  49499. }
  49500. void ScrollBar::lookAndFeelChanged()
  49501. {
  49502. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49503. }
  49504. void ScrollBar::resized()
  49505. {
  49506. const int length = ((vertical) ? getHeight() : getWidth());
  49507. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49508. : 0;
  49509. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49510. {
  49511. thumbAreaStart = length >> 1;
  49512. thumbAreaSize = 0;
  49513. }
  49514. else
  49515. {
  49516. thumbAreaStart = buttonSize;
  49517. thumbAreaSize = length - (buttonSize << 1);
  49518. }
  49519. if (upButton != 0)
  49520. {
  49521. if (vertical)
  49522. {
  49523. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49524. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49525. }
  49526. else
  49527. {
  49528. upButton->setBounds (0, 0, buttonSize, getHeight());
  49529. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49530. }
  49531. }
  49532. updateThumbPosition();
  49533. }
  49534. void ScrollBar::mouseDown (const MouseEvent& e)
  49535. {
  49536. isDraggingThumb = false;
  49537. lastMousePos = vertical ? e.y : e.x;
  49538. dragStartMousePos = lastMousePos;
  49539. dragStartRange = visibleRange.getStart();
  49540. if (dragStartMousePos < thumbStart)
  49541. {
  49542. moveScrollbarInPages (-1);
  49543. startTimer (400);
  49544. }
  49545. else if (dragStartMousePos >= thumbStart + thumbSize)
  49546. {
  49547. moveScrollbarInPages (1);
  49548. startTimer (400);
  49549. }
  49550. else
  49551. {
  49552. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49553. && (thumbAreaSize > thumbSize);
  49554. }
  49555. }
  49556. void ScrollBar::mouseDrag (const MouseEvent& e)
  49557. {
  49558. if (isDraggingThumb)
  49559. {
  49560. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49561. setCurrentRangeStart (dragStartRange
  49562. + deltaPixels * (totalRange.getLength() - visibleRange.getLength())
  49563. / (thumbAreaSize - thumbSize));
  49564. }
  49565. else
  49566. {
  49567. lastMousePos = (vertical) ? e.y : e.x;
  49568. }
  49569. }
  49570. void ScrollBar::mouseUp (const MouseEvent&)
  49571. {
  49572. isDraggingThumb = false;
  49573. stopTimer();
  49574. repaint();
  49575. }
  49576. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49577. float wheelIncrementX,
  49578. float wheelIncrementY)
  49579. {
  49580. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49581. if (increment < 0)
  49582. increment = jmin (increment * 10.0f, -1.0f);
  49583. else if (increment > 0)
  49584. increment = jmax (increment * 10.0f, 1.0f);
  49585. setCurrentRange (visibleRange - singleStepSize * increment);
  49586. }
  49587. void ScrollBar::timerCallback()
  49588. {
  49589. if (isMouseButtonDown())
  49590. {
  49591. startTimer (40);
  49592. if (lastMousePos < thumbStart)
  49593. setCurrentRange (visibleRange - visibleRange.getLength());
  49594. else if (lastMousePos > thumbStart + thumbSize)
  49595. setCurrentRangeStart (visibleRange.getEnd());
  49596. }
  49597. else
  49598. {
  49599. stopTimer();
  49600. }
  49601. }
  49602. bool ScrollBar::keyPressed (const KeyPress& key)
  49603. {
  49604. if (! isVisible())
  49605. return false;
  49606. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49607. moveScrollbarInSteps (-1);
  49608. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49609. moveScrollbarInSteps (1);
  49610. else if (key.isKeyCode (KeyPress::pageUpKey))
  49611. moveScrollbarInPages (-1);
  49612. else if (key.isKeyCode (KeyPress::pageDownKey))
  49613. moveScrollbarInPages (1);
  49614. else if (key.isKeyCode (KeyPress::homeKey))
  49615. scrollToTop();
  49616. else if (key.isKeyCode (KeyPress::endKey))
  49617. scrollToBottom();
  49618. else
  49619. return false;
  49620. return true;
  49621. }
  49622. END_JUCE_NAMESPACE
  49623. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49624. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49625. BEGIN_JUCE_NAMESPACE
  49626. StretchableLayoutManager::StretchableLayoutManager()
  49627. : totalSize (0)
  49628. {
  49629. }
  49630. StretchableLayoutManager::~StretchableLayoutManager()
  49631. {
  49632. }
  49633. void StretchableLayoutManager::clearAllItems()
  49634. {
  49635. items.clear();
  49636. totalSize = 0;
  49637. }
  49638. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49639. const double minimumSize,
  49640. const double maximumSize,
  49641. const double preferredSize)
  49642. {
  49643. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49644. if (layout == 0)
  49645. {
  49646. layout = new ItemLayoutProperties();
  49647. layout->itemIndex = itemIndex;
  49648. int i;
  49649. for (i = 0; i < items.size(); ++i)
  49650. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49651. break;
  49652. items.insert (i, layout);
  49653. }
  49654. layout->minSize = minimumSize;
  49655. layout->maxSize = maximumSize;
  49656. layout->preferredSize = preferredSize;
  49657. layout->currentSize = 0;
  49658. }
  49659. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49660. double& minimumSize,
  49661. double& maximumSize,
  49662. double& preferredSize) const
  49663. {
  49664. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49665. if (layout != 0)
  49666. {
  49667. minimumSize = layout->minSize;
  49668. maximumSize = layout->maxSize;
  49669. preferredSize = layout->preferredSize;
  49670. return true;
  49671. }
  49672. return false;
  49673. }
  49674. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49675. {
  49676. totalSize = newTotalSize;
  49677. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49678. }
  49679. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49680. {
  49681. int pos = 0;
  49682. for (int i = 0; i < itemIndex; ++i)
  49683. {
  49684. const ItemLayoutProperties* const layout = getInfoFor (i);
  49685. if (layout != 0)
  49686. pos += layout->currentSize;
  49687. }
  49688. return pos;
  49689. }
  49690. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49691. {
  49692. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49693. if (layout != 0)
  49694. return layout->currentSize;
  49695. return 0;
  49696. }
  49697. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49698. {
  49699. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49700. if (layout != 0)
  49701. return -layout->currentSize / (double) totalSize;
  49702. return 0;
  49703. }
  49704. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49705. int newPosition)
  49706. {
  49707. for (int i = items.size(); --i >= 0;)
  49708. {
  49709. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49710. if (layout->itemIndex == itemIndex)
  49711. {
  49712. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49713. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49714. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49715. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49716. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49717. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49718. endPos += layout->currentSize;
  49719. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49720. updatePrefSizesToMatchCurrentPositions();
  49721. break;
  49722. }
  49723. }
  49724. }
  49725. void StretchableLayoutManager::layOutComponents (Component** const components,
  49726. int numComponents,
  49727. int x, int y, int w, int h,
  49728. const bool vertically,
  49729. const bool resizeOtherDimension)
  49730. {
  49731. setTotalSize (vertically ? h : w);
  49732. int pos = vertically ? y : x;
  49733. for (int i = 0; i < numComponents; ++i)
  49734. {
  49735. const ItemLayoutProperties* const layout = getInfoFor (i);
  49736. if (layout != 0)
  49737. {
  49738. Component* const c = components[i];
  49739. if (c != 0)
  49740. {
  49741. if (i == numComponents - 1)
  49742. {
  49743. // if it's the last item, crop it to exactly fit the available space..
  49744. if (resizeOtherDimension)
  49745. {
  49746. if (vertically)
  49747. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49748. else
  49749. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49750. }
  49751. else
  49752. {
  49753. if (vertically)
  49754. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49755. else
  49756. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49757. }
  49758. }
  49759. else
  49760. {
  49761. if (resizeOtherDimension)
  49762. {
  49763. if (vertically)
  49764. c->setBounds (x, pos, w, layout->currentSize);
  49765. else
  49766. c->setBounds (pos, y, layout->currentSize, h);
  49767. }
  49768. else
  49769. {
  49770. if (vertically)
  49771. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49772. else
  49773. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49774. }
  49775. }
  49776. }
  49777. pos += layout->currentSize;
  49778. }
  49779. }
  49780. }
  49781. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49782. {
  49783. for (int i = items.size(); --i >= 0;)
  49784. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49785. return items.getUnchecked(i);
  49786. return 0;
  49787. }
  49788. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49789. const int endIndex,
  49790. const int availableSpace,
  49791. int startPos)
  49792. {
  49793. // calculate the total sizes
  49794. int i;
  49795. double totalIdealSize = 0.0;
  49796. int totalMinimums = 0;
  49797. for (i = startIndex; i < endIndex; ++i)
  49798. {
  49799. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49800. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49801. totalMinimums += layout->currentSize;
  49802. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49803. }
  49804. if (totalIdealSize <= 0)
  49805. totalIdealSize = 1.0;
  49806. // now calc the best sizes..
  49807. int extraSpace = availableSpace - totalMinimums;
  49808. while (extraSpace > 0)
  49809. {
  49810. int numWantingMoreSpace = 0;
  49811. int numHavingTakenExtraSpace = 0;
  49812. // first figure out how many comps want a slice of the extra space..
  49813. for (i = startIndex; i < endIndex; ++i)
  49814. {
  49815. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49816. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49817. const int bestSize = jlimit (layout->currentSize,
  49818. jmax (layout->currentSize,
  49819. sizeToRealSize (layout->maxSize, totalSize)),
  49820. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49821. if (bestSize > layout->currentSize)
  49822. ++numWantingMoreSpace;
  49823. }
  49824. // ..share out the extra space..
  49825. for (i = startIndex; i < endIndex; ++i)
  49826. {
  49827. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49828. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49829. int bestSize = jlimit (layout->currentSize,
  49830. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49831. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49832. const int extraWanted = bestSize - layout->currentSize;
  49833. if (extraWanted > 0)
  49834. {
  49835. const int extraAllowed = jmin (extraWanted,
  49836. extraSpace / jmax (1, numWantingMoreSpace));
  49837. if (extraAllowed > 0)
  49838. {
  49839. ++numHavingTakenExtraSpace;
  49840. --numWantingMoreSpace;
  49841. layout->currentSize += extraAllowed;
  49842. extraSpace -= extraAllowed;
  49843. }
  49844. }
  49845. }
  49846. if (numHavingTakenExtraSpace <= 0)
  49847. break;
  49848. }
  49849. // ..and calculate the end position
  49850. for (i = startIndex; i < endIndex; ++i)
  49851. {
  49852. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49853. startPos += layout->currentSize;
  49854. }
  49855. return startPos;
  49856. }
  49857. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49858. const int endIndex) const
  49859. {
  49860. int totalMinimums = 0;
  49861. for (int i = startIndex; i < endIndex; ++i)
  49862. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49863. return totalMinimums;
  49864. }
  49865. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49866. {
  49867. int totalMaximums = 0;
  49868. for (int i = startIndex; i < endIndex; ++i)
  49869. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49870. return totalMaximums;
  49871. }
  49872. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49873. {
  49874. for (int i = 0; i < items.size(); ++i)
  49875. {
  49876. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49877. layout->preferredSize
  49878. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49879. : getItemCurrentAbsoluteSize (i);
  49880. }
  49881. }
  49882. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49883. {
  49884. if (size < 0)
  49885. size *= -totalSpace;
  49886. return roundToInt (size);
  49887. }
  49888. END_JUCE_NAMESPACE
  49889. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49890. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49891. BEGIN_JUCE_NAMESPACE
  49892. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49893. const int itemIndex_,
  49894. const bool isVertical_)
  49895. : layout (layout_),
  49896. itemIndex (itemIndex_),
  49897. isVertical (isVertical_)
  49898. {
  49899. setRepaintsOnMouseActivity (true);
  49900. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49901. : MouseCursor::UpDownResizeCursor));
  49902. }
  49903. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49904. {
  49905. }
  49906. void StretchableLayoutResizerBar::paint (Graphics& g)
  49907. {
  49908. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49909. getWidth(), getHeight(),
  49910. isVertical,
  49911. isMouseOver(),
  49912. isMouseButtonDown());
  49913. }
  49914. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  49915. {
  49916. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  49917. }
  49918. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  49919. {
  49920. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  49921. : e.getDistanceFromDragStartY());
  49922. layout->setItemPosition (itemIndex, desiredPos);
  49923. hasBeenMoved();
  49924. }
  49925. void StretchableLayoutResizerBar::hasBeenMoved()
  49926. {
  49927. if (getParentComponent() != 0)
  49928. getParentComponent()->resized();
  49929. }
  49930. END_JUCE_NAMESPACE
  49931. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49932. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  49933. BEGIN_JUCE_NAMESPACE
  49934. StretchableObjectResizer::StretchableObjectResizer()
  49935. {
  49936. }
  49937. StretchableObjectResizer::~StretchableObjectResizer()
  49938. {
  49939. }
  49940. void StretchableObjectResizer::addItem (const double size,
  49941. const double minSize, const double maxSize,
  49942. const int order)
  49943. {
  49944. // the order must be >= 0 but less than the maximum integer value.
  49945. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  49946. Item* const item = new Item();
  49947. item->size = size;
  49948. item->minSize = minSize;
  49949. item->maxSize = maxSize;
  49950. item->order = order;
  49951. items.add (item);
  49952. }
  49953. double StretchableObjectResizer::getItemSize (const int index) const throw()
  49954. {
  49955. const Item* const it = items [index];
  49956. return it != 0 ? it->size : 0;
  49957. }
  49958. void StretchableObjectResizer::resizeToFit (const double targetSize)
  49959. {
  49960. int order = 0;
  49961. for (;;)
  49962. {
  49963. double currentSize = 0;
  49964. double minSize = 0;
  49965. double maxSize = 0;
  49966. int nextHighestOrder = std::numeric_limits<int>::max();
  49967. for (int i = 0; i < items.size(); ++i)
  49968. {
  49969. const Item* const it = items.getUnchecked(i);
  49970. currentSize += it->size;
  49971. if (it->order <= order)
  49972. {
  49973. minSize += it->minSize;
  49974. maxSize += it->maxSize;
  49975. }
  49976. else
  49977. {
  49978. minSize += it->size;
  49979. maxSize += it->size;
  49980. nextHighestOrder = jmin (nextHighestOrder, it->order);
  49981. }
  49982. }
  49983. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  49984. if (thisIterationTarget >= currentSize)
  49985. {
  49986. const double availableExtraSpace = maxSize - currentSize;
  49987. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  49988. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  49989. for (int i = 0; i < items.size(); ++i)
  49990. {
  49991. Item* const it = items.getUnchecked(i);
  49992. if (it->order <= order)
  49993. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  49994. }
  49995. }
  49996. else
  49997. {
  49998. const double amountOfSlack = currentSize - minSize;
  49999. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50000. const double scale = targetAmountOfSlack / amountOfSlack;
  50001. for (int i = 0; i < items.size(); ++i)
  50002. {
  50003. Item* const it = items.getUnchecked(i);
  50004. if (it->order <= order)
  50005. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50006. }
  50007. }
  50008. if (nextHighestOrder < std::numeric_limits<int>::max())
  50009. order = nextHighestOrder;
  50010. else
  50011. break;
  50012. }
  50013. }
  50014. END_JUCE_NAMESPACE
  50015. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50016. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50017. BEGIN_JUCE_NAMESPACE
  50018. TabBarButton::TabBarButton (const String& name,
  50019. TabbedButtonBar* const owner_,
  50020. const int index)
  50021. : Button (name),
  50022. owner (owner_),
  50023. tabIndex (index),
  50024. overlapPixels (0)
  50025. {
  50026. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50027. setComponentEffect (&shadow);
  50028. setWantsKeyboardFocus (false);
  50029. }
  50030. TabBarButton::~TabBarButton()
  50031. {
  50032. }
  50033. void TabBarButton::paintButton (Graphics& g,
  50034. bool isMouseOverButton,
  50035. bool isButtonDown)
  50036. {
  50037. int x, y, w, h;
  50038. getActiveArea (x, y, w, h);
  50039. g.setOrigin (x, y);
  50040. getLookAndFeel()
  50041. .drawTabButton (g, w, h,
  50042. owner->getTabBackgroundColour (tabIndex),
  50043. tabIndex, getButtonText(), *this,
  50044. owner->getOrientation(),
  50045. isMouseOverButton, isButtonDown,
  50046. getToggleState());
  50047. }
  50048. void TabBarButton::clicked (const ModifierKeys& mods)
  50049. {
  50050. if (mods.isPopupMenu())
  50051. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50052. else
  50053. owner->setCurrentTabIndex (tabIndex);
  50054. }
  50055. bool TabBarButton::hitTest (int mx, int my)
  50056. {
  50057. int x, y, w, h;
  50058. getActiveArea (x, y, w, h);
  50059. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50060. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50061. {
  50062. if (((unsigned int) mx) < (unsigned int) getWidth()
  50063. && my >= y + overlapPixels
  50064. && my < y + h - overlapPixels)
  50065. return true;
  50066. }
  50067. else
  50068. {
  50069. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50070. && ((unsigned int) my) < (unsigned int) getHeight())
  50071. return true;
  50072. }
  50073. Path p;
  50074. getLookAndFeel()
  50075. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50076. owner->getOrientation(),
  50077. false, false, getToggleState());
  50078. return p.contains ((float) (mx - x),
  50079. (float) (my - y));
  50080. }
  50081. int TabBarButton::getBestTabLength (const int depth)
  50082. {
  50083. return jlimit (depth * 2,
  50084. depth * 7,
  50085. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50086. }
  50087. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50088. {
  50089. x = 0;
  50090. y = 0;
  50091. int r = getWidth();
  50092. int b = getHeight();
  50093. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50094. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50095. r -= spaceAroundImage;
  50096. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50097. x += spaceAroundImage;
  50098. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50099. y += spaceAroundImage;
  50100. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50101. b -= spaceAroundImage;
  50102. w = r - x;
  50103. h = b - y;
  50104. }
  50105. class TabAreaBehindFrontButtonComponent : public Component
  50106. {
  50107. public:
  50108. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50109. : owner (owner_)
  50110. {
  50111. setInterceptsMouseClicks (false, false);
  50112. }
  50113. ~TabAreaBehindFrontButtonComponent()
  50114. {
  50115. }
  50116. void paint (Graphics& g)
  50117. {
  50118. getLookAndFeel()
  50119. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50120. *owner, owner->getOrientation());
  50121. }
  50122. void enablementChanged()
  50123. {
  50124. repaint();
  50125. }
  50126. private:
  50127. TabbedButtonBar* const owner;
  50128. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50129. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50130. };
  50131. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50132. : orientation (orientation_),
  50133. currentTabIndex (-1),
  50134. extraTabsButton (0)
  50135. {
  50136. setInterceptsMouseClicks (false, true);
  50137. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50138. setFocusContainer (true);
  50139. }
  50140. TabbedButtonBar::~TabbedButtonBar()
  50141. {
  50142. deleteAllChildren();
  50143. }
  50144. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50145. {
  50146. orientation = newOrientation;
  50147. for (int i = getNumChildComponents(); --i >= 0;)
  50148. getChildComponent (i)->resized();
  50149. resized();
  50150. }
  50151. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50152. {
  50153. return new TabBarButton (name, this, index);
  50154. }
  50155. void TabbedButtonBar::clearTabs()
  50156. {
  50157. tabs.clear();
  50158. tabColours.clear();
  50159. currentTabIndex = -1;
  50160. deleteAndZero (extraTabsButton);
  50161. removeChildComponent (behindFrontTab);
  50162. deleteAllChildren();
  50163. addChildComponent (behindFrontTab);
  50164. setCurrentTabIndex (-1);
  50165. }
  50166. void TabbedButtonBar::addTab (const String& tabName,
  50167. const Colour& tabBackgroundColour,
  50168. int insertIndex)
  50169. {
  50170. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50171. if (tabName.isNotEmpty())
  50172. {
  50173. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50174. insertIndex = tabs.size();
  50175. for (int i = tabs.size(); --i >= insertIndex;)
  50176. {
  50177. TabBarButton* const tb = getTabButton (i);
  50178. if (tb != 0)
  50179. tb->tabIndex++;
  50180. }
  50181. tabs.insert (insertIndex, tabName);
  50182. tabColours.insert (insertIndex, tabBackgroundColour);
  50183. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50184. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50185. addAndMakeVisible (tb, insertIndex);
  50186. resized();
  50187. if (currentTabIndex < 0)
  50188. setCurrentTabIndex (0);
  50189. }
  50190. }
  50191. void TabbedButtonBar::setTabName (const int tabIndex,
  50192. const String& newName)
  50193. {
  50194. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50195. && tabs[tabIndex] != newName)
  50196. {
  50197. tabs.set (tabIndex, newName);
  50198. TabBarButton* const tb = getTabButton (tabIndex);
  50199. if (tb != 0)
  50200. tb->setButtonText (newName);
  50201. resized();
  50202. }
  50203. }
  50204. void TabbedButtonBar::removeTab (const int tabIndex)
  50205. {
  50206. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50207. {
  50208. const int oldTabIndex = currentTabIndex;
  50209. if (currentTabIndex == tabIndex)
  50210. currentTabIndex = -1;
  50211. tabs.remove (tabIndex);
  50212. tabColours.remove (tabIndex);
  50213. delete getTabButton (tabIndex);
  50214. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50215. {
  50216. TabBarButton* const tb = getTabButton (i);
  50217. if (tb != 0)
  50218. tb->tabIndex--;
  50219. }
  50220. resized();
  50221. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50222. }
  50223. }
  50224. void TabbedButtonBar::moveTab (const int currentIndex,
  50225. const int newIndex)
  50226. {
  50227. tabs.move (currentIndex, newIndex);
  50228. tabColours.move (currentIndex, newIndex);
  50229. resized();
  50230. }
  50231. int TabbedButtonBar::getNumTabs() const
  50232. {
  50233. return tabs.size();
  50234. }
  50235. const StringArray TabbedButtonBar::getTabNames() const
  50236. {
  50237. return tabs;
  50238. }
  50239. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50240. {
  50241. if (currentTabIndex != newIndex)
  50242. {
  50243. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50244. newIndex = -1;
  50245. currentTabIndex = newIndex;
  50246. for (int i = 0; i < getNumChildComponents(); ++i)
  50247. {
  50248. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50249. if (tb != 0)
  50250. tb->setToggleState (tb->tabIndex == newIndex, false);
  50251. }
  50252. resized();
  50253. if (sendChangeMessage_)
  50254. sendChangeMessage (this);
  50255. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50256. }
  50257. }
  50258. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50259. {
  50260. for (int i = getNumChildComponents(); --i >= 0;)
  50261. {
  50262. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50263. if (tb != 0 && tb->tabIndex == index)
  50264. return tb;
  50265. }
  50266. return 0;
  50267. }
  50268. void TabbedButtonBar::lookAndFeelChanged()
  50269. {
  50270. deleteAndZero (extraTabsButton);
  50271. resized();
  50272. }
  50273. void TabbedButtonBar::resized()
  50274. {
  50275. const double minimumScale = 0.7;
  50276. int depth = getWidth();
  50277. int length = getHeight();
  50278. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50279. swapVariables (depth, length);
  50280. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50281. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50282. int i, totalLength = overlap;
  50283. int numVisibleButtons = tabs.size();
  50284. for (i = 0; i < getNumChildComponents(); ++i)
  50285. {
  50286. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50287. if (tb != 0)
  50288. {
  50289. totalLength += tb->getBestTabLength (depth) - overlap;
  50290. tb->overlapPixels = overlap / 2;
  50291. }
  50292. }
  50293. double scale = 1.0;
  50294. if (totalLength > length)
  50295. scale = jmax (minimumScale, length / (double) totalLength);
  50296. const bool isTooBig = totalLength * scale > length;
  50297. int tabsButtonPos = 0;
  50298. if (isTooBig)
  50299. {
  50300. if (extraTabsButton == 0)
  50301. {
  50302. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50303. extraTabsButton->addButtonListener (this);
  50304. extraTabsButton->setAlwaysOnTop (true);
  50305. extraTabsButton->setTriggeredOnMouseDown (true);
  50306. }
  50307. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50308. extraTabsButton->setSize (buttonSize, buttonSize);
  50309. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50310. {
  50311. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50312. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50313. }
  50314. else
  50315. {
  50316. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50317. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50318. }
  50319. totalLength = 0;
  50320. for (i = 0; i < tabs.size(); ++i)
  50321. {
  50322. TabBarButton* const tb = getTabButton (i);
  50323. if (tb != 0)
  50324. {
  50325. const int newLength = totalLength + tb->getBestTabLength (depth);
  50326. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50327. {
  50328. totalLength += overlap;
  50329. break;
  50330. }
  50331. numVisibleButtons = i + 1;
  50332. totalLength = newLength - overlap;
  50333. }
  50334. }
  50335. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50336. }
  50337. else
  50338. {
  50339. deleteAndZero (extraTabsButton);
  50340. }
  50341. int pos = 0;
  50342. TabBarButton* frontTab = 0;
  50343. for (i = 0; i < tabs.size(); ++i)
  50344. {
  50345. TabBarButton* const tb = getTabButton (i);
  50346. if (tb != 0)
  50347. {
  50348. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50349. if (i < numVisibleButtons)
  50350. {
  50351. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50352. tb->setBounds (pos, 0, bestLength, getHeight());
  50353. else
  50354. tb->setBounds (0, pos, getWidth(), bestLength);
  50355. tb->toBack();
  50356. if (tb->tabIndex == currentTabIndex)
  50357. frontTab = tb;
  50358. tb->setVisible (true);
  50359. }
  50360. else
  50361. {
  50362. tb->setVisible (false);
  50363. }
  50364. pos += bestLength - overlap;
  50365. }
  50366. }
  50367. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50368. if (frontTab != 0)
  50369. {
  50370. frontTab->toFront (false);
  50371. behindFrontTab->toBehind (frontTab);
  50372. }
  50373. }
  50374. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50375. {
  50376. return tabColours [tabIndex];
  50377. }
  50378. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50379. {
  50380. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50381. && tabColours [tabIndex] != newColour)
  50382. {
  50383. tabColours.set (tabIndex, newColour);
  50384. repaint();
  50385. }
  50386. }
  50387. void TabbedButtonBar::buttonClicked (Button* button)
  50388. {
  50389. if (extraTabsButton == button)
  50390. {
  50391. PopupMenu m;
  50392. for (int i = 0; i < tabs.size(); ++i)
  50393. {
  50394. TabBarButton* const tb = getTabButton (i);
  50395. if (tb != 0 && ! tb->isVisible())
  50396. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50397. }
  50398. const int res = m.showAt (extraTabsButton);
  50399. if (res != 0)
  50400. setCurrentTabIndex (res - 1);
  50401. }
  50402. }
  50403. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50404. {
  50405. }
  50406. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50407. {
  50408. }
  50409. END_JUCE_NAMESPACE
  50410. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50411. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50412. BEGIN_JUCE_NAMESPACE
  50413. class TabCompButtonBar : public TabbedButtonBar
  50414. {
  50415. public:
  50416. TabCompButtonBar (TabbedComponent* const owner_,
  50417. const TabbedButtonBar::Orientation orientation)
  50418. : TabbedButtonBar (orientation),
  50419. owner (owner_)
  50420. {
  50421. }
  50422. ~TabCompButtonBar()
  50423. {
  50424. }
  50425. void currentTabChanged (int newCurrentTabIndex,
  50426. const String& newTabName)
  50427. {
  50428. owner->changeCallback (newCurrentTabIndex, newTabName);
  50429. }
  50430. void popupMenuClickOnTab (int tabIndex,
  50431. const String& tabName)
  50432. {
  50433. owner->popupMenuClickOnTab (tabIndex, tabName);
  50434. }
  50435. const Colour getTabBackgroundColour (const int tabIndex)
  50436. {
  50437. return owner->tabs->getTabBackgroundColour (tabIndex);
  50438. }
  50439. TabBarButton* createTabButton (const String& tabName, int tabIndex)
  50440. {
  50441. return owner->createTabButton (tabName, tabIndex);
  50442. }
  50443. juce_UseDebuggingNewOperator
  50444. private:
  50445. TabbedComponent* const owner;
  50446. TabCompButtonBar (const TabCompButtonBar&);
  50447. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50448. };
  50449. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50450. : panelComponent (0),
  50451. tabDepth (30),
  50452. outlineThickness (1),
  50453. edgeIndent (0)
  50454. {
  50455. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50456. }
  50457. TabbedComponent::~TabbedComponent()
  50458. {
  50459. clearTabs();
  50460. delete tabs;
  50461. }
  50462. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50463. {
  50464. tabs->setOrientation (orientation);
  50465. resized();
  50466. }
  50467. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50468. {
  50469. return tabs->getOrientation();
  50470. }
  50471. void TabbedComponent::setTabBarDepth (const int newDepth)
  50472. {
  50473. if (tabDepth != newDepth)
  50474. {
  50475. tabDepth = newDepth;
  50476. resized();
  50477. }
  50478. }
  50479. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50480. {
  50481. return new TabBarButton (tabName, tabs, tabIndex);
  50482. }
  50483. void TabbedComponent::clearTabs()
  50484. {
  50485. if (panelComponent != 0)
  50486. {
  50487. panelComponent->setVisible (false);
  50488. removeChildComponent (panelComponent);
  50489. panelComponent = 0;
  50490. }
  50491. tabs->clearTabs();
  50492. for (int i = contentComponents.size(); --i >= 0;)
  50493. {
  50494. Component* const c = contentComponents.getUnchecked(i);
  50495. // be careful not to delete these components until they've been removed from the tab component
  50496. jassert (c == 0 || c->isValidComponent());
  50497. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50498. delete c;
  50499. }
  50500. contentComponents.clear();
  50501. }
  50502. void TabbedComponent::addTab (const String& tabName,
  50503. const Colour& tabBackgroundColour,
  50504. Component* const contentComponent,
  50505. const bool deleteComponentWhenNotNeeded,
  50506. const int insertIndex)
  50507. {
  50508. contentComponents.insert (insertIndex, contentComponent);
  50509. if (contentComponent != 0)
  50510. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50511. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50512. }
  50513. void TabbedComponent::setTabName (const int tabIndex,
  50514. const String& newName)
  50515. {
  50516. tabs->setTabName (tabIndex, newName);
  50517. }
  50518. void TabbedComponent::removeTab (const int tabIndex)
  50519. {
  50520. Component* const c = contentComponents [tabIndex];
  50521. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50522. {
  50523. if (c == panelComponent)
  50524. panelComponent = 0;
  50525. delete c;
  50526. }
  50527. contentComponents.remove (tabIndex);
  50528. tabs->removeTab (tabIndex);
  50529. }
  50530. int TabbedComponent::getNumTabs() const
  50531. {
  50532. return tabs->getNumTabs();
  50533. }
  50534. const StringArray TabbedComponent::getTabNames() const
  50535. {
  50536. return tabs->getTabNames();
  50537. }
  50538. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50539. {
  50540. return contentComponents [tabIndex];
  50541. }
  50542. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50543. {
  50544. return tabs->getTabBackgroundColour (tabIndex);
  50545. }
  50546. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50547. {
  50548. tabs->setTabBackgroundColour (tabIndex, newColour);
  50549. if (getCurrentTabIndex() == tabIndex)
  50550. repaint();
  50551. }
  50552. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50553. {
  50554. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50555. }
  50556. int TabbedComponent::getCurrentTabIndex() const
  50557. {
  50558. return tabs->getCurrentTabIndex();
  50559. }
  50560. const String& TabbedComponent::getCurrentTabName() const
  50561. {
  50562. return tabs->getCurrentTabName();
  50563. }
  50564. void TabbedComponent::setOutline (int thickness)
  50565. {
  50566. outlineThickness = thickness;
  50567. repaint();
  50568. }
  50569. void TabbedComponent::setIndent (const int indentThickness)
  50570. {
  50571. edgeIndent = indentThickness;
  50572. }
  50573. void TabbedComponent::paint (Graphics& g)
  50574. {
  50575. g.fillAll (findColour (backgroundColourId));
  50576. const TabbedButtonBar::Orientation o = getOrientation();
  50577. int x = 0;
  50578. int y = 0;
  50579. int r = getWidth();
  50580. int b = getHeight();
  50581. if (o == TabbedButtonBar::TabsAtTop)
  50582. y += tabDepth;
  50583. else if (o == TabbedButtonBar::TabsAtBottom)
  50584. b -= tabDepth;
  50585. else if (o == TabbedButtonBar::TabsAtLeft)
  50586. x += tabDepth;
  50587. else if (o == TabbedButtonBar::TabsAtRight)
  50588. r -= tabDepth;
  50589. g.reduceClipRegion (x, y, r - x, b - y);
  50590. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50591. if (outlineThickness > 0)
  50592. {
  50593. if (o == TabbedButtonBar::TabsAtTop)
  50594. --y;
  50595. else if (o == TabbedButtonBar::TabsAtBottom)
  50596. ++b;
  50597. else if (o == TabbedButtonBar::TabsAtLeft)
  50598. --x;
  50599. else if (o == TabbedButtonBar::TabsAtRight)
  50600. ++r;
  50601. g.setColour (findColour (outlineColourId));
  50602. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50603. }
  50604. }
  50605. void TabbedComponent::resized()
  50606. {
  50607. const TabbedButtonBar::Orientation o = getOrientation();
  50608. const int indent = edgeIndent + outlineThickness;
  50609. BorderSize indents (indent);
  50610. if (o == TabbedButtonBar::TabsAtTop)
  50611. {
  50612. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50613. indents.setTop (tabDepth + edgeIndent);
  50614. }
  50615. else if (o == TabbedButtonBar::TabsAtBottom)
  50616. {
  50617. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50618. indents.setBottom (tabDepth + edgeIndent);
  50619. }
  50620. else if (o == TabbedButtonBar::TabsAtLeft)
  50621. {
  50622. tabs->setBounds (0, 0, tabDepth, getHeight());
  50623. indents.setLeft (tabDepth + edgeIndent);
  50624. }
  50625. else if (o == TabbedButtonBar::TabsAtRight)
  50626. {
  50627. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50628. indents.setRight (tabDepth + edgeIndent);
  50629. }
  50630. const Rectangle<int> bounds (indents.subtractedFrom (getLocalBounds()));
  50631. for (int i = contentComponents.size(); --i >= 0;)
  50632. if (contentComponents.getUnchecked (i) != 0)
  50633. contentComponents.getUnchecked (i)->setBounds (bounds);
  50634. }
  50635. void TabbedComponent::lookAndFeelChanged()
  50636. {
  50637. for (int i = contentComponents.size(); --i >= 0;)
  50638. if (contentComponents.getUnchecked (i) != 0)
  50639. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50640. }
  50641. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50642. const String& newTabName)
  50643. {
  50644. if (panelComponent != 0)
  50645. {
  50646. panelComponent->setVisible (false);
  50647. removeChildComponent (panelComponent);
  50648. panelComponent = 0;
  50649. }
  50650. if (getCurrentTabIndex() >= 0)
  50651. {
  50652. panelComponent = contentComponents [getCurrentTabIndex()];
  50653. if (panelComponent != 0)
  50654. {
  50655. // do these ops as two stages instead of addAndMakeVisible() so that the
  50656. // component has always got a parent when it gets the visibilityChanged() callback
  50657. addChildComponent (panelComponent);
  50658. panelComponent->setVisible (true);
  50659. panelComponent->toFront (true);
  50660. }
  50661. repaint();
  50662. }
  50663. resized();
  50664. currentTabChanged (newCurrentTabIndex, newTabName);
  50665. }
  50666. void TabbedComponent::currentTabChanged (const int, const String&)
  50667. {
  50668. }
  50669. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50670. {
  50671. }
  50672. END_JUCE_NAMESPACE
  50673. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50674. /*** Start of inlined file: juce_Viewport.cpp ***/
  50675. BEGIN_JUCE_NAMESPACE
  50676. Viewport::Viewport (const String& componentName)
  50677. : Component (componentName),
  50678. contentComp (0),
  50679. lastVX (0),
  50680. lastVY (0),
  50681. lastVW (0),
  50682. lastVH (0),
  50683. scrollBarThickness (0),
  50684. singleStepX (16),
  50685. singleStepY (16),
  50686. showHScrollbar (true),
  50687. showVScrollbar (true)
  50688. {
  50689. // content holder is used to clip the contents so they don't overlap the scrollbars
  50690. addAndMakeVisible (contentHolder = new Component());
  50691. contentHolder->setInterceptsMouseClicks (false, true);
  50692. verticalScrollBar = new ScrollBar (true);
  50693. horizontalScrollBar = new ScrollBar (false);
  50694. addChildComponent (verticalScrollBar);
  50695. addChildComponent (horizontalScrollBar);
  50696. verticalScrollBar->addListener (this);
  50697. horizontalScrollBar->addListener (this);
  50698. setInterceptsMouseClicks (false, true);
  50699. setWantsKeyboardFocus (true);
  50700. }
  50701. Viewport::~Viewport()
  50702. {
  50703. contentHolder->deleteAllChildren();
  50704. deleteAllChildren();
  50705. }
  50706. void Viewport::visibleAreaChanged (int, int, int, int)
  50707. {
  50708. }
  50709. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50710. {
  50711. if (contentComp.getComponent() != newViewedComponent)
  50712. {
  50713. {
  50714. ScopedPointer<Component> oldCompDeleter (contentComp);
  50715. contentComp = 0;
  50716. }
  50717. contentComp = newViewedComponent;
  50718. if (contentComp != 0)
  50719. {
  50720. contentComp->setTopLeftPosition (0, 0);
  50721. contentHolder->addAndMakeVisible (contentComp);
  50722. contentComp->addComponentListener (this);
  50723. }
  50724. updateVisibleRegion();
  50725. }
  50726. }
  50727. int Viewport::getMaximumVisibleWidth() const throw()
  50728. {
  50729. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50730. }
  50731. int Viewport::getMaximumVisibleHeight() const throw()
  50732. {
  50733. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50734. }
  50735. void Viewport::setViewPosition (const int xPixelsOffset,
  50736. const int yPixelsOffset)
  50737. {
  50738. if (contentComp != 0)
  50739. contentComp->setTopLeftPosition (-xPixelsOffset,
  50740. -yPixelsOffset);
  50741. }
  50742. void Viewport::setViewPositionProportionately (const double x,
  50743. const double y)
  50744. {
  50745. if (contentComp != 0)
  50746. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50747. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50748. }
  50749. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50750. {
  50751. if (contentComp != 0)
  50752. {
  50753. int dx = 0, dy = 0;
  50754. if (mouseX < activeBorderThickness)
  50755. dx = activeBorderThickness - mouseX;
  50756. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50757. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50758. if (dx < 0)
  50759. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50760. else
  50761. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50762. if (mouseY < activeBorderThickness)
  50763. dy = activeBorderThickness - mouseY;
  50764. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50765. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50766. if (dy < 0)
  50767. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50768. else
  50769. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50770. if (dx != 0 || dy != 0)
  50771. {
  50772. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50773. contentComp->getY() + dy);
  50774. return true;
  50775. }
  50776. }
  50777. return false;
  50778. }
  50779. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50780. {
  50781. updateVisibleRegion();
  50782. }
  50783. void Viewport::resized()
  50784. {
  50785. updateVisibleRegion();
  50786. }
  50787. void Viewport::updateVisibleRegion()
  50788. {
  50789. if (contentComp != 0)
  50790. {
  50791. const int newVX = -contentComp->getX();
  50792. const int newVY = -contentComp->getY();
  50793. if (newVX == 0 && newVY == 0
  50794. && contentComp->getWidth() <= getWidth()
  50795. && contentComp->getHeight() <= getHeight())
  50796. {
  50797. horizontalScrollBar->setVisible (false);
  50798. verticalScrollBar->setVisible (false);
  50799. }
  50800. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50801. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50802. horizontalScrollBar->setSingleStepSize (singleStepX);
  50803. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50804. horizontalScrollBar->setVisible (false);
  50805. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50806. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50807. verticalScrollBar->setSingleStepSize (singleStepY);
  50808. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50809. verticalScrollBar->setVisible (false);
  50810. if (verticalScrollBar->isVisible())
  50811. {
  50812. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50813. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50814. verticalScrollBar
  50815. ->setBounds (getMaximumVisibleWidth(), 0,
  50816. getScrollBarThickness(), getMaximumVisibleHeight());
  50817. }
  50818. if (horizontalScrollBar->isVisible())
  50819. {
  50820. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50821. horizontalScrollBar
  50822. ->setBounds (0, getMaximumVisibleHeight(),
  50823. getMaximumVisibleWidth(), getScrollBarThickness());
  50824. }
  50825. contentHolder->setSize (getMaximumVisibleWidth(),
  50826. getMaximumVisibleHeight());
  50827. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50828. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50829. if (newVX != lastVX
  50830. || newVY != lastVY
  50831. || newVW != lastVW
  50832. || newVH != lastVH)
  50833. {
  50834. lastVX = newVX;
  50835. lastVY = newVY;
  50836. lastVW = newVW;
  50837. lastVH = newVH;
  50838. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50839. }
  50840. horizontalScrollBar->handleUpdateNowIfNeeded();
  50841. verticalScrollBar->handleUpdateNowIfNeeded();
  50842. }
  50843. else
  50844. {
  50845. horizontalScrollBar->setVisible (false);
  50846. verticalScrollBar->setVisible (false);
  50847. }
  50848. }
  50849. void Viewport::setSingleStepSizes (const int stepX,
  50850. const int stepY)
  50851. {
  50852. singleStepX = stepX;
  50853. singleStepY = stepY;
  50854. updateVisibleRegion();
  50855. }
  50856. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50857. const bool showHorizontalScrollbarIfNeeded)
  50858. {
  50859. showVScrollbar = showVerticalScrollbarIfNeeded;
  50860. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50861. updateVisibleRegion();
  50862. }
  50863. void Viewport::setScrollBarThickness (const int thickness)
  50864. {
  50865. scrollBarThickness = thickness;
  50866. updateVisibleRegion();
  50867. }
  50868. int Viewport::getScrollBarThickness() const throw()
  50869. {
  50870. return (scrollBarThickness > 0) ? scrollBarThickness
  50871. : getLookAndFeel().getDefaultScrollbarWidth();
  50872. }
  50873. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50874. {
  50875. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50876. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50877. }
  50878. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50879. {
  50880. if (scrollBarThatHasMoved == horizontalScrollBar)
  50881. {
  50882. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50883. }
  50884. else if (scrollBarThatHasMoved == verticalScrollBar)
  50885. {
  50886. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50887. }
  50888. }
  50889. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50890. {
  50891. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50892. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50893. }
  50894. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50895. {
  50896. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50897. {
  50898. const bool hasVertBar = verticalScrollBar->isVisible();
  50899. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50900. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50901. {
  50902. if (wheelIncrementX == 0 && ! hasVertBar)
  50903. wheelIncrementX = wheelIncrementY;
  50904. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50905. wheelIncrementX, wheelIncrementY);
  50906. return true;
  50907. }
  50908. else if (hasVertBar && wheelIncrementY != 0)
  50909. {
  50910. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  50911. wheelIncrementX, wheelIncrementY);
  50912. return true;
  50913. }
  50914. }
  50915. return false;
  50916. }
  50917. bool Viewport::keyPressed (const KeyPress& key)
  50918. {
  50919. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  50920. || key.isKeyCode (KeyPress::downKey)
  50921. || key.isKeyCode (KeyPress::pageUpKey)
  50922. || key.isKeyCode (KeyPress::pageDownKey)
  50923. || key.isKeyCode (KeyPress::homeKey)
  50924. || key.isKeyCode (KeyPress::endKey);
  50925. if (verticalScrollBar->isVisible() && isUpDownKey)
  50926. return verticalScrollBar->keyPressed (key);
  50927. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  50928. || key.isKeyCode (KeyPress::rightKey);
  50929. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  50930. return horizontalScrollBar->keyPressed (key);
  50931. return false;
  50932. }
  50933. END_JUCE_NAMESPACE
  50934. /*** End of inlined file: juce_Viewport.cpp ***/
  50935. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  50936. BEGIN_JUCE_NAMESPACE
  50937. static const Colour createBaseColour (const Colour& buttonColour,
  50938. const bool hasKeyboardFocus,
  50939. const bool isMouseOverButton,
  50940. const bool isButtonDown) throw()
  50941. {
  50942. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  50943. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  50944. if (isButtonDown)
  50945. return baseColour.contrasting (0.2f);
  50946. else if (isMouseOverButton)
  50947. return baseColour.contrasting (0.1f);
  50948. return baseColour;
  50949. }
  50950. LookAndFeel::LookAndFeel()
  50951. {
  50952. /* if this fails it means you're trying to create a LookAndFeel object before
  50953. the static Colours have been initialised. That ain't gonna work. It probably
  50954. means that you're using a static LookAndFeel object and that your compiler has
  50955. decided to intialise it before the Colours class.
  50956. */
  50957. jassert (Colours::white == Colour (0xffffffff));
  50958. // set up the standard set of colours..
  50959. const int textButtonColour = 0xffbbbbff;
  50960. const int textHighlightColour = 0x401111ee;
  50961. const int standardOutlineColour = 0xb2808080;
  50962. static const int standardColours[] =
  50963. {
  50964. TextButton::buttonColourId, textButtonColour,
  50965. TextButton::buttonOnColourId, 0xff4444ff,
  50966. TextButton::textColourOnId, 0xff000000,
  50967. TextButton::textColourOffId, 0xff000000,
  50968. ComboBox::buttonColourId, 0xffbbbbff,
  50969. ComboBox::outlineColourId, standardOutlineColour,
  50970. ToggleButton::textColourId, 0xff000000,
  50971. TextEditor::backgroundColourId, 0xffffffff,
  50972. TextEditor::textColourId, 0xff000000,
  50973. TextEditor::highlightColourId, textHighlightColour,
  50974. TextEditor::highlightedTextColourId, 0xff000000,
  50975. TextEditor::caretColourId, 0xff000000,
  50976. TextEditor::outlineColourId, 0x00000000,
  50977. TextEditor::focusedOutlineColourId, textButtonColour,
  50978. TextEditor::shadowColourId, 0x38000000,
  50979. Label::backgroundColourId, 0x00000000,
  50980. Label::textColourId, 0xff000000,
  50981. Label::outlineColourId, 0x00000000,
  50982. ScrollBar::backgroundColourId, 0x00000000,
  50983. ScrollBar::thumbColourId, 0xffffffff,
  50984. ScrollBar::trackColourId, 0xffffffff,
  50985. TreeView::linesColourId, 0x4c000000,
  50986. TreeView::backgroundColourId, 0x00000000,
  50987. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  50988. PopupMenu::backgroundColourId, 0xffffffff,
  50989. PopupMenu::textColourId, 0xff000000,
  50990. PopupMenu::headerTextColourId, 0xff000000,
  50991. PopupMenu::highlightedTextColourId, 0xffffffff,
  50992. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  50993. ComboBox::textColourId, 0xff000000,
  50994. ComboBox::backgroundColourId, 0xffffffff,
  50995. ComboBox::arrowColourId, 0x99000000,
  50996. ListBox::backgroundColourId, 0xffffffff,
  50997. ListBox::outlineColourId, standardOutlineColour,
  50998. ListBox::textColourId, 0xff000000,
  50999. Slider::backgroundColourId, 0x00000000,
  51000. Slider::thumbColourId, textButtonColour,
  51001. Slider::trackColourId, 0x7fffffff,
  51002. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51003. Slider::rotarySliderOutlineColourId, 0x66000000,
  51004. Slider::textBoxTextColourId, 0xff000000,
  51005. Slider::textBoxBackgroundColourId, 0xffffffff,
  51006. Slider::textBoxHighlightColourId, textHighlightColour,
  51007. Slider::textBoxOutlineColourId, standardOutlineColour,
  51008. ResizableWindow::backgroundColourId, 0xff777777,
  51009. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51010. AlertWindow::backgroundColourId, 0xffededed,
  51011. AlertWindow::textColourId, 0xff000000,
  51012. AlertWindow::outlineColourId, 0xff666666,
  51013. ProgressBar::backgroundColourId, 0xffeeeeee,
  51014. ProgressBar::foregroundColourId, 0xffaaaaee,
  51015. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51016. TooltipWindow::textColourId, 0xff000000,
  51017. TooltipWindow::outlineColourId, 0x4c000000,
  51018. TabbedComponent::backgroundColourId, 0x00000000,
  51019. TabbedComponent::outlineColourId, 0xff777777,
  51020. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51021. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51022. Toolbar::backgroundColourId, 0xfff6f8f9,
  51023. Toolbar::separatorColourId, 0x4c000000,
  51024. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51025. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51026. Toolbar::labelTextColourId, 0xff000000,
  51027. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51028. HyperlinkButton::textColourId, 0xcc1111ee,
  51029. GroupComponent::outlineColourId, 0x66000000,
  51030. GroupComponent::textColourId, 0xff000000,
  51031. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51032. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51033. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51034. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51035. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51036. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51037. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51038. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51039. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51040. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51041. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51042. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51043. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51044. CodeEditorComponent::caretColourId, 0xff000000,
  51045. CodeEditorComponent::highlightColourId, textHighlightColour,
  51046. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51047. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51048. ColourSelector::labelTextColourId, 0xff000000,
  51049. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51050. KeyMappingEditorComponent::textColourId, 0xff000000,
  51051. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51052. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51053. };
  51054. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51055. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51056. static String defaultSansName, defaultSerifName, defaultFixedName;
  51057. if (defaultSansName.isEmpty())
  51058. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51059. defaultSans = defaultSansName;
  51060. defaultSerif = defaultSerifName;
  51061. defaultFixed = defaultFixedName;
  51062. }
  51063. LookAndFeel::~LookAndFeel()
  51064. {
  51065. }
  51066. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51067. {
  51068. const int index = colourIds.indexOf (colourId);
  51069. if (index >= 0)
  51070. return colours [index];
  51071. jassertfalse
  51072. return Colours::black;
  51073. }
  51074. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51075. {
  51076. const int index = colourIds.indexOf (colourId);
  51077. if (index >= 0)
  51078. colours.set (index, colour);
  51079. colourIds.add (colourId);
  51080. colours.add (colour);
  51081. }
  51082. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51083. {
  51084. return colourIds.contains (colourId);
  51085. }
  51086. static LookAndFeel* defaultLF = 0;
  51087. static LookAndFeel* currentDefaultLF = 0;
  51088. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51089. {
  51090. // if this happens, your app hasn't initialised itself properly.. if you're
  51091. // trying to hack your own main() function, have a look at
  51092. // JUCEApplication::initialiseForGUI()
  51093. jassert (currentDefaultLF != 0);
  51094. return *currentDefaultLF;
  51095. }
  51096. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51097. {
  51098. if (newDefaultLookAndFeel == 0)
  51099. {
  51100. if (defaultLF == 0)
  51101. defaultLF = new LookAndFeel();
  51102. newDefaultLookAndFeel = defaultLF;
  51103. }
  51104. currentDefaultLF = newDefaultLookAndFeel;
  51105. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51106. {
  51107. Component* const c = Desktop::getInstance().getComponent (i);
  51108. if (c != 0)
  51109. c->sendLookAndFeelChange();
  51110. }
  51111. }
  51112. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51113. {
  51114. if (currentDefaultLF == defaultLF)
  51115. currentDefaultLF = 0;
  51116. deleteAndZero (defaultLF);
  51117. }
  51118. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51119. {
  51120. String faceName (font.getTypefaceName());
  51121. if (faceName == Font::getDefaultSansSerifFontName())
  51122. faceName = defaultSans;
  51123. else if (faceName == Font::getDefaultSerifFontName())
  51124. faceName = defaultSerif;
  51125. else if (faceName == Font::getDefaultMonospacedFontName())
  51126. faceName = defaultFixed;
  51127. Font f (font);
  51128. f.setTypefaceName (faceName);
  51129. return Typeface::createSystemTypefaceFor (f);
  51130. }
  51131. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51132. {
  51133. defaultSans = newName;
  51134. }
  51135. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51136. {
  51137. return component.getMouseCursor();
  51138. }
  51139. void LookAndFeel::drawButtonBackground (Graphics& g,
  51140. Button& button,
  51141. const Colour& backgroundColour,
  51142. bool isMouseOverButton,
  51143. bool isButtonDown)
  51144. {
  51145. const int width = button.getWidth();
  51146. const int height = button.getHeight();
  51147. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51148. const float halfThickness = outlineThickness * 0.5f;
  51149. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51150. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51151. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51152. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51153. const Colour baseColour (createBaseColour (backgroundColour,
  51154. button.hasKeyboardFocus (true),
  51155. isMouseOverButton, isButtonDown)
  51156. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51157. drawGlassLozenge (g,
  51158. indentL,
  51159. indentT,
  51160. width - indentL - indentR,
  51161. height - indentT - indentB,
  51162. baseColour, outlineThickness, -1.0f,
  51163. button.isConnectedOnLeft(),
  51164. button.isConnectedOnRight(),
  51165. button.isConnectedOnTop(),
  51166. button.isConnectedOnBottom());
  51167. }
  51168. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51169. {
  51170. return button.getFont();
  51171. }
  51172. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51173. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51174. {
  51175. Font font (getFontForTextButton (button));
  51176. g.setFont (font);
  51177. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51178. : TextButton::textColourOffId)
  51179. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51180. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51181. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51182. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51183. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51184. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51185. g.drawFittedText (button.getButtonText(),
  51186. leftIndent,
  51187. yIndent,
  51188. button.getWidth() - leftIndent - rightIndent,
  51189. button.getHeight() - yIndent * 2,
  51190. Justification::centred, 2);
  51191. }
  51192. void LookAndFeel::drawTickBox (Graphics& g,
  51193. Component& component,
  51194. float x, float y, float w, float h,
  51195. const bool ticked,
  51196. const bool isEnabled,
  51197. const bool isMouseOverButton,
  51198. const bool isButtonDown)
  51199. {
  51200. const float boxSize = w * 0.7f;
  51201. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51202. createBaseColour (component.findColour (TextButton::buttonColourId)
  51203. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51204. true,
  51205. isMouseOverButton,
  51206. isButtonDown),
  51207. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51208. if (ticked)
  51209. {
  51210. Path tick;
  51211. tick.startNewSubPath (1.5f, 3.0f);
  51212. tick.lineTo (3.0f, 6.0f);
  51213. tick.lineTo (6.0f, 0.0f);
  51214. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51215. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51216. .translated (x, y));
  51217. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51218. }
  51219. }
  51220. void LookAndFeel::drawToggleButton (Graphics& g,
  51221. ToggleButton& button,
  51222. bool isMouseOverButton,
  51223. bool isButtonDown)
  51224. {
  51225. if (button.hasKeyboardFocus (true))
  51226. {
  51227. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51228. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51229. }
  51230. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51231. const float tickWidth = fontSize * 1.1f;
  51232. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51233. tickWidth, tickWidth,
  51234. button.getToggleState(),
  51235. button.isEnabled(),
  51236. isMouseOverButton,
  51237. isButtonDown);
  51238. g.setColour (button.findColour (ToggleButton::textColourId));
  51239. g.setFont (fontSize);
  51240. if (! button.isEnabled())
  51241. g.setOpacity (0.5f);
  51242. const int textX = (int) tickWidth + 5;
  51243. g.drawFittedText (button.getButtonText(),
  51244. textX, 0,
  51245. button.getWidth() - textX - 2, button.getHeight(),
  51246. Justification::centredLeft, 10);
  51247. }
  51248. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51249. {
  51250. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51251. const int tickWidth = jmin (24, button.getHeight());
  51252. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51253. button.getHeight());
  51254. }
  51255. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51256. const String& message,
  51257. const String& button1,
  51258. const String& button2,
  51259. const String& button3,
  51260. AlertWindow::AlertIconType iconType,
  51261. int numButtons,
  51262. Component* associatedComponent)
  51263. {
  51264. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51265. if (numButtons == 1)
  51266. {
  51267. aw->addButton (button1, 0,
  51268. KeyPress (KeyPress::escapeKey, 0, 0),
  51269. KeyPress (KeyPress::returnKey, 0, 0));
  51270. }
  51271. else
  51272. {
  51273. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51274. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51275. if (button1ShortCut == button2ShortCut)
  51276. button2ShortCut = KeyPress();
  51277. if (numButtons == 2)
  51278. {
  51279. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51280. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51281. }
  51282. else if (numButtons == 3)
  51283. {
  51284. aw->addButton (button1, 1, button1ShortCut);
  51285. aw->addButton (button2, 2, button2ShortCut);
  51286. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51287. }
  51288. }
  51289. return aw;
  51290. }
  51291. void LookAndFeel::drawAlertBox (Graphics& g,
  51292. AlertWindow& alert,
  51293. const Rectangle<int>& textArea,
  51294. TextLayout& textLayout)
  51295. {
  51296. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51297. int iconSpaceUsed = 0;
  51298. Justification alignment (Justification::horizontallyCentred);
  51299. const int iconWidth = 80;
  51300. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51301. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51302. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51303. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51304. iconSize, iconSize);
  51305. if (alert.getAlertType() != AlertWindow::NoIcon)
  51306. {
  51307. Path icon;
  51308. uint32 colour;
  51309. char character;
  51310. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51311. {
  51312. colour = 0x55ff5555;
  51313. character = '!';
  51314. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51315. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51316. (float) iconRect.getX(), (float) iconRect.getBottom());
  51317. icon = icon.createPathWithRoundedCorners (5.0f);
  51318. }
  51319. else
  51320. {
  51321. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51322. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51323. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51324. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51325. }
  51326. GlyphArrangement ga;
  51327. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51328. String::charToString (character),
  51329. (float) iconRect.getX(), (float) iconRect.getY(),
  51330. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51331. Justification::centred, false);
  51332. ga.createPath (icon);
  51333. icon.setUsingNonZeroWinding (false);
  51334. g.setColour (Colour (colour));
  51335. g.fillPath (icon);
  51336. iconSpaceUsed = iconWidth;
  51337. alignment = Justification::left;
  51338. }
  51339. g.setColour (alert.findColour (AlertWindow::textColourId));
  51340. textLayout.drawWithin (g,
  51341. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51342. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51343. alignment.getFlags() | Justification::top);
  51344. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51345. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51346. }
  51347. int LookAndFeel::getAlertBoxWindowFlags()
  51348. {
  51349. return ComponentPeer::windowAppearsOnTaskbar
  51350. | ComponentPeer::windowHasDropShadow;
  51351. }
  51352. int LookAndFeel::getAlertWindowButtonHeight()
  51353. {
  51354. return 28;
  51355. }
  51356. const Font LookAndFeel::getAlertWindowFont()
  51357. {
  51358. return Font (12.0f);
  51359. }
  51360. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51361. int width, int height,
  51362. double progress, const String& textToShow)
  51363. {
  51364. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51365. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51366. g.fillAll (background);
  51367. if (progress >= 0.0f && progress < 1.0f)
  51368. {
  51369. drawGlassLozenge (g, 1.0f, 1.0f,
  51370. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51371. (float) (height - 2),
  51372. foreground,
  51373. 0.5f, 0.0f,
  51374. true, true, true, true);
  51375. }
  51376. else
  51377. {
  51378. // spinning bar..
  51379. g.setColour (foreground);
  51380. const int stripeWidth = height * 2;
  51381. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51382. Path p;
  51383. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51384. p.addQuadrilateral (x, 0.0f,
  51385. x + stripeWidth * 0.5f, 0.0f,
  51386. x, (float) height,
  51387. x - stripeWidth * 0.5f, (float) height);
  51388. Image im (Image::ARGB, width, height, true);
  51389. {
  51390. Graphics g2 (im);
  51391. drawGlassLozenge (g2, 1.0f, 1.0f,
  51392. (float) (width - 2),
  51393. (float) (height - 2),
  51394. foreground,
  51395. 0.5f, 0.0f,
  51396. true, true, true, true);
  51397. }
  51398. g.setTiledImageFill (im, 0, 0, 0.85f);
  51399. g.fillPath (p);
  51400. }
  51401. if (textToShow.isNotEmpty())
  51402. {
  51403. g.setColour (Colour::contrasting (background, foreground));
  51404. g.setFont (height * 0.6f);
  51405. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51406. }
  51407. }
  51408. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51409. {
  51410. const float radius = jmin (w, h) * 0.4f;
  51411. const float thickness = radius * 0.15f;
  51412. Path p;
  51413. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51414. radius * 0.6f, thickness,
  51415. thickness * 0.5f);
  51416. const float cx = x + w * 0.5f;
  51417. const float cy = y + h * 0.5f;
  51418. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51419. for (int i = 0; i < 12; ++i)
  51420. {
  51421. const int n = (i + 12 - animationIndex) % 12;
  51422. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51423. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51424. .translated (cx, cy));
  51425. }
  51426. }
  51427. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51428. ScrollBar& scrollbar,
  51429. int width, int height,
  51430. int buttonDirection,
  51431. bool /*isScrollbarVertical*/,
  51432. bool /*isMouseOverButton*/,
  51433. bool isButtonDown)
  51434. {
  51435. Path p;
  51436. if (buttonDirection == 0)
  51437. p.addTriangle (width * 0.5f, height * 0.2f,
  51438. width * 0.1f, height * 0.7f,
  51439. width * 0.9f, height * 0.7f);
  51440. else if (buttonDirection == 1)
  51441. p.addTriangle (width * 0.8f, height * 0.5f,
  51442. width * 0.3f, height * 0.1f,
  51443. width * 0.3f, height * 0.9f);
  51444. else if (buttonDirection == 2)
  51445. p.addTriangle (width * 0.5f, height * 0.8f,
  51446. width * 0.1f, height * 0.3f,
  51447. width * 0.9f, height * 0.3f);
  51448. else if (buttonDirection == 3)
  51449. p.addTriangle (width * 0.2f, height * 0.5f,
  51450. width * 0.7f, height * 0.1f,
  51451. width * 0.7f, height * 0.9f);
  51452. if (isButtonDown)
  51453. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51454. else
  51455. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51456. g.fillPath (p);
  51457. g.setColour (Colour (0x80000000));
  51458. g.strokePath (p, PathStrokeType (0.5f));
  51459. }
  51460. void LookAndFeel::drawScrollbar (Graphics& g,
  51461. ScrollBar& scrollbar,
  51462. int x, int y,
  51463. int width, int height,
  51464. bool isScrollbarVertical,
  51465. int thumbStartPosition,
  51466. int thumbSize,
  51467. bool /*isMouseOver*/,
  51468. bool /*isMouseDown*/)
  51469. {
  51470. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51471. Path slotPath, thumbPath;
  51472. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51473. const float slotIndentx2 = slotIndent * 2.0f;
  51474. const float thumbIndent = slotIndent + 1.0f;
  51475. const float thumbIndentx2 = thumbIndent * 2.0f;
  51476. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51477. if (isScrollbarVertical)
  51478. {
  51479. slotPath.addRoundedRectangle (x + slotIndent,
  51480. y + slotIndent,
  51481. width - slotIndentx2,
  51482. height - slotIndentx2,
  51483. (width - slotIndentx2) * 0.5f);
  51484. if (thumbSize > 0)
  51485. thumbPath.addRoundedRectangle (x + thumbIndent,
  51486. thumbStartPosition + thumbIndent,
  51487. width - thumbIndentx2,
  51488. thumbSize - thumbIndentx2,
  51489. (width - thumbIndentx2) * 0.5f);
  51490. gx1 = (float) x;
  51491. gx2 = x + width * 0.7f;
  51492. }
  51493. else
  51494. {
  51495. slotPath.addRoundedRectangle (x + slotIndent,
  51496. y + slotIndent,
  51497. width - slotIndentx2,
  51498. height - slotIndentx2,
  51499. (height - slotIndentx2) * 0.5f);
  51500. if (thumbSize > 0)
  51501. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51502. y + thumbIndent,
  51503. thumbSize - thumbIndentx2,
  51504. height - thumbIndentx2,
  51505. (height - thumbIndentx2) * 0.5f);
  51506. gy1 = (float) y;
  51507. gy2 = y + height * 0.7f;
  51508. }
  51509. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51510. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51511. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51512. g.fillPath (slotPath);
  51513. if (isScrollbarVertical)
  51514. {
  51515. gx1 = x + width * 0.6f;
  51516. gx2 = (float) x + width;
  51517. }
  51518. else
  51519. {
  51520. gy1 = y + height * 0.6f;
  51521. gy2 = (float) y + height;
  51522. }
  51523. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51524. Colour (0x19000000), gx2, gy2, false));
  51525. g.fillPath (slotPath);
  51526. g.setColour (thumbColour);
  51527. g.fillPath (thumbPath);
  51528. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51529. Colours::transparentBlack, gx2, gy2, false));
  51530. g.saveState();
  51531. if (isScrollbarVertical)
  51532. g.reduceClipRegion (x + width / 2, y, width, height);
  51533. else
  51534. g.reduceClipRegion (x, y + height / 2, width, height);
  51535. g.fillPath (thumbPath);
  51536. g.restoreState();
  51537. g.setColour (Colour (0x4c000000));
  51538. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51539. }
  51540. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51541. {
  51542. return 0;
  51543. }
  51544. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51545. {
  51546. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51547. }
  51548. int LookAndFeel::getDefaultScrollbarWidth()
  51549. {
  51550. return 18;
  51551. }
  51552. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51553. {
  51554. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51555. : scrollbar.getHeight());
  51556. }
  51557. const Path LookAndFeel::getTickShape (const float height)
  51558. {
  51559. static const unsigned char tickShapeData[] =
  51560. {
  51561. 109,0,224,168,68,0,0,119,67,108,0,224,172,68,0,128,146,67,113,0,192,148,68,0,0,219,67,0,96,110,68,0,224,56,68,113,0,64,51,68,0,32,130,68,0,64,20,68,0,224,
  51562. 162,68,108,0,128,3,68,0,128,168,68,113,0,128,221,67,0,192,175,68,0,0,207,67,0,32,179,68,113,0,0,201,67,0,224,173,68,0,0,181,67,0,224,161,68,108,0,128,168,67,
  51563. 0,128,154,68,113,0,128,141,67,0,192,138,68,0,128,108,67,0,64,131,68,113,0,0,62,67,0,128,119,68,0,0,5,67,0,128,114,68,113,0,0,102,67,0,192,88,68,0,128,155,
  51564. 67,0,192,88,68,113,0,0,190,67,0,192,88,68,0,128,232,67,0,224,131,68,108,0,128,246,67,0,192,139,68,113,0,64,33,68,0,128,87,68,0,0,93,68,0,224,26,68,113,0,
  51565. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51566. };
  51567. Path p;
  51568. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51569. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51570. return p;
  51571. }
  51572. const Path LookAndFeel::getCrossShape (const float height)
  51573. {
  51574. static const unsigned char crossShapeData[] =
  51575. {
  51576. 109,0,0,17,68,0,96,145,68,108,0,192,13,68,0,192,147,68,113,0,0,213,67,0,64,174,68,0,0,168,67,0,64,174,68,113,0,0,104,67,0,64,174,68,0,0,5,67,0,64,
  51577. 153,68,113,0,0,18,67,0,64,153,68,0,0,24,67,0,64,153,68,113,0,0,135,67,0,64,153,68,0,128,207,67,0,224,130,68,108,0,0,220,67,0,0,126,68,108,0,0,204,67,
  51578. 0,128,117,68,113,0,0,138,67,0,64,82,68,0,0,138,67,0,192,57,68,113,0,0,138,67,0,192,37,68,0,128,210,67,0,64,10,68,113,0,128,220,67,0,64,45,68,0,0,8,
  51579. 68,0,128,78,68,108,0,192,14,68,0,0,87,68,108,0,64,20,68,0,0,80,68,113,0,192,57,68,0,0,32,68,0,128,88,68,0,0,32,68,113,0,64,112,68,0,0,32,68,0,
  51580. 128,124,68,0,64,68,68,113,0,0,121,68,0,192,67,68,0,128,119,68,0,192,67,68,113,0,192,108,68,0,192,67,68,0,32,89,68,0,96,82,68,113,0,128,69,68,0,0,97,68,
  51581. 0,0,56,68,0,64,115,68,108,0,64,49,68,0,128,124,68,108,0,192,55,68,0,96,129,68,113,0,0,92,68,0,224,146,68,0,192,129,68,0,224,146,68,113,0,64,110,68,0,64,
  51582. 168,68,0,64,87,68,0,64,168,68,113,0,128,66,68,0,64,168,68,0,64,27,68,0,32,150,68,99,101
  51583. };
  51584. Path p;
  51585. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51586. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51587. return p;
  51588. }
  51589. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51590. {
  51591. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51592. x += (w - boxSize) >> 1;
  51593. y += (h - boxSize) >> 1;
  51594. w = boxSize;
  51595. h = boxSize;
  51596. g.setColour (Colour (0xe5ffffff));
  51597. g.fillRect (x, y, w, h);
  51598. g.setColour (Colour (0x80000000));
  51599. g.drawRect (x, y, w, h);
  51600. const float size = boxSize / 2 + 1.0f;
  51601. const float centre = (float) (boxSize / 2);
  51602. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51603. if (isPlus)
  51604. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51605. }
  51606. void LookAndFeel::drawBubble (Graphics& g,
  51607. float tipX, float tipY,
  51608. float boxX, float boxY,
  51609. float boxW, float boxH)
  51610. {
  51611. int side = 0;
  51612. if (tipX < boxX)
  51613. side = 1;
  51614. else if (tipX > boxX + boxW)
  51615. side = 3;
  51616. else if (tipY > boxY + boxH)
  51617. side = 2;
  51618. const float indent = 2.0f;
  51619. Path p;
  51620. p.addBubble (boxX + indent,
  51621. boxY + indent,
  51622. boxW - indent * 2.0f,
  51623. boxH - indent * 2.0f,
  51624. 5.0f,
  51625. tipX, tipY,
  51626. side,
  51627. 0.5f,
  51628. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51629. //xxx need to take comp as param for colour
  51630. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51631. g.fillPath (p);
  51632. //xxx as above
  51633. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51634. g.strokePath (p, PathStrokeType (1.33f));
  51635. }
  51636. const Font LookAndFeel::getPopupMenuFont()
  51637. {
  51638. return Font (17.0f);
  51639. }
  51640. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51641. const bool isSeparator,
  51642. int standardMenuItemHeight,
  51643. int& idealWidth,
  51644. int& idealHeight)
  51645. {
  51646. if (isSeparator)
  51647. {
  51648. idealWidth = 50;
  51649. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51650. }
  51651. else
  51652. {
  51653. Font font (getPopupMenuFont());
  51654. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51655. font.setHeight (standardMenuItemHeight / 1.3f);
  51656. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51657. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51658. }
  51659. }
  51660. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51661. {
  51662. const Colour background (findColour (PopupMenu::backgroundColourId));
  51663. g.fillAll (background);
  51664. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51665. for (int i = 0; i < height; i += 3)
  51666. g.fillRect (0, i, width, 1);
  51667. #if ! JUCE_MAC
  51668. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51669. g.drawRect (0, 0, width, height);
  51670. #endif
  51671. }
  51672. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51673. int width, int height,
  51674. bool isScrollUpArrow)
  51675. {
  51676. const Colour background (findColour (PopupMenu::backgroundColourId));
  51677. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51678. background.withAlpha (0.0f),
  51679. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51680. false));
  51681. g.fillRect (1, 1, width - 2, height - 2);
  51682. const float hw = width * 0.5f;
  51683. const float arrowW = height * 0.3f;
  51684. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51685. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51686. Path p;
  51687. p.addTriangle (hw - arrowW, y1,
  51688. hw + arrowW, y1,
  51689. hw, y2);
  51690. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51691. g.fillPath (p);
  51692. }
  51693. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51694. int width, int height,
  51695. const bool isSeparator,
  51696. const bool isActive,
  51697. const bool isHighlighted,
  51698. const bool isTicked,
  51699. const bool hasSubMenu,
  51700. const String& text,
  51701. const String& shortcutKeyText,
  51702. Image* image,
  51703. const Colour* const textColourToUse)
  51704. {
  51705. const float halfH = height * 0.5f;
  51706. if (isSeparator)
  51707. {
  51708. const float separatorIndent = 5.5f;
  51709. g.setColour (Colour (0x33000000));
  51710. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51711. g.setColour (Colour (0x66ffffff));
  51712. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51713. }
  51714. else
  51715. {
  51716. Colour textColour (findColour (PopupMenu::textColourId));
  51717. if (textColourToUse != 0)
  51718. textColour = *textColourToUse;
  51719. if (isHighlighted)
  51720. {
  51721. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51722. g.fillRect (1, 1, width - 2, height - 2);
  51723. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51724. }
  51725. else
  51726. {
  51727. g.setColour (textColour);
  51728. }
  51729. if (! isActive)
  51730. g.setOpacity (0.3f);
  51731. Font font (getPopupMenuFont());
  51732. if (font.getHeight() > height / 1.3f)
  51733. font.setHeight (height / 1.3f);
  51734. g.setFont (font);
  51735. const int leftBorder = (height * 5) / 4;
  51736. const int rightBorder = 4;
  51737. if (image != 0)
  51738. {
  51739. g.drawImageWithin (image,
  51740. 2, 1, leftBorder - 4, height - 2,
  51741. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51742. }
  51743. else if (isTicked)
  51744. {
  51745. const Path tick (getTickShape (1.0f));
  51746. const float th = font.getAscent();
  51747. const float ty = halfH - th * 0.5f;
  51748. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51749. th, true));
  51750. }
  51751. g.drawFittedText (text,
  51752. leftBorder, 0,
  51753. width - (leftBorder + rightBorder), height,
  51754. Justification::centredLeft, 1);
  51755. if (shortcutKeyText.isNotEmpty())
  51756. {
  51757. Font f2 (font);
  51758. f2.setHeight (f2.getHeight() * 0.75f);
  51759. f2.setHorizontalScale (0.95f);
  51760. g.setFont (f2);
  51761. g.drawText (shortcutKeyText,
  51762. leftBorder,
  51763. 0,
  51764. width - (leftBorder + rightBorder + 4),
  51765. height,
  51766. Justification::centredRight,
  51767. true);
  51768. }
  51769. if (hasSubMenu)
  51770. {
  51771. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51772. const float x = width - height * 0.6f;
  51773. Path p;
  51774. p.addTriangle (x, halfH - arrowH * 0.5f,
  51775. x, halfH + arrowH * 0.5f,
  51776. x + arrowH * 0.6f, halfH);
  51777. g.fillPath (p);
  51778. }
  51779. }
  51780. }
  51781. int LookAndFeel::getMenuWindowFlags()
  51782. {
  51783. return ComponentPeer::windowHasDropShadow;
  51784. }
  51785. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51786. bool, MenuBarComponent& menuBar)
  51787. {
  51788. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51789. if (menuBar.isEnabled())
  51790. {
  51791. drawShinyButtonShape (g,
  51792. -4.0f, 0.0f,
  51793. width + 8.0f, (float) height,
  51794. 0.0f,
  51795. baseColour,
  51796. 0.4f,
  51797. true, true, true, true);
  51798. }
  51799. else
  51800. {
  51801. g.fillAll (baseColour);
  51802. }
  51803. }
  51804. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51805. {
  51806. return Font (menuBar.getHeight() * 0.7f);
  51807. }
  51808. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51809. {
  51810. return getMenuBarFont (menuBar, itemIndex, itemText)
  51811. .getStringWidth (itemText) + menuBar.getHeight();
  51812. }
  51813. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51814. int width, int height,
  51815. int itemIndex,
  51816. const String& itemText,
  51817. bool isMouseOverItem,
  51818. bool isMenuOpen,
  51819. bool /*isMouseOverBar*/,
  51820. MenuBarComponent& menuBar)
  51821. {
  51822. if (! menuBar.isEnabled())
  51823. {
  51824. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51825. .withMultipliedAlpha (0.5f));
  51826. }
  51827. else if (isMenuOpen || isMouseOverItem)
  51828. {
  51829. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51830. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51831. }
  51832. else
  51833. {
  51834. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51835. }
  51836. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51837. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51838. }
  51839. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51840. TextEditor& textEditor)
  51841. {
  51842. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51843. }
  51844. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51845. {
  51846. if (textEditor.isEnabled())
  51847. {
  51848. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51849. {
  51850. const int border = 2;
  51851. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51852. g.drawRect (0, 0, width, height, border);
  51853. g.setOpacity (1.0f);
  51854. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51855. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51856. }
  51857. else
  51858. {
  51859. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51860. g.drawRect (0, 0, width, height);
  51861. g.setOpacity (1.0f);
  51862. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51863. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51864. }
  51865. }
  51866. }
  51867. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51868. const bool isButtonDown,
  51869. int buttonX, int buttonY,
  51870. int buttonW, int buttonH,
  51871. ComboBox& box)
  51872. {
  51873. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51874. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51875. {
  51876. g.setColour (box.findColour (TextButton::buttonColourId));
  51877. g.drawRect (0, 0, width, height, 2);
  51878. }
  51879. else
  51880. {
  51881. g.setColour (box.findColour (ComboBox::outlineColourId));
  51882. g.drawRect (0, 0, width, height);
  51883. }
  51884. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51885. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51886. box.hasKeyboardFocus (true),
  51887. false, isButtonDown)
  51888. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51889. drawGlassLozenge (g,
  51890. buttonX + outlineThickness, buttonY + outlineThickness,
  51891. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51892. baseColour, outlineThickness, -1.0f,
  51893. true, true, true, true);
  51894. if (box.isEnabled())
  51895. {
  51896. const float arrowX = 0.3f;
  51897. const float arrowH = 0.2f;
  51898. Path p;
  51899. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51900. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51901. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51902. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51903. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51904. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51905. g.setColour (box.findColour (ComboBox::arrowColourId));
  51906. g.fillPath (p);
  51907. }
  51908. }
  51909. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51910. {
  51911. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  51912. }
  51913. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  51914. {
  51915. return new Label (String::empty, String::empty);
  51916. }
  51917. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  51918. {
  51919. label.setBounds (1, 1,
  51920. box.getWidth() + 3 - box.getHeight(),
  51921. box.getHeight() - 2);
  51922. label.setFont (getComboBoxFont (box));
  51923. }
  51924. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  51925. {
  51926. g.fillAll (label.findColour (Label::backgroundColourId));
  51927. if (! label.isBeingEdited())
  51928. {
  51929. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  51930. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  51931. g.setFont (label.getFont());
  51932. g.drawFittedText (label.getText(),
  51933. label.getHorizontalBorderSize(),
  51934. label.getVerticalBorderSize(),
  51935. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  51936. label.getHeight() - 2 * label.getVerticalBorderSize(),
  51937. label.getJustificationType(),
  51938. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  51939. label.getMinimumHorizontalScale());
  51940. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  51941. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51942. }
  51943. else if (label.isEnabled())
  51944. {
  51945. g.setColour (label.findColour (Label::outlineColourId));
  51946. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51947. }
  51948. }
  51949. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  51950. int x, int y,
  51951. int width, int height,
  51952. float /*sliderPos*/,
  51953. float /*minSliderPos*/,
  51954. float /*maxSliderPos*/,
  51955. const Slider::SliderStyle /*style*/,
  51956. Slider& slider)
  51957. {
  51958. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  51959. const Colour trackColour (slider.findColour (Slider::trackColourId));
  51960. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  51961. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  51962. Path indent;
  51963. if (slider.isHorizontal())
  51964. {
  51965. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  51966. const float ih = sliderRadius;
  51967. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  51968. gradCol2, 0.0f, iy + ih, false));
  51969. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  51970. width + sliderRadius, ih,
  51971. 5.0f);
  51972. g.fillPath (indent);
  51973. }
  51974. else
  51975. {
  51976. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  51977. const float iw = sliderRadius;
  51978. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  51979. gradCol2, ix + iw, 0.0f, false));
  51980. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  51981. iw, height + sliderRadius,
  51982. 5.0f);
  51983. g.fillPath (indent);
  51984. }
  51985. g.setColour (Colour (0x4c000000));
  51986. g.strokePath (indent, PathStrokeType (0.5f));
  51987. }
  51988. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  51989. int x, int y,
  51990. int width, int height,
  51991. float sliderPos,
  51992. float minSliderPos,
  51993. float maxSliderPos,
  51994. const Slider::SliderStyle style,
  51995. Slider& slider)
  51996. {
  51997. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  51998. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  51999. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52000. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52001. slider.isMouseButtonDown() && slider.isEnabled()));
  52002. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52003. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52004. {
  52005. float kx, ky;
  52006. if (style == Slider::LinearVertical)
  52007. {
  52008. kx = x + width * 0.5f;
  52009. ky = sliderPos;
  52010. }
  52011. else
  52012. {
  52013. kx = sliderPos;
  52014. ky = y + height * 0.5f;
  52015. }
  52016. drawGlassSphere (g,
  52017. kx - sliderRadius,
  52018. ky - sliderRadius,
  52019. sliderRadius * 2.0f,
  52020. knobColour, outlineThickness);
  52021. }
  52022. else
  52023. {
  52024. if (style == Slider::ThreeValueVertical)
  52025. {
  52026. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52027. sliderPos - sliderRadius,
  52028. sliderRadius * 2.0f,
  52029. knobColour, outlineThickness);
  52030. }
  52031. else if (style == Slider::ThreeValueHorizontal)
  52032. {
  52033. drawGlassSphere (g,sliderPos - sliderRadius,
  52034. y + height * 0.5f - sliderRadius,
  52035. sliderRadius * 2.0f,
  52036. knobColour, outlineThickness);
  52037. }
  52038. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52039. {
  52040. const float sr = jmin (sliderRadius, width * 0.4f);
  52041. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52042. minSliderPos - sliderRadius,
  52043. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52044. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52045. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52046. }
  52047. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52048. {
  52049. const float sr = jmin (sliderRadius, height * 0.4f);
  52050. drawGlassPointer (g, minSliderPos - sr,
  52051. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52052. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52053. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52054. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52055. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52056. }
  52057. }
  52058. }
  52059. void LookAndFeel::drawLinearSlider (Graphics& g,
  52060. int x, int y,
  52061. int width, int height,
  52062. float sliderPos,
  52063. float minSliderPos,
  52064. float maxSliderPos,
  52065. const Slider::SliderStyle style,
  52066. Slider& slider)
  52067. {
  52068. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52069. if (style == Slider::LinearBar)
  52070. {
  52071. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52072. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52073. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52074. false,
  52075. isMouseOver,
  52076. isMouseOver || slider.isMouseButtonDown()));
  52077. drawShinyButtonShape (g,
  52078. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52079. baseColour,
  52080. slider.isEnabled() ? 0.9f : 0.3f,
  52081. true, true, true, true);
  52082. }
  52083. else
  52084. {
  52085. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52086. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52087. }
  52088. }
  52089. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52090. {
  52091. return jmin (7,
  52092. slider.getHeight() / 2,
  52093. slider.getWidth() / 2) + 2;
  52094. }
  52095. void LookAndFeel::drawRotarySlider (Graphics& g,
  52096. int x, int y,
  52097. int width, int height,
  52098. float sliderPos,
  52099. const float rotaryStartAngle,
  52100. const float rotaryEndAngle,
  52101. Slider& slider)
  52102. {
  52103. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52104. const float centreX = x + width * 0.5f;
  52105. const float centreY = y + height * 0.5f;
  52106. const float rx = centreX - radius;
  52107. const float ry = centreY - radius;
  52108. const float rw = radius * 2.0f;
  52109. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52110. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52111. if (radius > 12.0f)
  52112. {
  52113. if (slider.isEnabled())
  52114. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52115. else
  52116. g.setColour (Colour (0x80808080));
  52117. const float thickness = 0.7f;
  52118. {
  52119. Path filledArc;
  52120. filledArc.addPieSegment (rx, ry, rw, rw,
  52121. rotaryStartAngle,
  52122. angle,
  52123. thickness);
  52124. g.fillPath (filledArc);
  52125. }
  52126. if (thickness > 0)
  52127. {
  52128. const float innerRadius = radius * 0.2f;
  52129. Path p;
  52130. p.addTriangle (-innerRadius, 0.0f,
  52131. 0.0f, -radius * thickness * 1.1f,
  52132. innerRadius, 0.0f);
  52133. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52134. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52135. }
  52136. if (slider.isEnabled())
  52137. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52138. else
  52139. g.setColour (Colour (0x80808080));
  52140. Path outlineArc;
  52141. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52142. outlineArc.closeSubPath();
  52143. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52144. }
  52145. else
  52146. {
  52147. if (slider.isEnabled())
  52148. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52149. else
  52150. g.setColour (Colour (0x80808080));
  52151. Path p;
  52152. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52153. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52154. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52155. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52156. }
  52157. }
  52158. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52159. {
  52160. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52161. }
  52162. class SliderLabelComp : public Label
  52163. {
  52164. public:
  52165. SliderLabelComp() : Label (String::empty, String::empty) {}
  52166. ~SliderLabelComp() {}
  52167. void mouseWheelMove (const MouseEvent&, float, float) {}
  52168. };
  52169. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52170. {
  52171. Label* const l = new SliderLabelComp();
  52172. l->setJustificationType (Justification::centred);
  52173. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52174. l->setColour (Label::backgroundColourId,
  52175. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52176. : slider.findColour (Slider::textBoxBackgroundColourId));
  52177. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52178. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52179. l->setColour (TextEditor::backgroundColourId,
  52180. slider.findColour (Slider::textBoxBackgroundColourId)
  52181. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52182. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52183. return l;
  52184. }
  52185. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52186. {
  52187. return 0;
  52188. }
  52189. static const TextLayout layoutTooltipText (const String& text) throw()
  52190. {
  52191. const float tooltipFontSize = 12.0f;
  52192. const int maxToolTipWidth = 400;
  52193. const Font f (tooltipFontSize, Font::bold);
  52194. TextLayout tl (text, f);
  52195. tl.layout (maxToolTipWidth, Justification::left, true);
  52196. return tl;
  52197. }
  52198. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52199. {
  52200. const TextLayout tl (layoutTooltipText (tipText));
  52201. width = tl.getWidth() + 14;
  52202. height = tl.getHeight() + 6;
  52203. }
  52204. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52205. {
  52206. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52207. const Colour textCol (findColour (TooltipWindow::textColourId));
  52208. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52209. g.setColour (findColour (TooltipWindow::outlineColourId));
  52210. g.drawRect (0, 0, width, height, 1);
  52211. #endif
  52212. const TextLayout tl (layoutTooltipText (text));
  52213. g.setColour (findColour (TooltipWindow::textColourId));
  52214. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52215. }
  52216. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52217. {
  52218. return new TextButton (text, TRANS("click to browse for a different file"));
  52219. }
  52220. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52221. ComboBox* filenameBox,
  52222. Button* browseButton)
  52223. {
  52224. browseButton->setSize (80, filenameComp.getHeight());
  52225. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52226. if (tb != 0)
  52227. tb->changeWidthToFitText();
  52228. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52229. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52230. }
  52231. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52232. int imageX, int imageY, int imageW, int imageH,
  52233. const Colour& overlayColour,
  52234. float imageOpacity,
  52235. ImageButton& button)
  52236. {
  52237. if (! button.isEnabled())
  52238. imageOpacity *= 0.3f;
  52239. if (! overlayColour.isOpaque())
  52240. {
  52241. g.setOpacity (imageOpacity);
  52242. g.drawImage (image, imageX, imageY, imageW, imageH,
  52243. 0, 0, image->getWidth(), image->getHeight(), false);
  52244. }
  52245. if (! overlayColour.isTransparent())
  52246. {
  52247. g.setColour (overlayColour);
  52248. g.drawImage (image, imageX, imageY, imageW, imageH,
  52249. 0, 0, image->getWidth(), image->getHeight(), true);
  52250. }
  52251. }
  52252. void LookAndFeel::drawCornerResizer (Graphics& g,
  52253. int w, int h,
  52254. bool /*isMouseOver*/,
  52255. bool /*isMouseDragging*/)
  52256. {
  52257. const float lineThickness = jmin (w, h) * 0.075f;
  52258. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52259. {
  52260. g.setColour (Colours::lightgrey);
  52261. g.drawLine (w * i,
  52262. h + 1.0f,
  52263. w + 1.0f,
  52264. h * i,
  52265. lineThickness);
  52266. g.setColour (Colours::darkgrey);
  52267. g.drawLine (w * i + lineThickness,
  52268. h + 1.0f,
  52269. w + 1.0f,
  52270. h * i + lineThickness,
  52271. lineThickness);
  52272. }
  52273. }
  52274. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52275. const BorderSize& /*borders*/)
  52276. {
  52277. }
  52278. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52279. const BorderSize& /*border*/, ResizableWindow& window)
  52280. {
  52281. g.fillAll (window.getBackgroundColour());
  52282. }
  52283. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52284. const BorderSize& border, ResizableWindow&)
  52285. {
  52286. g.setColour (Colour (0x80000000));
  52287. g.drawRect (0, 0, w, h);
  52288. g.setColour (Colour (0x19000000));
  52289. g.drawRect (border.getLeft() - 1,
  52290. border.getTop() - 1,
  52291. w + 2 - border.getLeftAndRight(),
  52292. h + 2 - border.getTopAndBottom());
  52293. }
  52294. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52295. Graphics& g, int w, int h,
  52296. int titleSpaceX, int titleSpaceW,
  52297. const Image* icon,
  52298. bool drawTitleTextOnLeft)
  52299. {
  52300. const bool isActive = window.isActiveWindow();
  52301. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52302. 0.0f, 0.0f,
  52303. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52304. 0.0f, (float) h, false));
  52305. g.fillAll();
  52306. Font font (h * 0.65f, Font::bold);
  52307. g.setFont (font);
  52308. int textW = font.getStringWidth (window.getName());
  52309. int iconW = 0;
  52310. int iconH = 0;
  52311. if (icon != 0)
  52312. {
  52313. iconH = (int) font.getHeight();
  52314. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52315. }
  52316. textW = jmin (titleSpaceW, textW + iconW);
  52317. int textX = drawTitleTextOnLeft ? titleSpaceX
  52318. : jmax (titleSpaceX, (w - textW) / 2);
  52319. if (textX + textW > titleSpaceX + titleSpaceW)
  52320. textX = titleSpaceX + titleSpaceW - textW;
  52321. if (icon != 0)
  52322. {
  52323. g.setOpacity (isActive ? 1.0f : 0.6f);
  52324. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52325. RectanglePlacement::centred, false);
  52326. textX += iconW;
  52327. textW -= iconW;
  52328. }
  52329. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52330. g.setColour (findColour (DocumentWindow::textColourId));
  52331. else
  52332. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52333. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52334. }
  52335. class GlassWindowButton : public Button
  52336. {
  52337. public:
  52338. GlassWindowButton (const String& name, const Colour& col,
  52339. const Path& normalShape_,
  52340. const Path& toggledShape_) throw()
  52341. : Button (name),
  52342. colour (col),
  52343. normalShape (normalShape_),
  52344. toggledShape (toggledShape_)
  52345. {
  52346. }
  52347. ~GlassWindowButton()
  52348. {
  52349. }
  52350. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52351. {
  52352. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52353. if (! isEnabled())
  52354. alpha *= 0.5f;
  52355. float x = 0, y = 0, diam;
  52356. if (getWidth() < getHeight())
  52357. {
  52358. diam = (float) getWidth();
  52359. y = (getHeight() - getWidth()) * 0.5f;
  52360. }
  52361. else
  52362. {
  52363. diam = (float) getHeight();
  52364. y = (getWidth() - getHeight()) * 0.5f;
  52365. }
  52366. x += diam * 0.05f;
  52367. y += diam * 0.05f;
  52368. diam *= 0.9f;
  52369. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52370. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52371. g.fillEllipse (x, y, diam, diam);
  52372. x += 2.0f;
  52373. y += 2.0f;
  52374. diam -= 4.0f;
  52375. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52376. Path& p = getToggleState() ? toggledShape : normalShape;
  52377. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52378. diam * 0.4f, diam * 0.4f, true));
  52379. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52380. g.fillPath (p, t);
  52381. }
  52382. juce_UseDebuggingNewOperator
  52383. private:
  52384. Colour colour;
  52385. Path normalShape, toggledShape;
  52386. GlassWindowButton (const GlassWindowButton&);
  52387. GlassWindowButton& operator= (const GlassWindowButton&);
  52388. };
  52389. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52390. {
  52391. Path shape;
  52392. const float crossThickness = 0.25f;
  52393. if (buttonType == DocumentWindow::closeButton)
  52394. {
  52395. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52396. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52397. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52398. }
  52399. else if (buttonType == DocumentWindow::minimiseButton)
  52400. {
  52401. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52402. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52403. }
  52404. else if (buttonType == DocumentWindow::maximiseButton)
  52405. {
  52406. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52407. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52408. Path fullscreenShape;
  52409. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52410. fullscreenShape.lineTo (0.0f, 100.0f);
  52411. fullscreenShape.lineTo (0.0f, 0.0f);
  52412. fullscreenShape.lineTo (100.0f, 0.0f);
  52413. fullscreenShape.lineTo (100.0f, 45.0f);
  52414. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52415. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52416. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52417. }
  52418. jassertfalse
  52419. return 0;
  52420. }
  52421. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52422. int titleBarX,
  52423. int titleBarY,
  52424. int titleBarW,
  52425. int titleBarH,
  52426. Button* minimiseButton,
  52427. Button* maximiseButton,
  52428. Button* closeButton,
  52429. bool positionTitleBarButtonsOnLeft)
  52430. {
  52431. const int buttonW = titleBarH - titleBarH / 8;
  52432. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52433. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52434. if (closeButton != 0)
  52435. {
  52436. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52437. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52438. }
  52439. if (positionTitleBarButtonsOnLeft)
  52440. swapVariables (minimiseButton, maximiseButton);
  52441. if (maximiseButton != 0)
  52442. {
  52443. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52444. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52445. }
  52446. if (minimiseButton != 0)
  52447. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52448. }
  52449. int LookAndFeel::getDefaultMenuBarHeight()
  52450. {
  52451. return 24;
  52452. }
  52453. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52454. {
  52455. return new DropShadower (0.4f, 1, 5, 10);
  52456. }
  52457. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52458. int w, int h,
  52459. bool /*isVerticalBar*/,
  52460. bool isMouseOver,
  52461. bool isMouseDragging)
  52462. {
  52463. float alpha = 0.5f;
  52464. if (isMouseOver || isMouseDragging)
  52465. {
  52466. g.fillAll (Colour (0x190000ff));
  52467. alpha = 1.0f;
  52468. }
  52469. const float cx = w * 0.5f;
  52470. const float cy = h * 0.5f;
  52471. const float cr = jmin (w, h) * 0.4f;
  52472. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52473. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52474. true));
  52475. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52476. }
  52477. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52478. const String& text,
  52479. const Justification& position,
  52480. GroupComponent& group)
  52481. {
  52482. const float textH = 15.0f;
  52483. const float indent = 3.0f;
  52484. const float textEdgeGap = 4.0f;
  52485. float cs = 5.0f;
  52486. Font f (textH);
  52487. Path p;
  52488. float x = indent;
  52489. float y = f.getAscent() - 3.0f;
  52490. float w = jmax (0.0f, width - x * 2.0f);
  52491. float h = jmax (0.0f, height - y - indent);
  52492. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52493. const float cs2 = 2.0f * cs;
  52494. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52495. float textX = cs + textEdgeGap;
  52496. if (position.testFlags (Justification::horizontallyCentred))
  52497. textX = cs + (w - cs2 - textW) * 0.5f;
  52498. else if (position.testFlags (Justification::right))
  52499. textX = w - cs - textW - textEdgeGap;
  52500. p.startNewSubPath (x + textX + textW, y);
  52501. p.lineTo (x + w - cs, y);
  52502. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52503. p.lineTo (x + w, y + h - cs);
  52504. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52505. p.lineTo (x + cs, y + h);
  52506. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52507. p.lineTo (x, y + cs);
  52508. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52509. p.lineTo (x + textX, y);
  52510. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52511. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52512. .withMultipliedAlpha (alpha));
  52513. g.strokePath (p, PathStrokeType (2.0f));
  52514. g.setColour (group.findColour (GroupComponent::textColourId)
  52515. .withMultipliedAlpha (alpha));
  52516. g.setFont (f);
  52517. g.drawText (text,
  52518. roundToInt (x + textX), 0,
  52519. roundToInt (textW),
  52520. roundToInt (textH),
  52521. Justification::centred, true);
  52522. }
  52523. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52524. {
  52525. return 1 + tabDepth / 3;
  52526. }
  52527. int LookAndFeel::getTabButtonSpaceAroundImage()
  52528. {
  52529. return 4;
  52530. }
  52531. void LookAndFeel::createTabButtonShape (Path& p,
  52532. int width, int height,
  52533. int /*tabIndex*/,
  52534. const String& /*text*/,
  52535. Button& /*button*/,
  52536. TabbedButtonBar::Orientation orientation,
  52537. const bool /*isMouseOver*/,
  52538. const bool /*isMouseDown*/,
  52539. const bool /*isFrontTab*/)
  52540. {
  52541. const float w = (float) width;
  52542. const float h = (float) height;
  52543. float length = w;
  52544. float depth = h;
  52545. if (orientation == TabbedButtonBar::TabsAtLeft
  52546. || orientation == TabbedButtonBar::TabsAtRight)
  52547. {
  52548. swapVariables (length, depth);
  52549. }
  52550. const float indent = (float) getTabButtonOverlap ((int) depth);
  52551. const float overhang = 4.0f;
  52552. if (orientation == TabbedButtonBar::TabsAtLeft)
  52553. {
  52554. p.startNewSubPath (w, 0.0f);
  52555. p.lineTo (0.0f, indent);
  52556. p.lineTo (0.0f, h - indent);
  52557. p.lineTo (w, h);
  52558. p.lineTo (w + overhang, h + overhang);
  52559. p.lineTo (w + overhang, -overhang);
  52560. }
  52561. else if (orientation == TabbedButtonBar::TabsAtRight)
  52562. {
  52563. p.startNewSubPath (0.0f, 0.0f);
  52564. p.lineTo (w, indent);
  52565. p.lineTo (w, h - indent);
  52566. p.lineTo (0.0f, h);
  52567. p.lineTo (-overhang, h + overhang);
  52568. p.lineTo (-overhang, -overhang);
  52569. }
  52570. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52571. {
  52572. p.startNewSubPath (0.0f, 0.0f);
  52573. p.lineTo (indent, h);
  52574. p.lineTo (w - indent, h);
  52575. p.lineTo (w, 0.0f);
  52576. p.lineTo (w + overhang, -overhang);
  52577. p.lineTo (-overhang, -overhang);
  52578. }
  52579. else
  52580. {
  52581. p.startNewSubPath (0.0f, h);
  52582. p.lineTo (indent, 0.0f);
  52583. p.lineTo (w - indent, 0.0f);
  52584. p.lineTo (w, h);
  52585. p.lineTo (w + overhang, h + overhang);
  52586. p.lineTo (-overhang, h + overhang);
  52587. }
  52588. p.closeSubPath();
  52589. p = p.createPathWithRoundedCorners (3.0f);
  52590. }
  52591. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52592. const Path& path,
  52593. const Colour& preferredColour,
  52594. int /*tabIndex*/,
  52595. const String& /*text*/,
  52596. Button& button,
  52597. TabbedButtonBar::Orientation /*orientation*/,
  52598. const bool /*isMouseOver*/,
  52599. const bool /*isMouseDown*/,
  52600. const bool isFrontTab)
  52601. {
  52602. g.setColour (isFrontTab ? preferredColour
  52603. : preferredColour.withMultipliedAlpha (0.9f));
  52604. g.fillPath (path);
  52605. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52606. : TabbedButtonBar::tabOutlineColourId, false)
  52607. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52608. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52609. }
  52610. void LookAndFeel::drawTabButtonText (Graphics& g,
  52611. int x, int y, int w, int h,
  52612. const Colour& preferredBackgroundColour,
  52613. int /*tabIndex*/,
  52614. const String& text,
  52615. Button& button,
  52616. TabbedButtonBar::Orientation orientation,
  52617. const bool isMouseOver,
  52618. const bool isMouseDown,
  52619. const bool isFrontTab)
  52620. {
  52621. int length = w;
  52622. int depth = h;
  52623. if (orientation == TabbedButtonBar::TabsAtLeft
  52624. || orientation == TabbedButtonBar::TabsAtRight)
  52625. {
  52626. swapVariables (length, depth);
  52627. }
  52628. Font font (depth * 0.6f);
  52629. font.setUnderline (button.hasKeyboardFocus (false));
  52630. GlyphArrangement textLayout;
  52631. textLayout.addFittedText (font, text.trim(),
  52632. 0.0f, 0.0f, (float) length, (float) depth,
  52633. Justification::centred,
  52634. jmax (1, depth / 12));
  52635. AffineTransform transform;
  52636. if (orientation == TabbedButtonBar::TabsAtLeft)
  52637. {
  52638. transform = transform.rotated (float_Pi * -0.5f)
  52639. .translated ((float) x, (float) (y + h));
  52640. }
  52641. else if (orientation == TabbedButtonBar::TabsAtRight)
  52642. {
  52643. transform = transform.rotated (float_Pi * 0.5f)
  52644. .translated ((float) (x + w), (float) y);
  52645. }
  52646. else
  52647. {
  52648. transform = transform.translated ((float) x, (float) y);
  52649. }
  52650. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52651. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52652. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52653. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52654. else
  52655. g.setColour (preferredBackgroundColour.contrasting());
  52656. if (! (isMouseOver || isMouseDown))
  52657. g.setOpacity (0.8f);
  52658. if (! button.isEnabled())
  52659. g.setOpacity (0.3f);
  52660. textLayout.draw (g, transform);
  52661. }
  52662. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52663. const String& text,
  52664. int tabDepth,
  52665. Button&)
  52666. {
  52667. Font f (tabDepth * 0.6f);
  52668. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52669. }
  52670. void LookAndFeel::drawTabButton (Graphics& g,
  52671. int w, int h,
  52672. const Colour& preferredColour,
  52673. int tabIndex,
  52674. const String& text,
  52675. Button& button,
  52676. TabbedButtonBar::Orientation orientation,
  52677. const bool isMouseOver,
  52678. const bool isMouseDown,
  52679. const bool isFrontTab)
  52680. {
  52681. int length = w;
  52682. int depth = h;
  52683. if (orientation == TabbedButtonBar::TabsAtLeft
  52684. || orientation == TabbedButtonBar::TabsAtRight)
  52685. {
  52686. swapVariables (length, depth);
  52687. }
  52688. Path tabShape;
  52689. createTabButtonShape (tabShape, w, h,
  52690. tabIndex, text, button, orientation,
  52691. isMouseOver, isMouseDown, isFrontTab);
  52692. fillTabButtonShape (g, tabShape, preferredColour,
  52693. tabIndex, text, button, orientation,
  52694. isMouseOver, isMouseDown, isFrontTab);
  52695. const int indent = getTabButtonOverlap (depth);
  52696. int x = 0, y = 0;
  52697. if (orientation == TabbedButtonBar::TabsAtLeft
  52698. || orientation == TabbedButtonBar::TabsAtRight)
  52699. {
  52700. y += indent;
  52701. h -= indent * 2;
  52702. }
  52703. else
  52704. {
  52705. x += indent;
  52706. w -= indent * 2;
  52707. }
  52708. drawTabButtonText (g, x, y, w, h, preferredColour,
  52709. tabIndex, text, button, orientation,
  52710. isMouseOver, isMouseDown, isFrontTab);
  52711. }
  52712. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52713. int w, int h,
  52714. TabbedButtonBar& tabBar,
  52715. TabbedButtonBar::Orientation orientation)
  52716. {
  52717. const float shadowSize = 0.2f;
  52718. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52719. Rectangle<int> shadowRect;
  52720. if (orientation == TabbedButtonBar::TabsAtLeft)
  52721. {
  52722. x1 = (float) w;
  52723. x2 = w * (1.0f - shadowSize);
  52724. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52725. }
  52726. else if (orientation == TabbedButtonBar::TabsAtRight)
  52727. {
  52728. x2 = w * shadowSize;
  52729. shadowRect.setBounds (0, 0, (int) x2, h);
  52730. }
  52731. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52732. {
  52733. y2 = h * shadowSize;
  52734. shadowRect.setBounds (0, 0, w, (int) y2);
  52735. }
  52736. else
  52737. {
  52738. y1 = (float) h;
  52739. y2 = h * (1.0f - shadowSize);
  52740. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52741. }
  52742. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52743. Colours::transparentBlack, x2, y2, false));
  52744. shadowRect.expand (2, 2);
  52745. g.fillRect (shadowRect);
  52746. g.setColour (Colour (0x80000000));
  52747. if (orientation == TabbedButtonBar::TabsAtLeft)
  52748. {
  52749. g.fillRect (w - 1, 0, 1, h);
  52750. }
  52751. else if (orientation == TabbedButtonBar::TabsAtRight)
  52752. {
  52753. g.fillRect (0, 0, 1, h);
  52754. }
  52755. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52756. {
  52757. g.fillRect (0, 0, w, 1);
  52758. }
  52759. else
  52760. {
  52761. g.fillRect (0, h - 1, w, 1);
  52762. }
  52763. }
  52764. Button* LookAndFeel::createTabBarExtrasButton()
  52765. {
  52766. const float thickness = 7.0f;
  52767. const float indent = 22.0f;
  52768. Path p;
  52769. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52770. DrawablePath ellipse;
  52771. ellipse.setPath (p);
  52772. ellipse.setFill (Colour (0x99ffffff));
  52773. p.clear();
  52774. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52775. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52776. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52777. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52778. p.setUsingNonZeroWinding (false);
  52779. DrawablePath dp;
  52780. dp.setPath (p);
  52781. dp.setFill (Colour (0x59000000));
  52782. DrawableComposite normalImage;
  52783. normalImage.insertDrawable (ellipse);
  52784. normalImage.insertDrawable (dp);
  52785. dp.setFill (Colour (0xcc000000));
  52786. DrawableComposite overImage;
  52787. overImage.insertDrawable (ellipse);
  52788. overImage.insertDrawable (dp);
  52789. DrawableButton* db = new DrawableButton ("tabs", DrawableButton::ImageFitted);
  52790. db->setImages (&normalImage, &overImage, 0);
  52791. return db;
  52792. }
  52793. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52794. {
  52795. g.fillAll (Colours::white);
  52796. const int w = header.getWidth();
  52797. const int h = header.getHeight();
  52798. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52799. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52800. false));
  52801. g.fillRect (0, h / 2, w, h);
  52802. g.setColour (Colour (0x33000000));
  52803. g.fillRect (0, h - 1, w, 1);
  52804. for (int i = header.getNumColumns (true); --i >= 0;)
  52805. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52806. }
  52807. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52808. int width, int height,
  52809. bool isMouseOver, bool isMouseDown,
  52810. int columnFlags)
  52811. {
  52812. if (isMouseDown)
  52813. g.fillAll (Colour (0x8899aadd));
  52814. else if (isMouseOver)
  52815. g.fillAll (Colour (0x5599aadd));
  52816. int rightOfText = width - 4;
  52817. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52818. {
  52819. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52820. const float bottom = height - top;
  52821. const float w = height * 0.5f;
  52822. const float x = rightOfText - (w * 1.25f);
  52823. rightOfText = (int) x;
  52824. Path sortArrow;
  52825. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52826. g.setColour (Colour (0x99000000));
  52827. g.fillPath (sortArrow);
  52828. }
  52829. g.setColour (Colours::black);
  52830. g.setFont (height * 0.5f, Font::bold);
  52831. const int textX = 4;
  52832. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52833. }
  52834. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52835. {
  52836. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52837. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52838. background.darker (0.1f),
  52839. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52840. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52841. false));
  52842. g.fillAll();
  52843. }
  52844. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52845. {
  52846. return createTabBarExtrasButton();
  52847. }
  52848. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52849. bool isMouseOver, bool isMouseDown,
  52850. ToolbarItemComponent& component)
  52851. {
  52852. if (isMouseDown)
  52853. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52854. else if (isMouseOver)
  52855. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52856. }
  52857. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52858. const String& text, ToolbarItemComponent& component)
  52859. {
  52860. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52861. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52862. const float fontHeight = jmin (14.0f, height * 0.85f);
  52863. g.setFont (fontHeight);
  52864. g.drawFittedText (text,
  52865. x, y, width, height,
  52866. Justification::centred,
  52867. jmax (1, height / (int) fontHeight));
  52868. }
  52869. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52870. bool isOpen, int width, int height)
  52871. {
  52872. const int buttonSize = (height * 3) / 4;
  52873. const int buttonIndent = (height - buttonSize) / 2;
  52874. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52875. const int textX = buttonIndent * 2 + buttonSize + 2;
  52876. g.setColour (Colours::black);
  52877. g.setFont (height * 0.7f, Font::bold);
  52878. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52879. }
  52880. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52881. PropertyComponent&)
  52882. {
  52883. g.setColour (Colour (0x66ffffff));
  52884. g.fillRect (0, 0, width, height - 1);
  52885. }
  52886. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52887. PropertyComponent& component)
  52888. {
  52889. g.setColour (Colours::black);
  52890. if (! component.isEnabled())
  52891. g.setOpacity (0.6f);
  52892. g.setFont (jmin (height, 24) * 0.65f);
  52893. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52894. g.drawFittedText (component.getName(),
  52895. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52896. Justification::centredLeft, 2);
  52897. }
  52898. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52899. {
  52900. return Rectangle<int> (component.getWidth() / 3, 1,
  52901. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52902. }
  52903. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52904. const String& instructions,
  52905. GlyphArrangement& text,
  52906. int width)
  52907. {
  52908. text.clear();
  52909. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52910. 8.0f, 22.0f, width - 16.0f,
  52911. Justification::centred);
  52912. text.addJustifiedText (Font (14.0f), instructions,
  52913. 8.0f, 24.0f + 16.0f, width - 16.0f,
  52914. Justification::centred);
  52915. }
  52916. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  52917. const String& filename, Image* icon,
  52918. const String& fileSizeDescription,
  52919. const String& fileTimeDescription,
  52920. const bool isDirectory,
  52921. const bool isItemSelected,
  52922. const int /*itemIndex*/)
  52923. {
  52924. if (isItemSelected)
  52925. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  52926. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  52927. g.setFont (height * 0.7f);
  52928. Image* im = icon;
  52929. Image* toRelease = 0;
  52930. if (im == 0)
  52931. {
  52932. toRelease = im = (isDirectory ? getDefaultFolderImage()
  52933. : getDefaultDocumentFileImage());
  52934. }
  52935. const int x = 32;
  52936. if (im != 0)
  52937. {
  52938. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  52939. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  52940. false);
  52941. ImageCache::release (toRelease);
  52942. }
  52943. if (width > 450 && ! isDirectory)
  52944. {
  52945. const int sizeX = roundToInt (width * 0.7f);
  52946. const int dateX = roundToInt (width * 0.8f);
  52947. g.drawFittedText (filename,
  52948. x, 0, sizeX - x, height,
  52949. Justification::centredLeft, 1);
  52950. g.setFont (height * 0.5f);
  52951. g.setColour (Colours::darkgrey);
  52952. if (! isDirectory)
  52953. {
  52954. g.drawFittedText (fileSizeDescription,
  52955. sizeX, 0, dateX - sizeX - 8, height,
  52956. Justification::centredRight, 1);
  52957. g.drawFittedText (fileTimeDescription,
  52958. dateX, 0, width - 8 - dateX, height,
  52959. Justification::centredRight, 1);
  52960. }
  52961. }
  52962. else
  52963. {
  52964. g.drawFittedText (filename,
  52965. x, 0, width - x, height,
  52966. Justification::centredLeft, 1);
  52967. }
  52968. }
  52969. Button* LookAndFeel::createFileBrowserGoUpButton()
  52970. {
  52971. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  52972. Path arrowPath;
  52973. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  52974. DrawablePath arrowImage;
  52975. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  52976. arrowImage.setPath (arrowPath);
  52977. goUpButton->setImages (&arrowImage);
  52978. return goUpButton;
  52979. }
  52980. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  52981. DirectoryContentsDisplayComponent* fileListComponent,
  52982. FilePreviewComponent* previewComp,
  52983. ComboBox* currentPathBox,
  52984. TextEditor* filenameBox,
  52985. Button* goUpButton)
  52986. {
  52987. const int x = 8;
  52988. int w = browserComp.getWidth() - x - x;
  52989. if (previewComp != 0)
  52990. {
  52991. const int previewWidth = w / 3;
  52992. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  52993. w -= previewWidth + 4;
  52994. }
  52995. int y = 4;
  52996. const int controlsHeight = 22;
  52997. const int bottomSectionHeight = controlsHeight + 8;
  52998. const int upButtonWidth = 50;
  52999. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53000. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53001. y += controlsHeight + 4;
  53002. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53003. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53004. y = listAsComp->getBottom() + 4;
  53005. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53006. }
  53007. Image* LookAndFeel::getDefaultFolderImage()
  53008. {
  53009. static const unsigned char foldericon_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,28,8,6,0,0,0,0,194,189,34,0,0,0,4,103,65,77,65,0,0,175,200,55,5,
  53010. 138,233,0,0,0,25,116,69,88,116,83,111,102,116,119,97,114,101,0,65,100,111,98,101,32,73,109,97,103,101,82,101,97,100,121,113,201,101,60,0,0,9,46,73,68,65,84,120,218,98,252,255,255,63,3,50,240,41,95,192,
  53011. 197,205,198,32,202,204,202,33,241,254,235,47,133,47,191,24,180,213,164,133,152,69,24,222,44,234,42,77,188,245,31,170,129,145,145,145,1,29,128,164,226,91,86,113,252,248,207,200,171,37,39,204,239,170,43,
  53012. 254,206,218,88,231,61,62,61,0,1,196,2,149,96,116,200,158,102,194,202,201,227,197,193,206,166,194,204,193,33,195,202,204,38,42,197,197,42,196,193,202,33,240,241,231,15,134,151,95,127,9,2,149,22,0,241,47,
  53013. 152,230,128,134,245,204,63,191,188,103,83,144,16,16,228,229,102,151,76,239,217,32,199,204,198,169,205,254,159,65,245,203,79,6,169,131,151,30,47,1,42,91,10,196,127,208,236,101,76,235,90,43,101,160,40,242,
  53014. 19,32,128,64,78,98,52,12,41,149,145,215,52,89,162,38,35,107,39,196,203,203,192,206,194,206,192,197,198,202,192,203,197,198,192,205,193,206,240,252,227,103,134,139,55,175,191,127,243,242,78,219,187,207,
  53015. 63,215,255,98,23,48,228,227,96,83,98,102,102,85,225,224,228,80,20,224,230,86,226,225,228,150,103,101,97,101,230,227,228,96,224,0,234,191,243,252,5,195,222,19,199,38,191,127,112,161,83,66,199,86,141,131,
  53016. 149,69,146,133,153,69,137,149,133,89,157,141,131,77,83,140,143,243,219,255,31,159,123,0,2,136,69,90,207,129,157,71,68,42,66,71,73,209,210,81,91,27,24,142,140,12,127,255,253,103,0,185,236,31,3,144,6,50,
  53017. 148,68,216,25,216,24,117,4,239,11,243,214,49,50,51,84,178,48,114,240,112,177,114,177,240,115,113,49,241,112,112,48,176,179,178,51,176,48,49,3,85,255,99,248,253,247,15,195,247,159,191,25,30,191,126,253,
  53018. 71,74,76,200,66,75,197,119,138,168,144,160,150,168,0,183,160,152,32,15,175,188,184,32,199,175,191,127,25,214,31,184,120,247,236,209,253,159,0,2,136,133,95,70,93,74,88,80,196,83,69,66,130,149,9,104,219,
  53019. 151,31,191,193,150,194,146,6,136,102,102,98,100,16,227,231,103,16,23,210,230,101,101,102,100,248,255,143,137,225,223,63,6,6,22,102,38,134,239,191,126,49,220,123,241,134,225,227,247,175,64,7,252,101,96,
  53020. 97,249,207,192,193,198,200,160,171,34,192,108,165,235,104,42,204,207,101,42,194,199,197,192,199,201,198,192,197,193,202,192,198,202,194,176,247,194,3,134,155,183,110,61,188,127,124,221,19,128,0,92,146,
  53021. 49,14,64,64,16,69,63,153,85,16,52,18,74,71,112,6,87,119,0,165,160,86,138,32,172,216,29,49,182,84,253,169,94,94,230,127,17,87,133,34,146,174,3,88,126,240,219,164,147,113,31,145,244,152,112,179,211,130,
  53022. 34,31,203,113,162,233,6,36,49,163,174,74,124,140,60,141,144,165,161,220,228,25,3,24,105,255,17,168,101,1,139,245,188,93,104,251,73,239,235,50,90,189,111,175,0,98,249,254,254,249,175,239,223,190,126,6,
  53023. 5,27,19,47,90,170,102,0,249,158,129,129,141,133,25,228,20,6,38,38,72,74,7,185,243,243,247,239,12,23,31,60,98,228,231,253,207,144,227,107,206,32,202,199,193,240,249,251,127,134,95,191,255,49,124,249,250,
  53024. 159,225,237,239,95,12,63,127,1,35,229,31,194,71,32,71,63,123,251,245,223,197,27,183,159,189,187,178,103,61,80,232,59,64,0,177,48,252,5,134,225,255,191,223,126,254,250,13,182,132,1,41,167,176,3,53,128,
  53025. 188,254,226,253,103,96,212,252,96,120,247,249,203,255,79,223,191,254,255,250,235,199,191,239,63,191,255,87,145,17,100,73,116,181,100,252,249,243,63,195,149,123,223,193,14,132,101,55,96,52,3,125,255,15,
  53026. 204,254,15,132,160,232,253,13,20,124,248,226,227,223,23,207,30,221,120,119,255,226,109,160,210,31,0,1,196,242,231,219,135,175,140,255,126,190,7,197,37,35,19,34,216,65,248,211,143,111,255,79,223,121,240,
  53027. 255,211,183,79,76,220,156,172,12,236,204,140,140,252,124,28,140,250,226,82,140,106,82,34,140,124,156,156,12,175,222,253,1,90,4,137,162,63,127,33,161,6,178,242,215,239,255,224,160,255,15,198,12,64,7,48,
  53028. 128,211,200,253,151,111,254,254,248,240,236,44,80,217,71,80,246,4,8,32,160,31,255,255,100,102,248,243,238,199,159,63,16,221,16,19,128,248,31,195,181,199,207,254,255,253,247,133,49,212,78,27,104,8,11,40,
  53029. 94,25,184,216,89,129,108,38,70,144,242,183,31,17,105,230,63,148,248,15,97,49,252,248,249,15,20,85,72,105,9,148,187,254,49,220,127,254,242,207,243,75,135,14,128,130,31,84,64,1,4,16,203,247,143,175,127,
  53030. 48,253,254,246,234,7,48,206,96,137,13,4,64,65,248,234,195,7,6,7,3,57,70,33,46,97,134,111,63,254,50,252,5,250,244,51,216,103,255,192,185,0,150,91,80,44,135,242,127,253,129,164,23,24,96,102,250,207,112,
  53031. 255,213,219,255,247,31,63,188,251,246,201,173,199,176,2,13,32,128,88,62,188,121,241,243,211,231,207,31,126,2,147,236,63,168,6,144,193,223,190,255,254,207,198,198,192,40,35,44,206,240,252,205,79,6,132,
  53032. 223,24,224,150,32,251,28,25,128,211,29,19,170,24,51,48,88,111,61,127,206,248,254,245,179,139,192,18,247,219,239,239,95,192,249,9,32,128,88,126,124,249,248,231,203,183,111,159,128,33,240,15,24,68,160,180,
  53033. 2,204,223,140,12,111,63,127,102,16,228,229,4,6,53,35,195,31,176,119,25,112,3,70,84,55,0,203,50,112,33,134,108,249,103,160,7,159,189,126,253,235,235,227,203,7,255,255,251,247,13,86,63,0,4,16,168,46,248,
  53034. 199,250,231,243,235,159,191,126,254,248,245,251,47,23,11,51,51,48,184,152,24,94,127,250,248,95,68,136,151,241,243,55,96,208,51,160,218,255,31,139,27,144,197,254,98,201,202,79,223,124,96,120,245,232,250,
  53035. 185,119,143,174,95,250,243,243,219,119,152,60,64,0,129,2,234,223,183,215,15,95,48,254,255,253,3,146,109,192,229,5,195,135,47,159,25,248,184,121,24,126,0,227,29,88,240,49,252,101,36,14,255,1,90,249,7,156,
  53036. 222,17,24,24,164,12,207,223,189,99,248,250,252,230,97,96,229,245,2,104,231,111,152,3,0,2,8,228,128,191,15,239,220,120,255,255,223,159,47,160,116,0,42,44,222,124,250,244,239,207,255,63,12,236,108,236,64,
  53037. 67,65,81,0,52,244,63,113,248,47,52,10,96,14,98,2,230,191,119,223,127,48,60,121,254,248,235,151,55,207,46,1,163,252,35,114,128,1,4,16,40,10,254,191,121,249,252,199,175,159,63,191,254,2,230,45,118,22,22,
  53038. 134,219,207,94,252,231,224,100,103,250,247,15,148,32,64,85,12,34,14,254,227,72,6,255,225,9,240,63,138,26,46,96,214,189,249,244,37,195,139,167,143,30,124,253,246,253,9,40,245,255,71,202,30,0,1,196,2,226,
  53039. 0,243,232,159,239,63,127,124,253,11,202,94,64,169,23,31,62,50,138,137,242,49,50,0,211,195,223,255,80,7,252,199,159,6,224,137,145,9,146,231,153,160,165,218,23,96,29,240,244,237,59,134,111,175,31,95,250,
  53040. 252,230,241,83,244,182,1,64,0,177,192,28,14,76,132,31,128,169,19,88,220,126,253,207,206,198,196,32,38,36,0,244,61,11,176,148,251,139,145,3,208,29,0,178,16,82,228,66,42,174,223,192,26,8,152,162,25,222,
  53041. 125,248,200,240,242,253,39,134,151,79,238,126,254,242,242,238,177,15,47,30,190,5,215,242,72,0,32,128,224,14,96,254,255,231,61,168,92,123,241,254,253,127,1,62,78,6,78,110,78,134,223,64,195,254,50,98,183,
  53042. 24,36,12,202,179,224,202,9,88,228,253,132,90,250,246,211,71,134,55,175,94,254,122,255,250,249,247,15,175,159,126,249,251,237,195,135,95,175,110,31,122,117,251,244,49,160,150,111,255,209,218,128,0,1,152,
  53043. 44,183,21,0,65,32,136,110,247,254,255,243,122,9,187,64,105,174,74,22,138,25,173,80,208,194,188,238,156,151,217,217,15,32,182,197,37,83,201,4,31,243,178,169,232,242,214,224,223,252,103,175,35,85,1,41,129,
  53044. 228,148,142,8,214,30,32,149,6,161,204,109,182,53,236,184,156,78,142,147,195,153,89,35,198,3,87,166,249,220,227,198,59,218,48,252,223,185,111,30,1,132,228,128,127,31,222,124,248,248,27,24,152,28,60,220,
  53045. 220,12,44,172,172,224,224,103,5,102,98,144,133,160,236,244,229,231,47,134,239,223,127,49,188,121,251,158,225,241,179,103,12,31,223,189,254,251,227,221,139,55,191,62,188,120,246,235,205,189,59,207,238,
  53046. 94,58,241,228,254,109,144,101,159,128,248,51,40,9,32,97,80,217,255,15,221,1,0,1,4,143,130,207,159,191,126,252,246,234,213,111,94,126,94,118,73,94,9,198,127,64,223,126,252,246,147,225,243,215,239,12,223,
  53047. 128,229,198,251,15,239,24,62,189,126,249,227,203,171,135,47,63,189,122,252,228,235,155,199,247,95,63,188,118,227,197,227,123,247,127,255,250,249,30,104,198,7,32,126,11,181,252,7,212,183,160,4,247,7,155,
  53048. 197,48,0,16,64,112,7,60,121,241,238,189,16,207,15,134,63,63,216,25,95,125,248,198,112,227,241,27,134,15,239,223,50,124,126,245,228,253,143,55,143,158,191,123,116,237,226,171,135,55,175,126,253,252,225,
  53049. 229,183,47,159,95,254,253,245,227,253,175,159,223,223,193,124,7,181,20,84,105,252,70,143,103,124,0,32,128,224,14,224,102,253,251,81,144,253,223,235,167,207,30,254,124,127,231,252,155,143,175,159,188,250,
  53050. 246,254,249,125,96,60,62,248,250,233,253,147,119,207,238,221,6,150,214,175,129,106,191,130,18,19,146,133,120,125,72,8,0,4,16,34,27,190,121,112,251,3,211,159,69,143,110,223,229,120,255,232,230,221,215,
  53051. 79,239,62,4,102,203,207,72,241,9,11,218,63,72,89,137,20,207,98,100,93,16,0,8,32,70,144,1,64,14,168,209,199,7,196,194,160,166,27,212,135,95,96,65,10,173,95,254,34,219,6,51,128,88,7,96,235,21,129,0,64,0,
  53052. 193,28,192,8,174,53,33,152,1,155,133,184,12,196,165,4,151,133,232,0,32,192,0,151,97,210,163,246,134,208,52,0,0,0,0,73,69,78,68,174,66,96,130,0,0};
  53053. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53054. }
  53055. Image* LookAndFeel::getDefaultDocumentFileImage()
  53056. {
  53057. static const unsigned char fileicon_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,32,0,0,0,32,8,6,0,0,0,115,122,122,244,0,0,0,4,103,65,77,65,0,0,175,200,55,5,
  53058. 138,233,0,0,0,25,116,69,88,116,83,111,102,116,119,97,114,101,0,65,100,111,98,101,32,73,109,97,103,101,82,101,97,100,121,113,201,101,60,0,0,4,99,73,68,65,84,120,218,98,252,255,255,63,3,12,48,50,50,50,1,
  53059. 169,127,200,98,148,2,160,153,204,64,243,254,226,146,7,8,32,22,52,203,255,107,233,233,91,76,93,176,184,232,239,239,95,127,24,40,112,8,19,51,203,255,179,23,175,108,1,90,190,28,104,54,43,80,232,207,127,44,
  53060. 62,3,8,32,6,144,24,84,156,25,132,189,252,3,146,255,83,9,220,127,254,242,134,162,138,170,10,208,92,144,3,152,97,118,33,99,128,0,98,66,114,11,200,1,92,255,254,252,225,32,215,215,32,127,64,240,127,80,60,
  53061. 50,40,72,136,169,47,95,179,118,130,136,148,140,0,40,80,128,33,193,136,174,7,32,128,144,29,192,8,117,41,59,209,22,66,241,191,255,16,12,244,19,195,63,48,134,240,255,0,9,115,125,93,239,252,130,130,108,168,
  53062. 249,44,232,102,0,4,16,19,22,62,51,33,11,255,195,44,4,211,255,25,96,16,33,6,117,24,56,226,25,24,202,139,10,75,226,51,115,66,160,105,13,197,17,0,1,196,68,172,79,255,33,91,206,192,192,128,176,22,17,10,200,
  53063. 234,32,161,240,31,24,10,255,24,152,153,153,184,39,244,247,117,107,234,234,105,131,66,1,154,224,193,0,32,128,240,58,0,22,180,255,144,18,13,40,136,33,113,140,36,255,15,17,26,48,12,81,15,145,255,254,251,
  53064. 31,131,0,59,171,84,81,73,105,33,208,216,191,200,161,12,16,64,44,248,131,251,63,10,31,198,253,143,38,6,83,7,11,33,228,232,2,123,4,202,226,228,96,151,132,166,49,144,35,126,131,196,0,2,136,5,103,60,51,252,
  53065. 71,49,12,213,130,255,168,226,232,150,254,255,15,143,6,80,202,3,133,16,200,198,63,127,193,229,17,39,16,127,135,217,7,16,64,88,67,0,28,143,255,25,225,46,135,249,18,155,133,240,178,4,205,145,8,62,52,186,
  53066. 32,234,152,160,118,194,179,35,64,0,177,96,11,123,144,236,95,104,92,162,228,113,36,11,81,125,140,112,56,186,131,96,226,176,172,137,148,229,193,0,32,128,88,112,167,248,255,112,223,48,34,165,110,6,124,190,
  53067. 253,143,61,106,192,9,19,73,28,25,0,4,16,206,40,248,251,15,45,104,209,130,21,51,222,145,18,238,127,180,68,8,244,250,95,164,16,66,6,0,1,196,130,45,253,195,12,250,135,53,206,255,195,131,18,213,98,236,81,
  53068. 243,31,154,11,144,115,8,50,0,8,32,156,81,0,203,227,12,80,223,98,230,4,68,72,96,38,78,84,11,65,9,250,47,146,3,145,1,64,0,97,117,192,95,112,34,68,138,130,255,176,224,251,143,226,51,6,6,68,29,192,136,20,
  53069. 77,200,69,54,35,3,36,49,255,69,77,132,112,0,16,64,44,56,139,94,36,7,96,102,59,164,108,249,31,181,82,98,64,203,174,255,144,234,142,127,88,146,33,64,0,97,205,134,240,120,67,75,76,136,224,198,140,22,6,44,
  53070. 142,66,201,41,255,177,231,2,128,0,194,25,5,255,254,161,134,192,127,6,28,229,0,129,242,1,150,56,33,81,138,209,28,96,0,8,32,172,81,0,78,3,104,190,68,182,224,31,146,197,224,56,6,146,140,176,202,135,17,169,
  53071. 96,130,40,64,56,0,139,93,0,1,132,61,10,64,248,31,106,156,162,199,55,204,65,255,144,178,38,74,84,252,71,51,239,63,246,68,8,16,64,44,216,74,1,88,217,13,203,191,32,1,80,58,7,133,224,127,6,68,114,6,241,65,
  53072. 81,197,8,101,255,71,114,33,92,237,127,228,52,128,233,2,128,0,98,193,149,3,64,117,193,255,127,255,81,75,191,127,168,5,18,136,255,31,45,161,49,32,151,134,72,252,127,12,216,203,98,128,0,98,193,210,144,135,
  53073. 248,30,201,242,127,208,252,140,145,27,160,113,206,136,148,197,192,121,159,17,53,184,225,149,17,22,23,0,4,16,11,182,150,237,63,168,207,96,142,248,143,163,72,6,203,253,67,13,61,6,104,14,66,46,17,254,65,
  53074. 19,40,182,16,0,8,32,22,108,109,235,255,176,234,24,35,79,255,199,222,30,64,81,135,90,35,194,211,4,142,92,0,16,64,88,29,0,107,7,254,251,247,31,53,78,241,54,207,80,29,135,209,96,249,143,189,46,0,8,32,116,
  53075. 7,252,101,102,103,103,228,103,99,96,248,193,198,137,53,248,49,125,204,128,225,227,255,88,18,54,47,176,25,202,205,195,205,6,109,11,194,149,0,4,16,35,204,85,208,254,27,159,128,176,176,142,166,182,142,21,
  53076. 48,4,248,129,41,143,13,217,16,70,52,95,147,0,254,0,187,69,95,223,188,122,125,235,206,141,107,7,129,252,247,64,123,193,237,66,128,0,66,118,0,168,189,198,3,196,252,32,135,64,105,54,228,230,19,185,29,100,
  53077. 168,175,191,0,241,7,32,254,4,196,159,129,246,254,2,73,2,4,16,11,90,72,125,135,210,63,161,138,153,169,212,75,255,15,117,196,15,40,134,119,215,1,2,12,0,187,0,132,247,216,161,197,124,0,0,0,0,73,69,78,68,
  53078. 174,66,96,130,0,0};
  53079. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53080. }
  53081. void LookAndFeel::playAlertSound()
  53082. {
  53083. PlatformUtilities::beep();
  53084. }
  53085. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53086. {
  53087. g.setColour (Colours::white.withAlpha (0.7f));
  53088. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53089. g.setColour (Colours::black.withAlpha (0.2f));
  53090. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53091. const int totalBlocks = 7;
  53092. const int numBlocks = roundToInt (totalBlocks * level);
  53093. const float w = (width - 6.0f) / (float) totalBlocks;
  53094. for (int i = 0; i < totalBlocks; ++i)
  53095. {
  53096. if (i >= numBlocks)
  53097. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53098. else
  53099. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53100. : Colours::red);
  53101. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53102. }
  53103. }
  53104. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53105. {
  53106. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53107. if (keyDescription.isNotEmpty())
  53108. {
  53109. if (button.isEnabled())
  53110. {
  53111. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53112. g.fillAll (textColour.withAlpha (alpha));
  53113. g.setOpacity (0.3f);
  53114. g.drawBevel (0, 0, width, height, 2);
  53115. }
  53116. g.setColour (textColour);
  53117. g.setFont (height * 0.6f);
  53118. g.drawFittedText (keyDescription,
  53119. 3, 0, width - 6, height,
  53120. Justification::centred, 1);
  53121. }
  53122. else
  53123. {
  53124. const float thickness = 7.0f;
  53125. const float indent = 22.0f;
  53126. Path p;
  53127. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53128. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53129. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53130. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53131. p.setUsingNonZeroWinding (false);
  53132. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53133. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53134. }
  53135. if (button.hasKeyboardFocus (false))
  53136. {
  53137. g.setColour (textColour.withAlpha (0.4f));
  53138. g.drawRect (0, 0, width, height);
  53139. }
  53140. }
  53141. static void createRoundedPath (Path& p,
  53142. const float x, const float y,
  53143. const float w, const float h,
  53144. const float cs,
  53145. const bool curveTopLeft, const bool curveTopRight,
  53146. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53147. {
  53148. const float cs2 = 2.0f * cs;
  53149. if (curveTopLeft)
  53150. {
  53151. p.startNewSubPath (x, y + cs);
  53152. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53153. }
  53154. else
  53155. {
  53156. p.startNewSubPath (x, y);
  53157. }
  53158. if (curveTopRight)
  53159. {
  53160. p.lineTo (x + w - cs, y);
  53161. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53162. }
  53163. else
  53164. {
  53165. p.lineTo (x + w, y);
  53166. }
  53167. if (curveBottomRight)
  53168. {
  53169. p.lineTo (x + w, y + h - cs);
  53170. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53171. }
  53172. else
  53173. {
  53174. p.lineTo (x + w, y + h);
  53175. }
  53176. if (curveBottomLeft)
  53177. {
  53178. p.lineTo (x + cs, y + h);
  53179. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53180. }
  53181. else
  53182. {
  53183. p.lineTo (x, y + h);
  53184. }
  53185. p.closeSubPath();
  53186. }
  53187. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53188. float x, float y, float w, float h,
  53189. float maxCornerSize,
  53190. const Colour& baseColour,
  53191. const float strokeWidth,
  53192. const bool flatOnLeft,
  53193. const bool flatOnRight,
  53194. const bool flatOnTop,
  53195. const bool flatOnBottom) throw()
  53196. {
  53197. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53198. return;
  53199. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53200. Path outline;
  53201. createRoundedPath (outline, x, y, w, h, cs,
  53202. ! (flatOnLeft || flatOnTop),
  53203. ! (flatOnRight || flatOnTop),
  53204. ! (flatOnLeft || flatOnBottom),
  53205. ! (flatOnRight || flatOnBottom));
  53206. ColourGradient cg (baseColour, 0.0f, y,
  53207. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53208. false);
  53209. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53210. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53211. g.setGradientFill (cg);
  53212. g.fillPath (outline);
  53213. g.setColour (Colour (0x80000000));
  53214. g.strokePath (outline, PathStrokeType (strokeWidth));
  53215. }
  53216. void LookAndFeel::drawGlassSphere (Graphics& g,
  53217. const float x, const float y,
  53218. const float diameter,
  53219. const Colour& colour,
  53220. const float outlineThickness) throw()
  53221. {
  53222. if (diameter <= outlineThickness)
  53223. return;
  53224. Path p;
  53225. p.addEllipse (x, y, diameter, diameter);
  53226. {
  53227. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53228. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53229. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53230. g.setGradientFill (cg);
  53231. g.fillPath (p);
  53232. }
  53233. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53234. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53235. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53236. ColourGradient cg (Colours::transparentBlack,
  53237. x + diameter * 0.5f, y + diameter * 0.5f,
  53238. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53239. x, y + diameter * 0.5f, true);
  53240. cg.addColour (0.7, Colours::transparentBlack);
  53241. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53242. g.setGradientFill (cg);
  53243. g.fillPath (p);
  53244. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53245. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53246. }
  53247. void LookAndFeel::drawGlassPointer (Graphics& g,
  53248. const float x, const float y,
  53249. const float diameter,
  53250. const Colour& colour, const float outlineThickness,
  53251. const int direction) throw()
  53252. {
  53253. if (diameter <= outlineThickness)
  53254. return;
  53255. Path p;
  53256. p.startNewSubPath (x + diameter * 0.5f, y);
  53257. p.lineTo (x + diameter, y + diameter * 0.6f);
  53258. p.lineTo (x + diameter, y + diameter);
  53259. p.lineTo (x, y + diameter);
  53260. p.lineTo (x, y + diameter * 0.6f);
  53261. p.closeSubPath();
  53262. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53263. {
  53264. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53265. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53266. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53267. g.setGradientFill (cg);
  53268. g.fillPath (p);
  53269. }
  53270. ColourGradient cg (Colours::transparentBlack,
  53271. x + diameter * 0.5f, y + diameter * 0.5f,
  53272. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53273. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53274. cg.addColour (0.5, Colours::transparentBlack);
  53275. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53276. g.setGradientFill (cg);
  53277. g.fillPath (p);
  53278. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53279. g.strokePath (p, PathStrokeType (outlineThickness));
  53280. }
  53281. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53282. const float x, const float y,
  53283. const float width, const float height,
  53284. const Colour& colour,
  53285. const float outlineThickness,
  53286. const float cornerSize,
  53287. const bool flatOnLeft,
  53288. const bool flatOnRight,
  53289. const bool flatOnTop,
  53290. const bool flatOnBottom) throw()
  53291. {
  53292. if (width <= outlineThickness || height <= outlineThickness)
  53293. return;
  53294. const int intX = (int) x;
  53295. const int intY = (int) y;
  53296. const int intW = (int) width;
  53297. const int intH = (int) height;
  53298. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53299. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53300. const int intEdge = (int) edgeBlurRadius;
  53301. Path outline;
  53302. createRoundedPath (outline, x, y, width, height, cs,
  53303. ! (flatOnLeft || flatOnTop),
  53304. ! (flatOnRight || flatOnTop),
  53305. ! (flatOnLeft || flatOnBottom),
  53306. ! (flatOnRight || flatOnBottom));
  53307. {
  53308. ColourGradient cg (colour.darker (0.2f), 0, y,
  53309. colour.darker (0.2f), 0, y + height, false);
  53310. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53311. cg.addColour (0.4, colour);
  53312. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53313. g.setGradientFill (cg);
  53314. g.fillPath (outline);
  53315. }
  53316. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53317. colour.darker (0.2f), x, y + height * 0.5f, true);
  53318. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53319. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53320. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53321. {
  53322. g.saveState();
  53323. g.setGradientFill (cg);
  53324. g.reduceClipRegion (intX, intY, intEdge, intH);
  53325. g.fillPath (outline);
  53326. g.restoreState();
  53327. }
  53328. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53329. {
  53330. cg.x1 = x + width - edgeBlurRadius;
  53331. cg.x2 = x + width;
  53332. g.saveState();
  53333. g.setGradientFill (cg);
  53334. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53335. g.fillPath (outline);
  53336. g.restoreState();
  53337. }
  53338. {
  53339. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53340. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53341. Path highlight;
  53342. createRoundedPath (highlight,
  53343. x + leftIndent,
  53344. y + cs * 0.1f,
  53345. width - (leftIndent + rightIndent),
  53346. height * 0.4f, cs * 0.4f,
  53347. ! (flatOnLeft || flatOnTop),
  53348. ! (flatOnRight || flatOnTop),
  53349. ! (flatOnLeft || flatOnBottom),
  53350. ! (flatOnRight || flatOnBottom));
  53351. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53352. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53353. g.fillPath (highlight);
  53354. }
  53355. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53356. g.strokePath (outline, PathStrokeType (outlineThickness));
  53357. }
  53358. END_JUCE_NAMESPACE
  53359. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53360. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53361. BEGIN_JUCE_NAMESPACE
  53362. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53363. {
  53364. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53365. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53366. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53367. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53368. setColour (Slider::thumbColourId, Colours::white);
  53369. setColour (Slider::trackColourId, Colour (0x7f000000));
  53370. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53371. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53372. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53373. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53374. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53375. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53376. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53377. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53378. }
  53379. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53380. {
  53381. }
  53382. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53383. Button& button,
  53384. const Colour& backgroundColour,
  53385. bool isMouseOverButton,
  53386. bool isButtonDown)
  53387. {
  53388. const int width = button.getWidth();
  53389. const int height = button.getHeight();
  53390. const float indent = 2.0f;
  53391. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53392. roundToInt (height * 0.4f));
  53393. Path p;
  53394. p.addRoundedRectangle (indent, indent,
  53395. width - indent * 2.0f,
  53396. height - indent * 2.0f,
  53397. (float) cornerSize);
  53398. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53399. if (isMouseOverButton)
  53400. {
  53401. if (isButtonDown)
  53402. bc = bc.brighter();
  53403. else if (bc.getBrightness() > 0.5f)
  53404. bc = bc.darker (0.1f);
  53405. else
  53406. bc = bc.brighter (0.1f);
  53407. }
  53408. g.setColour (bc);
  53409. g.fillPath (p);
  53410. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53411. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53412. }
  53413. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53414. Component& /*component*/,
  53415. float x, float y, float w, float h,
  53416. const bool ticked,
  53417. const bool isEnabled,
  53418. const bool /*isMouseOverButton*/,
  53419. const bool isButtonDown)
  53420. {
  53421. Path box;
  53422. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53423. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53424. : Colours::lightgrey.withAlpha (0.1f));
  53425. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53426. g.fillPath (box, trans);
  53427. g.setColour (Colours::black.withAlpha (0.6f));
  53428. g.strokePath (box, PathStrokeType (0.9f), trans);
  53429. if (ticked)
  53430. {
  53431. Path tick;
  53432. tick.startNewSubPath (1.5f, 3.0f);
  53433. tick.lineTo (3.0f, 6.0f);
  53434. tick.lineTo (6.0f, 0.0f);
  53435. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53436. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53437. }
  53438. }
  53439. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53440. ToggleButton& button,
  53441. bool isMouseOverButton,
  53442. bool isButtonDown)
  53443. {
  53444. if (button.hasKeyboardFocus (true))
  53445. {
  53446. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53447. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53448. }
  53449. const int tickWidth = jmin (20, button.getHeight() - 4);
  53450. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53451. (float) tickWidth, (float) tickWidth,
  53452. button.getToggleState(),
  53453. button.isEnabled(),
  53454. isMouseOverButton,
  53455. isButtonDown);
  53456. g.setColour (button.findColour (ToggleButton::textColourId));
  53457. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53458. if (! button.isEnabled())
  53459. g.setOpacity (0.5f);
  53460. const int textX = tickWidth + 5;
  53461. g.drawFittedText (button.getButtonText(),
  53462. textX, 4,
  53463. button.getWidth() - textX - 2, button.getHeight() - 8,
  53464. Justification::centredLeft, 10);
  53465. }
  53466. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53467. int width, int height,
  53468. double progress, const String& textToShow)
  53469. {
  53470. if (progress < 0 || progress >= 1.0)
  53471. {
  53472. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53473. }
  53474. else
  53475. {
  53476. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53477. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53478. g.fillAll (background);
  53479. g.setColour (foreground);
  53480. g.fillRect (1, 1,
  53481. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53482. height - 2);
  53483. if (textToShow.isNotEmpty())
  53484. {
  53485. g.setColour (Colour::contrasting (background, foreground));
  53486. g.setFont (height * 0.6f);
  53487. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53488. }
  53489. }
  53490. }
  53491. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53492. ScrollBar& bar,
  53493. int width, int height,
  53494. int buttonDirection,
  53495. bool isScrollbarVertical,
  53496. bool isMouseOverButton,
  53497. bool isButtonDown)
  53498. {
  53499. if (isScrollbarVertical)
  53500. width -= 2;
  53501. else
  53502. height -= 2;
  53503. Path p;
  53504. if (buttonDirection == 0)
  53505. p.addTriangle (width * 0.5f, height * 0.2f,
  53506. width * 0.1f, height * 0.7f,
  53507. width * 0.9f, height * 0.7f);
  53508. else if (buttonDirection == 1)
  53509. p.addTriangle (width * 0.8f, height * 0.5f,
  53510. width * 0.3f, height * 0.1f,
  53511. width * 0.3f, height * 0.9f);
  53512. else if (buttonDirection == 2)
  53513. p.addTriangle (width * 0.5f, height * 0.8f,
  53514. width * 0.1f, height * 0.3f,
  53515. width * 0.9f, height * 0.3f);
  53516. else if (buttonDirection == 3)
  53517. p.addTriangle (width * 0.2f, height * 0.5f,
  53518. width * 0.7f, height * 0.1f,
  53519. width * 0.7f, height * 0.9f);
  53520. if (isButtonDown)
  53521. g.setColour (Colours::white);
  53522. else if (isMouseOverButton)
  53523. g.setColour (Colours::white.withAlpha (0.7f));
  53524. else
  53525. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53526. g.fillPath (p);
  53527. g.setColour (Colours::black.withAlpha (0.5f));
  53528. g.strokePath (p, PathStrokeType (0.5f));
  53529. }
  53530. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53531. ScrollBar& bar,
  53532. int x, int y,
  53533. int width, int height,
  53534. bool isScrollbarVertical,
  53535. int thumbStartPosition,
  53536. int thumbSize,
  53537. bool isMouseOver,
  53538. bool isMouseDown)
  53539. {
  53540. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53541. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53542. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53543. if (thumbSize > 0.0f)
  53544. {
  53545. Rectangle<int> thumb;
  53546. if (isScrollbarVertical)
  53547. {
  53548. width -= 2;
  53549. g.fillRect (x + roundToInt (width * 0.35f), y,
  53550. roundToInt (width * 0.3f), height);
  53551. thumb.setBounds (x + 1, thumbStartPosition,
  53552. width - 2, thumbSize);
  53553. }
  53554. else
  53555. {
  53556. height -= 2;
  53557. g.fillRect (x, y + roundToInt (height * 0.35f),
  53558. width, roundToInt (height * 0.3f));
  53559. thumb.setBounds (thumbStartPosition, y + 1,
  53560. thumbSize, height - 2);
  53561. }
  53562. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53563. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53564. g.fillRect (thumb);
  53565. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53566. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53567. if (thumbSize > 16)
  53568. {
  53569. for (int i = 3; --i >= 0;)
  53570. {
  53571. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53572. g.setColour (Colours::black.withAlpha (0.15f));
  53573. if (isScrollbarVertical)
  53574. {
  53575. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53576. g.setColour (Colours::white.withAlpha (0.15f));
  53577. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53578. }
  53579. else
  53580. {
  53581. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53582. g.setColour (Colours::white.withAlpha (0.15f));
  53583. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53584. }
  53585. }
  53586. }
  53587. }
  53588. }
  53589. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53590. {
  53591. return &scrollbarShadow;
  53592. }
  53593. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53594. {
  53595. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53596. g.setColour (Colours::black.withAlpha (0.6f));
  53597. g.drawRect (0, 0, width, height);
  53598. }
  53599. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53600. bool, MenuBarComponent& menuBar)
  53601. {
  53602. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53603. }
  53604. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53605. {
  53606. if (textEditor.isEnabled())
  53607. {
  53608. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53609. g.drawRect (0, 0, width, height);
  53610. }
  53611. }
  53612. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53613. const bool isButtonDown,
  53614. int buttonX, int buttonY,
  53615. int buttonW, int buttonH,
  53616. ComboBox& box)
  53617. {
  53618. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53619. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53620. : ComboBox::backgroundColourId));
  53621. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53622. g.setColour (box.findColour (ComboBox::outlineColourId));
  53623. g.drawRect (0, 0, width, height);
  53624. const float arrowX = 0.2f;
  53625. const float arrowH = 0.3f;
  53626. if (box.isEnabled())
  53627. {
  53628. Path p;
  53629. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53630. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53631. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53632. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53633. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53634. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53635. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53636. : ComboBox::buttonColourId));
  53637. g.fillPath (p);
  53638. }
  53639. }
  53640. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53641. {
  53642. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53643. f.setHorizontalScale (0.9f);
  53644. return f;
  53645. }
  53646. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53647. {
  53648. Path p;
  53649. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53650. g.setColour (fill);
  53651. g.fillPath (p);
  53652. g.setColour (outline);
  53653. g.strokePath (p, PathStrokeType (0.3f));
  53654. }
  53655. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53656. int x, int y,
  53657. int w, int h,
  53658. float sliderPos,
  53659. float minSliderPos,
  53660. float maxSliderPos,
  53661. const Slider::SliderStyle style,
  53662. Slider& slider)
  53663. {
  53664. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53665. if (style == Slider::LinearBar)
  53666. {
  53667. g.setColour (slider.findColour (Slider::thumbColourId));
  53668. g.fillRect (x, y, (int) sliderPos - x, h);
  53669. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53670. g.drawRect (x, y, (int) sliderPos - x, h);
  53671. }
  53672. else
  53673. {
  53674. g.setColour (slider.findColour (Slider::trackColourId)
  53675. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53676. if (slider.isHorizontal())
  53677. {
  53678. g.fillRect (x, y + roundToInt (h * 0.6f),
  53679. w, roundToInt (h * 0.2f));
  53680. }
  53681. else
  53682. {
  53683. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53684. jmin (4, roundToInt (w * 0.2f)), h);
  53685. }
  53686. float alpha = 0.35f;
  53687. if (slider.isEnabled())
  53688. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53689. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53690. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53691. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53692. {
  53693. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53694. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53695. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53696. fill, outline);
  53697. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53698. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53699. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53700. fill, outline);
  53701. }
  53702. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53703. {
  53704. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53705. minSliderPos - 7.0f, y + h * 0.9f ,
  53706. minSliderPos, y + h * 0.9f,
  53707. fill, outline);
  53708. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53709. maxSliderPos, y + h * 0.9f,
  53710. maxSliderPos + 7.0f, y + h * 0.9f,
  53711. fill, outline);
  53712. }
  53713. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53714. {
  53715. drawTriangle (g, sliderPos, y + h * 0.9f,
  53716. sliderPos - 7.0f, y + h * 0.2f,
  53717. sliderPos + 7.0f, y + h * 0.2f,
  53718. fill, outline);
  53719. }
  53720. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53721. {
  53722. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53723. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53724. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53725. fill, outline);
  53726. }
  53727. }
  53728. }
  53729. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53730. {
  53731. if (isIncrement)
  53732. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53733. else
  53734. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53735. }
  53736. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53737. {
  53738. return &scrollbarShadow;
  53739. }
  53740. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53741. {
  53742. return 8;
  53743. }
  53744. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53745. int w, int h,
  53746. bool isMouseOver,
  53747. bool isMouseDragging)
  53748. {
  53749. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53750. : Colours::darkgrey);
  53751. const float lineThickness = jmin (w, h) * 0.1f;
  53752. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53753. {
  53754. g.drawLine (w * i,
  53755. h + 1.0f,
  53756. w + 1.0f,
  53757. h * i,
  53758. lineThickness);
  53759. }
  53760. }
  53761. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53762. {
  53763. Path shape;
  53764. if (buttonType == DocumentWindow::closeButton)
  53765. {
  53766. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53767. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53768. ShapeButton* const b = new ShapeButton ("close",
  53769. Colour (0x7fff3333),
  53770. Colour (0xd7ff3333),
  53771. Colour (0xf7ff3333));
  53772. b->setShape (shape, true, true, true);
  53773. return b;
  53774. }
  53775. else if (buttonType == DocumentWindow::minimiseButton)
  53776. {
  53777. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53778. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53779. DrawablePath dp;
  53780. dp.setPath (shape);
  53781. dp.setFill (Colours::black.withAlpha (0.3f));
  53782. b->setImages (&dp);
  53783. return b;
  53784. }
  53785. else if (buttonType == DocumentWindow::maximiseButton)
  53786. {
  53787. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53788. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53789. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53790. DrawablePath dp;
  53791. dp.setPath (shape);
  53792. dp.setFill (Colours::black.withAlpha (0.3f));
  53793. b->setImages (&dp);
  53794. return b;
  53795. }
  53796. jassertfalse
  53797. return 0;
  53798. }
  53799. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53800. int titleBarX,
  53801. int titleBarY,
  53802. int titleBarW,
  53803. int titleBarH,
  53804. Button* minimiseButton,
  53805. Button* maximiseButton,
  53806. Button* closeButton,
  53807. bool positionTitleBarButtonsOnLeft)
  53808. {
  53809. titleBarY += titleBarH / 8;
  53810. titleBarH -= titleBarH / 4;
  53811. const int buttonW = titleBarH;
  53812. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53813. : titleBarX + titleBarW - buttonW - 4;
  53814. if (closeButton != 0)
  53815. {
  53816. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53817. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53818. : -(buttonW + buttonW / 5);
  53819. }
  53820. if (positionTitleBarButtonsOnLeft)
  53821. swapVariables (minimiseButton, maximiseButton);
  53822. if (maximiseButton != 0)
  53823. {
  53824. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53825. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53826. }
  53827. if (minimiseButton != 0)
  53828. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53829. }
  53830. END_JUCE_NAMESPACE
  53831. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53832. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53833. BEGIN_JUCE_NAMESPACE
  53834. class DummyMenuComponent : public Component
  53835. {
  53836. DummyMenuComponent (const DummyMenuComponent&);
  53837. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53838. public:
  53839. DummyMenuComponent() {}
  53840. ~DummyMenuComponent() {}
  53841. void inputAttemptWhenModal()
  53842. {
  53843. exitModalState (0);
  53844. }
  53845. };
  53846. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53847. : model (0),
  53848. itemUnderMouse (-1),
  53849. currentPopupIndex (-1),
  53850. indexToShowAgain (-1),
  53851. lastMouseX (0),
  53852. lastMouseY (0),
  53853. inModalState (false)
  53854. {
  53855. setRepaintsOnMouseActivity (true);
  53856. setWantsKeyboardFocus (false);
  53857. setMouseClickGrabsKeyboardFocus (false);
  53858. setModel (model_);
  53859. }
  53860. MenuBarComponent::~MenuBarComponent()
  53861. {
  53862. setModel (0);
  53863. Desktop::getInstance().removeGlobalMouseListener (this);
  53864. currentPopup = 0;
  53865. }
  53866. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53867. {
  53868. if (model != newModel)
  53869. {
  53870. if (model != 0)
  53871. model->removeListener (this);
  53872. model = newModel;
  53873. if (model != 0)
  53874. model->addListener (this);
  53875. repaint();
  53876. menuBarItemsChanged (0);
  53877. }
  53878. }
  53879. void MenuBarComponent::paint (Graphics& g)
  53880. {
  53881. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53882. getLookAndFeel().drawMenuBarBackground (g,
  53883. getWidth(),
  53884. getHeight(),
  53885. isMouseOverBar,
  53886. *this);
  53887. if (model != 0)
  53888. {
  53889. for (int i = 0; i < menuNames.size(); ++i)
  53890. {
  53891. g.saveState();
  53892. g.setOrigin (xPositions [i], 0);
  53893. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53894. getLookAndFeel().drawMenuBarItem (g,
  53895. xPositions[i + 1] - xPositions[i],
  53896. getHeight(),
  53897. i,
  53898. menuNames[i],
  53899. i == itemUnderMouse,
  53900. i == currentPopupIndex,
  53901. isMouseOverBar,
  53902. *this);
  53903. g.restoreState();
  53904. }
  53905. }
  53906. }
  53907. void MenuBarComponent::resized()
  53908. {
  53909. xPositions.clear();
  53910. int x = 2;
  53911. xPositions.add (x);
  53912. for (int i = 0; i < menuNames.size(); ++i)
  53913. {
  53914. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  53915. xPositions.add (x);
  53916. }
  53917. }
  53918. int MenuBarComponent::getItemAt (const int x, const int y)
  53919. {
  53920. for (int i = 0; i < xPositions.size(); ++i)
  53921. if (x >= xPositions[i] && x < xPositions[i + 1])
  53922. return reallyContains (x, y, true) ? i : -1;
  53923. return -1;
  53924. }
  53925. void MenuBarComponent::repaintMenuItem (int index)
  53926. {
  53927. if (((unsigned int) index) < (unsigned int) xPositions.size())
  53928. {
  53929. const int x1 = xPositions [index];
  53930. const int x2 = xPositions [index + 1];
  53931. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  53932. }
  53933. }
  53934. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  53935. {
  53936. const int newItem = getItemAt (x, y);
  53937. if (itemUnderMouse != newItem)
  53938. {
  53939. repaintMenuItem (itemUnderMouse);
  53940. itemUnderMouse = newItem;
  53941. repaintMenuItem (itemUnderMouse);
  53942. }
  53943. }
  53944. void MenuBarComponent::hideCurrentMenu()
  53945. {
  53946. currentPopup = 0;
  53947. repaint();
  53948. }
  53949. void MenuBarComponent::showMenu (int index)
  53950. {
  53951. if (index != currentPopupIndex)
  53952. {
  53953. if (inModalState)
  53954. {
  53955. hideCurrentMenu();
  53956. indexToShowAgain = index;
  53957. return;
  53958. }
  53959. indexToShowAgain = -1;
  53960. currentPopupIndex = -1;
  53961. itemUnderMouse = index;
  53962. currentPopup = 0;
  53963. menuBarItemsChanged (0);
  53964. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  53965. Component::SafePointer<Component> deletionChecker (this);
  53966. enterModalState (false);
  53967. inModalState = true;
  53968. int result = 0;
  53969. ApplicationCommandManager* managerOfChosenCommand = 0;
  53970. Desktop::getInstance().addGlobalMouseListener (this);
  53971. for (;;)
  53972. {
  53973. const int x = getScreenX() + xPositions [itemUnderMouse];
  53974. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  53975. currentPopupIndex = itemUnderMouse;
  53976. indexToShowAgain = -1;
  53977. repaint();
  53978. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  53979. {
  53980. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  53981. menuNames [itemUnderMouse]));
  53982. if (m.lookAndFeel == 0)
  53983. m.setLookAndFeel (&getLookAndFeel());
  53984. currentPopup = m.createMenuComponent (x, getScreenY(),
  53985. w, getHeight(),
  53986. 0, w, 0, 0,
  53987. true, this,
  53988. &managerOfChosenCommand,
  53989. this);
  53990. }
  53991. if (currentPopup == 0)
  53992. {
  53993. currentPopup = new DummyMenuComponent();
  53994. addAndMakeVisible (currentPopup);
  53995. }
  53996. currentPopup->enterModalState (false);
  53997. currentPopup->toFront (false); // need to do this after making it modal, or it could
  53998. // be stuck behind other comps that are already modal..
  53999. result = currentPopup->runModalLoop();
  54000. if (deletionChecker == 0)
  54001. return;
  54002. const int lastPopupIndex = currentPopupIndex;
  54003. currentPopup = 0;
  54004. currentPopupIndex = -1;
  54005. if (result != 0)
  54006. {
  54007. topLevelIndexClicked = lastPopupIndex;
  54008. break;
  54009. }
  54010. else if (indexToShowAgain >= 0)
  54011. {
  54012. menuBarItemsChanged (0);
  54013. repaint();
  54014. itemUnderMouse = indexToShowAgain;
  54015. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54016. break;
  54017. }
  54018. else
  54019. {
  54020. break;
  54021. }
  54022. }
  54023. Desktop::getInstance().removeGlobalMouseListener (this);
  54024. inModalState = false;
  54025. exitModalState (0);
  54026. if (prevFocused != 0)
  54027. prevFocused->grabKeyboardFocus();
  54028. const Point<int> mousePos (getMouseXYRelative());
  54029. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54030. repaint();
  54031. if (result != 0)
  54032. {
  54033. if (managerOfChosenCommand != 0)
  54034. {
  54035. ApplicationCommandTarget::InvocationInfo info (result);
  54036. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54037. managerOfChosenCommand->invoke (info, true);
  54038. }
  54039. postCommandMessage (result);
  54040. }
  54041. }
  54042. }
  54043. void MenuBarComponent::handleCommandMessage (int commandId)
  54044. {
  54045. if (model != 0)
  54046. model->menuItemSelected (commandId, topLevelIndexClicked);
  54047. }
  54048. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54049. {
  54050. if (e.eventComponent == this)
  54051. updateItemUnderMouse (e.x, e.y);
  54052. }
  54053. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54054. {
  54055. if (e.eventComponent == this)
  54056. updateItemUnderMouse (e.x, e.y);
  54057. }
  54058. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54059. {
  54060. if (currentPopupIndex < 0)
  54061. {
  54062. const MouseEvent e2 (e.getEventRelativeTo (this));
  54063. updateItemUnderMouse (e2.x, e2.y);
  54064. currentPopupIndex = -2;
  54065. showMenu (itemUnderMouse);
  54066. }
  54067. }
  54068. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54069. {
  54070. const MouseEvent e2 (e.getEventRelativeTo (this));
  54071. const int item = getItemAt (e2.x, e2.y);
  54072. if (item >= 0)
  54073. showMenu (item);
  54074. }
  54075. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54076. {
  54077. const MouseEvent e2 (e.getEventRelativeTo (this));
  54078. updateItemUnderMouse (e2.x, e2.y);
  54079. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54080. hideCurrentMenu();
  54081. }
  54082. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54083. {
  54084. const MouseEvent e2 (e.getEventRelativeTo (this));
  54085. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54086. {
  54087. if (currentPopupIndex >= 0)
  54088. {
  54089. const int item = getItemAt (e2.x, e2.y);
  54090. if (item >= 0)
  54091. showMenu (item);
  54092. }
  54093. else
  54094. {
  54095. updateItemUnderMouse (e2.x, e2.y);
  54096. }
  54097. lastMouseX = e2.x;
  54098. lastMouseY = e2.y;
  54099. }
  54100. }
  54101. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54102. {
  54103. bool used = false;
  54104. const int numMenus = menuNames.size();
  54105. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54106. if (key.isKeyCode (KeyPress::leftKey))
  54107. {
  54108. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54109. used = true;
  54110. }
  54111. else if (key.isKeyCode (KeyPress::rightKey))
  54112. {
  54113. showMenu ((currentIndex + 1) % numMenus);
  54114. used = true;
  54115. }
  54116. return used;
  54117. }
  54118. void MenuBarComponent::inputAttemptWhenModal()
  54119. {
  54120. hideCurrentMenu();
  54121. }
  54122. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54123. {
  54124. StringArray newNames;
  54125. if (model != 0)
  54126. newNames = model->getMenuBarNames();
  54127. if (newNames != menuNames)
  54128. {
  54129. menuNames = newNames;
  54130. repaint();
  54131. resized();
  54132. }
  54133. }
  54134. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54135. const ApplicationCommandTarget::InvocationInfo& info)
  54136. {
  54137. if (model == 0
  54138. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54139. return;
  54140. for (int i = 0; i < menuNames.size(); ++i)
  54141. {
  54142. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54143. if (menu.containsCommandItem (info.commandID))
  54144. {
  54145. itemUnderMouse = i;
  54146. repaintMenuItem (i);
  54147. startTimer (200);
  54148. break;
  54149. }
  54150. }
  54151. }
  54152. void MenuBarComponent::timerCallback()
  54153. {
  54154. stopTimer();
  54155. const Point<int> mousePos (getMouseXYRelative());
  54156. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54157. }
  54158. END_JUCE_NAMESPACE
  54159. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54160. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54161. BEGIN_JUCE_NAMESPACE
  54162. MenuBarModel::MenuBarModel() throw()
  54163. : manager (0)
  54164. {
  54165. }
  54166. MenuBarModel::~MenuBarModel()
  54167. {
  54168. setApplicationCommandManagerToWatch (0);
  54169. }
  54170. void MenuBarModel::menuItemsChanged()
  54171. {
  54172. triggerAsyncUpdate();
  54173. }
  54174. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54175. {
  54176. if (manager != newManager)
  54177. {
  54178. if (manager != 0)
  54179. manager->removeListener (this);
  54180. manager = newManager;
  54181. if (manager != 0)
  54182. manager->addListener (this);
  54183. }
  54184. }
  54185. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54186. {
  54187. listeners.add (newListener);
  54188. }
  54189. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54190. {
  54191. // Trying to remove a listener that isn't on the list!
  54192. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54193. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54194. jassert (listeners.contains (listenerToRemove));
  54195. listeners.remove (listenerToRemove);
  54196. }
  54197. void MenuBarModel::handleAsyncUpdate()
  54198. {
  54199. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54200. }
  54201. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54202. {
  54203. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54204. }
  54205. void MenuBarModel::applicationCommandListChanged()
  54206. {
  54207. menuItemsChanged();
  54208. }
  54209. END_JUCE_NAMESPACE
  54210. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54211. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54212. BEGIN_JUCE_NAMESPACE
  54213. class PopupMenu::Item
  54214. {
  54215. public:
  54216. Item()
  54217. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54218. usesColour (false), customComp (0), commandManager (0)
  54219. {
  54220. }
  54221. Item (const int itemId_,
  54222. const String& text_,
  54223. const bool active_,
  54224. const bool isTicked_,
  54225. const Image* im,
  54226. const Colour& textColour_,
  54227. const bool usesColour_,
  54228. PopupMenuCustomComponent* const customComp_,
  54229. const PopupMenu* const subMenu_,
  54230. ApplicationCommandManager* const commandManager_)
  54231. : itemId (itemId_), text (text_), textColour (textColour_),
  54232. active (active_), isSeparator (false), isTicked (isTicked_),
  54233. usesColour (usesColour_), customComp (customComp_),
  54234. commandManager (commandManager_)
  54235. {
  54236. if (subMenu_ != 0)
  54237. subMenu = new PopupMenu (*subMenu_);
  54238. if (im != 0)
  54239. image = im->createCopy();
  54240. if (commandManager_ != 0 && itemId_ != 0)
  54241. {
  54242. String shortcutKey;
  54243. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54244. ->getKeyPressesAssignedToCommand (itemId_));
  54245. for (int i = 0; i < keyPresses.size(); ++i)
  54246. {
  54247. const String key (keyPresses.getReference(i).getTextDescription());
  54248. if (shortcutKey.isNotEmpty())
  54249. shortcutKey << ", ";
  54250. if (key.length() == 1)
  54251. shortcutKey << "shortcut: '" << key << '\'';
  54252. else
  54253. shortcutKey << key;
  54254. }
  54255. shortcutKey = shortcutKey.trim();
  54256. if (shortcutKey.isNotEmpty())
  54257. text << "<end>" << shortcutKey;
  54258. }
  54259. }
  54260. Item (const Item& other)
  54261. : itemId (other.itemId),
  54262. text (other.text),
  54263. textColour (other.textColour),
  54264. active (other.active),
  54265. isSeparator (other.isSeparator),
  54266. isTicked (other.isTicked),
  54267. usesColour (other.usesColour),
  54268. customComp (other.customComp),
  54269. commandManager (other.commandManager)
  54270. {
  54271. if (other.subMenu != 0)
  54272. subMenu = new PopupMenu (*(other.subMenu));
  54273. if (other.image != 0)
  54274. image = other.image->createCopy();
  54275. }
  54276. ~Item()
  54277. {
  54278. customComp = 0;
  54279. }
  54280. bool canBeTriggered() const throw()
  54281. {
  54282. return active && ! (isSeparator || (subMenu != 0));
  54283. }
  54284. bool hasActiveSubMenu() const throw()
  54285. {
  54286. return active && (subMenu != 0);
  54287. }
  54288. const int itemId;
  54289. String text;
  54290. const Colour textColour;
  54291. const bool active, isSeparator, isTicked, usesColour;
  54292. ScopedPointer <Image> image;
  54293. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54294. ScopedPointer <PopupMenu> subMenu;
  54295. ApplicationCommandManager* const commandManager;
  54296. juce_UseDebuggingNewOperator
  54297. private:
  54298. Item& operator= (const Item&);
  54299. };
  54300. class PopupMenu::ItemComponent : public Component
  54301. {
  54302. public:
  54303. ItemComponent (const PopupMenu::Item& itemInfo_)
  54304. : itemInfo (itemInfo_),
  54305. isHighlighted (false)
  54306. {
  54307. if (itemInfo.customComp != 0)
  54308. addAndMakeVisible (itemInfo.customComp);
  54309. }
  54310. ~ItemComponent()
  54311. {
  54312. if (itemInfo.customComp != 0)
  54313. removeChildComponent (itemInfo.customComp);
  54314. }
  54315. void getIdealSize (int& idealWidth,
  54316. int& idealHeight,
  54317. const int standardItemHeight)
  54318. {
  54319. if (itemInfo.customComp != 0)
  54320. {
  54321. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54322. }
  54323. else
  54324. {
  54325. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54326. itemInfo.isSeparator,
  54327. standardItemHeight,
  54328. idealWidth,
  54329. idealHeight);
  54330. }
  54331. }
  54332. void paint (Graphics& g)
  54333. {
  54334. if (itemInfo.customComp == 0)
  54335. {
  54336. String mainText (itemInfo.text);
  54337. String endText;
  54338. const int endIndex = mainText.indexOf ("<end>");
  54339. if (endIndex >= 0)
  54340. {
  54341. endText = mainText.substring (endIndex + 5).trim();
  54342. mainText = mainText.substring (0, endIndex);
  54343. }
  54344. getLookAndFeel()
  54345. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54346. itemInfo.isSeparator,
  54347. itemInfo.active,
  54348. isHighlighted,
  54349. itemInfo.isTicked,
  54350. itemInfo.subMenu != 0,
  54351. mainText, endText,
  54352. itemInfo.image,
  54353. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54354. }
  54355. }
  54356. void resized()
  54357. {
  54358. if (getNumChildComponents() > 0)
  54359. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54360. }
  54361. void setHighlighted (bool shouldBeHighlighted)
  54362. {
  54363. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54364. if (isHighlighted != shouldBeHighlighted)
  54365. {
  54366. isHighlighted = shouldBeHighlighted;
  54367. if (itemInfo.customComp != 0)
  54368. {
  54369. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54370. itemInfo.customComp->repaint();
  54371. }
  54372. repaint();
  54373. }
  54374. }
  54375. PopupMenu::Item itemInfo;
  54376. juce_UseDebuggingNewOperator
  54377. private:
  54378. bool isHighlighted;
  54379. ItemComponent (const ItemComponent&);
  54380. ItemComponent& operator= (const ItemComponent&);
  54381. };
  54382. namespace PopupMenuSettings
  54383. {
  54384. static const int scrollZone = 24;
  54385. static const int borderSize = 2;
  54386. static const int timerInterval = 50;
  54387. static const int dismissCommandId = 0x6287345f;
  54388. }
  54389. class PopupMenu::Window : public Component,
  54390. private Timer
  54391. {
  54392. public:
  54393. Window()
  54394. : Component ("menu"),
  54395. owner (0),
  54396. currentChild (0),
  54397. activeSubMenu (0),
  54398. menuBarComponent (0),
  54399. managerOfChosenCommand (0),
  54400. minimumWidth (0),
  54401. maximumNumColumns (7),
  54402. standardItemHeight (0),
  54403. isOver (false),
  54404. hasBeenOver (false),
  54405. isDown (false),
  54406. needsToScroll (false),
  54407. hideOnExit (false),
  54408. disableMouseMoves (false),
  54409. hasAnyJuceCompHadFocus (false),
  54410. numColumns (0),
  54411. contentHeight (0),
  54412. childYOffset (0),
  54413. timeEnteredCurrentChildComp (0),
  54414. scrollAcceleration (1.0)
  54415. {
  54416. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54417. setWantsKeyboardFocus (true);
  54418. setMouseClickGrabsKeyboardFocus (false);
  54419. setOpaque (true);
  54420. setAlwaysOnTop (true);
  54421. Desktop::getInstance().addGlobalMouseListener (this);
  54422. getActiveWindows().add (this);
  54423. }
  54424. ~Window()
  54425. {
  54426. getActiveWindows().removeValue (this);
  54427. Desktop::getInstance().removeGlobalMouseListener (this);
  54428. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54429. activeSubMenu = 0;
  54430. deleteAllChildren();
  54431. }
  54432. static Window* create (const PopupMenu& menu,
  54433. const bool dismissOnMouseUp,
  54434. Window* const owner_,
  54435. const int minX, const int maxX,
  54436. const int minY, const int maxY,
  54437. const int minimumWidth,
  54438. const int maximumNumColumns,
  54439. const int standardItemHeight,
  54440. const bool alignToRectangle,
  54441. const int itemIdThatMustBeVisible,
  54442. Component* const menuBarComponent,
  54443. ApplicationCommandManager** managerOfChosenCommand,
  54444. Component* const componentAttachedTo)
  54445. {
  54446. if (menu.items.size() > 0)
  54447. {
  54448. int totalItems = 0;
  54449. ScopedPointer <Window> mw (new Window());
  54450. mw->setLookAndFeel (menu.lookAndFeel);
  54451. mw->setWantsKeyboardFocus (false);
  54452. mw->minimumWidth = minimumWidth;
  54453. mw->maximumNumColumns = maximumNumColumns;
  54454. mw->standardItemHeight = standardItemHeight;
  54455. mw->dismissOnMouseUp = dismissOnMouseUp;
  54456. for (int i = 0; i < menu.items.size(); ++i)
  54457. {
  54458. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54459. mw->addItem (*item);
  54460. ++totalItems;
  54461. }
  54462. if (totalItems > 0)
  54463. {
  54464. mw->owner = owner_;
  54465. mw->menuBarComponent = menuBarComponent;
  54466. mw->managerOfChosenCommand = managerOfChosenCommand;
  54467. mw->componentAttachedTo = componentAttachedTo;
  54468. mw->componentAttachedToOriginal = componentAttachedTo;
  54469. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54470. mw->setTopLeftPosition (mw->windowPos.getX(),
  54471. mw->windowPos.getY());
  54472. mw->updateYPositions();
  54473. if (itemIdThatMustBeVisible != 0)
  54474. {
  54475. const int y = minY - mw->windowPos.getY();
  54476. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54477. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54478. }
  54479. mw->resizeToBestWindowPos();
  54480. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54481. | mw->getLookAndFeel().getMenuWindowFlags());
  54482. return mw.release();
  54483. }
  54484. }
  54485. return 0;
  54486. }
  54487. void paint (Graphics& g)
  54488. {
  54489. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54490. }
  54491. void paintOverChildren (Graphics& g)
  54492. {
  54493. if (isScrolling())
  54494. {
  54495. LookAndFeel& lf = getLookAndFeel();
  54496. if (isScrollZoneActive (false))
  54497. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54498. if (isScrollZoneActive (true))
  54499. {
  54500. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54501. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54502. }
  54503. }
  54504. }
  54505. bool isScrollZoneActive (bool bottomOne) const
  54506. {
  54507. return isScrolling()
  54508. && (bottomOne
  54509. ? childYOffset < contentHeight - windowPos.getHeight()
  54510. : childYOffset > 0);
  54511. }
  54512. void addItem (const PopupMenu::Item& item)
  54513. {
  54514. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54515. addAndMakeVisible (mic);
  54516. int itemW = 80;
  54517. int itemH = 16;
  54518. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54519. mic->setSize (itemW, jlimit (2, 600, itemH));
  54520. mic->addMouseListener (this, false);
  54521. }
  54522. // hide this and all sub-comps
  54523. void hide (const PopupMenu::Item* const item)
  54524. {
  54525. if (isVisible())
  54526. {
  54527. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54528. activeSubMenu = 0;
  54529. currentChild = 0;
  54530. exitModalState (item != 0 ? item->itemId : 0);
  54531. setVisible (false);
  54532. if (item != 0
  54533. && item->commandManager != 0
  54534. && item->itemId != 0)
  54535. {
  54536. *managerOfChosenCommand = item->commandManager;
  54537. }
  54538. }
  54539. }
  54540. void dismissMenu (const PopupMenu::Item* const item)
  54541. {
  54542. if (owner != 0)
  54543. {
  54544. owner->dismissMenu (item);
  54545. }
  54546. else
  54547. {
  54548. if (item != 0)
  54549. {
  54550. // need a copy of this on the stack as the one passed in will get deleted during this call
  54551. const PopupMenu::Item mi (*item);
  54552. hide (&mi);
  54553. }
  54554. else
  54555. {
  54556. hide (0);
  54557. }
  54558. }
  54559. }
  54560. void mouseMove (const MouseEvent&)
  54561. {
  54562. timerCallback();
  54563. }
  54564. void mouseDown (const MouseEvent&)
  54565. {
  54566. timerCallback();
  54567. }
  54568. void mouseDrag (const MouseEvent&)
  54569. {
  54570. timerCallback();
  54571. }
  54572. void mouseUp (const MouseEvent&)
  54573. {
  54574. timerCallback();
  54575. }
  54576. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54577. {
  54578. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54579. lastMouse = Point<int> (-1, -1);
  54580. }
  54581. bool keyPressed (const KeyPress& key)
  54582. {
  54583. if (key.isKeyCode (KeyPress::downKey))
  54584. {
  54585. selectNextItem (1);
  54586. }
  54587. else if (key.isKeyCode (KeyPress::upKey))
  54588. {
  54589. selectNextItem (-1);
  54590. }
  54591. else if (key.isKeyCode (KeyPress::leftKey))
  54592. {
  54593. if (owner != 0)
  54594. {
  54595. Component::SafePointer<Window> parentWindow (owner);
  54596. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54597. hide (0);
  54598. if (parentWindow != 0)
  54599. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54600. disableTimerUntilMouseMoves();
  54601. }
  54602. else if (menuBarComponent != 0)
  54603. {
  54604. menuBarComponent->keyPressed (key);
  54605. }
  54606. }
  54607. else if (key.isKeyCode (KeyPress::rightKey))
  54608. {
  54609. disableTimerUntilMouseMoves();
  54610. if (showSubMenuFor (currentChild))
  54611. {
  54612. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54613. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54614. activeSubMenu->selectNextItem (1);
  54615. }
  54616. else if (menuBarComponent != 0)
  54617. {
  54618. menuBarComponent->keyPressed (key);
  54619. }
  54620. }
  54621. else if (key.isKeyCode (KeyPress::returnKey))
  54622. {
  54623. triggerCurrentlyHighlightedItem();
  54624. }
  54625. else if (key.isKeyCode (KeyPress::escapeKey))
  54626. {
  54627. dismissMenu (0);
  54628. }
  54629. else
  54630. {
  54631. return false;
  54632. }
  54633. return true;
  54634. }
  54635. void inputAttemptWhenModal()
  54636. {
  54637. timerCallback();
  54638. if (! isOverAnyMenu())
  54639. {
  54640. if (componentAttachedTo != 0)
  54641. {
  54642. // we want to dismiss the menu, but if we do it synchronously, then
  54643. // the mouse-click will be allowed to pass through. That's good, except
  54644. // when the user clicks on the button that orginally popped the menu up,
  54645. // as they'll expect the menu to go away, and in fact it'll just
  54646. // come back. So only dismiss synchronously if they're not on the original
  54647. // comp that we're attached to.
  54648. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54649. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54650. {
  54651. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54652. return;
  54653. }
  54654. }
  54655. dismissMenu (0);
  54656. }
  54657. }
  54658. void handleCommandMessage (int commandId)
  54659. {
  54660. Component::handleCommandMessage (commandId);
  54661. if (commandId == PopupMenuSettings::dismissCommandId)
  54662. dismissMenu (0);
  54663. }
  54664. void timerCallback()
  54665. {
  54666. if (! isVisible())
  54667. return;
  54668. if (componentAttachedTo != componentAttachedToOriginal)
  54669. {
  54670. dismissMenu (0);
  54671. return;
  54672. }
  54673. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54674. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54675. return;
  54676. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54677. // move rather than a real timer callback
  54678. const Point<int> globalMousePos (Desktop::getMousePosition());
  54679. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54680. const uint32 now = Time::getMillisecondCounter();
  54681. if (now > timeEnteredCurrentChildComp + 100
  54682. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54683. && currentChild->isValidComponent()
  54684. && (! disableMouseMoves)
  54685. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54686. {
  54687. showSubMenuFor (currentChild);
  54688. }
  54689. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54690. {
  54691. highlightItemUnderMouse (globalMousePos, localMousePos);
  54692. }
  54693. bool overScrollArea = false;
  54694. if (isScrolling()
  54695. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54696. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54697. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54698. {
  54699. if (now > lastScroll + 20)
  54700. {
  54701. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54702. int amount = 0;
  54703. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54704. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54705. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54706. lastScroll = now;
  54707. }
  54708. overScrollArea = true;
  54709. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54710. }
  54711. else
  54712. {
  54713. scrollAcceleration = 1.0;
  54714. }
  54715. const bool wasDown = isDown;
  54716. bool isOverAny = isOverAnyMenu();
  54717. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54718. {
  54719. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54720. isOverAny = isOverAnyMenu();
  54721. }
  54722. if (hideOnExit && hasBeenOver && ! isOverAny)
  54723. {
  54724. hide (0);
  54725. }
  54726. else
  54727. {
  54728. isDown = hasBeenOver
  54729. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54730. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54731. bool anyFocused = Process::isForegroundProcess();
  54732. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54733. {
  54734. // because no component at all may have focus, our test here will
  54735. // only be triggered when something has focus and then loses it.
  54736. anyFocused = ! hasAnyJuceCompHadFocus;
  54737. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54738. {
  54739. if (ComponentPeer::getPeer (i)->isFocused())
  54740. {
  54741. anyFocused = true;
  54742. hasAnyJuceCompHadFocus = true;
  54743. break;
  54744. }
  54745. }
  54746. }
  54747. if (! anyFocused)
  54748. {
  54749. if (now > lastFocused + 10)
  54750. {
  54751. wasHiddenBecauseOfAppChange() = true;
  54752. dismissMenu (0);
  54753. return; // may have been deleted by the previous call..
  54754. }
  54755. }
  54756. else if (wasDown && now > menuCreationTime + 250
  54757. && ! (isDown || overScrollArea))
  54758. {
  54759. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54760. if (isOver)
  54761. {
  54762. triggerCurrentlyHighlightedItem();
  54763. }
  54764. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54765. {
  54766. dismissMenu (0);
  54767. }
  54768. return; // may have been deleted by the previous calls..
  54769. }
  54770. else
  54771. {
  54772. lastFocused = now;
  54773. }
  54774. }
  54775. }
  54776. static Array<Window*>& getActiveWindows()
  54777. {
  54778. static Array<Window*> activeMenuWindows;
  54779. return activeMenuWindows;
  54780. }
  54781. static bool& wasHiddenBecauseOfAppChange() throw()
  54782. {
  54783. static bool b = false;
  54784. return b;
  54785. }
  54786. juce_UseDebuggingNewOperator
  54787. private:
  54788. Window* owner;
  54789. PopupMenu::ItemComponent* currentChild;
  54790. ScopedPointer <Window> activeSubMenu;
  54791. Component* menuBarComponent;
  54792. ApplicationCommandManager** managerOfChosenCommand;
  54793. Component::SafePointer<Component> componentAttachedTo;
  54794. Component* componentAttachedToOriginal;
  54795. Rectangle<int> windowPos;
  54796. Point<int> lastMouse;
  54797. int minimumWidth, maximumNumColumns, standardItemHeight;
  54798. bool isOver, hasBeenOver, isDown, needsToScroll;
  54799. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54800. int numColumns, contentHeight, childYOffset;
  54801. Array <int> columnWidths;
  54802. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54803. double scrollAcceleration;
  54804. bool overlaps (const Rectangle<int>& r) const
  54805. {
  54806. return r.intersects (getBounds())
  54807. || (owner != 0 && owner->overlaps (r));
  54808. }
  54809. bool isOverAnyMenu() const
  54810. {
  54811. return (owner != 0) ? owner->isOverAnyMenu()
  54812. : isOverChildren();
  54813. }
  54814. bool isOverChildren() const
  54815. {
  54816. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54817. return isVisible()
  54818. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54819. }
  54820. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54821. {
  54822. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54823. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54824. if (activeSubMenu != 0)
  54825. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54826. }
  54827. bool treeContains (const Window* const window) const throw()
  54828. {
  54829. const Window* mw = this;
  54830. while (mw->owner != 0)
  54831. mw = mw->owner;
  54832. while (mw != 0)
  54833. {
  54834. if (mw == window)
  54835. return true;
  54836. mw = mw->activeSubMenu;
  54837. }
  54838. return false;
  54839. }
  54840. void calculateWindowPos (const int minX, const int maxX,
  54841. const int minY, const int maxY,
  54842. const bool alignToRectangle)
  54843. {
  54844. const Rectangle<int> mon (Desktop::getInstance()
  54845. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54846. (minY + maxY) / 2),
  54847. #if JUCE_MAC
  54848. true));
  54849. #else
  54850. false)); // on windows, don't stop the menu overlapping the taskbar
  54851. #endif
  54852. int x, y, widthToUse, heightToUse;
  54853. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54854. if (alignToRectangle)
  54855. {
  54856. x = minX;
  54857. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54858. const int spaceOver = minY - mon.getY();
  54859. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54860. y = maxY;
  54861. else
  54862. y = minY - heightToUse;
  54863. }
  54864. else
  54865. {
  54866. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54867. if (owner != 0)
  54868. {
  54869. if (owner->owner != 0)
  54870. {
  54871. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54872. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54873. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54874. tendTowardsRight = true;
  54875. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54876. tendTowardsRight = false;
  54877. }
  54878. else if (maxX + widthToUse < mon.getRight() - 32)
  54879. {
  54880. tendTowardsRight = true;
  54881. }
  54882. }
  54883. const int biggestSpace = jmax (mon.getRight() - maxX,
  54884. minX - mon.getX()) - 32;
  54885. if (biggestSpace < widthToUse)
  54886. {
  54887. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54888. if (numColumns > 1)
  54889. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54890. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54891. }
  54892. if (tendTowardsRight)
  54893. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54894. else
  54895. x = jmax (mon.getX() + 4, minX - widthToUse);
  54896. y = minY;
  54897. if ((minY + maxY) / 2 > mon.getCentreY())
  54898. y = jmax (mon.getY(), maxY - heightToUse);
  54899. }
  54900. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54901. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54902. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54903. // sets this flag if it's big enough to obscure any of its parent menus
  54904. hideOnExit = (owner != 0)
  54905. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54906. }
  54907. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54908. {
  54909. numColumns = 0;
  54910. contentHeight = 0;
  54911. const int maxMenuH = getParentHeight() - 24;
  54912. int totalW;
  54913. do
  54914. {
  54915. ++numColumns;
  54916. totalW = workOutBestSize (maxMenuW);
  54917. if (totalW > maxMenuW)
  54918. {
  54919. numColumns = jmax (1, numColumns - 1);
  54920. totalW = workOutBestSize (maxMenuW); // to update col widths
  54921. break;
  54922. }
  54923. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  54924. {
  54925. break;
  54926. }
  54927. } while (numColumns < maximumNumColumns);
  54928. const int actualH = jmin (contentHeight, maxMenuH);
  54929. needsToScroll = contentHeight > actualH;
  54930. width = updateYPositions();
  54931. height = actualH + PopupMenuSettings::borderSize * 2;
  54932. }
  54933. int workOutBestSize (const int maxMenuW)
  54934. {
  54935. int totalW = 0;
  54936. contentHeight = 0;
  54937. int childNum = 0;
  54938. for (int col = 0; col < numColumns; ++col)
  54939. {
  54940. int i, colW = 50, colH = 0;
  54941. const int numChildren = jmin (getNumChildComponents() - childNum,
  54942. (getNumChildComponents() + numColumns - 1) / numColumns);
  54943. for (i = numChildren; --i >= 0;)
  54944. {
  54945. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  54946. colH += getChildComponent (childNum + i)->getHeight();
  54947. }
  54948. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  54949. columnWidths.set (col, colW);
  54950. totalW += colW;
  54951. contentHeight = jmax (contentHeight, colH);
  54952. childNum += numChildren;
  54953. }
  54954. if (totalW < minimumWidth)
  54955. {
  54956. totalW = minimumWidth;
  54957. for (int col = 0; col < numColumns; ++col)
  54958. columnWidths.set (0, totalW / numColumns);
  54959. }
  54960. return totalW;
  54961. }
  54962. void ensureItemIsVisible (const int itemId, int wantedY)
  54963. {
  54964. jassert (itemId != 0)
  54965. for (int i = getNumChildComponents(); --i >= 0;)
  54966. {
  54967. PopupMenu::ItemComponent* const m = static_cast <PopupMenu::ItemComponent*> (getChildComponent (i));
  54968. if (m != 0
  54969. && m->itemInfo.itemId == itemId
  54970. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  54971. {
  54972. const int currentY = m->getY();
  54973. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  54974. {
  54975. if (wantedY < 0)
  54976. wantedY = jlimit (PopupMenuSettings::scrollZone,
  54977. jmax (PopupMenuSettings::scrollZone,
  54978. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  54979. currentY);
  54980. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  54981. int deltaY = wantedY - currentY;
  54982. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  54983. jmin (windowPos.getHeight(), mon.getHeight()));
  54984. const int newY = jlimit (mon.getY(),
  54985. mon.getBottom() - windowPos.getHeight(),
  54986. windowPos.getY() + deltaY);
  54987. deltaY -= newY - windowPos.getY();
  54988. childYOffset -= deltaY;
  54989. windowPos.setPosition (windowPos.getX(), newY);
  54990. updateYPositions();
  54991. }
  54992. break;
  54993. }
  54994. }
  54995. }
  54996. void resizeToBestWindowPos()
  54997. {
  54998. Rectangle<int> r (windowPos);
  54999. if (childYOffset < 0)
  55000. {
  55001. r.setBounds (r.getX(), r.getY() - childYOffset,
  55002. r.getWidth(), r.getHeight() + childYOffset);
  55003. }
  55004. else if (childYOffset > 0)
  55005. {
  55006. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55007. if (spaceAtBottom > 0)
  55008. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55009. }
  55010. setBounds (r);
  55011. updateYPositions();
  55012. }
  55013. void alterChildYPos (const int delta)
  55014. {
  55015. if (isScrolling())
  55016. {
  55017. childYOffset += delta;
  55018. if (delta < 0)
  55019. {
  55020. childYOffset = jmax (childYOffset, 0);
  55021. }
  55022. else if (delta > 0)
  55023. {
  55024. childYOffset = jmin (childYOffset,
  55025. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55026. }
  55027. updateYPositions();
  55028. }
  55029. else
  55030. {
  55031. childYOffset = 0;
  55032. }
  55033. resizeToBestWindowPos();
  55034. repaint();
  55035. }
  55036. int updateYPositions()
  55037. {
  55038. int x = 0;
  55039. int childNum = 0;
  55040. for (int col = 0; col < numColumns; ++col)
  55041. {
  55042. const int numChildren = jmin (getNumChildComponents() - childNum,
  55043. (getNumChildComponents() + numColumns - 1) / numColumns);
  55044. const int colW = columnWidths [col];
  55045. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55046. for (int i = 0; i < numChildren; ++i)
  55047. {
  55048. Component* const c = getChildComponent (childNum + i);
  55049. c->setBounds (x, y, colW, c->getHeight());
  55050. y += c->getHeight();
  55051. }
  55052. x += colW;
  55053. childNum += numChildren;
  55054. }
  55055. return x;
  55056. }
  55057. bool isScrolling() const throw()
  55058. {
  55059. return childYOffset != 0 || needsToScroll;
  55060. }
  55061. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55062. {
  55063. if (currentChild->isValidComponent())
  55064. currentChild->setHighlighted (false);
  55065. currentChild = child;
  55066. if (currentChild != 0)
  55067. {
  55068. currentChild->setHighlighted (true);
  55069. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55070. }
  55071. }
  55072. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55073. {
  55074. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55075. activeSubMenu = 0;
  55076. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55077. {
  55078. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55079. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55080. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55081. dismissOnMouseUp,
  55082. this,
  55083. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55084. 0, maximumNumColumns,
  55085. standardItemHeight,
  55086. false, 0, menuBarComponent,
  55087. managerOfChosenCommand,
  55088. componentAttachedTo);
  55089. if (activeSubMenu != 0)
  55090. {
  55091. activeSubMenu->setVisible (true);
  55092. activeSubMenu->enterModalState (false);
  55093. activeSubMenu->toFront (false);
  55094. return true;
  55095. }
  55096. }
  55097. return false;
  55098. }
  55099. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55100. {
  55101. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55102. if (isOver)
  55103. hasBeenOver = true;
  55104. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55105. {
  55106. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55107. if (disableMouseMoves && isOver)
  55108. disableMouseMoves = false;
  55109. }
  55110. if (disableMouseMoves)
  55111. return;
  55112. bool isMovingTowardsMenu = false;
  55113. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55114. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55115. {
  55116. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55117. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55118. // extends from the last mouse pos to the submenu's rectangle..
  55119. float subX = (float) activeSubMenu->getScreenX();
  55120. if (activeSubMenu->getX() > getX())
  55121. {
  55122. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55123. }
  55124. else
  55125. {
  55126. lastMouse += Point<int> (2, 0);
  55127. subX += activeSubMenu->getWidth();
  55128. }
  55129. Path areaTowardsSubMenu;
  55130. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55131. (float) lastMouse.getY(),
  55132. subX,
  55133. (float) activeSubMenu->getScreenY(),
  55134. subX,
  55135. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55136. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55137. }
  55138. lastMouse = globalMousePos;
  55139. if (! isMovingTowardsMenu)
  55140. {
  55141. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55142. if (c == this)
  55143. c = 0;
  55144. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55145. if (mic == 0 && c != 0)
  55146. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55147. if (mic != currentChild
  55148. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55149. {
  55150. if (isOver && (c != 0) && (activeSubMenu != 0))
  55151. {
  55152. activeSubMenu->hide (0);
  55153. }
  55154. if (! isOver)
  55155. mic = 0;
  55156. setCurrentlyHighlightedChild (mic);
  55157. }
  55158. }
  55159. }
  55160. void triggerCurrentlyHighlightedItem()
  55161. {
  55162. if (currentChild->isValidComponent()
  55163. && currentChild->itemInfo.canBeTriggered()
  55164. && (currentChild->itemInfo.customComp == 0
  55165. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55166. {
  55167. dismissMenu (&currentChild->itemInfo);
  55168. }
  55169. }
  55170. void selectNextItem (const int delta)
  55171. {
  55172. disableTimerUntilMouseMoves();
  55173. PopupMenu::ItemComponent* mic = 0;
  55174. bool wasLastOne = (currentChild == 0);
  55175. const int numItems = getNumChildComponents();
  55176. for (int i = 0; i < numItems + 1; ++i)
  55177. {
  55178. int index = (delta > 0) ? i : (numItems - 1 - i);
  55179. index = (index + numItems) % numItems;
  55180. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55181. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55182. && wasLastOne)
  55183. break;
  55184. if (mic == currentChild)
  55185. wasLastOne = true;
  55186. }
  55187. setCurrentlyHighlightedChild (mic);
  55188. }
  55189. void disableTimerUntilMouseMoves()
  55190. {
  55191. disableMouseMoves = true;
  55192. if (owner != 0)
  55193. owner->disableTimerUntilMouseMoves();
  55194. }
  55195. Window (const Window&);
  55196. Window& operator= (const Window&);
  55197. };
  55198. PopupMenu::PopupMenu()
  55199. : lookAndFeel (0),
  55200. separatorPending (false)
  55201. {
  55202. }
  55203. PopupMenu::PopupMenu (const PopupMenu& other)
  55204. : lookAndFeel (other.lookAndFeel),
  55205. separatorPending (false)
  55206. {
  55207. items.ensureStorageAllocated (other.items.size());
  55208. for (int i = 0; i < other.items.size(); ++i)
  55209. items.add (new Item (*other.items.getUnchecked(i)));
  55210. }
  55211. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55212. {
  55213. if (this != &other)
  55214. {
  55215. lookAndFeel = other.lookAndFeel;
  55216. clear();
  55217. items.ensureStorageAllocated (other.items.size());
  55218. for (int i = 0; i < other.items.size(); ++i)
  55219. items.add (new Item (*other.items.getUnchecked(i)));
  55220. }
  55221. return *this;
  55222. }
  55223. PopupMenu::~PopupMenu()
  55224. {
  55225. clear();
  55226. }
  55227. void PopupMenu::clear()
  55228. {
  55229. items.clear();
  55230. separatorPending = false;
  55231. }
  55232. void PopupMenu::addSeparatorIfPending()
  55233. {
  55234. if (separatorPending)
  55235. {
  55236. separatorPending = false;
  55237. if (items.size() > 0)
  55238. items.add (new Item());
  55239. }
  55240. }
  55241. void PopupMenu::addItem (const int itemResultId,
  55242. const String& itemText,
  55243. const bool isActive,
  55244. const bool isTicked,
  55245. const Image* const iconToUse)
  55246. {
  55247. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55248. // didn't pick anything, so you shouldn't use it as the id
  55249. // for an item..
  55250. addSeparatorIfPending();
  55251. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55252. iconToUse, Colours::black, false, 0, 0, 0));
  55253. }
  55254. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55255. const int commandID,
  55256. const String& displayName)
  55257. {
  55258. jassert (commandManager != 0 && commandID != 0);
  55259. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55260. if (registeredInfo != 0)
  55261. {
  55262. ApplicationCommandInfo info (*registeredInfo);
  55263. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55264. addSeparatorIfPending();
  55265. items.add (new Item (commandID,
  55266. displayName.isNotEmpty() ? displayName
  55267. : info.shortName,
  55268. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55269. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55270. 0,
  55271. Colours::black,
  55272. false,
  55273. 0, 0,
  55274. commandManager));
  55275. }
  55276. }
  55277. void PopupMenu::addColouredItem (const int itemResultId,
  55278. const String& itemText,
  55279. const Colour& itemTextColour,
  55280. const bool isActive,
  55281. const bool isTicked,
  55282. const Image* const iconToUse)
  55283. {
  55284. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55285. // didn't pick anything, so you shouldn't use it as the id
  55286. // for an item..
  55287. addSeparatorIfPending();
  55288. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55289. iconToUse, itemTextColour, true, 0, 0, 0));
  55290. }
  55291. void PopupMenu::addCustomItem (const int itemResultId,
  55292. PopupMenuCustomComponent* const customComponent)
  55293. {
  55294. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55295. // didn't pick anything, so you shouldn't use it as the id
  55296. // for an item..
  55297. addSeparatorIfPending();
  55298. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55299. Colours::black, false, customComponent, 0, 0));
  55300. }
  55301. class NormalComponentWrapper : public PopupMenuCustomComponent
  55302. {
  55303. public:
  55304. NormalComponentWrapper (Component* const comp,
  55305. const int w, const int h,
  55306. const bool triggerMenuItemAutomaticallyWhenClicked)
  55307. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55308. width (w),
  55309. height (h)
  55310. {
  55311. addAndMakeVisible (comp);
  55312. }
  55313. ~NormalComponentWrapper() {}
  55314. void getIdealSize (int& idealWidth, int& idealHeight)
  55315. {
  55316. idealWidth = width;
  55317. idealHeight = height;
  55318. }
  55319. void resized()
  55320. {
  55321. if (getChildComponent(0) != 0)
  55322. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55323. }
  55324. juce_UseDebuggingNewOperator
  55325. private:
  55326. const int width, height;
  55327. NormalComponentWrapper (const NormalComponentWrapper&);
  55328. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55329. };
  55330. void PopupMenu::addCustomItem (const int itemResultId,
  55331. Component* customComponent,
  55332. int idealWidth, int idealHeight,
  55333. const bool triggerMenuItemAutomaticallyWhenClicked)
  55334. {
  55335. addCustomItem (itemResultId,
  55336. new NormalComponentWrapper (customComponent,
  55337. idealWidth, idealHeight,
  55338. triggerMenuItemAutomaticallyWhenClicked));
  55339. }
  55340. void PopupMenu::addSubMenu (const String& subMenuName,
  55341. const PopupMenu& subMenu,
  55342. const bool isActive,
  55343. Image* const iconToUse,
  55344. const bool isTicked)
  55345. {
  55346. addSeparatorIfPending();
  55347. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55348. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55349. }
  55350. void PopupMenu::addSeparator()
  55351. {
  55352. separatorPending = true;
  55353. }
  55354. class HeaderItemComponent : public PopupMenuCustomComponent
  55355. {
  55356. public:
  55357. HeaderItemComponent (const String& name)
  55358. : PopupMenuCustomComponent (false)
  55359. {
  55360. setName (name);
  55361. }
  55362. ~HeaderItemComponent()
  55363. {
  55364. }
  55365. void paint (Graphics& g)
  55366. {
  55367. Font f (getLookAndFeel().getPopupMenuFont());
  55368. f.setBold (true);
  55369. g.setFont (f);
  55370. g.setColour (findColour (PopupMenu::headerTextColourId));
  55371. g.drawFittedText (getName(),
  55372. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55373. Justification::bottomLeft, 1);
  55374. }
  55375. void getIdealSize (int& idealWidth,
  55376. int& idealHeight)
  55377. {
  55378. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55379. idealHeight += idealHeight / 2;
  55380. idealWidth += idealWidth / 4;
  55381. }
  55382. juce_UseDebuggingNewOperator
  55383. };
  55384. void PopupMenu::addSectionHeader (const String& title)
  55385. {
  55386. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55387. }
  55388. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55389. const int itemIdThatMustBeVisible,
  55390. const int minimumWidth,
  55391. const int maximumNumColumns,
  55392. const int standardItemHeight,
  55393. const bool alignToRectangle,
  55394. Component* menuBarComponent,
  55395. ApplicationCommandManager** managerOfChosenCommand,
  55396. Component* const componentAttachedTo)
  55397. {
  55398. Window* const pw
  55399. = Window::create (*this,
  55400. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55401. 0,
  55402. x, x + w,
  55403. y, y + h,
  55404. minimumWidth,
  55405. maximumNumColumns,
  55406. standardItemHeight,
  55407. alignToRectangle,
  55408. itemIdThatMustBeVisible,
  55409. menuBarComponent,
  55410. managerOfChosenCommand,
  55411. componentAttachedTo);
  55412. if (pw != 0)
  55413. pw->setVisible (true);
  55414. return pw;
  55415. }
  55416. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55417. const int itemIdThatMustBeVisible,
  55418. const int minimumWidth,
  55419. const int maximumNumColumns,
  55420. const int standardItemHeight,
  55421. const bool alignToRectangle,
  55422. Component* const componentAttachedTo)
  55423. {
  55424. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55425. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55426. Window::wasHiddenBecauseOfAppChange() = false;
  55427. int result = 0;
  55428. ApplicationCommandManager* managerOfChosenCommand = 0;
  55429. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55430. itemIdThatMustBeVisible,
  55431. minimumWidth,
  55432. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55433. standardItemHeight,
  55434. alignToRectangle, 0,
  55435. &managerOfChosenCommand,
  55436. componentAttachedTo));
  55437. if (popupComp != 0)
  55438. {
  55439. popupComp->enterModalState (false);
  55440. popupComp->toFront (false); // need to do this after making it modal, or it could
  55441. // be stuck behind other comps that are already modal..
  55442. result = popupComp->runModalLoop();
  55443. popupComp = 0;
  55444. if (! Window::wasHiddenBecauseOfAppChange())
  55445. {
  55446. if (prevTopLevel != 0)
  55447. prevTopLevel->toFront (true);
  55448. if (prevFocused != 0)
  55449. prevFocused->grabKeyboardFocus();
  55450. }
  55451. }
  55452. if (managerOfChosenCommand != 0 && result != 0)
  55453. {
  55454. ApplicationCommandTarget::InvocationInfo info (result);
  55455. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55456. managerOfChosenCommand->invoke (info, true);
  55457. }
  55458. return result;
  55459. }
  55460. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55461. const int minimumWidth,
  55462. const int maximumNumColumns,
  55463. const int standardItemHeight)
  55464. {
  55465. const Point<int> mousePos (Desktop::getMousePosition());
  55466. return showAt (mousePos.getX(), mousePos.getY(),
  55467. itemIdThatMustBeVisible,
  55468. minimumWidth,
  55469. maximumNumColumns,
  55470. standardItemHeight);
  55471. }
  55472. int PopupMenu::showAt (const int screenX,
  55473. const int screenY,
  55474. const int itemIdThatMustBeVisible,
  55475. const int minimumWidth,
  55476. const int maximumNumColumns,
  55477. const int standardItemHeight)
  55478. {
  55479. return showMenu (screenX, screenY, 1, 1,
  55480. itemIdThatMustBeVisible,
  55481. minimumWidth, maximumNumColumns,
  55482. standardItemHeight,
  55483. false, 0);
  55484. }
  55485. int PopupMenu::showAt (Component* componentToAttachTo,
  55486. const int itemIdThatMustBeVisible,
  55487. const int minimumWidth,
  55488. const int maximumNumColumns,
  55489. const int standardItemHeight)
  55490. {
  55491. if (componentToAttachTo != 0)
  55492. {
  55493. return showMenu (componentToAttachTo->getScreenX(),
  55494. componentToAttachTo->getScreenY(),
  55495. componentToAttachTo->getWidth(),
  55496. componentToAttachTo->getHeight(),
  55497. itemIdThatMustBeVisible,
  55498. minimumWidth,
  55499. maximumNumColumns,
  55500. standardItemHeight,
  55501. true, componentToAttachTo);
  55502. }
  55503. else
  55504. {
  55505. return show (itemIdThatMustBeVisible,
  55506. minimumWidth,
  55507. maximumNumColumns,
  55508. standardItemHeight);
  55509. }
  55510. }
  55511. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55512. {
  55513. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55514. {
  55515. Window* const pmw = Window::getActiveWindows()[i];
  55516. if (pmw != 0)
  55517. pmw->dismissMenu (0);
  55518. }
  55519. }
  55520. int PopupMenu::getNumItems() const throw()
  55521. {
  55522. int num = 0;
  55523. for (int i = items.size(); --i >= 0;)
  55524. if (! (items.getUnchecked(i))->isSeparator)
  55525. ++num;
  55526. return num;
  55527. }
  55528. bool PopupMenu::containsCommandItem (const int commandID) const
  55529. {
  55530. for (int i = items.size(); --i >= 0;)
  55531. {
  55532. const Item* mi = items.getUnchecked (i);
  55533. if ((mi->itemId == commandID && mi->commandManager != 0)
  55534. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55535. {
  55536. return true;
  55537. }
  55538. }
  55539. return false;
  55540. }
  55541. bool PopupMenu::containsAnyActiveItems() const throw()
  55542. {
  55543. for (int i = items.size(); --i >= 0;)
  55544. {
  55545. const Item* const mi = items.getUnchecked (i);
  55546. if (mi->subMenu != 0)
  55547. {
  55548. if (mi->subMenu->containsAnyActiveItems())
  55549. return true;
  55550. }
  55551. else if (mi->active)
  55552. {
  55553. return true;
  55554. }
  55555. }
  55556. return false;
  55557. }
  55558. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55559. {
  55560. lookAndFeel = newLookAndFeel;
  55561. }
  55562. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55563. : isHighlighted (false),
  55564. isTriggeredAutomatically (isTriggeredAutomatically_)
  55565. {
  55566. }
  55567. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55568. {
  55569. }
  55570. void PopupMenuCustomComponent::triggerMenuItem()
  55571. {
  55572. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55573. if (mic != 0)
  55574. {
  55575. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55576. if (pmw != 0)
  55577. {
  55578. pmw->dismissMenu (&mic->itemInfo);
  55579. }
  55580. else
  55581. {
  55582. // something must have gone wrong with the component hierarchy if this happens..
  55583. jassertfalse
  55584. }
  55585. }
  55586. else
  55587. {
  55588. // why isn't this component inside a menu? Not much point triggering the item if
  55589. // there's no menu.
  55590. jassertfalse
  55591. }
  55592. }
  55593. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55594. : subMenu (0),
  55595. itemId (0),
  55596. isSeparator (false),
  55597. isTicked (false),
  55598. isEnabled (false),
  55599. isCustomComponent (false),
  55600. isSectionHeader (false),
  55601. customColour (0),
  55602. customImage (0),
  55603. menu (menu_),
  55604. index (0)
  55605. {
  55606. }
  55607. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55608. {
  55609. }
  55610. bool PopupMenu::MenuItemIterator::next()
  55611. {
  55612. if (index >= menu.items.size())
  55613. return false;
  55614. const Item* const item = menu.items.getUnchecked (index);
  55615. ++index;
  55616. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55617. subMenu = item->subMenu;
  55618. itemId = item->itemId;
  55619. isSeparator = item->isSeparator;
  55620. isTicked = item->isTicked;
  55621. isEnabled = item->active;
  55622. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55623. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55624. customColour = item->usesColour ? &(item->textColour) : 0;
  55625. customImage = item->image;
  55626. commandManager = item->commandManager;
  55627. return true;
  55628. }
  55629. END_JUCE_NAMESPACE
  55630. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55631. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55632. BEGIN_JUCE_NAMESPACE
  55633. ComponentDragger::ComponentDragger()
  55634. : constrainer (0)
  55635. {
  55636. }
  55637. ComponentDragger::~ComponentDragger()
  55638. {
  55639. }
  55640. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55641. ComponentBoundsConstrainer* const constrainer_)
  55642. {
  55643. jassert (componentToDrag->isValidComponent());
  55644. if (componentToDrag != 0)
  55645. {
  55646. constrainer = constrainer_;
  55647. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55648. }
  55649. }
  55650. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55651. {
  55652. jassert (componentToDrag->isValidComponent());
  55653. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55654. if (componentToDrag != 0)
  55655. {
  55656. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55657. const Component* const parentComp = componentToDrag->getParentComponent();
  55658. if (parentComp != 0)
  55659. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55660. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55661. if (constrainer != 0)
  55662. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55663. else
  55664. componentToDrag->setBounds (bounds);
  55665. }
  55666. }
  55667. END_JUCE_NAMESPACE
  55668. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55669. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55670. BEGIN_JUCE_NAMESPACE
  55671. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55672. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55673. class DragImageComponent : public Component,
  55674. public Timer
  55675. {
  55676. public:
  55677. DragImageComponent (Image* const im,
  55678. const String& desc,
  55679. Component* const sourceComponent,
  55680. Component* const mouseDragSource_,
  55681. DragAndDropContainer* const o,
  55682. const Point<int>& imageOffset_)
  55683. : image (im),
  55684. source (sourceComponent),
  55685. mouseDragSource (mouseDragSource_),
  55686. owner (o),
  55687. dragDesc (desc),
  55688. imageOffset (imageOffset_),
  55689. hasCheckedForExternalDrag (false),
  55690. drawImage (true)
  55691. {
  55692. setSize (im->getWidth(), im->getHeight());
  55693. if (mouseDragSource == 0)
  55694. mouseDragSource = source;
  55695. mouseDragSource->addMouseListener (this, false);
  55696. startTimer (200);
  55697. setInterceptsMouseClicks (false, false);
  55698. setAlwaysOnTop (true);
  55699. }
  55700. ~DragImageComponent()
  55701. {
  55702. if (owner->dragImageComponent == this)
  55703. owner->dragImageComponent.release();
  55704. if (mouseDragSource != 0)
  55705. {
  55706. mouseDragSource->removeMouseListener (this);
  55707. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55708. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55709. }
  55710. }
  55711. void paint (Graphics& g)
  55712. {
  55713. if (isOpaque())
  55714. g.fillAll (Colours::white);
  55715. if (drawImage)
  55716. {
  55717. g.setOpacity (1.0f);
  55718. g.drawImageAt (image, 0, 0);
  55719. }
  55720. }
  55721. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55722. {
  55723. Component* hit = getParentComponent();
  55724. if (hit == 0)
  55725. {
  55726. hit = Desktop::getInstance().findComponentAt (screenPos);
  55727. }
  55728. else
  55729. {
  55730. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55731. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55732. }
  55733. // (note: use a local copy of the dragDesc member in case the callback runs
  55734. // a modal loop and deletes this object before the method completes)
  55735. const String dragDescLocal (dragDesc);
  55736. while (hit != 0)
  55737. {
  55738. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55739. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55740. {
  55741. relativePos = hit->globalPositionToRelative (screenPos);
  55742. return ddt;
  55743. }
  55744. hit = hit->getParentComponent();
  55745. }
  55746. return 0;
  55747. }
  55748. void mouseUp (const MouseEvent& e)
  55749. {
  55750. if (e.originalComponent != this)
  55751. {
  55752. if (mouseDragSource != 0)
  55753. mouseDragSource->removeMouseListener (this);
  55754. bool dropAccepted = false;
  55755. DragAndDropTarget* ddt = 0;
  55756. Point<int> relPos;
  55757. if (isVisible())
  55758. {
  55759. setVisible (false);
  55760. ddt = findTarget (e.getScreenPosition(), relPos);
  55761. // fade this component and remove it - it'll be deleted later by the timer callback
  55762. dropAccepted = ddt != 0;
  55763. setVisible (true);
  55764. if (dropAccepted || source == 0)
  55765. {
  55766. fadeOutComponent (120);
  55767. }
  55768. else
  55769. {
  55770. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55771. source->getHeight() / 2)));
  55772. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55773. getHeight() / 2)));
  55774. fadeOutComponent (120,
  55775. target.getX() - ourCentre.getX(),
  55776. target.getY() - ourCentre.getY());
  55777. }
  55778. }
  55779. if (getParentComponent() != 0)
  55780. getParentComponent()->removeChildComponent (this);
  55781. if (dropAccepted && ddt != 0)
  55782. {
  55783. // (note: use a local copy of the dragDesc member in case the callback runs
  55784. // a modal loop and deletes this object before the method completes)
  55785. const String dragDescLocal (dragDesc);
  55786. currentlyOverComp = 0;
  55787. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55788. }
  55789. // careful - this object could now be deleted..
  55790. }
  55791. }
  55792. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55793. {
  55794. // (note: use a local copy of the dragDesc member in case the callback runs
  55795. // a modal loop and deletes this object before it returns)
  55796. const String dragDescLocal (dragDesc);
  55797. Point<int> newPos (screenPos + imageOffset);
  55798. if (getParentComponent() != 0)
  55799. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55800. //if (newX != getX() || newY != getY())
  55801. {
  55802. setTopLeftPosition (newPos.getX(), newPos.getY());
  55803. Point<int> relPos;
  55804. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55805. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55806. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55807. if (ddtComp != currentlyOverComp)
  55808. {
  55809. if (currentlyOverComp != 0 && source != 0
  55810. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55811. {
  55812. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55813. }
  55814. currentlyOverComp = ddtComp;
  55815. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55816. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55817. }
  55818. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55819. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55820. if (getCurrentlyOver() == 0
  55821. && canDoExternalDrag
  55822. && ! hasCheckedForExternalDrag)
  55823. {
  55824. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55825. {
  55826. hasCheckedForExternalDrag = true;
  55827. StringArray files;
  55828. bool canMoveFiles = false;
  55829. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55830. && files.size() > 0)
  55831. {
  55832. Component::SafePointer<Component> cdw (this);
  55833. setVisible (false);
  55834. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55835. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55836. if (cdw != 0)
  55837. delete this;
  55838. return;
  55839. }
  55840. }
  55841. }
  55842. }
  55843. }
  55844. void mouseDrag (const MouseEvent& e)
  55845. {
  55846. if (e.originalComponent != this)
  55847. updateLocation (true, e.getScreenPosition());
  55848. }
  55849. void timerCallback()
  55850. {
  55851. if (source == 0)
  55852. {
  55853. delete this;
  55854. }
  55855. else if (! isMouseButtonDownAnywhere())
  55856. {
  55857. if (mouseDragSource != 0)
  55858. mouseDragSource->removeMouseListener (this);
  55859. delete this;
  55860. }
  55861. }
  55862. private:
  55863. ScopedPointer<Image> image;
  55864. Component::SafePointer<Component> source;
  55865. Component::SafePointer<Component> mouseDragSource;
  55866. DragAndDropContainer* const owner;
  55867. Component::SafePointer<Component> currentlyOverComp;
  55868. DragAndDropTarget* getCurrentlyOver()
  55869. {
  55870. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55871. }
  55872. String dragDesc;
  55873. const Point<int> imageOffset;
  55874. bool hasCheckedForExternalDrag, drawImage;
  55875. DragImageComponent (const DragImageComponent&);
  55876. DragImageComponent& operator= (const DragImageComponent&);
  55877. };
  55878. DragAndDropContainer::DragAndDropContainer()
  55879. {
  55880. }
  55881. DragAndDropContainer::~DragAndDropContainer()
  55882. {
  55883. dragImageComponent = 0;
  55884. }
  55885. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55886. Component* sourceComponent,
  55887. Image* dragImage_,
  55888. const bool allowDraggingToExternalWindows,
  55889. const Point<int>* imageOffsetFromMouse)
  55890. {
  55891. ScopedPointer <Image> dragImage (dragImage_);
  55892. if (dragImageComponent == 0)
  55893. {
  55894. Component* const thisComp = dynamic_cast <Component*> (this);
  55895. if (thisComp == 0)
  55896. {
  55897. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55898. return;
  55899. }
  55900. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55901. if (draggingSource == 0 || ! draggingSource->isDragging())
  55902. {
  55903. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55904. return;
  55905. }
  55906. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55907. Point<int> imageOffset;
  55908. if (dragImage == 0)
  55909. {
  55910. dragImage = sourceComponent->createComponentSnapshot (sourceComponent->getLocalBounds());
  55911. if (dragImage->getFormat() != Image::ARGB)
  55912. {
  55913. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  55914. Graphics g2 (*newIm);
  55915. g2.drawImageAt (dragImage, 0, 0);
  55916. dragImage = newIm;
  55917. }
  55918. dragImage->multiplyAllAlphas (0.6f);
  55919. const int lo = 150;
  55920. const int hi = 400;
  55921. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  55922. Point<int> clipped (dragImage->getBounds().getConstrainedPoint (relPos));
  55923. for (int y = dragImage->getHeight(); --y >= 0;)
  55924. {
  55925. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  55926. for (int x = dragImage->getWidth(); --x >= 0;)
  55927. {
  55928. const int dx = x - clipped.getX();
  55929. const int distance = roundToInt (sqrt (dx * dx + dy));
  55930. if (distance > lo)
  55931. {
  55932. const float alpha = (distance > hi) ? 0
  55933. : (hi - distance) / (float) (hi - lo)
  55934. + Random::getSystemRandom().nextFloat() * 0.008f;
  55935. dragImage->multiplyAlphaAt (x, y, alpha);
  55936. }
  55937. }
  55938. }
  55939. imageOffset = -clipped;
  55940. }
  55941. else
  55942. {
  55943. if (imageOffsetFromMouse == 0)
  55944. imageOffset = Point<int> (dragImage->getWidth() / -2,
  55945. dragImage->getHeight() / -2);
  55946. else
  55947. imageOffset = *imageOffsetFromMouse;
  55948. }
  55949. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  55950. draggingSource->getComponentUnderMouse(), this, imageOffset);
  55951. currentDragDesc = sourceDescription;
  55952. if (allowDraggingToExternalWindows)
  55953. {
  55954. if (! Desktop::canUseSemiTransparentWindows())
  55955. dragImageComponent->setOpaque (true);
  55956. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  55957. | ComponentPeer::windowIsTemporary
  55958. | ComponentPeer::windowIgnoresKeyPresses);
  55959. }
  55960. else
  55961. thisComp->addChildComponent (dragImageComponent);
  55962. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  55963. dragImageComponent->setVisible (true);
  55964. }
  55965. }
  55966. bool DragAndDropContainer::isDragAndDropActive() const
  55967. {
  55968. return dragImageComponent != 0;
  55969. }
  55970. const String DragAndDropContainer::getCurrentDragDescription() const
  55971. {
  55972. return (dragImageComponent != 0) ? currentDragDesc
  55973. : String::empty;
  55974. }
  55975. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  55976. {
  55977. if (c == 0)
  55978. return 0;
  55979. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  55980. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  55981. }
  55982. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  55983. {
  55984. return false;
  55985. }
  55986. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  55987. {
  55988. }
  55989. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  55990. {
  55991. }
  55992. void DragAndDropTarget::itemDragExit (const String&, Component*)
  55993. {
  55994. }
  55995. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  55996. {
  55997. return true;
  55998. }
  55999. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56000. {
  56001. }
  56002. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56003. {
  56004. }
  56005. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56006. {
  56007. }
  56008. END_JUCE_NAMESPACE
  56009. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56010. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56011. BEGIN_JUCE_NAMESPACE
  56012. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56013. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56014. // isStandard set depending on which interface was used to create the cursor
  56015. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56016. static CriticalSection activeCursorListLock;
  56017. static VoidArray activeCursors;
  56018. class SharedMouseCursorInternal : public ReferenceCountedObject
  56019. {
  56020. public:
  56021. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56022. : standardType (type),
  56023. isStandard (true)
  56024. {
  56025. handle = juce_createStandardMouseCursor (standardType);
  56026. activeCursors.add (this);
  56027. }
  56028. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56029. : standardType (MouseCursor::NormalCursor),
  56030. isStandard (false)
  56031. {
  56032. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56033. }
  56034. ~SharedMouseCursorInternal() throw()
  56035. {
  56036. juce_deleteMouseCursor (handle, isStandard);
  56037. activeCursors.removeValue (this);
  56038. }
  56039. void* getHandle() const throw()
  56040. {
  56041. return handle;
  56042. }
  56043. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56044. {
  56045. for (int i = activeCursors.size(); --i >= 0;)
  56046. {
  56047. SharedMouseCursorInternal* const r = static_cast <SharedMouseCursorInternal*> (activeCursors.getUnchecked(i));
  56048. if (r->standardType == type)
  56049. return r;
  56050. }
  56051. return new SharedMouseCursorInternal (type);
  56052. }
  56053. juce_UseDebuggingNewOperator
  56054. private:
  56055. void* handle;
  56056. const MouseCursor::StandardCursorType standardType;
  56057. const bool isStandard;
  56058. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56059. };
  56060. MouseCursor::MouseCursor() throw()
  56061. {
  56062. const ScopedLock sl (activeCursorListLock);
  56063. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56064. }
  56065. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56066. {
  56067. const ScopedLock sl (activeCursorListLock);
  56068. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56069. }
  56070. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56071. {
  56072. const ScopedLock sl (activeCursorListLock);
  56073. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56074. }
  56075. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56076. : cursorHandle (other.cursorHandle)
  56077. {
  56078. }
  56079. MouseCursor::~MouseCursor() throw()
  56080. {
  56081. }
  56082. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56083. {
  56084. cursorHandle = other.cursorHandle;
  56085. return *this;
  56086. }
  56087. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56088. {
  56089. return cursorHandle == other.cursorHandle;
  56090. }
  56091. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56092. {
  56093. return cursorHandle != other.cursorHandle;
  56094. }
  56095. void* MouseCursor::getHandle() const throw()
  56096. {
  56097. return cursorHandle->getHandle();
  56098. }
  56099. void MouseCursor::showWaitCursor() throw()
  56100. {
  56101. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56102. }
  56103. void MouseCursor::hideWaitCursor() throw()
  56104. {
  56105. Desktop::getInstance().getMainMouseSource().revealCursor();
  56106. }
  56107. END_JUCE_NAMESPACE
  56108. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56109. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56110. BEGIN_JUCE_NAMESPACE
  56111. MouseEvent::MouseEvent (MouseInputSource& source_,
  56112. const Point<int>& position,
  56113. const ModifierKeys& mods_,
  56114. Component* const originator,
  56115. const Time& eventTime_,
  56116. const Point<int> mouseDownPos_,
  56117. const Time& mouseDownTime_,
  56118. const int numberOfClicks_,
  56119. const bool mouseWasDragged) throw()
  56120. : x (position.getX()),
  56121. y (position.getY()),
  56122. mods (mods_),
  56123. eventComponent (originator),
  56124. originalComponent (originator),
  56125. eventTime (eventTime_),
  56126. source (source_),
  56127. mouseDownPos (mouseDownPos_),
  56128. mouseDownTime (mouseDownTime_),
  56129. numberOfClicks (numberOfClicks_),
  56130. wasMovedSinceMouseDown (mouseWasDragged)
  56131. {
  56132. }
  56133. MouseEvent::~MouseEvent() throw()
  56134. {
  56135. }
  56136. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56137. {
  56138. if (otherComponent == 0)
  56139. {
  56140. jassertfalse
  56141. return *this;
  56142. }
  56143. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56144. mods, originalComponent, eventTime,
  56145. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56146. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56147. }
  56148. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56149. {
  56150. return MouseEvent (source, newPosition, mods, originalComponent,
  56151. eventTime, mouseDownPos, mouseDownTime,
  56152. numberOfClicks, wasMovedSinceMouseDown);
  56153. }
  56154. bool MouseEvent::mouseWasClicked() const throw()
  56155. {
  56156. return ! wasMovedSinceMouseDown;
  56157. }
  56158. int MouseEvent::getMouseDownX() const throw()
  56159. {
  56160. return mouseDownPos.getX();
  56161. }
  56162. int MouseEvent::getMouseDownY() const throw()
  56163. {
  56164. return mouseDownPos.getY();
  56165. }
  56166. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56167. {
  56168. return mouseDownPos;
  56169. }
  56170. int MouseEvent::getDistanceFromDragStartX() const throw()
  56171. {
  56172. return x - mouseDownPos.getX();
  56173. }
  56174. int MouseEvent::getDistanceFromDragStartY() const throw()
  56175. {
  56176. return y - mouseDownPos.getY();
  56177. }
  56178. int MouseEvent::getDistanceFromDragStart() const throw()
  56179. {
  56180. return mouseDownPos.getDistanceFrom (getPosition());
  56181. }
  56182. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56183. {
  56184. return getPosition() - mouseDownPos;
  56185. }
  56186. int MouseEvent::getLengthOfMousePress() const throw()
  56187. {
  56188. if (mouseDownTime.toMilliseconds() > 0)
  56189. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56190. return 0;
  56191. }
  56192. const Point<int> MouseEvent::getPosition() const throw()
  56193. {
  56194. return Point<int> (x, y);
  56195. }
  56196. int MouseEvent::getScreenX() const
  56197. {
  56198. return getScreenPosition().getX();
  56199. }
  56200. int MouseEvent::getScreenY() const
  56201. {
  56202. return getScreenPosition().getY();
  56203. }
  56204. const Point<int> MouseEvent::getScreenPosition() const
  56205. {
  56206. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56207. }
  56208. int MouseEvent::getMouseDownScreenX() const
  56209. {
  56210. return getMouseDownScreenPosition().getX();
  56211. }
  56212. int MouseEvent::getMouseDownScreenY() const
  56213. {
  56214. return getMouseDownScreenPosition().getY();
  56215. }
  56216. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56217. {
  56218. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56219. }
  56220. static int doubleClickTimeOutMs = 400;
  56221. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56222. {
  56223. doubleClickTimeOutMs = newTime;
  56224. }
  56225. int MouseEvent::getDoubleClickTimeout() throw()
  56226. {
  56227. return doubleClickTimeOutMs;
  56228. }
  56229. END_JUCE_NAMESPACE
  56230. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56231. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56232. BEGIN_JUCE_NAMESPACE
  56233. class MouseInputSourceInternal : public AsyncUpdater
  56234. {
  56235. public:
  56236. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56237. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56238. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56239. {
  56240. zerostruct (mouseDowns);
  56241. }
  56242. ~MouseInputSourceInternal()
  56243. {
  56244. }
  56245. bool isDragging() const throw()
  56246. {
  56247. return buttonState.isAnyMouseButtonDown();
  56248. }
  56249. Component* getComponentUnderMouse() const
  56250. {
  56251. return static_cast <Component*> (componentUnderMouse);
  56252. }
  56253. const ModifierKeys getCurrentModifiers() const
  56254. {
  56255. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56256. }
  56257. ComponentPeer* getPeer()
  56258. {
  56259. if (! ComponentPeer::isValidPeer (lastPeer))
  56260. lastPeer = 0;
  56261. return lastPeer;
  56262. }
  56263. Component* findComponentAt (const Point<int>& screenPos)
  56264. {
  56265. ComponentPeer* const peer = getPeer();
  56266. if (peer != 0)
  56267. {
  56268. Component* const comp = peer->getComponent();
  56269. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56270. // (the contains() call is needed to test for overlapping desktop windows)
  56271. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56272. return comp->getComponentAt (relativePos);
  56273. }
  56274. return 0;
  56275. }
  56276. const Point<int> getScreenPosition() const throw()
  56277. {
  56278. return lastScreenPos + unboundedMouseOffset;
  56279. }
  56280. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56281. {
  56282. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56283. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56284. }
  56285. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56286. {
  56287. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56288. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56289. }
  56290. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56291. {
  56292. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56293. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56294. }
  56295. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56296. {
  56297. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56298. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56299. }
  56300. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56301. {
  56302. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56303. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56304. }
  56305. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56306. {
  56307. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56308. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56309. }
  56310. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56311. {
  56312. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56313. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56314. }
  56315. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56316. {
  56317. if (buttonState != newButtonState)
  56318. {
  56319. // (ignore secondary clicks when there's already a button down)
  56320. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56321. {
  56322. buttonState = newButtonState;
  56323. return;
  56324. }
  56325. if (buttonState.isAnyMouseButtonDown())
  56326. {
  56327. Component* const current = getComponentUnderMouse();
  56328. if (current != 0)
  56329. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56330. enableUnboundedMouseMovement (false, false);
  56331. }
  56332. buttonState = newButtonState;
  56333. if (buttonState.isAnyMouseButtonDown())
  56334. {
  56335. Desktop::getInstance().incrementMouseClickCounter();
  56336. Component* const current = getComponentUnderMouse();
  56337. if (current != 0)
  56338. {
  56339. registerMouseDown (screenPos, time, current);
  56340. sendMouseDown (current, screenPos, time);
  56341. }
  56342. }
  56343. }
  56344. }
  56345. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56346. {
  56347. Component* current = getComponentUnderMouse();
  56348. if (newComponent != current)
  56349. {
  56350. Component::SafePointer<Component> safeNewComp (newComponent);
  56351. const ModifierKeys originalButtonState (buttonState);
  56352. if (current != 0)
  56353. {
  56354. setButtons (screenPos, time, ModifierKeys());
  56355. sendMouseExit (current, screenPos, time);
  56356. buttonState = originalButtonState;
  56357. }
  56358. componentUnderMouse = safeNewComp;
  56359. current = getComponentUnderMouse();
  56360. if (current != 0)
  56361. sendMouseEnter (current, screenPos, time);
  56362. revealCursor (false);
  56363. setButtons (screenPos, time, originalButtonState);
  56364. }
  56365. }
  56366. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56367. {
  56368. ModifierKeys::updateCurrentModifiers();
  56369. if (newPeer != lastPeer)
  56370. {
  56371. setComponentUnderMouse (0, screenPos, time);
  56372. lastPeer = newPeer;
  56373. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56374. }
  56375. }
  56376. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56377. {
  56378. if (! isDragging())
  56379. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56380. if (newScreenPos != lastScreenPos || forceUpdate)
  56381. {
  56382. cancelPendingUpdate();
  56383. lastScreenPos = newScreenPos;
  56384. Component* const current = getComponentUnderMouse();
  56385. if (current != 0)
  56386. {
  56387. if (isDragging())
  56388. {
  56389. registerMouseDrag (newScreenPos);
  56390. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56391. if (isUnboundedMouseModeOn)
  56392. handleUnboundedDrag (current);
  56393. }
  56394. else
  56395. {
  56396. sendMouseMove (current, newScreenPos, time);
  56397. }
  56398. }
  56399. revealCursor (false);
  56400. }
  56401. }
  56402. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56403. {
  56404. jassert (newPeer != 0);
  56405. lastTime = time;
  56406. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56407. if (isDragging() && newMods.isAnyMouseButtonDown())
  56408. {
  56409. setScreenPos (screenPos, time, false);
  56410. }
  56411. else
  56412. {
  56413. setPeer (newPeer, screenPos, time);
  56414. ComponentPeer* peer = getPeer();
  56415. if (peer != 0)
  56416. {
  56417. setButtons (screenPos, time, newMods);
  56418. peer = getPeer();
  56419. if (peer != 0)
  56420. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56421. }
  56422. }
  56423. }
  56424. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56425. {
  56426. jassert (peer != 0);
  56427. lastTime = time;
  56428. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56429. setPeer (peer, screenPos, time);
  56430. setScreenPos (screenPos, time, false);
  56431. triggerFakeMove();
  56432. if (! isDragging())
  56433. {
  56434. Component* current = getComponentUnderMouse();
  56435. if (current != 0)
  56436. sendMouseWheel (current, screenPos, time, x, y);
  56437. }
  56438. }
  56439. const Time getLastMouseDownTime() const throw()
  56440. {
  56441. return Time (mouseDowns[0].time);
  56442. }
  56443. const Point<int> getLastMouseDownPosition() const throw()
  56444. {
  56445. return mouseDowns[0].position;
  56446. }
  56447. int getNumberOfMultipleClicks() const throw()
  56448. {
  56449. int numClicks = 0;
  56450. if (mouseDowns[0].time != 0)
  56451. {
  56452. if (! mouseMovedSignificantlySincePressed)
  56453. ++numClicks;
  56454. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56455. {
  56456. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56457. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56458. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56459. && mouseDowns[0].component == mouseDowns[i].component)
  56460. {
  56461. ++numClicks;
  56462. }
  56463. else
  56464. {
  56465. break;
  56466. }
  56467. }
  56468. }
  56469. return numClicks;
  56470. }
  56471. bool hasMouseMovedSignificantlySincePressed() const throw()
  56472. {
  56473. return mouseMovedSignificantlySincePressed
  56474. || lastTime > mouseDowns[0].time + 300;
  56475. }
  56476. void triggerFakeMove()
  56477. {
  56478. triggerAsyncUpdate();
  56479. }
  56480. void handleAsyncUpdate()
  56481. {
  56482. if (! isDragging())
  56483. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56484. }
  56485. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56486. {
  56487. enable = enable && isDragging();
  56488. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56489. if (enable != isUnboundedMouseModeOn)
  56490. {
  56491. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56492. {
  56493. // when released, return the mouse to within the component's bounds
  56494. Component* current = getComponentUnderMouse();
  56495. if (current != 0)
  56496. Desktop::setMousePosition (current->getScreenBounds()
  56497. .getConstrainedPoint (current->getMouseXYRelative()));
  56498. }
  56499. isUnboundedMouseModeOn = enable;
  56500. unboundedMouseOffset = Point<int>();
  56501. revealCursor (true);
  56502. }
  56503. }
  56504. void handleUnboundedDrag (Component* current)
  56505. {
  56506. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56507. if (! screenArea.contains (lastScreenPos))
  56508. {
  56509. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56510. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56511. Desktop::setMousePosition (componentCentre);
  56512. }
  56513. else if (isCursorVisibleUntilOffscreen
  56514. && (! unboundedMouseOffset.isOrigin())
  56515. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56516. {
  56517. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56518. unboundedMouseOffset = Point<int>();
  56519. }
  56520. }
  56521. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56522. {
  56523. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56524. {
  56525. cursor = MouseCursor::NoCursor;
  56526. forcedUpdate = true;
  56527. }
  56528. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56529. {
  56530. currentCursorHandle = cursor.getHandle();
  56531. cursor.showInWindow (getPeer());
  56532. }
  56533. }
  56534. void hideCursor()
  56535. {
  56536. showMouseCursor (MouseCursor::NoCursor, true);
  56537. }
  56538. void revealCursor (bool forcedUpdate)
  56539. {
  56540. MouseCursor mc (MouseCursor::NormalCursor);
  56541. Component* current = getComponentUnderMouse();
  56542. if (current != 0)
  56543. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56544. showMouseCursor (mc, forcedUpdate);
  56545. }
  56546. int index;
  56547. bool isMouseDevice;
  56548. Point<int> lastScreenPos;
  56549. ModifierKeys buttonState;
  56550. private:
  56551. MouseInputSource& source;
  56552. Component::SafePointer<Component> componentUnderMouse;
  56553. ComponentPeer* lastPeer;
  56554. Point<int> unboundedMouseOffset;
  56555. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56556. void* currentCursorHandle;
  56557. struct RecentMouseDown
  56558. {
  56559. Point<int> position;
  56560. int64 time;
  56561. Component* component;
  56562. };
  56563. RecentMouseDown mouseDowns[4];
  56564. bool mouseMovedSignificantlySincePressed;
  56565. int64 lastTime;
  56566. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56567. {
  56568. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56569. mouseDowns[i] = mouseDowns[i - 1];
  56570. mouseDowns[0].position = screenPos;
  56571. mouseDowns[0].time = time;
  56572. mouseDowns[0].component = component;
  56573. mouseMovedSignificantlySincePressed = false;
  56574. }
  56575. void registerMouseDrag (const Point<int>& screenPos) throw()
  56576. {
  56577. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56578. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56579. }
  56580. MouseInputSourceInternal (const MouseInputSourceInternal&);
  56581. MouseInputSourceInternal& operator= (const MouseInputSourceInternal&);
  56582. };
  56583. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56584. {
  56585. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56586. }
  56587. MouseInputSource::~MouseInputSource()
  56588. {
  56589. }
  56590. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56591. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56592. bool MouseInputSource::canHover() const { return isMouse(); }
  56593. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56594. int MouseInputSource::getIndex() const { return pimpl->index; }
  56595. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56596. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56597. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56598. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56599. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56600. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56601. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56602. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56603. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56604. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56605. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56606. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56607. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56608. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56609. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56610. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56611. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56612. {
  56613. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56614. }
  56615. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56616. {
  56617. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56618. }
  56619. END_JUCE_NAMESPACE
  56620. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56621. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56622. BEGIN_JUCE_NAMESPACE
  56623. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56624. : source (0),
  56625. hoverTimeMillisecs (hoverTimeMillisecs_),
  56626. hasJustHovered (false)
  56627. {
  56628. internalTimer.owner = this;
  56629. }
  56630. MouseHoverDetector::~MouseHoverDetector()
  56631. {
  56632. setHoverComponent (0);
  56633. }
  56634. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56635. {
  56636. hoverTimeMillisecs = newTimeInMillisecs;
  56637. }
  56638. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56639. {
  56640. if (source != newSourceComponent)
  56641. {
  56642. internalTimer.stopTimer();
  56643. hasJustHovered = false;
  56644. if (source != 0)
  56645. {
  56646. // ! you need to delete the hover detector before deleting its component
  56647. jassert (source->isValidComponent());
  56648. source->removeMouseListener (&internalTimer);
  56649. }
  56650. source = newSourceComponent;
  56651. if (newSourceComponent != 0)
  56652. newSourceComponent->addMouseListener (&internalTimer, false);
  56653. }
  56654. }
  56655. void MouseHoverDetector::hoverTimerCallback()
  56656. {
  56657. internalTimer.stopTimer();
  56658. if (source != 0)
  56659. {
  56660. const Point<int> pos (source->getMouseXYRelative());
  56661. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56662. {
  56663. hasJustHovered = true;
  56664. mouseHovered (pos.getX(), pos.getY());
  56665. }
  56666. }
  56667. }
  56668. void MouseHoverDetector::checkJustHoveredCallback()
  56669. {
  56670. if (hasJustHovered)
  56671. {
  56672. hasJustHovered = false;
  56673. mouseMovedAfterHover();
  56674. }
  56675. }
  56676. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56677. {
  56678. owner->hoverTimerCallback();
  56679. }
  56680. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56681. {
  56682. stopTimer();
  56683. owner->checkJustHoveredCallback();
  56684. }
  56685. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56686. {
  56687. stopTimer();
  56688. owner->checkJustHoveredCallback();
  56689. }
  56690. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56691. {
  56692. stopTimer();
  56693. owner->checkJustHoveredCallback();
  56694. }
  56695. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56696. {
  56697. stopTimer();
  56698. owner->checkJustHoveredCallback();
  56699. }
  56700. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56701. {
  56702. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56703. {
  56704. lastX = e.x;
  56705. lastY = e.y;
  56706. if (owner->source != 0)
  56707. startTimer (owner->hoverTimeMillisecs);
  56708. owner->checkJustHoveredCallback();
  56709. }
  56710. }
  56711. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56712. {
  56713. stopTimer();
  56714. owner->checkJustHoveredCallback();
  56715. }
  56716. END_JUCE_NAMESPACE
  56717. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56718. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56719. BEGIN_JUCE_NAMESPACE
  56720. void MouseListener::mouseEnter (const MouseEvent&)
  56721. {
  56722. }
  56723. void MouseListener::mouseExit (const MouseEvent&)
  56724. {
  56725. }
  56726. void MouseListener::mouseDown (const MouseEvent&)
  56727. {
  56728. }
  56729. void MouseListener::mouseUp (const MouseEvent&)
  56730. {
  56731. }
  56732. void MouseListener::mouseDrag (const MouseEvent&)
  56733. {
  56734. }
  56735. void MouseListener::mouseMove (const MouseEvent&)
  56736. {
  56737. }
  56738. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56739. {
  56740. }
  56741. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56742. {
  56743. }
  56744. END_JUCE_NAMESPACE
  56745. /*** End of inlined file: juce_MouseListener.cpp ***/
  56746. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56747. BEGIN_JUCE_NAMESPACE
  56748. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56749. const String& buttonTextWhenTrue,
  56750. const String& buttonTextWhenFalse)
  56751. : PropertyComponent (name),
  56752. onText (buttonTextWhenTrue),
  56753. offText (buttonTextWhenFalse)
  56754. {
  56755. createButton();
  56756. button->addButtonListener (this);
  56757. }
  56758. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56759. const String& name,
  56760. const String& buttonText)
  56761. : PropertyComponent (name),
  56762. onText (buttonText),
  56763. offText (buttonText)
  56764. {
  56765. createButton();
  56766. button->setButtonText (buttonText);
  56767. button->getToggleStateValue().referTo (valueToControl);
  56768. button->setClickingTogglesState (true);
  56769. }
  56770. BooleanPropertyComponent::~BooleanPropertyComponent()
  56771. {
  56772. deleteAllChildren();
  56773. }
  56774. void BooleanPropertyComponent::createButton()
  56775. {
  56776. addAndMakeVisible (button = new ToggleButton (String::empty));
  56777. button->setClickingTogglesState (false);
  56778. }
  56779. void BooleanPropertyComponent::setState (const bool newState)
  56780. {
  56781. button->setToggleState (newState, true);
  56782. }
  56783. bool BooleanPropertyComponent::getState() const
  56784. {
  56785. return button->getToggleState();
  56786. }
  56787. void BooleanPropertyComponent::paint (Graphics& g)
  56788. {
  56789. PropertyComponent::paint (g);
  56790. const Rectangle<int> r (button->getBounds());
  56791. g.setColour (Colours::white);
  56792. g.fillRect (r);
  56793. g.setColour (findColour (ComboBox::outlineColourId));
  56794. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56795. }
  56796. void BooleanPropertyComponent::refresh()
  56797. {
  56798. button->setToggleState (getState(), false);
  56799. button->setButtonText (button->getToggleState() ? onText : offText);
  56800. }
  56801. void BooleanPropertyComponent::buttonClicked (Button*)
  56802. {
  56803. setState (! getState());
  56804. }
  56805. END_JUCE_NAMESPACE
  56806. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56807. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56808. BEGIN_JUCE_NAMESPACE
  56809. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56810. const bool triggerOnMouseDown)
  56811. : PropertyComponent (name)
  56812. {
  56813. addAndMakeVisible (button = new TextButton (String::empty));
  56814. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56815. button->addButtonListener (this);
  56816. }
  56817. ButtonPropertyComponent::~ButtonPropertyComponent()
  56818. {
  56819. deleteAllChildren();
  56820. }
  56821. void ButtonPropertyComponent::refresh()
  56822. {
  56823. button->setButtonText (getButtonText());
  56824. }
  56825. void ButtonPropertyComponent::buttonClicked (Button*)
  56826. {
  56827. buttonClicked();
  56828. }
  56829. END_JUCE_NAMESPACE
  56830. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56831. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56832. BEGIN_JUCE_NAMESPACE
  56833. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56834. : PropertyComponent (name),
  56835. comboBox (0)
  56836. {
  56837. }
  56838. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56839. const String& name,
  56840. const StringArray& choices_,
  56841. const Array <int>* choiceIDs)
  56842. : PropertyComponent (name),
  56843. choices (choices_),
  56844. comboBox (0)
  56845. {
  56846. createComboBox (choiceIDs);
  56847. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56848. }
  56849. ChoicePropertyComponent::~ChoicePropertyComponent()
  56850. {
  56851. deleteAllChildren();
  56852. }
  56853. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56854. {
  56855. // The array of IDs must contain the same number of values as the choices list!
  56856. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56857. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56858. for (int i = 0; i < choices.size(); ++i)
  56859. {
  56860. if (choices[i].isNotEmpty())
  56861. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56862. : ((*choiceIDs)[i]));
  56863. else
  56864. comboBox->addSeparator();
  56865. }
  56866. comboBox->setEditableText (false);
  56867. }
  56868. void ChoicePropertyComponent::setIndex (const int newIndex)
  56869. {
  56870. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56871. }
  56872. int ChoicePropertyComponent::getIndex() const
  56873. {
  56874. return comboBox->getSelectedItemIndex();
  56875. }
  56876. const StringArray& ChoicePropertyComponent::getChoices() const
  56877. {
  56878. return choices;
  56879. }
  56880. void ChoicePropertyComponent::refresh()
  56881. {
  56882. if (comboBox == 0)
  56883. {
  56884. createComboBox (0);
  56885. comboBox->addListener (this);
  56886. }
  56887. comboBox->setSelectedId (getIndex() + 1, true);
  56888. }
  56889. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  56890. {
  56891. const int newIndex = comboBox->getSelectedId() - 1;
  56892. if (newIndex != getIndex())
  56893. setIndex (newIndex);
  56894. }
  56895. END_JUCE_NAMESPACE
  56896. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56897. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  56898. BEGIN_JUCE_NAMESPACE
  56899. PropertyComponent::PropertyComponent (const String& name,
  56900. const int preferredHeight_)
  56901. : Component (name),
  56902. preferredHeight (preferredHeight_)
  56903. {
  56904. jassert (name.isNotEmpty());
  56905. }
  56906. PropertyComponent::~PropertyComponent()
  56907. {
  56908. }
  56909. void PropertyComponent::paint (Graphics& g)
  56910. {
  56911. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  56912. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  56913. }
  56914. void PropertyComponent::resized()
  56915. {
  56916. if (getNumChildComponents() > 0)
  56917. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  56918. }
  56919. void PropertyComponent::enablementChanged()
  56920. {
  56921. repaint();
  56922. }
  56923. END_JUCE_NAMESPACE
  56924. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  56925. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  56926. BEGIN_JUCE_NAMESPACE
  56927. class PropertyPanel::PropertyHolderComponent : public Component
  56928. {
  56929. public:
  56930. PropertyHolderComponent()
  56931. {
  56932. }
  56933. ~PropertyHolderComponent()
  56934. {
  56935. deleteAllChildren();
  56936. }
  56937. void paint (Graphics&)
  56938. {
  56939. }
  56940. void updateLayout (int width);
  56941. void refreshAll() const;
  56942. private:
  56943. PropertyHolderComponent (const PropertyHolderComponent&);
  56944. PropertyHolderComponent& operator= (const PropertyHolderComponent&);
  56945. };
  56946. class PropertySectionComponent : public Component
  56947. {
  56948. public:
  56949. PropertySectionComponent (const String& sectionTitle,
  56950. const Array <PropertyComponent*>& newProperties,
  56951. const bool open)
  56952. : Component (sectionTitle),
  56953. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  56954. isOpen_ (open)
  56955. {
  56956. for (int i = newProperties.size(); --i >= 0;)
  56957. {
  56958. addAndMakeVisible (newProperties.getUnchecked(i));
  56959. newProperties.getUnchecked(i)->refresh();
  56960. }
  56961. }
  56962. ~PropertySectionComponent()
  56963. {
  56964. deleteAllChildren();
  56965. }
  56966. void paint (Graphics& g)
  56967. {
  56968. if (titleHeight > 0)
  56969. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  56970. }
  56971. void resized()
  56972. {
  56973. int y = titleHeight;
  56974. for (int i = getNumChildComponents(); --i >= 0;)
  56975. {
  56976. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  56977. if (pec != 0)
  56978. {
  56979. const int prefH = pec->getPreferredHeight();
  56980. pec->setBounds (1, y, getWidth() - 2, prefH);
  56981. y += prefH;
  56982. }
  56983. }
  56984. }
  56985. int getPreferredHeight() const
  56986. {
  56987. int y = titleHeight;
  56988. if (isOpen())
  56989. {
  56990. for (int i = 0; i < getNumChildComponents(); ++i)
  56991. {
  56992. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  56993. if (pec != 0)
  56994. y += pec->getPreferredHeight();
  56995. }
  56996. }
  56997. return y;
  56998. }
  56999. void setOpen (const bool open)
  57000. {
  57001. if (isOpen_ != open)
  57002. {
  57003. isOpen_ = open;
  57004. for (int i = 0; i < getNumChildComponents(); ++i)
  57005. {
  57006. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57007. if (pec != 0)
  57008. pec->setVisible (open);
  57009. }
  57010. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57011. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57012. if (pp != 0)
  57013. pp->resized();
  57014. }
  57015. }
  57016. bool isOpen() const
  57017. {
  57018. return isOpen_;
  57019. }
  57020. void refreshAll() const
  57021. {
  57022. for (int i = 0; i < getNumChildComponents(); ++i)
  57023. {
  57024. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57025. if (pec != 0)
  57026. pec->refresh();
  57027. }
  57028. }
  57029. void mouseDown (const MouseEvent&)
  57030. {
  57031. }
  57032. void mouseUp (const MouseEvent& e)
  57033. {
  57034. if (e.getMouseDownX() < titleHeight
  57035. && e.x < titleHeight
  57036. && e.y < titleHeight
  57037. && e.getNumberOfClicks() != 2)
  57038. {
  57039. setOpen (! isOpen());
  57040. }
  57041. }
  57042. void mouseDoubleClick (const MouseEvent& e)
  57043. {
  57044. if (e.y < titleHeight)
  57045. setOpen (! isOpen());
  57046. }
  57047. private:
  57048. int titleHeight;
  57049. bool isOpen_;
  57050. PropertySectionComponent (const PropertySectionComponent&);
  57051. PropertySectionComponent& operator= (const PropertySectionComponent&);
  57052. };
  57053. void PropertyPanel::PropertyHolderComponent::updateLayout (const int width)
  57054. {
  57055. int y = 0;
  57056. for (int i = getNumChildComponents(); --i >= 0;)
  57057. {
  57058. PropertySectionComponent* const section
  57059. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57060. if (section != 0)
  57061. {
  57062. const int prefH = section->getPreferredHeight();
  57063. section->setBounds (0, y, width, prefH);
  57064. y += prefH;
  57065. }
  57066. }
  57067. setSize (width, y);
  57068. repaint();
  57069. }
  57070. void PropertyPanel::PropertyHolderComponent::refreshAll() const
  57071. {
  57072. for (int i = getNumChildComponents(); --i >= 0;)
  57073. {
  57074. PropertySectionComponent* const section
  57075. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57076. if (section != 0)
  57077. section->refreshAll();
  57078. }
  57079. }
  57080. PropertyPanel::PropertyPanel()
  57081. {
  57082. messageWhenEmpty = TRANS("(nothing selected)");
  57083. addAndMakeVisible (viewport = new Viewport());
  57084. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57085. viewport->setFocusContainer (true);
  57086. }
  57087. PropertyPanel::~PropertyPanel()
  57088. {
  57089. clear();
  57090. deleteAllChildren();
  57091. }
  57092. void PropertyPanel::paint (Graphics& g)
  57093. {
  57094. if (propertyHolderComponent->getNumChildComponents() == 0)
  57095. {
  57096. g.setColour (Colours::black.withAlpha (0.5f));
  57097. g.setFont (14.0f);
  57098. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57099. Justification::centred, true);
  57100. }
  57101. }
  57102. void PropertyPanel::resized()
  57103. {
  57104. viewport->setBounds (0, 0, getWidth(), getHeight());
  57105. updatePropHolderLayout();
  57106. }
  57107. void PropertyPanel::clear()
  57108. {
  57109. if (propertyHolderComponent->getNumChildComponents() > 0)
  57110. {
  57111. propertyHolderComponent->deleteAllChildren();
  57112. repaint();
  57113. }
  57114. }
  57115. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57116. {
  57117. if (propertyHolderComponent->getNumChildComponents() == 0)
  57118. repaint();
  57119. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57120. newProperties,
  57121. true), 0);
  57122. updatePropHolderLayout();
  57123. }
  57124. void PropertyPanel::addSection (const String& sectionTitle,
  57125. const Array <PropertyComponent*>& newProperties,
  57126. const bool shouldBeOpen)
  57127. {
  57128. jassert (sectionTitle.isNotEmpty());
  57129. if (propertyHolderComponent->getNumChildComponents() == 0)
  57130. repaint();
  57131. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57132. newProperties,
  57133. shouldBeOpen), 0);
  57134. updatePropHolderLayout();
  57135. }
  57136. void PropertyPanel::updatePropHolderLayout() const
  57137. {
  57138. const int maxWidth = viewport->getMaximumVisibleWidth();
  57139. propertyHolderComponent->updateLayout (maxWidth);
  57140. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57141. if (maxWidth != newMaxWidth)
  57142. {
  57143. // need to do this twice because of scrollbars changing the size, etc.
  57144. propertyHolderComponent->updateLayout (newMaxWidth);
  57145. }
  57146. }
  57147. void PropertyPanel::refreshAll() const
  57148. {
  57149. propertyHolderComponent->refreshAll();
  57150. }
  57151. const StringArray PropertyPanel::getSectionNames() const
  57152. {
  57153. StringArray s;
  57154. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57155. {
  57156. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57157. if (section != 0 && section->getName().isNotEmpty())
  57158. s.add (section->getName());
  57159. }
  57160. return s;
  57161. }
  57162. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57163. {
  57164. int index = 0;
  57165. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57166. {
  57167. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57168. if (section != 0 && section->getName().isNotEmpty())
  57169. {
  57170. if (index == sectionIndex)
  57171. return section->isOpen();
  57172. ++index;
  57173. }
  57174. }
  57175. return false;
  57176. }
  57177. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57178. {
  57179. int index = 0;
  57180. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57181. {
  57182. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57183. if (section != 0 && section->getName().isNotEmpty())
  57184. {
  57185. if (index == sectionIndex)
  57186. {
  57187. section->setOpen (shouldBeOpen);
  57188. break;
  57189. }
  57190. ++index;
  57191. }
  57192. }
  57193. }
  57194. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57195. {
  57196. int index = 0;
  57197. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57198. {
  57199. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57200. if (section != 0 && section->getName().isNotEmpty())
  57201. {
  57202. if (index == sectionIndex)
  57203. {
  57204. section->setEnabled (shouldBeEnabled);
  57205. break;
  57206. }
  57207. ++index;
  57208. }
  57209. }
  57210. }
  57211. XmlElement* PropertyPanel::getOpennessState() const
  57212. {
  57213. XmlElement* const xml = new XmlElement ("PROPERTYPANELSTATE");
  57214. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57215. const StringArray sections (getSectionNames());
  57216. for (int i = 0; i < sections.size(); ++i)
  57217. {
  57218. if (sections[i].isNotEmpty())
  57219. {
  57220. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57221. e->setAttribute ("name", sections[i]);
  57222. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57223. }
  57224. }
  57225. return xml;
  57226. }
  57227. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57228. {
  57229. if (xml.hasTagName ("PROPERTYPANELSTATE"))
  57230. {
  57231. const StringArray sections (getSectionNames());
  57232. forEachXmlChildElementWithTagName (xml, e, "SECTION")
  57233. {
  57234. setSectionOpen (sections.indexOf (e->getStringAttribute ("name")),
  57235. e->getBoolAttribute ("open"));
  57236. }
  57237. viewport->setViewPosition (viewport->getViewPositionX(),
  57238. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57239. }
  57240. }
  57241. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57242. {
  57243. if (messageWhenEmpty != newMessage)
  57244. {
  57245. messageWhenEmpty = newMessage;
  57246. repaint();
  57247. }
  57248. }
  57249. const String& PropertyPanel::getMessageWhenEmpty() const
  57250. {
  57251. return messageWhenEmpty;
  57252. }
  57253. END_JUCE_NAMESPACE
  57254. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57255. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57256. BEGIN_JUCE_NAMESPACE
  57257. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57258. const double rangeMin,
  57259. const double rangeMax,
  57260. const double interval,
  57261. const double skewFactor)
  57262. : PropertyComponent (name)
  57263. {
  57264. addAndMakeVisible (slider = new Slider (name));
  57265. slider->setRange (rangeMin, rangeMax, interval);
  57266. slider->setSkewFactor (skewFactor);
  57267. slider->setSliderStyle (Slider::LinearBar);
  57268. slider->addListener (this);
  57269. }
  57270. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57271. const String& name,
  57272. const double rangeMin,
  57273. const double rangeMax,
  57274. const double interval,
  57275. const double skewFactor)
  57276. : PropertyComponent (name)
  57277. {
  57278. addAndMakeVisible (slider = new Slider (name));
  57279. slider->setRange (rangeMin, rangeMax, interval);
  57280. slider->setSkewFactor (skewFactor);
  57281. slider->setSliderStyle (Slider::LinearBar);
  57282. slider->getValueObject().referTo (valueToControl);
  57283. }
  57284. SliderPropertyComponent::~SliderPropertyComponent()
  57285. {
  57286. deleteAllChildren();
  57287. }
  57288. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57289. {
  57290. }
  57291. double SliderPropertyComponent::getValue() const
  57292. {
  57293. return slider->getValue();
  57294. }
  57295. void SliderPropertyComponent::refresh()
  57296. {
  57297. slider->setValue (getValue(), false);
  57298. }
  57299. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57300. {
  57301. if (getValue() != slider->getValue())
  57302. setValue (slider->getValue());
  57303. }
  57304. END_JUCE_NAMESPACE
  57305. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57306. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57307. BEGIN_JUCE_NAMESPACE
  57308. class TextPropLabel : public Label
  57309. {
  57310. TextPropertyComponent& owner;
  57311. int maxChars;
  57312. bool isMultiline;
  57313. public:
  57314. TextPropLabel (TextPropertyComponent& owner_,
  57315. const int maxChars_, const bool isMultiline_)
  57316. : Label (String::empty, String::empty),
  57317. owner (owner_),
  57318. maxChars (maxChars_),
  57319. isMultiline (isMultiline_)
  57320. {
  57321. setEditable (true, true, false);
  57322. setColour (backgroundColourId, Colours::white);
  57323. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57324. }
  57325. ~TextPropLabel()
  57326. {
  57327. }
  57328. TextEditor* createEditorComponent()
  57329. {
  57330. TextEditor* const textEditor = Label::createEditorComponent();
  57331. textEditor->setInputRestrictions (maxChars);
  57332. if (isMultiline)
  57333. {
  57334. textEditor->setMultiLine (true, true);
  57335. textEditor->setReturnKeyStartsNewLine (true);
  57336. }
  57337. return textEditor;
  57338. }
  57339. void textWasEdited()
  57340. {
  57341. owner.textWasEdited();
  57342. }
  57343. };
  57344. TextPropertyComponent::TextPropertyComponent (const String& name,
  57345. const int maxNumChars,
  57346. const bool isMultiLine)
  57347. : PropertyComponent (name)
  57348. {
  57349. createEditor (maxNumChars, isMultiLine);
  57350. }
  57351. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57352. const String& name,
  57353. const int maxNumChars,
  57354. const bool isMultiLine)
  57355. : PropertyComponent (name)
  57356. {
  57357. createEditor (maxNumChars, isMultiLine);
  57358. textEditor->getTextValue().referTo (valueToControl);
  57359. }
  57360. TextPropertyComponent::~TextPropertyComponent()
  57361. {
  57362. deleteAllChildren();
  57363. }
  57364. void TextPropertyComponent::setText (const String& newText)
  57365. {
  57366. textEditor->setText (newText, true);
  57367. }
  57368. const String TextPropertyComponent::getText() const
  57369. {
  57370. return textEditor->getText();
  57371. }
  57372. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57373. {
  57374. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57375. if (isMultiLine)
  57376. {
  57377. textEditor->setJustificationType (Justification::topLeft);
  57378. preferredHeight = 120;
  57379. }
  57380. }
  57381. void TextPropertyComponent::refresh()
  57382. {
  57383. textEditor->setText (getText(), false);
  57384. }
  57385. void TextPropertyComponent::textWasEdited()
  57386. {
  57387. const String newText (textEditor->getText());
  57388. if (getText() != newText)
  57389. setText (newText);
  57390. }
  57391. END_JUCE_NAMESPACE
  57392. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57393. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57394. BEGIN_JUCE_NAMESPACE
  57395. class SimpleDeviceManagerInputLevelMeter : public Component,
  57396. public Timer
  57397. {
  57398. public:
  57399. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57400. : manager (manager_),
  57401. level (0)
  57402. {
  57403. startTimer (50);
  57404. manager->enableInputLevelMeasurement (true);
  57405. }
  57406. ~SimpleDeviceManagerInputLevelMeter()
  57407. {
  57408. manager->enableInputLevelMeasurement (false);
  57409. }
  57410. void timerCallback()
  57411. {
  57412. const float newLevel = (float) manager->getCurrentInputLevel();
  57413. if (fabsf (level - newLevel) > 0.005f)
  57414. {
  57415. level = newLevel;
  57416. repaint();
  57417. }
  57418. }
  57419. void paint (Graphics& g)
  57420. {
  57421. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57422. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57423. }
  57424. private:
  57425. AudioDeviceManager* const manager;
  57426. float level;
  57427. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57428. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57429. };
  57430. class MidiInputSelectorComponentListBox : public ListBox,
  57431. public ListBoxModel
  57432. {
  57433. public:
  57434. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57435. const String& noItemsMessage_,
  57436. const int minNumber_,
  57437. const int maxNumber_)
  57438. : ListBox (String::empty, 0),
  57439. deviceManager (deviceManager_),
  57440. noItemsMessage (noItemsMessage_),
  57441. minNumber (minNumber_),
  57442. maxNumber (maxNumber_)
  57443. {
  57444. items = MidiInput::getDevices();
  57445. setModel (this);
  57446. setOutlineThickness (1);
  57447. }
  57448. ~MidiInputSelectorComponentListBox()
  57449. {
  57450. }
  57451. int getNumRows()
  57452. {
  57453. return items.size();
  57454. }
  57455. void paintListBoxItem (int row,
  57456. Graphics& g,
  57457. int width, int height,
  57458. bool rowIsSelected)
  57459. {
  57460. if (((unsigned int) row) < (unsigned int) items.size())
  57461. {
  57462. if (rowIsSelected)
  57463. g.fillAll (findColour (TextEditor::highlightColourId)
  57464. .withMultipliedAlpha (0.3f));
  57465. const String item (items [row]);
  57466. bool enabled = deviceManager.isMidiInputEnabled (item);
  57467. const int x = getTickX();
  57468. const float tickW = height * 0.75f;
  57469. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57470. enabled, true, true, false);
  57471. g.setFont (height * 0.6f);
  57472. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57473. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57474. }
  57475. }
  57476. void listBoxItemClicked (int row, const MouseEvent& e)
  57477. {
  57478. selectRow (row);
  57479. if (e.x < getTickX())
  57480. flipEnablement (row);
  57481. }
  57482. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57483. {
  57484. flipEnablement (row);
  57485. }
  57486. void returnKeyPressed (int row)
  57487. {
  57488. flipEnablement (row);
  57489. }
  57490. void paint (Graphics& g)
  57491. {
  57492. ListBox::paint (g);
  57493. if (items.size() == 0)
  57494. {
  57495. g.setColour (Colours::grey);
  57496. g.setFont (13.0f);
  57497. g.drawText (noItemsMessage,
  57498. 0, 0, getWidth(), getHeight() / 2,
  57499. Justification::centred, true);
  57500. }
  57501. }
  57502. int getBestHeight (const int preferredHeight)
  57503. {
  57504. const int extra = getOutlineThickness() * 2;
  57505. return jmax (getRowHeight() * 2 + extra,
  57506. jmin (getRowHeight() * getNumRows() + extra,
  57507. preferredHeight));
  57508. }
  57509. juce_UseDebuggingNewOperator
  57510. private:
  57511. AudioDeviceManager& deviceManager;
  57512. const String noItemsMessage;
  57513. StringArray items;
  57514. int minNumber, maxNumber;
  57515. void flipEnablement (const int row)
  57516. {
  57517. if (((unsigned int) row) < (unsigned int) items.size())
  57518. {
  57519. const String item (items [row]);
  57520. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57521. }
  57522. }
  57523. int getTickX() const
  57524. {
  57525. return getRowHeight() + 5;
  57526. }
  57527. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57528. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57529. };
  57530. class AudioDeviceSettingsPanel : public Component,
  57531. public ComboBoxListener,
  57532. public ChangeListener,
  57533. public ButtonListener
  57534. {
  57535. public:
  57536. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57537. AudioIODeviceType::DeviceSetupDetails& setup_,
  57538. const bool hideAdvancedOptionsWithButton)
  57539. : type (type_),
  57540. setup (setup_)
  57541. {
  57542. sampleRateDropDown = 0;
  57543. sampleRateLabel = 0;
  57544. bufferSizeDropDown = 0;
  57545. bufferSizeLabel = 0;
  57546. outputDeviceDropDown = 0;
  57547. outputDeviceLabel = 0;
  57548. inputDeviceDropDown = 0;
  57549. inputDeviceLabel = 0;
  57550. testButton = 0;
  57551. inputLevelMeter = 0;
  57552. showUIButton = 0;
  57553. inputChanList = 0;
  57554. outputChanList = 0;
  57555. inputChanLabel = 0;
  57556. outputChanLabel = 0;
  57557. showAdvancedSettingsButton = 0;
  57558. if (hideAdvancedOptionsWithButton)
  57559. {
  57560. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57561. showAdvancedSettingsButton->addButtonListener (this);
  57562. }
  57563. type->scanForDevices();
  57564. setup.manager->addChangeListener (this);
  57565. changeListenerCallback (0);
  57566. }
  57567. ~AudioDeviceSettingsPanel()
  57568. {
  57569. setup.manager->removeChangeListener (this);
  57570. deleteAndZero (outputDeviceLabel);
  57571. deleteAndZero (inputDeviceLabel);
  57572. deleteAndZero (sampleRateLabel);
  57573. deleteAndZero (bufferSizeLabel);
  57574. deleteAndZero (showUIButton);
  57575. deleteAndZero (inputChanLabel);
  57576. deleteAndZero (outputChanLabel);
  57577. deleteAndZero (showAdvancedSettingsButton);
  57578. deleteAllChildren();
  57579. }
  57580. void resized()
  57581. {
  57582. const int lx = proportionOfWidth (0.35f);
  57583. const int w = proportionOfWidth (0.4f);
  57584. const int h = 24;
  57585. const int space = 6;
  57586. const int dh = h + space;
  57587. int y = 0;
  57588. if (outputDeviceDropDown != 0)
  57589. {
  57590. outputDeviceDropDown->setBounds (lx, y, w, h);
  57591. if (testButton != 0)
  57592. testButton->setBounds (proportionOfWidth (0.77f),
  57593. outputDeviceDropDown->getY(),
  57594. proportionOfWidth (0.18f),
  57595. h);
  57596. y += dh;
  57597. }
  57598. if (inputDeviceDropDown != 0)
  57599. {
  57600. inputDeviceDropDown->setBounds (lx, y, w, h);
  57601. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57602. inputDeviceDropDown->getY(),
  57603. proportionOfWidth (0.18f),
  57604. h);
  57605. y += dh;
  57606. }
  57607. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57608. if (outputChanList != 0)
  57609. {
  57610. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57611. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57612. y += bh + space;
  57613. }
  57614. if (inputChanList != 0)
  57615. {
  57616. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57617. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57618. y += bh + space;
  57619. }
  57620. y += space * 2;
  57621. if (showAdvancedSettingsButton != 0)
  57622. {
  57623. showAdvancedSettingsButton->changeWidthToFitText (h);
  57624. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57625. }
  57626. if (sampleRateDropDown != 0)
  57627. {
  57628. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57629. || ! showAdvancedSettingsButton->isVisible());
  57630. sampleRateDropDown->setBounds (lx, y, w, h);
  57631. y += dh;
  57632. }
  57633. if (bufferSizeDropDown != 0)
  57634. {
  57635. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57636. || ! showAdvancedSettingsButton->isVisible());
  57637. bufferSizeDropDown->setBounds (lx, y, w, h);
  57638. y += dh;
  57639. }
  57640. if (showUIButton != 0)
  57641. {
  57642. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57643. || ! showAdvancedSettingsButton->isVisible());
  57644. showUIButton->changeWidthToFitText (h);
  57645. showUIButton->setTopLeftPosition (lx, y);
  57646. }
  57647. }
  57648. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57649. {
  57650. if (comboBoxThatHasChanged == 0)
  57651. return;
  57652. AudioDeviceManager::AudioDeviceSetup config;
  57653. setup.manager->getAudioDeviceSetup (config);
  57654. String error;
  57655. if (comboBoxThatHasChanged == outputDeviceDropDown
  57656. || comboBoxThatHasChanged == inputDeviceDropDown)
  57657. {
  57658. if (outputDeviceDropDown != 0)
  57659. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57660. : outputDeviceDropDown->getText();
  57661. if (inputDeviceDropDown != 0)
  57662. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57663. : inputDeviceDropDown->getText();
  57664. if (! type->hasSeparateInputsAndOutputs())
  57665. config.inputDeviceName = config.outputDeviceName;
  57666. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57667. config.useDefaultInputChannels = true;
  57668. else
  57669. config.useDefaultOutputChannels = true;
  57670. error = setup.manager->setAudioDeviceSetup (config, true);
  57671. showCorrectDeviceName (inputDeviceDropDown, true);
  57672. showCorrectDeviceName (outputDeviceDropDown, false);
  57673. updateControlPanelButton();
  57674. resized();
  57675. }
  57676. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57677. {
  57678. if (sampleRateDropDown->getSelectedId() > 0)
  57679. {
  57680. config.sampleRate = sampleRateDropDown->getSelectedId();
  57681. error = setup.manager->setAudioDeviceSetup (config, true);
  57682. }
  57683. }
  57684. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57685. {
  57686. if (bufferSizeDropDown->getSelectedId() > 0)
  57687. {
  57688. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57689. error = setup.manager->setAudioDeviceSetup (config, true);
  57690. }
  57691. }
  57692. if (error.isNotEmpty())
  57693. {
  57694. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57695. "Error when trying to open audio device!",
  57696. error);
  57697. }
  57698. }
  57699. void buttonClicked (Button* button)
  57700. {
  57701. if (button == showAdvancedSettingsButton)
  57702. {
  57703. showAdvancedSettingsButton->setVisible (false);
  57704. resized();
  57705. }
  57706. else if (button == showUIButton)
  57707. {
  57708. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57709. if (device != 0 && device->showControlPanel())
  57710. {
  57711. setup.manager->closeAudioDevice();
  57712. setup.manager->restartLastAudioDevice();
  57713. getTopLevelComponent()->toFront (true);
  57714. }
  57715. }
  57716. else if (button == testButton && testButton != 0)
  57717. {
  57718. setup.manager->playTestSound();
  57719. }
  57720. }
  57721. void updateControlPanelButton()
  57722. {
  57723. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57724. deleteAndZero (showUIButton);
  57725. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57726. {
  57727. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57728. TRANS ("opens the device's own control panel")));
  57729. showUIButton->addButtonListener (this);
  57730. }
  57731. resized();
  57732. }
  57733. void changeListenerCallback (void*)
  57734. {
  57735. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57736. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57737. {
  57738. if (outputDeviceDropDown == 0)
  57739. {
  57740. outputDeviceDropDown = new ComboBox (String::empty);
  57741. outputDeviceDropDown->addListener (this);
  57742. addAndMakeVisible (outputDeviceDropDown);
  57743. outputDeviceLabel = new Label (String::empty,
  57744. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57745. : TRANS ("device:"));
  57746. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57747. if (setup.maxNumOutputChannels > 0)
  57748. {
  57749. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57750. testButton->addButtonListener (this);
  57751. }
  57752. }
  57753. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57754. }
  57755. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57756. {
  57757. if (inputDeviceDropDown == 0)
  57758. {
  57759. inputDeviceDropDown = new ComboBox (String::empty);
  57760. inputDeviceDropDown->addListener (this);
  57761. addAndMakeVisible (inputDeviceDropDown);
  57762. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57763. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57764. addAndMakeVisible (inputLevelMeter
  57765. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57766. }
  57767. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57768. }
  57769. updateControlPanelButton();
  57770. showCorrectDeviceName (inputDeviceDropDown, true);
  57771. showCorrectDeviceName (outputDeviceDropDown, false);
  57772. if (currentDevice != 0)
  57773. {
  57774. if (setup.maxNumOutputChannels > 0
  57775. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57776. {
  57777. if (outputChanList == 0)
  57778. {
  57779. addAndMakeVisible (outputChanList
  57780. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57781. TRANS ("(no audio output channels found)")));
  57782. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57783. outputChanLabel->attachToComponent (outputChanList, true);
  57784. }
  57785. outputChanList->refresh();
  57786. }
  57787. else
  57788. {
  57789. deleteAndZero (outputChanLabel);
  57790. deleteAndZero (outputChanList);
  57791. }
  57792. if (setup.maxNumInputChannels > 0
  57793. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57794. {
  57795. if (inputChanList == 0)
  57796. {
  57797. addAndMakeVisible (inputChanList
  57798. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57799. TRANS ("(no audio input channels found)")));
  57800. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57801. inputChanLabel->attachToComponent (inputChanList, true);
  57802. }
  57803. inputChanList->refresh();
  57804. }
  57805. else
  57806. {
  57807. deleteAndZero (inputChanLabel);
  57808. deleteAndZero (inputChanList);
  57809. }
  57810. // sample rate..
  57811. {
  57812. if (sampleRateDropDown == 0)
  57813. {
  57814. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57815. sampleRateDropDown->addListener (this);
  57816. delete sampleRateLabel;
  57817. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57818. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57819. }
  57820. else
  57821. {
  57822. sampleRateDropDown->clear();
  57823. sampleRateDropDown->removeListener (this);
  57824. }
  57825. const int numRates = currentDevice->getNumSampleRates();
  57826. for (int i = 0; i < numRates; ++i)
  57827. {
  57828. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57829. sampleRateDropDown->addItem (String (rate) + " Hz", rate);
  57830. }
  57831. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57832. sampleRateDropDown->addListener (this);
  57833. }
  57834. // buffer size
  57835. {
  57836. if (bufferSizeDropDown == 0)
  57837. {
  57838. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57839. bufferSizeDropDown->addListener (this);
  57840. delete bufferSizeLabel;
  57841. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57842. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57843. }
  57844. else
  57845. {
  57846. bufferSizeDropDown->clear();
  57847. }
  57848. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57849. double currentRate = currentDevice->getCurrentSampleRate();
  57850. if (currentRate == 0)
  57851. currentRate = 48000.0;
  57852. for (int i = 0; i < numBufferSizes; ++i)
  57853. {
  57854. const int bs = currentDevice->getBufferSizeSamples (i);
  57855. bufferSizeDropDown->addItem (String (bs)
  57856. + " samples ("
  57857. + String (bs * 1000.0 / currentRate, 1)
  57858. + " ms)",
  57859. bs);
  57860. }
  57861. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57862. }
  57863. }
  57864. else
  57865. {
  57866. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57867. deleteAndZero (sampleRateLabel);
  57868. deleteAndZero (bufferSizeLabel);
  57869. deleteAndZero (sampleRateDropDown);
  57870. deleteAndZero (bufferSizeDropDown);
  57871. if (outputDeviceDropDown != 0)
  57872. outputDeviceDropDown->setSelectedId (-1, true);
  57873. if (inputDeviceDropDown != 0)
  57874. inputDeviceDropDown->setSelectedId (-1, true);
  57875. }
  57876. resized();
  57877. setSize (getWidth(), getLowestY() + 4);
  57878. }
  57879. private:
  57880. AudioIODeviceType* const type;
  57881. const AudioIODeviceType::DeviceSetupDetails setup;
  57882. ComboBox* outputDeviceDropDown;
  57883. ComboBox* inputDeviceDropDown;
  57884. ComboBox* sampleRateDropDown;
  57885. ComboBox* bufferSizeDropDown;
  57886. Label* outputDeviceLabel;
  57887. Label* inputDeviceLabel;
  57888. Label* sampleRateLabel;
  57889. Label* bufferSizeLabel;
  57890. Label* inputChanLabel;
  57891. Label* outputChanLabel;
  57892. TextButton* testButton;
  57893. Component* inputLevelMeter;
  57894. TextButton* showUIButton;
  57895. TextButton* showAdvancedSettingsButton;
  57896. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  57897. {
  57898. if (box != 0)
  57899. {
  57900. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  57901. const int index = type->getIndexOfDevice (currentDevice, isInput);
  57902. box->setSelectedId (index + 1, true);
  57903. if (testButton != 0 && ! isInput)
  57904. testButton->setEnabled (index >= 0);
  57905. }
  57906. }
  57907. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  57908. {
  57909. const StringArray devs (type->getDeviceNames (isInputs));
  57910. combo.clear (true);
  57911. for (int i = 0; i < devs.size(); ++i)
  57912. combo.addItem (devs[i], i + 1);
  57913. combo.addItem (TRANS("<< none >>"), -1);
  57914. combo.setSelectedId (-1, true);
  57915. }
  57916. int getLowestY() const
  57917. {
  57918. int y = 0;
  57919. for (int i = getNumChildComponents(); --i >= 0;)
  57920. y = jmax (y, getChildComponent (i)->getBottom());
  57921. return y;
  57922. }
  57923. public:
  57924. class ChannelSelectorListBox : public ListBox,
  57925. public ListBoxModel
  57926. {
  57927. public:
  57928. enum BoxType
  57929. {
  57930. audioInputType,
  57931. audioOutputType
  57932. };
  57933. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  57934. const BoxType type_,
  57935. const String& noItemsMessage_)
  57936. : ListBox (String::empty, 0),
  57937. setup (setup_),
  57938. type (type_),
  57939. noItemsMessage (noItemsMessage_)
  57940. {
  57941. refresh();
  57942. setModel (this);
  57943. setOutlineThickness (1);
  57944. }
  57945. ~ChannelSelectorListBox()
  57946. {
  57947. }
  57948. void refresh()
  57949. {
  57950. items.clear();
  57951. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57952. if (currentDevice != 0)
  57953. {
  57954. if (type == audioInputType)
  57955. items = currentDevice->getInputChannelNames();
  57956. else if (type == audioOutputType)
  57957. items = currentDevice->getOutputChannelNames();
  57958. if (setup.useStereoPairs)
  57959. {
  57960. StringArray pairs;
  57961. for (int i = 0; i < items.size(); i += 2)
  57962. {
  57963. const String name (items[i]);
  57964. const String name2 (items[i + 1]);
  57965. String commonBit;
  57966. for (int j = 0; j < name.length(); ++j)
  57967. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  57968. commonBit = name.substring (0, j);
  57969. // Make sure we only split the name at a space, because otherwise, things
  57970. // like "input 11" + "input 12" would become "input 11 + 2"
  57971. while (commonBit.isNotEmpty() && ! CharacterFunctions::isWhitespace (commonBit.getLastCharacter()))
  57972. commonBit = commonBit.dropLastCharacters (1);
  57973. pairs.add (name.trim() + " + " + name2.substring (commonBit.length()).trim());
  57974. }
  57975. items = pairs;
  57976. }
  57977. }
  57978. updateContent();
  57979. repaint();
  57980. }
  57981. int getNumRows()
  57982. {
  57983. return items.size();
  57984. }
  57985. void paintListBoxItem (int row,
  57986. Graphics& g,
  57987. int width, int height,
  57988. bool rowIsSelected)
  57989. {
  57990. if (((unsigned int) row) < (unsigned int) items.size())
  57991. {
  57992. if (rowIsSelected)
  57993. g.fillAll (findColour (TextEditor::highlightColourId)
  57994. .withMultipliedAlpha (0.3f));
  57995. const String item (items [row]);
  57996. bool enabled = false;
  57997. AudioDeviceManager::AudioDeviceSetup config;
  57998. setup.manager->getAudioDeviceSetup (config);
  57999. if (setup.useStereoPairs)
  58000. {
  58001. if (type == audioInputType)
  58002. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58003. else if (type == audioOutputType)
  58004. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58005. }
  58006. else
  58007. {
  58008. if (type == audioInputType)
  58009. enabled = config.inputChannels [row];
  58010. else if (type == audioOutputType)
  58011. enabled = config.outputChannels [row];
  58012. }
  58013. const int x = getTickX();
  58014. const float tickW = height * 0.75f;
  58015. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58016. enabled, true, true, false);
  58017. g.setFont (height * 0.6f);
  58018. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58019. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58020. }
  58021. }
  58022. void listBoxItemClicked (int row, const MouseEvent& e)
  58023. {
  58024. selectRow (row);
  58025. if (e.x < getTickX())
  58026. flipEnablement (row);
  58027. }
  58028. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58029. {
  58030. flipEnablement (row);
  58031. }
  58032. void returnKeyPressed (int row)
  58033. {
  58034. flipEnablement (row);
  58035. }
  58036. void paint (Graphics& g)
  58037. {
  58038. ListBox::paint (g);
  58039. if (items.size() == 0)
  58040. {
  58041. g.setColour (Colours::grey);
  58042. g.setFont (13.0f);
  58043. g.drawText (noItemsMessage,
  58044. 0, 0, getWidth(), getHeight() / 2,
  58045. Justification::centred, true);
  58046. }
  58047. }
  58048. int getBestHeight (int maxHeight)
  58049. {
  58050. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58051. getNumRows())
  58052. + getOutlineThickness() * 2;
  58053. }
  58054. juce_UseDebuggingNewOperator
  58055. private:
  58056. const AudioIODeviceType::DeviceSetupDetails setup;
  58057. const BoxType type;
  58058. const String noItemsMessage;
  58059. StringArray items;
  58060. void flipEnablement (const int row)
  58061. {
  58062. jassert (type == audioInputType || type == audioOutputType);
  58063. if (((unsigned int) row) < (unsigned int) items.size())
  58064. {
  58065. AudioDeviceManager::AudioDeviceSetup config;
  58066. setup.manager->getAudioDeviceSetup (config);
  58067. if (setup.useStereoPairs)
  58068. {
  58069. BigInteger bits;
  58070. BigInteger& original = (type == audioInputType ? config.inputChannels
  58071. : config.outputChannels);
  58072. int i;
  58073. for (i = 0; i < 256; i += 2)
  58074. bits.setBit (i / 2, original [i] || original [i + 1]);
  58075. if (type == audioInputType)
  58076. {
  58077. config.useDefaultInputChannels = false;
  58078. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58079. }
  58080. else
  58081. {
  58082. config.useDefaultOutputChannels = false;
  58083. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58084. }
  58085. for (i = 0; i < 256; ++i)
  58086. original.setBit (i, bits [i / 2]);
  58087. }
  58088. else
  58089. {
  58090. if (type == audioInputType)
  58091. {
  58092. config.useDefaultInputChannels = false;
  58093. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58094. }
  58095. else
  58096. {
  58097. config.useDefaultOutputChannels = false;
  58098. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58099. }
  58100. }
  58101. String error (setup.manager->setAudioDeviceSetup (config, true));
  58102. if (! error.isEmpty())
  58103. {
  58104. //xxx
  58105. }
  58106. }
  58107. }
  58108. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58109. {
  58110. const int numActive = chans.countNumberOfSetBits();
  58111. if (chans [index])
  58112. {
  58113. if (numActive > minNumber)
  58114. chans.setBit (index, false);
  58115. }
  58116. else
  58117. {
  58118. if (numActive >= maxNumber)
  58119. {
  58120. const int firstActiveChan = chans.findNextSetBit();
  58121. chans.setBit (index > firstActiveChan
  58122. ? firstActiveChan : chans.getHighestBit(),
  58123. false);
  58124. }
  58125. chans.setBit (index, true);
  58126. }
  58127. }
  58128. int getTickX() const
  58129. {
  58130. return getRowHeight() + 5;
  58131. }
  58132. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58133. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58134. };
  58135. private:
  58136. ChannelSelectorListBox* inputChanList;
  58137. ChannelSelectorListBox* outputChanList;
  58138. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58139. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58140. };
  58141. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58142. const int minInputChannels_,
  58143. const int maxInputChannels_,
  58144. const int minOutputChannels_,
  58145. const int maxOutputChannels_,
  58146. const bool showMidiInputOptions,
  58147. const bool showMidiOutputSelector,
  58148. const bool showChannelsAsStereoPairs_,
  58149. const bool hideAdvancedOptionsWithButton_)
  58150. : deviceManager (deviceManager_),
  58151. deviceTypeDropDown (0),
  58152. deviceTypeDropDownLabel (0),
  58153. audioDeviceSettingsComp (0),
  58154. minOutputChannels (minOutputChannels_),
  58155. maxOutputChannels (maxOutputChannels_),
  58156. minInputChannels (minInputChannels_),
  58157. maxInputChannels (maxInputChannels_),
  58158. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58159. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58160. {
  58161. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58162. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58163. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58164. {
  58165. deviceTypeDropDown = new ComboBox (String::empty);
  58166. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58167. {
  58168. deviceTypeDropDown
  58169. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58170. i + 1);
  58171. }
  58172. addAndMakeVisible (deviceTypeDropDown);
  58173. deviceTypeDropDown->addListener (this);
  58174. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58175. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58176. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58177. }
  58178. if (showMidiInputOptions)
  58179. {
  58180. addAndMakeVisible (midiInputsList
  58181. = new MidiInputSelectorComponentListBox (deviceManager,
  58182. TRANS("(no midi inputs available)"),
  58183. 0, 0));
  58184. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58185. midiInputsLabel->setJustificationType (Justification::topRight);
  58186. midiInputsLabel->attachToComponent (midiInputsList, true);
  58187. }
  58188. else
  58189. {
  58190. midiInputsList = 0;
  58191. midiInputsLabel = 0;
  58192. }
  58193. if (showMidiOutputSelector)
  58194. {
  58195. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58196. midiOutputSelector->addListener (this);
  58197. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58198. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58199. }
  58200. else
  58201. {
  58202. midiOutputSelector = 0;
  58203. midiOutputLabel = 0;
  58204. }
  58205. deviceManager_.addChangeListener (this);
  58206. changeListenerCallback (0);
  58207. }
  58208. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58209. {
  58210. deviceManager.removeChangeListener (this);
  58211. deleteAllChildren();
  58212. }
  58213. void AudioDeviceSelectorComponent::resized()
  58214. {
  58215. const int lx = proportionOfWidth (0.35f);
  58216. const int w = proportionOfWidth (0.4f);
  58217. const int h = 24;
  58218. const int space = 6;
  58219. const int dh = h + space;
  58220. int y = 15;
  58221. if (deviceTypeDropDown != 0)
  58222. {
  58223. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58224. y += dh + space * 2;
  58225. }
  58226. if (audioDeviceSettingsComp != 0)
  58227. {
  58228. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58229. y += audioDeviceSettingsComp->getHeight() + space;
  58230. }
  58231. if (midiInputsList != 0)
  58232. {
  58233. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58234. midiInputsList->setBounds (lx, y, w, bh);
  58235. y += bh + space;
  58236. }
  58237. if (midiOutputSelector != 0)
  58238. midiOutputSelector->setBounds (lx, y, w, h);
  58239. }
  58240. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58241. {
  58242. if (child == audioDeviceSettingsComp)
  58243. resized();
  58244. }
  58245. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58246. {
  58247. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58248. if (device != 0 && device->hasControlPanel())
  58249. {
  58250. if (device->showControlPanel())
  58251. deviceManager.restartLastAudioDevice();
  58252. getTopLevelComponent()->toFront (true);
  58253. }
  58254. }
  58255. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58256. {
  58257. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58258. {
  58259. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58260. if (type != 0)
  58261. {
  58262. deleteAndZero (audioDeviceSettingsComp);
  58263. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58264. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58265. }
  58266. }
  58267. else if (comboBoxThatHasChanged == midiOutputSelector)
  58268. {
  58269. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58270. }
  58271. }
  58272. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58273. {
  58274. if (deviceTypeDropDown != 0)
  58275. {
  58276. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58277. }
  58278. if (audioDeviceSettingsComp == 0
  58279. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58280. {
  58281. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58282. deleteAndZero (audioDeviceSettingsComp);
  58283. AudioIODeviceType* const type
  58284. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58285. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58286. if (type != 0)
  58287. {
  58288. AudioIODeviceType::DeviceSetupDetails details;
  58289. details.manager = &deviceManager;
  58290. details.minNumInputChannels = minInputChannels;
  58291. details.maxNumInputChannels = maxInputChannels;
  58292. details.minNumOutputChannels = minOutputChannels;
  58293. details.maxNumOutputChannels = maxOutputChannels;
  58294. details.useStereoPairs = showChannelsAsStereoPairs;
  58295. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58296. if (audioDeviceSettingsComp != 0)
  58297. {
  58298. addAndMakeVisible (audioDeviceSettingsComp);
  58299. audioDeviceSettingsComp->resized();
  58300. }
  58301. }
  58302. }
  58303. if (midiInputsList != 0)
  58304. {
  58305. midiInputsList->updateContent();
  58306. midiInputsList->repaint();
  58307. }
  58308. if (midiOutputSelector != 0)
  58309. {
  58310. midiOutputSelector->clear();
  58311. const StringArray midiOuts (MidiOutput::getDevices());
  58312. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58313. midiOutputSelector->addSeparator();
  58314. for (int i = 0; i < midiOuts.size(); ++i)
  58315. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58316. int current = -1;
  58317. if (deviceManager.getDefaultMidiOutput() != 0)
  58318. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58319. midiOutputSelector->setSelectedId (current, true);
  58320. }
  58321. resized();
  58322. }
  58323. END_JUCE_NAMESPACE
  58324. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58325. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58326. BEGIN_JUCE_NAMESPACE
  58327. BubbleComponent::BubbleComponent()
  58328. : side (0),
  58329. allowablePlacements (above | below | left | right),
  58330. arrowTipX (0.0f),
  58331. arrowTipY (0.0f)
  58332. {
  58333. setInterceptsMouseClicks (false, false);
  58334. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58335. setComponentEffect (&shadow);
  58336. }
  58337. BubbleComponent::~BubbleComponent()
  58338. {
  58339. }
  58340. void BubbleComponent::paint (Graphics& g)
  58341. {
  58342. int x = content.getX();
  58343. int y = content.getY();
  58344. int w = content.getWidth();
  58345. int h = content.getHeight();
  58346. int cw, ch;
  58347. getContentSize (cw, ch);
  58348. if (side == 3)
  58349. x += w - cw;
  58350. else if (side != 1)
  58351. x += (w - cw) / 2;
  58352. w = cw;
  58353. if (side == 2)
  58354. y += h - ch;
  58355. else if (side != 0)
  58356. y += (h - ch) / 2;
  58357. h = ch;
  58358. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58359. (float) x, (float) y,
  58360. (float) w, (float) h);
  58361. const int cx = x + (w - cw) / 2;
  58362. const int cy = y + (h - ch) / 2;
  58363. const int indent = 3;
  58364. g.setOrigin (cx + indent, cy + indent);
  58365. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58366. paintContent (g, cw - indent * 2, ch - indent * 2);
  58367. }
  58368. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58369. {
  58370. allowablePlacements = newPlacement;
  58371. }
  58372. void BubbleComponent::setPosition (Component* componentToPointTo)
  58373. {
  58374. jassert (componentToPointTo->isValidComponent());
  58375. Point<int> pos;
  58376. if (getParentComponent() != 0)
  58377. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58378. else
  58379. pos = componentToPointTo->relativePositionToGlobal (pos);
  58380. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58381. }
  58382. void BubbleComponent::setPosition (const int arrowTipX_,
  58383. const int arrowTipY_)
  58384. {
  58385. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58386. }
  58387. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58388. {
  58389. Rectangle<int> availableSpace;
  58390. if (getParentComponent() != 0)
  58391. {
  58392. availableSpace.setSize (getParentComponent()->getWidth(),
  58393. getParentComponent()->getHeight());
  58394. }
  58395. else
  58396. {
  58397. availableSpace = getParentMonitorArea();
  58398. }
  58399. int x = 0;
  58400. int y = 0;
  58401. int w = 150;
  58402. int h = 30;
  58403. getContentSize (w, h);
  58404. w += 30;
  58405. h += 30;
  58406. const float edgeIndent = 2.0f;
  58407. const int arrowLength = jmin (10, h / 3, w / 3);
  58408. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58409. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58410. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58411. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58412. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58413. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58414. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58415. {
  58416. spaceLeft = spaceRight = 0;
  58417. }
  58418. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58419. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58420. {
  58421. spaceAbove = spaceBelow = 0;
  58422. }
  58423. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58424. {
  58425. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58426. arrowTipX = w * 0.5f;
  58427. content.setSize (w, h - arrowLength);
  58428. if (spaceAbove >= spaceBelow)
  58429. {
  58430. // above
  58431. y = rectangleToPointTo.getY() - h;
  58432. content.setPosition (0, 0);
  58433. arrowTipY = h - edgeIndent;
  58434. side = 2;
  58435. }
  58436. else
  58437. {
  58438. // below
  58439. y = rectangleToPointTo.getBottom();
  58440. content.setPosition (0, arrowLength);
  58441. arrowTipY = edgeIndent;
  58442. side = 0;
  58443. }
  58444. }
  58445. else
  58446. {
  58447. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58448. arrowTipY = h * 0.5f;
  58449. content.setSize (w - arrowLength, h);
  58450. if (spaceLeft > spaceRight)
  58451. {
  58452. // on the left
  58453. x = rectangleToPointTo.getX() - w;
  58454. content.setPosition (0, 0);
  58455. arrowTipX = w - edgeIndent;
  58456. side = 3;
  58457. }
  58458. else
  58459. {
  58460. // on the right
  58461. x = rectangleToPointTo.getRight();
  58462. content.setPosition (arrowLength, 0);
  58463. arrowTipX = edgeIndent;
  58464. side = 1;
  58465. }
  58466. }
  58467. setBounds (x, y, w, h);
  58468. }
  58469. END_JUCE_NAMESPACE
  58470. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58471. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58472. BEGIN_JUCE_NAMESPACE
  58473. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58474. : fadeOutLength (fadeOutLengthMs),
  58475. deleteAfterUse (false)
  58476. {
  58477. }
  58478. BubbleMessageComponent::~BubbleMessageComponent()
  58479. {
  58480. fadeOutComponent (fadeOutLength);
  58481. }
  58482. void BubbleMessageComponent::showAt (int x, int y,
  58483. const String& text,
  58484. const int numMillisecondsBeforeRemoving,
  58485. const bool removeWhenMouseClicked,
  58486. const bool deleteSelfAfterUse)
  58487. {
  58488. textLayout.clear();
  58489. textLayout.setText (text, Font (14.0f));
  58490. textLayout.layout (256, Justification::centredLeft, true);
  58491. setPosition (x, y);
  58492. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58493. }
  58494. void BubbleMessageComponent::showAt (Component* const component,
  58495. const String& text,
  58496. const int numMillisecondsBeforeRemoving,
  58497. const bool removeWhenMouseClicked,
  58498. const bool deleteSelfAfterUse)
  58499. {
  58500. textLayout.clear();
  58501. textLayout.setText (text, Font (14.0f));
  58502. textLayout.layout (256, Justification::centredLeft, true);
  58503. setPosition (component);
  58504. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58505. }
  58506. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58507. const bool removeWhenMouseClicked,
  58508. const bool deleteSelfAfterUse)
  58509. {
  58510. setVisible (true);
  58511. deleteAfterUse = deleteSelfAfterUse;
  58512. if (numMillisecondsBeforeRemoving > 0)
  58513. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58514. else
  58515. expiryTime = 0;
  58516. startTimer (77);
  58517. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58518. if (! (removeWhenMouseClicked && isShowing()))
  58519. mouseClickCounter += 0xfffff;
  58520. repaint();
  58521. }
  58522. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58523. {
  58524. w = textLayout.getWidth() + 16;
  58525. h = textLayout.getHeight() + 16;
  58526. }
  58527. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58528. {
  58529. g.setColour (findColour (TooltipWindow::textColourId));
  58530. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58531. }
  58532. void BubbleMessageComponent::timerCallback()
  58533. {
  58534. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58535. {
  58536. stopTimer();
  58537. setVisible (false);
  58538. if (deleteAfterUse)
  58539. delete this;
  58540. }
  58541. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58542. {
  58543. stopTimer();
  58544. fadeOutComponent (fadeOutLength);
  58545. if (deleteAfterUse)
  58546. delete this;
  58547. }
  58548. }
  58549. END_JUCE_NAMESPACE
  58550. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58551. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58552. BEGIN_JUCE_NAMESPACE
  58553. static const int swatchesPerRow = 8;
  58554. static const int swatchHeight = 22;
  58555. class ColourComponentSlider : public Slider
  58556. {
  58557. public:
  58558. ColourComponentSlider (const String& name)
  58559. : Slider (name)
  58560. {
  58561. setRange (0.0, 255.0, 1.0);
  58562. }
  58563. ~ColourComponentSlider()
  58564. {
  58565. }
  58566. const String getTextFromValue (double value)
  58567. {
  58568. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58569. }
  58570. double getValueFromText (const String& text)
  58571. {
  58572. return (double) text.getHexValue32();
  58573. }
  58574. private:
  58575. ColourComponentSlider (const ColourComponentSlider&);
  58576. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58577. };
  58578. class ColourSpaceMarker : public Component
  58579. {
  58580. public:
  58581. ColourSpaceMarker()
  58582. {
  58583. setInterceptsMouseClicks (false, false);
  58584. }
  58585. ~ColourSpaceMarker()
  58586. {
  58587. }
  58588. void paint (Graphics& g)
  58589. {
  58590. g.setColour (Colour::greyLevel (0.1f));
  58591. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58592. g.setColour (Colour::greyLevel (0.9f));
  58593. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58594. }
  58595. private:
  58596. ColourSpaceMarker (const ColourSpaceMarker&);
  58597. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58598. };
  58599. class ColourSelector::ColourSpaceView : public Component
  58600. {
  58601. public:
  58602. ColourSpaceView (ColourSelector* owner_,
  58603. float& h_, float& s_, float& v_,
  58604. const int edgeSize)
  58605. : owner (owner_),
  58606. h (h_), s (s_), v (v_),
  58607. lastHue (0.0f),
  58608. edge (edgeSize)
  58609. {
  58610. addAndMakeVisible (marker = new ColourSpaceMarker());
  58611. setMouseCursor (MouseCursor::CrosshairCursor);
  58612. }
  58613. ~ColourSpaceView()
  58614. {
  58615. deleteAllChildren();
  58616. }
  58617. void paint (Graphics& g)
  58618. {
  58619. if (colours == 0)
  58620. {
  58621. const int width = getWidth() / 2;
  58622. const int height = getHeight() / 2;
  58623. colours = new Image (Image::RGB, width, height, false);
  58624. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58625. for (int y = 0; y < height; ++y)
  58626. {
  58627. const float v = 1.0f - y / (float) height;
  58628. for (int x = 0; x < width; ++x)
  58629. {
  58630. const float s = x / (float) width;
  58631. const Colour col (h, s, v, 1.0f);
  58632. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58633. pix->set (col.getPixelARGB());
  58634. }
  58635. }
  58636. }
  58637. g.setOpacity (1.0f);
  58638. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58639. 0, 0, colours->getWidth(), colours->getHeight());
  58640. }
  58641. void mouseDown (const MouseEvent& e)
  58642. {
  58643. mouseDrag (e);
  58644. }
  58645. void mouseDrag (const MouseEvent& e)
  58646. {
  58647. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58648. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58649. owner->setSV (s, v);
  58650. }
  58651. void updateIfNeeded()
  58652. {
  58653. if (lastHue != h)
  58654. {
  58655. lastHue = h;
  58656. colours = 0;
  58657. repaint();
  58658. }
  58659. updateMarker();
  58660. }
  58661. void resized()
  58662. {
  58663. colours = 0;
  58664. updateMarker();
  58665. }
  58666. private:
  58667. ColourSelector* const owner;
  58668. float& h;
  58669. float& s;
  58670. float& v;
  58671. float lastHue;
  58672. ColourSpaceMarker* marker;
  58673. const int edge;
  58674. ScopedPointer <Image> colours;
  58675. void updateMarker() const throw()
  58676. {
  58677. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58678. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58679. edge * 2, edge * 2);
  58680. }
  58681. ColourSpaceView (const ColourSpaceView&);
  58682. ColourSpaceView& operator= (const ColourSpaceView&);
  58683. };
  58684. class HueSelectorMarker : public Component
  58685. {
  58686. public:
  58687. HueSelectorMarker()
  58688. {
  58689. setInterceptsMouseClicks (false, false);
  58690. }
  58691. ~HueSelectorMarker()
  58692. {
  58693. }
  58694. void paint (Graphics& g)
  58695. {
  58696. Path p;
  58697. p.addTriangle (1.0f, 1.0f,
  58698. getWidth() * 0.3f, getHeight() * 0.5f,
  58699. 1.0f, getHeight() - 1.0f);
  58700. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58701. getWidth() * 0.7f, getHeight() * 0.5f,
  58702. getWidth() - 1.0f, getHeight() - 1.0f);
  58703. g.setColour (Colours::white.withAlpha (0.75f));
  58704. g.fillPath (p);
  58705. g.setColour (Colours::black.withAlpha (0.75f));
  58706. g.strokePath (p, PathStrokeType (1.2f));
  58707. }
  58708. private:
  58709. HueSelectorMarker (const HueSelectorMarker&);
  58710. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58711. };
  58712. class ColourSelector::HueSelectorComp : public Component
  58713. {
  58714. public:
  58715. HueSelectorComp (ColourSelector* owner_,
  58716. float& h_, float& s_, float& v_,
  58717. const int edgeSize)
  58718. : owner (owner_),
  58719. h (h_), s (s_), v (v_),
  58720. lastHue (0.0f),
  58721. edge (edgeSize)
  58722. {
  58723. addAndMakeVisible (marker = new HueSelectorMarker());
  58724. }
  58725. ~HueSelectorComp()
  58726. {
  58727. deleteAllChildren();
  58728. }
  58729. void paint (Graphics& g)
  58730. {
  58731. const float yScale = 1.0f / (getHeight() - edge * 2);
  58732. const Rectangle<int> clip (g.getClipBounds());
  58733. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58734. {
  58735. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58736. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58737. }
  58738. }
  58739. void resized()
  58740. {
  58741. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58742. getWidth(), edge * 2);
  58743. }
  58744. void mouseDown (const MouseEvent& e)
  58745. {
  58746. mouseDrag (e);
  58747. }
  58748. void mouseDrag (const MouseEvent& e)
  58749. {
  58750. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58751. owner->setHue (hue);
  58752. }
  58753. void updateIfNeeded()
  58754. {
  58755. resized();
  58756. }
  58757. private:
  58758. ColourSelector* const owner;
  58759. float& h;
  58760. float& s;
  58761. float& v;
  58762. float lastHue;
  58763. HueSelectorMarker* marker;
  58764. const int edge;
  58765. HueSelectorComp (const HueSelectorComp&);
  58766. HueSelectorComp& operator= (const HueSelectorComp&);
  58767. };
  58768. class ColourSelector::SwatchComponent : public Component
  58769. {
  58770. public:
  58771. SwatchComponent (ColourSelector* owner_, int index_)
  58772. : owner (owner_),
  58773. index (index_)
  58774. {
  58775. }
  58776. ~SwatchComponent()
  58777. {
  58778. }
  58779. void paint (Graphics& g)
  58780. {
  58781. const Colour colour (owner->getSwatchColour (index));
  58782. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58783. 6, 6,
  58784. Colour (0xffdddddd).overlaidWith (colour),
  58785. Colour (0xffffffff).overlaidWith (colour));
  58786. }
  58787. void mouseDown (const MouseEvent&)
  58788. {
  58789. PopupMenu m;
  58790. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58791. m.addSeparator();
  58792. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58793. const int r = m.showAt (this);
  58794. if (r == 1)
  58795. {
  58796. owner->setCurrentColour (owner->getSwatchColour (index));
  58797. }
  58798. else if (r == 2)
  58799. {
  58800. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58801. {
  58802. owner->setSwatchColour (index, owner->getCurrentColour());
  58803. repaint();
  58804. }
  58805. }
  58806. }
  58807. private:
  58808. ColourSelector* const owner;
  58809. const int index;
  58810. SwatchComponent (const SwatchComponent&);
  58811. SwatchComponent& operator= (const SwatchComponent&);
  58812. };
  58813. ColourSelector::ColourSelector (const int flags_,
  58814. const int edgeGap_,
  58815. const int gapAroundColourSpaceComponent)
  58816. : colour (Colours::white),
  58817. flags (flags_),
  58818. topSpace (0),
  58819. edgeGap (edgeGap_)
  58820. {
  58821. // not much point having a selector with no components in it!
  58822. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58823. updateHSV();
  58824. if ((flags & showSliders) != 0)
  58825. {
  58826. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58827. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58828. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58829. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58830. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58831. for (int i = 4; --i >= 0;)
  58832. sliders[i]->addListener (this);
  58833. }
  58834. else
  58835. {
  58836. zeromem (sliders, sizeof (sliders));
  58837. }
  58838. if ((flags & showColourspace) != 0)
  58839. {
  58840. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58841. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58842. }
  58843. else
  58844. {
  58845. colourSpace = 0;
  58846. hueSelector = 0;
  58847. }
  58848. update();
  58849. }
  58850. ColourSelector::~ColourSelector()
  58851. {
  58852. dispatchPendingMessages();
  58853. swatchComponents.clear();
  58854. deleteAllChildren();
  58855. }
  58856. const Colour ColourSelector::getCurrentColour() const
  58857. {
  58858. return ((flags & showAlphaChannel) != 0) ? colour
  58859. : colour.withAlpha ((uint8) 0xff);
  58860. }
  58861. void ColourSelector::setCurrentColour (const Colour& c)
  58862. {
  58863. if (c != colour)
  58864. {
  58865. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58866. updateHSV();
  58867. update();
  58868. }
  58869. }
  58870. void ColourSelector::setHue (float newH)
  58871. {
  58872. newH = jlimit (0.0f, 1.0f, newH);
  58873. if (h != newH)
  58874. {
  58875. h = newH;
  58876. colour = Colour (h, s, v, colour.getFloatAlpha());
  58877. update();
  58878. }
  58879. }
  58880. void ColourSelector::setSV (float newS, float newV)
  58881. {
  58882. newS = jlimit (0.0f, 1.0f, newS);
  58883. newV = jlimit (0.0f, 1.0f, newV);
  58884. if (s != newS || v != newV)
  58885. {
  58886. s = newS;
  58887. v = newV;
  58888. colour = Colour (h, s, v, colour.getFloatAlpha());
  58889. update();
  58890. }
  58891. }
  58892. void ColourSelector::updateHSV()
  58893. {
  58894. colour.getHSB (h, s, v);
  58895. }
  58896. void ColourSelector::update()
  58897. {
  58898. if (sliders[0] != 0)
  58899. {
  58900. sliders[0]->setValue ((int) colour.getRed());
  58901. sliders[1]->setValue ((int) colour.getGreen());
  58902. sliders[2]->setValue ((int) colour.getBlue());
  58903. sliders[3]->setValue ((int) colour.getAlpha());
  58904. }
  58905. if (colourSpace != 0)
  58906. {
  58907. colourSpace->updateIfNeeded();
  58908. hueSelector->updateIfNeeded();
  58909. }
  58910. if ((flags & showColourAtTop) != 0)
  58911. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  58912. sendChangeMessage (this);
  58913. }
  58914. void ColourSelector::paint (Graphics& g)
  58915. {
  58916. g.fillAll (findColour (backgroundColourId));
  58917. if ((flags & showColourAtTop) != 0)
  58918. {
  58919. const Colour colour (getCurrentColour());
  58920. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  58921. 10, 10,
  58922. Colour (0xffdddddd).overlaidWith (colour),
  58923. Colour (0xffffffff).overlaidWith (colour));
  58924. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  58925. g.setFont (14.0f, true);
  58926. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  58927. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  58928. Justification::centred, false);
  58929. }
  58930. if ((flags & showSliders) != 0)
  58931. {
  58932. g.setColour (findColour (labelTextColourId));
  58933. g.setFont (11.0f);
  58934. for (int i = 4; --i >= 0;)
  58935. {
  58936. if (sliders[i]->isVisible())
  58937. g.drawText (sliders[i]->getName() + ":",
  58938. 0, sliders[i]->getY(),
  58939. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  58940. Justification::centredRight, false);
  58941. }
  58942. }
  58943. }
  58944. void ColourSelector::resized()
  58945. {
  58946. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  58947. const int numSwatches = getNumSwatches();
  58948. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  58949. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  58950. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  58951. int y = topSpace;
  58952. if ((flags & showColourspace) != 0)
  58953. {
  58954. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  58955. colourSpace->setBounds (edgeGap, y,
  58956. getWidth() - hueWidth - edgeGap - 4,
  58957. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  58958. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  58959. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  58960. colourSpace->getHeight());
  58961. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  58962. }
  58963. if ((flags & showSliders) != 0)
  58964. {
  58965. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  58966. for (int i = 0; i < numSliders; ++i)
  58967. {
  58968. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  58969. proportionOfWidth (0.72f), sliderHeight - 2);
  58970. y += sliderHeight;
  58971. }
  58972. }
  58973. if (numSwatches > 0)
  58974. {
  58975. const int startX = 8;
  58976. const int xGap = 4;
  58977. const int yGap = 4;
  58978. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  58979. y += edgeGap;
  58980. if (swatchComponents.size() != numSwatches)
  58981. {
  58982. swatchComponents.clear();
  58983. for (int i = 0; i < numSwatches; ++i)
  58984. {
  58985. SwatchComponent* const sc = new SwatchComponent (this, i);
  58986. swatchComponents.add (sc);
  58987. addAndMakeVisible (sc);
  58988. }
  58989. }
  58990. int x = startX;
  58991. for (int i = 0; i < swatchComponents.size(); ++i)
  58992. {
  58993. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  58994. sc->setBounds (x + xGap / 2,
  58995. y + yGap / 2,
  58996. swatchWidth - xGap,
  58997. swatchHeight - yGap);
  58998. if (((i + 1) % swatchesPerRow) == 0)
  58999. {
  59000. x = startX;
  59001. y += swatchHeight;
  59002. }
  59003. else
  59004. {
  59005. x += swatchWidth;
  59006. }
  59007. }
  59008. }
  59009. }
  59010. void ColourSelector::sliderValueChanged (Slider*)
  59011. {
  59012. if (sliders[0] != 0)
  59013. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59014. (uint8) sliders[1]->getValue(),
  59015. (uint8) sliders[2]->getValue(),
  59016. (uint8) sliders[3]->getValue()));
  59017. }
  59018. int ColourSelector::getNumSwatches() const
  59019. {
  59020. return 0;
  59021. }
  59022. const Colour ColourSelector::getSwatchColour (const int) const
  59023. {
  59024. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59025. return Colours::black;
  59026. }
  59027. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59028. {
  59029. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59030. }
  59031. END_JUCE_NAMESPACE
  59032. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59033. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59034. BEGIN_JUCE_NAMESPACE
  59035. class ShadowWindow : public Component
  59036. {
  59037. Component* owner;
  59038. Image** shadowImageSections;
  59039. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59040. public:
  59041. ShadowWindow (Component* const owner_,
  59042. const int type_,
  59043. Image** const shadowImageSections_)
  59044. : owner (owner_),
  59045. shadowImageSections (shadowImageSections_),
  59046. type (type_)
  59047. {
  59048. setInterceptsMouseClicks (false, false);
  59049. if (owner_->isOnDesktop())
  59050. {
  59051. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59052. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59053. | ComponentPeer::windowIsTemporary
  59054. | ComponentPeer::windowIgnoresKeyPresses);
  59055. }
  59056. else if (owner_->getParentComponent() != 0)
  59057. {
  59058. owner_->getParentComponent()->addChildComponent (this);
  59059. }
  59060. }
  59061. ~ShadowWindow()
  59062. {
  59063. }
  59064. void paint (Graphics& g)
  59065. {
  59066. Image* const topLeft = shadowImageSections [type * 3];
  59067. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59068. Image* const filler = shadowImageSections [type * 3 + 2];
  59069. g.setOpacity (1.0f);
  59070. if (type < 2)
  59071. {
  59072. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59073. g.drawImage (topLeft,
  59074. 0, 0, topLeft->getWidth(), imH,
  59075. 0, 0, topLeft->getWidth(), imH);
  59076. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59077. g.drawImage (bottomRight,
  59078. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59079. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59080. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59081. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59082. }
  59083. else
  59084. {
  59085. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59086. g.drawImage (topLeft,
  59087. 0, 0, imW, topLeft->getHeight(),
  59088. 0, 0, imW, topLeft->getHeight());
  59089. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59090. g.drawImage (bottomRight,
  59091. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59092. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59093. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59094. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59095. }
  59096. }
  59097. void resized()
  59098. {
  59099. repaint(); // (needed for correct repainting)
  59100. }
  59101. private:
  59102. ShadowWindow (const ShadowWindow&);
  59103. ShadowWindow& operator= (const ShadowWindow&);
  59104. };
  59105. DropShadower::DropShadower (const float alpha_,
  59106. const int xOffset_,
  59107. const int yOffset_,
  59108. const float blurRadius_)
  59109. : owner (0),
  59110. numShadows (0),
  59111. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59112. xOffset (xOffset_),
  59113. yOffset (yOffset_),
  59114. alpha (alpha_),
  59115. blurRadius (blurRadius_),
  59116. inDestructor (false),
  59117. reentrant (false)
  59118. {
  59119. }
  59120. DropShadower::~DropShadower()
  59121. {
  59122. if (owner != 0)
  59123. owner->removeComponentListener (this);
  59124. inDestructor = true;
  59125. deleteShadowWindows();
  59126. }
  59127. void DropShadower::deleteShadowWindows()
  59128. {
  59129. if (numShadows > 0)
  59130. {
  59131. int i;
  59132. for (i = numShadows; --i >= 0;)
  59133. delete shadowWindows[i];
  59134. for (i = 12; --i >= 0;)
  59135. delete shadowImageSections[i];
  59136. numShadows = 0;
  59137. }
  59138. }
  59139. void DropShadower::setOwner (Component* componentToFollow)
  59140. {
  59141. if (componentToFollow != owner)
  59142. {
  59143. if (owner != 0)
  59144. owner->removeComponentListener (this);
  59145. // (the component can't be null)
  59146. jassert (componentToFollow != 0);
  59147. owner = componentToFollow;
  59148. jassert (owner != 0);
  59149. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59150. owner->addComponentListener (this);
  59151. updateShadows();
  59152. }
  59153. }
  59154. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59155. {
  59156. updateShadows();
  59157. }
  59158. void DropShadower::componentBroughtToFront (Component&)
  59159. {
  59160. bringShadowWindowsToFront();
  59161. }
  59162. void DropShadower::componentChildrenChanged (Component&)
  59163. {
  59164. }
  59165. void DropShadower::componentParentHierarchyChanged (Component&)
  59166. {
  59167. deleteShadowWindows();
  59168. updateShadows();
  59169. }
  59170. void DropShadower::componentVisibilityChanged (Component&)
  59171. {
  59172. updateShadows();
  59173. }
  59174. void DropShadower::updateShadows()
  59175. {
  59176. if (reentrant || inDestructor || (owner == 0))
  59177. return;
  59178. reentrant = true;
  59179. ComponentPeer* const nw = owner->getPeer();
  59180. const bool isOwnerVisible = owner->isVisible()
  59181. && (nw == 0 || ! nw->isMinimised());
  59182. const bool createShadowWindows = numShadows == 0
  59183. && owner->getWidth() > 0
  59184. && owner->getHeight() > 0
  59185. && isOwnerVisible
  59186. && (Desktop::canUseSemiTransparentWindows()
  59187. || owner->getParentComponent() != 0);
  59188. if (createShadowWindows)
  59189. {
  59190. // keep a cached version of the image to save doing the gaussian too often
  59191. String imageId;
  59192. imageId << shadowEdge << ',' << xOffset << ',' << yOffset << ',' << alpha;
  59193. const int hash = imageId.hashCode();
  59194. Image* bigIm = ImageCache::getFromHashCode (hash);
  59195. if (bigIm == 0)
  59196. {
  59197. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59198. Graphics bigG (*bigIm);
  59199. bigG.setColour (Colours::black.withAlpha (alpha));
  59200. bigG.fillRect (shadowEdge + xOffset,
  59201. shadowEdge + yOffset,
  59202. bigIm->getWidth() - (shadowEdge * 2),
  59203. bigIm->getHeight() - (shadowEdge * 2));
  59204. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59205. blurKernel.createGaussianBlur (blurRadius);
  59206. blurKernel.applyToImage (*bigIm, 0,
  59207. Rectangle<int> (xOffset, yOffset,
  59208. bigIm->getWidth(), bigIm->getHeight()));
  59209. ImageCache::addImageToCache (bigIm, hash);
  59210. }
  59211. const int iw = bigIm->getWidth();
  59212. const int ih = bigIm->getHeight();
  59213. const int shadowEdge2 = shadowEdge * 2;
  59214. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59215. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59216. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59217. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59218. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59219. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59220. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59221. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59222. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59223. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59224. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59225. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59226. ImageCache::release (bigIm);
  59227. for (int i = 0; i < 4; ++i)
  59228. {
  59229. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59230. ++numShadows;
  59231. }
  59232. }
  59233. if (numShadows > 0)
  59234. {
  59235. for (int i = numShadows; --i >= 0;)
  59236. {
  59237. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59238. shadowWindows[i]->setVisible (isOwnerVisible);
  59239. }
  59240. const int x = owner->getX();
  59241. const int y = owner->getY() - shadowEdge;
  59242. const int w = owner->getWidth();
  59243. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59244. shadowWindows[0]->setBounds (x - shadowEdge,
  59245. y,
  59246. shadowEdge,
  59247. h);
  59248. shadowWindows[1]->setBounds (x + w,
  59249. y,
  59250. shadowEdge,
  59251. h);
  59252. shadowWindows[2]->setBounds (x,
  59253. y,
  59254. w,
  59255. shadowEdge);
  59256. shadowWindows[3]->setBounds (x,
  59257. owner->getBottom(),
  59258. w,
  59259. shadowEdge);
  59260. }
  59261. reentrant = false;
  59262. if (createShadowWindows)
  59263. bringShadowWindowsToFront();
  59264. }
  59265. void DropShadower::setShadowImage (Image* const src, const int num, const int w, const int h,
  59266. const int sx, const int sy)
  59267. {
  59268. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59269. Graphics g (*shadowImageSections[num]);
  59270. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59271. }
  59272. void DropShadower::bringShadowWindowsToFront()
  59273. {
  59274. if (! (inDestructor || reentrant))
  59275. {
  59276. updateShadows();
  59277. reentrant = true;
  59278. for (int i = numShadows; --i >= 0;)
  59279. shadowWindows[i]->toBehind (owner);
  59280. reentrant = false;
  59281. }
  59282. }
  59283. END_JUCE_NAMESPACE
  59284. /*** End of inlined file: juce_DropShadower.cpp ***/
  59285. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59286. BEGIN_JUCE_NAMESPACE
  59287. class MagnifyingPeer : public ComponentPeer
  59288. {
  59289. public:
  59290. MagnifyingPeer (Component* const component_,
  59291. MagnifierComponent* const magnifierComp_)
  59292. : ComponentPeer (component_, 0),
  59293. magnifierComp (magnifierComp_)
  59294. {
  59295. }
  59296. ~MagnifyingPeer()
  59297. {
  59298. }
  59299. void* getNativeHandle() const { return 0; }
  59300. void setVisible (bool) {}
  59301. void setTitle (const String&) {}
  59302. void setPosition (int, int) {}
  59303. void setSize (int, int) {}
  59304. void setBounds (int, int, int, int, bool) {}
  59305. void setMinimised (bool) {}
  59306. bool isMinimised() const { return false; }
  59307. void setFullScreen (bool) {}
  59308. bool isFullScreen() const { return false; }
  59309. const BorderSize getFrameSize() const { return BorderSize (0); }
  59310. bool setAlwaysOnTop (bool) { return true; }
  59311. void toFront (bool) {}
  59312. void toBehind (ComponentPeer*) {}
  59313. void setIcon (const Image&) {}
  59314. bool isFocused() const
  59315. {
  59316. return magnifierComp->hasKeyboardFocus (true);
  59317. }
  59318. void grabFocus()
  59319. {
  59320. ComponentPeer* peer = magnifierComp->getPeer();
  59321. if (peer != 0)
  59322. peer->grabFocus();
  59323. }
  59324. void textInputRequired (const Point<int>& position)
  59325. {
  59326. ComponentPeer* peer = magnifierComp->getPeer();
  59327. if (peer != 0)
  59328. peer->textInputRequired (position);
  59329. }
  59330. const Rectangle<int> getBounds() const
  59331. {
  59332. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59333. component->getWidth(), component->getHeight());
  59334. }
  59335. const Point<int> getScreenPosition() const
  59336. {
  59337. return magnifierComp->getScreenPosition();
  59338. }
  59339. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59340. {
  59341. const double zoom = magnifierComp->getScaleFactor();
  59342. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59343. roundToInt (relativePosition.getY() * zoom)));
  59344. }
  59345. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59346. {
  59347. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59348. const double zoom = magnifierComp->getScaleFactor();
  59349. return Point<int> (roundToInt (p.getX() / zoom),
  59350. roundToInt (p.getY() / zoom));
  59351. }
  59352. bool contains (const Point<int>& position, bool) const
  59353. {
  59354. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59355. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59356. }
  59357. void repaint (int x, int y, int w, int h)
  59358. {
  59359. const double zoom = magnifierComp->getScaleFactor();
  59360. magnifierComp->repaint ((int) (x * zoom),
  59361. (int) (y * zoom),
  59362. roundToInt (w * zoom) + 1,
  59363. roundToInt (h * zoom) + 1);
  59364. }
  59365. void performAnyPendingRepaintsNow()
  59366. {
  59367. }
  59368. juce_UseDebuggingNewOperator
  59369. private:
  59370. MagnifierComponent* const magnifierComp;
  59371. MagnifyingPeer (const MagnifyingPeer&);
  59372. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59373. };
  59374. class PeerHolderComp : public Component
  59375. {
  59376. public:
  59377. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59378. : magnifierComp (magnifierComp_)
  59379. {
  59380. setVisible (true);
  59381. }
  59382. ~PeerHolderComp()
  59383. {
  59384. }
  59385. ComponentPeer* createNewPeer (int, void*)
  59386. {
  59387. return new MagnifyingPeer (this, magnifierComp);
  59388. }
  59389. void childBoundsChanged (Component* c)
  59390. {
  59391. if (c != 0)
  59392. {
  59393. setSize (c->getWidth(), c->getHeight());
  59394. magnifierComp->childBoundsChanged (this);
  59395. }
  59396. }
  59397. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59398. {
  59399. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59400. Component* const p = magnifierComp->getParentComponent();
  59401. if (p != 0)
  59402. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59403. }
  59404. private:
  59405. MagnifierComponent* const magnifierComp;
  59406. PeerHolderComp (const PeerHolderComp&);
  59407. PeerHolderComp& operator= (const PeerHolderComp&);
  59408. };
  59409. MagnifierComponent::MagnifierComponent (Component* const content_,
  59410. const bool deleteContentCompWhenNoLongerNeeded)
  59411. : content (content_),
  59412. scaleFactor (0.0),
  59413. peer (0),
  59414. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59415. quality (Graphics::lowResamplingQuality),
  59416. mouseSource (0, true)
  59417. {
  59418. holderComp = new PeerHolderComp (this);
  59419. setScaleFactor (1.0);
  59420. }
  59421. MagnifierComponent::~MagnifierComponent()
  59422. {
  59423. delete holderComp;
  59424. if (deleteContent)
  59425. delete content;
  59426. }
  59427. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59428. {
  59429. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59430. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59431. if (scaleFactor != newScaleFactor)
  59432. {
  59433. scaleFactor = newScaleFactor;
  59434. if (scaleFactor == 1.0)
  59435. {
  59436. holderComp->removeFromDesktop();
  59437. peer = 0;
  59438. addChildComponent (content);
  59439. childBoundsChanged (content);
  59440. }
  59441. else
  59442. {
  59443. holderComp->addAndMakeVisible (content);
  59444. holderComp->childBoundsChanged (content);
  59445. childBoundsChanged (holderComp);
  59446. holderComp->addToDesktop (0);
  59447. peer = holderComp->getPeer();
  59448. }
  59449. repaint();
  59450. }
  59451. }
  59452. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59453. {
  59454. quality = newQuality;
  59455. }
  59456. void MagnifierComponent::paint (Graphics& g)
  59457. {
  59458. const int w = holderComp->getWidth();
  59459. const int h = holderComp->getHeight();
  59460. if (w == 0 || h == 0)
  59461. return;
  59462. const Rectangle<int> r (g.getClipBounds());
  59463. const int srcX = (int) (r.getX() / scaleFactor);
  59464. const int srcY = (int) (r.getY() / scaleFactor);
  59465. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59466. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59467. if (scaleFactor >= 1.0)
  59468. {
  59469. ++srcW;
  59470. ++srcH;
  59471. }
  59472. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59473. temp.clear (srcX, srcY, srcW, srcH);
  59474. {
  59475. Graphics g2 (temp);
  59476. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59477. holderComp->paintEntireComponent (g2);
  59478. }
  59479. g.setImageResamplingQuality (quality);
  59480. g.drawImageTransformed (&temp, temp.getBounds(),
  59481. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59482. false);
  59483. }
  59484. void MagnifierComponent::childBoundsChanged (Component* c)
  59485. {
  59486. if (c != 0)
  59487. setSize (roundToInt (c->getWidth() * scaleFactor),
  59488. roundToInt (c->getHeight() * scaleFactor));
  59489. }
  59490. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59491. {
  59492. if (peer != 0)
  59493. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59494. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59495. }
  59496. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59497. {
  59498. passOnMouseEventToPeer (e);
  59499. }
  59500. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59501. {
  59502. passOnMouseEventToPeer (e);
  59503. }
  59504. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59505. {
  59506. passOnMouseEventToPeer (e);
  59507. }
  59508. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59509. {
  59510. passOnMouseEventToPeer (e);
  59511. }
  59512. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59513. {
  59514. passOnMouseEventToPeer (e);
  59515. }
  59516. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59517. {
  59518. passOnMouseEventToPeer (e);
  59519. }
  59520. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59521. {
  59522. if (peer != 0)
  59523. peer->handleMouseWheel (e.source.getIndex(),
  59524. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59525. ix * 256.0f, iy * 256.0f);
  59526. else
  59527. Component::mouseWheelMove (e, ix, iy);
  59528. }
  59529. int MagnifierComponent::scaleInt (const int n) const
  59530. {
  59531. return roundToInt (n / scaleFactor);
  59532. }
  59533. END_JUCE_NAMESPACE
  59534. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59535. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59536. BEGIN_JUCE_NAMESPACE
  59537. class MidiKeyboardUpDownButton : public Button
  59538. {
  59539. public:
  59540. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59541. const int delta_)
  59542. : Button (String::empty),
  59543. owner (owner_),
  59544. delta (delta_)
  59545. {
  59546. setOpaque (true);
  59547. }
  59548. ~MidiKeyboardUpDownButton()
  59549. {
  59550. }
  59551. void clicked()
  59552. {
  59553. int note = owner->getLowestVisibleKey();
  59554. if (delta < 0)
  59555. note = (note - 1) / 12;
  59556. else
  59557. note = note / 12 + 1;
  59558. owner->setLowestVisibleKey (note * 12);
  59559. }
  59560. void paintButton (Graphics& g,
  59561. bool isMouseOverButton,
  59562. bool isButtonDown)
  59563. {
  59564. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59565. isMouseOverButton, isButtonDown,
  59566. delta > 0);
  59567. }
  59568. private:
  59569. MidiKeyboardComponent* const owner;
  59570. const int delta;
  59571. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59572. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59573. };
  59574. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59575. const Orientation orientation_)
  59576. : state (state_),
  59577. xOffset (0),
  59578. blackNoteLength (1),
  59579. keyWidth (16.0f),
  59580. orientation (orientation_),
  59581. midiChannel (1),
  59582. midiInChannelMask (0xffff),
  59583. velocity (1.0f),
  59584. noteUnderMouse (-1),
  59585. mouseDownNote (-1),
  59586. rangeStart (0),
  59587. rangeEnd (127),
  59588. firstKey (12 * 4),
  59589. canScroll (true),
  59590. mouseDragging (false),
  59591. useMousePositionForVelocity (true),
  59592. keyMappingOctave (6),
  59593. octaveNumForMiddleC (3)
  59594. {
  59595. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59596. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59597. // initialise with a default set of querty key-mappings..
  59598. const char* const keymap = "awsedftgyhujkolp;";
  59599. for (int i = String (keymap).length(); --i >= 0;)
  59600. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59601. setOpaque (true);
  59602. setWantsKeyboardFocus (true);
  59603. state.addListener (this);
  59604. }
  59605. MidiKeyboardComponent::~MidiKeyboardComponent()
  59606. {
  59607. state.removeListener (this);
  59608. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59609. deleteAllChildren();
  59610. }
  59611. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59612. {
  59613. keyWidth = widthInPixels;
  59614. resized();
  59615. }
  59616. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59617. {
  59618. if (orientation != newOrientation)
  59619. {
  59620. orientation = newOrientation;
  59621. resized();
  59622. }
  59623. }
  59624. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59625. const int highestNote)
  59626. {
  59627. jassert (lowestNote >= 0 && lowestNote <= 127);
  59628. jassert (highestNote >= 0 && highestNote <= 127);
  59629. jassert (lowestNote <= highestNote);
  59630. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59631. {
  59632. rangeStart = jlimit (0, 127, lowestNote);
  59633. rangeEnd = jlimit (0, 127, highestNote);
  59634. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59635. resized();
  59636. }
  59637. }
  59638. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59639. {
  59640. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59641. if (noteNumber != firstKey)
  59642. {
  59643. firstKey = noteNumber;
  59644. sendChangeMessage (this);
  59645. resized();
  59646. }
  59647. }
  59648. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59649. {
  59650. if (canScroll != canScroll_)
  59651. {
  59652. canScroll = canScroll_;
  59653. resized();
  59654. }
  59655. }
  59656. void MidiKeyboardComponent::colourChanged()
  59657. {
  59658. repaint();
  59659. }
  59660. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59661. {
  59662. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59663. if (midiChannel != midiChannelNumber)
  59664. {
  59665. resetAnyKeysInUse();
  59666. midiChannel = jlimit (1, 16, midiChannelNumber);
  59667. }
  59668. }
  59669. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59670. {
  59671. midiInChannelMask = midiChannelMask;
  59672. triggerAsyncUpdate();
  59673. }
  59674. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59675. {
  59676. velocity = jlimit (0.0f, 1.0f, velocity_);
  59677. useMousePositionForVelocity = useMousePositionForVelocity_;
  59678. }
  59679. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59680. {
  59681. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59682. static const float blackNoteWidth = 0.7f;
  59683. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59684. 1.0f, 2 - blackNoteWidth * 0.4f,
  59685. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59686. 4.0f, 5 - blackNoteWidth * 0.5f,
  59687. 5.0f, 6 - blackNoteWidth * 0.3f,
  59688. 6.0f };
  59689. static const float widths[] = { 1.0f, blackNoteWidth,
  59690. 1.0f, blackNoteWidth,
  59691. 1.0f, 1.0f, blackNoteWidth,
  59692. 1.0f, blackNoteWidth,
  59693. 1.0f, blackNoteWidth,
  59694. 1.0f };
  59695. const int octave = midiNoteNumber / 12;
  59696. const int note = midiNoteNumber % 12;
  59697. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59698. w = roundToInt (widths [note] * keyWidth);
  59699. }
  59700. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59701. {
  59702. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59703. int rx, rw;
  59704. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59705. x -= xOffset + rx;
  59706. }
  59707. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59708. {
  59709. int x, y;
  59710. getKeyPos (midiNoteNumber, x, y);
  59711. return x;
  59712. }
  59713. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59714. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59715. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59716. {
  59717. if (! reallyContains (pos.getX(), pos.getY(), false))
  59718. return -1;
  59719. Point<int> p (pos);
  59720. if (orientation != horizontalKeyboard)
  59721. {
  59722. p = Point<int> (p.getY(), p.getX());
  59723. if (orientation == verticalKeyboardFacingLeft)
  59724. p = Point<int> (p.getX(), getWidth() - p.getY());
  59725. else
  59726. p = Point<int> (getHeight() - p.getX(), p.getY());
  59727. }
  59728. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59729. }
  59730. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59731. {
  59732. if (pos.getY() < blackNoteLength)
  59733. {
  59734. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59735. {
  59736. for (int i = 0; i < 5; ++i)
  59737. {
  59738. const int note = octaveStart + blackNotes [i];
  59739. if (note >= rangeStart && note <= rangeEnd)
  59740. {
  59741. int kx, kw;
  59742. getKeyPos (note, kx, kw);
  59743. kx += xOffset;
  59744. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59745. {
  59746. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59747. return note;
  59748. }
  59749. }
  59750. }
  59751. }
  59752. }
  59753. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59754. {
  59755. for (int i = 0; i < 7; ++i)
  59756. {
  59757. const int note = octaveStart + whiteNotes [i];
  59758. if (note >= rangeStart && note <= rangeEnd)
  59759. {
  59760. int kx, kw;
  59761. getKeyPos (note, kx, kw);
  59762. kx += xOffset;
  59763. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59764. {
  59765. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59766. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59767. return note;
  59768. }
  59769. }
  59770. }
  59771. }
  59772. mousePositionVelocity = 0;
  59773. return -1;
  59774. }
  59775. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59776. {
  59777. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59778. {
  59779. int x, w;
  59780. getKeyPos (noteNum, x, w);
  59781. if (orientation == horizontalKeyboard)
  59782. repaint (x, 0, w, getHeight());
  59783. else if (orientation == verticalKeyboardFacingLeft)
  59784. repaint (0, x, getWidth(), w);
  59785. else if (orientation == verticalKeyboardFacingRight)
  59786. repaint (0, getHeight() - x - w, getWidth(), w);
  59787. }
  59788. }
  59789. void MidiKeyboardComponent::paint (Graphics& g)
  59790. {
  59791. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59792. const Colour lineColour (findColour (keySeparatorLineColourId));
  59793. const Colour textColour (findColour (textLabelColourId));
  59794. int x, w, octave;
  59795. for (octave = 0; octave < 128; octave += 12)
  59796. {
  59797. for (int white = 0; white < 7; ++white)
  59798. {
  59799. const int noteNum = octave + whiteNotes [white];
  59800. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59801. {
  59802. getKeyPos (noteNum, x, w);
  59803. if (orientation == horizontalKeyboard)
  59804. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59805. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59806. noteUnderMouse == noteNum,
  59807. lineColour, textColour);
  59808. else if (orientation == verticalKeyboardFacingLeft)
  59809. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59810. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59811. noteUnderMouse == noteNum,
  59812. lineColour, textColour);
  59813. else if (orientation == verticalKeyboardFacingRight)
  59814. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59815. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59816. noteUnderMouse == noteNum,
  59817. lineColour, textColour);
  59818. }
  59819. }
  59820. }
  59821. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59822. if (orientation == verticalKeyboardFacingLeft)
  59823. {
  59824. x1 = getWidth() - 1.0f;
  59825. x2 = getWidth() - 5.0f;
  59826. }
  59827. else if (orientation == verticalKeyboardFacingRight)
  59828. x2 = 5.0f;
  59829. else
  59830. y2 = 5.0f;
  59831. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59832. Colours::transparentBlack, x2, y2, false));
  59833. getKeyPos (rangeEnd, x, w);
  59834. x += w;
  59835. if (orientation == verticalKeyboardFacingLeft)
  59836. g.fillRect (getWidth() - 5, 0, 5, x);
  59837. else if (orientation == verticalKeyboardFacingRight)
  59838. g.fillRect (0, 0, 5, x);
  59839. else
  59840. g.fillRect (0, 0, x, 5);
  59841. g.setColour (lineColour);
  59842. if (orientation == verticalKeyboardFacingLeft)
  59843. g.fillRect (0, 0, 1, x);
  59844. else if (orientation == verticalKeyboardFacingRight)
  59845. g.fillRect (getWidth() - 1, 0, 1, x);
  59846. else
  59847. g.fillRect (0, getHeight() - 1, x, 1);
  59848. const Colour blackNoteColour (findColour (blackNoteColourId));
  59849. for (octave = 0; octave < 128; octave += 12)
  59850. {
  59851. for (int black = 0; black < 5; ++black)
  59852. {
  59853. const int noteNum = octave + blackNotes [black];
  59854. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59855. {
  59856. getKeyPos (noteNum, x, w);
  59857. if (orientation == horizontalKeyboard)
  59858. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59859. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59860. noteUnderMouse == noteNum,
  59861. blackNoteColour);
  59862. else if (orientation == verticalKeyboardFacingLeft)
  59863. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59864. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59865. noteUnderMouse == noteNum,
  59866. blackNoteColour);
  59867. else if (orientation == verticalKeyboardFacingRight)
  59868. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59869. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59870. noteUnderMouse == noteNum,
  59871. blackNoteColour);
  59872. }
  59873. }
  59874. }
  59875. }
  59876. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59877. Graphics& g, int x, int y, int w, int h,
  59878. bool isDown, bool isOver,
  59879. const Colour& lineColour,
  59880. const Colour& textColour)
  59881. {
  59882. Colour c (Colours::transparentWhite);
  59883. if (isDown)
  59884. c = findColour (keyDownOverlayColourId);
  59885. if (isOver)
  59886. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59887. g.setColour (c);
  59888. g.fillRect (x, y, w, h);
  59889. const String text (getWhiteNoteText (midiNoteNumber));
  59890. if (! text.isEmpty())
  59891. {
  59892. g.setColour (textColour);
  59893. Font f (jmin (12.0f, keyWidth * 0.9f));
  59894. f.setHorizontalScale (0.8f);
  59895. g.setFont (f);
  59896. Justification justification (Justification::centredBottom);
  59897. if (orientation == verticalKeyboardFacingLeft)
  59898. justification = Justification::centredLeft;
  59899. else if (orientation == verticalKeyboardFacingRight)
  59900. justification = Justification::centredRight;
  59901. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  59902. }
  59903. g.setColour (lineColour);
  59904. if (orientation == horizontalKeyboard)
  59905. g.fillRect (x, y, 1, h);
  59906. else if (orientation == verticalKeyboardFacingLeft)
  59907. g.fillRect (x, y, w, 1);
  59908. else if (orientation == verticalKeyboardFacingRight)
  59909. g.fillRect (x, y + h - 1, w, 1);
  59910. if (midiNoteNumber == rangeEnd)
  59911. {
  59912. if (orientation == horizontalKeyboard)
  59913. g.fillRect (x + w, y, 1, h);
  59914. else if (orientation == verticalKeyboardFacingLeft)
  59915. g.fillRect (x, y + h, w, 1);
  59916. else if (orientation == verticalKeyboardFacingRight)
  59917. g.fillRect (x, y - 1, w, 1);
  59918. }
  59919. }
  59920. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  59921. Graphics& g, int x, int y, int w, int h,
  59922. bool isDown, bool isOver,
  59923. const Colour& noteFillColour)
  59924. {
  59925. Colour c (noteFillColour);
  59926. if (isDown)
  59927. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  59928. if (isOver)
  59929. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59930. g.setColour (c);
  59931. g.fillRect (x, y, w, h);
  59932. if (isDown)
  59933. {
  59934. g.setColour (noteFillColour);
  59935. g.drawRect (x, y, w, h);
  59936. }
  59937. else
  59938. {
  59939. const int xIndent = jmax (1, jmin (w, h) / 8);
  59940. g.setColour (c.brighter());
  59941. if (orientation == horizontalKeyboard)
  59942. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  59943. else if (orientation == verticalKeyboardFacingLeft)
  59944. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  59945. else if (orientation == verticalKeyboardFacingRight)
  59946. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  59947. }
  59948. }
  59949. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  59950. {
  59951. octaveNumForMiddleC = octaveNumForMiddleC_;
  59952. repaint();
  59953. }
  59954. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  59955. {
  59956. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  59957. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  59958. return String::empty;
  59959. }
  59960. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  59961. const bool isMouseOver,
  59962. const bool isButtonDown,
  59963. const bool movesOctavesUp)
  59964. {
  59965. g.fillAll (findColour (upDownButtonBackgroundColourId));
  59966. float angle;
  59967. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  59968. angle = movesOctavesUp ? 0.0f : 0.5f;
  59969. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  59970. angle = movesOctavesUp ? 0.25f : 0.75f;
  59971. else
  59972. angle = movesOctavesUp ? 0.75f : 0.25f;
  59973. Path path;
  59974. path.lineTo (0.0f, 1.0f);
  59975. path.lineTo (1.0f, 0.5f);
  59976. path.closeSubPath();
  59977. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  59978. g.setColour (findColour (upDownButtonArrowColourId)
  59979. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  59980. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  59981. w - 2.0f,
  59982. h - 2.0f,
  59983. true));
  59984. }
  59985. void MidiKeyboardComponent::resized()
  59986. {
  59987. int w = getWidth();
  59988. int h = getHeight();
  59989. if (w > 0 && h > 0)
  59990. {
  59991. if (orientation != horizontalKeyboard)
  59992. swapVariables (w, h);
  59993. blackNoteLength = roundToInt (h * 0.7f);
  59994. int kx2, kw2;
  59995. getKeyPos (rangeEnd, kx2, kw2);
  59996. kx2 += kw2;
  59997. if (firstKey != rangeStart)
  59998. {
  59999. int kx1, kw1;
  60000. getKeyPos (rangeStart, kx1, kw1);
  60001. if (kx2 - kx1 <= w)
  60002. {
  60003. firstKey = rangeStart;
  60004. sendChangeMessage (this);
  60005. repaint();
  60006. }
  60007. }
  60008. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60009. scrollDown->setVisible (showScrollButtons);
  60010. scrollUp->setVisible (showScrollButtons);
  60011. xOffset = 0;
  60012. if (showScrollButtons)
  60013. {
  60014. const int scrollButtonW = jmin (12, w / 2);
  60015. if (orientation == horizontalKeyboard)
  60016. {
  60017. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60018. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60019. }
  60020. else if (orientation == verticalKeyboardFacingLeft)
  60021. {
  60022. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60023. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60024. }
  60025. else if (orientation == verticalKeyboardFacingRight)
  60026. {
  60027. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60028. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60029. }
  60030. int endOfLastKey, kw;
  60031. getKeyPos (rangeEnd, endOfLastKey, kw);
  60032. endOfLastKey += kw;
  60033. float mousePositionVelocity;
  60034. const int spaceAvailable = w - scrollButtonW * 2;
  60035. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60036. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60037. {
  60038. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60039. sendChangeMessage (this);
  60040. }
  60041. int newOffset = 0;
  60042. getKeyPos (firstKey, newOffset, kw);
  60043. xOffset = newOffset - scrollButtonW;
  60044. }
  60045. else
  60046. {
  60047. firstKey = rangeStart;
  60048. }
  60049. timerCallback();
  60050. repaint();
  60051. }
  60052. }
  60053. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60054. {
  60055. triggerAsyncUpdate();
  60056. }
  60057. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60058. {
  60059. triggerAsyncUpdate();
  60060. }
  60061. void MidiKeyboardComponent::handleAsyncUpdate()
  60062. {
  60063. for (int i = rangeStart; i <= rangeEnd; ++i)
  60064. {
  60065. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60066. {
  60067. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60068. repaintNote (i);
  60069. }
  60070. }
  60071. }
  60072. void MidiKeyboardComponent::resetAnyKeysInUse()
  60073. {
  60074. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60075. {
  60076. state.allNotesOff (midiChannel);
  60077. keysPressed.clear();
  60078. mouseDownNote = -1;
  60079. }
  60080. }
  60081. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60082. {
  60083. float mousePositionVelocity = 0.0f;
  60084. const int newNote = (mouseDragging || isMouseOver())
  60085. ? xyToNote (pos, mousePositionVelocity) : -1;
  60086. if (noteUnderMouse != newNote)
  60087. {
  60088. if (mouseDownNote >= 0)
  60089. {
  60090. state.noteOff (midiChannel, mouseDownNote);
  60091. mouseDownNote = -1;
  60092. }
  60093. if (mouseDragging && newNote >= 0)
  60094. {
  60095. if (! useMousePositionForVelocity)
  60096. mousePositionVelocity = 1.0f;
  60097. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60098. mouseDownNote = newNote;
  60099. }
  60100. repaintNote (noteUnderMouse);
  60101. noteUnderMouse = newNote;
  60102. repaintNote (noteUnderMouse);
  60103. }
  60104. else if (mouseDownNote >= 0 && ! mouseDragging)
  60105. {
  60106. state.noteOff (midiChannel, mouseDownNote);
  60107. mouseDownNote = -1;
  60108. }
  60109. }
  60110. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60111. {
  60112. updateNoteUnderMouse (e.getPosition());
  60113. stopTimer();
  60114. }
  60115. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60116. {
  60117. float mousePositionVelocity;
  60118. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60119. if (newNote >= 0)
  60120. mouseDraggedToKey (newNote, e);
  60121. updateNoteUnderMouse (e.getPosition());
  60122. }
  60123. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60124. {
  60125. return true;
  60126. }
  60127. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60128. {
  60129. }
  60130. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60131. {
  60132. float mousePositionVelocity;
  60133. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60134. mouseDragging = false;
  60135. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60136. {
  60137. repaintNote (noteUnderMouse);
  60138. noteUnderMouse = -1;
  60139. mouseDragging = true;
  60140. updateNoteUnderMouse (e.getPosition());
  60141. startTimer (500);
  60142. }
  60143. }
  60144. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60145. {
  60146. mouseDragging = false;
  60147. updateNoteUnderMouse (e.getPosition());
  60148. stopTimer();
  60149. }
  60150. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60151. {
  60152. updateNoteUnderMouse (e.getPosition());
  60153. }
  60154. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60155. {
  60156. updateNoteUnderMouse (e.getPosition());
  60157. }
  60158. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60159. {
  60160. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60161. }
  60162. void MidiKeyboardComponent::timerCallback()
  60163. {
  60164. updateNoteUnderMouse (getMouseXYRelative());
  60165. }
  60166. void MidiKeyboardComponent::clearKeyMappings()
  60167. {
  60168. resetAnyKeysInUse();
  60169. keyPressNotes.clear();
  60170. keyPresses.clear();
  60171. }
  60172. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60173. const int midiNoteOffsetFromC)
  60174. {
  60175. removeKeyPressForNote (midiNoteOffsetFromC);
  60176. keyPressNotes.add (midiNoteOffsetFromC);
  60177. keyPresses.add (key);
  60178. }
  60179. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60180. {
  60181. for (int i = keyPressNotes.size(); --i >= 0;)
  60182. {
  60183. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60184. {
  60185. keyPressNotes.remove (i);
  60186. keyPresses.remove (i);
  60187. }
  60188. }
  60189. }
  60190. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60191. {
  60192. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60193. keyMappingOctave = newOctaveNumber;
  60194. }
  60195. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60196. {
  60197. bool keyPressUsed = false;
  60198. for (int i = keyPresses.size(); --i >= 0;)
  60199. {
  60200. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60201. if (keyPresses.getReference(i).isCurrentlyDown())
  60202. {
  60203. if (! keysPressed [note])
  60204. {
  60205. keysPressed.setBit (note);
  60206. state.noteOn (midiChannel, note, velocity);
  60207. keyPressUsed = true;
  60208. }
  60209. }
  60210. else
  60211. {
  60212. if (keysPressed [note])
  60213. {
  60214. keysPressed.clearBit (note);
  60215. state.noteOff (midiChannel, note);
  60216. keyPressUsed = true;
  60217. }
  60218. }
  60219. }
  60220. return keyPressUsed;
  60221. }
  60222. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60223. {
  60224. resetAnyKeysInUse();
  60225. }
  60226. END_JUCE_NAMESPACE
  60227. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60228. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60229. #if JUCE_OPENGL
  60230. BEGIN_JUCE_NAMESPACE
  60231. extern void juce_glViewport (const int w, const int h);
  60232. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60233. const int alphaBits_,
  60234. const int depthBufferBits_,
  60235. const int stencilBufferBits_)
  60236. : redBits (bitsPerRGBComponent),
  60237. greenBits (bitsPerRGBComponent),
  60238. blueBits (bitsPerRGBComponent),
  60239. alphaBits (alphaBits_),
  60240. depthBufferBits (depthBufferBits_),
  60241. stencilBufferBits (stencilBufferBits_),
  60242. accumulationBufferRedBits (0),
  60243. accumulationBufferGreenBits (0),
  60244. accumulationBufferBlueBits (0),
  60245. accumulationBufferAlphaBits (0),
  60246. fullSceneAntiAliasingNumSamples (0)
  60247. {
  60248. }
  60249. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60250. : redBits (other.redBits),
  60251. greenBits (other.greenBits),
  60252. blueBits (other.blueBits),
  60253. alphaBits (other.alphaBits),
  60254. depthBufferBits (other.depthBufferBits),
  60255. stencilBufferBits (other.stencilBufferBits),
  60256. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60257. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60258. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60259. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60260. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60261. {
  60262. }
  60263. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60264. {
  60265. redBits = other.redBits;
  60266. greenBits = other.greenBits;
  60267. blueBits = other.blueBits;
  60268. alphaBits = other.alphaBits;
  60269. depthBufferBits = other.depthBufferBits;
  60270. stencilBufferBits = other.stencilBufferBits;
  60271. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60272. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60273. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60274. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60275. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60276. return *this;
  60277. }
  60278. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60279. {
  60280. return redBits == other.redBits
  60281. && greenBits == other.greenBits
  60282. && blueBits == other.blueBits
  60283. && alphaBits == other.alphaBits
  60284. && depthBufferBits == other.depthBufferBits
  60285. && stencilBufferBits == other.stencilBufferBits
  60286. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60287. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60288. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60289. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60290. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60291. }
  60292. static VoidArray knownContexts;
  60293. OpenGLContext::OpenGLContext() throw()
  60294. {
  60295. knownContexts.add (this);
  60296. }
  60297. OpenGLContext::~OpenGLContext()
  60298. {
  60299. knownContexts.removeValue (this);
  60300. }
  60301. OpenGLContext* OpenGLContext::getCurrentContext()
  60302. {
  60303. for (int i = knownContexts.size(); --i >= 0;)
  60304. {
  60305. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60306. if (oglc->isActive())
  60307. return oglc;
  60308. }
  60309. return 0;
  60310. }
  60311. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60312. {
  60313. public:
  60314. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60315. : ComponentMovementWatcher (owner_),
  60316. owner (owner_),
  60317. wasShowing (false)
  60318. {
  60319. }
  60320. ~OpenGLComponentWatcher() {}
  60321. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60322. {
  60323. owner->updateContextPosition();
  60324. }
  60325. void componentPeerChanged()
  60326. {
  60327. const ScopedLock sl (owner->getContextLock());
  60328. owner->deleteContext();
  60329. }
  60330. void componentVisibilityChanged (Component&)
  60331. {
  60332. const bool isShowingNow = owner->isShowing();
  60333. if (wasShowing != isShowingNow)
  60334. {
  60335. wasShowing = isShowingNow;
  60336. owner->updateContextPosition();
  60337. }
  60338. }
  60339. juce_UseDebuggingNewOperator
  60340. private:
  60341. OpenGLComponent* const owner;
  60342. bool wasShowing;
  60343. };
  60344. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60345. : type (type_),
  60346. contextToShareListsWith (0),
  60347. needToUpdateViewport (true)
  60348. {
  60349. setOpaque (true);
  60350. componentWatcher = new OpenGLComponentWatcher (this);
  60351. }
  60352. OpenGLComponent::~OpenGLComponent()
  60353. {
  60354. deleteContext();
  60355. componentWatcher = 0;
  60356. }
  60357. void OpenGLComponent::deleteContext()
  60358. {
  60359. const ScopedLock sl (contextLock);
  60360. context = 0;
  60361. }
  60362. void OpenGLComponent::updateContextPosition()
  60363. {
  60364. needToUpdateViewport = true;
  60365. if (getWidth() > 0 && getHeight() > 0)
  60366. {
  60367. Component* const topComp = getTopLevelComponent();
  60368. if (topComp->getPeer() != 0)
  60369. {
  60370. const ScopedLock sl (contextLock);
  60371. if (context != 0)
  60372. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60373. getScreenY() - topComp->getScreenY(),
  60374. getWidth(),
  60375. getHeight(),
  60376. topComp->getHeight());
  60377. }
  60378. }
  60379. }
  60380. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60381. {
  60382. OpenGLPixelFormat pf;
  60383. const ScopedLock sl (contextLock);
  60384. if (context != 0)
  60385. pf = context->getPixelFormat();
  60386. return pf;
  60387. }
  60388. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60389. {
  60390. if (! (preferredPixelFormat == formatToUse))
  60391. {
  60392. const ScopedLock sl (contextLock);
  60393. deleteContext();
  60394. preferredPixelFormat = formatToUse;
  60395. }
  60396. }
  60397. void OpenGLComponent::shareWith (OpenGLContext* c)
  60398. {
  60399. if (contextToShareListsWith != c)
  60400. {
  60401. const ScopedLock sl (contextLock);
  60402. deleteContext();
  60403. contextToShareListsWith = c;
  60404. }
  60405. }
  60406. bool OpenGLComponent::makeCurrentContextActive()
  60407. {
  60408. if (context == 0)
  60409. {
  60410. const ScopedLock sl (contextLock);
  60411. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60412. {
  60413. context = createContext();
  60414. if (context != 0)
  60415. {
  60416. updateContextPosition();
  60417. if (context->makeActive())
  60418. newOpenGLContextCreated();
  60419. }
  60420. }
  60421. }
  60422. return context != 0 && context->makeActive();
  60423. }
  60424. void OpenGLComponent::makeCurrentContextInactive()
  60425. {
  60426. if (context != 0)
  60427. context->makeInactive();
  60428. }
  60429. bool OpenGLComponent::isActiveContext() const throw()
  60430. {
  60431. return context != 0 && context->isActive();
  60432. }
  60433. void OpenGLComponent::swapBuffers()
  60434. {
  60435. if (context != 0)
  60436. context->swapBuffers();
  60437. }
  60438. void OpenGLComponent::paint (Graphics&)
  60439. {
  60440. if (renderAndSwapBuffers())
  60441. {
  60442. ComponentPeer* const peer = getPeer();
  60443. if (peer != 0)
  60444. {
  60445. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60446. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60447. }
  60448. }
  60449. }
  60450. bool OpenGLComponent::renderAndSwapBuffers()
  60451. {
  60452. const ScopedLock sl (contextLock);
  60453. if (! makeCurrentContextActive())
  60454. return false;
  60455. if (needToUpdateViewport)
  60456. {
  60457. needToUpdateViewport = false;
  60458. juce_glViewport (getWidth(), getHeight());
  60459. }
  60460. renderOpenGL();
  60461. swapBuffers();
  60462. return true;
  60463. }
  60464. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60465. {
  60466. Component::internalRepaint (x, y, w, h);
  60467. if (context != 0)
  60468. context->repaint();
  60469. }
  60470. END_JUCE_NAMESPACE
  60471. #endif
  60472. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60473. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60474. BEGIN_JUCE_NAMESPACE
  60475. PreferencesPanel::PreferencesPanel()
  60476. : buttonSize (70)
  60477. {
  60478. }
  60479. PreferencesPanel::~PreferencesPanel()
  60480. {
  60481. currentPage = 0;
  60482. deleteAllChildren();
  60483. }
  60484. void PreferencesPanel::addSettingsPage (const String& title,
  60485. const Drawable* icon,
  60486. const Drawable* overIcon,
  60487. const Drawable* downIcon)
  60488. {
  60489. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60490. button->setImages (icon, overIcon, downIcon);
  60491. button->setRadioGroupId (1);
  60492. button->addButtonListener (this);
  60493. button->setClickingTogglesState (true);
  60494. button->setWantsKeyboardFocus (false);
  60495. addAndMakeVisible (button);
  60496. resized();
  60497. if (currentPage == 0)
  60498. setCurrentPage (title);
  60499. }
  60500. void PreferencesPanel::addSettingsPage (const String& title,
  60501. const char* imageData,
  60502. const int imageDataSize)
  60503. {
  60504. DrawableImage icon, iconOver, iconDown;
  60505. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60506. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60507. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60508. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60509. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60510. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60511. }
  60512. class PrefsDialogWindow : public DialogWindow
  60513. {
  60514. public:
  60515. PrefsDialogWindow (const String& dialogtitle,
  60516. const Colour& backgroundColour)
  60517. : DialogWindow (dialogtitle, backgroundColour, true)
  60518. {
  60519. }
  60520. ~PrefsDialogWindow()
  60521. {
  60522. }
  60523. void closeButtonPressed()
  60524. {
  60525. exitModalState (0);
  60526. }
  60527. private:
  60528. PrefsDialogWindow (const PrefsDialogWindow&);
  60529. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60530. };
  60531. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60532. int dialogWidth,
  60533. int dialogHeight,
  60534. const Colour& backgroundColour)
  60535. {
  60536. setSize (dialogWidth, dialogHeight);
  60537. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60538. dw.setContentComponent (this, true, true);
  60539. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60540. dw.runModalLoop();
  60541. dw.setContentComponent (0, false, false);
  60542. }
  60543. void PreferencesPanel::resized()
  60544. {
  60545. int x = 0;
  60546. for (int i = 0; i < getNumChildComponents(); ++i)
  60547. {
  60548. Component* c = getChildComponent (i);
  60549. if (dynamic_cast <DrawableButton*> (c) == 0)
  60550. {
  60551. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60552. }
  60553. else
  60554. {
  60555. c->setBounds (x, 0, buttonSize, buttonSize);
  60556. x += buttonSize;
  60557. }
  60558. }
  60559. }
  60560. void PreferencesPanel::paint (Graphics& g)
  60561. {
  60562. g.setColour (Colours::grey);
  60563. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60564. }
  60565. void PreferencesPanel::setCurrentPage (const String& pageName)
  60566. {
  60567. if (currentPageName != pageName)
  60568. {
  60569. currentPageName = pageName;
  60570. currentPage = 0;
  60571. currentPage = createComponentForPage (pageName);
  60572. if (currentPage != 0)
  60573. {
  60574. addAndMakeVisible (currentPage);
  60575. currentPage->toBack();
  60576. resized();
  60577. }
  60578. for (int i = 0; i < getNumChildComponents(); ++i)
  60579. {
  60580. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60581. if (db != 0 && db->getName() == pageName)
  60582. {
  60583. db->setToggleState (true, false);
  60584. break;
  60585. }
  60586. }
  60587. }
  60588. }
  60589. void PreferencesPanel::buttonClicked (Button*)
  60590. {
  60591. for (int i = 0; i < getNumChildComponents(); ++i)
  60592. {
  60593. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60594. if (db != 0 && db->getToggleState())
  60595. {
  60596. setCurrentPage (db->getName());
  60597. break;
  60598. }
  60599. }
  60600. }
  60601. END_JUCE_NAMESPACE
  60602. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60603. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60604. #if JUCE_WINDOWS || JUCE_LINUX
  60605. BEGIN_JUCE_NAMESPACE
  60606. SystemTrayIconComponent::SystemTrayIconComponent()
  60607. {
  60608. addToDesktop (0);
  60609. }
  60610. SystemTrayIconComponent::~SystemTrayIconComponent()
  60611. {
  60612. }
  60613. END_JUCE_NAMESPACE
  60614. #endif
  60615. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60616. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60617. BEGIN_JUCE_NAMESPACE
  60618. static const int titleH = 24;
  60619. static const int iconWidth = 80;
  60620. class AlertWindowTextEditor : public TextEditor
  60621. {
  60622. public:
  60623. static const tchar passwordChar;
  60624. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60625. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60626. {
  60627. setSelectAllWhenFocused (true);
  60628. }
  60629. ~AlertWindowTextEditor()
  60630. {
  60631. }
  60632. void returnPressed()
  60633. {
  60634. // pass these up the component hierarchy to be trigger the buttons
  60635. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, '\n'));
  60636. }
  60637. void escapePressed()
  60638. {
  60639. // pass these up the component hierarchy to be trigger the buttons
  60640. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60641. }
  60642. private:
  60643. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60644. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60645. };
  60646. #if JUCE_LINUX
  60647. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60648. #else
  60649. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60650. #endif
  60651. AlertWindow::AlertWindow (const String& title,
  60652. const String& message,
  60653. AlertIconType iconType,
  60654. Component* associatedComponent_)
  60655. : TopLevelWindow (title, true),
  60656. alertIconType (iconType),
  60657. associatedComponent (associatedComponent_)
  60658. {
  60659. if (message.isEmpty())
  60660. text = " "; // to force an update if the message is empty
  60661. setMessage (message);
  60662. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60663. {
  60664. Component* const c = Desktop::getInstance().getComponent (i);
  60665. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60666. {
  60667. setAlwaysOnTop (true);
  60668. break;
  60669. }
  60670. }
  60671. if (JUCEApplication::getInstance() == 0)
  60672. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60673. lookAndFeelChanged();
  60674. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60675. }
  60676. AlertWindow::~AlertWindow()
  60677. {
  60678. for (int i = customComps.size(); --i >= 0;)
  60679. removeChildComponent ((Component*) customComps[i]);
  60680. deleteAllChildren();
  60681. }
  60682. void AlertWindow::userTriedToCloseWindow()
  60683. {
  60684. exitModalState (0);
  60685. }
  60686. void AlertWindow::setMessage (const String& message)
  60687. {
  60688. const String newMessage (message.substring (0, 2048));
  60689. if (text != newMessage)
  60690. {
  60691. text = newMessage;
  60692. font.setHeight (15.0f);
  60693. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60694. textLayout.setText (getName() + "\n\n", titleFont);
  60695. textLayout.appendText (text, font);
  60696. updateLayout (true);
  60697. repaint();
  60698. }
  60699. }
  60700. void AlertWindow::buttonClicked (Button* button)
  60701. {
  60702. for (int i = 0; i < buttons.size(); i++)
  60703. {
  60704. TextButton* const c = (TextButton*) buttons[i];
  60705. if (button->getName() == c->getName())
  60706. {
  60707. if (c->getParentComponent() != 0)
  60708. c->getParentComponent()->exitModalState (c->getCommandID());
  60709. break;
  60710. }
  60711. }
  60712. }
  60713. void AlertWindow::addButton (const String& name,
  60714. const int returnValue,
  60715. const KeyPress& shortcutKey1,
  60716. const KeyPress& shortcutKey2)
  60717. {
  60718. TextButton* const b = new TextButton (name, String::empty);
  60719. b->setWantsKeyboardFocus (true);
  60720. b->setMouseClickGrabsKeyboardFocus (false);
  60721. b->setCommandToTrigger (0, returnValue, false);
  60722. b->addShortcut (shortcutKey1);
  60723. b->addShortcut (shortcutKey2);
  60724. b->addButtonListener (this);
  60725. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60726. addAndMakeVisible (b, 0);
  60727. buttons.add (b);
  60728. updateLayout (false);
  60729. }
  60730. int AlertWindow::getNumButtons() const
  60731. {
  60732. return buttons.size();
  60733. }
  60734. void AlertWindow::addTextEditor (const String& name,
  60735. const String& initialContents,
  60736. const String& onScreenLabel,
  60737. const bool isPasswordBox)
  60738. {
  60739. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60740. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60741. tc->setFont (font);
  60742. tc->setText (initialContents);
  60743. tc->setCaretPosition (initialContents.length());
  60744. addAndMakeVisible (tc);
  60745. textBoxes.add (tc);
  60746. allComps.add (tc);
  60747. textboxNames.add (onScreenLabel);
  60748. updateLayout (false);
  60749. }
  60750. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60751. {
  60752. for (int i = textBoxes.size(); --i >= 0;)
  60753. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60754. return ((TextEditor*)textBoxes[i])->getText();
  60755. return String::empty;
  60756. }
  60757. void AlertWindow::addComboBox (const String& name,
  60758. const StringArray& items,
  60759. const String& onScreenLabel)
  60760. {
  60761. ComboBox* const cb = new ComboBox (name);
  60762. for (int i = 0; i < items.size(); ++i)
  60763. cb->addItem (items[i], i + 1);
  60764. addAndMakeVisible (cb);
  60765. cb->setSelectedItemIndex (0);
  60766. comboBoxes.add (cb);
  60767. allComps.add (cb);
  60768. comboBoxNames.add (onScreenLabel);
  60769. updateLayout (false);
  60770. }
  60771. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60772. {
  60773. for (int i = comboBoxes.size(); --i >= 0;)
  60774. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60775. return (ComboBox*) comboBoxes[i];
  60776. return 0;
  60777. }
  60778. class AlertTextComp : public TextEditor
  60779. {
  60780. public:
  60781. AlertTextComp (const String& message,
  60782. const Font& font)
  60783. {
  60784. setReadOnly (true);
  60785. setMultiLine (true, true);
  60786. setCaretVisible (false);
  60787. setScrollbarsShown (true);
  60788. lookAndFeelChanged();
  60789. setWantsKeyboardFocus (false);
  60790. setFont (font);
  60791. setText (message, false);
  60792. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60793. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60794. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60795. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60796. }
  60797. ~AlertTextComp()
  60798. {
  60799. }
  60800. int getPreferredWidth() const throw() { return bestWidth; }
  60801. void updateLayout (const int width)
  60802. {
  60803. TextLayout text;
  60804. text.appendText (getText(), getFont());
  60805. text.layout (width - 8, Justification::topLeft, true);
  60806. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60807. }
  60808. private:
  60809. int bestWidth;
  60810. AlertTextComp (const AlertTextComp&);
  60811. AlertTextComp& operator= (const AlertTextComp&);
  60812. };
  60813. void AlertWindow::addTextBlock (const String& text)
  60814. {
  60815. AlertTextComp* const c = new AlertTextComp (text, font);
  60816. textBlocks.add (c);
  60817. allComps.add (c);
  60818. addAndMakeVisible (c);
  60819. updateLayout (false);
  60820. }
  60821. void AlertWindow::addProgressBarComponent (double& progressValue)
  60822. {
  60823. ProgressBar* const pb = new ProgressBar (progressValue);
  60824. progressBars.add (pb);
  60825. allComps.add (pb);
  60826. addAndMakeVisible (pb);
  60827. updateLayout (false);
  60828. }
  60829. void AlertWindow::addCustomComponent (Component* const component)
  60830. {
  60831. customComps.add (component);
  60832. allComps.add (component);
  60833. addAndMakeVisible (component);
  60834. updateLayout (false);
  60835. }
  60836. int AlertWindow::getNumCustomComponents() const
  60837. {
  60838. return customComps.size();
  60839. }
  60840. Component* AlertWindow::getCustomComponent (const int index) const
  60841. {
  60842. return (Component*) customComps [index];
  60843. }
  60844. Component* AlertWindow::removeCustomComponent (const int index)
  60845. {
  60846. Component* const c = getCustomComponent (index);
  60847. if (c != 0)
  60848. {
  60849. customComps.removeValue (c);
  60850. allComps.removeValue (c);
  60851. removeChildComponent (c);
  60852. updateLayout (false);
  60853. }
  60854. return c;
  60855. }
  60856. void AlertWindow::paint (Graphics& g)
  60857. {
  60858. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60859. g.setColour (findColour (textColourId));
  60860. g.setFont (getLookAndFeel().getAlertWindowFont());
  60861. int i;
  60862. for (i = textBoxes.size(); --i >= 0;)
  60863. {
  60864. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60865. g.drawFittedText (textboxNames[i],
  60866. te->getX(), te->getY() - 14,
  60867. te->getWidth(), 14,
  60868. Justification::centredLeft, 1);
  60869. }
  60870. for (i = comboBoxNames.size(); --i >= 0;)
  60871. {
  60872. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60873. g.drawFittedText (comboBoxNames[i],
  60874. cb->getX(), cb->getY() - 14,
  60875. cb->getWidth(), 14,
  60876. Justification::centredLeft, 1);
  60877. }
  60878. for (i = customComps.size(); --i >= 0;)
  60879. {
  60880. const Component* const c = (Component*) customComps[i];
  60881. g.drawFittedText (c->getName(),
  60882. c->getX(), c->getY() - 14,
  60883. c->getWidth(), 14,
  60884. Justification::centredLeft, 1);
  60885. }
  60886. }
  60887. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  60888. {
  60889. const int wid = jmax (font.getStringWidth (text),
  60890. font.getStringWidth (getName()));
  60891. const int sw = (int) sqrt (font.getHeight() * wid);
  60892. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  60893. const int edgeGap = 10;
  60894. const int labelHeight = 18;
  60895. int iconSpace;
  60896. if (alertIconType == NoIcon)
  60897. {
  60898. textLayout.layout (w, Justification::horizontallyCentred, true);
  60899. iconSpace = 0;
  60900. }
  60901. else
  60902. {
  60903. textLayout.layout (w, Justification::left, true);
  60904. iconSpace = iconWidth;
  60905. }
  60906. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  60907. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60908. const int textLayoutH = textLayout.getHeight();
  60909. const int textBottom = 16 + titleH + textLayoutH;
  60910. int h = textBottom;
  60911. int buttonW = 40;
  60912. int i;
  60913. for (i = 0; i < buttons.size(); ++i)
  60914. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  60915. w = jmax (buttonW, w);
  60916. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  60917. if (buttons.size() > 0)
  60918. h += 20 + ((TextButton*) buttons[0])->getHeight();
  60919. for (i = customComps.size(); --i >= 0;)
  60920. {
  60921. Component* c = (Component*) customComps[i];
  60922. w = jmax (w, (c->getWidth() * 100) / 80);
  60923. h += 10 + c->getHeight();
  60924. if (c->getName().isNotEmpty())
  60925. h += labelHeight;
  60926. }
  60927. for (i = textBlocks.size(); --i >= 0;)
  60928. {
  60929. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60930. w = jmax (w, ac->getPreferredWidth());
  60931. }
  60932. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60933. for (i = textBlocks.size(); --i >= 0;)
  60934. {
  60935. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60936. ac->updateLayout ((int) (w * 0.8f));
  60937. h += ac->getHeight() + 10;
  60938. }
  60939. h = jmin (getParentHeight() - 50, h);
  60940. if (onlyIncreaseSize)
  60941. {
  60942. w = jmax (w, getWidth());
  60943. h = jmax (h, getHeight());
  60944. }
  60945. if (! isVisible())
  60946. {
  60947. centreAroundComponent (associatedComponent, w, h);
  60948. }
  60949. else
  60950. {
  60951. const int cx = getX() + getWidth() / 2;
  60952. const int cy = getY() + getHeight() / 2;
  60953. setBounds (cx - w / 2,
  60954. cy - h / 2,
  60955. w, h);
  60956. }
  60957. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  60958. const int spacer = 16;
  60959. int totalWidth = -spacer;
  60960. for (i = buttons.size(); --i >= 0;)
  60961. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  60962. int x = (w - totalWidth) / 2;
  60963. int y = (int) (getHeight() * 0.95f);
  60964. for (i = 0; i < buttons.size(); ++i)
  60965. {
  60966. TextButton* const c = (TextButton*) buttons[i];
  60967. int ny = proportionOfHeight (0.95f) - c->getHeight();
  60968. c->setTopLeftPosition (x, ny);
  60969. if (ny < y)
  60970. y = ny;
  60971. x += c->getWidth() + spacer;
  60972. c->toFront (false);
  60973. }
  60974. y = textBottom;
  60975. for (i = 0; i < allComps.size(); ++i)
  60976. {
  60977. Component* const c = (Component*) allComps[i];
  60978. int h = 22;
  60979. const int comboIndex = comboBoxes.indexOf (c);
  60980. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  60981. y += labelHeight;
  60982. const int tbIndex = textBoxes.indexOf (c);
  60983. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  60984. y += labelHeight;
  60985. if (customComps.contains (c))
  60986. {
  60987. if (c->getName().isNotEmpty())
  60988. y += labelHeight;
  60989. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  60990. h = c->getHeight();
  60991. }
  60992. else if (textBlocks.contains (c))
  60993. {
  60994. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  60995. h = c->getHeight();
  60996. }
  60997. else
  60998. {
  60999. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61000. }
  61001. y += h + 10;
  61002. }
  61003. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61004. }
  61005. bool AlertWindow::containsAnyExtraComponents() const
  61006. {
  61007. return textBoxes.size()
  61008. + comboBoxes.size()
  61009. + progressBars.size()
  61010. + customComps.size() > 0;
  61011. }
  61012. void AlertWindow::mouseDown (const MouseEvent&)
  61013. {
  61014. dragger.startDraggingComponent (this, &constrainer);
  61015. }
  61016. void AlertWindow::mouseDrag (const MouseEvent& e)
  61017. {
  61018. dragger.dragComponent (this, e);
  61019. }
  61020. bool AlertWindow::keyPressed (const KeyPress& key)
  61021. {
  61022. for (int i = buttons.size(); --i >= 0;)
  61023. {
  61024. TextButton* const b = (TextButton*) buttons[i];
  61025. if (b->isRegisteredForShortcut (key))
  61026. {
  61027. b->triggerClick();
  61028. return true;
  61029. }
  61030. }
  61031. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61032. {
  61033. exitModalState (0);
  61034. return true;
  61035. }
  61036. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61037. {
  61038. ((TextButton*) buttons.getFirst())->triggerClick();
  61039. return true;
  61040. }
  61041. return false;
  61042. }
  61043. void AlertWindow::lookAndFeelChanged()
  61044. {
  61045. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61046. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61047. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61048. }
  61049. int AlertWindow::getDesktopWindowStyleFlags() const
  61050. {
  61051. return getLookAndFeel().getAlertBoxWindowFlags();
  61052. }
  61053. struct AlertWindowInfo
  61054. {
  61055. String title, message, button1, button2, button3;
  61056. AlertWindow::AlertIconType iconType;
  61057. int numButtons;
  61058. Component::SafePointer<Component> associatedComponent;
  61059. int run() const
  61060. {
  61061. return (int) (pointer_sized_int)
  61062. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61063. }
  61064. private:
  61065. int show() const
  61066. {
  61067. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61068. : LookAndFeel::getDefaultLookAndFeel();
  61069. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61070. iconType, numButtons, associatedComponent));
  61071. jassert (alertBox != 0); // you have to return one of these!
  61072. return alertBox->runModalLoop();
  61073. }
  61074. static void* showCallback (void* userData)
  61075. {
  61076. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61077. }
  61078. };
  61079. void AlertWindow::showMessageBox (AlertIconType iconType,
  61080. const String& title,
  61081. const String& message,
  61082. const String& buttonText,
  61083. Component* associatedComponent)
  61084. {
  61085. AlertWindowInfo info;
  61086. info.title = title;
  61087. info.message = message;
  61088. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61089. info.iconType = iconType;
  61090. info.numButtons = 1;
  61091. info.associatedComponent = associatedComponent;
  61092. info.run();
  61093. }
  61094. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61095. const String& title,
  61096. const String& message,
  61097. const String& button1Text,
  61098. const String& button2Text,
  61099. Component* associatedComponent)
  61100. {
  61101. AlertWindowInfo info;
  61102. info.title = title;
  61103. info.message = message;
  61104. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61105. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61106. info.iconType = iconType;
  61107. info.numButtons = 2;
  61108. info.associatedComponent = associatedComponent;
  61109. return info.run() != 0;
  61110. }
  61111. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61112. const String& title,
  61113. const String& message,
  61114. const String& button1Text,
  61115. const String& button2Text,
  61116. const String& button3Text,
  61117. Component* associatedComponent)
  61118. {
  61119. AlertWindowInfo info;
  61120. info.title = title;
  61121. info.message = message;
  61122. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61123. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61124. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61125. info.iconType = iconType;
  61126. info.numButtons = 3;
  61127. info.associatedComponent = associatedComponent;
  61128. return info.run();
  61129. }
  61130. END_JUCE_NAMESPACE
  61131. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61132. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61133. BEGIN_JUCE_NAMESPACE
  61134. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61135. static VoidArray heavyweightPeers;
  61136. ComponentPeer::ComponentPeer (Component* const component_,
  61137. const int styleFlags_) throw()
  61138. : component (component_),
  61139. styleFlags (styleFlags_),
  61140. lastPaintTime (0),
  61141. constrainer (0),
  61142. lastDragAndDropCompUnderMouse (0),
  61143. fakeMouseMessageSent (false),
  61144. isWindowMinimised (false)
  61145. {
  61146. heavyweightPeers.add (this);
  61147. }
  61148. ComponentPeer::~ComponentPeer()
  61149. {
  61150. heavyweightPeers.removeValue (this);
  61151. Desktop::getInstance().triggerFocusCallback();
  61152. }
  61153. int ComponentPeer::getNumPeers() throw()
  61154. {
  61155. return heavyweightPeers.size();
  61156. }
  61157. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61158. {
  61159. return (ComponentPeer*) heavyweightPeers [index];
  61160. }
  61161. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61162. {
  61163. for (int i = heavyweightPeers.size(); --i >= 0;)
  61164. {
  61165. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61166. if (peer->getComponent() == component)
  61167. return peer;
  61168. }
  61169. return 0;
  61170. }
  61171. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61172. {
  61173. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61174. }
  61175. void ComponentPeer::updateCurrentModifiers() throw()
  61176. {
  61177. ModifierKeys::updateCurrentModifiers();
  61178. }
  61179. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61180. {
  61181. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61182. jassert (mouse != 0); // not enough sources!
  61183. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61184. }
  61185. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61186. {
  61187. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61188. jassert (mouse != 0); // not enough sources!
  61189. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61190. }
  61191. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61192. {
  61193. Graphics g (&contextToPaintTo);
  61194. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61195. g.saveState();
  61196. #endif
  61197. JUCE_TRY
  61198. {
  61199. component->paintEntireComponent (g);
  61200. }
  61201. JUCE_CATCH_EXCEPTION
  61202. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61203. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61204. // clearly when things are being repainted.
  61205. {
  61206. g.restoreState();
  61207. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61208. (uint8) Random::getSystemRandom().nextInt (255),
  61209. (uint8) Random::getSystemRandom().nextInt (255),
  61210. (uint8) 0x50));
  61211. }
  61212. #endif
  61213. }
  61214. bool ComponentPeer::handleKeyPress (const int keyCode,
  61215. const juce_wchar textCharacter)
  61216. {
  61217. updateCurrentModifiers();
  61218. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61219. ? Component::getCurrentlyFocusedComponent()
  61220. : component;
  61221. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61222. {
  61223. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61224. if (currentModalComp != 0)
  61225. target = currentModalComp;
  61226. }
  61227. const KeyPress keyInfo (keyCode,
  61228. ModifierKeys::getCurrentModifiers().getRawFlags()
  61229. & ModifierKeys::allKeyboardModifiers,
  61230. textCharacter);
  61231. bool keyWasUsed = false;
  61232. while (target != 0)
  61233. {
  61234. const Component::SafePointer<Component> deletionChecker (target);
  61235. if (target->keyListeners_ != 0)
  61236. {
  61237. for (int i = target->keyListeners_->size(); --i >= 0;)
  61238. {
  61239. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61240. if (keyWasUsed || deletionChecker == 0)
  61241. return keyWasUsed;
  61242. i = jmin (i, target->keyListeners_->size());
  61243. }
  61244. }
  61245. keyWasUsed = target->keyPressed (keyInfo);
  61246. if (keyWasUsed || deletionChecker == 0)
  61247. break;
  61248. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61249. {
  61250. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61251. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61252. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61253. break;
  61254. }
  61255. target = target->parentComponent_;
  61256. }
  61257. return keyWasUsed;
  61258. }
  61259. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61260. {
  61261. updateCurrentModifiers();
  61262. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61263. ? Component::getCurrentlyFocusedComponent()
  61264. : component;
  61265. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61266. {
  61267. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61268. if (currentModalComp != 0)
  61269. target = currentModalComp;
  61270. }
  61271. bool keyWasUsed = false;
  61272. while (target != 0)
  61273. {
  61274. const Component::SafePointer<Component> deletionChecker (target);
  61275. keyWasUsed = target->keyStateChanged (isKeyDown);
  61276. if (keyWasUsed || deletionChecker == 0)
  61277. break;
  61278. if (target->keyListeners_ != 0)
  61279. {
  61280. for (int i = target->keyListeners_->size(); --i >= 0;)
  61281. {
  61282. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61283. if (keyWasUsed || deletionChecker == 0)
  61284. return keyWasUsed;
  61285. i = jmin (i, target->keyListeners_->size());
  61286. }
  61287. }
  61288. target = target->parentComponent_;
  61289. }
  61290. return keyWasUsed;
  61291. }
  61292. void ComponentPeer::handleModifierKeysChange()
  61293. {
  61294. updateCurrentModifiers();
  61295. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61296. if (target == 0)
  61297. target = Component::getCurrentlyFocusedComponent();
  61298. if (target == 0)
  61299. target = component;
  61300. if (target != 0)
  61301. target->internalModifierKeysChanged();
  61302. }
  61303. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61304. {
  61305. Component* const c = Component::getCurrentlyFocusedComponent();
  61306. if (component->isParentOf (c))
  61307. return dynamic_cast <TextInputTarget*> (c);
  61308. return 0;
  61309. }
  61310. void ComponentPeer::handleBroughtToFront()
  61311. {
  61312. updateCurrentModifiers();
  61313. if (component != 0)
  61314. component->internalBroughtToFront();
  61315. }
  61316. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61317. {
  61318. constrainer = newConstrainer;
  61319. }
  61320. void ComponentPeer::handleMovedOrResized()
  61321. {
  61322. jassert (component->isValidComponent());
  61323. updateCurrentModifiers();
  61324. const bool nowMinimised = isMinimised();
  61325. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61326. {
  61327. const Component::SafePointer<Component> deletionChecker (component);
  61328. const Rectangle<int> newBounds (getBounds());
  61329. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61330. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61331. if (wasMoved || wasResized)
  61332. {
  61333. component->bounds_ = newBounds;
  61334. if (wasResized)
  61335. component->repaint();
  61336. component->sendMovedResizedMessages (wasMoved, wasResized);
  61337. if (deletionChecker == 0)
  61338. return;
  61339. }
  61340. }
  61341. if (isWindowMinimised != nowMinimised)
  61342. {
  61343. isWindowMinimised = nowMinimised;
  61344. component->minimisationStateChanged (nowMinimised);
  61345. component->sendVisibilityChangeMessage();
  61346. }
  61347. if (! isFullScreen())
  61348. lastNonFullscreenBounds = component->getBounds();
  61349. }
  61350. void ComponentPeer::handleFocusGain()
  61351. {
  61352. updateCurrentModifiers();
  61353. if (component->isParentOf (lastFocusedComponent))
  61354. {
  61355. Component::currentlyFocusedComponent = lastFocusedComponent;
  61356. Desktop::getInstance().triggerFocusCallback();
  61357. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61358. }
  61359. else
  61360. {
  61361. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61362. component->grabKeyboardFocus();
  61363. else
  61364. Component::bringModalComponentToFront();
  61365. }
  61366. }
  61367. void ComponentPeer::handleFocusLoss()
  61368. {
  61369. updateCurrentModifiers();
  61370. if (component->hasKeyboardFocus (true))
  61371. {
  61372. lastFocusedComponent = Component::currentlyFocusedComponent;
  61373. if (lastFocusedComponent != 0)
  61374. {
  61375. Component::currentlyFocusedComponent = 0;
  61376. Desktop::getInstance().triggerFocusCallback();
  61377. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61378. }
  61379. }
  61380. }
  61381. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61382. {
  61383. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61384. ? static_cast <Component*> (lastFocusedComponent)
  61385. : component;
  61386. }
  61387. void ComponentPeer::handleScreenSizeChange()
  61388. {
  61389. updateCurrentModifiers();
  61390. component->parentSizeChanged();
  61391. handleMovedOrResized();
  61392. }
  61393. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61394. {
  61395. lastNonFullscreenBounds = newBounds;
  61396. }
  61397. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61398. {
  61399. return lastNonFullscreenBounds;
  61400. }
  61401. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61402. const StringArray& files,
  61403. FileDragAndDropTarget* const lastOne)
  61404. {
  61405. while (c != 0)
  61406. {
  61407. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61408. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61409. return t;
  61410. c = c->getParentComponent();
  61411. }
  61412. return 0;
  61413. }
  61414. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61415. {
  61416. updateCurrentModifiers();
  61417. FileDragAndDropTarget* lastTarget
  61418. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61419. FileDragAndDropTarget* newTarget = 0;
  61420. Component* const compUnderMouse = component->getComponentAt (position);
  61421. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61422. {
  61423. lastDragAndDropCompUnderMouse = compUnderMouse;
  61424. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61425. if (newTarget != lastTarget)
  61426. {
  61427. if (lastTarget != 0)
  61428. lastTarget->fileDragExit (files);
  61429. dragAndDropTargetComponent = 0;
  61430. if (newTarget != 0)
  61431. {
  61432. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61433. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61434. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61435. }
  61436. }
  61437. }
  61438. else
  61439. {
  61440. newTarget = lastTarget;
  61441. }
  61442. if (newTarget != 0)
  61443. {
  61444. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61445. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61446. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61447. }
  61448. }
  61449. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61450. {
  61451. handleFileDragMove (files, Point<int> (-1, -1));
  61452. jassert (dragAndDropTargetComponent == 0);
  61453. lastDragAndDropCompUnderMouse = 0;
  61454. }
  61455. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61456. {
  61457. handleFileDragMove (files, position);
  61458. if (dragAndDropTargetComponent != 0)
  61459. {
  61460. FileDragAndDropTarget* const target
  61461. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61462. dragAndDropTargetComponent = 0;
  61463. lastDragAndDropCompUnderMouse = 0;
  61464. if (target != 0)
  61465. {
  61466. Component* const targetComp = dynamic_cast <Component*> (target);
  61467. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61468. {
  61469. targetComp->internalModalInputAttempt();
  61470. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61471. return;
  61472. }
  61473. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61474. target->filesDropped (files, pos.getX(), pos.getY());
  61475. }
  61476. }
  61477. }
  61478. void ComponentPeer::handleUserClosingWindow()
  61479. {
  61480. updateCurrentModifiers();
  61481. component->userTriedToCloseWindow();
  61482. }
  61483. void ComponentPeer::bringModalComponentToFront()
  61484. {
  61485. Component::bringModalComponentToFront();
  61486. }
  61487. void ComponentPeer::clearMaskedRegion() throw()
  61488. {
  61489. maskedRegion.clear();
  61490. }
  61491. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61492. {
  61493. maskedRegion.add (x, y, w, h);
  61494. }
  61495. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61496. {
  61497. StringArray s;
  61498. s.add ("Software Renderer");
  61499. return s;
  61500. }
  61501. int ComponentPeer::getCurrentRenderingEngine() throw()
  61502. {
  61503. return 0;
  61504. }
  61505. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61506. {
  61507. }
  61508. END_JUCE_NAMESPACE
  61509. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61510. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61511. BEGIN_JUCE_NAMESPACE
  61512. DialogWindow::DialogWindow (const String& name,
  61513. const Colour& backgroundColour_,
  61514. const bool escapeKeyTriggersCloseButton_,
  61515. const bool addToDesktop_)
  61516. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61517. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61518. {
  61519. }
  61520. DialogWindow::~DialogWindow()
  61521. {
  61522. }
  61523. void DialogWindow::resized()
  61524. {
  61525. DocumentWindow::resized();
  61526. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61527. if (escapeKeyTriggersCloseButton
  61528. && getCloseButton() != 0
  61529. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61530. {
  61531. getCloseButton()->addShortcut (esc);
  61532. }
  61533. }
  61534. class TempDialogWindow : public DialogWindow
  61535. {
  61536. public:
  61537. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61538. : DialogWindow (title, colour, escapeCloses, true)
  61539. {
  61540. }
  61541. ~TempDialogWindow()
  61542. {
  61543. }
  61544. void closeButtonPressed()
  61545. {
  61546. setVisible (false);
  61547. }
  61548. private:
  61549. TempDialogWindow (const TempDialogWindow&);
  61550. TempDialogWindow& operator= (const TempDialogWindow&);
  61551. };
  61552. int DialogWindow::showModalDialog (const String& dialogTitle,
  61553. Component* contentComponent,
  61554. Component* componentToCentreAround,
  61555. const Colour& colour,
  61556. const bool escapeKeyTriggersCloseButton,
  61557. const bool shouldBeResizable,
  61558. const bool useBottomRightCornerResizer)
  61559. {
  61560. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61561. dw.setContentComponent (contentComponent, true, true);
  61562. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61563. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61564. const int result = dw.runModalLoop();
  61565. dw.setContentComponent (0, false);
  61566. return result;
  61567. }
  61568. END_JUCE_NAMESPACE
  61569. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61570. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61571. BEGIN_JUCE_NAMESPACE
  61572. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61573. {
  61574. public:
  61575. ButtonListenerProxy (DocumentWindow& owner_)
  61576. : owner (owner_)
  61577. {
  61578. }
  61579. void buttonClicked (Button* button)
  61580. {
  61581. if (button == owner.getMinimiseButton())
  61582. owner.minimiseButtonPressed();
  61583. else if (button == owner.getMaximiseButton())
  61584. owner.maximiseButtonPressed();
  61585. else if (button == owner.getCloseButton())
  61586. owner.closeButtonPressed();
  61587. }
  61588. juce_UseDebuggingNewOperator
  61589. private:
  61590. DocumentWindow& owner;
  61591. ButtonListenerProxy (const ButtonListenerProxy&);
  61592. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61593. };
  61594. DocumentWindow::DocumentWindow (const String& title,
  61595. const Colour& backgroundColour,
  61596. const int requiredButtons_,
  61597. const bool addToDesktop_)
  61598. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61599. titleBarHeight (26),
  61600. menuBarHeight (24),
  61601. requiredButtons (requiredButtons_),
  61602. #if JUCE_MAC
  61603. positionTitleBarButtonsOnLeft (true),
  61604. #else
  61605. positionTitleBarButtonsOnLeft (false),
  61606. #endif
  61607. drawTitleTextCentred (true),
  61608. menuBarModel (0)
  61609. {
  61610. setResizeLimits (128, 128, 32768, 32768);
  61611. lookAndFeelChanged();
  61612. }
  61613. DocumentWindow::~DocumentWindow()
  61614. {
  61615. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61616. titleBarButtons[i] = 0;
  61617. menuBar = 0;
  61618. }
  61619. void DocumentWindow::repaintTitleBar()
  61620. {
  61621. const Rectangle<int> titleBarArea (getTitleBarArea());
  61622. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61623. titleBarArea.getWidth(), titleBarArea.getHeight());
  61624. }
  61625. void DocumentWindow::setName (const String& newName)
  61626. {
  61627. if (newName != getName())
  61628. {
  61629. Component::setName (newName);
  61630. repaintTitleBar();
  61631. }
  61632. }
  61633. void DocumentWindow::setIcon (const Image* imageToUse)
  61634. {
  61635. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61636. repaintTitleBar();
  61637. }
  61638. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61639. {
  61640. titleBarHeight = newHeight;
  61641. resized();
  61642. repaintTitleBar();
  61643. }
  61644. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61645. const bool positionTitleBarButtonsOnLeft_)
  61646. {
  61647. requiredButtons = requiredButtons_;
  61648. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61649. lookAndFeelChanged();
  61650. }
  61651. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61652. {
  61653. drawTitleTextCentred = textShouldBeCentred;
  61654. repaintTitleBar();
  61655. }
  61656. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61657. const int menuBarHeight_)
  61658. {
  61659. if (menuBarModel != menuBarModel_)
  61660. {
  61661. menuBar = 0;
  61662. menuBarModel = menuBarModel_;
  61663. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61664. : getLookAndFeel().getDefaultMenuBarHeight();
  61665. if (menuBarModel != 0)
  61666. {
  61667. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61668. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61669. menuBar->setEnabled (isActiveWindow());
  61670. }
  61671. resized();
  61672. }
  61673. }
  61674. void DocumentWindow::closeButtonPressed()
  61675. {
  61676. /* If you've got a close button, you have to override this method to get
  61677. rid of your window!
  61678. If the window is just a pop-up, you should override this method and make
  61679. it delete the window in whatever way is appropriate for your app. E.g. you
  61680. might just want to call "delete this".
  61681. If your app is centred around this window such that the whole app should quit when
  61682. the window is closed, then you will probably want to use this method as an opportunity
  61683. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61684. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61685. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61686. or closing it via the taskbar icon on Windows).
  61687. */
  61688. jassertfalse
  61689. }
  61690. void DocumentWindow::minimiseButtonPressed()
  61691. {
  61692. setMinimised (true);
  61693. }
  61694. void DocumentWindow::maximiseButtonPressed()
  61695. {
  61696. setFullScreen (! isFullScreen());
  61697. }
  61698. void DocumentWindow::paint (Graphics& g)
  61699. {
  61700. ResizableWindow::paint (g);
  61701. if (resizableBorder == 0)
  61702. {
  61703. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61704. const BorderSize border (getBorderThickness());
  61705. g.fillRect (0, 0, getWidth(), border.getTop());
  61706. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61707. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61708. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61709. }
  61710. const Rectangle<int> titleBarArea (getTitleBarArea());
  61711. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61712. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61713. int titleSpaceX1 = 6;
  61714. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61715. for (int i = 0; i < 3; ++i)
  61716. {
  61717. if (titleBarButtons[i] != 0)
  61718. {
  61719. if (positionTitleBarButtonsOnLeft)
  61720. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61721. else
  61722. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61723. }
  61724. }
  61725. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61726. titleBarArea.getWidth(),
  61727. titleBarArea.getHeight(),
  61728. titleSpaceX1,
  61729. jmax (1, titleSpaceX2 - titleSpaceX1),
  61730. titleBarIcon,
  61731. ! drawTitleTextCentred);
  61732. }
  61733. void DocumentWindow::resized()
  61734. {
  61735. ResizableWindow::resized();
  61736. if (titleBarButtons[1] != 0)
  61737. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61738. const Rectangle<int> titleBarArea (getTitleBarArea());
  61739. getLookAndFeel()
  61740. .positionDocumentWindowButtons (*this,
  61741. titleBarArea.getX(), titleBarArea.getY(),
  61742. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61743. titleBarButtons[0],
  61744. titleBarButtons[1],
  61745. titleBarButtons[2],
  61746. positionTitleBarButtonsOnLeft);
  61747. if (menuBar != 0)
  61748. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61749. titleBarArea.getWidth(), menuBarHeight);
  61750. }
  61751. const BorderSize DocumentWindow::getBorderThickness()
  61752. {
  61753. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61754. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61755. }
  61756. const BorderSize DocumentWindow::getContentComponentBorder()
  61757. {
  61758. BorderSize border (getBorderThickness());
  61759. border.setTop (border.getTop()
  61760. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61761. + (menuBar != 0 ? menuBarHeight : 0));
  61762. return border;
  61763. }
  61764. int DocumentWindow::getTitleBarHeight() const
  61765. {
  61766. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61767. }
  61768. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61769. {
  61770. const BorderSize border (getBorderThickness());
  61771. return Rectangle<int> (border.getLeft(), border.getTop(),
  61772. getWidth() - border.getLeftAndRight(),
  61773. getTitleBarHeight());
  61774. }
  61775. Button* DocumentWindow::getCloseButton() const throw()
  61776. {
  61777. return titleBarButtons[2];
  61778. }
  61779. Button* DocumentWindow::getMinimiseButton() const throw()
  61780. {
  61781. return titleBarButtons[0];
  61782. }
  61783. Button* DocumentWindow::getMaximiseButton() const throw()
  61784. {
  61785. return titleBarButtons[1];
  61786. }
  61787. int DocumentWindow::getDesktopWindowStyleFlags() const
  61788. {
  61789. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61790. if ((requiredButtons & minimiseButton) != 0)
  61791. flags |= ComponentPeer::windowHasMinimiseButton;
  61792. if ((requiredButtons & maximiseButton) != 0)
  61793. flags |= ComponentPeer::windowHasMaximiseButton;
  61794. if ((requiredButtons & closeButton) != 0)
  61795. flags |= ComponentPeer::windowHasCloseButton;
  61796. return flags;
  61797. }
  61798. void DocumentWindow::lookAndFeelChanged()
  61799. {
  61800. int i;
  61801. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61802. titleBarButtons[i] = 0;
  61803. if (! isUsingNativeTitleBar())
  61804. {
  61805. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61806. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61807. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61808. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61809. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61810. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61811. for (i = 0; i < 3; ++i)
  61812. {
  61813. if (titleBarButtons[i] != 0)
  61814. {
  61815. if (buttonListener == 0)
  61816. buttonListener = new ButtonListenerProxy (*this);
  61817. titleBarButtons[i]->addButtonListener (buttonListener);
  61818. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61819. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61820. Component::addAndMakeVisible (titleBarButtons[i]);
  61821. }
  61822. }
  61823. if (getCloseButton() != 0)
  61824. {
  61825. #if JUCE_MAC
  61826. getCloseButton()->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
  61827. #else
  61828. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61829. #endif
  61830. }
  61831. }
  61832. activeWindowStatusChanged();
  61833. ResizableWindow::lookAndFeelChanged();
  61834. }
  61835. void DocumentWindow::parentHierarchyChanged()
  61836. {
  61837. lookAndFeelChanged();
  61838. }
  61839. void DocumentWindow::activeWindowStatusChanged()
  61840. {
  61841. ResizableWindow::activeWindowStatusChanged();
  61842. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61843. if (titleBarButtons[i] != 0)
  61844. titleBarButtons[i]->setEnabled (isActiveWindow());
  61845. if (menuBar != 0)
  61846. menuBar->setEnabled (isActiveWindow());
  61847. }
  61848. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61849. {
  61850. if (getTitleBarArea().contains (e.x, e.y)
  61851. && getMaximiseButton() != 0)
  61852. {
  61853. getMaximiseButton()->triggerClick();
  61854. }
  61855. }
  61856. void DocumentWindow::userTriedToCloseWindow()
  61857. {
  61858. closeButtonPressed();
  61859. }
  61860. END_JUCE_NAMESPACE
  61861. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61862. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61863. BEGIN_JUCE_NAMESPACE
  61864. ResizableWindow::ResizableWindow (const String& name,
  61865. const bool addToDesktop_)
  61866. : TopLevelWindow (name, addToDesktop_),
  61867. resizeToFitContent (false),
  61868. fullscreen (false),
  61869. lastNonFullScreenPos (50, 50, 256, 256),
  61870. constrainer (0)
  61871. #ifdef JUCE_DEBUG
  61872. , hasBeenResized (false)
  61873. #endif
  61874. {
  61875. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61876. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61877. if (addToDesktop_)
  61878. Component::addToDesktop (getDesktopWindowStyleFlags());
  61879. }
  61880. ResizableWindow::ResizableWindow (const String& name,
  61881. const Colour& backgroundColour_,
  61882. const bool addToDesktop_)
  61883. : TopLevelWindow (name, addToDesktop_),
  61884. resizeToFitContent (false),
  61885. fullscreen (false),
  61886. lastNonFullScreenPos (50, 50, 256, 256),
  61887. constrainer (0)
  61888. #ifdef JUCE_DEBUG
  61889. , hasBeenResized (false)
  61890. #endif
  61891. {
  61892. setBackgroundColour (backgroundColour_);
  61893. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61894. if (addToDesktop_)
  61895. Component::addToDesktop (getDesktopWindowStyleFlags());
  61896. }
  61897. ResizableWindow::~ResizableWindow()
  61898. {
  61899. resizableCorner = 0;
  61900. resizableBorder = 0;
  61901. contentComponent = 0;
  61902. // have you been adding your own components directly to this window..? tut tut tut.
  61903. // Read the instructions for using a ResizableWindow!
  61904. jassert (getNumChildComponents() == 0);
  61905. }
  61906. int ResizableWindow::getDesktopWindowStyleFlags() const
  61907. {
  61908. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  61909. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  61910. flags |= ComponentPeer::windowIsResizable;
  61911. return flags;
  61912. }
  61913. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  61914. const bool deleteOldOne,
  61915. const bool resizeToFit)
  61916. {
  61917. resizeToFitContent = resizeToFit;
  61918. if (newContentComponent != static_cast <Component*> (contentComponent))
  61919. {
  61920. if (! deleteOldOne)
  61921. removeChildComponent (contentComponent.release());
  61922. contentComponent = newContentComponent;
  61923. Component::addAndMakeVisible (contentComponent);
  61924. }
  61925. if (resizeToFit)
  61926. childBoundsChanged (contentComponent);
  61927. resized(); // must always be called to position the new content comp
  61928. }
  61929. void ResizableWindow::setContentComponentSize (int width, int height)
  61930. {
  61931. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  61932. const BorderSize border (getContentComponentBorder());
  61933. setSize (width + border.getLeftAndRight(),
  61934. height + border.getTopAndBottom());
  61935. }
  61936. const BorderSize ResizableWindow::getBorderThickness()
  61937. {
  61938. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  61939. }
  61940. const BorderSize ResizableWindow::getContentComponentBorder()
  61941. {
  61942. return getBorderThickness();
  61943. }
  61944. void ResizableWindow::moved()
  61945. {
  61946. updateLastPos();
  61947. }
  61948. void ResizableWindow::visibilityChanged()
  61949. {
  61950. TopLevelWindow::visibilityChanged();
  61951. updateLastPos();
  61952. }
  61953. void ResizableWindow::resized()
  61954. {
  61955. if (resizableBorder != 0)
  61956. {
  61957. resizableBorder->setVisible (! isFullScreen());
  61958. resizableBorder->setBorderThickness (getBorderThickness());
  61959. resizableBorder->setSize (getWidth(), getHeight());
  61960. resizableBorder->toBack();
  61961. }
  61962. if (resizableCorner != 0)
  61963. {
  61964. resizableCorner->setVisible (! isFullScreen());
  61965. const int resizerSize = 18;
  61966. resizableCorner->setBounds (getWidth() - resizerSize,
  61967. getHeight() - resizerSize,
  61968. resizerSize, resizerSize);
  61969. }
  61970. if (contentComponent != 0)
  61971. contentComponent->setBoundsInset (getContentComponentBorder());
  61972. updateLastPos();
  61973. #ifdef JUCE_DEBUG
  61974. hasBeenResized = true;
  61975. #endif
  61976. }
  61977. void ResizableWindow::childBoundsChanged (Component* child)
  61978. {
  61979. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  61980. {
  61981. // not going to look very good if this component has a zero size..
  61982. jassert (child->getWidth() > 0);
  61983. jassert (child->getHeight() > 0);
  61984. const BorderSize borders (getContentComponentBorder());
  61985. setSize (child->getWidth() + borders.getLeftAndRight(),
  61986. child->getHeight() + borders.getTopAndBottom());
  61987. }
  61988. }
  61989. void ResizableWindow::activeWindowStatusChanged()
  61990. {
  61991. const BorderSize borders (getContentComponentBorder());
  61992. repaint (0, 0, getWidth(), borders.getTop());
  61993. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  61994. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  61995. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  61996. }
  61997. void ResizableWindow::setResizable (const bool shouldBeResizable,
  61998. const bool useBottomRightCornerResizer)
  61999. {
  62000. if (shouldBeResizable)
  62001. {
  62002. if (useBottomRightCornerResizer)
  62003. {
  62004. resizableBorder = 0;
  62005. if (resizableCorner == 0)
  62006. {
  62007. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62008. resizableCorner->setAlwaysOnTop (true);
  62009. }
  62010. }
  62011. else
  62012. {
  62013. resizableCorner = 0;
  62014. if (resizableBorder == 0)
  62015. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62016. }
  62017. }
  62018. else
  62019. {
  62020. resizableCorner = 0;
  62021. resizableBorder = 0;
  62022. }
  62023. if (isUsingNativeTitleBar())
  62024. recreateDesktopWindow();
  62025. childBoundsChanged (contentComponent);
  62026. resized();
  62027. }
  62028. bool ResizableWindow::isResizable() const throw()
  62029. {
  62030. return resizableCorner != 0
  62031. || resizableBorder != 0;
  62032. }
  62033. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62034. const int newMinimumHeight,
  62035. const int newMaximumWidth,
  62036. const int newMaximumHeight) throw()
  62037. {
  62038. // if you've set up a custom constrainer then these settings won't have any effect..
  62039. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62040. if (constrainer == 0)
  62041. setConstrainer (&defaultConstrainer);
  62042. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62043. newMaximumWidth, newMaximumHeight);
  62044. setBoundsConstrained (getBounds());
  62045. }
  62046. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62047. {
  62048. if (constrainer != newConstrainer)
  62049. {
  62050. constrainer = newConstrainer;
  62051. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62052. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62053. resizableCorner = 0;
  62054. resizableBorder = 0;
  62055. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62056. ComponentPeer* const peer = getPeer();
  62057. if (peer != 0)
  62058. peer->setConstrainer (newConstrainer);
  62059. }
  62060. }
  62061. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62062. {
  62063. if (constrainer != 0)
  62064. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62065. else
  62066. setBounds (bounds);
  62067. }
  62068. void ResizableWindow::paint (Graphics& g)
  62069. {
  62070. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62071. getBorderThickness(), *this);
  62072. if (! isFullScreen())
  62073. {
  62074. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62075. getBorderThickness(), *this);
  62076. }
  62077. #ifdef JUCE_DEBUG
  62078. /* If this fails, then you've probably written a subclass with a resized()
  62079. callback but forgotten to make it call its parent class's resized() method.
  62080. It's important when you override methods like resized(), moved(),
  62081. etc., that you make sure the base class methods also get called.
  62082. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62083. because your content should all be inside the content component - and it's the
  62084. content component's resized() method that you should be using to do your
  62085. layout.
  62086. */
  62087. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62088. #endif
  62089. }
  62090. void ResizableWindow::lookAndFeelChanged()
  62091. {
  62092. resized();
  62093. if (isOnDesktop())
  62094. {
  62095. Component::addToDesktop (getDesktopWindowStyleFlags());
  62096. ComponentPeer* const peer = getPeer();
  62097. if (peer != 0)
  62098. peer->setConstrainer (constrainer);
  62099. }
  62100. }
  62101. const Colour ResizableWindow::getBackgroundColour() const throw()
  62102. {
  62103. return findColour (backgroundColourId, false);
  62104. }
  62105. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62106. {
  62107. Colour backgroundColour (newColour);
  62108. if (! Desktop::canUseSemiTransparentWindows())
  62109. backgroundColour = newColour.withAlpha (1.0f);
  62110. setColour (backgroundColourId, backgroundColour);
  62111. setOpaque (backgroundColour.isOpaque());
  62112. repaint();
  62113. }
  62114. bool ResizableWindow::isFullScreen() const
  62115. {
  62116. if (isOnDesktop())
  62117. {
  62118. ComponentPeer* const peer = getPeer();
  62119. return peer != 0 && peer->isFullScreen();
  62120. }
  62121. return fullscreen;
  62122. }
  62123. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62124. {
  62125. if (shouldBeFullScreen != isFullScreen())
  62126. {
  62127. updateLastPos();
  62128. fullscreen = shouldBeFullScreen;
  62129. if (isOnDesktop())
  62130. {
  62131. ComponentPeer* const peer = getPeer();
  62132. if (peer != 0)
  62133. {
  62134. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62135. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62136. peer->setFullScreen (shouldBeFullScreen);
  62137. if (! shouldBeFullScreen)
  62138. setBounds (lastPos);
  62139. }
  62140. else
  62141. {
  62142. jassertfalse
  62143. }
  62144. }
  62145. else
  62146. {
  62147. if (shouldBeFullScreen)
  62148. setBounds (0, 0, getParentWidth(), getParentHeight());
  62149. else
  62150. setBounds (lastNonFullScreenPos);
  62151. }
  62152. resized();
  62153. }
  62154. }
  62155. bool ResizableWindow::isMinimised() const
  62156. {
  62157. ComponentPeer* const peer = getPeer();
  62158. return (peer != 0) && peer->isMinimised();
  62159. }
  62160. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62161. {
  62162. if (shouldMinimise != isMinimised())
  62163. {
  62164. ComponentPeer* const peer = getPeer();
  62165. if (peer != 0)
  62166. {
  62167. updateLastPos();
  62168. peer->setMinimised (shouldMinimise);
  62169. }
  62170. else
  62171. {
  62172. jassertfalse
  62173. }
  62174. }
  62175. }
  62176. void ResizableWindow::updateLastPos()
  62177. {
  62178. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62179. {
  62180. lastNonFullScreenPos = getBounds();
  62181. }
  62182. }
  62183. void ResizableWindow::parentSizeChanged()
  62184. {
  62185. if (isFullScreen() && getParentComponent() != 0)
  62186. {
  62187. setBounds (0, 0, getParentWidth(), getParentHeight());
  62188. }
  62189. }
  62190. const String ResizableWindow::getWindowStateAsString()
  62191. {
  62192. updateLastPos();
  62193. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62194. }
  62195. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62196. {
  62197. StringArray tokens;
  62198. tokens.addTokens (s, false);
  62199. tokens.removeEmptyStrings();
  62200. tokens.trim();
  62201. const bool fs = tokens[0].startsWithIgnoreCase ("fs");
  62202. const int firstCoord = fs ? 1 : 0;
  62203. if (tokens.size() != firstCoord + 4)
  62204. return false;
  62205. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62206. tokens[firstCoord + 1].getIntValue(),
  62207. tokens[firstCoord + 2].getIntValue(),
  62208. tokens[firstCoord + 3].getIntValue());
  62209. if (newPos.isEmpty())
  62210. return false;
  62211. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62212. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62213. if (peer != 0)
  62214. peer->getFrameSize().addTo (newPos);
  62215. if (! screen.contains (newPos))
  62216. {
  62217. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62218. jmin (newPos.getHeight(), screen.getHeight()));
  62219. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62220. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62221. }
  62222. if (peer != 0)
  62223. {
  62224. peer->getFrameSize().subtractFrom (newPos);
  62225. peer->setNonFullScreenBounds (newPos);
  62226. }
  62227. lastNonFullScreenPos = newPos;
  62228. setFullScreen (fs);
  62229. if (! fs)
  62230. setBoundsConstrained (newPos);
  62231. return true;
  62232. }
  62233. void ResizableWindow::mouseDown (const MouseEvent&)
  62234. {
  62235. if (! isFullScreen())
  62236. dragger.startDraggingComponent (this, constrainer);
  62237. }
  62238. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62239. {
  62240. if (! isFullScreen())
  62241. dragger.dragComponent (this, e);
  62242. }
  62243. #ifdef JUCE_DEBUG
  62244. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62245. {
  62246. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62247. manages its child components automatically, and if you add your own it'll cause
  62248. trouble. Instead, use setContentComponent() to give it a component which
  62249. will be automatically resized and kept in the right place - then you can add
  62250. subcomponents to the content comp. See the notes for the ResizableWindow class
  62251. for more info.
  62252. If you really know what you're doing and want to avoid this assertion, just call
  62253. Component::addChildComponent directly.
  62254. */
  62255. jassertfalse
  62256. Component::addChildComponent (child, zOrder);
  62257. }
  62258. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62259. {
  62260. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62261. manages its child components automatically, and if you add your own it'll cause
  62262. trouble. Instead, use setContentComponent() to give it a component which
  62263. will be automatically resized and kept in the right place - then you can add
  62264. subcomponents to the content comp. See the notes for the ResizableWindow class
  62265. for more info.
  62266. If you really know what you're doing and want to avoid this assertion, just call
  62267. Component::addAndMakeVisible directly.
  62268. */
  62269. jassertfalse
  62270. Component::addAndMakeVisible (child, zOrder);
  62271. }
  62272. #endif
  62273. END_JUCE_NAMESPACE
  62274. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62275. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62276. BEGIN_JUCE_NAMESPACE
  62277. SplashScreen::SplashScreen()
  62278. : backgroundImage (0)
  62279. {
  62280. setOpaque (true);
  62281. }
  62282. SplashScreen::~SplashScreen()
  62283. {
  62284. ImageCache::releaseOrDelete (backgroundImage);
  62285. }
  62286. void SplashScreen::show (const String& title,
  62287. Image* const backgroundImage_,
  62288. const int minimumTimeToDisplayFor,
  62289. const bool useDropShadow,
  62290. const bool removeOnMouseClick)
  62291. {
  62292. backgroundImage = backgroundImage_;
  62293. jassert (backgroundImage_ != 0);
  62294. if (backgroundImage_ != 0)
  62295. {
  62296. setOpaque (! backgroundImage_->hasAlphaChannel());
  62297. show (title,
  62298. backgroundImage_->getWidth(),
  62299. backgroundImage_->getHeight(),
  62300. minimumTimeToDisplayFor,
  62301. useDropShadow,
  62302. removeOnMouseClick);
  62303. }
  62304. }
  62305. void SplashScreen::show (const String& title,
  62306. const int width,
  62307. const int height,
  62308. const int minimumTimeToDisplayFor,
  62309. const bool useDropShadow,
  62310. const bool removeOnMouseClick)
  62311. {
  62312. setName (title);
  62313. setAlwaysOnTop (true);
  62314. setVisible (true);
  62315. centreWithSize (width, height);
  62316. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62317. toFront (false);
  62318. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62319. repaint();
  62320. originalClickCounter = removeOnMouseClick
  62321. ? Desktop::getMouseButtonClickCounter()
  62322. : std::numeric_limits<int>::max();
  62323. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62324. startTimer (50);
  62325. }
  62326. void SplashScreen::paint (Graphics& g)
  62327. {
  62328. if (backgroundImage != 0)
  62329. {
  62330. g.setOpacity (1.0f);
  62331. g.drawImage (backgroundImage,
  62332. 0, 0, getWidth(), getHeight(),
  62333. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62334. }
  62335. }
  62336. void SplashScreen::timerCallback()
  62337. {
  62338. if (Time::getCurrentTime() > earliestTimeToDelete
  62339. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62340. {
  62341. delete this;
  62342. }
  62343. }
  62344. END_JUCE_NAMESPACE
  62345. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62346. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62347. BEGIN_JUCE_NAMESPACE
  62348. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62349. const bool hasProgressBar,
  62350. const bool hasCancelButton,
  62351. const int timeOutMsWhenCancelling_,
  62352. const String& cancelButtonText)
  62353. : Thread ("Juce Progress Window"),
  62354. progress (0.0),
  62355. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62356. {
  62357. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62358. .createAlertWindow (title, String::empty, cancelButtonText,
  62359. String::empty, String::empty,
  62360. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62361. if (hasProgressBar)
  62362. alertWindow->addProgressBarComponent (progress);
  62363. }
  62364. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62365. {
  62366. stopThread (timeOutMsWhenCancelling);
  62367. }
  62368. bool ThreadWithProgressWindow::runThread (const int priority)
  62369. {
  62370. startThread (priority);
  62371. startTimer (100);
  62372. {
  62373. const ScopedLock sl (messageLock);
  62374. alertWindow->setMessage (message);
  62375. }
  62376. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62377. stopThread (timeOutMsWhenCancelling);
  62378. alertWindow->setVisible (false);
  62379. return finishedNaturally;
  62380. }
  62381. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62382. {
  62383. progress = newProgress;
  62384. }
  62385. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62386. {
  62387. const ScopedLock sl (messageLock);
  62388. message = newStatusMessage;
  62389. }
  62390. void ThreadWithProgressWindow::timerCallback()
  62391. {
  62392. if (! isThreadRunning())
  62393. {
  62394. // thread has finished normally..
  62395. alertWindow->exitModalState (1);
  62396. alertWindow->setVisible (false);
  62397. }
  62398. else
  62399. {
  62400. const ScopedLock sl (messageLock);
  62401. alertWindow->setMessage (message);
  62402. }
  62403. }
  62404. END_JUCE_NAMESPACE
  62405. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62406. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62407. BEGIN_JUCE_NAMESPACE
  62408. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62409. const int millisecondsBeforeTipAppears_)
  62410. : Component ("tooltip"),
  62411. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62412. lastHideTime (0),
  62413. lastComponentUnderMouse (0),
  62414. changedCompsSinceShown (true)
  62415. {
  62416. if (Desktop::getInstance().getMainMouseSource().canHover())
  62417. startTimer (123);
  62418. setAlwaysOnTop (true);
  62419. setOpaque (true);
  62420. if (parentComponent != 0)
  62421. parentComponent->addChildComponent (this);
  62422. }
  62423. TooltipWindow::~TooltipWindow()
  62424. {
  62425. hide();
  62426. }
  62427. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62428. {
  62429. millisecondsBeforeTipAppears = newTimeMs;
  62430. }
  62431. void TooltipWindow::paint (Graphics& g)
  62432. {
  62433. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62434. }
  62435. void TooltipWindow::mouseEnter (const MouseEvent&)
  62436. {
  62437. hide();
  62438. }
  62439. void TooltipWindow::showFor (const String& tip)
  62440. {
  62441. jassert (tip.isNotEmpty());
  62442. tipShowing = tip;
  62443. Point<int> mousePos (Desktop::getMousePosition());
  62444. if (getParentComponent() != 0)
  62445. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62446. int x, y, w, h;
  62447. getLookAndFeel().getTooltipSize (tip, w, h);
  62448. if (mousePos.getX() > getParentWidth() / 2)
  62449. x = mousePos.getX() - (w + 12);
  62450. else
  62451. x = mousePos.getX() + 24;
  62452. if (mousePos.getY() > getParentHeight() / 2)
  62453. y = mousePos.getY() - (h + 6);
  62454. else
  62455. y = mousePos.getY() + 6;
  62456. setBounds (x, y, w, h);
  62457. setVisible (true);
  62458. if (getParentComponent() == 0)
  62459. {
  62460. addToDesktop (ComponentPeer::windowHasDropShadow
  62461. | ComponentPeer::windowIsTemporary
  62462. | ComponentPeer::windowIgnoresKeyPresses);
  62463. }
  62464. toFront (false);
  62465. }
  62466. const String TooltipWindow::getTipFor (Component* const c)
  62467. {
  62468. if (c != 0
  62469. && Process::isForegroundProcess()
  62470. && ! Component::isMouseButtonDownAnywhere())
  62471. {
  62472. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62473. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62474. return ttc->getTooltip();
  62475. }
  62476. return String::empty;
  62477. }
  62478. void TooltipWindow::hide()
  62479. {
  62480. tipShowing = String::empty;
  62481. removeFromDesktop();
  62482. setVisible (false);
  62483. }
  62484. void TooltipWindow::timerCallback()
  62485. {
  62486. const unsigned int now = Time::getApproximateMillisecondCounter();
  62487. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62488. const String newTip (getTipFor (newComp));
  62489. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62490. lastComponentUnderMouse = newComp;
  62491. lastTipUnderMouse = newTip;
  62492. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62493. const bool mouseWasClicked = clickCount > mouseClicks;
  62494. mouseClicks = clickCount;
  62495. const Point<int> mousePos (Desktop::getMousePosition());
  62496. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62497. lastMousePos = mousePos;
  62498. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62499. lastCompChangeTime = now;
  62500. if (isVisible() || now < lastHideTime + 500)
  62501. {
  62502. // if a tip is currently visible (or has just disappeared), update to a new one
  62503. // immediately if needed..
  62504. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62505. {
  62506. if (isVisible())
  62507. {
  62508. lastHideTime = now;
  62509. hide();
  62510. }
  62511. }
  62512. else if (tipChanged)
  62513. {
  62514. showFor (newTip);
  62515. }
  62516. }
  62517. else
  62518. {
  62519. // if there isn't currently a tip, but one is needed, only let it
  62520. // appear after a timeout..
  62521. if (newTip.isNotEmpty()
  62522. && newTip != tipShowing
  62523. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62524. {
  62525. showFor (newTip);
  62526. }
  62527. }
  62528. }
  62529. END_JUCE_NAMESPACE
  62530. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62531. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62532. BEGIN_JUCE_NAMESPACE
  62533. class TopLevelWindowManager : public Timer,
  62534. public DeletedAtShutdown
  62535. {
  62536. public:
  62537. TopLevelWindowManager()
  62538. : currentActive (0)
  62539. {
  62540. }
  62541. ~TopLevelWindowManager()
  62542. {
  62543. clearSingletonInstance();
  62544. }
  62545. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62546. void timerCallback()
  62547. {
  62548. startTimer (jmin (1731, getTimerInterval() * 2));
  62549. TopLevelWindow* active = 0;
  62550. if (Process::isForegroundProcess())
  62551. {
  62552. active = currentActive;
  62553. Component* const c = Component::getCurrentlyFocusedComponent();
  62554. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62555. if (tlw == 0 && c != 0)
  62556. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62557. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62558. if (tlw != 0)
  62559. active = tlw;
  62560. }
  62561. if (active != currentActive)
  62562. {
  62563. currentActive = active;
  62564. for (int i = windows.size(); --i >= 0;)
  62565. {
  62566. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62567. tlw->setWindowActive (isWindowActive (tlw));
  62568. i = jmin (i, windows.size() - 1);
  62569. }
  62570. Desktop::getInstance().triggerFocusCallback();
  62571. }
  62572. }
  62573. bool addWindow (TopLevelWindow* const w) throw()
  62574. {
  62575. windows.add (w);
  62576. startTimer (10);
  62577. return isWindowActive (w);
  62578. }
  62579. void removeWindow (TopLevelWindow* const w) throw()
  62580. {
  62581. startTimer (10);
  62582. if (currentActive == w)
  62583. currentActive = 0;
  62584. windows.removeValue (w);
  62585. if (windows.size() == 0)
  62586. deleteInstance();
  62587. }
  62588. VoidArray windows;
  62589. private:
  62590. TopLevelWindow* currentActive;
  62591. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62592. {
  62593. return (tlw == currentActive
  62594. || tlw->isParentOf (currentActive)
  62595. || tlw->hasKeyboardFocus (true))
  62596. && tlw->isShowing();
  62597. }
  62598. TopLevelWindowManager (const TopLevelWindowManager&);
  62599. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62600. };
  62601. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62602. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62603. {
  62604. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62605. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62606. }
  62607. TopLevelWindow::TopLevelWindow (const String& name,
  62608. const bool addToDesktop_)
  62609. : Component (name),
  62610. useDropShadow (true),
  62611. useNativeTitleBar (false),
  62612. windowIsActive_ (false)
  62613. {
  62614. setOpaque (true);
  62615. if (addToDesktop_)
  62616. Component::addToDesktop (getDesktopWindowStyleFlags());
  62617. else
  62618. setDropShadowEnabled (true);
  62619. setWantsKeyboardFocus (true);
  62620. setBroughtToFrontOnMouseClick (true);
  62621. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62622. }
  62623. TopLevelWindow::~TopLevelWindow()
  62624. {
  62625. shadower = 0;
  62626. TopLevelWindowManager::getInstance()->removeWindow (this);
  62627. }
  62628. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62629. {
  62630. if (hasKeyboardFocus (true))
  62631. TopLevelWindowManager::getInstance()->timerCallback();
  62632. else
  62633. TopLevelWindowManager::getInstance()->startTimer (10);
  62634. }
  62635. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62636. {
  62637. if (windowIsActive_ != isNowActive)
  62638. {
  62639. windowIsActive_ = isNowActive;
  62640. activeWindowStatusChanged();
  62641. }
  62642. }
  62643. void TopLevelWindow::activeWindowStatusChanged()
  62644. {
  62645. }
  62646. void TopLevelWindow::parentHierarchyChanged()
  62647. {
  62648. setDropShadowEnabled (useDropShadow);
  62649. }
  62650. void TopLevelWindow::visibilityChanged()
  62651. {
  62652. if (isShowing())
  62653. toFront (true);
  62654. }
  62655. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62656. {
  62657. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62658. if (useDropShadow)
  62659. flags |= ComponentPeer::windowHasDropShadow;
  62660. if (useNativeTitleBar)
  62661. flags |= ComponentPeer::windowHasTitleBar;
  62662. return flags;
  62663. }
  62664. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62665. {
  62666. useDropShadow = useShadow;
  62667. if (isOnDesktop())
  62668. {
  62669. shadower = 0;
  62670. Component::addToDesktop (getDesktopWindowStyleFlags());
  62671. }
  62672. else
  62673. {
  62674. if (useShadow && isOpaque())
  62675. {
  62676. if (shadower == 0)
  62677. {
  62678. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62679. if (shadower != 0)
  62680. shadower->setOwner (this);
  62681. }
  62682. }
  62683. else
  62684. {
  62685. shadower = 0;
  62686. }
  62687. }
  62688. }
  62689. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62690. {
  62691. if (useNativeTitleBar != useNativeTitleBar_)
  62692. {
  62693. useNativeTitleBar = useNativeTitleBar_;
  62694. recreateDesktopWindow();
  62695. sendLookAndFeelChange();
  62696. }
  62697. }
  62698. void TopLevelWindow::recreateDesktopWindow()
  62699. {
  62700. if (isOnDesktop())
  62701. {
  62702. Component::addToDesktop (getDesktopWindowStyleFlags());
  62703. toFront (true);
  62704. }
  62705. }
  62706. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62707. {
  62708. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62709. because this class needs to make sure its layout corresponds with settings like whether
  62710. it's got a native title bar or not.
  62711. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62712. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62713. method, then add or remove whatever flags are necessary from this value before returning it.
  62714. */
  62715. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62716. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62717. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62718. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62719. sendLookAndFeelChange();
  62720. }
  62721. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62722. {
  62723. if (c == 0)
  62724. c = TopLevelWindow::getActiveTopLevelWindow();
  62725. if (c == 0)
  62726. {
  62727. centreWithSize (width, height);
  62728. }
  62729. else
  62730. {
  62731. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62732. (c->getHeight() - height) / 2)));
  62733. Rectangle<int> parentArea (c->getParentMonitorArea());
  62734. if (getParentComponent() != 0)
  62735. {
  62736. p = getParentComponent()->globalPositionToRelative (p);
  62737. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62738. }
  62739. parentArea.reduce (12, 12);
  62740. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62741. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62742. width, height);
  62743. }
  62744. }
  62745. int TopLevelWindow::getNumTopLevelWindows() throw()
  62746. {
  62747. return TopLevelWindowManager::getInstance()->windows.size();
  62748. }
  62749. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62750. {
  62751. return static_cast <TopLevelWindow*> (TopLevelWindowManager::getInstance()->windows [index]);
  62752. }
  62753. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62754. {
  62755. TopLevelWindow* best = 0;
  62756. int bestNumTWLParents = -1;
  62757. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62758. {
  62759. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62760. if (tlw->isActiveWindow())
  62761. {
  62762. int numTWLParents = 0;
  62763. const Component* c = tlw->getParentComponent();
  62764. while (c != 0)
  62765. {
  62766. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62767. ++numTWLParents;
  62768. c = c->getParentComponent();
  62769. }
  62770. if (bestNumTWLParents < numTWLParents)
  62771. {
  62772. best = tlw;
  62773. bestNumTWLParents = numTWLParents;
  62774. }
  62775. }
  62776. }
  62777. return best;
  62778. }
  62779. END_JUCE_NAMESPACE
  62780. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62781. /*** Start of inlined file: juce_Colour.cpp ***/
  62782. BEGIN_JUCE_NAMESPACE
  62783. namespace ColourHelpers
  62784. {
  62785. static uint8 floatAlphaToInt (const float alpha) throw()
  62786. {
  62787. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62788. }
  62789. static void convertHSBtoRGB (float h, float s, float v,
  62790. uint8& r, uint8& g, uint8& b) throw()
  62791. {
  62792. v = jlimit (0.0f, 1.0f, v);
  62793. v *= 255.0f;
  62794. const uint8 intV = (uint8) roundToInt (v);
  62795. if (s <= 0)
  62796. {
  62797. r = intV;
  62798. g = intV;
  62799. b = intV;
  62800. }
  62801. else
  62802. {
  62803. s = jmin (1.0f, s);
  62804. h = jlimit (0.0f, 1.0f, h);
  62805. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62806. const float f = h - floorf (h);
  62807. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62808. const float y = v * (1.0f - s * f);
  62809. const float z = v * (1.0f - (s * (1.0f - f)));
  62810. if (h < 1.0f)
  62811. {
  62812. r = intV;
  62813. g = (uint8) roundToInt (z);
  62814. b = x;
  62815. }
  62816. else if (h < 2.0f)
  62817. {
  62818. r = (uint8) roundToInt (y);
  62819. g = intV;
  62820. b = x;
  62821. }
  62822. else if (h < 3.0f)
  62823. {
  62824. r = x;
  62825. g = intV;
  62826. b = (uint8) roundToInt (z);
  62827. }
  62828. else if (h < 4.0f)
  62829. {
  62830. r = x;
  62831. g = (uint8) roundToInt (y);
  62832. b = intV;
  62833. }
  62834. else if (h < 5.0f)
  62835. {
  62836. r = (uint8) roundToInt (z);
  62837. g = x;
  62838. b = intV;
  62839. }
  62840. else if (h < 6.0f)
  62841. {
  62842. r = intV;
  62843. g = x;
  62844. b = (uint8) roundToInt (y);
  62845. }
  62846. else
  62847. {
  62848. r = 0;
  62849. g = 0;
  62850. b = 0;
  62851. }
  62852. }
  62853. }
  62854. }
  62855. Colour::Colour() throw()
  62856. : argb (0)
  62857. {
  62858. }
  62859. Colour::Colour (const Colour& other) throw()
  62860. : argb (other.argb)
  62861. {
  62862. }
  62863. Colour& Colour::operator= (const Colour& other) throw()
  62864. {
  62865. argb = other.argb;
  62866. return *this;
  62867. }
  62868. bool Colour::operator== (const Colour& other) const throw()
  62869. {
  62870. return argb.getARGB() == other.argb.getARGB();
  62871. }
  62872. bool Colour::operator!= (const Colour& other) const throw()
  62873. {
  62874. return argb.getARGB() != other.argb.getARGB();
  62875. }
  62876. Colour::Colour (const uint32 argb_) throw()
  62877. : argb (argb_)
  62878. {
  62879. }
  62880. Colour::Colour (const uint8 red,
  62881. const uint8 green,
  62882. const uint8 blue) throw()
  62883. {
  62884. argb.setARGB (0xff, red, green, blue);
  62885. }
  62886. const Colour Colour::fromRGB (const uint8 red,
  62887. const uint8 green,
  62888. const uint8 blue) throw()
  62889. {
  62890. return Colour (red, green, blue);
  62891. }
  62892. Colour::Colour (const uint8 red,
  62893. const uint8 green,
  62894. const uint8 blue,
  62895. const uint8 alpha) throw()
  62896. {
  62897. argb.setARGB (alpha, red, green, blue);
  62898. }
  62899. const Colour Colour::fromRGBA (const uint8 red,
  62900. const uint8 green,
  62901. const uint8 blue,
  62902. const uint8 alpha) throw()
  62903. {
  62904. return Colour (red, green, blue, alpha);
  62905. }
  62906. Colour::Colour (const uint8 red,
  62907. const uint8 green,
  62908. const uint8 blue,
  62909. const float alpha) throw()
  62910. {
  62911. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  62912. }
  62913. const Colour Colour::fromRGBAFloat (const uint8 red,
  62914. const uint8 green,
  62915. const uint8 blue,
  62916. const float alpha) throw()
  62917. {
  62918. return Colour (red, green, blue, alpha);
  62919. }
  62920. Colour::Colour (const float hue,
  62921. const float saturation,
  62922. const float brightness,
  62923. const float alpha) throw()
  62924. {
  62925. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62926. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62927. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  62928. }
  62929. const Colour Colour::fromHSV (const float hue,
  62930. const float saturation,
  62931. const float brightness,
  62932. const float alpha) throw()
  62933. {
  62934. return Colour (hue, saturation, brightness, alpha);
  62935. }
  62936. Colour::Colour (const float hue,
  62937. const float saturation,
  62938. const float brightness,
  62939. const uint8 alpha) throw()
  62940. {
  62941. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62942. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62943. argb.setARGB (alpha, r, g, b);
  62944. }
  62945. Colour::~Colour() throw()
  62946. {
  62947. }
  62948. const PixelARGB Colour::getPixelARGB() const throw()
  62949. {
  62950. PixelARGB p (argb);
  62951. p.premultiply();
  62952. return p;
  62953. }
  62954. uint32 Colour::getARGB() const throw()
  62955. {
  62956. return argb.getARGB();
  62957. }
  62958. bool Colour::isTransparent() const throw()
  62959. {
  62960. return getAlpha() == 0;
  62961. }
  62962. bool Colour::isOpaque() const throw()
  62963. {
  62964. return getAlpha() == 0xff;
  62965. }
  62966. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  62967. {
  62968. PixelARGB newCol (argb);
  62969. newCol.setAlpha (newAlpha);
  62970. return Colour (newCol.getARGB());
  62971. }
  62972. const Colour Colour::withAlpha (const float newAlpha) const throw()
  62973. {
  62974. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  62975. PixelARGB newCol (argb);
  62976. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  62977. return Colour (newCol.getARGB());
  62978. }
  62979. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  62980. {
  62981. jassert (alphaMultiplier >= 0);
  62982. PixelARGB newCol (argb);
  62983. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  62984. return Colour (newCol.getARGB());
  62985. }
  62986. const Colour Colour::overlaidWith (const Colour& src) const throw()
  62987. {
  62988. const int destAlpha = getAlpha();
  62989. if (destAlpha > 0)
  62990. {
  62991. const int invA = 0xff - (int) src.getAlpha();
  62992. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  62993. if (resA > 0)
  62994. {
  62995. const int da = (invA * destAlpha) / resA;
  62996. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  62997. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  62998. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  62999. (uint8) resA);
  63000. }
  63001. return *this;
  63002. }
  63003. else
  63004. {
  63005. return src;
  63006. }
  63007. }
  63008. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63009. {
  63010. if (proportionOfOther <= 0)
  63011. return *this;
  63012. if (proportionOfOther >= 1.0f)
  63013. return other;
  63014. PixelARGB c1 (getPixelARGB());
  63015. const PixelARGB c2 (other.getPixelARGB());
  63016. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63017. c1.unpremultiply();
  63018. return Colour (c1.getARGB());
  63019. }
  63020. float Colour::getFloatRed() const throw()
  63021. {
  63022. return getRed() / 255.0f;
  63023. }
  63024. float Colour::getFloatGreen() const throw()
  63025. {
  63026. return getGreen() / 255.0f;
  63027. }
  63028. float Colour::getFloatBlue() const throw()
  63029. {
  63030. return getBlue() / 255.0f;
  63031. }
  63032. float Colour::getFloatAlpha() const throw()
  63033. {
  63034. return getAlpha() / 255.0f;
  63035. }
  63036. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63037. {
  63038. const int r = getRed();
  63039. const int g = getGreen();
  63040. const int b = getBlue();
  63041. const int hi = jmax (r, g, b);
  63042. const int lo = jmin (r, g, b);
  63043. if (hi != 0)
  63044. {
  63045. s = (hi - lo) / (float) hi;
  63046. if (s != 0)
  63047. {
  63048. const float invDiff = 1.0f / (hi - lo);
  63049. const float red = (hi - r) * invDiff;
  63050. const float green = (hi - g) * invDiff;
  63051. const float blue = (hi - b) * invDiff;
  63052. if (r == hi)
  63053. h = blue - green;
  63054. else if (g == hi)
  63055. h = 2.0f + red - blue;
  63056. else
  63057. h = 4.0f + green - red;
  63058. h *= 1.0f / 6.0f;
  63059. if (h < 0)
  63060. ++h;
  63061. }
  63062. else
  63063. {
  63064. h = 0;
  63065. }
  63066. }
  63067. else
  63068. {
  63069. s = 0;
  63070. h = 0;
  63071. }
  63072. v = hi / 255.0f;
  63073. }
  63074. float Colour::getHue() const throw()
  63075. {
  63076. float h, s, b;
  63077. getHSB (h, s, b);
  63078. return h;
  63079. }
  63080. const Colour Colour::withHue (const float hue) const throw()
  63081. {
  63082. float h, s, b;
  63083. getHSB (h, s, b);
  63084. return Colour (hue, s, b, getAlpha());
  63085. }
  63086. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63087. {
  63088. float h, s, b;
  63089. getHSB (h, s, b);
  63090. h += amountToRotate;
  63091. h -= floorf (h);
  63092. return Colour (h, s, b, getAlpha());
  63093. }
  63094. float Colour::getSaturation() const throw()
  63095. {
  63096. float h, s, b;
  63097. getHSB (h, s, b);
  63098. return s;
  63099. }
  63100. const Colour Colour::withSaturation (const float saturation) const throw()
  63101. {
  63102. float h, s, b;
  63103. getHSB (h, s, b);
  63104. return Colour (h, saturation, b, getAlpha());
  63105. }
  63106. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63107. {
  63108. float h, s, b;
  63109. getHSB (h, s, b);
  63110. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63111. }
  63112. float Colour::getBrightness() const throw()
  63113. {
  63114. float h, s, b;
  63115. getHSB (h, s, b);
  63116. return b;
  63117. }
  63118. const Colour Colour::withBrightness (const float brightness) const throw()
  63119. {
  63120. float h, s, b;
  63121. getHSB (h, s, b);
  63122. return Colour (h, s, brightness, getAlpha());
  63123. }
  63124. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63125. {
  63126. float h, s, b;
  63127. getHSB (h, s, b);
  63128. b *= amount;
  63129. if (b > 1.0f)
  63130. b = 1.0f;
  63131. return Colour (h, s, b, getAlpha());
  63132. }
  63133. const Colour Colour::brighter (float amount) const throw()
  63134. {
  63135. amount = 1.0f / (1.0f + amount);
  63136. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63137. (uint8) (255 - (amount * (255 - getGreen()))),
  63138. (uint8) (255 - (amount * (255 - getBlue()))),
  63139. getAlpha());
  63140. }
  63141. const Colour Colour::darker (float amount) const throw()
  63142. {
  63143. amount = 1.0f / (1.0f + amount);
  63144. return Colour ((uint8) (amount * getRed()),
  63145. (uint8) (amount * getGreen()),
  63146. (uint8) (amount * getBlue()),
  63147. getAlpha());
  63148. }
  63149. const Colour Colour::greyLevel (const float brightness) throw()
  63150. {
  63151. const uint8 level
  63152. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63153. return Colour (level, level, level);
  63154. }
  63155. const Colour Colour::contrasting (const float amount) const throw()
  63156. {
  63157. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63158. ? Colours::black
  63159. : Colours::white).withAlpha (amount));
  63160. }
  63161. const Colour Colour::contrasting (const Colour& colour1,
  63162. const Colour& colour2) throw()
  63163. {
  63164. const float b1 = colour1.getBrightness();
  63165. const float b2 = colour2.getBrightness();
  63166. float best = 0.0f;
  63167. float bestDist = 0.0f;
  63168. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63169. {
  63170. const float d1 = fabsf (i - b1);
  63171. const float d2 = fabsf (i - b2);
  63172. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63173. if (dist > bestDist)
  63174. {
  63175. best = i;
  63176. bestDist = dist;
  63177. }
  63178. }
  63179. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63180. .withBrightness (best);
  63181. }
  63182. const String Colour::toString() const
  63183. {
  63184. return String::toHexString ((int) argb.getARGB());
  63185. }
  63186. const Colour Colour::fromString (const String& encodedColourString)
  63187. {
  63188. return Colour ((uint32) encodedColourString.getHexValue32());
  63189. }
  63190. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63191. {
  63192. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63193. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63194. .toUpperCase();
  63195. }
  63196. END_JUCE_NAMESPACE
  63197. /*** End of inlined file: juce_Colour.cpp ***/
  63198. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63199. BEGIN_JUCE_NAMESPACE
  63200. ColourGradient::ColourGradient() throw()
  63201. {
  63202. #ifdef JUCE_DEBUG
  63203. x1 = 987654.0f;
  63204. #endif
  63205. }
  63206. ColourGradient::ColourGradient (const Colour& colour1,
  63207. const float x1_,
  63208. const float y1_,
  63209. const Colour& colour2,
  63210. const float x2_,
  63211. const float y2_,
  63212. const bool isRadial_) throw()
  63213. : x1 (x1_),
  63214. y1 (y1_),
  63215. x2 (x2_),
  63216. y2 (y2_),
  63217. isRadial (isRadial_)
  63218. {
  63219. colours.add (0);
  63220. colours.add (colour1.getARGB());
  63221. colours.add (1 << 16);
  63222. colours.add (colour2.getARGB());
  63223. }
  63224. ColourGradient::~ColourGradient() throw()
  63225. {
  63226. }
  63227. void ColourGradient::clearColours() throw()
  63228. {
  63229. colours.clear();
  63230. }
  63231. void ColourGradient::addColour (const double proportionAlongGradient,
  63232. const Colour& colour) throw()
  63233. {
  63234. // must be within the two end-points
  63235. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63236. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63237. int i;
  63238. for (i = 0; i < colours.size(); i += 2)
  63239. if (colours.getUnchecked(i) > pos)
  63240. break;
  63241. colours.insert (i, pos);
  63242. colours.insert (i + 1, colour.getARGB());
  63243. }
  63244. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63245. {
  63246. for (int i = 1; i < colours.size(); i += 2)
  63247. {
  63248. const Colour c (colours.getUnchecked(i));
  63249. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63250. }
  63251. }
  63252. int ColourGradient::getNumColours() const throw()
  63253. {
  63254. return colours.size() >> 1;
  63255. }
  63256. double ColourGradient::getColourPosition (const int index) const throw()
  63257. {
  63258. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63259. }
  63260. const Colour ColourGradient::getColour (const int index) const throw()
  63261. {
  63262. return Colour (colours [(index << 1) + 1]);
  63263. }
  63264. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63265. {
  63266. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63267. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63268. if (integerPos <= 0 || colours.size() <= 2)
  63269. return getColour (0);
  63270. int i = colours.size() - 2;
  63271. while (integerPos < (int) colours.getUnchecked(i))
  63272. i -= 2;
  63273. if (i >= colours.size() - 2)
  63274. return Colour (colours.getUnchecked(i));
  63275. const int pos1 = colours.getUnchecked (i);
  63276. const Colour col1 (colours.getUnchecked (i + 1));
  63277. const int pos2 = colours.getUnchecked (i + 2);
  63278. const Colour col2 (colours.getUnchecked (i + 3));
  63279. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63280. }
  63281. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63282. {
  63283. #ifdef JUCE_DEBUG
  63284. // trying to use the object without setting its co-ordinates? Have a careful read of
  63285. // the comments for the constructors.
  63286. jassert (x1 != 987654.0f);
  63287. #endif
  63288. const int numColours = colours.size() >> 1;
  63289. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63290. transform.transformPoint (tx1, ty1);
  63291. transform.transformPoint (tx2, ty2);
  63292. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63293. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63294. lookupTable.malloc (numEntries);
  63295. if (numColours >= 2)
  63296. {
  63297. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63298. PixelARGB pix1 (colours.getUnchecked (1));
  63299. pix1.premultiply();
  63300. int index = 0;
  63301. for (int j = 2; j < colours.size(); j += 2)
  63302. {
  63303. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63304. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63305. pix2.premultiply();
  63306. for (int i = 0; i < numToDo; ++i)
  63307. {
  63308. jassert (index >= 0 && index < numEntries);
  63309. lookupTable[index] = pix1;
  63310. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63311. ++index;
  63312. }
  63313. pix1 = pix2;
  63314. }
  63315. while (index < numEntries)
  63316. lookupTable [index++] = pix1;
  63317. }
  63318. else
  63319. {
  63320. jassertfalse // no colours specified!
  63321. }
  63322. return numEntries;
  63323. }
  63324. bool ColourGradient::isOpaque() const throw()
  63325. {
  63326. for (int i = 1; i < colours.size(); i += 2)
  63327. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63328. return false;
  63329. return true;
  63330. }
  63331. bool ColourGradient::isInvisible() const throw()
  63332. {
  63333. for (int i = 1; i < colours.size(); i += 2)
  63334. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63335. return false;
  63336. return true;
  63337. }
  63338. END_JUCE_NAMESPACE
  63339. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63340. /*** Start of inlined file: juce_Colours.cpp ***/
  63341. BEGIN_JUCE_NAMESPACE
  63342. const Colour Colours::transparentBlack (0);
  63343. const Colour Colours::transparentWhite (0x00ffffff);
  63344. const Colour Colours::aliceblue (0xfff0f8ff);
  63345. const Colour Colours::antiquewhite (0xfffaebd7);
  63346. const Colour Colours::aqua (0xff00ffff);
  63347. const Colour Colours::aquamarine (0xff7fffd4);
  63348. const Colour Colours::azure (0xfff0ffff);
  63349. const Colour Colours::beige (0xfff5f5dc);
  63350. const Colour Colours::bisque (0xffffe4c4);
  63351. const Colour Colours::black (0xff000000);
  63352. const Colour Colours::blanchedalmond (0xffffebcd);
  63353. const Colour Colours::blue (0xff0000ff);
  63354. const Colour Colours::blueviolet (0xff8a2be2);
  63355. const Colour Colours::brown (0xffa52a2a);
  63356. const Colour Colours::burlywood (0xffdeb887);
  63357. const Colour Colours::cadetblue (0xff5f9ea0);
  63358. const Colour Colours::chartreuse (0xff7fff00);
  63359. const Colour Colours::chocolate (0xffd2691e);
  63360. const Colour Colours::coral (0xffff7f50);
  63361. const Colour Colours::cornflowerblue (0xff6495ed);
  63362. const Colour Colours::cornsilk (0xfffff8dc);
  63363. const Colour Colours::crimson (0xffdc143c);
  63364. const Colour Colours::cyan (0xff00ffff);
  63365. const Colour Colours::darkblue (0xff00008b);
  63366. const Colour Colours::darkcyan (0xff008b8b);
  63367. const Colour Colours::darkgoldenrod (0xffb8860b);
  63368. const Colour Colours::darkgrey (0xff555555);
  63369. const Colour Colours::darkgreen (0xff006400);
  63370. const Colour Colours::darkkhaki (0xffbdb76b);
  63371. const Colour Colours::darkmagenta (0xff8b008b);
  63372. const Colour Colours::darkolivegreen (0xff556b2f);
  63373. const Colour Colours::darkorange (0xffff8c00);
  63374. const Colour Colours::darkorchid (0xff9932cc);
  63375. const Colour Colours::darkred (0xff8b0000);
  63376. const Colour Colours::darksalmon (0xffe9967a);
  63377. const Colour Colours::darkseagreen (0xff8fbc8f);
  63378. const Colour Colours::darkslateblue (0xff483d8b);
  63379. const Colour Colours::darkslategrey (0xff2f4f4f);
  63380. const Colour Colours::darkturquoise (0xff00ced1);
  63381. const Colour Colours::darkviolet (0xff9400d3);
  63382. const Colour Colours::deeppink (0xffff1493);
  63383. const Colour Colours::deepskyblue (0xff00bfff);
  63384. const Colour Colours::dimgrey (0xff696969);
  63385. const Colour Colours::dodgerblue (0xff1e90ff);
  63386. const Colour Colours::firebrick (0xffb22222);
  63387. const Colour Colours::floralwhite (0xfffffaf0);
  63388. const Colour Colours::forestgreen (0xff228b22);
  63389. const Colour Colours::fuchsia (0xffff00ff);
  63390. const Colour Colours::gainsboro (0xffdcdcdc);
  63391. const Colour Colours::gold (0xffffd700);
  63392. const Colour Colours::goldenrod (0xffdaa520);
  63393. const Colour Colours::grey (0xff808080);
  63394. const Colour Colours::green (0xff008000);
  63395. const Colour Colours::greenyellow (0xffadff2f);
  63396. const Colour Colours::honeydew (0xfff0fff0);
  63397. const Colour Colours::hotpink (0xffff69b4);
  63398. const Colour Colours::indianred (0xffcd5c5c);
  63399. const Colour Colours::indigo (0xff4b0082);
  63400. const Colour Colours::ivory (0xfffffff0);
  63401. const Colour Colours::khaki (0xfff0e68c);
  63402. const Colour Colours::lavender (0xffe6e6fa);
  63403. const Colour Colours::lavenderblush (0xfffff0f5);
  63404. const Colour Colours::lemonchiffon (0xfffffacd);
  63405. const Colour Colours::lightblue (0xffadd8e6);
  63406. const Colour Colours::lightcoral (0xfff08080);
  63407. const Colour Colours::lightcyan (0xffe0ffff);
  63408. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63409. const Colour Colours::lightgreen (0xff90ee90);
  63410. const Colour Colours::lightgrey (0xffd3d3d3);
  63411. const Colour Colours::lightpink (0xffffb6c1);
  63412. const Colour Colours::lightsalmon (0xffffa07a);
  63413. const Colour Colours::lightseagreen (0xff20b2aa);
  63414. const Colour Colours::lightskyblue (0xff87cefa);
  63415. const Colour Colours::lightslategrey (0xff778899);
  63416. const Colour Colours::lightsteelblue (0xffb0c4de);
  63417. const Colour Colours::lightyellow (0xffffffe0);
  63418. const Colour Colours::lime (0xff00ff00);
  63419. const Colour Colours::limegreen (0xff32cd32);
  63420. const Colour Colours::linen (0xfffaf0e6);
  63421. const Colour Colours::magenta (0xffff00ff);
  63422. const Colour Colours::maroon (0xff800000);
  63423. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63424. const Colour Colours::mediumblue (0xff0000cd);
  63425. const Colour Colours::mediumorchid (0xffba55d3);
  63426. const Colour Colours::mediumpurple (0xff9370db);
  63427. const Colour Colours::mediumseagreen (0xff3cb371);
  63428. const Colour Colours::mediumslateblue (0xff7b68ee);
  63429. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63430. const Colour Colours::mediumturquoise (0xff48d1cc);
  63431. const Colour Colours::mediumvioletred (0xffc71585);
  63432. const Colour Colours::midnightblue (0xff191970);
  63433. const Colour Colours::mintcream (0xfff5fffa);
  63434. const Colour Colours::mistyrose (0xffffe4e1);
  63435. const Colour Colours::navajowhite (0xffffdead);
  63436. const Colour Colours::navy (0xff000080);
  63437. const Colour Colours::oldlace (0xfffdf5e6);
  63438. const Colour Colours::olive (0xff808000);
  63439. const Colour Colours::olivedrab (0xff6b8e23);
  63440. const Colour Colours::orange (0xffffa500);
  63441. const Colour Colours::orangered (0xffff4500);
  63442. const Colour Colours::orchid (0xffda70d6);
  63443. const Colour Colours::palegoldenrod (0xffeee8aa);
  63444. const Colour Colours::palegreen (0xff98fb98);
  63445. const Colour Colours::paleturquoise (0xffafeeee);
  63446. const Colour Colours::palevioletred (0xffdb7093);
  63447. const Colour Colours::papayawhip (0xffffefd5);
  63448. const Colour Colours::peachpuff (0xffffdab9);
  63449. const Colour Colours::peru (0xffcd853f);
  63450. const Colour Colours::pink (0xffffc0cb);
  63451. const Colour Colours::plum (0xffdda0dd);
  63452. const Colour Colours::powderblue (0xffb0e0e6);
  63453. const Colour Colours::purple (0xff800080);
  63454. const Colour Colours::red (0xffff0000);
  63455. const Colour Colours::rosybrown (0xffbc8f8f);
  63456. const Colour Colours::royalblue (0xff4169e1);
  63457. const Colour Colours::saddlebrown (0xff8b4513);
  63458. const Colour Colours::salmon (0xfffa8072);
  63459. const Colour Colours::sandybrown (0xfff4a460);
  63460. const Colour Colours::seagreen (0xff2e8b57);
  63461. const Colour Colours::seashell (0xfffff5ee);
  63462. const Colour Colours::sienna (0xffa0522d);
  63463. const Colour Colours::silver (0xffc0c0c0);
  63464. const Colour Colours::skyblue (0xff87ceeb);
  63465. const Colour Colours::slateblue (0xff6a5acd);
  63466. const Colour Colours::slategrey (0xff708090);
  63467. const Colour Colours::snow (0xfffffafa);
  63468. const Colour Colours::springgreen (0xff00ff7f);
  63469. const Colour Colours::steelblue (0xff4682b4);
  63470. const Colour Colours::tan (0xffd2b48c);
  63471. const Colour Colours::teal (0xff008080);
  63472. const Colour Colours::thistle (0xffd8bfd8);
  63473. const Colour Colours::tomato (0xffff6347);
  63474. const Colour Colours::turquoise (0xff40e0d0);
  63475. const Colour Colours::violet (0xffee82ee);
  63476. const Colour Colours::wheat (0xfff5deb3);
  63477. const Colour Colours::white (0xffffffff);
  63478. const Colour Colours::whitesmoke (0xfff5f5f5);
  63479. const Colour Colours::yellow (0xffffff00);
  63480. const Colour Colours::yellowgreen (0xff9acd32);
  63481. const Colour Colours::findColourForName (const String& colourName,
  63482. const Colour& defaultColour)
  63483. {
  63484. static const int presets[] =
  63485. {
  63486. // (first value is the string's hashcode, second is ARGB)
  63487. 0x05978fff, 0xff000000, /* black */
  63488. 0x06bdcc29, 0xffffffff, /* white */
  63489. 0x002e305a, 0xff0000ff, /* blue */
  63490. 0x00308adf, 0xff808080, /* grey */
  63491. 0x05e0cf03, 0xff008000, /* green */
  63492. 0x0001b891, 0xffff0000, /* red */
  63493. 0xd43c6474, 0xffffff00, /* yellow */
  63494. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63495. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63496. 0x002dcebc, 0xff00ffff, /* aqua */
  63497. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63498. 0x0590228f, 0xfff0ffff, /* azure */
  63499. 0x05947fe4, 0xfff5f5dc, /* beige */
  63500. 0xad388e35, 0xffffe4c4, /* bisque */
  63501. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63502. 0x39129959, 0xff8a2be2, /* blueviolet */
  63503. 0x059a8136, 0xffa52a2a, /* brown */
  63504. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63505. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63506. 0x6b748956, 0xff7fff00, /* chartreuse */
  63507. 0x2903623c, 0xffd2691e, /* chocolate */
  63508. 0x05a74431, 0xffff7f50, /* coral */
  63509. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63510. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63511. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63512. 0x002ed323, 0xff00ffff, /* cyan */
  63513. 0x67cc74d0, 0xff00008b, /* darkblue */
  63514. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63515. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63516. 0x67cecf55, 0xff555555, /* darkgrey */
  63517. 0x920b194d, 0xff006400, /* darkgreen */
  63518. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63519. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63520. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63521. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63522. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63523. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63524. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63525. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63526. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63527. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63528. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63529. 0xc8769375, 0xff9400d3, /* darkviolet */
  63530. 0x25832862, 0xffff1493, /* deeppink */
  63531. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63532. 0x634c8b67, 0xff696969, /* dimgrey */
  63533. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63534. 0xef19e3cb, 0xffb22222, /* firebrick */
  63535. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63536. 0xd086fd06, 0xff228b22, /* forestgreen */
  63537. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63538. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63539. 0x00308060, 0xffffd700, /* gold */
  63540. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63541. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63542. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63543. 0x41892743, 0xffff69b4, /* hotpink */
  63544. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63545. 0xb969fed2, 0xff4b0082, /* indigo */
  63546. 0x05fef6a9, 0xfffffff0, /* ivory */
  63547. 0x06149302, 0xfff0e68c, /* khaki */
  63548. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63549. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63550. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63551. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63552. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63553. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63554. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63555. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63556. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63557. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63558. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63559. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63560. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63561. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63562. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63563. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63564. 0x0032afd5, 0xff00ff00, /* lime */
  63565. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63566. 0x06234efa, 0xfffaf0e6, /* linen */
  63567. 0x316858a9, 0xffff00ff, /* magenta */
  63568. 0xbf8ca470, 0xff800000, /* maroon */
  63569. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63570. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63571. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63572. 0x07556b71, 0xff9370db, /* mediumpurple */
  63573. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63574. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63575. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63576. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63577. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63578. 0x168eb32a, 0xff191970, /* midnightblue */
  63579. 0x4306b960, 0xfff5fffa, /* mintcream */
  63580. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63581. 0xe97218a6, 0xffffdead, /* navajowhite */
  63582. 0x00337bb6, 0xff000080, /* navy */
  63583. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63584. 0x064ee1db, 0xff808000, /* olive */
  63585. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63586. 0xc3de262e, 0xffffa500, /* orange */
  63587. 0x58bebba3, 0xffff4500, /* orangered */
  63588. 0xc3def8a3, 0xffda70d6, /* orchid */
  63589. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63590. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63591. 0x74022737, 0xffafeeee, /* paleturquoise */
  63592. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63593. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63594. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63595. 0x003472f8, 0xffcd853f, /* peru */
  63596. 0x00348176, 0xffffc0cb, /* pink */
  63597. 0x00348d94, 0xffdda0dd, /* plum */
  63598. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63599. 0xc5c507bc, 0xff800080, /* purple */
  63600. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63601. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63602. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63603. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63604. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63605. 0x34636c14, 0xff2e8b57, /* seagreen */
  63606. 0x3507fb41, 0xfffff5ee, /* seashell */
  63607. 0xca348772, 0xffa0522d, /* sienna */
  63608. 0xca37d30d, 0xffc0c0c0, /* silver */
  63609. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63610. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63611. 0x44ab37f8, 0xff708090, /* slategrey */
  63612. 0x0035f183, 0xfffffafa, /* snow */
  63613. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63614. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63615. 0x0001bfa1, 0xffd2b48c, /* tan */
  63616. 0x0036425c, 0xff008080, /* teal */
  63617. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63618. 0xcc41600a, 0xffff6347, /* tomato */
  63619. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63620. 0xcf57947f, 0xffee82ee, /* violet */
  63621. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63622. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63623. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63624. };
  63625. const int hash = colourName.trim().toLowerCase().hashCode();
  63626. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63627. if (presets [i] == hash)
  63628. return Colour (presets [i + 1]);
  63629. return defaultColour;
  63630. }
  63631. END_JUCE_NAMESPACE
  63632. /*** End of inlined file: juce_Colours.cpp ***/
  63633. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63634. BEGIN_JUCE_NAMESPACE
  63635. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63636. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63637. const Path& path, const AffineTransform& transform)
  63638. : bounds (bounds_),
  63639. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63640. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63641. needToCheckEmptinesss (true)
  63642. {
  63643. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63644. int* t = table;
  63645. for (int i = bounds.getHeight(); --i >= 0;)
  63646. {
  63647. *t = 0;
  63648. t += lineStrideElements;
  63649. }
  63650. const int topLimit = bounds.getY() << 8;
  63651. const int heightLimit = bounds.getHeight() << 8;
  63652. const int leftLimit = bounds.getX() << 8;
  63653. const int rightLimit = bounds.getRight() << 8;
  63654. PathFlatteningIterator iter (path, transform);
  63655. while (iter.next())
  63656. {
  63657. int y1 = roundToInt (iter.y1 * 256.0f);
  63658. int y2 = roundToInt (iter.y2 * 256.0f);
  63659. if (y1 != y2)
  63660. {
  63661. y1 -= topLimit;
  63662. y2 -= topLimit;
  63663. const int startY = y1;
  63664. int direction = -1;
  63665. if (y1 > y2)
  63666. {
  63667. swapVariables (y1, y2);
  63668. direction = 1;
  63669. }
  63670. if (y1 < 0)
  63671. y1 = 0;
  63672. if (y2 > heightLimit)
  63673. y2 = heightLimit;
  63674. if (y1 < y2)
  63675. {
  63676. const double startX = 256.0f * iter.x1;
  63677. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63678. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63679. do
  63680. {
  63681. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63682. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63683. if (x < leftLimit)
  63684. x = leftLimit;
  63685. else if (x >= rightLimit)
  63686. x = rightLimit - 1;
  63687. addEdgePoint (x, y1 >> 8, direction * step);
  63688. y1 += step;
  63689. }
  63690. while (y1 < y2);
  63691. }
  63692. }
  63693. }
  63694. sanitiseLevels (path.isUsingNonZeroWinding());
  63695. }
  63696. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63697. : bounds (rectangleToAdd),
  63698. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63699. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63700. needToCheckEmptinesss (true)
  63701. {
  63702. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63703. table[0] = 0;
  63704. const int x1 = rectangleToAdd.getX() << 8;
  63705. const int x2 = rectangleToAdd.getRight() << 8;
  63706. int* t = table;
  63707. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63708. {
  63709. t[0] = 2;
  63710. t[1] = x1;
  63711. t[2] = 255;
  63712. t[3] = x2;
  63713. t[4] = 0;
  63714. t += lineStrideElements;
  63715. }
  63716. }
  63717. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63718. : bounds (rectanglesToAdd.getBounds()),
  63719. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63720. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63721. needToCheckEmptinesss (true)
  63722. {
  63723. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63724. int* t = table;
  63725. for (int i = bounds.getHeight(); --i >= 0;)
  63726. {
  63727. *t = 0;
  63728. t += lineStrideElements;
  63729. }
  63730. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63731. {
  63732. const Rectangle<int>* const r = iter.getRectangle();
  63733. const int x1 = r->getX() << 8;
  63734. const int x2 = r->getRight() << 8;
  63735. int y = r->getY() - bounds.getY();
  63736. for (int j = r->getHeight(); --j >= 0;)
  63737. {
  63738. addEdgePoint (x1, y, 255);
  63739. addEdgePoint (x2, y, -255);
  63740. ++y;
  63741. }
  63742. }
  63743. sanitiseLevels (true);
  63744. }
  63745. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63746. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63747. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63748. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63749. needToCheckEmptinesss (true)
  63750. {
  63751. jassert (w > 0 && h > 0);
  63752. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63753. table[0] = 0;
  63754. const int x1 = roundToInt (x * 256.0f);
  63755. const int x2 = roundToInt ((x + w) * 256.0f);
  63756. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63757. jassert (y1 < 256);
  63758. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63759. if (x2 <= x1 || y2 <= y1)
  63760. {
  63761. bounds.setHeight (0);
  63762. return;
  63763. }
  63764. int lineY = 0;
  63765. int* t = table;
  63766. if ((y1 >> 8) == (y2 >> 8))
  63767. {
  63768. t[0] = 2;
  63769. t[1] = x1;
  63770. t[2] = y2 - y1;
  63771. t[3] = x2;
  63772. t[4] = 0;
  63773. ++lineY;
  63774. t += lineStrideElements;
  63775. }
  63776. else
  63777. {
  63778. t[0] = 2;
  63779. t[1] = x1;
  63780. t[2] = 255 - (y1 & 255);
  63781. t[3] = x2;
  63782. t[4] = 0;
  63783. ++lineY;
  63784. t += lineStrideElements;
  63785. while (lineY < (y2 >> 8))
  63786. {
  63787. t[0] = 2;
  63788. t[1] = x1;
  63789. t[2] = 255;
  63790. t[3] = x2;
  63791. t[4] = 0;
  63792. ++lineY;
  63793. t += lineStrideElements;
  63794. }
  63795. jassert (lineY < bounds.getHeight());
  63796. t[0] = 2;
  63797. t[1] = x1;
  63798. t[2] = y2 & 255;
  63799. t[3] = x2;
  63800. t[4] = 0;
  63801. ++lineY;
  63802. t += lineStrideElements;
  63803. }
  63804. while (lineY < bounds.getHeight())
  63805. {
  63806. t[0] = 0;
  63807. t += lineStrideElements;
  63808. ++lineY;
  63809. }
  63810. }
  63811. EdgeTable::EdgeTable (const EdgeTable& other)
  63812. : table (0)
  63813. {
  63814. operator= (other);
  63815. }
  63816. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63817. {
  63818. bounds = other.bounds;
  63819. maxEdgesPerLine = other.maxEdgesPerLine;
  63820. lineStrideElements = other.lineStrideElements;
  63821. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63822. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63823. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63824. return *this;
  63825. }
  63826. EdgeTable::~EdgeTable()
  63827. {
  63828. }
  63829. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63830. {
  63831. while (--numLines >= 0)
  63832. {
  63833. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63834. src += srcLineStride;
  63835. dest += destLineStride;
  63836. }
  63837. }
  63838. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63839. {
  63840. // Convert the table from relative windings to absolute levels..
  63841. int* lineStart = table;
  63842. for (int i = bounds.getHeight(); --i >= 0;)
  63843. {
  63844. int* line = lineStart;
  63845. lineStart += lineStrideElements;
  63846. int num = *line;
  63847. if (num == 0)
  63848. continue;
  63849. int level = 0;
  63850. if (useNonZeroWinding)
  63851. {
  63852. while (--num > 0)
  63853. {
  63854. line += 2;
  63855. level += *line;
  63856. int corrected = abs (level);
  63857. if (corrected >> 8)
  63858. corrected = 255;
  63859. *line = corrected;
  63860. }
  63861. }
  63862. else
  63863. {
  63864. while (--num > 0)
  63865. {
  63866. line += 2;
  63867. level += *line;
  63868. int corrected = abs (level);
  63869. if (corrected >> 8)
  63870. {
  63871. corrected &= 511;
  63872. if (corrected >> 8)
  63873. corrected = 511 - corrected;
  63874. }
  63875. *line = corrected;
  63876. }
  63877. }
  63878. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  63879. }
  63880. }
  63881. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  63882. {
  63883. if (newNumEdgesPerLine != maxEdgesPerLine)
  63884. {
  63885. maxEdgesPerLine = newNumEdgesPerLine;
  63886. jassert (bounds.getHeight() > 0);
  63887. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  63888. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  63889. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  63890. table.swapWith (newTable);
  63891. lineStrideElements = newLineStrideElements;
  63892. }
  63893. }
  63894. void EdgeTable::optimiseTable() throw()
  63895. {
  63896. int maxLineElements = 0;
  63897. for (int i = bounds.getHeight(); --i >= 0;)
  63898. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  63899. remapTableForNumEdges (maxLineElements);
  63900. }
  63901. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  63902. {
  63903. jassert (y >= 0 && y < bounds.getHeight());
  63904. int* line = table + lineStrideElements * y;
  63905. const int numPoints = line[0];
  63906. int n = numPoints << 1;
  63907. if (n > 0)
  63908. {
  63909. while (n > 0)
  63910. {
  63911. const int cx = line [n - 1];
  63912. if (cx <= x)
  63913. {
  63914. if (cx == x)
  63915. {
  63916. line [n] += winding;
  63917. return;
  63918. }
  63919. break;
  63920. }
  63921. n -= 2;
  63922. }
  63923. if (numPoints >= maxEdgesPerLine)
  63924. {
  63925. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  63926. jassert (numPoints < maxEdgesPerLine);
  63927. line = table + lineStrideElements * y;
  63928. }
  63929. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  63930. }
  63931. line [n + 1] = x;
  63932. line [n + 2] = winding;
  63933. line[0]++;
  63934. }
  63935. void EdgeTable::translate (float dx, int dy) throw()
  63936. {
  63937. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  63938. int* lineStart = table;
  63939. const int intDx = (int) (dx * 256.0f);
  63940. for (int i = bounds.getHeight(); --i >= 0;)
  63941. {
  63942. int* line = lineStart;
  63943. lineStart += lineStrideElements;
  63944. int num = *line++;
  63945. while (--num >= 0)
  63946. {
  63947. *line += intDx;
  63948. line += 2;
  63949. }
  63950. }
  63951. }
  63952. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  63953. {
  63954. jassert (y >= 0 && y < bounds.getHeight());
  63955. int* dest = table + lineStrideElements * y;
  63956. if (dest[0] == 0)
  63957. return;
  63958. int otherNumPoints = *otherLine;
  63959. if (otherNumPoints == 0)
  63960. {
  63961. *dest = 0;
  63962. return;
  63963. }
  63964. const int right = bounds.getRight() << 8;
  63965. // optimise for the common case where our line lies entirely within a
  63966. // single pair of points, as happens when clipping to a simple rect.
  63967. if (otherNumPoints == 2 && otherLine[2] >= 255)
  63968. {
  63969. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  63970. return;
  63971. }
  63972. ++otherLine;
  63973. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  63974. int* temp = (int*) alloca (lineSizeBytes);
  63975. memcpy (temp, dest, lineSizeBytes);
  63976. const int* src1 = temp;
  63977. int srcNum1 = *src1++;
  63978. int x1 = *src1++;
  63979. const int* src2 = otherLine;
  63980. int srcNum2 = otherNumPoints;
  63981. int x2 = *src2++;
  63982. int destIndex = 0, destTotal = 0;
  63983. int level1 = 0, level2 = 0;
  63984. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  63985. while (srcNum1 > 0 && srcNum2 > 0)
  63986. {
  63987. int nextX;
  63988. if (x1 < x2)
  63989. {
  63990. nextX = x1;
  63991. level1 = *src1++;
  63992. x1 = *src1++;
  63993. --srcNum1;
  63994. }
  63995. else if (x1 == x2)
  63996. {
  63997. nextX = x1;
  63998. level1 = *src1++;
  63999. level2 = *src2++;
  64000. x1 = *src1++;
  64001. x2 = *src2++;
  64002. --srcNum1;
  64003. --srcNum2;
  64004. }
  64005. else
  64006. {
  64007. nextX = x2;
  64008. level2 = *src2++;
  64009. x2 = *src2++;
  64010. --srcNum2;
  64011. }
  64012. if (nextX > lastX)
  64013. {
  64014. if (nextX >= right)
  64015. break;
  64016. lastX = nextX;
  64017. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64018. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64019. if (nextLevel != lastLevel)
  64020. {
  64021. if (destTotal >= maxEdgesPerLine)
  64022. {
  64023. dest[0] = destTotal;
  64024. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64025. dest = table + lineStrideElements * y;
  64026. }
  64027. ++destTotal;
  64028. lastLevel = nextLevel;
  64029. dest[++destIndex] = nextX;
  64030. dest[++destIndex] = nextLevel;
  64031. }
  64032. }
  64033. }
  64034. if (lastLevel > 0)
  64035. {
  64036. if (destTotal >= maxEdgesPerLine)
  64037. {
  64038. dest[0] = destTotal;
  64039. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64040. dest = table + lineStrideElements * y;
  64041. }
  64042. ++destTotal;
  64043. dest[++destIndex] = right;
  64044. dest[++destIndex] = 0;
  64045. }
  64046. dest[0] = destTotal;
  64047. #if JUCE_DEBUG
  64048. int last = std::numeric_limits<int>::min();
  64049. for (int i = 0; i < dest[0]; ++i)
  64050. {
  64051. jassert (dest[i * 2 + 1] > last);
  64052. last = dest[i * 2 + 1];
  64053. }
  64054. jassert (dest [dest[0] * 2] == 0);
  64055. #endif
  64056. }
  64057. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64058. {
  64059. int* lastItem = dest + (dest[0] * 2 - 1);
  64060. if (x2 < lastItem[0])
  64061. {
  64062. if (x2 <= dest[1])
  64063. {
  64064. dest[0] = 0;
  64065. return;
  64066. }
  64067. while (x2 < lastItem[-2])
  64068. {
  64069. --(dest[0]);
  64070. lastItem -= 2;
  64071. }
  64072. lastItem[0] = x2;
  64073. lastItem[1] = 0;
  64074. }
  64075. if (x1 > dest[1])
  64076. {
  64077. while (lastItem[0] > x1)
  64078. lastItem -= 2;
  64079. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64080. if (itemsRemoved > 0)
  64081. {
  64082. dest[0] -= itemsRemoved;
  64083. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64084. }
  64085. dest[1] = x1;
  64086. }
  64087. }
  64088. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64089. {
  64090. const Rectangle<int> clipped (r.getIntersection (bounds));
  64091. if (clipped.isEmpty())
  64092. {
  64093. needToCheckEmptinesss = false;
  64094. bounds.setHeight (0);
  64095. }
  64096. else
  64097. {
  64098. const int top = clipped.getY() - bounds.getY();
  64099. const int bottom = clipped.getBottom() - bounds.getY();
  64100. if (bottom < bounds.getHeight())
  64101. bounds.setHeight (bottom);
  64102. if (clipped.getRight() < bounds.getRight())
  64103. bounds.setRight (clipped.getRight());
  64104. for (int i = top; --i >= 0;)
  64105. table [lineStrideElements * i] = 0;
  64106. if (clipped.getX() > bounds.getX())
  64107. {
  64108. const int x1 = clipped.getX() << 8;
  64109. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64110. int* line = table + lineStrideElements * top;
  64111. for (int i = bottom - top; --i >= 0;)
  64112. {
  64113. if (line[0] != 0)
  64114. clipEdgeTableLineToRange (line, x1, x2);
  64115. line += lineStrideElements;
  64116. }
  64117. }
  64118. needToCheckEmptinesss = true;
  64119. }
  64120. }
  64121. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64122. {
  64123. const Rectangle<int> clipped (r.getIntersection (bounds));
  64124. if (! clipped.isEmpty())
  64125. {
  64126. const int top = clipped.getY() - bounds.getY();
  64127. const int bottom = clipped.getBottom() - bounds.getY();
  64128. //XXX optimise here by shortening the table if it fills top or bottom
  64129. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64130. clipped.getX() << 8, 0,
  64131. clipped.getRight() << 8, 255,
  64132. std::numeric_limits<int>::max(), 0 };
  64133. for (int i = top; i < bottom; ++i)
  64134. intersectWithEdgeTableLine (i, rectLine);
  64135. needToCheckEmptinesss = true;
  64136. }
  64137. }
  64138. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64139. {
  64140. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64141. if (clipped.isEmpty())
  64142. {
  64143. needToCheckEmptinesss = false;
  64144. bounds.setHeight (0);
  64145. }
  64146. else
  64147. {
  64148. const int top = clipped.getY() - bounds.getY();
  64149. const int bottom = clipped.getBottom() - bounds.getY();
  64150. if (bottom < bounds.getHeight())
  64151. bounds.setHeight (bottom);
  64152. if (clipped.getRight() < bounds.getRight())
  64153. bounds.setRight (clipped.getRight());
  64154. int i = 0;
  64155. for (i = top; --i >= 0;)
  64156. table [lineStrideElements * i] = 0;
  64157. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64158. for (i = top; i < bottom; ++i)
  64159. {
  64160. intersectWithEdgeTableLine (i, otherLine);
  64161. otherLine += other.lineStrideElements;
  64162. }
  64163. needToCheckEmptinesss = true;
  64164. }
  64165. }
  64166. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64167. {
  64168. y -= bounds.getY();
  64169. if (y < 0 || y >= bounds.getHeight())
  64170. return;
  64171. needToCheckEmptinesss = true;
  64172. if (numPixels <= 0)
  64173. {
  64174. table [lineStrideElements * y] = 0;
  64175. return;
  64176. }
  64177. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64178. int destIndex = 0, lastLevel = 0;
  64179. while (--numPixels >= 0)
  64180. {
  64181. const int alpha = *mask;
  64182. mask += maskStride;
  64183. if (alpha != lastLevel)
  64184. {
  64185. tempLine[++destIndex] = (x << 8);
  64186. tempLine[++destIndex] = alpha;
  64187. lastLevel = alpha;
  64188. }
  64189. ++x;
  64190. }
  64191. if (lastLevel > 0)
  64192. {
  64193. tempLine[++destIndex] = (x << 8);
  64194. tempLine[++destIndex] = 0;
  64195. }
  64196. tempLine[0] = destIndex >> 1;
  64197. intersectWithEdgeTableLine (y, tempLine);
  64198. }
  64199. bool EdgeTable::isEmpty() throw()
  64200. {
  64201. if (needToCheckEmptinesss)
  64202. {
  64203. needToCheckEmptinesss = false;
  64204. int* t = table;
  64205. for (int i = bounds.getHeight(); --i >= 0;)
  64206. {
  64207. if (t[0] > 1)
  64208. return false;
  64209. t += lineStrideElements;
  64210. }
  64211. bounds.setHeight (0);
  64212. }
  64213. return bounds.getHeight() == 0;
  64214. }
  64215. END_JUCE_NAMESPACE
  64216. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64217. /*** Start of inlined file: juce_FillType.cpp ***/
  64218. BEGIN_JUCE_NAMESPACE
  64219. FillType::FillType() throw()
  64220. : colour (0xff000000), image (0)
  64221. {
  64222. }
  64223. FillType::FillType (const Colour& colour_) throw()
  64224. : colour (colour_), image (0)
  64225. {
  64226. }
  64227. FillType::FillType (const ColourGradient& gradient_) throw()
  64228. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64229. {
  64230. }
  64231. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64232. : colour (0xff000000), image (&image_), transform (transform_)
  64233. {
  64234. }
  64235. FillType::FillType (const FillType& other) throw()
  64236. : colour (other.colour),
  64237. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64238. image (other.image), transform (other.transform)
  64239. {
  64240. }
  64241. FillType& FillType::operator= (const FillType& other) throw()
  64242. {
  64243. if (this != &other)
  64244. {
  64245. colour = other.colour;
  64246. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64247. image = other.image;
  64248. transform = other.transform;
  64249. }
  64250. return *this;
  64251. }
  64252. FillType::~FillType() throw()
  64253. {
  64254. }
  64255. void FillType::setColour (const Colour& newColour) throw()
  64256. {
  64257. gradient = 0;
  64258. image = 0;
  64259. colour = newColour;
  64260. }
  64261. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64262. {
  64263. if (gradient != 0)
  64264. {
  64265. *gradient = newGradient;
  64266. }
  64267. else
  64268. {
  64269. image = 0;
  64270. gradient = new ColourGradient (newGradient);
  64271. colour = Colours::black;
  64272. }
  64273. }
  64274. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64275. {
  64276. gradient = 0;
  64277. image = &image_;
  64278. transform = transform_;
  64279. colour = Colours::black;
  64280. }
  64281. void FillType::setOpacity (const float newOpacity) throw()
  64282. {
  64283. colour = colour.withAlpha (newOpacity);
  64284. }
  64285. END_JUCE_NAMESPACE
  64286. /*** End of inlined file: juce_FillType.cpp ***/
  64287. /*** Start of inlined file: juce_Graphics.cpp ***/
  64288. BEGIN_JUCE_NAMESPACE
  64289. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64290. template <typename Type>
  64291. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64292. {
  64293. const int maxVal = 0x3fffffff;
  64294. return (int) x >= -maxVal && (int) x <= maxVal
  64295. && (int) y >= -maxVal && (int) y <= maxVal
  64296. && (int) w >= -maxVal && (int) w <= maxVal
  64297. && (int) h >= -maxVal && (int) h <= maxVal;
  64298. }
  64299. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64300. {
  64301. }
  64302. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64303. {
  64304. }
  64305. Graphics::Graphics (Image& imageToDrawOnto)
  64306. : context (imageToDrawOnto.createLowLevelContext()),
  64307. contextToDelete (context),
  64308. saveStatePending (false)
  64309. {
  64310. }
  64311. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64312. : context (internalContext),
  64313. saveStatePending (false)
  64314. {
  64315. }
  64316. Graphics::~Graphics()
  64317. {
  64318. }
  64319. void Graphics::resetToDefaultState()
  64320. {
  64321. saveStateIfPending();
  64322. context->setFill (FillType());
  64323. context->setFont (Font());
  64324. context->setInterpolationQuality (defaultQuality);
  64325. }
  64326. bool Graphics::isVectorDevice() const
  64327. {
  64328. return context->isVectorDevice();
  64329. }
  64330. bool Graphics::reduceClipRegion (const int x, const int y, const int w, const int h)
  64331. {
  64332. saveStateIfPending();
  64333. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64334. }
  64335. bool Graphics::reduceClipRegion (const RectangleList& clipRegion)
  64336. {
  64337. saveStateIfPending();
  64338. return context->clipToRectangleList (clipRegion);
  64339. }
  64340. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform)
  64341. {
  64342. saveStateIfPending();
  64343. context->clipToPath (path, transform);
  64344. return ! context->isClipEmpty();
  64345. }
  64346. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform)
  64347. {
  64348. saveStateIfPending();
  64349. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64350. return ! context->isClipEmpty();
  64351. }
  64352. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude)
  64353. {
  64354. saveStateIfPending();
  64355. context->excludeClipRectangle (rectangleToExclude);
  64356. }
  64357. bool Graphics::isClipEmpty() const
  64358. {
  64359. return context->isClipEmpty();
  64360. }
  64361. const Rectangle<int> Graphics::getClipBounds() const
  64362. {
  64363. return context->getClipBounds();
  64364. }
  64365. void Graphics::saveState()
  64366. {
  64367. saveStateIfPending();
  64368. saveStatePending = true;
  64369. }
  64370. void Graphics::restoreState()
  64371. {
  64372. if (saveStatePending)
  64373. saveStatePending = false;
  64374. else
  64375. context->restoreState();
  64376. }
  64377. void Graphics::saveStateIfPending()
  64378. {
  64379. if (saveStatePending)
  64380. {
  64381. saveStatePending = false;
  64382. context->saveState();
  64383. }
  64384. }
  64385. void Graphics::setOrigin (const int newOriginX, const int newOriginY)
  64386. {
  64387. saveStateIfPending();
  64388. context->setOrigin (newOriginX, newOriginY);
  64389. }
  64390. bool Graphics::clipRegionIntersects (const int x, const int y, const int w, const int h) const
  64391. {
  64392. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64393. }
  64394. void Graphics::setColour (const Colour& newColour)
  64395. {
  64396. saveStateIfPending();
  64397. context->setFill (newColour);
  64398. }
  64399. void Graphics::setOpacity (const float newOpacity)
  64400. {
  64401. saveStateIfPending();
  64402. context->setOpacity (newOpacity);
  64403. }
  64404. void Graphics::setGradientFill (const ColourGradient& gradient)
  64405. {
  64406. setFillType (gradient);
  64407. }
  64408. void Graphics::setTiledImageFill (const Image& imageToUse, const int anchorX, const int anchorY, const float opacity)
  64409. {
  64410. saveStateIfPending();
  64411. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64412. context->setOpacity (opacity);
  64413. }
  64414. void Graphics::setFillType (const FillType& newFill)
  64415. {
  64416. saveStateIfPending();
  64417. context->setFill (newFill);
  64418. }
  64419. void Graphics::setFont (const Font& newFont)
  64420. {
  64421. saveStateIfPending();
  64422. context->setFont (newFont);
  64423. }
  64424. void Graphics::setFont (const float newFontHeight, const int newFontStyleFlags)
  64425. {
  64426. saveStateIfPending();
  64427. Font f (context->getFont());
  64428. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64429. context->setFont (f);
  64430. }
  64431. void Graphics::drawSingleLineText (const String& text, const int startX, const int baselineY) const
  64432. {
  64433. if (text.isNotEmpty()
  64434. && startX < context->getClipBounds().getRight())
  64435. {
  64436. GlyphArrangement arr;
  64437. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64438. arr.draw (*this);
  64439. }
  64440. }
  64441. void Graphics::drawTextAsPath (const String& text, const AffineTransform& transform) const
  64442. {
  64443. if (text.isNotEmpty())
  64444. {
  64445. GlyphArrangement arr;
  64446. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64447. arr.draw (*this, transform);
  64448. }
  64449. }
  64450. void Graphics::drawMultiLineText (const String& text, const int startX, const int baselineY, const int maximumLineWidth) const
  64451. {
  64452. if (text.isNotEmpty()
  64453. && startX < context->getClipBounds().getRight())
  64454. {
  64455. GlyphArrangement arr;
  64456. arr.addJustifiedText (context->getFont(), text,
  64457. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64458. Justification::left);
  64459. arr.draw (*this);
  64460. }
  64461. }
  64462. void Graphics::drawText (const String& text,
  64463. const int x, const int y, const int width, const int height,
  64464. const Justification& justificationType,
  64465. const bool useEllipsesIfTooBig) const
  64466. {
  64467. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64468. {
  64469. GlyphArrangement arr;
  64470. arr.addCurtailedLineOfText (context->getFont(), text,
  64471. 0.0f, 0.0f, (float) width,
  64472. useEllipsesIfTooBig);
  64473. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64474. (float) x, (float) y, (float) width, (float) height,
  64475. justificationType);
  64476. arr.draw (*this);
  64477. }
  64478. }
  64479. void Graphics::drawFittedText (const String& text,
  64480. const int x, const int y, const int width, const int height,
  64481. const Justification& justification,
  64482. const int maximumNumberOfLines,
  64483. const float minimumHorizontalScale) const
  64484. {
  64485. if (text.isNotEmpty()
  64486. && width > 0 && height > 0
  64487. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64488. {
  64489. GlyphArrangement arr;
  64490. arr.addFittedText (context->getFont(), text,
  64491. (float) x, (float) y, (float) width, (float) height,
  64492. justification,
  64493. maximumNumberOfLines,
  64494. minimumHorizontalScale);
  64495. arr.draw (*this);
  64496. }
  64497. }
  64498. void Graphics::fillRect (int x, int y, int width, int height) const
  64499. {
  64500. // passing in a silly number can cause maths problems in rendering!
  64501. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64502. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64503. }
  64504. void Graphics::fillRect (const Rectangle<int>& r) const
  64505. {
  64506. context->fillRect (r, false);
  64507. }
  64508. void Graphics::fillRect (const float x, const float y, const float width, const float height) const
  64509. {
  64510. // passing in a silly number can cause maths problems in rendering!
  64511. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64512. Path p;
  64513. p.addRectangle (x, y, width, height);
  64514. fillPath (p);
  64515. }
  64516. void Graphics::setPixel (int x, int y) const
  64517. {
  64518. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64519. }
  64520. void Graphics::fillAll() const
  64521. {
  64522. fillRect (context->getClipBounds());
  64523. }
  64524. void Graphics::fillAll (const Colour& colourToUse) const
  64525. {
  64526. if (! colourToUse.isTransparent())
  64527. {
  64528. const Rectangle<int> clip (context->getClipBounds());
  64529. context->saveState();
  64530. context->setFill (colourToUse);
  64531. context->fillRect (clip, false);
  64532. context->restoreState();
  64533. }
  64534. }
  64535. void Graphics::fillPath (const Path& path, const AffineTransform& transform) const
  64536. {
  64537. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64538. context->fillPath (path, transform);
  64539. }
  64540. void Graphics::strokePath (const Path& path,
  64541. const PathStrokeType& strokeType,
  64542. const AffineTransform& transform) const
  64543. {
  64544. Path stroke;
  64545. strokeType.createStrokedPath (stroke, path, transform);
  64546. fillPath (stroke);
  64547. }
  64548. void Graphics::drawRect (const int x, const int y, const int width, const int height,
  64549. const int lineThickness) const
  64550. {
  64551. // passing in a silly number can cause maths problems in rendering!
  64552. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64553. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64554. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64555. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64556. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64557. }
  64558. void Graphics::drawRect (const float x, const float y, const float width, const float height, const float lineThickness) const
  64559. {
  64560. // passing in a silly number can cause maths problems in rendering!
  64561. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64562. Path p;
  64563. p.addRectangle (x, y, width, lineThickness);
  64564. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64565. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64566. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64567. fillPath (p);
  64568. }
  64569. void Graphics::drawRect (const Rectangle<int>& r, const int lineThickness) const
  64570. {
  64571. drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight(), lineThickness);
  64572. }
  64573. void Graphics::drawBevel (const int x, const int y, const int width, const int height,
  64574. const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
  64575. const bool useGradient, const bool sharpEdgeOnOutside) const
  64576. {
  64577. // passing in a silly number can cause maths problems in rendering!
  64578. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64579. if (clipRegionIntersects (x, y, width, height))
  64580. {
  64581. context->saveState();
  64582. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64583. const float ramp = oldOpacity / bevelThickness;
  64584. for (int i = bevelThickness; --i >= 0;)
  64585. {
  64586. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64587. : oldOpacity;
  64588. context->setFill (topLeftColour.withMultipliedAlpha (op));
  64589. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64590. context->setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
  64591. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64592. context->setFill (bottomRightColour.withMultipliedAlpha (op));
  64593. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64594. context->setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
  64595. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64596. }
  64597. context->restoreState();
  64598. }
  64599. }
  64600. void Graphics::fillEllipse (const float x, const float y, const float width, const float height) const
  64601. {
  64602. // passing in a silly number can cause maths problems in rendering!
  64603. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64604. Path p;
  64605. p.addEllipse (x, y, width, height);
  64606. fillPath (p);
  64607. }
  64608. void Graphics::drawEllipse (const float x, const float y, const float width, const float height,
  64609. const float lineThickness) const
  64610. {
  64611. // passing in a silly number can cause maths problems in rendering!
  64612. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64613. Path p;
  64614. p.addEllipse (x, y, width, height);
  64615. strokePath (p, PathStrokeType (lineThickness));
  64616. }
  64617. void Graphics::fillRoundedRectangle (const float x, const float y, const float width, const float height, const float cornerSize) const
  64618. {
  64619. // passing in a silly number can cause maths problems in rendering!
  64620. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64621. Path p;
  64622. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64623. fillPath (p);
  64624. }
  64625. void Graphics::fillRoundedRectangle (const Rectangle<float>& r, const float cornerSize) const
  64626. {
  64627. fillRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize);
  64628. }
  64629. void Graphics::drawRoundedRectangle (const float x, const float y, const float width, const float height,
  64630. const float cornerSize, const float lineThickness) const
  64631. {
  64632. // passing in a silly number can cause maths problems in rendering!
  64633. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64634. Path p;
  64635. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64636. strokePath (p, PathStrokeType (lineThickness));
  64637. }
  64638. void Graphics::drawRoundedRectangle (const Rectangle<float>& r, const float cornerSize, const float lineThickness) const
  64639. {
  64640. drawRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize, lineThickness);
  64641. }
  64642. void Graphics::drawArrow (const float startX, const float startY, const float endX, const float endY,
  64643. const float lineThickness, const float arrowheadWidth, const float arrowheadLength) const
  64644. {
  64645. Path p;
  64646. p.addArrow (startX, startY, endX, endY,
  64647. lineThickness, arrowheadWidth, arrowheadLength);
  64648. fillPath (p);
  64649. }
  64650. void Graphics::fillCheckerBoard (int x, int y, int width, int height,
  64651. const int checkWidth, const int checkHeight,
  64652. const Colour& colour1, const Colour& colour2) const
  64653. {
  64654. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64655. if (checkWidth > 0 && checkHeight > 0)
  64656. {
  64657. context->saveState();
  64658. if (colour1 == colour2)
  64659. {
  64660. context->setFill (colour1);
  64661. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64662. }
  64663. else
  64664. {
  64665. const Rectangle<int> clip (context->getClipBounds());
  64666. const int right = jmin (x + width, clip.getRight());
  64667. const int bottom = jmin (y + height, clip.getBottom());
  64668. int cy = 0;
  64669. while (y < bottom)
  64670. {
  64671. int cx = cy;
  64672. for (int xx = x; xx < right; xx += checkWidth)
  64673. {
  64674. context->setFill (((cx++ & 1) == 0) ? colour1 : colour2);
  64675. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64676. false);
  64677. }
  64678. ++cy;
  64679. y += checkHeight;
  64680. }
  64681. }
  64682. context->restoreState();
  64683. }
  64684. }
  64685. void Graphics::drawVerticalLine (const int x, float top, float bottom) const
  64686. {
  64687. context->drawVerticalLine (x, top, bottom);
  64688. }
  64689. void Graphics::drawHorizontalLine (const int y, float left, float right) const
  64690. {
  64691. context->drawHorizontalLine (y, left, right);
  64692. }
  64693. void Graphics::drawLine (float x1, float y1, float x2, float y2) const
  64694. {
  64695. context->drawLine (x1, y1, x2, y2);
  64696. }
  64697. void Graphics::drawLine (const float startX, const float startY,
  64698. const float endX, const float endY,
  64699. const float lineThickness) const
  64700. {
  64701. Path p;
  64702. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64703. fillPath (p);
  64704. }
  64705. void Graphics::drawLine (const Line& line) const
  64706. {
  64707. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64708. }
  64709. void Graphics::drawLine (const Line& line, const float lineThickness) const
  64710. {
  64711. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64712. }
  64713. void Graphics::drawDashedLine (const float startX, const float startY,
  64714. const float endX, const float endY,
  64715. const float* const dashLengths,
  64716. const int numDashLengths,
  64717. const float lineThickness) const
  64718. {
  64719. const double dx = endX - startX;
  64720. const double dy = endY - startY;
  64721. const double totalLen = juce_hypot (dx, dy);
  64722. if (totalLen >= 0.5)
  64723. {
  64724. const double onePixAlpha = 1.0 / totalLen;
  64725. double alpha = 0.0;
  64726. float x = startX;
  64727. float y = startY;
  64728. int n = 0;
  64729. while (alpha < 1.0f)
  64730. {
  64731. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64732. n = n % numDashLengths;
  64733. const float oldX = x;
  64734. const float oldY = y;
  64735. x = (float) (startX + dx * alpha);
  64736. y = (float) (startY + dy * alpha);
  64737. if ((n & 1) != 0)
  64738. {
  64739. if (lineThickness != 1.0f)
  64740. drawLine (oldX, oldY, x, y, lineThickness);
  64741. else
  64742. drawLine (oldX, oldY, x, y);
  64743. }
  64744. }
  64745. }
  64746. }
  64747. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality)
  64748. {
  64749. saveStateIfPending();
  64750. context->setInterpolationQuality (newQuality);
  64751. }
  64752. void Graphics::drawImageAt (const Image* const imageToDraw,
  64753. const int topLeftX, const int topLeftY,
  64754. const bool fillAlphaChannelWithCurrentBrush) const
  64755. {
  64756. if (imageToDraw != 0)
  64757. {
  64758. const int imageW = imageToDraw->getWidth();
  64759. const int imageH = imageToDraw->getHeight();
  64760. drawImage (imageToDraw,
  64761. topLeftX, topLeftY, imageW, imageH,
  64762. 0, 0, imageW, imageH,
  64763. fillAlphaChannelWithCurrentBrush);
  64764. }
  64765. }
  64766. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64767. const int destX, const int destY,
  64768. const int destW, const int destH,
  64769. const RectanglePlacement& placementWithinTarget,
  64770. const bool fillAlphaChannelWithCurrentBrush) const
  64771. {
  64772. // passing in a silly number can cause maths problems in rendering!
  64773. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64774. if (imageToDraw != 0)
  64775. {
  64776. const int imageW = imageToDraw->getWidth();
  64777. const int imageH = imageToDraw->getHeight();
  64778. if (imageW > 0 && imageH > 0)
  64779. {
  64780. double newX = 0.0, newY = 0.0;
  64781. double newW = imageW;
  64782. double newH = imageH;
  64783. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64784. destX, destY, destW, destH);
  64785. if (newW > 0 && newH > 0)
  64786. {
  64787. drawImage (imageToDraw,
  64788. roundToInt (newX), roundToInt (newY),
  64789. roundToInt (newW), roundToInt (newH),
  64790. 0, 0, imageW, imageH,
  64791. fillAlphaChannelWithCurrentBrush);
  64792. }
  64793. }
  64794. }
  64795. }
  64796. void Graphics::drawImage (const Image* const imageToDraw,
  64797. int dx, int dy, int dw, int dh,
  64798. int sx, int sy, int sw, int sh,
  64799. const bool fillAlphaChannelWithCurrentBrush) const
  64800. {
  64801. // passing in a silly number can cause maths problems in rendering!
  64802. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64803. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64804. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64805. {
  64806. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64807. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64808. .translated ((float) dx, (float) dy),
  64809. fillAlphaChannelWithCurrentBrush);
  64810. }
  64811. }
  64812. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64813. const Rectangle<int>& imageSubRegion,
  64814. const AffineTransform& transform,
  64815. const bool fillAlphaChannelWithCurrentBrush) const
  64816. {
  64817. if (imageToDraw != 0 && ! context->isClipEmpty())
  64818. {
  64819. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64820. if (fillAlphaChannelWithCurrentBrush)
  64821. {
  64822. context->saveState();
  64823. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64824. fillAll();
  64825. context->restoreState();
  64826. }
  64827. else
  64828. {
  64829. context->drawImage (*imageToDraw, srcClip, transform, false);
  64830. }
  64831. }
  64832. }
  64833. END_JUCE_NAMESPACE
  64834. /*** End of inlined file: juce_Graphics.cpp ***/
  64835. /*** Start of inlined file: juce_Justification.cpp ***/
  64836. BEGIN_JUCE_NAMESPACE
  64837. Justification::Justification (const Justification& other) throw()
  64838. : flags (other.flags)
  64839. {
  64840. }
  64841. Justification& Justification::operator= (const Justification& other) throw()
  64842. {
  64843. flags = other.flags;
  64844. return *this;
  64845. }
  64846. int Justification::getOnlyVerticalFlags() const throw()
  64847. {
  64848. return flags & (top | bottom | verticallyCentred);
  64849. }
  64850. int Justification::getOnlyHorizontalFlags() const throw()
  64851. {
  64852. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  64853. }
  64854. void Justification::applyToRectangle (int& x, int& y,
  64855. const int w, const int h,
  64856. const int spaceX, const int spaceY,
  64857. const int spaceW, const int spaceH) const throw()
  64858. {
  64859. if ((flags & horizontallyCentred) != 0)
  64860. {
  64861. x = spaceX + ((spaceW - w) >> 1);
  64862. }
  64863. else if ((flags & right) != 0)
  64864. {
  64865. x = spaceX + spaceW - w;
  64866. }
  64867. else
  64868. {
  64869. x = spaceX;
  64870. }
  64871. if ((flags & verticallyCentred) != 0)
  64872. {
  64873. y = spaceY + ((spaceH - h) >> 1);
  64874. }
  64875. else if ((flags & bottom) != 0)
  64876. {
  64877. y = spaceY + spaceH - h;
  64878. }
  64879. else
  64880. {
  64881. y = spaceY;
  64882. }
  64883. }
  64884. END_JUCE_NAMESPACE
  64885. /*** End of inlined file: juce_Justification.cpp ***/
  64886. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  64887. BEGIN_JUCE_NAMESPACE
  64888. // this will throw an assertion if you try to draw something that's not
  64889. // possible in postscript
  64890. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  64891. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  64892. #define notPossibleInPostscriptAssert jassertfalse
  64893. #else
  64894. #define notPossibleInPostscriptAssert
  64895. #endif
  64896. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  64897. const String& documentTitle,
  64898. const int totalWidth_,
  64899. const int totalHeight_)
  64900. : out (resultingPostScript),
  64901. totalWidth (totalWidth_),
  64902. totalHeight (totalHeight_),
  64903. needToClip (true)
  64904. {
  64905. stateStack.add (new SavedState());
  64906. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  64907. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  64908. out << "%!PS-Adobe-3.0 EPSF-3.0"
  64909. "\n%%BoundingBox: 0 0 600 824"
  64910. "\n%%Pages: 0"
  64911. "\n%%Creator: Raw Material Software JUCE"
  64912. "\n%%Title: " << documentTitle <<
  64913. "\n%%CreationDate: none"
  64914. "\n%%LanguageLevel: 2"
  64915. "\n%%EndComments"
  64916. "\n%%BeginProlog"
  64917. "\n%%BeginResource: JRes"
  64918. "\n/bd {bind def} bind def"
  64919. "\n/c {setrgbcolor} bd"
  64920. "\n/m {moveto} bd"
  64921. "\n/l {lineto} bd"
  64922. "\n/rl {rlineto} bd"
  64923. "\n/ct {curveto} bd"
  64924. "\n/cp {closepath} bd"
  64925. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  64926. "\n/doclip {initclip newpath} bd"
  64927. "\n/endclip {clip newpath} bd"
  64928. "\n%%EndResource"
  64929. "\n%%EndProlog"
  64930. "\n%%BeginSetup"
  64931. "\n%%EndSetup"
  64932. "\n%%Page: 1 1"
  64933. "\n%%BeginPageSetup"
  64934. "\n%%EndPageSetup\n\n"
  64935. << "40 800 translate\n"
  64936. << scale << ' ' << scale << " scale\n\n";
  64937. }
  64938. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  64939. {
  64940. }
  64941. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  64942. {
  64943. return true;
  64944. }
  64945. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  64946. {
  64947. if (x != 0 || y != 0)
  64948. {
  64949. stateStack.getLast()->xOffset += x;
  64950. stateStack.getLast()->yOffset += y;
  64951. needToClip = true;
  64952. }
  64953. }
  64954. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  64955. {
  64956. needToClip = true;
  64957. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  64958. }
  64959. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  64960. {
  64961. needToClip = true;
  64962. return stateStack.getLast()->clip.clipTo (clipRegion);
  64963. }
  64964. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  64965. {
  64966. needToClip = true;
  64967. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  64968. }
  64969. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  64970. {
  64971. writeClip();
  64972. Path p (path);
  64973. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  64974. writePath (p);
  64975. out << "clip\n";
  64976. }
  64977. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  64978. {
  64979. needToClip = true;
  64980. jassertfalse // xxx
  64981. }
  64982. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  64983. {
  64984. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  64985. }
  64986. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  64987. {
  64988. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  64989. -stateStack.getLast()->yOffset);
  64990. }
  64991. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  64992. {
  64993. return stateStack.getLast()->clip.isEmpty();
  64994. }
  64995. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  64996. : xOffset (0),
  64997. yOffset (0)
  64998. {
  64999. }
  65000. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65001. {
  65002. }
  65003. void LowLevelGraphicsPostScriptRenderer::saveState()
  65004. {
  65005. stateStack.add (new SavedState (*stateStack.getLast()));
  65006. }
  65007. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65008. {
  65009. jassert (stateStack.size() > 0);
  65010. if (stateStack.size() > 0)
  65011. stateStack.removeLast();
  65012. }
  65013. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65014. {
  65015. if (needToClip)
  65016. {
  65017. needToClip = false;
  65018. out << "doclip ";
  65019. int itemsOnLine = 0;
  65020. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65021. {
  65022. if (++itemsOnLine == 6)
  65023. {
  65024. itemsOnLine = 0;
  65025. out << '\n';
  65026. }
  65027. const Rectangle<int>& r = *i.getRectangle();
  65028. out << r.getX() << ' ' << -r.getY() << ' '
  65029. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65030. }
  65031. out << "endclip\n";
  65032. }
  65033. }
  65034. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65035. {
  65036. Colour c (Colours::white.overlaidWith (colour));
  65037. if (lastColour != c)
  65038. {
  65039. lastColour = c;
  65040. out << String (c.getFloatRed(), 3) << ' '
  65041. << String (c.getFloatGreen(), 3) << ' '
  65042. << String (c.getFloatBlue(), 3) << " c\n";
  65043. }
  65044. }
  65045. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65046. {
  65047. out << String (x, 2) << ' '
  65048. << String (-y, 2) << ' ';
  65049. }
  65050. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65051. {
  65052. out << "newpath ";
  65053. float lastX = 0.0f;
  65054. float lastY = 0.0f;
  65055. int itemsOnLine = 0;
  65056. Path::Iterator i (path);
  65057. while (i.next())
  65058. {
  65059. if (++itemsOnLine == 4)
  65060. {
  65061. itemsOnLine = 0;
  65062. out << '\n';
  65063. }
  65064. switch (i.elementType)
  65065. {
  65066. case Path::Iterator::startNewSubPath:
  65067. writeXY (i.x1, i.y1);
  65068. lastX = i.x1;
  65069. lastY = i.y1;
  65070. out << "m ";
  65071. break;
  65072. case Path::Iterator::lineTo:
  65073. writeXY (i.x1, i.y1);
  65074. lastX = i.x1;
  65075. lastY = i.y1;
  65076. out << "l ";
  65077. break;
  65078. case Path::Iterator::quadraticTo:
  65079. {
  65080. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65081. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65082. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65083. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65084. writeXY (cp1x, cp1y);
  65085. writeXY (cp2x, cp2y);
  65086. writeXY (i.x2, i.y2);
  65087. out << "ct ";
  65088. lastX = i.x2;
  65089. lastY = i.y2;
  65090. }
  65091. break;
  65092. case Path::Iterator::cubicTo:
  65093. writeXY (i.x1, i.y1);
  65094. writeXY (i.x2, i.y2);
  65095. writeXY (i.x3, i.y3);
  65096. out << "ct ";
  65097. lastX = i.x3;
  65098. lastY = i.y3;
  65099. break;
  65100. case Path::Iterator::closePath:
  65101. out << "cp ";
  65102. break;
  65103. default:
  65104. jassertfalse
  65105. break;
  65106. }
  65107. }
  65108. out << '\n';
  65109. }
  65110. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65111. {
  65112. out << "[ "
  65113. << trans.mat00 << ' '
  65114. << trans.mat10 << ' '
  65115. << trans.mat01 << ' '
  65116. << trans.mat11 << ' '
  65117. << trans.mat02 << ' '
  65118. << trans.mat12 << " ] concat ";
  65119. }
  65120. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65121. {
  65122. stateStack.getLast()->fillType = fillType;
  65123. }
  65124. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65125. {
  65126. }
  65127. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65128. {
  65129. }
  65130. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65131. {
  65132. if (stateStack.getLast()->fillType.isColour())
  65133. {
  65134. writeClip();
  65135. writeColour (stateStack.getLast()->fillType.colour);
  65136. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65137. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65138. }
  65139. else
  65140. {
  65141. Path p;
  65142. p.addRectangle (r);
  65143. fillPath (p, AffineTransform::identity);
  65144. }
  65145. }
  65146. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65147. {
  65148. if (stateStack.getLast()->fillType.isColour())
  65149. {
  65150. writeClip();
  65151. Path p (path);
  65152. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65153. (float) stateStack.getLast()->yOffset));
  65154. writePath (p);
  65155. writeColour (stateStack.getLast()->fillType.colour);
  65156. out << "fill\n";
  65157. }
  65158. else if (stateStack.getLast()->fillType.isGradient())
  65159. {
  65160. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65161. // postscript can't do semi-transparent ones.
  65162. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65163. writeClip();
  65164. out << "gsave ";
  65165. {
  65166. Path p (path);
  65167. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65168. writePath (p);
  65169. out << "clip\n";
  65170. }
  65171. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65172. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65173. // time-being, this just fills it with the average colour..
  65174. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65175. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65176. out << "grestore\n";
  65177. }
  65178. }
  65179. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65180. const int sx, const int sy,
  65181. const int maxW, const int maxH) const
  65182. {
  65183. out << "{<\n";
  65184. const int w = jmin (maxW, im.getWidth());
  65185. const int h = jmin (maxH, im.getHeight());
  65186. int charsOnLine = 0;
  65187. const Image::BitmapData srcData (im, 0, 0, w, h);
  65188. Colour pixel;
  65189. for (int y = h; --y >= 0;)
  65190. {
  65191. for (int x = 0; x < w; ++x)
  65192. {
  65193. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65194. if (x >= sx && y >= sy)
  65195. {
  65196. if (im.isARGB())
  65197. {
  65198. PixelARGB p (*(const PixelARGB*) pixelData);
  65199. p.unpremultiply();
  65200. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65201. }
  65202. else if (im.isRGB())
  65203. {
  65204. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65205. }
  65206. else
  65207. {
  65208. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65209. }
  65210. }
  65211. else
  65212. {
  65213. pixel = Colours::transparentWhite;
  65214. }
  65215. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65216. out << String::toHexString (pixelValues, 3, 0);
  65217. charsOnLine += 3;
  65218. if (charsOnLine > 100)
  65219. {
  65220. out << '\n';
  65221. charsOnLine = 0;
  65222. }
  65223. }
  65224. }
  65225. out << "\n>}\n";
  65226. }
  65227. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65228. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65229. {
  65230. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65231. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65232. writeClip();
  65233. out << "gsave ";
  65234. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65235. .scaled (1.0f, -1.0f));
  65236. RectangleList imageClip;
  65237. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65238. imageClip.clipTo (srcClip);
  65239. out << "newpath ";
  65240. int itemsOnLine = 0;
  65241. for (RectangleList::Iterator i (imageClip); i.next();)
  65242. {
  65243. if (++itemsOnLine == 6)
  65244. {
  65245. out << '\n';
  65246. itemsOnLine = 0;
  65247. }
  65248. const Rectangle<int>& r = *i.getRectangle();
  65249. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65250. }
  65251. out << " clip newpath\n";
  65252. out << w << ' ' << h << " scale\n";
  65253. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65254. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65255. out << "false 3 colorimage grestore\n";
  65256. needToClip = true;
  65257. }
  65258. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65259. {
  65260. Path p;
  65261. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65262. fillPath (p, AffineTransform::identity);
  65263. }
  65264. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65265. {
  65266. drawLine (x, top, x, bottom);
  65267. }
  65268. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65269. {
  65270. drawLine (left, y, right, y);
  65271. }
  65272. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65273. {
  65274. stateStack.getLast()->font = newFont;
  65275. }
  65276. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65277. {
  65278. return stateStack.getLast()->font;
  65279. }
  65280. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65281. {
  65282. Path p;
  65283. Font& font = stateStack.getLast()->font;
  65284. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65285. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65286. }
  65287. END_JUCE_NAMESPACE
  65288. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65289. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65290. BEGIN_JUCE_NAMESPACE
  65291. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65292. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65293. #endif
  65294. #if JUCE_MSVC
  65295. #if JUCE_DEBUG
  65296. #pragma optimize ("t", on) // optimise just this file, to avoid sluggish graphics when debugging
  65297. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65298. #endif
  65299. #pragma warning (push)
  65300. #pragma warning (disable: 4127) // "expression is constant" warning
  65301. #endif
  65302. template <class PixelType, bool replaceExisting = false>
  65303. class SolidColourEdgeTableRenderer
  65304. {
  65305. public:
  65306. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65307. : data (data_),
  65308. sourceColour (colour)
  65309. {
  65310. if (sizeof (PixelType) == 3)
  65311. {
  65312. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65313. && sourceColour.getGreen() == sourceColour.getBlue();
  65314. filler[0].set (sourceColour);
  65315. filler[1].set (sourceColour);
  65316. filler[2].set (sourceColour);
  65317. filler[3].set (sourceColour);
  65318. }
  65319. }
  65320. forcedinline void setEdgeTableYPos (const int y) throw()
  65321. {
  65322. linePixels = (PixelType*) data.getLinePointer (y);
  65323. }
  65324. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65325. {
  65326. if (replaceExisting)
  65327. linePixels[x].set (sourceColour);
  65328. else
  65329. linePixels[x].blend (sourceColour, alphaLevel);
  65330. }
  65331. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65332. {
  65333. PixelARGB p (sourceColour);
  65334. p.multiplyAlpha (alphaLevel);
  65335. PixelType* dest = linePixels + x;
  65336. if (replaceExisting || p.getAlpha() >= 0xff)
  65337. replaceLine (dest, p, width);
  65338. else
  65339. blendLine (dest, p, width);
  65340. }
  65341. private:
  65342. const Image::BitmapData& data;
  65343. PixelType* linePixels;
  65344. PixelARGB sourceColour;
  65345. PixelRGB filler [4];
  65346. bool areRGBComponentsEqual;
  65347. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65348. {
  65349. do
  65350. {
  65351. dest->blend (colour);
  65352. ++dest;
  65353. } while (--width > 0);
  65354. }
  65355. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65356. {
  65357. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65358. {
  65359. memset (dest, colour.getRed(), width * 3);
  65360. }
  65361. else
  65362. {
  65363. if (width >> 5)
  65364. {
  65365. const int* const intFiller = (const int*) filler;
  65366. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65367. {
  65368. dest->set (colour);
  65369. ++dest;
  65370. --width;
  65371. }
  65372. while (width > 4)
  65373. {
  65374. ((int*) dest) [0] = intFiller[0];
  65375. ((int*) dest) [1] = intFiller[1];
  65376. ((int*) dest) [2] = intFiller[2];
  65377. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65378. width -= 4;
  65379. }
  65380. }
  65381. while (--width >= 0)
  65382. {
  65383. dest->set (colour);
  65384. ++dest;
  65385. }
  65386. }
  65387. }
  65388. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65389. {
  65390. memset (dest, colour.getAlpha(), width);
  65391. }
  65392. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65393. {
  65394. do
  65395. {
  65396. dest->set (colour);
  65397. ++dest;
  65398. } while (--width > 0);
  65399. }
  65400. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65401. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65402. };
  65403. class LinearGradientPixelGenerator
  65404. {
  65405. public:
  65406. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65407. : lookupTable (lookupTable_), numEntries (numEntries_)
  65408. {
  65409. jassert (numEntries_ >= 0);
  65410. float x1 = gradient.x1;
  65411. float y1 = gradient.y1;
  65412. float x2 = gradient.x2;
  65413. float y2 = gradient.y2;
  65414. if (! transform.isIdentity())
  65415. {
  65416. const Line l (x2, y2, x1, y1);
  65417. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65418. float x3 = p3.getX();
  65419. float y3 = p3.getY();
  65420. transform.transformPoint (x1, y1);
  65421. transform.transformPoint (x2, y2);
  65422. transform.transformPoint (x3, y3);
  65423. const Line l2 (x2, y2, x3, y3);
  65424. const float prop = l2.findNearestPointTo (x1, y1);
  65425. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65426. x2 = newP2.getX();
  65427. y2 = newP2.getY();
  65428. }
  65429. vertical = fabs (x1 - x2) < 0.001f;
  65430. horizontal = fabs (y1 - y2) < 0.001f;
  65431. if (vertical)
  65432. {
  65433. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65434. start = roundToInt (y1 * scale);
  65435. }
  65436. else if (horizontal)
  65437. {
  65438. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65439. start = roundToInt (x1 * scale);
  65440. }
  65441. else
  65442. {
  65443. grad = (y2 - y1) / (double) (x1 - x2);
  65444. yTerm = y1 - x1 / grad;
  65445. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65446. grad *= scale;
  65447. }
  65448. }
  65449. forcedinline void setY (const int y) throw()
  65450. {
  65451. if (vertical)
  65452. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65453. else if (! horizontal)
  65454. start = roundToInt ((y - yTerm) * grad);
  65455. }
  65456. inline const PixelARGB getPixel (const int x) const throw()
  65457. {
  65458. return vertical ? linePix
  65459. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65460. }
  65461. private:
  65462. const PixelARGB* const lookupTable;
  65463. const int numEntries;
  65464. PixelARGB linePix;
  65465. int start, scale;
  65466. double grad, yTerm;
  65467. bool vertical, horizontal;
  65468. enum { numScaleBits = 12 };
  65469. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65470. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65471. };
  65472. class RadialGradientPixelGenerator
  65473. {
  65474. public:
  65475. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65476. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65477. : lookupTable (lookupTable_),
  65478. numEntries (numEntries_),
  65479. gx1 (gradient.x1),
  65480. gy1 (gradient.y1)
  65481. {
  65482. jassert (numEntries_ >= 0);
  65483. const float gdx = gradient.x1 - gradient.x2;
  65484. const float gdy = gradient.y1 - gradient.y2;
  65485. maxDist = gdx * gdx + gdy * gdy;
  65486. invScale = numEntries / sqrt (maxDist);
  65487. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65488. }
  65489. forcedinline void setY (const int y) throw()
  65490. {
  65491. dy = y - gy1;
  65492. dy *= dy;
  65493. }
  65494. inline const PixelARGB getPixel (const int px) const throw()
  65495. {
  65496. double x = px - gx1;
  65497. x *= x;
  65498. x += dy;
  65499. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65500. }
  65501. protected:
  65502. const PixelARGB* const lookupTable;
  65503. const int numEntries;
  65504. const double gx1, gy1;
  65505. double maxDist, invScale, dy;
  65506. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65507. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65508. };
  65509. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65510. {
  65511. public:
  65512. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65513. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65514. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65515. inverseTransform (transform.inverted())
  65516. {
  65517. tM10 = inverseTransform.mat10;
  65518. tM00 = inverseTransform.mat00;
  65519. }
  65520. forcedinline void setY (const int y) throw()
  65521. {
  65522. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65523. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65524. }
  65525. inline const PixelARGB getPixel (const int px) const throw()
  65526. {
  65527. double x = px;
  65528. const double y = tM10 * x + lineYM11;
  65529. x = tM00 * x + lineYM01;
  65530. x *= x;
  65531. x += y * y;
  65532. if (x >= maxDist)
  65533. return lookupTable [numEntries];
  65534. else
  65535. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65536. }
  65537. private:
  65538. double tM10, tM00, lineYM01, lineYM11;
  65539. const AffineTransform inverseTransform;
  65540. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65541. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65542. };
  65543. template <class PixelType, class GradientType>
  65544. class GradientEdgeTableRenderer : public GradientType
  65545. {
  65546. public:
  65547. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65548. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65549. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65550. destData (destData_)
  65551. {
  65552. }
  65553. forcedinline void setEdgeTableYPos (const int y) throw()
  65554. {
  65555. linePixels = (PixelType*) destData.getLinePointer (y);
  65556. GradientType::setY (y);
  65557. }
  65558. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65559. {
  65560. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65561. }
  65562. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65563. {
  65564. PixelType* dest = linePixels + x;
  65565. if (alphaLevel < 0xff)
  65566. {
  65567. do
  65568. {
  65569. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65570. } while (--width > 0);
  65571. }
  65572. else
  65573. {
  65574. do
  65575. {
  65576. (dest++)->blend (GradientType::getPixel (x++));
  65577. } while (--width > 0);
  65578. }
  65579. }
  65580. private:
  65581. const Image::BitmapData& destData;
  65582. PixelType* linePixels;
  65583. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65584. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65585. };
  65586. static forcedinline int safeModulo (int n, const int divisor) throw()
  65587. {
  65588. jassert (divisor > 0);
  65589. n %= divisor;
  65590. return (n < 0) ? (n + divisor) : n;
  65591. }
  65592. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65593. class ImageFillEdgeTableRenderer
  65594. {
  65595. public:
  65596. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65597. const Image::BitmapData& srcData_,
  65598. const int extraAlpha_,
  65599. const int x, const int y) throw()
  65600. : destData (destData_),
  65601. srcData (srcData_),
  65602. extraAlpha (extraAlpha_ + 1),
  65603. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65604. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65605. {
  65606. }
  65607. forcedinline void setEdgeTableYPos (int y) throw()
  65608. {
  65609. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65610. y -= yOffset;
  65611. if (repeatPattern)
  65612. {
  65613. jassert (y >= 0);
  65614. y %= srcData.height;
  65615. }
  65616. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65617. }
  65618. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65619. {
  65620. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65621. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65622. }
  65623. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65624. {
  65625. DestPixelType* dest = linePixels + x;
  65626. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65627. x -= xOffset;
  65628. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65629. if (alphaLevel < 0xfe)
  65630. {
  65631. do
  65632. {
  65633. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65634. } while (--width > 0);
  65635. }
  65636. else
  65637. {
  65638. if (repeatPattern)
  65639. {
  65640. do
  65641. {
  65642. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65643. } while (--width > 0);
  65644. }
  65645. else
  65646. {
  65647. copyRow (dest, sourceLineStart + x, width);
  65648. }
  65649. }
  65650. }
  65651. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65652. {
  65653. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65654. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65655. uint8* mask = (uint8*) (s + x - xOffset);
  65656. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65657. mask += PixelARGB::indexA;
  65658. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65659. }
  65660. private:
  65661. const Image::BitmapData& destData;
  65662. const Image::BitmapData& srcData;
  65663. const int extraAlpha, xOffset, yOffset;
  65664. DestPixelType* linePixels;
  65665. SrcPixelType* sourceLineStart;
  65666. template <class PixelType1, class PixelType2>
  65667. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65668. {
  65669. do
  65670. {
  65671. dest++ ->blend (*src++);
  65672. } while (--width > 0);
  65673. }
  65674. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65675. {
  65676. memcpy (dest, src, width * sizeof (PixelRGB));
  65677. }
  65678. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65679. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65680. };
  65681. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65682. class TransformedImageFillEdgeTableRenderer
  65683. {
  65684. public:
  65685. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65686. const Image::BitmapData& srcData_,
  65687. const AffineTransform& transform,
  65688. const int extraAlpha_,
  65689. const bool betterQuality_) throw()
  65690. : interpolator (transform),
  65691. destData (destData_),
  65692. srcData (srcData_),
  65693. extraAlpha (extraAlpha_ + 1),
  65694. betterQuality (betterQuality_),
  65695. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65696. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65697. maxX (srcData_.width - 1),
  65698. maxY (srcData_.height - 1),
  65699. scratchSize (2048)
  65700. {
  65701. scratchBuffer.malloc (scratchSize);
  65702. }
  65703. ~TransformedImageFillEdgeTableRenderer() throw()
  65704. {
  65705. }
  65706. forcedinline void setEdgeTableYPos (const int newY) throw()
  65707. {
  65708. y = newY;
  65709. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65710. }
  65711. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65712. {
  65713. alphaLevel *= extraAlpha;
  65714. alphaLevel >>= 8;
  65715. SrcPixelType p;
  65716. generate (&p, x, 1);
  65717. linePixels[x].blend (p, alphaLevel);
  65718. }
  65719. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65720. {
  65721. if (width > scratchSize)
  65722. {
  65723. scratchSize = width;
  65724. scratchBuffer.malloc (scratchSize);
  65725. }
  65726. SrcPixelType* span = scratchBuffer;
  65727. generate (span, x, width);
  65728. DestPixelType* dest = linePixels + x;
  65729. alphaLevel *= extraAlpha;
  65730. alphaLevel >>= 8;
  65731. if (alphaLevel < 0xfe)
  65732. {
  65733. do
  65734. {
  65735. dest++ ->blend (*span++, alphaLevel);
  65736. } while (--width > 0);
  65737. }
  65738. else
  65739. {
  65740. do
  65741. {
  65742. dest++ ->blend (*span++);
  65743. } while (--width > 0);
  65744. }
  65745. }
  65746. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65747. {
  65748. if (width > scratchSize)
  65749. {
  65750. scratchSize = width;
  65751. scratchBuffer.malloc (scratchSize);
  65752. }
  65753. y = y_;
  65754. generate (scratchBuffer, x, width);
  65755. et.clipLineToMask (x, y_,
  65756. reinterpret_cast<uint8*> (scratchBuffer.getData()) + SrcPixelType::indexA,
  65757. sizeof (SrcPixelType), width);
  65758. }
  65759. private:
  65760. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65761. {
  65762. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65763. do
  65764. {
  65765. int hiResX, hiResY;
  65766. this->interpolator.next (hiResX, hiResY);
  65767. hiResX += pixelOffsetInt;
  65768. hiResY += pixelOffsetInt;
  65769. int loResX = hiResX >> 8;
  65770. int loResY = hiResY >> 8;
  65771. if (repeatPattern)
  65772. {
  65773. loResX = safeModulo (loResX, srcData.width);
  65774. loResY = safeModulo (loResY, srcData.height);
  65775. }
  65776. if (betterQuality
  65777. && ((unsigned int) loResX) < (unsigned int) maxX
  65778. && ((unsigned int) loResY) < (unsigned int) maxY)
  65779. {
  65780. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65781. hiResX &= 255;
  65782. hiResY &= 255;
  65783. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65784. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65785. c[0] += weight * src[0];
  65786. c[1] += weight * src[1];
  65787. c[2] += weight * src[2];
  65788. c[3] += weight * src[3];
  65789. weight = hiResX * (256 - hiResY);
  65790. c[0] += weight * src[4];
  65791. c[1] += weight * src[5];
  65792. c[2] += weight * src[6];
  65793. c[3] += weight * src[7];
  65794. src += this->srcData.lineStride;
  65795. weight = (256 - hiResX) * hiResY;
  65796. c[0] += weight * src[0];
  65797. c[1] += weight * src[1];
  65798. c[2] += weight * src[2];
  65799. c[3] += weight * src[3];
  65800. weight = hiResX * hiResY;
  65801. c[0] += weight * src[4];
  65802. c[1] += weight * src[5];
  65803. c[2] += weight * src[6];
  65804. c[3] += weight * src[7];
  65805. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65806. (uint8) (c[PixelARGB::indexR] >> 16),
  65807. (uint8) (c[PixelARGB::indexG] >> 16),
  65808. (uint8) (c[PixelARGB::indexB] >> 16));
  65809. }
  65810. else
  65811. {
  65812. if (! repeatPattern)
  65813. {
  65814. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65815. if (loResX < 0) loResX = 0;
  65816. if (loResY < 0) loResY = 0;
  65817. if (loResX > maxX) loResX = maxX;
  65818. if (loResY > maxY) loResY = maxY;
  65819. }
  65820. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65821. }
  65822. ++dest;
  65823. } while (--numPixels > 0);
  65824. }
  65825. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65826. {
  65827. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65828. do
  65829. {
  65830. int hiResX, hiResY;
  65831. this->interpolator.next (hiResX, hiResY);
  65832. hiResX += pixelOffsetInt;
  65833. hiResY += pixelOffsetInt;
  65834. int loResX = hiResX >> 8;
  65835. int loResY = hiResY >> 8;
  65836. if (repeatPattern)
  65837. {
  65838. loResX = safeModulo (loResX, srcData.width);
  65839. loResY = safeModulo (loResY, srcData.height);
  65840. }
  65841. if (betterQuality
  65842. && ((unsigned int) loResX) < (unsigned int) maxX
  65843. && ((unsigned int) loResY) < (unsigned int) maxY)
  65844. {
  65845. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  65846. hiResX &= 255;
  65847. hiResY &= 255;
  65848. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65849. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  65850. c[0] += weight * src[0];
  65851. c[1] += weight * src[1];
  65852. c[2] += weight * src[2];
  65853. weight = hiResX * (256 - hiResY);
  65854. c[0] += weight * src[3];
  65855. c[1] += weight * src[4];
  65856. c[2] += weight * src[5];
  65857. src += this->srcData.lineStride;
  65858. weight = (256 - hiResX) * hiResY;
  65859. c[0] += weight * src[0];
  65860. c[1] += weight * src[1];
  65861. c[2] += weight * src[2];
  65862. weight = hiResX * hiResY;
  65863. c[0] += weight * src[3];
  65864. c[1] += weight * src[4];
  65865. c[2] += weight * src[5];
  65866. dest->setARGB ((uint8) 255,
  65867. (uint8) (c[PixelRGB::indexR] >> 16),
  65868. (uint8) (c[PixelRGB::indexG] >> 16),
  65869. (uint8) (c[PixelRGB::indexB] >> 16));
  65870. }
  65871. else
  65872. {
  65873. if (! repeatPattern)
  65874. {
  65875. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65876. if (loResX < 0) loResX = 0;
  65877. if (loResY < 0) loResY = 0;
  65878. if (loResX > maxX) loResX = maxX;
  65879. if (loResY > maxY) loResY = maxY;
  65880. }
  65881. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  65882. }
  65883. ++dest;
  65884. } while (--numPixels > 0);
  65885. }
  65886. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  65887. {
  65888. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65889. do
  65890. {
  65891. int hiResX, hiResY;
  65892. this->interpolator.next (hiResX, hiResY);
  65893. hiResX += pixelOffsetInt;
  65894. hiResY += pixelOffsetInt;
  65895. int loResX = hiResX >> 8;
  65896. int loResY = hiResY >> 8;
  65897. if (repeatPattern)
  65898. {
  65899. loResX = safeModulo (loResX, srcData.width);
  65900. loResY = safeModulo (loResY, srcData.height);
  65901. }
  65902. if (betterQuality
  65903. && ((unsigned int) loResX) < (unsigned int) maxX
  65904. && ((unsigned int) loResY) < (unsigned int) maxY)
  65905. {
  65906. hiResX &= 255;
  65907. hiResY &= 255;
  65908. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65909. uint32 c = 256 * 128;
  65910. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  65911. c += src[1] * (hiResX * (256 - hiResY));
  65912. src += this->srcData.lineStride;
  65913. c += src[0] * ((256 - hiResX) * hiResY);
  65914. c += src[1] * (hiResX * hiResY);
  65915. *((uint8*) dest) = (uint8) c;
  65916. }
  65917. else
  65918. {
  65919. if (! repeatPattern)
  65920. {
  65921. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65922. if (loResX < 0) loResX = 0;
  65923. if (loResY < 0) loResY = 0;
  65924. if (loResX > maxX) loResX = maxX;
  65925. if (loResY > maxY) loResY = maxY;
  65926. }
  65927. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  65928. }
  65929. ++dest;
  65930. } while (--numPixels > 0);
  65931. }
  65932. class TransformedImageSpanInterpolator
  65933. {
  65934. public:
  65935. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  65936. : inverseTransform (transform.inverted())
  65937. {}
  65938. void setStartOfLine (float x, float y, const int numPixels) throw()
  65939. {
  65940. float x1 = x, y1 = y;
  65941. inverseTransform.transformPoint (x1, y1);
  65942. x += numPixels;
  65943. inverseTransform.transformPoint (x, y);
  65944. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  65945. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  65946. }
  65947. void next (int& x, int& y) throw()
  65948. {
  65949. x = xBresenham.n;
  65950. xBresenham.stepToNext();
  65951. y = yBresenham.n;
  65952. yBresenham.stepToNext();
  65953. }
  65954. private:
  65955. class BresenhamInterpolator
  65956. {
  65957. public:
  65958. BresenhamInterpolator() throw() {}
  65959. void set (const int n1, const int n2, const int numSteps_) throw()
  65960. {
  65961. numSteps = jmax (1, numSteps_);
  65962. step = (n2 - n1) / numSteps;
  65963. remainder = modulo = (n2 - n1) % numSteps;
  65964. n = n1;
  65965. if (modulo <= 0)
  65966. {
  65967. modulo += numSteps;
  65968. remainder += numSteps;
  65969. --step;
  65970. }
  65971. modulo -= numSteps;
  65972. }
  65973. forcedinline void stepToNext() throw()
  65974. {
  65975. modulo += remainder;
  65976. n += step;
  65977. if (modulo > 0)
  65978. {
  65979. modulo -= numSteps;
  65980. ++n;
  65981. }
  65982. }
  65983. int n;
  65984. private:
  65985. int numSteps, step, modulo, remainder;
  65986. };
  65987. const AffineTransform inverseTransform;
  65988. BresenhamInterpolator xBresenham, yBresenham;
  65989. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  65990. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  65991. };
  65992. TransformedImageSpanInterpolator interpolator;
  65993. const Image::BitmapData& destData;
  65994. const Image::BitmapData& srcData;
  65995. const int extraAlpha;
  65996. const bool betterQuality;
  65997. const float pixelOffset;
  65998. const int pixelOffsetInt, maxX, maxY;
  65999. int y;
  66000. DestPixelType* linePixels;
  66001. HeapBlock <SrcPixelType> scratchBuffer;
  66002. int scratchSize;
  66003. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66004. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66005. };
  66006. class LLGCSavedState
  66007. {
  66008. public:
  66009. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66010. const Font& font_, const FillType& fillType_,
  66011. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66012. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66013. xOffset (xOffset_), yOffset (yOffset_),
  66014. font (font_), fillType (fillType_),
  66015. interpolationQuality (interpolationQuality_)
  66016. {
  66017. }
  66018. LLGCSavedState (const LLGCSavedState& other) throw()
  66019. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66020. yOffset (other.yOffset), font (other.font),
  66021. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66022. {
  66023. }
  66024. ~LLGCSavedState() throw()
  66025. {
  66026. }
  66027. bool clipToRectangle (const Rectangle<int>& r) throw()
  66028. {
  66029. dupeEdgeTableIfMultiplyReferenced();
  66030. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66031. return ! edgeTable->edgeTable.isEmpty();
  66032. }
  66033. bool clipToRectangleList (const RectangleList& r) throw()
  66034. {
  66035. dupeEdgeTableIfMultiplyReferenced();
  66036. RectangleList offsetList (r);
  66037. offsetList.offsetAll (xOffset, yOffset);
  66038. EdgeTable e2 (offsetList);
  66039. edgeTable->edgeTable.clipToEdgeTable (e2);
  66040. return ! edgeTable->edgeTable.isEmpty();
  66041. }
  66042. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66043. {
  66044. dupeEdgeTableIfMultiplyReferenced();
  66045. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66046. return ! edgeTable->edgeTable.isEmpty();
  66047. }
  66048. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66049. {
  66050. dupeEdgeTableIfMultiplyReferenced();
  66051. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66052. edgeTable->edgeTable.clipToEdgeTable (et);
  66053. }
  66054. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66055. {
  66056. et.clipToEdgeTable (edgeTable->edgeTable);
  66057. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66058. if (fillType.isGradient())
  66059. {
  66060. jassert (! replaceContents); // that option is just for solid colours
  66061. ColourGradient g2 (*(fillType.gradient));
  66062. g2.multiplyOpacity (fillType.getOpacity());
  66063. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66064. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66065. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66066. const bool isIdentity = transform.isOnlyTranslation();
  66067. if (isIdentity)
  66068. {
  66069. // If our translation doesn't involve any distortion, we can speed it up..
  66070. transform.transformPoint (g2.x1, g2.y1);
  66071. transform.transformPoint (g2.x2, g2.y2);
  66072. transform = AffineTransform::identity;
  66073. }
  66074. HeapBlock <PixelARGB> lookupTable;
  66075. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66076. jassert (numLookupEntries > 0);
  66077. switch (image.getFormat())
  66078. {
  66079. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66080. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66081. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66082. }
  66083. }
  66084. else if (fillType.isTiledImage())
  66085. {
  66086. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66087. }
  66088. else
  66089. {
  66090. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66091. switch (image.getFormat())
  66092. {
  66093. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66094. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66095. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66096. }
  66097. }
  66098. }
  66099. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66100. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66101. {
  66102. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66103. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66104. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66105. const int alpha = fillType.colour.getAlpha();
  66106. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66107. if (transform.isOnlyTranslation())
  66108. {
  66109. // If our translation doesn't involve any distortion, just use a simple blit..
  66110. int tx = (int) (transform.getTranslationX() * 256.0f);
  66111. int ty = (int) (transform.getTranslationY() * 256.0f);
  66112. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66113. {
  66114. tx = ((tx + 128) >> 8);
  66115. ty = ((ty + 128) >> 8);
  66116. if (tiledFillClipRegion != 0)
  66117. {
  66118. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66119. }
  66120. else
  66121. {
  66122. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66123. et.clipToEdgeTable (edgeTable->edgeTable);
  66124. if (! et.isEmpty())
  66125. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66126. }
  66127. return;
  66128. }
  66129. }
  66130. if (transform.isSingularity())
  66131. return;
  66132. if (tiledFillClipRegion != 0)
  66133. {
  66134. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66135. }
  66136. else
  66137. {
  66138. Path p;
  66139. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66140. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66141. et.clipToEdgeTable (edgeTable->edgeTable);
  66142. if (! et.isEmpty())
  66143. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66144. }
  66145. }
  66146. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66147. {
  66148. if (! image.hasAlphaChannel())
  66149. {
  66150. Path p;
  66151. p.addRectangle (srcClip);
  66152. clipToPath (p, t);
  66153. return;
  66154. }
  66155. dupeEdgeTableIfMultiplyReferenced();
  66156. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66157. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66158. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66159. EdgeTable& et = edgeTable->edgeTable;
  66160. if (transform.isOnlyTranslation())
  66161. {
  66162. // If our translation doesn't involve any distortion, just use a simple blit..
  66163. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66164. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66165. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66166. {
  66167. const int imageX = ((tx + 128) >> 8);
  66168. const int imageY = ((ty + 128) >> 8);
  66169. if (image.getFormat() == Image::ARGB)
  66170. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66171. else
  66172. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66173. return;
  66174. }
  66175. }
  66176. if (transform.isSingularity())
  66177. {
  66178. et.clipToRectangle (Rectangle<int>());
  66179. return;
  66180. }
  66181. {
  66182. Path p;
  66183. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66184. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66185. et.clipToEdgeTable (et2);
  66186. }
  66187. if (! et.isEmpty())
  66188. {
  66189. if (image.getFormat() == Image::ARGB)
  66190. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66191. else
  66192. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66193. }
  66194. }
  66195. template <class SrcPixelType>
  66196. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66197. {
  66198. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66199. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66200. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66201. et.getMaximumBounds().getWidth());
  66202. }
  66203. template <class SrcPixelType>
  66204. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66205. {
  66206. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66207. et.clipToRectangle (r);
  66208. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66209. for (int y = 0; y < r.getHeight(); ++y)
  66210. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66211. }
  66212. class EdgeTableHolder : public ReferenceCountedObject
  66213. {
  66214. public:
  66215. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66216. EdgeTable edgeTable;
  66217. };
  66218. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66219. int xOffset, yOffset;
  66220. Font font;
  66221. FillType fillType;
  66222. Graphics::ResamplingQuality interpolationQuality;
  66223. private:
  66224. LLGCSavedState& operator= (const LLGCSavedState&);
  66225. void dupeEdgeTableIfMultiplyReferenced() throw()
  66226. {
  66227. if (edgeTable->getReferenceCount() > 1)
  66228. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66229. }
  66230. template <class DestPixelType>
  66231. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66232. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66233. {
  66234. jassert (destData.pixelStride == sizeof (DestPixelType));
  66235. if (g.isRadial)
  66236. {
  66237. if (isIdentity)
  66238. {
  66239. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66240. et.iterate (renderer);
  66241. }
  66242. else
  66243. {
  66244. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66245. et.iterate (renderer);
  66246. }
  66247. }
  66248. else
  66249. {
  66250. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66251. et.iterate (renderer);
  66252. }
  66253. }
  66254. template <class DestPixelType>
  66255. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66256. {
  66257. jassert (destData.pixelStride == sizeof (DestPixelType));
  66258. if (replaceContents)
  66259. {
  66260. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66261. et.iterate (r);
  66262. }
  66263. else
  66264. {
  66265. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66266. et.iterate (r);
  66267. }
  66268. }
  66269. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66270. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66271. {
  66272. switch (destImage.getFormat())
  66273. {
  66274. case Image::ARGB:
  66275. switch (srcImage.getFormat())
  66276. {
  66277. case Image::ARGB:
  66278. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66279. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66280. break;
  66281. case Image::RGB:
  66282. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66283. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66284. break;
  66285. default:
  66286. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66287. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66288. break;
  66289. }
  66290. break;
  66291. case Image::RGB:
  66292. switch (srcImage.getFormat())
  66293. {
  66294. case Image::ARGB:
  66295. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66296. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66297. break;
  66298. case Image::RGB:
  66299. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66300. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66301. break;
  66302. default:
  66303. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66304. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66305. break;
  66306. }
  66307. break;
  66308. default:
  66309. switch (srcImage.getFormat())
  66310. {
  66311. case Image::ARGB:
  66312. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66313. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66314. break;
  66315. case Image::RGB:
  66316. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66317. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66318. break;
  66319. default:
  66320. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66321. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66322. break;
  66323. }
  66324. break;
  66325. }
  66326. }
  66327. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66328. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66329. {
  66330. switch (destImage.getFormat())
  66331. {
  66332. case Image::ARGB:
  66333. switch (srcImage.getFormat())
  66334. {
  66335. case Image::ARGB:
  66336. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66337. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66338. break;
  66339. case Image::RGB:
  66340. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66341. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66342. break;
  66343. default:
  66344. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66345. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66346. break;
  66347. }
  66348. break;
  66349. case Image::RGB:
  66350. switch (srcImage.getFormat())
  66351. {
  66352. case Image::ARGB:
  66353. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66354. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66355. break;
  66356. case Image::RGB:
  66357. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66358. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66359. break;
  66360. default:
  66361. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66362. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66363. break;
  66364. }
  66365. break;
  66366. default:
  66367. switch (srcImage.getFormat())
  66368. {
  66369. case Image::ARGB:
  66370. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66371. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66372. break;
  66373. case Image::RGB:
  66374. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66375. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66376. break;
  66377. default:
  66378. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66379. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66380. break;
  66381. }
  66382. break;
  66383. }
  66384. }
  66385. };
  66386. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66387. : image (image_)
  66388. {
  66389. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66390. FillType(), Graphics::mediumResamplingQuality);
  66391. }
  66392. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66393. {
  66394. }
  66395. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66396. {
  66397. return false;
  66398. }
  66399. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66400. {
  66401. currentState->xOffset += x;
  66402. currentState->yOffset += y;
  66403. }
  66404. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66405. {
  66406. return currentState->clipToRectangle (r);
  66407. }
  66408. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66409. {
  66410. return currentState->clipToRectangleList (clipRegion);
  66411. }
  66412. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66413. {
  66414. currentState->excludeClipRectangle (r);
  66415. }
  66416. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66417. {
  66418. currentState->clipToPath (path, transform);
  66419. }
  66420. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66421. {
  66422. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66423. }
  66424. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66425. {
  66426. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66427. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66428. }
  66429. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66430. {
  66431. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66432. }
  66433. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66434. {
  66435. return currentState->edgeTable->edgeTable.isEmpty();
  66436. }
  66437. void LowLevelGraphicsSoftwareRenderer::saveState()
  66438. {
  66439. stateStack.add (new LLGCSavedState (*currentState));
  66440. }
  66441. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66442. {
  66443. LLGCSavedState* const top = stateStack.getLast();
  66444. if (top != 0)
  66445. {
  66446. currentState = top;
  66447. stateStack.removeLast (1, false);
  66448. }
  66449. else
  66450. {
  66451. jassertfalse // trying to pop with an empty stack!
  66452. }
  66453. }
  66454. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66455. {
  66456. currentState->fillType = fillType;
  66457. }
  66458. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66459. {
  66460. currentState->fillType.setOpacity (newOpacity);
  66461. }
  66462. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66463. {
  66464. currentState->interpolationQuality = quality;
  66465. }
  66466. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66467. {
  66468. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66469. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66470. if (! clipped.isEmpty())
  66471. {
  66472. EdgeTable et (clipped);
  66473. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66474. }
  66475. }
  66476. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66477. {
  66478. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66479. path, transform.translated ((float) currentState->xOffset,
  66480. (float) currentState->yOffset));
  66481. currentState->fillEdgeTable (image, et);
  66482. }
  66483. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66484. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66485. {
  66486. jassert (sourceImage.getBounds().contains (srcClip));
  66487. currentState->renderImage (image, sourceImage, srcClip, transform,
  66488. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66489. }
  66490. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66491. {
  66492. Path p;
  66493. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66494. fillPath (p, AffineTransform::identity);
  66495. }
  66496. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66497. {
  66498. if (bottom > top)
  66499. {
  66500. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66501. currentState->fillEdgeTable (image, et);
  66502. }
  66503. }
  66504. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66505. {
  66506. if (right > left)
  66507. {
  66508. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66509. (float) (right - left), 1.0f);
  66510. currentState->fillEdgeTable (image, et);
  66511. }
  66512. }
  66513. class GlyphCache : private DeletedAtShutdown
  66514. {
  66515. public:
  66516. GlyphCache() throw()
  66517. : accessCounter (0), hits (0), misses (0)
  66518. {
  66519. for (int i = 120; --i >= 0;)
  66520. glyphs.add (new CachedGlyph());
  66521. }
  66522. ~GlyphCache() throw()
  66523. {
  66524. clearSingletonInstance();
  66525. }
  66526. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66527. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66528. {
  66529. ++accessCounter;
  66530. int oldestCounter = std::numeric_limits<int>::max();
  66531. CachedGlyph* oldest = 0;
  66532. for (int i = glyphs.size(); --i >= 0;)
  66533. {
  66534. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66535. if (glyph->glyph == glyphNumber && glyph->font == font)
  66536. {
  66537. ++hits;
  66538. glyph->lastAccessCount = accessCounter;
  66539. glyph->draw (state, image, x, y);
  66540. return;
  66541. }
  66542. if (glyph->lastAccessCount <= oldestCounter)
  66543. {
  66544. oldestCounter = glyph->lastAccessCount;
  66545. oldest = glyph;
  66546. }
  66547. }
  66548. if (hits + ++misses > (glyphs.size() << 4))
  66549. {
  66550. if (misses * 2 > hits)
  66551. {
  66552. for (int i = 32; --i >= 0;)
  66553. glyphs.add (new CachedGlyph());
  66554. }
  66555. hits = misses = 0;
  66556. oldest = glyphs.getLast();
  66557. }
  66558. jassert (oldest != 0);
  66559. oldest->lastAccessCount = accessCounter;
  66560. oldest->generate (font, glyphNumber);
  66561. oldest->draw (state, image, x, y);
  66562. }
  66563. class CachedGlyph
  66564. {
  66565. public:
  66566. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66567. ~CachedGlyph() {}
  66568. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66569. {
  66570. if (edgeTable != 0)
  66571. {
  66572. EdgeTable et (*edgeTable);
  66573. et.translate (x, roundToInt (y));
  66574. state.fillEdgeTable (image, et, false);
  66575. }
  66576. }
  66577. void generate (const Font& newFont, const int glyphNumber) throw()
  66578. {
  66579. font = newFont;
  66580. glyph = glyphNumber;
  66581. edgeTable = 0;
  66582. Path glyphPath;
  66583. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66584. if (! glyphPath.isEmpty())
  66585. {
  66586. const float fontHeight = font.getHeight();
  66587. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66588. .translated (0.0f, -0.5f));
  66589. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66590. glyphPath, transform);
  66591. }
  66592. }
  66593. int glyph, lastAccessCount;
  66594. Font font;
  66595. juce_UseDebuggingNewOperator
  66596. private:
  66597. ScopedPointer <EdgeTable> edgeTable;
  66598. CachedGlyph (const CachedGlyph&);
  66599. CachedGlyph& operator= (const CachedGlyph&);
  66600. };
  66601. juce_UseDebuggingNewOperator
  66602. private:
  66603. OwnedArray <CachedGlyph> glyphs;
  66604. int accessCounter, hits, misses;
  66605. GlyphCache (const GlyphCache&);
  66606. GlyphCache& operator= (const GlyphCache&);
  66607. };
  66608. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66609. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66610. {
  66611. currentState->font = newFont;
  66612. }
  66613. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66614. {
  66615. return currentState->font;
  66616. }
  66617. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66618. {
  66619. Font& f = currentState->font;
  66620. if (transform.isOnlyTranslation())
  66621. {
  66622. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66623. transform.getTranslationX() + (float) currentState->xOffset,
  66624. transform.getTranslationY() + (float) currentState->yOffset);
  66625. }
  66626. else
  66627. {
  66628. Path p;
  66629. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66630. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66631. }
  66632. }
  66633. #if JUCE_MSVC
  66634. #pragma warning (pop)
  66635. #if JUCE_DEBUG
  66636. #pragma optimize ("", on) // resets optimisations to the project defaults
  66637. #endif
  66638. #endif
  66639. END_JUCE_NAMESPACE
  66640. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66641. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66642. BEGIN_JUCE_NAMESPACE
  66643. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66644. : flags (other.flags)
  66645. {
  66646. }
  66647. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66648. {
  66649. flags = other.flags;
  66650. return *this;
  66651. }
  66652. void RectanglePlacement::applyTo (double& x, double& y,
  66653. double& w, double& h,
  66654. const double dx, const double dy,
  66655. const double dw, const double dh) const throw()
  66656. {
  66657. if (w == 0 || h == 0)
  66658. return;
  66659. if ((flags & stretchToFit) != 0)
  66660. {
  66661. x = dx;
  66662. y = dy;
  66663. w = dw;
  66664. h = dh;
  66665. }
  66666. else
  66667. {
  66668. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66669. : jmin (dw / w, dh / h);
  66670. if ((flags & onlyReduceInSize) != 0)
  66671. scale = jmin (scale, 1.0);
  66672. if ((flags & onlyIncreaseInSize) != 0)
  66673. scale = jmax (scale, 1.0);
  66674. w *= scale;
  66675. h *= scale;
  66676. if ((flags & xLeft) != 0)
  66677. x = dx;
  66678. else if ((flags & xRight) != 0)
  66679. x = dx + dw - w;
  66680. else
  66681. x = dx + (dw - w) * 0.5;
  66682. if ((flags & yTop) != 0)
  66683. y = dy;
  66684. else if ((flags & yBottom) != 0)
  66685. y = dy + dh - h;
  66686. else
  66687. y = dy + (dh - h) * 0.5;
  66688. }
  66689. }
  66690. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66691. float w, float h,
  66692. const float dx, const float dy,
  66693. const float dw, const float dh) const throw()
  66694. {
  66695. if (w == 0 || h == 0)
  66696. return AffineTransform::identity;
  66697. const float scaleX = dw / w;
  66698. const float scaleY = dh / h;
  66699. if ((flags & stretchToFit) != 0)
  66700. return AffineTransform::translation (-x, -y)
  66701. .scaled (scaleX, scaleY)
  66702. .translated (dx, dy);
  66703. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66704. : jmin (scaleX, scaleY);
  66705. if ((flags & onlyReduceInSize) != 0)
  66706. scale = jmin (scale, 1.0f);
  66707. if ((flags & onlyIncreaseInSize) != 0)
  66708. scale = jmax (scale, 1.0f);
  66709. w *= scale;
  66710. h *= scale;
  66711. float newX = dx;
  66712. if ((flags & xRight) != 0)
  66713. newX += dw - w; // right
  66714. else if ((flags & xLeft) == 0)
  66715. newX += (dw - w) / 2.0f; // centre
  66716. float newY = dy;
  66717. if ((flags & yBottom) != 0)
  66718. newY += dh - h; // bottom
  66719. else if ((flags & yTop) == 0)
  66720. newY += (dh - h) / 2.0f; // centre
  66721. return AffineTransform::translation (-x, -y)
  66722. .scaled (scale, scale)
  66723. .translated (newX, newY);
  66724. }
  66725. END_JUCE_NAMESPACE
  66726. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66727. /*** Start of inlined file: juce_Drawable.cpp ***/
  66728. BEGIN_JUCE_NAMESPACE
  66729. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66730. const AffineTransform& transform_,
  66731. const float opacity_) throw()
  66732. : g (g_),
  66733. transform (transform_),
  66734. opacity (opacity_)
  66735. {
  66736. }
  66737. Drawable::Drawable()
  66738. {
  66739. }
  66740. Drawable::~Drawable()
  66741. {
  66742. }
  66743. void Drawable::draw (Graphics& g, const float opacity,
  66744. const AffineTransform& transform) const
  66745. {
  66746. render (RenderingContext (g, transform, opacity));
  66747. }
  66748. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66749. {
  66750. draw (g, opacity, AffineTransform::translation (x, y));
  66751. }
  66752. void Drawable::drawWithin (Graphics& g,
  66753. const int destX,
  66754. const int destY,
  66755. const int destW,
  66756. const int destH,
  66757. const RectanglePlacement& placement,
  66758. const float opacity) const
  66759. {
  66760. if (destW > 0 && destH > 0)
  66761. {
  66762. Rectangle<float> bounds (getBounds());
  66763. draw (g, opacity,
  66764. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66765. (float) destX, (float) destY,
  66766. (float) destW, (float) destH));
  66767. }
  66768. }
  66769. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66770. {
  66771. Drawable* result = 0;
  66772. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66773. if (image != 0)
  66774. {
  66775. DrawableImage* const di = new DrawableImage();
  66776. di->setImage (image, true);
  66777. result = di;
  66778. }
  66779. else
  66780. {
  66781. const String asString (String::createStringFromData (data, (int) numBytes));
  66782. XmlDocument doc (asString);
  66783. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66784. if (outer != 0 && outer->hasTagName ("svg"))
  66785. {
  66786. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66787. if (svg != 0)
  66788. result = Drawable::createFromSVG (*svg);
  66789. }
  66790. }
  66791. return result;
  66792. }
  66793. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66794. {
  66795. MemoryBlock mb;
  66796. dataSource.readIntoMemoryBlock (mb);
  66797. return createFromImageData (mb.getData(), mb.getSize());
  66798. }
  66799. Drawable* Drawable::createFromImageFile (const File& file)
  66800. {
  66801. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66802. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66803. }
  66804. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66805. {
  66806. Drawable* d = DrawablePath::createFromValueTree (tree);
  66807. if (d == 0)
  66808. {
  66809. d = DrawableComposite::createFromValueTree (tree);
  66810. if (d == 0)
  66811. {
  66812. d = DrawableImage::createFromValueTree (tree);
  66813. if (d == 0)
  66814. d = DrawableText::createFromValueTree (tree);
  66815. }
  66816. }
  66817. return d;
  66818. }
  66819. END_JUCE_NAMESPACE
  66820. /*** End of inlined file: juce_Drawable.cpp ***/
  66821. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66822. BEGIN_JUCE_NAMESPACE
  66823. DrawableComposite::DrawableComposite()
  66824. {
  66825. }
  66826. DrawableComposite::~DrawableComposite()
  66827. {
  66828. }
  66829. void DrawableComposite::insertDrawable (Drawable* drawable,
  66830. const AffineTransform& transform,
  66831. const int index)
  66832. {
  66833. if (drawable != 0)
  66834. {
  66835. if (! drawables.contains (drawable))
  66836. {
  66837. drawables.insert (index, drawable);
  66838. if (transform.isIdentity())
  66839. transforms.insert (index, 0);
  66840. else
  66841. transforms.insert (index, new AffineTransform (transform));
  66842. }
  66843. else
  66844. {
  66845. jassertfalse // trying to add a drawable that's already in here!
  66846. }
  66847. }
  66848. }
  66849. void DrawableComposite::insertDrawable (const Drawable& drawable,
  66850. const AffineTransform& transform,
  66851. const int index)
  66852. {
  66853. insertDrawable (drawable.createCopy(), transform, index);
  66854. }
  66855. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  66856. {
  66857. drawables.remove (index, deleteDrawable);
  66858. transforms.remove (index);
  66859. }
  66860. void DrawableComposite::bringToFront (const int index)
  66861. {
  66862. if (index >= 0 && index < drawables.size() - 1)
  66863. {
  66864. drawables.move (index, -1);
  66865. transforms.move (index, -1);
  66866. }
  66867. }
  66868. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  66869. {
  66870. if (drawables.size() > 0 && context.opacity > 0)
  66871. {
  66872. if (context.opacity >= 1.0f || drawables.size() == 1)
  66873. {
  66874. Drawable::RenderingContext contextCopy (context);
  66875. for (int i = 0; i < drawables.size(); ++i)
  66876. {
  66877. const AffineTransform* const t = transforms.getUnchecked(i);
  66878. contextCopy.transform = (t == 0) ? context.transform
  66879. : t->followedBy (context.transform);
  66880. drawables.getUnchecked(i)->render (contextCopy);
  66881. }
  66882. }
  66883. else
  66884. {
  66885. // To correctly render a whole composite layer with an overall transparency,
  66886. // we need to render everything opaquely into a temp buffer, then blend that
  66887. // with the target opacity...
  66888. const Rectangle<int> clipBounds (context.g.getClipBounds());
  66889. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  66890. {
  66891. Graphics tempG (tempImage);
  66892. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  66893. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  66894. render (tempContext);
  66895. }
  66896. context.g.setOpacity (context.opacity);
  66897. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  66898. }
  66899. }
  66900. }
  66901. const Rectangle<float> DrawableComposite::getBounds() const
  66902. {
  66903. Rectangle<float> bounds;
  66904. for (int i = 0; i < drawables.size(); ++i)
  66905. {
  66906. const Drawable* const d = drawables.getUnchecked(i);
  66907. const AffineTransform* const t = transforms.getUnchecked(i);
  66908. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  66909. : d->getBounds().transformed (*t));
  66910. if (bounds.isEmpty())
  66911. bounds = childBounds;
  66912. else if (! childBounds.isEmpty())
  66913. bounds = bounds.getUnion (childBounds);
  66914. }
  66915. return bounds;
  66916. }
  66917. bool DrawableComposite::hitTest (float x, float y) const
  66918. {
  66919. for (int i = 0; i < drawables.size(); ++i)
  66920. {
  66921. float tx = x;
  66922. float ty = y;
  66923. const AffineTransform* const t = transforms.getUnchecked(i);
  66924. if (t != 0)
  66925. t->inverted().transformPoint (tx, ty);
  66926. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  66927. return true;
  66928. }
  66929. return false;
  66930. }
  66931. Drawable* DrawableComposite::createCopy() const
  66932. {
  66933. DrawableComposite* const dc = new DrawableComposite();
  66934. for (int i = 0; i < drawables.size(); ++i)
  66935. {
  66936. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  66937. const AffineTransform* const t = transforms.getUnchecked(i);
  66938. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  66939. }
  66940. return dc;
  66941. }
  66942. ValueTree DrawableComposite::createValueTree() const throw()
  66943. {
  66944. ValueTree v ("Group");
  66945. if (getName().isNotEmpty())
  66946. v.setProperty ("id", getName(), 0);
  66947. for (int i = 0; i < drawables.size(); ++i)
  66948. {
  66949. Drawable* const d = drawables.getUnchecked(i);
  66950. ValueTree child (d->createValueTree());
  66951. AffineTransform* transform = transforms.getUnchecked(i);
  66952. if (transform != 0)
  66953. {
  66954. String t;
  66955. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  66956. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  66957. child.setProperty ("transform", t, 0);
  66958. }
  66959. v.addChild (child, -1, 0);
  66960. }
  66961. return v;
  66962. }
  66963. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  66964. {
  66965. if (! tree.hasType ("Group"))
  66966. return 0;
  66967. DrawableComposite* dc = new DrawableComposite();
  66968. dc->setName (tree ["id"]);
  66969. for (int i = 0; i < tree.getNumChildren(); ++i)
  66970. {
  66971. ValueTree childTree (tree.getChild (i));
  66972. Drawable* d = Drawable::createFromValueTree (childTree);
  66973. if (d != 0)
  66974. {
  66975. AffineTransform transform;
  66976. const String transformAtt (childTree ["transform"].toString());
  66977. if (transformAtt.isNotEmpty())
  66978. {
  66979. StringArray tokens;
  66980. tokens.addTokens (transformAtt.trim(), false);
  66981. tokens.removeEmptyStrings (true);
  66982. if (tokens.size() == 6)
  66983. {
  66984. float f[6];
  66985. for (int j = 0; j < 6; ++j)
  66986. f[j] = (float) tokens[j].getDoubleValue();
  66987. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  66988. }
  66989. }
  66990. dc->insertDrawable (d, transform);
  66991. }
  66992. }
  66993. return dc;
  66994. }
  66995. END_JUCE_NAMESPACE
  66996. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  66997. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  66998. BEGIN_JUCE_NAMESPACE
  66999. DrawableImage::DrawableImage()
  67000. : image (0),
  67001. canDeleteImage (false),
  67002. opacity (1.0f),
  67003. overlayColour (0x00000000)
  67004. {
  67005. }
  67006. DrawableImage::~DrawableImage()
  67007. {
  67008. clearImage();
  67009. }
  67010. void DrawableImage::clearImage()
  67011. {
  67012. if (canDeleteImage && image != 0)
  67013. ImageCache::releaseOrDelete (image);
  67014. image = 0;
  67015. }
  67016. void DrawableImage::setImage (const Image& imageToCopy)
  67017. {
  67018. clearImage();
  67019. image = new Image (imageToCopy);
  67020. canDeleteImage = true;
  67021. }
  67022. void DrawableImage::setImage (Image* imageToUse,
  67023. const bool releaseWhenNotNeeded)
  67024. {
  67025. clearImage();
  67026. image = imageToUse;
  67027. canDeleteImage = releaseWhenNotNeeded;
  67028. }
  67029. void DrawableImage::setOpacity (const float newOpacity)
  67030. {
  67031. opacity = newOpacity;
  67032. }
  67033. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67034. {
  67035. overlayColour = newOverlayColour;
  67036. }
  67037. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67038. {
  67039. if (image != 0)
  67040. {
  67041. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67042. {
  67043. context.g.setOpacity (context.opacity * opacity);
  67044. context.g.drawImageTransformed (image, image->getBounds(),
  67045. context.transform, false);
  67046. }
  67047. if (! overlayColour.isTransparent())
  67048. {
  67049. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67050. context.g.drawImageTransformed (image, image->getBounds(),
  67051. context.transform, true);
  67052. }
  67053. }
  67054. }
  67055. const Rectangle<float> DrawableImage::getBounds() const
  67056. {
  67057. if (image == 0)
  67058. return Rectangle<float>();
  67059. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67060. }
  67061. bool DrawableImage::hitTest (float x, float y) const
  67062. {
  67063. return image != 0
  67064. && x >= 0.0f
  67065. && y >= 0.0f
  67066. && x < image->getWidth()
  67067. && y < image->getHeight()
  67068. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67069. }
  67070. Drawable* DrawableImage::createCopy() const
  67071. {
  67072. DrawableImage* const di = new DrawableImage();
  67073. di->opacity = opacity;
  67074. di->overlayColour = overlayColour;
  67075. if (image != 0)
  67076. {
  67077. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67078. {
  67079. di->setImage (*image);
  67080. }
  67081. else
  67082. {
  67083. ImageCache::incReferenceCount (image);
  67084. di->setImage (image, true);
  67085. }
  67086. }
  67087. return di;
  67088. }
  67089. ValueTree DrawableImage::createValueTree() const throw()
  67090. {
  67091. ValueTree v ("Image");
  67092. if (getName().isNotEmpty())
  67093. v.setProperty ("id", getName(), 0);
  67094. if (opacity < 1.0f)
  67095. v.setProperty ("opacity", (double) opacity, 0);
  67096. if (! overlayColour.isTransparent())
  67097. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67098. if (image != 0)
  67099. {
  67100. MemoryOutputStream imageData;
  67101. PNGImageFormat pngFormat;
  67102. if (pngFormat.writeImageToStream (*image, imageData))
  67103. {
  67104. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67105. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67106. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67107. v.setProperty ("data", base64, 0);
  67108. }
  67109. }
  67110. return v;
  67111. }
  67112. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67113. {
  67114. if (! tree.hasType ("Image"))
  67115. return 0;
  67116. DrawableImage* di = new DrawableImage();
  67117. di->setName (tree ["id"]);
  67118. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67119. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67120. MemoryBlock imageData;
  67121. if (imageData.fromBase64Encoding (tree ["data"]))
  67122. {
  67123. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67124. if (im == 0)
  67125. return false;
  67126. di->setImage (im, true);
  67127. }
  67128. return di;
  67129. }
  67130. END_JUCE_NAMESPACE
  67131. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67132. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67133. BEGIN_JUCE_NAMESPACE
  67134. DrawablePath::DrawablePath()
  67135. : mainFill (Colours::black),
  67136. strokeFill (Colours::transparentBlack),
  67137. strokeType (0.0f)
  67138. {
  67139. }
  67140. DrawablePath::~DrawablePath()
  67141. {
  67142. }
  67143. void DrawablePath::setPath (const Path& newPath) throw()
  67144. {
  67145. path = newPath;
  67146. updateOutline();
  67147. }
  67148. void DrawablePath::setFill (const FillType& newFill) throw()
  67149. {
  67150. mainFill = newFill;
  67151. }
  67152. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67153. {
  67154. strokeFill = newFill;
  67155. }
  67156. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67157. {
  67158. strokeType = newStrokeType;
  67159. updateOutline();
  67160. }
  67161. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67162. {
  67163. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67164. }
  67165. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67166. {
  67167. {
  67168. FillType f (mainFill);
  67169. if (f.isGradient())
  67170. f.gradient->multiplyOpacity (context.opacity);
  67171. f.transform = f.transform.followedBy (context.transform);
  67172. context.g.setFillType (f);
  67173. context.g.fillPath (path, context.transform);
  67174. }
  67175. if (strokeType.getStrokeThickness() > 0.0f)
  67176. {
  67177. FillType f (strokeFill);
  67178. if (f.isGradient())
  67179. f.gradient->multiplyOpacity (context.opacity);
  67180. f.transform = f.transform.followedBy (context.transform);
  67181. context.g.setFillType (f);
  67182. context.g.fillPath (stroke, context.transform);
  67183. }
  67184. }
  67185. void DrawablePath::updateOutline()
  67186. {
  67187. stroke.clear();
  67188. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67189. }
  67190. const Rectangle<float> DrawablePath::getBounds() const
  67191. {
  67192. if (strokeType.getStrokeThickness() > 0.0f)
  67193. return stroke.getBounds();
  67194. else
  67195. return path.getBounds();
  67196. }
  67197. bool DrawablePath::hitTest (float x, float y) const
  67198. {
  67199. return path.contains (x, y)
  67200. || stroke.contains (x, y);
  67201. }
  67202. Drawable* DrawablePath::createCopy() const
  67203. {
  67204. DrawablePath* const dp = new DrawablePath();
  67205. dp->path = path;
  67206. dp->stroke = stroke;
  67207. dp->mainFill = mainFill;
  67208. dp->strokeFill = strokeFill;
  67209. dp->strokeType = strokeType;
  67210. return dp;
  67211. }
  67212. static const FillType readFillTypeFromTree (const ValueTree& v)
  67213. {
  67214. const String type (v["type"].toString());
  67215. if (type.equalsIgnoreCase ("solid"))
  67216. {
  67217. const String colour (v ["colour"].toString());
  67218. return Colour (colour.isEmpty() ? (uint32) 0xff000000
  67219. : (uint32) colour.getHexValue32());
  67220. }
  67221. else if (type.equalsIgnoreCase ("gradient"))
  67222. {
  67223. ColourGradient g;
  67224. g.x1 = v["x1"];
  67225. g.y1 = v["y1"];
  67226. g.x2 = v["x2"];
  67227. g.y2 = v["y2"];
  67228. g.isRadial = v["radial"];
  67229. StringArray colours;
  67230. colours.addTokens (v["colours"].toString(), false);
  67231. for (int i = 0; i < colours.size() / 2; ++i)
  67232. g.addColour (colours[i * 2].getDoubleValue(),
  67233. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67234. return g;
  67235. }
  67236. jassertfalse
  67237. return FillType();
  67238. }
  67239. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67240. {
  67241. ValueTree v (tagName);
  67242. if (fillType.isColour())
  67243. {
  67244. v.setProperty ("type", "solid", 0);
  67245. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67246. }
  67247. else if (fillType.isGradient())
  67248. {
  67249. v.setProperty ("type", "gradient", 0);
  67250. v.setProperty ("x1", fillType.gradient->x1, 0);
  67251. v.setProperty ("y1", fillType.gradient->y1, 0);
  67252. v.setProperty ("x2", fillType.gradient->x2, 0);
  67253. v.setProperty ("y2", fillType.gradient->y2, 0);
  67254. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67255. String s;
  67256. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67257. s << " " << fillType.gradient->getColourPosition (i)
  67258. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67259. v.setProperty ("colours", s.trimStart(), 0);
  67260. }
  67261. else
  67262. {
  67263. jassertfalse //xxx
  67264. }
  67265. return v;
  67266. }
  67267. ValueTree DrawablePath::createValueTree() const throw()
  67268. {
  67269. ValueTree v ("Path");
  67270. v.addChild (createTreeForFillType ("fill", mainFill), -1, 0);
  67271. v.addChild (createTreeForFillType ("stroke", strokeFill), -1, 0);
  67272. if (getName().isNotEmpty())
  67273. v.setProperty ("id", getName(), 0);
  67274. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67275. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67276. ? "miter" : (strokeType.getJointStyle() == PathStrokeType::curved ? "curved" : "bevel"), 0);
  67277. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67278. ? "butt" : (strokeType.getEndStyle() == PathStrokeType::square ? "square" : "round"), 0);
  67279. v.setProperty ("path", path.toString(), 0);
  67280. return v;
  67281. }
  67282. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67283. {
  67284. if (! tree.hasType ("Path"))
  67285. return 0;
  67286. DrawablePath* p = new DrawablePath();
  67287. p->setName (tree ["id"]);
  67288. p->mainFill = readFillTypeFromTree (tree.getChildWithName ("fill"));
  67289. p->strokeFill = readFillTypeFromTree (tree.getChildWithName ("stroke"));
  67290. const String jointStyle (tree ["jointStyle"].toString());
  67291. const String endStyle (tree ["capStyle"].toString());
  67292. p->strokeType
  67293. = PathStrokeType (tree ["strokeWidth"],
  67294. jointStyle.equalsIgnoreCase ("curved") ? PathStrokeType::curved
  67295. : (jointStyle.equalsIgnoreCase ("bevel") ? PathStrokeType::beveled
  67296. : PathStrokeType::mitered),
  67297. endStyle.equalsIgnoreCase ("square") ? PathStrokeType::square
  67298. : (endStyle.equalsIgnoreCase ("round") ? PathStrokeType::rounded
  67299. : PathStrokeType::butt));
  67300. p->path.clear();
  67301. p->path.restoreFromString (tree ["path"]);
  67302. p->updateOutline();
  67303. return p;
  67304. }
  67305. END_JUCE_NAMESPACE
  67306. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67307. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67308. BEGIN_JUCE_NAMESPACE
  67309. DrawableText::DrawableText()
  67310. : colour (Colours::white)
  67311. {
  67312. }
  67313. DrawableText::~DrawableText()
  67314. {
  67315. }
  67316. void DrawableText::setText (const GlyphArrangement& newText)
  67317. {
  67318. text = newText;
  67319. }
  67320. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67321. {
  67322. text.clear();
  67323. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67324. }
  67325. void DrawableText::setColour (const Colour& newColour)
  67326. {
  67327. colour = newColour;
  67328. }
  67329. void DrawableText::render (const Drawable::RenderingContext& context) const
  67330. {
  67331. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67332. text.draw (context.g, context.transform);
  67333. }
  67334. const Rectangle<float> DrawableText::getBounds() const
  67335. {
  67336. return text.getBoundingBox (0, -1, false);
  67337. }
  67338. bool DrawableText::hitTest (float x, float y) const
  67339. {
  67340. return text.findGlyphIndexAt (x, y) >= 0;
  67341. }
  67342. Drawable* DrawableText::createCopy() const
  67343. {
  67344. DrawableText* const dt = new DrawableText();
  67345. dt->text = text;
  67346. dt->colour = colour;
  67347. return dt;
  67348. }
  67349. ValueTree DrawableText::createValueTree() const throw()
  67350. {
  67351. ValueTree v ("Text");
  67352. if (getName().isNotEmpty())
  67353. v.setProperty ("id", getName(), 0);
  67354. jassertfalse // xxx not finished!
  67355. return v;
  67356. }
  67357. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67358. {
  67359. if (! tree.hasType ("Text"))
  67360. return 0;
  67361. DrawableText* dt = new DrawableText();
  67362. dt->setName (tree ["id"]);
  67363. jassertfalse // xxx not finished!
  67364. return dt;
  67365. }
  67366. END_JUCE_NAMESPACE
  67367. /*** End of inlined file: juce_DrawableText.cpp ***/
  67368. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67369. BEGIN_JUCE_NAMESPACE
  67370. class SVGState
  67371. {
  67372. public:
  67373. SVGState (const XmlElement* const topLevel)
  67374. : topLevelXml (topLevel),
  67375. elementX (0), elementY (0),
  67376. width (512), height (512),
  67377. viewBoxW (0), viewBoxH (0)
  67378. {
  67379. }
  67380. ~SVGState()
  67381. {
  67382. }
  67383. Drawable* parseSVGElement (const XmlElement& xml)
  67384. {
  67385. if (! xml.hasTagName ("svg"))
  67386. return 0;
  67387. DrawableComposite* const drawable = new DrawableComposite();
  67388. drawable->setName (xml.getStringAttribute ("id"));
  67389. SVGState newState (*this);
  67390. if (xml.hasAttribute ("transform"))
  67391. newState.addTransform (xml);
  67392. newState.elementX = getCoordLength (xml.getStringAttribute ("x", String (newState.elementX)), viewBoxW);
  67393. newState.elementY = getCoordLength (xml.getStringAttribute ("y", String (newState.elementY)), viewBoxH);
  67394. newState.width = getCoordLength (xml.getStringAttribute ("width", String (newState.width)), viewBoxW);
  67395. newState.height = getCoordLength (xml.getStringAttribute ("height", String (newState.height)), viewBoxH);
  67396. if (xml.hasAttribute ("viewBox"))
  67397. {
  67398. const String viewParams (xml.getStringAttribute ("viewBox"));
  67399. int i = 0;
  67400. float vx, vy, vw, vh;
  67401. if (parseCoords (viewParams, vx, vy, i, true)
  67402. && parseCoords (viewParams, vw, vh, i, true)
  67403. && vw > 0
  67404. && vh > 0)
  67405. {
  67406. newState.viewBoxW = vw;
  67407. newState.viewBoxH = vh;
  67408. int placementFlags = 0;
  67409. const String aspect (xml.getStringAttribute ("preserveAspectRatio"));
  67410. if (aspect.containsIgnoreCase ("none"))
  67411. {
  67412. placementFlags = RectanglePlacement::stretchToFit;
  67413. }
  67414. else
  67415. {
  67416. if (aspect.containsIgnoreCase ("slice"))
  67417. placementFlags |= RectanglePlacement::fillDestination;
  67418. if (aspect.containsIgnoreCase ("xMin"))
  67419. placementFlags |= RectanglePlacement::xLeft;
  67420. else if (aspect.containsIgnoreCase ("xMax"))
  67421. placementFlags |= RectanglePlacement::xRight;
  67422. else
  67423. placementFlags |= RectanglePlacement::xMid;
  67424. if (aspect.containsIgnoreCase ("yMin"))
  67425. placementFlags |= RectanglePlacement::yTop;
  67426. else if (aspect.containsIgnoreCase ("yMax"))
  67427. placementFlags |= RectanglePlacement::yBottom;
  67428. else
  67429. placementFlags |= RectanglePlacement::yMid;
  67430. }
  67431. const RectanglePlacement placement (placementFlags);
  67432. newState.transform
  67433. = placement.getTransformToFit (vx, vy, vw, vh,
  67434. 0.0f, 0.0f, newState.width, newState.height)
  67435. .followedBy (newState.transform);
  67436. }
  67437. }
  67438. else
  67439. {
  67440. if (viewBoxW == 0)
  67441. newState.viewBoxW = newState.width;
  67442. if (viewBoxH == 0)
  67443. newState.viewBoxH = newState.height;
  67444. }
  67445. newState.parseSubElements (xml, drawable);
  67446. return drawable;
  67447. }
  67448. private:
  67449. const XmlElement* const topLevelXml;
  67450. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67451. AffineTransform transform;
  67452. String cssStyleText;
  67453. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67454. {
  67455. forEachXmlChildElement (xml, e)
  67456. {
  67457. Drawable* d = 0;
  67458. if (e->hasTagName ("g"))
  67459. d = parseGroupElement (*e);
  67460. else if (e->hasTagName ("svg"))
  67461. d = parseSVGElement (*e);
  67462. else if (e->hasTagName ("path"))
  67463. d = parsePath (*e);
  67464. else if (e->hasTagName ("rect"))
  67465. d = parseRect (*e);
  67466. else if (e->hasTagName ("circle"))
  67467. d = parseCircle (*e);
  67468. else if (e->hasTagName ("ellipse"))
  67469. d = parseEllipse (*e);
  67470. else if (e->hasTagName ("line"))
  67471. d = parseLine (*e);
  67472. else if (e->hasTagName ("polyline"))
  67473. d = parsePolygon (*e, true);
  67474. else if (e->hasTagName ("polygon"))
  67475. d = parsePolygon (*e, false);
  67476. else if (e->hasTagName ("text"))
  67477. d = parseText (*e);
  67478. else if (e->hasTagName ("switch"))
  67479. d = parseSwitch (*e);
  67480. else if (e->hasTagName ("style"))
  67481. parseCSSStyle (*e);
  67482. parentDrawable->insertDrawable (d);
  67483. }
  67484. }
  67485. DrawableComposite* parseSwitch (const XmlElement& xml)
  67486. {
  67487. const XmlElement* const group = xml.getChildByName ("g");
  67488. if (group != 0)
  67489. return parseGroupElement (*group);
  67490. return 0;
  67491. }
  67492. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67493. {
  67494. DrawableComposite* const drawable = new DrawableComposite();
  67495. drawable->setName (xml.getStringAttribute ("id"));
  67496. if (xml.hasAttribute ("transform"))
  67497. {
  67498. SVGState newState (*this);
  67499. newState.addTransform (xml);
  67500. newState.parseSubElements (xml, drawable);
  67501. }
  67502. else
  67503. {
  67504. parseSubElements (xml, drawable);
  67505. }
  67506. return drawable;
  67507. }
  67508. Drawable* parsePath (const XmlElement& xml) const
  67509. {
  67510. const String d (xml.getStringAttribute ("d").trimStart());
  67511. Path path;
  67512. if (getStyleAttribute (&xml, "fill-rule").trim().equalsIgnoreCase ("evenodd"))
  67513. path.setUsingNonZeroWinding (false);
  67514. int index = 0;
  67515. float lastX = 0, lastY = 0;
  67516. float lastX2 = 0, lastY2 = 0;
  67517. tchar lastCommandChar = 0;
  67518. bool isRelative = true;
  67519. bool carryOn = true;
  67520. const String validCommandChars ("MmLlHhVvCcSsQqTtAaZz");
  67521. while (d[index] != 0)
  67522. {
  67523. float x, y, x2, y2, x3, y3;
  67524. if (validCommandChars.containsChar (d[index]))
  67525. {
  67526. lastCommandChar = d [index++];
  67527. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67528. }
  67529. switch (lastCommandChar)
  67530. {
  67531. case 'M':
  67532. case 'm':
  67533. case 'L':
  67534. case 'l':
  67535. if (parseCoords (d, x, y, index, false))
  67536. {
  67537. if (isRelative)
  67538. {
  67539. x += lastX;
  67540. y += lastY;
  67541. }
  67542. if (lastCommandChar == 'M' || lastCommandChar == 'm')
  67543. {
  67544. path.startNewSubPath (x, y);
  67545. lastCommandChar = 'l';
  67546. }
  67547. else
  67548. path.lineTo (x, y);
  67549. lastX2 = lastX;
  67550. lastY2 = lastY;
  67551. lastX = x;
  67552. lastY = y;
  67553. }
  67554. else
  67555. {
  67556. ++index;
  67557. }
  67558. break;
  67559. case 'H':
  67560. case 'h':
  67561. if (parseCoord (d, x, index, false, true))
  67562. {
  67563. if (isRelative)
  67564. x += lastX;
  67565. path.lineTo (x, lastY);
  67566. lastX2 = lastX;
  67567. lastX = x;
  67568. }
  67569. else
  67570. {
  67571. ++index;
  67572. }
  67573. break;
  67574. case 'V':
  67575. case 'v':
  67576. if (parseCoord (d, y, index, false, false))
  67577. {
  67578. if (isRelative)
  67579. y += lastY;
  67580. path.lineTo (lastX, y);
  67581. lastY2 = lastY;
  67582. lastY = y;
  67583. }
  67584. else
  67585. {
  67586. ++index;
  67587. }
  67588. break;
  67589. case 'C':
  67590. case 'c':
  67591. if (parseCoords (d, x, y, index, false)
  67592. && parseCoords (d, x2, y2, index, false)
  67593. && parseCoords (d, x3, y3, index, false))
  67594. {
  67595. if (isRelative)
  67596. {
  67597. x += lastX;
  67598. y += lastY;
  67599. x2 += lastX;
  67600. y2 += lastY;
  67601. x3 += lastX;
  67602. y3 += lastY;
  67603. }
  67604. path.cubicTo (x, y, x2, y2, x3, y3);
  67605. lastX2 = x2;
  67606. lastY2 = y2;
  67607. lastX = x3;
  67608. lastY = y3;
  67609. }
  67610. else
  67611. {
  67612. ++index;
  67613. }
  67614. break;
  67615. case 'S':
  67616. case 's':
  67617. if (parseCoords (d, x, y, index, false)
  67618. && parseCoords (d, x3, y3, index, false))
  67619. {
  67620. if (isRelative)
  67621. {
  67622. x += lastX;
  67623. y += lastY;
  67624. x3 += lastX;
  67625. y3 += lastY;
  67626. }
  67627. x2 = lastX + (lastX - lastX2);
  67628. y2 = lastY + (lastY - lastY2);
  67629. path.cubicTo (x2, y2, x, y, x3, y3);
  67630. lastX2 = x;
  67631. lastY2 = y;
  67632. lastX = x3;
  67633. lastY = y3;
  67634. }
  67635. else
  67636. {
  67637. ++index;
  67638. }
  67639. break;
  67640. case 'Q':
  67641. case 'q':
  67642. if (parseCoords (d, x, y, index, false)
  67643. && parseCoords (d, x2, y2, index, false))
  67644. {
  67645. if (isRelative)
  67646. {
  67647. x += lastX;
  67648. y += lastY;
  67649. x2 += lastX;
  67650. y2 += lastY;
  67651. }
  67652. path.quadraticTo (x, y, x2, y2);
  67653. lastX2 = x;
  67654. lastY2 = y;
  67655. lastX = x2;
  67656. lastY = y2;
  67657. }
  67658. else
  67659. {
  67660. ++index;
  67661. }
  67662. break;
  67663. case 'T':
  67664. case 't':
  67665. if (parseCoords (d, x, y, index, false))
  67666. {
  67667. if (isRelative)
  67668. {
  67669. x += lastX;
  67670. y += lastY;
  67671. }
  67672. x2 = lastX + (lastX - lastX2);
  67673. y2 = lastY + (lastY - lastY2);
  67674. path.quadraticTo (x2, y2, x, y);
  67675. lastX2 = x2;
  67676. lastY2 = y2;
  67677. lastX = x;
  67678. lastY = y;
  67679. }
  67680. else
  67681. {
  67682. ++index;
  67683. }
  67684. break;
  67685. case 'A':
  67686. case 'a':
  67687. if (parseCoords (d, x, y, index, false))
  67688. {
  67689. String num;
  67690. if (parseNextNumber (d, num, index, false))
  67691. {
  67692. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67693. if (parseNextNumber (d, num, index, false))
  67694. {
  67695. const bool largeArc = num.getIntValue() != 0;
  67696. if (parseNextNumber (d, num, index, false))
  67697. {
  67698. const bool sweep = num.getIntValue() != 0;
  67699. if (parseCoords (d, x2, y2, index, false))
  67700. {
  67701. if (isRelative)
  67702. {
  67703. x2 += lastX;
  67704. y2 += lastY;
  67705. }
  67706. if (lastX != x2 || lastY != y2)
  67707. {
  67708. double centreX, centreY, startAngle, deltaAngle;
  67709. double rx = x, ry = y;
  67710. endpointToCentreParameters (lastX, lastY, x2, y2,
  67711. angle, largeArc, sweep,
  67712. rx, ry, centreX, centreY,
  67713. startAngle, deltaAngle);
  67714. path.addCentredArc ((float) centreX, (float) centreY,
  67715. (float) rx, (float) ry,
  67716. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67717. false);
  67718. path.lineTo (x2, y2);
  67719. }
  67720. lastX2 = lastX;
  67721. lastY2 = lastY;
  67722. lastX = x2;
  67723. lastY = y2;
  67724. }
  67725. }
  67726. }
  67727. }
  67728. }
  67729. else
  67730. {
  67731. ++index;
  67732. }
  67733. break;
  67734. case 'Z':
  67735. case 'z':
  67736. path.closeSubPath();
  67737. while (CharacterFunctions::isWhitespace (d [index]))
  67738. ++index;
  67739. break;
  67740. default:
  67741. carryOn = false;
  67742. break;
  67743. }
  67744. if (! carryOn)
  67745. break;
  67746. }
  67747. return parseShape (xml, path);
  67748. }
  67749. Drawable* parseRect (const XmlElement& xml) const
  67750. {
  67751. Path rect;
  67752. const bool hasRX = xml.hasAttribute ("rx");
  67753. const bool hasRY = xml.hasAttribute ("ry");
  67754. if (hasRX || hasRY)
  67755. {
  67756. float rx = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67757. float ry = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67758. if (! hasRX)
  67759. rx = ry;
  67760. else if (! hasRY)
  67761. ry = rx;
  67762. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67763. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67764. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67765. getCoordLength (xml.getStringAttribute ("height"), viewBoxH),
  67766. rx, ry);
  67767. }
  67768. else
  67769. {
  67770. rect.addRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67771. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67772. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67773. getCoordLength (xml.getStringAttribute ("height"), viewBoxH));
  67774. }
  67775. return parseShape (xml, rect);
  67776. }
  67777. Drawable* parseCircle (const XmlElement& xml) const
  67778. {
  67779. Path circle;
  67780. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67781. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67782. const float radius = getCoordLength (xml.getStringAttribute ("r"), viewBoxW);
  67783. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67784. return parseShape (xml, circle);
  67785. }
  67786. Drawable* parseEllipse (const XmlElement& xml) const
  67787. {
  67788. Path ellipse;
  67789. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67790. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67791. const float radiusX = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67792. const float radiusY = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67793. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67794. return parseShape (xml, ellipse);
  67795. }
  67796. Drawable* parseLine (const XmlElement& xml) const
  67797. {
  67798. Path line;
  67799. const float x1 = getCoordLength (xml.getStringAttribute ("x1"), viewBoxW);
  67800. const float y1 = getCoordLength (xml.getStringAttribute ("y1"), viewBoxH);
  67801. const float x2 = getCoordLength (xml.getStringAttribute ("x2"), viewBoxW);
  67802. const float y2 = getCoordLength (xml.getStringAttribute ("y2"), viewBoxH);
  67803. line.startNewSubPath (x1, y1);
  67804. line.lineTo (x2, y2);
  67805. return parseShape (xml, line);
  67806. }
  67807. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67808. {
  67809. const String points (xml.getStringAttribute ("points"));
  67810. Path path;
  67811. int index = 0;
  67812. float x, y;
  67813. if (parseCoords (points, x, y, index, true))
  67814. {
  67815. float firstX = x;
  67816. float firstY = y;
  67817. float lastX = 0, lastY = 0;
  67818. path.startNewSubPath (x, y);
  67819. while (parseCoords (points, x, y, index, true))
  67820. {
  67821. lastX = x;
  67822. lastY = y;
  67823. path.lineTo (x, y);
  67824. }
  67825. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67826. path.closeSubPath();
  67827. }
  67828. return parseShape (xml, path);
  67829. }
  67830. Drawable* parseShape (const XmlElement& xml, Path& path,
  67831. const bool shouldParseTransform = true) const
  67832. {
  67833. if (shouldParseTransform && xml.hasAttribute ("transform"))
  67834. {
  67835. SVGState newState (*this);
  67836. newState.addTransform (xml);
  67837. return newState.parseShape (xml, path, false);
  67838. }
  67839. DrawablePath* dp = new DrawablePath();
  67840. dp->setName (xml.getStringAttribute ("id"));
  67841. dp->setFill (Colours::transparentBlack);
  67842. path.applyTransform (transform);
  67843. dp->setPath (path);
  67844. Path::Iterator iter (path);
  67845. bool containsClosedSubPath = false;
  67846. while (iter.next())
  67847. {
  67848. if (iter.elementType == Path::Iterator::closePath)
  67849. {
  67850. containsClosedSubPath = true;
  67851. break;
  67852. }
  67853. }
  67854. dp->setFill (getPathFillType (path,
  67855. getStyleAttribute (&xml, "fill"),
  67856. getStyleAttribute (&xml, "fill-opacity"),
  67857. getStyleAttribute (&xml, "opacity"),
  67858. containsClosedSubPath ? Colours::black
  67859. : Colours::transparentBlack));
  67860. const String strokeType (getStyleAttribute (&xml, "stroke"));
  67861. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase ("none"))
  67862. {
  67863. dp->setStrokeFill (getPathFillType (path, strokeType,
  67864. getStyleAttribute (&xml, "stroke-opacity"),
  67865. getStyleAttribute (&xml, "opacity"),
  67866. Colours::transparentBlack));
  67867. dp->setStrokeType (getStrokeFor (&xml));
  67868. }
  67869. return dp;
  67870. }
  67871. const XmlElement* findLinkedElement (const XmlElement* e) const
  67872. {
  67873. const String id (e->getStringAttribute ("xlink:href"));
  67874. if (! id.startsWithChar ('#'))
  67875. return 0;
  67876. return findElementForId (topLevelXml, id.substring (1));
  67877. }
  67878. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  67879. {
  67880. if (fillXml == 0)
  67881. return;
  67882. forEachXmlChildElementWithTagName (*fillXml, e, "stop")
  67883. {
  67884. int index = 0;
  67885. Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
  67886. const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
  67887. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  67888. double offset = e->getDoubleAttribute ("offset");
  67889. if (e->getStringAttribute ("offset").containsChar ('%'))
  67890. offset *= 0.01;
  67891. cg.addColour (jlimit (0.0, 1.0, offset), col);
  67892. }
  67893. }
  67894. const FillType getPathFillType (const Path& path,
  67895. const String& fill,
  67896. const String& fillOpacity,
  67897. const String& overallOpacity,
  67898. const Colour& defaultColour) const
  67899. {
  67900. float opacity = 1.0f;
  67901. if (overallOpacity.isNotEmpty())
  67902. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  67903. if (fillOpacity.isNotEmpty())
  67904. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  67905. if (fill.startsWithIgnoreCase ("url"))
  67906. {
  67907. const String id (fill.fromFirstOccurrenceOf ("#", false, false)
  67908. .upToLastOccurrenceOf (")", false, false).trim());
  67909. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  67910. if (fillXml != 0
  67911. && (fillXml->hasTagName ("linearGradient")
  67912. || fillXml->hasTagName ("radialGradient")))
  67913. {
  67914. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  67915. ColourGradient gradient;
  67916. addGradientStopsIn (gradient, inheritedFrom);
  67917. addGradientStopsIn (gradient, fillXml);
  67918. if (gradient.getNumColours() > 0)
  67919. {
  67920. gradient.addColour (0.0, gradient.getColour (0));
  67921. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  67922. }
  67923. else
  67924. {
  67925. gradient.addColour (0.0, Colours::black);
  67926. gradient.addColour (1.0, Colours::black);
  67927. }
  67928. if (overallOpacity.isNotEmpty())
  67929. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  67930. jassert (gradient.getNumColours() > 0);
  67931. gradient.isRadial = fillXml->hasTagName ("radialGradient");
  67932. float width = viewBoxW;
  67933. float height = viewBoxH;
  67934. float dx = 0.0f;
  67935. float dy = 0.0f;
  67936. const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
  67937. if (! userSpace)
  67938. {
  67939. const Rectangle<float> bounds (path.getBounds());
  67940. dx = bounds.getX();
  67941. dy = bounds.getY();
  67942. width = bounds.getWidth();
  67943. height = bounds.getHeight();
  67944. }
  67945. if (gradient.isRadial)
  67946. {
  67947. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), width);
  67948. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), height);
  67949. const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), width);
  67950. gradient.x2 = gradient.x1 + radius;
  67951. gradient.y2 = gradient.y1;
  67952. //xxx (the fx, fy focal point isn't handled properly here..)
  67953. }
  67954. else
  67955. {
  67956. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), width);
  67957. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), height);
  67958. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), width);
  67959. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), height);
  67960. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  67961. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  67962. }
  67963. FillType type (gradient);
  67964. type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
  67965. .followedBy (transform);
  67966. return type;
  67967. }
  67968. }
  67969. if (fill.equalsIgnoreCase ("none"))
  67970. return Colours::transparentBlack;
  67971. int i = 0;
  67972. const Colour colour (parseColour (fill, i, defaultColour));
  67973. return colour.withMultipliedAlpha (opacity);
  67974. }
  67975. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  67976. {
  67977. const String width (getStyleAttribute (xml, "stroke-width"));
  67978. const String cap (getStyleAttribute (xml, "stroke-linecap"));
  67979. const String join (getStyleAttribute (xml, "stroke-linejoin"));
  67980. //const String mitreLimit (getStyleAttribute (xml, "stroke-miterlimit"));
  67981. //const String dashArray (getStyleAttribute (xml, "stroke-dasharray"));
  67982. //const String dashOffset (getStyleAttribute (xml, "stroke-dashoffset"));
  67983. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  67984. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  67985. if (join.equalsIgnoreCase ("round"))
  67986. joinStyle = PathStrokeType::curved;
  67987. else if (join.equalsIgnoreCase ("bevel"))
  67988. joinStyle = PathStrokeType::beveled;
  67989. if (cap.equalsIgnoreCase ("round"))
  67990. capStyle = PathStrokeType::rounded;
  67991. else if (cap.equalsIgnoreCase ("square"))
  67992. capStyle = PathStrokeType::square;
  67993. float ox = 0.0f, oy = 0.0f;
  67994. transform.transformPoint (ox, oy);
  67995. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  67996. transform.transformPoint (x, y);
  67997. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  67998. joinStyle, capStyle);
  67999. }
  68000. Drawable* parseText (const XmlElement& xml)
  68001. {
  68002. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68003. getCoordList (xCoords, getInheritedAttribute (&xml, "x"), true, true);
  68004. getCoordList (yCoords, getInheritedAttribute (&xml, "y"), true, false);
  68005. getCoordList (dxCoords, getInheritedAttribute (&xml, "dx"), true, true);
  68006. getCoordList (dyCoords, getInheritedAttribute (&xml, "dy"), true, false);
  68007. //xxx not done text yet!
  68008. forEachXmlChildElement (xml, e)
  68009. {
  68010. if (e->isTextElement())
  68011. {
  68012. const String text (e->getText());
  68013. Path path;
  68014. Drawable* s = parseShape (*e, path);
  68015. delete s;
  68016. }
  68017. else if (e->hasTagName ("tspan"))
  68018. {
  68019. Drawable* s = parseText (*e);
  68020. delete s;
  68021. }
  68022. }
  68023. return 0;
  68024. }
  68025. void addTransform (const XmlElement& xml)
  68026. {
  68027. transform = parseTransform (xml.getStringAttribute ("transform"))
  68028. .followedBy (transform);
  68029. }
  68030. bool parseCoord (const String& s, float& value, int& index,
  68031. const bool allowUnits, const bool isX) const
  68032. {
  68033. String number;
  68034. if (! parseNextNumber (s, number, index, allowUnits))
  68035. {
  68036. value = 0;
  68037. return false;
  68038. }
  68039. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68040. return true;
  68041. }
  68042. bool parseCoords (const String& s, float& x, float& y,
  68043. int& index, const bool allowUnits) const
  68044. {
  68045. return parseCoord (s, x, index, allowUnits, true)
  68046. && parseCoord (s, y, index, allowUnits, false);
  68047. }
  68048. float getCoordLength (const String& s, const float sizeForProportions) const
  68049. {
  68050. float n = s.getFloatValue();
  68051. const int len = s.length();
  68052. if (len > 2)
  68053. {
  68054. const float dpi = 96.0f;
  68055. const tchar n1 = s [len - 2];
  68056. const tchar n2 = s [len - 1];
  68057. if (n1 == 'i' && n2 == 'n')
  68058. n *= dpi;
  68059. else if (n1 == 'm' && n2 == 'm')
  68060. n *= dpi / 25.4f;
  68061. else if (n1 == 'c' && n2 == 'm')
  68062. n *= dpi / 2.54f;
  68063. else if (n1 == 'p' && n2 == 'c')
  68064. n *= 15.0f;
  68065. else if (n2 == '%')
  68066. n *= 0.01f * sizeForProportions;
  68067. }
  68068. return n;
  68069. }
  68070. void getCoordList (Array <float>& coords, const String& list,
  68071. const bool allowUnits, const bool isX) const
  68072. {
  68073. int index = 0;
  68074. float value;
  68075. while (parseCoord (list, value, index, allowUnits, isX))
  68076. coords.add (value);
  68077. }
  68078. void parseCSSStyle (const XmlElement& xml)
  68079. {
  68080. cssStyleText = xml.getAllSubText() + "\n" + cssStyleText;
  68081. }
  68082. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68083. const String& defaultValue = String::empty) const
  68084. {
  68085. if (xml->hasAttribute (attributeName))
  68086. return xml->getStringAttribute (attributeName, defaultValue);
  68087. const String styleAtt (xml->getStringAttribute ("style"));
  68088. if (styleAtt.isNotEmpty())
  68089. {
  68090. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68091. if (value.isNotEmpty())
  68092. return value;
  68093. }
  68094. else if (xml->hasAttribute ("class"))
  68095. {
  68096. const String className ("." + xml->getStringAttribute ("class"));
  68097. int index = cssStyleText.indexOfIgnoreCase (className + " ");
  68098. if (index < 0)
  68099. index = cssStyleText.indexOfIgnoreCase (className + "{");
  68100. if (index >= 0)
  68101. {
  68102. const int openBracket = cssStyleText.indexOfChar (index, '{');
  68103. if (openBracket > index)
  68104. {
  68105. const int closeBracket = cssStyleText.indexOfChar (openBracket, '}');
  68106. if (closeBracket > openBracket)
  68107. {
  68108. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68109. if (value.isNotEmpty())
  68110. return value;
  68111. }
  68112. }
  68113. }
  68114. }
  68115. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68116. if (xml != 0)
  68117. return getStyleAttribute (xml, attributeName, defaultValue);
  68118. return defaultValue;
  68119. }
  68120. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68121. {
  68122. if (xml->hasAttribute (attributeName))
  68123. return xml->getStringAttribute (attributeName);
  68124. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68125. if (xml != 0)
  68126. return getInheritedAttribute (xml, attributeName);
  68127. return String::empty;
  68128. }
  68129. static bool isIdentifierChar (const tchar c)
  68130. {
  68131. return CharacterFunctions::isLetter (c) || c == '-';
  68132. }
  68133. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68134. {
  68135. int i = 0;
  68136. for (;;)
  68137. {
  68138. i = list.indexOf (i, attributeName);
  68139. if (i < 0)
  68140. break;
  68141. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68142. && ! isIdentifierChar (list [i + attributeName.length()]))
  68143. {
  68144. i = list.indexOfChar (i, ':');
  68145. if (i < 0)
  68146. break;
  68147. int end = list.indexOfChar (i, ';');
  68148. if (end < 0)
  68149. end = 0x7ffff;
  68150. return list.substring (i + 1, end).trim();
  68151. }
  68152. ++i;
  68153. }
  68154. return defaultValue;
  68155. }
  68156. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68157. {
  68158. const juce_wchar* const s = source;
  68159. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68160. ++index;
  68161. int start = index;
  68162. if (CharacterFunctions::isDigit (s[index]) || s[index] == '.' || s[index] == '-')
  68163. ++index;
  68164. while (CharacterFunctions::isDigit (s[index]) || s[index] == '.')
  68165. ++index;
  68166. if ((s[index] == 'e' || s[index] == 'E')
  68167. && (CharacterFunctions::isDigit (s[index + 1])
  68168. || s[index + 1] == '-'
  68169. || s[index + 1] == '+'))
  68170. {
  68171. index += 2;
  68172. while (CharacterFunctions::isDigit (s[index]))
  68173. ++index;
  68174. }
  68175. if (allowUnits)
  68176. {
  68177. while (CharacterFunctions::isLetter (s[index]))
  68178. ++index;
  68179. }
  68180. if (index == start)
  68181. return false;
  68182. value = String (s + start, index - start);
  68183. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68184. ++index;
  68185. return true;
  68186. }
  68187. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68188. {
  68189. if (s [index] == '#')
  68190. {
  68191. uint32 hex [6];
  68192. zeromem (hex, sizeof (hex));
  68193. int numChars = 0;
  68194. for (int i = 6; --i >= 0;)
  68195. {
  68196. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68197. if (hexValue >= 0)
  68198. hex [numChars++] = hexValue;
  68199. else
  68200. break;
  68201. }
  68202. if (numChars <= 3)
  68203. return Colour ((uint8) (hex [0] * 0x11),
  68204. (uint8) (hex [1] * 0x11),
  68205. (uint8) (hex [2] * 0x11));
  68206. else
  68207. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68208. (uint8) ((hex [2] << 4) + hex [3]),
  68209. (uint8) ((hex [4] << 4) + hex [5]));
  68210. }
  68211. else if (s [index] == 'r'
  68212. && s [index + 1] == 'g'
  68213. && s [index + 2] == 'b')
  68214. {
  68215. const int openBracket = s.indexOfChar (index, '(');
  68216. const int closeBracket = s.indexOfChar (openBracket, ')');
  68217. if (openBracket >= 3 && closeBracket > openBracket)
  68218. {
  68219. index = closeBracket;
  68220. StringArray tokens;
  68221. tokens.addTokens (s.substring (openBracket + 1, closeBracket), ",", "");
  68222. tokens.trim();
  68223. tokens.removeEmptyStrings();
  68224. if (tokens[0].containsChar ('%'))
  68225. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68226. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68227. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68228. else
  68229. return Colour ((uint8) tokens[0].getIntValue(),
  68230. (uint8) tokens[1].getIntValue(),
  68231. (uint8) tokens[2].getIntValue());
  68232. }
  68233. }
  68234. return Colours::findColourForName (s, defaultColour);
  68235. }
  68236. static const AffineTransform parseTransform (String t)
  68237. {
  68238. AffineTransform result;
  68239. while (t.isNotEmpty())
  68240. {
  68241. StringArray tokens;
  68242. tokens.addTokens (t.fromFirstOccurrenceOf ("(", false, false)
  68243. .upToFirstOccurrenceOf (")", false, false),
  68244. ", ", String::empty);
  68245. tokens.removeEmptyStrings (true);
  68246. float numbers [6];
  68247. for (int i = 0; i < 6; ++i)
  68248. numbers[i] = tokens[i].getFloatValue();
  68249. AffineTransform trans;
  68250. if (t.startsWithIgnoreCase ("matrix"))
  68251. {
  68252. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68253. numbers[1], numbers[3], numbers[5]);
  68254. }
  68255. else if (t.startsWithIgnoreCase ("translate"))
  68256. {
  68257. jassert (tokens.size() == 2);
  68258. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68259. }
  68260. else if (t.startsWithIgnoreCase ("scale"))
  68261. {
  68262. if (tokens.size() == 1)
  68263. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68264. else
  68265. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68266. }
  68267. else if (t.startsWithIgnoreCase ("rotate"))
  68268. {
  68269. if (tokens.size() != 3)
  68270. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68271. else
  68272. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68273. numbers[1], numbers[2]);
  68274. }
  68275. else if (t.startsWithIgnoreCase ("skewX"))
  68276. {
  68277. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68278. 0.0f, 1.0f, 0.0f);
  68279. }
  68280. else if (t.startsWithIgnoreCase ("skewY"))
  68281. {
  68282. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68283. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68284. }
  68285. result = trans.followedBy (result);
  68286. t = t.fromFirstOccurrenceOf (")", false, false).trimStart();
  68287. }
  68288. return result;
  68289. }
  68290. static void endpointToCentreParameters (const double x1, const double y1,
  68291. const double x2, const double y2,
  68292. const double angle,
  68293. const bool largeArc, const bool sweep,
  68294. double& rx, double& ry,
  68295. double& centreX, double& centreY,
  68296. double& startAngle, double& deltaAngle)
  68297. {
  68298. const double midX = (x1 - x2) * 0.5;
  68299. const double midY = (y1 - y2) * 0.5;
  68300. const double cosAngle = cos (angle);
  68301. const double sinAngle = sin (angle);
  68302. const double xp = cosAngle * midX + sinAngle * midY;
  68303. const double yp = cosAngle * midY - sinAngle * midX;
  68304. const double xp2 = xp * xp;
  68305. const double yp2 = yp * yp;
  68306. double rx2 = rx * rx;
  68307. double ry2 = ry * ry;
  68308. const double s = (xp2 / rx2) + (yp2 / ry2);
  68309. double c;
  68310. if (s <= 1.0)
  68311. {
  68312. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68313. / (( rx2 * yp2) + (ry2 * xp2))));
  68314. if (largeArc == sweep)
  68315. c = -c;
  68316. }
  68317. else
  68318. {
  68319. const double s2 = sqrt (s);
  68320. rx *= s2;
  68321. ry *= s2;
  68322. rx2 = rx * rx;
  68323. ry2 = ry * ry;
  68324. c = 0;
  68325. }
  68326. const double cpx = ((rx * yp) / ry) * c;
  68327. const double cpy = ((-ry * xp) / rx) * c;
  68328. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68329. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68330. const double ux = (xp - cpx) / rx;
  68331. const double uy = (yp - cpy) / ry;
  68332. const double vx = (-xp - cpx) / rx;
  68333. const double vy = (-yp - cpy) / ry;
  68334. const double length = juce_hypot (ux, uy);
  68335. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68336. if (uy < 0)
  68337. startAngle = -startAngle;
  68338. startAngle += double_Pi * 0.5;
  68339. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68340. / (length * juce_hypot (vx, vy))));
  68341. if ((ux * vy) - (uy * vx) < 0)
  68342. deltaAngle = -deltaAngle;
  68343. if (sweep)
  68344. {
  68345. if (deltaAngle < 0)
  68346. deltaAngle += double_Pi * 2.0;
  68347. }
  68348. else
  68349. {
  68350. if (deltaAngle > 0)
  68351. deltaAngle -= double_Pi * 2.0;
  68352. }
  68353. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68354. }
  68355. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68356. {
  68357. forEachXmlChildElement (*parent, e)
  68358. {
  68359. if (e->compareAttribute ("id", id))
  68360. return e;
  68361. const XmlElement* const found = findElementForId (e, id);
  68362. if (found != 0)
  68363. return found;
  68364. }
  68365. return 0;
  68366. }
  68367. SVGState& operator= (const SVGState&);
  68368. };
  68369. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68370. {
  68371. SVGState state (&svgDocument);
  68372. return state.parseSVGElement (svgDocument);
  68373. }
  68374. END_JUCE_NAMESPACE
  68375. /*** End of inlined file: juce_SVGParser.cpp ***/
  68376. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68377. BEGIN_JUCE_NAMESPACE
  68378. #if JUCE_MSVC
  68379. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68380. #endif
  68381. DropShadowEffect::DropShadowEffect()
  68382. : offsetX (0),
  68383. offsetY (0),
  68384. radius (4),
  68385. opacity (0.6f)
  68386. {
  68387. }
  68388. DropShadowEffect::~DropShadowEffect()
  68389. {
  68390. }
  68391. void DropShadowEffect::setShadowProperties (const float newRadius,
  68392. const float newOpacity,
  68393. const int newShadowOffsetX,
  68394. const int newShadowOffsetY)
  68395. {
  68396. radius = jmax (1.1f, newRadius);
  68397. offsetX = newShadowOffsetX;
  68398. offsetY = newShadowOffsetY;
  68399. opacity = newOpacity;
  68400. }
  68401. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68402. {
  68403. const int w = image.getWidth();
  68404. const int h = image.getHeight();
  68405. Image shadowImage (Image::SingleChannel, w, h, false);
  68406. const Image::BitmapData srcData (image, 0, 0, w, h);
  68407. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68408. const int filter = roundToInt (63.0f / radius);
  68409. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68410. for (int x = w; --x >= 0;)
  68411. {
  68412. int shadowAlpha = 0;
  68413. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68414. uint8* shadowPix = destData.data + x;
  68415. for (int y = h; --y >= 0;)
  68416. {
  68417. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68418. *shadowPix = (uint8) shadowAlpha;
  68419. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68420. shadowPix += destData.lineStride;
  68421. }
  68422. }
  68423. for (int y = h; --y >= 0;)
  68424. {
  68425. int shadowAlpha = 0;
  68426. uint8* shadowPix = destData.getLinePointer (y);
  68427. for (int x = w; --x >= 0;)
  68428. {
  68429. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68430. *shadowPix++ = (uint8) shadowAlpha;
  68431. }
  68432. }
  68433. g.setColour (Colours::black.withAlpha (opacity));
  68434. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68435. g.setOpacity (1.0f);
  68436. g.drawImageAt (&image, 0, 0);
  68437. }
  68438. END_JUCE_NAMESPACE
  68439. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68440. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68441. BEGIN_JUCE_NAMESPACE
  68442. GlowEffect::GlowEffect()
  68443. : radius (2.0f),
  68444. colour (Colours::white)
  68445. {
  68446. }
  68447. GlowEffect::~GlowEffect()
  68448. {
  68449. }
  68450. void GlowEffect::setGlowProperties (const float newRadius,
  68451. const Colour& newColour)
  68452. {
  68453. radius = newRadius;
  68454. colour = newColour;
  68455. }
  68456. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68457. {
  68458. Image temp (image.getFormat(), image.getWidth(), image.getHeight(), true);
  68459. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68460. blurKernel.createGaussianBlur (radius);
  68461. blurKernel.rescaleAllValues (radius);
  68462. blurKernel.applyToImage (temp, &image, image.getBounds());
  68463. g.setColour (colour);
  68464. g.drawImageAt (&temp, 0, 0, true);
  68465. g.setOpacity (1.0f);
  68466. g.drawImageAt (&image, 0, 0, false);
  68467. }
  68468. END_JUCE_NAMESPACE
  68469. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68470. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68471. BEGIN_JUCE_NAMESPACE
  68472. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68473. : opacity (opacity_)
  68474. {
  68475. }
  68476. ReduceOpacityEffect::~ReduceOpacityEffect()
  68477. {
  68478. }
  68479. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68480. {
  68481. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68482. }
  68483. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68484. {
  68485. g.setOpacity (opacity);
  68486. g.drawImageAt (&image, 0, 0);
  68487. }
  68488. END_JUCE_NAMESPACE
  68489. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68490. /*** Start of inlined file: juce_Font.cpp ***/
  68491. BEGIN_JUCE_NAMESPACE
  68492. namespace FontValues
  68493. {
  68494. static float limitFontHeight (const float height) throw()
  68495. {
  68496. return jlimit (0.1f, 10000.0f, height);
  68497. }
  68498. static const float defaultFontHeight = 14.0f;
  68499. }
  68500. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68501. const float kerning_, const float ascent_, const int styleFlags_,
  68502. Typeface* const typeface_) throw()
  68503. : typefaceName (typefaceName_),
  68504. height (height_),
  68505. horizontalScale (horizontalScale_),
  68506. kerning (kerning_),
  68507. ascent (ascent_),
  68508. styleFlags (styleFlags_),
  68509. typeface (typeface_)
  68510. {
  68511. }
  68512. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68513. : typefaceName (other.typefaceName),
  68514. height (other.height),
  68515. horizontalScale (other.horizontalScale),
  68516. kerning (other.kerning),
  68517. ascent (other.ascent),
  68518. styleFlags (other.styleFlags),
  68519. typeface (other.typeface)
  68520. {
  68521. }
  68522. Font::Font() throw()
  68523. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::defaultFontHeight,
  68524. 1.0f, 0, 0, Font::plain, 0))
  68525. {
  68526. }
  68527. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68528. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::limitFontHeight (fontHeight),
  68529. 1.0f, 0, 0, styleFlags_, 0))
  68530. {
  68531. }
  68532. Font::Font (const String& typefaceName_,
  68533. const float fontHeight,
  68534. const int styleFlags_) throw()
  68535. : font (new SharedFontInternal (typefaceName_, FontValues::limitFontHeight (fontHeight),
  68536. 1.0f, 0, 0, styleFlags_, 0))
  68537. {
  68538. }
  68539. Font::Font (const Font& other) throw()
  68540. : font (other.font)
  68541. {
  68542. }
  68543. Font& Font::operator= (const Font& other) throw()
  68544. {
  68545. font = other.font;
  68546. return *this;
  68547. }
  68548. Font::~Font() throw()
  68549. {
  68550. }
  68551. Font::Font (const Typeface::Ptr& typeface) throw()
  68552. : font (new SharedFontInternal (typeface->getName(), FontValues::defaultFontHeight,
  68553. 1.0f, 0, 0, Font::plain, typeface))
  68554. {
  68555. }
  68556. bool Font::operator== (const Font& other) const throw()
  68557. {
  68558. return font == other.font
  68559. || (font->height == other.font->height
  68560. && font->styleFlags == other.font->styleFlags
  68561. && font->horizontalScale == other.font->horizontalScale
  68562. && font->kerning == other.font->kerning
  68563. && font->typefaceName == other.font->typefaceName);
  68564. }
  68565. bool Font::operator!= (const Font& other) const throw()
  68566. {
  68567. return ! operator== (other);
  68568. }
  68569. void Font::dupeInternalIfShared() throw()
  68570. {
  68571. if (font->getReferenceCount() > 1)
  68572. font = new SharedFontInternal (*font);
  68573. }
  68574. const String Font::getDefaultSansSerifFontName() throw()
  68575. {
  68576. static const String name ("<Sans-Serif>");
  68577. return name;
  68578. }
  68579. const String Font::getDefaultSerifFontName() throw()
  68580. {
  68581. static const String name ("<Serif>");
  68582. return name;
  68583. }
  68584. const String Font::getDefaultMonospacedFontName() throw()
  68585. {
  68586. static const String name ("<Monospaced>");
  68587. return name;
  68588. }
  68589. void Font::setTypefaceName (const String& faceName) throw()
  68590. {
  68591. if (faceName != font->typefaceName)
  68592. {
  68593. dupeInternalIfShared();
  68594. font->typefaceName = faceName;
  68595. font->typeface = 0;
  68596. font->ascent = 0;
  68597. }
  68598. }
  68599. static String fallbackFont;
  68600. const String Font::getFallbackFontName() throw()
  68601. {
  68602. return fallbackFont;
  68603. }
  68604. void Font::setFallbackFontName (const String& name) throw()
  68605. {
  68606. fallbackFont = name;
  68607. }
  68608. void Font::setHeight (float newHeight) throw()
  68609. {
  68610. newHeight = FontValues::limitFontHeight (newHeight);
  68611. if (font->height != newHeight)
  68612. {
  68613. dupeInternalIfShared();
  68614. font->height = newHeight;
  68615. }
  68616. }
  68617. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68618. {
  68619. newHeight = FontValues::limitFontHeight (newHeight);
  68620. if (font->height != newHeight)
  68621. {
  68622. dupeInternalIfShared();
  68623. font->horizontalScale *= (font->height / newHeight);
  68624. font->height = newHeight;
  68625. }
  68626. }
  68627. void Font::setStyleFlags (const int newFlags) throw()
  68628. {
  68629. if (font->styleFlags != newFlags)
  68630. {
  68631. dupeInternalIfShared();
  68632. font->styleFlags = newFlags;
  68633. font->typeface = 0;
  68634. font->ascent = 0;
  68635. }
  68636. }
  68637. void Font::setSizeAndStyle (float newHeight,
  68638. const int newStyleFlags,
  68639. const float newHorizontalScale,
  68640. const float newKerningAmount) throw()
  68641. {
  68642. newHeight = FontValues::limitFontHeight (newHeight);
  68643. if (font->height != newHeight
  68644. || font->horizontalScale != newHorizontalScale
  68645. || font->kerning != newKerningAmount)
  68646. {
  68647. dupeInternalIfShared();
  68648. font->height = newHeight;
  68649. font->horizontalScale = newHorizontalScale;
  68650. font->kerning = newKerningAmount;
  68651. }
  68652. setStyleFlags (newStyleFlags);
  68653. }
  68654. void Font::setHorizontalScale (const float scaleFactor) throw()
  68655. {
  68656. dupeInternalIfShared();
  68657. font->horizontalScale = scaleFactor;
  68658. }
  68659. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68660. {
  68661. dupeInternalIfShared();
  68662. font->kerning = extraKerning;
  68663. }
  68664. void Font::setBold (const bool shouldBeBold) throw()
  68665. {
  68666. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68667. : (font->styleFlags & ~bold));
  68668. }
  68669. bool Font::isBold() const throw()
  68670. {
  68671. return (font->styleFlags & bold) != 0;
  68672. }
  68673. void Font::setItalic (const bool shouldBeItalic) throw()
  68674. {
  68675. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68676. : (font->styleFlags & ~italic));
  68677. }
  68678. bool Font::isItalic() const throw()
  68679. {
  68680. return (font->styleFlags & italic) != 0;
  68681. }
  68682. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68683. {
  68684. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68685. : (font->styleFlags & ~underlined));
  68686. }
  68687. bool Font::isUnderlined() const throw()
  68688. {
  68689. return (font->styleFlags & underlined) != 0;
  68690. }
  68691. float Font::getAscent() const throw()
  68692. {
  68693. if (font->ascent == 0)
  68694. font->ascent = getTypeface()->getAscent();
  68695. return font->height * font->ascent;
  68696. }
  68697. float Font::getDescent() const throw()
  68698. {
  68699. return font->height - getAscent();
  68700. }
  68701. int Font::getStringWidth (const String& text) const throw()
  68702. {
  68703. return roundToInt (getStringWidthFloat (text));
  68704. }
  68705. float Font::getStringWidthFloat (const String& text) const throw()
  68706. {
  68707. float w = getTypeface()->getStringWidth (text);
  68708. if (font->kerning != 0)
  68709. w += font->kerning * text.length();
  68710. return w * font->height * font->horizontalScale;
  68711. }
  68712. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68713. {
  68714. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68715. const float scale = font->height * font->horizontalScale;
  68716. const int num = xOffsets.size();
  68717. if (num > 0)
  68718. {
  68719. float* const x = &(xOffsets.getReference(0));
  68720. if (font->kerning != 0)
  68721. {
  68722. for (int i = 0; i < num; ++i)
  68723. x[i] = (x[i] + i * font->kerning) * scale;
  68724. }
  68725. else
  68726. {
  68727. for (int i = 0; i < num; ++i)
  68728. x[i] *= scale;
  68729. }
  68730. }
  68731. }
  68732. void Font::findFonts (Array<Font>& destArray) throw()
  68733. {
  68734. const StringArray names (findAllTypefaceNames());
  68735. for (int i = 0; i < names.size(); ++i)
  68736. destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain));
  68737. }
  68738. class TypefaceCache : public DeletedAtShutdown
  68739. {
  68740. public:
  68741. TypefaceCache (int numToCache = 10) throw()
  68742. : counter (1)
  68743. {
  68744. while (--numToCache >= 0)
  68745. faces.add (new CachedFace());
  68746. }
  68747. ~TypefaceCache()
  68748. {
  68749. clearSingletonInstance();
  68750. }
  68751. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68752. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68753. {
  68754. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68755. const String faceName (font.getTypefaceName());
  68756. int i;
  68757. for (i = faces.size(); --i >= 0;)
  68758. {
  68759. CachedFace* const face = faces.getUnchecked(i);
  68760. if (face->flags == flags
  68761. && face->typefaceName == faceName)
  68762. {
  68763. face->lastUsageCount = ++counter;
  68764. return face->typeFace;
  68765. }
  68766. }
  68767. int replaceIndex = 0;
  68768. int bestLastUsageCount = std::numeric_limits<int>::max();
  68769. for (i = faces.size(); --i >= 0;)
  68770. {
  68771. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68772. if (bestLastUsageCount > lu)
  68773. {
  68774. bestLastUsageCount = lu;
  68775. replaceIndex = i;
  68776. }
  68777. }
  68778. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68779. face->typefaceName = faceName;
  68780. face->flags = flags;
  68781. face->lastUsageCount = ++counter;
  68782. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68783. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68784. return face->typeFace;
  68785. }
  68786. juce_UseDebuggingNewOperator
  68787. private:
  68788. struct CachedFace
  68789. {
  68790. CachedFace() throw()
  68791. : lastUsageCount (0), flags (-1)
  68792. {
  68793. }
  68794. String typefaceName;
  68795. int lastUsageCount;
  68796. int flags;
  68797. Typeface::Ptr typeFace;
  68798. };
  68799. int counter;
  68800. OwnedArray <CachedFace> faces;
  68801. TypefaceCache (const TypefaceCache&);
  68802. TypefaceCache& operator= (const TypefaceCache&);
  68803. };
  68804. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68805. Typeface* Font::getTypeface() const throw()
  68806. {
  68807. if (font->typeface == 0)
  68808. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68809. return font->typeface;
  68810. }
  68811. END_JUCE_NAMESPACE
  68812. /*** End of inlined file: juce_Font.cpp ***/
  68813. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68814. BEGIN_JUCE_NAMESPACE
  68815. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68816. const juce_wchar character_, const int glyph_)
  68817. : x (x_),
  68818. y (y_),
  68819. w (w_),
  68820. font (font_),
  68821. character (character_),
  68822. glyph (glyph_)
  68823. {
  68824. }
  68825. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68826. : x (other.x),
  68827. y (other.y),
  68828. w (other.w),
  68829. font (other.font),
  68830. character (other.character),
  68831. glyph (other.glyph)
  68832. {
  68833. }
  68834. void PositionedGlyph::draw (const Graphics& g) const
  68835. {
  68836. if (! isWhitespace())
  68837. {
  68838. g.getInternalContext()->setFont (font);
  68839. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68840. }
  68841. }
  68842. void PositionedGlyph::draw (const Graphics& g,
  68843. const AffineTransform& transform) const
  68844. {
  68845. if (! isWhitespace())
  68846. {
  68847. g.getInternalContext()->setFont (font);
  68848. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  68849. .followedBy (transform));
  68850. }
  68851. }
  68852. void PositionedGlyph::createPath (Path& path) const
  68853. {
  68854. if (! isWhitespace())
  68855. {
  68856. Typeface* const t = font.getTypeface();
  68857. if (t != 0)
  68858. {
  68859. Path p;
  68860. t->getOutlineForGlyph (glyph, p);
  68861. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  68862. .translated (x, y));
  68863. }
  68864. }
  68865. }
  68866. bool PositionedGlyph::hitTest (float px, float py) const
  68867. {
  68868. if (getBounds().contains (px, py) && ! isWhitespace())
  68869. {
  68870. Typeface* const t = font.getTypeface();
  68871. if (t != 0)
  68872. {
  68873. Path p;
  68874. t->getOutlineForGlyph (glyph, p);
  68875. AffineTransform::translation (-x, -y)
  68876. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  68877. .transformPoint (px, py);
  68878. return p.contains (px, py);
  68879. }
  68880. }
  68881. return false;
  68882. }
  68883. void PositionedGlyph::moveBy (const float deltaX,
  68884. const float deltaY)
  68885. {
  68886. x += deltaX;
  68887. y += deltaY;
  68888. }
  68889. GlyphArrangement::GlyphArrangement()
  68890. {
  68891. glyphs.ensureStorageAllocated (128);
  68892. }
  68893. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  68894. {
  68895. addGlyphArrangement (other);
  68896. }
  68897. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  68898. {
  68899. if (this != &other)
  68900. {
  68901. clear();
  68902. addGlyphArrangement (other);
  68903. }
  68904. return *this;
  68905. }
  68906. GlyphArrangement::~GlyphArrangement()
  68907. {
  68908. }
  68909. void GlyphArrangement::clear()
  68910. {
  68911. glyphs.clear();
  68912. }
  68913. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  68914. {
  68915. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  68916. return *glyphs [index];
  68917. }
  68918. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  68919. {
  68920. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  68921. for (int i = 0; i < other.glyphs.size(); ++i)
  68922. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  68923. }
  68924. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  68925. {
  68926. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  68927. }
  68928. void GlyphArrangement::addLineOfText (const Font& font,
  68929. const String& text,
  68930. const float xOffset,
  68931. const float yOffset)
  68932. {
  68933. addCurtailedLineOfText (font, text,
  68934. xOffset, yOffset,
  68935. 1.0e10f, false);
  68936. }
  68937. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  68938. const String& text,
  68939. float xOffset,
  68940. const float yOffset,
  68941. const float maxWidthPixels,
  68942. const bool useEllipsis)
  68943. {
  68944. if (text.isNotEmpty())
  68945. {
  68946. Array <int> newGlyphs;
  68947. Array <float> xOffsets;
  68948. font.getGlyphPositions (text, newGlyphs, xOffsets);
  68949. const int textLen = newGlyphs.size();
  68950. const juce_wchar* const unicodeText = text;
  68951. for (int i = 0; i < textLen; ++i)
  68952. {
  68953. const float thisX = xOffsets.getUnchecked (i);
  68954. const float nextX = xOffsets.getUnchecked (i + 1);
  68955. if (nextX > maxWidthPixels + 1.0f)
  68956. {
  68957. // curtail the string if it's too wide..
  68958. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  68959. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  68960. break;
  68961. }
  68962. else
  68963. {
  68964. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  68965. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  68966. }
  68967. }
  68968. }
  68969. }
  68970. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  68971. const int startIndex, int endIndex)
  68972. {
  68973. int numDeleted = 0;
  68974. if (glyphs.size() > 0)
  68975. {
  68976. Array<int> dotGlyphs;
  68977. Array<float> dotXs;
  68978. font.getGlyphPositions ("..", dotGlyphs, dotXs);
  68979. const float dx = dotXs[1];
  68980. float xOffset = 0.0f, yOffset = 0.0f;
  68981. while (endIndex > startIndex)
  68982. {
  68983. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  68984. xOffset = pg->x;
  68985. yOffset = pg->y;
  68986. glyphs.remove (endIndex);
  68987. ++numDeleted;
  68988. if (xOffset + dx * 3 <= maxXPos)
  68989. break;
  68990. }
  68991. for (int i = 3; --i >= 0;)
  68992. {
  68993. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  68994. font, '.', dotGlyphs.getFirst()));
  68995. --numDeleted;
  68996. xOffset += dx;
  68997. if (xOffset > maxXPos)
  68998. break;
  68999. }
  69000. }
  69001. return numDeleted;
  69002. }
  69003. void GlyphArrangement::addJustifiedText (const Font& font,
  69004. const String& text,
  69005. float x, float y,
  69006. const float maxLineWidth,
  69007. const Justification& horizontalLayout)
  69008. {
  69009. int lineStartIndex = glyphs.size();
  69010. addLineOfText (font, text, x, y);
  69011. const float originalY = y;
  69012. while (lineStartIndex < glyphs.size())
  69013. {
  69014. int i = lineStartIndex;
  69015. if (glyphs.getUnchecked(i)->getCharacter() != '\n'
  69016. && glyphs.getUnchecked(i)->getCharacter() != '\r')
  69017. ++i;
  69018. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69019. int lastWordBreakIndex = -1;
  69020. while (i < glyphs.size())
  69021. {
  69022. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69023. const juce_wchar c = pg->getCharacter();
  69024. if (c == '\r' || c == '\n')
  69025. {
  69026. ++i;
  69027. if (c == '\r' && i < glyphs.size()
  69028. && glyphs.getUnchecked(i)->getCharacter() == '\n')
  69029. ++i;
  69030. break;
  69031. }
  69032. else if (pg->isWhitespace())
  69033. {
  69034. lastWordBreakIndex = i + 1;
  69035. }
  69036. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69037. {
  69038. if (lastWordBreakIndex >= 0)
  69039. i = lastWordBreakIndex;
  69040. break;
  69041. }
  69042. ++i;
  69043. }
  69044. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69045. float currentLineEndX = currentLineStartX;
  69046. for (int j = i; --j >= lineStartIndex;)
  69047. {
  69048. if (! glyphs.getUnchecked (j)->isWhitespace())
  69049. {
  69050. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69051. break;
  69052. }
  69053. }
  69054. float deltaX = 0.0f;
  69055. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69056. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69057. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69058. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69059. else if (horizontalLayout.testFlags (Justification::right))
  69060. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69061. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69062. x + deltaX - currentLineStartX, y - originalY);
  69063. lineStartIndex = i;
  69064. y += font.getHeight();
  69065. }
  69066. }
  69067. void GlyphArrangement::addFittedText (const Font& f,
  69068. const String& text,
  69069. const float x, const float y,
  69070. const float width, const float height,
  69071. const Justification& layout,
  69072. int maximumLines,
  69073. const float minimumHorizontalScale)
  69074. {
  69075. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69076. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69077. if (text.containsAnyOf ("\r\n"))
  69078. {
  69079. GlyphArrangement ga;
  69080. ga.addJustifiedText (f, text, x, y, width, layout);
  69081. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  69082. float dy = y - bb.getY();
  69083. if (layout.testFlags (Justification::verticallyCentred))
  69084. dy += (height - bb.getHeight()) * 0.5f;
  69085. else if (layout.testFlags (Justification::bottom))
  69086. dy += height - bb.getHeight();
  69087. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69088. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69089. for (int i = 0; i < ga.glyphs.size(); ++i)
  69090. glyphs.add (ga.glyphs.getUnchecked (i));
  69091. ga.glyphs.clear (false);
  69092. return;
  69093. }
  69094. int startIndex = glyphs.size();
  69095. addLineOfText (f, text.trim(), x, y);
  69096. if (glyphs.size() > startIndex)
  69097. {
  69098. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69099. - glyphs.getUnchecked (startIndex)->getLeft();
  69100. if (lineWidth <= 0)
  69101. return;
  69102. if (lineWidth * minimumHorizontalScale < width)
  69103. {
  69104. if (lineWidth > width)
  69105. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69106. width / lineWidth);
  69107. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69108. x, y, width, height, layout);
  69109. }
  69110. else if (maximumLines <= 1)
  69111. {
  69112. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69113. x, y, width, height, f, layout, minimumHorizontalScale);
  69114. }
  69115. else
  69116. {
  69117. Font font (f);
  69118. String txt (text.trim());
  69119. const int length = txt.length();
  69120. const int originalStartIndex = startIndex;
  69121. int numLines = 1;
  69122. if (length <= 12 && ! txt.containsAnyOf (" -\t\r\n"))
  69123. maximumLines = 1;
  69124. maximumLines = jmin (maximumLines, length);
  69125. while (numLines < maximumLines)
  69126. {
  69127. ++numLines;
  69128. const float newFontHeight = height / (float) numLines;
  69129. if (newFontHeight < font.getHeight())
  69130. {
  69131. font.setHeight (jmax (8.0f, newFontHeight));
  69132. removeRangeOfGlyphs (startIndex, -1);
  69133. addLineOfText (font, txt, x, y);
  69134. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69135. - glyphs.getUnchecked (startIndex)->getLeft();
  69136. }
  69137. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69138. break;
  69139. }
  69140. if (numLines < 1)
  69141. numLines = 1;
  69142. float lineY = y;
  69143. float widthPerLine = lineWidth / numLines;
  69144. int lastLineStartIndex = 0;
  69145. for (int line = 0; line < numLines; ++line)
  69146. {
  69147. int i = startIndex;
  69148. lastLineStartIndex = i;
  69149. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69150. if (line == numLines - 1)
  69151. {
  69152. widthPerLine = width;
  69153. i = glyphs.size();
  69154. }
  69155. else
  69156. {
  69157. while (i < glyphs.size())
  69158. {
  69159. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69160. if (lineWidth > widthPerLine)
  69161. {
  69162. // got to a point where the line's too long, so skip forward to find a
  69163. // good place to break it..
  69164. const int searchStartIndex = i;
  69165. while (i < glyphs.size())
  69166. {
  69167. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69168. {
  69169. if (glyphs.getUnchecked (i)->isWhitespace()
  69170. || glyphs.getUnchecked (i)->getCharacter() == '-')
  69171. {
  69172. ++i;
  69173. break;
  69174. }
  69175. }
  69176. else
  69177. {
  69178. // can't find a suitable break, so try looking backwards..
  69179. i = searchStartIndex;
  69180. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69181. {
  69182. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69183. || glyphs.getUnchecked (i - back)->getCharacter() == '-')
  69184. {
  69185. i -= back - 1;
  69186. break;
  69187. }
  69188. }
  69189. break;
  69190. }
  69191. ++i;
  69192. }
  69193. break;
  69194. }
  69195. ++i;
  69196. }
  69197. int wsStart = i;
  69198. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69199. --wsStart;
  69200. int wsEnd = i;
  69201. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69202. ++wsEnd;
  69203. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69204. i = jmax (wsStart, startIndex + 1);
  69205. }
  69206. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69207. x, lineY, width, font.getHeight(), font,
  69208. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69209. minimumHorizontalScale);
  69210. startIndex = i;
  69211. lineY += font.getHeight();
  69212. if (startIndex >= glyphs.size())
  69213. break;
  69214. }
  69215. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69216. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69217. }
  69218. }
  69219. }
  69220. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69221. const float dx, const float dy)
  69222. {
  69223. jassert (startIndex >= 0);
  69224. if (dx != 0.0f || dy != 0.0f)
  69225. {
  69226. if (num < 0 || startIndex + num > glyphs.size())
  69227. num = glyphs.size() - startIndex;
  69228. while (--num >= 0)
  69229. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69230. }
  69231. }
  69232. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69233. const Justification& justification, float minimumHorizontalScale)
  69234. {
  69235. int numDeleted = 0;
  69236. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69237. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69238. if (lineWidth > w)
  69239. {
  69240. if (minimumHorizontalScale < 1.0f)
  69241. {
  69242. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69243. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69244. }
  69245. if (lineWidth > w)
  69246. {
  69247. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69248. numGlyphs -= numDeleted;
  69249. }
  69250. }
  69251. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69252. return numDeleted;
  69253. }
  69254. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69255. const float horizontalScaleFactor)
  69256. {
  69257. jassert (startIndex >= 0);
  69258. if (num < 0 || startIndex + num > glyphs.size())
  69259. num = glyphs.size() - startIndex;
  69260. if (num > 0)
  69261. {
  69262. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69263. while (--num >= 0)
  69264. {
  69265. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69266. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69267. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69268. pg->w *= horizontalScaleFactor;
  69269. }
  69270. }
  69271. }
  69272. const Rectangle<float> GlyphArrangement::getBoundingBox (int startIndex, int num, const bool includeWhitespace) const
  69273. {
  69274. jassert (startIndex >= 0);
  69275. if (num < 0 || startIndex + num > glyphs.size())
  69276. num = glyphs.size() - startIndex;
  69277. Rectangle<float> result;
  69278. bool isFirst = true;
  69279. while (--num >= 0)
  69280. {
  69281. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69282. if (includeWhitespace || ! pg->isWhitespace())
  69283. {
  69284. if (isFirst)
  69285. {
  69286. isFirst = false;
  69287. result = pg->getBounds();
  69288. }
  69289. else
  69290. {
  69291. result = result.getUnion (pg->getBounds());
  69292. }
  69293. }
  69294. }
  69295. return result;
  69296. }
  69297. void GlyphArrangement::justifyGlyphs (const int startIndex, const int num,
  69298. const float x, const float y, const float width, const float height,
  69299. const Justification& justification)
  69300. {
  69301. jassert (num >= 0 && startIndex >= 0);
  69302. if (glyphs.size() > 0 && num > 0)
  69303. {
  69304. const Rectangle<float> bb (getBoundingBox (startIndex, num, ! justification.testFlags (Justification::horizontallyJustified
  69305. | Justification::horizontallyCentred)));
  69306. float deltaX = 0.0f;
  69307. if (justification.testFlags (Justification::horizontallyJustified))
  69308. deltaX = x - bb.getX();
  69309. else if (justification.testFlags (Justification::horizontallyCentred))
  69310. deltaX = x + (width - bb.getWidth()) * 0.5f - bb.getX();
  69311. else if (justification.testFlags (Justification::right))
  69312. deltaX = (x + width) - bb.getRight();
  69313. else
  69314. deltaX = x - bb.getX();
  69315. float deltaY = 0.0f;
  69316. if (justification.testFlags (Justification::top))
  69317. deltaY = y - bb.getY();
  69318. else if (justification.testFlags (Justification::bottom))
  69319. deltaY = (y + height) - bb.getBottom();
  69320. else
  69321. deltaY = y + (height - bb.getHeight()) * 0.5f - bb.getY();
  69322. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69323. if (justification.testFlags (Justification::horizontallyJustified))
  69324. {
  69325. int lineStart = 0;
  69326. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69327. int i;
  69328. for (i = 0; i < num; ++i)
  69329. {
  69330. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69331. if (glyphY != baseY)
  69332. {
  69333. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69334. lineStart = i;
  69335. baseY = glyphY;
  69336. }
  69337. }
  69338. if (i > lineStart)
  69339. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69340. }
  69341. }
  69342. }
  69343. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69344. {
  69345. if (start + num < glyphs.size()
  69346. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\r'
  69347. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\n')
  69348. {
  69349. int numSpaces = 0;
  69350. int spacesAtEnd = 0;
  69351. for (int i = 0; i < num; ++i)
  69352. {
  69353. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69354. {
  69355. ++spacesAtEnd;
  69356. ++numSpaces;
  69357. }
  69358. else
  69359. {
  69360. spacesAtEnd = 0;
  69361. }
  69362. }
  69363. numSpaces -= spacesAtEnd;
  69364. if (numSpaces > 0)
  69365. {
  69366. const float startX = glyphs.getUnchecked (start)->getLeft();
  69367. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69368. const float extraPaddingBetweenWords
  69369. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69370. float deltaX = 0.0f;
  69371. for (int i = 0; i < num; ++i)
  69372. {
  69373. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69374. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69375. deltaX += extraPaddingBetweenWords;
  69376. }
  69377. }
  69378. }
  69379. }
  69380. void GlyphArrangement::draw (const Graphics& g) const
  69381. {
  69382. for (int i = 0; i < glyphs.size(); ++i)
  69383. {
  69384. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69385. if (pg->font.isUnderlined())
  69386. {
  69387. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69388. float nextX = pg->x + pg->w;
  69389. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69390. nextX = glyphs.getUnchecked (i + 1)->x;
  69391. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69392. nextX - pg->x, lineThickness);
  69393. }
  69394. pg->draw (g);
  69395. }
  69396. }
  69397. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69398. {
  69399. for (int i = 0; i < glyphs.size(); ++i)
  69400. {
  69401. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69402. if (pg->font.isUnderlined())
  69403. {
  69404. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69405. float nextX = pg->x + pg->w;
  69406. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69407. nextX = glyphs.getUnchecked (i + 1)->x;
  69408. Path p;
  69409. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69410. nextX, pg->y + lineThickness * 2.0f,
  69411. lineThickness);
  69412. g.fillPath (p, transform);
  69413. }
  69414. pg->draw (g, transform);
  69415. }
  69416. }
  69417. void GlyphArrangement::createPath (Path& path) const
  69418. {
  69419. for (int i = 0; i < glyphs.size(); ++i)
  69420. glyphs.getUnchecked (i)->createPath (path);
  69421. }
  69422. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69423. {
  69424. for (int i = 0; i < glyphs.size(); ++i)
  69425. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69426. return i;
  69427. return -1;
  69428. }
  69429. END_JUCE_NAMESPACE
  69430. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69431. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69432. BEGIN_JUCE_NAMESPACE
  69433. class TextLayout::Token
  69434. {
  69435. public:
  69436. String text;
  69437. Font font;
  69438. int x, y, w, h;
  69439. int line, lineHeight;
  69440. bool isWhitespace, isNewLine;
  69441. Token (const String& t,
  69442. const Font& f,
  69443. const bool isWhitespace_)
  69444. : text (t),
  69445. font (f),
  69446. x(0),
  69447. y(0),
  69448. isWhitespace (isWhitespace_)
  69449. {
  69450. w = font.getStringWidth (t);
  69451. h = roundToInt (f.getHeight());
  69452. isNewLine = t.containsChar ('\n') || t.containsChar ('\r');
  69453. }
  69454. Token (const Token& other) throw()
  69455. : text (other.text),
  69456. font (other.font),
  69457. x (other.x),
  69458. y (other.y),
  69459. w (other.w),
  69460. h (other.h),
  69461. line (other.line),
  69462. lineHeight (other.lineHeight),
  69463. isWhitespace (other.isWhitespace),
  69464. isNewLine (other.isNewLine)
  69465. {
  69466. }
  69467. ~Token() throw()
  69468. {
  69469. }
  69470. void draw (Graphics& g,
  69471. const int xOffset,
  69472. const int yOffset)
  69473. {
  69474. if (! isWhitespace)
  69475. {
  69476. g.setFont (font);
  69477. g.drawSingleLineText (text.trimEnd(),
  69478. xOffset + x,
  69479. yOffset + y + (lineHeight - h)
  69480. + roundToInt (font.getAscent()));
  69481. }
  69482. }
  69483. juce_UseDebuggingNewOperator
  69484. };
  69485. TextLayout::TextLayout() throw()
  69486. : totalLines (0)
  69487. {
  69488. tokens.ensureStorageAllocated (64);
  69489. }
  69490. TextLayout::TextLayout (const String& text,
  69491. const Font& font) throw()
  69492. : totalLines (0)
  69493. {
  69494. tokens.ensureStorageAllocated (64);
  69495. appendText (text, font);
  69496. }
  69497. TextLayout::TextLayout (const TextLayout& other) throw()
  69498. : totalLines (0)
  69499. {
  69500. *this = other;
  69501. }
  69502. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  69503. {
  69504. if (this != &other)
  69505. {
  69506. clear();
  69507. totalLines = other.totalLines;
  69508. for (int i = 0; i < other.tokens.size(); ++i)
  69509. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69510. }
  69511. return *this;
  69512. }
  69513. TextLayout::~TextLayout() throw()
  69514. {
  69515. clear();
  69516. }
  69517. void TextLayout::clear() throw()
  69518. {
  69519. tokens.clear();
  69520. totalLines = 0;
  69521. }
  69522. void TextLayout::appendText (const String& text,
  69523. const Font& font) throw()
  69524. {
  69525. const tchar* t = text;
  69526. String currentString;
  69527. int lastCharType = 0;
  69528. for (;;)
  69529. {
  69530. const tchar c = *t++;
  69531. if (c == 0)
  69532. break;
  69533. int charType;
  69534. if (c == '\r' || c == '\n')
  69535. {
  69536. charType = 0;
  69537. }
  69538. else if (CharacterFunctions::isWhitespace (c))
  69539. {
  69540. charType = 2;
  69541. }
  69542. else
  69543. {
  69544. charType = 1;
  69545. }
  69546. if (charType == 0 || charType != lastCharType)
  69547. {
  69548. if (currentString.isNotEmpty())
  69549. {
  69550. tokens.add (new Token (currentString, font,
  69551. lastCharType == 2 || lastCharType == 0));
  69552. }
  69553. currentString = String::charToString (c);
  69554. if (c == '\r' && *t == '\n')
  69555. currentString += *t++;
  69556. }
  69557. else
  69558. {
  69559. currentString += c;
  69560. }
  69561. lastCharType = charType;
  69562. }
  69563. if (currentString.isNotEmpty())
  69564. tokens.add (new Token (currentString, font, lastCharType == 2));
  69565. }
  69566. void TextLayout::setText (const String& text, const Font& font) throw()
  69567. {
  69568. clear();
  69569. appendText (text, font);
  69570. }
  69571. void TextLayout::layout (int maxWidth,
  69572. const Justification& justification,
  69573. const bool attemptToBalanceLineLengths) throw()
  69574. {
  69575. if (attemptToBalanceLineLengths)
  69576. {
  69577. const int originalW = maxWidth;
  69578. int bestWidth = maxWidth;
  69579. float bestLineProportion = 0.0f;
  69580. while (maxWidth > originalW / 2)
  69581. {
  69582. layout (maxWidth, justification, false);
  69583. if (getNumLines() <= 1)
  69584. return;
  69585. const int lastLineW = getLineWidth (getNumLines() - 1);
  69586. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69587. const float prop = lastLineW / (float) lastButOneLineW;
  69588. if (prop > 0.9f)
  69589. return;
  69590. if (prop > bestLineProportion)
  69591. {
  69592. bestLineProportion = prop;
  69593. bestWidth = maxWidth;
  69594. }
  69595. maxWidth -= 10;
  69596. }
  69597. layout (bestWidth, justification, false);
  69598. }
  69599. else
  69600. {
  69601. int x = 0;
  69602. int y = 0;
  69603. int h = 0;
  69604. totalLines = 0;
  69605. int i;
  69606. for (i = 0; i < tokens.size(); ++i)
  69607. {
  69608. Token* const t = tokens.getUnchecked(i);
  69609. t->x = x;
  69610. t->y = y;
  69611. t->line = totalLines;
  69612. x += t->w;
  69613. h = jmax (h, t->h);
  69614. const Token* nextTok = tokens [i + 1];
  69615. if (nextTok == 0)
  69616. break;
  69617. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69618. {
  69619. // finished a line, so go back and update the heights of the things on it
  69620. for (int j = i; j >= 0; --j)
  69621. {
  69622. Token* const tok = tokens.getUnchecked(j);
  69623. if (tok->line == totalLines)
  69624. tok->lineHeight = h;
  69625. else
  69626. break;
  69627. }
  69628. x = 0;
  69629. y += h;
  69630. h = 0;
  69631. ++totalLines;
  69632. }
  69633. }
  69634. // finished a line, so go back and update the heights of the things on it
  69635. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69636. {
  69637. Token* const t = tokens.getUnchecked(j);
  69638. if (t->line == totalLines)
  69639. t->lineHeight = h;
  69640. else
  69641. break;
  69642. }
  69643. ++totalLines;
  69644. if (! justification.testFlags (Justification::left))
  69645. {
  69646. int totalW = getWidth();
  69647. for (i = totalLines; --i >= 0;)
  69648. {
  69649. const int lineW = getLineWidth (i);
  69650. int dx = 0;
  69651. if (justification.testFlags (Justification::horizontallyCentred))
  69652. dx = (totalW - lineW) / 2;
  69653. else if (justification.testFlags (Justification::right))
  69654. dx = totalW - lineW;
  69655. for (int j = tokens.size(); --j >= 0;)
  69656. {
  69657. Token* const t = tokens.getUnchecked(j);
  69658. if (t->line == i)
  69659. t->x += dx;
  69660. }
  69661. }
  69662. }
  69663. }
  69664. }
  69665. int TextLayout::getLineWidth (const int lineNumber) const throw()
  69666. {
  69667. int maxW = 0;
  69668. for (int i = tokens.size(); --i >= 0;)
  69669. {
  69670. const Token* const t = tokens.getUnchecked(i);
  69671. if (t->line == lineNumber && ! t->isWhitespace)
  69672. maxW = jmax (maxW, t->x + t->w);
  69673. }
  69674. return maxW;
  69675. }
  69676. int TextLayout::getWidth() const throw()
  69677. {
  69678. int maxW = 0;
  69679. for (int i = tokens.size(); --i >= 0;)
  69680. {
  69681. const Token* const t = tokens.getUnchecked(i);
  69682. if (! t->isWhitespace)
  69683. maxW = jmax (maxW, t->x + t->w);
  69684. }
  69685. return maxW;
  69686. }
  69687. int TextLayout::getHeight() const throw()
  69688. {
  69689. int maxH = 0;
  69690. for (int i = tokens.size(); --i >= 0;)
  69691. {
  69692. const Token* const t = tokens.getUnchecked(i);
  69693. if (! t->isWhitespace)
  69694. maxH = jmax (maxH, t->y + t->h);
  69695. }
  69696. return maxH;
  69697. }
  69698. void TextLayout::draw (Graphics& g,
  69699. const int xOffset,
  69700. const int yOffset) const throw()
  69701. {
  69702. for (int i = tokens.size(); --i >= 0;)
  69703. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69704. }
  69705. void TextLayout::drawWithin (Graphics& g,
  69706. int x, int y, int w, int h,
  69707. const Justification& justification) const throw()
  69708. {
  69709. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69710. x, y, w, h);
  69711. draw (g, x, y);
  69712. }
  69713. END_JUCE_NAMESPACE
  69714. /*** End of inlined file: juce_TextLayout.cpp ***/
  69715. /*** Start of inlined file: juce_Typeface.cpp ***/
  69716. BEGIN_JUCE_NAMESPACE
  69717. Typeface::Typeface (const String& name_) throw()
  69718. : name (name_)
  69719. {
  69720. }
  69721. Typeface::~Typeface()
  69722. {
  69723. }
  69724. class CustomTypeface::GlyphInfo
  69725. {
  69726. public:
  69727. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69728. : character (character_), path (path_), width (width_)
  69729. {
  69730. }
  69731. ~GlyphInfo() throw()
  69732. {
  69733. }
  69734. struct KerningPair
  69735. {
  69736. juce_wchar character2;
  69737. float kerningAmount;
  69738. };
  69739. void addKerningPair (const juce_wchar subsequentCharacter,
  69740. const float extraKerningAmount) throw()
  69741. {
  69742. KerningPair kp;
  69743. kp.character2 = subsequentCharacter;
  69744. kp.kerningAmount = extraKerningAmount;
  69745. kerningPairs.add (kp);
  69746. }
  69747. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69748. {
  69749. if (subsequentCharacter != 0)
  69750. {
  69751. for (int i = kerningPairs.size(); --i >= 0;)
  69752. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69753. return width + kerningPairs.getReference(i).kerningAmount;
  69754. }
  69755. return width;
  69756. }
  69757. const juce_wchar character;
  69758. const Path path;
  69759. float width;
  69760. Array <KerningPair> kerningPairs;
  69761. juce_UseDebuggingNewOperator
  69762. private:
  69763. GlyphInfo (const GlyphInfo&);
  69764. GlyphInfo& operator= (const GlyphInfo&);
  69765. };
  69766. CustomTypeface::CustomTypeface()
  69767. : Typeface (String::empty)
  69768. {
  69769. clear();
  69770. }
  69771. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69772. : Typeface (String::empty)
  69773. {
  69774. clear();
  69775. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69776. BufferedInputStream in (&gzin, 32768, false);
  69777. name = in.readString();
  69778. isBold = in.readBool();
  69779. isItalic = in.readBool();
  69780. ascent = in.readFloat();
  69781. defaultCharacter = (juce_wchar) in.readShort();
  69782. int i, numChars = in.readInt();
  69783. for (i = 0; i < numChars; ++i)
  69784. {
  69785. const juce_wchar c = (juce_wchar) in.readShort();
  69786. const float width = in.readFloat();
  69787. Path p;
  69788. p.loadPathFromStream (in);
  69789. addGlyph (c, p, width);
  69790. }
  69791. const int numKerningPairs = in.readInt();
  69792. for (i = 0; i < numKerningPairs; ++i)
  69793. {
  69794. const juce_wchar char1 = (juce_wchar) in.readShort();
  69795. const juce_wchar char2 = (juce_wchar) in.readShort();
  69796. addKerningPair (char1, char2, in.readFloat());
  69797. }
  69798. }
  69799. CustomTypeface::~CustomTypeface()
  69800. {
  69801. }
  69802. void CustomTypeface::clear()
  69803. {
  69804. defaultCharacter = 0;
  69805. ascent = 1.0f;
  69806. isBold = isItalic = false;
  69807. zeromem (lookupTable, sizeof (lookupTable));
  69808. glyphs.clear();
  69809. }
  69810. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69811. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69812. {
  69813. name = name_;
  69814. defaultCharacter = defaultCharacter_;
  69815. ascent = ascent_;
  69816. isBold = isBold_;
  69817. isItalic = isItalic_;
  69818. }
  69819. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69820. {
  69821. // Check that you're not trying to add the same character twice..
  69822. jassert (findGlyph (character, false) == 0);
  69823. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  69824. lookupTable [character] = (short) glyphs.size();
  69825. glyphs.add (new GlyphInfo (character, path, width));
  69826. }
  69827. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  69828. {
  69829. if (extraAmount != 0)
  69830. {
  69831. GlyphInfo* const g = findGlyph (char1, true);
  69832. jassert (g != 0); // can only add kerning pairs for characters that exist!
  69833. if (g != 0)
  69834. g->addKerningPair (char2, extraAmount);
  69835. }
  69836. }
  69837. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  69838. {
  69839. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  69840. return glyphs [(int) lookupTable [(int) character]];
  69841. for (int i = 0; i < glyphs.size(); ++i)
  69842. {
  69843. GlyphInfo* const g = glyphs.getUnchecked(i);
  69844. if (g->character == character)
  69845. return g;
  69846. }
  69847. if (loadIfNeeded && loadGlyphIfPossible (character))
  69848. return findGlyph (character, false);
  69849. return 0;
  69850. }
  69851. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  69852. {
  69853. GlyphInfo* glyph = findGlyph (character, true);
  69854. if (glyph == 0)
  69855. {
  69856. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  69857. glyph = findGlyph (L' ', true);
  69858. if (glyph == 0)
  69859. {
  69860. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  69861. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  69862. if (fallbackTypeface != 0 && fallbackTypeface != this)
  69863. {
  69864. //xxx
  69865. }
  69866. if (glyph == 0)
  69867. glyph = findGlyph (defaultCharacter, true);
  69868. }
  69869. }
  69870. return glyph;
  69871. }
  69872. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  69873. {
  69874. return false;
  69875. }
  69876. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  69877. {
  69878. for (int i = 0; i < numCharacters; ++i)
  69879. {
  69880. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  69881. Array <int> glyphIndexes;
  69882. Array <float> offsets;
  69883. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  69884. const int glyphIndex = glyphIndexes.getFirst();
  69885. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  69886. {
  69887. const float glyphWidth = offsets[1];
  69888. Path p;
  69889. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  69890. addGlyph (c, p, glyphWidth);
  69891. for (int j = glyphs.size() - 1; --j >= 0;)
  69892. {
  69893. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  69894. glyphIndexes.clearQuick();
  69895. offsets.clearQuick();
  69896. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  69897. if (offsets.size() > 1)
  69898. addKerningPair (c, char2, offsets[1] - glyphWidth);
  69899. }
  69900. }
  69901. }
  69902. }
  69903. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  69904. {
  69905. GZIPCompressorOutputStream out (&outputStream);
  69906. out.writeString (name);
  69907. out.writeBool (isBold);
  69908. out.writeBool (isItalic);
  69909. out.writeFloat (ascent);
  69910. out.writeShort ((short) (unsigned short) defaultCharacter);
  69911. out.writeInt (glyphs.size());
  69912. int i, numKerningPairs = 0;
  69913. for (i = 0; i < glyphs.size(); ++i)
  69914. {
  69915. const GlyphInfo* const g = glyphs.getUnchecked (i);
  69916. out.writeShort ((short) (unsigned short) g->character);
  69917. out.writeFloat (g->width);
  69918. g->path.writePathToStream (out);
  69919. numKerningPairs += g->kerningPairs.size();
  69920. }
  69921. out.writeInt (numKerningPairs);
  69922. for (i = 0; i < glyphs.size(); ++i)
  69923. {
  69924. const GlyphInfo* const g = glyphs.getUnchecked (i);
  69925. for (int j = 0; j < g->kerningPairs.size(); ++j)
  69926. {
  69927. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  69928. out.writeShort ((short) (unsigned short) g->character);
  69929. out.writeShort ((short) (unsigned short) p.character2);
  69930. out.writeFloat (p.kerningAmount);
  69931. }
  69932. }
  69933. return true;
  69934. }
  69935. float CustomTypeface::getAscent() const
  69936. {
  69937. return ascent;
  69938. }
  69939. float CustomTypeface::getDescent() const
  69940. {
  69941. return 1.0f - ascent;
  69942. }
  69943. float CustomTypeface::getStringWidth (const String& text)
  69944. {
  69945. float x = 0;
  69946. const juce_wchar* t = text;
  69947. while (*t != 0)
  69948. {
  69949. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  69950. if (glyph != 0)
  69951. x += glyph->getHorizontalSpacing (*t);
  69952. }
  69953. return x;
  69954. }
  69955. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  69956. {
  69957. xOffsets.add (0);
  69958. float x = 0;
  69959. const juce_wchar* t = text;
  69960. while (*t != 0)
  69961. {
  69962. const juce_wchar c = *t++;
  69963. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  69964. if (glyph != 0)
  69965. {
  69966. x += glyph->getHorizontalSpacing (*t);
  69967. resultGlyphs.add ((int) glyph->character);
  69968. xOffsets.add (x);
  69969. }
  69970. }
  69971. }
  69972. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  69973. {
  69974. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  69975. if (glyph != 0)
  69976. {
  69977. path = glyph->path;
  69978. return true;
  69979. }
  69980. return false;
  69981. }
  69982. END_JUCE_NAMESPACE
  69983. /*** End of inlined file: juce_Typeface.cpp ***/
  69984. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  69985. BEGIN_JUCE_NAMESPACE
  69986. AffineTransform::AffineTransform() throw()
  69987. : mat00 (1.0f),
  69988. mat01 (0),
  69989. mat02 (0),
  69990. mat10 (0),
  69991. mat11 (1.0f),
  69992. mat12 (0)
  69993. {
  69994. }
  69995. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  69996. : mat00 (other.mat00),
  69997. mat01 (other.mat01),
  69998. mat02 (other.mat02),
  69999. mat10 (other.mat10),
  70000. mat11 (other.mat11),
  70001. mat12 (other.mat12)
  70002. {
  70003. }
  70004. AffineTransform::AffineTransform (const float mat00_,
  70005. const float mat01_,
  70006. const float mat02_,
  70007. const float mat10_,
  70008. const float mat11_,
  70009. const float mat12_) throw()
  70010. : mat00 (mat00_),
  70011. mat01 (mat01_),
  70012. mat02 (mat02_),
  70013. mat10 (mat10_),
  70014. mat11 (mat11_),
  70015. mat12 (mat12_)
  70016. {
  70017. }
  70018. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70019. {
  70020. mat00 = other.mat00;
  70021. mat01 = other.mat01;
  70022. mat02 = other.mat02;
  70023. mat10 = other.mat10;
  70024. mat11 = other.mat11;
  70025. mat12 = other.mat12;
  70026. return *this;
  70027. }
  70028. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70029. {
  70030. return mat00 == other.mat00
  70031. && mat01 == other.mat01
  70032. && mat02 == other.mat02
  70033. && mat10 == other.mat10
  70034. && mat11 == other.mat11
  70035. && mat12 == other.mat12;
  70036. }
  70037. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70038. {
  70039. return ! operator== (other);
  70040. }
  70041. bool AffineTransform::isIdentity() const throw()
  70042. {
  70043. return (mat01 == 0)
  70044. && (mat02 == 0)
  70045. && (mat10 == 0)
  70046. && (mat12 == 0)
  70047. && (mat00 == 1.0f)
  70048. && (mat11 == 1.0f);
  70049. }
  70050. const AffineTransform AffineTransform::identity;
  70051. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70052. {
  70053. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70054. other.mat00 * mat01 + other.mat01 * mat11,
  70055. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70056. other.mat10 * mat00 + other.mat11 * mat10,
  70057. other.mat10 * mat01 + other.mat11 * mat11,
  70058. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70059. }
  70060. const AffineTransform AffineTransform::followedBy (const float omat00,
  70061. const float omat01,
  70062. const float omat02,
  70063. const float omat10,
  70064. const float omat11,
  70065. const float omat12) const throw()
  70066. {
  70067. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70068. omat00 * mat01 + omat01 * mat11,
  70069. omat00 * mat02 + omat01 * mat12 + omat02,
  70070. omat10 * mat00 + omat11 * mat10,
  70071. omat10 * mat01 + omat11 * mat11,
  70072. omat10 * mat02 + omat11 * mat12 + omat12);
  70073. }
  70074. const AffineTransform AffineTransform::translated (const float dx,
  70075. const float dy) const throw()
  70076. {
  70077. return AffineTransform (mat00, mat01, mat02 + dx,
  70078. mat10, mat11, mat12 + dy);
  70079. }
  70080. const AffineTransform AffineTransform::translation (const float dx,
  70081. const float dy) throw()
  70082. {
  70083. return AffineTransform (1.0f, 0, dx,
  70084. 0, 1.0f, dy);
  70085. }
  70086. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70087. {
  70088. const float cosRad = cosf (rad);
  70089. const float sinRad = sinf (rad);
  70090. return followedBy (cosRad, -sinRad, 0,
  70091. sinRad, cosRad, 0);
  70092. }
  70093. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70094. {
  70095. const float cosRad = cosf (rad);
  70096. const float sinRad = sinf (rad);
  70097. return AffineTransform (cosRad, -sinRad, 0,
  70098. sinRad, cosRad, 0);
  70099. }
  70100. const AffineTransform AffineTransform::rotated (const float angle,
  70101. const float pivotX,
  70102. const float pivotY) const throw()
  70103. {
  70104. return translated (-pivotX, -pivotY)
  70105. .rotated (angle)
  70106. .translated (pivotX, pivotY);
  70107. }
  70108. const AffineTransform AffineTransform::rotation (const float angle,
  70109. const float pivotX,
  70110. const float pivotY) throw()
  70111. {
  70112. return translation (-pivotX, -pivotY)
  70113. .rotated (angle)
  70114. .translated (pivotX, pivotY);
  70115. }
  70116. const AffineTransform AffineTransform::scaled (const float factorX,
  70117. const float factorY) const throw()
  70118. {
  70119. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70120. factorY * mat10, factorY * mat11, factorY * mat12);
  70121. }
  70122. const AffineTransform AffineTransform::scale (const float factorX,
  70123. const float factorY) throw()
  70124. {
  70125. return AffineTransform (factorX, 0, 0,
  70126. 0, factorY, 0);
  70127. }
  70128. const AffineTransform AffineTransform::sheared (const float shearX,
  70129. const float shearY) const throw()
  70130. {
  70131. return followedBy (1.0f, shearX, 0,
  70132. shearY, 1.0f, 0);
  70133. }
  70134. const AffineTransform AffineTransform::inverted() const throw()
  70135. {
  70136. double determinant = (mat00 * mat11 - mat10 * mat01);
  70137. if (determinant != 0.0)
  70138. {
  70139. determinant = 1.0 / determinant;
  70140. const float dst00 = (float) (mat11 * determinant);
  70141. const float dst10 = (float) (-mat10 * determinant);
  70142. const float dst01 = (float) (-mat01 * determinant);
  70143. const float dst11 = (float) (mat00 * determinant);
  70144. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70145. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70146. }
  70147. else
  70148. {
  70149. // singularity..
  70150. return *this;
  70151. }
  70152. }
  70153. bool AffineTransform::isSingularity() const throw()
  70154. {
  70155. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70156. }
  70157. bool AffineTransform::isOnlyTranslation() const throw()
  70158. {
  70159. return (mat01 == 0)
  70160. && (mat10 == 0)
  70161. && (mat00 == 1.0f)
  70162. && (mat11 == 1.0f);
  70163. }
  70164. void AffineTransform::transformPoint (float& x,
  70165. float& y) const throw()
  70166. {
  70167. const float oldX = x;
  70168. x = mat00 * oldX + mat01 * y + mat02;
  70169. y = mat10 * oldX + mat11 * y + mat12;
  70170. }
  70171. void AffineTransform::transformPoint (double& x,
  70172. double& y) const throw()
  70173. {
  70174. const double oldX = x;
  70175. x = mat00 * oldX + mat01 * y + mat02;
  70176. y = mat10 * oldX + mat11 * y + mat12;
  70177. }
  70178. END_JUCE_NAMESPACE
  70179. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70180. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70181. BEGIN_JUCE_NAMESPACE
  70182. BorderSize::BorderSize() throw()
  70183. : top (0),
  70184. left (0),
  70185. bottom (0),
  70186. right (0)
  70187. {
  70188. }
  70189. BorderSize::BorderSize (const BorderSize& other) throw()
  70190. : top (other.top),
  70191. left (other.left),
  70192. bottom (other.bottom),
  70193. right (other.right)
  70194. {
  70195. }
  70196. BorderSize::BorderSize (const int topGap,
  70197. const int leftGap,
  70198. const int bottomGap,
  70199. const int rightGap) throw()
  70200. : top (topGap),
  70201. left (leftGap),
  70202. bottom (bottomGap),
  70203. right (rightGap)
  70204. {
  70205. }
  70206. BorderSize::BorderSize (const int allGaps) throw()
  70207. : top (allGaps),
  70208. left (allGaps),
  70209. bottom (allGaps),
  70210. right (allGaps)
  70211. {
  70212. }
  70213. BorderSize::~BorderSize() throw()
  70214. {
  70215. }
  70216. void BorderSize::setTop (const int newTopGap) throw()
  70217. {
  70218. top = newTopGap;
  70219. }
  70220. void BorderSize::setLeft (const int newLeftGap) throw()
  70221. {
  70222. left = newLeftGap;
  70223. }
  70224. void BorderSize::setBottom (const int newBottomGap) throw()
  70225. {
  70226. bottom = newBottomGap;
  70227. }
  70228. void BorderSize::setRight (const int newRightGap) throw()
  70229. {
  70230. right = newRightGap;
  70231. }
  70232. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70233. {
  70234. return Rectangle<int> (r.getX() + left,
  70235. r.getY() + top,
  70236. r.getWidth() - (left + right),
  70237. r.getHeight() - (top + bottom));
  70238. }
  70239. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70240. {
  70241. r.setBounds (r.getX() + left,
  70242. r.getY() + top,
  70243. r.getWidth() - (left + right),
  70244. r.getHeight() - (top + bottom));
  70245. }
  70246. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70247. {
  70248. return Rectangle<int> (r.getX() - left,
  70249. r.getY() - top,
  70250. r.getWidth() + (left + right),
  70251. r.getHeight() + (top + bottom));
  70252. }
  70253. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70254. {
  70255. r.setBounds (r.getX() - left,
  70256. r.getY() - top,
  70257. r.getWidth() + (left + right),
  70258. r.getHeight() + (top + bottom));
  70259. }
  70260. bool BorderSize::operator== (const BorderSize& other) const throw()
  70261. {
  70262. return top == other.top
  70263. && left == other.left
  70264. && bottom == other.bottom
  70265. && right == other.right;
  70266. }
  70267. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70268. {
  70269. return ! operator== (other);
  70270. }
  70271. END_JUCE_NAMESPACE
  70272. /*** End of inlined file: juce_BorderSize.cpp ***/
  70273. /*** Start of inlined file: juce_Line.cpp ***/
  70274. BEGIN_JUCE_NAMESPACE
  70275. static bool juce_lineIntersection (const float x1, const float y1,
  70276. const float x2, const float y2,
  70277. const float x3, const float y3,
  70278. const float x4, const float y4,
  70279. float& intersectionX,
  70280. float& intersectionY) throw()
  70281. {
  70282. if (x2 != x3 || y2 != y3)
  70283. {
  70284. const float dx1 = x2 - x1;
  70285. const float dy1 = y2 - y1;
  70286. const float dx2 = x4 - x3;
  70287. const float dy2 = y4 - y3;
  70288. const float divisor = dx1 * dy2 - dx2 * dy1;
  70289. if (divisor == 0)
  70290. {
  70291. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70292. {
  70293. if (dy1 == 0 && dy2 != 0)
  70294. {
  70295. const float along = (y1 - y3) / dy2;
  70296. intersectionX = x3 + along * dx2;
  70297. intersectionY = y1;
  70298. return along >= 0 && along <= 1.0f;
  70299. }
  70300. else if (dy2 == 0 && dy1 != 0)
  70301. {
  70302. const float along = (y3 - y1) / dy1;
  70303. intersectionX = x1 + along * dx1;
  70304. intersectionY = y3;
  70305. return along >= 0 && along <= 1.0f;
  70306. }
  70307. else if (dx1 == 0 && dx2 != 0)
  70308. {
  70309. const float along = (x1 - x3) / dx2;
  70310. intersectionX = x1;
  70311. intersectionY = y3 + along * dy2;
  70312. return along >= 0 && along <= 1.0f;
  70313. }
  70314. else if (dx2 == 0 && dx1 != 0)
  70315. {
  70316. const float along = (x3 - x1) / dx1;
  70317. intersectionX = x3;
  70318. intersectionY = y1 + along * dy1;
  70319. return along >= 0 && along <= 1.0f;
  70320. }
  70321. }
  70322. intersectionX = 0.5f * (x2 + x3);
  70323. intersectionY = 0.5f * (y2 + y3);
  70324. return false;
  70325. }
  70326. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70327. intersectionX = x1 + along1 * dx1;
  70328. intersectionY = y1 + along1 * dy1;
  70329. if (along1 < 0 || along1 > 1.0f)
  70330. return false;
  70331. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70332. return along2 >= 0 && along2 <= 1.0f;
  70333. }
  70334. intersectionX = x2;
  70335. intersectionY = y2;
  70336. return true;
  70337. }
  70338. Line::Line() throw()
  70339. : startX (0.0f),
  70340. startY (0.0f),
  70341. endX (0.0f),
  70342. endY (0.0f)
  70343. {
  70344. }
  70345. Line::Line (const Line& other) throw()
  70346. : startX (other.startX),
  70347. startY (other.startY),
  70348. endX (other.endX),
  70349. endY (other.endY)
  70350. {
  70351. }
  70352. Line::Line (const float startX_, const float startY_,
  70353. const float endX_, const float endY_) throw()
  70354. : startX (startX_),
  70355. startY (startY_),
  70356. endX (endX_),
  70357. endY (endY_)
  70358. {
  70359. }
  70360. Line::Line (const Point<float>& start,
  70361. const Point<float>& end) throw()
  70362. : startX (start.getX()),
  70363. startY (start.getY()),
  70364. endX (end.getX()),
  70365. endY (end.getY())
  70366. {
  70367. }
  70368. Line& Line::operator= (const Line& other) throw()
  70369. {
  70370. startX = other.startX;
  70371. startY = other.startY;
  70372. endX = other.endX;
  70373. endY = other.endY;
  70374. return *this;
  70375. }
  70376. Line::~Line() throw()
  70377. {
  70378. }
  70379. const Point<float> Line::getStart() const throw()
  70380. {
  70381. return Point<float> (startX, startY);
  70382. }
  70383. const Point<float> Line::getEnd() const throw()
  70384. {
  70385. return Point<float> (endX, endY);
  70386. }
  70387. void Line::setStart (const float newStartX,
  70388. const float newStartY) throw()
  70389. {
  70390. startX = newStartX;
  70391. startY = newStartY;
  70392. }
  70393. void Line::setStart (const Point<float>& newStart) throw()
  70394. {
  70395. startX = newStart.getX();
  70396. startY = newStart.getY();
  70397. }
  70398. void Line::setEnd (const float newEndX,
  70399. const float newEndY) throw()
  70400. {
  70401. endX = newEndX;
  70402. endY = newEndY;
  70403. }
  70404. void Line::setEnd (const Point<float>& newEnd) throw()
  70405. {
  70406. endX = newEnd.getX();
  70407. endY = newEnd.getY();
  70408. }
  70409. bool Line::operator== (const Line& other) const throw()
  70410. {
  70411. return startX == other.startX
  70412. && startY == other.startY
  70413. && endX == other.endX
  70414. && endY == other.endY;
  70415. }
  70416. bool Line::operator!= (const Line& other) const throw()
  70417. {
  70418. return startX != other.startX
  70419. || startY != other.startY
  70420. || endX != other.endX
  70421. || endY != other.endY;
  70422. }
  70423. void Line::applyTransform (const AffineTransform& transform) throw()
  70424. {
  70425. transform.transformPoint (startX, startY);
  70426. transform.transformPoint (endX, endY);
  70427. }
  70428. float Line::getLength() const throw()
  70429. {
  70430. return (float) juce_hypot (startX - endX,
  70431. startY - endY);
  70432. }
  70433. float Line::getAngle() const throw()
  70434. {
  70435. return atan2f (endX - startX,
  70436. endY - startY);
  70437. }
  70438. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70439. {
  70440. const float alpha = distanceFromStart / getLength();
  70441. return Point<float> (startX + (endX - startX) * alpha,
  70442. startY + (endY - startY) * alpha);
  70443. }
  70444. const Point<float> Line::getPointAlongLine (const float offsetX,
  70445. const float offsetY) const throw()
  70446. {
  70447. const float dx = endX - startX;
  70448. const float dy = endY - startY;
  70449. const double length = juce_hypot (dx, dy);
  70450. if (length == 0)
  70451. return Point<float> (startX, startY);
  70452. else
  70453. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70454. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70455. }
  70456. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70457. {
  70458. return Point<float> (startX + (endX - startX) * alpha,
  70459. startY + (endY - startY) * alpha);
  70460. }
  70461. float Line::getDistanceFromLine (const float x,
  70462. const float y) const throw()
  70463. {
  70464. const double dx = endX - startX;
  70465. const double dy = endY - startY;
  70466. const double length = dx * dx + dy * dy;
  70467. if (length > 0)
  70468. {
  70469. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70470. if (prop >= 0.0f && prop < 1.0f)
  70471. {
  70472. return (float) juce_hypot (x - (startX + prop * dx),
  70473. y - (startY + prop * dy));
  70474. }
  70475. }
  70476. return (float) jmin (juce_hypot (x - startX, y - startY),
  70477. juce_hypot (x - endX, y - endY));
  70478. }
  70479. float Line::findNearestPointTo (const float x,
  70480. const float y) const throw()
  70481. {
  70482. const double dx = endX - startX;
  70483. const double dy = endY - startY;
  70484. const double length = dx * dx + dy * dy;
  70485. if (length <= 0.0)
  70486. return 0.0f;
  70487. return jlimit (0.0f, 1.0f,
  70488. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70489. }
  70490. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70491. {
  70492. const float length = getLength();
  70493. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70494. getEnd());
  70495. }
  70496. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70497. {
  70498. const float length = getLength();
  70499. return Line (getStart(),
  70500. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70501. }
  70502. bool Line::clipToPath (const Path& path,
  70503. const bool keepSectionOutsidePath) throw()
  70504. {
  70505. const bool startInside = path.contains (startX, startY);
  70506. const bool endInside = path.contains (endX, endY);
  70507. if (startInside == endInside)
  70508. {
  70509. if (keepSectionOutsidePath != startInside)
  70510. {
  70511. // entirely outside the path
  70512. return false;
  70513. }
  70514. else
  70515. {
  70516. // entirely inside the path
  70517. startX = 0.0f;
  70518. startY = 0.0f;
  70519. endX = 0.0f;
  70520. endY = 0.0f;
  70521. return true;
  70522. }
  70523. }
  70524. else
  70525. {
  70526. bool changed = false;
  70527. PathFlatteningIterator iter (path, AffineTransform::identity);
  70528. while (iter.next())
  70529. {
  70530. float ix, iy;
  70531. if (intersects (Line (iter.x1, iter.y1,
  70532. iter.x2, iter.y2),
  70533. ix, iy))
  70534. {
  70535. if ((startInside && keepSectionOutsidePath)
  70536. || (endInside && ! keepSectionOutsidePath))
  70537. {
  70538. setStart (ix, iy);
  70539. }
  70540. else
  70541. {
  70542. setEnd (ix, iy);
  70543. }
  70544. changed = true;
  70545. }
  70546. }
  70547. return changed;
  70548. }
  70549. }
  70550. bool Line::intersects (const Line& line,
  70551. float& intersectionX,
  70552. float& intersectionY) const throw()
  70553. {
  70554. return juce_lineIntersection (startX, startY,
  70555. endX, endY,
  70556. line.startX, line.startY,
  70557. line.endX, line.endY,
  70558. intersectionX,
  70559. intersectionY);
  70560. }
  70561. bool Line::isVertical() const throw()
  70562. {
  70563. return startX == endX;
  70564. }
  70565. bool Line::isHorizontal() const throw()
  70566. {
  70567. return startY == endY;
  70568. }
  70569. bool Line::isPointAbove (const float x, const float y) const throw()
  70570. {
  70571. return startX != endX
  70572. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70573. }
  70574. END_JUCE_NAMESPACE
  70575. /*** End of inlined file: juce_Line.cpp ***/
  70576. /*** Start of inlined file: juce_Path.cpp ***/
  70577. BEGIN_JUCE_NAMESPACE
  70578. // tests that some co-ords aren't NaNs
  70579. #define CHECK_COORDS_ARE_VALID(x, y) \
  70580. jassert (x == x && y == y);
  70581. namespace PathHelpers
  70582. {
  70583. static const float ellipseAngularIncrement = 0.05f;
  70584. static void perpendicularOffset (const float x1, const float y1,
  70585. const float x2, const float y2,
  70586. const float offsetX, const float offsetY,
  70587. float& resultX, float& resultY) throw()
  70588. {
  70589. const float dx = x2 - x1;
  70590. const float dy = y2 - y1;
  70591. const float len = juce_hypotf (dx, dy);
  70592. if (len == 0)
  70593. {
  70594. resultX = x1;
  70595. resultY = y1;
  70596. }
  70597. else
  70598. {
  70599. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70600. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70601. }
  70602. }
  70603. static const String nextToken (const tchar*& t)
  70604. {
  70605. while (CharacterFunctions::isWhitespace (*t))
  70606. ++t;
  70607. const tchar* const start = t;
  70608. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70609. ++t;
  70610. const int length = (int) (t - start);
  70611. while (CharacterFunctions::isWhitespace (*t))
  70612. ++t;
  70613. return String (start, length);
  70614. }
  70615. }
  70616. const float Path::lineMarker = 100001.0f;
  70617. const float Path::moveMarker = 100002.0f;
  70618. const float Path::quadMarker = 100003.0f;
  70619. const float Path::cubicMarker = 100004.0f;
  70620. const float Path::closeSubPathMarker = 100005.0f;
  70621. Path::Path()
  70622. : numElements (0),
  70623. pathXMin (0),
  70624. pathXMax (0),
  70625. pathYMin (0),
  70626. pathYMax (0),
  70627. useNonZeroWinding (true)
  70628. {
  70629. }
  70630. Path::~Path()
  70631. {
  70632. }
  70633. Path::Path (const Path& other)
  70634. : numElements (other.numElements),
  70635. pathXMin (other.pathXMin),
  70636. pathXMax (other.pathXMax),
  70637. pathYMin (other.pathYMin),
  70638. pathYMax (other.pathYMax),
  70639. useNonZeroWinding (other.useNonZeroWinding)
  70640. {
  70641. if (numElements > 0)
  70642. {
  70643. data.setAllocatedSize (numElements);
  70644. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70645. }
  70646. }
  70647. Path& Path::operator= (const Path& other)
  70648. {
  70649. if (this != &other)
  70650. {
  70651. data.ensureAllocatedSize (other.numElements);
  70652. numElements = other.numElements;
  70653. pathXMin = other.pathXMin;
  70654. pathXMax = other.pathXMax;
  70655. pathYMin = other.pathYMin;
  70656. pathYMax = other.pathYMax;
  70657. useNonZeroWinding = other.useNonZeroWinding;
  70658. if (numElements > 0)
  70659. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70660. }
  70661. return *this;
  70662. }
  70663. void Path::clear() throw()
  70664. {
  70665. numElements = 0;
  70666. pathXMin = 0;
  70667. pathYMin = 0;
  70668. pathYMax = 0;
  70669. pathXMax = 0;
  70670. }
  70671. void Path::swapWithPath (Path& other)
  70672. {
  70673. data.swapWith (other.data);
  70674. swapVariables <size_t> (numElements, other.numElements);
  70675. swapVariables <float> (pathXMin, other.pathXMin);
  70676. swapVariables <float> (pathXMax, other.pathXMax);
  70677. swapVariables <float> (pathYMin, other.pathYMin);
  70678. swapVariables <float> (pathYMax, other.pathYMax);
  70679. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70680. }
  70681. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70682. {
  70683. useNonZeroWinding = isNonZero;
  70684. }
  70685. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70686. const bool preserveProportions) throw()
  70687. {
  70688. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70689. }
  70690. bool Path::isEmpty() const throw()
  70691. {
  70692. size_t i = 0;
  70693. while (i < numElements)
  70694. {
  70695. const float type = data.elements [i++];
  70696. if (type == moveMarker)
  70697. {
  70698. i += 2;
  70699. }
  70700. else if (type == lineMarker
  70701. || type == quadMarker
  70702. || type == cubicMarker)
  70703. {
  70704. return false;
  70705. }
  70706. }
  70707. return true;
  70708. }
  70709. const Rectangle<float> Path::getBounds() const throw()
  70710. {
  70711. return Rectangle<float> (pathXMin, pathYMin,
  70712. pathXMax - pathXMin,
  70713. pathYMax - pathYMin);
  70714. }
  70715. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70716. {
  70717. return getBounds().transformed (transform);
  70718. }
  70719. void Path::startNewSubPath (const float x, const float y)
  70720. {
  70721. CHECK_COORDS_ARE_VALID (x, y);
  70722. if (numElements == 0)
  70723. {
  70724. pathXMin = pathXMax = x;
  70725. pathYMin = pathYMax = y;
  70726. }
  70727. else
  70728. {
  70729. pathXMin = jmin (pathXMin, x);
  70730. pathXMax = jmax (pathXMax, x);
  70731. pathYMin = jmin (pathYMin, y);
  70732. pathYMax = jmax (pathYMax, y);
  70733. }
  70734. data.ensureAllocatedSize (numElements + 3);
  70735. data.elements [numElements++] = moveMarker;
  70736. data.elements [numElements++] = x;
  70737. data.elements [numElements++] = y;
  70738. }
  70739. void Path::lineTo (const float x, const float y)
  70740. {
  70741. CHECK_COORDS_ARE_VALID (x, y);
  70742. if (numElements == 0)
  70743. startNewSubPath (0, 0);
  70744. data.ensureAllocatedSize (numElements + 3);
  70745. data.elements [numElements++] = lineMarker;
  70746. data.elements [numElements++] = x;
  70747. data.elements [numElements++] = y;
  70748. pathXMin = jmin (pathXMin, x);
  70749. pathXMax = jmax (pathXMax, x);
  70750. pathYMin = jmin (pathYMin, y);
  70751. pathYMax = jmax (pathYMax, y);
  70752. }
  70753. void Path::quadraticTo (const float x1, const float y1,
  70754. const float x2, const float y2)
  70755. {
  70756. CHECK_COORDS_ARE_VALID (x1, y1);
  70757. CHECK_COORDS_ARE_VALID (x2, y2);
  70758. if (numElements == 0)
  70759. startNewSubPath (0, 0);
  70760. data.ensureAllocatedSize (numElements + 5);
  70761. data.elements [numElements++] = quadMarker;
  70762. data.elements [numElements++] = x1;
  70763. data.elements [numElements++] = y1;
  70764. data.elements [numElements++] = x2;
  70765. data.elements [numElements++] = y2;
  70766. pathXMin = jmin (pathXMin, x1, x2);
  70767. pathXMax = jmax (pathXMax, x1, x2);
  70768. pathYMin = jmin (pathYMin, y1, y2);
  70769. pathYMax = jmax (pathYMax, y1, y2);
  70770. }
  70771. void Path::cubicTo (const float x1, const float y1,
  70772. const float x2, const float y2,
  70773. const float x3, const float y3)
  70774. {
  70775. CHECK_COORDS_ARE_VALID (x1, y1);
  70776. CHECK_COORDS_ARE_VALID (x2, y2);
  70777. CHECK_COORDS_ARE_VALID (x3, y3);
  70778. if (numElements == 0)
  70779. startNewSubPath (0, 0);
  70780. data.ensureAllocatedSize (numElements + 7);
  70781. data.elements [numElements++] = cubicMarker;
  70782. data.elements [numElements++] = x1;
  70783. data.elements [numElements++] = y1;
  70784. data.elements [numElements++] = x2;
  70785. data.elements [numElements++] = y2;
  70786. data.elements [numElements++] = x3;
  70787. data.elements [numElements++] = y3;
  70788. pathXMin = jmin (pathXMin, x1, x2, x3);
  70789. pathXMax = jmax (pathXMax, x1, x2, x3);
  70790. pathYMin = jmin (pathYMin, y1, y2, y3);
  70791. pathYMax = jmax (pathYMax, y1, y2, y3);
  70792. }
  70793. void Path::closeSubPath()
  70794. {
  70795. if (numElements > 0
  70796. && data.elements [numElements - 1] != closeSubPathMarker)
  70797. {
  70798. data.ensureAllocatedSize (numElements + 1);
  70799. data.elements [numElements++] = closeSubPathMarker;
  70800. }
  70801. }
  70802. const Point<float> Path::getCurrentPosition() const
  70803. {
  70804. int i = numElements - 1;
  70805. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70806. {
  70807. while (i >= 0)
  70808. {
  70809. if (data.elements[i] == moveMarker)
  70810. {
  70811. i += 2;
  70812. break;
  70813. }
  70814. --i;
  70815. }
  70816. }
  70817. if (i > 0)
  70818. return Point<float> (data.elements [i - 1], data.elements [i]);
  70819. return Point<float>();
  70820. }
  70821. void Path::addRectangle (const float x, const float y,
  70822. const float w, const float h)
  70823. {
  70824. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  70825. if (w < 0)
  70826. swapVariables (x1, x2);
  70827. if (h < 0)
  70828. swapVariables (y1, y2);
  70829. data.ensureAllocatedSize (numElements + 13);
  70830. if (numElements == 0)
  70831. {
  70832. pathXMin = x1;
  70833. pathXMax = x2;
  70834. pathYMin = y1;
  70835. pathYMax = y2;
  70836. }
  70837. else
  70838. {
  70839. pathXMin = jmin (pathXMin, x1);
  70840. pathXMax = jmax (pathXMax, x2);
  70841. pathYMin = jmin (pathYMin, y1);
  70842. pathYMax = jmax (pathYMax, y2);
  70843. }
  70844. data.elements [numElements++] = moveMarker;
  70845. data.elements [numElements++] = x1;
  70846. data.elements [numElements++] = y2;
  70847. data.elements [numElements++] = lineMarker;
  70848. data.elements [numElements++] = x1;
  70849. data.elements [numElements++] = y1;
  70850. data.elements [numElements++] = lineMarker;
  70851. data.elements [numElements++] = x2;
  70852. data.elements [numElements++] = y1;
  70853. data.elements [numElements++] = lineMarker;
  70854. data.elements [numElements++] = x2;
  70855. data.elements [numElements++] = y2;
  70856. data.elements [numElements++] = closeSubPathMarker;
  70857. }
  70858. void Path::addRectangle (const Rectangle<int>& rectangle)
  70859. {
  70860. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  70861. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  70862. }
  70863. void Path::addRoundedRectangle (const float x, const float y,
  70864. const float w, const float h,
  70865. float csx,
  70866. float csy)
  70867. {
  70868. csx = jmin (csx, w * 0.5f);
  70869. csy = jmin (csy, h * 0.5f);
  70870. const float cs45x = csx * 0.45f;
  70871. const float cs45y = csy * 0.45f;
  70872. const float x2 = x + w;
  70873. const float y2 = y + h;
  70874. startNewSubPath (x + csx, y);
  70875. lineTo (x2 - csx, y);
  70876. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  70877. lineTo (x2, y2 - csy);
  70878. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  70879. lineTo (x + csx, y2);
  70880. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  70881. lineTo (x, y + csy);
  70882. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  70883. closeSubPath();
  70884. }
  70885. void Path::addRoundedRectangle (const float x, const float y,
  70886. const float w, const float h,
  70887. float cs)
  70888. {
  70889. addRoundedRectangle (x, y, w, h, cs, cs);
  70890. }
  70891. void Path::addTriangle (const float x1, const float y1,
  70892. const float x2, const float y2,
  70893. const float x3, const float y3)
  70894. {
  70895. startNewSubPath (x1, y1);
  70896. lineTo (x2, y2);
  70897. lineTo (x3, y3);
  70898. closeSubPath();
  70899. }
  70900. void Path::addQuadrilateral (const float x1, const float y1,
  70901. const float x2, const float y2,
  70902. const float x3, const float y3,
  70903. const float x4, const float y4)
  70904. {
  70905. startNewSubPath (x1, y1);
  70906. lineTo (x2, y2);
  70907. lineTo (x3, y3);
  70908. lineTo (x4, y4);
  70909. closeSubPath();
  70910. }
  70911. void Path::addEllipse (const float x, const float y,
  70912. const float w, const float h)
  70913. {
  70914. const float hw = w * 0.5f;
  70915. const float hw55 = hw * 0.55f;
  70916. const float hh = h * 0.5f;
  70917. const float hh45 = hh * 0.55f;
  70918. const float cx = x + hw;
  70919. const float cy = y + hh;
  70920. startNewSubPath (cx, cy - hh);
  70921. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  70922. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  70923. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  70924. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  70925. closeSubPath();
  70926. }
  70927. void Path::addArc (const float x, const float y,
  70928. const float w, const float h,
  70929. const float fromRadians,
  70930. const float toRadians,
  70931. const bool startAsNewSubPath)
  70932. {
  70933. const float radiusX = w / 2.0f;
  70934. const float radiusY = h / 2.0f;
  70935. addCentredArc (x + radiusX,
  70936. y + radiusY,
  70937. radiusX, radiusY,
  70938. 0.0f,
  70939. fromRadians, toRadians,
  70940. startAsNewSubPath);
  70941. }
  70942. void Path::addCentredArc (const float centreX, const float centreY,
  70943. const float radiusX, const float radiusY,
  70944. const float rotationOfEllipse,
  70945. const float fromRadians,
  70946. const float toRadians,
  70947. const bool startAsNewSubPath)
  70948. {
  70949. if (radiusX > 0.0f && radiusY > 0.0f)
  70950. {
  70951. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  70952. float angle = fromRadians;
  70953. if (startAsNewSubPath)
  70954. {
  70955. float x = centreX + radiusX * sinf (angle);
  70956. float y = centreY - radiusY * cosf (angle);
  70957. if (rotationOfEllipse != 0)
  70958. rotation.transformPoint (x, y);
  70959. startNewSubPath (x, y);
  70960. }
  70961. if (fromRadians < toRadians)
  70962. {
  70963. if (startAsNewSubPath)
  70964. angle += PathHelpers::ellipseAngularIncrement;
  70965. while (angle < toRadians)
  70966. {
  70967. float x = centreX + radiusX * sinf (angle);
  70968. float y = centreY - radiusY * cosf (angle);
  70969. if (rotationOfEllipse != 0)
  70970. rotation.transformPoint (x, y);
  70971. lineTo (x, y);
  70972. angle += PathHelpers::ellipseAngularIncrement;
  70973. }
  70974. }
  70975. else
  70976. {
  70977. if (startAsNewSubPath)
  70978. angle -= PathHelpers::ellipseAngularIncrement;
  70979. while (angle > toRadians)
  70980. {
  70981. float x = centreX + radiusX * sinf (angle);
  70982. float y = centreY - radiusY * cosf (angle);
  70983. if (rotationOfEllipse != 0)
  70984. rotation.transformPoint (x, y);
  70985. lineTo (x, y);
  70986. angle -= PathHelpers::ellipseAngularIncrement;
  70987. }
  70988. }
  70989. float x = centreX + radiusX * sinf (toRadians);
  70990. float y = centreY - radiusY * cosf (toRadians);
  70991. if (rotationOfEllipse != 0)
  70992. rotation.transformPoint (x, y);
  70993. lineTo (x, y);
  70994. }
  70995. }
  70996. void Path::addPieSegment (const float x, const float y,
  70997. const float width, const float height,
  70998. const float fromRadians,
  70999. const float toRadians,
  71000. const float innerCircleProportionalSize)
  71001. {
  71002. float hw = width * 0.5f;
  71003. float hh = height * 0.5f;
  71004. const float centreX = x + hw;
  71005. const float centreY = y + hh;
  71006. startNewSubPath (centreX + hw * sinf (fromRadians),
  71007. centreY - hh * cosf (fromRadians));
  71008. addArc (x, y, width, height, fromRadians, toRadians);
  71009. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71010. {
  71011. closeSubPath();
  71012. if (innerCircleProportionalSize > 0)
  71013. {
  71014. hw *= innerCircleProportionalSize;
  71015. hh *= innerCircleProportionalSize;
  71016. startNewSubPath (centreX + hw * sinf (toRadians),
  71017. centreY - hh * cosf (toRadians));
  71018. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71019. toRadians, fromRadians);
  71020. }
  71021. }
  71022. else
  71023. {
  71024. if (innerCircleProportionalSize > 0)
  71025. {
  71026. hw *= innerCircleProportionalSize;
  71027. hh *= innerCircleProportionalSize;
  71028. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71029. toRadians, fromRadians);
  71030. }
  71031. else
  71032. {
  71033. lineTo (centreX, centreY);
  71034. }
  71035. }
  71036. closeSubPath();
  71037. }
  71038. void Path::addLineSegment (const float startX, const float startY,
  71039. const float endX, const float endY,
  71040. float lineThickness)
  71041. {
  71042. lineThickness *= 0.5f;
  71043. float x, y;
  71044. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71045. 0, lineThickness, x, y);
  71046. startNewSubPath (x, y);
  71047. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71048. 0, -lineThickness, x, y);
  71049. lineTo (x, y);
  71050. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71051. 0, lineThickness, x, y);
  71052. lineTo (x, y);
  71053. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71054. 0, -lineThickness, x, y);
  71055. lineTo (x, y);
  71056. closeSubPath();
  71057. }
  71058. void Path::addArrow (const float startX, const float startY,
  71059. const float endX, const float endY,
  71060. float lineThickness,
  71061. float arrowheadWidth,
  71062. float arrowheadLength)
  71063. {
  71064. lineThickness *= 0.5f;
  71065. arrowheadWidth *= 0.5f;
  71066. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71067. startY - endY));
  71068. float x, y;
  71069. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71070. 0, lineThickness, x, y);
  71071. startNewSubPath (x, y);
  71072. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71073. 0, -lineThickness, x, y);
  71074. lineTo (x, y);
  71075. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71076. arrowheadLength, lineThickness, x, y);
  71077. lineTo (x, y);
  71078. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71079. arrowheadLength, arrowheadWidth, x, y);
  71080. lineTo (x, y);
  71081. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71082. 0, 0, x, y);
  71083. lineTo (x, y);
  71084. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71085. arrowheadLength, -arrowheadWidth, x, y);
  71086. lineTo (x, y);
  71087. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71088. arrowheadLength, -lineThickness, x, y);
  71089. lineTo (x, y);
  71090. closeSubPath();
  71091. }
  71092. void Path::addStar (const float centreX,
  71093. const float centreY,
  71094. const int numberOfPoints,
  71095. const float innerRadius,
  71096. const float outerRadius,
  71097. const float startAngle)
  71098. {
  71099. jassert (numberOfPoints > 1); // this would be silly.
  71100. if (numberOfPoints > 1)
  71101. {
  71102. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71103. for (int i = 0; i < numberOfPoints; ++i)
  71104. {
  71105. float angle = startAngle + i * angleBetweenPoints;
  71106. const float x = centreX + outerRadius * sinf (angle);
  71107. const float y = centreY - outerRadius * cosf (angle);
  71108. if (i == 0)
  71109. startNewSubPath (x, y);
  71110. else
  71111. lineTo (x, y);
  71112. angle += angleBetweenPoints * 0.5f;
  71113. lineTo (centreX + innerRadius * sinf (angle),
  71114. centreY - innerRadius * cosf (angle));
  71115. }
  71116. closeSubPath();
  71117. }
  71118. }
  71119. void Path::addBubble (float x, float y,
  71120. float w, float h,
  71121. float cs,
  71122. float tipX,
  71123. float tipY,
  71124. int whichSide,
  71125. float arrowPos,
  71126. float arrowWidth)
  71127. {
  71128. if (w > 1.0f && h > 1.0f)
  71129. {
  71130. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71131. const float cs2 = 2.0f * cs;
  71132. startNewSubPath (x + cs, y);
  71133. if (whichSide == 0)
  71134. {
  71135. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71136. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71137. lineTo (arrowX1, y);
  71138. lineTo (tipX, tipY);
  71139. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71140. }
  71141. lineTo (x + w - cs, y);
  71142. if (cs > 0.0f)
  71143. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71144. if (whichSide == 3)
  71145. {
  71146. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71147. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71148. lineTo (x + w, arrowY1);
  71149. lineTo (tipX, tipY);
  71150. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71151. }
  71152. lineTo (x + w, y + h - cs);
  71153. if (cs > 0.0f)
  71154. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71155. if (whichSide == 2)
  71156. {
  71157. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71158. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71159. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71160. lineTo (tipX, tipY);
  71161. lineTo (arrowX1, y + h);
  71162. }
  71163. lineTo (x + cs, y + h);
  71164. if (cs > 0.0f)
  71165. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71166. if (whichSide == 1)
  71167. {
  71168. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71169. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71170. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71171. lineTo (tipX, tipY);
  71172. lineTo (x, arrowY1);
  71173. }
  71174. lineTo (x, y + cs);
  71175. if (cs > 0.0f)
  71176. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71177. closeSubPath();
  71178. }
  71179. }
  71180. void Path::addPath (const Path& other)
  71181. {
  71182. size_t i = 0;
  71183. while (i < other.numElements)
  71184. {
  71185. const float type = other.data.elements [i++];
  71186. if (type == moveMarker)
  71187. {
  71188. startNewSubPath (other.data.elements [i],
  71189. other.data.elements [i + 1]);
  71190. i += 2;
  71191. }
  71192. else if (type == lineMarker)
  71193. {
  71194. lineTo (other.data.elements [i],
  71195. other.data.elements [i + 1]);
  71196. i += 2;
  71197. }
  71198. else if (type == quadMarker)
  71199. {
  71200. quadraticTo (other.data.elements [i],
  71201. other.data.elements [i + 1],
  71202. other.data.elements [i + 2],
  71203. other.data.elements [i + 3]);
  71204. i += 4;
  71205. }
  71206. else if (type == cubicMarker)
  71207. {
  71208. cubicTo (other.data.elements [i],
  71209. other.data.elements [i + 1],
  71210. other.data.elements [i + 2],
  71211. other.data.elements [i + 3],
  71212. other.data.elements [i + 4],
  71213. other.data.elements [i + 5]);
  71214. i += 6;
  71215. }
  71216. else if (type == closeSubPathMarker)
  71217. {
  71218. closeSubPath();
  71219. }
  71220. else
  71221. {
  71222. // something's gone wrong with the element list!
  71223. jassertfalse
  71224. }
  71225. }
  71226. }
  71227. void Path::addPath (const Path& other,
  71228. const AffineTransform& transformToApply)
  71229. {
  71230. size_t i = 0;
  71231. while (i < other.numElements)
  71232. {
  71233. const float type = other.data.elements [i++];
  71234. if (type == closeSubPathMarker)
  71235. {
  71236. closeSubPath();
  71237. }
  71238. else
  71239. {
  71240. float x = other.data.elements [i++];
  71241. float y = other.data.elements [i++];
  71242. transformToApply.transformPoint (x, y);
  71243. if (type == moveMarker)
  71244. {
  71245. startNewSubPath (x, y);
  71246. }
  71247. else if (type == lineMarker)
  71248. {
  71249. lineTo (x, y);
  71250. }
  71251. else if (type == quadMarker)
  71252. {
  71253. float x2 = other.data.elements [i++];
  71254. float y2 = other.data.elements [i++];
  71255. transformToApply.transformPoint (x2, y2);
  71256. quadraticTo (x, y, x2, y2);
  71257. }
  71258. else if (type == cubicMarker)
  71259. {
  71260. float x2 = other.data.elements [i++];
  71261. float y2 = other.data.elements [i++];
  71262. float x3 = other.data.elements [i++];
  71263. float y3 = other.data.elements [i++];
  71264. transformToApply.transformPoint (x2, y2);
  71265. transformToApply.transformPoint (x3, y3);
  71266. cubicTo (x, y, x2, y2, x3, y3);
  71267. }
  71268. else
  71269. {
  71270. // something's gone wrong with the element list!
  71271. jassertfalse
  71272. }
  71273. }
  71274. }
  71275. }
  71276. void Path::applyTransform (const AffineTransform& transform) throw()
  71277. {
  71278. size_t i = 0;
  71279. pathYMin = pathXMin = 0;
  71280. pathYMax = pathXMax = 0;
  71281. bool setMaxMin = false;
  71282. while (i < numElements)
  71283. {
  71284. const float type = data.elements [i++];
  71285. if (type == moveMarker)
  71286. {
  71287. transform.transformPoint (data.elements [i],
  71288. data.elements [i + 1]);
  71289. if (setMaxMin)
  71290. {
  71291. pathXMin = jmin (pathXMin, data.elements [i]);
  71292. pathXMax = jmax (pathXMax, data.elements [i]);
  71293. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71294. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71295. }
  71296. else
  71297. {
  71298. pathXMin = pathXMax = data.elements [i];
  71299. pathYMin = pathYMax = data.elements [i + 1];
  71300. setMaxMin = true;
  71301. }
  71302. i += 2;
  71303. }
  71304. else if (type == lineMarker)
  71305. {
  71306. transform.transformPoint (data.elements [i],
  71307. data.elements [i + 1]);
  71308. pathXMin = jmin (pathXMin, data.elements [i]);
  71309. pathXMax = jmax (pathXMax, data.elements [i]);
  71310. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71311. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71312. i += 2;
  71313. }
  71314. else if (type == quadMarker)
  71315. {
  71316. transform.transformPoint (data.elements [i],
  71317. data.elements [i + 1]);
  71318. transform.transformPoint (data.elements [i + 2],
  71319. data.elements [i + 3]);
  71320. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71321. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71322. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71323. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71324. i += 4;
  71325. }
  71326. else if (type == cubicMarker)
  71327. {
  71328. transform.transformPoint (data.elements [i],
  71329. data.elements [i + 1]);
  71330. transform.transformPoint (data.elements [i + 2],
  71331. data.elements [i + 3]);
  71332. transform.transformPoint (data.elements [i + 4],
  71333. data.elements [i + 5]);
  71334. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71335. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71336. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71337. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71338. i += 6;
  71339. }
  71340. }
  71341. }
  71342. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71343. const float w, const float h,
  71344. const bool preserveProportions,
  71345. const Justification& justification) const
  71346. {
  71347. Rectangle<float> bounds (getBounds());
  71348. if (preserveProportions)
  71349. {
  71350. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71351. return AffineTransform::identity;
  71352. float newW, newH;
  71353. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71354. if (srcRatio > h / w)
  71355. {
  71356. newW = h / srcRatio;
  71357. newH = h;
  71358. }
  71359. else
  71360. {
  71361. newW = w;
  71362. newH = w * srcRatio;
  71363. }
  71364. float newXCentre = x;
  71365. float newYCentre = y;
  71366. if (justification.testFlags (Justification::left))
  71367. newXCentre += newW * 0.5f;
  71368. else if (justification.testFlags (Justification::right))
  71369. newXCentre += w - newW * 0.5f;
  71370. else
  71371. newXCentre += w * 0.5f;
  71372. if (justification.testFlags (Justification::top))
  71373. newYCentre += newH * 0.5f;
  71374. else if (justification.testFlags (Justification::bottom))
  71375. newYCentre += h - newH * 0.5f;
  71376. else
  71377. newYCentre += h * 0.5f;
  71378. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71379. bounds.getHeight() * -0.5f - bounds.getY())
  71380. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71381. .translated (newXCentre, newYCentre);
  71382. }
  71383. else
  71384. {
  71385. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71386. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71387. .translated (x, y);
  71388. }
  71389. }
  71390. bool Path::contains (const float x, const float y, const float tolerence) const
  71391. {
  71392. if (x <= pathXMin || x >= pathXMax
  71393. || y <= pathYMin || y >= pathYMax)
  71394. return false;
  71395. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71396. int positiveCrossings = 0;
  71397. int negativeCrossings = 0;
  71398. while (i.next())
  71399. {
  71400. if ((i.y1 <= y && i.y2 > y)
  71401. || (i.y2 <= y && i.y1 > y))
  71402. {
  71403. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71404. if (intersectX <= x)
  71405. {
  71406. if (i.y1 < i.y2)
  71407. ++positiveCrossings;
  71408. else
  71409. ++negativeCrossings;
  71410. }
  71411. }
  71412. }
  71413. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71414. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71415. }
  71416. bool Path::intersectsLine (const float x1, const float y1,
  71417. const float x2, const float y2,
  71418. const float tolerence)
  71419. {
  71420. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71421. const Line line1 (x1, y1, x2, y2);
  71422. while (i.next())
  71423. {
  71424. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71425. float ix, iy;
  71426. if (line1.intersects (line2, ix, iy))
  71427. return true;
  71428. }
  71429. return false;
  71430. }
  71431. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71432. {
  71433. if (cornerRadius <= 0.01f)
  71434. return *this;
  71435. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71436. size_t n = 0;
  71437. bool lastWasLine = false, firstWasLine = false;
  71438. Path p;
  71439. while (n < numElements)
  71440. {
  71441. const float type = data.elements [n++];
  71442. if (type == moveMarker)
  71443. {
  71444. indexOfPathStart = p.numElements;
  71445. indexOfPathStartThis = n - 1;
  71446. const float x = data.elements [n++];
  71447. const float y = data.elements [n++];
  71448. p.startNewSubPath (x, y);
  71449. lastWasLine = false;
  71450. firstWasLine = (data.elements [n] == lineMarker);
  71451. }
  71452. else if (type == lineMarker || type == closeSubPathMarker)
  71453. {
  71454. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71455. if (type == lineMarker)
  71456. {
  71457. endX = data.elements [n++];
  71458. endY = data.elements [n++];
  71459. if (n > 8)
  71460. {
  71461. startX = data.elements [n - 8];
  71462. startY = data.elements [n - 7];
  71463. joinX = data.elements [n - 5];
  71464. joinY = data.elements [n - 4];
  71465. }
  71466. }
  71467. else
  71468. {
  71469. endX = data.elements [indexOfPathStartThis + 1];
  71470. endY = data.elements [indexOfPathStartThis + 2];
  71471. if (n > 6)
  71472. {
  71473. startX = data.elements [n - 6];
  71474. startY = data.elements [n - 5];
  71475. joinX = data.elements [n - 3];
  71476. joinY = data.elements [n - 2];
  71477. }
  71478. }
  71479. if (lastWasLine)
  71480. {
  71481. const double len1 = juce_hypot (startX - joinX,
  71482. startY - joinY);
  71483. if (len1 > 0)
  71484. {
  71485. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71486. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71487. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71488. }
  71489. const double len2 = juce_hypot (endX - joinX,
  71490. endY - joinY);
  71491. if (len2 > 0)
  71492. {
  71493. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71494. p.quadraticTo (joinX, joinY,
  71495. (float) (joinX + (endX - joinX) * propNeeded),
  71496. (float) (joinY + (endY - joinY) * propNeeded));
  71497. }
  71498. p.lineTo (endX, endY);
  71499. }
  71500. else if (type == lineMarker)
  71501. {
  71502. p.lineTo (endX, endY);
  71503. lastWasLine = true;
  71504. }
  71505. if (type == closeSubPathMarker)
  71506. {
  71507. if (firstWasLine)
  71508. {
  71509. startX = data.elements [n - 3];
  71510. startY = data.elements [n - 2];
  71511. joinX = endX;
  71512. joinY = endY;
  71513. endX = data.elements [indexOfPathStartThis + 4];
  71514. endY = data.elements [indexOfPathStartThis + 5];
  71515. const double len1 = juce_hypot (startX - joinX,
  71516. startY - joinY);
  71517. if (len1 > 0)
  71518. {
  71519. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71520. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71521. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71522. }
  71523. const double len2 = juce_hypot (endX - joinX,
  71524. endY - joinY);
  71525. if (len2 > 0)
  71526. {
  71527. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71528. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71529. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71530. p.quadraticTo (joinX, joinY, endX, endY);
  71531. p.data.elements [indexOfPathStart + 1] = endX;
  71532. p.data.elements [indexOfPathStart + 2] = endY;
  71533. }
  71534. }
  71535. p.closeSubPath();
  71536. }
  71537. }
  71538. else if (type == quadMarker)
  71539. {
  71540. lastWasLine = false;
  71541. const float x1 = data.elements [n++];
  71542. const float y1 = data.elements [n++];
  71543. const float x2 = data.elements [n++];
  71544. const float y2 = data.elements [n++];
  71545. p.quadraticTo (x1, y1, x2, y2);
  71546. }
  71547. else if (type == cubicMarker)
  71548. {
  71549. lastWasLine = false;
  71550. const float x1 = data.elements [n++];
  71551. const float y1 = data.elements [n++];
  71552. const float x2 = data.elements [n++];
  71553. const float y2 = data.elements [n++];
  71554. const float x3 = data.elements [n++];
  71555. const float y3 = data.elements [n++];
  71556. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71557. }
  71558. }
  71559. return p;
  71560. }
  71561. void Path::loadPathFromStream (InputStream& source)
  71562. {
  71563. while (! source.isExhausted())
  71564. {
  71565. switch (source.readByte())
  71566. {
  71567. case 'm':
  71568. {
  71569. const float x = source.readFloat();
  71570. const float y = source.readFloat();
  71571. startNewSubPath (x, y);
  71572. break;
  71573. }
  71574. case 'l':
  71575. {
  71576. const float x = source.readFloat();
  71577. const float y = source.readFloat();
  71578. lineTo (x, y);
  71579. break;
  71580. }
  71581. case 'q':
  71582. {
  71583. const float x1 = source.readFloat();
  71584. const float y1 = source.readFloat();
  71585. const float x2 = source.readFloat();
  71586. const float y2 = source.readFloat();
  71587. quadraticTo (x1, y1, x2, y2);
  71588. break;
  71589. }
  71590. case 'b':
  71591. {
  71592. const float x1 = source.readFloat();
  71593. const float y1 = source.readFloat();
  71594. const float x2 = source.readFloat();
  71595. const float y2 = source.readFloat();
  71596. const float x3 = source.readFloat();
  71597. const float y3 = source.readFloat();
  71598. cubicTo (x1, y1, x2, y2, x3, y3);
  71599. break;
  71600. }
  71601. case 'c':
  71602. closeSubPath();
  71603. break;
  71604. case 'n':
  71605. useNonZeroWinding = true;
  71606. break;
  71607. case 'z':
  71608. useNonZeroWinding = false;
  71609. break;
  71610. case 'e':
  71611. return; // end of path marker
  71612. default:
  71613. jassertfalse // illegal char in the stream
  71614. break;
  71615. }
  71616. }
  71617. }
  71618. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71619. {
  71620. MemoryInputStream in (data, numberOfBytes, false);
  71621. loadPathFromStream (in);
  71622. }
  71623. void Path::writePathToStream (OutputStream& dest) const
  71624. {
  71625. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71626. size_t i = 0;
  71627. while (i < numElements)
  71628. {
  71629. const float type = data.elements [i++];
  71630. if (type == moveMarker)
  71631. {
  71632. dest.writeByte ('m');
  71633. dest.writeFloat (data.elements [i++]);
  71634. dest.writeFloat (data.elements [i++]);
  71635. }
  71636. else if (type == lineMarker)
  71637. {
  71638. dest.writeByte ('l');
  71639. dest.writeFloat (data.elements [i++]);
  71640. dest.writeFloat (data.elements [i++]);
  71641. }
  71642. else if (type == quadMarker)
  71643. {
  71644. dest.writeByte ('q');
  71645. dest.writeFloat (data.elements [i++]);
  71646. dest.writeFloat (data.elements [i++]);
  71647. dest.writeFloat (data.elements [i++]);
  71648. dest.writeFloat (data.elements [i++]);
  71649. }
  71650. else if (type == cubicMarker)
  71651. {
  71652. dest.writeByte ('b');
  71653. dest.writeFloat (data.elements [i++]);
  71654. dest.writeFloat (data.elements [i++]);
  71655. dest.writeFloat (data.elements [i++]);
  71656. dest.writeFloat (data.elements [i++]);
  71657. dest.writeFloat (data.elements [i++]);
  71658. dest.writeFloat (data.elements [i++]);
  71659. }
  71660. else if (type == closeSubPathMarker)
  71661. {
  71662. dest.writeByte ('c');
  71663. }
  71664. }
  71665. dest.writeByte ('e'); // marks the end-of-path
  71666. }
  71667. const String Path::toString() const
  71668. {
  71669. MemoryOutputStream s (2048, 2048);
  71670. if (! useNonZeroWinding)
  71671. s << 'a';
  71672. size_t i = 0;
  71673. float lastMarker = 0.0f;
  71674. while (i < numElements)
  71675. {
  71676. const float marker = data.elements [i++];
  71677. char markerChar = 0;
  71678. int numCoords = 0;
  71679. if (marker == moveMarker)
  71680. {
  71681. markerChar = 'm';
  71682. numCoords = 2;
  71683. }
  71684. else if (marker == lineMarker)
  71685. {
  71686. markerChar = 'l';
  71687. numCoords = 2;
  71688. }
  71689. else if (marker == quadMarker)
  71690. {
  71691. markerChar = 'q';
  71692. numCoords = 4;
  71693. }
  71694. else if (marker == cubicMarker)
  71695. {
  71696. markerChar = 'c';
  71697. numCoords = 6;
  71698. }
  71699. else
  71700. {
  71701. jassert (marker == closeSubPathMarker);
  71702. markerChar = 'z';
  71703. }
  71704. if (marker != lastMarker)
  71705. {
  71706. if (s.getDataSize() != 0)
  71707. s << ' ';
  71708. s << markerChar;
  71709. lastMarker = marker;
  71710. }
  71711. while (--numCoords >= 0 && i < numElements)
  71712. {
  71713. String coord (data.elements [i++], 3);
  71714. while (coord.endsWithChar ('0') && coord != "0")
  71715. coord = coord.dropLastCharacters (1);
  71716. if (coord.endsWithChar ('.'))
  71717. coord = coord.dropLastCharacters (1);
  71718. if (s.getDataSize() != 0)
  71719. s << ' ';
  71720. s << coord;
  71721. }
  71722. }
  71723. return s.toUTF8();
  71724. }
  71725. void Path::restoreFromString (const String& stringVersion)
  71726. {
  71727. clear();
  71728. setUsingNonZeroWinding (true);
  71729. const juce_wchar* t = stringVersion;
  71730. juce_wchar marker = 'm';
  71731. int numValues = 2;
  71732. float values [6];
  71733. while (*t != 0)
  71734. {
  71735. const String token (PathHelpers::nextToken (t));
  71736. const juce_wchar firstChar = token[0];
  71737. int startNum = 0;
  71738. if (firstChar == 'm' || firstChar == 'l')
  71739. {
  71740. marker = firstChar;
  71741. numValues = 2;
  71742. }
  71743. else if (firstChar == 'q')
  71744. {
  71745. marker = firstChar;
  71746. numValues = 4;
  71747. }
  71748. else if (firstChar == 'c')
  71749. {
  71750. marker = firstChar;
  71751. numValues = 6;
  71752. }
  71753. else if (firstChar == 'z')
  71754. {
  71755. marker = firstChar;
  71756. numValues = 0;
  71757. }
  71758. else if (firstChar == 'a')
  71759. {
  71760. setUsingNonZeroWinding (false);
  71761. continue;
  71762. }
  71763. else
  71764. {
  71765. ++startNum;
  71766. values [0] = token.getFloatValue();
  71767. }
  71768. for (int i = startNum; i < numValues; ++i)
  71769. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71770. switch (marker)
  71771. {
  71772. case 'm':
  71773. startNewSubPath (values[0], values[1]);
  71774. break;
  71775. case 'l':
  71776. lineTo (values[0], values[1]);
  71777. break;
  71778. case 'q':
  71779. quadraticTo (values[0], values[1],
  71780. values[2], values[3]);
  71781. break;
  71782. case 'c':
  71783. cubicTo (values[0], values[1],
  71784. values[2], values[3],
  71785. values[4], values[5]);
  71786. break;
  71787. case 'z':
  71788. closeSubPath();
  71789. break;
  71790. default:
  71791. jassertfalse // illegal string format?
  71792. break;
  71793. }
  71794. }
  71795. }
  71796. Path::Iterator::Iterator (const Path& path_)
  71797. : path (path_),
  71798. index (0)
  71799. {
  71800. }
  71801. Path::Iterator::~Iterator()
  71802. {
  71803. }
  71804. bool Path::Iterator::next()
  71805. {
  71806. const float* const elements = path.data.elements;
  71807. if (index < path.numElements)
  71808. {
  71809. const float type = elements [index++];
  71810. if (type == moveMarker)
  71811. {
  71812. elementType = startNewSubPath;
  71813. x1 = elements [index++];
  71814. y1 = elements [index++];
  71815. }
  71816. else if (type == lineMarker)
  71817. {
  71818. elementType = lineTo;
  71819. x1 = elements [index++];
  71820. y1 = elements [index++];
  71821. }
  71822. else if (type == quadMarker)
  71823. {
  71824. elementType = quadraticTo;
  71825. x1 = elements [index++];
  71826. y1 = elements [index++];
  71827. x2 = elements [index++];
  71828. y2 = elements [index++];
  71829. }
  71830. else if (type == cubicMarker)
  71831. {
  71832. elementType = cubicTo;
  71833. x1 = elements [index++];
  71834. y1 = elements [index++];
  71835. x2 = elements [index++];
  71836. y2 = elements [index++];
  71837. x3 = elements [index++];
  71838. y3 = elements [index++];
  71839. }
  71840. else if (type == closeSubPathMarker)
  71841. {
  71842. elementType = closePath;
  71843. }
  71844. return true;
  71845. }
  71846. return false;
  71847. }
  71848. END_JUCE_NAMESPACE
  71849. /*** End of inlined file: juce_Path.cpp ***/
  71850. /*** Start of inlined file: juce_PathIterator.cpp ***/
  71851. BEGIN_JUCE_NAMESPACE
  71852. #if JUCE_MSVC
  71853. #pragma optimize ("t", on)
  71854. #endif
  71855. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  71856. const AffineTransform& transform_,
  71857. float tolerence_)
  71858. : x2 (0),
  71859. y2 (0),
  71860. closesSubPath (false),
  71861. subPathIndex (-1),
  71862. path (path_),
  71863. transform (transform_),
  71864. points (path_.data.elements),
  71865. tolerence (tolerence_ * tolerence_),
  71866. subPathCloseX (0),
  71867. subPathCloseY (0),
  71868. isIdentityTransform (transform_.isIdentity()),
  71869. stackBase (32),
  71870. index (0),
  71871. stackSize (32)
  71872. {
  71873. stackPos = stackBase;
  71874. }
  71875. PathFlatteningIterator::~PathFlatteningIterator()
  71876. {
  71877. }
  71878. bool PathFlatteningIterator::next()
  71879. {
  71880. x1 = x2;
  71881. y1 = y2;
  71882. float x3 = 0;
  71883. float y3 = 0;
  71884. float x4 = 0;
  71885. float y4 = 0;
  71886. float type;
  71887. for (;;)
  71888. {
  71889. if (stackPos == stackBase)
  71890. {
  71891. if (index >= path.numElements)
  71892. {
  71893. return false;
  71894. }
  71895. else
  71896. {
  71897. type = points [index++];
  71898. if (type != Path::closeSubPathMarker)
  71899. {
  71900. x2 = points [index++];
  71901. y2 = points [index++];
  71902. if (! isIdentityTransform)
  71903. transform.transformPoint (x2, y2);
  71904. if (type == Path::quadMarker)
  71905. {
  71906. x3 = points [index++];
  71907. y3 = points [index++];
  71908. if (! isIdentityTransform)
  71909. transform.transformPoint (x3, y3);
  71910. }
  71911. else if (type == Path::cubicMarker)
  71912. {
  71913. x3 = points [index++];
  71914. y3 = points [index++];
  71915. x4 = points [index++];
  71916. y4 = points [index++];
  71917. if (! isIdentityTransform)
  71918. {
  71919. transform.transformPoint (x3, y3);
  71920. transform.transformPoint (x4, y4);
  71921. }
  71922. }
  71923. }
  71924. }
  71925. }
  71926. else
  71927. {
  71928. type = *--stackPos;
  71929. if (type != Path::closeSubPathMarker)
  71930. {
  71931. x2 = *--stackPos;
  71932. y2 = *--stackPos;
  71933. if (type == Path::quadMarker)
  71934. {
  71935. x3 = *--stackPos;
  71936. y3 = *--stackPos;
  71937. }
  71938. else if (type == Path::cubicMarker)
  71939. {
  71940. x3 = *--stackPos;
  71941. y3 = *--stackPos;
  71942. x4 = *--stackPos;
  71943. y4 = *--stackPos;
  71944. }
  71945. }
  71946. }
  71947. if (type == Path::lineMarker)
  71948. {
  71949. ++subPathIndex;
  71950. closesSubPath = (stackPos == stackBase)
  71951. && (index < path.numElements)
  71952. && (points [index] == Path::closeSubPathMarker)
  71953. && x2 == subPathCloseX
  71954. && y2 == subPathCloseY;
  71955. return true;
  71956. }
  71957. else if (type == Path::quadMarker)
  71958. {
  71959. const size_t offset = (size_t) (stackPos - stackBase);
  71960. if (offset >= stackSize - 10)
  71961. {
  71962. stackSize <<= 1;
  71963. stackBase.realloc (stackSize);
  71964. stackPos = stackBase + offset;
  71965. }
  71966. const float dx1 = x1 - x2;
  71967. const float dy1 = y1 - y2;
  71968. const float dx2 = x2 - x3;
  71969. const float dy2 = y2 - y3;
  71970. const float m1x = (x1 + x2) * 0.5f;
  71971. const float m1y = (y1 + y2) * 0.5f;
  71972. const float m2x = (x2 + x3) * 0.5f;
  71973. const float m2y = (y2 + y3) * 0.5f;
  71974. const float m3x = (m1x + m2x) * 0.5f;
  71975. const float m3y = (m1y + m2y) * 0.5f;
  71976. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  71977. {
  71978. *stackPos++ = y3;
  71979. *stackPos++ = x3;
  71980. *stackPos++ = m2y;
  71981. *stackPos++ = m2x;
  71982. *stackPos++ = Path::quadMarker;
  71983. *stackPos++ = m3y;
  71984. *stackPos++ = m3x;
  71985. *stackPos++ = m1y;
  71986. *stackPos++ = m1x;
  71987. *stackPos++ = Path::quadMarker;
  71988. }
  71989. else
  71990. {
  71991. *stackPos++ = y3;
  71992. *stackPos++ = x3;
  71993. *stackPos++ = Path::lineMarker;
  71994. *stackPos++ = m3y;
  71995. *stackPos++ = m3x;
  71996. *stackPos++ = Path::lineMarker;
  71997. }
  71998. jassert (stackPos < stackBase + stackSize);
  71999. }
  72000. else if (type == Path::cubicMarker)
  72001. {
  72002. const size_t offset = (size_t) (stackPos - stackBase);
  72003. if (offset >= stackSize - 16)
  72004. {
  72005. stackSize <<= 1;
  72006. stackBase.realloc (stackSize);
  72007. stackPos = stackBase + offset;
  72008. }
  72009. const float dx1 = x1 - x2;
  72010. const float dy1 = y1 - y2;
  72011. const float dx2 = x2 - x3;
  72012. const float dy2 = y2 - y3;
  72013. const float dx3 = x3 - x4;
  72014. const float dy3 = y3 - y4;
  72015. const float m1x = (x1 + x2) * 0.5f;
  72016. const float m1y = (y1 + y2) * 0.5f;
  72017. const float m2x = (x3 + x2) * 0.5f;
  72018. const float m2y = (y3 + y2) * 0.5f;
  72019. const float m3x = (x3 + x4) * 0.5f;
  72020. const float m3y = (y3 + y4) * 0.5f;
  72021. const float m4x = (m1x + m2x) * 0.5f;
  72022. const float m4y = (m1y + m2y) * 0.5f;
  72023. const float m5x = (m3x + m2x) * 0.5f;
  72024. const float m5y = (m3y + m2y) * 0.5f;
  72025. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72026. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72027. {
  72028. *stackPos++ = y4;
  72029. *stackPos++ = x4;
  72030. *stackPos++ = m3y;
  72031. *stackPos++ = m3x;
  72032. *stackPos++ = m5y;
  72033. *stackPos++ = m5x;
  72034. *stackPos++ = Path::cubicMarker;
  72035. *stackPos++ = (m4y + m5y) * 0.5f;
  72036. *stackPos++ = (m4x + m5x) * 0.5f;
  72037. *stackPos++ = m4y;
  72038. *stackPos++ = m4x;
  72039. *stackPos++ = m1y;
  72040. *stackPos++ = m1x;
  72041. *stackPos++ = Path::cubicMarker;
  72042. }
  72043. else
  72044. {
  72045. *stackPos++ = y4;
  72046. *stackPos++ = x4;
  72047. *stackPos++ = Path::lineMarker;
  72048. *stackPos++ = m5y;
  72049. *stackPos++ = m5x;
  72050. *stackPos++ = Path::lineMarker;
  72051. *stackPos++ = m4y;
  72052. *stackPos++ = m4x;
  72053. *stackPos++ = Path::lineMarker;
  72054. }
  72055. }
  72056. else if (type == Path::closeSubPathMarker)
  72057. {
  72058. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72059. {
  72060. x1 = x2;
  72061. y1 = y2;
  72062. x2 = subPathCloseX;
  72063. y2 = subPathCloseY;
  72064. closesSubPath = true;
  72065. return true;
  72066. }
  72067. }
  72068. else
  72069. {
  72070. jassert (type == Path::moveMarker);
  72071. subPathIndex = -1;
  72072. subPathCloseX = x1 = x2;
  72073. subPathCloseY = y1 = y2;
  72074. }
  72075. }
  72076. }
  72077. END_JUCE_NAMESPACE
  72078. /*** End of inlined file: juce_PathIterator.cpp ***/
  72079. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72080. BEGIN_JUCE_NAMESPACE
  72081. PathStrokeType::PathStrokeType (const float strokeThickness,
  72082. const JointStyle jointStyle_,
  72083. const EndCapStyle endStyle_) throw()
  72084. : thickness (strokeThickness),
  72085. jointStyle (jointStyle_),
  72086. endStyle (endStyle_)
  72087. {
  72088. }
  72089. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72090. : thickness (other.thickness),
  72091. jointStyle (other.jointStyle),
  72092. endStyle (other.endStyle)
  72093. {
  72094. }
  72095. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72096. {
  72097. thickness = other.thickness;
  72098. jointStyle = other.jointStyle;
  72099. endStyle = other.endStyle;
  72100. return *this;
  72101. }
  72102. PathStrokeType::~PathStrokeType() throw()
  72103. {
  72104. }
  72105. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72106. {
  72107. return thickness == other.thickness
  72108. && jointStyle == other.jointStyle
  72109. && endStyle == other.endStyle;
  72110. }
  72111. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72112. {
  72113. return ! operator== (other);
  72114. }
  72115. static bool lineIntersection (const float x1, const float y1,
  72116. const float x2, const float y2,
  72117. const float x3, const float y3,
  72118. const float x4, const float y4,
  72119. float& intersectionX,
  72120. float& intersectionY,
  72121. float& distanceBeyondLine1EndSquared) throw()
  72122. {
  72123. if (x2 != x3 || y2 != y3)
  72124. {
  72125. const float dx1 = x2 - x1;
  72126. const float dy1 = y2 - y1;
  72127. const float dx2 = x4 - x3;
  72128. const float dy2 = y4 - y3;
  72129. const float divisor = dx1 * dy2 - dx2 * dy1;
  72130. if (divisor == 0)
  72131. {
  72132. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72133. {
  72134. if (dy1 == 0 && dy2 != 0)
  72135. {
  72136. const float along = (y1 - y3) / dy2;
  72137. intersectionX = x3 + along * dx2;
  72138. intersectionY = y1;
  72139. distanceBeyondLine1EndSquared = intersectionX - x2;
  72140. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72141. if ((x2 > x1) == (intersectionX < x2))
  72142. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72143. return along >= 0 && along <= 1.0f;
  72144. }
  72145. else if (dy2 == 0 && dy1 != 0)
  72146. {
  72147. const float along = (y3 - y1) / dy1;
  72148. intersectionX = x1 + along * dx1;
  72149. intersectionY = y3;
  72150. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72151. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72152. if (along < 1.0f)
  72153. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72154. return along >= 0 && along <= 1.0f;
  72155. }
  72156. else if (dx1 == 0 && dx2 != 0)
  72157. {
  72158. const float along = (x1 - x3) / dx2;
  72159. intersectionX = x1;
  72160. intersectionY = y3 + along * dy2;
  72161. distanceBeyondLine1EndSquared = intersectionY - y2;
  72162. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72163. if ((y2 > y1) == (intersectionY < y2))
  72164. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72165. return along >= 0 && along <= 1.0f;
  72166. }
  72167. else if (dx2 == 0 && dx1 != 0)
  72168. {
  72169. const float along = (x3 - x1) / dx1;
  72170. intersectionX = x3;
  72171. intersectionY = y1 + along * dy1;
  72172. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72173. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72174. if (along < 1.0f)
  72175. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72176. return along >= 0 && along <= 1.0f;
  72177. }
  72178. }
  72179. intersectionX = 0.5f * (x2 + x3);
  72180. intersectionY = 0.5f * (y2 + y3);
  72181. distanceBeyondLine1EndSquared = 0.0f;
  72182. return false;
  72183. }
  72184. else
  72185. {
  72186. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72187. intersectionX = x1 + along1 * dx1;
  72188. intersectionY = y1 + along1 * dy1;
  72189. if (along1 >= 0 && along1 <= 1.0f)
  72190. {
  72191. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72192. if (along2 >= 0 && along2 <= divisor)
  72193. {
  72194. distanceBeyondLine1EndSquared = 0.0f;
  72195. return true;
  72196. }
  72197. }
  72198. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72199. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72200. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72201. if (along1 < 1.0f)
  72202. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72203. return false;
  72204. }
  72205. }
  72206. intersectionX = x2;
  72207. intersectionY = y2;
  72208. distanceBeyondLine1EndSquared = 0.0f;
  72209. return true;
  72210. }
  72211. namespace PathFunctions
  72212. {
  72213. // part of stroke drawing stuff
  72214. static void addEdgeAndJoint (Path& destPath,
  72215. const PathStrokeType::JointStyle style,
  72216. const float maxMiterExtensionSquared, const float width,
  72217. const float x1, const float y1,
  72218. const float x2, const float y2,
  72219. const float x3, const float y3,
  72220. const float x4, const float y4,
  72221. const float midX, const float midY)
  72222. {
  72223. if (style == PathStrokeType::beveled
  72224. || (x3 == x4 && y3 == y4)
  72225. || (x1 == x2 && y1 == y2))
  72226. {
  72227. destPath.lineTo (x2, y2);
  72228. destPath.lineTo (x3, y3);
  72229. }
  72230. else
  72231. {
  72232. float jx, jy, distanceBeyondLine1EndSquared;
  72233. // if they intersect, use this point..
  72234. if (lineIntersection (x1, y1, x2, y2,
  72235. x3, y3, x4, y4,
  72236. jx, jy, distanceBeyondLine1EndSquared))
  72237. {
  72238. destPath.lineTo (jx, jy);
  72239. }
  72240. else
  72241. {
  72242. if (style == PathStrokeType::mitered)
  72243. {
  72244. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72245. && distanceBeyondLine1EndSquared > 0.0f)
  72246. {
  72247. destPath.lineTo (jx, jy);
  72248. }
  72249. else
  72250. {
  72251. // the end sticks out too far, so just use a blunt joint
  72252. destPath.lineTo (x2, y2);
  72253. destPath.lineTo (x3, y3);
  72254. }
  72255. }
  72256. else
  72257. {
  72258. // curved joints
  72259. float angle1 = atan2f (x2 - midX, y2 - midY);
  72260. float angle2 = atan2f (x3 - midX, y3 - midY);
  72261. const float angleIncrement = 0.1f;
  72262. destPath.lineTo (x2, y2);
  72263. if (fabs (angle1 - angle2) > angleIncrement)
  72264. {
  72265. if (angle2 > angle1 + float_Pi
  72266. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72267. {
  72268. if (angle2 > angle1)
  72269. angle2 -= float_Pi * 2.0f;
  72270. jassert (angle1 <= angle2 + float_Pi);
  72271. angle1 -= angleIncrement;
  72272. while (angle1 > angle2)
  72273. {
  72274. destPath.lineTo (midX + width * sinf (angle1),
  72275. midY + width * cosf (angle1));
  72276. angle1 -= angleIncrement;
  72277. }
  72278. }
  72279. else
  72280. {
  72281. if (angle1 > angle2)
  72282. angle1 -= float_Pi * 2.0f;
  72283. jassert (angle1 >= angle2 - float_Pi);
  72284. angle1 += angleIncrement;
  72285. while (angle1 < angle2)
  72286. {
  72287. destPath.lineTo (midX + width * sinf (angle1),
  72288. midY + width * cosf (angle1));
  72289. angle1 += angleIncrement;
  72290. }
  72291. }
  72292. }
  72293. destPath.lineTo (x3, y3);
  72294. }
  72295. }
  72296. }
  72297. }
  72298. static void addLineEnd (Path& destPath,
  72299. const PathStrokeType::EndCapStyle style,
  72300. const float x1, const float y1,
  72301. const float x2, const float y2,
  72302. const float width)
  72303. {
  72304. if (style == PathStrokeType::butt)
  72305. {
  72306. destPath.lineTo (x2, y2);
  72307. }
  72308. else
  72309. {
  72310. float offx1, offy1, offx2, offy2;
  72311. float dx = x2 - x1;
  72312. float dy = y2 - y1;
  72313. const float len = juce_hypotf (dx, dy);
  72314. if (len == 0)
  72315. {
  72316. offx1 = offx2 = x1;
  72317. offy1 = offy2 = y1;
  72318. }
  72319. else
  72320. {
  72321. const float offset = width / len;
  72322. dx *= offset;
  72323. dy *= offset;
  72324. offx1 = x1 + dy;
  72325. offy1 = y1 - dx;
  72326. offx2 = x2 + dy;
  72327. offy2 = y2 - dx;
  72328. }
  72329. if (style == PathStrokeType::square)
  72330. {
  72331. // sqaure ends
  72332. destPath.lineTo (offx1, offy1);
  72333. destPath.lineTo (offx2, offy2);
  72334. destPath.lineTo (x2, y2);
  72335. }
  72336. else
  72337. {
  72338. // rounded ends
  72339. const float midx = (offx1 + offx2) * 0.5f;
  72340. const float midy = (offy1 + offy2) * 0.5f;
  72341. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72342. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72343. midx, midy);
  72344. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72345. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72346. x2, y2);
  72347. }
  72348. }
  72349. }
  72350. struct LineSection
  72351. {
  72352. LineSection() {}
  72353. LineSection (int) {}
  72354. float x1, y1, x2, y2; // original line
  72355. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72356. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72357. };
  72358. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72359. const bool isClosed,
  72360. const float width, const float maxMiterExtensionSquared,
  72361. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72362. {
  72363. jassert (subPath.size() > 0);
  72364. const LineSection& firstLine = subPath.getReference (0);
  72365. float lastX1 = firstLine.lx1;
  72366. float lastY1 = firstLine.ly1;
  72367. float lastX2 = firstLine.lx2;
  72368. float lastY2 = firstLine.ly2;
  72369. if (isClosed)
  72370. {
  72371. destPath.startNewSubPath (lastX1, lastY1);
  72372. }
  72373. else
  72374. {
  72375. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72376. addLineEnd (destPath, endStyle,
  72377. firstLine.rx2, firstLine.ry2,
  72378. lastX1, lastY1,
  72379. width);
  72380. }
  72381. int i;
  72382. for (i = 1; i < subPath.size(); ++i)
  72383. {
  72384. const LineSection& l = subPath.getReference (i);
  72385. addEdgeAndJoint (destPath, jointStyle,
  72386. maxMiterExtensionSquared, width,
  72387. lastX1, lastY1, lastX2, lastY2,
  72388. l.lx1, l.ly1, l.lx2, l.ly2,
  72389. l.x1, l.y1);
  72390. lastX1 = l.lx1;
  72391. lastY1 = l.ly1;
  72392. lastX2 = l.lx2;
  72393. lastY2 = l.ly2;
  72394. }
  72395. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72396. if (isClosed)
  72397. {
  72398. const LineSection& l = subPath.getReference (0);
  72399. addEdgeAndJoint (destPath, jointStyle,
  72400. maxMiterExtensionSquared, width,
  72401. lastX1, lastY1, lastX2, lastY2,
  72402. l.lx1, l.ly1, l.lx2, l.ly2,
  72403. l.x1, l.y1);
  72404. destPath.closeSubPath();
  72405. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72406. }
  72407. else
  72408. {
  72409. destPath.lineTo (lastX2, lastY2);
  72410. addLineEnd (destPath, endStyle,
  72411. lastX2, lastY2,
  72412. lastLine.rx1, lastLine.ry1,
  72413. width);
  72414. }
  72415. lastX1 = lastLine.rx1;
  72416. lastY1 = lastLine.ry1;
  72417. lastX2 = lastLine.rx2;
  72418. lastY2 = lastLine.ry2;
  72419. for (i = subPath.size() - 1; --i >= 0;)
  72420. {
  72421. const LineSection& l = subPath.getReference (i);
  72422. addEdgeAndJoint (destPath, jointStyle,
  72423. maxMiterExtensionSquared, width,
  72424. lastX1, lastY1, lastX2, lastY2,
  72425. l.rx1, l.ry1, l.rx2, l.ry2,
  72426. l.x2, l.y2);
  72427. lastX1 = l.rx1;
  72428. lastY1 = l.ry1;
  72429. lastX2 = l.rx2;
  72430. lastY2 = l.ry2;
  72431. }
  72432. if (isClosed)
  72433. {
  72434. addEdgeAndJoint (destPath, jointStyle,
  72435. maxMiterExtensionSquared, width,
  72436. lastX1, lastY1, lastX2, lastY2,
  72437. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72438. lastLine.x2, lastLine.y2);
  72439. }
  72440. else
  72441. {
  72442. // do the last line
  72443. destPath.lineTo (lastX2, lastY2);
  72444. }
  72445. destPath.closeSubPath();
  72446. }
  72447. }
  72448. void PathStrokeType::createStrokedPath (Path& destPath,
  72449. const Path& source,
  72450. const AffineTransform& transform,
  72451. const float extraAccuracy) const
  72452. {
  72453. if (thickness <= 0)
  72454. {
  72455. destPath.clear();
  72456. return;
  72457. }
  72458. const Path* sourcePath = &source;
  72459. Path temp;
  72460. if (sourcePath == &destPath)
  72461. {
  72462. destPath.swapWithPath (temp);
  72463. sourcePath = &temp;
  72464. }
  72465. else
  72466. {
  72467. destPath.clear();
  72468. }
  72469. destPath.setUsingNonZeroWinding (true);
  72470. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72471. const float width = 0.5f * thickness;
  72472. // Iterate the path, creating a list of the
  72473. // left/right-hand lines along either side of it...
  72474. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72475. using namespace PathFunctions;
  72476. Array <LineSection> subPath;
  72477. LineSection l;
  72478. l.x1 = 0;
  72479. l.y1 = 0;
  72480. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72481. while (it.next())
  72482. {
  72483. if (it.subPathIndex == 0)
  72484. {
  72485. if (subPath.size() > 0)
  72486. {
  72487. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72488. subPath.clearQuick();
  72489. }
  72490. l.x1 = it.x1;
  72491. l.y1 = it.y1;
  72492. }
  72493. l.x2 = it.x2;
  72494. l.y2 = it.y2;
  72495. float dx = l.x2 - l.x1;
  72496. float dy = l.y2 - l.y1;
  72497. const float hypotSquared = dx*dx + dy*dy;
  72498. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72499. {
  72500. const float len = sqrtf (hypotSquared);
  72501. if (len == 0)
  72502. {
  72503. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72504. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72505. }
  72506. else
  72507. {
  72508. const float offset = width / len;
  72509. dx *= offset;
  72510. dy *= offset;
  72511. l.rx2 = l.x1 - dy;
  72512. l.ry2 = l.y1 + dx;
  72513. l.lx1 = l.x1 + dy;
  72514. l.ly1 = l.y1 - dx;
  72515. l.lx2 = l.x2 + dy;
  72516. l.ly2 = l.y2 - dx;
  72517. l.rx1 = l.x2 - dy;
  72518. l.ry1 = l.y2 + dx;
  72519. }
  72520. subPath.add (l);
  72521. if (it.closesSubPath)
  72522. {
  72523. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72524. subPath.clearQuick();
  72525. }
  72526. else
  72527. {
  72528. l.x1 = it.x2;
  72529. l.y1 = it.y2;
  72530. }
  72531. }
  72532. }
  72533. if (subPath.size() > 0)
  72534. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72535. }
  72536. void PathStrokeType::createDashedStroke (Path& destPath,
  72537. const Path& sourcePath,
  72538. const float* dashLengths,
  72539. int numDashLengths,
  72540. const AffineTransform& transform,
  72541. const float extraAccuracy) const
  72542. {
  72543. if (thickness <= 0)
  72544. return;
  72545. // this should really be an even number..
  72546. jassert ((numDashLengths & 1) == 0);
  72547. Path newDestPath;
  72548. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72549. bool first = true;
  72550. int dashNum = 0;
  72551. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72552. float dx = 0.0f, dy = 0.0f;
  72553. for (;;)
  72554. {
  72555. const bool isSolid = ((dashNum & 1) == 0);
  72556. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72557. jassert (dashLen > 0); // must be a positive increment!
  72558. if (dashLen <= 0)
  72559. break;
  72560. pos += dashLen;
  72561. while (pos > lineEndPos)
  72562. {
  72563. if (! it.next())
  72564. {
  72565. if (isSolid && ! first)
  72566. newDestPath.lineTo (it.x2, it.y2);
  72567. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72568. return;
  72569. }
  72570. if (isSolid && ! first)
  72571. newDestPath.lineTo (it.x1, it.y1);
  72572. else
  72573. newDestPath.startNewSubPath (it.x1, it.y1);
  72574. dx = it.x2 - it.x1;
  72575. dy = it.y2 - it.y1;
  72576. lineLen = juce_hypotf (dx, dy);
  72577. lineEndPos += lineLen;
  72578. first = it.closesSubPath;
  72579. }
  72580. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72581. if (isSolid)
  72582. newDestPath.lineTo (it.x1 + dx * alpha,
  72583. it.y1 + dy * alpha);
  72584. else
  72585. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72586. it.y1 + dy * alpha);
  72587. }
  72588. }
  72589. END_JUCE_NAMESPACE
  72590. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72591. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72592. BEGIN_JUCE_NAMESPACE
  72593. PositionedRectangle::PositionedRectangle() throw()
  72594. : x (0.0),
  72595. y (0.0),
  72596. w (0.0),
  72597. h (0.0),
  72598. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72599. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72600. wMode (absoluteSize),
  72601. hMode (absoluteSize)
  72602. {
  72603. }
  72604. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72605. : x (other.x),
  72606. y (other.y),
  72607. w (other.w),
  72608. h (other.h),
  72609. xMode (other.xMode),
  72610. yMode (other.yMode),
  72611. wMode (other.wMode),
  72612. hMode (other.hMode)
  72613. {
  72614. }
  72615. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72616. {
  72617. x = other.x;
  72618. y = other.y;
  72619. w = other.w;
  72620. h = other.h;
  72621. xMode = other.xMode;
  72622. yMode = other.yMode;
  72623. wMode = other.wMode;
  72624. hMode = other.hMode;
  72625. return *this;
  72626. }
  72627. PositionedRectangle::~PositionedRectangle() throw()
  72628. {
  72629. }
  72630. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72631. {
  72632. return x == other.x
  72633. && y == other.y
  72634. && w == other.w
  72635. && h == other.h
  72636. && xMode == other.xMode
  72637. && yMode == other.yMode
  72638. && wMode == other.wMode
  72639. && hMode == other.hMode;
  72640. }
  72641. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72642. {
  72643. return ! operator== (other);
  72644. }
  72645. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72646. {
  72647. StringArray tokens;
  72648. tokens.addTokens (stringVersion, false);
  72649. decodePosString (tokens [0], xMode, x);
  72650. decodePosString (tokens [1], yMode, y);
  72651. decodeSizeString (tokens [2], wMode, w);
  72652. decodeSizeString (tokens [3], hMode, h);
  72653. }
  72654. const String PositionedRectangle::toString() const throw()
  72655. {
  72656. String s;
  72657. s.preallocateStorage (12);
  72658. addPosDescription (s, xMode, x);
  72659. s << ' ';
  72660. addPosDescription (s, yMode, y);
  72661. s << ' ';
  72662. addSizeDescription (s, wMode, w);
  72663. s << ' ';
  72664. addSizeDescription (s, hMode, h);
  72665. return s;
  72666. }
  72667. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72668. {
  72669. jassert (! target.isEmpty());
  72670. double x_, y_, w_, h_;
  72671. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72672. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72673. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72674. roundToInt (w_), roundToInt (h_));
  72675. }
  72676. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72677. double& x_, double& y_,
  72678. double& w_, double& h_) const throw()
  72679. {
  72680. jassert (! target.isEmpty());
  72681. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72682. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72683. }
  72684. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72685. {
  72686. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72687. }
  72688. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72689. const Rectangle<int>& target) throw()
  72690. {
  72691. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72692. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72693. }
  72694. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72695. const double newW, const double newH,
  72696. const Rectangle<int>& target) throw()
  72697. {
  72698. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72699. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72700. }
  72701. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72702. {
  72703. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72704. updateFrom (comp.getBounds(), Rectangle<int>());
  72705. else
  72706. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72707. }
  72708. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72709. {
  72710. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72711. }
  72712. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72713. {
  72714. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72715. | absoluteFromParentBottomRight
  72716. | absoluteFromParentCentre
  72717. | proportionOfParentSize));
  72718. }
  72719. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72720. {
  72721. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72722. }
  72723. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72724. {
  72725. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72726. | absoluteFromParentBottomRight
  72727. | absoluteFromParentCentre
  72728. | proportionOfParentSize));
  72729. }
  72730. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72731. {
  72732. return (SizeMode) wMode;
  72733. }
  72734. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72735. {
  72736. return (SizeMode) hMode;
  72737. }
  72738. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72739. const PositionMode xMode_,
  72740. const AnchorPoint yAnchor,
  72741. const PositionMode yMode_,
  72742. const SizeMode widthMode,
  72743. const SizeMode heightMode,
  72744. const Rectangle<int>& target) throw()
  72745. {
  72746. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72747. {
  72748. double tx, tw;
  72749. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72750. xMode = (uint8) (xAnchor | xMode_);
  72751. wMode = (uint8) widthMode;
  72752. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72753. }
  72754. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72755. {
  72756. double ty, th;
  72757. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72758. yMode = (uint8) (yAnchor | yMode_);
  72759. hMode = (uint8) heightMode;
  72760. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72761. }
  72762. }
  72763. bool PositionedRectangle::isPositionAbsolute() const throw()
  72764. {
  72765. return xMode == absoluteFromParentTopLeft
  72766. && yMode == absoluteFromParentTopLeft
  72767. && wMode == absoluteSize
  72768. && hMode == absoluteSize;
  72769. }
  72770. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72771. {
  72772. if ((mode & proportionOfParentSize) != 0)
  72773. {
  72774. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72775. }
  72776. else
  72777. {
  72778. s << (roundToInt (value * 100.0) / 100.0);
  72779. if ((mode & absoluteFromParentBottomRight) != 0)
  72780. s << 'R';
  72781. else if ((mode & absoluteFromParentCentre) != 0)
  72782. s << 'C';
  72783. }
  72784. if ((mode & anchorAtRightOrBottom) != 0)
  72785. s << 'r';
  72786. else if ((mode & anchorAtCentre) != 0)
  72787. s << 'c';
  72788. }
  72789. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72790. {
  72791. if (mode == proportionalSize)
  72792. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72793. else if (mode == parentSizeMinusAbsolute)
  72794. s << (roundToInt (value * 100.0) / 100.0) << 'M';
  72795. else
  72796. s << (roundToInt (value * 100.0) / 100.0);
  72797. }
  72798. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72799. {
  72800. if (s.containsChar ('r'))
  72801. mode = anchorAtRightOrBottom;
  72802. else if (s.containsChar ('c'))
  72803. mode = anchorAtCentre;
  72804. else
  72805. mode = anchorAtLeftOrTop;
  72806. if (s.containsChar ('%'))
  72807. {
  72808. mode |= proportionOfParentSize;
  72809. value = s.removeCharacters ("%rcRC").getDoubleValue() / 100.0;
  72810. }
  72811. else
  72812. {
  72813. if (s.containsChar ('R'))
  72814. mode |= absoluteFromParentBottomRight;
  72815. else if (s.containsChar ('C'))
  72816. mode |= absoluteFromParentCentre;
  72817. else
  72818. mode |= absoluteFromParentTopLeft;
  72819. value = s.removeCharacters ("rcRC").getDoubleValue();
  72820. }
  72821. }
  72822. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  72823. {
  72824. if (s.containsChar ('%'))
  72825. {
  72826. mode = proportionalSize;
  72827. value = s.upToFirstOccurrenceOf ("%", false, false).getDoubleValue() / 100.0;
  72828. }
  72829. else if (s.containsChar ('M'))
  72830. {
  72831. mode = parentSizeMinusAbsolute;
  72832. value = s.getDoubleValue();
  72833. }
  72834. else
  72835. {
  72836. mode = absoluteSize;
  72837. value = s.getDoubleValue();
  72838. }
  72839. }
  72840. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  72841. const double x_, const double w_,
  72842. const uint8 xMode_, const uint8 wMode_,
  72843. const int parentPos,
  72844. const int parentSize) const throw()
  72845. {
  72846. if (wMode_ == proportionalSize)
  72847. wOut = roundToInt (w_ * parentSize);
  72848. else if (wMode_ == parentSizeMinusAbsolute)
  72849. wOut = jmax (0, parentSize - roundToInt (w_));
  72850. else
  72851. wOut = roundToInt (w_);
  72852. if ((xMode_ & proportionOfParentSize) != 0)
  72853. xOut = parentPos + x_ * parentSize;
  72854. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72855. xOut = (parentPos + parentSize) - x_;
  72856. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72857. xOut = x_ + (parentPos + parentSize / 2);
  72858. else
  72859. xOut = x_ + parentPos;
  72860. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72861. xOut -= wOut;
  72862. else if ((xMode_ & anchorAtCentre) != 0)
  72863. xOut -= wOut / 2;
  72864. }
  72865. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  72866. double x_, const double w_,
  72867. const uint8 xMode_, const uint8 wMode_,
  72868. const int parentPos,
  72869. const int parentSize) const throw()
  72870. {
  72871. if (wMode_ == proportionalSize)
  72872. {
  72873. if (parentSize > 0)
  72874. wOut = w_ / parentSize;
  72875. }
  72876. else if (wMode_ == parentSizeMinusAbsolute)
  72877. wOut = parentSize - w_;
  72878. else
  72879. wOut = w_;
  72880. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72881. x_ += w_;
  72882. else if ((xMode_ & anchorAtCentre) != 0)
  72883. x_ += w_ / 2;
  72884. if ((xMode_ & proportionOfParentSize) != 0)
  72885. {
  72886. if (parentSize > 0)
  72887. xOut = (x_ - parentPos) / parentSize;
  72888. }
  72889. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72890. xOut = (parentPos + parentSize) - x_;
  72891. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72892. xOut = x_ - (parentPos + parentSize / 2);
  72893. else
  72894. xOut = x_ - parentPos;
  72895. }
  72896. END_JUCE_NAMESPACE
  72897. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  72898. /*** Start of inlined file: juce_RectangleList.cpp ***/
  72899. BEGIN_JUCE_NAMESPACE
  72900. RectangleList::RectangleList() throw()
  72901. {
  72902. }
  72903. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  72904. {
  72905. if (! rect.isEmpty())
  72906. rects.add (rect);
  72907. }
  72908. RectangleList::RectangleList (const RectangleList& other) throw()
  72909. : rects (other.rects)
  72910. {
  72911. }
  72912. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  72913. {
  72914. rects = other.rects;
  72915. return *this;
  72916. }
  72917. RectangleList::~RectangleList() throw()
  72918. {
  72919. }
  72920. void RectangleList::clear() throw()
  72921. {
  72922. rects.clearQuick();
  72923. }
  72924. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  72925. {
  72926. if (((unsigned int) index) < (unsigned int) rects.size())
  72927. return rects.getReference (index);
  72928. return Rectangle<int>();
  72929. }
  72930. bool RectangleList::isEmpty() const throw()
  72931. {
  72932. return rects.size() == 0;
  72933. }
  72934. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  72935. : current (0),
  72936. owner (list),
  72937. index (list.rects.size())
  72938. {
  72939. }
  72940. RectangleList::Iterator::~Iterator() throw()
  72941. {
  72942. }
  72943. bool RectangleList::Iterator::next() throw()
  72944. {
  72945. if (--index >= 0)
  72946. {
  72947. current = & (owner.rects.getReference (index));
  72948. return true;
  72949. }
  72950. return false;
  72951. }
  72952. void RectangleList::add (const Rectangle<int>& rect) throw()
  72953. {
  72954. if (! rect.isEmpty())
  72955. {
  72956. if (rects.size() == 0)
  72957. {
  72958. rects.add (rect);
  72959. }
  72960. else
  72961. {
  72962. bool anyOverlaps = false;
  72963. int i;
  72964. for (i = rects.size(); --i >= 0;)
  72965. {
  72966. Rectangle<int>& ourRect = rects.getReference (i);
  72967. if (rect.intersects (ourRect))
  72968. {
  72969. if (rect.contains (ourRect))
  72970. rects.remove (i);
  72971. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  72972. anyOverlaps = true;
  72973. }
  72974. }
  72975. if (anyOverlaps && rects.size() > 0)
  72976. {
  72977. RectangleList r (rect);
  72978. for (i = rects.size(); --i >= 0;)
  72979. {
  72980. const Rectangle<int>& ourRect = rects.getReference (i);
  72981. if (rect.intersects (ourRect))
  72982. {
  72983. r.subtract (ourRect);
  72984. if (r.rects.size() == 0)
  72985. return;
  72986. }
  72987. }
  72988. for (i = r.getNumRectangles(); --i >= 0;)
  72989. rects.add (r.rects.getReference (i));
  72990. }
  72991. else
  72992. {
  72993. rects.add (rect);
  72994. }
  72995. }
  72996. }
  72997. }
  72998. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  72999. {
  73000. rects.add (rect);
  73001. }
  73002. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73003. {
  73004. if (rects.size() == 0)
  73005. {
  73006. if (w > 0 && h > 0)
  73007. rects.add (Rectangle<int> (x, y, w, h));
  73008. }
  73009. else
  73010. {
  73011. add (Rectangle<int> (x, y, w, h));
  73012. }
  73013. }
  73014. void RectangleList::add (const RectangleList& other) throw()
  73015. {
  73016. for (int i = 0; i < other.rects.size(); ++i)
  73017. add (other.rects.getReference (i));
  73018. }
  73019. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73020. {
  73021. const int originalNumRects = rects.size();
  73022. if (originalNumRects > 0)
  73023. {
  73024. const int x1 = rect.x;
  73025. const int y1 = rect.y;
  73026. const int x2 = x1 + rect.w;
  73027. const int y2 = y1 + rect.h;
  73028. for (int i = getNumRectangles(); --i >= 0;)
  73029. {
  73030. Rectangle<int>& r = rects.getReference (i);
  73031. const int rx1 = r.x;
  73032. const int ry1 = r.y;
  73033. const int rx2 = rx1 + r.w;
  73034. const int ry2 = ry1 + r.h;
  73035. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73036. {
  73037. if (x1 > rx1 && x1 < rx2)
  73038. {
  73039. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73040. {
  73041. r.w = x1 - rx1;
  73042. }
  73043. else
  73044. {
  73045. r.x = x1;
  73046. r.w = rx2 - x1;
  73047. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73048. i += 2;
  73049. }
  73050. }
  73051. else if (x2 > rx1 && x2 < rx2)
  73052. {
  73053. r.x = x2;
  73054. r.w = rx2 - x2;
  73055. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73056. {
  73057. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73058. i += 2;
  73059. }
  73060. }
  73061. else if (y1 > ry1 && y1 < ry2)
  73062. {
  73063. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73064. {
  73065. r.h = y1 - ry1;
  73066. }
  73067. else
  73068. {
  73069. r.y = y1;
  73070. r.h = ry2 - y1;
  73071. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73072. i += 2;
  73073. }
  73074. }
  73075. else if (y2 > ry1 && y2 < ry2)
  73076. {
  73077. r.y = y2;
  73078. r.h = ry2 - y2;
  73079. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73080. {
  73081. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73082. i += 2;
  73083. }
  73084. }
  73085. else
  73086. {
  73087. rects.remove (i);
  73088. }
  73089. }
  73090. }
  73091. if (rects.size() > originalNumRects + 10)
  73092. consolidate();
  73093. }
  73094. }
  73095. void RectangleList::subtract (const RectangleList& otherList) throw()
  73096. {
  73097. for (int i = otherList.rects.size(); --i >= 0;)
  73098. subtract (otherList.rects.getReference (i));
  73099. }
  73100. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73101. {
  73102. bool notEmpty = false;
  73103. if (rect.isEmpty())
  73104. {
  73105. clear();
  73106. }
  73107. else
  73108. {
  73109. for (int i = rects.size(); --i >= 0;)
  73110. {
  73111. Rectangle<int>& r = rects.getReference (i);
  73112. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73113. rects.remove (i);
  73114. else
  73115. notEmpty = true;
  73116. }
  73117. }
  73118. return notEmpty;
  73119. }
  73120. bool RectangleList::clipTo (const RectangleList& other) throw()
  73121. {
  73122. if (rects.size() == 0)
  73123. return false;
  73124. RectangleList result;
  73125. for (int j = 0; j < rects.size(); ++j)
  73126. {
  73127. const Rectangle<int>& rect = rects.getReference (j);
  73128. for (int i = other.rects.size(); --i >= 0;)
  73129. {
  73130. Rectangle<int> r (other.rects.getReference (i));
  73131. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73132. result.rects.add (r);
  73133. }
  73134. }
  73135. swapWith (result);
  73136. return ! isEmpty();
  73137. }
  73138. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73139. {
  73140. destRegion.clear();
  73141. if (! rect.isEmpty())
  73142. {
  73143. for (int i = rects.size(); --i >= 0;)
  73144. {
  73145. Rectangle<int> r (rects.getReference (i));
  73146. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73147. destRegion.rects.add (r);
  73148. }
  73149. }
  73150. return destRegion.rects.size() > 0;
  73151. }
  73152. void RectangleList::swapWith (RectangleList& otherList) throw()
  73153. {
  73154. rects.swapWithArray (otherList.rects);
  73155. }
  73156. void RectangleList::consolidate() throw()
  73157. {
  73158. int i;
  73159. for (i = 0; i < getNumRectangles() - 1; ++i)
  73160. {
  73161. Rectangle<int>& r = rects.getReference (i);
  73162. const int rx1 = r.x;
  73163. const int ry1 = r.y;
  73164. const int rx2 = rx1 + r.w;
  73165. const int ry2 = ry1 + r.h;
  73166. for (int j = rects.size(); --j > i;)
  73167. {
  73168. Rectangle<int>& r2 = rects.getReference (j);
  73169. const int jrx1 = r2.x;
  73170. const int jry1 = r2.y;
  73171. const int jrx2 = jrx1 + r2.w;
  73172. const int jry2 = jry1 + r2.h;
  73173. // if the vertical edges of any blocks are touching and their horizontals don't
  73174. // line up, split them horizontally..
  73175. if (jrx1 == rx2 || jrx2 == rx1)
  73176. {
  73177. if (jry1 > ry1 && jry1 < ry2)
  73178. {
  73179. r.h = jry1 - ry1;
  73180. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73181. i = -1;
  73182. break;
  73183. }
  73184. if (jry2 > ry1 && jry2 < ry2)
  73185. {
  73186. r.h = jry2 - ry1;
  73187. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73188. i = -1;
  73189. break;
  73190. }
  73191. else if (ry1 > jry1 && ry1 < jry2)
  73192. {
  73193. r2.h = ry1 - jry1;
  73194. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73195. i = -1;
  73196. break;
  73197. }
  73198. else if (ry2 > jry1 && ry2 < jry2)
  73199. {
  73200. r2.h = ry2 - jry1;
  73201. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73202. i = -1;
  73203. break;
  73204. }
  73205. }
  73206. }
  73207. }
  73208. for (i = 0; i < rects.size() - 1; ++i)
  73209. {
  73210. Rectangle<int>& r = rects.getReference (i);
  73211. for (int j = rects.size(); --j > i;)
  73212. {
  73213. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73214. {
  73215. rects.remove (j);
  73216. i = -1;
  73217. break;
  73218. }
  73219. }
  73220. }
  73221. }
  73222. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73223. {
  73224. for (int i = getNumRectangles(); --i >= 0;)
  73225. if (rects.getReference (i).contains (x, y))
  73226. return true;
  73227. return false;
  73228. }
  73229. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73230. {
  73231. if (rects.size() > 1)
  73232. {
  73233. RectangleList r (rectangleToCheck);
  73234. for (int i = rects.size(); --i >= 0;)
  73235. {
  73236. r.subtract (rects.getReference (i));
  73237. if (r.rects.size() == 0)
  73238. return true;
  73239. }
  73240. }
  73241. else if (rects.size() > 0)
  73242. {
  73243. return rects.getReference (0).contains (rectangleToCheck);
  73244. }
  73245. return false;
  73246. }
  73247. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73248. {
  73249. for (int i = rects.size(); --i >= 0;)
  73250. if (rects.getReference (i).intersects (rectangleToCheck))
  73251. return true;
  73252. return false;
  73253. }
  73254. bool RectangleList::intersects (const RectangleList& other) const throw()
  73255. {
  73256. for (int i = rects.size(); --i >= 0;)
  73257. if (other.intersectsRectangle (rects.getReference (i)))
  73258. return true;
  73259. return false;
  73260. }
  73261. const Rectangle<int> RectangleList::getBounds() const throw()
  73262. {
  73263. if (rects.size() <= 1)
  73264. {
  73265. if (rects.size() == 0)
  73266. return Rectangle<int>();
  73267. else
  73268. return rects.getReference (0);
  73269. }
  73270. else
  73271. {
  73272. const Rectangle<int>& r = rects.getReference (0);
  73273. int minX = r.x;
  73274. int minY = r.y;
  73275. int maxX = minX + r.w;
  73276. int maxY = minY + r.h;
  73277. for (int i = rects.size(); --i > 0;)
  73278. {
  73279. const Rectangle<int>& r2 = rects.getReference (i);
  73280. minX = jmin (minX, r2.x);
  73281. minY = jmin (minY, r2.y);
  73282. maxX = jmax (maxX, r2.getRight());
  73283. maxY = jmax (maxY, r2.getBottom());
  73284. }
  73285. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73286. }
  73287. }
  73288. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73289. {
  73290. for (int i = rects.size(); --i >= 0;)
  73291. {
  73292. Rectangle<int>& r = rects.getReference (i);
  73293. r.x += dx;
  73294. r.y += dy;
  73295. }
  73296. }
  73297. const Path RectangleList::toPath() const throw()
  73298. {
  73299. Path p;
  73300. for (int i = rects.size(); --i >= 0;)
  73301. {
  73302. const Rectangle<int>& r = rects.getReference (i);
  73303. p.addRectangle ((float) r.x,
  73304. (float) r.y,
  73305. (float) r.w,
  73306. (float) r.h);
  73307. }
  73308. return p;
  73309. }
  73310. END_JUCE_NAMESPACE
  73311. /*** End of inlined file: juce_RectangleList.cpp ***/
  73312. /*** Start of inlined file: juce_Image.cpp ***/
  73313. BEGIN_JUCE_NAMESPACE
  73314. static const int fullAlphaThreshold = 253;
  73315. Image::Image (const PixelFormat format_,
  73316. const int imageWidth_,
  73317. const int imageHeight_)
  73318. : format (format_),
  73319. imageWidth (imageWidth_),
  73320. imageHeight (imageHeight_),
  73321. imageData (0)
  73322. {
  73323. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73324. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73325. // actual image will be at least 1x1.
  73326. }
  73327. Image::Image (const PixelFormat format_,
  73328. const int imageWidth_,
  73329. const int imageHeight_,
  73330. const bool clearImage)
  73331. : format (format_),
  73332. imageWidth (imageWidth_),
  73333. imageHeight (imageHeight_)
  73334. {
  73335. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73336. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73337. // actual image will be at least 1x1.
  73338. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73339. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73340. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73341. imageData = imageDataAllocated;
  73342. }
  73343. Image::Image (const Image& other)
  73344. : format (other.format),
  73345. imageWidth (other.imageWidth),
  73346. imageHeight (other.imageHeight)
  73347. {
  73348. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73349. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73350. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73351. imageData = imageDataAllocated;
  73352. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73353. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73354. }
  73355. Image::~Image()
  73356. {
  73357. }
  73358. LowLevelGraphicsContext* Image::createLowLevelContext()
  73359. {
  73360. return new LowLevelGraphicsSoftwareRenderer (*this);
  73361. }
  73362. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73363. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73364. lineStride (image.lineStride),
  73365. pixelStride (image.pixelStride),
  73366. width (w),
  73367. height (h)
  73368. {
  73369. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73370. }
  73371. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73372. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73373. lineStride (image.lineStride),
  73374. pixelStride (image.pixelStride),
  73375. width (w),
  73376. height (h)
  73377. {
  73378. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73379. }
  73380. Image::BitmapData::~BitmapData()
  73381. {
  73382. }
  73383. void Image::setPixelData (int x, int y, int w, int h,
  73384. const uint8* sourcePixelData, int sourceLineStride)
  73385. {
  73386. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73387. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73388. {
  73389. const BitmapData dest (*this, x, y, w, h, true);
  73390. for (int i = 0; i < h; ++i)
  73391. {
  73392. memcpy (dest.getLinePointer(i),
  73393. sourcePixelData + sourceLineStride * i,
  73394. w * dest.pixelStride);
  73395. }
  73396. }
  73397. }
  73398. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73399. {
  73400. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73401. {
  73402. const PixelARGB col (colourToClearTo.getPixelARGB());
  73403. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73404. uint8* dest = destData.data;
  73405. while (--dh >= 0)
  73406. {
  73407. uint8* line = dest;
  73408. dest += destData.lineStride;
  73409. if (isARGB())
  73410. {
  73411. for (int x = dw; --x >= 0;)
  73412. {
  73413. ((PixelARGB*) line)->set (col);
  73414. line += destData.pixelStride;
  73415. }
  73416. }
  73417. else if (isRGB())
  73418. {
  73419. for (int x = dw; --x >= 0;)
  73420. {
  73421. ((PixelRGB*) line)->set (col);
  73422. line += destData.pixelStride;
  73423. }
  73424. }
  73425. else
  73426. {
  73427. for (int x = dw; --x >= 0;)
  73428. {
  73429. *line = col.getAlpha();
  73430. line += destData.pixelStride;
  73431. }
  73432. }
  73433. }
  73434. }
  73435. }
  73436. Image* Image::createCopy (int newWidth, int newHeight,
  73437. const Graphics::ResamplingQuality quality) const
  73438. {
  73439. if (newWidth < 0)
  73440. newWidth = imageWidth;
  73441. if (newHeight < 0)
  73442. newHeight = imageHeight;
  73443. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73444. Graphics g (*newImage);
  73445. g.setImageResamplingQuality (quality);
  73446. g.drawImage (this,
  73447. 0, 0, newWidth, newHeight,
  73448. 0, 0, imageWidth, imageHeight,
  73449. false);
  73450. return newImage;
  73451. }
  73452. Image* Image::createCopyOfAlphaChannel() const
  73453. {
  73454. jassert (format != SingleChannel);
  73455. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73456. if (! hasAlphaChannel())
  73457. {
  73458. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73459. }
  73460. else
  73461. {
  73462. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73463. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73464. for (int y = 0; y < imageHeight; ++y)
  73465. {
  73466. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73467. uint8* dst = destData.getLinePointer (y);
  73468. for (int x = imageWidth; --x >= 0;)
  73469. {
  73470. *dst++ = src->getAlpha();
  73471. ++src;
  73472. }
  73473. }
  73474. }
  73475. return newImage;
  73476. }
  73477. const Colour Image::getPixelAt (const int x, const int y) const
  73478. {
  73479. Colour c;
  73480. if (((unsigned int) x) < (unsigned int) imageWidth
  73481. && ((unsigned int) y) < (unsigned int) imageHeight)
  73482. {
  73483. const BitmapData srcData (*this, x, y, 1, 1);
  73484. if (isARGB())
  73485. {
  73486. PixelARGB p (*(const PixelARGB*) srcData.data);
  73487. p.unpremultiply();
  73488. c = Colour (p.getARGB());
  73489. }
  73490. else if (isRGB())
  73491. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73492. else
  73493. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73494. }
  73495. return c;
  73496. }
  73497. void Image::setPixelAt (const int x, const int y,
  73498. const Colour& colour)
  73499. {
  73500. if (((unsigned int) x) < (unsigned int) imageWidth
  73501. && ((unsigned int) y) < (unsigned int) imageHeight)
  73502. {
  73503. const BitmapData destData (*this, x, y, 1, 1, true);
  73504. const PixelARGB col (colour.getPixelARGB());
  73505. if (isARGB())
  73506. ((PixelARGB*) destData.data)->set (col);
  73507. else if (isRGB())
  73508. ((PixelRGB*) destData.data)->set (col);
  73509. else
  73510. *(destData.data) = col.getAlpha();
  73511. }
  73512. }
  73513. void Image::multiplyAlphaAt (const int x, const int y,
  73514. const float multiplier)
  73515. {
  73516. if (((unsigned int) x) < (unsigned int) imageWidth
  73517. && ((unsigned int) y) < (unsigned int) imageHeight
  73518. && hasAlphaChannel())
  73519. {
  73520. const BitmapData destData (*this, x, y, 1, 1, true);
  73521. if (isARGB())
  73522. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73523. else
  73524. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73525. }
  73526. }
  73527. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73528. {
  73529. if (hasAlphaChannel())
  73530. {
  73531. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73532. if (isARGB())
  73533. {
  73534. for (int y = 0; y < imageHeight; ++y)
  73535. {
  73536. uint8* p = destData.getLinePointer (y);
  73537. for (int x = 0; x < imageWidth; ++x)
  73538. {
  73539. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73540. p += destData.pixelStride;
  73541. }
  73542. }
  73543. }
  73544. else
  73545. {
  73546. for (int y = 0; y < imageHeight; ++y)
  73547. {
  73548. uint8* p = destData.getLinePointer (y);
  73549. for (int x = 0; x < imageWidth; ++x)
  73550. {
  73551. *p = (uint8) (*p * amountToMultiplyBy);
  73552. p += destData.pixelStride;
  73553. }
  73554. }
  73555. }
  73556. }
  73557. else
  73558. {
  73559. jassertfalse // can't do this without an alpha-channel!
  73560. }
  73561. }
  73562. void Image::desaturate()
  73563. {
  73564. if (isARGB() || isRGB())
  73565. {
  73566. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73567. if (isARGB())
  73568. {
  73569. for (int y = 0; y < imageHeight; ++y)
  73570. {
  73571. uint8* p = destData.getLinePointer (y);
  73572. for (int x = 0; x < imageWidth; ++x)
  73573. {
  73574. ((PixelARGB*) p)->desaturate();
  73575. p += destData.pixelStride;
  73576. }
  73577. }
  73578. }
  73579. else
  73580. {
  73581. for (int y = 0; y < imageHeight; ++y)
  73582. {
  73583. uint8* p = destData.getLinePointer (y);
  73584. for (int x = 0; x < imageWidth; ++x)
  73585. {
  73586. ((PixelRGB*) p)->desaturate();
  73587. p += destData.pixelStride;
  73588. }
  73589. }
  73590. }
  73591. }
  73592. }
  73593. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73594. {
  73595. if (hasAlphaChannel())
  73596. {
  73597. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73598. SparseSet <int> pixelsOnRow;
  73599. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73600. for (int y = 0; y < imageHeight; ++y)
  73601. {
  73602. pixelsOnRow.clear();
  73603. const uint8* lineData = srcData.getLinePointer (y);
  73604. if (isARGB())
  73605. {
  73606. for (int x = 0; x < imageWidth; ++x)
  73607. {
  73608. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73609. pixelsOnRow.addRange (x, 1);
  73610. lineData += srcData.pixelStride;
  73611. }
  73612. }
  73613. else
  73614. {
  73615. for (int x = 0; x < imageWidth; ++x)
  73616. {
  73617. if (*lineData >= threshold)
  73618. pixelsOnRow.addRange (x, 1);
  73619. lineData += srcData.pixelStride;
  73620. }
  73621. }
  73622. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73623. {
  73624. int x, w;
  73625. if (pixelsOnRow.getRange (i, x, w))
  73626. result.add (Rectangle<int> (x, y, w, 1));
  73627. }
  73628. result.consolidate();
  73629. }
  73630. }
  73631. else
  73632. {
  73633. result.add (0, 0, imageWidth, imageHeight);
  73634. }
  73635. }
  73636. void Image::moveImageSection (int dx, int dy,
  73637. int sx, int sy,
  73638. int w, int h)
  73639. {
  73640. if (dx < 0)
  73641. {
  73642. w += dx;
  73643. sx -= dx;
  73644. dx = 0;
  73645. }
  73646. if (dy < 0)
  73647. {
  73648. h += dy;
  73649. sy -= dy;
  73650. dy = 0;
  73651. }
  73652. if (sx < 0)
  73653. {
  73654. w += sx;
  73655. dx -= sx;
  73656. sx = 0;
  73657. }
  73658. if (sy < 0)
  73659. {
  73660. h += sy;
  73661. dy -= sy;
  73662. sy = 0;
  73663. }
  73664. const int minX = jmin (dx, sx);
  73665. const int minY = jmin (dy, sy);
  73666. w = jmin (w, getWidth() - jmax (sx, dx));
  73667. h = jmin (h, getHeight() - jmax (sy, dy));
  73668. if (w > 0 && h > 0)
  73669. {
  73670. const int maxX = jmax (dx, sx) + w;
  73671. const int maxY = jmax (dy, sy) + h;
  73672. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73673. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73674. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73675. const int lineSize = destData.pixelStride * w;
  73676. if (dy > sy)
  73677. {
  73678. while (--h >= 0)
  73679. {
  73680. const int offset = h * destData.lineStride;
  73681. memmove (dst + offset, src + offset, lineSize);
  73682. }
  73683. }
  73684. else if (dst != src)
  73685. {
  73686. while (--h >= 0)
  73687. {
  73688. memmove (dst, src, lineSize);
  73689. dst += destData.lineStride;
  73690. src += destData.lineStride;
  73691. }
  73692. }
  73693. }
  73694. }
  73695. END_JUCE_NAMESPACE
  73696. /*** End of inlined file: juce_Image.cpp ***/
  73697. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73698. BEGIN_JUCE_NAMESPACE
  73699. struct ImageCache::Item
  73700. {
  73701. ScopedPointer <Image> image;
  73702. int64 hashCode;
  73703. int refCount;
  73704. uint32 releaseTime;
  73705. juce_UseDebuggingNewOperator
  73706. };
  73707. ImageCache* ImageCache::instance = 0;
  73708. int ImageCache::cacheTimeout = 5000;
  73709. ImageCache::ImageCache()
  73710. {
  73711. }
  73712. ImageCache::~ImageCache()
  73713. {
  73714. jassert (instance == this);
  73715. instance = 0;
  73716. }
  73717. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73718. {
  73719. if (instance != 0)
  73720. {
  73721. const ScopedLock sl (instance->lock);
  73722. for (int i = instance->images.size(); --i >= 0;)
  73723. {
  73724. Item* const ci = instance->images.getUnchecked(i);
  73725. if (ci->hashCode == hashCode)
  73726. {
  73727. ci->refCount++;
  73728. return ci->image;
  73729. }
  73730. }
  73731. }
  73732. return 0;
  73733. }
  73734. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73735. {
  73736. if (image != 0)
  73737. {
  73738. if (instance == 0)
  73739. instance = new ImageCache();
  73740. Item* const newC = new Item();
  73741. newC->hashCode = hashCode;
  73742. newC->image = image;
  73743. newC->refCount = 1;
  73744. newC->releaseTime = 0;
  73745. const ScopedLock sl (instance->lock);
  73746. instance->images.add (newC);
  73747. }
  73748. }
  73749. void ImageCache::release (Image* const imageToRelease)
  73750. {
  73751. if (imageToRelease != 0 && instance != 0)
  73752. {
  73753. const ScopedLock sl (instance->lock);
  73754. for (int i = instance->images.size(); --i >= 0;)
  73755. {
  73756. Item* const ci = instance->images.getUnchecked(i);
  73757. if (static_cast <Image*> (ci->image) == imageToRelease)
  73758. {
  73759. if (--(ci->refCount) == 0)
  73760. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73761. if (! instance->isTimerRunning())
  73762. instance->startTimer (999);
  73763. break;
  73764. }
  73765. }
  73766. }
  73767. }
  73768. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73769. {
  73770. if (isImageInCache (imageToRelease))
  73771. release (imageToRelease);
  73772. else
  73773. delete imageToRelease;
  73774. }
  73775. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73776. {
  73777. if (instance != 0)
  73778. {
  73779. const ScopedLock sl (instance->lock);
  73780. for (int i = instance->images.size(); --i >= 0;)
  73781. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73782. return true;
  73783. }
  73784. return false;
  73785. }
  73786. void ImageCache::incReferenceCount (Image* const image)
  73787. {
  73788. if (instance != 0)
  73789. {
  73790. const ScopedLock sl (instance->lock);
  73791. for (int i = instance->images.size(); --i >= 0;)
  73792. {
  73793. Item* const ci = instance->images.getUnchecked(i);
  73794. if (static_cast <Image*> (ci->image) == image)
  73795. {
  73796. ci->refCount++;
  73797. return;
  73798. }
  73799. }
  73800. }
  73801. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73802. }
  73803. void ImageCache::timerCallback()
  73804. {
  73805. int numberStillNeedingReleasing = 0;
  73806. const uint32 now = Time::getApproximateMillisecondCounter();
  73807. const ScopedLock sl (lock);
  73808. for (int i = images.size(); --i >= 0;)
  73809. {
  73810. Item* const ci = images.getUnchecked(i);
  73811. if (ci->refCount <= 0)
  73812. {
  73813. if (now > ci->releaseTime + cacheTimeout
  73814. || now < ci->releaseTime - 1000)
  73815. {
  73816. images.remove (i);
  73817. }
  73818. else
  73819. {
  73820. ++numberStillNeedingReleasing;
  73821. }
  73822. }
  73823. }
  73824. if (numberStillNeedingReleasing == 0)
  73825. stopTimer();
  73826. }
  73827. Image* ImageCache::getFromFile (const File& file)
  73828. {
  73829. const int64 hashCode = file.hashCode64();
  73830. Image* image = getFromHashCode (hashCode);
  73831. if (image == 0)
  73832. {
  73833. image = ImageFileFormat::loadFrom (file);
  73834. addImageToCache (image, hashCode);
  73835. }
  73836. return image;
  73837. }
  73838. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  73839. {
  73840. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  73841. Image* image = getFromHashCode (hashCode);
  73842. if (image == 0)
  73843. {
  73844. image = ImageFileFormat::loadFrom (imageData, dataSize);
  73845. addImageToCache (image, hashCode);
  73846. }
  73847. return image;
  73848. }
  73849. void ImageCache::setCacheTimeout (const int millisecs)
  73850. {
  73851. cacheTimeout = millisecs;
  73852. }
  73853. END_JUCE_NAMESPACE
  73854. /*** End of inlined file: juce_ImageCache.cpp ***/
  73855. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  73856. BEGIN_JUCE_NAMESPACE
  73857. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  73858. : values (size_ * size_),
  73859. size (size_)
  73860. {
  73861. clear();
  73862. }
  73863. ImageConvolutionKernel::~ImageConvolutionKernel()
  73864. {
  73865. }
  73866. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  73867. {
  73868. if (((unsigned int) x) < (unsigned int) size
  73869. && ((unsigned int) y) < (unsigned int) size)
  73870. {
  73871. return values [x + y * size];
  73872. }
  73873. else
  73874. {
  73875. jassertfalse;
  73876. return 0;
  73877. }
  73878. }
  73879. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  73880. {
  73881. if (((unsigned int) x) < (unsigned int) size
  73882. && ((unsigned int) y) < (unsigned int) size)
  73883. {
  73884. values [x + y * size] = value;
  73885. }
  73886. else
  73887. {
  73888. jassertfalse;
  73889. }
  73890. }
  73891. void ImageConvolutionKernel::clear()
  73892. {
  73893. for (int i = size * size; --i >= 0;)
  73894. values[i] = 0;
  73895. }
  73896. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  73897. {
  73898. double currentTotal = 0.0;
  73899. for (int i = size * size; --i >= 0;)
  73900. currentTotal += values[i];
  73901. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  73902. }
  73903. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  73904. {
  73905. for (int i = size * size; --i >= 0;)
  73906. values[i] *= multiplier;
  73907. }
  73908. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  73909. {
  73910. const double radiusFactor = -1.0 / (radius * radius * 2);
  73911. const int centre = size >> 1;
  73912. for (int y = size; --y >= 0;)
  73913. {
  73914. for (int x = size; --x >= 0;)
  73915. {
  73916. const int cx = x - centre;
  73917. const int cy = y - centre;
  73918. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  73919. }
  73920. }
  73921. setOverallSum (1.0f);
  73922. }
  73923. void ImageConvolutionKernel::applyToImage (Image& destImage,
  73924. const Image* sourceImage,
  73925. const Rectangle<int>& destinationArea) const
  73926. {
  73927. ScopedPointer <Image> imageCreated;
  73928. if (sourceImage == 0)
  73929. {
  73930. sourceImage = imageCreated = destImage.createCopy();
  73931. }
  73932. else
  73933. {
  73934. jassert (sourceImage->getWidth() == destImage.getWidth()
  73935. && sourceImage->getHeight() == destImage.getHeight()
  73936. && sourceImage->getFormat() == destImage.getFormat());
  73937. if (sourceImage->getWidth() != destImage.getWidth()
  73938. || sourceImage->getHeight() != destImage.getHeight()
  73939. || sourceImage->getFormat() != destImage.getFormat())
  73940. return;
  73941. }
  73942. const Rectangle<int> area (destinationArea.getIntersection (destImage.getBounds()));
  73943. if (area.isEmpty())
  73944. return;
  73945. const int right = area.getRight();
  73946. const int bottom = area.getBottom();
  73947. const Image::BitmapData destData (destImage, area.getX(), area.getY(), area.getWidth(), area.getHeight(), true);
  73948. uint8* line = destData.data;
  73949. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  73950. if (destData.pixelStride == 4)
  73951. {
  73952. for (int y = area.getY(); y < bottom; ++y)
  73953. {
  73954. uint8* dest = line;
  73955. line += destData.lineStride;
  73956. for (int x = area.getX(); x < right; ++x)
  73957. {
  73958. float c1 = 0;
  73959. float c2 = 0;
  73960. float c3 = 0;
  73961. float c4 = 0;
  73962. for (int yy = 0; yy < size; ++yy)
  73963. {
  73964. const int sy = y + yy - (size >> 1);
  73965. if (sy >= srcData.height)
  73966. break;
  73967. if (sy >= 0)
  73968. {
  73969. int sx = x - (size >> 1);
  73970. const uint8* src = srcData.getPixelPointer (sx, sy);
  73971. for (int xx = 0; xx < size; ++xx)
  73972. {
  73973. if (sx >= srcData.width)
  73974. break;
  73975. if (sx >= 0)
  73976. {
  73977. const float kernelMult = values [xx + yy * size];
  73978. c1 += kernelMult * *src++;
  73979. c2 += kernelMult * *src++;
  73980. c3 += kernelMult * *src++;
  73981. c4 += kernelMult * *src++;
  73982. }
  73983. else
  73984. {
  73985. src += 4;
  73986. }
  73987. ++sx;
  73988. }
  73989. }
  73990. }
  73991. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  73992. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  73993. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  73994. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  73995. }
  73996. }
  73997. }
  73998. else if (destData.pixelStride == 3)
  73999. {
  74000. for (int y = area.getY(); y < bottom; ++y)
  74001. {
  74002. uint8* dest = line;
  74003. line += destData.lineStride;
  74004. for (int x = area.getX(); x < right; ++x)
  74005. {
  74006. float c1 = 0;
  74007. float c2 = 0;
  74008. float c3 = 0;
  74009. for (int yy = 0; yy < size; ++yy)
  74010. {
  74011. const int sy = y + yy - (size >> 1);
  74012. if (sy >= srcData.height)
  74013. break;
  74014. if (sy >= 0)
  74015. {
  74016. int sx = x - (size >> 1);
  74017. const uint8* src = srcData.getPixelPointer (sx, sy);
  74018. for (int xx = 0; xx < size; ++xx)
  74019. {
  74020. if (sx >= srcData.width)
  74021. break;
  74022. if (sx >= 0)
  74023. {
  74024. const float kernelMult = values [xx + yy * size];
  74025. c1 += kernelMult * *src++;
  74026. c2 += kernelMult * *src++;
  74027. c3 += kernelMult * *src++;
  74028. }
  74029. else
  74030. {
  74031. src += 3;
  74032. }
  74033. ++sx;
  74034. }
  74035. }
  74036. }
  74037. *dest++ = (uint8) roundToInt (c1);
  74038. *dest++ = (uint8) roundToInt (c2);
  74039. *dest++ = (uint8) roundToInt (c3);
  74040. }
  74041. }
  74042. }
  74043. }
  74044. END_JUCE_NAMESPACE
  74045. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74046. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74047. BEGIN_JUCE_NAMESPACE
  74048. /*** Start of inlined file: juce_GIFLoader.h ***/
  74049. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74050. #define __JUCE_GIFLOADER_JUCEHEADER__
  74051. #ifndef DOXYGEN
  74052. class GIFLoader
  74053. {
  74054. public:
  74055. GIFLoader (InputStream& in);
  74056. ~GIFLoader();
  74057. Image* getImage() const { return image; }
  74058. private:
  74059. Image* image;
  74060. InputStream& input;
  74061. uint8 buffer [300];
  74062. uint8 palette [256][4];
  74063. bool dataBlockIsZero, fresh, finished;
  74064. int currentBit, lastBit, lastByteIndex;
  74065. int codeSize, setCodeSize;
  74066. int maxCode, maxCodeSize;
  74067. int firstcode, oldcode;
  74068. int clearCode, end_code;
  74069. enum { maxGifCode = 1 << 12 };
  74070. int table [2] [maxGifCode];
  74071. int stack [2 * maxGifCode];
  74072. int *sp;
  74073. bool getSizeFromHeader (int& width, int& height);
  74074. bool readPalette (const int numCols);
  74075. int readDataBlock (unsigned char* dest);
  74076. int processExtension (int type, int& transparent);
  74077. int readLZWByte (bool initialise, int input_code_size);
  74078. int getCode (int code_size, bool initialise);
  74079. bool readImage (int width, int height, int interlace, int transparent);
  74080. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74081. GIFLoader (const GIFLoader&);
  74082. GIFLoader& operator= (const GIFLoader&);
  74083. };
  74084. #endif // DOXYGEN
  74085. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74086. /*** End of inlined file: juce_GIFLoader.h ***/
  74087. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74088. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74089. PNGImageFormat::PNGImageFormat() {}
  74090. PNGImageFormat::~PNGImageFormat() {}
  74091. const String PNGImageFormat::getFormatName()
  74092. {
  74093. return "PNG";
  74094. }
  74095. bool PNGImageFormat::canUnderstand (InputStream& in)
  74096. {
  74097. const int bytesNeeded = 4;
  74098. char header [bytesNeeded];
  74099. return in.read (header, bytesNeeded) == bytesNeeded
  74100. && header[1] == 'P'
  74101. && header[2] == 'N'
  74102. && header[3] == 'G';
  74103. }
  74104. Image* PNGImageFormat::decodeImage (InputStream& in)
  74105. {
  74106. return juce_loadPNGImageFromStream (in);
  74107. }
  74108. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74109. OutputStream& destStream)
  74110. {
  74111. return juce_writePNGImageToStream (sourceImage, destStream);
  74112. }
  74113. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74114. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74115. JPEGImageFormat::JPEGImageFormat()
  74116. : quality (-1.0f)
  74117. {
  74118. }
  74119. JPEGImageFormat::~JPEGImageFormat() {}
  74120. void JPEGImageFormat::setQuality (const float newQuality)
  74121. {
  74122. quality = newQuality;
  74123. }
  74124. const String JPEGImageFormat::getFormatName()
  74125. {
  74126. return "JPEG";
  74127. }
  74128. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74129. {
  74130. const int bytesNeeded = 10;
  74131. uint8 header [bytesNeeded];
  74132. if (in.read (header, bytesNeeded) == bytesNeeded)
  74133. {
  74134. return header[0] == 0xff
  74135. && header[1] == 0xd8
  74136. && header[2] == 0xff
  74137. && (header[3] == 0xe0 || header[3] == 0xe1);
  74138. }
  74139. return false;
  74140. }
  74141. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74142. {
  74143. return juce_loadJPEGImageFromStream (in);
  74144. }
  74145. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74146. OutputStream& destStream)
  74147. {
  74148. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74149. }
  74150. class GIFImageFormat : public ImageFileFormat
  74151. {
  74152. public:
  74153. GIFImageFormat() {}
  74154. ~GIFImageFormat() {}
  74155. const String getFormatName()
  74156. {
  74157. return "GIF";
  74158. }
  74159. bool canUnderstand (InputStream& in)
  74160. {
  74161. const int bytesNeeded = 4;
  74162. char header [bytesNeeded];
  74163. return (in.read (header, bytesNeeded) == bytesNeeded)
  74164. && header[0] == 'G'
  74165. && header[1] == 'I'
  74166. && header[2] == 'F';
  74167. }
  74168. Image* decodeImage (InputStream& in)
  74169. {
  74170. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74171. return loader->getImage();
  74172. }
  74173. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74174. {
  74175. return false;
  74176. }
  74177. };
  74178. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74179. {
  74180. static PNGImageFormat png;
  74181. static JPEGImageFormat jpg;
  74182. static GIFImageFormat gif;
  74183. ImageFileFormat* formats[4];
  74184. int numFormats = 0;
  74185. formats [numFormats++] = &png;
  74186. formats [numFormats++] = &jpg;
  74187. formats [numFormats++] = &gif;
  74188. const int64 streamPos = input.getPosition();
  74189. for (int i = 0; i < numFormats; ++i)
  74190. {
  74191. const bool found = formats[i]->canUnderstand (input);
  74192. input.setPosition (streamPos);
  74193. if (found)
  74194. return formats[i];
  74195. }
  74196. return 0;
  74197. }
  74198. Image* ImageFileFormat::loadFrom (InputStream& input)
  74199. {
  74200. ImageFileFormat* const format = findImageFormatForStream (input);
  74201. if (format != 0)
  74202. return format->decodeImage (input);
  74203. return 0;
  74204. }
  74205. Image* ImageFileFormat::loadFrom (const File& file)
  74206. {
  74207. InputStream* const in = file.createInputStream();
  74208. if (in != 0)
  74209. {
  74210. BufferedInputStream b (in, 8192, true);
  74211. return loadFrom (b);
  74212. }
  74213. return 0;
  74214. }
  74215. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74216. {
  74217. if (rawData != 0 && numBytes > 4)
  74218. {
  74219. MemoryInputStream stream (rawData, numBytes, false);
  74220. return loadFrom (stream);
  74221. }
  74222. return 0;
  74223. }
  74224. END_JUCE_NAMESPACE
  74225. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74226. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74227. BEGIN_JUCE_NAMESPACE
  74228. GIFLoader::GIFLoader (InputStream& in)
  74229. : image (0),
  74230. input (in),
  74231. dataBlockIsZero (false),
  74232. fresh (false),
  74233. finished (false)
  74234. {
  74235. currentBit = lastBit = lastByteIndex = 0;
  74236. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74237. firstcode = oldcode = 0;
  74238. clearCode = end_code = 0;
  74239. int imageWidth, imageHeight;
  74240. int transparent = -1;
  74241. if (! getSizeFromHeader (imageWidth, imageHeight))
  74242. return;
  74243. if ((imageWidth <= 0) || (imageHeight <= 0))
  74244. return;
  74245. unsigned char buf [16];
  74246. if (in.read (buf, 3) != 3)
  74247. return;
  74248. int numColours = 2 << (buf[0] & 7);
  74249. if ((buf[0] & 0x80) != 0)
  74250. readPalette (numColours);
  74251. for (;;)
  74252. {
  74253. if (input.read (buf, 1) != 1)
  74254. break;
  74255. if (buf[0] == ';')
  74256. break;
  74257. if (buf[0] == '!')
  74258. {
  74259. if (input.read (buf, 1) != 1)
  74260. break;
  74261. if (processExtension (buf[0], transparent) < 0)
  74262. break;
  74263. continue;
  74264. }
  74265. if (buf[0] != ',')
  74266. continue;
  74267. if (input.read (buf, 9) != 9)
  74268. break;
  74269. imageWidth = makeWord (buf[4], buf[5]);
  74270. imageHeight = makeWord (buf[6], buf[7]);
  74271. numColours = 2 << (buf[8] & 7);
  74272. if ((buf[8] & 0x80) != 0)
  74273. if (! readPalette (numColours))
  74274. break;
  74275. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74276. imageWidth, imageHeight, (transparent >= 0));
  74277. readImage (imageWidth, imageHeight,
  74278. (buf[8] & 0x40) != 0,
  74279. transparent);
  74280. break;
  74281. }
  74282. }
  74283. GIFLoader::~GIFLoader()
  74284. {
  74285. }
  74286. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74287. {
  74288. char b[8];
  74289. if (input.read (b, 6) == 6)
  74290. {
  74291. if ((strncmp ("GIF87a", b, 6) == 0)
  74292. || (strncmp ("GIF89a", b, 6) == 0))
  74293. {
  74294. if (input.read (b, 4) == 4)
  74295. {
  74296. w = makeWord (b[0], b[1]);
  74297. h = makeWord (b[2], b[3]);
  74298. return true;
  74299. }
  74300. }
  74301. }
  74302. return false;
  74303. }
  74304. bool GIFLoader::readPalette (const int numCols)
  74305. {
  74306. unsigned char rgb[4];
  74307. for (int i = 0; i < numCols; ++i)
  74308. {
  74309. input.read (rgb, 3);
  74310. palette [i][0] = rgb[0];
  74311. palette [i][1] = rgb[1];
  74312. palette [i][2] = rgb[2];
  74313. palette [i][3] = 0xff;
  74314. }
  74315. return true;
  74316. }
  74317. int GIFLoader::readDataBlock (unsigned char* const dest)
  74318. {
  74319. unsigned char n;
  74320. if (input.read (&n, 1) == 1)
  74321. {
  74322. dataBlockIsZero = (n == 0);
  74323. if (dataBlockIsZero || (input.read (dest, n) == n))
  74324. return n;
  74325. }
  74326. return -1;
  74327. }
  74328. int GIFLoader::processExtension (const int type, int& transparent)
  74329. {
  74330. unsigned char b [300];
  74331. int n = 0;
  74332. if (type == 0xf9)
  74333. {
  74334. n = readDataBlock (b);
  74335. if (n < 0)
  74336. return 1;
  74337. if ((b[0] & 0x1) != 0)
  74338. transparent = b[3];
  74339. }
  74340. do
  74341. {
  74342. n = readDataBlock (b);
  74343. }
  74344. while (n > 0);
  74345. return n;
  74346. }
  74347. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74348. {
  74349. if (initialise)
  74350. {
  74351. currentBit = 0;
  74352. lastBit = 0;
  74353. finished = false;
  74354. return 0;
  74355. }
  74356. if ((currentBit + codeSize_) >= lastBit)
  74357. {
  74358. if (finished)
  74359. return -1;
  74360. buffer[0] = buffer [lastByteIndex - 2];
  74361. buffer[1] = buffer [lastByteIndex - 1];
  74362. const int n = readDataBlock (&buffer[2]);
  74363. if (n == 0)
  74364. finished = true;
  74365. lastByteIndex = 2 + n;
  74366. currentBit = (currentBit - lastBit) + 16;
  74367. lastBit = (2 + n) * 8 ;
  74368. }
  74369. int result = 0;
  74370. int i = currentBit;
  74371. for (int j = 0; j < codeSize_; ++j)
  74372. {
  74373. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74374. ++i;
  74375. }
  74376. currentBit += codeSize_;
  74377. return result;
  74378. }
  74379. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74380. {
  74381. int code, incode, i;
  74382. if (initialise)
  74383. {
  74384. setCodeSize = inputCodeSize;
  74385. codeSize = setCodeSize + 1;
  74386. clearCode = 1 << setCodeSize;
  74387. end_code = clearCode + 1;
  74388. maxCodeSize = 2 * clearCode;
  74389. maxCode = clearCode + 2;
  74390. getCode (0, true);
  74391. fresh = true;
  74392. for (i = 0; i < clearCode; ++i)
  74393. {
  74394. table[0][i] = 0;
  74395. table[1][i] = i;
  74396. }
  74397. for (; i < maxGifCode; ++i)
  74398. {
  74399. table[0][i] = 0;
  74400. table[1][i] = 0;
  74401. }
  74402. sp = stack;
  74403. return 0;
  74404. }
  74405. else if (fresh)
  74406. {
  74407. fresh = false;
  74408. do
  74409. {
  74410. firstcode = oldcode
  74411. = getCode (codeSize, false);
  74412. }
  74413. while (firstcode == clearCode);
  74414. return firstcode;
  74415. }
  74416. if (sp > stack)
  74417. return *--sp;
  74418. while ((code = getCode (codeSize, false)) >= 0)
  74419. {
  74420. if (code == clearCode)
  74421. {
  74422. for (i = 0; i < clearCode; ++i)
  74423. {
  74424. table[0][i] = 0;
  74425. table[1][i] = i;
  74426. }
  74427. for (; i < maxGifCode; ++i)
  74428. {
  74429. table[0][i] = 0;
  74430. table[1][i] = 0;
  74431. }
  74432. codeSize = setCodeSize + 1;
  74433. maxCodeSize = 2 * clearCode;
  74434. maxCode = clearCode + 2;
  74435. sp = stack;
  74436. firstcode = oldcode = getCode (codeSize, false);
  74437. return firstcode;
  74438. }
  74439. else if (code == end_code)
  74440. {
  74441. if (dataBlockIsZero)
  74442. return -2;
  74443. unsigned char buf [260];
  74444. int n;
  74445. while ((n = readDataBlock (buf)) > 0)
  74446. {}
  74447. if (n != 0)
  74448. return -2;
  74449. }
  74450. incode = code;
  74451. if (code >= maxCode)
  74452. {
  74453. *sp++ = firstcode;
  74454. code = oldcode;
  74455. }
  74456. while (code >= clearCode)
  74457. {
  74458. *sp++ = table[1][code];
  74459. if (code == table[0][code])
  74460. return -2;
  74461. code = table[0][code];
  74462. }
  74463. *sp++ = firstcode = table[1][code];
  74464. if ((code = maxCode) < maxGifCode)
  74465. {
  74466. table[0][code] = oldcode;
  74467. table[1][code] = firstcode;
  74468. ++maxCode;
  74469. if ((maxCode >= maxCodeSize)
  74470. && (maxCodeSize < maxGifCode))
  74471. {
  74472. maxCodeSize <<= 1;
  74473. ++codeSize;
  74474. }
  74475. }
  74476. oldcode = incode;
  74477. if (sp > stack)
  74478. return *--sp;
  74479. }
  74480. return code;
  74481. }
  74482. bool GIFLoader::readImage (const int width, const int height,
  74483. const int interlace, const int transparent)
  74484. {
  74485. unsigned char c;
  74486. if (input.read (&c, 1) != 1
  74487. || readLZWByte (true, c) < 0)
  74488. return false;
  74489. if (transparent >= 0)
  74490. {
  74491. palette [transparent][0] = 0;
  74492. palette [transparent][1] = 0;
  74493. palette [transparent][2] = 0;
  74494. palette [transparent][3] = 0;
  74495. }
  74496. int index;
  74497. int xpos = 0, ypos = 0, pass = 0;
  74498. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74499. uint8* p = destData.data;
  74500. const bool hasAlpha = image->hasAlphaChannel();
  74501. while ((index = readLZWByte (false, c)) >= 0)
  74502. {
  74503. const uint8* const paletteEntry = palette [index];
  74504. if (hasAlpha)
  74505. {
  74506. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74507. paletteEntry[0],
  74508. paletteEntry[1],
  74509. paletteEntry[2]);
  74510. ((PixelARGB*) p)->premultiply();
  74511. }
  74512. else
  74513. {
  74514. ((PixelRGB*) p)->setARGB (0,
  74515. paletteEntry[0],
  74516. paletteEntry[1],
  74517. paletteEntry[2]);
  74518. }
  74519. p += destData.pixelStride;
  74520. ++xpos;
  74521. if (xpos == width)
  74522. {
  74523. xpos = 0;
  74524. if (interlace)
  74525. {
  74526. switch (pass)
  74527. {
  74528. case 0:
  74529. case 1:
  74530. ypos += 8;
  74531. break;
  74532. case 2:
  74533. ypos += 4;
  74534. break;
  74535. case 3:
  74536. ypos += 2;
  74537. break;
  74538. }
  74539. while (ypos >= height)
  74540. {
  74541. ++pass;
  74542. switch (pass)
  74543. {
  74544. case 1:
  74545. ypos = 4;
  74546. break;
  74547. case 2:
  74548. ypos = 2;
  74549. break;
  74550. case 3:
  74551. ypos = 1;
  74552. break;
  74553. default:
  74554. return true;
  74555. }
  74556. }
  74557. }
  74558. else
  74559. {
  74560. ++ypos;
  74561. }
  74562. p = destData.getPixelPointer (xpos, ypos);
  74563. }
  74564. if (ypos >= height)
  74565. break;
  74566. }
  74567. return true;
  74568. }
  74569. END_JUCE_NAMESPACE
  74570. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74571. #endif
  74572. //==============================================================================
  74573. // some files include lots of library code, so leave them to the end to avoid cluttering
  74574. // up the build for the clean files.
  74575. #if JUCE_BUILD_CORE
  74576. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74577. namespace zlibNamespace
  74578. {
  74579. #if JUCE_INCLUDE_ZLIB_CODE
  74580. #undef OS_CODE
  74581. #undef fdopen
  74582. /*** Start of inlined file: zlib.h ***/
  74583. #ifndef ZLIB_H
  74584. #define ZLIB_H
  74585. /*** Start of inlined file: zconf.h ***/
  74586. #ifndef ZCONF_H
  74587. #define ZCONF_H
  74588. // *** Just a few hacks here to make it compile nicely with Juce..
  74589. #define Z_PREFIX 1
  74590. #undef __MACTYPES__
  74591. #ifdef _MSC_VER
  74592. #pragma warning (disable : 4131 4127 4244 4267)
  74593. #endif
  74594. #ifdef Z_PREFIX
  74595. # define deflateInit_ z_deflateInit_
  74596. # define deflate z_deflate
  74597. # define deflateEnd z_deflateEnd
  74598. # define inflateInit_ z_inflateInit_
  74599. # define inflate z_inflate
  74600. # define inflateEnd z_inflateEnd
  74601. # define inflatePrime z_inflatePrime
  74602. # define inflateGetHeader z_inflateGetHeader
  74603. # define adler32_combine z_adler32_combine
  74604. # define crc32_combine z_crc32_combine
  74605. # define deflateInit2_ z_deflateInit2_
  74606. # define deflateSetDictionary z_deflateSetDictionary
  74607. # define deflateCopy z_deflateCopy
  74608. # define deflateReset z_deflateReset
  74609. # define deflateParams z_deflateParams
  74610. # define deflateBound z_deflateBound
  74611. # define deflatePrime z_deflatePrime
  74612. # define inflateInit2_ z_inflateInit2_
  74613. # define inflateSetDictionary z_inflateSetDictionary
  74614. # define inflateSync z_inflateSync
  74615. # define inflateSyncPoint z_inflateSyncPoint
  74616. # define inflateCopy z_inflateCopy
  74617. # define inflateReset z_inflateReset
  74618. # define inflateBack z_inflateBack
  74619. # define inflateBackEnd z_inflateBackEnd
  74620. # define compress z_compress
  74621. # define compress2 z_compress2
  74622. # define compressBound z_compressBound
  74623. # define uncompress z_uncompress
  74624. # define adler32 z_adler32
  74625. # define crc32 z_crc32
  74626. # define get_crc_table z_get_crc_table
  74627. # define zError z_zError
  74628. # define alloc_func z_alloc_func
  74629. # define free_func z_free_func
  74630. # define in_func z_in_func
  74631. # define out_func z_out_func
  74632. # define Byte z_Byte
  74633. # define uInt z_uInt
  74634. # define uLong z_uLong
  74635. # define Bytef z_Bytef
  74636. # define charf z_charf
  74637. # define intf z_intf
  74638. # define uIntf z_uIntf
  74639. # define uLongf z_uLongf
  74640. # define voidpf z_voidpf
  74641. # define voidp z_voidp
  74642. #endif
  74643. #if defined(__MSDOS__) && !defined(MSDOS)
  74644. # define MSDOS
  74645. #endif
  74646. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74647. # define OS2
  74648. #endif
  74649. #if defined(_WINDOWS) && !defined(WINDOWS)
  74650. # define WINDOWS
  74651. #endif
  74652. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74653. # ifndef WIN32
  74654. # define WIN32
  74655. # endif
  74656. #endif
  74657. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74658. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74659. # ifndef SYS16BIT
  74660. # define SYS16BIT
  74661. # endif
  74662. # endif
  74663. #endif
  74664. #ifdef SYS16BIT
  74665. # define MAXSEG_64K
  74666. #endif
  74667. #ifdef MSDOS
  74668. # define UNALIGNED_OK
  74669. #endif
  74670. #ifdef __STDC_VERSION__
  74671. # ifndef STDC
  74672. # define STDC
  74673. # endif
  74674. # if __STDC_VERSION__ >= 199901L
  74675. # ifndef STDC99
  74676. # define STDC99
  74677. # endif
  74678. # endif
  74679. #endif
  74680. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74681. # define STDC
  74682. #endif
  74683. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74684. # define STDC
  74685. #endif
  74686. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74687. # define STDC
  74688. #endif
  74689. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74690. # define STDC
  74691. #endif
  74692. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74693. # define STDC
  74694. #endif
  74695. #ifndef STDC
  74696. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74697. # define const /* note: need a more gentle solution here */
  74698. # endif
  74699. #endif
  74700. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74701. # define NO_DUMMY_DECL
  74702. #endif
  74703. #ifndef MAX_MEM_LEVEL
  74704. # ifdef MAXSEG_64K
  74705. # define MAX_MEM_LEVEL 8
  74706. # else
  74707. # define MAX_MEM_LEVEL 9
  74708. # endif
  74709. #endif
  74710. #ifndef MAX_WBITS
  74711. # define MAX_WBITS 15 /* 32K LZ77 window */
  74712. #endif
  74713. #ifndef OF /* function prototypes */
  74714. # ifdef STDC
  74715. # define OF(args) args
  74716. # else
  74717. # define OF(args) ()
  74718. # endif
  74719. #endif
  74720. #ifdef SYS16BIT
  74721. # if defined(M_I86SM) || defined(M_I86MM)
  74722. # define SMALL_MEDIUM
  74723. # ifdef _MSC_VER
  74724. # define FAR _far
  74725. # else
  74726. # define FAR far
  74727. # endif
  74728. # endif
  74729. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74730. # define SMALL_MEDIUM
  74731. # ifdef __BORLANDC__
  74732. # define FAR _far
  74733. # else
  74734. # define FAR far
  74735. # endif
  74736. # endif
  74737. #endif
  74738. #if defined(WINDOWS) || defined(WIN32)
  74739. # ifdef ZLIB_DLL
  74740. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74741. # ifdef ZLIB_INTERNAL
  74742. # define ZEXTERN extern __declspec(dllexport)
  74743. # else
  74744. # define ZEXTERN extern __declspec(dllimport)
  74745. # endif
  74746. # endif
  74747. # endif /* ZLIB_DLL */
  74748. # ifdef ZLIB_WINAPI
  74749. # ifdef FAR
  74750. # undef FAR
  74751. # endif
  74752. # include <windows.h>
  74753. # define ZEXPORT WINAPI
  74754. # ifdef WIN32
  74755. # define ZEXPORTVA WINAPIV
  74756. # else
  74757. # define ZEXPORTVA FAR CDECL
  74758. # endif
  74759. # endif
  74760. #endif
  74761. #if defined (__BEOS__)
  74762. # ifdef ZLIB_DLL
  74763. # ifdef ZLIB_INTERNAL
  74764. # define ZEXPORT __declspec(dllexport)
  74765. # define ZEXPORTVA __declspec(dllexport)
  74766. # else
  74767. # define ZEXPORT __declspec(dllimport)
  74768. # define ZEXPORTVA __declspec(dllimport)
  74769. # endif
  74770. # endif
  74771. #endif
  74772. #ifndef ZEXTERN
  74773. # define ZEXTERN extern
  74774. #endif
  74775. #ifndef ZEXPORT
  74776. # define ZEXPORT
  74777. #endif
  74778. #ifndef ZEXPORTVA
  74779. # define ZEXPORTVA
  74780. #endif
  74781. #ifndef FAR
  74782. # define FAR
  74783. #endif
  74784. #if !defined(__MACTYPES__)
  74785. typedef unsigned char Byte; /* 8 bits */
  74786. #endif
  74787. typedef unsigned int uInt; /* 16 bits or more */
  74788. typedef unsigned long uLong; /* 32 bits or more */
  74789. #ifdef SMALL_MEDIUM
  74790. # define Bytef Byte FAR
  74791. #else
  74792. typedef Byte FAR Bytef;
  74793. #endif
  74794. typedef char FAR charf;
  74795. typedef int FAR intf;
  74796. typedef uInt FAR uIntf;
  74797. typedef uLong FAR uLongf;
  74798. #ifdef STDC
  74799. typedef void const *voidpc;
  74800. typedef void FAR *voidpf;
  74801. typedef void *voidp;
  74802. #else
  74803. typedef Byte const *voidpc;
  74804. typedef Byte FAR *voidpf;
  74805. typedef Byte *voidp;
  74806. #endif
  74807. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74808. # include <sys/types.h> /* for off_t */
  74809. # include <unistd.h> /* for SEEK_* and off_t */
  74810. # ifdef VMS
  74811. # include <unixio.h> /* for off_t */
  74812. # endif
  74813. # define z_off_t off_t
  74814. #endif
  74815. #ifndef SEEK_SET
  74816. # define SEEK_SET 0 /* Seek from beginning of file. */
  74817. # define SEEK_CUR 1 /* Seek from current position. */
  74818. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  74819. #endif
  74820. #ifndef z_off_t
  74821. # define z_off_t long
  74822. #endif
  74823. #if defined(__OS400__)
  74824. # define NO_vsnprintf
  74825. #endif
  74826. #if defined(__MVS__)
  74827. # define NO_vsnprintf
  74828. # ifdef FAR
  74829. # undef FAR
  74830. # endif
  74831. #endif
  74832. #if defined(__MVS__)
  74833. # pragma map(deflateInit_,"DEIN")
  74834. # pragma map(deflateInit2_,"DEIN2")
  74835. # pragma map(deflateEnd,"DEEND")
  74836. # pragma map(deflateBound,"DEBND")
  74837. # pragma map(inflateInit_,"ININ")
  74838. # pragma map(inflateInit2_,"ININ2")
  74839. # pragma map(inflateEnd,"INEND")
  74840. # pragma map(inflateSync,"INSY")
  74841. # pragma map(inflateSetDictionary,"INSEDI")
  74842. # pragma map(compressBound,"CMBND")
  74843. # pragma map(inflate_table,"INTABL")
  74844. # pragma map(inflate_fast,"INFA")
  74845. # pragma map(inflate_copyright,"INCOPY")
  74846. #endif
  74847. #endif /* ZCONF_H */
  74848. /*** End of inlined file: zconf.h ***/
  74849. #ifdef __cplusplus
  74850. extern "C" {
  74851. #endif
  74852. #define ZLIB_VERSION "1.2.3"
  74853. #define ZLIB_VERNUM 0x1230
  74854. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  74855. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  74856. struct internal_state;
  74857. typedef struct z_stream_s {
  74858. Bytef *next_in; /* next input byte */
  74859. uInt avail_in; /* number of bytes available at next_in */
  74860. uLong total_in; /* total nb of input bytes read so far */
  74861. Bytef *next_out; /* next output byte should be put there */
  74862. uInt avail_out; /* remaining free space at next_out */
  74863. uLong total_out; /* total nb of bytes output so far */
  74864. char *msg; /* last error message, NULL if no error */
  74865. struct internal_state FAR *state; /* not visible by applications */
  74866. alloc_func zalloc; /* used to allocate the internal state */
  74867. free_func zfree; /* used to free the internal state */
  74868. voidpf opaque; /* private data object passed to zalloc and zfree */
  74869. int data_type; /* best guess about the data type: binary or text */
  74870. uLong adler; /* adler32 value of the uncompressed data */
  74871. uLong reserved; /* reserved for future use */
  74872. } z_stream;
  74873. typedef z_stream FAR *z_streamp;
  74874. typedef struct gz_header_s {
  74875. int text; /* true if compressed data believed to be text */
  74876. uLong time; /* modification time */
  74877. int xflags; /* extra flags (not used when writing a gzip file) */
  74878. int os; /* operating system */
  74879. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  74880. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  74881. uInt extra_max; /* space at extra (only when reading header) */
  74882. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  74883. uInt name_max; /* space at name (only when reading header) */
  74884. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  74885. uInt comm_max; /* space at comment (only when reading header) */
  74886. int hcrc; /* true if there was or will be a header crc */
  74887. int done; /* true when done reading gzip header (not used
  74888. when writing a gzip file) */
  74889. } gz_header;
  74890. typedef gz_header FAR *gz_headerp;
  74891. #define Z_NO_FLUSH 0
  74892. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  74893. #define Z_SYNC_FLUSH 2
  74894. #define Z_FULL_FLUSH 3
  74895. #define Z_FINISH 4
  74896. #define Z_BLOCK 5
  74897. #define Z_OK 0
  74898. #define Z_STREAM_END 1
  74899. #define Z_NEED_DICT 2
  74900. #define Z_ERRNO (-1)
  74901. #define Z_STREAM_ERROR (-2)
  74902. #define Z_DATA_ERROR (-3)
  74903. #define Z_MEM_ERROR (-4)
  74904. #define Z_BUF_ERROR (-5)
  74905. #define Z_VERSION_ERROR (-6)
  74906. #define Z_NO_COMPRESSION 0
  74907. #define Z_BEST_SPEED 1
  74908. #define Z_BEST_COMPRESSION 9
  74909. #define Z_DEFAULT_COMPRESSION (-1)
  74910. #define Z_FILTERED 1
  74911. #define Z_HUFFMAN_ONLY 2
  74912. #define Z_RLE 3
  74913. #define Z_FIXED 4
  74914. #define Z_DEFAULT_STRATEGY 0
  74915. #define Z_BINARY 0
  74916. #define Z_TEXT 1
  74917. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  74918. #define Z_UNKNOWN 2
  74919. #define Z_DEFLATED 8
  74920. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  74921. #define zlib_version zlibVersion()
  74922. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  74923. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  74924. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  74925. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  74926. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  74927. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  74928. const Bytef *dictionary,
  74929. uInt dictLength));
  74930. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  74931. z_streamp source));
  74932. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  74933. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  74934. int level,
  74935. int strategy));
  74936. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  74937. int good_length,
  74938. int max_lazy,
  74939. int nice_length,
  74940. int max_chain));
  74941. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  74942. uLong sourceLen));
  74943. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  74944. int bits,
  74945. int value));
  74946. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  74947. gz_headerp head));
  74948. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  74949. const Bytef *dictionary,
  74950. uInt dictLength));
  74951. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  74952. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  74953. z_streamp source));
  74954. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  74955. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  74956. int bits,
  74957. int value));
  74958. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  74959. gz_headerp head));
  74960. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  74961. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  74962. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  74963. in_func in, void FAR *in_desc,
  74964. out_func out, void FAR *out_desc));
  74965. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  74966. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  74967. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  74968. const Bytef *source, uLong sourceLen));
  74969. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  74970. const Bytef *source, uLong sourceLen,
  74971. int level));
  74972. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  74973. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  74974. const Bytef *source, uLong sourceLen));
  74975. typedef voidp gzFile;
  74976. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  74977. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  74978. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  74979. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  74980. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  74981. voidpc buf, unsigned len));
  74982. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  74983. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  74984. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  74985. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  74986. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  74987. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  74988. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  74989. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  74990. z_off_t offset, int whence));
  74991. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  74992. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  74993. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  74994. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  74995. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  74996. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  74997. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  74998. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  74999. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75000. z_off_t len2));
  75001. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75002. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75003. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75004. const char *version, int stream_size));
  75005. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75006. const char *version, int stream_size));
  75007. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75008. int windowBits, int memLevel,
  75009. int strategy, const char *version,
  75010. int stream_size));
  75011. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75012. const char *version, int stream_size));
  75013. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75014. unsigned char FAR *window,
  75015. const char *version,
  75016. int stream_size));
  75017. #define deflateInit(strm, level) \
  75018. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75019. #define inflateInit(strm) \
  75020. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75021. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75022. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75023. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75024. #define inflateInit2(strm, windowBits) \
  75025. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75026. #define inflateBackInit(strm, windowBits, window) \
  75027. inflateBackInit_((strm), (windowBits), (window), \
  75028. ZLIB_VERSION, sizeof(z_stream))
  75029. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75030. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75031. #endif
  75032. ZEXTERN const char * ZEXPORT zError OF((int));
  75033. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75034. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75035. #ifdef __cplusplus
  75036. }
  75037. #endif
  75038. #endif /* ZLIB_H */
  75039. /*** End of inlined file: zlib.h ***/
  75040. #undef OS_CODE
  75041. #else
  75042. #include <zlib.h>
  75043. #endif
  75044. }
  75045. BEGIN_JUCE_NAMESPACE
  75046. // internal helper object that holds the zlib structures so they don't have to be
  75047. // included publicly.
  75048. class GZIPCompressorHelper
  75049. {
  75050. public:
  75051. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75052. : data (0),
  75053. dataSize (0),
  75054. compLevel (compressionLevel),
  75055. strategy (0),
  75056. setParams (true),
  75057. streamIsValid (false),
  75058. finished (false),
  75059. shouldFinish (false)
  75060. {
  75061. using namespace zlibNamespace;
  75062. zerostruct (stream);
  75063. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75064. nowrap ? -MAX_WBITS : MAX_WBITS,
  75065. 8, strategy) == Z_OK);
  75066. }
  75067. ~GZIPCompressorHelper()
  75068. {
  75069. using namespace zlibNamespace;
  75070. if (streamIsValid)
  75071. deflateEnd (&stream);
  75072. }
  75073. bool needsInput() const throw()
  75074. {
  75075. return dataSize <= 0;
  75076. }
  75077. void setInput (const uint8* const newData, const int size) throw()
  75078. {
  75079. data = newData;
  75080. dataSize = size;
  75081. }
  75082. int doNextBlock (uint8* const dest, const int destSize) throw()
  75083. {
  75084. using namespace zlibNamespace;
  75085. if (streamIsValid)
  75086. {
  75087. stream.next_in = const_cast <uint8*> (data);
  75088. stream.next_out = dest;
  75089. stream.avail_in = dataSize;
  75090. stream.avail_out = destSize;
  75091. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75092. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75093. setParams = false;
  75094. switch (result)
  75095. {
  75096. case Z_STREAM_END:
  75097. finished = true;
  75098. // Deliberate fall-through..
  75099. case Z_OK:
  75100. data += dataSize - stream.avail_in;
  75101. dataSize = stream.avail_in;
  75102. return destSize - stream.avail_out;
  75103. default:
  75104. break;
  75105. }
  75106. }
  75107. return 0;
  75108. }
  75109. private:
  75110. zlibNamespace::z_stream stream;
  75111. const uint8* data;
  75112. int dataSize, compLevel, strategy;
  75113. bool setParams, streamIsValid;
  75114. public:
  75115. bool finished, shouldFinish;
  75116. };
  75117. const int gzipCompBufferSize = 32768;
  75118. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75119. int compressionLevel,
  75120. const bool deleteDestStream,
  75121. const bool noWrap)
  75122. : destStream (destStream_),
  75123. streamToDelete (deleteDestStream ? destStream_ : 0),
  75124. buffer (gzipCompBufferSize)
  75125. {
  75126. if (compressionLevel < 1 || compressionLevel > 9)
  75127. compressionLevel = -1;
  75128. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75129. }
  75130. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75131. {
  75132. flush();
  75133. }
  75134. void GZIPCompressorOutputStream::flush()
  75135. {
  75136. if (! helper->finished)
  75137. {
  75138. helper->shouldFinish = true;
  75139. while (! helper->finished)
  75140. doNextBlock();
  75141. }
  75142. destStream->flush();
  75143. }
  75144. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75145. {
  75146. if (! helper->finished)
  75147. {
  75148. helper->setInput (static_cast <const uint8*> (destBuffer), howMany);
  75149. while (! helper->needsInput())
  75150. {
  75151. if (! doNextBlock())
  75152. return false;
  75153. }
  75154. }
  75155. return true;
  75156. }
  75157. bool GZIPCompressorOutputStream::doNextBlock()
  75158. {
  75159. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75160. if (len > 0)
  75161. return destStream->write (buffer, len);
  75162. else
  75163. return true;
  75164. }
  75165. int64 GZIPCompressorOutputStream::getPosition()
  75166. {
  75167. return destStream->getPosition();
  75168. }
  75169. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75170. {
  75171. jassertfalse // can't do it!
  75172. return false;
  75173. }
  75174. END_JUCE_NAMESPACE
  75175. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75176. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75177. #if JUCE_MSVC
  75178. #pragma warning (push)
  75179. #pragma warning (disable: 4309 4305)
  75180. #endif
  75181. namespace zlibNamespace
  75182. {
  75183. #if JUCE_INCLUDE_ZLIB_CODE
  75184. extern "C"
  75185. {
  75186. #undef OS_CODE
  75187. #undef fdopen
  75188. #define ZLIB_INTERNAL
  75189. #define NO_DUMMY_DECL
  75190. /*** Start of inlined file: adler32.c ***/
  75191. #define ZLIB_INTERNAL
  75192. #define BASE 65521UL /* largest prime smaller than 65536 */
  75193. #define NMAX 5552
  75194. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75195. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75196. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75197. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75198. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75199. #ifdef NO_DIVIDE
  75200. # define MOD(a) \
  75201. do { \
  75202. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75203. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75204. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75205. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75206. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75207. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75208. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75209. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75210. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75211. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75212. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75213. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75214. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75215. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75216. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75217. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75218. if (a >= BASE) a -= BASE; \
  75219. } while (0)
  75220. # define MOD4(a) \
  75221. do { \
  75222. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75223. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75224. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75225. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75226. if (a >= BASE) a -= BASE; \
  75227. } while (0)
  75228. #else
  75229. # define MOD(a) a %= BASE
  75230. # define MOD4(a) a %= BASE
  75231. #endif
  75232. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75233. {
  75234. unsigned long sum2;
  75235. unsigned n;
  75236. sum2 = (adler >> 16) & 0xffff;
  75237. adler &= 0xffff;
  75238. if (len == 1) {
  75239. adler += buf[0];
  75240. if (adler >= BASE)
  75241. adler -= BASE;
  75242. sum2 += adler;
  75243. if (sum2 >= BASE)
  75244. sum2 -= BASE;
  75245. return adler | (sum2 << 16);
  75246. }
  75247. if (buf == Z_NULL)
  75248. return 1L;
  75249. if (len < 16) {
  75250. while (len--) {
  75251. adler += *buf++;
  75252. sum2 += adler;
  75253. }
  75254. if (adler >= BASE)
  75255. adler -= BASE;
  75256. MOD4(sum2); /* only added so many BASE's */
  75257. return adler | (sum2 << 16);
  75258. }
  75259. while (len >= NMAX) {
  75260. len -= NMAX;
  75261. n = NMAX / 16; /* NMAX is divisible by 16 */
  75262. do {
  75263. DO16(buf); /* 16 sums unrolled */
  75264. buf += 16;
  75265. } while (--n);
  75266. MOD(adler);
  75267. MOD(sum2);
  75268. }
  75269. if (len) { /* avoid modulos if none remaining */
  75270. while (len >= 16) {
  75271. len -= 16;
  75272. DO16(buf);
  75273. buf += 16;
  75274. }
  75275. while (len--) {
  75276. adler += *buf++;
  75277. sum2 += adler;
  75278. }
  75279. MOD(adler);
  75280. MOD(sum2);
  75281. }
  75282. return adler | (sum2 << 16);
  75283. }
  75284. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75285. {
  75286. unsigned long sum1;
  75287. unsigned long sum2;
  75288. unsigned rem;
  75289. rem = (unsigned)(len2 % BASE);
  75290. sum1 = adler1 & 0xffff;
  75291. sum2 = rem * sum1;
  75292. MOD(sum2);
  75293. sum1 += (adler2 & 0xffff) + BASE - 1;
  75294. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75295. if (sum1 > BASE) sum1 -= BASE;
  75296. if (sum1 > BASE) sum1 -= BASE;
  75297. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75298. if (sum2 > BASE) sum2 -= BASE;
  75299. return sum1 | (sum2 << 16);
  75300. }
  75301. /*** End of inlined file: adler32.c ***/
  75302. /*** Start of inlined file: compress.c ***/
  75303. #define ZLIB_INTERNAL
  75304. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75305. uLong sourceLen, int level)
  75306. {
  75307. z_stream stream;
  75308. int err;
  75309. stream.next_in = (Bytef*)source;
  75310. stream.avail_in = (uInt)sourceLen;
  75311. #ifdef MAXSEG_64K
  75312. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75313. #endif
  75314. stream.next_out = dest;
  75315. stream.avail_out = (uInt)*destLen;
  75316. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75317. stream.zalloc = (alloc_func)0;
  75318. stream.zfree = (free_func)0;
  75319. stream.opaque = (voidpf)0;
  75320. err = deflateInit(&stream, level);
  75321. if (err != Z_OK) return err;
  75322. err = deflate(&stream, Z_FINISH);
  75323. if (err != Z_STREAM_END) {
  75324. deflateEnd(&stream);
  75325. return err == Z_OK ? Z_BUF_ERROR : err;
  75326. }
  75327. *destLen = stream.total_out;
  75328. err = deflateEnd(&stream);
  75329. return err;
  75330. }
  75331. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75332. {
  75333. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75334. }
  75335. uLong ZEXPORT compressBound (uLong sourceLen)
  75336. {
  75337. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75338. }
  75339. /*** End of inlined file: compress.c ***/
  75340. #undef DO1
  75341. #undef DO8
  75342. /*** Start of inlined file: crc32.c ***/
  75343. #ifdef MAKECRCH
  75344. # include <stdio.h>
  75345. # ifndef DYNAMIC_CRC_TABLE
  75346. # define DYNAMIC_CRC_TABLE
  75347. # endif /* !DYNAMIC_CRC_TABLE */
  75348. #endif /* MAKECRCH */
  75349. /*** Start of inlined file: zutil.h ***/
  75350. #ifndef ZUTIL_H
  75351. #define ZUTIL_H
  75352. #define ZLIB_INTERNAL
  75353. #ifdef STDC
  75354. # ifndef _WIN32_WCE
  75355. # include <stddef.h>
  75356. # endif
  75357. # include <string.h>
  75358. # include <stdlib.h>
  75359. #endif
  75360. #ifdef NO_ERRNO_H
  75361. # ifdef _WIN32_WCE
  75362. # define errno z_errno
  75363. # endif
  75364. extern int errno;
  75365. #else
  75366. # ifndef _WIN32_WCE
  75367. # include <errno.h>
  75368. # endif
  75369. #endif
  75370. #ifndef local
  75371. # define local static
  75372. #endif
  75373. typedef unsigned char uch;
  75374. typedef uch FAR uchf;
  75375. typedef unsigned short ush;
  75376. typedef ush FAR ushf;
  75377. typedef unsigned long ulg;
  75378. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75379. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75380. #define ERR_RETURN(strm,err) \
  75381. return (strm->msg = (char*)ERR_MSG(err), (err))
  75382. #ifndef DEF_WBITS
  75383. # define DEF_WBITS MAX_WBITS
  75384. #endif
  75385. #if MAX_MEM_LEVEL >= 8
  75386. # define DEF_MEM_LEVEL 8
  75387. #else
  75388. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75389. #endif
  75390. #define STORED_BLOCK 0
  75391. #define STATIC_TREES 1
  75392. #define DYN_TREES 2
  75393. #define MIN_MATCH 3
  75394. #define MAX_MATCH 258
  75395. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75396. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75397. # define OS_CODE 0x00
  75398. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75399. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75400. void _Cdecl farfree( void *block );
  75401. void *_Cdecl farmalloc( unsigned long nbytes );
  75402. # else
  75403. # include <alloc.h>
  75404. # endif
  75405. # else /* MSC or DJGPP */
  75406. # include <malloc.h>
  75407. # endif
  75408. #endif
  75409. #ifdef AMIGA
  75410. # define OS_CODE 0x01
  75411. #endif
  75412. #if defined(VAXC) || defined(VMS)
  75413. # define OS_CODE 0x02
  75414. # define F_OPEN(name, mode) \
  75415. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75416. #endif
  75417. #if defined(ATARI) || defined(atarist)
  75418. # define OS_CODE 0x05
  75419. #endif
  75420. #ifdef OS2
  75421. # define OS_CODE 0x06
  75422. # ifdef M_I86
  75423. #include <malloc.h>
  75424. # endif
  75425. #endif
  75426. #if defined(MACOS) || TARGET_OS_MAC
  75427. # define OS_CODE 0x07
  75428. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75429. # include <unix.h> /* for fdopen */
  75430. # else
  75431. # ifndef fdopen
  75432. # define fdopen(fd,mode) NULL /* No fdopen() */
  75433. # endif
  75434. # endif
  75435. #endif
  75436. #ifdef TOPS20
  75437. # define OS_CODE 0x0a
  75438. #endif
  75439. #ifdef WIN32
  75440. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75441. # define OS_CODE 0x0b
  75442. # endif
  75443. #endif
  75444. #ifdef __50SERIES /* Prime/PRIMOS */
  75445. # define OS_CODE 0x0f
  75446. #endif
  75447. #if defined(_BEOS_) || defined(RISCOS)
  75448. # define fdopen(fd,mode) NULL /* No fdopen() */
  75449. #endif
  75450. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75451. # if defined(_WIN32_WCE)
  75452. # define fdopen(fd,mode) NULL /* No fdopen() */
  75453. # ifndef _PTRDIFF_T_DEFINED
  75454. typedef int ptrdiff_t;
  75455. # define _PTRDIFF_T_DEFINED
  75456. # endif
  75457. # else
  75458. # define fdopen(fd,type) _fdopen(fd,type)
  75459. # endif
  75460. #endif
  75461. #ifndef OS_CODE
  75462. # define OS_CODE 0x03 /* assume Unix */
  75463. #endif
  75464. #ifndef F_OPEN
  75465. # define F_OPEN(name, mode) fopen((name), (mode))
  75466. #endif
  75467. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75468. # ifndef HAVE_VSNPRINTF
  75469. # define HAVE_VSNPRINTF
  75470. # endif
  75471. #endif
  75472. #if defined(__CYGWIN__)
  75473. # ifndef HAVE_VSNPRINTF
  75474. # define HAVE_VSNPRINTF
  75475. # endif
  75476. #endif
  75477. #ifndef HAVE_VSNPRINTF
  75478. # ifdef MSDOS
  75479. # define NO_vsnprintf
  75480. # endif
  75481. # ifdef __TURBOC__
  75482. # define NO_vsnprintf
  75483. # endif
  75484. # ifdef WIN32
  75485. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75486. # define vsnprintf _vsnprintf
  75487. # endif
  75488. # endif
  75489. # ifdef __SASC
  75490. # define NO_vsnprintf
  75491. # endif
  75492. #endif
  75493. #ifdef VMS
  75494. # define NO_vsnprintf
  75495. #endif
  75496. #if defined(pyr)
  75497. # define NO_MEMCPY
  75498. #endif
  75499. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75500. # define NO_MEMCPY
  75501. #endif
  75502. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75503. # define HAVE_MEMCPY
  75504. #endif
  75505. #ifdef HAVE_MEMCPY
  75506. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75507. # define zmemcpy _fmemcpy
  75508. # define zmemcmp _fmemcmp
  75509. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75510. # else
  75511. # define zmemcpy memcpy
  75512. # define zmemcmp memcmp
  75513. # define zmemzero(dest, len) memset(dest, 0, len)
  75514. # endif
  75515. #else
  75516. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75517. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75518. extern void zmemzero OF((Bytef* dest, uInt len));
  75519. #endif
  75520. #ifdef DEBUG
  75521. # include <stdio.h>
  75522. extern int z_verbose;
  75523. extern void z_error OF((const char *m));
  75524. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75525. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75526. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75527. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75528. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75529. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75530. #else
  75531. # define Assert(cond,msg)
  75532. # define Trace(x)
  75533. # define Tracev(x)
  75534. # define Tracevv(x)
  75535. # define Tracec(c,x)
  75536. # define Tracecv(c,x)
  75537. #endif
  75538. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75539. void zcfree OF((voidpf opaque, voidpf ptr));
  75540. #define ZALLOC(strm, items, size) \
  75541. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75542. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75543. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75544. #endif /* ZUTIL_H */
  75545. /*** End of inlined file: zutil.h ***/
  75546. /* for STDC and FAR definitions */
  75547. #define local static
  75548. #ifndef NOBYFOUR
  75549. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75550. # include <limits.h>
  75551. # define BYFOUR
  75552. # if (UINT_MAX == 0xffffffffUL)
  75553. typedef unsigned int u4;
  75554. # else
  75555. # if (ULONG_MAX == 0xffffffffUL)
  75556. typedef unsigned long u4;
  75557. # else
  75558. # if (USHRT_MAX == 0xffffffffUL)
  75559. typedef unsigned short u4;
  75560. # else
  75561. # undef BYFOUR /* can't find a four-byte integer type! */
  75562. # endif
  75563. # endif
  75564. # endif
  75565. # endif /* STDC */
  75566. #endif /* !NOBYFOUR */
  75567. #ifdef BYFOUR
  75568. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75569. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75570. local unsigned long crc32_little OF((unsigned long,
  75571. const unsigned char FAR *, unsigned));
  75572. local unsigned long crc32_big OF((unsigned long,
  75573. const unsigned char FAR *, unsigned));
  75574. # define TBLS 8
  75575. #else
  75576. # define TBLS 1
  75577. #endif /* BYFOUR */
  75578. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75579. unsigned long vec));
  75580. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75581. #ifdef DYNAMIC_CRC_TABLE
  75582. local volatile int crc_table_empty = 1;
  75583. local unsigned long FAR crc_table[TBLS][256];
  75584. local void make_crc_table OF((void));
  75585. #ifdef MAKECRCH
  75586. local void write_table OF((FILE *, const unsigned long FAR *));
  75587. #endif /* MAKECRCH */
  75588. local void make_crc_table()
  75589. {
  75590. unsigned long c;
  75591. int n, k;
  75592. unsigned long poly; /* polynomial exclusive-or pattern */
  75593. static volatile int first = 1; /* flag to limit concurrent making */
  75594. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75595. if (first) {
  75596. first = 0;
  75597. poly = 0UL;
  75598. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75599. poly |= 1UL << (31 - p[n]);
  75600. for (n = 0; n < 256; n++) {
  75601. c = (unsigned long)n;
  75602. for (k = 0; k < 8; k++)
  75603. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75604. crc_table[0][n] = c;
  75605. }
  75606. #ifdef BYFOUR
  75607. for (n = 0; n < 256; n++) {
  75608. c = crc_table[0][n];
  75609. crc_table[4][n] = REV(c);
  75610. for (k = 1; k < 4; k++) {
  75611. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75612. crc_table[k][n] = c;
  75613. crc_table[k + 4][n] = REV(c);
  75614. }
  75615. }
  75616. #endif /* BYFOUR */
  75617. crc_table_empty = 0;
  75618. }
  75619. else { /* not first */
  75620. while (crc_table_empty)
  75621. ;
  75622. }
  75623. #ifdef MAKECRCH
  75624. {
  75625. FILE *out;
  75626. out = fopen("crc32.h", "w");
  75627. if (out == NULL) return;
  75628. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75629. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75630. fprintf(out, "local const unsigned long FAR ");
  75631. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75632. write_table(out, crc_table[0]);
  75633. # ifdef BYFOUR
  75634. fprintf(out, "#ifdef BYFOUR\n");
  75635. for (k = 1; k < 8; k++) {
  75636. fprintf(out, " },\n {\n");
  75637. write_table(out, crc_table[k]);
  75638. }
  75639. fprintf(out, "#endif\n");
  75640. # endif /* BYFOUR */
  75641. fprintf(out, " }\n};\n");
  75642. fclose(out);
  75643. }
  75644. #endif /* MAKECRCH */
  75645. }
  75646. #ifdef MAKECRCH
  75647. local void write_table(out, table)
  75648. FILE *out;
  75649. const unsigned long FAR *table;
  75650. {
  75651. int n;
  75652. for (n = 0; n < 256; n++)
  75653. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75654. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75655. }
  75656. #endif /* MAKECRCH */
  75657. #else /* !DYNAMIC_CRC_TABLE */
  75658. /*** Start of inlined file: crc32.h ***/
  75659. local const unsigned long FAR crc_table[TBLS][256] =
  75660. {
  75661. {
  75662. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75663. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75664. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75665. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75666. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75667. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75668. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75669. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75670. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75671. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75672. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75673. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75674. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75675. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75676. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75677. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75678. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75679. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75680. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75681. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75682. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75683. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75684. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75685. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75686. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75687. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75688. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75689. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75690. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75691. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75692. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75693. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75694. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75695. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75696. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75697. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75698. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75699. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75700. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75701. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75702. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75703. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75704. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75705. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75706. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75707. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75708. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75709. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75710. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75711. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75712. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75713. 0x2d02ef8dUL
  75714. #ifdef BYFOUR
  75715. },
  75716. {
  75717. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75718. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75719. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75720. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75721. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75722. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75723. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75724. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75725. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75726. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75727. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75728. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75729. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75730. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75731. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75732. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75733. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75734. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75735. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75736. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75737. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75738. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75739. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75740. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75741. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75742. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75743. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75744. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75745. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75746. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75747. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75748. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75749. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75750. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75751. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75752. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75753. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75754. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75755. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75756. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75757. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75758. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75759. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75760. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75761. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75762. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75763. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75764. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75765. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75766. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75767. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75768. 0x9324fd72UL
  75769. },
  75770. {
  75771. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75772. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75773. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75774. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75775. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75776. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75777. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75778. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75779. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75780. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75781. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75782. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75783. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75784. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75785. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75786. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75787. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75788. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75789. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75790. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75791. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75792. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75793. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75794. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75795. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75796. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75797. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75798. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75799. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75800. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75801. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75802. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75803. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75804. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75805. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75806. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75807. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75808. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75809. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75810. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75811. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75812. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  75813. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  75814. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  75815. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  75816. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  75817. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  75818. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  75819. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  75820. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  75821. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  75822. 0xbe9834edUL
  75823. },
  75824. {
  75825. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  75826. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  75827. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  75828. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  75829. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  75830. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  75831. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  75832. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  75833. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  75834. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  75835. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  75836. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  75837. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  75838. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  75839. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  75840. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  75841. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  75842. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  75843. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  75844. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  75845. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  75846. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  75847. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  75848. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  75849. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  75850. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  75851. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  75852. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  75853. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  75854. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  75855. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  75856. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  75857. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  75858. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  75859. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  75860. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  75861. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  75862. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  75863. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  75864. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  75865. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  75866. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  75867. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  75868. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  75869. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  75870. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  75871. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  75872. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  75873. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  75874. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  75875. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  75876. 0xde0506f1UL
  75877. },
  75878. {
  75879. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  75880. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  75881. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  75882. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  75883. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  75884. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  75885. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  75886. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  75887. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  75888. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  75889. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  75890. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  75891. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  75892. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  75893. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  75894. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  75895. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  75896. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  75897. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  75898. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  75899. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  75900. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  75901. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  75902. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  75903. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  75904. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  75905. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  75906. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  75907. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  75908. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  75909. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  75910. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  75911. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  75912. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  75913. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  75914. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  75915. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  75916. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  75917. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  75918. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  75919. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  75920. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  75921. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  75922. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  75923. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  75924. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  75925. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  75926. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  75927. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  75928. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  75929. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  75930. 0x8def022dUL
  75931. },
  75932. {
  75933. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  75934. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  75935. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  75936. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  75937. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  75938. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  75939. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  75940. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  75941. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  75942. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  75943. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  75944. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  75945. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  75946. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  75947. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  75948. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  75949. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  75950. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  75951. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  75952. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  75953. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  75954. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  75955. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  75956. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  75957. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  75958. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  75959. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  75960. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  75961. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  75962. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  75963. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  75964. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  75965. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  75966. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  75967. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  75968. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  75969. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  75970. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  75971. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  75972. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  75973. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  75974. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  75975. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  75976. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  75977. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  75978. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  75979. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  75980. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  75981. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  75982. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  75983. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  75984. 0x72fd2493UL
  75985. },
  75986. {
  75987. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  75988. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  75989. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  75990. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  75991. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  75992. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  75993. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  75994. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  75995. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  75996. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  75997. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  75998. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  75999. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76000. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76001. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76002. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76003. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76004. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76005. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76006. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76007. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76008. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76009. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76010. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76011. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76012. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76013. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76014. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76015. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76016. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76017. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76018. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76019. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76020. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76021. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76022. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76023. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76024. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76025. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76026. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76027. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76028. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76029. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76030. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76031. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76032. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76033. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76034. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76035. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76036. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76037. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76038. 0xed3498beUL
  76039. },
  76040. {
  76041. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76042. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76043. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76044. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76045. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76046. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76047. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76048. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76049. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76050. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76051. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76052. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76053. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76054. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76055. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76056. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76057. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76058. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76059. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76060. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76061. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76062. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76063. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76064. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76065. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76066. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76067. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76068. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76069. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76070. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76071. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76072. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76073. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76074. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76075. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76076. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76077. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76078. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76079. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76080. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76081. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76082. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76083. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76084. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76085. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76086. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76087. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76088. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76089. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76090. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76091. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76092. 0xf10605deUL
  76093. #endif
  76094. }
  76095. };
  76096. /*** End of inlined file: crc32.h ***/
  76097. #endif /* DYNAMIC_CRC_TABLE */
  76098. const unsigned long FAR * ZEXPORT get_crc_table()
  76099. {
  76100. #ifdef DYNAMIC_CRC_TABLE
  76101. if (crc_table_empty)
  76102. make_crc_table();
  76103. #endif /* DYNAMIC_CRC_TABLE */
  76104. return (const unsigned long FAR *)crc_table;
  76105. }
  76106. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76107. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76108. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76109. {
  76110. if (buf == Z_NULL) return 0UL;
  76111. #ifdef DYNAMIC_CRC_TABLE
  76112. if (crc_table_empty)
  76113. make_crc_table();
  76114. #endif /* DYNAMIC_CRC_TABLE */
  76115. #ifdef BYFOUR
  76116. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76117. u4 endian;
  76118. endian = 1;
  76119. if (*((unsigned char *)(&endian)))
  76120. return crc32_little(crc, buf, len);
  76121. else
  76122. return crc32_big(crc, buf, len);
  76123. }
  76124. #endif /* BYFOUR */
  76125. crc = crc ^ 0xffffffffUL;
  76126. while (len >= 8) {
  76127. DO8;
  76128. len -= 8;
  76129. }
  76130. if (len) do {
  76131. DO1;
  76132. } while (--len);
  76133. return crc ^ 0xffffffffUL;
  76134. }
  76135. #ifdef BYFOUR
  76136. #define DOLIT4 c ^= *buf4++; \
  76137. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76138. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76139. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76140. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76141. {
  76142. register u4 c;
  76143. register const u4 FAR *buf4;
  76144. c = (u4)crc;
  76145. c = ~c;
  76146. while (len && ((ptrdiff_t)buf & 3)) {
  76147. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76148. len--;
  76149. }
  76150. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76151. while (len >= 32) {
  76152. DOLIT32;
  76153. len -= 32;
  76154. }
  76155. while (len >= 4) {
  76156. DOLIT4;
  76157. len -= 4;
  76158. }
  76159. buf = (const unsigned char FAR *)buf4;
  76160. if (len) do {
  76161. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76162. } while (--len);
  76163. c = ~c;
  76164. return (unsigned long)c;
  76165. }
  76166. #define DOBIG4 c ^= *++buf4; \
  76167. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76168. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76169. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76170. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76171. {
  76172. register u4 c;
  76173. register const u4 FAR *buf4;
  76174. c = REV((u4)crc);
  76175. c = ~c;
  76176. while (len && ((ptrdiff_t)buf & 3)) {
  76177. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76178. len--;
  76179. }
  76180. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76181. buf4--;
  76182. while (len >= 32) {
  76183. DOBIG32;
  76184. len -= 32;
  76185. }
  76186. while (len >= 4) {
  76187. DOBIG4;
  76188. len -= 4;
  76189. }
  76190. buf4++;
  76191. buf = (const unsigned char FAR *)buf4;
  76192. if (len) do {
  76193. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76194. } while (--len);
  76195. c = ~c;
  76196. return (unsigned long)(REV(c));
  76197. }
  76198. #endif /* BYFOUR */
  76199. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76200. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76201. {
  76202. unsigned long sum;
  76203. sum = 0;
  76204. while (vec) {
  76205. if (vec & 1)
  76206. sum ^= *mat;
  76207. vec >>= 1;
  76208. mat++;
  76209. }
  76210. return sum;
  76211. }
  76212. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76213. {
  76214. int n;
  76215. for (n = 0; n < GF2_DIM; n++)
  76216. square[n] = gf2_matrix_times(mat, mat[n]);
  76217. }
  76218. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76219. {
  76220. int n;
  76221. unsigned long row;
  76222. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76223. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76224. if (len2 == 0)
  76225. return crc1;
  76226. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76227. row = 1;
  76228. for (n = 1; n < GF2_DIM; n++) {
  76229. odd[n] = row;
  76230. row <<= 1;
  76231. }
  76232. gf2_matrix_square(even, odd);
  76233. gf2_matrix_square(odd, even);
  76234. do {
  76235. gf2_matrix_square(even, odd);
  76236. if (len2 & 1)
  76237. crc1 = gf2_matrix_times(even, crc1);
  76238. len2 >>= 1;
  76239. if (len2 == 0)
  76240. break;
  76241. gf2_matrix_square(odd, even);
  76242. if (len2 & 1)
  76243. crc1 = gf2_matrix_times(odd, crc1);
  76244. len2 >>= 1;
  76245. } while (len2 != 0);
  76246. crc1 ^= crc2;
  76247. return crc1;
  76248. }
  76249. /*** End of inlined file: crc32.c ***/
  76250. /*** Start of inlined file: deflate.c ***/
  76251. /*** Start of inlined file: deflate.h ***/
  76252. #ifndef DEFLATE_H
  76253. #define DEFLATE_H
  76254. #ifndef NO_GZIP
  76255. # define GZIP
  76256. #endif
  76257. #define NO_DUMMY_DECL
  76258. #define LENGTH_CODES 29
  76259. #define LITERALS 256
  76260. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76261. #define D_CODES 30
  76262. #define BL_CODES 19
  76263. #define HEAP_SIZE (2*L_CODES+1)
  76264. #define MAX_BITS 15
  76265. #define INIT_STATE 42
  76266. #define EXTRA_STATE 69
  76267. #define NAME_STATE 73
  76268. #define COMMENT_STATE 91
  76269. #define HCRC_STATE 103
  76270. #define BUSY_STATE 113
  76271. #define FINISH_STATE 666
  76272. typedef struct ct_data_s {
  76273. union {
  76274. ush freq; /* frequency count */
  76275. ush code; /* bit string */
  76276. } fc;
  76277. union {
  76278. ush dad; /* father node in Huffman tree */
  76279. ush len; /* length of bit string */
  76280. } dl;
  76281. } FAR ct_data;
  76282. #define Freq fc.freq
  76283. #define Code fc.code
  76284. #define Dad dl.dad
  76285. #define Len dl.len
  76286. typedef struct static_tree_desc_s static_tree_desc;
  76287. typedef struct tree_desc_s {
  76288. ct_data *dyn_tree; /* the dynamic tree */
  76289. int max_code; /* largest code with non zero frequency */
  76290. static_tree_desc *stat_desc; /* the corresponding static tree */
  76291. } FAR tree_desc;
  76292. typedef ush Pos;
  76293. typedef Pos FAR Posf;
  76294. typedef unsigned IPos;
  76295. typedef struct internal_state {
  76296. z_streamp strm; /* pointer back to this zlib stream */
  76297. int status; /* as the name implies */
  76298. Bytef *pending_buf; /* output still pending */
  76299. ulg pending_buf_size; /* size of pending_buf */
  76300. Bytef *pending_out; /* next pending byte to output to the stream */
  76301. uInt pending; /* nb of bytes in the pending buffer */
  76302. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76303. gz_headerp gzhead; /* gzip header information to write */
  76304. uInt gzindex; /* where in extra, name, or comment */
  76305. Byte method; /* STORED (for zip only) or DEFLATED */
  76306. int last_flush; /* value of flush param for previous deflate call */
  76307. uInt w_size; /* LZ77 window size (32K by default) */
  76308. uInt w_bits; /* log2(w_size) (8..16) */
  76309. uInt w_mask; /* w_size - 1 */
  76310. Bytef *window;
  76311. ulg window_size;
  76312. Posf *prev;
  76313. Posf *head; /* Heads of the hash chains or NIL. */
  76314. uInt ins_h; /* hash index of string to be inserted */
  76315. uInt hash_size; /* number of elements in hash table */
  76316. uInt hash_bits; /* log2(hash_size) */
  76317. uInt hash_mask; /* hash_size-1 */
  76318. uInt hash_shift;
  76319. long block_start;
  76320. uInt match_length; /* length of best match */
  76321. IPos prev_match; /* previous match */
  76322. int match_available; /* set if previous match exists */
  76323. uInt strstart; /* start of string to insert */
  76324. uInt match_start; /* start of matching string */
  76325. uInt lookahead; /* number of valid bytes ahead in window */
  76326. uInt prev_length;
  76327. uInt max_chain_length;
  76328. uInt max_lazy_match;
  76329. # define max_insert_length max_lazy_match
  76330. int level; /* compression level (1..9) */
  76331. int strategy; /* favor or force Huffman coding*/
  76332. uInt good_match;
  76333. int nice_match; /* Stop searching when current match exceeds this */
  76334. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76335. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76336. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76337. struct tree_desc_s l_desc; /* desc. for literal tree */
  76338. struct tree_desc_s d_desc; /* desc. for distance tree */
  76339. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76340. ush bl_count[MAX_BITS+1];
  76341. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76342. int heap_len; /* number of elements in the heap */
  76343. int heap_max; /* element of largest frequency */
  76344. uch depth[2*L_CODES+1];
  76345. uchf *l_buf; /* buffer for literals or lengths */
  76346. uInt lit_bufsize;
  76347. uInt last_lit; /* running index in l_buf */
  76348. ushf *d_buf;
  76349. ulg opt_len; /* bit length of current block with optimal trees */
  76350. ulg static_len; /* bit length of current block with static trees */
  76351. uInt matches; /* number of string matches in current block */
  76352. int last_eob_len; /* bit length of EOB code for last block */
  76353. #ifdef DEBUG
  76354. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76355. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76356. #endif
  76357. ush bi_buf;
  76358. int bi_valid;
  76359. } FAR deflate_state;
  76360. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76361. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76362. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76363. void _tr_init OF((deflate_state *s));
  76364. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76365. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76366. int eof));
  76367. void _tr_align OF((deflate_state *s));
  76368. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76369. int eof));
  76370. #define d_code(dist) \
  76371. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76372. #ifndef DEBUG
  76373. #if defined(GEN_TREES_H) || !defined(STDC)
  76374. extern uch _length_code[];
  76375. extern uch _dist_code[];
  76376. #else
  76377. extern const uch _length_code[];
  76378. extern const uch _dist_code[];
  76379. #endif
  76380. # define _tr_tally_lit(s, c, flush) \
  76381. { uch cc = (c); \
  76382. s->d_buf[s->last_lit] = 0; \
  76383. s->l_buf[s->last_lit++] = cc; \
  76384. s->dyn_ltree[cc].Freq++; \
  76385. flush = (s->last_lit == s->lit_bufsize-1); \
  76386. }
  76387. # define _tr_tally_dist(s, distance, length, flush) \
  76388. { uch len = (length); \
  76389. ush dist = (distance); \
  76390. s->d_buf[s->last_lit] = dist; \
  76391. s->l_buf[s->last_lit++] = len; \
  76392. dist--; \
  76393. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76394. s->dyn_dtree[d_code(dist)].Freq++; \
  76395. flush = (s->last_lit == s->lit_bufsize-1); \
  76396. }
  76397. #else
  76398. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76399. # define _tr_tally_dist(s, distance, length, flush) \
  76400. flush = _tr_tally(s, distance, length)
  76401. #endif
  76402. #endif /* DEFLATE_H */
  76403. /*** End of inlined file: deflate.h ***/
  76404. const char deflate_copyright[] =
  76405. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76406. typedef enum {
  76407. need_more, /* block not completed, need more input or more output */
  76408. block_done, /* block flush performed */
  76409. finish_started, /* finish started, need only more output at next deflate */
  76410. finish_done /* finish done, accept no more input or output */
  76411. } block_state;
  76412. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76413. local void fill_window OF((deflate_state *s));
  76414. local block_state deflate_stored OF((deflate_state *s, int flush));
  76415. local block_state deflate_fast OF((deflate_state *s, int flush));
  76416. #ifndef FASTEST
  76417. local block_state deflate_slow OF((deflate_state *s, int flush));
  76418. #endif
  76419. local void lm_init OF((deflate_state *s));
  76420. local void putShortMSB OF((deflate_state *s, uInt b));
  76421. local void flush_pending OF((z_streamp strm));
  76422. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76423. #ifndef FASTEST
  76424. #ifdef ASMV
  76425. void match_init OF((void)); /* asm code initialization */
  76426. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76427. #else
  76428. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76429. #endif
  76430. #endif
  76431. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76432. #ifdef DEBUG
  76433. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76434. int length));
  76435. #endif
  76436. #define NIL 0
  76437. #ifndef TOO_FAR
  76438. # define TOO_FAR 4096
  76439. #endif
  76440. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76441. typedef struct config_s {
  76442. ush good_length; /* reduce lazy search above this match length */
  76443. ush max_lazy; /* do not perform lazy search above this match length */
  76444. ush nice_length; /* quit search above this match length */
  76445. ush max_chain;
  76446. compress_func func;
  76447. } config;
  76448. #ifdef FASTEST
  76449. local const config configuration_table[2] = {
  76450. {0, 0, 0, 0, deflate_stored}, /* store only */
  76451. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76452. #else
  76453. local const config configuration_table[10] = {
  76454. {0, 0, 0, 0, deflate_stored}, /* store only */
  76455. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76456. {4, 5, 16, 8, deflate_fast},
  76457. {4, 6, 32, 32, deflate_fast},
  76458. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76459. {8, 16, 32, 32, deflate_slow},
  76460. {8, 16, 128, 128, deflate_slow},
  76461. {8, 32, 128, 256, deflate_slow},
  76462. {32, 128, 258, 1024, deflate_slow},
  76463. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76464. #endif
  76465. #define EQUAL 0
  76466. #ifndef NO_DUMMY_DECL
  76467. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76468. #endif
  76469. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76470. #ifdef FASTEST
  76471. #define INSERT_STRING(s, str, match_head) \
  76472. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76473. match_head = s->head[s->ins_h], \
  76474. s->head[s->ins_h] = (Pos)(str))
  76475. #else
  76476. #define INSERT_STRING(s, str, match_head) \
  76477. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76478. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76479. s->head[s->ins_h] = (Pos)(str))
  76480. #endif
  76481. #define CLEAR_HASH(s) \
  76482. s->head[s->hash_size-1] = NIL; \
  76483. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76484. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76485. {
  76486. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76487. Z_DEFAULT_STRATEGY, version, stream_size);
  76488. }
  76489. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76490. {
  76491. deflate_state *s;
  76492. int wrap = 1;
  76493. static const char my_version[] = ZLIB_VERSION;
  76494. ushf *overlay;
  76495. if (version == Z_NULL || version[0] != my_version[0] ||
  76496. stream_size != sizeof(z_stream)) {
  76497. return Z_VERSION_ERROR;
  76498. }
  76499. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76500. strm->msg = Z_NULL;
  76501. if (strm->zalloc == (alloc_func)0) {
  76502. strm->zalloc = zcalloc;
  76503. strm->opaque = (voidpf)0;
  76504. }
  76505. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76506. #ifdef FASTEST
  76507. if (level != 0) level = 1;
  76508. #else
  76509. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76510. #endif
  76511. if (windowBits < 0) { /* suppress zlib wrapper */
  76512. wrap = 0;
  76513. windowBits = -windowBits;
  76514. }
  76515. #ifdef GZIP
  76516. else if (windowBits > 15) {
  76517. wrap = 2; /* write gzip wrapper instead */
  76518. windowBits -= 16;
  76519. }
  76520. #endif
  76521. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76522. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76523. strategy < 0 || strategy > Z_FIXED) {
  76524. return Z_STREAM_ERROR;
  76525. }
  76526. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76527. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76528. if (s == Z_NULL) return Z_MEM_ERROR;
  76529. strm->state = (struct internal_state FAR *)s;
  76530. s->strm = strm;
  76531. s->wrap = wrap;
  76532. s->gzhead = Z_NULL;
  76533. s->w_bits = windowBits;
  76534. s->w_size = 1 << s->w_bits;
  76535. s->w_mask = s->w_size - 1;
  76536. s->hash_bits = memLevel + 7;
  76537. s->hash_size = 1 << s->hash_bits;
  76538. s->hash_mask = s->hash_size - 1;
  76539. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76540. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76541. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76542. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76543. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76544. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76545. s->pending_buf = (uchf *) overlay;
  76546. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76547. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76548. s->pending_buf == Z_NULL) {
  76549. s->status = FINISH_STATE;
  76550. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76551. deflateEnd (strm);
  76552. return Z_MEM_ERROR;
  76553. }
  76554. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76555. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76556. s->level = level;
  76557. s->strategy = strategy;
  76558. s->method = (Byte)method;
  76559. return deflateReset(strm);
  76560. }
  76561. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76562. {
  76563. deflate_state *s;
  76564. uInt length = dictLength;
  76565. uInt n;
  76566. IPos hash_head = 0;
  76567. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76568. strm->state->wrap == 2 ||
  76569. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76570. return Z_STREAM_ERROR;
  76571. s = strm->state;
  76572. if (s->wrap)
  76573. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76574. if (length < MIN_MATCH) return Z_OK;
  76575. if (length > MAX_DIST(s)) {
  76576. length = MAX_DIST(s);
  76577. dictionary += dictLength - length; /* use the tail of the dictionary */
  76578. }
  76579. zmemcpy(s->window, dictionary, length);
  76580. s->strstart = length;
  76581. s->block_start = (long)length;
  76582. s->ins_h = s->window[0];
  76583. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76584. for (n = 0; n <= length - MIN_MATCH; n++) {
  76585. INSERT_STRING(s, n, hash_head);
  76586. }
  76587. if (hash_head) hash_head = 0; /* to make compiler happy */
  76588. return Z_OK;
  76589. }
  76590. int ZEXPORT deflateReset (z_streamp strm)
  76591. {
  76592. deflate_state *s;
  76593. if (strm == Z_NULL || strm->state == Z_NULL ||
  76594. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76595. return Z_STREAM_ERROR;
  76596. }
  76597. strm->total_in = strm->total_out = 0;
  76598. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76599. strm->data_type = Z_UNKNOWN;
  76600. s = (deflate_state *)strm->state;
  76601. s->pending = 0;
  76602. s->pending_out = s->pending_buf;
  76603. if (s->wrap < 0) {
  76604. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76605. }
  76606. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76607. strm->adler =
  76608. #ifdef GZIP
  76609. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76610. #endif
  76611. adler32(0L, Z_NULL, 0);
  76612. s->last_flush = Z_NO_FLUSH;
  76613. _tr_init(s);
  76614. lm_init(s);
  76615. return Z_OK;
  76616. }
  76617. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76618. {
  76619. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76620. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76621. strm->state->gzhead = head;
  76622. return Z_OK;
  76623. }
  76624. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76625. {
  76626. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76627. strm->state->bi_valid = bits;
  76628. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76629. return Z_OK;
  76630. }
  76631. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76632. {
  76633. deflate_state *s;
  76634. compress_func func;
  76635. int err = Z_OK;
  76636. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76637. s = strm->state;
  76638. #ifdef FASTEST
  76639. if (level != 0) level = 1;
  76640. #else
  76641. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76642. #endif
  76643. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76644. return Z_STREAM_ERROR;
  76645. }
  76646. func = configuration_table[s->level].func;
  76647. if (func != configuration_table[level].func && strm->total_in != 0) {
  76648. err = deflate(strm, Z_PARTIAL_FLUSH);
  76649. }
  76650. if (s->level != level) {
  76651. s->level = level;
  76652. s->max_lazy_match = configuration_table[level].max_lazy;
  76653. s->good_match = configuration_table[level].good_length;
  76654. s->nice_match = configuration_table[level].nice_length;
  76655. s->max_chain_length = configuration_table[level].max_chain;
  76656. }
  76657. s->strategy = strategy;
  76658. return err;
  76659. }
  76660. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76661. {
  76662. deflate_state *s;
  76663. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76664. s = strm->state;
  76665. s->good_match = good_length;
  76666. s->max_lazy_match = max_lazy;
  76667. s->nice_match = nice_length;
  76668. s->max_chain_length = max_chain;
  76669. return Z_OK;
  76670. }
  76671. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76672. {
  76673. deflate_state *s;
  76674. uLong destLen;
  76675. destLen = sourceLen +
  76676. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76677. if (strm == Z_NULL || strm->state == Z_NULL)
  76678. return destLen;
  76679. s = strm->state;
  76680. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76681. return destLen;
  76682. return compressBound(sourceLen);
  76683. }
  76684. local void putShortMSB (deflate_state *s, uInt b)
  76685. {
  76686. put_byte(s, (Byte)(b >> 8));
  76687. put_byte(s, (Byte)(b & 0xff));
  76688. }
  76689. local void flush_pending (z_streamp strm)
  76690. {
  76691. unsigned len = strm->state->pending;
  76692. if (len > strm->avail_out) len = strm->avail_out;
  76693. if (len == 0) return;
  76694. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76695. strm->next_out += len;
  76696. strm->state->pending_out += len;
  76697. strm->total_out += len;
  76698. strm->avail_out -= len;
  76699. strm->state->pending -= len;
  76700. if (strm->state->pending == 0) {
  76701. strm->state->pending_out = strm->state->pending_buf;
  76702. }
  76703. }
  76704. int ZEXPORT deflate (z_streamp strm, int flush)
  76705. {
  76706. int old_flush; /* value of flush param for previous deflate call */
  76707. deflate_state *s;
  76708. if (strm == Z_NULL || strm->state == Z_NULL ||
  76709. flush > Z_FINISH || flush < 0) {
  76710. return Z_STREAM_ERROR;
  76711. }
  76712. s = strm->state;
  76713. if (strm->next_out == Z_NULL ||
  76714. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76715. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76716. ERR_RETURN(strm, Z_STREAM_ERROR);
  76717. }
  76718. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76719. s->strm = strm; /* just in case */
  76720. old_flush = s->last_flush;
  76721. s->last_flush = flush;
  76722. if (s->status == INIT_STATE) {
  76723. #ifdef GZIP
  76724. if (s->wrap == 2) {
  76725. strm->adler = crc32(0L, Z_NULL, 0);
  76726. put_byte(s, 31);
  76727. put_byte(s, 139);
  76728. put_byte(s, 8);
  76729. if (s->gzhead == NULL) {
  76730. put_byte(s, 0);
  76731. put_byte(s, 0);
  76732. put_byte(s, 0);
  76733. put_byte(s, 0);
  76734. put_byte(s, 0);
  76735. put_byte(s, s->level == 9 ? 2 :
  76736. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76737. 4 : 0));
  76738. put_byte(s, OS_CODE);
  76739. s->status = BUSY_STATE;
  76740. }
  76741. else {
  76742. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76743. (s->gzhead->hcrc ? 2 : 0) +
  76744. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76745. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76746. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76747. );
  76748. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76749. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76750. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76751. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76752. put_byte(s, s->level == 9 ? 2 :
  76753. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76754. 4 : 0));
  76755. put_byte(s, s->gzhead->os & 0xff);
  76756. if (s->gzhead->extra != NULL) {
  76757. put_byte(s, s->gzhead->extra_len & 0xff);
  76758. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76759. }
  76760. if (s->gzhead->hcrc)
  76761. strm->adler = crc32(strm->adler, s->pending_buf,
  76762. s->pending);
  76763. s->gzindex = 0;
  76764. s->status = EXTRA_STATE;
  76765. }
  76766. }
  76767. else
  76768. #endif
  76769. {
  76770. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76771. uInt level_flags;
  76772. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76773. level_flags = 0;
  76774. else if (s->level < 6)
  76775. level_flags = 1;
  76776. else if (s->level == 6)
  76777. level_flags = 2;
  76778. else
  76779. level_flags = 3;
  76780. header |= (level_flags << 6);
  76781. if (s->strstart != 0) header |= PRESET_DICT;
  76782. header += 31 - (header % 31);
  76783. s->status = BUSY_STATE;
  76784. putShortMSB(s, header);
  76785. if (s->strstart != 0) {
  76786. putShortMSB(s, (uInt)(strm->adler >> 16));
  76787. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76788. }
  76789. strm->adler = adler32(0L, Z_NULL, 0);
  76790. }
  76791. }
  76792. #ifdef GZIP
  76793. if (s->status == EXTRA_STATE) {
  76794. if (s->gzhead->extra != NULL) {
  76795. uInt beg = s->pending; /* start of bytes to update crc */
  76796. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76797. if (s->pending == s->pending_buf_size) {
  76798. if (s->gzhead->hcrc && s->pending > beg)
  76799. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76800. s->pending - beg);
  76801. flush_pending(strm);
  76802. beg = s->pending;
  76803. if (s->pending == s->pending_buf_size)
  76804. break;
  76805. }
  76806. put_byte(s, s->gzhead->extra[s->gzindex]);
  76807. s->gzindex++;
  76808. }
  76809. if (s->gzhead->hcrc && s->pending > beg)
  76810. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76811. s->pending - beg);
  76812. if (s->gzindex == s->gzhead->extra_len) {
  76813. s->gzindex = 0;
  76814. s->status = NAME_STATE;
  76815. }
  76816. }
  76817. else
  76818. s->status = NAME_STATE;
  76819. }
  76820. if (s->status == NAME_STATE) {
  76821. if (s->gzhead->name != NULL) {
  76822. uInt beg = s->pending; /* start of bytes to update crc */
  76823. int val;
  76824. do {
  76825. if (s->pending == s->pending_buf_size) {
  76826. if (s->gzhead->hcrc && s->pending > beg)
  76827. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76828. s->pending - beg);
  76829. flush_pending(strm);
  76830. beg = s->pending;
  76831. if (s->pending == s->pending_buf_size) {
  76832. val = 1;
  76833. break;
  76834. }
  76835. }
  76836. val = s->gzhead->name[s->gzindex++];
  76837. put_byte(s, val);
  76838. } while (val != 0);
  76839. if (s->gzhead->hcrc && s->pending > beg)
  76840. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76841. s->pending - beg);
  76842. if (val == 0) {
  76843. s->gzindex = 0;
  76844. s->status = COMMENT_STATE;
  76845. }
  76846. }
  76847. else
  76848. s->status = COMMENT_STATE;
  76849. }
  76850. if (s->status == COMMENT_STATE) {
  76851. if (s->gzhead->comment != NULL) {
  76852. uInt beg = s->pending; /* start of bytes to update crc */
  76853. int val;
  76854. do {
  76855. if (s->pending == s->pending_buf_size) {
  76856. if (s->gzhead->hcrc && s->pending > beg)
  76857. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76858. s->pending - beg);
  76859. flush_pending(strm);
  76860. beg = s->pending;
  76861. if (s->pending == s->pending_buf_size) {
  76862. val = 1;
  76863. break;
  76864. }
  76865. }
  76866. val = s->gzhead->comment[s->gzindex++];
  76867. put_byte(s, val);
  76868. } while (val != 0);
  76869. if (s->gzhead->hcrc && s->pending > beg)
  76870. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76871. s->pending - beg);
  76872. if (val == 0)
  76873. s->status = HCRC_STATE;
  76874. }
  76875. else
  76876. s->status = HCRC_STATE;
  76877. }
  76878. if (s->status == HCRC_STATE) {
  76879. if (s->gzhead->hcrc) {
  76880. if (s->pending + 2 > s->pending_buf_size)
  76881. flush_pending(strm);
  76882. if (s->pending + 2 <= s->pending_buf_size) {
  76883. put_byte(s, (Byte)(strm->adler & 0xff));
  76884. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  76885. strm->adler = crc32(0L, Z_NULL, 0);
  76886. s->status = BUSY_STATE;
  76887. }
  76888. }
  76889. else
  76890. s->status = BUSY_STATE;
  76891. }
  76892. #endif
  76893. if (s->pending != 0) {
  76894. flush_pending(strm);
  76895. if (strm->avail_out == 0) {
  76896. s->last_flush = -1;
  76897. return Z_OK;
  76898. }
  76899. } else if (strm->avail_in == 0 && flush <= old_flush &&
  76900. flush != Z_FINISH) {
  76901. ERR_RETURN(strm, Z_BUF_ERROR);
  76902. }
  76903. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  76904. ERR_RETURN(strm, Z_BUF_ERROR);
  76905. }
  76906. if (strm->avail_in != 0 || s->lookahead != 0 ||
  76907. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  76908. block_state bstate;
  76909. bstate = (*(configuration_table[s->level].func))(s, flush);
  76910. if (bstate == finish_started || bstate == finish_done) {
  76911. s->status = FINISH_STATE;
  76912. }
  76913. if (bstate == need_more || bstate == finish_started) {
  76914. if (strm->avail_out == 0) {
  76915. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  76916. }
  76917. return Z_OK;
  76918. }
  76919. if (bstate == block_done) {
  76920. if (flush == Z_PARTIAL_FLUSH) {
  76921. _tr_align(s);
  76922. } else { /* FULL_FLUSH or SYNC_FLUSH */
  76923. _tr_stored_block(s, (char*)0, 0L, 0);
  76924. if (flush == Z_FULL_FLUSH) {
  76925. CLEAR_HASH(s); /* forget history */
  76926. }
  76927. }
  76928. flush_pending(strm);
  76929. if (strm->avail_out == 0) {
  76930. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  76931. return Z_OK;
  76932. }
  76933. }
  76934. }
  76935. Assert(strm->avail_out > 0, "bug2");
  76936. if (flush != Z_FINISH) return Z_OK;
  76937. if (s->wrap <= 0) return Z_STREAM_END;
  76938. #ifdef GZIP
  76939. if (s->wrap == 2) {
  76940. put_byte(s, (Byte)(strm->adler & 0xff));
  76941. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  76942. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  76943. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  76944. put_byte(s, (Byte)(strm->total_in & 0xff));
  76945. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  76946. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  76947. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  76948. }
  76949. else
  76950. #endif
  76951. {
  76952. putShortMSB(s, (uInt)(strm->adler >> 16));
  76953. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76954. }
  76955. flush_pending(strm);
  76956. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  76957. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  76958. }
  76959. int ZEXPORT deflateEnd (z_streamp strm)
  76960. {
  76961. int status;
  76962. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76963. status = strm->state->status;
  76964. if (status != INIT_STATE &&
  76965. status != EXTRA_STATE &&
  76966. status != NAME_STATE &&
  76967. status != COMMENT_STATE &&
  76968. status != HCRC_STATE &&
  76969. status != BUSY_STATE &&
  76970. status != FINISH_STATE) {
  76971. return Z_STREAM_ERROR;
  76972. }
  76973. TRY_FREE(strm, strm->state->pending_buf);
  76974. TRY_FREE(strm, strm->state->head);
  76975. TRY_FREE(strm, strm->state->prev);
  76976. TRY_FREE(strm, strm->state->window);
  76977. ZFREE(strm, strm->state);
  76978. strm->state = Z_NULL;
  76979. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  76980. }
  76981. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  76982. {
  76983. #ifdef MAXSEG_64K
  76984. return Z_STREAM_ERROR;
  76985. #else
  76986. deflate_state *ds;
  76987. deflate_state *ss;
  76988. ushf *overlay;
  76989. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  76990. return Z_STREAM_ERROR;
  76991. }
  76992. ss = source->state;
  76993. zmemcpy(dest, source, sizeof(z_stream));
  76994. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  76995. if (ds == Z_NULL) return Z_MEM_ERROR;
  76996. dest->state = (struct internal_state FAR *) ds;
  76997. zmemcpy(ds, ss, sizeof(deflate_state));
  76998. ds->strm = dest;
  76999. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77000. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77001. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77002. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77003. ds->pending_buf = (uchf *) overlay;
  77004. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77005. ds->pending_buf == Z_NULL) {
  77006. deflateEnd (dest);
  77007. return Z_MEM_ERROR;
  77008. }
  77009. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77010. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77011. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77012. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77013. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77014. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77015. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77016. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77017. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77018. ds->bl_desc.dyn_tree = ds->bl_tree;
  77019. return Z_OK;
  77020. #endif /* MAXSEG_64K */
  77021. }
  77022. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77023. {
  77024. unsigned len = strm->avail_in;
  77025. if (len > size) len = size;
  77026. if (len == 0) return 0;
  77027. strm->avail_in -= len;
  77028. if (strm->state->wrap == 1) {
  77029. strm->adler = adler32(strm->adler, strm->next_in, len);
  77030. }
  77031. #ifdef GZIP
  77032. else if (strm->state->wrap == 2) {
  77033. strm->adler = crc32(strm->adler, strm->next_in, len);
  77034. }
  77035. #endif
  77036. zmemcpy(buf, strm->next_in, len);
  77037. strm->next_in += len;
  77038. strm->total_in += len;
  77039. return (int)len;
  77040. }
  77041. local void lm_init (deflate_state *s)
  77042. {
  77043. s->window_size = (ulg)2L*s->w_size;
  77044. CLEAR_HASH(s);
  77045. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77046. s->good_match = configuration_table[s->level].good_length;
  77047. s->nice_match = configuration_table[s->level].nice_length;
  77048. s->max_chain_length = configuration_table[s->level].max_chain;
  77049. s->strstart = 0;
  77050. s->block_start = 0L;
  77051. s->lookahead = 0;
  77052. s->match_length = s->prev_length = MIN_MATCH-1;
  77053. s->match_available = 0;
  77054. s->ins_h = 0;
  77055. #ifndef FASTEST
  77056. #ifdef ASMV
  77057. match_init(); /* initialize the asm code */
  77058. #endif
  77059. #endif
  77060. }
  77061. #ifndef FASTEST
  77062. #ifndef ASMV
  77063. local uInt longest_match(deflate_state *s, IPos cur_match)
  77064. {
  77065. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77066. register Bytef *scan = s->window + s->strstart; /* current string */
  77067. register Bytef *match; /* matched string */
  77068. register int len; /* length of current match */
  77069. int best_len = s->prev_length; /* best match length so far */
  77070. int nice_match = s->nice_match; /* stop if match long enough */
  77071. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77072. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77073. Posf *prev = s->prev;
  77074. uInt wmask = s->w_mask;
  77075. #ifdef UNALIGNED_OK
  77076. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77077. register ush scan_start = *(ushf*)scan;
  77078. register ush scan_end = *(ushf*)(scan+best_len-1);
  77079. #else
  77080. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77081. register Byte scan_end1 = scan[best_len-1];
  77082. register Byte scan_end = scan[best_len];
  77083. #endif
  77084. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77085. if (s->prev_length >= s->good_match) {
  77086. chain_length >>= 2;
  77087. }
  77088. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77089. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77090. do {
  77091. Assert(cur_match < s->strstart, "no future");
  77092. match = s->window + cur_match;
  77093. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77094. if (*(ushf*)(match+best_len-1) != scan_end ||
  77095. *(ushf*)match != scan_start) continue;
  77096. Assert(scan[2] == match[2], "scan[2]?");
  77097. scan++, match++;
  77098. do {
  77099. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77100. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77101. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77102. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77103. scan < strend);
  77104. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77105. if (*scan == *match) scan++;
  77106. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77107. scan = strend - (MAX_MATCH-1);
  77108. #else /* UNALIGNED_OK */
  77109. if (match[best_len] != scan_end ||
  77110. match[best_len-1] != scan_end1 ||
  77111. *match != *scan ||
  77112. *++match != scan[1]) continue;
  77113. scan += 2, match++;
  77114. Assert(*scan == *match, "match[2]?");
  77115. do {
  77116. } while (*++scan == *++match && *++scan == *++match &&
  77117. *++scan == *++match && *++scan == *++match &&
  77118. *++scan == *++match && *++scan == *++match &&
  77119. *++scan == *++match && *++scan == *++match &&
  77120. scan < strend);
  77121. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77122. len = MAX_MATCH - (int)(strend - scan);
  77123. scan = strend - MAX_MATCH;
  77124. #endif /* UNALIGNED_OK */
  77125. if (len > best_len) {
  77126. s->match_start = cur_match;
  77127. best_len = len;
  77128. if (len >= nice_match) break;
  77129. #ifdef UNALIGNED_OK
  77130. scan_end = *(ushf*)(scan+best_len-1);
  77131. #else
  77132. scan_end1 = scan[best_len-1];
  77133. scan_end = scan[best_len];
  77134. #endif
  77135. }
  77136. } while ((cur_match = prev[cur_match & wmask]) > limit
  77137. && --chain_length != 0);
  77138. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77139. return s->lookahead;
  77140. }
  77141. #endif /* ASMV */
  77142. #endif /* FASTEST */
  77143. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77144. {
  77145. register Bytef *scan = s->window + s->strstart; /* current string */
  77146. register Bytef *match; /* matched string */
  77147. register int len; /* length of current match */
  77148. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77149. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77150. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77151. Assert(cur_match < s->strstart, "no future");
  77152. match = s->window + cur_match;
  77153. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77154. scan += 2, match += 2;
  77155. Assert(*scan == *match, "match[2]?");
  77156. do {
  77157. } while (*++scan == *++match && *++scan == *++match &&
  77158. *++scan == *++match && *++scan == *++match &&
  77159. *++scan == *++match && *++scan == *++match &&
  77160. *++scan == *++match && *++scan == *++match &&
  77161. scan < strend);
  77162. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77163. len = MAX_MATCH - (int)(strend - scan);
  77164. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77165. s->match_start = cur_match;
  77166. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77167. }
  77168. #ifdef DEBUG
  77169. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77170. {
  77171. if (zmemcmp(s->window + match,
  77172. s->window + start, length) != EQUAL) {
  77173. fprintf(stderr, " start %u, match %u, length %d\n",
  77174. start, match, length);
  77175. do {
  77176. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77177. } while (--length != 0);
  77178. z_error("invalid match");
  77179. }
  77180. if (z_verbose > 1) {
  77181. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77182. do { putc(s->window[start++], stderr); } while (--length != 0);
  77183. }
  77184. }
  77185. #else
  77186. # define check_match(s, start, match, length)
  77187. #endif /* DEBUG */
  77188. local void fill_window (deflate_state *s)
  77189. {
  77190. register unsigned n, m;
  77191. register Posf *p;
  77192. unsigned more; /* Amount of free space at the end of the window. */
  77193. uInt wsize = s->w_size;
  77194. do {
  77195. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77196. if (sizeof(int) <= 2) {
  77197. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77198. more = wsize;
  77199. } else if (more == (unsigned)(-1)) {
  77200. more--;
  77201. }
  77202. }
  77203. if (s->strstart >= wsize+MAX_DIST(s)) {
  77204. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77205. s->match_start -= wsize;
  77206. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77207. s->block_start -= (long) wsize;
  77208. n = s->hash_size;
  77209. p = &s->head[n];
  77210. do {
  77211. m = *--p;
  77212. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77213. } while (--n);
  77214. n = wsize;
  77215. #ifndef FASTEST
  77216. p = &s->prev[n];
  77217. do {
  77218. m = *--p;
  77219. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77220. } while (--n);
  77221. #endif
  77222. more += wsize;
  77223. }
  77224. if (s->strm->avail_in == 0) return;
  77225. Assert(more >= 2, "more < 2");
  77226. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77227. s->lookahead += n;
  77228. if (s->lookahead >= MIN_MATCH) {
  77229. s->ins_h = s->window[s->strstart];
  77230. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77231. #if MIN_MATCH != 3
  77232. Call UPDATE_HASH() MIN_MATCH-3 more times
  77233. #endif
  77234. }
  77235. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77236. }
  77237. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77238. _tr_flush_block(s, (s->block_start >= 0L ? \
  77239. (charf *)&s->window[(unsigned)s->block_start] : \
  77240. (charf *)Z_NULL), \
  77241. (ulg)((long)s->strstart - s->block_start), \
  77242. (eof)); \
  77243. s->block_start = s->strstart; \
  77244. flush_pending(s->strm); \
  77245. Tracev((stderr,"[FLUSH]")); \
  77246. }
  77247. #define FLUSH_BLOCK(s, eof) { \
  77248. FLUSH_BLOCK_ONLY(s, eof); \
  77249. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77250. }
  77251. local block_state deflate_stored(deflate_state *s, int flush)
  77252. {
  77253. ulg max_block_size = 0xffff;
  77254. ulg max_start;
  77255. if (max_block_size > s->pending_buf_size - 5) {
  77256. max_block_size = s->pending_buf_size - 5;
  77257. }
  77258. for (;;) {
  77259. if (s->lookahead <= 1) {
  77260. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77261. s->block_start >= (long)s->w_size, "slide too late");
  77262. fill_window(s);
  77263. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77264. if (s->lookahead == 0) break; /* flush the current block */
  77265. }
  77266. Assert(s->block_start >= 0L, "block gone");
  77267. s->strstart += s->lookahead;
  77268. s->lookahead = 0;
  77269. max_start = s->block_start + max_block_size;
  77270. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77271. s->lookahead = (uInt)(s->strstart - max_start);
  77272. s->strstart = (uInt)max_start;
  77273. FLUSH_BLOCK(s, 0);
  77274. }
  77275. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77276. FLUSH_BLOCK(s, 0);
  77277. }
  77278. }
  77279. FLUSH_BLOCK(s, flush == Z_FINISH);
  77280. return flush == Z_FINISH ? finish_done : block_done;
  77281. }
  77282. local block_state deflate_fast(deflate_state *s, int flush)
  77283. {
  77284. IPos hash_head = NIL; /* head of the hash chain */
  77285. int bflush; /* set if current block must be flushed */
  77286. for (;;) {
  77287. if (s->lookahead < MIN_LOOKAHEAD) {
  77288. fill_window(s);
  77289. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77290. return need_more;
  77291. }
  77292. if (s->lookahead == 0) break; /* flush the current block */
  77293. }
  77294. if (s->lookahead >= MIN_MATCH) {
  77295. INSERT_STRING(s, s->strstart, hash_head);
  77296. }
  77297. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77298. #ifdef FASTEST
  77299. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77300. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77301. s->match_length = longest_match_fast (s, hash_head);
  77302. }
  77303. #else
  77304. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77305. s->match_length = longest_match (s, hash_head);
  77306. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77307. s->match_length = longest_match_fast (s, hash_head);
  77308. }
  77309. #endif
  77310. }
  77311. if (s->match_length >= MIN_MATCH) {
  77312. check_match(s, s->strstart, s->match_start, s->match_length);
  77313. _tr_tally_dist(s, s->strstart - s->match_start,
  77314. s->match_length - MIN_MATCH, bflush);
  77315. s->lookahead -= s->match_length;
  77316. #ifndef FASTEST
  77317. if (s->match_length <= s->max_insert_length &&
  77318. s->lookahead >= MIN_MATCH) {
  77319. s->match_length--; /* string at strstart already in table */
  77320. do {
  77321. s->strstart++;
  77322. INSERT_STRING(s, s->strstart, hash_head);
  77323. } while (--s->match_length != 0);
  77324. s->strstart++;
  77325. } else
  77326. #endif
  77327. {
  77328. s->strstart += s->match_length;
  77329. s->match_length = 0;
  77330. s->ins_h = s->window[s->strstart];
  77331. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77332. #if MIN_MATCH != 3
  77333. Call UPDATE_HASH() MIN_MATCH-3 more times
  77334. #endif
  77335. }
  77336. } else {
  77337. Tracevv((stderr,"%c", s->window[s->strstart]));
  77338. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77339. s->lookahead--;
  77340. s->strstart++;
  77341. }
  77342. if (bflush) FLUSH_BLOCK(s, 0);
  77343. }
  77344. FLUSH_BLOCK(s, flush == Z_FINISH);
  77345. return flush == Z_FINISH ? finish_done : block_done;
  77346. }
  77347. #ifndef FASTEST
  77348. local block_state deflate_slow(deflate_state *s, int flush)
  77349. {
  77350. IPos hash_head = NIL; /* head of hash chain */
  77351. int bflush; /* set if current block must be flushed */
  77352. for (;;) {
  77353. if (s->lookahead < MIN_LOOKAHEAD) {
  77354. fill_window(s);
  77355. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77356. return need_more;
  77357. }
  77358. if (s->lookahead == 0) break; /* flush the current block */
  77359. }
  77360. if (s->lookahead >= MIN_MATCH) {
  77361. INSERT_STRING(s, s->strstart, hash_head);
  77362. }
  77363. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77364. s->match_length = MIN_MATCH-1;
  77365. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77366. s->strstart - hash_head <= MAX_DIST(s)) {
  77367. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77368. s->match_length = longest_match (s, hash_head);
  77369. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77370. s->match_length = longest_match_fast (s, hash_head);
  77371. }
  77372. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77373. #if TOO_FAR <= 32767
  77374. || (s->match_length == MIN_MATCH &&
  77375. s->strstart - s->match_start > TOO_FAR)
  77376. #endif
  77377. )) {
  77378. s->match_length = MIN_MATCH-1;
  77379. }
  77380. }
  77381. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77382. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77383. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77384. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77385. s->prev_length - MIN_MATCH, bflush);
  77386. s->lookahead -= s->prev_length-1;
  77387. s->prev_length -= 2;
  77388. do {
  77389. if (++s->strstart <= max_insert) {
  77390. INSERT_STRING(s, s->strstart, hash_head);
  77391. }
  77392. } while (--s->prev_length != 0);
  77393. s->match_available = 0;
  77394. s->match_length = MIN_MATCH-1;
  77395. s->strstart++;
  77396. if (bflush) FLUSH_BLOCK(s, 0);
  77397. } else if (s->match_available) {
  77398. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77399. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77400. if (bflush) {
  77401. FLUSH_BLOCK_ONLY(s, 0);
  77402. }
  77403. s->strstart++;
  77404. s->lookahead--;
  77405. if (s->strm->avail_out == 0) return need_more;
  77406. } else {
  77407. s->match_available = 1;
  77408. s->strstart++;
  77409. s->lookahead--;
  77410. }
  77411. }
  77412. Assert (flush != Z_NO_FLUSH, "no flush?");
  77413. if (s->match_available) {
  77414. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77415. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77416. s->match_available = 0;
  77417. }
  77418. FLUSH_BLOCK(s, flush == Z_FINISH);
  77419. return flush == Z_FINISH ? finish_done : block_done;
  77420. }
  77421. #endif /* FASTEST */
  77422. #if 0
  77423. local block_state deflate_rle(s, flush)
  77424. deflate_state *s;
  77425. int flush;
  77426. {
  77427. int bflush; /* set if current block must be flushed */
  77428. uInt run; /* length of run */
  77429. uInt max; /* maximum length of run */
  77430. uInt prev; /* byte at distance one to match */
  77431. Bytef *scan; /* scan for end of run */
  77432. for (;;) {
  77433. if (s->lookahead < MAX_MATCH) {
  77434. fill_window(s);
  77435. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77436. return need_more;
  77437. }
  77438. if (s->lookahead == 0) break; /* flush the current block */
  77439. }
  77440. run = 0;
  77441. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77442. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77443. scan = s->window + s->strstart - 1;
  77444. prev = *scan++;
  77445. do {
  77446. if (*scan++ != prev)
  77447. break;
  77448. } while (++run < max);
  77449. }
  77450. if (run >= MIN_MATCH) {
  77451. check_match(s, s->strstart, s->strstart - 1, run);
  77452. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77453. s->lookahead -= run;
  77454. s->strstart += run;
  77455. } else {
  77456. Tracevv((stderr,"%c", s->window[s->strstart]));
  77457. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77458. s->lookahead--;
  77459. s->strstart++;
  77460. }
  77461. if (bflush) FLUSH_BLOCK(s, 0);
  77462. }
  77463. FLUSH_BLOCK(s, flush == Z_FINISH);
  77464. return flush == Z_FINISH ? finish_done : block_done;
  77465. }
  77466. #endif
  77467. /*** End of inlined file: deflate.c ***/
  77468. /*** Start of inlined file: inffast.c ***/
  77469. /*** Start of inlined file: inftrees.h ***/
  77470. #ifndef _INFTREES_H_
  77471. #define _INFTREES_H_
  77472. typedef struct {
  77473. unsigned char op; /* operation, extra bits, table bits */
  77474. unsigned char bits; /* bits in this part of the code */
  77475. unsigned short val; /* offset in table or code value */
  77476. } code;
  77477. #define ENOUGH 2048
  77478. #define MAXD 592
  77479. typedef enum {
  77480. CODES,
  77481. LENS,
  77482. DISTS
  77483. } codetype;
  77484. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77485. unsigned codes, code FAR * FAR *table,
  77486. unsigned FAR *bits, unsigned short FAR *work));
  77487. #endif
  77488. /*** End of inlined file: inftrees.h ***/
  77489. /*** Start of inlined file: inflate.h ***/
  77490. #ifndef _INFLATE_H_
  77491. #define _INFLATE_H_
  77492. #ifndef NO_GZIP
  77493. # define GUNZIP
  77494. #endif
  77495. typedef enum {
  77496. HEAD, /* i: waiting for magic header */
  77497. FLAGS, /* i: waiting for method and flags (gzip) */
  77498. TIME, /* i: waiting for modification time (gzip) */
  77499. OS, /* i: waiting for extra flags and operating system (gzip) */
  77500. EXLEN, /* i: waiting for extra length (gzip) */
  77501. EXTRA, /* i: waiting for extra bytes (gzip) */
  77502. NAME, /* i: waiting for end of file name (gzip) */
  77503. COMMENT, /* i: waiting for end of comment (gzip) */
  77504. HCRC, /* i: waiting for header crc (gzip) */
  77505. DICTID, /* i: waiting for dictionary check value */
  77506. DICT, /* waiting for inflateSetDictionary() call */
  77507. TYPE, /* i: waiting for type bits, including last-flag bit */
  77508. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77509. STORED, /* i: waiting for stored size (length and complement) */
  77510. COPY, /* i/o: waiting for input or output to copy stored block */
  77511. TABLE, /* i: waiting for dynamic block table lengths */
  77512. LENLENS, /* i: waiting for code length code lengths */
  77513. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77514. LEN, /* i: waiting for length/lit code */
  77515. LENEXT, /* i: waiting for length extra bits */
  77516. DIST, /* i: waiting for distance code */
  77517. DISTEXT, /* i: waiting for distance extra bits */
  77518. MATCH, /* o: waiting for output space to copy string */
  77519. LIT, /* o: waiting for output space to write literal */
  77520. CHECK, /* i: waiting for 32-bit check value */
  77521. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77522. DONE, /* finished check, done -- remain here until reset */
  77523. BAD, /* got a data error -- remain here until reset */
  77524. MEM, /* got an inflate() memory error -- remain here until reset */
  77525. SYNC /* looking for synchronization bytes to restart inflate() */
  77526. } inflate_mode;
  77527. struct inflate_state {
  77528. inflate_mode mode; /* current inflate mode */
  77529. int last; /* true if processing last block */
  77530. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77531. int havedict; /* true if dictionary provided */
  77532. int flags; /* gzip header method and flags (0 if zlib) */
  77533. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77534. unsigned long check; /* protected copy of check value */
  77535. unsigned long total; /* protected copy of output count */
  77536. gz_headerp head; /* where to save gzip header information */
  77537. unsigned wbits; /* log base 2 of requested window size */
  77538. unsigned wsize; /* window size or zero if not using window */
  77539. unsigned whave; /* valid bytes in the window */
  77540. unsigned write; /* window write index */
  77541. unsigned char FAR *window; /* allocated sliding window, if needed */
  77542. unsigned long hold; /* input bit accumulator */
  77543. unsigned bits; /* number of bits in "in" */
  77544. unsigned length; /* literal or length of data to copy */
  77545. unsigned offset; /* distance back to copy string from */
  77546. unsigned extra; /* extra bits needed */
  77547. code const FAR *lencode; /* starting table for length/literal codes */
  77548. code const FAR *distcode; /* starting table for distance codes */
  77549. unsigned lenbits; /* index bits for lencode */
  77550. unsigned distbits; /* index bits for distcode */
  77551. unsigned ncode; /* number of code length code lengths */
  77552. unsigned nlen; /* number of length code lengths */
  77553. unsigned ndist; /* number of distance code lengths */
  77554. unsigned have; /* number of code lengths in lens[] */
  77555. code FAR *next; /* next available space in codes[] */
  77556. unsigned short lens[320]; /* temporary storage for code lengths */
  77557. unsigned short work[288]; /* work area for code table building */
  77558. code codes[ENOUGH]; /* space for code tables */
  77559. };
  77560. #endif
  77561. /*** End of inlined file: inflate.h ***/
  77562. /*** Start of inlined file: inffast.h ***/
  77563. void inflate_fast OF((z_streamp strm, unsigned start));
  77564. /*** End of inlined file: inffast.h ***/
  77565. #ifndef ASMINF
  77566. #ifdef POSTINC
  77567. # define OFF 0
  77568. # define PUP(a) *(a)++
  77569. #else
  77570. # define OFF 1
  77571. # define PUP(a) *++(a)
  77572. #endif
  77573. void inflate_fast (z_streamp strm, unsigned start)
  77574. {
  77575. struct inflate_state FAR *state;
  77576. unsigned char FAR *in; /* local strm->next_in */
  77577. unsigned char FAR *last; /* while in < last, enough input available */
  77578. unsigned char FAR *out; /* local strm->next_out */
  77579. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77580. unsigned char FAR *end; /* while out < end, enough space available */
  77581. #ifdef INFLATE_STRICT
  77582. unsigned dmax; /* maximum distance from zlib header */
  77583. #endif
  77584. unsigned wsize; /* window size or zero if not using window */
  77585. unsigned whave; /* valid bytes in the window */
  77586. unsigned write; /* window write index */
  77587. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77588. unsigned long hold; /* local strm->hold */
  77589. unsigned bits; /* local strm->bits */
  77590. code const FAR *lcode; /* local strm->lencode */
  77591. code const FAR *dcode; /* local strm->distcode */
  77592. unsigned lmask; /* mask for first level of length codes */
  77593. unsigned dmask; /* mask for first level of distance codes */
  77594. code thisx; /* retrieved table entry */
  77595. unsigned op; /* code bits, operation, extra bits, or */
  77596. unsigned len; /* match length, unused bytes */
  77597. unsigned dist; /* match distance */
  77598. unsigned char FAR *from; /* where to copy match from */
  77599. state = (struct inflate_state FAR *)strm->state;
  77600. in = strm->next_in - OFF;
  77601. last = in + (strm->avail_in - 5);
  77602. out = strm->next_out - OFF;
  77603. beg = out - (start - strm->avail_out);
  77604. end = out + (strm->avail_out - 257);
  77605. #ifdef INFLATE_STRICT
  77606. dmax = state->dmax;
  77607. #endif
  77608. wsize = state->wsize;
  77609. whave = state->whave;
  77610. write = state->write;
  77611. window = state->window;
  77612. hold = state->hold;
  77613. bits = state->bits;
  77614. lcode = state->lencode;
  77615. dcode = state->distcode;
  77616. lmask = (1U << state->lenbits) - 1;
  77617. dmask = (1U << state->distbits) - 1;
  77618. do {
  77619. if (bits < 15) {
  77620. hold += (unsigned long)(PUP(in)) << bits;
  77621. bits += 8;
  77622. hold += (unsigned long)(PUP(in)) << bits;
  77623. bits += 8;
  77624. }
  77625. thisx = lcode[hold & lmask];
  77626. dolen:
  77627. op = (unsigned)(thisx.bits);
  77628. hold >>= op;
  77629. bits -= op;
  77630. op = (unsigned)(thisx.op);
  77631. if (op == 0) { /* literal */
  77632. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77633. "inflate: literal '%c'\n" :
  77634. "inflate: literal 0x%02x\n", thisx.val));
  77635. PUP(out) = (unsigned char)(thisx.val);
  77636. }
  77637. else if (op & 16) { /* length base */
  77638. len = (unsigned)(thisx.val);
  77639. op &= 15; /* number of extra bits */
  77640. if (op) {
  77641. if (bits < op) {
  77642. hold += (unsigned long)(PUP(in)) << bits;
  77643. bits += 8;
  77644. }
  77645. len += (unsigned)hold & ((1U << op) - 1);
  77646. hold >>= op;
  77647. bits -= op;
  77648. }
  77649. Tracevv((stderr, "inflate: length %u\n", len));
  77650. if (bits < 15) {
  77651. hold += (unsigned long)(PUP(in)) << bits;
  77652. bits += 8;
  77653. hold += (unsigned long)(PUP(in)) << bits;
  77654. bits += 8;
  77655. }
  77656. thisx = dcode[hold & dmask];
  77657. dodist:
  77658. op = (unsigned)(thisx.bits);
  77659. hold >>= op;
  77660. bits -= op;
  77661. op = (unsigned)(thisx.op);
  77662. if (op & 16) { /* distance base */
  77663. dist = (unsigned)(thisx.val);
  77664. op &= 15; /* number of extra bits */
  77665. if (bits < op) {
  77666. hold += (unsigned long)(PUP(in)) << bits;
  77667. bits += 8;
  77668. if (bits < op) {
  77669. hold += (unsigned long)(PUP(in)) << bits;
  77670. bits += 8;
  77671. }
  77672. }
  77673. dist += (unsigned)hold & ((1U << op) - 1);
  77674. #ifdef INFLATE_STRICT
  77675. if (dist > dmax) {
  77676. strm->msg = (char *)"invalid distance too far back";
  77677. state->mode = BAD;
  77678. break;
  77679. }
  77680. #endif
  77681. hold >>= op;
  77682. bits -= op;
  77683. Tracevv((stderr, "inflate: distance %u\n", dist));
  77684. op = (unsigned)(out - beg); /* max distance in output */
  77685. if (dist > op) { /* see if copy from window */
  77686. op = dist - op; /* distance back in window */
  77687. if (op > whave) {
  77688. strm->msg = (char *)"invalid distance too far back";
  77689. state->mode = BAD;
  77690. break;
  77691. }
  77692. from = window - OFF;
  77693. if (write == 0) { /* very common case */
  77694. from += wsize - op;
  77695. if (op < len) { /* some from window */
  77696. len -= op;
  77697. do {
  77698. PUP(out) = PUP(from);
  77699. } while (--op);
  77700. from = out - dist; /* rest from output */
  77701. }
  77702. }
  77703. else if (write < op) { /* wrap around window */
  77704. from += wsize + write - op;
  77705. op -= write;
  77706. if (op < len) { /* some from end of window */
  77707. len -= op;
  77708. do {
  77709. PUP(out) = PUP(from);
  77710. } while (--op);
  77711. from = window - OFF;
  77712. if (write < len) { /* some from start of window */
  77713. op = write;
  77714. len -= op;
  77715. do {
  77716. PUP(out) = PUP(from);
  77717. } while (--op);
  77718. from = out - dist; /* rest from output */
  77719. }
  77720. }
  77721. }
  77722. else { /* contiguous in window */
  77723. from += write - op;
  77724. if (op < len) { /* some from window */
  77725. len -= op;
  77726. do {
  77727. PUP(out) = PUP(from);
  77728. } while (--op);
  77729. from = out - dist; /* rest from output */
  77730. }
  77731. }
  77732. while (len > 2) {
  77733. PUP(out) = PUP(from);
  77734. PUP(out) = PUP(from);
  77735. PUP(out) = PUP(from);
  77736. len -= 3;
  77737. }
  77738. if (len) {
  77739. PUP(out) = PUP(from);
  77740. if (len > 1)
  77741. PUP(out) = PUP(from);
  77742. }
  77743. }
  77744. else {
  77745. from = out - dist; /* copy direct from output */
  77746. do { /* minimum length is three */
  77747. PUP(out) = PUP(from);
  77748. PUP(out) = PUP(from);
  77749. PUP(out) = PUP(from);
  77750. len -= 3;
  77751. } while (len > 2);
  77752. if (len) {
  77753. PUP(out) = PUP(from);
  77754. if (len > 1)
  77755. PUP(out) = PUP(from);
  77756. }
  77757. }
  77758. }
  77759. else if ((op & 64) == 0) { /* 2nd level distance code */
  77760. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77761. goto dodist;
  77762. }
  77763. else {
  77764. strm->msg = (char *)"invalid distance code";
  77765. state->mode = BAD;
  77766. break;
  77767. }
  77768. }
  77769. else if ((op & 64) == 0) { /* 2nd level length code */
  77770. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77771. goto dolen;
  77772. }
  77773. else if (op & 32) { /* end-of-block */
  77774. Tracevv((stderr, "inflate: end of block\n"));
  77775. state->mode = TYPE;
  77776. break;
  77777. }
  77778. else {
  77779. strm->msg = (char *)"invalid literal/length code";
  77780. state->mode = BAD;
  77781. break;
  77782. }
  77783. } while (in < last && out < end);
  77784. len = bits >> 3;
  77785. in -= len;
  77786. bits -= len << 3;
  77787. hold &= (1U << bits) - 1;
  77788. strm->next_in = in + OFF;
  77789. strm->next_out = out + OFF;
  77790. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77791. strm->avail_out = (unsigned)(out < end ?
  77792. 257 + (end - out) : 257 - (out - end));
  77793. state->hold = hold;
  77794. state->bits = bits;
  77795. return;
  77796. }
  77797. #endif /* !ASMINF */
  77798. /*** End of inlined file: inffast.c ***/
  77799. #undef PULLBYTE
  77800. #undef LOAD
  77801. #undef RESTORE
  77802. #undef INITBITS
  77803. #undef NEEDBITS
  77804. #undef DROPBITS
  77805. #undef BYTEBITS
  77806. /*** Start of inlined file: inflate.c ***/
  77807. /*** Start of inlined file: inffast.h ***/
  77808. void inflate_fast OF((z_streamp strm, unsigned start));
  77809. /*** End of inlined file: inffast.h ***/
  77810. #ifdef MAKEFIXED
  77811. # ifndef BUILDFIXED
  77812. # define BUILDFIXED
  77813. # endif
  77814. #endif
  77815. local void fixedtables OF((struct inflate_state FAR *state));
  77816. local int updatewindow OF((z_streamp strm, unsigned out));
  77817. #ifdef BUILDFIXED
  77818. void makefixed OF((void));
  77819. #endif
  77820. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  77821. unsigned len));
  77822. int ZEXPORT inflateReset (z_streamp strm)
  77823. {
  77824. struct inflate_state FAR *state;
  77825. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77826. state = (struct inflate_state FAR *)strm->state;
  77827. strm->total_in = strm->total_out = state->total = 0;
  77828. strm->msg = Z_NULL;
  77829. strm->adler = 1; /* to support ill-conceived Java test suite */
  77830. state->mode = HEAD;
  77831. state->last = 0;
  77832. state->havedict = 0;
  77833. state->dmax = 32768U;
  77834. state->head = Z_NULL;
  77835. state->wsize = 0;
  77836. state->whave = 0;
  77837. state->write = 0;
  77838. state->hold = 0;
  77839. state->bits = 0;
  77840. state->lencode = state->distcode = state->next = state->codes;
  77841. Tracev((stderr, "inflate: reset\n"));
  77842. return Z_OK;
  77843. }
  77844. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  77845. {
  77846. struct inflate_state FAR *state;
  77847. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77848. state = (struct inflate_state FAR *)strm->state;
  77849. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  77850. value &= (1L << bits) - 1;
  77851. state->hold += value << state->bits;
  77852. state->bits += bits;
  77853. return Z_OK;
  77854. }
  77855. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  77856. {
  77857. struct inflate_state FAR *state;
  77858. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  77859. stream_size != (int)(sizeof(z_stream)))
  77860. return Z_VERSION_ERROR;
  77861. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77862. strm->msg = Z_NULL; /* in case we return an error */
  77863. if (strm->zalloc == (alloc_func)0) {
  77864. strm->zalloc = zcalloc;
  77865. strm->opaque = (voidpf)0;
  77866. }
  77867. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77868. state = (struct inflate_state FAR *)
  77869. ZALLOC(strm, 1, sizeof(struct inflate_state));
  77870. if (state == Z_NULL) return Z_MEM_ERROR;
  77871. Tracev((stderr, "inflate: allocated\n"));
  77872. strm->state = (struct internal_state FAR *)state;
  77873. if (windowBits < 0) {
  77874. state->wrap = 0;
  77875. windowBits = -windowBits;
  77876. }
  77877. else {
  77878. state->wrap = (windowBits >> 4) + 1;
  77879. #ifdef GUNZIP
  77880. if (windowBits < 48) windowBits &= 15;
  77881. #endif
  77882. }
  77883. if (windowBits < 8 || windowBits > 15) {
  77884. ZFREE(strm, state);
  77885. strm->state = Z_NULL;
  77886. return Z_STREAM_ERROR;
  77887. }
  77888. state->wbits = (unsigned)windowBits;
  77889. state->window = Z_NULL;
  77890. return inflateReset(strm);
  77891. }
  77892. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  77893. {
  77894. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  77895. }
  77896. local void fixedtables (struct inflate_state FAR *state)
  77897. {
  77898. #ifdef BUILDFIXED
  77899. static int virgin = 1;
  77900. static code *lenfix, *distfix;
  77901. static code fixed[544];
  77902. if (virgin) {
  77903. unsigned sym, bits;
  77904. static code *next;
  77905. sym = 0;
  77906. while (sym < 144) state->lens[sym++] = 8;
  77907. while (sym < 256) state->lens[sym++] = 9;
  77908. while (sym < 280) state->lens[sym++] = 7;
  77909. while (sym < 288) state->lens[sym++] = 8;
  77910. next = fixed;
  77911. lenfix = next;
  77912. bits = 9;
  77913. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  77914. sym = 0;
  77915. while (sym < 32) state->lens[sym++] = 5;
  77916. distfix = next;
  77917. bits = 5;
  77918. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  77919. virgin = 0;
  77920. }
  77921. #else /* !BUILDFIXED */
  77922. /*** Start of inlined file: inffixed.h ***/
  77923. static const code lenfix[512] = {
  77924. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  77925. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  77926. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  77927. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  77928. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  77929. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  77930. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  77931. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  77932. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  77933. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  77934. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  77935. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  77936. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  77937. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  77938. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  77939. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  77940. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  77941. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  77942. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  77943. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  77944. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  77945. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  77946. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  77947. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  77948. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  77949. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  77950. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  77951. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  77952. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  77953. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  77954. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  77955. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  77956. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  77957. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  77958. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  77959. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  77960. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  77961. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  77962. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  77963. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  77964. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  77965. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  77966. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  77967. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  77968. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  77969. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  77970. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  77971. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  77972. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  77973. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  77974. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  77975. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  77976. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  77977. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  77978. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  77979. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  77980. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  77981. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  77982. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  77983. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  77984. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  77985. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  77986. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  77987. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  77988. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  77989. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  77990. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  77991. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  77992. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  77993. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  77994. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  77995. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  77996. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  77997. {0,9,255}
  77998. };
  77999. static const code distfix[32] = {
  78000. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78001. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78002. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78003. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78004. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78005. {22,5,193},{64,5,0}
  78006. };
  78007. /*** End of inlined file: inffixed.h ***/
  78008. #endif /* BUILDFIXED */
  78009. state->lencode = lenfix;
  78010. state->lenbits = 9;
  78011. state->distcode = distfix;
  78012. state->distbits = 5;
  78013. }
  78014. #ifdef MAKEFIXED
  78015. #include <stdio.h>
  78016. void makefixed()
  78017. {
  78018. unsigned low, size;
  78019. struct inflate_state state;
  78020. fixedtables(&state);
  78021. puts(" /* inffixed.h -- table for decoding fixed codes");
  78022. puts(" * Generated automatically by makefixed().");
  78023. puts(" */");
  78024. puts("");
  78025. puts(" /* WARNING: this file should *not* be used by applications.");
  78026. puts(" It is part of the implementation of this library and is");
  78027. puts(" subject to change. Applications should only use zlib.h.");
  78028. puts(" */");
  78029. puts("");
  78030. size = 1U << 9;
  78031. printf(" static const code lenfix[%u] = {", size);
  78032. low = 0;
  78033. for (;;) {
  78034. if ((low % 7) == 0) printf("\n ");
  78035. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78036. state.lencode[low].val);
  78037. if (++low == size) break;
  78038. putchar(',');
  78039. }
  78040. puts("\n };");
  78041. size = 1U << 5;
  78042. printf("\n static const code distfix[%u] = {", size);
  78043. low = 0;
  78044. for (;;) {
  78045. if ((low % 6) == 0) printf("\n ");
  78046. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78047. state.distcode[low].val);
  78048. if (++low == size) break;
  78049. putchar(',');
  78050. }
  78051. puts("\n };");
  78052. }
  78053. #endif /* MAKEFIXED */
  78054. local int updatewindow (z_streamp strm, unsigned out)
  78055. {
  78056. struct inflate_state FAR *state;
  78057. unsigned copy, dist;
  78058. state = (struct inflate_state FAR *)strm->state;
  78059. if (state->window == Z_NULL) {
  78060. state->window = (unsigned char FAR *)
  78061. ZALLOC(strm, 1U << state->wbits,
  78062. sizeof(unsigned char));
  78063. if (state->window == Z_NULL) return 1;
  78064. }
  78065. if (state->wsize == 0) {
  78066. state->wsize = 1U << state->wbits;
  78067. state->write = 0;
  78068. state->whave = 0;
  78069. }
  78070. copy = out - strm->avail_out;
  78071. if (copy >= state->wsize) {
  78072. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78073. state->write = 0;
  78074. state->whave = state->wsize;
  78075. }
  78076. else {
  78077. dist = state->wsize - state->write;
  78078. if (dist > copy) dist = copy;
  78079. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78080. copy -= dist;
  78081. if (copy) {
  78082. zmemcpy(state->window, strm->next_out - copy, copy);
  78083. state->write = copy;
  78084. state->whave = state->wsize;
  78085. }
  78086. else {
  78087. state->write += dist;
  78088. if (state->write == state->wsize) state->write = 0;
  78089. if (state->whave < state->wsize) state->whave += dist;
  78090. }
  78091. }
  78092. return 0;
  78093. }
  78094. #ifdef GUNZIP
  78095. # define UPDATE(check, buf, len) \
  78096. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78097. #else
  78098. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78099. #endif
  78100. #ifdef GUNZIP
  78101. # define CRC2(check, word) \
  78102. do { \
  78103. hbuf[0] = (unsigned char)(word); \
  78104. hbuf[1] = (unsigned char)((word) >> 8); \
  78105. check = crc32(check, hbuf, 2); \
  78106. } while (0)
  78107. # define CRC4(check, word) \
  78108. do { \
  78109. hbuf[0] = (unsigned char)(word); \
  78110. hbuf[1] = (unsigned char)((word) >> 8); \
  78111. hbuf[2] = (unsigned char)((word) >> 16); \
  78112. hbuf[3] = (unsigned char)((word) >> 24); \
  78113. check = crc32(check, hbuf, 4); \
  78114. } while (0)
  78115. #endif
  78116. #define LOAD() \
  78117. do { \
  78118. put = strm->next_out; \
  78119. left = strm->avail_out; \
  78120. next = strm->next_in; \
  78121. have = strm->avail_in; \
  78122. hold = state->hold; \
  78123. bits = state->bits; \
  78124. } while (0)
  78125. #define RESTORE() \
  78126. do { \
  78127. strm->next_out = put; \
  78128. strm->avail_out = left; \
  78129. strm->next_in = next; \
  78130. strm->avail_in = have; \
  78131. state->hold = hold; \
  78132. state->bits = bits; \
  78133. } while (0)
  78134. #define INITBITS() \
  78135. do { \
  78136. hold = 0; \
  78137. bits = 0; \
  78138. } while (0)
  78139. #define PULLBYTE() \
  78140. do { \
  78141. if (have == 0) goto inf_leave; \
  78142. have--; \
  78143. hold += (unsigned long)(*next++) << bits; \
  78144. bits += 8; \
  78145. } while (0)
  78146. #define NEEDBITS(n) \
  78147. do { \
  78148. while (bits < (unsigned)(n)) \
  78149. PULLBYTE(); \
  78150. } while (0)
  78151. #define BITS(n) \
  78152. ((unsigned)hold & ((1U << (n)) - 1))
  78153. #define DROPBITS(n) \
  78154. do { \
  78155. hold >>= (n); \
  78156. bits -= (unsigned)(n); \
  78157. } while (0)
  78158. #define BYTEBITS() \
  78159. do { \
  78160. hold >>= bits & 7; \
  78161. bits -= bits & 7; \
  78162. } while (0)
  78163. #define REVERSE(q) \
  78164. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78165. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78166. int ZEXPORT inflate (z_streamp strm, int flush)
  78167. {
  78168. struct inflate_state FAR *state;
  78169. unsigned char FAR *next; /* next input */
  78170. unsigned char FAR *put; /* next output */
  78171. unsigned have, left; /* available input and output */
  78172. unsigned long hold; /* bit buffer */
  78173. unsigned bits; /* bits in bit buffer */
  78174. unsigned in, out; /* save starting available input and output */
  78175. unsigned copy; /* number of stored or match bytes to copy */
  78176. unsigned char FAR *from; /* where to copy match bytes from */
  78177. code thisx; /* current decoding table entry */
  78178. code last; /* parent table entry */
  78179. unsigned len; /* length to copy for repeats, bits to drop */
  78180. int ret; /* return code */
  78181. #ifdef GUNZIP
  78182. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78183. #endif
  78184. static const unsigned short order[19] = /* permutation of code lengths */
  78185. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78186. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78187. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78188. return Z_STREAM_ERROR;
  78189. state = (struct inflate_state FAR *)strm->state;
  78190. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78191. LOAD();
  78192. in = have;
  78193. out = left;
  78194. ret = Z_OK;
  78195. for (;;)
  78196. switch (state->mode) {
  78197. case HEAD:
  78198. if (state->wrap == 0) {
  78199. state->mode = TYPEDO;
  78200. break;
  78201. }
  78202. NEEDBITS(16);
  78203. #ifdef GUNZIP
  78204. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78205. state->check = crc32(0L, Z_NULL, 0);
  78206. CRC2(state->check, hold);
  78207. INITBITS();
  78208. state->mode = FLAGS;
  78209. break;
  78210. }
  78211. state->flags = 0; /* expect zlib header */
  78212. if (state->head != Z_NULL)
  78213. state->head->done = -1;
  78214. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78215. #else
  78216. if (
  78217. #endif
  78218. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78219. strm->msg = (char *)"incorrect header check";
  78220. state->mode = BAD;
  78221. break;
  78222. }
  78223. if (BITS(4) != Z_DEFLATED) {
  78224. strm->msg = (char *)"unknown compression method";
  78225. state->mode = BAD;
  78226. break;
  78227. }
  78228. DROPBITS(4);
  78229. len = BITS(4) + 8;
  78230. if (len > state->wbits) {
  78231. strm->msg = (char *)"invalid window size";
  78232. state->mode = BAD;
  78233. break;
  78234. }
  78235. state->dmax = 1U << len;
  78236. Tracev((stderr, "inflate: zlib header ok\n"));
  78237. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78238. state->mode = hold & 0x200 ? DICTID : TYPE;
  78239. INITBITS();
  78240. break;
  78241. #ifdef GUNZIP
  78242. case FLAGS:
  78243. NEEDBITS(16);
  78244. state->flags = (int)(hold);
  78245. if ((state->flags & 0xff) != Z_DEFLATED) {
  78246. strm->msg = (char *)"unknown compression method";
  78247. state->mode = BAD;
  78248. break;
  78249. }
  78250. if (state->flags & 0xe000) {
  78251. strm->msg = (char *)"unknown header flags set";
  78252. state->mode = BAD;
  78253. break;
  78254. }
  78255. if (state->head != Z_NULL)
  78256. state->head->text = (int)((hold >> 8) & 1);
  78257. if (state->flags & 0x0200) CRC2(state->check, hold);
  78258. INITBITS();
  78259. state->mode = TIME;
  78260. case TIME:
  78261. NEEDBITS(32);
  78262. if (state->head != Z_NULL)
  78263. state->head->time = hold;
  78264. if (state->flags & 0x0200) CRC4(state->check, hold);
  78265. INITBITS();
  78266. state->mode = OS;
  78267. case OS:
  78268. NEEDBITS(16);
  78269. if (state->head != Z_NULL) {
  78270. state->head->xflags = (int)(hold & 0xff);
  78271. state->head->os = (int)(hold >> 8);
  78272. }
  78273. if (state->flags & 0x0200) CRC2(state->check, hold);
  78274. INITBITS();
  78275. state->mode = EXLEN;
  78276. case EXLEN:
  78277. if (state->flags & 0x0400) {
  78278. NEEDBITS(16);
  78279. state->length = (unsigned)(hold);
  78280. if (state->head != Z_NULL)
  78281. state->head->extra_len = (unsigned)hold;
  78282. if (state->flags & 0x0200) CRC2(state->check, hold);
  78283. INITBITS();
  78284. }
  78285. else if (state->head != Z_NULL)
  78286. state->head->extra = Z_NULL;
  78287. state->mode = EXTRA;
  78288. case EXTRA:
  78289. if (state->flags & 0x0400) {
  78290. copy = state->length;
  78291. if (copy > have) copy = have;
  78292. if (copy) {
  78293. if (state->head != Z_NULL &&
  78294. state->head->extra != Z_NULL) {
  78295. len = state->head->extra_len - state->length;
  78296. zmemcpy(state->head->extra + len, next,
  78297. len + copy > state->head->extra_max ?
  78298. state->head->extra_max - len : copy);
  78299. }
  78300. if (state->flags & 0x0200)
  78301. state->check = crc32(state->check, next, copy);
  78302. have -= copy;
  78303. next += copy;
  78304. state->length -= copy;
  78305. }
  78306. if (state->length) goto inf_leave;
  78307. }
  78308. state->length = 0;
  78309. state->mode = NAME;
  78310. case NAME:
  78311. if (state->flags & 0x0800) {
  78312. if (have == 0) goto inf_leave;
  78313. copy = 0;
  78314. do {
  78315. len = (unsigned)(next[copy++]);
  78316. if (state->head != Z_NULL &&
  78317. state->head->name != Z_NULL &&
  78318. state->length < state->head->name_max)
  78319. state->head->name[state->length++] = len;
  78320. } while (len && copy < have);
  78321. if (state->flags & 0x0200)
  78322. state->check = crc32(state->check, next, copy);
  78323. have -= copy;
  78324. next += copy;
  78325. if (len) goto inf_leave;
  78326. }
  78327. else if (state->head != Z_NULL)
  78328. state->head->name = Z_NULL;
  78329. state->length = 0;
  78330. state->mode = COMMENT;
  78331. case COMMENT:
  78332. if (state->flags & 0x1000) {
  78333. if (have == 0) goto inf_leave;
  78334. copy = 0;
  78335. do {
  78336. len = (unsigned)(next[copy++]);
  78337. if (state->head != Z_NULL &&
  78338. state->head->comment != Z_NULL &&
  78339. state->length < state->head->comm_max)
  78340. state->head->comment[state->length++] = len;
  78341. } while (len && copy < have);
  78342. if (state->flags & 0x0200)
  78343. state->check = crc32(state->check, next, copy);
  78344. have -= copy;
  78345. next += copy;
  78346. if (len) goto inf_leave;
  78347. }
  78348. else if (state->head != Z_NULL)
  78349. state->head->comment = Z_NULL;
  78350. state->mode = HCRC;
  78351. case HCRC:
  78352. if (state->flags & 0x0200) {
  78353. NEEDBITS(16);
  78354. if (hold != (state->check & 0xffff)) {
  78355. strm->msg = (char *)"header crc mismatch";
  78356. state->mode = BAD;
  78357. break;
  78358. }
  78359. INITBITS();
  78360. }
  78361. if (state->head != Z_NULL) {
  78362. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78363. state->head->done = 1;
  78364. }
  78365. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78366. state->mode = TYPE;
  78367. break;
  78368. #endif
  78369. case DICTID:
  78370. NEEDBITS(32);
  78371. strm->adler = state->check = REVERSE(hold);
  78372. INITBITS();
  78373. state->mode = DICT;
  78374. case DICT:
  78375. if (state->havedict == 0) {
  78376. RESTORE();
  78377. return Z_NEED_DICT;
  78378. }
  78379. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78380. state->mode = TYPE;
  78381. case TYPE:
  78382. if (flush == Z_BLOCK) goto inf_leave;
  78383. case TYPEDO:
  78384. if (state->last) {
  78385. BYTEBITS();
  78386. state->mode = CHECK;
  78387. break;
  78388. }
  78389. NEEDBITS(3);
  78390. state->last = BITS(1);
  78391. DROPBITS(1);
  78392. switch (BITS(2)) {
  78393. case 0: /* stored block */
  78394. Tracev((stderr, "inflate: stored block%s\n",
  78395. state->last ? " (last)" : ""));
  78396. state->mode = STORED;
  78397. break;
  78398. case 1: /* fixed block */
  78399. fixedtables(state);
  78400. Tracev((stderr, "inflate: fixed codes block%s\n",
  78401. state->last ? " (last)" : ""));
  78402. state->mode = LEN; /* decode codes */
  78403. break;
  78404. case 2: /* dynamic block */
  78405. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78406. state->last ? " (last)" : ""));
  78407. state->mode = TABLE;
  78408. break;
  78409. case 3:
  78410. strm->msg = (char *)"invalid block type";
  78411. state->mode = BAD;
  78412. }
  78413. DROPBITS(2);
  78414. break;
  78415. case STORED:
  78416. BYTEBITS(); /* go to byte boundary */
  78417. NEEDBITS(32);
  78418. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78419. strm->msg = (char *)"invalid stored block lengths";
  78420. state->mode = BAD;
  78421. break;
  78422. }
  78423. state->length = (unsigned)hold & 0xffff;
  78424. Tracev((stderr, "inflate: stored length %u\n",
  78425. state->length));
  78426. INITBITS();
  78427. state->mode = COPY;
  78428. case COPY:
  78429. copy = state->length;
  78430. if (copy) {
  78431. if (copy > have) copy = have;
  78432. if (copy > left) copy = left;
  78433. if (copy == 0) goto inf_leave;
  78434. zmemcpy(put, next, copy);
  78435. have -= copy;
  78436. next += copy;
  78437. left -= copy;
  78438. put += copy;
  78439. state->length -= copy;
  78440. break;
  78441. }
  78442. Tracev((stderr, "inflate: stored end\n"));
  78443. state->mode = TYPE;
  78444. break;
  78445. case TABLE:
  78446. NEEDBITS(14);
  78447. state->nlen = BITS(5) + 257;
  78448. DROPBITS(5);
  78449. state->ndist = BITS(5) + 1;
  78450. DROPBITS(5);
  78451. state->ncode = BITS(4) + 4;
  78452. DROPBITS(4);
  78453. #ifndef PKZIP_BUG_WORKAROUND
  78454. if (state->nlen > 286 || state->ndist > 30) {
  78455. strm->msg = (char *)"too many length or distance symbols";
  78456. state->mode = BAD;
  78457. break;
  78458. }
  78459. #endif
  78460. Tracev((stderr, "inflate: table sizes ok\n"));
  78461. state->have = 0;
  78462. state->mode = LENLENS;
  78463. case LENLENS:
  78464. while (state->have < state->ncode) {
  78465. NEEDBITS(3);
  78466. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78467. DROPBITS(3);
  78468. }
  78469. while (state->have < 19)
  78470. state->lens[order[state->have++]] = 0;
  78471. state->next = state->codes;
  78472. state->lencode = (code const FAR *)(state->next);
  78473. state->lenbits = 7;
  78474. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78475. &(state->lenbits), state->work);
  78476. if (ret) {
  78477. strm->msg = (char *)"invalid code lengths set";
  78478. state->mode = BAD;
  78479. break;
  78480. }
  78481. Tracev((stderr, "inflate: code lengths ok\n"));
  78482. state->have = 0;
  78483. state->mode = CODELENS;
  78484. case CODELENS:
  78485. while (state->have < state->nlen + state->ndist) {
  78486. for (;;) {
  78487. thisx = state->lencode[BITS(state->lenbits)];
  78488. if ((unsigned)(thisx.bits) <= bits) break;
  78489. PULLBYTE();
  78490. }
  78491. if (thisx.val < 16) {
  78492. NEEDBITS(thisx.bits);
  78493. DROPBITS(thisx.bits);
  78494. state->lens[state->have++] = thisx.val;
  78495. }
  78496. else {
  78497. if (thisx.val == 16) {
  78498. NEEDBITS(thisx.bits + 2);
  78499. DROPBITS(thisx.bits);
  78500. if (state->have == 0) {
  78501. strm->msg = (char *)"invalid bit length repeat";
  78502. state->mode = BAD;
  78503. break;
  78504. }
  78505. len = state->lens[state->have - 1];
  78506. copy = 3 + BITS(2);
  78507. DROPBITS(2);
  78508. }
  78509. else if (thisx.val == 17) {
  78510. NEEDBITS(thisx.bits + 3);
  78511. DROPBITS(thisx.bits);
  78512. len = 0;
  78513. copy = 3 + BITS(3);
  78514. DROPBITS(3);
  78515. }
  78516. else {
  78517. NEEDBITS(thisx.bits + 7);
  78518. DROPBITS(thisx.bits);
  78519. len = 0;
  78520. copy = 11 + BITS(7);
  78521. DROPBITS(7);
  78522. }
  78523. if (state->have + copy > state->nlen + state->ndist) {
  78524. strm->msg = (char *)"invalid bit length repeat";
  78525. state->mode = BAD;
  78526. break;
  78527. }
  78528. while (copy--)
  78529. state->lens[state->have++] = (unsigned short)len;
  78530. }
  78531. }
  78532. if (state->mode == BAD) break;
  78533. state->next = state->codes;
  78534. state->lencode = (code const FAR *)(state->next);
  78535. state->lenbits = 9;
  78536. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78537. &(state->lenbits), state->work);
  78538. if (ret) {
  78539. strm->msg = (char *)"invalid literal/lengths set";
  78540. state->mode = BAD;
  78541. break;
  78542. }
  78543. state->distcode = (code const FAR *)(state->next);
  78544. state->distbits = 6;
  78545. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78546. &(state->next), &(state->distbits), state->work);
  78547. if (ret) {
  78548. strm->msg = (char *)"invalid distances set";
  78549. state->mode = BAD;
  78550. break;
  78551. }
  78552. Tracev((stderr, "inflate: codes ok\n"));
  78553. state->mode = LEN;
  78554. case LEN:
  78555. if (have >= 6 && left >= 258) {
  78556. RESTORE();
  78557. inflate_fast(strm, out);
  78558. LOAD();
  78559. break;
  78560. }
  78561. for (;;) {
  78562. thisx = state->lencode[BITS(state->lenbits)];
  78563. if ((unsigned)(thisx.bits) <= bits) break;
  78564. PULLBYTE();
  78565. }
  78566. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78567. last = thisx;
  78568. for (;;) {
  78569. thisx = state->lencode[last.val +
  78570. (BITS(last.bits + last.op) >> last.bits)];
  78571. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78572. PULLBYTE();
  78573. }
  78574. DROPBITS(last.bits);
  78575. }
  78576. DROPBITS(thisx.bits);
  78577. state->length = (unsigned)thisx.val;
  78578. if ((int)(thisx.op) == 0) {
  78579. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78580. "inflate: literal '%c'\n" :
  78581. "inflate: literal 0x%02x\n", thisx.val));
  78582. state->mode = LIT;
  78583. break;
  78584. }
  78585. if (thisx.op & 32) {
  78586. Tracevv((stderr, "inflate: end of block\n"));
  78587. state->mode = TYPE;
  78588. break;
  78589. }
  78590. if (thisx.op & 64) {
  78591. strm->msg = (char *)"invalid literal/length code";
  78592. state->mode = BAD;
  78593. break;
  78594. }
  78595. state->extra = (unsigned)(thisx.op) & 15;
  78596. state->mode = LENEXT;
  78597. case LENEXT:
  78598. if (state->extra) {
  78599. NEEDBITS(state->extra);
  78600. state->length += BITS(state->extra);
  78601. DROPBITS(state->extra);
  78602. }
  78603. Tracevv((stderr, "inflate: length %u\n", state->length));
  78604. state->mode = DIST;
  78605. case DIST:
  78606. for (;;) {
  78607. thisx = state->distcode[BITS(state->distbits)];
  78608. if ((unsigned)(thisx.bits) <= bits) break;
  78609. PULLBYTE();
  78610. }
  78611. if ((thisx.op & 0xf0) == 0) {
  78612. last = thisx;
  78613. for (;;) {
  78614. thisx = state->distcode[last.val +
  78615. (BITS(last.bits + last.op) >> last.bits)];
  78616. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78617. PULLBYTE();
  78618. }
  78619. DROPBITS(last.bits);
  78620. }
  78621. DROPBITS(thisx.bits);
  78622. if (thisx.op & 64) {
  78623. strm->msg = (char *)"invalid distance code";
  78624. state->mode = BAD;
  78625. break;
  78626. }
  78627. state->offset = (unsigned)thisx.val;
  78628. state->extra = (unsigned)(thisx.op) & 15;
  78629. state->mode = DISTEXT;
  78630. case DISTEXT:
  78631. if (state->extra) {
  78632. NEEDBITS(state->extra);
  78633. state->offset += BITS(state->extra);
  78634. DROPBITS(state->extra);
  78635. }
  78636. #ifdef INFLATE_STRICT
  78637. if (state->offset > state->dmax) {
  78638. strm->msg = (char *)"invalid distance too far back";
  78639. state->mode = BAD;
  78640. break;
  78641. }
  78642. #endif
  78643. if (state->offset > state->whave + out - left) {
  78644. strm->msg = (char *)"invalid distance too far back";
  78645. state->mode = BAD;
  78646. break;
  78647. }
  78648. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78649. state->mode = MATCH;
  78650. case MATCH:
  78651. if (left == 0) goto inf_leave;
  78652. copy = out - left;
  78653. if (state->offset > copy) { /* copy from window */
  78654. copy = state->offset - copy;
  78655. if (copy > state->write) {
  78656. copy -= state->write;
  78657. from = state->window + (state->wsize - copy);
  78658. }
  78659. else
  78660. from = state->window + (state->write - copy);
  78661. if (copy > state->length) copy = state->length;
  78662. }
  78663. else { /* copy from output */
  78664. from = put - state->offset;
  78665. copy = state->length;
  78666. }
  78667. if (copy > left) copy = left;
  78668. left -= copy;
  78669. state->length -= copy;
  78670. do {
  78671. *put++ = *from++;
  78672. } while (--copy);
  78673. if (state->length == 0) state->mode = LEN;
  78674. break;
  78675. case LIT:
  78676. if (left == 0) goto inf_leave;
  78677. *put++ = (unsigned char)(state->length);
  78678. left--;
  78679. state->mode = LEN;
  78680. break;
  78681. case CHECK:
  78682. if (state->wrap) {
  78683. NEEDBITS(32);
  78684. out -= left;
  78685. strm->total_out += out;
  78686. state->total += out;
  78687. if (out)
  78688. strm->adler = state->check =
  78689. UPDATE(state->check, put - out, out);
  78690. out = left;
  78691. if ((
  78692. #ifdef GUNZIP
  78693. state->flags ? hold :
  78694. #endif
  78695. REVERSE(hold)) != state->check) {
  78696. strm->msg = (char *)"incorrect data check";
  78697. state->mode = BAD;
  78698. break;
  78699. }
  78700. INITBITS();
  78701. Tracev((stderr, "inflate: check matches trailer\n"));
  78702. }
  78703. #ifdef GUNZIP
  78704. state->mode = LENGTH;
  78705. case LENGTH:
  78706. if (state->wrap && state->flags) {
  78707. NEEDBITS(32);
  78708. if (hold != (state->total & 0xffffffffUL)) {
  78709. strm->msg = (char *)"incorrect length check";
  78710. state->mode = BAD;
  78711. break;
  78712. }
  78713. INITBITS();
  78714. Tracev((stderr, "inflate: length matches trailer\n"));
  78715. }
  78716. #endif
  78717. state->mode = DONE;
  78718. case DONE:
  78719. ret = Z_STREAM_END;
  78720. goto inf_leave;
  78721. case BAD:
  78722. ret = Z_DATA_ERROR;
  78723. goto inf_leave;
  78724. case MEM:
  78725. return Z_MEM_ERROR;
  78726. case SYNC:
  78727. default:
  78728. return Z_STREAM_ERROR;
  78729. }
  78730. inf_leave:
  78731. RESTORE();
  78732. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78733. if (updatewindow(strm, out)) {
  78734. state->mode = MEM;
  78735. return Z_MEM_ERROR;
  78736. }
  78737. in -= strm->avail_in;
  78738. out -= strm->avail_out;
  78739. strm->total_in += in;
  78740. strm->total_out += out;
  78741. state->total += out;
  78742. if (state->wrap && out)
  78743. strm->adler = state->check =
  78744. UPDATE(state->check, strm->next_out - out, out);
  78745. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78746. (state->mode == TYPE ? 128 : 0);
  78747. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78748. ret = Z_BUF_ERROR;
  78749. return ret;
  78750. }
  78751. int ZEXPORT inflateEnd (z_streamp strm)
  78752. {
  78753. struct inflate_state FAR *state;
  78754. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78755. return Z_STREAM_ERROR;
  78756. state = (struct inflate_state FAR *)strm->state;
  78757. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78758. ZFREE(strm, strm->state);
  78759. strm->state = Z_NULL;
  78760. Tracev((stderr, "inflate: end\n"));
  78761. return Z_OK;
  78762. }
  78763. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78764. {
  78765. struct inflate_state FAR *state;
  78766. unsigned long id_;
  78767. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78768. state = (struct inflate_state FAR *)strm->state;
  78769. if (state->wrap != 0 && state->mode != DICT)
  78770. return Z_STREAM_ERROR;
  78771. if (state->mode == DICT) {
  78772. id_ = adler32(0L, Z_NULL, 0);
  78773. id_ = adler32(id_, dictionary, dictLength);
  78774. if (id_ != state->check)
  78775. return Z_DATA_ERROR;
  78776. }
  78777. if (updatewindow(strm, strm->avail_out)) {
  78778. state->mode = MEM;
  78779. return Z_MEM_ERROR;
  78780. }
  78781. if (dictLength > state->wsize) {
  78782. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78783. state->wsize);
  78784. state->whave = state->wsize;
  78785. }
  78786. else {
  78787. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78788. dictLength);
  78789. state->whave = dictLength;
  78790. }
  78791. state->havedict = 1;
  78792. Tracev((stderr, "inflate: dictionary set\n"));
  78793. return Z_OK;
  78794. }
  78795. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78796. {
  78797. struct inflate_state FAR *state;
  78798. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78799. state = (struct inflate_state FAR *)strm->state;
  78800. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78801. state->head = head;
  78802. head->done = 0;
  78803. return Z_OK;
  78804. }
  78805. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78806. {
  78807. unsigned got;
  78808. unsigned next;
  78809. got = *have;
  78810. next = 0;
  78811. while (next < len && got < 4) {
  78812. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  78813. got++;
  78814. else if (buf[next])
  78815. got = 0;
  78816. else
  78817. got = 4 - got;
  78818. next++;
  78819. }
  78820. *have = got;
  78821. return next;
  78822. }
  78823. int ZEXPORT inflateSync (z_streamp strm)
  78824. {
  78825. unsigned len; /* number of bytes to look at or looked at */
  78826. unsigned long in, out; /* temporary to save total_in and total_out */
  78827. unsigned char buf[4]; /* to restore bit buffer to byte string */
  78828. struct inflate_state FAR *state;
  78829. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78830. state = (struct inflate_state FAR *)strm->state;
  78831. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  78832. if (state->mode != SYNC) {
  78833. state->mode = SYNC;
  78834. state->hold <<= state->bits & 7;
  78835. state->bits -= state->bits & 7;
  78836. len = 0;
  78837. while (state->bits >= 8) {
  78838. buf[len++] = (unsigned char)(state->hold);
  78839. state->hold >>= 8;
  78840. state->bits -= 8;
  78841. }
  78842. state->have = 0;
  78843. syncsearch(&(state->have), buf, len);
  78844. }
  78845. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  78846. strm->avail_in -= len;
  78847. strm->next_in += len;
  78848. strm->total_in += len;
  78849. if (state->have != 4) return Z_DATA_ERROR;
  78850. in = strm->total_in; out = strm->total_out;
  78851. inflateReset(strm);
  78852. strm->total_in = in; strm->total_out = out;
  78853. state->mode = TYPE;
  78854. return Z_OK;
  78855. }
  78856. int ZEXPORT inflateSyncPoint (z_streamp strm)
  78857. {
  78858. struct inflate_state FAR *state;
  78859. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78860. state = (struct inflate_state FAR *)strm->state;
  78861. return state->mode == STORED && state->bits == 0;
  78862. }
  78863. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  78864. {
  78865. struct inflate_state FAR *state;
  78866. struct inflate_state FAR *copy;
  78867. unsigned char FAR *window;
  78868. unsigned wsize;
  78869. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  78870. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  78871. return Z_STREAM_ERROR;
  78872. state = (struct inflate_state FAR *)source->state;
  78873. copy = (struct inflate_state FAR *)
  78874. ZALLOC(source, 1, sizeof(struct inflate_state));
  78875. if (copy == Z_NULL) return Z_MEM_ERROR;
  78876. window = Z_NULL;
  78877. if (state->window != Z_NULL) {
  78878. window = (unsigned char FAR *)
  78879. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  78880. if (window == Z_NULL) {
  78881. ZFREE(source, copy);
  78882. return Z_MEM_ERROR;
  78883. }
  78884. }
  78885. zmemcpy(dest, source, sizeof(z_stream));
  78886. zmemcpy(copy, state, sizeof(struct inflate_state));
  78887. if (state->lencode >= state->codes &&
  78888. state->lencode <= state->codes + ENOUGH - 1) {
  78889. copy->lencode = copy->codes + (state->lencode - state->codes);
  78890. copy->distcode = copy->codes + (state->distcode - state->codes);
  78891. }
  78892. copy->next = copy->codes + (state->next - state->codes);
  78893. if (window != Z_NULL) {
  78894. wsize = 1U << state->wbits;
  78895. zmemcpy(window, state->window, wsize);
  78896. }
  78897. copy->window = window;
  78898. dest->state = (struct internal_state FAR *)copy;
  78899. return Z_OK;
  78900. }
  78901. /*** End of inlined file: inflate.c ***/
  78902. /*** Start of inlined file: inftrees.c ***/
  78903. #define MAXBITS 15
  78904. const char inflate_copyright[] =
  78905. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  78906. int inflate_table (codetype type,
  78907. unsigned short FAR *lens,
  78908. unsigned codes,
  78909. code FAR * FAR *table,
  78910. unsigned FAR *bits,
  78911. unsigned short FAR *work)
  78912. {
  78913. unsigned len; /* a code's length in bits */
  78914. unsigned sym; /* index of code symbols */
  78915. unsigned min, max; /* minimum and maximum code lengths */
  78916. unsigned root; /* number of index bits for root table */
  78917. unsigned curr; /* number of index bits for current table */
  78918. unsigned drop; /* code bits to drop for sub-table */
  78919. int left; /* number of prefix codes available */
  78920. unsigned used; /* code entries in table used */
  78921. unsigned huff; /* Huffman code */
  78922. unsigned incr; /* for incrementing code, index */
  78923. unsigned fill; /* index for replicating entries */
  78924. unsigned low; /* low bits for current root entry */
  78925. unsigned mask; /* mask for low root bits */
  78926. code thisx; /* table entry for duplication */
  78927. code FAR *next; /* next available space in table */
  78928. const unsigned short FAR *base; /* base value table to use */
  78929. const unsigned short FAR *extra; /* extra bits table to use */
  78930. int end; /* use base and extra for symbol > end */
  78931. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  78932. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  78933. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  78934. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  78935. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  78936. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  78937. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  78938. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  78939. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  78940. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  78941. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  78942. 8193, 12289, 16385, 24577, 0, 0};
  78943. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  78944. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  78945. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  78946. 28, 28, 29, 29, 64, 64};
  78947. for (len = 0; len <= MAXBITS; len++)
  78948. count[len] = 0;
  78949. for (sym = 0; sym < codes; sym++)
  78950. count[lens[sym]]++;
  78951. root = *bits;
  78952. for (max = MAXBITS; max >= 1; max--)
  78953. if (count[max] != 0) break;
  78954. if (root > max) root = max;
  78955. if (max == 0) { /* no symbols to code at all */
  78956. thisx.op = (unsigned char)64; /* invalid code marker */
  78957. thisx.bits = (unsigned char)1;
  78958. thisx.val = (unsigned short)0;
  78959. *(*table)++ = thisx; /* make a table to force an error */
  78960. *(*table)++ = thisx;
  78961. *bits = 1;
  78962. return 0; /* no symbols, but wait for decoding to report error */
  78963. }
  78964. for (min = 1; min <= MAXBITS; min++)
  78965. if (count[min] != 0) break;
  78966. if (root < min) root = min;
  78967. left = 1;
  78968. for (len = 1; len <= MAXBITS; len++) {
  78969. left <<= 1;
  78970. left -= count[len];
  78971. if (left < 0) return -1; /* over-subscribed */
  78972. }
  78973. if (left > 0 && (type == CODES || max != 1))
  78974. return -1; /* incomplete set */
  78975. offs[1] = 0;
  78976. for (len = 1; len < MAXBITS; len++)
  78977. offs[len + 1] = offs[len] + count[len];
  78978. for (sym = 0; sym < codes; sym++)
  78979. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  78980. switch (type) {
  78981. case CODES:
  78982. base = extra = work; /* dummy value--not used */
  78983. end = 19;
  78984. break;
  78985. case LENS:
  78986. base = lbase;
  78987. base -= 257;
  78988. extra = lext;
  78989. extra -= 257;
  78990. end = 256;
  78991. break;
  78992. default: /* DISTS */
  78993. base = dbase;
  78994. extra = dext;
  78995. end = -1;
  78996. }
  78997. huff = 0; /* starting code */
  78998. sym = 0; /* starting code symbol */
  78999. len = min; /* starting code length */
  79000. next = *table; /* current table to fill in */
  79001. curr = root; /* current table index bits */
  79002. drop = 0; /* current bits to drop from code for index */
  79003. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79004. used = 1U << root; /* use root table entries */
  79005. mask = used - 1; /* mask for comparing low */
  79006. if (type == LENS && used >= ENOUGH - MAXD)
  79007. return 1;
  79008. for (;;) {
  79009. thisx.bits = (unsigned char)(len - drop);
  79010. if ((int)(work[sym]) < end) {
  79011. thisx.op = (unsigned char)0;
  79012. thisx.val = work[sym];
  79013. }
  79014. else if ((int)(work[sym]) > end) {
  79015. thisx.op = (unsigned char)(extra[work[sym]]);
  79016. thisx.val = base[work[sym]];
  79017. }
  79018. else {
  79019. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79020. thisx.val = 0;
  79021. }
  79022. incr = 1U << (len - drop);
  79023. fill = 1U << curr;
  79024. min = fill; /* save offset to next table */
  79025. do {
  79026. fill -= incr;
  79027. next[(huff >> drop) + fill] = thisx;
  79028. } while (fill != 0);
  79029. incr = 1U << (len - 1);
  79030. while (huff & incr)
  79031. incr >>= 1;
  79032. if (incr != 0) {
  79033. huff &= incr - 1;
  79034. huff += incr;
  79035. }
  79036. else
  79037. huff = 0;
  79038. sym++;
  79039. if (--(count[len]) == 0) {
  79040. if (len == max) break;
  79041. len = lens[work[sym]];
  79042. }
  79043. if (len > root && (huff & mask) != low) {
  79044. if (drop == 0)
  79045. drop = root;
  79046. next += min; /* here min is 1 << curr */
  79047. curr = len - drop;
  79048. left = (int)(1 << curr);
  79049. while (curr + drop < max) {
  79050. left -= count[curr + drop];
  79051. if (left <= 0) break;
  79052. curr++;
  79053. left <<= 1;
  79054. }
  79055. used += 1U << curr;
  79056. if (type == LENS && used >= ENOUGH - MAXD)
  79057. return 1;
  79058. low = huff & mask;
  79059. (*table)[low].op = (unsigned char)curr;
  79060. (*table)[low].bits = (unsigned char)root;
  79061. (*table)[low].val = (unsigned short)(next - *table);
  79062. }
  79063. }
  79064. thisx.op = (unsigned char)64; /* invalid code marker */
  79065. thisx.bits = (unsigned char)(len - drop);
  79066. thisx.val = (unsigned short)0;
  79067. while (huff != 0) {
  79068. if (drop != 0 && (huff & mask) != low) {
  79069. drop = 0;
  79070. len = root;
  79071. next = *table;
  79072. thisx.bits = (unsigned char)len;
  79073. }
  79074. next[huff >> drop] = thisx;
  79075. incr = 1U << (len - 1);
  79076. while (huff & incr)
  79077. incr >>= 1;
  79078. if (incr != 0) {
  79079. huff &= incr - 1;
  79080. huff += incr;
  79081. }
  79082. else
  79083. huff = 0;
  79084. }
  79085. *table += used;
  79086. *bits = root;
  79087. return 0;
  79088. }
  79089. /*** End of inlined file: inftrees.c ***/
  79090. /*** Start of inlined file: trees.c ***/
  79091. #ifdef DEBUG
  79092. # include <ctype.h>
  79093. #endif
  79094. #define MAX_BL_BITS 7
  79095. #define END_BLOCK 256
  79096. #define REP_3_6 16
  79097. #define REPZ_3_10 17
  79098. #define REPZ_11_138 18
  79099. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79100. = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
  79101. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79102. = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
  79103. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79104. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79105. local const uch bl_order[BL_CODES]
  79106. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79107. #define Buf_size (8 * 2*sizeof(char))
  79108. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79109. #if defined(GEN_TREES_H) || !defined(STDC)
  79110. local ct_data static_ltree[L_CODES+2];
  79111. local ct_data static_dtree[D_CODES];
  79112. uch _dist_code[DIST_CODE_LEN];
  79113. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79114. local int base_length[LENGTH_CODES];
  79115. local int base_dist[D_CODES];
  79116. #else
  79117. /*** Start of inlined file: trees.h ***/
  79118. local const ct_data static_ltree[L_CODES+2] = {
  79119. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79120. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79121. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79122. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79123. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79124. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79125. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79126. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79127. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79128. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79129. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79130. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79131. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79132. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79133. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79134. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79135. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79136. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79137. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79138. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79139. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79140. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79141. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79142. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79143. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79144. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79145. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79146. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79147. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79148. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79149. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79150. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79151. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79152. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79153. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79154. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79155. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79156. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79157. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79158. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79159. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79160. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79161. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79162. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79163. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79164. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79165. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79166. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79167. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79168. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79169. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79170. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79171. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79172. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79173. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79174. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79175. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79176. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79177. };
  79178. local const ct_data static_dtree[D_CODES] = {
  79179. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79180. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79181. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79182. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79183. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79184. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79185. };
  79186. const uch _dist_code[DIST_CODE_LEN] = {
  79187. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79188. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79189. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79190. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79191. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79192. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79193. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79194. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79195. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79196. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79197. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79198. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79199. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79200. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79201. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79202. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79203. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79204. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79205. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79206. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79207. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79208. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79209. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79210. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79211. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79212. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79213. };
  79214. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79215. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79216. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79217. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79218. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79219. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79220. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79221. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79222. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79223. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79224. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79225. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79226. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79227. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79228. };
  79229. local const int base_length[LENGTH_CODES] = {
  79230. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79231. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79232. };
  79233. local const int base_dist[D_CODES] = {
  79234. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79235. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79236. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79237. };
  79238. /*** End of inlined file: trees.h ***/
  79239. #endif /* GEN_TREES_H */
  79240. struct static_tree_desc_s {
  79241. const ct_data *static_tree; /* static tree or NULL */
  79242. const intf *extra_bits; /* extra bits for each code or NULL */
  79243. int extra_base; /* base index for extra_bits */
  79244. int elems; /* max number of elements in the tree */
  79245. int max_length; /* max bit length for the codes */
  79246. };
  79247. local static_tree_desc static_l_desc =
  79248. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79249. local static_tree_desc static_d_desc =
  79250. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79251. local static_tree_desc static_bl_desc =
  79252. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79253. local void tr_static_init OF((void));
  79254. local void init_block OF((deflate_state *s));
  79255. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79256. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79257. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79258. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79259. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79260. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79261. local int build_bl_tree OF((deflate_state *s));
  79262. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79263. int blcodes));
  79264. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79265. ct_data *dtree));
  79266. local void set_data_type OF((deflate_state *s));
  79267. local unsigned bi_reverse OF((unsigned value, int length));
  79268. local void bi_windup OF((deflate_state *s));
  79269. local void bi_flush OF((deflate_state *s));
  79270. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79271. int header));
  79272. #ifdef GEN_TREES_H
  79273. local void gen_trees_header OF((void));
  79274. #endif
  79275. #ifndef DEBUG
  79276. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79277. #else /* DEBUG */
  79278. # define send_code(s, c, tree) \
  79279. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79280. send_bits(s, tree[c].Code, tree[c].Len); }
  79281. #endif
  79282. #define put_short(s, w) { \
  79283. put_byte(s, (uch)((w) & 0xff)); \
  79284. put_byte(s, (uch)((ush)(w) >> 8)); \
  79285. }
  79286. #ifdef DEBUG
  79287. local void send_bits OF((deflate_state *s, int value, int length));
  79288. local void send_bits (deflate_state *s, int value, int length)
  79289. {
  79290. Tracevv((stderr," l %2d v %4x ", length, value));
  79291. Assert(length > 0 && length <= 15, "invalid length");
  79292. s->bits_sent += (ulg)length;
  79293. if (s->bi_valid > (int)Buf_size - length) {
  79294. s->bi_buf |= (value << s->bi_valid);
  79295. put_short(s, s->bi_buf);
  79296. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79297. s->bi_valid += length - Buf_size;
  79298. } else {
  79299. s->bi_buf |= value << s->bi_valid;
  79300. s->bi_valid += length;
  79301. }
  79302. }
  79303. #else /* !DEBUG */
  79304. #define send_bits(s, value, length) \
  79305. { int len = length;\
  79306. if (s->bi_valid > (int)Buf_size - len) {\
  79307. int val = value;\
  79308. s->bi_buf |= (val << s->bi_valid);\
  79309. put_short(s, s->bi_buf);\
  79310. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79311. s->bi_valid += len - Buf_size;\
  79312. } else {\
  79313. s->bi_buf |= (value) << s->bi_valid;\
  79314. s->bi_valid += len;\
  79315. }\
  79316. }
  79317. #endif /* DEBUG */
  79318. local void tr_static_init()
  79319. {
  79320. #if defined(GEN_TREES_H) || !defined(STDC)
  79321. static int static_init_done = 0;
  79322. int n; /* iterates over tree elements */
  79323. int bits; /* bit counter */
  79324. int length; /* length value */
  79325. int code; /* code value */
  79326. int dist; /* distance index */
  79327. ush bl_count[MAX_BITS+1];
  79328. if (static_init_done) return;
  79329. static_l_desc.static_tree = static_ltree;
  79330. static_l_desc.extra_bits = extra_lbits;
  79331. static_d_desc.static_tree = static_dtree;
  79332. static_d_desc.extra_bits = extra_dbits;
  79333. static_bl_desc.extra_bits = extra_blbits;
  79334. length = 0;
  79335. for (code = 0; code < LENGTH_CODES-1; code++) {
  79336. base_length[code] = length;
  79337. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79338. _length_code[length++] = (uch)code;
  79339. }
  79340. }
  79341. Assert (length == 256, "tr_static_init: length != 256");
  79342. _length_code[length-1] = (uch)code;
  79343. dist = 0;
  79344. for (code = 0 ; code < 16; code++) {
  79345. base_dist[code] = dist;
  79346. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79347. _dist_code[dist++] = (uch)code;
  79348. }
  79349. }
  79350. Assert (dist == 256, "tr_static_init: dist != 256");
  79351. dist >>= 7; /* from now on, all distances are divided by 128 */
  79352. for ( ; code < D_CODES; code++) {
  79353. base_dist[code] = dist << 7;
  79354. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79355. _dist_code[256 + dist++] = (uch)code;
  79356. }
  79357. }
  79358. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79359. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79360. n = 0;
  79361. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79362. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79363. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79364. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79365. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79366. for (n = 0; n < D_CODES; n++) {
  79367. static_dtree[n].Len = 5;
  79368. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79369. }
  79370. static_init_done = 1;
  79371. # ifdef GEN_TREES_H
  79372. gen_trees_header();
  79373. # endif
  79374. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79375. }
  79376. #ifdef GEN_TREES_H
  79377. # ifndef DEBUG
  79378. # include <stdio.h>
  79379. # endif
  79380. # define SEPARATOR(i, last, width) \
  79381. ((i) == (last)? "\n};\n\n" : \
  79382. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79383. void gen_trees_header()
  79384. {
  79385. FILE *header = fopen("trees.h", "w");
  79386. int i;
  79387. Assert (header != NULL, "Can't open trees.h");
  79388. fprintf(header,
  79389. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79390. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79391. for (i = 0; i < L_CODES+2; i++) {
  79392. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79393. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79394. }
  79395. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79396. for (i = 0; i < D_CODES; i++) {
  79397. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79398. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79399. }
  79400. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79401. for (i = 0; i < DIST_CODE_LEN; i++) {
  79402. fprintf(header, "%2u%s", _dist_code[i],
  79403. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79404. }
  79405. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79406. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79407. fprintf(header, "%2u%s", _length_code[i],
  79408. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79409. }
  79410. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79411. for (i = 0; i < LENGTH_CODES; i++) {
  79412. fprintf(header, "%1u%s", base_length[i],
  79413. SEPARATOR(i, LENGTH_CODES-1, 20));
  79414. }
  79415. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79416. for (i = 0; i < D_CODES; i++) {
  79417. fprintf(header, "%5u%s", base_dist[i],
  79418. SEPARATOR(i, D_CODES-1, 10));
  79419. }
  79420. fclose(header);
  79421. }
  79422. #endif /* GEN_TREES_H */
  79423. void _tr_init(deflate_state *s)
  79424. {
  79425. tr_static_init();
  79426. s->l_desc.dyn_tree = s->dyn_ltree;
  79427. s->l_desc.stat_desc = &static_l_desc;
  79428. s->d_desc.dyn_tree = s->dyn_dtree;
  79429. s->d_desc.stat_desc = &static_d_desc;
  79430. s->bl_desc.dyn_tree = s->bl_tree;
  79431. s->bl_desc.stat_desc = &static_bl_desc;
  79432. s->bi_buf = 0;
  79433. s->bi_valid = 0;
  79434. s->last_eob_len = 8; /* enough lookahead for inflate */
  79435. #ifdef DEBUG
  79436. s->compressed_len = 0L;
  79437. s->bits_sent = 0L;
  79438. #endif
  79439. init_block(s);
  79440. }
  79441. local void init_block (deflate_state *s)
  79442. {
  79443. int n; /* iterates over tree elements */
  79444. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79445. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79446. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79447. s->dyn_ltree[END_BLOCK].Freq = 1;
  79448. s->opt_len = s->static_len = 0L;
  79449. s->last_lit = s->matches = 0;
  79450. }
  79451. #define SMALLEST 1
  79452. #define pqremove(s, tree, top) \
  79453. {\
  79454. top = s->heap[SMALLEST]; \
  79455. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79456. pqdownheap(s, tree, SMALLEST); \
  79457. }
  79458. #define smaller(tree, n, m, depth) \
  79459. (tree[n].Freq < tree[m].Freq || \
  79460. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79461. local void pqdownheap (deflate_state *s,
  79462. ct_data *tree, /* the tree to restore */
  79463. int k) /* node to move down */
  79464. {
  79465. int v = s->heap[k];
  79466. int j = k << 1; /* left son of k */
  79467. while (j <= s->heap_len) {
  79468. if (j < s->heap_len &&
  79469. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79470. j++;
  79471. }
  79472. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79473. s->heap[k] = s->heap[j]; k = j;
  79474. j <<= 1;
  79475. }
  79476. s->heap[k] = v;
  79477. }
  79478. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79479. {
  79480. ct_data *tree = desc->dyn_tree;
  79481. int max_code = desc->max_code;
  79482. const ct_data *stree = desc->stat_desc->static_tree;
  79483. const intf *extra = desc->stat_desc->extra_bits;
  79484. int base = desc->stat_desc->extra_base;
  79485. int max_length = desc->stat_desc->max_length;
  79486. int h; /* heap index */
  79487. int n, m; /* iterate over the tree elements */
  79488. int bits; /* bit length */
  79489. int xbits; /* extra bits */
  79490. ush f; /* frequency */
  79491. int overflow = 0; /* number of elements with bit length too large */
  79492. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79493. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79494. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79495. n = s->heap[h];
  79496. bits = tree[tree[n].Dad].Len + 1;
  79497. if (bits > max_length) bits = max_length, overflow++;
  79498. tree[n].Len = (ush)bits;
  79499. if (n > max_code) continue; /* not a leaf node */
  79500. s->bl_count[bits]++;
  79501. xbits = 0;
  79502. if (n >= base) xbits = extra[n-base];
  79503. f = tree[n].Freq;
  79504. s->opt_len += (ulg)f * (bits + xbits);
  79505. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79506. }
  79507. if (overflow == 0) return;
  79508. Trace((stderr,"\nbit length overflow\n"));
  79509. do {
  79510. bits = max_length-1;
  79511. while (s->bl_count[bits] == 0) bits--;
  79512. s->bl_count[bits]--; /* move one leaf down the tree */
  79513. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79514. s->bl_count[max_length]--;
  79515. overflow -= 2;
  79516. } while (overflow > 0);
  79517. for (bits = max_length; bits != 0; bits--) {
  79518. n = s->bl_count[bits];
  79519. while (n != 0) {
  79520. m = s->heap[--h];
  79521. if (m > max_code) continue;
  79522. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79523. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79524. s->opt_len += ((long)bits - (long)tree[m].Len)
  79525. *(long)tree[m].Freq;
  79526. tree[m].Len = (ush)bits;
  79527. }
  79528. n--;
  79529. }
  79530. }
  79531. }
  79532. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79533. int max_code, /* largest code with non zero frequency */
  79534. ushf *bl_count) /* number of codes at each bit length */
  79535. {
  79536. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79537. ush code = 0; /* running code value */
  79538. int bits; /* bit index */
  79539. int n; /* code index */
  79540. for (bits = 1; bits <= MAX_BITS; bits++) {
  79541. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79542. }
  79543. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79544. "inconsistent bit counts");
  79545. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79546. for (n = 0; n <= max_code; n++) {
  79547. int len = tree[n].Len;
  79548. if (len == 0) continue;
  79549. tree[n].Code = bi_reverse(next_code[len]++, len);
  79550. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79551. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79552. }
  79553. }
  79554. local void build_tree (deflate_state *s,
  79555. tree_desc *desc) /* the tree descriptor */
  79556. {
  79557. ct_data *tree = desc->dyn_tree;
  79558. const ct_data *stree = desc->stat_desc->static_tree;
  79559. int elems = desc->stat_desc->elems;
  79560. int n, m; /* iterate over heap elements */
  79561. int max_code = -1; /* largest code with non zero frequency */
  79562. int node; /* new node being created */
  79563. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79564. for (n = 0; n < elems; n++) {
  79565. if (tree[n].Freq != 0) {
  79566. s->heap[++(s->heap_len)] = max_code = n;
  79567. s->depth[n] = 0;
  79568. } else {
  79569. tree[n].Len = 0;
  79570. }
  79571. }
  79572. while (s->heap_len < 2) {
  79573. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79574. tree[node].Freq = 1;
  79575. s->depth[node] = 0;
  79576. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79577. }
  79578. desc->max_code = max_code;
  79579. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79580. node = elems; /* next internal node of the tree */
  79581. do {
  79582. pqremove(s, tree, n); /* n = node of least frequency */
  79583. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79584. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79585. s->heap[--(s->heap_max)] = m;
  79586. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79587. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79588. s->depth[n] : s->depth[m]) + 1);
  79589. tree[n].Dad = tree[m].Dad = (ush)node;
  79590. #ifdef DUMP_BL_TREE
  79591. if (tree == s->bl_tree) {
  79592. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79593. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79594. }
  79595. #endif
  79596. s->heap[SMALLEST] = node++;
  79597. pqdownheap(s, tree, SMALLEST);
  79598. } while (s->heap_len >= 2);
  79599. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79600. gen_bitlen(s, (tree_desc *)desc);
  79601. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79602. }
  79603. local void scan_tree (deflate_state *s,
  79604. ct_data *tree, /* the tree to be scanned */
  79605. int max_code) /* and its largest code of non zero frequency */
  79606. {
  79607. int n; /* iterates over all tree elements */
  79608. int prevlen = -1; /* last emitted length */
  79609. int curlen; /* length of current code */
  79610. int nextlen = tree[0].Len; /* length of next code */
  79611. int count = 0; /* repeat count of the current code */
  79612. int max_count = 7; /* max repeat count */
  79613. int min_count = 4; /* min repeat count */
  79614. if (nextlen == 0) max_count = 138, min_count = 3;
  79615. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79616. for (n = 0; n <= max_code; n++) {
  79617. curlen = nextlen; nextlen = tree[n+1].Len;
  79618. if (++count < max_count && curlen == nextlen) {
  79619. continue;
  79620. } else if (count < min_count) {
  79621. s->bl_tree[curlen].Freq += count;
  79622. } else if (curlen != 0) {
  79623. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79624. s->bl_tree[REP_3_6].Freq++;
  79625. } else if (count <= 10) {
  79626. s->bl_tree[REPZ_3_10].Freq++;
  79627. } else {
  79628. s->bl_tree[REPZ_11_138].Freq++;
  79629. }
  79630. count = 0; prevlen = curlen;
  79631. if (nextlen == 0) {
  79632. max_count = 138, min_count = 3;
  79633. } else if (curlen == nextlen) {
  79634. max_count = 6, min_count = 3;
  79635. } else {
  79636. max_count = 7, min_count = 4;
  79637. }
  79638. }
  79639. }
  79640. local void send_tree (deflate_state *s,
  79641. ct_data *tree, /* the tree to be scanned */
  79642. int max_code) /* and its largest code of non zero frequency */
  79643. {
  79644. int n; /* iterates over all tree elements */
  79645. int prevlen = -1; /* last emitted length */
  79646. int curlen; /* length of current code */
  79647. int nextlen = tree[0].Len; /* length of next code */
  79648. int count = 0; /* repeat count of the current code */
  79649. int max_count = 7; /* max repeat count */
  79650. int min_count = 4; /* min repeat count */
  79651. /* guard already set */
  79652. if (nextlen == 0) max_count = 138, min_count = 3;
  79653. for (n = 0; n <= max_code; n++) {
  79654. curlen = nextlen; nextlen = tree[n+1].Len;
  79655. if (++count < max_count && curlen == nextlen) {
  79656. continue;
  79657. } else if (count < min_count) {
  79658. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79659. } else if (curlen != 0) {
  79660. if (curlen != prevlen) {
  79661. send_code(s, curlen, s->bl_tree); count--;
  79662. }
  79663. Assert(count >= 3 && count <= 6, " 3_6?");
  79664. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79665. } else if (count <= 10) {
  79666. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79667. } else {
  79668. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79669. }
  79670. count = 0; prevlen = curlen;
  79671. if (nextlen == 0) {
  79672. max_count = 138, min_count = 3;
  79673. } else if (curlen == nextlen) {
  79674. max_count = 6, min_count = 3;
  79675. } else {
  79676. max_count = 7, min_count = 4;
  79677. }
  79678. }
  79679. }
  79680. local int build_bl_tree (deflate_state *s)
  79681. {
  79682. int max_blindex; /* index of last bit length code of non zero freq */
  79683. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79684. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79685. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79686. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79687. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79688. }
  79689. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79690. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79691. s->opt_len, s->static_len));
  79692. return max_blindex;
  79693. }
  79694. local void send_all_trees (deflate_state *s,
  79695. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79696. {
  79697. int rank; /* index in bl_order */
  79698. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79699. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79700. "too many codes");
  79701. Tracev((stderr, "\nbl counts: "));
  79702. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79703. send_bits(s, dcodes-1, 5);
  79704. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79705. for (rank = 0; rank < blcodes; rank++) {
  79706. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79707. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79708. }
  79709. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79710. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79711. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79712. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79713. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79714. }
  79715. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79716. {
  79717. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79718. #ifdef DEBUG
  79719. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79720. s->compressed_len += (stored_len + 4) << 3;
  79721. #endif
  79722. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79723. }
  79724. void _tr_align (deflate_state *s)
  79725. {
  79726. send_bits(s, STATIC_TREES<<1, 3);
  79727. send_code(s, END_BLOCK, static_ltree);
  79728. #ifdef DEBUG
  79729. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79730. #endif
  79731. bi_flush(s);
  79732. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79733. send_bits(s, STATIC_TREES<<1, 3);
  79734. send_code(s, END_BLOCK, static_ltree);
  79735. #ifdef DEBUG
  79736. s->compressed_len += 10L;
  79737. #endif
  79738. bi_flush(s);
  79739. }
  79740. s->last_eob_len = 7;
  79741. }
  79742. void _tr_flush_block (deflate_state *s,
  79743. charf *buf, /* input block, or NULL if too old */
  79744. ulg stored_len, /* length of input block */
  79745. int eof) /* true if this is the last block for a file */
  79746. {
  79747. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79748. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79749. if (s->level > 0) {
  79750. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79751. set_data_type(s);
  79752. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79753. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79754. s->static_len));
  79755. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79756. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79757. s->static_len));
  79758. max_blindex = build_bl_tree(s);
  79759. opt_lenb = (s->opt_len+3+7)>>3;
  79760. static_lenb = (s->static_len+3+7)>>3;
  79761. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79762. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79763. s->last_lit));
  79764. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79765. } else {
  79766. Assert(buf != (char*)0, "lost buf");
  79767. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79768. }
  79769. #ifdef FORCE_STORED
  79770. if (buf != (char*)0) { /* force stored block */
  79771. #else
  79772. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79773. #endif
  79774. _tr_stored_block(s, buf, stored_len, eof);
  79775. #ifdef FORCE_STATIC
  79776. } else if (static_lenb >= 0) { /* force static trees */
  79777. #else
  79778. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79779. #endif
  79780. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79781. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79782. #ifdef DEBUG
  79783. s->compressed_len += 3 + s->static_len;
  79784. #endif
  79785. } else {
  79786. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79787. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79788. max_blindex+1);
  79789. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79790. #ifdef DEBUG
  79791. s->compressed_len += 3 + s->opt_len;
  79792. #endif
  79793. }
  79794. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79795. init_block(s);
  79796. if (eof) {
  79797. bi_windup(s);
  79798. #ifdef DEBUG
  79799. s->compressed_len += 7; /* align on byte boundary */
  79800. #endif
  79801. }
  79802. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79803. s->compressed_len-7*eof));
  79804. }
  79805. int _tr_tally (deflate_state *s,
  79806. unsigned dist, /* distance of matched string */
  79807. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79808. {
  79809. s->d_buf[s->last_lit] = (ush)dist;
  79810. s->l_buf[s->last_lit++] = (uch)lc;
  79811. if (dist == 0) {
  79812. s->dyn_ltree[lc].Freq++;
  79813. } else {
  79814. s->matches++;
  79815. dist--; /* dist = match distance - 1 */
  79816. Assert((ush)dist < (ush)MAX_DIST(s) &&
  79817. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  79818. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  79819. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  79820. s->dyn_dtree[d_code(dist)].Freq++;
  79821. }
  79822. #ifdef TRUNCATE_BLOCK
  79823. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  79824. ulg out_length = (ulg)s->last_lit*8L;
  79825. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  79826. int dcode;
  79827. for (dcode = 0; dcode < D_CODES; dcode++) {
  79828. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  79829. (5L+extra_dbits[dcode]);
  79830. }
  79831. out_length >>= 3;
  79832. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  79833. s->last_lit, in_length, out_length,
  79834. 100L - out_length*100L/in_length));
  79835. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  79836. }
  79837. #endif
  79838. return (s->last_lit == s->lit_bufsize-1);
  79839. }
  79840. local void compress_block (deflate_state *s,
  79841. ct_data *ltree, /* literal tree */
  79842. ct_data *dtree) /* distance tree */
  79843. {
  79844. unsigned dist; /* distance of matched string */
  79845. int lc; /* match length or unmatched char (if dist == 0) */
  79846. unsigned lx = 0; /* running index in l_buf */
  79847. unsigned code; /* the code to send */
  79848. int extra; /* number of extra bits to send */
  79849. if (s->last_lit != 0) do {
  79850. dist = s->d_buf[lx];
  79851. lc = s->l_buf[lx++];
  79852. if (dist == 0) {
  79853. send_code(s, lc, ltree); /* send a literal byte */
  79854. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  79855. } else {
  79856. code = _length_code[lc];
  79857. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  79858. extra = extra_lbits[code];
  79859. if (extra != 0) {
  79860. lc -= base_length[code];
  79861. send_bits(s, lc, extra); /* send the extra length bits */
  79862. }
  79863. dist--; /* dist is now the match distance - 1 */
  79864. code = d_code(dist);
  79865. Assert (code < D_CODES, "bad d_code");
  79866. send_code(s, code, dtree); /* send the distance code */
  79867. extra = extra_dbits[code];
  79868. if (extra != 0) {
  79869. dist -= base_dist[code];
  79870. send_bits(s, dist, extra); /* send the extra distance bits */
  79871. }
  79872. } /* literal or match pair ? */
  79873. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  79874. "pendingBuf overflow");
  79875. } while (lx < s->last_lit);
  79876. send_code(s, END_BLOCK, ltree);
  79877. s->last_eob_len = ltree[END_BLOCK].Len;
  79878. }
  79879. local void set_data_type (deflate_state *s)
  79880. {
  79881. int n;
  79882. for (n = 0; n < 9; n++)
  79883. if (s->dyn_ltree[n].Freq != 0)
  79884. break;
  79885. if (n == 9)
  79886. for (n = 14; n < 32; n++)
  79887. if (s->dyn_ltree[n].Freq != 0)
  79888. break;
  79889. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  79890. }
  79891. local unsigned bi_reverse (unsigned code, int len)
  79892. {
  79893. register unsigned res = 0;
  79894. do {
  79895. res |= code & 1;
  79896. code >>= 1, res <<= 1;
  79897. } while (--len > 0);
  79898. return res >> 1;
  79899. }
  79900. local void bi_flush (deflate_state *s)
  79901. {
  79902. if (s->bi_valid == 16) {
  79903. put_short(s, s->bi_buf);
  79904. s->bi_buf = 0;
  79905. s->bi_valid = 0;
  79906. } else if (s->bi_valid >= 8) {
  79907. put_byte(s, (Byte)s->bi_buf);
  79908. s->bi_buf >>= 8;
  79909. s->bi_valid -= 8;
  79910. }
  79911. }
  79912. local void bi_windup (deflate_state *s)
  79913. {
  79914. if (s->bi_valid > 8) {
  79915. put_short(s, s->bi_buf);
  79916. } else if (s->bi_valid > 0) {
  79917. put_byte(s, (Byte)s->bi_buf);
  79918. }
  79919. s->bi_buf = 0;
  79920. s->bi_valid = 0;
  79921. #ifdef DEBUG
  79922. s->bits_sent = (s->bits_sent+7) & ~7;
  79923. #endif
  79924. }
  79925. local void copy_block(deflate_state *s,
  79926. charf *buf, /* the input data */
  79927. unsigned len, /* its length */
  79928. int header) /* true if block header must be written */
  79929. {
  79930. bi_windup(s); /* align on byte boundary */
  79931. s->last_eob_len = 8; /* enough lookahead for inflate */
  79932. if (header) {
  79933. put_short(s, (ush)len);
  79934. put_short(s, (ush)~len);
  79935. #ifdef DEBUG
  79936. s->bits_sent += 2*16;
  79937. #endif
  79938. }
  79939. #ifdef DEBUG
  79940. s->bits_sent += (ulg)len<<3;
  79941. #endif
  79942. while (len--) {
  79943. put_byte(s, *buf++);
  79944. }
  79945. }
  79946. /*** End of inlined file: trees.c ***/
  79947. /*** Start of inlined file: zutil.c ***/
  79948. #ifndef NO_DUMMY_DECL
  79949. struct internal_state {int dummy;}; /* for buggy compilers */
  79950. #endif
  79951. const char * const z_errmsg[10] = {
  79952. "need dictionary", /* Z_NEED_DICT 2 */
  79953. "stream end", /* Z_STREAM_END 1 */
  79954. "", /* Z_OK 0 */
  79955. "file error", /* Z_ERRNO (-1) */
  79956. "stream error", /* Z_STREAM_ERROR (-2) */
  79957. "data error", /* Z_DATA_ERROR (-3) */
  79958. "insufficient memory", /* Z_MEM_ERROR (-4) */
  79959. "buffer error", /* Z_BUF_ERROR (-5) */
  79960. "incompatible version",/* Z_VERSION_ERROR (-6) */
  79961. ""};
  79962. #ifdef DEBUG
  79963. # ifndef verbose
  79964. # define verbose 0
  79965. # endif
  79966. int z_verbose = verbose;
  79967. void z_error (const char *m)
  79968. {
  79969. fprintf(stderr, "%s\n", m);
  79970. exit(1);
  79971. }
  79972. #endif
  79973. const char * ZEXPORT zError(int err)
  79974. {
  79975. return ERR_MSG(err);
  79976. }
  79977. #if defined(_WIN32_WCE)
  79978. int errno = 0;
  79979. #endif
  79980. #ifndef HAVE_MEMCPY
  79981. void zmemcpy(dest, source, len)
  79982. Bytef* dest;
  79983. const Bytef* source;
  79984. uInt len;
  79985. {
  79986. if (len == 0) return;
  79987. do {
  79988. *dest++ = *source++; /* ??? to be unrolled */
  79989. } while (--len != 0);
  79990. }
  79991. int zmemcmp(s1, s2, len)
  79992. const Bytef* s1;
  79993. const Bytef* s2;
  79994. uInt len;
  79995. {
  79996. uInt j;
  79997. for (j = 0; j < len; j++) {
  79998. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  79999. }
  80000. return 0;
  80001. }
  80002. void zmemzero(dest, len)
  80003. Bytef* dest;
  80004. uInt len;
  80005. {
  80006. if (len == 0) return;
  80007. do {
  80008. *dest++ = 0; /* ??? to be unrolled */
  80009. } while (--len != 0);
  80010. }
  80011. #endif
  80012. #ifdef SYS16BIT
  80013. #ifdef __TURBOC__
  80014. # define MY_ZCALLOC
  80015. #define MAX_PTR 10
  80016. local int next_ptr = 0;
  80017. typedef struct ptr_table_s {
  80018. voidpf org_ptr;
  80019. voidpf new_ptr;
  80020. } ptr_table;
  80021. local ptr_table table[MAX_PTR];
  80022. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80023. {
  80024. voidpf buf = opaque; /* just to make some compilers happy */
  80025. ulg bsize = (ulg)items*size;
  80026. if (bsize < 65520L) {
  80027. buf = farmalloc(bsize);
  80028. if (*(ush*)&buf != 0) return buf;
  80029. } else {
  80030. buf = farmalloc(bsize + 16L);
  80031. }
  80032. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80033. table[next_ptr].org_ptr = buf;
  80034. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80035. *(ush*)&buf = 0;
  80036. table[next_ptr++].new_ptr = buf;
  80037. return buf;
  80038. }
  80039. void zcfree (voidpf opaque, voidpf ptr)
  80040. {
  80041. int n;
  80042. if (*(ush*)&ptr != 0) { /* object < 64K */
  80043. farfree(ptr);
  80044. return;
  80045. }
  80046. for (n = 0; n < next_ptr; n++) {
  80047. if (ptr != table[n].new_ptr) continue;
  80048. farfree(table[n].org_ptr);
  80049. while (++n < next_ptr) {
  80050. table[n-1] = table[n];
  80051. }
  80052. next_ptr--;
  80053. return;
  80054. }
  80055. ptr = opaque; /* just to make some compilers happy */
  80056. Assert(0, "zcfree: ptr not found");
  80057. }
  80058. #endif /* __TURBOC__ */
  80059. #ifdef M_I86
  80060. # define MY_ZCALLOC
  80061. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80062. # define _halloc halloc
  80063. # define _hfree hfree
  80064. #endif
  80065. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80066. {
  80067. if (opaque) opaque = 0; /* to make compiler happy */
  80068. return _halloc((long)items, size);
  80069. }
  80070. void zcfree (voidpf opaque, voidpf ptr)
  80071. {
  80072. if (opaque) opaque = 0; /* to make compiler happy */
  80073. _hfree(ptr);
  80074. }
  80075. #endif /* M_I86 */
  80076. #endif /* SYS16BIT */
  80077. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80078. #ifndef STDC
  80079. extern voidp malloc OF((uInt size));
  80080. extern voidp calloc OF((uInt items, uInt size));
  80081. extern void free OF((voidpf ptr));
  80082. #endif
  80083. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80084. {
  80085. if (opaque) items += size - size; /* make compiler happy */
  80086. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80087. (voidpf)calloc(items, size);
  80088. }
  80089. void zcfree (voidpf opaque, voidpf ptr)
  80090. {
  80091. free(ptr);
  80092. if (opaque) return; /* make compiler happy */
  80093. }
  80094. #endif /* MY_ZCALLOC */
  80095. /*** End of inlined file: zutil.c ***/
  80096. #undef Byte
  80097. }
  80098. #else
  80099. #include <zlib.h>
  80100. #endif
  80101. }
  80102. #if JUCE_MSVC
  80103. #pragma warning (pop)
  80104. #endif
  80105. BEGIN_JUCE_NAMESPACE
  80106. // internal helper object that holds the zlib structures so they don't have to be
  80107. // included publicly.
  80108. class GZIPDecompressHelper
  80109. {
  80110. public:
  80111. GZIPDecompressHelper (const bool noWrap)
  80112. : finished (true),
  80113. needsDictionary (false),
  80114. error (true),
  80115. streamIsValid (false),
  80116. data (0),
  80117. dataSize (0)
  80118. {
  80119. using namespace zlibNamespace;
  80120. zerostruct (stream);
  80121. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80122. finished = error = ! streamIsValid;
  80123. }
  80124. ~GZIPDecompressHelper()
  80125. {
  80126. using namespace zlibNamespace;
  80127. if (streamIsValid)
  80128. inflateEnd (&stream);
  80129. }
  80130. bool needsInput() const throw() { return dataSize <= 0; }
  80131. void setInput (uint8* const data_, const int size) throw()
  80132. {
  80133. data = data_;
  80134. dataSize = size;
  80135. }
  80136. int doNextBlock (uint8* const dest, const int destSize)
  80137. {
  80138. using namespace zlibNamespace;
  80139. if (streamIsValid && data != 0 && ! finished)
  80140. {
  80141. stream.next_in = data;
  80142. stream.next_out = dest;
  80143. stream.avail_in = dataSize;
  80144. stream.avail_out = destSize;
  80145. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80146. {
  80147. case Z_STREAM_END:
  80148. finished = true;
  80149. // deliberate fall-through
  80150. case Z_OK:
  80151. data += dataSize - stream.avail_in;
  80152. dataSize = stream.avail_in;
  80153. return destSize - stream.avail_out;
  80154. case Z_NEED_DICT:
  80155. needsDictionary = true;
  80156. data += dataSize - stream.avail_in;
  80157. dataSize = stream.avail_in;
  80158. break;
  80159. case Z_DATA_ERROR:
  80160. case Z_MEM_ERROR:
  80161. error = true;
  80162. default:
  80163. break;
  80164. }
  80165. }
  80166. return 0;
  80167. }
  80168. bool finished, needsDictionary, error, streamIsValid;
  80169. private:
  80170. zlibNamespace::z_stream stream;
  80171. uint8* data;
  80172. int dataSize;
  80173. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80174. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80175. };
  80176. const int gzipDecompBufferSize = 32768;
  80177. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80178. const bool deleteSourceWhenDestroyed,
  80179. const bool noWrap_,
  80180. const int64 uncompressedStreamLength_)
  80181. : sourceStream (sourceStream_),
  80182. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80183. uncompressedStreamLength (uncompressedStreamLength_),
  80184. noWrap (noWrap_),
  80185. isEof (false),
  80186. activeBufferSize (0),
  80187. originalSourcePos (sourceStream_->getPosition()),
  80188. currentPos (0),
  80189. buffer (gzipDecompBufferSize),
  80190. helper (new GZIPDecompressHelper (noWrap_))
  80191. {
  80192. }
  80193. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80194. {
  80195. }
  80196. int64 GZIPDecompressorInputStream::getTotalLength()
  80197. {
  80198. return uncompressedStreamLength;
  80199. }
  80200. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80201. {
  80202. if ((howMany > 0) && ! isEof)
  80203. {
  80204. jassert (destBuffer != 0);
  80205. if (destBuffer != 0)
  80206. {
  80207. int numRead = 0;
  80208. uint8* d = static_cast <uint8*> (destBuffer);
  80209. while (! helper->error)
  80210. {
  80211. const int n = helper->doNextBlock (d, howMany);
  80212. currentPos += n;
  80213. if (n == 0)
  80214. {
  80215. if (helper->finished || helper->needsDictionary)
  80216. {
  80217. isEof = true;
  80218. return numRead;
  80219. }
  80220. if (helper->needsInput())
  80221. {
  80222. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80223. if (activeBufferSize > 0)
  80224. {
  80225. helper->setInput (buffer, activeBufferSize);
  80226. }
  80227. else
  80228. {
  80229. isEof = true;
  80230. return numRead;
  80231. }
  80232. }
  80233. }
  80234. else
  80235. {
  80236. numRead += n;
  80237. howMany -= n;
  80238. d += n;
  80239. if (howMany <= 0)
  80240. return numRead;
  80241. }
  80242. }
  80243. }
  80244. }
  80245. return 0;
  80246. }
  80247. bool GZIPDecompressorInputStream::isExhausted()
  80248. {
  80249. return helper->error || isEof;
  80250. }
  80251. int64 GZIPDecompressorInputStream::getPosition()
  80252. {
  80253. return currentPos;
  80254. }
  80255. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80256. {
  80257. if (newPos < currentPos)
  80258. {
  80259. // to go backwards, reset the stream and start again..
  80260. isEof = false;
  80261. activeBufferSize = 0;
  80262. currentPos = 0;
  80263. helper = new GZIPDecompressHelper (noWrap);
  80264. sourceStream->setPosition (originalSourcePos);
  80265. }
  80266. skipNextBytes (newPos - currentPos);
  80267. return true;
  80268. }
  80269. END_JUCE_NAMESPACE
  80270. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80271. #endif
  80272. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80273. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80274. #if JUCE_USE_FLAC
  80275. #if JUCE_WINDOWS
  80276. #include <windows.h>
  80277. #endif
  80278. #ifdef _MSC_VER
  80279. #pragma warning (disable : 4505)
  80280. #pragma warning (push)
  80281. #endif
  80282. namespace FlacNamespace
  80283. {
  80284. #if JUCE_INCLUDE_FLAC_CODE
  80285. #define FLAC__NO_DLL 1
  80286. #if ! defined (SIZE_MAX)
  80287. #define SIZE_MAX 0xffffffff
  80288. #endif
  80289. #define __STDC_LIMIT_MACROS 1
  80290. /*** Start of inlined file: all.h ***/
  80291. #ifndef FLAC__ALL_H
  80292. #define FLAC__ALL_H
  80293. /*** Start of inlined file: export.h ***/
  80294. #ifndef FLAC__EXPORT_H
  80295. #define FLAC__EXPORT_H
  80296. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80297. #define FLAC_API
  80298. #else
  80299. #ifdef FLAC_API_EXPORTS
  80300. #define FLAC_API _declspec(dllexport)
  80301. #else
  80302. #define FLAC_API _declspec(dllimport)
  80303. #endif
  80304. #endif
  80305. #define FLAC_API_VERSION_CURRENT 10
  80306. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80307. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80308. #ifdef __cplusplus
  80309. extern "C" {
  80310. #endif
  80311. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80312. #ifdef __cplusplus
  80313. }
  80314. #endif
  80315. #endif
  80316. /*** End of inlined file: export.h ***/
  80317. /*** Start of inlined file: assert.h ***/
  80318. #ifndef FLAC__ASSERT_H
  80319. #define FLAC__ASSERT_H
  80320. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80321. #ifdef DEBUG
  80322. #include <assert.h>
  80323. #define FLAC__ASSERT(x) assert(x)
  80324. #define FLAC__ASSERT_DECLARATION(x) x
  80325. #else
  80326. #define FLAC__ASSERT(x)
  80327. #define FLAC__ASSERT_DECLARATION(x)
  80328. #endif
  80329. #endif
  80330. /*** End of inlined file: assert.h ***/
  80331. /*** Start of inlined file: callback.h ***/
  80332. #ifndef FLAC__CALLBACK_H
  80333. #define FLAC__CALLBACK_H
  80334. /*** Start of inlined file: ordinals.h ***/
  80335. #ifndef FLAC__ORDINALS_H
  80336. #define FLAC__ORDINALS_H
  80337. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80338. #include <inttypes.h>
  80339. #endif
  80340. typedef signed char FLAC__int8;
  80341. typedef unsigned char FLAC__uint8;
  80342. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80343. typedef __int16 FLAC__int16;
  80344. typedef __int32 FLAC__int32;
  80345. typedef __int64 FLAC__int64;
  80346. typedef unsigned __int16 FLAC__uint16;
  80347. typedef unsigned __int32 FLAC__uint32;
  80348. typedef unsigned __int64 FLAC__uint64;
  80349. #elif defined(__EMX__)
  80350. typedef short FLAC__int16;
  80351. typedef long FLAC__int32;
  80352. typedef long long FLAC__int64;
  80353. typedef unsigned short FLAC__uint16;
  80354. typedef unsigned long FLAC__uint32;
  80355. typedef unsigned long long FLAC__uint64;
  80356. #else
  80357. typedef int16_t FLAC__int16;
  80358. typedef int32_t FLAC__int32;
  80359. typedef int64_t FLAC__int64;
  80360. typedef uint16_t FLAC__uint16;
  80361. typedef uint32_t FLAC__uint32;
  80362. typedef uint64_t FLAC__uint64;
  80363. #endif
  80364. typedef int FLAC__bool;
  80365. typedef FLAC__uint8 FLAC__byte;
  80366. #ifdef true
  80367. #undef true
  80368. #endif
  80369. #ifdef false
  80370. #undef false
  80371. #endif
  80372. #ifndef __cplusplus
  80373. #define true 1
  80374. #define false 0
  80375. #endif
  80376. #endif
  80377. /*** End of inlined file: ordinals.h ***/
  80378. #include <stdlib.h> /* for size_t */
  80379. #ifdef __cplusplus
  80380. extern "C" {
  80381. #endif
  80382. typedef void* FLAC__IOHandle;
  80383. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80384. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80385. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80386. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80387. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80388. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80389. typedef struct {
  80390. FLAC__IOCallback_Read read;
  80391. FLAC__IOCallback_Write write;
  80392. FLAC__IOCallback_Seek seek;
  80393. FLAC__IOCallback_Tell tell;
  80394. FLAC__IOCallback_Eof eof;
  80395. FLAC__IOCallback_Close close;
  80396. } FLAC__IOCallbacks;
  80397. #ifdef __cplusplus
  80398. }
  80399. #endif
  80400. #endif
  80401. /*** End of inlined file: callback.h ***/
  80402. /*** Start of inlined file: format.h ***/
  80403. #ifndef FLAC__FORMAT_H
  80404. #define FLAC__FORMAT_H
  80405. #ifdef __cplusplus
  80406. extern "C" {
  80407. #endif
  80408. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80409. #define FLAC__MIN_BLOCK_SIZE (16u)
  80410. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80411. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80412. #define FLAC__MAX_CHANNELS (8u)
  80413. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80414. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80415. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80416. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80417. #define FLAC__MAX_LPC_ORDER (32u)
  80418. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80419. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80420. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80421. #define FLAC__MAX_FIXED_ORDER (4u)
  80422. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80423. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80424. extern FLAC_API const char *FLAC__VERSION_STRING;
  80425. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80426. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80427. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80428. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80429. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80430. typedef enum {
  80431. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80432. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80433. } FLAC__EntropyCodingMethodType;
  80434. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80435. typedef struct {
  80436. unsigned *parameters;
  80437. unsigned *raw_bits;
  80438. unsigned capacity_by_order;
  80439. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80440. typedef struct {
  80441. unsigned order;
  80442. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80443. } FLAC__EntropyCodingMethod_PartitionedRice;
  80444. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80445. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80446. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80447. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80448. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80449. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80450. typedef struct {
  80451. FLAC__EntropyCodingMethodType type;
  80452. union {
  80453. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80454. } data;
  80455. } FLAC__EntropyCodingMethod;
  80456. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80457. typedef enum {
  80458. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80459. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80460. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80461. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80462. } FLAC__SubframeType;
  80463. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80464. typedef struct {
  80465. FLAC__int32 value; /**< The constant signal value. */
  80466. } FLAC__Subframe_Constant;
  80467. typedef struct {
  80468. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80469. } FLAC__Subframe_Verbatim;
  80470. typedef struct {
  80471. FLAC__EntropyCodingMethod entropy_coding_method;
  80472. unsigned order;
  80473. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80474. const FLAC__int32 *residual;
  80475. } FLAC__Subframe_Fixed;
  80476. typedef struct {
  80477. FLAC__EntropyCodingMethod entropy_coding_method;
  80478. unsigned order;
  80479. unsigned qlp_coeff_precision;
  80480. int quantization_level;
  80481. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80482. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80483. const FLAC__int32 *residual;
  80484. } FLAC__Subframe_LPC;
  80485. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80486. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80487. typedef struct {
  80488. FLAC__SubframeType type;
  80489. union {
  80490. FLAC__Subframe_Constant constant;
  80491. FLAC__Subframe_Fixed fixed;
  80492. FLAC__Subframe_LPC lpc;
  80493. FLAC__Subframe_Verbatim verbatim;
  80494. } data;
  80495. unsigned wasted_bits;
  80496. } FLAC__Subframe;
  80497. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80498. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80499. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80500. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80501. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80502. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80503. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80504. typedef enum {
  80505. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80506. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80507. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80508. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80509. } FLAC__ChannelAssignment;
  80510. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80511. typedef enum {
  80512. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80513. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80514. } FLAC__FrameNumberType;
  80515. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80516. typedef struct {
  80517. unsigned blocksize;
  80518. unsigned sample_rate;
  80519. unsigned channels;
  80520. FLAC__ChannelAssignment channel_assignment;
  80521. unsigned bits_per_sample;
  80522. FLAC__FrameNumberType number_type;
  80523. union {
  80524. FLAC__uint32 frame_number;
  80525. FLAC__uint64 sample_number;
  80526. } number;
  80527. FLAC__uint8 crc;
  80528. } FLAC__FrameHeader;
  80529. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80530. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80531. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80532. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80533. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80534. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80535. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80536. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80537. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80538. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80539. typedef struct {
  80540. FLAC__uint16 crc;
  80541. } FLAC__FrameFooter;
  80542. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80543. typedef struct {
  80544. FLAC__FrameHeader header;
  80545. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80546. FLAC__FrameFooter footer;
  80547. } FLAC__Frame;
  80548. typedef enum {
  80549. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80550. FLAC__METADATA_TYPE_PADDING = 1,
  80551. FLAC__METADATA_TYPE_APPLICATION = 2,
  80552. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80553. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80554. FLAC__METADATA_TYPE_CUESHEET = 5,
  80555. FLAC__METADATA_TYPE_PICTURE = 6,
  80556. FLAC__METADATA_TYPE_UNDEFINED = 7
  80557. } FLAC__MetadataType;
  80558. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80559. typedef struct {
  80560. unsigned min_blocksize, max_blocksize;
  80561. unsigned min_framesize, max_framesize;
  80562. unsigned sample_rate;
  80563. unsigned channels;
  80564. unsigned bits_per_sample;
  80565. FLAC__uint64 total_samples;
  80566. FLAC__byte md5sum[16];
  80567. } FLAC__StreamMetadata_StreamInfo;
  80568. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80569. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80570. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80571. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80572. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80573. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80574. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80575. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80576. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80577. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80578. typedef struct {
  80579. int dummy;
  80580. } FLAC__StreamMetadata_Padding;
  80581. typedef struct {
  80582. FLAC__byte id[4];
  80583. FLAC__byte *data;
  80584. } FLAC__StreamMetadata_Application;
  80585. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80586. typedef struct {
  80587. FLAC__uint64 sample_number;
  80588. FLAC__uint64 stream_offset;
  80589. unsigned frame_samples;
  80590. } FLAC__StreamMetadata_SeekPoint;
  80591. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80592. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80593. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80594. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80595. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80596. typedef struct {
  80597. unsigned num_points;
  80598. FLAC__StreamMetadata_SeekPoint *points;
  80599. } FLAC__StreamMetadata_SeekTable;
  80600. typedef struct {
  80601. FLAC__uint32 length;
  80602. FLAC__byte *entry;
  80603. } FLAC__StreamMetadata_VorbisComment_Entry;
  80604. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80605. typedef struct {
  80606. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80607. FLAC__uint32 num_comments;
  80608. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80609. } FLAC__StreamMetadata_VorbisComment;
  80610. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80611. typedef struct {
  80612. FLAC__uint64 offset;
  80613. FLAC__byte number;
  80614. } FLAC__StreamMetadata_CueSheet_Index;
  80615. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80616. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80617. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80618. typedef struct {
  80619. FLAC__uint64 offset;
  80620. FLAC__byte number;
  80621. char isrc[13];
  80622. unsigned type:1;
  80623. unsigned pre_emphasis:1;
  80624. FLAC__byte num_indices;
  80625. FLAC__StreamMetadata_CueSheet_Index *indices;
  80626. } FLAC__StreamMetadata_CueSheet_Track;
  80627. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80628. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80629. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80630. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80631. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80632. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80633. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80634. typedef struct {
  80635. char media_catalog_number[129];
  80636. FLAC__uint64 lead_in;
  80637. FLAC__bool is_cd;
  80638. unsigned num_tracks;
  80639. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80640. } FLAC__StreamMetadata_CueSheet;
  80641. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80642. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80643. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80644. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80645. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80646. typedef enum {
  80647. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80648. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80649. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80650. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80651. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80652. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80653. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80654. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80655. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80656. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80657. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80658. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80659. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80660. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80661. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80662. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80663. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80664. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80665. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80666. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80667. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80668. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80669. } FLAC__StreamMetadata_Picture_Type;
  80670. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80671. typedef struct {
  80672. FLAC__StreamMetadata_Picture_Type type;
  80673. char *mime_type;
  80674. FLAC__byte *description;
  80675. FLAC__uint32 width;
  80676. FLAC__uint32 height;
  80677. FLAC__uint32 depth;
  80678. FLAC__uint32 colors;
  80679. FLAC__uint32 data_length;
  80680. FLAC__byte *data;
  80681. } FLAC__StreamMetadata_Picture;
  80682. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80683. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80684. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80685. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80686. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80687. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80688. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80689. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80690. typedef struct {
  80691. FLAC__byte *data;
  80692. } FLAC__StreamMetadata_Unknown;
  80693. typedef struct {
  80694. FLAC__MetadataType type;
  80695. FLAC__bool is_last;
  80696. unsigned length;
  80697. union {
  80698. FLAC__StreamMetadata_StreamInfo stream_info;
  80699. FLAC__StreamMetadata_Padding padding;
  80700. FLAC__StreamMetadata_Application application;
  80701. FLAC__StreamMetadata_SeekTable seek_table;
  80702. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80703. FLAC__StreamMetadata_CueSheet cue_sheet;
  80704. FLAC__StreamMetadata_Picture picture;
  80705. FLAC__StreamMetadata_Unknown unknown;
  80706. } data;
  80707. } FLAC__StreamMetadata;
  80708. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80709. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80710. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80711. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80712. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80713. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80714. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80715. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80716. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80717. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80718. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80719. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80720. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80721. #ifdef __cplusplus
  80722. }
  80723. #endif
  80724. #endif
  80725. /*** End of inlined file: format.h ***/
  80726. /*** Start of inlined file: metadata.h ***/
  80727. #ifndef FLAC__METADATA_H
  80728. #define FLAC__METADATA_H
  80729. #include <sys/types.h> /* for off_t */
  80730. #ifdef __cplusplus
  80731. extern "C" {
  80732. #endif
  80733. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80734. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80735. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80736. FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors);
  80737. struct FLAC__Metadata_SimpleIterator;
  80738. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80739. typedef enum {
  80740. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80741. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80742. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80743. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80744. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80745. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80746. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80747. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80748. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80749. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80750. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80751. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80752. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80753. } FLAC__Metadata_SimpleIteratorStatus;
  80754. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80755. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80756. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80757. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80758. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats);
  80759. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80760. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80761. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80762. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80763. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80764. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80765. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80766. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80767. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80768. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80769. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80770. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80771. struct FLAC__Metadata_Chain;
  80772. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80773. struct FLAC__Metadata_Iterator;
  80774. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80775. typedef enum {
  80776. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80777. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80778. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80779. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80780. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80781. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80782. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80783. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80784. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80785. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80786. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80787. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80788. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80789. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80790. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80791. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80792. } FLAC__Metadata_ChainStatus;
  80793. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80794. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80795. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80796. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80797. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80798. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80799. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80800. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80801. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80802. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80803. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80804. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks);
  80805. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80806. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80807. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80808. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80809. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80810. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80811. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80812. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  80813. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  80814. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80815. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  80816. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80817. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80818. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  80819. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  80820. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  80821. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  80822. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  80823. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  80824. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80825. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80826. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  80827. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  80828. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  80829. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  80830. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  80831. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  80832. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  80833. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  80834. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80835. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  80836. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80837. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80838. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80839. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  80840. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  80841. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, const char *field_value);
  80842. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char **field_name, char **field_value);
  80843. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  80844. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  80845. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  80846. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  80847. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  80848. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  80849. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  80850. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  80851. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num, FLAC__StreamMetadata_CueSheet_Index index);
  80852. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80853. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80854. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  80855. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80856. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80857. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  80858. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  80859. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  80860. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  80861. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  80862. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  80863. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  80864. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  80865. #ifdef __cplusplus
  80866. }
  80867. #endif
  80868. #endif
  80869. /*** End of inlined file: metadata.h ***/
  80870. /*** Start of inlined file: stream_decoder.h ***/
  80871. #ifndef FLAC__STREAM_DECODER_H
  80872. #define FLAC__STREAM_DECODER_H
  80873. #include <stdio.h> /* for FILE */
  80874. #ifdef __cplusplus
  80875. extern "C" {
  80876. #endif
  80877. typedef enum {
  80878. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  80879. FLAC__STREAM_DECODER_READ_METADATA,
  80880. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  80881. FLAC__STREAM_DECODER_READ_FRAME,
  80882. FLAC__STREAM_DECODER_END_OF_STREAM,
  80883. FLAC__STREAM_DECODER_OGG_ERROR,
  80884. FLAC__STREAM_DECODER_SEEK_ERROR,
  80885. FLAC__STREAM_DECODER_ABORTED,
  80886. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  80887. FLAC__STREAM_DECODER_UNINITIALIZED
  80888. } FLAC__StreamDecoderState;
  80889. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  80890. typedef enum {
  80891. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  80892. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  80893. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  80894. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  80895. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  80896. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  80897. } FLAC__StreamDecoderInitStatus;
  80898. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  80899. typedef enum {
  80900. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  80901. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  80902. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  80903. } FLAC__StreamDecoderReadStatus;
  80904. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  80905. typedef enum {
  80906. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  80907. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  80908. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  80909. } FLAC__StreamDecoderSeekStatus;
  80910. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  80911. typedef enum {
  80912. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  80913. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  80914. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  80915. } FLAC__StreamDecoderTellStatus;
  80916. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  80917. typedef enum {
  80918. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  80919. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  80920. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  80921. } FLAC__StreamDecoderLengthStatus;
  80922. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  80923. typedef enum {
  80924. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  80925. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  80926. } FLAC__StreamDecoderWriteStatus;
  80927. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  80928. typedef enum {
  80929. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  80930. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  80931. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  80932. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  80933. } FLAC__StreamDecoderErrorStatus;
  80934. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  80935. struct FLAC__StreamDecoderProtected;
  80936. struct FLAC__StreamDecoderPrivate;
  80937. typedef struct {
  80938. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  80939. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  80940. } FLAC__StreamDecoder;
  80941. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  80942. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  80943. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  80944. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  80945. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  80946. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  80947. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  80948. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  80949. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  80950. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  80951. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  80952. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  80953. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  80954. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  80955. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  80956. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  80957. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  80958. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  80959. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  80960. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  80961. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  80962. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  80963. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  80964. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  80965. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  80966. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  80967. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  80968. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  80969. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  80970. FLAC__StreamDecoder *decoder,
  80971. FLAC__StreamDecoderReadCallback read_callback,
  80972. FLAC__StreamDecoderSeekCallback seek_callback,
  80973. FLAC__StreamDecoderTellCallback tell_callback,
  80974. FLAC__StreamDecoderLengthCallback length_callback,
  80975. FLAC__StreamDecoderEofCallback eof_callback,
  80976. FLAC__StreamDecoderWriteCallback write_callback,
  80977. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80978. FLAC__StreamDecoderErrorCallback error_callback,
  80979. void *client_data
  80980. );
  80981. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  80982. FLAC__StreamDecoder *decoder,
  80983. FLAC__StreamDecoderReadCallback read_callback,
  80984. FLAC__StreamDecoderSeekCallback seek_callback,
  80985. FLAC__StreamDecoderTellCallback tell_callback,
  80986. FLAC__StreamDecoderLengthCallback length_callback,
  80987. FLAC__StreamDecoderEofCallback eof_callback,
  80988. FLAC__StreamDecoderWriteCallback write_callback,
  80989. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80990. FLAC__StreamDecoderErrorCallback error_callback,
  80991. void *client_data
  80992. );
  80993. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  80994. FLAC__StreamDecoder *decoder,
  80995. FILE *file,
  80996. FLAC__StreamDecoderWriteCallback write_callback,
  80997. FLAC__StreamDecoderMetadataCallback metadata_callback,
  80998. FLAC__StreamDecoderErrorCallback error_callback,
  80999. void *client_data
  81000. );
  81001. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81002. FLAC__StreamDecoder *decoder,
  81003. FILE *file,
  81004. FLAC__StreamDecoderWriteCallback write_callback,
  81005. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81006. FLAC__StreamDecoderErrorCallback error_callback,
  81007. void *client_data
  81008. );
  81009. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81010. FLAC__StreamDecoder *decoder,
  81011. const char *filename,
  81012. FLAC__StreamDecoderWriteCallback write_callback,
  81013. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81014. FLAC__StreamDecoderErrorCallback error_callback,
  81015. void *client_data
  81016. );
  81017. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81018. FLAC__StreamDecoder *decoder,
  81019. const char *filename,
  81020. FLAC__StreamDecoderWriteCallback write_callback,
  81021. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81022. FLAC__StreamDecoderErrorCallback error_callback,
  81023. void *client_data
  81024. );
  81025. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81026. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81027. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81028. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81029. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81030. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81031. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81032. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81033. #ifdef __cplusplus
  81034. }
  81035. #endif
  81036. #endif
  81037. /*** End of inlined file: stream_decoder.h ***/
  81038. /*** Start of inlined file: stream_encoder.h ***/
  81039. #ifndef FLAC__STREAM_ENCODER_H
  81040. #define FLAC__STREAM_ENCODER_H
  81041. #include <stdio.h> /* for FILE */
  81042. #ifdef __cplusplus
  81043. extern "C" {
  81044. #endif
  81045. typedef enum {
  81046. FLAC__STREAM_ENCODER_OK = 0,
  81047. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81048. FLAC__STREAM_ENCODER_OGG_ERROR,
  81049. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81050. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81051. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81052. FLAC__STREAM_ENCODER_IO_ERROR,
  81053. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81054. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81055. } FLAC__StreamEncoderState;
  81056. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81057. typedef enum {
  81058. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81059. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81060. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81061. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81062. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81063. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81064. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81065. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81066. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81067. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81068. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81069. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81070. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81071. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81072. } FLAC__StreamEncoderInitStatus;
  81073. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81074. typedef enum {
  81075. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81076. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81077. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81078. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81079. } FLAC__StreamEncoderReadStatus;
  81080. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81081. typedef enum {
  81082. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81083. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81084. } FLAC__StreamEncoderWriteStatus;
  81085. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81086. typedef enum {
  81087. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81088. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81089. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81090. } FLAC__StreamEncoderSeekStatus;
  81091. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81092. typedef enum {
  81093. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81094. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81095. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81096. } FLAC__StreamEncoderTellStatus;
  81097. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81098. struct FLAC__StreamEncoderProtected;
  81099. struct FLAC__StreamEncoderPrivate;
  81100. typedef struct {
  81101. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81102. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81103. } FLAC__StreamEncoder;
  81104. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81105. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81106. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81107. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81108. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81109. typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
  81110. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81111. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81112. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81113. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81114. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81115. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81116. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81117. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81118. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81119. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81120. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81121. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81122. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81123. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81124. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81125. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81126. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81127. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81128. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81129. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81130. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81131. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81132. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81133. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81134. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81135. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81136. FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
  81137. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81138. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81139. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81140. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81141. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81142. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81143. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81144. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81145. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81146. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81147. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81148. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81149. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81150. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81151. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81152. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81153. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81154. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
  81155. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
  81156. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81157. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81158. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81159. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81160. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81161. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81162. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81163. #ifdef __cplusplus
  81164. }
  81165. #endif
  81166. #endif
  81167. /*** End of inlined file: stream_encoder.h ***/
  81168. #ifdef _MSC_VER
  81169. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81170. {
  81171. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81172. return (x>>16) | (x<<16);
  81173. }
  81174. #endif
  81175. #if defined(_MSC_VER) && defined(_X86_)
  81176. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81177. {
  81178. __asm {
  81179. mov edx, start
  81180. mov ecx, len
  81181. test ecx, ecx
  81182. loop1:
  81183. jz done1
  81184. mov eax, [edx]
  81185. bswap eax
  81186. mov [edx], eax
  81187. add edx, 4
  81188. dec ecx
  81189. jmp short loop1
  81190. done1:
  81191. }
  81192. }
  81193. #endif
  81194. #endif
  81195. /*** End of inlined file: all.h ***/
  81196. /*** Start of inlined file: bitmath.c ***/
  81197. /*** Start of inlined file: juce_FlacHeader.h ***/
  81198. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81199. // tasks..
  81200. #define VERSION "1.2.1"
  81201. #define FLAC__NO_DLL 1
  81202. #if JUCE_MSVC
  81203. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81204. #endif
  81205. #if JUCE_MAC
  81206. #define FLAC__SYS_DARWIN 1
  81207. #endif
  81208. /*** End of inlined file: juce_FlacHeader.h ***/
  81209. #if JUCE_USE_FLAC
  81210. #if HAVE_CONFIG_H
  81211. # include <config.h>
  81212. #endif
  81213. /*** Start of inlined file: bitmath.h ***/
  81214. #ifndef FLAC__PRIVATE__BITMATH_H
  81215. #define FLAC__PRIVATE__BITMATH_H
  81216. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81217. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81218. unsigned FLAC__bitmath_silog2(int v);
  81219. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81220. #endif
  81221. /*** End of inlined file: bitmath.h ***/
  81222. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81223. {
  81224. unsigned l = 0;
  81225. FLAC__ASSERT(v > 0);
  81226. while(v >>= 1)
  81227. l++;
  81228. return l;
  81229. }
  81230. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81231. {
  81232. unsigned l = 0;
  81233. FLAC__ASSERT(v > 0);
  81234. while(v >>= 1)
  81235. l++;
  81236. return l;
  81237. }
  81238. unsigned FLAC__bitmath_silog2(int v)
  81239. {
  81240. while(1) {
  81241. if(v == 0) {
  81242. return 0;
  81243. }
  81244. else if(v > 0) {
  81245. unsigned l = 0;
  81246. while(v) {
  81247. l++;
  81248. v >>= 1;
  81249. }
  81250. return l+1;
  81251. }
  81252. else if(v == -1) {
  81253. return 2;
  81254. }
  81255. else {
  81256. v++;
  81257. v = -v;
  81258. }
  81259. }
  81260. }
  81261. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81262. {
  81263. while(1) {
  81264. if(v == 0) {
  81265. return 0;
  81266. }
  81267. else if(v > 0) {
  81268. unsigned l = 0;
  81269. while(v) {
  81270. l++;
  81271. v >>= 1;
  81272. }
  81273. return l+1;
  81274. }
  81275. else if(v == -1) {
  81276. return 2;
  81277. }
  81278. else {
  81279. v++;
  81280. v = -v;
  81281. }
  81282. }
  81283. }
  81284. #endif
  81285. /*** End of inlined file: bitmath.c ***/
  81286. /*** Start of inlined file: bitreader.c ***/
  81287. /*** Start of inlined file: juce_FlacHeader.h ***/
  81288. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81289. // tasks..
  81290. #define VERSION "1.2.1"
  81291. #define FLAC__NO_DLL 1
  81292. #if JUCE_MSVC
  81293. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81294. #endif
  81295. #if JUCE_MAC
  81296. #define FLAC__SYS_DARWIN 1
  81297. #endif
  81298. /*** End of inlined file: juce_FlacHeader.h ***/
  81299. #if JUCE_USE_FLAC
  81300. #if HAVE_CONFIG_H
  81301. # include <config.h>
  81302. #endif
  81303. #include <stdlib.h> /* for malloc() */
  81304. #include <string.h> /* for memcpy(), memset() */
  81305. #ifdef _MSC_VER
  81306. #include <winsock.h> /* for ntohl() */
  81307. #elif defined FLAC__SYS_DARWIN
  81308. #include <machine/endian.h> /* for ntohl() */
  81309. #elif defined __MINGW32__
  81310. #include <winsock.h> /* for ntohl() */
  81311. #else
  81312. #include <netinet/in.h> /* for ntohl() */
  81313. #endif
  81314. /*** Start of inlined file: bitreader.h ***/
  81315. #ifndef FLAC__PRIVATE__BITREADER_H
  81316. #define FLAC__PRIVATE__BITREADER_H
  81317. #include <stdio.h> /* for FILE */
  81318. /*** Start of inlined file: cpu.h ***/
  81319. #ifndef FLAC__PRIVATE__CPU_H
  81320. #define FLAC__PRIVATE__CPU_H
  81321. #ifdef HAVE_CONFIG_H
  81322. #include <config.h>
  81323. #endif
  81324. typedef enum {
  81325. FLAC__CPUINFO_TYPE_IA32,
  81326. FLAC__CPUINFO_TYPE_PPC,
  81327. FLAC__CPUINFO_TYPE_UNKNOWN
  81328. } FLAC__CPUInfo_Type;
  81329. typedef struct {
  81330. FLAC__bool cpuid;
  81331. FLAC__bool bswap;
  81332. FLAC__bool cmov;
  81333. FLAC__bool mmx;
  81334. FLAC__bool fxsr;
  81335. FLAC__bool sse;
  81336. FLAC__bool sse2;
  81337. FLAC__bool sse3;
  81338. FLAC__bool ssse3;
  81339. FLAC__bool _3dnow;
  81340. FLAC__bool ext3dnow;
  81341. FLAC__bool extmmx;
  81342. } FLAC__CPUInfo_IA32;
  81343. typedef struct {
  81344. FLAC__bool altivec;
  81345. FLAC__bool ppc64;
  81346. } FLAC__CPUInfo_PPC;
  81347. typedef struct {
  81348. FLAC__bool use_asm;
  81349. FLAC__CPUInfo_Type type;
  81350. union {
  81351. FLAC__CPUInfo_IA32 ia32;
  81352. FLAC__CPUInfo_PPC ppc;
  81353. } data;
  81354. } FLAC__CPUInfo;
  81355. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81356. #ifndef FLAC__NO_ASM
  81357. #ifdef FLAC__CPU_IA32
  81358. #ifdef FLAC__HAS_NASM
  81359. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81360. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81361. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81362. #endif
  81363. #endif
  81364. #endif
  81365. #endif
  81366. /*** End of inlined file: cpu.h ***/
  81367. struct FLAC__BitReader;
  81368. typedef struct FLAC__BitReader FLAC__BitReader;
  81369. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81370. FLAC__BitReader *FLAC__bitreader_new(void);
  81371. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81372. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81373. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81374. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81375. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81376. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81377. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81378. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81379. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81380. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81381. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81382. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81383. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81384. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81385. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81386. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81387. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81388. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81389. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81390. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81391. #ifndef FLAC__NO_ASM
  81392. # ifdef FLAC__CPU_IA32
  81393. # ifdef FLAC__HAS_NASM
  81394. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81395. # endif
  81396. # endif
  81397. #endif
  81398. #if 0 /* UNUSED */
  81399. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81400. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81401. #endif
  81402. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81403. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81404. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81405. #endif
  81406. /*** End of inlined file: bitreader.h ***/
  81407. /*** Start of inlined file: crc.h ***/
  81408. #ifndef FLAC__PRIVATE__CRC_H
  81409. #define FLAC__PRIVATE__CRC_H
  81410. extern FLAC__byte const FLAC__crc8_table[256];
  81411. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81412. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81413. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81414. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81415. extern unsigned FLAC__crc16_table[256];
  81416. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81417. #if 0
  81418. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81419. #endif
  81420. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81421. #endif
  81422. /*** End of inlined file: crc.h ***/
  81423. typedef FLAC__uint32 brword;
  81424. #define FLAC__BYTES_PER_WORD 4
  81425. #define FLAC__BITS_PER_WORD 32
  81426. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81427. #if WORDS_BIGENDIAN
  81428. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81429. #else
  81430. #if defined (_MSC_VER) && defined (_X86_)
  81431. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81432. #else
  81433. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81434. #endif
  81435. #endif
  81436. #define COUNT_ZERO_MSBS(word) ( \
  81437. (word) <= 0xffff ? \
  81438. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81439. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81440. )
  81441. #define COUNT_ZERO_MSBS2(word) ( (word) <= 0xff ? byte_to_unary_table[word] + 24 : ((word) <= 0xffff ? byte_to_unary_table[(word) >> 8] + 16 : ((word) <= 0xffffff ? byte_to_unary_table[(word) >> 16] + 8 : byte_to_unary_table[(word) >> 24])) )
  81442. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81443. static const unsigned char byte_to_unary_table[] = {
  81444. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81445. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81446. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81447. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81448. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81449. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81450. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81451. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81460. };
  81461. #ifdef min
  81462. #undef min
  81463. #endif
  81464. #define min(x,y) ((x)<(y)?(x):(y))
  81465. #ifdef max
  81466. #undef max
  81467. #endif
  81468. #define max(x,y) ((x)>(y)?(x):(y))
  81469. #ifdef _MSC_VER
  81470. #define FLAC__U64L(x) x
  81471. #else
  81472. #define FLAC__U64L(x) x##LLU
  81473. #endif
  81474. #ifndef FLaC__INLINE
  81475. #define FLaC__INLINE
  81476. #endif
  81477. struct FLAC__BitReader {
  81478. brword *buffer;
  81479. unsigned capacity; /* in words */
  81480. unsigned words; /* # of completed words in buffer */
  81481. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81482. unsigned consumed_words; /* #words ... */
  81483. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81484. unsigned read_crc16; /* the running frame CRC */
  81485. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81486. FLAC__BitReaderReadCallback read_callback;
  81487. void *client_data;
  81488. FLAC__CPUInfo cpu_info;
  81489. };
  81490. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81491. {
  81492. register unsigned crc = br->read_crc16;
  81493. #if FLAC__BYTES_PER_WORD == 4
  81494. switch(br->crc16_align) {
  81495. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81496. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81497. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81498. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81499. }
  81500. #elif FLAC__BYTES_PER_WORD == 8
  81501. switch(br->crc16_align) {
  81502. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81503. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81504. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81505. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81506. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81507. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81508. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81509. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81510. }
  81511. #else
  81512. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81513. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81514. br->read_crc16 = crc;
  81515. #endif
  81516. br->crc16_align = 0;
  81517. }
  81518. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81519. {
  81520. unsigned start, end;
  81521. size_t bytes;
  81522. FLAC__byte *target;
  81523. if(br->consumed_words > 0) {
  81524. start = br->consumed_words;
  81525. end = br->words + (br->bytes? 1:0);
  81526. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81527. br->words -= start;
  81528. br->consumed_words = 0;
  81529. }
  81530. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81531. if(bytes == 0)
  81532. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81533. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81534. #if WORDS_BIGENDIAN
  81535. #else
  81536. if(br->bytes)
  81537. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81538. #endif
  81539. if(!br->read_callback(target, &bytes, br->client_data))
  81540. return false;
  81541. #if WORDS_BIGENDIAN
  81542. #else
  81543. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81544. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81545. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81546. start = br->words;
  81547. local_swap32_block_(br->buffer + start, end - start);
  81548. }
  81549. else
  81550. # endif
  81551. for(start = br->words; start < end; start++)
  81552. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81553. #endif
  81554. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81555. br->words = end / FLAC__BYTES_PER_WORD;
  81556. br->bytes = end % FLAC__BYTES_PER_WORD;
  81557. return true;
  81558. }
  81559. FLAC__BitReader *FLAC__bitreader_new(void)
  81560. {
  81561. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81562. return br;
  81563. }
  81564. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81565. {
  81566. FLAC__ASSERT(0 != br);
  81567. FLAC__bitreader_free(br);
  81568. free(br);
  81569. }
  81570. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81571. {
  81572. FLAC__ASSERT(0 != br);
  81573. br->words = br->bytes = 0;
  81574. br->consumed_words = br->consumed_bits = 0;
  81575. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81576. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81577. if(br->buffer == 0)
  81578. return false;
  81579. br->read_callback = rcb;
  81580. br->client_data = cd;
  81581. br->cpu_info = cpu;
  81582. return true;
  81583. }
  81584. void FLAC__bitreader_free(FLAC__BitReader *br)
  81585. {
  81586. FLAC__ASSERT(0 != br);
  81587. if(0 != br->buffer)
  81588. free(br->buffer);
  81589. br->buffer = 0;
  81590. br->capacity = 0;
  81591. br->words = br->bytes = 0;
  81592. br->consumed_words = br->consumed_bits = 0;
  81593. br->read_callback = 0;
  81594. br->client_data = 0;
  81595. }
  81596. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81597. {
  81598. br->words = br->bytes = 0;
  81599. br->consumed_words = br->consumed_bits = 0;
  81600. return true;
  81601. }
  81602. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81603. {
  81604. unsigned i, j;
  81605. if(br == 0) {
  81606. fprintf(out, "bitreader is NULL\n");
  81607. }
  81608. else {
  81609. fprintf(out, "bitreader: capacity=%u words=%u bytes=%u consumed: words=%u, bits=%u\n", br->capacity, br->words, br->bytes, br->consumed_words, br->consumed_bits);
  81610. for(i = 0; i < br->words; i++) {
  81611. fprintf(out, "%08X: ", i);
  81612. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81613. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81614. fprintf(out, ".");
  81615. else
  81616. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81617. fprintf(out, "\n");
  81618. }
  81619. if(br->bytes > 0) {
  81620. fprintf(out, "%08X: ", i);
  81621. for(j = 0; j < br->bytes*8; j++)
  81622. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81623. fprintf(out, ".");
  81624. else
  81625. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81626. fprintf(out, "\n");
  81627. }
  81628. }
  81629. }
  81630. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81631. {
  81632. FLAC__ASSERT(0 != br);
  81633. FLAC__ASSERT(0 != br->buffer);
  81634. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81635. br->read_crc16 = (unsigned)seed;
  81636. br->crc16_align = br->consumed_bits;
  81637. }
  81638. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81639. {
  81640. FLAC__ASSERT(0 != br);
  81641. FLAC__ASSERT(0 != br->buffer);
  81642. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81643. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81644. if(br->consumed_bits) {
  81645. const brword tail = br->buffer[br->consumed_words];
  81646. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81647. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81648. }
  81649. return br->read_crc16;
  81650. }
  81651. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81652. {
  81653. return ((br->consumed_bits & 7) == 0);
  81654. }
  81655. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81656. {
  81657. return 8 - (br->consumed_bits & 7);
  81658. }
  81659. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81660. {
  81661. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81662. }
  81663. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81664. {
  81665. FLAC__ASSERT(0 != br);
  81666. FLAC__ASSERT(0 != br->buffer);
  81667. FLAC__ASSERT(bits <= 32);
  81668. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81669. FLAC__ASSERT(br->consumed_words <= br->words);
  81670. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81671. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81672. *val = 0;
  81673. return true;
  81674. }
  81675. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81676. if(!bitreader_read_from_client_(br))
  81677. return false;
  81678. }
  81679. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81680. if(br->consumed_bits) {
  81681. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81682. const brword word = br->buffer[br->consumed_words];
  81683. if(bits < n) {
  81684. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81685. br->consumed_bits += bits;
  81686. return true;
  81687. }
  81688. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81689. bits -= n;
  81690. crc16_update_word_(br, word);
  81691. br->consumed_words++;
  81692. br->consumed_bits = 0;
  81693. if(bits) { /* if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  81694. *val <<= bits;
  81695. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81696. br->consumed_bits = bits;
  81697. }
  81698. return true;
  81699. }
  81700. else {
  81701. const brword word = br->buffer[br->consumed_words];
  81702. if(bits < FLAC__BITS_PER_WORD) {
  81703. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81704. br->consumed_bits = bits;
  81705. return true;
  81706. }
  81707. *val = word;
  81708. crc16_update_word_(br, word);
  81709. br->consumed_words++;
  81710. return true;
  81711. }
  81712. }
  81713. else {
  81714. if(br->consumed_bits) {
  81715. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81716. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81717. br->consumed_bits += bits;
  81718. return true;
  81719. }
  81720. else {
  81721. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81722. br->consumed_bits += bits;
  81723. return true;
  81724. }
  81725. }
  81726. }
  81727. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81728. {
  81729. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81730. return false;
  81731. *val <<= (32-bits);
  81732. *val >>= (32-bits);
  81733. return true;
  81734. }
  81735. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81736. {
  81737. FLAC__uint32 hi, lo;
  81738. if(bits > 32) {
  81739. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81740. return false;
  81741. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81742. return false;
  81743. *val = hi;
  81744. *val <<= 32;
  81745. *val |= lo;
  81746. }
  81747. else {
  81748. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81749. return false;
  81750. *val = lo;
  81751. }
  81752. return true;
  81753. }
  81754. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81755. {
  81756. FLAC__uint32 x8, x32 = 0;
  81757. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81758. return false;
  81759. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81760. return false;
  81761. x32 |= (x8 << 8);
  81762. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81763. return false;
  81764. x32 |= (x8 << 16);
  81765. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81766. return false;
  81767. x32 |= (x8 << 24);
  81768. *val = x32;
  81769. return true;
  81770. }
  81771. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81772. {
  81773. FLAC__ASSERT(0 != br);
  81774. FLAC__ASSERT(0 != br->buffer);
  81775. if(bits > 0) {
  81776. const unsigned n = br->consumed_bits & 7;
  81777. unsigned m;
  81778. FLAC__uint32 x;
  81779. if(n != 0) {
  81780. m = min(8-n, bits);
  81781. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81782. return false;
  81783. bits -= m;
  81784. }
  81785. m = bits / 8;
  81786. if(m > 0) {
  81787. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81788. return false;
  81789. bits %= 8;
  81790. }
  81791. if(bits > 0) {
  81792. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81793. return false;
  81794. }
  81795. }
  81796. return true;
  81797. }
  81798. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81799. {
  81800. FLAC__uint32 x;
  81801. FLAC__ASSERT(0 != br);
  81802. FLAC__ASSERT(0 != br->buffer);
  81803. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81804. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81805. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81806. return false;
  81807. nvals--;
  81808. }
  81809. if(0 == nvals)
  81810. return true;
  81811. while(nvals >= FLAC__BYTES_PER_WORD) {
  81812. if(br->consumed_words < br->words) {
  81813. br->consumed_words++;
  81814. nvals -= FLAC__BYTES_PER_WORD;
  81815. }
  81816. else if(!bitreader_read_from_client_(br))
  81817. return false;
  81818. }
  81819. while(nvals) {
  81820. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81821. return false;
  81822. nvals--;
  81823. }
  81824. return true;
  81825. }
  81826. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  81827. {
  81828. FLAC__uint32 x;
  81829. FLAC__ASSERT(0 != br);
  81830. FLAC__ASSERT(0 != br->buffer);
  81831. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81832. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81833. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81834. return false;
  81835. *val++ = (FLAC__byte)x;
  81836. nvals--;
  81837. }
  81838. if(0 == nvals)
  81839. return true;
  81840. while(nvals >= FLAC__BYTES_PER_WORD) {
  81841. if(br->consumed_words < br->words) {
  81842. const brword word = br->buffer[br->consumed_words++];
  81843. #if FLAC__BYTES_PER_WORD == 4
  81844. val[0] = (FLAC__byte)(word >> 24);
  81845. val[1] = (FLAC__byte)(word >> 16);
  81846. val[2] = (FLAC__byte)(word >> 8);
  81847. val[3] = (FLAC__byte)word;
  81848. #elif FLAC__BYTES_PER_WORD == 8
  81849. val[0] = (FLAC__byte)(word >> 56);
  81850. val[1] = (FLAC__byte)(word >> 48);
  81851. val[2] = (FLAC__byte)(word >> 40);
  81852. val[3] = (FLAC__byte)(word >> 32);
  81853. val[4] = (FLAC__byte)(word >> 24);
  81854. val[5] = (FLAC__byte)(word >> 16);
  81855. val[6] = (FLAC__byte)(word >> 8);
  81856. val[7] = (FLAC__byte)word;
  81857. #else
  81858. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  81859. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  81860. #endif
  81861. val += FLAC__BYTES_PER_WORD;
  81862. nvals -= FLAC__BYTES_PER_WORD;
  81863. }
  81864. else if(!bitreader_read_from_client_(br))
  81865. return false;
  81866. }
  81867. while(nvals) {
  81868. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81869. return false;
  81870. *val++ = (FLAC__byte)x;
  81871. nvals--;
  81872. }
  81873. return true;
  81874. }
  81875. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  81876. #if 0 /* slow but readable version */
  81877. {
  81878. unsigned bit;
  81879. FLAC__ASSERT(0 != br);
  81880. FLAC__ASSERT(0 != br->buffer);
  81881. *val = 0;
  81882. while(1) {
  81883. if(!FLAC__bitreader_read_bit(br, &bit))
  81884. return false;
  81885. if(bit)
  81886. break;
  81887. else
  81888. *val++;
  81889. }
  81890. return true;
  81891. }
  81892. #else
  81893. {
  81894. unsigned i;
  81895. FLAC__ASSERT(0 != br);
  81896. FLAC__ASSERT(0 != br->buffer);
  81897. *val = 0;
  81898. while(1) {
  81899. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81900. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  81901. if(b) {
  81902. i = COUNT_ZERO_MSBS(b);
  81903. *val += i;
  81904. i++;
  81905. br->consumed_bits += i;
  81906. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  81907. crc16_update_word_(br, br->buffer[br->consumed_words]);
  81908. br->consumed_words++;
  81909. br->consumed_bits = 0;
  81910. }
  81911. return true;
  81912. }
  81913. else {
  81914. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  81915. crc16_update_word_(br, br->buffer[br->consumed_words]);
  81916. br->consumed_words++;
  81917. br->consumed_bits = 0;
  81918. }
  81919. }
  81920. if(br->bytes) {
  81921. const unsigned end = br->bytes * 8;
  81922. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  81923. if(b) {
  81924. i = COUNT_ZERO_MSBS(b);
  81925. *val += i;
  81926. i++;
  81927. br->consumed_bits += i;
  81928. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  81929. return true;
  81930. }
  81931. else {
  81932. *val += end - br->consumed_bits;
  81933. br->consumed_bits += end;
  81934. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  81935. }
  81936. }
  81937. if(!bitreader_read_from_client_(br))
  81938. return false;
  81939. }
  81940. }
  81941. #endif
  81942. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  81943. {
  81944. FLAC__uint32 lsbs = 0, msbs = 0;
  81945. unsigned uval;
  81946. FLAC__ASSERT(0 != br);
  81947. FLAC__ASSERT(0 != br->buffer);
  81948. FLAC__ASSERT(parameter <= 31);
  81949. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  81950. return false;
  81951. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  81952. return false;
  81953. uval = (msbs << parameter) | lsbs;
  81954. if(uval & 1)
  81955. *val = -((int)(uval >> 1)) - 1;
  81956. else
  81957. *val = (int)(uval >> 1);
  81958. return true;
  81959. }
  81960. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  81961. #ifdef _MSC_VER
  81962. {
  81963. unsigned i;
  81964. unsigned uval = 0;
  81965. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  81966. register unsigned cwords;
  81967. register unsigned cbits;
  81968. FLAC__ASSERT(0 != br);
  81969. FLAC__ASSERT(0 != br->buffer);
  81970. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81971. FLAC__ASSERT(parameter < 32);
  81972. if(nvals == 0)
  81973. return true;
  81974. cbits = br->consumed_bits;
  81975. cwords = br->consumed_words;
  81976. while(1) {
  81977. while(1) {
  81978. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  81979. brword b = br->buffer[cwords] << cbits;
  81980. if(b) {
  81981. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  81982. __asm {
  81983. bsr eax, b
  81984. not eax
  81985. and eax, 31
  81986. mov i, eax
  81987. }
  81988. #else
  81989. i = COUNT_ZERO_MSBS(b);
  81990. #endif
  81991. uval += i;
  81992. bits = parameter;
  81993. i++;
  81994. cbits += i;
  81995. if(cbits == FLAC__BITS_PER_WORD) {
  81996. crc16_update_word_(br, br->buffer[cwords]);
  81997. cwords++;
  81998. cbits = 0;
  81999. }
  82000. goto break1;
  82001. }
  82002. else {
  82003. uval += FLAC__BITS_PER_WORD - cbits;
  82004. crc16_update_word_(br, br->buffer[cwords]);
  82005. cwords++;
  82006. cbits = 0;
  82007. }
  82008. }
  82009. if(br->bytes) {
  82010. const unsigned end = br->bytes * 8;
  82011. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82012. if(b) {
  82013. i = COUNT_ZERO_MSBS(b);
  82014. uval += i;
  82015. bits = parameter;
  82016. i++;
  82017. cbits += i;
  82018. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82019. goto break1;
  82020. }
  82021. else {
  82022. uval += end - cbits;
  82023. cbits += end;
  82024. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82025. }
  82026. }
  82027. br->consumed_bits = cbits;
  82028. br->consumed_words = cwords;
  82029. if(!bitreader_read_from_client_(br))
  82030. return false;
  82031. cwords = br->consumed_words;
  82032. }
  82033. break1:
  82034. FLAC__ASSERT(cwords <= br->words);
  82035. if(bits) {
  82036. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82037. br->consumed_bits = cbits;
  82038. br->consumed_words = cwords;
  82039. if(!bitreader_read_from_client_(br))
  82040. return false;
  82041. cwords = br->consumed_words;
  82042. }
  82043. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82044. if(cbits) {
  82045. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82046. const brword word = br->buffer[cwords];
  82047. if(bits < n) {
  82048. uval <<= bits;
  82049. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82050. cbits += bits;
  82051. goto break2;
  82052. }
  82053. uval <<= n;
  82054. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82055. bits -= n;
  82056. crc16_update_word_(br, word);
  82057. cwords++;
  82058. cbits = 0;
  82059. if(bits) { /* if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  82060. uval <<= bits;
  82061. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82062. cbits = bits;
  82063. }
  82064. goto break2;
  82065. }
  82066. else {
  82067. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82068. uval <<= bits;
  82069. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82070. cbits = bits;
  82071. goto break2;
  82072. }
  82073. }
  82074. else {
  82075. uval <<= bits;
  82076. if(cbits) {
  82077. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82078. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82079. cbits += bits;
  82080. goto break2;
  82081. }
  82082. else {
  82083. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82084. cbits += bits;
  82085. goto break2;
  82086. }
  82087. }
  82088. }
  82089. break2:
  82090. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82091. --nvals;
  82092. if(nvals == 0) {
  82093. br->consumed_bits = cbits;
  82094. br->consumed_words = cwords;
  82095. return true;
  82096. }
  82097. uval = 0;
  82098. ++vals;
  82099. }
  82100. }
  82101. #else
  82102. {
  82103. unsigned i;
  82104. unsigned uval = 0;
  82105. register unsigned cwords;
  82106. register unsigned cbits;
  82107. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82108. FLAC__ASSERT(0 != br);
  82109. FLAC__ASSERT(0 != br->buffer);
  82110. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82111. FLAC__ASSERT(parameter < 32);
  82112. if(nvals == 0)
  82113. return true;
  82114. cbits = br->consumed_bits;
  82115. cwords = br->consumed_words;
  82116. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82117. while(1) {
  82118. while(1) {
  82119. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82120. brword b = br->buffer[cwords] << cbits;
  82121. if(b) {
  82122. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82123. asm volatile (
  82124. "bsrl %1, %0;"
  82125. "notl %0;"
  82126. "andl $31, %0;"
  82127. : "=r"(i)
  82128. : "r"(b)
  82129. );
  82130. #else
  82131. i = COUNT_ZERO_MSBS(b);
  82132. #endif
  82133. uval += i;
  82134. cbits += i;
  82135. cbits++; /* skip over stop bit */
  82136. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82137. crc16_update_word_(br, br->buffer[cwords]);
  82138. cwords++;
  82139. cbits = 0;
  82140. }
  82141. goto break1;
  82142. }
  82143. else {
  82144. uval += FLAC__BITS_PER_WORD - cbits;
  82145. crc16_update_word_(br, br->buffer[cwords]);
  82146. cwords++;
  82147. cbits = 0;
  82148. }
  82149. }
  82150. if(br->bytes) {
  82151. const unsigned end = br->bytes * 8;
  82152. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82153. if(b) {
  82154. i = COUNT_ZERO_MSBS(b);
  82155. uval += i;
  82156. cbits += i;
  82157. cbits++; /* skip over stop bit */
  82158. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82159. goto break1;
  82160. }
  82161. else {
  82162. uval += end - cbits;
  82163. cbits += end;
  82164. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82165. }
  82166. }
  82167. br->consumed_bits = cbits;
  82168. br->consumed_words = cwords;
  82169. if(!bitreader_read_from_client_(br))
  82170. return false;
  82171. cwords = br->consumed_words;
  82172. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82173. }
  82174. break1:
  82175. ucbits -= uval;
  82176. ucbits--; /* account for stop bit */
  82177. FLAC__ASSERT(cwords <= br->words);
  82178. if(parameter) {
  82179. while(ucbits < parameter) {
  82180. br->consumed_bits = cbits;
  82181. br->consumed_words = cwords;
  82182. if(!bitreader_read_from_client_(br))
  82183. return false;
  82184. cwords = br->consumed_words;
  82185. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82186. }
  82187. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82188. if(cbits) {
  82189. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82190. const brword word = br->buffer[cwords];
  82191. if(parameter < n) {
  82192. uval <<= parameter;
  82193. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82194. cbits += parameter;
  82195. }
  82196. else {
  82197. uval <<= n;
  82198. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82199. crc16_update_word_(br, word);
  82200. cwords++;
  82201. cbits = parameter - n;
  82202. if(cbits) { /* parameter > n, i.e. if there are still bits left to read, there have to be less than 32 so they will all be in the next word */
  82203. uval <<= cbits;
  82204. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82205. }
  82206. }
  82207. }
  82208. else {
  82209. cbits = parameter;
  82210. uval <<= parameter;
  82211. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82212. }
  82213. }
  82214. else {
  82215. uval <<= parameter;
  82216. if(cbits) {
  82217. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82218. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82219. cbits += parameter;
  82220. }
  82221. else {
  82222. cbits = parameter;
  82223. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82224. }
  82225. }
  82226. }
  82227. ucbits -= parameter;
  82228. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82229. --nvals;
  82230. if(nvals == 0) {
  82231. br->consumed_bits = cbits;
  82232. br->consumed_words = cwords;
  82233. return true;
  82234. }
  82235. uval = 0;
  82236. ++vals;
  82237. }
  82238. }
  82239. #endif
  82240. #if 0 /* UNUSED */
  82241. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82242. {
  82243. FLAC__uint32 lsbs = 0, msbs = 0;
  82244. unsigned bit, uval, k;
  82245. FLAC__ASSERT(0 != br);
  82246. FLAC__ASSERT(0 != br->buffer);
  82247. k = FLAC__bitmath_ilog2(parameter);
  82248. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82249. return false;
  82250. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82251. return false;
  82252. if(parameter == 1u<<k) {
  82253. uval = (msbs << k) | lsbs;
  82254. }
  82255. else {
  82256. unsigned d = (1 << (k+1)) - parameter;
  82257. if(lsbs >= d) {
  82258. if(!FLAC__bitreader_read_bit(br, &bit))
  82259. return false;
  82260. lsbs <<= 1;
  82261. lsbs |= bit;
  82262. lsbs -= d;
  82263. }
  82264. uval = msbs * parameter + lsbs;
  82265. }
  82266. if(uval & 1)
  82267. *val = -((int)(uval >> 1)) - 1;
  82268. else
  82269. *val = (int)(uval >> 1);
  82270. return true;
  82271. }
  82272. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82273. {
  82274. FLAC__uint32 lsbs, msbs = 0;
  82275. unsigned bit, k;
  82276. FLAC__ASSERT(0 != br);
  82277. FLAC__ASSERT(0 != br->buffer);
  82278. k = FLAC__bitmath_ilog2(parameter);
  82279. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82280. return false;
  82281. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82282. return false;
  82283. if(parameter == 1u<<k) {
  82284. *val = (msbs << k) | lsbs;
  82285. }
  82286. else {
  82287. unsigned d = (1 << (k+1)) - parameter;
  82288. if(lsbs >= d) {
  82289. if(!FLAC__bitreader_read_bit(br, &bit))
  82290. return false;
  82291. lsbs <<= 1;
  82292. lsbs |= bit;
  82293. lsbs -= d;
  82294. }
  82295. *val = msbs * parameter + lsbs;
  82296. }
  82297. return true;
  82298. }
  82299. #endif /* UNUSED */
  82300. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82301. {
  82302. FLAC__uint32 v = 0;
  82303. FLAC__uint32 x;
  82304. unsigned i;
  82305. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82306. return false;
  82307. if(raw)
  82308. raw[(*rawlen)++] = (FLAC__byte)x;
  82309. if(!(x & 0x80)) { /* 0xxxxxxx */
  82310. v = x;
  82311. i = 0;
  82312. }
  82313. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82314. v = x & 0x1F;
  82315. i = 1;
  82316. }
  82317. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82318. v = x & 0x0F;
  82319. i = 2;
  82320. }
  82321. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82322. v = x & 0x07;
  82323. i = 3;
  82324. }
  82325. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82326. v = x & 0x03;
  82327. i = 4;
  82328. }
  82329. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82330. v = x & 0x01;
  82331. i = 5;
  82332. }
  82333. else {
  82334. *val = 0xffffffff;
  82335. return true;
  82336. }
  82337. for( ; i; i--) {
  82338. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82339. return false;
  82340. if(raw)
  82341. raw[(*rawlen)++] = (FLAC__byte)x;
  82342. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82343. *val = 0xffffffff;
  82344. return true;
  82345. }
  82346. v <<= 6;
  82347. v |= (x & 0x3F);
  82348. }
  82349. *val = v;
  82350. return true;
  82351. }
  82352. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82353. {
  82354. FLAC__uint64 v = 0;
  82355. FLAC__uint32 x;
  82356. unsigned i;
  82357. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82358. return false;
  82359. if(raw)
  82360. raw[(*rawlen)++] = (FLAC__byte)x;
  82361. if(!(x & 0x80)) { /* 0xxxxxxx */
  82362. v = x;
  82363. i = 0;
  82364. }
  82365. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82366. v = x & 0x1F;
  82367. i = 1;
  82368. }
  82369. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82370. v = x & 0x0F;
  82371. i = 2;
  82372. }
  82373. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82374. v = x & 0x07;
  82375. i = 3;
  82376. }
  82377. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82378. v = x & 0x03;
  82379. i = 4;
  82380. }
  82381. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82382. v = x & 0x01;
  82383. i = 5;
  82384. }
  82385. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82386. v = 0;
  82387. i = 6;
  82388. }
  82389. else {
  82390. *val = FLAC__U64L(0xffffffffffffffff);
  82391. return true;
  82392. }
  82393. for( ; i; i--) {
  82394. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82395. return false;
  82396. if(raw)
  82397. raw[(*rawlen)++] = (FLAC__byte)x;
  82398. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82399. *val = FLAC__U64L(0xffffffffffffffff);
  82400. return true;
  82401. }
  82402. v <<= 6;
  82403. v |= (x & 0x3F);
  82404. }
  82405. *val = v;
  82406. return true;
  82407. }
  82408. #endif
  82409. /*** End of inlined file: bitreader.c ***/
  82410. /*** Start of inlined file: bitwriter.c ***/
  82411. /*** Start of inlined file: juce_FlacHeader.h ***/
  82412. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82413. // tasks..
  82414. #define VERSION "1.2.1"
  82415. #define FLAC__NO_DLL 1
  82416. #if JUCE_MSVC
  82417. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82418. #endif
  82419. #if JUCE_MAC
  82420. #define FLAC__SYS_DARWIN 1
  82421. #endif
  82422. /*** End of inlined file: juce_FlacHeader.h ***/
  82423. #if JUCE_USE_FLAC
  82424. #if HAVE_CONFIG_H
  82425. # include <config.h>
  82426. #endif
  82427. #include <stdlib.h> /* for malloc() */
  82428. #include <string.h> /* for memcpy(), memset() */
  82429. #ifdef _MSC_VER
  82430. #include <winsock.h> /* for ntohl() */
  82431. #elif defined FLAC__SYS_DARWIN
  82432. #include <machine/endian.h> /* for ntohl() */
  82433. #elif defined __MINGW32__
  82434. #include <winsock.h> /* for ntohl() */
  82435. #else
  82436. #include <netinet/in.h> /* for ntohl() */
  82437. #endif
  82438. #if 0 /* UNUSED */
  82439. #endif
  82440. /*** Start of inlined file: bitwriter.h ***/
  82441. #ifndef FLAC__PRIVATE__BITWRITER_H
  82442. #define FLAC__PRIVATE__BITWRITER_H
  82443. #include <stdio.h> /* for FILE */
  82444. struct FLAC__BitWriter;
  82445. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82446. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82447. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82448. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82449. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82450. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82451. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82452. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82453. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82454. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82455. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82456. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82457. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82458. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82459. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82460. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82461. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82462. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82463. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82464. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82465. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82466. #if 0 /* UNUSED */
  82467. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82468. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82469. #endif
  82470. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82471. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82472. #if 0 /* UNUSED */
  82473. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82474. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82475. #endif
  82476. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82477. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82478. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82479. #endif
  82480. /*** End of inlined file: bitwriter.h ***/
  82481. /*** Start of inlined file: alloc.h ***/
  82482. #ifndef FLAC__SHARE__ALLOC_H
  82483. #define FLAC__SHARE__ALLOC_H
  82484. #if HAVE_CONFIG_H
  82485. # include <config.h>
  82486. #endif
  82487. #include <limits.h> /* for SIZE_MAX */
  82488. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82489. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82490. #endif
  82491. #include <stdlib.h> /* for size_t, malloc(), etc */
  82492. #ifndef SIZE_MAX
  82493. # ifndef SIZE_T_MAX
  82494. # ifdef _MSC_VER
  82495. # define SIZE_T_MAX UINT_MAX
  82496. # else
  82497. # error
  82498. # endif
  82499. # endif
  82500. # define SIZE_MAX SIZE_T_MAX
  82501. #endif
  82502. #ifndef FLaC__INLINE
  82503. #define FLaC__INLINE
  82504. #endif
  82505. static FLaC__INLINE void *safe_malloc_(size_t size)
  82506. {
  82507. if(!size)
  82508. size++;
  82509. return malloc(size);
  82510. }
  82511. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82512. {
  82513. if(!nmemb || !size)
  82514. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82515. return calloc(nmemb, size);
  82516. }
  82517. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82518. {
  82519. size2 += size1;
  82520. if(size2 < size1)
  82521. return 0;
  82522. return safe_malloc_(size2);
  82523. }
  82524. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82525. {
  82526. size2 += size1;
  82527. if(size2 < size1)
  82528. return 0;
  82529. size3 += size2;
  82530. if(size3 < size2)
  82531. return 0;
  82532. return safe_malloc_(size3);
  82533. }
  82534. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82535. {
  82536. size2 += size1;
  82537. if(size2 < size1)
  82538. return 0;
  82539. size3 += size2;
  82540. if(size3 < size2)
  82541. return 0;
  82542. size4 += size3;
  82543. if(size4 < size3)
  82544. return 0;
  82545. return safe_malloc_(size4);
  82546. }
  82547. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82548. #if 0
  82549. needs support for cases where sizeof(size_t) != 4
  82550. {
  82551. if(sizeof(size_t) == 4) {
  82552. if ((double)size1 * (double)size2 < 4294967296.0)
  82553. return malloc(size1*size2);
  82554. }
  82555. return 0;
  82556. }
  82557. #else
  82558. {
  82559. if(!size1 || !size2)
  82560. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82561. if(size1 > SIZE_MAX / size2)
  82562. return 0;
  82563. return malloc(size1*size2);
  82564. }
  82565. #endif
  82566. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82567. {
  82568. if(!size1 || !size2 || !size3)
  82569. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82570. if(size1 > SIZE_MAX / size2)
  82571. return 0;
  82572. size1 *= size2;
  82573. if(size1 > SIZE_MAX / size3)
  82574. return 0;
  82575. return malloc(size1*size3);
  82576. }
  82577. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82578. {
  82579. if(!size1 || !size2)
  82580. return safe_malloc_(size3);
  82581. if(size1 > SIZE_MAX / size2)
  82582. return 0;
  82583. return safe_malloc_add_2op_(size1*size2, size3);
  82584. }
  82585. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82586. {
  82587. if(!size1 || (!size2 && !size3))
  82588. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82589. size2 += size3;
  82590. if(size2 < size3)
  82591. return 0;
  82592. return safe_malloc_mul_2op_(size1, size2);
  82593. }
  82594. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82595. {
  82596. size2 += size1;
  82597. if(size2 < size1)
  82598. return 0;
  82599. return realloc(ptr, size2);
  82600. }
  82601. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82602. {
  82603. size2 += size1;
  82604. if(size2 < size1)
  82605. return 0;
  82606. size3 += size2;
  82607. if(size3 < size2)
  82608. return 0;
  82609. return realloc(ptr, size3);
  82610. }
  82611. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82612. {
  82613. size2 += size1;
  82614. if(size2 < size1)
  82615. return 0;
  82616. size3 += size2;
  82617. if(size3 < size2)
  82618. return 0;
  82619. size4 += size3;
  82620. if(size4 < size3)
  82621. return 0;
  82622. return realloc(ptr, size4);
  82623. }
  82624. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82625. {
  82626. if(!size1 || !size2)
  82627. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82628. if(size1 > SIZE_MAX / size2)
  82629. return 0;
  82630. return realloc(ptr, size1*size2);
  82631. }
  82632. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82633. {
  82634. if(!size1 || (!size2 && !size3))
  82635. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82636. size2 += size3;
  82637. if(size2 < size3)
  82638. return 0;
  82639. return safe_realloc_mul_2op_(ptr, size1, size2);
  82640. }
  82641. #endif
  82642. /*** End of inlined file: alloc.h ***/
  82643. typedef FLAC__uint32 bwword;
  82644. #define FLAC__BYTES_PER_WORD 4
  82645. #define FLAC__BITS_PER_WORD 32
  82646. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82647. #if WORDS_BIGENDIAN
  82648. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82649. #else
  82650. #ifdef _MSC_VER
  82651. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82652. #else
  82653. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82654. #endif
  82655. #endif
  82656. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82657. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82658. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82659. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82660. #ifdef min
  82661. #undef min
  82662. #endif
  82663. #define min(x,y) ((x)<(y)?(x):(y))
  82664. #ifdef _MSC_VER
  82665. #define FLAC__U64L(x) x
  82666. #else
  82667. #define FLAC__U64L(x) x##LLU
  82668. #endif
  82669. #ifndef FLaC__INLINE
  82670. #define FLaC__INLINE
  82671. #endif
  82672. struct FLAC__BitWriter {
  82673. bwword *buffer;
  82674. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82675. unsigned capacity; /* capacity of buffer in words */
  82676. unsigned words; /* # of complete words in buffer */
  82677. unsigned bits; /* # of used bits in accum */
  82678. };
  82679. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82680. {
  82681. unsigned new_capacity;
  82682. bwword *new_buffer;
  82683. FLAC__ASSERT(0 != bw);
  82684. FLAC__ASSERT(0 != bw->buffer);
  82685. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82686. if(bw->capacity >= new_capacity)
  82687. return true;
  82688. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82689. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82690. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82691. FLAC__ASSERT(new_capacity > bw->capacity);
  82692. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82693. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82694. if(new_buffer == 0)
  82695. return false;
  82696. bw->buffer = new_buffer;
  82697. bw->capacity = new_capacity;
  82698. return true;
  82699. }
  82700. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82701. {
  82702. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82703. return bw;
  82704. }
  82705. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82706. {
  82707. FLAC__ASSERT(0 != bw);
  82708. FLAC__bitwriter_free(bw);
  82709. free(bw);
  82710. }
  82711. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82712. {
  82713. FLAC__ASSERT(0 != bw);
  82714. bw->words = bw->bits = 0;
  82715. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82716. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82717. if(bw->buffer == 0)
  82718. return false;
  82719. return true;
  82720. }
  82721. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82722. {
  82723. FLAC__ASSERT(0 != bw);
  82724. if(0 != bw->buffer)
  82725. free(bw->buffer);
  82726. bw->buffer = 0;
  82727. bw->capacity = 0;
  82728. bw->words = bw->bits = 0;
  82729. }
  82730. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82731. {
  82732. bw->words = bw->bits = 0;
  82733. }
  82734. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82735. {
  82736. unsigned i, j;
  82737. if(bw == 0) {
  82738. fprintf(out, "bitwriter is NULL\n");
  82739. }
  82740. else {
  82741. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82742. for(i = 0; i < bw->words; i++) {
  82743. fprintf(out, "%08X: ", i);
  82744. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82745. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82746. fprintf(out, "\n");
  82747. }
  82748. if(bw->bits > 0) {
  82749. fprintf(out, "%08X: ", i);
  82750. for(j = 0; j < bw->bits; j++)
  82751. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82752. fprintf(out, "\n");
  82753. }
  82754. }
  82755. }
  82756. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82757. {
  82758. const FLAC__byte *buffer;
  82759. size_t bytes;
  82760. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82761. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82762. return false;
  82763. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82764. FLAC__bitwriter_release_buffer(bw);
  82765. return true;
  82766. }
  82767. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  82768. {
  82769. const FLAC__byte *buffer;
  82770. size_t bytes;
  82771. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82772. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82773. return false;
  82774. *crc = FLAC__crc8(buffer, bytes);
  82775. FLAC__bitwriter_release_buffer(bw);
  82776. return true;
  82777. }
  82778. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82779. {
  82780. return ((bw->bits & 7) == 0);
  82781. }
  82782. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82783. {
  82784. return FLAC__TOTAL_BITS(bw);
  82785. }
  82786. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82787. {
  82788. FLAC__ASSERT((bw->bits & 7) == 0);
  82789. if(bw->bits & 7)
  82790. return false;
  82791. if(bw->bits) {
  82792. FLAC__ASSERT(bw->words <= bw->capacity);
  82793. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82794. return false;
  82795. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82796. }
  82797. *buffer = (FLAC__byte*)bw->buffer;
  82798. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82799. return true;
  82800. }
  82801. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82802. {
  82803. (void)bw;
  82804. }
  82805. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82806. {
  82807. unsigned n;
  82808. FLAC__ASSERT(0 != bw);
  82809. FLAC__ASSERT(0 != bw->buffer);
  82810. if(bits == 0)
  82811. return true;
  82812. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82813. return false;
  82814. if(bw->bits) {
  82815. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  82816. bw->accum <<= n;
  82817. bits -= n;
  82818. bw->bits += n;
  82819. if(bw->bits == FLAC__BITS_PER_WORD) {
  82820. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82821. bw->bits = 0;
  82822. }
  82823. else
  82824. return true;
  82825. }
  82826. while(bits >= FLAC__BITS_PER_WORD) {
  82827. bw->buffer[bw->words++] = 0;
  82828. bits -= FLAC__BITS_PER_WORD;
  82829. }
  82830. if(bits > 0) {
  82831. bw->accum = 0;
  82832. bw->bits = bits;
  82833. }
  82834. return true;
  82835. }
  82836. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  82837. {
  82838. register unsigned left;
  82839. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82840. FLAC__ASSERT(0 != bw);
  82841. FLAC__ASSERT(0 != bw->buffer);
  82842. FLAC__ASSERT(bits <= 32);
  82843. if(bits == 0)
  82844. return true;
  82845. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82846. return false;
  82847. left = FLAC__BITS_PER_WORD - bw->bits;
  82848. if(bits < left) {
  82849. bw->accum <<= bits;
  82850. bw->accum |= val;
  82851. bw->bits += bits;
  82852. }
  82853. else if(bw->bits) { /* WATCHOUT: if bw->bits == 0, left==FLAC__BITS_PER_WORD and bw->accum<<=left is a NOP instead of setting to 0 */
  82854. bw->accum <<= left;
  82855. bw->accum |= val >> (bw->bits = bits - left);
  82856. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82857. bw->accum = val;
  82858. }
  82859. else {
  82860. bw->accum = val;
  82861. bw->bits = 0;
  82862. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  82863. }
  82864. return true;
  82865. }
  82866. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  82867. {
  82868. if(bits < 32)
  82869. val &= (~(0xffffffff << bits));
  82870. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82871. }
  82872. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  82873. {
  82874. if(bits > 32) {
  82875. return
  82876. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  82877. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  82878. }
  82879. else
  82880. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82881. }
  82882. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  82883. {
  82884. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  82885. return false;
  82886. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  82887. return false;
  82888. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  82889. return false;
  82890. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  82891. return false;
  82892. return true;
  82893. }
  82894. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  82895. {
  82896. unsigned i;
  82897. for(i = 0; i < nvals; i++) {
  82898. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  82899. return false;
  82900. }
  82901. return true;
  82902. }
  82903. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  82904. {
  82905. if(val < 32)
  82906. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  82907. else
  82908. return
  82909. FLAC__bitwriter_write_zeroes(bw, val) &&
  82910. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  82911. }
  82912. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  82913. {
  82914. FLAC__uint32 uval;
  82915. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  82916. uval = (val<<1) ^ (val>>31);
  82917. return 1 + parameter + (uval >> parameter);
  82918. }
  82919. #if 0 /* UNUSED */
  82920. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  82921. {
  82922. unsigned bits, msbs, uval;
  82923. unsigned k;
  82924. FLAC__ASSERT(parameter > 0);
  82925. if(val < 0)
  82926. uval = (unsigned)(((-(++val)) << 1) + 1);
  82927. else
  82928. uval = (unsigned)(val << 1);
  82929. k = FLAC__bitmath_ilog2(parameter);
  82930. if(parameter == 1u<<k) {
  82931. FLAC__ASSERT(k <= 30);
  82932. msbs = uval >> k;
  82933. bits = 1 + k + msbs;
  82934. }
  82935. else {
  82936. unsigned q, r, d;
  82937. d = (1 << (k+1)) - parameter;
  82938. q = uval / parameter;
  82939. r = uval - (q * parameter);
  82940. bits = 1 + q + k;
  82941. if(r >= d)
  82942. bits++;
  82943. }
  82944. return bits;
  82945. }
  82946. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  82947. {
  82948. unsigned bits, msbs;
  82949. unsigned k;
  82950. FLAC__ASSERT(parameter > 0);
  82951. k = FLAC__bitmath_ilog2(parameter);
  82952. if(parameter == 1u<<k) {
  82953. FLAC__ASSERT(k <= 30);
  82954. msbs = uval >> k;
  82955. bits = 1 + k + msbs;
  82956. }
  82957. else {
  82958. unsigned q, r, d;
  82959. d = (1 << (k+1)) - parameter;
  82960. q = uval / parameter;
  82961. r = uval - (q * parameter);
  82962. bits = 1 + q + k;
  82963. if(r >= d)
  82964. bits++;
  82965. }
  82966. return bits;
  82967. }
  82968. #endif /* UNUSED */
  82969. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  82970. {
  82971. unsigned total_bits, interesting_bits, msbs;
  82972. FLAC__uint32 uval, pattern;
  82973. FLAC__ASSERT(0 != bw);
  82974. FLAC__ASSERT(0 != bw->buffer);
  82975. FLAC__ASSERT(parameter < 8*sizeof(uval));
  82976. uval = (val<<1) ^ (val>>31);
  82977. msbs = uval >> parameter;
  82978. interesting_bits = 1 + parameter;
  82979. total_bits = interesting_bits + msbs;
  82980. pattern = 1 << parameter; /* the unary end bit */
  82981. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  82982. if(total_bits <= 32)
  82983. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  82984. else
  82985. return
  82986. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  82987. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  82988. }
  82989. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  82990. {
  82991. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  82992. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  82993. FLAC__uint32 uval;
  82994. unsigned left;
  82995. const unsigned lsbits = 1 + parameter;
  82996. unsigned msbits;
  82997. FLAC__ASSERT(0 != bw);
  82998. FLAC__ASSERT(0 != bw->buffer);
  82999. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83000. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83001. while(nvals) {
  83002. uval = (*vals<<1) ^ (*vals>>31);
  83003. msbits = uval >> parameter;
  83004. #if 0 /* OPT: can remove this special case if it doesn't make up for the extra compare (doesn't make a statistically significant difference with msvc or gcc/x86) */
  83005. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83006. bw->bits = bw->bits + msbits + lsbits;
  83007. uval |= mask1; /* set stop bit */
  83008. uval &= mask2; /* mask off unused top bits */
  83009. bw->accum <<= msbits;
  83010. bw->accum <<= lsbits;
  83011. bw->accum |= uval;
  83012. if(bw->bits == FLAC__BITS_PER_WORD) {
  83013. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83014. bw->bits = 0;
  83015. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83016. FLAC__ASSERT(bw->capacity == bw->words);
  83017. return false;
  83018. }
  83019. }
  83020. }
  83021. else {
  83022. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83023. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83024. bw->bits = bw->bits + msbits + lsbits;
  83025. uval |= mask1; /* set stop bit */
  83026. uval &= mask2; /* mask off unused top bits */
  83027. bw->accum <<= msbits + lsbits;
  83028. bw->accum |= uval;
  83029. }
  83030. else {
  83031. #endif
  83032. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83033. return false;
  83034. if(msbits) {
  83035. if(bw->bits) {
  83036. left = FLAC__BITS_PER_WORD - bw->bits;
  83037. if(msbits < left) {
  83038. bw->accum <<= msbits;
  83039. bw->bits += msbits;
  83040. goto break1;
  83041. }
  83042. else {
  83043. bw->accum <<= left;
  83044. msbits -= left;
  83045. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83046. bw->bits = 0;
  83047. }
  83048. }
  83049. while(msbits >= FLAC__BITS_PER_WORD) {
  83050. bw->buffer[bw->words++] = 0;
  83051. msbits -= FLAC__BITS_PER_WORD;
  83052. }
  83053. if(msbits > 0) {
  83054. bw->accum = 0;
  83055. bw->bits = msbits;
  83056. }
  83057. }
  83058. break1:
  83059. uval |= mask1; /* set stop bit */
  83060. uval &= mask2; /* mask off unused top bits */
  83061. left = FLAC__BITS_PER_WORD - bw->bits;
  83062. if(lsbits < left) {
  83063. bw->accum <<= lsbits;
  83064. bw->accum |= uval;
  83065. bw->bits += lsbits;
  83066. }
  83067. else {
  83068. FLAC__ASSERT(bw->bits);
  83069. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83070. bw->accum <<= left;
  83071. bw->accum |= uval >> (bw->bits = lsbits - left);
  83072. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83073. bw->accum = uval;
  83074. }
  83075. #if 1
  83076. }
  83077. #endif
  83078. vals++;
  83079. nvals--;
  83080. }
  83081. return true;
  83082. }
  83083. #if 0 /* UNUSED */
  83084. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83085. {
  83086. unsigned total_bits, msbs, uval;
  83087. unsigned k;
  83088. FLAC__ASSERT(0 != bw);
  83089. FLAC__ASSERT(0 != bw->buffer);
  83090. FLAC__ASSERT(parameter > 0);
  83091. if(val < 0)
  83092. uval = (unsigned)(((-(++val)) << 1) + 1);
  83093. else
  83094. uval = (unsigned)(val << 1);
  83095. k = FLAC__bitmath_ilog2(parameter);
  83096. if(parameter == 1u<<k) {
  83097. unsigned pattern;
  83098. FLAC__ASSERT(k <= 30);
  83099. msbs = uval >> k;
  83100. total_bits = 1 + k + msbs;
  83101. pattern = 1 << k; /* the unary end bit */
  83102. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83103. if(total_bits <= 32) {
  83104. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83105. return false;
  83106. }
  83107. else {
  83108. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83109. return false;
  83110. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83111. return false;
  83112. }
  83113. }
  83114. else {
  83115. unsigned q, r, d;
  83116. d = (1 << (k+1)) - parameter;
  83117. q = uval / parameter;
  83118. r = uval - (q * parameter);
  83119. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83120. return false;
  83121. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83122. return false;
  83123. if(r >= d) {
  83124. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83125. return false;
  83126. }
  83127. else {
  83128. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83129. return false;
  83130. }
  83131. }
  83132. return true;
  83133. }
  83134. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83135. {
  83136. unsigned total_bits, msbs;
  83137. unsigned k;
  83138. FLAC__ASSERT(0 != bw);
  83139. FLAC__ASSERT(0 != bw->buffer);
  83140. FLAC__ASSERT(parameter > 0);
  83141. k = FLAC__bitmath_ilog2(parameter);
  83142. if(parameter == 1u<<k) {
  83143. unsigned pattern;
  83144. FLAC__ASSERT(k <= 30);
  83145. msbs = uval >> k;
  83146. total_bits = 1 + k + msbs;
  83147. pattern = 1 << k; /* the unary end bit */
  83148. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83149. if(total_bits <= 32) {
  83150. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83151. return false;
  83152. }
  83153. else {
  83154. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83155. return false;
  83156. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83157. return false;
  83158. }
  83159. }
  83160. else {
  83161. unsigned q, r, d;
  83162. d = (1 << (k+1)) - parameter;
  83163. q = uval / parameter;
  83164. r = uval - (q * parameter);
  83165. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83166. return false;
  83167. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83168. return false;
  83169. if(r >= d) {
  83170. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83171. return false;
  83172. }
  83173. else {
  83174. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83175. return false;
  83176. }
  83177. }
  83178. return true;
  83179. }
  83180. #endif /* UNUSED */
  83181. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83182. {
  83183. FLAC__bool ok = 1;
  83184. FLAC__ASSERT(0 != bw);
  83185. FLAC__ASSERT(0 != bw->buffer);
  83186. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83187. if(val < 0x80) {
  83188. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83189. }
  83190. else if(val < 0x800) {
  83191. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83192. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83193. }
  83194. else if(val < 0x10000) {
  83195. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83196. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83197. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83198. }
  83199. else if(val < 0x200000) {
  83200. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83201. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83202. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83203. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83204. }
  83205. else if(val < 0x4000000) {
  83206. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83207. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83208. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83209. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83210. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83211. }
  83212. else {
  83213. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83214. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83215. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83216. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83217. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83218. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83219. }
  83220. return ok;
  83221. }
  83222. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83223. {
  83224. FLAC__bool ok = 1;
  83225. FLAC__ASSERT(0 != bw);
  83226. FLAC__ASSERT(0 != bw->buffer);
  83227. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83228. if(val < 0x80) {
  83229. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83230. }
  83231. else if(val < 0x800) {
  83232. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83233. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83234. }
  83235. else if(val < 0x10000) {
  83236. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83237. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83238. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83239. }
  83240. else if(val < 0x200000) {
  83241. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83242. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83243. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83244. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83245. }
  83246. else if(val < 0x4000000) {
  83247. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83248. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83249. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83250. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83251. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83252. }
  83253. else if(val < 0x80000000) {
  83254. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83255. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83256. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83257. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83258. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83259. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83260. }
  83261. else {
  83262. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83263. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83264. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83265. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83266. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83267. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83268. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83269. }
  83270. return ok;
  83271. }
  83272. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83273. {
  83274. if(bw->bits & 7u)
  83275. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83276. else
  83277. return true;
  83278. }
  83279. #endif
  83280. /*** End of inlined file: bitwriter.c ***/
  83281. /*** Start of inlined file: cpu.c ***/
  83282. /*** Start of inlined file: juce_FlacHeader.h ***/
  83283. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83284. // tasks..
  83285. #define VERSION "1.2.1"
  83286. #define FLAC__NO_DLL 1
  83287. #if JUCE_MSVC
  83288. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83289. #endif
  83290. #if JUCE_MAC
  83291. #define FLAC__SYS_DARWIN 1
  83292. #endif
  83293. /*** End of inlined file: juce_FlacHeader.h ***/
  83294. #if JUCE_USE_FLAC
  83295. #if HAVE_CONFIG_H
  83296. # include <config.h>
  83297. #endif
  83298. #include <stdlib.h>
  83299. #include <stdio.h>
  83300. #if defined FLAC__CPU_IA32
  83301. # include <signal.h>
  83302. #elif defined FLAC__CPU_PPC
  83303. # if !defined FLAC__NO_ASM
  83304. # if defined FLAC__SYS_DARWIN
  83305. # include <sys/sysctl.h>
  83306. # include <mach/mach.h>
  83307. # include <mach/mach_host.h>
  83308. # include <mach/host_info.h>
  83309. # include <mach/machine.h>
  83310. # ifndef CPU_SUBTYPE_POWERPC_970
  83311. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83312. # endif
  83313. # else /* FLAC__SYS_DARWIN */
  83314. # include <signal.h>
  83315. # include <setjmp.h>
  83316. static sigjmp_buf jmpbuf;
  83317. static volatile sig_atomic_t canjump = 0;
  83318. static void sigill_handler (int sig)
  83319. {
  83320. if (!canjump) {
  83321. signal (sig, SIG_DFL);
  83322. raise (sig);
  83323. }
  83324. canjump = 0;
  83325. siglongjmp (jmpbuf, 1);
  83326. }
  83327. # endif /* FLAC__SYS_DARWIN */
  83328. # endif /* FLAC__NO_ASM */
  83329. #endif /* FLAC__CPU_PPC */
  83330. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83331. #include <sys/param.h>
  83332. #include <sys/sysctl.h>
  83333. #include <machine/cpu.h>
  83334. #endif
  83335. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83336. #include <sys/types.h>
  83337. #include <sys/sysctl.h>
  83338. #endif
  83339. #if defined(__APPLE__)
  83340. #endif
  83341. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83342. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83343. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83344. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83345. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83346. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83347. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83348. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83349. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83350. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83351. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83352. # if defined(__linux__)
  83353. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83354. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83355. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83356. {
  83357. (void)signal;
  83358. sc.eip += 3 + 3 + 6;
  83359. }
  83360. # else
  83361. # include <sys/ucontext.h>
  83362. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83363. {
  83364. (void)signal, (void)si;
  83365. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83366. }
  83367. # endif
  83368. # elif defined(_MSC_VER)
  83369. # include <windows.h>
  83370. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83371. # ifdef USE_TRY_CATCH_FLAVOR
  83372. # else
  83373. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83374. {
  83375. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83376. ep->ContextRecord->Eip += 3 + 3 + 6;
  83377. return EXCEPTION_CONTINUE_EXECUTION;
  83378. }
  83379. return EXCEPTION_CONTINUE_SEARCH;
  83380. }
  83381. # endif
  83382. # endif
  83383. #endif
  83384. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83385. {
  83386. #ifdef FLAC__CPU_IA32
  83387. info->type = FLAC__CPUINFO_TYPE_IA32;
  83388. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83389. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83390. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83391. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83392. info->data.ia32.cmov = false;
  83393. info->data.ia32.mmx = false;
  83394. info->data.ia32.fxsr = false;
  83395. info->data.ia32.sse = false;
  83396. info->data.ia32.sse2 = false;
  83397. info->data.ia32.sse3 = false;
  83398. info->data.ia32.ssse3 = false;
  83399. info->data.ia32._3dnow = false;
  83400. info->data.ia32.ext3dnow = false;
  83401. info->data.ia32.extmmx = false;
  83402. if(info->data.ia32.cpuid) {
  83403. FLAC__uint32 flags_edx, flags_ecx;
  83404. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83405. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83406. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83407. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83408. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83409. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83410. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83411. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83412. #ifdef FLAC__USE_3DNOW
  83413. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83414. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83415. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83416. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83417. #else
  83418. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83419. #endif
  83420. #ifdef DEBUG
  83421. fprintf(stderr, "CPU info (IA-32):\n");
  83422. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83423. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83424. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83425. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83426. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83427. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83428. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83429. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83430. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83431. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83432. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83433. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83434. #endif
  83435. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83436. #if defined FLAC__NO_SSE_OS
  83437. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83438. #elif defined FLAC__SSE_OS
  83439. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83440. int sse = 0;
  83441. size_t len;
  83442. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83443. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83444. if(!sse)
  83445. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83446. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83447. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83448. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83449. size_t len = sizeof(val);
  83450. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83451. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83452. else { /* double-check SSE2 */
  83453. mib[1] = CPU_SSE2;
  83454. len = sizeof(val);
  83455. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83456. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83457. }
  83458. # else
  83459. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83460. # endif
  83461. #elif defined(__linux__)
  83462. int sse = 0;
  83463. struct sigaction sigill_save;
  83464. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83465. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83466. #else
  83467. struct sigaction sigill_sse;
  83468. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83469. __sigemptyset(&sigill_sse.sa_mask);
  83470. sigill_sse.sa_flags = SA_SIGINFO | SA_RESETHAND; /* SA_RESETHAND just in case our SIGILL return jump breaks, so we don't get stuck in a loop */
  83471. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83472. #endif
  83473. {
  83474. asm volatile (
  83475. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83476. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83477. "incl %0\n\t" /* SIGILL handler will jump over this */
  83478. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83479. "nop\n\t"
  83480. "nop\n\t"
  83481. "nop\n\t"
  83482. "nop\n\t"
  83483. "nop\n\t"
  83484. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83485. "nop\n\t"
  83486. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83487. : "=r"(sse)
  83488. : "r"(sse)
  83489. );
  83490. sigaction(SIGILL, &sigill_save, NULL);
  83491. }
  83492. if(!sse)
  83493. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83494. #elif defined(_MSC_VER)
  83495. # ifdef USE_TRY_CATCH_FLAVOR
  83496. _try {
  83497. __asm {
  83498. # if _MSC_VER <= 1200
  83499. _emit 0x0F
  83500. _emit 0x57
  83501. _emit 0xC0
  83502. # else
  83503. xorps xmm0,xmm0
  83504. # endif
  83505. }
  83506. }
  83507. _except(EXCEPTION_EXECUTE_HANDLER) {
  83508. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83509. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83510. }
  83511. # else
  83512. int sse = 0;
  83513. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83514. __asm {
  83515. # if _MSC_VER <= 1200
  83516. _emit 0x0F
  83517. _emit 0x57
  83518. _emit 0xC0
  83519. # else
  83520. xorps xmm0,xmm0
  83521. # endif
  83522. inc sse
  83523. nop
  83524. nop
  83525. nop
  83526. nop
  83527. nop
  83528. nop
  83529. nop
  83530. nop
  83531. nop
  83532. }
  83533. SetUnhandledExceptionFilter(save);
  83534. if(!sse)
  83535. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83536. # endif
  83537. #else
  83538. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83539. #endif
  83540. #ifdef DEBUG
  83541. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83542. #endif
  83543. }
  83544. }
  83545. #else
  83546. info->use_asm = false;
  83547. #endif
  83548. #elif defined FLAC__CPU_PPC
  83549. info->type = FLAC__CPUINFO_TYPE_PPC;
  83550. # if !defined FLAC__NO_ASM
  83551. info->use_asm = true;
  83552. # ifdef FLAC__USE_ALTIVEC
  83553. # if defined FLAC__SYS_DARWIN
  83554. {
  83555. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83556. size_t len = sizeof(val);
  83557. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83558. }
  83559. {
  83560. host_basic_info_data_t hostInfo;
  83561. mach_msg_type_number_t infoCount;
  83562. infoCount = HOST_BASIC_INFO_COUNT;
  83563. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83564. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83565. }
  83566. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83567. {
  83568. info->data.ppc.altivec = 0;
  83569. info->data.ppc.ppc64 = 0;
  83570. signal (SIGILL, sigill_handler);
  83571. canjump = 0;
  83572. if (!sigsetjmp (jmpbuf, 1)) {
  83573. canjump = 1;
  83574. asm volatile (
  83575. "mtspr 256, %0\n\t"
  83576. "vand %%v0, %%v0, %%v0"
  83577. :
  83578. : "r" (-1)
  83579. );
  83580. info->data.ppc.altivec = 1;
  83581. }
  83582. canjump = 0;
  83583. if (!sigsetjmp (jmpbuf, 1)) {
  83584. int x = 0;
  83585. canjump = 1;
  83586. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83587. info->data.ppc.ppc64 = 1;
  83588. }
  83589. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83590. }
  83591. # endif
  83592. # else /* !FLAC__USE_ALTIVEC */
  83593. info->data.ppc.altivec = 0;
  83594. info->data.ppc.ppc64 = 0;
  83595. # endif
  83596. # else
  83597. info->use_asm = false;
  83598. # endif
  83599. #else
  83600. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83601. info->use_asm = false;
  83602. #endif
  83603. }
  83604. #endif
  83605. /*** End of inlined file: cpu.c ***/
  83606. /*** Start of inlined file: crc.c ***/
  83607. /*** Start of inlined file: juce_FlacHeader.h ***/
  83608. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83609. // tasks..
  83610. #define VERSION "1.2.1"
  83611. #define FLAC__NO_DLL 1
  83612. #if JUCE_MSVC
  83613. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83614. #endif
  83615. #if JUCE_MAC
  83616. #define FLAC__SYS_DARWIN 1
  83617. #endif
  83618. /*** End of inlined file: juce_FlacHeader.h ***/
  83619. #if JUCE_USE_FLAC
  83620. #if HAVE_CONFIG_H
  83621. # include <config.h>
  83622. #endif
  83623. FLAC__byte const FLAC__crc8_table[256] = {
  83624. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83625. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83626. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83627. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83628. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83629. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83630. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83631. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83632. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83633. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83634. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83635. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83636. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83637. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83638. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83639. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83640. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83641. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83642. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83643. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83644. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83645. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83646. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83647. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83648. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83649. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83650. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83651. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83652. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83653. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83654. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83655. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83656. };
  83657. unsigned FLAC__crc16_table[256] = {
  83658. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83659. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83660. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83661. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83662. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83663. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83664. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83665. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83666. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83667. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83668. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83669. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83670. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83671. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83672. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83673. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83674. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83675. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83676. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83677. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83678. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83679. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83680. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83681. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83682. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83683. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83684. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83685. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83686. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83687. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83688. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83689. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83690. };
  83691. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83692. {
  83693. *crc = FLAC__crc8_table[*crc ^ data];
  83694. }
  83695. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83696. {
  83697. while(len--)
  83698. *crc = FLAC__crc8_table[*crc ^ *data++];
  83699. }
  83700. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83701. {
  83702. FLAC__uint8 crc = 0;
  83703. while(len--)
  83704. crc = FLAC__crc8_table[crc ^ *data++];
  83705. return crc;
  83706. }
  83707. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83708. {
  83709. unsigned crc = 0;
  83710. while(len--)
  83711. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83712. return crc;
  83713. }
  83714. #endif
  83715. /*** End of inlined file: crc.c ***/
  83716. /*** Start of inlined file: fixed.c ***/
  83717. /*** Start of inlined file: juce_FlacHeader.h ***/
  83718. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83719. // tasks..
  83720. #define VERSION "1.2.1"
  83721. #define FLAC__NO_DLL 1
  83722. #if JUCE_MSVC
  83723. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83724. #endif
  83725. #if JUCE_MAC
  83726. #define FLAC__SYS_DARWIN 1
  83727. #endif
  83728. /*** End of inlined file: juce_FlacHeader.h ***/
  83729. #if JUCE_USE_FLAC
  83730. #if HAVE_CONFIG_H
  83731. # include <config.h>
  83732. #endif
  83733. #include <math.h>
  83734. #include <string.h>
  83735. /*** Start of inlined file: fixed.h ***/
  83736. #ifndef FLAC__PRIVATE__FIXED_H
  83737. #define FLAC__PRIVATE__FIXED_H
  83738. #ifdef HAVE_CONFIG_H
  83739. #include <config.h>
  83740. #endif
  83741. /*** Start of inlined file: float.h ***/
  83742. #ifndef FLAC__PRIVATE__FLOAT_H
  83743. #define FLAC__PRIVATE__FLOAT_H
  83744. #ifdef HAVE_CONFIG_H
  83745. #include <config.h>
  83746. #endif
  83747. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83748. typedef double FLAC__double;
  83749. typedef float FLAC__float;
  83750. typedef float FLAC__real;
  83751. #else
  83752. typedef FLAC__int32 FLAC__fixedpoint;
  83753. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83754. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83755. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83756. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83757. extern const FLAC__fixedpoint FLAC__FP_E;
  83758. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83759. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83760. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83761. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83762. #endif
  83763. #endif
  83764. /*** End of inlined file: float.h ***/
  83765. /*** Start of inlined file: format.h ***/
  83766. #ifndef FLAC__PRIVATE__FORMAT_H
  83767. #define FLAC__PRIVATE__FORMAT_H
  83768. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83769. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83770. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83771. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83772. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83773. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83774. #endif
  83775. /*** End of inlined file: format.h ***/
  83776. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83777. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83778. # ifndef FLAC__NO_ASM
  83779. # ifdef FLAC__CPU_IA32
  83780. # ifdef FLAC__HAS_NASM
  83781. unsigned FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83782. # endif
  83783. # endif
  83784. # endif
  83785. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83786. #else
  83787. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83788. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83789. #endif
  83790. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83791. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83792. #endif
  83793. /*** End of inlined file: fixed.h ***/
  83794. #ifndef M_LN2
  83795. #define M_LN2 0.69314718055994530942
  83796. #endif
  83797. #ifdef min
  83798. #undef min
  83799. #endif
  83800. #define min(x,y) ((x) < (y)? (x) : (y))
  83801. #ifdef local_abs
  83802. #undef local_abs
  83803. #endif
  83804. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83805. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83806. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83807. {
  83808. FLAC__uint32 rbps;
  83809. unsigned bits; /* the number of bits required to represent a number */
  83810. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83811. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83812. FLAC__ASSERT(err > 0);
  83813. FLAC__ASSERT(n > 0);
  83814. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83815. if(err <= n)
  83816. return 0;
  83817. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  83818. err <<= fracbits;
  83819. err /= n;
  83820. FLAC__ASSERT(err > 0);
  83821. bits = FLAC__bitmath_ilog2(err)+1;
  83822. if(bits > 16) {
  83823. err >>= (bits-16);
  83824. fracbits -= (bits-16);
  83825. }
  83826. rbps = (FLAC__uint32)err;
  83827. rbps *= FLAC__FP_LN2;
  83828. fracbits += 16;
  83829. FLAC__ASSERT(fracbits >= 0);
  83830. {
  83831. const int f = fracbits & 3;
  83832. if(f) {
  83833. rbps >>= f;
  83834. fracbits -= f;
  83835. }
  83836. }
  83837. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83838. if(rbps == 0)
  83839. return 0;
  83840. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83841. FLAC__ASSERT(fracbits >= -3);
  83842. if(fracbits < 16)
  83843. return rbps << (16-fracbits);
  83844. else if(fracbits > 16)
  83845. return rbps >> (fracbits-16);
  83846. else
  83847. return rbps;
  83848. }
  83849. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  83850. {
  83851. FLAC__uint32 rbps;
  83852. unsigned bits; /* the number of bits required to represent a number */
  83853. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83854. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83855. FLAC__ASSERT(err > 0);
  83856. FLAC__ASSERT(n > 0);
  83857. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83858. if(err <= n)
  83859. return 0;
  83860. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  83861. err <<= fracbits;
  83862. err /= n;
  83863. FLAC__ASSERT(err > 0);
  83864. bits = FLAC__bitmath_ilog2_wide(err)+1;
  83865. if(bits > 16) {
  83866. err >>= (bits-16);
  83867. fracbits -= (bits-16);
  83868. }
  83869. rbps = (FLAC__uint32)err;
  83870. rbps *= FLAC__FP_LN2;
  83871. fracbits += 16;
  83872. FLAC__ASSERT(fracbits >= 0);
  83873. {
  83874. const int f = fracbits & 3;
  83875. if(f) {
  83876. rbps >>= f;
  83877. fracbits -= f;
  83878. }
  83879. }
  83880. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83881. if(rbps == 0)
  83882. return 0;
  83883. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83884. FLAC__ASSERT(fracbits >= -3);
  83885. if(fracbits < 16)
  83886. return rbps << (16-fracbits);
  83887. else if(fracbits > 16)
  83888. return rbps >> (fracbits-16);
  83889. else
  83890. return rbps;
  83891. }
  83892. #endif
  83893. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83894. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83895. #else
  83896. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83897. #endif
  83898. {
  83899. FLAC__int32 last_error_0 = data[-1];
  83900. FLAC__int32 last_error_1 = data[-1] - data[-2];
  83901. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  83902. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  83903. FLAC__int32 error, save;
  83904. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  83905. unsigned i, order;
  83906. for(i = 0; i < data_len; i++) {
  83907. error = data[i] ; total_error_0 += local_abs(error); save = error;
  83908. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  83909. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  83910. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  83911. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  83912. }
  83913. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  83914. order = 0;
  83915. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  83916. order = 1;
  83917. else if(total_error_2 < min(total_error_3, total_error_4))
  83918. order = 2;
  83919. else if(total_error_3 < total_error_4)
  83920. order = 3;
  83921. else
  83922. order = 4;
  83923. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  83924. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  83925. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  83926. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  83927. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  83928. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83929. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83930. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83931. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83932. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83933. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83934. #else
  83935. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  83936. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  83937. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  83938. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  83939. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  83940. #endif
  83941. return order;
  83942. }
  83943. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83944. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83945. #else
  83946. unsigned FLAC__fixed_compute_best_predictor_wide(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83947. #endif
  83948. {
  83949. FLAC__int32 last_error_0 = data[-1];
  83950. FLAC__int32 last_error_1 = data[-1] - data[-2];
  83951. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  83952. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  83953. FLAC__int32 error, save;
  83954. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  83955. unsigned i, order;
  83956. for(i = 0; i < data_len; i++) {
  83957. error = data[i] ; total_error_0 += local_abs(error); save = error;
  83958. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  83959. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  83960. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  83961. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  83962. }
  83963. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  83964. order = 0;
  83965. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  83966. order = 1;
  83967. else if(total_error_2 < min(total_error_3, total_error_4))
  83968. order = 2;
  83969. else if(total_error_3 < total_error_4)
  83970. order = 3;
  83971. else
  83972. order = 4;
  83973. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  83974. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  83975. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  83976. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  83977. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  83978. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83979. #if defined _MSC_VER || defined __MINGW32__
  83980. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83981. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83982. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83983. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83984. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)(FLAC__int64)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83985. #else
  83986. residual_bits_per_sample[0] = (FLAC__float)((total_error_0 > 0) ? log(M_LN2 * (FLAC__double)total_error_0 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83987. residual_bits_per_sample[1] = (FLAC__float)((total_error_1 > 0) ? log(M_LN2 * (FLAC__double)total_error_1 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83988. residual_bits_per_sample[2] = (FLAC__float)((total_error_2 > 0) ? log(M_LN2 * (FLAC__double)total_error_2 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83989. residual_bits_per_sample[3] = (FLAC__float)((total_error_3 > 0) ? log(M_LN2 * (FLAC__double)total_error_3 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83990. residual_bits_per_sample[4] = (FLAC__float)((total_error_4 > 0) ? log(M_LN2 * (FLAC__double)total_error_4 / (FLAC__double)data_len) / M_LN2 : 0.0);
  83991. #endif
  83992. #else
  83993. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  83994. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  83995. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  83996. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  83997. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  83998. #endif
  83999. return order;
  84000. }
  84001. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84002. {
  84003. const int idata_len = (int)data_len;
  84004. int i;
  84005. switch(order) {
  84006. case 0:
  84007. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84008. memcpy(residual, data, sizeof(residual[0])*data_len);
  84009. break;
  84010. case 1:
  84011. for(i = 0; i < idata_len; i++)
  84012. residual[i] = data[i] - data[i-1];
  84013. break;
  84014. case 2:
  84015. for(i = 0; i < idata_len; i++)
  84016. #if 1 /* OPT: may be faster with some compilers on some systems */
  84017. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84018. #else
  84019. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84020. #endif
  84021. break;
  84022. case 3:
  84023. for(i = 0; i < idata_len; i++)
  84024. #if 1 /* OPT: may be faster with some compilers on some systems */
  84025. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84026. #else
  84027. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84028. #endif
  84029. break;
  84030. case 4:
  84031. for(i = 0; i < idata_len; i++)
  84032. #if 1 /* OPT: may be faster with some compilers on some systems */
  84033. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84034. #else
  84035. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84036. #endif
  84037. break;
  84038. default:
  84039. FLAC__ASSERT(0);
  84040. }
  84041. }
  84042. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84043. {
  84044. int i, idata_len = (int)data_len;
  84045. switch(order) {
  84046. case 0:
  84047. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84048. memcpy(data, residual, sizeof(residual[0])*data_len);
  84049. break;
  84050. case 1:
  84051. for(i = 0; i < idata_len; i++)
  84052. data[i] = residual[i] + data[i-1];
  84053. break;
  84054. case 2:
  84055. for(i = 0; i < idata_len; i++)
  84056. #if 1 /* OPT: may be faster with some compilers on some systems */
  84057. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84058. #else
  84059. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84060. #endif
  84061. break;
  84062. case 3:
  84063. for(i = 0; i < idata_len; i++)
  84064. #if 1 /* OPT: may be faster with some compilers on some systems */
  84065. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84066. #else
  84067. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84068. #endif
  84069. break;
  84070. case 4:
  84071. for(i = 0; i < idata_len; i++)
  84072. #if 1 /* OPT: may be faster with some compilers on some systems */
  84073. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84074. #else
  84075. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84076. #endif
  84077. break;
  84078. default:
  84079. FLAC__ASSERT(0);
  84080. }
  84081. }
  84082. #endif
  84083. /*** End of inlined file: fixed.c ***/
  84084. /*** Start of inlined file: float.c ***/
  84085. /*** Start of inlined file: juce_FlacHeader.h ***/
  84086. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84087. // tasks..
  84088. #define VERSION "1.2.1"
  84089. #define FLAC__NO_DLL 1
  84090. #if JUCE_MSVC
  84091. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84092. #endif
  84093. #if JUCE_MAC
  84094. #define FLAC__SYS_DARWIN 1
  84095. #endif
  84096. /*** End of inlined file: juce_FlacHeader.h ***/
  84097. #if JUCE_USE_FLAC
  84098. #if HAVE_CONFIG_H
  84099. # include <config.h>
  84100. #endif
  84101. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84102. #ifdef _MSC_VER
  84103. #define FLAC__U64L(x) x
  84104. #else
  84105. #define FLAC__U64L(x) x##LLU
  84106. #endif
  84107. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84108. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84109. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84110. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84111. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84112. #define LOG2_LOOKUP_PRECISION 16
  84113. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84114. {
  84115. 0x00000000,
  84116. 0x00000001,
  84117. 0x00000000,
  84118. 0x00000000,
  84119. 0x00000000,
  84120. 0x00000000,
  84121. 0x00000000,
  84122. 0x00000000,
  84123. 0x00000000,
  84124. 0x00000000,
  84125. 0x00000000,
  84126. 0x00000000,
  84127. 0x00000000,
  84128. 0x00000000,
  84129. 0x00000000,
  84130. 0x00000000
  84131. },
  84132. {
  84133. 0x00000000,
  84134. 0x00000010,
  84135. 0x00000007,
  84136. 0x00000003,
  84137. 0x00000001,
  84138. 0x00000001,
  84139. 0x00000000,
  84140. 0x00000000,
  84141. 0x00000000,
  84142. 0x00000000,
  84143. 0x00000000,
  84144. 0x00000000,
  84145. 0x00000000,
  84146. 0x00000000,
  84147. 0x00000000,
  84148. 0x00000000
  84149. },
  84150. {
  84151. 0x00000000,
  84152. 0x00000100,
  84153. 0x0000006a,
  84154. 0x00000031,
  84155. 0x00000018,
  84156. 0x0000000c,
  84157. 0x00000006,
  84158. 0x00000003,
  84159. 0x00000001,
  84160. 0x00000001,
  84161. 0x00000000,
  84162. 0x00000000,
  84163. 0x00000000,
  84164. 0x00000000,
  84165. 0x00000000,
  84166. 0x00000000
  84167. },
  84168. {
  84169. 0x00000000,
  84170. 0x00001000,
  84171. 0x000006a4,
  84172. 0x00000315,
  84173. 0x0000017d,
  84174. 0x000000bc,
  84175. 0x0000005d,
  84176. 0x0000002e,
  84177. 0x00000017,
  84178. 0x0000000c,
  84179. 0x00000006,
  84180. 0x00000003,
  84181. 0x00000001,
  84182. 0x00000001,
  84183. 0x00000000,
  84184. 0x00000000
  84185. },
  84186. {
  84187. 0x00000000,
  84188. 0x00010000,
  84189. 0x00006a40,
  84190. 0x00003151,
  84191. 0x000017d6,
  84192. 0x00000bba,
  84193. 0x000005d1,
  84194. 0x000002e6,
  84195. 0x00000172,
  84196. 0x000000b9,
  84197. 0x0000005c,
  84198. 0x0000002e,
  84199. 0x00000017,
  84200. 0x0000000c,
  84201. 0x00000006,
  84202. 0x00000003
  84203. },
  84204. {
  84205. 0x00000000,
  84206. 0x00100000,
  84207. 0x0006a3fe,
  84208. 0x00031513,
  84209. 0x00017d60,
  84210. 0x0000bb9d,
  84211. 0x00005d10,
  84212. 0x00002e59,
  84213. 0x00001721,
  84214. 0x00000b8e,
  84215. 0x000005c6,
  84216. 0x000002e3,
  84217. 0x00000171,
  84218. 0x000000b9,
  84219. 0x0000005c,
  84220. 0x0000002e
  84221. },
  84222. {
  84223. 0x00000000,
  84224. 0x01000000,
  84225. 0x006a3fe6,
  84226. 0x00315130,
  84227. 0x0017d605,
  84228. 0x000bb9ca,
  84229. 0x0005d0fc,
  84230. 0x0002e58f,
  84231. 0x0001720e,
  84232. 0x0000b8d8,
  84233. 0x00005c61,
  84234. 0x00002e2d,
  84235. 0x00001716,
  84236. 0x00000b8b,
  84237. 0x000005c5,
  84238. 0x000002e3
  84239. },
  84240. {
  84241. 0x00000000,
  84242. 0x10000000,
  84243. 0x06a3fe5c,
  84244. 0x03151301,
  84245. 0x017d6049,
  84246. 0x00bb9ca6,
  84247. 0x005d0fba,
  84248. 0x002e58f7,
  84249. 0x001720da,
  84250. 0x000b8d87,
  84251. 0x0005c60b,
  84252. 0x0002e2d7,
  84253. 0x00017160,
  84254. 0x0000b8ad,
  84255. 0x00005c56,
  84256. 0x00002e2b
  84257. }
  84258. };
  84259. #if 0
  84260. static const FLAC__uint64 log2_lookup_wide[] = {
  84261. {
  84262. 0x00000000,
  84263. FLAC__U64L(0x100000000),
  84264. FLAC__U64L(0x6a3fe5c6),
  84265. FLAC__U64L(0x31513015),
  84266. FLAC__U64L(0x17d60497),
  84267. FLAC__U64L(0x0bb9ca65),
  84268. FLAC__U64L(0x05d0fba2),
  84269. FLAC__U64L(0x02e58f74),
  84270. FLAC__U64L(0x01720d9c),
  84271. FLAC__U64L(0x00b8d875),
  84272. FLAC__U64L(0x005c60aa),
  84273. FLAC__U64L(0x002e2d72),
  84274. FLAC__U64L(0x00171600),
  84275. FLAC__U64L(0x000b8ad2),
  84276. FLAC__U64L(0x0005c55d),
  84277. FLAC__U64L(0x0002e2ac)
  84278. },
  84279. {
  84280. 0x00000000,
  84281. FLAC__U64L(0x1000000000000),
  84282. FLAC__U64L(0x6a3fe5c60429),
  84283. FLAC__U64L(0x315130157f7a),
  84284. FLAC__U64L(0x17d60496cfbb),
  84285. FLAC__U64L(0xbb9ca64ecac),
  84286. FLAC__U64L(0x5d0fba187cd),
  84287. FLAC__U64L(0x2e58f7441ee),
  84288. FLAC__U64L(0x1720d9c06a8),
  84289. FLAC__U64L(0xb8d8752173),
  84290. FLAC__U64L(0x5c60aa252e),
  84291. FLAC__U64L(0x2e2d71b0d8),
  84292. FLAC__U64L(0x1716001719),
  84293. FLAC__U64L(0xb8ad1de1b),
  84294. FLAC__U64L(0x5c55d640d),
  84295. FLAC__U64L(0x2e2abcf52)
  84296. }
  84297. };
  84298. #endif
  84299. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84300. {
  84301. const FLAC__uint32 ONE = (1u << fracbits);
  84302. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84303. FLAC__ASSERT(fracbits < 32);
  84304. FLAC__ASSERT((fracbits & 0x3) == 0);
  84305. if(x < ONE)
  84306. return 0;
  84307. if(precision > LOG2_LOOKUP_PRECISION)
  84308. precision = LOG2_LOOKUP_PRECISION;
  84309. {
  84310. FLAC__uint32 y = 0;
  84311. FLAC__uint32 z = x >> 1, k = 1;
  84312. while (x > ONE && k < precision) {
  84313. if (x - z >= ONE) {
  84314. x -= z;
  84315. z = x >> k;
  84316. y += table[k];
  84317. }
  84318. else {
  84319. z >>= 1;
  84320. k++;
  84321. }
  84322. }
  84323. return y;
  84324. }
  84325. }
  84326. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84327. #endif
  84328. /*** End of inlined file: float.c ***/
  84329. /*** Start of inlined file: format.c ***/
  84330. /*** Start of inlined file: juce_FlacHeader.h ***/
  84331. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84332. // tasks..
  84333. #define VERSION "1.2.1"
  84334. #define FLAC__NO_DLL 1
  84335. #if JUCE_MSVC
  84336. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84337. #endif
  84338. #if JUCE_MAC
  84339. #define FLAC__SYS_DARWIN 1
  84340. #endif
  84341. /*** End of inlined file: juce_FlacHeader.h ***/
  84342. #if JUCE_USE_FLAC
  84343. #if HAVE_CONFIG_H
  84344. # include <config.h>
  84345. #endif
  84346. #include <stdio.h>
  84347. #include <stdlib.h> /* for qsort() */
  84348. #include <string.h> /* for memset() */
  84349. #ifndef FLaC__INLINE
  84350. #define FLaC__INLINE
  84351. #endif
  84352. #ifdef min
  84353. #undef min
  84354. #endif
  84355. #define min(a,b) ((a)<(b)?(a):(b))
  84356. #ifdef _MSC_VER
  84357. #define FLAC__U64L(x) x
  84358. #else
  84359. #define FLAC__U64L(x) x##LLU
  84360. #endif
  84361. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84362. ;
  84363. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84364. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84365. #else
  84366. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84367. #endif
  84368. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84369. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84370. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84371. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84372. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84373. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84374. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84375. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84376. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84377. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84378. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84379. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84380. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84381. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84382. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84383. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84384. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84385. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84386. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84387. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84388. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84389. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84390. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84391. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84392. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84393. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84394. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84395. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84396. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84397. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84398. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84399. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84400. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84401. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84402. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84403. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84404. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84405. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84406. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84407. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84408. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84409. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84410. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84411. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84412. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84413. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84414. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84415. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84416. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84417. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84418. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84419. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84420. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84421. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84422. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84423. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84424. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84425. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84426. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84427. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84428. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84429. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84430. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84431. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84432. "PARTITIONED_RICE",
  84433. "PARTITIONED_RICE2"
  84434. };
  84435. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84436. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84437. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84438. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84439. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84440. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84441. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84442. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84443. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84444. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84445. "CONSTANT",
  84446. "VERBATIM",
  84447. "FIXED",
  84448. "LPC"
  84449. };
  84450. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84451. "INDEPENDENT",
  84452. "LEFT_SIDE",
  84453. "RIGHT_SIDE",
  84454. "MID_SIDE"
  84455. };
  84456. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84457. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84458. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84459. };
  84460. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84461. "STREAMINFO",
  84462. "PADDING",
  84463. "APPLICATION",
  84464. "SEEKTABLE",
  84465. "VORBIS_COMMENT",
  84466. "CUESHEET",
  84467. "PICTURE"
  84468. };
  84469. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84470. "Other",
  84471. "32x32 pixels 'file icon' (PNG only)",
  84472. "Other file icon",
  84473. "Cover (front)",
  84474. "Cover (back)",
  84475. "Leaflet page",
  84476. "Media (e.g. label side of CD)",
  84477. "Lead artist/lead performer/soloist",
  84478. "Artist/performer",
  84479. "Conductor",
  84480. "Band/Orchestra",
  84481. "Composer",
  84482. "Lyricist/text writer",
  84483. "Recording Location",
  84484. "During recording",
  84485. "During performance",
  84486. "Movie/video screen capture",
  84487. "A bright coloured fish",
  84488. "Illustration",
  84489. "Band/artist logotype",
  84490. "Publisher/Studio logotype"
  84491. };
  84492. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84493. {
  84494. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84495. return false;
  84496. }
  84497. else
  84498. return true;
  84499. }
  84500. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84501. {
  84502. if(
  84503. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84504. (
  84505. sample_rate >= (1u << 16) &&
  84506. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84507. )
  84508. ) {
  84509. return false;
  84510. }
  84511. else
  84512. return true;
  84513. }
  84514. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84515. {
  84516. unsigned i;
  84517. FLAC__uint64 prev_sample_number = 0;
  84518. FLAC__bool got_prev = false;
  84519. FLAC__ASSERT(0 != seek_table);
  84520. for(i = 0; i < seek_table->num_points; i++) {
  84521. if(got_prev) {
  84522. if(
  84523. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84524. seek_table->points[i].sample_number <= prev_sample_number
  84525. )
  84526. return false;
  84527. }
  84528. prev_sample_number = seek_table->points[i].sample_number;
  84529. got_prev = true;
  84530. }
  84531. return true;
  84532. }
  84533. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84534. {
  84535. if(l->sample_number == r->sample_number)
  84536. return 0;
  84537. else if(l->sample_number < r->sample_number)
  84538. return -1;
  84539. else
  84540. return 1;
  84541. }
  84542. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84543. {
  84544. unsigned i, j;
  84545. FLAC__bool first;
  84546. FLAC__ASSERT(0 != seek_table);
  84547. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84548. first = true;
  84549. for(i = j = 0; i < seek_table->num_points; i++) {
  84550. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84551. if(!first) {
  84552. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84553. continue;
  84554. }
  84555. }
  84556. first = false;
  84557. seek_table->points[j++] = seek_table->points[i];
  84558. }
  84559. for(i = j; i < seek_table->num_points; i++) {
  84560. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84561. seek_table->points[i].stream_offset = 0;
  84562. seek_table->points[i].frame_samples = 0;
  84563. }
  84564. return j;
  84565. }
  84566. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84567. {
  84568. FLAC__ASSERT(0 != utf8);
  84569. if ((utf8[0] & 0x80) == 0) {
  84570. return 1;
  84571. }
  84572. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84573. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84574. return 0;
  84575. return 2;
  84576. }
  84577. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84578. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84579. return 0;
  84580. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84581. return 0;
  84582. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84583. return 0;
  84584. return 3;
  84585. }
  84586. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84587. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84588. return 0;
  84589. return 4;
  84590. }
  84591. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84592. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84593. return 0;
  84594. return 5;
  84595. }
  84596. else if ((utf8[0] & 0xFE) == 0xFC && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80 && (utf8[5] & 0xC0) == 0x80) {
  84597. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84598. return 0;
  84599. return 6;
  84600. }
  84601. else {
  84602. return 0;
  84603. }
  84604. }
  84605. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84606. {
  84607. char c;
  84608. for(c = *name; c; c = *(++name))
  84609. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84610. return false;
  84611. return true;
  84612. }
  84613. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84614. {
  84615. if(length == (unsigned)(-1)) {
  84616. while(*value) {
  84617. unsigned n = utf8len_(value);
  84618. if(n == 0)
  84619. return false;
  84620. value += n;
  84621. }
  84622. }
  84623. else {
  84624. const FLAC__byte *end = value + length;
  84625. while(value < end) {
  84626. unsigned n = utf8len_(value);
  84627. if(n == 0)
  84628. return false;
  84629. value += n;
  84630. }
  84631. if(value != end)
  84632. return false;
  84633. }
  84634. return true;
  84635. }
  84636. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84637. {
  84638. const FLAC__byte *s, *end;
  84639. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84640. if(*s < 0x20 || *s > 0x7D)
  84641. return false;
  84642. }
  84643. if(s == end)
  84644. return false;
  84645. s++; /* skip '=' */
  84646. while(s < end) {
  84647. unsigned n = utf8len_(s);
  84648. if(n == 0)
  84649. return false;
  84650. s += n;
  84651. }
  84652. if(s != end)
  84653. return false;
  84654. return true;
  84655. }
  84656. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84657. {
  84658. unsigned i, j;
  84659. if(check_cd_da_subset) {
  84660. if(cue_sheet->lead_in < 2 * 44100) {
  84661. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84662. return false;
  84663. }
  84664. if(cue_sheet->lead_in % 588 != 0) {
  84665. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84666. return false;
  84667. }
  84668. }
  84669. if(cue_sheet->num_tracks == 0) {
  84670. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84671. return false;
  84672. }
  84673. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84674. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84675. return false;
  84676. }
  84677. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84678. if(cue_sheet->tracks[i].number == 0) {
  84679. if(violation) *violation = "cue sheet may not have a track number 0";
  84680. return false;
  84681. }
  84682. if(check_cd_da_subset) {
  84683. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84684. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84685. return false;
  84686. }
  84687. }
  84688. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84689. if(violation) {
  84690. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84691. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84692. else
  84693. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84694. }
  84695. return false;
  84696. }
  84697. if(i < cue_sheet->num_tracks - 1) {
  84698. if(cue_sheet->tracks[i].num_indices == 0) {
  84699. if(violation) *violation = "cue sheet track must have at least one index point";
  84700. return false;
  84701. }
  84702. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84703. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84704. return false;
  84705. }
  84706. }
  84707. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84708. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84709. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84710. return false;
  84711. }
  84712. if(j > 0) {
  84713. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84714. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84715. return false;
  84716. }
  84717. }
  84718. }
  84719. }
  84720. return true;
  84721. }
  84722. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84723. {
  84724. char *p;
  84725. FLAC__byte *b;
  84726. for(p = picture->mime_type; *p; p++) {
  84727. if(*p < 0x20 || *p > 0x7e) {
  84728. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84729. return false;
  84730. }
  84731. }
  84732. for(b = picture->description; *b; ) {
  84733. unsigned n = utf8len_(b);
  84734. if(n == 0) {
  84735. if(violation) *violation = "description string must be valid UTF-8";
  84736. return false;
  84737. }
  84738. b += n;
  84739. }
  84740. return true;
  84741. }
  84742. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84743. {
  84744. return
  84745. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84746. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84747. blocksize,
  84748. predictor_order
  84749. );
  84750. }
  84751. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84752. {
  84753. unsigned max_rice_partition_order = 0;
  84754. while(!(blocksize & 1)) {
  84755. max_rice_partition_order++;
  84756. blocksize >>= 1;
  84757. }
  84758. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84759. }
  84760. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84761. {
  84762. unsigned max_rice_partition_order = limit;
  84763. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84764. max_rice_partition_order--;
  84765. FLAC__ASSERT(
  84766. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84767. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84768. );
  84769. return max_rice_partition_order;
  84770. }
  84771. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84772. {
  84773. FLAC__ASSERT(0 != object);
  84774. object->parameters = 0;
  84775. object->raw_bits = 0;
  84776. object->capacity_by_order = 0;
  84777. }
  84778. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84779. {
  84780. FLAC__ASSERT(0 != object);
  84781. if(0 != object->parameters)
  84782. free(object->parameters);
  84783. if(0 != object->raw_bits)
  84784. free(object->raw_bits);
  84785. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84786. }
  84787. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84788. {
  84789. FLAC__ASSERT(0 != object);
  84790. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84791. if(object->capacity_by_order < max_partition_order) {
  84792. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84793. return false;
  84794. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84795. return false;
  84796. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84797. object->capacity_by_order = max_partition_order;
  84798. }
  84799. return true;
  84800. }
  84801. #endif
  84802. /*** End of inlined file: format.c ***/
  84803. /*** Start of inlined file: lpc_flac.c ***/
  84804. /*** Start of inlined file: juce_FlacHeader.h ***/
  84805. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84806. // tasks..
  84807. #define VERSION "1.2.1"
  84808. #define FLAC__NO_DLL 1
  84809. #if JUCE_MSVC
  84810. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84811. #endif
  84812. #if JUCE_MAC
  84813. #define FLAC__SYS_DARWIN 1
  84814. #endif
  84815. /*** End of inlined file: juce_FlacHeader.h ***/
  84816. #if JUCE_USE_FLAC
  84817. #if HAVE_CONFIG_H
  84818. # include <config.h>
  84819. #endif
  84820. #include <math.h>
  84821. /*** Start of inlined file: lpc.h ***/
  84822. #ifndef FLAC__PRIVATE__LPC_H
  84823. #define FLAC__PRIVATE__LPC_H
  84824. #ifdef HAVE_CONFIG_H
  84825. #include <config.h>
  84826. #endif
  84827. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84828. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  84829. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84830. #ifndef FLAC__NO_ASM
  84831. # ifdef FLAC__CPU_IA32
  84832. # ifdef FLAC__HAS_NASM
  84833. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84834. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84835. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84836. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84837. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84838. # endif
  84839. # endif
  84840. #endif
  84841. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  84842. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  84843. void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  84844. void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  84845. #ifndef FLAC__NO_ASM
  84846. # ifdef FLAC__CPU_IA32
  84847. # ifdef FLAC__HAS_NASM
  84848. void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  84849. void FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  84850. # endif
  84851. # endif
  84852. #endif
  84853. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84854. void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84855. void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84856. #ifndef FLAC__NO_ASM
  84857. # ifdef FLAC__CPU_IA32
  84858. # ifdef FLAC__HAS_NASM
  84859. void FLAC__lpc_restore_signal_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84860. void FLAC__lpc_restore_signal_asm_ia32_mmx(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84861. # endif /* FLAC__HAS_NASM */
  84862. # elif defined FLAC__CPU_PPC
  84863. void FLAC__lpc_restore_signal_asm_ppc_altivec_16(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84864. void FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  84865. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  84866. #endif /* FLAC__NO_ASM */
  84867. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84868. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  84869. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  84870. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  84871. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84872. #endif
  84873. /*** End of inlined file: lpc.h ***/
  84874. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  84875. #include <stdio.h>
  84876. #endif
  84877. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84878. #ifndef M_LN2
  84879. #define M_LN2 0.69314718055994530942
  84880. #endif
  84881. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  84882. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  84883. {
  84884. unsigned i;
  84885. for(i = 0; i < data_len; i++)
  84886. out[i] = in[i] * window[i];
  84887. }
  84888. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  84889. {
  84890. #if 0
  84891. FLAC__real d;
  84892. unsigned i;
  84893. FLAC__ASSERT(lag > 0);
  84894. FLAC__ASSERT(lag <= data_len);
  84895. while(lag--) {
  84896. for(i = lag, d = 0.0; i < data_len; i++)
  84897. d += data[i] * data[i - lag];
  84898. autoc[lag] = d;
  84899. }
  84900. #endif
  84901. FLAC__real d;
  84902. unsigned sample, coeff;
  84903. const unsigned limit = data_len - lag;
  84904. FLAC__ASSERT(lag > 0);
  84905. FLAC__ASSERT(lag <= data_len);
  84906. for(coeff = 0; coeff < lag; coeff++)
  84907. autoc[coeff] = 0.0;
  84908. for(sample = 0; sample <= limit; sample++) {
  84909. d = data[sample];
  84910. for(coeff = 0; coeff < lag; coeff++)
  84911. autoc[coeff] += d * data[sample+coeff];
  84912. }
  84913. for(; sample < data_len; sample++) {
  84914. d = data[sample];
  84915. for(coeff = 0; coeff < data_len - sample; coeff++)
  84916. autoc[coeff] += d * data[sample+coeff];
  84917. }
  84918. }
  84919. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  84920. {
  84921. unsigned i, j;
  84922. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  84923. FLAC__ASSERT(0 != max_order);
  84924. FLAC__ASSERT(0 < *max_order);
  84925. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  84926. FLAC__ASSERT(autoc[0] != 0.0);
  84927. err = autoc[0];
  84928. for(i = 0; i < *max_order; i++) {
  84929. r = -autoc[i+1];
  84930. for(j = 0; j < i; j++)
  84931. r -= lpc[j] * autoc[i-j];
  84932. ref[i] = (r/=err);
  84933. lpc[i]=r;
  84934. for(j = 0; j < (i>>1); j++) {
  84935. FLAC__double tmp = lpc[j];
  84936. lpc[j] += r * lpc[i-1-j];
  84937. lpc[i-1-j] += r * tmp;
  84938. }
  84939. if(i & 1)
  84940. lpc[j] += lpc[j] * r;
  84941. err *= (1.0 - r * r);
  84942. for(j = 0; j <= i; j++)
  84943. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  84944. error[i] = err;
  84945. if(err == 0.0) {
  84946. *max_order = i+1;
  84947. return;
  84948. }
  84949. }
  84950. }
  84951. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  84952. {
  84953. unsigned i;
  84954. FLAC__double cmax;
  84955. FLAC__int32 qmax, qmin;
  84956. FLAC__ASSERT(precision > 0);
  84957. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  84958. precision--;
  84959. qmax = 1 << precision;
  84960. qmin = -qmax;
  84961. qmax--;
  84962. cmax = 0.0;
  84963. for(i = 0; i < order; i++) {
  84964. const FLAC__double d = fabs(lp_coeff[i]);
  84965. if(d > cmax)
  84966. cmax = d;
  84967. }
  84968. if(cmax <= 0.0) {
  84969. return 2;
  84970. }
  84971. else {
  84972. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  84973. const int min_shiftlimit = -max_shiftlimit - 1;
  84974. int log2cmax;
  84975. (void)frexp(cmax, &log2cmax);
  84976. log2cmax--;
  84977. *shift = (int)precision - log2cmax - 1;
  84978. if(*shift > max_shiftlimit)
  84979. *shift = max_shiftlimit;
  84980. else if(*shift < min_shiftlimit)
  84981. return 1;
  84982. }
  84983. if(*shift >= 0) {
  84984. FLAC__double error = 0.0;
  84985. FLAC__int32 q;
  84986. for(i = 0; i < order; i++) {
  84987. error += lp_coeff[i] * (1 << *shift);
  84988. #if 1 /* unfortunately lround() is C99 */
  84989. if(error >= 0.0)
  84990. q = (FLAC__int32)(error + 0.5);
  84991. else
  84992. q = (FLAC__int32)(error - 0.5);
  84993. #else
  84994. q = lround(error);
  84995. #endif
  84996. #ifdef FLAC__OVERFLOW_DETECT
  84997. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  84998. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
  84999. else if(q < qmin)
  85000. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
  85001. #endif
  85002. if(q > qmax)
  85003. q = qmax;
  85004. else if(q < qmin)
  85005. q = qmin;
  85006. error -= q;
  85007. qlp_coeff[i] = q;
  85008. }
  85009. }
  85010. else {
  85011. const int nshift = -(*shift);
  85012. FLAC__double error = 0.0;
  85013. FLAC__int32 q;
  85014. #ifdef DEBUG
  85015. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85016. #endif
  85017. for(i = 0; i < order; i++) {
  85018. error += lp_coeff[i] / (1 << nshift);
  85019. #if 1 /* unfortunately lround() is C99 */
  85020. if(error >= 0.0)
  85021. q = (FLAC__int32)(error + 0.5);
  85022. else
  85023. q = (FLAC__int32)(error - 0.5);
  85024. #else
  85025. q = lround(error);
  85026. #endif
  85027. #ifdef FLAC__OVERFLOW_DETECT
  85028. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85029. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q>qmax %d>%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmax,*shift,cmax,precision+1,i,lp_coeff[i]);
  85030. else if(q < qmin)
  85031. fprintf(stderr,"FLAC__lpc_quantize_coefficients: quantizer overflow: q<qmin %d<%d shift=%d cmax=%f precision=%u lpc[%u]=%f\n",q,qmin,*shift,cmax,precision+1,i,lp_coeff[i]);
  85032. #endif
  85033. if(q > qmax)
  85034. q = qmax;
  85035. else if(q < qmin)
  85036. q = qmin;
  85037. error -= q;
  85038. qlp_coeff[i] = q;
  85039. }
  85040. *shift = 0;
  85041. }
  85042. return 0;
  85043. }
  85044. void FLAC__lpc_compute_residual_from_qlp_coefficients(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
  85045. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85046. {
  85047. FLAC__int64 sumo;
  85048. unsigned i, j;
  85049. FLAC__int32 sum;
  85050. const FLAC__int32 *history;
  85051. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85052. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85053. for(i=0;i<order;i++)
  85054. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85055. fprintf(stderr,"\n");
  85056. #endif
  85057. FLAC__ASSERT(order > 0);
  85058. for(i = 0; i < data_len; i++) {
  85059. sumo = 0;
  85060. sum = 0;
  85061. history = data;
  85062. for(j = 0; j < order; j++) {
  85063. sum += qlp_coeff[j] * (*(--history));
  85064. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85065. #if defined _MSC_VER
  85066. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85067. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%I64d\n",i,j,qlp_coeff[j],*history,sumo);
  85068. #else
  85069. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85070. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%lld\n",i,j,qlp_coeff[j],*history,(long long)sumo);
  85071. #endif
  85072. }
  85073. *(residual++) = *(data++) - (sum >> lp_quantization);
  85074. }
  85075. }
  85076. #else /* fully unrolled version for normal use */
  85077. {
  85078. int i;
  85079. FLAC__int32 sum;
  85080. FLAC__ASSERT(order > 0);
  85081. FLAC__ASSERT(order <= 32);
  85082. if(order <= 12) {
  85083. if(order > 8) {
  85084. if(order > 10) {
  85085. if(order == 12) {
  85086. for(i = 0; i < (int)data_len; i++) {
  85087. sum = 0;
  85088. sum += qlp_coeff[11] * data[i-12];
  85089. sum += qlp_coeff[10] * data[i-11];
  85090. sum += qlp_coeff[9] * data[i-10];
  85091. sum += qlp_coeff[8] * data[i-9];
  85092. sum += qlp_coeff[7] * data[i-8];
  85093. sum += qlp_coeff[6] * data[i-7];
  85094. sum += qlp_coeff[5] * data[i-6];
  85095. sum += qlp_coeff[4] * data[i-5];
  85096. sum += qlp_coeff[3] * data[i-4];
  85097. sum += qlp_coeff[2] * data[i-3];
  85098. sum += qlp_coeff[1] * data[i-2];
  85099. sum += qlp_coeff[0] * data[i-1];
  85100. residual[i] = data[i] - (sum >> lp_quantization);
  85101. }
  85102. }
  85103. else { /* order == 11 */
  85104. for(i = 0; i < (int)data_len; i++) {
  85105. sum = 0;
  85106. sum += qlp_coeff[10] * data[i-11];
  85107. sum += qlp_coeff[9] * data[i-10];
  85108. sum += qlp_coeff[8] * data[i-9];
  85109. sum += qlp_coeff[7] * data[i-8];
  85110. sum += qlp_coeff[6] * data[i-7];
  85111. sum += qlp_coeff[5] * data[i-6];
  85112. sum += qlp_coeff[4] * data[i-5];
  85113. sum += qlp_coeff[3] * data[i-4];
  85114. sum += qlp_coeff[2] * data[i-3];
  85115. sum += qlp_coeff[1] * data[i-2];
  85116. sum += qlp_coeff[0] * data[i-1];
  85117. residual[i] = data[i] - (sum >> lp_quantization);
  85118. }
  85119. }
  85120. }
  85121. else {
  85122. if(order == 10) {
  85123. for(i = 0; i < (int)data_len; i++) {
  85124. sum = 0;
  85125. sum += qlp_coeff[9] * data[i-10];
  85126. sum += qlp_coeff[8] * data[i-9];
  85127. sum += qlp_coeff[7] * data[i-8];
  85128. sum += qlp_coeff[6] * data[i-7];
  85129. sum += qlp_coeff[5] * data[i-6];
  85130. sum += qlp_coeff[4] * data[i-5];
  85131. sum += qlp_coeff[3] * data[i-4];
  85132. sum += qlp_coeff[2] * data[i-3];
  85133. sum += qlp_coeff[1] * data[i-2];
  85134. sum += qlp_coeff[0] * data[i-1];
  85135. residual[i] = data[i] - (sum >> lp_quantization);
  85136. }
  85137. }
  85138. else { /* order == 9 */
  85139. for(i = 0; i < (int)data_len; i++) {
  85140. sum = 0;
  85141. sum += qlp_coeff[8] * data[i-9];
  85142. sum += qlp_coeff[7] * data[i-8];
  85143. sum += qlp_coeff[6] * data[i-7];
  85144. sum += qlp_coeff[5] * data[i-6];
  85145. sum += qlp_coeff[4] * data[i-5];
  85146. sum += qlp_coeff[3] * data[i-4];
  85147. sum += qlp_coeff[2] * data[i-3];
  85148. sum += qlp_coeff[1] * data[i-2];
  85149. sum += qlp_coeff[0] * data[i-1];
  85150. residual[i] = data[i] - (sum >> lp_quantization);
  85151. }
  85152. }
  85153. }
  85154. }
  85155. else if(order > 4) {
  85156. if(order > 6) {
  85157. if(order == 8) {
  85158. for(i = 0; i < (int)data_len; i++) {
  85159. sum = 0;
  85160. sum += qlp_coeff[7] * data[i-8];
  85161. sum += qlp_coeff[6] * data[i-7];
  85162. sum += qlp_coeff[5] * data[i-6];
  85163. sum += qlp_coeff[4] * data[i-5];
  85164. sum += qlp_coeff[3] * data[i-4];
  85165. sum += qlp_coeff[2] * data[i-3];
  85166. sum += qlp_coeff[1] * data[i-2];
  85167. sum += qlp_coeff[0] * data[i-1];
  85168. residual[i] = data[i] - (sum >> lp_quantization);
  85169. }
  85170. }
  85171. else { /* order == 7 */
  85172. for(i = 0; i < (int)data_len; i++) {
  85173. sum = 0;
  85174. sum += qlp_coeff[6] * data[i-7];
  85175. sum += qlp_coeff[5] * data[i-6];
  85176. sum += qlp_coeff[4] * data[i-5];
  85177. sum += qlp_coeff[3] * data[i-4];
  85178. sum += qlp_coeff[2] * data[i-3];
  85179. sum += qlp_coeff[1] * data[i-2];
  85180. sum += qlp_coeff[0] * data[i-1];
  85181. residual[i] = data[i] - (sum >> lp_quantization);
  85182. }
  85183. }
  85184. }
  85185. else {
  85186. if(order == 6) {
  85187. for(i = 0; i < (int)data_len; i++) {
  85188. sum = 0;
  85189. sum += qlp_coeff[5] * data[i-6];
  85190. sum += qlp_coeff[4] * data[i-5];
  85191. sum += qlp_coeff[3] * data[i-4];
  85192. sum += qlp_coeff[2] * data[i-3];
  85193. sum += qlp_coeff[1] * data[i-2];
  85194. sum += qlp_coeff[0] * data[i-1];
  85195. residual[i] = data[i] - (sum >> lp_quantization);
  85196. }
  85197. }
  85198. else { /* order == 5 */
  85199. for(i = 0; i < (int)data_len; i++) {
  85200. sum = 0;
  85201. sum += qlp_coeff[4] * data[i-5];
  85202. sum += qlp_coeff[3] * data[i-4];
  85203. sum += qlp_coeff[2] * data[i-3];
  85204. sum += qlp_coeff[1] * data[i-2];
  85205. sum += qlp_coeff[0] * data[i-1];
  85206. residual[i] = data[i] - (sum >> lp_quantization);
  85207. }
  85208. }
  85209. }
  85210. }
  85211. else {
  85212. if(order > 2) {
  85213. if(order == 4) {
  85214. for(i = 0; i < (int)data_len; i++) {
  85215. sum = 0;
  85216. sum += qlp_coeff[3] * data[i-4];
  85217. sum += qlp_coeff[2] * data[i-3];
  85218. sum += qlp_coeff[1] * data[i-2];
  85219. sum += qlp_coeff[0] * data[i-1];
  85220. residual[i] = data[i] - (sum >> lp_quantization);
  85221. }
  85222. }
  85223. else { /* order == 3 */
  85224. for(i = 0; i < (int)data_len; i++) {
  85225. sum = 0;
  85226. sum += qlp_coeff[2] * data[i-3];
  85227. sum += qlp_coeff[1] * data[i-2];
  85228. sum += qlp_coeff[0] * data[i-1];
  85229. residual[i] = data[i] - (sum >> lp_quantization);
  85230. }
  85231. }
  85232. }
  85233. else {
  85234. if(order == 2) {
  85235. for(i = 0; i < (int)data_len; i++) {
  85236. sum = 0;
  85237. sum += qlp_coeff[1] * data[i-2];
  85238. sum += qlp_coeff[0] * data[i-1];
  85239. residual[i] = data[i] - (sum >> lp_quantization);
  85240. }
  85241. }
  85242. else { /* order == 1 */
  85243. for(i = 0; i < (int)data_len; i++)
  85244. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85245. }
  85246. }
  85247. }
  85248. }
  85249. else { /* order > 12 */
  85250. for(i = 0; i < (int)data_len; i++) {
  85251. sum = 0;
  85252. switch(order) {
  85253. case 32: sum += qlp_coeff[31] * data[i-32];
  85254. case 31: sum += qlp_coeff[30] * data[i-31];
  85255. case 30: sum += qlp_coeff[29] * data[i-30];
  85256. case 29: sum += qlp_coeff[28] * data[i-29];
  85257. case 28: sum += qlp_coeff[27] * data[i-28];
  85258. case 27: sum += qlp_coeff[26] * data[i-27];
  85259. case 26: sum += qlp_coeff[25] * data[i-26];
  85260. case 25: sum += qlp_coeff[24] * data[i-25];
  85261. case 24: sum += qlp_coeff[23] * data[i-24];
  85262. case 23: sum += qlp_coeff[22] * data[i-23];
  85263. case 22: sum += qlp_coeff[21] * data[i-22];
  85264. case 21: sum += qlp_coeff[20] * data[i-21];
  85265. case 20: sum += qlp_coeff[19] * data[i-20];
  85266. case 19: sum += qlp_coeff[18] * data[i-19];
  85267. case 18: sum += qlp_coeff[17] * data[i-18];
  85268. case 17: sum += qlp_coeff[16] * data[i-17];
  85269. case 16: sum += qlp_coeff[15] * data[i-16];
  85270. case 15: sum += qlp_coeff[14] * data[i-15];
  85271. case 14: sum += qlp_coeff[13] * data[i-14];
  85272. case 13: sum += qlp_coeff[12] * data[i-13];
  85273. sum += qlp_coeff[11] * data[i-12];
  85274. sum += qlp_coeff[10] * data[i-11];
  85275. sum += qlp_coeff[ 9] * data[i-10];
  85276. sum += qlp_coeff[ 8] * data[i- 9];
  85277. sum += qlp_coeff[ 7] * data[i- 8];
  85278. sum += qlp_coeff[ 6] * data[i- 7];
  85279. sum += qlp_coeff[ 5] * data[i- 6];
  85280. sum += qlp_coeff[ 4] * data[i- 5];
  85281. sum += qlp_coeff[ 3] * data[i- 4];
  85282. sum += qlp_coeff[ 2] * data[i- 3];
  85283. sum += qlp_coeff[ 1] * data[i- 2];
  85284. sum += qlp_coeff[ 0] * data[i- 1];
  85285. }
  85286. residual[i] = data[i] - (sum >> lp_quantization);
  85287. }
  85288. }
  85289. }
  85290. #endif
  85291. void FLAC__lpc_compute_residual_from_qlp_coefficients_wide(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[])
  85292. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85293. {
  85294. unsigned i, j;
  85295. FLAC__int64 sum;
  85296. const FLAC__int32 *history;
  85297. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85298. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85299. for(i=0;i<order;i++)
  85300. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85301. fprintf(stderr,"\n");
  85302. #endif
  85303. FLAC__ASSERT(order > 0);
  85304. for(i = 0; i < data_len; i++) {
  85305. sum = 0;
  85306. history = data;
  85307. for(j = 0; j < order; j++)
  85308. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85309. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85310. #if defined _MSC_VER
  85311. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85312. #else
  85313. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85314. #endif
  85315. break;
  85316. }
  85317. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85318. #if defined _MSC_VER
  85319. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%I64d, residual=%I64d\n", i, *data, sum >> lp_quantization, (FLAC__int64)(*data) - (sum >> lp_quantization));
  85320. #else
  85321. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, data=%d, sum=%lld, residual=%lld\n", i, *data, (long long)(sum >> lp_quantization), (long long)((FLAC__int64)(*data) - (sum >> lp_quantization)));
  85322. #endif
  85323. break;
  85324. }
  85325. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85326. }
  85327. }
  85328. #else /* fully unrolled version for normal use */
  85329. {
  85330. int i;
  85331. FLAC__int64 sum;
  85332. FLAC__ASSERT(order > 0);
  85333. FLAC__ASSERT(order <= 32);
  85334. if(order <= 12) {
  85335. if(order > 8) {
  85336. if(order > 10) {
  85337. if(order == 12) {
  85338. for(i = 0; i < (int)data_len; i++) {
  85339. sum = 0;
  85340. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85341. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85342. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85343. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85344. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85345. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85346. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85347. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85348. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85349. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85350. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85351. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85352. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85353. }
  85354. }
  85355. else { /* order == 11 */
  85356. for(i = 0; i < (int)data_len; i++) {
  85357. sum = 0;
  85358. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85359. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85360. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85361. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85362. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85363. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85364. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85365. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85366. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85367. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85368. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85369. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85370. }
  85371. }
  85372. }
  85373. else {
  85374. if(order == 10) {
  85375. for(i = 0; i < (int)data_len; i++) {
  85376. sum = 0;
  85377. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85378. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85379. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85380. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85381. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85382. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85383. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85384. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85385. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85386. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85387. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85388. }
  85389. }
  85390. else { /* order == 9 */
  85391. for(i = 0; i < (int)data_len; i++) {
  85392. sum = 0;
  85393. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85394. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85395. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85396. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85397. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85398. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85399. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85400. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85401. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85402. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85403. }
  85404. }
  85405. }
  85406. }
  85407. else if(order > 4) {
  85408. if(order > 6) {
  85409. if(order == 8) {
  85410. for(i = 0; i < (int)data_len; i++) {
  85411. sum = 0;
  85412. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85413. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85414. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85415. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85416. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85417. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85418. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85419. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85420. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85421. }
  85422. }
  85423. else { /* order == 7 */
  85424. for(i = 0; i < (int)data_len; i++) {
  85425. sum = 0;
  85426. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85427. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85428. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85429. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85430. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85431. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85432. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85433. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85434. }
  85435. }
  85436. }
  85437. else {
  85438. if(order == 6) {
  85439. for(i = 0; i < (int)data_len; i++) {
  85440. sum = 0;
  85441. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85442. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85443. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85444. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85445. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85446. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85447. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85448. }
  85449. }
  85450. else { /* order == 5 */
  85451. for(i = 0; i < (int)data_len; i++) {
  85452. sum = 0;
  85453. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85454. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85455. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85456. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85457. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85458. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85459. }
  85460. }
  85461. }
  85462. }
  85463. else {
  85464. if(order > 2) {
  85465. if(order == 4) {
  85466. for(i = 0; i < (int)data_len; i++) {
  85467. sum = 0;
  85468. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85469. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85470. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85471. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85472. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85473. }
  85474. }
  85475. else { /* order == 3 */
  85476. for(i = 0; i < (int)data_len; i++) {
  85477. sum = 0;
  85478. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85479. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85480. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85481. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85482. }
  85483. }
  85484. }
  85485. else {
  85486. if(order == 2) {
  85487. for(i = 0; i < (int)data_len; i++) {
  85488. sum = 0;
  85489. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85490. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85491. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85492. }
  85493. }
  85494. else { /* order == 1 */
  85495. for(i = 0; i < (int)data_len; i++)
  85496. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85497. }
  85498. }
  85499. }
  85500. }
  85501. else { /* order > 12 */
  85502. for(i = 0; i < (int)data_len; i++) {
  85503. sum = 0;
  85504. switch(order) {
  85505. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85506. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85507. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85508. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85509. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85510. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85511. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85512. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85513. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85514. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85515. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85516. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85517. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85518. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85519. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85520. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85521. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85522. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85523. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85524. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85525. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85526. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85527. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85528. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85529. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85530. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85531. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85532. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85533. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85534. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85535. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85536. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85537. }
  85538. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85539. }
  85540. }
  85541. }
  85542. #endif
  85543. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85544. void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
  85545. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85546. {
  85547. FLAC__int64 sumo;
  85548. unsigned i, j;
  85549. FLAC__int32 sum;
  85550. const FLAC__int32 *r = residual, *history;
  85551. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85552. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85553. for(i=0;i<order;i++)
  85554. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85555. fprintf(stderr,"\n");
  85556. #endif
  85557. FLAC__ASSERT(order > 0);
  85558. for(i = 0; i < data_len; i++) {
  85559. sumo = 0;
  85560. sum = 0;
  85561. history = data;
  85562. for(j = 0; j < order; j++) {
  85563. sum += qlp_coeff[j] * (*(--history));
  85564. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85565. #if defined _MSC_VER
  85566. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85567. fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%I64d\n",i,j,qlp_coeff[j],*history,sumo);
  85568. #else
  85569. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85570. fprintf(stderr,"FLAC__lpc_restore_signal: OVERFLOW, i=%u, j=%u, c=%d, d=%d, sumo=%lld\n",i,j,qlp_coeff[j],*history,(long long)sumo);
  85571. #endif
  85572. }
  85573. *(data++) = *(r++) + (sum >> lp_quantization);
  85574. }
  85575. }
  85576. #else /* fully unrolled version for normal use */
  85577. {
  85578. int i;
  85579. FLAC__int32 sum;
  85580. FLAC__ASSERT(order > 0);
  85581. FLAC__ASSERT(order <= 32);
  85582. if(order <= 12) {
  85583. if(order > 8) {
  85584. if(order > 10) {
  85585. if(order == 12) {
  85586. for(i = 0; i < (int)data_len; i++) {
  85587. sum = 0;
  85588. sum += qlp_coeff[11] * data[i-12];
  85589. sum += qlp_coeff[10] * data[i-11];
  85590. sum += qlp_coeff[9] * data[i-10];
  85591. sum += qlp_coeff[8] * data[i-9];
  85592. sum += qlp_coeff[7] * data[i-8];
  85593. sum += qlp_coeff[6] * data[i-7];
  85594. sum += qlp_coeff[5] * data[i-6];
  85595. sum += qlp_coeff[4] * data[i-5];
  85596. sum += qlp_coeff[3] * data[i-4];
  85597. sum += qlp_coeff[2] * data[i-3];
  85598. sum += qlp_coeff[1] * data[i-2];
  85599. sum += qlp_coeff[0] * data[i-1];
  85600. data[i] = residual[i] + (sum >> lp_quantization);
  85601. }
  85602. }
  85603. else { /* order == 11 */
  85604. for(i = 0; i < (int)data_len; i++) {
  85605. sum = 0;
  85606. sum += qlp_coeff[10] * data[i-11];
  85607. sum += qlp_coeff[9] * data[i-10];
  85608. sum += qlp_coeff[8] * data[i-9];
  85609. sum += qlp_coeff[7] * data[i-8];
  85610. sum += qlp_coeff[6] * data[i-7];
  85611. sum += qlp_coeff[5] * data[i-6];
  85612. sum += qlp_coeff[4] * data[i-5];
  85613. sum += qlp_coeff[3] * data[i-4];
  85614. sum += qlp_coeff[2] * data[i-3];
  85615. sum += qlp_coeff[1] * data[i-2];
  85616. sum += qlp_coeff[0] * data[i-1];
  85617. data[i] = residual[i] + (sum >> lp_quantization);
  85618. }
  85619. }
  85620. }
  85621. else {
  85622. if(order == 10) {
  85623. for(i = 0; i < (int)data_len; i++) {
  85624. sum = 0;
  85625. sum += qlp_coeff[9] * data[i-10];
  85626. sum += qlp_coeff[8] * data[i-9];
  85627. sum += qlp_coeff[7] * data[i-8];
  85628. sum += qlp_coeff[6] * data[i-7];
  85629. sum += qlp_coeff[5] * data[i-6];
  85630. sum += qlp_coeff[4] * data[i-5];
  85631. sum += qlp_coeff[3] * data[i-4];
  85632. sum += qlp_coeff[2] * data[i-3];
  85633. sum += qlp_coeff[1] * data[i-2];
  85634. sum += qlp_coeff[0] * data[i-1];
  85635. data[i] = residual[i] + (sum >> lp_quantization);
  85636. }
  85637. }
  85638. else { /* order == 9 */
  85639. for(i = 0; i < (int)data_len; i++) {
  85640. sum = 0;
  85641. sum += qlp_coeff[8] * data[i-9];
  85642. sum += qlp_coeff[7] * data[i-8];
  85643. sum += qlp_coeff[6] * data[i-7];
  85644. sum += qlp_coeff[5] * data[i-6];
  85645. sum += qlp_coeff[4] * data[i-5];
  85646. sum += qlp_coeff[3] * data[i-4];
  85647. sum += qlp_coeff[2] * data[i-3];
  85648. sum += qlp_coeff[1] * data[i-2];
  85649. sum += qlp_coeff[0] * data[i-1];
  85650. data[i] = residual[i] + (sum >> lp_quantization);
  85651. }
  85652. }
  85653. }
  85654. }
  85655. else if(order > 4) {
  85656. if(order > 6) {
  85657. if(order == 8) {
  85658. for(i = 0; i < (int)data_len; i++) {
  85659. sum = 0;
  85660. sum += qlp_coeff[7] * data[i-8];
  85661. sum += qlp_coeff[6] * data[i-7];
  85662. sum += qlp_coeff[5] * data[i-6];
  85663. sum += qlp_coeff[4] * data[i-5];
  85664. sum += qlp_coeff[3] * data[i-4];
  85665. sum += qlp_coeff[2] * data[i-3];
  85666. sum += qlp_coeff[1] * data[i-2];
  85667. sum += qlp_coeff[0] * data[i-1];
  85668. data[i] = residual[i] + (sum >> lp_quantization);
  85669. }
  85670. }
  85671. else { /* order == 7 */
  85672. for(i = 0; i < (int)data_len; i++) {
  85673. sum = 0;
  85674. sum += qlp_coeff[6] * data[i-7];
  85675. sum += qlp_coeff[5] * data[i-6];
  85676. sum += qlp_coeff[4] * data[i-5];
  85677. sum += qlp_coeff[3] * data[i-4];
  85678. sum += qlp_coeff[2] * data[i-3];
  85679. sum += qlp_coeff[1] * data[i-2];
  85680. sum += qlp_coeff[0] * data[i-1];
  85681. data[i] = residual[i] + (sum >> lp_quantization);
  85682. }
  85683. }
  85684. }
  85685. else {
  85686. if(order == 6) {
  85687. for(i = 0; i < (int)data_len; i++) {
  85688. sum = 0;
  85689. sum += qlp_coeff[5] * data[i-6];
  85690. sum += qlp_coeff[4] * data[i-5];
  85691. sum += qlp_coeff[3] * data[i-4];
  85692. sum += qlp_coeff[2] * data[i-3];
  85693. sum += qlp_coeff[1] * data[i-2];
  85694. sum += qlp_coeff[0] * data[i-1];
  85695. data[i] = residual[i] + (sum >> lp_quantization);
  85696. }
  85697. }
  85698. else { /* order == 5 */
  85699. for(i = 0; i < (int)data_len; i++) {
  85700. sum = 0;
  85701. sum += qlp_coeff[4] * data[i-5];
  85702. sum += qlp_coeff[3] * data[i-4];
  85703. sum += qlp_coeff[2] * data[i-3];
  85704. sum += qlp_coeff[1] * data[i-2];
  85705. sum += qlp_coeff[0] * data[i-1];
  85706. data[i] = residual[i] + (sum >> lp_quantization);
  85707. }
  85708. }
  85709. }
  85710. }
  85711. else {
  85712. if(order > 2) {
  85713. if(order == 4) {
  85714. for(i = 0; i < (int)data_len; i++) {
  85715. sum = 0;
  85716. sum += qlp_coeff[3] * data[i-4];
  85717. sum += qlp_coeff[2] * data[i-3];
  85718. sum += qlp_coeff[1] * data[i-2];
  85719. sum += qlp_coeff[0] * data[i-1];
  85720. data[i] = residual[i] + (sum >> lp_quantization);
  85721. }
  85722. }
  85723. else { /* order == 3 */
  85724. for(i = 0; i < (int)data_len; i++) {
  85725. sum = 0;
  85726. sum += qlp_coeff[2] * data[i-3];
  85727. sum += qlp_coeff[1] * data[i-2];
  85728. sum += qlp_coeff[0] * data[i-1];
  85729. data[i] = residual[i] + (sum >> lp_quantization);
  85730. }
  85731. }
  85732. }
  85733. else {
  85734. if(order == 2) {
  85735. for(i = 0; i < (int)data_len; i++) {
  85736. sum = 0;
  85737. sum += qlp_coeff[1] * data[i-2];
  85738. sum += qlp_coeff[0] * data[i-1];
  85739. data[i] = residual[i] + (sum >> lp_quantization);
  85740. }
  85741. }
  85742. else { /* order == 1 */
  85743. for(i = 0; i < (int)data_len; i++)
  85744. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85745. }
  85746. }
  85747. }
  85748. }
  85749. else { /* order > 12 */
  85750. for(i = 0; i < (int)data_len; i++) {
  85751. sum = 0;
  85752. switch(order) {
  85753. case 32: sum += qlp_coeff[31] * data[i-32];
  85754. case 31: sum += qlp_coeff[30] * data[i-31];
  85755. case 30: sum += qlp_coeff[29] * data[i-30];
  85756. case 29: sum += qlp_coeff[28] * data[i-29];
  85757. case 28: sum += qlp_coeff[27] * data[i-28];
  85758. case 27: sum += qlp_coeff[26] * data[i-27];
  85759. case 26: sum += qlp_coeff[25] * data[i-26];
  85760. case 25: sum += qlp_coeff[24] * data[i-25];
  85761. case 24: sum += qlp_coeff[23] * data[i-24];
  85762. case 23: sum += qlp_coeff[22] * data[i-23];
  85763. case 22: sum += qlp_coeff[21] * data[i-22];
  85764. case 21: sum += qlp_coeff[20] * data[i-21];
  85765. case 20: sum += qlp_coeff[19] * data[i-20];
  85766. case 19: sum += qlp_coeff[18] * data[i-19];
  85767. case 18: sum += qlp_coeff[17] * data[i-18];
  85768. case 17: sum += qlp_coeff[16] * data[i-17];
  85769. case 16: sum += qlp_coeff[15] * data[i-16];
  85770. case 15: sum += qlp_coeff[14] * data[i-15];
  85771. case 14: sum += qlp_coeff[13] * data[i-14];
  85772. case 13: sum += qlp_coeff[12] * data[i-13];
  85773. sum += qlp_coeff[11] * data[i-12];
  85774. sum += qlp_coeff[10] * data[i-11];
  85775. sum += qlp_coeff[ 9] * data[i-10];
  85776. sum += qlp_coeff[ 8] * data[i- 9];
  85777. sum += qlp_coeff[ 7] * data[i- 8];
  85778. sum += qlp_coeff[ 6] * data[i- 7];
  85779. sum += qlp_coeff[ 5] * data[i- 6];
  85780. sum += qlp_coeff[ 4] * data[i- 5];
  85781. sum += qlp_coeff[ 3] * data[i- 4];
  85782. sum += qlp_coeff[ 2] * data[i- 3];
  85783. sum += qlp_coeff[ 1] * data[i- 2];
  85784. sum += qlp_coeff[ 0] * data[i- 1];
  85785. }
  85786. data[i] = residual[i] + (sum >> lp_quantization);
  85787. }
  85788. }
  85789. }
  85790. #endif
  85791. void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[])
  85792. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85793. {
  85794. unsigned i, j;
  85795. FLAC__int64 sum;
  85796. const FLAC__int32 *r = residual, *history;
  85797. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85798. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85799. for(i=0;i<order;i++)
  85800. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85801. fprintf(stderr,"\n");
  85802. #endif
  85803. FLAC__ASSERT(order > 0);
  85804. for(i = 0; i < data_len; i++) {
  85805. sum = 0;
  85806. history = data;
  85807. for(j = 0; j < order; j++)
  85808. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85809. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85810. #ifdef _MSC_VER
  85811. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85812. #else
  85813. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85814. #endif
  85815. break;
  85816. }
  85817. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  85818. #ifdef _MSC_VER
  85819. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%I64d, data=%I64d\n", i, *r, sum >> lp_quantization, (FLAC__int64)(*r) + (sum >> lp_quantization));
  85820. #else
  85821. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, residual=%d, sum=%lld, data=%lld\n", i, *r, (long long)(sum >> lp_quantization), (long long)((FLAC__int64)(*r) + (sum >> lp_quantization)));
  85822. #endif
  85823. break;
  85824. }
  85825. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  85826. }
  85827. }
  85828. #else /* fully unrolled version for normal use */
  85829. {
  85830. int i;
  85831. FLAC__int64 sum;
  85832. FLAC__ASSERT(order > 0);
  85833. FLAC__ASSERT(order <= 32);
  85834. if(order <= 12) {
  85835. if(order > 8) {
  85836. if(order > 10) {
  85837. if(order == 12) {
  85838. for(i = 0; i < (int)data_len; i++) {
  85839. sum = 0;
  85840. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85841. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85842. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85843. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85844. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85845. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85846. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85847. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85848. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85849. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85850. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85851. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85852. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85853. }
  85854. }
  85855. else { /* order == 11 */
  85856. for(i = 0; i < (int)data_len; i++) {
  85857. sum = 0;
  85858. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85859. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85860. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85861. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85862. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85863. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85864. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85865. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85866. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85867. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85868. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85869. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85870. }
  85871. }
  85872. }
  85873. else {
  85874. if(order == 10) {
  85875. for(i = 0; i < (int)data_len; i++) {
  85876. sum = 0;
  85877. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85878. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85879. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85880. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85881. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85882. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85883. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85884. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85885. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85886. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85887. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85888. }
  85889. }
  85890. else { /* order == 9 */
  85891. for(i = 0; i < (int)data_len; i++) {
  85892. sum = 0;
  85893. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85894. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85895. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85896. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85897. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85898. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85899. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85900. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85901. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85902. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85903. }
  85904. }
  85905. }
  85906. }
  85907. else if(order > 4) {
  85908. if(order > 6) {
  85909. if(order == 8) {
  85910. for(i = 0; i < (int)data_len; i++) {
  85911. sum = 0;
  85912. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85913. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85914. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85915. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85916. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85917. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85918. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85919. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85920. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85921. }
  85922. }
  85923. else { /* order == 7 */
  85924. for(i = 0; i < (int)data_len; i++) {
  85925. sum = 0;
  85926. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85927. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85928. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85929. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85930. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85931. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85932. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85933. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85934. }
  85935. }
  85936. }
  85937. else {
  85938. if(order == 6) {
  85939. for(i = 0; i < (int)data_len; i++) {
  85940. sum = 0;
  85941. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85942. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85943. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85944. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85945. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85946. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85947. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85948. }
  85949. }
  85950. else { /* order == 5 */
  85951. for(i = 0; i < (int)data_len; i++) {
  85952. sum = 0;
  85953. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85954. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85955. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85956. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85957. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85958. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85959. }
  85960. }
  85961. }
  85962. }
  85963. else {
  85964. if(order > 2) {
  85965. if(order == 4) {
  85966. for(i = 0; i < (int)data_len; i++) {
  85967. sum = 0;
  85968. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85969. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85970. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85971. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85972. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85973. }
  85974. }
  85975. else { /* order == 3 */
  85976. for(i = 0; i < (int)data_len; i++) {
  85977. sum = 0;
  85978. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85979. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85980. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85981. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85982. }
  85983. }
  85984. }
  85985. else {
  85986. if(order == 2) {
  85987. for(i = 0; i < (int)data_len; i++) {
  85988. sum = 0;
  85989. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85990. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85991. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85992. }
  85993. }
  85994. else { /* order == 1 */
  85995. for(i = 0; i < (int)data_len; i++)
  85996. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85997. }
  85998. }
  85999. }
  86000. }
  86001. else { /* order > 12 */
  86002. for(i = 0; i < (int)data_len; i++) {
  86003. sum = 0;
  86004. switch(order) {
  86005. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86006. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86007. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86008. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86009. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86010. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86011. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86012. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86013. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86014. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86015. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86016. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86017. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86018. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86019. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86020. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86021. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86022. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86023. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86024. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86025. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86026. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86027. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86028. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86029. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86030. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86031. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86032. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86033. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86034. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86035. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86036. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86037. }
  86038. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86039. }
  86040. }
  86041. }
  86042. #endif
  86043. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86044. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86045. {
  86046. FLAC__double error_scale;
  86047. FLAC__ASSERT(total_samples > 0);
  86048. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86049. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86050. }
  86051. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86052. {
  86053. if(lpc_error > 0.0) {
  86054. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86055. if(bps >= 0.0)
  86056. return bps;
  86057. else
  86058. return 0.0;
  86059. }
  86060. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86061. return 1e32;
  86062. }
  86063. else {
  86064. return 0.0;
  86065. }
  86066. }
  86067. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86068. {
  86069. unsigned order, index, best_index; /* 'index' the index into lpc_error; index==order-1 since lpc_error[0] is for order==1, lpc_error[1] is for order==2, etc */
  86070. FLAC__double bits, best_bits, error_scale;
  86071. FLAC__ASSERT(max_order > 0);
  86072. FLAC__ASSERT(total_samples > 0);
  86073. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86074. best_index = 0;
  86075. best_bits = (unsigned)(-1);
  86076. for(index = 0, order = 1; index < max_order; index++, order++) {
  86077. bits = FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error[index], error_scale) * (FLAC__double)(total_samples - order) + (FLAC__double)(order * overhead_bits_per_order);
  86078. if(bits < best_bits) {
  86079. best_index = index;
  86080. best_bits = bits;
  86081. }
  86082. }
  86083. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86084. }
  86085. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86086. #endif
  86087. /*** End of inlined file: lpc_flac.c ***/
  86088. /*** Start of inlined file: md5.c ***/
  86089. /*** Start of inlined file: juce_FlacHeader.h ***/
  86090. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86091. // tasks..
  86092. #define VERSION "1.2.1"
  86093. #define FLAC__NO_DLL 1
  86094. #if JUCE_MSVC
  86095. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86096. #endif
  86097. #if JUCE_MAC
  86098. #define FLAC__SYS_DARWIN 1
  86099. #endif
  86100. /*** End of inlined file: juce_FlacHeader.h ***/
  86101. #if JUCE_USE_FLAC
  86102. #if HAVE_CONFIG_H
  86103. # include <config.h>
  86104. #endif
  86105. #include <stdlib.h> /* for malloc() */
  86106. #include <string.h> /* for memcpy() */
  86107. /*** Start of inlined file: md5.h ***/
  86108. #ifndef FLAC__PRIVATE__MD5_H
  86109. #define FLAC__PRIVATE__MD5_H
  86110. typedef struct {
  86111. FLAC__uint32 in[16];
  86112. FLAC__uint32 buf[4];
  86113. FLAC__uint32 bytes[2];
  86114. FLAC__byte *internal_buf;
  86115. size_t capacity;
  86116. } FLAC__MD5Context;
  86117. void FLAC__MD5Init(FLAC__MD5Context *context);
  86118. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86119. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86120. #endif
  86121. /*** End of inlined file: md5.h ***/
  86122. #ifndef FLaC__INLINE
  86123. #define FLaC__INLINE
  86124. #endif
  86125. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86126. #define F2(x, y, z) F1(z, x, y)
  86127. #define F3(x, y, z) (x ^ y ^ z)
  86128. #define F4(x, y, z) (y ^ (x | ~z))
  86129. #define MD5STEP(f,w,x,y,z,in,s) \
  86130. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86131. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86132. {
  86133. register FLAC__uint32 a, b, c, d;
  86134. a = buf[0];
  86135. b = buf[1];
  86136. c = buf[2];
  86137. d = buf[3];
  86138. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86139. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86140. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86141. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86142. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86143. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86144. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86145. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86146. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86147. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86148. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86149. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86150. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86151. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86152. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86153. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86154. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86155. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86156. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86157. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86158. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86159. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86160. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86161. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86162. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86163. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86164. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86165. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86166. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86167. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86168. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86169. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86170. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86171. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86172. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86173. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86174. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86175. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86176. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86177. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86178. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86179. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86180. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86181. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86182. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86183. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86184. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86185. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86186. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86187. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86188. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86189. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86190. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86191. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86192. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86193. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86194. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86195. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86196. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86197. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86198. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86199. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86200. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86201. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86202. buf[0] += a;
  86203. buf[1] += b;
  86204. buf[2] += c;
  86205. buf[3] += d;
  86206. }
  86207. #if WORDS_BIGENDIAN
  86208. //@@@@@@ OPT: use bswap/intrinsics
  86209. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86210. {
  86211. register FLAC__uint32 x;
  86212. do {
  86213. x = *buf;
  86214. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86215. *buf++ = (x >> 16) | (x << 16);
  86216. } while (--words);
  86217. }
  86218. static void byteSwapX16(FLAC__uint32 *buf)
  86219. {
  86220. register FLAC__uint32 x;
  86221. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86222. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86223. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86224. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86225. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86226. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86227. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86228. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86229. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86230. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86231. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86232. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86233. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86234. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86235. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86236. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86237. }
  86238. #else
  86239. #define byteSwap(buf, words)
  86240. #define byteSwapX16(buf)
  86241. #endif
  86242. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86243. {
  86244. FLAC__uint32 t;
  86245. t = ctx->bytes[0];
  86246. if ((ctx->bytes[0] = t + len) < t)
  86247. ctx->bytes[1]++; /* Carry from low to high */
  86248. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86249. if (t > len) {
  86250. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86251. return;
  86252. }
  86253. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86254. byteSwapX16(ctx->in);
  86255. FLAC__MD5Transform(ctx->buf, ctx->in);
  86256. buf += t;
  86257. len -= t;
  86258. while (len >= 64) {
  86259. memcpy(ctx->in, buf, 64);
  86260. byteSwapX16(ctx->in);
  86261. FLAC__MD5Transform(ctx->buf, ctx->in);
  86262. buf += 64;
  86263. len -= 64;
  86264. }
  86265. memcpy(ctx->in, buf, len);
  86266. }
  86267. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86268. {
  86269. ctx->buf[0] = 0x67452301;
  86270. ctx->buf[1] = 0xefcdab89;
  86271. ctx->buf[2] = 0x98badcfe;
  86272. ctx->buf[3] = 0x10325476;
  86273. ctx->bytes[0] = 0;
  86274. ctx->bytes[1] = 0;
  86275. ctx->internal_buf = 0;
  86276. ctx->capacity = 0;
  86277. }
  86278. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86279. {
  86280. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86281. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86282. *p++ = 0x80;
  86283. count = 56 - 1 - count;
  86284. if (count < 0) { /* Padding forces an extra block */
  86285. memset(p, 0, count + 8);
  86286. byteSwapX16(ctx->in);
  86287. FLAC__MD5Transform(ctx->buf, ctx->in);
  86288. p = (FLAC__byte *)ctx->in;
  86289. count = 56;
  86290. }
  86291. memset(p, 0, count);
  86292. byteSwap(ctx->in, 14);
  86293. ctx->in[14] = ctx->bytes[0] << 3;
  86294. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86295. FLAC__MD5Transform(ctx->buf, ctx->in);
  86296. byteSwap(ctx->buf, 4);
  86297. memcpy(digest, ctx->buf, 16);
  86298. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86299. if(0 != ctx->internal_buf) {
  86300. free(ctx->internal_buf);
  86301. ctx->internal_buf = 0;
  86302. ctx->capacity = 0;
  86303. }
  86304. }
  86305. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86306. {
  86307. unsigned channel, sample;
  86308. register FLAC__int32 a_word;
  86309. register FLAC__byte *buf_ = buf;
  86310. #if WORDS_BIGENDIAN
  86311. #else
  86312. if(channels == 2 && bytes_per_sample == 2) {
  86313. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86314. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86315. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86316. *buf1_ = (FLAC__int16)signal[1][sample];
  86317. }
  86318. else if(channels == 1 && bytes_per_sample == 2) {
  86319. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86320. for(sample = 0; sample < samples; sample++)
  86321. *buf1_++ = (FLAC__int16)signal[0][sample];
  86322. }
  86323. else
  86324. #endif
  86325. if(bytes_per_sample == 2) {
  86326. if(channels == 2) {
  86327. for(sample = 0; sample < samples; sample++) {
  86328. a_word = signal[0][sample];
  86329. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86330. *buf_++ = (FLAC__byte)a_word;
  86331. a_word = signal[1][sample];
  86332. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86333. *buf_++ = (FLAC__byte)a_word;
  86334. }
  86335. }
  86336. else if(channels == 1) {
  86337. for(sample = 0; sample < samples; sample++) {
  86338. a_word = signal[0][sample];
  86339. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86340. *buf_++ = (FLAC__byte)a_word;
  86341. }
  86342. }
  86343. else {
  86344. for(sample = 0; sample < samples; sample++) {
  86345. for(channel = 0; channel < channels; channel++) {
  86346. a_word = signal[channel][sample];
  86347. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86348. *buf_++ = (FLAC__byte)a_word;
  86349. }
  86350. }
  86351. }
  86352. }
  86353. else if(bytes_per_sample == 3) {
  86354. if(channels == 2) {
  86355. for(sample = 0; sample < samples; sample++) {
  86356. a_word = signal[0][sample];
  86357. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86358. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86359. *buf_++ = (FLAC__byte)a_word;
  86360. a_word = signal[1][sample];
  86361. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86362. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86363. *buf_++ = (FLAC__byte)a_word;
  86364. }
  86365. }
  86366. else if(channels == 1) {
  86367. for(sample = 0; sample < samples; sample++) {
  86368. a_word = signal[0][sample];
  86369. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86370. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86371. *buf_++ = (FLAC__byte)a_word;
  86372. }
  86373. }
  86374. else {
  86375. for(sample = 0; sample < samples; sample++) {
  86376. for(channel = 0; channel < channels; channel++) {
  86377. a_word = signal[channel][sample];
  86378. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86379. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86380. *buf_++ = (FLAC__byte)a_word;
  86381. }
  86382. }
  86383. }
  86384. }
  86385. else if(bytes_per_sample == 1) {
  86386. if(channels == 2) {
  86387. for(sample = 0; sample < samples; sample++) {
  86388. a_word = signal[0][sample];
  86389. *buf_++ = (FLAC__byte)a_word;
  86390. a_word = signal[1][sample];
  86391. *buf_++ = (FLAC__byte)a_word;
  86392. }
  86393. }
  86394. else if(channels == 1) {
  86395. for(sample = 0; sample < samples; sample++) {
  86396. a_word = signal[0][sample];
  86397. *buf_++ = (FLAC__byte)a_word;
  86398. }
  86399. }
  86400. else {
  86401. for(sample = 0; sample < samples; sample++) {
  86402. for(channel = 0; channel < channels; channel++) {
  86403. a_word = signal[channel][sample];
  86404. *buf_++ = (FLAC__byte)a_word;
  86405. }
  86406. }
  86407. }
  86408. }
  86409. else { /* bytes_per_sample == 4, maybe optimize more later */
  86410. for(sample = 0; sample < samples; sample++) {
  86411. for(channel = 0; channel < channels; channel++) {
  86412. a_word = signal[channel][sample];
  86413. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86414. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86415. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86416. *buf_++ = (FLAC__byte)a_word;
  86417. }
  86418. }
  86419. }
  86420. }
  86421. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86422. {
  86423. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86424. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86425. return false;
  86426. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86427. return false;
  86428. if(ctx->capacity < bytes_needed) {
  86429. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86430. if(0 == tmp) {
  86431. free(ctx->internal_buf);
  86432. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86433. return false;
  86434. }
  86435. ctx->internal_buf = tmp;
  86436. ctx->capacity = bytes_needed;
  86437. }
  86438. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86439. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86440. return true;
  86441. }
  86442. #endif
  86443. /*** End of inlined file: md5.c ***/
  86444. /*** Start of inlined file: memory.c ***/
  86445. /*** Start of inlined file: juce_FlacHeader.h ***/
  86446. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86447. // tasks..
  86448. #define VERSION "1.2.1"
  86449. #define FLAC__NO_DLL 1
  86450. #if JUCE_MSVC
  86451. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86452. #endif
  86453. #if JUCE_MAC
  86454. #define FLAC__SYS_DARWIN 1
  86455. #endif
  86456. /*** End of inlined file: juce_FlacHeader.h ***/
  86457. #if JUCE_USE_FLAC
  86458. #if HAVE_CONFIG_H
  86459. # include <config.h>
  86460. #endif
  86461. /*** Start of inlined file: memory.h ***/
  86462. #ifndef FLAC__PRIVATE__MEMORY_H
  86463. #define FLAC__PRIVATE__MEMORY_H
  86464. #ifdef HAVE_CONFIG_H
  86465. #include <config.h>
  86466. #endif
  86467. #include <stdlib.h> /* for size_t */
  86468. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86469. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86470. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86471. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86472. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86473. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86474. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86475. #endif
  86476. #endif
  86477. /*** End of inlined file: memory.h ***/
  86478. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86479. {
  86480. void *x;
  86481. FLAC__ASSERT(0 != aligned_address);
  86482. #ifdef FLAC__ALIGN_MALLOC_DATA
  86483. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86484. #ifdef SIZEOF_VOIDP
  86485. #if SIZEOF_VOIDP == 4
  86486. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86487. #elif SIZEOF_VOIDP == 8
  86488. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86489. #else
  86490. # error Unsupported sizeof(void*)
  86491. #endif
  86492. #else
  86493. if(sizeof(void*) == sizeof(unsigned))
  86494. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86495. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86496. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86497. else
  86498. return 0;
  86499. #endif
  86500. #else
  86501. x = safe_malloc_(bytes);
  86502. *aligned_address = x;
  86503. #endif
  86504. return x;
  86505. }
  86506. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86507. {
  86508. FLAC__int32 *pu; /* unaligned pointer */
  86509. union { /* union needed to comply with C99 pointer aliasing rules */
  86510. FLAC__int32 *pa; /* aligned pointer */
  86511. void *pv; /* aligned pointer alias */
  86512. } u;
  86513. FLAC__ASSERT(elements > 0);
  86514. FLAC__ASSERT(0 != unaligned_pointer);
  86515. FLAC__ASSERT(0 != aligned_pointer);
  86516. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86517. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86518. if(0 == pu) {
  86519. return false;
  86520. }
  86521. else {
  86522. if(*unaligned_pointer != 0)
  86523. free(*unaligned_pointer);
  86524. *unaligned_pointer = pu;
  86525. *aligned_pointer = u.pa;
  86526. return true;
  86527. }
  86528. }
  86529. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86530. {
  86531. FLAC__uint32 *pu; /* unaligned pointer */
  86532. union { /* union needed to comply with C99 pointer aliasing rules */
  86533. FLAC__uint32 *pa; /* aligned pointer */
  86534. void *pv; /* aligned pointer alias */
  86535. } u;
  86536. FLAC__ASSERT(elements > 0);
  86537. FLAC__ASSERT(0 != unaligned_pointer);
  86538. FLAC__ASSERT(0 != aligned_pointer);
  86539. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86540. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86541. if(0 == pu) {
  86542. return false;
  86543. }
  86544. else {
  86545. if(*unaligned_pointer != 0)
  86546. free(*unaligned_pointer);
  86547. *unaligned_pointer = pu;
  86548. *aligned_pointer = u.pa;
  86549. return true;
  86550. }
  86551. }
  86552. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86553. {
  86554. FLAC__uint64 *pu; /* unaligned pointer */
  86555. union { /* union needed to comply with C99 pointer aliasing rules */
  86556. FLAC__uint64 *pa; /* aligned pointer */
  86557. void *pv; /* aligned pointer alias */
  86558. } u;
  86559. FLAC__ASSERT(elements > 0);
  86560. FLAC__ASSERT(0 != unaligned_pointer);
  86561. FLAC__ASSERT(0 != aligned_pointer);
  86562. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86563. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86564. if(0 == pu) {
  86565. return false;
  86566. }
  86567. else {
  86568. if(*unaligned_pointer != 0)
  86569. free(*unaligned_pointer);
  86570. *unaligned_pointer = pu;
  86571. *aligned_pointer = u.pa;
  86572. return true;
  86573. }
  86574. }
  86575. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86576. {
  86577. unsigned *pu; /* unaligned pointer */
  86578. union { /* union needed to comply with C99 pointer aliasing rules */
  86579. unsigned *pa; /* aligned pointer */
  86580. void *pv; /* aligned pointer alias */
  86581. } u;
  86582. FLAC__ASSERT(elements > 0);
  86583. FLAC__ASSERT(0 != unaligned_pointer);
  86584. FLAC__ASSERT(0 != aligned_pointer);
  86585. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86586. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86587. if(0 == pu) {
  86588. return false;
  86589. }
  86590. else {
  86591. if(*unaligned_pointer != 0)
  86592. free(*unaligned_pointer);
  86593. *unaligned_pointer = pu;
  86594. *aligned_pointer = u.pa;
  86595. return true;
  86596. }
  86597. }
  86598. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86599. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86600. {
  86601. FLAC__real *pu; /* unaligned pointer */
  86602. union { /* union needed to comply with C99 pointer aliasing rules */
  86603. FLAC__real *pa; /* aligned pointer */
  86604. void *pv; /* aligned pointer alias */
  86605. } u;
  86606. FLAC__ASSERT(elements > 0);
  86607. FLAC__ASSERT(0 != unaligned_pointer);
  86608. FLAC__ASSERT(0 != aligned_pointer);
  86609. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86610. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86611. if(0 == pu) {
  86612. return false;
  86613. }
  86614. else {
  86615. if(*unaligned_pointer != 0)
  86616. free(*unaligned_pointer);
  86617. *unaligned_pointer = pu;
  86618. *aligned_pointer = u.pa;
  86619. return true;
  86620. }
  86621. }
  86622. #endif
  86623. #endif
  86624. /*** End of inlined file: memory.c ***/
  86625. /*** Start of inlined file: stream_decoder.c ***/
  86626. /*** Start of inlined file: juce_FlacHeader.h ***/
  86627. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86628. // tasks..
  86629. #define VERSION "1.2.1"
  86630. #define FLAC__NO_DLL 1
  86631. #if JUCE_MSVC
  86632. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86633. #endif
  86634. #if JUCE_MAC
  86635. #define FLAC__SYS_DARWIN 1
  86636. #endif
  86637. /*** End of inlined file: juce_FlacHeader.h ***/
  86638. #if JUCE_USE_FLAC
  86639. #if HAVE_CONFIG_H
  86640. # include <config.h>
  86641. #endif
  86642. #if defined _MSC_VER || defined __MINGW32__
  86643. #include <io.h> /* for _setmode() */
  86644. #include <fcntl.h> /* for _O_BINARY */
  86645. #endif
  86646. #if defined __CYGWIN__ || defined __EMX__
  86647. #include <io.h> /* for setmode(), O_BINARY */
  86648. #include <fcntl.h> /* for _O_BINARY */
  86649. #endif
  86650. #include <stdio.h>
  86651. #include <stdlib.h> /* for malloc() */
  86652. #include <string.h> /* for memset/memcpy() */
  86653. #include <sys/stat.h> /* for stat() */
  86654. #include <sys/types.h> /* for off_t */
  86655. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86656. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86657. #define fseeko fseek
  86658. #define ftello ftell
  86659. #endif
  86660. #endif
  86661. /*** Start of inlined file: stream_decoder.h ***/
  86662. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86663. #define FLAC__PROTECTED__STREAM_DECODER_H
  86664. #if FLAC__HAS_OGG
  86665. #include "include/private/ogg_decoder_aspect.h"
  86666. #endif
  86667. typedef struct FLAC__StreamDecoderProtected {
  86668. FLAC__StreamDecoderState state;
  86669. unsigned channels;
  86670. FLAC__ChannelAssignment channel_assignment;
  86671. unsigned bits_per_sample;
  86672. unsigned sample_rate; /* in Hz */
  86673. unsigned blocksize; /* in samples (per channel) */
  86674. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86675. #if FLAC__HAS_OGG
  86676. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86677. #endif
  86678. } FLAC__StreamDecoderProtected;
  86679. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86680. #endif
  86681. /*** End of inlined file: stream_decoder.h ***/
  86682. #ifdef max
  86683. #undef max
  86684. #endif
  86685. #define max(a,b) ((a)>(b)?(a):(b))
  86686. #ifdef _MSC_VER
  86687. #define FLAC__U64L(x) x
  86688. #else
  86689. #define FLAC__U64L(x) x##LLU
  86690. #endif
  86691. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86692. #if FLAC__HAS_OGG
  86693. 1
  86694. #else
  86695. 0
  86696. #endif
  86697. ;
  86698. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86699. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86700. static FILE *get_binary_stdin_(void);
  86701. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86702. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86703. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86704. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86705. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86706. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86707. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86708. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86709. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86710. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86711. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86712. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86713. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86714. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86715. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86716. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86717. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86718. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86719. static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended);
  86720. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86721. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86722. #if FLAC__HAS_OGG
  86723. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86724. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86725. #endif
  86726. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86727. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86728. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86729. #if FLAC__HAS_OGG
  86730. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86731. #endif
  86732. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86733. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86734. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86735. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86736. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86737. typedef struct FLAC__StreamDecoderPrivate {
  86738. #if FLAC__HAS_OGG
  86739. FLAC__bool is_ogg;
  86740. #endif
  86741. FLAC__StreamDecoderReadCallback read_callback;
  86742. FLAC__StreamDecoderSeekCallback seek_callback;
  86743. FLAC__StreamDecoderTellCallback tell_callback;
  86744. FLAC__StreamDecoderLengthCallback length_callback;
  86745. FLAC__StreamDecoderEofCallback eof_callback;
  86746. FLAC__StreamDecoderWriteCallback write_callback;
  86747. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86748. FLAC__StreamDecoderErrorCallback error_callback;
  86749. void (*local_lpc_restore_signal)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  86750. void (*local_lpc_restore_signal_64bit)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  86751. void (*local_lpc_restore_signal_16bit)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  86752. void (*local_lpc_restore_signal_16bit_order8)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]);
  86753. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86754. void *client_data;
  86755. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86756. FLAC__BitReader *input;
  86757. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86758. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86759. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86760. unsigned output_capacity, output_channels;
  86761. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86762. FLAC__uint64 samples_decoded;
  86763. FLAC__bool has_stream_info, has_seek_table;
  86764. FLAC__StreamMetadata stream_info;
  86765. FLAC__StreamMetadata seek_table;
  86766. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86767. FLAC__byte *metadata_filter_ids;
  86768. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86769. FLAC__Frame frame;
  86770. FLAC__bool cached; /* true if there is a byte in lookahead */
  86771. FLAC__CPUInfo cpuinfo;
  86772. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86773. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86774. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86775. FLAC__bool do_md5_checking; /* initially gets protected_->md5_checking but is turned off after a seek or if the metadata has a zero MD5 */
  86776. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86777. FLAC__bool is_seeking;
  86778. FLAC__MD5Context md5context;
  86779. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86780. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86781. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86782. FLAC__uint64 target_sample;
  86783. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86784. #if FLAC__HAS_OGG
  86785. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86786. #endif
  86787. } FLAC__StreamDecoderPrivate;
  86788. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86789. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86790. "FLAC__STREAM_DECODER_READ_METADATA",
  86791. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86792. "FLAC__STREAM_DECODER_READ_FRAME",
  86793. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86794. "FLAC__STREAM_DECODER_OGG_ERROR",
  86795. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86796. "FLAC__STREAM_DECODER_ABORTED",
  86797. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86798. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86799. };
  86800. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86801. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86802. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86803. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86804. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86805. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86806. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86807. };
  86808. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86809. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86810. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86811. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86812. };
  86813. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  86814. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  86815. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  86816. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  86817. };
  86818. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  86819. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  86820. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  86821. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  86822. };
  86823. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  86824. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  86825. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  86826. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  86827. };
  86828. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  86829. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  86830. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  86831. };
  86832. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  86833. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  86834. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  86835. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  86836. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  86837. };
  86838. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  86839. {
  86840. FLAC__StreamDecoder *decoder;
  86841. unsigned i;
  86842. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  86843. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  86844. if(decoder == 0) {
  86845. return 0;
  86846. }
  86847. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  86848. if(decoder->protected_ == 0) {
  86849. free(decoder);
  86850. return 0;
  86851. }
  86852. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  86853. if(decoder->private_ == 0) {
  86854. free(decoder->protected_);
  86855. free(decoder);
  86856. return 0;
  86857. }
  86858. decoder->private_->input = FLAC__bitreader_new();
  86859. if(decoder->private_->input == 0) {
  86860. free(decoder->private_);
  86861. free(decoder->protected_);
  86862. free(decoder);
  86863. return 0;
  86864. }
  86865. decoder->private_->metadata_filter_ids_capacity = 16;
  86866. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  86867. FLAC__bitreader_delete(decoder->private_->input);
  86868. free(decoder->private_);
  86869. free(decoder->protected_);
  86870. free(decoder);
  86871. return 0;
  86872. }
  86873. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  86874. decoder->private_->output[i] = 0;
  86875. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  86876. }
  86877. decoder->private_->output_capacity = 0;
  86878. decoder->private_->output_channels = 0;
  86879. decoder->private_->has_seek_table = false;
  86880. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86881. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  86882. decoder->private_->file = 0;
  86883. set_defaults_dec(decoder);
  86884. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  86885. return decoder;
  86886. }
  86887. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  86888. {
  86889. unsigned i;
  86890. FLAC__ASSERT(0 != decoder);
  86891. FLAC__ASSERT(0 != decoder->protected_);
  86892. FLAC__ASSERT(0 != decoder->private_);
  86893. FLAC__ASSERT(0 != decoder->private_->input);
  86894. (void)FLAC__stream_decoder_finish(decoder);
  86895. if(0 != decoder->private_->metadata_filter_ids)
  86896. free(decoder->private_->metadata_filter_ids);
  86897. FLAC__bitreader_delete(decoder->private_->input);
  86898. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86899. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  86900. free(decoder->private_);
  86901. free(decoder->protected_);
  86902. free(decoder);
  86903. }
  86904. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  86905. FLAC__StreamDecoder *decoder,
  86906. FLAC__StreamDecoderReadCallback read_callback,
  86907. FLAC__StreamDecoderSeekCallback seek_callback,
  86908. FLAC__StreamDecoderTellCallback tell_callback,
  86909. FLAC__StreamDecoderLengthCallback length_callback,
  86910. FLAC__StreamDecoderEofCallback eof_callback,
  86911. FLAC__StreamDecoderWriteCallback write_callback,
  86912. FLAC__StreamDecoderMetadataCallback metadata_callback,
  86913. FLAC__StreamDecoderErrorCallback error_callback,
  86914. void *client_data,
  86915. FLAC__bool is_ogg
  86916. )
  86917. {
  86918. FLAC__ASSERT(0 != decoder);
  86919. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  86920. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  86921. #if !FLAC__HAS_OGG
  86922. if(is_ogg)
  86923. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  86924. #endif
  86925. if(
  86926. 0 == read_callback ||
  86927. 0 == write_callback ||
  86928. 0 == error_callback ||
  86929. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  86930. )
  86931. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  86932. #if FLAC__HAS_OGG
  86933. decoder->private_->is_ogg = is_ogg;
  86934. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  86935. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  86936. #endif
  86937. FLAC__cpu_info(&decoder->private_->cpuinfo);
  86938. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  86939. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  86940. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  86941. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  86942. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  86943. #ifndef FLAC__NO_ASM
  86944. if(decoder->private_->cpuinfo.use_asm) {
  86945. #ifdef FLAC__CPU_IA32
  86946. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  86947. #ifdef FLAC__HAS_NASM
  86948. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  86949. if(decoder->private_->cpuinfo.data.ia32.bswap)
  86950. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  86951. #endif
  86952. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  86953. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  86954. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  86955. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  86956. }
  86957. else {
  86958. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  86959. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  86960. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  86961. }
  86962. #endif
  86963. #elif defined FLAC__CPU_PPC
  86964. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  86965. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  86966. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  86967. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  86968. }
  86969. #endif
  86970. }
  86971. #endif
  86972. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  86973. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  86974. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  86975. }
  86976. decoder->private_->read_callback = read_callback;
  86977. decoder->private_->seek_callback = seek_callback;
  86978. decoder->private_->tell_callback = tell_callback;
  86979. decoder->private_->length_callback = length_callback;
  86980. decoder->private_->eof_callback = eof_callback;
  86981. decoder->private_->write_callback = write_callback;
  86982. decoder->private_->metadata_callback = metadata_callback;
  86983. decoder->private_->error_callback = error_callback;
  86984. decoder->private_->client_data = client_data;
  86985. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  86986. decoder->private_->samples_decoded = 0;
  86987. decoder->private_->has_stream_info = false;
  86988. decoder->private_->cached = false;
  86989. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  86990. decoder->private_->is_seeking = false;
  86991. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  86992. if(!FLAC__stream_decoder_reset(decoder)) {
  86993. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  86994. }
  86995. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  86996. }
  86997. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  86998. FLAC__StreamDecoder *decoder,
  86999. FLAC__StreamDecoderReadCallback read_callback,
  87000. FLAC__StreamDecoderSeekCallback seek_callback,
  87001. FLAC__StreamDecoderTellCallback tell_callback,
  87002. FLAC__StreamDecoderLengthCallback length_callback,
  87003. FLAC__StreamDecoderEofCallback eof_callback,
  87004. FLAC__StreamDecoderWriteCallback write_callback,
  87005. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87006. FLAC__StreamDecoderErrorCallback error_callback,
  87007. void *client_data
  87008. )
  87009. {
  87010. return init_stream_internal_dec(
  87011. decoder,
  87012. read_callback,
  87013. seek_callback,
  87014. tell_callback,
  87015. length_callback,
  87016. eof_callback,
  87017. write_callback,
  87018. metadata_callback,
  87019. error_callback,
  87020. client_data,
  87021. false
  87022. );
  87023. }
  87024. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87025. FLAC__StreamDecoder *decoder,
  87026. FLAC__StreamDecoderReadCallback read_callback,
  87027. FLAC__StreamDecoderSeekCallback seek_callback,
  87028. FLAC__StreamDecoderTellCallback tell_callback,
  87029. FLAC__StreamDecoderLengthCallback length_callback,
  87030. FLAC__StreamDecoderEofCallback eof_callback,
  87031. FLAC__StreamDecoderWriteCallback write_callback,
  87032. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87033. FLAC__StreamDecoderErrorCallback error_callback,
  87034. void *client_data
  87035. )
  87036. {
  87037. return init_stream_internal_dec(
  87038. decoder,
  87039. read_callback,
  87040. seek_callback,
  87041. tell_callback,
  87042. length_callback,
  87043. eof_callback,
  87044. write_callback,
  87045. metadata_callback,
  87046. error_callback,
  87047. client_data,
  87048. true
  87049. );
  87050. }
  87051. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87052. FLAC__StreamDecoder *decoder,
  87053. FILE *file,
  87054. FLAC__StreamDecoderWriteCallback write_callback,
  87055. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87056. FLAC__StreamDecoderErrorCallback error_callback,
  87057. void *client_data,
  87058. FLAC__bool is_ogg
  87059. )
  87060. {
  87061. FLAC__ASSERT(0 != decoder);
  87062. FLAC__ASSERT(0 != file);
  87063. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87064. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87065. if(0 == write_callback || 0 == error_callback)
  87066. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87067. if(file == stdin)
  87068. file = get_binary_stdin_(); /* just to be safe */
  87069. decoder->private_->file = file;
  87070. return init_stream_internal_dec(
  87071. decoder,
  87072. file_read_callback_dec,
  87073. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87074. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87075. decoder->private_->file == stdin? 0: file_length_callback_,
  87076. file_eof_callback_,
  87077. write_callback,
  87078. metadata_callback,
  87079. error_callback,
  87080. client_data,
  87081. is_ogg
  87082. );
  87083. }
  87084. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87085. FLAC__StreamDecoder *decoder,
  87086. FILE *file,
  87087. FLAC__StreamDecoderWriteCallback write_callback,
  87088. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87089. FLAC__StreamDecoderErrorCallback error_callback,
  87090. void *client_data
  87091. )
  87092. {
  87093. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87094. }
  87095. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87096. FLAC__StreamDecoder *decoder,
  87097. FILE *file,
  87098. FLAC__StreamDecoderWriteCallback write_callback,
  87099. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87100. FLAC__StreamDecoderErrorCallback error_callback,
  87101. void *client_data
  87102. )
  87103. {
  87104. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87105. }
  87106. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87107. FLAC__StreamDecoder *decoder,
  87108. const char *filename,
  87109. FLAC__StreamDecoderWriteCallback write_callback,
  87110. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87111. FLAC__StreamDecoderErrorCallback error_callback,
  87112. void *client_data,
  87113. FLAC__bool is_ogg
  87114. )
  87115. {
  87116. FILE *file;
  87117. FLAC__ASSERT(0 != decoder);
  87118. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87119. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87120. if(0 == write_callback || 0 == error_callback)
  87121. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87122. file = filename? fopen(filename, "rb") : stdin;
  87123. if(0 == file)
  87124. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87125. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87126. }
  87127. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87128. FLAC__StreamDecoder *decoder,
  87129. const char *filename,
  87130. FLAC__StreamDecoderWriteCallback write_callback,
  87131. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87132. FLAC__StreamDecoderErrorCallback error_callback,
  87133. void *client_data
  87134. )
  87135. {
  87136. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87137. }
  87138. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87139. FLAC__StreamDecoder *decoder,
  87140. const char *filename,
  87141. FLAC__StreamDecoderWriteCallback write_callback,
  87142. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87143. FLAC__StreamDecoderErrorCallback error_callback,
  87144. void *client_data
  87145. )
  87146. {
  87147. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87148. }
  87149. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87150. {
  87151. FLAC__bool md5_failed = false;
  87152. unsigned i;
  87153. FLAC__ASSERT(0 != decoder);
  87154. FLAC__ASSERT(0 != decoder->private_);
  87155. FLAC__ASSERT(0 != decoder->protected_);
  87156. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87157. return true;
  87158. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87159. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87160. free(decoder->private_->seek_table.data.seek_table.points);
  87161. decoder->private_->seek_table.data.seek_table.points = 0;
  87162. decoder->private_->has_seek_table = false;
  87163. }
  87164. FLAC__bitreader_free(decoder->private_->input);
  87165. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87166. if(0 != decoder->private_->output[i]) {
  87167. free(decoder->private_->output[i]-4);
  87168. decoder->private_->output[i] = 0;
  87169. }
  87170. if(0 != decoder->private_->residual_unaligned[i]) {
  87171. free(decoder->private_->residual_unaligned[i]);
  87172. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87173. }
  87174. }
  87175. decoder->private_->output_capacity = 0;
  87176. decoder->private_->output_channels = 0;
  87177. #if FLAC__HAS_OGG
  87178. if(decoder->private_->is_ogg)
  87179. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87180. #endif
  87181. if(0 != decoder->private_->file) {
  87182. if(decoder->private_->file != stdin)
  87183. fclose(decoder->private_->file);
  87184. decoder->private_->file = 0;
  87185. }
  87186. if(decoder->private_->do_md5_checking) {
  87187. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87188. md5_failed = true;
  87189. }
  87190. decoder->private_->is_seeking = false;
  87191. set_defaults_dec(decoder);
  87192. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87193. return !md5_failed;
  87194. }
  87195. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87196. {
  87197. FLAC__ASSERT(0 != decoder);
  87198. FLAC__ASSERT(0 != decoder->private_);
  87199. FLAC__ASSERT(0 != decoder->protected_);
  87200. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87201. return false;
  87202. #if FLAC__HAS_OGG
  87203. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87204. return true;
  87205. #else
  87206. (void)value;
  87207. return false;
  87208. #endif
  87209. }
  87210. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87211. {
  87212. FLAC__ASSERT(0 != decoder);
  87213. FLAC__ASSERT(0 != decoder->protected_);
  87214. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87215. return false;
  87216. decoder->protected_->md5_checking = value;
  87217. return true;
  87218. }
  87219. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87220. {
  87221. FLAC__ASSERT(0 != decoder);
  87222. FLAC__ASSERT(0 != decoder->private_);
  87223. FLAC__ASSERT(0 != decoder->protected_);
  87224. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87225. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87226. return false;
  87227. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87228. return false;
  87229. decoder->private_->metadata_filter[type] = true;
  87230. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87231. decoder->private_->metadata_filter_ids_count = 0;
  87232. return true;
  87233. }
  87234. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87235. {
  87236. FLAC__ASSERT(0 != decoder);
  87237. FLAC__ASSERT(0 != decoder->private_);
  87238. FLAC__ASSERT(0 != decoder->protected_);
  87239. FLAC__ASSERT(0 != id);
  87240. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87241. return false;
  87242. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87243. return true;
  87244. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87245. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87246. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) {
  87247. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87248. return false;
  87249. }
  87250. decoder->private_->metadata_filter_ids_capacity *= 2;
  87251. }
  87252. memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metadata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8));
  87253. decoder->private_->metadata_filter_ids_count++;
  87254. return true;
  87255. }
  87256. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87257. {
  87258. unsigned i;
  87259. FLAC__ASSERT(0 != decoder);
  87260. FLAC__ASSERT(0 != decoder->private_);
  87261. FLAC__ASSERT(0 != decoder->protected_);
  87262. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87263. return false;
  87264. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87265. decoder->private_->metadata_filter[i] = true;
  87266. decoder->private_->metadata_filter_ids_count = 0;
  87267. return true;
  87268. }
  87269. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87270. {
  87271. FLAC__ASSERT(0 != decoder);
  87272. FLAC__ASSERT(0 != decoder->private_);
  87273. FLAC__ASSERT(0 != decoder->protected_);
  87274. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87275. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87276. return false;
  87277. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87278. return false;
  87279. decoder->private_->metadata_filter[type] = false;
  87280. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87281. decoder->private_->metadata_filter_ids_count = 0;
  87282. return true;
  87283. }
  87284. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87285. {
  87286. FLAC__ASSERT(0 != decoder);
  87287. FLAC__ASSERT(0 != decoder->private_);
  87288. FLAC__ASSERT(0 != decoder->protected_);
  87289. FLAC__ASSERT(0 != id);
  87290. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87291. return false;
  87292. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87293. return true;
  87294. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87295. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87296. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)safe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filter_ids_capacity, /*times*/2))) {
  87297. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87298. return false;
  87299. }
  87300. decoder->private_->metadata_filter_ids_capacity *= 2;
  87301. }
  87302. memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metadata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8));
  87303. decoder->private_->metadata_filter_ids_count++;
  87304. return true;
  87305. }
  87306. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87307. {
  87308. FLAC__ASSERT(0 != decoder);
  87309. FLAC__ASSERT(0 != decoder->private_);
  87310. FLAC__ASSERT(0 != decoder->protected_);
  87311. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87312. return false;
  87313. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87314. decoder->private_->metadata_filter_ids_count = 0;
  87315. return true;
  87316. }
  87317. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87318. {
  87319. FLAC__ASSERT(0 != decoder);
  87320. FLAC__ASSERT(0 != decoder->protected_);
  87321. return decoder->protected_->state;
  87322. }
  87323. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87324. {
  87325. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87326. }
  87327. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87328. {
  87329. FLAC__ASSERT(0 != decoder);
  87330. FLAC__ASSERT(0 != decoder->protected_);
  87331. return decoder->protected_->md5_checking;
  87332. }
  87333. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87334. {
  87335. FLAC__ASSERT(0 != decoder);
  87336. FLAC__ASSERT(0 != decoder->protected_);
  87337. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87338. }
  87339. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87340. {
  87341. FLAC__ASSERT(0 != decoder);
  87342. FLAC__ASSERT(0 != decoder->protected_);
  87343. return decoder->protected_->channels;
  87344. }
  87345. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87346. {
  87347. FLAC__ASSERT(0 != decoder);
  87348. FLAC__ASSERT(0 != decoder->protected_);
  87349. return decoder->protected_->channel_assignment;
  87350. }
  87351. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87352. {
  87353. FLAC__ASSERT(0 != decoder);
  87354. FLAC__ASSERT(0 != decoder->protected_);
  87355. return decoder->protected_->bits_per_sample;
  87356. }
  87357. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87358. {
  87359. FLAC__ASSERT(0 != decoder);
  87360. FLAC__ASSERT(0 != decoder->protected_);
  87361. return decoder->protected_->sample_rate;
  87362. }
  87363. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87364. {
  87365. FLAC__ASSERT(0 != decoder);
  87366. FLAC__ASSERT(0 != decoder->protected_);
  87367. return decoder->protected_->blocksize;
  87368. }
  87369. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87370. {
  87371. FLAC__ASSERT(0 != decoder);
  87372. FLAC__ASSERT(0 != decoder->private_);
  87373. FLAC__ASSERT(0 != position);
  87374. #if FLAC__HAS_OGG
  87375. if(decoder->private_->is_ogg)
  87376. return false;
  87377. #endif
  87378. if(0 == decoder->private_->tell_callback)
  87379. return false;
  87380. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87381. return false;
  87382. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87383. return false;
  87384. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87385. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87386. return true;
  87387. }
  87388. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87389. {
  87390. FLAC__ASSERT(0 != decoder);
  87391. FLAC__ASSERT(0 != decoder->private_);
  87392. FLAC__ASSERT(0 != decoder->protected_);
  87393. decoder->private_->samples_decoded = 0;
  87394. decoder->private_->do_md5_checking = false;
  87395. #if FLAC__HAS_OGG
  87396. if(decoder->private_->is_ogg)
  87397. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87398. #endif
  87399. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87400. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87401. return false;
  87402. }
  87403. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87404. return true;
  87405. }
  87406. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87407. {
  87408. FLAC__ASSERT(0 != decoder);
  87409. FLAC__ASSERT(0 != decoder->private_);
  87410. FLAC__ASSERT(0 != decoder->protected_);
  87411. if(!FLAC__stream_decoder_flush(decoder)) {
  87412. return false;
  87413. }
  87414. #if FLAC__HAS_OGG
  87415. if(decoder->private_->is_ogg)
  87416. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87417. #endif
  87418. if(!decoder->private_->internal_reset_hack) {
  87419. if(decoder->private_->file == stdin)
  87420. return false; /* can't rewind stdin, reset fails */
  87421. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87422. return false; /* seekable and seek fails, reset fails */
  87423. }
  87424. else
  87425. decoder->private_->internal_reset_hack = false;
  87426. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87427. decoder->private_->has_stream_info = false;
  87428. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87429. free(decoder->private_->seek_table.data.seek_table.points);
  87430. decoder->private_->seek_table.data.seek_table.points = 0;
  87431. decoder->private_->has_seek_table = false;
  87432. }
  87433. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87434. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87435. FLAC__MD5Init(&decoder->private_->md5context);
  87436. decoder->private_->first_frame_offset = 0;
  87437. decoder->private_->unparseable_frame_count = 0;
  87438. return true;
  87439. }
  87440. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87441. {
  87442. FLAC__bool got_a_frame;
  87443. FLAC__ASSERT(0 != decoder);
  87444. FLAC__ASSERT(0 != decoder->protected_);
  87445. while(1) {
  87446. switch(decoder->protected_->state) {
  87447. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87448. if(!find_metadata_(decoder))
  87449. return false; /* above function sets the status for us */
  87450. break;
  87451. case FLAC__STREAM_DECODER_READ_METADATA:
  87452. if(!read_metadata_(decoder))
  87453. return false; /* above function sets the status for us */
  87454. else
  87455. return true;
  87456. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87457. if(!frame_sync_(decoder))
  87458. return true; /* above function sets the status for us */
  87459. break;
  87460. case FLAC__STREAM_DECODER_READ_FRAME:
  87461. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87462. return false; /* above function sets the status for us */
  87463. if(got_a_frame)
  87464. return true; /* above function sets the status for us */
  87465. break;
  87466. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87467. case FLAC__STREAM_DECODER_ABORTED:
  87468. return true;
  87469. default:
  87470. FLAC__ASSERT(0);
  87471. return false;
  87472. }
  87473. }
  87474. }
  87475. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87476. {
  87477. FLAC__ASSERT(0 != decoder);
  87478. FLAC__ASSERT(0 != decoder->protected_);
  87479. while(1) {
  87480. switch(decoder->protected_->state) {
  87481. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87482. if(!find_metadata_(decoder))
  87483. return false; /* above function sets the status for us */
  87484. break;
  87485. case FLAC__STREAM_DECODER_READ_METADATA:
  87486. if(!read_metadata_(decoder))
  87487. return false; /* above function sets the status for us */
  87488. break;
  87489. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87490. case FLAC__STREAM_DECODER_READ_FRAME:
  87491. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87492. case FLAC__STREAM_DECODER_ABORTED:
  87493. return true;
  87494. default:
  87495. FLAC__ASSERT(0);
  87496. return false;
  87497. }
  87498. }
  87499. }
  87500. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87501. {
  87502. FLAC__bool dummy;
  87503. FLAC__ASSERT(0 != decoder);
  87504. FLAC__ASSERT(0 != decoder->protected_);
  87505. while(1) {
  87506. switch(decoder->protected_->state) {
  87507. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87508. if(!find_metadata_(decoder))
  87509. return false; /* above function sets the status for us */
  87510. break;
  87511. case FLAC__STREAM_DECODER_READ_METADATA:
  87512. if(!read_metadata_(decoder))
  87513. return false; /* above function sets the status for us */
  87514. break;
  87515. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87516. if(!frame_sync_(decoder))
  87517. return true; /* above function sets the status for us */
  87518. break;
  87519. case FLAC__STREAM_DECODER_READ_FRAME:
  87520. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87521. return false; /* above function sets the status for us */
  87522. break;
  87523. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87524. case FLAC__STREAM_DECODER_ABORTED:
  87525. return true;
  87526. default:
  87527. FLAC__ASSERT(0);
  87528. return false;
  87529. }
  87530. }
  87531. }
  87532. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87533. {
  87534. FLAC__bool got_a_frame;
  87535. FLAC__ASSERT(0 != decoder);
  87536. FLAC__ASSERT(0 != decoder->protected_);
  87537. while(1) {
  87538. switch(decoder->protected_->state) {
  87539. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87540. case FLAC__STREAM_DECODER_READ_METADATA:
  87541. return false; /* above function sets the status for us */
  87542. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87543. if(!frame_sync_(decoder))
  87544. return true; /* above function sets the status for us */
  87545. break;
  87546. case FLAC__STREAM_DECODER_READ_FRAME:
  87547. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87548. return false; /* above function sets the status for us */
  87549. if(got_a_frame)
  87550. return true; /* above function sets the status for us */
  87551. break;
  87552. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87553. case FLAC__STREAM_DECODER_ABORTED:
  87554. return true;
  87555. default:
  87556. FLAC__ASSERT(0);
  87557. return false;
  87558. }
  87559. }
  87560. }
  87561. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87562. {
  87563. FLAC__uint64 length;
  87564. FLAC__ASSERT(0 != decoder);
  87565. if(
  87566. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87567. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87568. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87569. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87570. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87571. )
  87572. return false;
  87573. if(0 == decoder->private_->seek_callback)
  87574. return false;
  87575. FLAC__ASSERT(decoder->private_->seek_callback);
  87576. FLAC__ASSERT(decoder->private_->tell_callback);
  87577. FLAC__ASSERT(decoder->private_->length_callback);
  87578. FLAC__ASSERT(decoder->private_->eof_callback);
  87579. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87580. return false;
  87581. decoder->private_->is_seeking = true;
  87582. decoder->private_->do_md5_checking = false;
  87583. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87584. decoder->private_->is_seeking = false;
  87585. return false;
  87586. }
  87587. if(
  87588. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87589. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87590. ) {
  87591. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87592. decoder->private_->is_seeking = false;
  87593. return false;
  87594. }
  87595. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87596. decoder->private_->is_seeking = false;
  87597. return false;
  87598. }
  87599. }
  87600. {
  87601. const FLAC__bool ok =
  87602. #if FLAC__HAS_OGG
  87603. decoder->private_->is_ogg?
  87604. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87605. #endif
  87606. seek_to_absolute_sample_(decoder, length, sample)
  87607. ;
  87608. decoder->private_->is_seeking = false;
  87609. return ok;
  87610. }
  87611. }
  87612. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87613. {
  87614. FLAC__ASSERT(0 != decoder);
  87615. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87616. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87617. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87618. }
  87619. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87620. {
  87621. #if FLAC__HAS_OGG
  87622. decoder->private_->is_ogg = false;
  87623. #endif
  87624. decoder->private_->read_callback = 0;
  87625. decoder->private_->seek_callback = 0;
  87626. decoder->private_->tell_callback = 0;
  87627. decoder->private_->length_callback = 0;
  87628. decoder->private_->eof_callback = 0;
  87629. decoder->private_->write_callback = 0;
  87630. decoder->private_->metadata_callback = 0;
  87631. decoder->private_->error_callback = 0;
  87632. decoder->private_->client_data = 0;
  87633. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87634. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87635. decoder->private_->metadata_filter_ids_count = 0;
  87636. decoder->protected_->md5_checking = false;
  87637. #if FLAC__HAS_OGG
  87638. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87639. #endif
  87640. }
  87641. FILE *get_binary_stdin_(void)
  87642. {
  87643. #if defined _MSC_VER || defined __MINGW32__
  87644. _setmode(_fileno(stdin), _O_BINARY);
  87645. #elif defined __CYGWIN__
  87646. setmode(_fileno(stdin), _O_BINARY);
  87647. #elif defined __EMX__
  87648. setmode(fileno(stdin), O_BINARY);
  87649. #endif
  87650. return stdin;
  87651. }
  87652. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87653. {
  87654. unsigned i;
  87655. FLAC__int32 *tmp;
  87656. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87657. return true;
  87658. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87659. if(0 != decoder->private_->output[i]) {
  87660. free(decoder->private_->output[i]-4);
  87661. decoder->private_->output[i] = 0;
  87662. }
  87663. if(0 != decoder->private_->residual_unaligned[i]) {
  87664. free(decoder->private_->residual_unaligned[i]);
  87665. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87666. }
  87667. }
  87668. for(i = 0; i < channels; i++) {
  87669. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87670. if(tmp == 0) {
  87671. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87672. return false;
  87673. }
  87674. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87675. decoder->private_->output[i] = tmp + 4;
  87676. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87677. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87678. return false;
  87679. }
  87680. }
  87681. decoder->private_->output_capacity = size;
  87682. decoder->private_->output_channels = channels;
  87683. return true;
  87684. }
  87685. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87686. {
  87687. size_t i;
  87688. FLAC__ASSERT(0 != decoder);
  87689. FLAC__ASSERT(0 != decoder->private_);
  87690. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87691. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87692. return true;
  87693. return false;
  87694. }
  87695. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87696. {
  87697. FLAC__uint32 x;
  87698. unsigned i, id_;
  87699. FLAC__bool first = true;
  87700. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87701. for(i = id_ = 0; i < 4; ) {
  87702. if(decoder->private_->cached) {
  87703. x = (FLAC__uint32)decoder->private_->lookahead;
  87704. decoder->private_->cached = false;
  87705. }
  87706. else {
  87707. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87708. return false; /* read_callback_ sets the state for us */
  87709. }
  87710. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87711. first = true;
  87712. i++;
  87713. id_ = 0;
  87714. continue;
  87715. }
  87716. if(x == ID3V2_TAG_[id_]) {
  87717. id_++;
  87718. i = 0;
  87719. if(id_ == 3) {
  87720. if(!skip_id3v2_tag_(decoder))
  87721. return false; /* skip_id3v2_tag_ sets the state for us */
  87722. }
  87723. continue;
  87724. }
  87725. id_ = 0;
  87726. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87727. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87728. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87729. return false; /* read_callback_ sets the state for us */
  87730. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87731. decoder->private_->lookahead = (FLAC__byte)x;
  87732. decoder->private_->cached = true;
  87733. }
  87734. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87735. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87736. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87737. return true;
  87738. }
  87739. }
  87740. i = 0;
  87741. if(first) {
  87742. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87743. first = false;
  87744. }
  87745. }
  87746. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87747. return true;
  87748. }
  87749. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87750. {
  87751. FLAC__bool is_last;
  87752. FLAC__uint32 i, x, type, length;
  87753. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87754. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87755. return false; /* read_callback_ sets the state for us */
  87756. is_last = x? true : false;
  87757. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87758. return false; /* read_callback_ sets the state for us */
  87759. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87760. return false; /* read_callback_ sets the state for us */
  87761. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87762. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87763. return false;
  87764. decoder->private_->has_stream_info = true;
  87765. if(0 == memcmp(decoder->private_->stream_info.data.stream_info.md5sum, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16))
  87766. decoder->private_->do_md5_checking = false;
  87767. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87768. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87769. }
  87770. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87771. if(!read_metadata_seektable_(decoder, is_last, length))
  87772. return false;
  87773. decoder->private_->has_seek_table = true;
  87774. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87775. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87776. }
  87777. else {
  87778. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87779. unsigned real_length = length;
  87780. FLAC__StreamMetadata block;
  87781. block.is_last = is_last;
  87782. block.type = (FLAC__MetadataType)type;
  87783. block.length = length;
  87784. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87785. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87786. return false; /* read_callback_ sets the state for us */
  87787. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87788. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87789. return false;
  87790. }
  87791. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87792. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87793. skip_it = !skip_it;
  87794. }
  87795. if(skip_it) {
  87796. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87797. return false; /* read_callback_ sets the state for us */
  87798. }
  87799. else {
  87800. switch(type) {
  87801. case FLAC__METADATA_TYPE_PADDING:
  87802. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87803. return false; /* read_callback_ sets the state for us */
  87804. break;
  87805. case FLAC__METADATA_TYPE_APPLICATION:
  87806. if(real_length > 0) {
  87807. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87808. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87809. return false;
  87810. }
  87811. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87812. return false; /* read_callback_ sets the state for us */
  87813. }
  87814. else
  87815. block.data.application.data = 0;
  87816. break;
  87817. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87818. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  87819. return false;
  87820. break;
  87821. case FLAC__METADATA_TYPE_CUESHEET:
  87822. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  87823. return false;
  87824. break;
  87825. case FLAC__METADATA_TYPE_PICTURE:
  87826. if(!read_metadata_picture_(decoder, &block.data.picture))
  87827. return false;
  87828. break;
  87829. case FLAC__METADATA_TYPE_STREAMINFO:
  87830. case FLAC__METADATA_TYPE_SEEKTABLE:
  87831. FLAC__ASSERT(0);
  87832. break;
  87833. default:
  87834. if(real_length > 0) {
  87835. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  87836. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87837. return false;
  87838. }
  87839. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  87840. return false; /* read_callback_ sets the state for us */
  87841. }
  87842. else
  87843. block.data.unknown.data = 0;
  87844. break;
  87845. }
  87846. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  87847. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  87848. switch(type) {
  87849. case FLAC__METADATA_TYPE_PADDING:
  87850. break;
  87851. case FLAC__METADATA_TYPE_APPLICATION:
  87852. if(0 != block.data.application.data)
  87853. free(block.data.application.data);
  87854. break;
  87855. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87856. if(0 != block.data.vorbis_comment.vendor_string.entry)
  87857. free(block.data.vorbis_comment.vendor_string.entry);
  87858. if(block.data.vorbis_comment.num_comments > 0)
  87859. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  87860. if(0 != block.data.vorbis_comment.comments[i].entry)
  87861. free(block.data.vorbis_comment.comments[i].entry);
  87862. if(0 != block.data.vorbis_comment.comments)
  87863. free(block.data.vorbis_comment.comments);
  87864. break;
  87865. case FLAC__METADATA_TYPE_CUESHEET:
  87866. if(block.data.cue_sheet.num_tracks > 0)
  87867. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  87868. if(0 != block.data.cue_sheet.tracks[i].indices)
  87869. free(block.data.cue_sheet.tracks[i].indices);
  87870. if(0 != block.data.cue_sheet.tracks)
  87871. free(block.data.cue_sheet.tracks);
  87872. break;
  87873. case FLAC__METADATA_TYPE_PICTURE:
  87874. if(0 != block.data.picture.mime_type)
  87875. free(block.data.picture.mime_type);
  87876. if(0 != block.data.picture.description)
  87877. free(block.data.picture.description);
  87878. if(0 != block.data.picture.data)
  87879. free(block.data.picture.data);
  87880. break;
  87881. case FLAC__METADATA_TYPE_STREAMINFO:
  87882. case FLAC__METADATA_TYPE_SEEKTABLE:
  87883. FLAC__ASSERT(0);
  87884. default:
  87885. if(0 != block.data.unknown.data)
  87886. free(block.data.unknown.data);
  87887. break;
  87888. }
  87889. }
  87890. }
  87891. if(is_last) {
  87892. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  87893. decoder->private_->first_frame_offset = 0;
  87894. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87895. }
  87896. return true;
  87897. }
  87898. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  87899. {
  87900. FLAC__uint32 x;
  87901. unsigned bits, used_bits = 0;
  87902. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87903. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  87904. decoder->private_->stream_info.is_last = is_last;
  87905. decoder->private_->stream_info.length = length;
  87906. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  87907. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  87908. return false; /* read_callback_ sets the state for us */
  87909. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  87910. used_bits += bits;
  87911. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  87912. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  87913. return false; /* read_callback_ sets the state for us */
  87914. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  87915. used_bits += bits;
  87916. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  87917. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  87918. return false; /* read_callback_ sets the state for us */
  87919. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  87920. used_bits += bits;
  87921. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  87922. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  87923. return false; /* read_callback_ sets the state for us */
  87924. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  87925. used_bits += bits;
  87926. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  87927. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  87928. return false; /* read_callback_ sets the state for us */
  87929. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  87930. used_bits += bits;
  87931. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  87932. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  87933. return false; /* read_callback_ sets the state for us */
  87934. decoder->private_->stream_info.data.stream_info.channels = x+1;
  87935. used_bits += bits;
  87936. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  87937. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  87938. return false; /* read_callback_ sets the state for us */
  87939. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  87940. used_bits += bits;
  87941. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  87942. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &decoder->private_->stream_info.data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  87943. return false; /* read_callback_ sets the state for us */
  87944. used_bits += bits;
  87945. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  87946. return false; /* read_callback_ sets the state for us */
  87947. used_bits += 16*8;
  87948. FLAC__ASSERT(used_bits % 8 == 0);
  87949. length -= (used_bits / 8);
  87950. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  87951. return false; /* read_callback_ sets the state for us */
  87952. return true;
  87953. }
  87954. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  87955. {
  87956. FLAC__uint32 i, x;
  87957. FLAC__uint64 xx;
  87958. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87959. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  87960. decoder->private_->seek_table.is_last = is_last;
  87961. decoder->private_->seek_table.length = length;
  87962. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  87963. if(0 == (decoder->private_->seek_table.data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)safe_realloc_mul_2op_(decoder->private_->seek_table.data.seek_table.points, decoder->private_->seek_table.data.seek_table.num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) {
  87964. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87965. return false;
  87966. }
  87967. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  87968. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  87969. return false; /* read_callback_ sets the state for us */
  87970. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  87971. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  87972. return false; /* read_callback_ sets the state for us */
  87973. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  87974. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  87975. return false; /* read_callback_ sets the state for us */
  87976. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  87977. }
  87978. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  87979. if(length > 0) {
  87980. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  87981. return false; /* read_callback_ sets the state for us */
  87982. }
  87983. return true;
  87984. }
  87985. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  87986. {
  87987. FLAC__uint32 i;
  87988. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87989. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  87990. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  87991. return false; /* read_callback_ sets the state for us */
  87992. if(obj->vendor_string.length > 0) {
  87993. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  87994. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87995. return false;
  87996. }
  87997. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  87998. return false; /* read_callback_ sets the state for us */
  87999. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88000. }
  88001. else
  88002. obj->vendor_string.entry = 0;
  88003. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88004. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88005. return false; /* read_callback_ sets the state for us */
  88006. if(obj->num_comments > 0) {
  88007. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88008. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88009. return false;
  88010. }
  88011. for(i = 0; i < obj->num_comments; i++) {
  88012. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88013. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88014. return false; /* read_callback_ sets the state for us */
  88015. if(obj->comments[i].length > 0) {
  88016. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88017. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88018. return false;
  88019. }
  88020. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88021. return false; /* read_callback_ sets the state for us */
  88022. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88023. }
  88024. else
  88025. obj->comments[i].entry = 0;
  88026. }
  88027. }
  88028. else {
  88029. obj->comments = 0;
  88030. }
  88031. return true;
  88032. }
  88033. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88034. {
  88035. FLAC__uint32 i, j, x;
  88036. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88037. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88038. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88039. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8))
  88040. return false; /* read_callback_ sets the state for us */
  88041. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88042. return false; /* read_callback_ sets the state for us */
  88043. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88044. return false; /* read_callback_ sets the state for us */
  88045. obj->is_cd = x? true : false;
  88046. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88047. return false; /* read_callback_ sets the state for us */
  88048. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88049. return false; /* read_callback_ sets the state for us */
  88050. obj->num_tracks = x;
  88051. if(obj->num_tracks > 0) {
  88052. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88053. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88054. return false;
  88055. }
  88056. for(i = 0; i < obj->num_tracks; i++) {
  88057. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88058. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88059. return false; /* read_callback_ sets the state for us */
  88060. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88061. return false; /* read_callback_ sets the state for us */
  88062. track->number = (FLAC__byte)x;
  88063. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88064. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88065. return false; /* read_callback_ sets the state for us */
  88066. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88067. return false; /* read_callback_ sets the state for us */
  88068. track->type = x;
  88069. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88070. return false; /* read_callback_ sets the state for us */
  88071. track->pre_emphasis = x;
  88072. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88073. return false; /* read_callback_ sets the state for us */
  88074. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88075. return false; /* read_callback_ sets the state for us */
  88076. track->num_indices = (FLAC__byte)x;
  88077. if(track->num_indices > 0) {
  88078. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88079. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88080. return false;
  88081. }
  88082. for(j = 0; j < track->num_indices; j++) {
  88083. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88084. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88085. return false; /* read_callback_ sets the state for us */
  88086. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88087. return false; /* read_callback_ sets the state for us */
  88088. index->number = (FLAC__byte)x;
  88089. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88090. return false; /* read_callback_ sets the state for us */
  88091. }
  88092. }
  88093. }
  88094. }
  88095. return true;
  88096. }
  88097. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88098. {
  88099. FLAC__uint32 x;
  88100. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88101. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88102. return false; /* read_callback_ sets the state for us */
  88103. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88104. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88105. return false; /* read_callback_ sets the state for us */
  88106. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88107. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88108. return false;
  88109. }
  88110. if(x > 0) {
  88111. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88112. return false; /* read_callback_ sets the state for us */
  88113. }
  88114. obj->mime_type[x] = '\0';
  88115. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88116. return false; /* read_callback_ sets the state for us */
  88117. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88118. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88119. return false;
  88120. }
  88121. if(x > 0) {
  88122. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88123. return false; /* read_callback_ sets the state for us */
  88124. }
  88125. obj->description[x] = '\0';
  88126. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88127. return false; /* read_callback_ sets the state for us */
  88128. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88129. return false; /* read_callback_ sets the state for us */
  88130. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88131. return false; /* read_callback_ sets the state for us */
  88132. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88133. return false; /* read_callback_ sets the state for us */
  88134. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88135. return false; /* read_callback_ sets the state for us */
  88136. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88137. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88138. return false;
  88139. }
  88140. if(obj->data_length > 0) {
  88141. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88142. return false; /* read_callback_ sets the state for us */
  88143. }
  88144. return true;
  88145. }
  88146. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88147. {
  88148. FLAC__uint32 x;
  88149. unsigned i, skip;
  88150. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88151. return false; /* read_callback_ sets the state for us */
  88152. skip = 0;
  88153. for(i = 0; i < 4; i++) {
  88154. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88155. return false; /* read_callback_ sets the state for us */
  88156. skip <<= 7;
  88157. skip |= (x & 0x7f);
  88158. }
  88159. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88160. return false; /* read_callback_ sets the state for us */
  88161. return true;
  88162. }
  88163. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88164. {
  88165. FLAC__uint32 x;
  88166. FLAC__bool first = true;
  88167. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88168. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88169. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88170. return true;
  88171. }
  88172. }
  88173. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88174. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88175. return false; /* read_callback_ sets the state for us */
  88176. }
  88177. while(1) {
  88178. if(decoder->private_->cached) {
  88179. x = (FLAC__uint32)decoder->private_->lookahead;
  88180. decoder->private_->cached = false;
  88181. }
  88182. else {
  88183. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88184. return false; /* read_callback_ sets the state for us */
  88185. }
  88186. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88187. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88188. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88189. return false; /* read_callback_ sets the state for us */
  88190. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88191. decoder->private_->lookahead = (FLAC__byte)x;
  88192. decoder->private_->cached = true;
  88193. }
  88194. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88195. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88196. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88197. return true;
  88198. }
  88199. }
  88200. if(first) {
  88201. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88202. first = false;
  88203. }
  88204. }
  88205. return true;
  88206. }
  88207. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88208. {
  88209. unsigned channel;
  88210. unsigned i;
  88211. FLAC__int32 mid, side;
  88212. unsigned frame_crc; /* the one we calculate from the input stream */
  88213. FLAC__uint32 x;
  88214. *got_a_frame = false;
  88215. frame_crc = 0;
  88216. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88217. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88218. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88219. if(!read_frame_header_(decoder))
  88220. return false;
  88221. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88222. return true;
  88223. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88224. return false;
  88225. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88226. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88227. switch(decoder->private_->frame.header.channel_assignment) {
  88228. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88229. break;
  88230. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88231. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88232. if(channel == 1)
  88233. bps++;
  88234. break;
  88235. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88236. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88237. if(channel == 0)
  88238. bps++;
  88239. break;
  88240. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88241. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88242. if(channel == 1)
  88243. bps++;
  88244. break;
  88245. default:
  88246. FLAC__ASSERT(0);
  88247. }
  88248. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88249. return false;
  88250. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88251. return true;
  88252. }
  88253. if(!read_zero_padding_(decoder))
  88254. return false;
  88255. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption (i.e. "zero bits" were not all zeroes) */
  88256. return true;
  88257. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88258. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88259. return false; /* read_callback_ sets the state for us */
  88260. if(frame_crc == x) {
  88261. if(do_full_decode) {
  88262. switch(decoder->private_->frame.header.channel_assignment) {
  88263. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88264. break;
  88265. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88266. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88267. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88268. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88269. break;
  88270. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88271. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88272. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88273. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88274. break;
  88275. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88276. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88277. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88278. #if 1
  88279. mid = decoder->private_->output[0][i];
  88280. side = decoder->private_->output[1][i];
  88281. mid <<= 1;
  88282. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88283. decoder->private_->output[0][i] = (mid + side) >> 1;
  88284. decoder->private_->output[1][i] = (mid - side) >> 1;
  88285. #else
  88286. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88287. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88288. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88289. #endif
  88290. }
  88291. break;
  88292. default:
  88293. FLAC__ASSERT(0);
  88294. break;
  88295. }
  88296. }
  88297. }
  88298. else {
  88299. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88300. if(do_full_decode) {
  88301. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88302. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88303. }
  88304. }
  88305. }
  88306. *got_a_frame = true;
  88307. if(decoder->private_->next_fixed_block_size)
  88308. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88309. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88310. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88311. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88312. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88313. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88314. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88315. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88316. if(do_full_decode) {
  88317. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88318. return false;
  88319. }
  88320. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88321. return true;
  88322. }
  88323. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88324. {
  88325. FLAC__uint32 x;
  88326. FLAC__uint64 xx;
  88327. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88328. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88329. unsigned raw_header_len;
  88330. FLAC__bool is_unparseable = false;
  88331. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88332. raw_header[0] = decoder->private_->header_warmup[0];
  88333. raw_header[1] = decoder->private_->header_warmup[1];
  88334. raw_header_len = 2;
  88335. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88336. is_unparseable = true;
  88337. for(i = 0; i < 2; i++) {
  88338. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88339. return false; /* read_callback_ sets the state for us */
  88340. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88341. decoder->private_->lookahead = (FLAC__byte)x;
  88342. decoder->private_->cached = true;
  88343. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88344. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88345. return true;
  88346. }
  88347. raw_header[raw_header_len++] = (FLAC__byte)x;
  88348. }
  88349. switch(x = raw_header[2] >> 4) {
  88350. case 0:
  88351. is_unparseable = true;
  88352. break;
  88353. case 1:
  88354. decoder->private_->frame.header.blocksize = 192;
  88355. break;
  88356. case 2:
  88357. case 3:
  88358. case 4:
  88359. case 5:
  88360. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88361. break;
  88362. case 6:
  88363. case 7:
  88364. blocksize_hint = x;
  88365. break;
  88366. case 8:
  88367. case 9:
  88368. case 10:
  88369. case 11:
  88370. case 12:
  88371. case 13:
  88372. case 14:
  88373. case 15:
  88374. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88375. break;
  88376. default:
  88377. FLAC__ASSERT(0);
  88378. break;
  88379. }
  88380. switch(x = raw_header[2] & 0x0f) {
  88381. case 0:
  88382. if(decoder->private_->has_stream_info)
  88383. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88384. else
  88385. is_unparseable = true;
  88386. break;
  88387. case 1:
  88388. decoder->private_->frame.header.sample_rate = 88200;
  88389. break;
  88390. case 2:
  88391. decoder->private_->frame.header.sample_rate = 176400;
  88392. break;
  88393. case 3:
  88394. decoder->private_->frame.header.sample_rate = 192000;
  88395. break;
  88396. case 4:
  88397. decoder->private_->frame.header.sample_rate = 8000;
  88398. break;
  88399. case 5:
  88400. decoder->private_->frame.header.sample_rate = 16000;
  88401. break;
  88402. case 6:
  88403. decoder->private_->frame.header.sample_rate = 22050;
  88404. break;
  88405. case 7:
  88406. decoder->private_->frame.header.sample_rate = 24000;
  88407. break;
  88408. case 8:
  88409. decoder->private_->frame.header.sample_rate = 32000;
  88410. break;
  88411. case 9:
  88412. decoder->private_->frame.header.sample_rate = 44100;
  88413. break;
  88414. case 10:
  88415. decoder->private_->frame.header.sample_rate = 48000;
  88416. break;
  88417. case 11:
  88418. decoder->private_->frame.header.sample_rate = 96000;
  88419. break;
  88420. case 12:
  88421. case 13:
  88422. case 14:
  88423. sample_rate_hint = x;
  88424. break;
  88425. case 15:
  88426. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88427. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88428. return true;
  88429. default:
  88430. FLAC__ASSERT(0);
  88431. }
  88432. x = (unsigned)(raw_header[3] >> 4);
  88433. if(x & 8) {
  88434. decoder->private_->frame.header.channels = 2;
  88435. switch(x & 7) {
  88436. case 0:
  88437. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88438. break;
  88439. case 1:
  88440. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88441. break;
  88442. case 2:
  88443. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88444. break;
  88445. default:
  88446. is_unparseable = true;
  88447. break;
  88448. }
  88449. }
  88450. else {
  88451. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88452. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88453. }
  88454. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88455. case 0:
  88456. if(decoder->private_->has_stream_info)
  88457. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88458. else
  88459. is_unparseable = true;
  88460. break;
  88461. case 1:
  88462. decoder->private_->frame.header.bits_per_sample = 8;
  88463. break;
  88464. case 2:
  88465. decoder->private_->frame.header.bits_per_sample = 12;
  88466. break;
  88467. case 4:
  88468. decoder->private_->frame.header.bits_per_sample = 16;
  88469. break;
  88470. case 5:
  88471. decoder->private_->frame.header.bits_per_sample = 20;
  88472. break;
  88473. case 6:
  88474. decoder->private_->frame.header.bits_per_sample = 24;
  88475. break;
  88476. case 3:
  88477. case 7:
  88478. is_unparseable = true;
  88479. break;
  88480. default:
  88481. FLAC__ASSERT(0);
  88482. break;
  88483. }
  88484. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88485. is_unparseable = true;
  88486. if(
  88487. raw_header[1] & 0x01 ||
  88488. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88489. ) { /* variable blocksize */
  88490. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88491. return false; /* read_callback_ sets the state for us */
  88492. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88493. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88494. decoder->private_->cached = true;
  88495. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88496. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88497. return true;
  88498. }
  88499. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88500. decoder->private_->frame.header.number.sample_number = xx;
  88501. }
  88502. else { /* fixed blocksize */
  88503. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88504. return false; /* read_callback_ sets the state for us */
  88505. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88506. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88507. decoder->private_->cached = true;
  88508. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88509. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88510. return true;
  88511. }
  88512. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88513. decoder->private_->frame.header.number.frame_number = x;
  88514. }
  88515. if(blocksize_hint) {
  88516. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88517. return false; /* read_callback_ sets the state for us */
  88518. raw_header[raw_header_len++] = (FLAC__byte)x;
  88519. if(blocksize_hint == 7) {
  88520. FLAC__uint32 _x;
  88521. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88522. return false; /* read_callback_ sets the state for us */
  88523. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88524. x = (x << 8) | _x;
  88525. }
  88526. decoder->private_->frame.header.blocksize = x+1;
  88527. }
  88528. if(sample_rate_hint) {
  88529. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88530. return false; /* read_callback_ sets the state for us */
  88531. raw_header[raw_header_len++] = (FLAC__byte)x;
  88532. if(sample_rate_hint != 12) {
  88533. FLAC__uint32 _x;
  88534. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88535. return false; /* read_callback_ sets the state for us */
  88536. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88537. x = (x << 8) | _x;
  88538. }
  88539. if(sample_rate_hint == 12)
  88540. decoder->private_->frame.header.sample_rate = x*1000;
  88541. else if(sample_rate_hint == 13)
  88542. decoder->private_->frame.header.sample_rate = x;
  88543. else
  88544. decoder->private_->frame.header.sample_rate = x*10;
  88545. }
  88546. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88547. return false; /* read_callback_ sets the state for us */
  88548. crc8 = (FLAC__byte)x;
  88549. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88550. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88551. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88552. return true;
  88553. }
  88554. decoder->private_->next_fixed_block_size = 0;
  88555. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88556. x = decoder->private_->frame.header.number.frame_number;
  88557. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88558. if(decoder->private_->fixed_block_size)
  88559. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88560. else if(decoder->private_->has_stream_info) {
  88561. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88562. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88563. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88564. }
  88565. else
  88566. is_unparseable = true;
  88567. }
  88568. else if(x == 0) {
  88569. decoder->private_->frame.header.number.sample_number = 0;
  88570. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88571. }
  88572. else {
  88573. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88574. }
  88575. }
  88576. if(is_unparseable) {
  88577. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88578. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88579. return true;
  88580. }
  88581. return true;
  88582. }
  88583. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88584. {
  88585. FLAC__uint32 x;
  88586. FLAC__bool wasted_bits;
  88587. unsigned i;
  88588. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88589. return false; /* read_callback_ sets the state for us */
  88590. wasted_bits = (x & 1);
  88591. x &= 0xfe;
  88592. if(wasted_bits) {
  88593. unsigned u;
  88594. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88595. return false; /* read_callback_ sets the state for us */
  88596. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88597. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88598. }
  88599. else
  88600. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88601. if(x & 0x80) {
  88602. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88603. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88604. return true;
  88605. }
  88606. else if(x == 0) {
  88607. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88608. return false;
  88609. }
  88610. else if(x == 2) {
  88611. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88612. return false;
  88613. }
  88614. else if(x < 16) {
  88615. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88616. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88617. return true;
  88618. }
  88619. else if(x <= 24) {
  88620. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88621. return false;
  88622. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88623. return true;
  88624. }
  88625. else if(x < 64) {
  88626. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88627. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88628. return true;
  88629. }
  88630. else {
  88631. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88632. return false;
  88633. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88634. return true;
  88635. }
  88636. if(wasted_bits && do_full_decode) {
  88637. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88638. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88639. decoder->private_->output[channel][i] <<= x;
  88640. }
  88641. return true;
  88642. }
  88643. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88644. {
  88645. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88646. FLAC__int32 x;
  88647. unsigned i;
  88648. FLAC__int32 *output = decoder->private_->output[channel];
  88649. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88650. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88651. return false; /* read_callback_ sets the state for us */
  88652. subframe->value = x;
  88653. if(do_full_decode) {
  88654. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88655. output[i] = x;
  88656. }
  88657. return true;
  88658. }
  88659. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88660. {
  88661. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88662. FLAC__int32 i32;
  88663. FLAC__uint32 u32;
  88664. unsigned u;
  88665. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88666. subframe->residual = decoder->private_->residual[channel];
  88667. subframe->order = order;
  88668. for(u = 0; u < order; u++) {
  88669. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88670. return false; /* read_callback_ sets the state for us */
  88671. subframe->warmup[u] = i32;
  88672. }
  88673. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88674. return false; /* read_callback_ sets the state for us */
  88675. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88676. switch(subframe->entropy_coding_method.type) {
  88677. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88678. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88679. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88680. return false; /* read_callback_ sets the state for us */
  88681. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88682. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88683. break;
  88684. default:
  88685. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88686. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88687. return true;
  88688. }
  88689. switch(subframe->entropy_coding_method.type) {
  88690. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88691. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88692. if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2))
  88693. return false;
  88694. break;
  88695. default:
  88696. FLAC__ASSERT(0);
  88697. }
  88698. if(do_full_decode) {
  88699. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88700. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88701. }
  88702. return true;
  88703. }
  88704. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88705. {
  88706. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88707. FLAC__int32 i32;
  88708. FLAC__uint32 u32;
  88709. unsigned u;
  88710. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88711. subframe->residual = decoder->private_->residual[channel];
  88712. subframe->order = order;
  88713. for(u = 0; u < order; u++) {
  88714. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88715. return false; /* read_callback_ sets the state for us */
  88716. subframe->warmup[u] = i32;
  88717. }
  88718. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88719. return false; /* read_callback_ sets the state for us */
  88720. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88721. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88722. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88723. return true;
  88724. }
  88725. subframe->qlp_coeff_precision = u32+1;
  88726. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88727. return false; /* read_callback_ sets the state for us */
  88728. subframe->quantization_level = i32;
  88729. for(u = 0; u < order; u++) {
  88730. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88731. return false; /* read_callback_ sets the state for us */
  88732. subframe->qlp_coeff[u] = i32;
  88733. }
  88734. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88735. return false; /* read_callback_ sets the state for us */
  88736. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88737. switch(subframe->entropy_coding_method.type) {
  88738. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88739. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88740. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88741. return false; /* read_callback_ sets the state for us */
  88742. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88743. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88744. break;
  88745. default:
  88746. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88747. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88748. return true;
  88749. }
  88750. switch(subframe->entropy_coding_method.type) {
  88751. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88752. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88753. if(!read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, &decoder->private_->partitioned_rice_contents[channel], decoder->private_->residual[channel], /*is_extended=*/subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2))
  88754. return false;
  88755. break;
  88756. default:
  88757. FLAC__ASSERT(0);
  88758. }
  88759. if(do_full_decode) {
  88760. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88761. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88762. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88763. if(order <= 8)
  88764. decoder->private_->local_lpc_restore_signal_16bit_order8(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  88765. else
  88766. decoder->private_->local_lpc_restore_signal_16bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  88767. }
  88768. else
  88769. decoder->private_->local_lpc_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  88770. else
  88771. decoder->private_->local_lpc_restore_signal_64bit(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->output[channel]+order);
  88772. }
  88773. return true;
  88774. }
  88775. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88776. {
  88777. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88778. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88779. unsigned i;
  88780. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88781. subframe->data = residual;
  88782. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88783. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88784. return false; /* read_callback_ sets the state for us */
  88785. residual[i] = x;
  88786. }
  88787. if(do_full_decode)
  88788. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88789. return true;
  88790. }
  88791. FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual, FLAC__bool is_extended)
  88792. {
  88793. FLAC__uint32 rice_parameter;
  88794. int i;
  88795. unsigned partition, sample, u;
  88796. const unsigned partitions = 1u << partition_order;
  88797. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88798. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88799. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88800. if(partition_order == 0) {
  88801. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88802. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88803. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88804. return true;
  88805. }
  88806. }
  88807. else {
  88808. if(partition_samples < predictor_order) {
  88809. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88810. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88811. return true;
  88812. }
  88813. }
  88814. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  88815. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88816. return false;
  88817. }
  88818. sample = 0;
  88819. for(partition = 0; partition < partitions; partition++) {
  88820. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  88821. return false; /* read_callback_ sets the state for us */
  88822. partitioned_rice_contents->parameters[partition] = rice_parameter;
  88823. if(rice_parameter < pesc) {
  88824. partitioned_rice_contents->raw_bits[partition] = 0;
  88825. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  88826. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  88827. return false; /* read_callback_ sets the state for us */
  88828. sample += u;
  88829. }
  88830. else {
  88831. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  88832. return false; /* read_callback_ sets the state for us */
  88833. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  88834. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  88835. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  88836. return false; /* read_callback_ sets the state for us */
  88837. residual[sample] = i;
  88838. }
  88839. }
  88840. }
  88841. return true;
  88842. }
  88843. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  88844. {
  88845. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88846. FLAC__uint32 zero = 0;
  88847. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88848. return false; /* read_callback_ sets the state for us */
  88849. if(zero != 0) {
  88850. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88851. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88852. }
  88853. }
  88854. return true;
  88855. }
  88856. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  88857. {
  88858. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  88859. if(
  88860. #if FLAC__HAS_OGG
  88861. !decoder->private_->is_ogg &&
  88862. #endif
  88863. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88864. ) {
  88865. *bytes = 0;
  88866. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88867. return false;
  88868. }
  88869. else if(*bytes > 0) {
  88870. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  88871. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88872. return false;
  88873. }
  88874. else {
  88875. const FLAC__StreamDecoderReadStatus status =
  88876. #if FLAC__HAS_OGG
  88877. decoder->private_->is_ogg?
  88878. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  88879. #endif
  88880. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  88881. ;
  88882. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  88883. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88884. return false;
  88885. }
  88886. else if(*bytes == 0) {
  88887. if(
  88888. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  88889. (
  88890. #if FLAC__HAS_OGG
  88891. !decoder->private_->is_ogg &&
  88892. #endif
  88893. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88894. )
  88895. ) {
  88896. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88897. return false;
  88898. }
  88899. else
  88900. return true;
  88901. }
  88902. else
  88903. return true;
  88904. }
  88905. }
  88906. else {
  88907. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88908. return false;
  88909. }
  88910. }
  88911. #if FLAC__HAS_OGG
  88912. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  88913. {
  88914. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  88915. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  88916. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  88917. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  88918. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  88919. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  88920. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  88921. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  88922. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  88923. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  88924. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  88925. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  88926. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  88927. default:
  88928. FLAC__ASSERT(0);
  88929. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  88930. }
  88931. }
  88932. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  88933. {
  88934. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  88935. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  88936. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  88937. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  88938. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  88939. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  88940. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  88941. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  88942. default:
  88943. FLAC__ASSERT(0);
  88944. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  88945. }
  88946. }
  88947. #endif
  88948. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  88949. {
  88950. if(decoder->private_->is_seeking) {
  88951. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  88952. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  88953. FLAC__uint64 target_sample = decoder->private_->target_sample;
  88954. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88955. #if FLAC__HAS_OGG
  88956. decoder->private_->got_a_frame = true;
  88957. #endif
  88958. decoder->private_->last_frame = *frame; /* save the frame */
  88959. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  88960. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  88961. decoder->private_->is_seeking = false;
  88962. if(delta > 0) {
  88963. unsigned channel;
  88964. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  88965. for(channel = 0; channel < frame->header.channels; channel++)
  88966. newbuffer[channel] = buffer[channel] + delta;
  88967. decoder->private_->last_frame.header.blocksize -= delta;
  88968. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  88969. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  88970. }
  88971. else {
  88972. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  88973. }
  88974. }
  88975. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  88976. }
  88977. if(!decoder->private_->has_stream_info)
  88978. decoder->private_->do_md5_checking = false;
  88979. if(decoder->private_->do_md5_checking) {
  88980. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  88981. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  88982. }
  88983. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  88984. }
  88985. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  88986. {
  88987. if(!decoder->private_->is_seeking)
  88988. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  88989. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  88990. decoder->private_->unparseable_frame_count++;
  88991. }
  88992. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  88993. {
  88994. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  88995. FLAC__int64 pos = -1;
  88996. int i;
  88997. unsigned approx_bytes_per_frame;
  88998. FLAC__bool first_seek = true;
  88999. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89000. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89001. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89002. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89003. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89004. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89005. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89006. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89007. if(channels == 0)
  89008. channels = decoder->private_->stream_info.data.stream_info.channels;
  89009. if(bps == 0)
  89010. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89011. if(max_framesize > 0)
  89012. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89013. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89014. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89015. }
  89016. else
  89017. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89018. lower_bound = first_frame_offset;
  89019. lower_bound_sample = 0;
  89020. upper_bound = stream_length;
  89021. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89022. if(seek_table) {
  89023. FLAC__uint64 new_lower_bound = lower_bound;
  89024. FLAC__uint64 new_upper_bound = upper_bound;
  89025. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89026. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89027. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89028. if(
  89029. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89030. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89031. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89032. seek_table->points[i].sample_number <= target_sample
  89033. )
  89034. break;
  89035. }
  89036. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89037. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89038. new_lower_bound_sample = seek_table->points[i].sample_number;
  89039. }
  89040. for(i = 0; i < (int)seek_table->num_points; i++) {
  89041. if(
  89042. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89043. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89044. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89045. seek_table->points[i].sample_number > target_sample
  89046. )
  89047. break;
  89048. }
  89049. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89050. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89051. new_upper_bound_sample = seek_table->points[i].sample_number;
  89052. }
  89053. if(new_upper_bound >= new_lower_bound) {
  89054. lower_bound = new_lower_bound;
  89055. upper_bound = new_upper_bound;
  89056. lower_bound_sample = new_lower_bound_sample;
  89057. upper_bound_sample = new_upper_bound_sample;
  89058. }
  89059. }
  89060. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89061. if(upper_bound_sample == lower_bound_sample)
  89062. upper_bound_sample++;
  89063. decoder->private_->target_sample = target_sample;
  89064. while(1) {
  89065. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89066. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89067. return false;
  89068. }
  89069. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89070. #if defined _MSC_VER || defined __MINGW32__
  89071. pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(FLAC__int64)(target_sample - lower_bound_sample) / (FLAC__double)(FLAC__int64)(upper_bound_sample - lower_bound_sample) * (FLAC__double)(FLAC__int64)(upper_bound - lower_bound)) - approx_bytes_per_frame;
  89072. #else
  89073. pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(target_sample - lower_bound_sample) / (FLAC__double)(upper_bound_sample - lower_bound_sample) * (FLAC__double)(upper_bound - lower_bound)) - approx_bytes_per_frame;
  89074. #endif
  89075. #else
  89076. if(upper_bound - lower_bound < 0xffffffff)
  89077. pos = (FLAC__int64)lower_bound + (FLAC__int64)(((target_sample - lower_bound_sample) * (upper_bound - lower_bound)) / (upper_bound_sample - lower_bound_sample)) - approx_bytes_per_frame;
  89078. else /* @@@ WATCHOUT, ~2TB limit */
  89079. pos = (FLAC__int64)lower_bound + (FLAC__int64)((((target_sample - lower_bound_sample)>>8) * ((upper_bound - lower_bound)>>8)) / ((upper_bound_sample - lower_bound_sample)>>16)) - approx_bytes_per_frame;
  89080. #endif
  89081. if(pos >= (FLAC__int64)upper_bound)
  89082. pos = (FLAC__int64)upper_bound - 1;
  89083. if(pos < (FLAC__int64)lower_bound)
  89084. pos = (FLAC__int64)lower_bound;
  89085. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89086. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89087. return false;
  89088. }
  89089. if(!FLAC__stream_decoder_flush(decoder)) {
  89090. return false;
  89091. }
  89092. decoder->private_->unparseable_frame_count = 0;
  89093. if(!FLAC__stream_decoder_process_single(decoder)) {
  89094. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89095. return false;
  89096. }
  89097. #if 0
  89098. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89099. break;
  89100. #endif
  89101. if(!decoder->private_->is_seeking)
  89102. break;
  89103. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89104. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89105. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89106. if (pos == (FLAC__int64)lower_bound) {
  89107. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89108. return false;
  89109. }
  89110. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89111. continue;
  89112. }
  89113. first_seek = false;
  89114. if (this_frame_sample < lower_bound_sample) {
  89115. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89116. return false;
  89117. }
  89118. if(target_sample < this_frame_sample) {
  89119. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89120. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89121. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89122. return false;
  89123. }
  89124. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89125. }
  89126. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89127. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89128. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89129. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89130. return false;
  89131. }
  89132. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89133. }
  89134. }
  89135. return true;
  89136. }
  89137. #if FLAC__HAS_OGG
  89138. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89139. {
  89140. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89141. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89142. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89143. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89144. FLAC__bool did_a_seek;
  89145. unsigned iteration = 0;
  89146. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89147. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89148. if(right_sample == 0) {
  89149. right_sample = (FLAC__uint64)(-1);
  89150. BINARY_SEARCH_AFTER_ITERATION = 0;
  89151. }
  89152. decoder->private_->target_sample = target_sample;
  89153. for( ; ; iteration++) {
  89154. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89155. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89156. pos = (right_pos + left_pos) / 2;
  89157. }
  89158. else {
  89159. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89160. #if defined _MSC_VER || defined __MINGW32__
  89161. pos = (FLAC__uint64)((FLAC__double)(FLAC__int64)(target_sample - left_sample) / (FLAC__double)(FLAC__int64)(right_sample - left_sample) * (FLAC__double)(FLAC__int64)(right_pos - left_pos));
  89162. #else
  89163. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89164. #endif
  89165. #else
  89166. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89167. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89168. else /* @@@ WATCHOUT, ~2TB limit */
  89169. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89170. #endif
  89171. }
  89172. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89173. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89174. return false;
  89175. }
  89176. if(!FLAC__stream_decoder_flush(decoder)) {
  89177. return false;
  89178. }
  89179. did_a_seek = true;
  89180. }
  89181. else
  89182. did_a_seek = false;
  89183. decoder->private_->got_a_frame = false;
  89184. if(!FLAC__stream_decoder_process_single(decoder)) {
  89185. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89186. return false;
  89187. }
  89188. if(!decoder->private_->got_a_frame) {
  89189. if(did_a_seek) {
  89190. right_pos = pos;
  89191. BINARY_SEARCH_AFTER_ITERATION = 0;
  89192. }
  89193. else {
  89194. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89195. return false;
  89196. }
  89197. }
  89198. else if(!decoder->private_->is_seeking) {
  89199. break;
  89200. }
  89201. else {
  89202. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89203. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89204. if (did_a_seek) {
  89205. if (this_frame_sample <= target_sample) {
  89206. FLAC__ASSERT(this_frame_sample != target_sample);
  89207. left_sample = this_frame_sample;
  89208. if (left_pos == pos) {
  89209. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89210. return false;
  89211. }
  89212. left_pos = pos;
  89213. }
  89214. else if(this_frame_sample > target_sample) {
  89215. right_sample = this_frame_sample;
  89216. if (right_pos == pos) {
  89217. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89218. return false;
  89219. }
  89220. right_pos = pos;
  89221. }
  89222. }
  89223. }
  89224. }
  89225. return true;
  89226. }
  89227. #endif
  89228. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89229. {
  89230. (void)client_data;
  89231. if(*bytes > 0) {
  89232. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89233. if(ferror(decoder->private_->file))
  89234. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89235. else if(*bytes == 0)
  89236. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89237. else
  89238. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89239. }
  89240. else
  89241. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89242. }
  89243. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89244. {
  89245. (void)client_data;
  89246. if(decoder->private_->file == stdin)
  89247. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89248. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89249. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89250. else
  89251. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89252. }
  89253. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89254. {
  89255. off_t pos;
  89256. (void)client_data;
  89257. if(decoder->private_->file == stdin)
  89258. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89259. else if((pos = ftello(decoder->private_->file)) < 0)
  89260. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89261. else {
  89262. *absolute_byte_offset = (FLAC__uint64)pos;
  89263. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89264. }
  89265. }
  89266. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89267. {
  89268. struct stat filestats;
  89269. (void)client_data;
  89270. if(decoder->private_->file == stdin)
  89271. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89272. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89273. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89274. else {
  89275. *stream_length = (FLAC__uint64)filestats.st_size;
  89276. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89277. }
  89278. }
  89279. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89280. {
  89281. (void)client_data;
  89282. return feof(decoder->private_->file)? true : false;
  89283. }
  89284. #endif
  89285. /*** End of inlined file: stream_decoder.c ***/
  89286. /*** Start of inlined file: stream_encoder.c ***/
  89287. /*** Start of inlined file: juce_FlacHeader.h ***/
  89288. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89289. // tasks..
  89290. #define VERSION "1.2.1"
  89291. #define FLAC__NO_DLL 1
  89292. #if JUCE_MSVC
  89293. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89294. #endif
  89295. #if JUCE_MAC
  89296. #define FLAC__SYS_DARWIN 1
  89297. #endif
  89298. /*** End of inlined file: juce_FlacHeader.h ***/
  89299. #if JUCE_USE_FLAC
  89300. #if HAVE_CONFIG_H
  89301. # include <config.h>
  89302. #endif
  89303. #if defined _MSC_VER || defined __MINGW32__
  89304. #include <io.h> /* for _setmode() */
  89305. #include <fcntl.h> /* for _O_BINARY */
  89306. #endif
  89307. #if defined __CYGWIN__ || defined __EMX__
  89308. #include <io.h> /* for setmode(), O_BINARY */
  89309. #include <fcntl.h> /* for _O_BINARY */
  89310. #endif
  89311. #include <limits.h>
  89312. #include <stdio.h>
  89313. #include <stdlib.h> /* for malloc() */
  89314. #include <string.h> /* for memcpy() */
  89315. #include <sys/types.h> /* for off_t */
  89316. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89317. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89318. #define fseeko fseek
  89319. #define ftello ftell
  89320. #endif
  89321. #endif
  89322. /*** Start of inlined file: stream_encoder.h ***/
  89323. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89324. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89325. #if FLAC__HAS_OGG
  89326. #include "private/ogg_encoder_aspect.h"
  89327. #endif
  89328. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89329. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89330. typedef enum {
  89331. FLAC__APODIZATION_BARTLETT,
  89332. FLAC__APODIZATION_BARTLETT_HANN,
  89333. FLAC__APODIZATION_BLACKMAN,
  89334. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89335. FLAC__APODIZATION_CONNES,
  89336. FLAC__APODIZATION_FLATTOP,
  89337. FLAC__APODIZATION_GAUSS,
  89338. FLAC__APODIZATION_HAMMING,
  89339. FLAC__APODIZATION_HANN,
  89340. FLAC__APODIZATION_KAISER_BESSEL,
  89341. FLAC__APODIZATION_NUTTALL,
  89342. FLAC__APODIZATION_RECTANGLE,
  89343. FLAC__APODIZATION_TRIANGLE,
  89344. FLAC__APODIZATION_TUKEY,
  89345. FLAC__APODIZATION_WELCH
  89346. } FLAC__ApodizationFunction;
  89347. typedef struct {
  89348. FLAC__ApodizationFunction type;
  89349. union {
  89350. struct {
  89351. FLAC__real stddev;
  89352. } gauss;
  89353. struct {
  89354. FLAC__real p;
  89355. } tukey;
  89356. } parameters;
  89357. } FLAC__ApodizationSpecification;
  89358. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89359. typedef struct FLAC__StreamEncoderProtected {
  89360. FLAC__StreamEncoderState state;
  89361. FLAC__bool verify;
  89362. FLAC__bool streamable_subset;
  89363. FLAC__bool do_md5;
  89364. FLAC__bool do_mid_side_stereo;
  89365. FLAC__bool loose_mid_side_stereo;
  89366. unsigned channels;
  89367. unsigned bits_per_sample;
  89368. unsigned sample_rate;
  89369. unsigned blocksize;
  89370. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89371. unsigned num_apodizations;
  89372. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89373. #endif
  89374. unsigned max_lpc_order;
  89375. unsigned qlp_coeff_precision;
  89376. FLAC__bool do_qlp_coeff_prec_search;
  89377. FLAC__bool do_exhaustive_model_search;
  89378. FLAC__bool do_escape_coding;
  89379. unsigned min_residual_partition_order;
  89380. unsigned max_residual_partition_order;
  89381. unsigned rice_parameter_search_dist;
  89382. FLAC__uint64 total_samples_estimate;
  89383. FLAC__StreamMetadata **metadata;
  89384. unsigned num_metadata_blocks;
  89385. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89386. #if FLAC__HAS_OGG
  89387. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89388. #endif
  89389. } FLAC__StreamEncoderProtected;
  89390. #endif
  89391. /*** End of inlined file: stream_encoder.h ***/
  89392. #if FLAC__HAS_OGG
  89393. #include "include/private/ogg_helper.h"
  89394. #include "include/private/ogg_mapping.h"
  89395. #endif
  89396. /*** Start of inlined file: stream_encoder_framing.h ***/
  89397. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89398. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89399. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89400. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89401. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89402. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89403. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89404. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89405. #endif
  89406. /*** End of inlined file: stream_encoder_framing.h ***/
  89407. /*** Start of inlined file: window.h ***/
  89408. #ifndef FLAC__PRIVATE__WINDOW_H
  89409. #define FLAC__PRIVATE__WINDOW_H
  89410. #ifdef HAVE_CONFIG_H
  89411. #include <config.h>
  89412. #endif
  89413. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89414. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89415. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89416. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89417. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89418. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89419. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89420. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89421. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89422. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89423. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89424. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89425. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89426. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89427. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89428. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89429. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89430. #endif
  89431. /*** End of inlined file: window.h ***/
  89432. #ifndef FLaC__INLINE
  89433. #define FLaC__INLINE
  89434. #endif
  89435. #ifdef min
  89436. #undef min
  89437. #endif
  89438. #define min(x,y) ((x)<(y)?(x):(y))
  89439. #ifdef max
  89440. #undef max
  89441. #endif
  89442. #define max(x,y) ((x)>(y)?(x):(y))
  89443. #undef EXACT_RICE_BITS_CALCULATION
  89444. #undef ENABLE_RICE_PARAMETER_SEARCH
  89445. typedef struct {
  89446. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89447. unsigned size; /* of each data[] in samples */
  89448. unsigned tail;
  89449. } verify_input_fifo;
  89450. typedef struct {
  89451. const FLAC__byte *data;
  89452. unsigned capacity;
  89453. unsigned bytes;
  89454. } verify_output;
  89455. typedef enum {
  89456. ENCODER_IN_MAGIC = 0,
  89457. ENCODER_IN_METADATA = 1,
  89458. ENCODER_IN_AUDIO = 2
  89459. } EncoderStateHint;
  89460. static struct CompressionLevels {
  89461. FLAC__bool do_mid_side_stereo;
  89462. FLAC__bool loose_mid_side_stereo;
  89463. unsigned max_lpc_order;
  89464. unsigned qlp_coeff_precision;
  89465. FLAC__bool do_qlp_coeff_prec_search;
  89466. FLAC__bool do_escape_coding;
  89467. FLAC__bool do_exhaustive_model_search;
  89468. unsigned min_residual_partition_order;
  89469. unsigned max_residual_partition_order;
  89470. unsigned rice_parameter_search_dist;
  89471. } compression_levels_[] = {
  89472. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89473. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89474. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89475. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89476. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89477. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89478. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89479. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89480. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89481. };
  89482. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89483. static void free_(FLAC__StreamEncoder *encoder);
  89484. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89485. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89486. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89487. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89488. #if FLAC__HAS_OGG
  89489. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89490. #endif
  89491. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89492. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89493. static FLAC__bool process_subframe_(
  89494. FLAC__StreamEncoder *encoder,
  89495. unsigned min_partition_order,
  89496. unsigned max_partition_order,
  89497. const FLAC__FrameHeader *frame_header,
  89498. unsigned subframe_bps,
  89499. const FLAC__int32 integer_signal[],
  89500. FLAC__Subframe *subframe[2],
  89501. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89502. FLAC__int32 *residual[2],
  89503. unsigned *best_subframe,
  89504. unsigned *best_bits
  89505. );
  89506. static FLAC__bool add_subframe_(
  89507. FLAC__StreamEncoder *encoder,
  89508. unsigned blocksize,
  89509. unsigned subframe_bps,
  89510. const FLAC__Subframe *subframe,
  89511. FLAC__BitWriter *frame
  89512. );
  89513. static unsigned evaluate_constant_subframe_(
  89514. FLAC__StreamEncoder *encoder,
  89515. const FLAC__int32 signal,
  89516. unsigned blocksize,
  89517. unsigned subframe_bps,
  89518. FLAC__Subframe *subframe
  89519. );
  89520. static unsigned evaluate_fixed_subframe_(
  89521. FLAC__StreamEncoder *encoder,
  89522. const FLAC__int32 signal[],
  89523. FLAC__int32 residual[],
  89524. FLAC__uint64 abs_residual_partition_sums[],
  89525. unsigned raw_bits_per_partition[],
  89526. unsigned blocksize,
  89527. unsigned subframe_bps,
  89528. unsigned order,
  89529. unsigned rice_parameter,
  89530. unsigned rice_parameter_limit,
  89531. unsigned min_partition_order,
  89532. unsigned max_partition_order,
  89533. FLAC__bool do_escape_coding,
  89534. unsigned rice_parameter_search_dist,
  89535. FLAC__Subframe *subframe,
  89536. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89537. );
  89538. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89539. static unsigned evaluate_lpc_subframe_(
  89540. FLAC__StreamEncoder *encoder,
  89541. const FLAC__int32 signal[],
  89542. FLAC__int32 residual[],
  89543. FLAC__uint64 abs_residual_partition_sums[],
  89544. unsigned raw_bits_per_partition[],
  89545. const FLAC__real lp_coeff[],
  89546. unsigned blocksize,
  89547. unsigned subframe_bps,
  89548. unsigned order,
  89549. unsigned qlp_coeff_precision,
  89550. unsigned rice_parameter,
  89551. unsigned rice_parameter_limit,
  89552. unsigned min_partition_order,
  89553. unsigned max_partition_order,
  89554. FLAC__bool do_escape_coding,
  89555. unsigned rice_parameter_search_dist,
  89556. FLAC__Subframe *subframe,
  89557. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89558. );
  89559. #endif
  89560. static unsigned evaluate_verbatim_subframe_(
  89561. FLAC__StreamEncoder *encoder,
  89562. const FLAC__int32 signal[],
  89563. unsigned blocksize,
  89564. unsigned subframe_bps,
  89565. FLAC__Subframe *subframe
  89566. );
  89567. static unsigned find_best_partition_order_(
  89568. struct FLAC__StreamEncoderPrivate *private_,
  89569. const FLAC__int32 residual[],
  89570. FLAC__uint64 abs_residual_partition_sums[],
  89571. unsigned raw_bits_per_partition[],
  89572. unsigned residual_samples,
  89573. unsigned predictor_order,
  89574. unsigned rice_parameter,
  89575. unsigned rice_parameter_limit,
  89576. unsigned min_partition_order,
  89577. unsigned max_partition_order,
  89578. unsigned bps,
  89579. FLAC__bool do_escape_coding,
  89580. unsigned rice_parameter_search_dist,
  89581. FLAC__EntropyCodingMethod *best_ecm
  89582. );
  89583. static void precompute_partition_info_sums_(
  89584. const FLAC__int32 residual[],
  89585. FLAC__uint64 abs_residual_partition_sums[],
  89586. unsigned residual_samples,
  89587. unsigned predictor_order,
  89588. unsigned min_partition_order,
  89589. unsigned max_partition_order,
  89590. unsigned bps
  89591. );
  89592. static void precompute_partition_info_escapes_(
  89593. const FLAC__int32 residual[],
  89594. unsigned raw_bits_per_partition[],
  89595. unsigned residual_samples,
  89596. unsigned predictor_order,
  89597. unsigned min_partition_order,
  89598. unsigned max_partition_order
  89599. );
  89600. static FLAC__bool set_partitioned_rice_(
  89601. #ifdef EXACT_RICE_BITS_CALCULATION
  89602. const FLAC__int32 residual[],
  89603. #endif
  89604. const FLAC__uint64 abs_residual_partition_sums[],
  89605. const unsigned raw_bits_per_partition[],
  89606. const unsigned residual_samples,
  89607. const unsigned predictor_order,
  89608. const unsigned suggested_rice_parameter,
  89609. const unsigned rice_parameter_limit,
  89610. const unsigned rice_parameter_search_dist,
  89611. const unsigned partition_order,
  89612. const FLAC__bool search_for_escapes,
  89613. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89614. unsigned *bits
  89615. );
  89616. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89617. static void append_to_verify_fifo_(
  89618. verify_input_fifo *fifo,
  89619. const FLAC__int32 * const input[],
  89620. unsigned input_offset,
  89621. unsigned channels,
  89622. unsigned wide_samples
  89623. );
  89624. static void append_to_verify_fifo_interleaved_(
  89625. verify_input_fifo *fifo,
  89626. const FLAC__int32 input[],
  89627. unsigned input_offset,
  89628. unsigned channels,
  89629. unsigned wide_samples
  89630. );
  89631. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89632. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89633. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89634. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89635. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89636. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89637. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89638. static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  89639. static FILE *get_binary_stdout_(void);
  89640. typedef struct FLAC__StreamEncoderPrivate {
  89641. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89642. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89643. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89644. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89645. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89646. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89647. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89648. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89649. #endif
  89650. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89651. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89652. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89653. FLAC__int32 *residual_workspace_mid_side[2][2];
  89654. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89655. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89656. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89657. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89658. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89659. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89660. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89661. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89662. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89663. unsigned best_subframe_mid_side[2];
  89664. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89665. unsigned best_subframe_bits_mid_side[2];
  89666. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89667. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89668. FLAC__BitWriter *frame; /* the current frame being worked on */
  89669. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89670. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89671. FLAC__ChannelAssignment last_channel_assignment;
  89672. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89673. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89674. unsigned current_sample_number;
  89675. unsigned current_frame_number;
  89676. FLAC__MD5Context md5context;
  89677. FLAC__CPUInfo cpuinfo;
  89678. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89679. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89680. #else
  89681. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89682. #endif
  89683. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89684. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89685. void (*local_lpc_compute_residual_from_qlp_coefficients)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  89686. void (*local_lpc_compute_residual_from_qlp_coefficients_64bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  89687. void (*local_lpc_compute_residual_from_qlp_coefficients_16bit)(const FLAC__int32 *data, unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 residual[]);
  89688. #endif
  89689. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89690. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89691. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89692. FLAC__bool disable_constant_subframes;
  89693. FLAC__bool disable_fixed_subframes;
  89694. FLAC__bool disable_verbatim_subframes;
  89695. #if FLAC__HAS_OGG
  89696. FLAC__bool is_ogg;
  89697. #endif
  89698. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89699. FLAC__StreamEncoderSeekCallback seek_callback;
  89700. FLAC__StreamEncoderTellCallback tell_callback;
  89701. FLAC__StreamEncoderWriteCallback write_callback;
  89702. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89703. FLAC__StreamEncoderProgressCallback progress_callback;
  89704. void *client_data;
  89705. unsigned first_seekpoint_to_check;
  89706. FILE *file; /* only used when encoding to a file */
  89707. FLAC__uint64 bytes_written;
  89708. FLAC__uint64 samples_written;
  89709. unsigned frames_written;
  89710. unsigned total_frames_estimate;
  89711. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89712. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89713. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89714. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89715. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89716. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89717. FLAC__real *windowed_signal_unaligned;
  89718. #endif
  89719. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89720. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89721. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89722. unsigned *raw_bits_per_partition_unaligned;
  89723. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89724. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89725. #endif
  89726. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89727. struct {
  89728. FLAC__StreamDecoder *decoder;
  89729. EncoderStateHint state_hint;
  89730. FLAC__bool needs_magic_hack;
  89731. verify_input_fifo input_fifo;
  89732. verify_output output;
  89733. struct {
  89734. FLAC__uint64 absolute_sample;
  89735. unsigned frame_number;
  89736. unsigned channel;
  89737. unsigned sample;
  89738. FLAC__int32 expected;
  89739. FLAC__int32 got;
  89740. } error_stats;
  89741. } verify;
  89742. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89743. } FLAC__StreamEncoderPrivate;
  89744. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89745. "FLAC__STREAM_ENCODER_OK",
  89746. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89747. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89748. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89749. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89750. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89751. "FLAC__STREAM_ENCODER_IO_ERROR",
  89752. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89753. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89754. };
  89755. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89756. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89757. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89758. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89759. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89760. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89761. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89762. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89763. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89764. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89765. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89766. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89767. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89768. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89769. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89770. };
  89771. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89772. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89773. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89774. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89775. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89776. };
  89777. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89778. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89779. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89780. };
  89781. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89782. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89783. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89784. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89785. };
  89786. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89787. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89788. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89789. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89790. };
  89791. static const unsigned OVERREAD_ = 1;
  89792. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89793. {
  89794. FLAC__StreamEncoder *encoder;
  89795. unsigned i;
  89796. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89797. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89798. if(encoder == 0) {
  89799. return 0;
  89800. }
  89801. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89802. if(encoder->protected_ == 0) {
  89803. free(encoder);
  89804. return 0;
  89805. }
  89806. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89807. if(encoder->private_ == 0) {
  89808. free(encoder->protected_);
  89809. free(encoder);
  89810. return 0;
  89811. }
  89812. encoder->private_->frame = FLAC__bitwriter_new();
  89813. if(encoder->private_->frame == 0) {
  89814. free(encoder->private_);
  89815. free(encoder->protected_);
  89816. free(encoder);
  89817. return 0;
  89818. }
  89819. encoder->private_->file = 0;
  89820. set_defaults_enc(encoder);
  89821. encoder->private_->is_being_deleted = false;
  89822. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89823. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  89824. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  89825. }
  89826. for(i = 0; i < 2; i++) {
  89827. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  89828. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  89829. }
  89830. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89831. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  89832. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  89833. }
  89834. for(i = 0; i < 2; i++) {
  89835. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  89836. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  89837. }
  89838. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89839. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89840. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89841. }
  89842. for(i = 0; i < 2; i++) {
  89843. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89844. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89845. }
  89846. for(i = 0; i < 2; i++)
  89847. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  89848. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  89849. return encoder;
  89850. }
  89851. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  89852. {
  89853. unsigned i;
  89854. FLAC__ASSERT(0 != encoder);
  89855. FLAC__ASSERT(0 != encoder->protected_);
  89856. FLAC__ASSERT(0 != encoder->private_);
  89857. FLAC__ASSERT(0 != encoder->private_->frame);
  89858. encoder->private_->is_being_deleted = true;
  89859. (void)FLAC__stream_encoder_finish(encoder);
  89860. if(0 != encoder->private_->verify.decoder)
  89861. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  89862. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89863. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89864. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89865. }
  89866. for(i = 0; i < 2; i++) {
  89867. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89868. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89869. }
  89870. for(i = 0; i < 2; i++)
  89871. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  89872. FLAC__bitwriter_delete(encoder->private_->frame);
  89873. free(encoder->private_);
  89874. free(encoder->protected_);
  89875. free(encoder);
  89876. }
  89877. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  89878. FLAC__StreamEncoder *encoder,
  89879. FLAC__StreamEncoderReadCallback read_callback,
  89880. FLAC__StreamEncoderWriteCallback write_callback,
  89881. FLAC__StreamEncoderSeekCallback seek_callback,
  89882. FLAC__StreamEncoderTellCallback tell_callback,
  89883. FLAC__StreamEncoderMetadataCallback metadata_callback,
  89884. void *client_data,
  89885. FLAC__bool is_ogg
  89886. )
  89887. {
  89888. unsigned i;
  89889. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  89890. FLAC__ASSERT(0 != encoder);
  89891. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  89892. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  89893. #if !FLAC__HAS_OGG
  89894. if(is_ogg)
  89895. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  89896. #endif
  89897. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  89898. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  89899. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  89900. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  89901. if(encoder->protected_->channels != 2) {
  89902. encoder->protected_->do_mid_side_stereo = false;
  89903. encoder->protected_->loose_mid_side_stereo = false;
  89904. }
  89905. else if(!encoder->protected_->do_mid_side_stereo)
  89906. encoder->protected_->loose_mid_side_stereo = false;
  89907. if(encoder->protected_->bits_per_sample >= 32)
  89908. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  89909. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  89910. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  89911. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  89912. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  89913. if(encoder->protected_->blocksize == 0) {
  89914. if(encoder->protected_->max_lpc_order == 0)
  89915. encoder->protected_->blocksize = 1152;
  89916. else
  89917. encoder->protected_->blocksize = 4096;
  89918. }
  89919. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  89920. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  89921. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  89922. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  89923. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  89924. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  89925. if(encoder->protected_->qlp_coeff_precision == 0) {
  89926. if(encoder->protected_->bits_per_sample < 16) {
  89927. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  89928. }
  89929. else if(encoder->protected_->bits_per_sample == 16) {
  89930. if(encoder->protected_->blocksize <= 192)
  89931. encoder->protected_->qlp_coeff_precision = 7;
  89932. else if(encoder->protected_->blocksize <= 384)
  89933. encoder->protected_->qlp_coeff_precision = 8;
  89934. else if(encoder->protected_->blocksize <= 576)
  89935. encoder->protected_->qlp_coeff_precision = 9;
  89936. else if(encoder->protected_->blocksize <= 1152)
  89937. encoder->protected_->qlp_coeff_precision = 10;
  89938. else if(encoder->protected_->blocksize <= 2304)
  89939. encoder->protected_->qlp_coeff_precision = 11;
  89940. else if(encoder->protected_->blocksize <= 4608)
  89941. encoder->protected_->qlp_coeff_precision = 12;
  89942. else
  89943. encoder->protected_->qlp_coeff_precision = 13;
  89944. }
  89945. else {
  89946. if(encoder->protected_->blocksize <= 384)
  89947. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  89948. else if(encoder->protected_->blocksize <= 1152)
  89949. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  89950. else
  89951. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  89952. }
  89953. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  89954. }
  89955. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  89956. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  89957. if(encoder->protected_->streamable_subset) {
  89958. if(
  89959. encoder->protected_->blocksize != 192 &&
  89960. encoder->protected_->blocksize != 576 &&
  89961. encoder->protected_->blocksize != 1152 &&
  89962. encoder->protected_->blocksize != 2304 &&
  89963. encoder->protected_->blocksize != 4608 &&
  89964. encoder->protected_->blocksize != 256 &&
  89965. encoder->protected_->blocksize != 512 &&
  89966. encoder->protected_->blocksize != 1024 &&
  89967. encoder->protected_->blocksize != 2048 &&
  89968. encoder->protected_->blocksize != 4096 &&
  89969. encoder->protected_->blocksize != 8192 &&
  89970. encoder->protected_->blocksize != 16384
  89971. )
  89972. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89973. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  89974. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89975. if(
  89976. encoder->protected_->bits_per_sample != 8 &&
  89977. encoder->protected_->bits_per_sample != 12 &&
  89978. encoder->protected_->bits_per_sample != 16 &&
  89979. encoder->protected_->bits_per_sample != 20 &&
  89980. encoder->protected_->bits_per_sample != 24
  89981. )
  89982. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89983. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  89984. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89985. if(
  89986. encoder->protected_->sample_rate <= 48000 &&
  89987. (
  89988. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  89989. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  89990. )
  89991. ) {
  89992. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  89993. }
  89994. }
  89995. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89996. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  89997. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  89998. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  89999. #if FLAC__HAS_OGG
  90000. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90001. unsigned i;
  90002. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90003. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90004. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90005. for( ; i > 0; i--)
  90006. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90007. encoder->protected_->metadata[0] = vc;
  90008. break;
  90009. }
  90010. }
  90011. }
  90012. #endif
  90013. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90014. unsigned i;
  90015. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90016. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90017. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90018. break; /* take only the first one */
  90019. }
  90020. }
  90021. }
  90022. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90023. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90024. metadata_has_seektable = false;
  90025. metadata_has_vorbis_comment = false;
  90026. metadata_picture_has_type1 = false;
  90027. metadata_picture_has_type2 = false;
  90028. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90029. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90030. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90031. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90032. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90033. if(metadata_has_seektable) /* only one is allowed */
  90034. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90035. metadata_has_seektable = true;
  90036. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90037. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90038. }
  90039. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90040. if(metadata_has_vorbis_comment) /* only one is allowed */
  90041. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90042. metadata_has_vorbis_comment = true;
  90043. }
  90044. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90045. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90046. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90047. }
  90048. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90049. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90050. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90051. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90052. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90053. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90054. metadata_picture_has_type1 = true;
  90055. if(
  90056. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90057. (
  90058. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90059. m->data.picture.width != 32 ||
  90060. m->data.picture.height != 32
  90061. )
  90062. )
  90063. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90064. }
  90065. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90066. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90067. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90068. metadata_picture_has_type2 = true;
  90069. }
  90070. }
  90071. }
  90072. encoder->private_->input_capacity = 0;
  90073. for(i = 0; i < encoder->protected_->channels; i++) {
  90074. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90075. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90076. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90077. #endif
  90078. }
  90079. for(i = 0; i < 2; i++) {
  90080. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90081. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90082. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90083. #endif
  90084. }
  90085. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90086. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90087. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90088. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90089. #endif
  90090. for(i = 0; i < encoder->protected_->channels; i++) {
  90091. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90092. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90093. encoder->private_->best_subframe[i] = 0;
  90094. }
  90095. for(i = 0; i < 2; i++) {
  90096. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90097. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90098. encoder->private_->best_subframe_mid_side[i] = 0;
  90099. }
  90100. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90101. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90102. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90103. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90104. #else
  90105. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90106. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90107. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90108. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90109. encoder->private_->loose_mid_side_stereo_frames = (unsigned)FLAC__fixedpoint_trunc((((FLAC__uint64)(encoder->protected_->sample_rate) * (FLAC__uint64)(26214)) << 16) / (encoder->protected_->blocksize<<16) + FLAC__FP_ONE_HALF);
  90110. #endif
  90111. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90112. encoder->private_->loose_mid_side_stereo_frames = 1;
  90113. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90114. encoder->private_->current_sample_number = 0;
  90115. encoder->private_->current_frame_number = 0;
  90116. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90117. encoder->private_->use_wide_by_order = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(max(encoder->protected_->max_lpc_order, FLAC__MAX_FIXED_ORDER))+1 > 30); /*@@@ need to use this? */
  90118. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90119. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90120. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90121. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90122. #endif
  90123. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90124. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90125. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90126. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90127. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90128. #endif
  90129. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90130. # ifndef FLAC__NO_ASM
  90131. if(encoder->private_->cpuinfo.use_asm) {
  90132. # ifdef FLAC__CPU_IA32
  90133. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90134. # ifdef FLAC__HAS_NASM
  90135. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90136. if(encoder->protected_->max_lpc_order < 4)
  90137. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90138. else if(encoder->protected_->max_lpc_order < 8)
  90139. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90140. else if(encoder->protected_->max_lpc_order < 12)
  90141. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90142. else
  90143. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90144. }
  90145. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90146. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90147. else
  90148. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90149. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90150. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90151. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90152. }
  90153. else {
  90154. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90155. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90156. }
  90157. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90158. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90159. # endif /* FLAC__HAS_NASM */
  90160. # endif /* FLAC__CPU_IA32 */
  90161. }
  90162. # endif /* !FLAC__NO_ASM */
  90163. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90164. if(encoder->private_->use_wide_by_block) {
  90165. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90166. }
  90167. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90168. #if FLAC__HAS_OGG
  90169. encoder->private_->is_ogg = is_ogg;
  90170. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90171. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90172. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90173. }
  90174. #endif
  90175. encoder->private_->read_callback = read_callback;
  90176. encoder->private_->write_callback = write_callback;
  90177. encoder->private_->seek_callback = seek_callback;
  90178. encoder->private_->tell_callback = tell_callback;
  90179. encoder->private_->metadata_callback = metadata_callback;
  90180. encoder->private_->client_data = client_data;
  90181. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90182. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90183. }
  90184. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90185. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90186. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90187. }
  90188. if(encoder->protected_->verify) {
  90189. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90190. for(i = 0; i < encoder->protected_->channels; i++) {
  90191. if(0 == (encoder->private_->verify.input_fifo.data[i] = (FLAC__int32*)safe_malloc_mul_2op_(sizeof(FLAC__int32), /*times*/encoder->private_->verify.input_fifo.size))) {
  90192. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90193. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90194. }
  90195. }
  90196. encoder->private_->verify.input_fifo.tail = 0;
  90197. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90198. if(0 == encoder->private_->verify.decoder) {
  90199. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90200. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90201. }
  90202. if(FLAC__stream_decoder_init_stream(encoder->private_->verify.decoder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callback_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
  90203. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90204. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90205. }
  90206. }
  90207. encoder->private_->verify.error_stats.absolute_sample = 0;
  90208. encoder->private_->verify.error_stats.frame_number = 0;
  90209. encoder->private_->verify.error_stats.channel = 0;
  90210. encoder->private_->verify.error_stats.sample = 0;
  90211. encoder->private_->verify.error_stats.expected = 0;
  90212. encoder->private_->verify.error_stats.got = 0;
  90213. encoder->private_->first_seekpoint_to_check = 0;
  90214. encoder->private_->samples_written = 0;
  90215. encoder->protected_->streaminfo_offset = 0;
  90216. encoder->protected_->seektable_offset = 0;
  90217. encoder->protected_->audio_offset = 0;
  90218. if(encoder->protected_->verify)
  90219. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90220. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90221. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90222. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90223. }
  90224. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90225. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90226. }
  90227. if(encoder->protected_->verify)
  90228. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90229. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90230. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90231. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90232. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90233. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90234. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90235. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90236. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90237. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90238. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90239. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90240. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90241. if(encoder->protected_->do_md5)
  90242. FLAC__MD5Init(&encoder->private_->md5context);
  90243. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90244. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90245. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90246. }
  90247. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90248. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90249. }
  90250. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90251. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90252. if(!metadata_has_vorbis_comment) {
  90253. FLAC__StreamMetadata vorbis_comment;
  90254. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90255. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90256. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90257. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90258. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90259. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90260. vorbis_comment.data.vorbis_comment.comments = 0;
  90261. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90262. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90263. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90264. }
  90265. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90266. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90267. }
  90268. }
  90269. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90270. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90271. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90272. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90273. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90274. }
  90275. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90276. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90277. }
  90278. }
  90279. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &encoder->protected_->audio_offset, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) { /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */
  90280. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90281. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90282. }
  90283. if(encoder->protected_->verify)
  90284. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90285. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90286. }
  90287. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90288. FLAC__StreamEncoder *encoder,
  90289. FLAC__StreamEncoderWriteCallback write_callback,
  90290. FLAC__StreamEncoderSeekCallback seek_callback,
  90291. FLAC__StreamEncoderTellCallback tell_callback,
  90292. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90293. void *client_data
  90294. )
  90295. {
  90296. return init_stream_internal_enc(
  90297. encoder,
  90298. 0,
  90299. write_callback,
  90300. seek_callback,
  90301. tell_callback,
  90302. metadata_callback,
  90303. client_data,
  90304. false
  90305. );
  90306. }
  90307. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90308. FLAC__StreamEncoder *encoder,
  90309. FLAC__StreamEncoderReadCallback read_callback,
  90310. FLAC__StreamEncoderWriteCallback write_callback,
  90311. FLAC__StreamEncoderSeekCallback seek_callback,
  90312. FLAC__StreamEncoderTellCallback tell_callback,
  90313. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90314. void *client_data
  90315. )
  90316. {
  90317. return init_stream_internal_enc(
  90318. encoder,
  90319. read_callback,
  90320. write_callback,
  90321. seek_callback,
  90322. tell_callback,
  90323. metadata_callback,
  90324. client_data,
  90325. true
  90326. );
  90327. }
  90328. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90329. FLAC__StreamEncoder *encoder,
  90330. FILE *file,
  90331. FLAC__StreamEncoderProgressCallback progress_callback,
  90332. void *client_data,
  90333. FLAC__bool is_ogg
  90334. )
  90335. {
  90336. FLAC__StreamEncoderInitStatus init_status;
  90337. FLAC__ASSERT(0 != encoder);
  90338. FLAC__ASSERT(0 != file);
  90339. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90340. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90341. if(file == 0) {
  90342. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90343. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90344. }
  90345. if(file == stdout)
  90346. file = get_binary_stdout_(); /* just to be safe */
  90347. encoder->private_->file = file;
  90348. encoder->private_->progress_callback = progress_callback;
  90349. encoder->private_->bytes_written = 0;
  90350. encoder->private_->samples_written = 0;
  90351. encoder->private_->frames_written = 0;
  90352. init_status = init_stream_internal_enc(
  90353. encoder,
  90354. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90355. file_write_callback_,
  90356. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90357. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90358. 0,
  90359. client_data,
  90360. is_ogg
  90361. );
  90362. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90363. return init_status;
  90364. }
  90365. {
  90366. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90367. FLAC__ASSERT(blocksize != 0);
  90368. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90369. }
  90370. return init_status;
  90371. }
  90372. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90373. FLAC__StreamEncoder *encoder,
  90374. FILE *file,
  90375. FLAC__StreamEncoderProgressCallback progress_callback,
  90376. void *client_data
  90377. )
  90378. {
  90379. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90380. }
  90381. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90382. FLAC__StreamEncoder *encoder,
  90383. FILE *file,
  90384. FLAC__StreamEncoderProgressCallback progress_callback,
  90385. void *client_data
  90386. )
  90387. {
  90388. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90389. }
  90390. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90391. FLAC__StreamEncoder *encoder,
  90392. const char *filename,
  90393. FLAC__StreamEncoderProgressCallback progress_callback,
  90394. void *client_data,
  90395. FLAC__bool is_ogg
  90396. )
  90397. {
  90398. FILE *file;
  90399. FLAC__ASSERT(0 != encoder);
  90400. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90401. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90402. file = filename? fopen(filename, "w+b") : stdout;
  90403. if(file == 0) {
  90404. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90405. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90406. }
  90407. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90408. }
  90409. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90410. FLAC__StreamEncoder *encoder,
  90411. const char *filename,
  90412. FLAC__StreamEncoderProgressCallback progress_callback,
  90413. void *client_data
  90414. )
  90415. {
  90416. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90417. }
  90418. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90419. FLAC__StreamEncoder *encoder,
  90420. const char *filename,
  90421. FLAC__StreamEncoderProgressCallback progress_callback,
  90422. void *client_data
  90423. )
  90424. {
  90425. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90426. }
  90427. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90428. {
  90429. FLAC__bool error = false;
  90430. FLAC__ASSERT(0 != encoder);
  90431. FLAC__ASSERT(0 != encoder->private_);
  90432. FLAC__ASSERT(0 != encoder->protected_);
  90433. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90434. return true;
  90435. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90436. if(encoder->private_->current_sample_number != 0) {
  90437. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90438. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90439. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90440. error = true;
  90441. }
  90442. }
  90443. if(encoder->protected_->do_md5)
  90444. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90445. if(!encoder->private_->is_being_deleted) {
  90446. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90447. if(encoder->private_->seek_callback) {
  90448. #if FLAC__HAS_OGG
  90449. if(encoder->private_->is_ogg)
  90450. update_ogg_metadata_(encoder);
  90451. else
  90452. #endif
  90453. update_metadata_(encoder);
  90454. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90455. error = true;
  90456. }
  90457. if(encoder->private_->metadata_callback)
  90458. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90459. }
  90460. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90461. if(!error)
  90462. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90463. error = true;
  90464. }
  90465. }
  90466. if(0 != encoder->private_->file) {
  90467. if(encoder->private_->file != stdout)
  90468. fclose(encoder->private_->file);
  90469. encoder->private_->file = 0;
  90470. }
  90471. #if FLAC__HAS_OGG
  90472. if(encoder->private_->is_ogg)
  90473. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90474. #endif
  90475. free_(encoder);
  90476. set_defaults_enc(encoder);
  90477. if(!error)
  90478. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90479. return !error;
  90480. }
  90481. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90482. {
  90483. FLAC__ASSERT(0 != encoder);
  90484. FLAC__ASSERT(0 != encoder->private_);
  90485. FLAC__ASSERT(0 != encoder->protected_);
  90486. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90487. return false;
  90488. #if FLAC__HAS_OGG
  90489. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90490. return true;
  90491. #else
  90492. (void)value;
  90493. return false;
  90494. #endif
  90495. }
  90496. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90497. {
  90498. FLAC__ASSERT(0 != encoder);
  90499. FLAC__ASSERT(0 != encoder->private_);
  90500. FLAC__ASSERT(0 != encoder->protected_);
  90501. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90502. return false;
  90503. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90504. encoder->protected_->verify = value;
  90505. #endif
  90506. return true;
  90507. }
  90508. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90509. {
  90510. FLAC__ASSERT(0 != encoder);
  90511. FLAC__ASSERT(0 != encoder->private_);
  90512. FLAC__ASSERT(0 != encoder->protected_);
  90513. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90514. return false;
  90515. encoder->protected_->streamable_subset = value;
  90516. return true;
  90517. }
  90518. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90519. {
  90520. FLAC__ASSERT(0 != encoder);
  90521. FLAC__ASSERT(0 != encoder->private_);
  90522. FLAC__ASSERT(0 != encoder->protected_);
  90523. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90524. return false;
  90525. encoder->protected_->do_md5 = value;
  90526. return true;
  90527. }
  90528. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90529. {
  90530. FLAC__ASSERT(0 != encoder);
  90531. FLAC__ASSERT(0 != encoder->private_);
  90532. FLAC__ASSERT(0 != encoder->protected_);
  90533. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90534. return false;
  90535. encoder->protected_->channels = value;
  90536. return true;
  90537. }
  90538. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90539. {
  90540. FLAC__ASSERT(0 != encoder);
  90541. FLAC__ASSERT(0 != encoder->private_);
  90542. FLAC__ASSERT(0 != encoder->protected_);
  90543. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90544. return false;
  90545. encoder->protected_->bits_per_sample = value;
  90546. return true;
  90547. }
  90548. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90549. {
  90550. FLAC__ASSERT(0 != encoder);
  90551. FLAC__ASSERT(0 != encoder->private_);
  90552. FLAC__ASSERT(0 != encoder->protected_);
  90553. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90554. return false;
  90555. encoder->protected_->sample_rate = value;
  90556. return true;
  90557. }
  90558. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90559. {
  90560. FLAC__bool ok = true;
  90561. FLAC__ASSERT(0 != encoder);
  90562. FLAC__ASSERT(0 != encoder->private_);
  90563. FLAC__ASSERT(0 != encoder->protected_);
  90564. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90565. return false;
  90566. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90567. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90568. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90569. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90570. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90571. #if 0
  90572. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90573. #else
  90574. encoder->protected_->num_apodizations = 1;
  90575. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90576. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90577. #endif
  90578. #endif
  90579. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90580. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90581. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90582. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90583. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90584. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90585. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90586. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90587. return ok;
  90588. }
  90589. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90590. {
  90591. FLAC__ASSERT(0 != encoder);
  90592. FLAC__ASSERT(0 != encoder->private_);
  90593. FLAC__ASSERT(0 != encoder->protected_);
  90594. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90595. return false;
  90596. encoder->protected_->blocksize = value;
  90597. return true;
  90598. }
  90599. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90600. {
  90601. FLAC__ASSERT(0 != encoder);
  90602. FLAC__ASSERT(0 != encoder->private_);
  90603. FLAC__ASSERT(0 != encoder->protected_);
  90604. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90605. return false;
  90606. encoder->protected_->do_mid_side_stereo = value;
  90607. return true;
  90608. }
  90609. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90610. {
  90611. FLAC__ASSERT(0 != encoder);
  90612. FLAC__ASSERT(0 != encoder->private_);
  90613. FLAC__ASSERT(0 != encoder->protected_);
  90614. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90615. return false;
  90616. encoder->protected_->loose_mid_side_stereo = value;
  90617. return true;
  90618. }
  90619. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90620. {
  90621. FLAC__ASSERT(0 != encoder);
  90622. FLAC__ASSERT(0 != encoder->private_);
  90623. FLAC__ASSERT(0 != encoder->protected_);
  90624. FLAC__ASSERT(0 != specification);
  90625. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90626. return false;
  90627. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90628. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90629. #else
  90630. encoder->protected_->num_apodizations = 0;
  90631. while(1) {
  90632. const char *s = strchr(specification, ';');
  90633. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90634. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90635. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90636. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90637. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90638. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90639. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90640. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90641. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90642. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90643. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90644. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90645. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90646. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90647. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90648. if (stddev > 0.0 && stddev <= 0.5) {
  90649. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90650. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90651. }
  90652. }
  90653. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90654. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90655. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90656. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90657. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90658. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90659. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90660. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90661. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90662. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90663. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90664. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90665. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90666. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90667. if (p >= 0.0 && p <= 1.0) {
  90668. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90669. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90670. }
  90671. }
  90672. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90673. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90674. if (encoder->protected_->num_apodizations == 32)
  90675. break;
  90676. if (s)
  90677. specification = s+1;
  90678. else
  90679. break;
  90680. }
  90681. if(encoder->protected_->num_apodizations == 0) {
  90682. encoder->protected_->num_apodizations = 1;
  90683. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90684. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90685. }
  90686. #endif
  90687. return true;
  90688. }
  90689. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90690. {
  90691. FLAC__ASSERT(0 != encoder);
  90692. FLAC__ASSERT(0 != encoder->private_);
  90693. FLAC__ASSERT(0 != encoder->protected_);
  90694. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90695. return false;
  90696. encoder->protected_->max_lpc_order = value;
  90697. return true;
  90698. }
  90699. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90700. {
  90701. FLAC__ASSERT(0 != encoder);
  90702. FLAC__ASSERT(0 != encoder->private_);
  90703. FLAC__ASSERT(0 != encoder->protected_);
  90704. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90705. return false;
  90706. encoder->protected_->qlp_coeff_precision = value;
  90707. return true;
  90708. }
  90709. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90710. {
  90711. FLAC__ASSERT(0 != encoder);
  90712. FLAC__ASSERT(0 != encoder->private_);
  90713. FLAC__ASSERT(0 != encoder->protected_);
  90714. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90715. return false;
  90716. encoder->protected_->do_qlp_coeff_prec_search = value;
  90717. return true;
  90718. }
  90719. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90720. {
  90721. FLAC__ASSERT(0 != encoder);
  90722. FLAC__ASSERT(0 != encoder->private_);
  90723. FLAC__ASSERT(0 != encoder->protected_);
  90724. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90725. return false;
  90726. #if 0
  90727. encoder->protected_->do_escape_coding = value;
  90728. #else
  90729. (void)value;
  90730. #endif
  90731. return true;
  90732. }
  90733. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90734. {
  90735. FLAC__ASSERT(0 != encoder);
  90736. FLAC__ASSERT(0 != encoder->private_);
  90737. FLAC__ASSERT(0 != encoder->protected_);
  90738. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90739. return false;
  90740. encoder->protected_->do_exhaustive_model_search = value;
  90741. return true;
  90742. }
  90743. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90744. {
  90745. FLAC__ASSERT(0 != encoder);
  90746. FLAC__ASSERT(0 != encoder->private_);
  90747. FLAC__ASSERT(0 != encoder->protected_);
  90748. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90749. return false;
  90750. encoder->protected_->min_residual_partition_order = value;
  90751. return true;
  90752. }
  90753. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90754. {
  90755. FLAC__ASSERT(0 != encoder);
  90756. FLAC__ASSERT(0 != encoder->private_);
  90757. FLAC__ASSERT(0 != encoder->protected_);
  90758. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90759. return false;
  90760. encoder->protected_->max_residual_partition_order = value;
  90761. return true;
  90762. }
  90763. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90764. {
  90765. FLAC__ASSERT(0 != encoder);
  90766. FLAC__ASSERT(0 != encoder->private_);
  90767. FLAC__ASSERT(0 != encoder->protected_);
  90768. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90769. return false;
  90770. #if 0
  90771. encoder->protected_->rice_parameter_search_dist = value;
  90772. #else
  90773. (void)value;
  90774. #endif
  90775. return true;
  90776. }
  90777. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  90778. {
  90779. FLAC__ASSERT(0 != encoder);
  90780. FLAC__ASSERT(0 != encoder->private_);
  90781. FLAC__ASSERT(0 != encoder->protected_);
  90782. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90783. return false;
  90784. encoder->protected_->total_samples_estimate = value;
  90785. return true;
  90786. }
  90787. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  90788. {
  90789. FLAC__ASSERT(0 != encoder);
  90790. FLAC__ASSERT(0 != encoder->private_);
  90791. FLAC__ASSERT(0 != encoder->protected_);
  90792. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90793. return false;
  90794. if(0 == metadata)
  90795. num_blocks = 0;
  90796. if(0 == num_blocks)
  90797. metadata = 0;
  90798. if(encoder->protected_->metadata) {
  90799. free(encoder->protected_->metadata);
  90800. encoder->protected_->metadata = 0;
  90801. encoder->protected_->num_metadata_blocks = 0;
  90802. }
  90803. if(num_blocks) {
  90804. FLAC__StreamMetadata **m;
  90805. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90806. return false;
  90807. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90808. encoder->protected_->metadata = m;
  90809. encoder->protected_->num_metadata_blocks = num_blocks;
  90810. }
  90811. #if FLAC__HAS_OGG
  90812. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  90813. return false;
  90814. #endif
  90815. return true;
  90816. }
  90817. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90818. {
  90819. FLAC__ASSERT(0 != encoder);
  90820. FLAC__ASSERT(0 != encoder->private_);
  90821. FLAC__ASSERT(0 != encoder->protected_);
  90822. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90823. return false;
  90824. encoder->private_->disable_constant_subframes = value;
  90825. return true;
  90826. }
  90827. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90828. {
  90829. FLAC__ASSERT(0 != encoder);
  90830. FLAC__ASSERT(0 != encoder->private_);
  90831. FLAC__ASSERT(0 != encoder->protected_);
  90832. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90833. return false;
  90834. encoder->private_->disable_fixed_subframes = value;
  90835. return true;
  90836. }
  90837. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90838. {
  90839. FLAC__ASSERT(0 != encoder);
  90840. FLAC__ASSERT(0 != encoder->private_);
  90841. FLAC__ASSERT(0 != encoder->protected_);
  90842. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90843. return false;
  90844. encoder->private_->disable_verbatim_subframes = value;
  90845. return true;
  90846. }
  90847. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  90848. {
  90849. FLAC__ASSERT(0 != encoder);
  90850. FLAC__ASSERT(0 != encoder->private_);
  90851. FLAC__ASSERT(0 != encoder->protected_);
  90852. return encoder->protected_->state;
  90853. }
  90854. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  90855. {
  90856. FLAC__ASSERT(0 != encoder);
  90857. FLAC__ASSERT(0 != encoder->private_);
  90858. FLAC__ASSERT(0 != encoder->protected_);
  90859. if(encoder->protected_->verify)
  90860. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  90861. else
  90862. return FLAC__STREAM_DECODER_UNINITIALIZED;
  90863. }
  90864. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  90865. {
  90866. FLAC__ASSERT(0 != encoder);
  90867. FLAC__ASSERT(0 != encoder->private_);
  90868. FLAC__ASSERT(0 != encoder->protected_);
  90869. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  90870. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  90871. else
  90872. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  90873. }
  90874. FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
  90875. {
  90876. FLAC__ASSERT(0 != encoder);
  90877. FLAC__ASSERT(0 != encoder->private_);
  90878. FLAC__ASSERT(0 != encoder->protected_);
  90879. if(0 != absolute_sample)
  90880. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  90881. if(0 != frame_number)
  90882. *frame_number = encoder->private_->verify.error_stats.frame_number;
  90883. if(0 != channel)
  90884. *channel = encoder->private_->verify.error_stats.channel;
  90885. if(0 != sample)
  90886. *sample = encoder->private_->verify.error_stats.sample;
  90887. if(0 != expected)
  90888. *expected = encoder->private_->verify.error_stats.expected;
  90889. if(0 != got)
  90890. *got = encoder->private_->verify.error_stats.got;
  90891. }
  90892. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  90893. {
  90894. FLAC__ASSERT(0 != encoder);
  90895. FLAC__ASSERT(0 != encoder->private_);
  90896. FLAC__ASSERT(0 != encoder->protected_);
  90897. return encoder->protected_->verify;
  90898. }
  90899. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  90900. {
  90901. FLAC__ASSERT(0 != encoder);
  90902. FLAC__ASSERT(0 != encoder->private_);
  90903. FLAC__ASSERT(0 != encoder->protected_);
  90904. return encoder->protected_->streamable_subset;
  90905. }
  90906. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  90907. {
  90908. FLAC__ASSERT(0 != encoder);
  90909. FLAC__ASSERT(0 != encoder->private_);
  90910. FLAC__ASSERT(0 != encoder->protected_);
  90911. return encoder->protected_->do_md5;
  90912. }
  90913. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  90914. {
  90915. FLAC__ASSERT(0 != encoder);
  90916. FLAC__ASSERT(0 != encoder->private_);
  90917. FLAC__ASSERT(0 != encoder->protected_);
  90918. return encoder->protected_->channels;
  90919. }
  90920. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  90921. {
  90922. FLAC__ASSERT(0 != encoder);
  90923. FLAC__ASSERT(0 != encoder->private_);
  90924. FLAC__ASSERT(0 != encoder->protected_);
  90925. return encoder->protected_->bits_per_sample;
  90926. }
  90927. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  90928. {
  90929. FLAC__ASSERT(0 != encoder);
  90930. FLAC__ASSERT(0 != encoder->private_);
  90931. FLAC__ASSERT(0 != encoder->protected_);
  90932. return encoder->protected_->sample_rate;
  90933. }
  90934. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  90935. {
  90936. FLAC__ASSERT(0 != encoder);
  90937. FLAC__ASSERT(0 != encoder->private_);
  90938. FLAC__ASSERT(0 != encoder->protected_);
  90939. return encoder->protected_->blocksize;
  90940. }
  90941. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  90942. {
  90943. FLAC__ASSERT(0 != encoder);
  90944. FLAC__ASSERT(0 != encoder->private_);
  90945. FLAC__ASSERT(0 != encoder->protected_);
  90946. return encoder->protected_->do_mid_side_stereo;
  90947. }
  90948. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  90949. {
  90950. FLAC__ASSERT(0 != encoder);
  90951. FLAC__ASSERT(0 != encoder->private_);
  90952. FLAC__ASSERT(0 != encoder->protected_);
  90953. return encoder->protected_->loose_mid_side_stereo;
  90954. }
  90955. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  90956. {
  90957. FLAC__ASSERT(0 != encoder);
  90958. FLAC__ASSERT(0 != encoder->private_);
  90959. FLAC__ASSERT(0 != encoder->protected_);
  90960. return encoder->protected_->max_lpc_order;
  90961. }
  90962. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  90963. {
  90964. FLAC__ASSERT(0 != encoder);
  90965. FLAC__ASSERT(0 != encoder->private_);
  90966. FLAC__ASSERT(0 != encoder->protected_);
  90967. return encoder->protected_->qlp_coeff_precision;
  90968. }
  90969. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  90970. {
  90971. FLAC__ASSERT(0 != encoder);
  90972. FLAC__ASSERT(0 != encoder->private_);
  90973. FLAC__ASSERT(0 != encoder->protected_);
  90974. return encoder->protected_->do_qlp_coeff_prec_search;
  90975. }
  90976. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  90977. {
  90978. FLAC__ASSERT(0 != encoder);
  90979. FLAC__ASSERT(0 != encoder->private_);
  90980. FLAC__ASSERT(0 != encoder->protected_);
  90981. return encoder->protected_->do_escape_coding;
  90982. }
  90983. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  90984. {
  90985. FLAC__ASSERT(0 != encoder);
  90986. FLAC__ASSERT(0 != encoder->private_);
  90987. FLAC__ASSERT(0 != encoder->protected_);
  90988. return encoder->protected_->do_exhaustive_model_search;
  90989. }
  90990. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  90991. {
  90992. FLAC__ASSERT(0 != encoder);
  90993. FLAC__ASSERT(0 != encoder->private_);
  90994. FLAC__ASSERT(0 != encoder->protected_);
  90995. return encoder->protected_->min_residual_partition_order;
  90996. }
  90997. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  90998. {
  90999. FLAC__ASSERT(0 != encoder);
  91000. FLAC__ASSERT(0 != encoder->private_);
  91001. FLAC__ASSERT(0 != encoder->protected_);
  91002. return encoder->protected_->max_residual_partition_order;
  91003. }
  91004. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91005. {
  91006. FLAC__ASSERT(0 != encoder);
  91007. FLAC__ASSERT(0 != encoder->private_);
  91008. FLAC__ASSERT(0 != encoder->protected_);
  91009. return encoder->protected_->rice_parameter_search_dist;
  91010. }
  91011. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91012. {
  91013. FLAC__ASSERT(0 != encoder);
  91014. FLAC__ASSERT(0 != encoder->private_);
  91015. FLAC__ASSERT(0 != encoder->protected_);
  91016. return encoder->protected_->total_samples_estimate;
  91017. }
  91018. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91019. {
  91020. unsigned i, j = 0, channel;
  91021. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91022. FLAC__ASSERT(0 != encoder);
  91023. FLAC__ASSERT(0 != encoder->private_);
  91024. FLAC__ASSERT(0 != encoder->protected_);
  91025. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91026. do {
  91027. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91028. if(encoder->protected_->verify)
  91029. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91030. for(channel = 0; channel < channels; channel++)
  91031. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91032. if(encoder->protected_->do_mid_side_stereo) {
  91033. FLAC__ASSERT(channels == 2);
  91034. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91035. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91036. encoder->private_->integer_signal_mid_side[0][i] = (buffer[0][j] + buffer[1][j]) >> 1; /* NOTE: not the same as 'mid = (buffer[0][j] + buffer[1][j]) / 2' ! */
  91037. }
  91038. }
  91039. else
  91040. j += n;
  91041. encoder->private_->current_sample_number += n;
  91042. if(encoder->private_->current_sample_number > blocksize) {
  91043. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91044. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91045. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91046. return false;
  91047. for(channel = 0; channel < channels; channel++)
  91048. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91049. if(encoder->protected_->do_mid_side_stereo) {
  91050. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91051. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91052. }
  91053. encoder->private_->current_sample_number = 1;
  91054. }
  91055. } while(j < samples);
  91056. return true;
  91057. }
  91058. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91059. {
  91060. unsigned i, j, k, channel;
  91061. FLAC__int32 x, mid, side;
  91062. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91063. FLAC__ASSERT(0 != encoder);
  91064. FLAC__ASSERT(0 != encoder->private_);
  91065. FLAC__ASSERT(0 != encoder->protected_);
  91066. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91067. j = k = 0;
  91068. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91069. do {
  91070. if(encoder->protected_->verify)
  91071. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91072. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91073. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91074. x = buffer[k++];
  91075. encoder->private_->integer_signal[1][i] = x;
  91076. mid += x;
  91077. side -= x;
  91078. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91079. encoder->private_->integer_signal_mid_side[1][i] = side;
  91080. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91081. }
  91082. encoder->private_->current_sample_number = i;
  91083. if(i > blocksize) {
  91084. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91085. return false;
  91086. /* move unprocessed overread samples to beginnings of arrays */
  91087. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91088. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91089. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91090. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91091. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91092. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91093. encoder->private_->current_sample_number = 1;
  91094. }
  91095. } while(j < samples);
  91096. }
  91097. else {
  91098. do {
  91099. if(encoder->protected_->verify)
  91100. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91101. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91102. for(channel = 0; channel < channels; channel++)
  91103. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91104. }
  91105. encoder->private_->current_sample_number = i;
  91106. if(i > blocksize) {
  91107. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91108. return false;
  91109. /* move unprocessed overread samples to beginnings of arrays */
  91110. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91111. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91112. for(channel = 0; channel < channels; channel++)
  91113. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91114. encoder->private_->current_sample_number = 1;
  91115. }
  91116. } while(j < samples);
  91117. }
  91118. return true;
  91119. }
  91120. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91121. {
  91122. FLAC__ASSERT(0 != encoder);
  91123. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91124. encoder->protected_->verify = true;
  91125. #else
  91126. encoder->protected_->verify = false;
  91127. #endif
  91128. encoder->protected_->streamable_subset = true;
  91129. encoder->protected_->do_md5 = true;
  91130. encoder->protected_->do_mid_side_stereo = false;
  91131. encoder->protected_->loose_mid_side_stereo = false;
  91132. encoder->protected_->channels = 2;
  91133. encoder->protected_->bits_per_sample = 16;
  91134. encoder->protected_->sample_rate = 44100;
  91135. encoder->protected_->blocksize = 0;
  91136. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91137. encoder->protected_->num_apodizations = 1;
  91138. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91139. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91140. #endif
  91141. encoder->protected_->max_lpc_order = 0;
  91142. encoder->protected_->qlp_coeff_precision = 0;
  91143. encoder->protected_->do_qlp_coeff_prec_search = false;
  91144. encoder->protected_->do_exhaustive_model_search = false;
  91145. encoder->protected_->do_escape_coding = false;
  91146. encoder->protected_->min_residual_partition_order = 0;
  91147. encoder->protected_->max_residual_partition_order = 0;
  91148. encoder->protected_->rice_parameter_search_dist = 0;
  91149. encoder->protected_->total_samples_estimate = 0;
  91150. encoder->protected_->metadata = 0;
  91151. encoder->protected_->num_metadata_blocks = 0;
  91152. encoder->private_->seek_table = 0;
  91153. encoder->private_->disable_constant_subframes = false;
  91154. encoder->private_->disable_fixed_subframes = false;
  91155. encoder->private_->disable_verbatim_subframes = false;
  91156. #if FLAC__HAS_OGG
  91157. encoder->private_->is_ogg = false;
  91158. #endif
  91159. encoder->private_->read_callback = 0;
  91160. encoder->private_->write_callback = 0;
  91161. encoder->private_->seek_callback = 0;
  91162. encoder->private_->tell_callback = 0;
  91163. encoder->private_->metadata_callback = 0;
  91164. encoder->private_->progress_callback = 0;
  91165. encoder->private_->client_data = 0;
  91166. #if FLAC__HAS_OGG
  91167. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91168. #endif
  91169. }
  91170. void free_(FLAC__StreamEncoder *encoder)
  91171. {
  91172. unsigned i, channel;
  91173. FLAC__ASSERT(0 != encoder);
  91174. if(encoder->protected_->metadata) {
  91175. free(encoder->protected_->metadata);
  91176. encoder->protected_->metadata = 0;
  91177. encoder->protected_->num_metadata_blocks = 0;
  91178. }
  91179. for(i = 0; i < encoder->protected_->channels; i++) {
  91180. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91181. free(encoder->private_->integer_signal_unaligned[i]);
  91182. encoder->private_->integer_signal_unaligned[i] = 0;
  91183. }
  91184. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91185. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91186. free(encoder->private_->real_signal_unaligned[i]);
  91187. encoder->private_->real_signal_unaligned[i] = 0;
  91188. }
  91189. #endif
  91190. }
  91191. for(i = 0; i < 2; i++) {
  91192. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91193. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91194. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91195. }
  91196. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91197. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91198. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91199. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91200. }
  91201. #endif
  91202. }
  91203. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91204. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91205. if(0 != encoder->private_->window_unaligned[i]) {
  91206. free(encoder->private_->window_unaligned[i]);
  91207. encoder->private_->window_unaligned[i] = 0;
  91208. }
  91209. }
  91210. if(0 != encoder->private_->windowed_signal_unaligned) {
  91211. free(encoder->private_->windowed_signal_unaligned);
  91212. encoder->private_->windowed_signal_unaligned = 0;
  91213. }
  91214. #endif
  91215. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91216. for(i = 0; i < 2; i++) {
  91217. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91218. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91219. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91220. }
  91221. }
  91222. }
  91223. for(channel = 0; channel < 2; channel++) {
  91224. for(i = 0; i < 2; i++) {
  91225. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91226. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91227. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91228. }
  91229. }
  91230. }
  91231. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91232. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91233. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91234. }
  91235. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91236. free(encoder->private_->raw_bits_per_partition_unaligned);
  91237. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91238. }
  91239. if(encoder->protected_->verify) {
  91240. for(i = 0; i < encoder->protected_->channels; i++) {
  91241. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91242. free(encoder->private_->verify.input_fifo.data[i]);
  91243. encoder->private_->verify.input_fifo.data[i] = 0;
  91244. }
  91245. }
  91246. }
  91247. FLAC__bitwriter_free(encoder->private_->frame);
  91248. }
  91249. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91250. {
  91251. FLAC__bool ok;
  91252. unsigned i, channel;
  91253. FLAC__ASSERT(new_blocksize > 0);
  91254. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91255. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91256. if(new_blocksize <= encoder->private_->input_capacity)
  91257. return true;
  91258. ok = true;
  91259. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91260. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91261. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91262. encoder->private_->integer_signal[i] += 4;
  91263. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91264. #if 0 /* @@@ currently unused */
  91265. if(encoder->protected_->max_lpc_order > 0)
  91266. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91267. #endif
  91268. #endif
  91269. }
  91270. for(i = 0; ok && i < 2; i++) {
  91271. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_mid_side_unaligned[i], &encoder->private_->integer_signal_mid_side[i]);
  91272. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91273. encoder->private_->integer_signal_mid_side[i] += 4;
  91274. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91275. #if 0 /* @@@ currently unused */
  91276. if(encoder->protected_->max_lpc_order > 0)
  91277. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_mid_side_unaligned[i], &encoder->private_->real_signal_mid_side[i]);
  91278. #endif
  91279. #endif
  91280. }
  91281. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91282. if(ok && encoder->protected_->max_lpc_order > 0) {
  91283. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91284. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91285. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91286. }
  91287. #endif
  91288. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91289. for(i = 0; ok && i < 2; i++) {
  91290. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91291. }
  91292. }
  91293. for(channel = 0; ok && channel < 2; channel++) {
  91294. for(i = 0; ok && i < 2; i++) {
  91295. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_mid_side_unaligned[channel][i], &encoder->private_->residual_workspace_mid_side[channel][i]);
  91296. }
  91297. }
  91298. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91299. if(encoder->protected_->do_escape_coding)
  91300. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91301. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91302. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91303. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91304. switch(encoder->protected_->apodizations[i].type) {
  91305. case FLAC__APODIZATION_BARTLETT:
  91306. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91307. break;
  91308. case FLAC__APODIZATION_BARTLETT_HANN:
  91309. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91310. break;
  91311. case FLAC__APODIZATION_BLACKMAN:
  91312. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91313. break;
  91314. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91315. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91316. break;
  91317. case FLAC__APODIZATION_CONNES:
  91318. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91319. break;
  91320. case FLAC__APODIZATION_FLATTOP:
  91321. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91322. break;
  91323. case FLAC__APODIZATION_GAUSS:
  91324. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91325. break;
  91326. case FLAC__APODIZATION_HAMMING:
  91327. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91328. break;
  91329. case FLAC__APODIZATION_HANN:
  91330. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91331. break;
  91332. case FLAC__APODIZATION_KAISER_BESSEL:
  91333. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91334. break;
  91335. case FLAC__APODIZATION_NUTTALL:
  91336. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91337. break;
  91338. case FLAC__APODIZATION_RECTANGLE:
  91339. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91340. break;
  91341. case FLAC__APODIZATION_TRIANGLE:
  91342. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91343. break;
  91344. case FLAC__APODIZATION_TUKEY:
  91345. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91346. break;
  91347. case FLAC__APODIZATION_WELCH:
  91348. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91349. break;
  91350. default:
  91351. FLAC__ASSERT(0);
  91352. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91353. break;
  91354. }
  91355. }
  91356. }
  91357. #endif
  91358. if(ok)
  91359. encoder->private_->input_capacity = new_blocksize;
  91360. else
  91361. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91362. return ok;
  91363. }
  91364. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91365. {
  91366. const FLAC__byte *buffer;
  91367. size_t bytes;
  91368. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91369. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91370. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91371. return false;
  91372. }
  91373. if(encoder->protected_->verify) {
  91374. encoder->private_->verify.output.data = buffer;
  91375. encoder->private_->verify.output.bytes = bytes;
  91376. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91377. encoder->private_->verify.needs_magic_hack = true;
  91378. }
  91379. else {
  91380. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91381. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91382. FLAC__bitwriter_clear(encoder->private_->frame);
  91383. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91384. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91385. return false;
  91386. }
  91387. }
  91388. }
  91389. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91390. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91391. FLAC__bitwriter_clear(encoder->private_->frame);
  91392. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91393. return false;
  91394. }
  91395. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91396. FLAC__bitwriter_clear(encoder->private_->frame);
  91397. if(samples > 0) {
  91398. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91399. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91400. }
  91401. return true;
  91402. }
  91403. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91404. {
  91405. FLAC__StreamEncoderWriteStatus status;
  91406. FLAC__uint64 output_position = 0;
  91407. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91408. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91409. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91410. }
  91411. if(samples == 0) {
  91412. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91413. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91414. encoder->protected_->streaminfo_offset = output_position;
  91415. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91416. encoder->protected_->seektable_offset = output_position;
  91417. }
  91418. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91419. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91420. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91421. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91422. FLAC__uint64 test_sample;
  91423. unsigned i;
  91424. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91425. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91426. if(test_sample > frame_last_sample) {
  91427. break;
  91428. }
  91429. else if(test_sample >= frame_first_sample) {
  91430. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91431. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91432. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91433. encoder->private_->first_seekpoint_to_check++;
  91434. }
  91435. else {
  91436. encoder->private_->first_seekpoint_to_check++;
  91437. }
  91438. }
  91439. }
  91440. #if FLAC__HAS_OGG
  91441. if(encoder->private_->is_ogg) {
  91442. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91443. &encoder->protected_->ogg_encoder_aspect,
  91444. buffer,
  91445. bytes,
  91446. samples,
  91447. encoder->private_->current_frame_number,
  91448. is_last_block,
  91449. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91450. encoder,
  91451. encoder->private_->client_data
  91452. );
  91453. }
  91454. else
  91455. #endif
  91456. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91457. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91458. encoder->private_->bytes_written += bytes;
  91459. encoder->private_->samples_written += samples;
  91460. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91461. }
  91462. else
  91463. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91464. return status;
  91465. }
  91466. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91467. {
  91468. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91469. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91470. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91471. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91472. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91473. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91474. FLAC__StreamEncoderSeekStatus seek_status;
  91475. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91476. {
  91477. const unsigned md5_offset =
  91478. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91479. (
  91480. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91481. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91482. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91483. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91484. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91485. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91486. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91487. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91488. ) / 8;
  91489. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91490. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91491. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91492. return;
  91493. }
  91494. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91495. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91496. return;
  91497. }
  91498. }
  91499. {
  91500. const unsigned total_samples_byte_offset =
  91501. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91502. (
  91503. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91504. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91505. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91506. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91507. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91508. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91509. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91510. - 4
  91511. ) / 8;
  91512. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91513. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91514. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91515. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91516. b[4] = (FLAC__byte)(samples & 0xFF);
  91517. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + total_samples_byte_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91518. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91519. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91520. return;
  91521. }
  91522. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91523. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91524. return;
  91525. }
  91526. }
  91527. {
  91528. const unsigned min_framesize_offset =
  91529. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91530. (
  91531. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91532. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91533. ) / 8;
  91534. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91535. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91536. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91537. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91538. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91539. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91540. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + min_framesize_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91541. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91542. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91543. return;
  91544. }
  91545. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91546. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91547. return;
  91548. }
  91549. }
  91550. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91551. unsigned i;
  91552. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91553. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91554. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->seektable_offset + FLAC__STREAM_METADATA_HEADER_LENGTH, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91555. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91556. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91557. return;
  91558. }
  91559. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91560. FLAC__uint64 xx;
  91561. unsigned x;
  91562. xx = encoder->private_->seek_table->points[i].sample_number;
  91563. b[7] = (FLAC__byte)xx; xx >>= 8;
  91564. b[6] = (FLAC__byte)xx; xx >>= 8;
  91565. b[5] = (FLAC__byte)xx; xx >>= 8;
  91566. b[4] = (FLAC__byte)xx; xx >>= 8;
  91567. b[3] = (FLAC__byte)xx; xx >>= 8;
  91568. b[2] = (FLAC__byte)xx; xx >>= 8;
  91569. b[1] = (FLAC__byte)xx; xx >>= 8;
  91570. b[0] = (FLAC__byte)xx; xx >>= 8;
  91571. xx = encoder->private_->seek_table->points[i].stream_offset;
  91572. b[15] = (FLAC__byte)xx; xx >>= 8;
  91573. b[14] = (FLAC__byte)xx; xx >>= 8;
  91574. b[13] = (FLAC__byte)xx; xx >>= 8;
  91575. b[12] = (FLAC__byte)xx; xx >>= 8;
  91576. b[11] = (FLAC__byte)xx; xx >>= 8;
  91577. b[10] = (FLAC__byte)xx; xx >>= 8;
  91578. b[9] = (FLAC__byte)xx; xx >>= 8;
  91579. b[8] = (FLAC__byte)xx; xx >>= 8;
  91580. x = encoder->private_->seek_table->points[i].frame_samples;
  91581. b[17] = (FLAC__byte)x; x >>= 8;
  91582. b[16] = (FLAC__byte)x; x >>= 8;
  91583. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91584. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91585. return;
  91586. }
  91587. }
  91588. }
  91589. }
  91590. #if FLAC__HAS_OGG
  91591. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91592. {
  91593. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91594. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91595. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91596. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91597. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91598. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91599. FLAC__STREAM_SYNC_LENGTH
  91600. ;
  91601. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91602. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91603. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91604. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91605. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91606. ogg_page page;
  91607. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91608. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91609. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91610. return;
  91611. simple_ogg_page__init(&page);
  91612. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91613. simple_ogg_page__clear(&page);
  91614. return; /* state already set */
  91615. }
  91616. {
  91617. const unsigned md5_offset =
  91618. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91619. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91620. (
  91621. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91622. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91623. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91624. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91625. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91626. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91627. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91628. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91629. ) / 8;
  91630. if(md5_offset + 16 > (unsigned)page.body_len) {
  91631. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91632. simple_ogg_page__clear(&page);
  91633. return;
  91634. }
  91635. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91636. }
  91637. {
  91638. const unsigned total_samples_byte_offset =
  91639. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91640. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91641. (
  91642. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91643. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91644. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91645. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91646. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91647. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91648. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91649. - 4
  91650. ) / 8;
  91651. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91652. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91653. simple_ogg_page__clear(&page);
  91654. return;
  91655. }
  91656. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91657. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91658. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91659. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91660. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91661. b[4] = (FLAC__byte)(samples & 0xFF);
  91662. memcpy(page.body + total_samples_byte_offset, b, 5);
  91663. }
  91664. {
  91665. const unsigned min_framesize_offset =
  91666. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91667. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91668. (
  91669. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91670. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91671. ) / 8;
  91672. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91673. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91674. simple_ogg_page__clear(&page);
  91675. return;
  91676. }
  91677. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91678. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91679. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91680. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91681. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91682. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91683. memcpy(page.body + min_framesize_offset, b, 6);
  91684. }
  91685. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91686. simple_ogg_page__clear(&page);
  91687. return; /* state already set */
  91688. }
  91689. simple_ogg_page__clear(&page);
  91690. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91691. unsigned i;
  91692. FLAC__byte *p;
  91693. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91694. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91695. simple_ogg_page__init(&page);
  91696. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91697. simple_ogg_page__clear(&page);
  91698. return; /* state already set */
  91699. }
  91700. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91701. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91702. simple_ogg_page__clear(&page);
  91703. return;
  91704. }
  91705. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91706. FLAC__uint64 xx;
  91707. unsigned x;
  91708. xx = encoder->private_->seek_table->points[i].sample_number;
  91709. b[7] = (FLAC__byte)xx; xx >>= 8;
  91710. b[6] = (FLAC__byte)xx; xx >>= 8;
  91711. b[5] = (FLAC__byte)xx; xx >>= 8;
  91712. b[4] = (FLAC__byte)xx; xx >>= 8;
  91713. b[3] = (FLAC__byte)xx; xx >>= 8;
  91714. b[2] = (FLAC__byte)xx; xx >>= 8;
  91715. b[1] = (FLAC__byte)xx; xx >>= 8;
  91716. b[0] = (FLAC__byte)xx; xx >>= 8;
  91717. xx = encoder->private_->seek_table->points[i].stream_offset;
  91718. b[15] = (FLAC__byte)xx; xx >>= 8;
  91719. b[14] = (FLAC__byte)xx; xx >>= 8;
  91720. b[13] = (FLAC__byte)xx; xx >>= 8;
  91721. b[12] = (FLAC__byte)xx; xx >>= 8;
  91722. b[11] = (FLAC__byte)xx; xx >>= 8;
  91723. b[10] = (FLAC__byte)xx; xx >>= 8;
  91724. b[9] = (FLAC__byte)xx; xx >>= 8;
  91725. b[8] = (FLAC__byte)xx; xx >>= 8;
  91726. x = encoder->private_->seek_table->points[i].frame_samples;
  91727. b[17] = (FLAC__byte)x; x >>= 8;
  91728. b[16] = (FLAC__byte)x; x >>= 8;
  91729. memcpy(p, b, 18);
  91730. }
  91731. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91732. simple_ogg_page__clear(&page);
  91733. return; /* state already set */
  91734. }
  91735. simple_ogg_page__clear(&page);
  91736. }
  91737. }
  91738. #endif
  91739. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91740. {
  91741. FLAC__uint16 crc;
  91742. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91743. if(encoder->protected_->do_md5 && !FLAC__MD5Accumulate(&encoder->private_->md5context, (const FLAC__int32 * const *)encoder->private_->integer_signal, encoder->protected_->channels, encoder->protected_->blocksize, (encoder->protected_->bits_per_sample+7) / 8)) {
  91744. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91745. return false;
  91746. }
  91747. if(!process_subframes_(encoder, is_fractional_block)) {
  91748. return false;
  91749. }
  91750. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91751. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91752. return false;
  91753. }
  91754. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91755. if(
  91756. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91757. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91758. ) {
  91759. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91760. return false;
  91761. }
  91762. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91763. return false;
  91764. }
  91765. encoder->private_->current_sample_number = 0;
  91766. encoder->private_->current_frame_number++;
  91767. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91768. return true;
  91769. }
  91770. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91771. {
  91772. FLAC__FrameHeader frame_header;
  91773. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91774. FLAC__bool do_independent, do_mid_side;
  91775. if(is_fractional_block) {
  91776. max_partition_order = 0;
  91777. }
  91778. else {
  91779. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91780. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91781. }
  91782. min_partition_order = min(min_partition_order, max_partition_order);
  91783. frame_header.blocksize = encoder->protected_->blocksize;
  91784. frame_header.sample_rate = encoder->protected_->sample_rate;
  91785. frame_header.channels = encoder->protected_->channels;
  91786. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91787. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91788. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91789. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91790. if(encoder->protected_->do_mid_side_stereo) {
  91791. if(encoder->protected_->loose_mid_side_stereo) {
  91792. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91793. do_independent = true;
  91794. do_mid_side = true;
  91795. }
  91796. else {
  91797. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91798. do_mid_side = !do_independent;
  91799. }
  91800. }
  91801. else {
  91802. do_independent = true;
  91803. do_mid_side = true;
  91804. }
  91805. }
  91806. else {
  91807. do_independent = true;
  91808. do_mid_side = false;
  91809. }
  91810. FLAC__ASSERT(do_independent || do_mid_side);
  91811. if(do_independent) {
  91812. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91813. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  91814. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  91815. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  91816. }
  91817. }
  91818. if(do_mid_side) {
  91819. FLAC__ASSERT(encoder->protected_->channels == 2);
  91820. for(channel = 0; channel < 2; channel++) {
  91821. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  91822. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  91823. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  91824. }
  91825. }
  91826. if(do_independent) {
  91827. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91828. if(!
  91829. process_subframe_(
  91830. encoder,
  91831. min_partition_order,
  91832. max_partition_order,
  91833. &frame_header,
  91834. encoder->private_->subframe_bps[channel],
  91835. encoder->private_->integer_signal[channel],
  91836. encoder->private_->subframe_workspace_ptr[channel],
  91837. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  91838. encoder->private_->residual_workspace[channel],
  91839. encoder->private_->best_subframe+channel,
  91840. encoder->private_->best_subframe_bits+channel
  91841. )
  91842. )
  91843. return false;
  91844. }
  91845. }
  91846. if(do_mid_side) {
  91847. FLAC__ASSERT(encoder->protected_->channels == 2);
  91848. for(channel = 0; channel < 2; channel++) {
  91849. if(!
  91850. process_subframe_(
  91851. encoder,
  91852. min_partition_order,
  91853. max_partition_order,
  91854. &frame_header,
  91855. encoder->private_->subframe_bps_mid_side[channel],
  91856. encoder->private_->integer_signal_mid_side[channel],
  91857. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  91858. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  91859. encoder->private_->residual_workspace_mid_side[channel],
  91860. encoder->private_->best_subframe_mid_side+channel,
  91861. encoder->private_->best_subframe_bits_mid_side+channel
  91862. )
  91863. )
  91864. return false;
  91865. }
  91866. }
  91867. if(do_mid_side) {
  91868. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  91869. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  91870. FLAC__ChannelAssignment channel_assignment;
  91871. FLAC__ASSERT(encoder->protected_->channels == 2);
  91872. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  91873. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  91874. }
  91875. else {
  91876. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  91877. unsigned min_bits;
  91878. int ca;
  91879. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  91880. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  91881. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  91882. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  91883. FLAC__ASSERT(do_independent && do_mid_side);
  91884. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  91885. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  91886. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  91887. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  91888. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  91889. min_bits = bits[channel_assignment];
  91890. for(ca = 1; ca <= 3; ca++) {
  91891. if(bits[ca] < min_bits) {
  91892. min_bits = bits[ca];
  91893. channel_assignment = (FLAC__ChannelAssignment)ca;
  91894. }
  91895. }
  91896. }
  91897. frame_header.channel_assignment = channel_assignment;
  91898. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  91899. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91900. return false;
  91901. }
  91902. switch(channel_assignment) {
  91903. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  91904. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  91905. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  91906. break;
  91907. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  91908. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  91909. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91910. break;
  91911. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  91912. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91913. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  91914. break;
  91915. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  91916. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  91917. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91918. break;
  91919. default:
  91920. FLAC__ASSERT(0);
  91921. }
  91922. switch(channel_assignment) {
  91923. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  91924. left_bps = encoder->private_->subframe_bps [0];
  91925. right_bps = encoder->private_->subframe_bps [1];
  91926. break;
  91927. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  91928. left_bps = encoder->private_->subframe_bps [0];
  91929. right_bps = encoder->private_->subframe_bps_mid_side[1];
  91930. break;
  91931. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  91932. left_bps = encoder->private_->subframe_bps_mid_side[1];
  91933. right_bps = encoder->private_->subframe_bps [1];
  91934. break;
  91935. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  91936. left_bps = encoder->private_->subframe_bps_mid_side[0];
  91937. right_bps = encoder->private_->subframe_bps_mid_side[1];
  91938. break;
  91939. default:
  91940. FLAC__ASSERT(0);
  91941. }
  91942. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  91943. return false;
  91944. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  91945. return false;
  91946. }
  91947. else {
  91948. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  91949. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91950. return false;
  91951. }
  91952. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91953. if(!add_subframe_(encoder, frame_header.blocksize, encoder->private_->subframe_bps[channel], &encoder->private_->subframe_workspace[channel][encoder->private_->best_subframe[channel]], encoder->private_->frame)) {
  91954. return false;
  91955. }
  91956. }
  91957. }
  91958. if(encoder->protected_->loose_mid_side_stereo) {
  91959. encoder->private_->loose_mid_side_stereo_frame_count++;
  91960. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  91961. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  91962. }
  91963. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  91964. return true;
  91965. }
  91966. FLAC__bool process_subframe_(
  91967. FLAC__StreamEncoder *encoder,
  91968. unsigned min_partition_order,
  91969. unsigned max_partition_order,
  91970. const FLAC__FrameHeader *frame_header,
  91971. unsigned subframe_bps,
  91972. const FLAC__int32 integer_signal[],
  91973. FLAC__Subframe *subframe[2],
  91974. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  91975. FLAC__int32 *residual[2],
  91976. unsigned *best_subframe,
  91977. unsigned *best_bits
  91978. )
  91979. {
  91980. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91981. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  91982. #else
  91983. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  91984. #endif
  91985. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91986. FLAC__double lpc_residual_bits_per_sample;
  91987. FLAC__real autoc[FLAC__MAX_LPC_ORDER+1]; /* WATCHOUT: the size is important even though encoder->protected_->max_lpc_order might be less; some asm routines need all the space */
  91988. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  91989. unsigned min_lpc_order, max_lpc_order, lpc_order;
  91990. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  91991. #endif
  91992. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  91993. unsigned rice_parameter;
  91994. unsigned _candidate_bits, _best_bits;
  91995. unsigned _best_subframe;
  91996. const unsigned rice_parameter_limit = FLAC__stream_encoder_get_bits_per_sample(encoder) > 16? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  91997. FLAC__ASSERT(frame_header->blocksize > 0);
  91998. _best_subframe = 0;
  91999. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92000. _best_bits = UINT_MAX;
  92001. else
  92002. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92003. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92004. unsigned signal_is_constant = false;
  92005. guess_fixed_order = encoder->private_->local_fixed_compute_best_predictor(integer_signal+FLAC__MAX_FIXED_ORDER, frame_header->blocksize-FLAC__MAX_FIXED_ORDER, fixed_residual_bits_per_sample);
  92006. if(
  92007. !encoder->private_->disable_constant_subframes &&
  92008. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92009. fixed_residual_bits_per_sample[1] == 0.0
  92010. #else
  92011. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92012. #endif
  92013. ) {
  92014. unsigned i;
  92015. signal_is_constant = true;
  92016. for(i = 1; i < frame_header->blocksize; i++) {
  92017. if(integer_signal[0] != integer_signal[i]) {
  92018. signal_is_constant = false;
  92019. break;
  92020. }
  92021. }
  92022. }
  92023. if(signal_is_constant) {
  92024. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92025. if(_candidate_bits < _best_bits) {
  92026. _best_subframe = !_best_subframe;
  92027. _best_bits = _candidate_bits;
  92028. }
  92029. }
  92030. else {
  92031. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92032. if(encoder->protected_->do_exhaustive_model_search) {
  92033. min_fixed_order = 0;
  92034. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92035. }
  92036. else {
  92037. min_fixed_order = max_fixed_order = guess_fixed_order;
  92038. }
  92039. if(max_fixed_order >= frame_header->blocksize)
  92040. max_fixed_order = frame_header->blocksize - 1;
  92041. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92042. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92043. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92044. continue; /* don't even try */
  92045. rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > 0.0)? (unsigned)(fixed_residual_bits_per_sample[fixed_order]+0.5) : 0; /* 0.5 is for rounding */
  92046. #else
  92047. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92048. continue; /* don't even try */
  92049. rice_parameter = (fixed_residual_bits_per_sample[fixed_order] > FLAC__FP_ZERO)? (unsigned)FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]+FLAC__FP_ONE_HALF) : 0; /* 0.5 is for rounding */
  92050. #endif
  92051. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92052. if(rice_parameter >= rice_parameter_limit) {
  92053. #ifdef DEBUG_VERBOSE
  92054. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92055. #endif
  92056. rice_parameter = rice_parameter_limit - 1;
  92057. }
  92058. _candidate_bits =
  92059. evaluate_fixed_subframe_(
  92060. encoder,
  92061. integer_signal,
  92062. residual[!_best_subframe],
  92063. encoder->private_->abs_residual_partition_sums,
  92064. encoder->private_->raw_bits_per_partition,
  92065. frame_header->blocksize,
  92066. subframe_bps,
  92067. fixed_order,
  92068. rice_parameter,
  92069. rice_parameter_limit,
  92070. min_partition_order,
  92071. max_partition_order,
  92072. encoder->protected_->do_escape_coding,
  92073. encoder->protected_->rice_parameter_search_dist,
  92074. subframe[!_best_subframe],
  92075. partitioned_rice_contents[!_best_subframe]
  92076. );
  92077. if(_candidate_bits < _best_bits) {
  92078. _best_subframe = !_best_subframe;
  92079. _best_bits = _candidate_bits;
  92080. }
  92081. }
  92082. }
  92083. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92084. if(encoder->protected_->max_lpc_order > 0) {
  92085. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92086. max_lpc_order = frame_header->blocksize-1;
  92087. else
  92088. max_lpc_order = encoder->protected_->max_lpc_order;
  92089. if(max_lpc_order > 0) {
  92090. unsigned a;
  92091. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92092. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92093. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92094. if(autoc[0] != 0.0) {
  92095. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92096. if(encoder->protected_->do_exhaustive_model_search) {
  92097. min_lpc_order = 1;
  92098. }
  92099. else {
  92100. const unsigned guess_lpc_order =
  92101. FLAC__lpc_compute_best_order(
  92102. lpc_error,
  92103. max_lpc_order,
  92104. frame_header->blocksize,
  92105. subframe_bps + (
  92106. encoder->protected_->do_qlp_coeff_prec_search?
  92107. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92108. encoder->protected_->qlp_coeff_precision
  92109. )
  92110. );
  92111. min_lpc_order = max_lpc_order = guess_lpc_order;
  92112. }
  92113. if(max_lpc_order >= frame_header->blocksize)
  92114. max_lpc_order = frame_header->blocksize - 1;
  92115. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92116. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92117. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92118. continue; /* don't even try */
  92119. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92120. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92121. if(rice_parameter >= rice_parameter_limit) {
  92122. #ifdef DEBUG_VERBOSE
  92123. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92124. #endif
  92125. rice_parameter = rice_parameter_limit - 1;
  92126. }
  92127. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92128. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92129. if(subframe_bps <= 17) {
  92130. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92131. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92132. }
  92133. else
  92134. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92135. }
  92136. else {
  92137. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92138. }
  92139. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92140. _candidate_bits =
  92141. evaluate_lpc_subframe_(
  92142. encoder,
  92143. integer_signal,
  92144. residual[!_best_subframe],
  92145. encoder->private_->abs_residual_partition_sums,
  92146. encoder->private_->raw_bits_per_partition,
  92147. encoder->private_->lp_coeff[lpc_order-1],
  92148. frame_header->blocksize,
  92149. subframe_bps,
  92150. lpc_order,
  92151. qlp_coeff_precision,
  92152. rice_parameter,
  92153. rice_parameter_limit,
  92154. min_partition_order,
  92155. max_partition_order,
  92156. encoder->protected_->do_escape_coding,
  92157. encoder->protected_->rice_parameter_search_dist,
  92158. subframe[!_best_subframe],
  92159. partitioned_rice_contents[!_best_subframe]
  92160. );
  92161. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92162. if(_candidate_bits < _best_bits) {
  92163. _best_subframe = !_best_subframe;
  92164. _best_bits = _candidate_bits;
  92165. }
  92166. }
  92167. }
  92168. }
  92169. }
  92170. }
  92171. }
  92172. }
  92173. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92174. }
  92175. }
  92176. if(_best_bits == UINT_MAX) {
  92177. FLAC__ASSERT(_best_subframe == 0);
  92178. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92179. }
  92180. *best_subframe = _best_subframe;
  92181. *best_bits = _best_bits;
  92182. return true;
  92183. }
  92184. FLAC__bool add_subframe_(
  92185. FLAC__StreamEncoder *encoder,
  92186. unsigned blocksize,
  92187. unsigned subframe_bps,
  92188. const FLAC__Subframe *subframe,
  92189. FLAC__BitWriter *frame
  92190. )
  92191. {
  92192. switch(subframe->type) {
  92193. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92194. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92195. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92196. return false;
  92197. }
  92198. break;
  92199. case FLAC__SUBFRAME_TYPE_FIXED:
  92200. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92201. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92202. return false;
  92203. }
  92204. break;
  92205. case FLAC__SUBFRAME_TYPE_LPC:
  92206. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92207. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92208. return false;
  92209. }
  92210. break;
  92211. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92212. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92213. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92214. return false;
  92215. }
  92216. break;
  92217. default:
  92218. FLAC__ASSERT(0);
  92219. }
  92220. return true;
  92221. }
  92222. #define SPOTCHECK_ESTIMATE 0
  92223. #if SPOTCHECK_ESTIMATE
  92224. static void spotcheck_subframe_estimate_(
  92225. FLAC__StreamEncoder *encoder,
  92226. unsigned blocksize,
  92227. unsigned subframe_bps,
  92228. const FLAC__Subframe *subframe,
  92229. unsigned estimate
  92230. )
  92231. {
  92232. FLAC__bool ret;
  92233. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92234. if(frame == 0) {
  92235. fprintf(stderr, "EST: can't allocate frame\n");
  92236. return;
  92237. }
  92238. if(!FLAC__bitwriter_init(frame)) {
  92239. fprintf(stderr, "EST: can't init frame\n");
  92240. return;
  92241. }
  92242. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92243. FLAC__ASSERT(ret);
  92244. {
  92245. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92246. if(estimate != actual)
  92247. fprintf(stderr, "EST: bad, frame#%u sub#%%d type=%8s est=%u, actual=%u, delta=%d\n", encoder->private_->current_frame_number, FLAC__SubframeTypeString[subframe->type], estimate, actual, (int)actual-(int)estimate);
  92248. }
  92249. FLAC__bitwriter_delete(frame);
  92250. }
  92251. #endif
  92252. unsigned evaluate_constant_subframe_(
  92253. FLAC__StreamEncoder *encoder,
  92254. const FLAC__int32 signal,
  92255. unsigned blocksize,
  92256. unsigned subframe_bps,
  92257. FLAC__Subframe *subframe
  92258. )
  92259. {
  92260. unsigned estimate;
  92261. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92262. subframe->data.constant.value = signal;
  92263. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92264. #if SPOTCHECK_ESTIMATE
  92265. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92266. #else
  92267. (void)encoder, (void)blocksize;
  92268. #endif
  92269. return estimate;
  92270. }
  92271. unsigned evaluate_fixed_subframe_(
  92272. FLAC__StreamEncoder *encoder,
  92273. const FLAC__int32 signal[],
  92274. FLAC__int32 residual[],
  92275. FLAC__uint64 abs_residual_partition_sums[],
  92276. unsigned raw_bits_per_partition[],
  92277. unsigned blocksize,
  92278. unsigned subframe_bps,
  92279. unsigned order,
  92280. unsigned rice_parameter,
  92281. unsigned rice_parameter_limit,
  92282. unsigned min_partition_order,
  92283. unsigned max_partition_order,
  92284. FLAC__bool do_escape_coding,
  92285. unsigned rice_parameter_search_dist,
  92286. FLAC__Subframe *subframe,
  92287. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92288. )
  92289. {
  92290. unsigned i, residual_bits, estimate;
  92291. const unsigned residual_samples = blocksize - order;
  92292. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92293. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92294. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92295. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92296. subframe->data.fixed.residual = residual;
  92297. residual_bits =
  92298. find_best_partition_order_(
  92299. encoder->private_,
  92300. residual,
  92301. abs_residual_partition_sums,
  92302. raw_bits_per_partition,
  92303. residual_samples,
  92304. order,
  92305. rice_parameter,
  92306. rice_parameter_limit,
  92307. min_partition_order,
  92308. max_partition_order,
  92309. subframe_bps,
  92310. do_escape_coding,
  92311. rice_parameter_search_dist,
  92312. &subframe->data.fixed.entropy_coding_method
  92313. );
  92314. subframe->data.fixed.order = order;
  92315. for(i = 0; i < order; i++)
  92316. subframe->data.fixed.warmup[i] = signal[i];
  92317. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92318. #if SPOTCHECK_ESTIMATE
  92319. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92320. #endif
  92321. return estimate;
  92322. }
  92323. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92324. unsigned evaluate_lpc_subframe_(
  92325. FLAC__StreamEncoder *encoder,
  92326. const FLAC__int32 signal[],
  92327. FLAC__int32 residual[],
  92328. FLAC__uint64 abs_residual_partition_sums[],
  92329. unsigned raw_bits_per_partition[],
  92330. const FLAC__real lp_coeff[],
  92331. unsigned blocksize,
  92332. unsigned subframe_bps,
  92333. unsigned order,
  92334. unsigned qlp_coeff_precision,
  92335. unsigned rice_parameter,
  92336. unsigned rice_parameter_limit,
  92337. unsigned min_partition_order,
  92338. unsigned max_partition_order,
  92339. FLAC__bool do_escape_coding,
  92340. unsigned rice_parameter_search_dist,
  92341. FLAC__Subframe *subframe,
  92342. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92343. )
  92344. {
  92345. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92346. unsigned i, residual_bits, estimate;
  92347. int quantization, ret;
  92348. const unsigned residual_samples = blocksize - order;
  92349. if(subframe_bps <= 16) {
  92350. FLAC__ASSERT(order > 0);
  92351. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92352. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92353. }
  92354. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92355. if(ret != 0)
  92356. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92357. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92358. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92359. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92360. else
  92361. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92362. else
  92363. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92364. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92365. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92366. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92367. subframe->data.lpc.residual = residual;
  92368. residual_bits =
  92369. find_best_partition_order_(
  92370. encoder->private_,
  92371. residual,
  92372. abs_residual_partition_sums,
  92373. raw_bits_per_partition,
  92374. residual_samples,
  92375. order,
  92376. rice_parameter,
  92377. rice_parameter_limit,
  92378. min_partition_order,
  92379. max_partition_order,
  92380. subframe_bps,
  92381. do_escape_coding,
  92382. rice_parameter_search_dist,
  92383. &subframe->data.lpc.entropy_coding_method
  92384. );
  92385. subframe->data.lpc.order = order;
  92386. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92387. subframe->data.lpc.quantization_level = quantization;
  92388. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92389. for(i = 0; i < order; i++)
  92390. subframe->data.lpc.warmup[i] = signal[i];
  92391. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN + FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN + (order * (qlp_coeff_precision + subframe_bps)) + residual_bits;
  92392. #if SPOTCHECK_ESTIMATE
  92393. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92394. #endif
  92395. return estimate;
  92396. }
  92397. #endif
  92398. unsigned evaluate_verbatim_subframe_(
  92399. FLAC__StreamEncoder *encoder,
  92400. const FLAC__int32 signal[],
  92401. unsigned blocksize,
  92402. unsigned subframe_bps,
  92403. FLAC__Subframe *subframe
  92404. )
  92405. {
  92406. unsigned estimate;
  92407. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92408. subframe->data.verbatim.data = signal;
  92409. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92410. #if SPOTCHECK_ESTIMATE
  92411. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92412. #else
  92413. (void)encoder;
  92414. #endif
  92415. return estimate;
  92416. }
  92417. unsigned find_best_partition_order_(
  92418. FLAC__StreamEncoderPrivate *private_,
  92419. const FLAC__int32 residual[],
  92420. FLAC__uint64 abs_residual_partition_sums[],
  92421. unsigned raw_bits_per_partition[],
  92422. unsigned residual_samples,
  92423. unsigned predictor_order,
  92424. unsigned rice_parameter,
  92425. unsigned rice_parameter_limit,
  92426. unsigned min_partition_order,
  92427. unsigned max_partition_order,
  92428. unsigned bps,
  92429. FLAC__bool do_escape_coding,
  92430. unsigned rice_parameter_search_dist,
  92431. FLAC__EntropyCodingMethod *best_ecm
  92432. )
  92433. {
  92434. unsigned residual_bits, best_residual_bits = 0;
  92435. unsigned best_parameters_index = 0;
  92436. unsigned best_partition_order = 0;
  92437. const unsigned blocksize = residual_samples + predictor_order;
  92438. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92439. min_partition_order = min(min_partition_order, max_partition_order);
  92440. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92441. if(do_escape_coding)
  92442. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92443. {
  92444. int partition_order;
  92445. unsigned sum;
  92446. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92447. if(!
  92448. set_partitioned_rice_(
  92449. #ifdef EXACT_RICE_BITS_CALCULATION
  92450. residual,
  92451. #endif
  92452. abs_residual_partition_sums+sum,
  92453. raw_bits_per_partition+sum,
  92454. residual_samples,
  92455. predictor_order,
  92456. rice_parameter,
  92457. rice_parameter_limit,
  92458. rice_parameter_search_dist,
  92459. (unsigned)partition_order,
  92460. do_escape_coding,
  92461. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92462. &residual_bits
  92463. )
  92464. )
  92465. {
  92466. FLAC__ASSERT(best_residual_bits != 0);
  92467. break;
  92468. }
  92469. sum += 1u << partition_order;
  92470. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92471. best_residual_bits = residual_bits;
  92472. best_parameters_index = !best_parameters_index;
  92473. best_partition_order = partition_order;
  92474. }
  92475. }
  92476. }
  92477. best_ecm->data.partitioned_rice.order = best_partition_order;
  92478. {
  92479. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92480. unsigned partition;
  92481. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92482. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92483. if(do_escape_coding)
  92484. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92485. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92486. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92487. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92488. break;
  92489. }
  92490. }
  92491. }
  92492. return best_residual_bits;
  92493. }
  92494. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92495. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92496. const FLAC__int32 residual[],
  92497. FLAC__uint64 abs_residual_partition_sums[],
  92498. unsigned blocksize,
  92499. unsigned predictor_order,
  92500. unsigned min_partition_order,
  92501. unsigned max_partition_order
  92502. );
  92503. #endif
  92504. void precompute_partition_info_sums_(
  92505. const FLAC__int32 residual[],
  92506. FLAC__uint64 abs_residual_partition_sums[],
  92507. unsigned residual_samples,
  92508. unsigned predictor_order,
  92509. unsigned min_partition_order,
  92510. unsigned max_partition_order,
  92511. unsigned bps
  92512. )
  92513. {
  92514. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92515. unsigned partitions = 1u << max_partition_order;
  92516. FLAC__ASSERT(default_partition_samples > predictor_order);
  92517. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92518. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92519. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92520. return;
  92521. }
  92522. #endif
  92523. {
  92524. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92525. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92526. FLAC__uint32 abs_residual_partition_sum;
  92527. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92528. end += default_partition_samples;
  92529. abs_residual_partition_sum = 0;
  92530. for( ; residual_sample < end; residual_sample++)
  92531. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92532. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92533. }
  92534. }
  92535. else { /* have to pessimistically use 64 bits for accumulator */
  92536. FLAC__uint64 abs_residual_partition_sum;
  92537. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92538. end += default_partition_samples;
  92539. abs_residual_partition_sum = 0;
  92540. for( ; residual_sample < end; residual_sample++)
  92541. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92542. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92543. }
  92544. }
  92545. }
  92546. {
  92547. unsigned from_partition = 0, to_partition = partitions;
  92548. int partition_order;
  92549. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92550. unsigned i;
  92551. partitions >>= 1;
  92552. for(i = 0; i < partitions; i++) {
  92553. abs_residual_partition_sums[to_partition++] =
  92554. abs_residual_partition_sums[from_partition ] +
  92555. abs_residual_partition_sums[from_partition+1];
  92556. from_partition += 2;
  92557. }
  92558. }
  92559. }
  92560. }
  92561. void precompute_partition_info_escapes_(
  92562. const FLAC__int32 residual[],
  92563. unsigned raw_bits_per_partition[],
  92564. unsigned residual_samples,
  92565. unsigned predictor_order,
  92566. unsigned min_partition_order,
  92567. unsigned max_partition_order
  92568. )
  92569. {
  92570. int partition_order;
  92571. unsigned from_partition, to_partition = 0;
  92572. const unsigned blocksize = residual_samples + predictor_order;
  92573. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92574. FLAC__int32 r;
  92575. FLAC__uint32 rmax;
  92576. unsigned partition, partition_sample, partition_samples, residual_sample;
  92577. const unsigned partitions = 1u << partition_order;
  92578. const unsigned default_partition_samples = blocksize >> partition_order;
  92579. FLAC__ASSERT(default_partition_samples > predictor_order);
  92580. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92581. partition_samples = default_partition_samples;
  92582. if(partition == 0)
  92583. partition_samples -= predictor_order;
  92584. rmax = 0;
  92585. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92586. r = residual[residual_sample++];
  92587. if(r < 0)
  92588. rmax |= ~r;
  92589. else
  92590. rmax |= r;
  92591. }
  92592. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92593. }
  92594. to_partition = partitions;
  92595. break; /*@@@ yuck, should remove the 'for' loop instead */
  92596. }
  92597. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92598. unsigned m;
  92599. unsigned i;
  92600. const unsigned partitions = 1u << partition_order;
  92601. for(i = 0; i < partitions; i++) {
  92602. m = raw_bits_per_partition[from_partition];
  92603. from_partition++;
  92604. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92605. from_partition++;
  92606. to_partition++;
  92607. }
  92608. }
  92609. }
  92610. #ifdef EXACT_RICE_BITS_CALCULATION
  92611. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92612. const unsigned rice_parameter,
  92613. const unsigned partition_samples,
  92614. const FLAC__int32 *residual
  92615. )
  92616. {
  92617. unsigned i, partition_bits =
  92618. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */
  92619. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92620. ;
  92621. for(i = 0; i < partition_samples; i++)
  92622. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92623. return partition_bits;
  92624. }
  92625. #else
  92626. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92627. const unsigned rice_parameter,
  92628. const unsigned partition_samples,
  92629. const FLAC__uint64 abs_residual_partition_sum
  92630. )
  92631. {
  92632. return
  92633. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN + /* actually could end up being FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN but err on side of 16bps */
  92634. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92635. (
  92636. rice_parameter?
  92637. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92638. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92639. )
  92640. - (partition_samples >> 1)
  92641. ;
  92642. }
  92643. #endif
  92644. FLAC__bool set_partitioned_rice_(
  92645. #ifdef EXACT_RICE_BITS_CALCULATION
  92646. const FLAC__int32 residual[],
  92647. #endif
  92648. const FLAC__uint64 abs_residual_partition_sums[],
  92649. const unsigned raw_bits_per_partition[],
  92650. const unsigned residual_samples,
  92651. const unsigned predictor_order,
  92652. const unsigned suggested_rice_parameter,
  92653. const unsigned rice_parameter_limit,
  92654. const unsigned rice_parameter_search_dist,
  92655. const unsigned partition_order,
  92656. const FLAC__bool search_for_escapes,
  92657. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92658. unsigned *bits
  92659. )
  92660. {
  92661. unsigned rice_parameter, partition_bits;
  92662. unsigned best_partition_bits, best_rice_parameter = 0;
  92663. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92664. unsigned *parameters, *raw_bits;
  92665. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92666. unsigned min_rice_parameter, max_rice_parameter;
  92667. #else
  92668. (void)rice_parameter_search_dist;
  92669. #endif
  92670. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92671. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92672. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92673. parameters = partitioned_rice_contents->parameters;
  92674. raw_bits = partitioned_rice_contents->raw_bits;
  92675. if(partition_order == 0) {
  92676. best_partition_bits = (unsigned)(-1);
  92677. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92678. if(rice_parameter_search_dist) {
  92679. if(suggested_rice_parameter < rice_parameter_search_dist)
  92680. min_rice_parameter = 0;
  92681. else
  92682. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92683. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92684. if(max_rice_parameter >= rice_parameter_limit) {
  92685. #ifdef DEBUG_VERBOSE
  92686. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92687. #endif
  92688. max_rice_parameter = rice_parameter_limit - 1;
  92689. }
  92690. }
  92691. else
  92692. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92693. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92694. #else
  92695. rice_parameter = suggested_rice_parameter;
  92696. #endif
  92697. #ifdef EXACT_RICE_BITS_CALCULATION
  92698. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92699. #else
  92700. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92701. #endif
  92702. if(partition_bits < best_partition_bits) {
  92703. best_rice_parameter = rice_parameter;
  92704. best_partition_bits = partition_bits;
  92705. }
  92706. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92707. }
  92708. #endif
  92709. if(search_for_escapes) {
  92710. partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[0] * residual_samples;
  92711. if(partition_bits <= best_partition_bits) {
  92712. raw_bits[0] = raw_bits_per_partition[0];
  92713. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92714. best_partition_bits = partition_bits;
  92715. }
  92716. else
  92717. raw_bits[0] = 0;
  92718. }
  92719. parameters[0] = best_rice_parameter;
  92720. bits_ += best_partition_bits;
  92721. }
  92722. else {
  92723. unsigned partition, residual_sample;
  92724. unsigned partition_samples;
  92725. FLAC__uint64 mean, k;
  92726. const unsigned partitions = 1u << partition_order;
  92727. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92728. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92729. if(partition == 0) {
  92730. if(partition_samples <= predictor_order)
  92731. return false;
  92732. else
  92733. partition_samples -= predictor_order;
  92734. }
  92735. mean = abs_residual_partition_sums[partition];
  92736. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92737. ;
  92738. if(rice_parameter >= rice_parameter_limit) {
  92739. #ifdef DEBUG_VERBOSE
  92740. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92741. #endif
  92742. rice_parameter = rice_parameter_limit - 1;
  92743. }
  92744. best_partition_bits = (unsigned)(-1);
  92745. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92746. if(rice_parameter_search_dist) {
  92747. if(rice_parameter < rice_parameter_search_dist)
  92748. min_rice_parameter = 0;
  92749. else
  92750. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92751. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92752. if(max_rice_parameter >= rice_parameter_limit) {
  92753. #ifdef DEBUG_VERBOSE
  92754. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92755. #endif
  92756. max_rice_parameter = rice_parameter_limit - 1;
  92757. }
  92758. }
  92759. else
  92760. min_rice_parameter = max_rice_parameter = rice_parameter;
  92761. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92762. #endif
  92763. #ifdef EXACT_RICE_BITS_CALCULATION
  92764. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92765. #else
  92766. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92767. #endif
  92768. if(partition_bits < best_partition_bits) {
  92769. best_rice_parameter = rice_parameter;
  92770. best_partition_bits = partition_bits;
  92771. }
  92772. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92773. }
  92774. #endif
  92775. if(search_for_escapes) {
  92776. partition_bits = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN + raw_bits_per_partition[partition] * partition_samples;
  92777. if(partition_bits <= best_partition_bits) {
  92778. raw_bits[partition] = raw_bits_per_partition[partition];
  92779. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92780. best_partition_bits = partition_bits;
  92781. }
  92782. else
  92783. raw_bits[partition] = 0;
  92784. }
  92785. parameters[partition] = best_rice_parameter;
  92786. bits_ += best_partition_bits;
  92787. residual_sample += partition_samples;
  92788. }
  92789. }
  92790. *bits = bits_;
  92791. return true;
  92792. }
  92793. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92794. {
  92795. unsigned i, shift;
  92796. FLAC__int32 x = 0;
  92797. for(i = 0; i < samples && !(x&1); i++)
  92798. x |= signal[i];
  92799. if(x == 0) {
  92800. shift = 0;
  92801. }
  92802. else {
  92803. for(shift = 0; !(x&1); shift++)
  92804. x >>= 1;
  92805. }
  92806. if(shift > 0) {
  92807. for(i = 0; i < samples; i++)
  92808. signal[i] >>= shift;
  92809. }
  92810. return shift;
  92811. }
  92812. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92813. {
  92814. unsigned channel;
  92815. for(channel = 0; channel < channels; channel++)
  92816. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  92817. fifo->tail += wide_samples;
  92818. FLAC__ASSERT(fifo->tail <= fifo->size);
  92819. }
  92820. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92821. {
  92822. unsigned channel;
  92823. unsigned sample, wide_sample;
  92824. unsigned tail = fifo->tail;
  92825. sample = input_offset * channels;
  92826. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  92827. for(channel = 0; channel < channels; channel++)
  92828. fifo->data[channel][tail] = input[sample++];
  92829. tail++;
  92830. }
  92831. fifo->tail = tail;
  92832. FLAC__ASSERT(fifo->tail <= fifo->size);
  92833. }
  92834. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92835. {
  92836. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92837. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  92838. (void)decoder;
  92839. if(encoder->private_->verify.needs_magic_hack) {
  92840. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  92841. *bytes = FLAC__STREAM_SYNC_LENGTH;
  92842. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  92843. encoder->private_->verify.needs_magic_hack = false;
  92844. }
  92845. else {
  92846. if(encoded_bytes == 0) {
  92847. FLAC__ASSERT(0);
  92848. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  92849. }
  92850. else if(encoded_bytes < *bytes)
  92851. *bytes = encoded_bytes;
  92852. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  92853. encoder->private_->verify.output.data += *bytes;
  92854. encoder->private_->verify.output.bytes -= *bytes;
  92855. }
  92856. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  92857. }
  92858. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  92859. {
  92860. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  92861. unsigned channel;
  92862. const unsigned channels = frame->header.channels;
  92863. const unsigned blocksize = frame->header.blocksize;
  92864. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  92865. (void)decoder;
  92866. for(channel = 0; channel < channels; channel++) {
  92867. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  92868. unsigned i, sample = 0;
  92869. FLAC__int32 expect = 0, got = 0;
  92870. for(i = 0; i < blocksize; i++) {
  92871. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  92872. sample = i;
  92873. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  92874. got = (FLAC__int32)buffer[channel][i];
  92875. break;
  92876. }
  92877. }
  92878. FLAC__ASSERT(i < blocksize);
  92879. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  92880. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  92881. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  92882. encoder->private_->verify.error_stats.channel = channel;
  92883. encoder->private_->verify.error_stats.sample = sample;
  92884. encoder->private_->verify.error_stats.expected = expect;
  92885. encoder->private_->verify.error_stats.got = got;
  92886. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  92887. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  92888. }
  92889. }
  92890. encoder->private_->verify.input_fifo.tail -= blocksize;
  92891. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  92892. for(channel = 0; channel < channels; channel++)
  92893. memmove(&encoder->private_->verify.input_fifo.data[channel][0], &encoder->private_->verify.input_fifo.data[channel][blocksize], encoder->private_->verify.input_fifo.tail * sizeof(encoder->private_->verify.input_fifo.data[0][0]));
  92894. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  92895. }
  92896. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  92897. {
  92898. (void)decoder, (void)metadata, (void)client_data;
  92899. }
  92900. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  92901. {
  92902. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92903. (void)decoder, (void)status;
  92904. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92905. }
  92906. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92907. {
  92908. (void)client_data;
  92909. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  92910. if (*bytes == 0) {
  92911. if (feof(encoder->private_->file))
  92912. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  92913. else if (ferror(encoder->private_->file))
  92914. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  92915. }
  92916. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  92917. }
  92918. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  92919. {
  92920. (void)client_data;
  92921. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  92922. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  92923. else
  92924. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  92925. }
  92926. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  92927. {
  92928. off_t offset;
  92929. (void)client_data;
  92930. offset = ftello(encoder->private_->file);
  92931. if(offset < 0) {
  92932. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  92933. }
  92934. else {
  92935. *absolute_byte_offset = (FLAC__uint64)offset;
  92936. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  92937. }
  92938. }
  92939. #ifdef FLAC__VALGRIND_TESTING
  92940. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  92941. {
  92942. size_t ret = fwrite(ptr, size, nmemb, stream);
  92943. if(!ferror(stream))
  92944. fflush(stream);
  92945. return ret;
  92946. }
  92947. #else
  92948. #define local__fwrite fwrite
  92949. #endif
  92950. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  92951. {
  92952. (void)client_data, (void)current_frame;
  92953. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  92954. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  92955. #if FLAC__HAS_OGG
  92956. encoder->private_->is_ogg? true :
  92957. #endif
  92958. samples > 0
  92959. );
  92960. if(call_it) {
  92961. encoder->private_->progress_callback(encoder, encoder->private_->bytes_written+bytes, encoder->private_->samples_written+samples, encoder->private_->frames_written+(samples?1:0), encoder->private_->total_frames_estimate, encoder->private_->client_data);
  92962. }
  92963. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  92964. }
  92965. else
  92966. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92967. }
  92968. FILE *get_binary_stdout_(void)
  92969. {
  92970. #if defined _MSC_VER || defined __MINGW32__
  92971. _setmode(_fileno(stdout), _O_BINARY);
  92972. #elif defined __CYGWIN__
  92973. setmode(_fileno(stdout), _O_BINARY);
  92974. #elif defined __EMX__
  92975. setmode(fileno(stdout), O_BINARY);
  92976. #endif
  92977. return stdout;
  92978. }
  92979. #endif
  92980. /*** End of inlined file: stream_encoder.c ***/
  92981. /*** Start of inlined file: stream_encoder_framing.c ***/
  92982. /*** Start of inlined file: juce_FlacHeader.h ***/
  92983. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  92984. // tasks..
  92985. #define VERSION "1.2.1"
  92986. #define FLAC__NO_DLL 1
  92987. #if JUCE_MSVC
  92988. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  92989. #endif
  92990. #if JUCE_MAC
  92991. #define FLAC__SYS_DARWIN 1
  92992. #endif
  92993. /*** End of inlined file: juce_FlacHeader.h ***/
  92994. #if JUCE_USE_FLAC
  92995. #if HAVE_CONFIG_H
  92996. # include <config.h>
  92997. #endif
  92998. #include <stdio.h>
  92999. #include <string.h> /* for strlen() */
  93000. #ifdef max
  93001. #undef max
  93002. #endif
  93003. #define max(x,y) ((x)>(y)?(x):(y))
  93004. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93005. static FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended);
  93006. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93007. {
  93008. unsigned i, j;
  93009. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93010. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93011. return false;
  93012. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93013. return false;
  93014. i = metadata->length;
  93015. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93016. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93017. i -= metadata->data.vorbis_comment.vendor_string.length;
  93018. i += vendor_string_length;
  93019. }
  93020. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93021. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93022. return false;
  93023. switch(metadata->type) {
  93024. case FLAC__METADATA_TYPE_STREAMINFO:
  93025. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93026. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93027. return false;
  93028. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93029. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93030. return false;
  93031. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93032. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93033. return false;
  93034. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93035. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93036. return false;
  93037. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93038. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93039. return false;
  93040. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93041. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93042. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93043. return false;
  93044. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93045. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93046. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93047. return false;
  93048. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93049. return false;
  93050. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93051. return false;
  93052. break;
  93053. case FLAC__METADATA_TYPE_PADDING:
  93054. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93055. return false;
  93056. break;
  93057. case FLAC__METADATA_TYPE_APPLICATION:
  93058. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93059. return false;
  93060. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93061. return false;
  93062. break;
  93063. case FLAC__METADATA_TYPE_SEEKTABLE:
  93064. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93065. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93066. return false;
  93067. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93068. return false;
  93069. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93070. return false;
  93071. }
  93072. break;
  93073. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93074. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93075. return false;
  93076. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93077. return false;
  93078. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93079. return false;
  93080. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93081. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93082. return false;
  93083. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93084. return false;
  93085. }
  93086. break;
  93087. case FLAC__METADATA_TYPE_CUESHEET:
  93088. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93089. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.cue_sheet.media_catalog_number, FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN/8))
  93090. return false;
  93091. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93092. return false;
  93093. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93094. return false;
  93095. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93096. return false;
  93097. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93098. return false;
  93099. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93100. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93101. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93102. return false;
  93103. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93104. return false;
  93105. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93106. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93107. return false;
  93108. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93109. return false;
  93110. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93111. return false;
  93112. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93113. return false;
  93114. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93115. return false;
  93116. for(j = 0; j < track->num_indices; j++) {
  93117. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93118. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93119. return false;
  93120. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93121. return false;
  93122. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93123. return false;
  93124. }
  93125. }
  93126. break;
  93127. case FLAC__METADATA_TYPE_PICTURE:
  93128. {
  93129. size_t len;
  93130. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93131. return false;
  93132. len = strlen(metadata->data.picture.mime_type);
  93133. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93134. return false;
  93135. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93136. return false;
  93137. len = strlen((const char *)metadata->data.picture.description);
  93138. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93139. return false;
  93140. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93141. return false;
  93142. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93143. return false;
  93144. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93145. return false;
  93146. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93147. return false;
  93148. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93149. return false;
  93150. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93151. return false;
  93152. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93153. return false;
  93154. }
  93155. break;
  93156. default:
  93157. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93158. return false;
  93159. break;
  93160. }
  93161. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93162. return true;
  93163. }
  93164. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93165. {
  93166. unsigned u, blocksize_hint, sample_rate_hint;
  93167. FLAC__byte crc;
  93168. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93169. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93170. return false;
  93171. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93172. return false;
  93173. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93174. return false;
  93175. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93176. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93177. blocksize_hint = 0;
  93178. switch(header->blocksize) {
  93179. case 192: u = 1; break;
  93180. case 576: u = 2; break;
  93181. case 1152: u = 3; break;
  93182. case 2304: u = 4; break;
  93183. case 4608: u = 5; break;
  93184. case 256: u = 8; break;
  93185. case 512: u = 9; break;
  93186. case 1024: u = 10; break;
  93187. case 2048: u = 11; break;
  93188. case 4096: u = 12; break;
  93189. case 8192: u = 13; break;
  93190. case 16384: u = 14; break;
  93191. case 32768: u = 15; break;
  93192. default:
  93193. if(header->blocksize <= 0x100)
  93194. blocksize_hint = u = 6;
  93195. else
  93196. blocksize_hint = u = 7;
  93197. break;
  93198. }
  93199. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93200. return false;
  93201. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93202. sample_rate_hint = 0;
  93203. switch(header->sample_rate) {
  93204. case 88200: u = 1; break;
  93205. case 176400: u = 2; break;
  93206. case 192000: u = 3; break;
  93207. case 8000: u = 4; break;
  93208. case 16000: u = 5; break;
  93209. case 22050: u = 6; break;
  93210. case 24000: u = 7; break;
  93211. case 32000: u = 8; break;
  93212. case 44100: u = 9; break;
  93213. case 48000: u = 10; break;
  93214. case 96000: u = 11; break;
  93215. default:
  93216. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93217. sample_rate_hint = u = 12;
  93218. else if(header->sample_rate % 10 == 0)
  93219. sample_rate_hint = u = 14;
  93220. else if(header->sample_rate <= 0xffff)
  93221. sample_rate_hint = u = 13;
  93222. else
  93223. u = 0;
  93224. break;
  93225. }
  93226. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93227. return false;
  93228. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93229. switch(header->channel_assignment) {
  93230. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93231. u = header->channels - 1;
  93232. break;
  93233. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93234. FLAC__ASSERT(header->channels == 2);
  93235. u = 8;
  93236. break;
  93237. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93238. FLAC__ASSERT(header->channels == 2);
  93239. u = 9;
  93240. break;
  93241. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93242. FLAC__ASSERT(header->channels == 2);
  93243. u = 10;
  93244. break;
  93245. default:
  93246. FLAC__ASSERT(0);
  93247. }
  93248. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93249. return false;
  93250. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93251. switch(header->bits_per_sample) {
  93252. case 8 : u = 1; break;
  93253. case 12: u = 2; break;
  93254. case 16: u = 4; break;
  93255. case 20: u = 5; break;
  93256. case 24: u = 6; break;
  93257. default: u = 0; break;
  93258. }
  93259. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93260. return false;
  93261. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93262. return false;
  93263. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93264. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93265. return false;
  93266. }
  93267. else {
  93268. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93269. return false;
  93270. }
  93271. if(blocksize_hint)
  93272. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93273. return false;
  93274. switch(sample_rate_hint) {
  93275. case 12:
  93276. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93277. return false;
  93278. break;
  93279. case 13:
  93280. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93281. return false;
  93282. break;
  93283. case 14:
  93284. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93285. return false;
  93286. break;
  93287. }
  93288. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93289. return false;
  93290. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93291. return false;
  93292. return true;
  93293. }
  93294. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93295. {
  93296. FLAC__bool ok;
  93297. ok =
  93298. FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN) &&
  93299. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93300. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93301. ;
  93302. return ok;
  93303. }
  93304. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93305. {
  93306. unsigned i;
  93307. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK | (subframe->order<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  93308. return false;
  93309. if(wasted_bits)
  93310. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93311. return false;
  93312. for(i = 0; i < subframe->order; i++)
  93313. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93314. return false;
  93315. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93316. return false;
  93317. switch(subframe->entropy_coding_method.type) {
  93318. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93319. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93320. if(!add_residual_partitioned_rice_(
  93321. bw,
  93322. subframe->residual,
  93323. residual_samples,
  93324. subframe->order,
  93325. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93326. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93327. subframe->entropy_coding_method.data.partitioned_rice.order,
  93328. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93329. ))
  93330. return false;
  93331. break;
  93332. default:
  93333. FLAC__ASSERT(0);
  93334. }
  93335. return true;
  93336. }
  93337. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93338. {
  93339. unsigned i;
  93340. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK | ((subframe->order-1)<<1) | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  93341. return false;
  93342. if(wasted_bits)
  93343. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93344. return false;
  93345. for(i = 0; i < subframe->order; i++)
  93346. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93347. return false;
  93348. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93349. return false;
  93350. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93351. return false;
  93352. for(i = 0; i < subframe->order; i++)
  93353. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93354. return false;
  93355. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93356. return false;
  93357. switch(subframe->entropy_coding_method.type) {
  93358. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93359. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93360. if(!add_residual_partitioned_rice_(
  93361. bw,
  93362. subframe->residual,
  93363. residual_samples,
  93364. subframe->order,
  93365. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93366. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93367. subframe->entropy_coding_method.data.partitioned_rice.order,
  93368. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93369. ))
  93370. return false;
  93371. break;
  93372. default:
  93373. FLAC__ASSERT(0);
  93374. }
  93375. return true;
  93376. }
  93377. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93378. {
  93379. unsigned i;
  93380. const FLAC__int32 *signal = subframe->data;
  93381. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK | (wasted_bits? 1:0), FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN))
  93382. return false;
  93383. if(wasted_bits)
  93384. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93385. return false;
  93386. for(i = 0; i < samples; i++)
  93387. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93388. return false;
  93389. return true;
  93390. }
  93391. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93392. {
  93393. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93394. return false;
  93395. switch(method->type) {
  93396. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93397. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93398. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93399. return false;
  93400. break;
  93401. default:
  93402. FLAC__ASSERT(0);
  93403. }
  93404. return true;
  93405. }
  93406. FLAC__bool add_residual_partitioned_rice_(FLAC__BitWriter *bw, const FLAC__int32 residual[], const unsigned residual_samples, const unsigned predictor_order, const unsigned rice_parameters[], const unsigned raw_bits[], const unsigned partition_order, const FLAC__bool is_extended)
  93407. {
  93408. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93409. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93410. if(partition_order == 0) {
  93411. unsigned i;
  93412. if(raw_bits[0] == 0) {
  93413. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93414. return false;
  93415. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93416. return false;
  93417. }
  93418. else {
  93419. FLAC__ASSERT(rice_parameters[0] == 0);
  93420. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93421. return false;
  93422. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93423. return false;
  93424. for(i = 0; i < residual_samples; i++) {
  93425. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93426. return false;
  93427. }
  93428. }
  93429. return true;
  93430. }
  93431. else {
  93432. unsigned i, j, k = 0, k_last = 0;
  93433. unsigned partition_samples;
  93434. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93435. for(i = 0; i < (1u<<partition_order); i++) {
  93436. partition_samples = default_partition_samples;
  93437. if(i == 0)
  93438. partition_samples -= predictor_order;
  93439. k += partition_samples;
  93440. if(raw_bits[i] == 0) {
  93441. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93442. return false;
  93443. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93444. return false;
  93445. }
  93446. else {
  93447. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93448. return false;
  93449. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93450. return false;
  93451. for(j = k_last; j < k; j++) {
  93452. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93453. return false;
  93454. }
  93455. }
  93456. k_last = k;
  93457. }
  93458. return true;
  93459. }
  93460. }
  93461. #endif
  93462. /*** End of inlined file: stream_encoder_framing.c ***/
  93463. /*** Start of inlined file: window_flac.c ***/
  93464. /*** Start of inlined file: juce_FlacHeader.h ***/
  93465. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93466. // tasks..
  93467. #define VERSION "1.2.1"
  93468. #define FLAC__NO_DLL 1
  93469. #if JUCE_MSVC
  93470. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93471. #endif
  93472. #if JUCE_MAC
  93473. #define FLAC__SYS_DARWIN 1
  93474. #endif
  93475. /*** End of inlined file: juce_FlacHeader.h ***/
  93476. #if JUCE_USE_FLAC
  93477. #if HAVE_CONFIG_H
  93478. # include <config.h>
  93479. #endif
  93480. #include <math.h>
  93481. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93482. #ifndef M_PI
  93483. #define M_PI 3.14159265358979323846
  93484. #endif
  93485. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93486. {
  93487. const FLAC__int32 N = L - 1;
  93488. FLAC__int32 n;
  93489. if (L & 1) {
  93490. for (n = 0; n <= N/2; n++)
  93491. window[n] = 2.0f * n / (float)N;
  93492. for (; n <= N; n++)
  93493. window[n] = 2.0f - 2.0f * n / (float)N;
  93494. }
  93495. else {
  93496. for (n = 0; n <= L/2-1; n++)
  93497. window[n] = 2.0f * n / (float)N;
  93498. for (; n <= N; n++)
  93499. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93500. }
  93501. }
  93502. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93503. {
  93504. const FLAC__int32 N = L - 1;
  93505. FLAC__int32 n;
  93506. for (n = 0; n < L; n++)
  93507. window[n] = (FLAC__real)(0.62f - 0.48f * fabs((float)n/(float)N+0.5f) + 0.38f * cos(2.0f * M_PI * ((float)n/(float)N+0.5f)));
  93508. }
  93509. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93510. {
  93511. const FLAC__int32 N = L - 1;
  93512. FLAC__int32 n;
  93513. for (n = 0; n < L; n++)
  93514. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93515. }
  93516. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93517. {
  93518. const FLAC__int32 N = L - 1;
  93519. FLAC__int32 n;
  93520. for (n = 0; n <= N; n++)
  93521. window[n] = (FLAC__real)(0.35875f - 0.48829f * cos(2.0f * M_PI * n / N) + 0.14128f * cos(4.0f * M_PI * n / N) - 0.01168f * cos(6.0f * M_PI * n / N));
  93522. }
  93523. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93524. {
  93525. const FLAC__int32 N = L - 1;
  93526. const double N2 = (double)N / 2.;
  93527. FLAC__int32 n;
  93528. for (n = 0; n <= N; n++) {
  93529. double k = ((double)n - N2) / N2;
  93530. k = 1.0f - k * k;
  93531. window[n] = (FLAC__real)(k * k);
  93532. }
  93533. }
  93534. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93535. {
  93536. const FLAC__int32 N = L - 1;
  93537. FLAC__int32 n;
  93538. for (n = 0; n < L; n++)
  93539. window[n] = (FLAC__real)(1.0f - 1.93f * cos(2.0f * M_PI * n / N) + 1.29f * cos(4.0f * M_PI * n / N) - 0.388f * cos(6.0f * M_PI * n / N) + 0.0322f * cos(8.0f * M_PI * n / N));
  93540. }
  93541. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93542. {
  93543. const FLAC__int32 N = L - 1;
  93544. const double N2 = (double)N / 2.;
  93545. FLAC__int32 n;
  93546. for (n = 0; n <= N; n++) {
  93547. const double k = ((double)n - N2) / (stddev * N2);
  93548. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93549. }
  93550. }
  93551. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93552. {
  93553. const FLAC__int32 N = L - 1;
  93554. FLAC__int32 n;
  93555. for (n = 0; n < L; n++)
  93556. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93557. }
  93558. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93559. {
  93560. const FLAC__int32 N = L - 1;
  93561. FLAC__int32 n;
  93562. for (n = 0; n < L; n++)
  93563. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93564. }
  93565. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93566. {
  93567. const FLAC__int32 N = L - 1;
  93568. FLAC__int32 n;
  93569. for (n = 0; n < L; n++)
  93570. window[n] = (FLAC__real)(0.402f - 0.498f * cos(2.0f * M_PI * n / N) + 0.098f * cos(4.0f * M_PI * n / N) - 0.001f * cos(6.0f * M_PI * n / N));
  93571. }
  93572. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93573. {
  93574. const FLAC__int32 N = L - 1;
  93575. FLAC__int32 n;
  93576. for (n = 0; n < L; n++)
  93577. window[n] = (FLAC__real)(0.3635819f - 0.4891775f*cos(2.0f*M_PI*n/N) + 0.1365995f*cos(4.0f*M_PI*n/N) - 0.0106411f*cos(6.0f*M_PI*n/N));
  93578. }
  93579. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93580. {
  93581. FLAC__int32 n;
  93582. for (n = 0; n < L; n++)
  93583. window[n] = 1.0f;
  93584. }
  93585. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93586. {
  93587. FLAC__int32 n;
  93588. if (L & 1) {
  93589. for (n = 1; n <= L+1/2; n++)
  93590. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93591. for (; n <= L; n++)
  93592. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93593. }
  93594. else {
  93595. for (n = 1; n <= L/2; n++)
  93596. window[n-1] = 2.0f * n / (float)L;
  93597. for (; n <= L; n++)
  93598. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93599. }
  93600. }
  93601. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93602. {
  93603. if (p <= 0.0)
  93604. FLAC__window_rectangle(window, L);
  93605. else if (p >= 1.0)
  93606. FLAC__window_hann(window, L);
  93607. else {
  93608. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93609. FLAC__int32 n;
  93610. FLAC__window_rectangle(window, L);
  93611. if (Np > 0) {
  93612. for (n = 0; n <= Np; n++) {
  93613. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93614. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93615. }
  93616. }
  93617. }
  93618. }
  93619. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93620. {
  93621. const FLAC__int32 N = L - 1;
  93622. const double N2 = (double)N / 2.;
  93623. FLAC__int32 n;
  93624. for (n = 0; n <= N; n++) {
  93625. const double k = ((double)n - N2) / N2;
  93626. window[n] = (FLAC__real)(1.0f - k * k);
  93627. }
  93628. }
  93629. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93630. #endif
  93631. /*** End of inlined file: window_flac.c ***/
  93632. #else
  93633. #include <FLAC/all.h>
  93634. #endif
  93635. }
  93636. #undef max
  93637. #undef min
  93638. #ifdef _MSC_VER
  93639. #pragma warning (pop)
  93640. #endif
  93641. BEGIN_JUCE_NAMESPACE
  93642. static const char* const flacFormatName = "FLAC file";
  93643. static const juce_wchar* const flacExtensions[] = { T(".flac"), 0 };
  93644. class FlacReader : public AudioFormatReader
  93645. {
  93646. public:
  93647. FlacReader (InputStream* const in)
  93648. : AudioFormatReader (in, TRANS (flacFormatName)),
  93649. reservoir (2, 0),
  93650. reservoirStart (0),
  93651. samplesInReservoir (0),
  93652. scanningForLength (false)
  93653. {
  93654. using namespace FlacNamespace;
  93655. lengthInSamples = 0;
  93656. decoder = FLAC__stream_decoder_new();
  93657. ok = FLAC__stream_decoder_init_stream (decoder,
  93658. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93659. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93660. this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93661. if (ok)
  93662. {
  93663. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93664. if (lengthInSamples == 0 && sampleRate > 0)
  93665. {
  93666. // the length hasn't been stored in the metadata, so we'll need to
  93667. // work it out the length the hard way, by scanning the whole file..
  93668. scanningForLength = true;
  93669. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93670. scanningForLength = false;
  93671. const int64 tempLength = lengthInSamples;
  93672. FLAC__stream_decoder_reset (decoder);
  93673. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93674. lengthInSamples = tempLength;
  93675. }
  93676. }
  93677. }
  93678. ~FlacReader()
  93679. {
  93680. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93681. }
  93682. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93683. {
  93684. sampleRate = info.sample_rate;
  93685. bitsPerSample = info.bits_per_sample;
  93686. lengthInSamples = (unsigned int) info.total_samples;
  93687. numChannels = info.channels;
  93688. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93689. }
  93690. // returns the number of samples read
  93691. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93692. int64 startSampleInFile, int numSamples)
  93693. {
  93694. using namespace FlacNamespace;
  93695. if (! ok)
  93696. return false;
  93697. while (numSamples > 0)
  93698. {
  93699. if (startSampleInFile >= reservoirStart
  93700. && startSampleInFile < reservoirStart + samplesInReservoir)
  93701. {
  93702. const int num = (int) jmin ((int64) numSamples,
  93703. reservoirStart + samplesInReservoir - startSampleInFile);
  93704. jassert (num > 0);
  93705. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93706. if (destSamples[i] != 0)
  93707. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93708. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93709. sizeof (int) * num);
  93710. startOffsetInDestBuffer += num;
  93711. startSampleInFile += num;
  93712. numSamples -= num;
  93713. }
  93714. else
  93715. {
  93716. if (startSampleInFile >= (int) lengthInSamples)
  93717. {
  93718. samplesInReservoir = 0;
  93719. }
  93720. else if (startSampleInFile < reservoirStart
  93721. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93722. {
  93723. // had some problems with flac crashing if the read pos is aligned more
  93724. // accurately than this. Probably fixed in newer versions of the library, though.
  93725. reservoirStart = (int) (startSampleInFile & ~511);
  93726. samplesInReservoir = 0;
  93727. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93728. }
  93729. else
  93730. {
  93731. reservoirStart += samplesInReservoir;
  93732. samplesInReservoir = 0;
  93733. FLAC__stream_decoder_process_single (decoder);
  93734. }
  93735. if (samplesInReservoir == 0)
  93736. break;
  93737. }
  93738. }
  93739. if (numSamples > 0)
  93740. {
  93741. for (int i = numDestChannels; --i >= 0;)
  93742. if (destSamples[i] != 0)
  93743. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93744. sizeof (int) * numSamples);
  93745. }
  93746. return true;
  93747. }
  93748. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93749. {
  93750. if (scanningForLength)
  93751. {
  93752. lengthInSamples += numSamples;
  93753. }
  93754. else
  93755. {
  93756. if (numSamples > reservoir.getNumSamples())
  93757. reservoir.setSize (numChannels, numSamples, false, false, true);
  93758. const int bitsToShift = 32 - bitsPerSample;
  93759. for (int i = 0; i < (int) numChannels; ++i)
  93760. {
  93761. const FlacNamespace::FLAC__int32* src = buffer[i];
  93762. int n = i;
  93763. while (src == 0 && n > 0)
  93764. src = buffer [--n];
  93765. if (src != 0)
  93766. {
  93767. int* dest = (int*) reservoir.getSampleData(i);
  93768. for (int j = 0; j < numSamples; ++j)
  93769. dest[j] = src[j] << bitsToShift;
  93770. }
  93771. }
  93772. samplesInReservoir = numSamples;
  93773. }
  93774. }
  93775. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93776. {
  93777. using namespace FlacNamespace;
  93778. *bytes = (size_t) static_cast <const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
  93779. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93780. }
  93781. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93782. {
  93783. using namespace FlacNamespace;
  93784. static_cast <const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
  93785. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93786. }
  93787. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93788. {
  93789. using namespace FlacNamespace;
  93790. *absolute_byte_offset = static_cast <const FlacReader*> (client_data)->input->getPosition();
  93791. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93792. }
  93793. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93794. {
  93795. using namespace FlacNamespace;
  93796. *stream_length = static_cast <const FlacReader*> (client_data)->input->getTotalLength();
  93797. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93798. }
  93799. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93800. {
  93801. return static_cast <const FlacReader*> (client_data)->input->isExhausted();
  93802. }
  93803. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93804. const FlacNamespace::FLAC__Frame* frame,
  93805. const FlacNamespace::FLAC__int32* const buffer[],
  93806. void* client_data)
  93807. {
  93808. using namespace FlacNamespace;
  93809. static_cast <FlacReader*> (client_data)->useSamples (buffer, frame->header.blocksize);
  93810. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93811. }
  93812. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93813. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93814. void* client_data)
  93815. {
  93816. static_cast <FlacReader*> (client_data)->useMetadata (metadata->data.stream_info);
  93817. }
  93818. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  93819. {
  93820. }
  93821. juce_UseDebuggingNewOperator
  93822. private:
  93823. FlacNamespace::FLAC__StreamDecoder* decoder;
  93824. AudioSampleBuffer reservoir;
  93825. int reservoirStart, samplesInReservoir;
  93826. bool ok, scanningForLength;
  93827. FlacReader (const FlacReader&);
  93828. FlacReader& operator= (const FlacReader&);
  93829. };
  93830. class FlacWriter : public AudioFormatWriter
  93831. {
  93832. public:
  93833. FlacWriter (OutputStream* const out,
  93834. const double sampleRate_,
  93835. const int numChannels_,
  93836. const int bitsPerSample_)
  93837. : AudioFormatWriter (out, TRANS (flacFormatName),
  93838. sampleRate_,
  93839. numChannels_,
  93840. bitsPerSample_)
  93841. {
  93842. using namespace FlacNamespace;
  93843. encoder = FLAC__stream_encoder_new();
  93844. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  93845. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  93846. FLAC__stream_encoder_set_channels (encoder, numChannels);
  93847. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  93848. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  93849. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  93850. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  93851. ok = FLAC__stream_encoder_init_stream (encoder,
  93852. encodeWriteCallback, encodeSeekCallback,
  93853. encodeTellCallback, encodeMetadataCallback,
  93854. this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  93855. }
  93856. ~FlacWriter()
  93857. {
  93858. if (ok)
  93859. {
  93860. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  93861. output->flush();
  93862. }
  93863. else
  93864. {
  93865. output = 0; // to stop the base class deleting this, as it needs to be returned
  93866. // to the caller of createWriter()
  93867. }
  93868. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  93869. }
  93870. bool write (const int** samplesToWrite, int numSamples)
  93871. {
  93872. using namespace FlacNamespace;
  93873. if (! ok)
  93874. return false;
  93875. int* buf[3];
  93876. const int bitsToShift = 32 - bitsPerSample;
  93877. if (bitsToShift > 0)
  93878. {
  93879. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  93880. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  93881. buf[0] = (int*) temp.getData();
  93882. buf[1] = buf[0] + numSamples;
  93883. buf[2] = 0;
  93884. for (int i = numChannelsToWrite; --i >= 0;)
  93885. {
  93886. if (samplesToWrite[i] != 0)
  93887. {
  93888. for (int j = 0; j < numSamples; ++j)
  93889. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  93890. }
  93891. }
  93892. samplesToWrite = (const int**) buf;
  93893. }
  93894. return FLAC__stream_encoder_process (encoder,
  93895. (const FLAC__int32**) samplesToWrite,
  93896. numSamples) != 0;
  93897. }
  93898. bool writeData (const void* const data, const int size) const
  93899. {
  93900. return output->write (data, size);
  93901. }
  93902. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  93903. {
  93904. using namespace FlacNamespace;
  93905. b += bytes;
  93906. for (int i = 0; i < bytes; ++i)
  93907. {
  93908. *(--b) = (FLAC__byte) (val & 0xff);
  93909. val >>= 8;
  93910. }
  93911. }
  93912. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  93913. {
  93914. using namespace FlacNamespace;
  93915. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  93916. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  93917. const unsigned int channelsMinus1 = info.channels - 1;
  93918. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  93919. packUint32 (info.min_blocksize, buffer, 2);
  93920. packUint32 (info.max_blocksize, buffer + 2, 2);
  93921. packUint32 (info.min_framesize, buffer + 4, 3);
  93922. packUint32 (info.max_framesize, buffer + 7, 3);
  93923. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  93924. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  93925. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  93926. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  93927. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  93928. memcpy (buffer + 18, info.md5sum, 16);
  93929. const bool seekOk = output->setPosition (4);
  93930. (void) seekOk;
  93931. // if this fails, you've given it an output stream that can't seek! It needs
  93932. // to be able to seek back to write the header
  93933. jassert (seekOk);
  93934. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  93935. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  93936. }
  93937. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  93938. const FlacNamespace::FLAC__byte buffer[],
  93939. size_t bytes,
  93940. unsigned int /*samples*/,
  93941. unsigned int /*current_frame*/,
  93942. void* client_data)
  93943. {
  93944. using namespace FlacNamespace;
  93945. return static_cast <FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
  93946. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  93947. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93948. }
  93949. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  93950. {
  93951. using namespace FlacNamespace;
  93952. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  93953. }
  93954. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93955. {
  93956. using namespace FlacNamespace;
  93957. if (client_data == 0)
  93958. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  93959. *absolute_byte_offset = (FLAC__uint64) static_cast <FlacWriter*> (client_data)->output->getPosition();
  93960. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93961. }
  93962. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
  93963. {
  93964. static_cast <FlacWriter*> (client_data)->writeMetaData (metadata);
  93965. }
  93966. juce_UseDebuggingNewOperator
  93967. bool ok;
  93968. private:
  93969. FlacNamespace::FLAC__StreamEncoder* encoder;
  93970. MemoryBlock temp;
  93971. FlacWriter (const FlacWriter&);
  93972. FlacWriter& operator= (const FlacWriter&);
  93973. };
  93974. FlacAudioFormat::FlacAudioFormat()
  93975. : AudioFormat (TRANS (flacFormatName), (const juce_wchar**) flacExtensions)
  93976. {
  93977. }
  93978. FlacAudioFormat::~FlacAudioFormat()
  93979. {
  93980. }
  93981. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  93982. {
  93983. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  93984. return Array <int> (rates);
  93985. }
  93986. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  93987. {
  93988. const int depths[] = { 16, 24, 0 };
  93989. return Array <int> (depths);
  93990. }
  93991. bool FlacAudioFormat::canDoStereo()
  93992. {
  93993. return true;
  93994. }
  93995. bool FlacAudioFormat::canDoMono()
  93996. {
  93997. return true;
  93998. }
  93999. bool FlacAudioFormat::isCompressed()
  94000. {
  94001. return true;
  94002. }
  94003. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94004. const bool deleteStreamIfOpeningFails)
  94005. {
  94006. ScopedPointer<FlacReader> r (new FlacReader (in));
  94007. if (r->sampleRate != 0)
  94008. return r.release();
  94009. if (! deleteStreamIfOpeningFails)
  94010. r->input = 0;
  94011. return 0;
  94012. }
  94013. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94014. double sampleRate,
  94015. unsigned int numberOfChannels,
  94016. int bitsPerSample,
  94017. const StringPairArray& /*metadataValues*/,
  94018. int /*qualityOptionIndex*/)
  94019. {
  94020. if (getPossibleBitDepths().contains (bitsPerSample))
  94021. {
  94022. ScopedPointer<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels, bitsPerSample));
  94023. if (w->ok)
  94024. return w.release();
  94025. }
  94026. return 0;
  94027. }
  94028. END_JUCE_NAMESPACE
  94029. #endif
  94030. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94031. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94032. #if JUCE_USE_OGGVORBIS
  94033. #if JUCE_MAC
  94034. #define __MACOSX__ 1
  94035. #endif
  94036. namespace OggVorbisNamespace
  94037. {
  94038. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94039. /*** Start of inlined file: vorbisenc.h ***/
  94040. #ifndef _OV_ENC_H_
  94041. #define _OV_ENC_H_
  94042. #ifdef __cplusplus
  94043. extern "C"
  94044. {
  94045. #endif /* __cplusplus */
  94046. /*** Start of inlined file: codec.h ***/
  94047. #ifndef _vorbis_codec_h_
  94048. #define _vorbis_codec_h_
  94049. #ifdef __cplusplus
  94050. extern "C"
  94051. {
  94052. #endif /* __cplusplus */
  94053. /*** Start of inlined file: ogg.h ***/
  94054. #ifndef _OGG_H
  94055. #define _OGG_H
  94056. #ifdef __cplusplus
  94057. extern "C" {
  94058. #endif
  94059. /*** Start of inlined file: os_types.h ***/
  94060. #ifndef _OS_TYPES_H
  94061. #define _OS_TYPES_H
  94062. #define _ogg_malloc malloc
  94063. #define _ogg_calloc calloc
  94064. #define _ogg_realloc realloc
  94065. #define _ogg_free free
  94066. #if defined(_WIN32)
  94067. # if defined(__CYGWIN__)
  94068. # include <_G_config.h>
  94069. typedef _G_int64_t ogg_int64_t;
  94070. typedef _G_int32_t ogg_int32_t;
  94071. typedef _G_uint32_t ogg_uint32_t;
  94072. typedef _G_int16_t ogg_int16_t;
  94073. typedef _G_uint16_t ogg_uint16_t;
  94074. # elif defined(__MINGW32__)
  94075. typedef short ogg_int16_t;
  94076. typedef unsigned short ogg_uint16_t;
  94077. typedef int ogg_int32_t;
  94078. typedef unsigned int ogg_uint32_t;
  94079. typedef long long ogg_int64_t;
  94080. typedef unsigned long long ogg_uint64_t;
  94081. # elif defined(__MWERKS__)
  94082. typedef long long ogg_int64_t;
  94083. typedef int ogg_int32_t;
  94084. typedef unsigned int ogg_uint32_t;
  94085. typedef short ogg_int16_t;
  94086. typedef unsigned short ogg_uint16_t;
  94087. # else
  94088. typedef __int64 ogg_int64_t;
  94089. typedef __int32 ogg_int32_t;
  94090. typedef unsigned __int32 ogg_uint32_t;
  94091. typedef __int16 ogg_int16_t;
  94092. typedef unsigned __int16 ogg_uint16_t;
  94093. # endif
  94094. #elif defined(__MACOS__)
  94095. # include <sys/types.h>
  94096. typedef SInt16 ogg_int16_t;
  94097. typedef UInt16 ogg_uint16_t;
  94098. typedef SInt32 ogg_int32_t;
  94099. typedef UInt32 ogg_uint32_t;
  94100. typedef SInt64 ogg_int64_t;
  94101. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94102. # include <sys/types.h>
  94103. typedef int16_t ogg_int16_t;
  94104. typedef u_int16_t ogg_uint16_t;
  94105. typedef int32_t ogg_int32_t;
  94106. typedef u_int32_t ogg_uint32_t;
  94107. typedef int64_t ogg_int64_t;
  94108. #elif defined(__BEOS__)
  94109. # include <inttypes.h>
  94110. typedef int16_t ogg_int16_t;
  94111. typedef u_int16_t ogg_uint16_t;
  94112. typedef int32_t ogg_int32_t;
  94113. typedef u_int32_t ogg_uint32_t;
  94114. typedef int64_t ogg_int64_t;
  94115. #elif defined (__EMX__)
  94116. typedef short ogg_int16_t;
  94117. typedef unsigned short ogg_uint16_t;
  94118. typedef int ogg_int32_t;
  94119. typedef unsigned int ogg_uint32_t;
  94120. typedef long long ogg_int64_t;
  94121. #elif defined (DJGPP)
  94122. typedef short ogg_int16_t;
  94123. typedef int ogg_int32_t;
  94124. typedef unsigned int ogg_uint32_t;
  94125. typedef long long ogg_int64_t;
  94126. #elif defined(R5900)
  94127. typedef long ogg_int64_t;
  94128. typedef int ogg_int32_t;
  94129. typedef unsigned ogg_uint32_t;
  94130. typedef short ogg_int16_t;
  94131. #elif defined(__SYMBIAN32__)
  94132. typedef signed short ogg_int16_t;
  94133. typedef unsigned short ogg_uint16_t;
  94134. typedef signed int ogg_int32_t;
  94135. typedef unsigned int ogg_uint32_t;
  94136. typedef long long int ogg_int64_t;
  94137. #else
  94138. # include <sys/types.h>
  94139. /*** Start of inlined file: config_types.h ***/
  94140. #ifndef __CONFIG_TYPES_H__
  94141. #define __CONFIG_TYPES_H__
  94142. typedef int16_t ogg_int16_t;
  94143. typedef unsigned short ogg_uint16_t;
  94144. typedef int32_t ogg_int32_t;
  94145. typedef unsigned int ogg_uint32_t;
  94146. typedef int64_t ogg_int64_t;
  94147. #endif
  94148. /*** End of inlined file: config_types.h ***/
  94149. #endif
  94150. #endif /* _OS_TYPES_H */
  94151. /*** End of inlined file: os_types.h ***/
  94152. typedef struct {
  94153. long endbyte;
  94154. int endbit;
  94155. unsigned char *buffer;
  94156. unsigned char *ptr;
  94157. long storage;
  94158. } oggpack_buffer;
  94159. typedef struct {
  94160. unsigned char *header;
  94161. long header_len;
  94162. unsigned char *body;
  94163. long body_len;
  94164. } ogg_page;
  94165. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94166. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94167. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94168. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94169. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94170. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94171. }
  94172. typedef struct {
  94173. unsigned char *body_data; /* bytes from packet bodies */
  94174. long body_storage; /* storage elements allocated */
  94175. long body_fill; /* elements stored; fill mark */
  94176. long body_returned; /* elements of fill returned */
  94177. int *lacing_vals; /* The values that will go to the segment table */
  94178. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94179. this way, but it is simple coupled to the
  94180. lacing fifo */
  94181. long lacing_storage;
  94182. long lacing_fill;
  94183. long lacing_packet;
  94184. long lacing_returned;
  94185. unsigned char header[282]; /* working space for header encode */
  94186. int header_fill;
  94187. int e_o_s; /* set when we have buffered the last packet in the
  94188. logical bitstream */
  94189. int b_o_s; /* set after we've written the initial page
  94190. of a logical bitstream */
  94191. long serialno;
  94192. long pageno;
  94193. ogg_int64_t packetno; /* sequence number for decode; the framing
  94194. knows where there's a hole in the data,
  94195. but we need coupling so that the codec
  94196. (which is in a seperate abstraction
  94197. layer) also knows about the gap */
  94198. ogg_int64_t granulepos;
  94199. } ogg_stream_state;
  94200. typedef struct {
  94201. unsigned char *packet;
  94202. long bytes;
  94203. long b_o_s;
  94204. long e_o_s;
  94205. ogg_int64_t granulepos;
  94206. ogg_int64_t packetno; /* sequence number for decode; the framing
  94207. knows where there's a hole in the data,
  94208. but we need coupling so that the codec
  94209. (which is in a seperate abstraction
  94210. layer) also knows about the gap */
  94211. } ogg_packet;
  94212. typedef struct {
  94213. unsigned char *data;
  94214. int storage;
  94215. int fill;
  94216. int returned;
  94217. int unsynced;
  94218. int headerbytes;
  94219. int bodybytes;
  94220. } ogg_sync_state;
  94221. extern void oggpack_writeinit(oggpack_buffer *b);
  94222. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94223. extern void oggpack_writealign(oggpack_buffer *b);
  94224. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94225. extern void oggpack_reset(oggpack_buffer *b);
  94226. extern void oggpack_writeclear(oggpack_buffer *b);
  94227. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94228. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94229. extern long oggpack_look(oggpack_buffer *b,int bits);
  94230. extern long oggpack_look1(oggpack_buffer *b);
  94231. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94232. extern void oggpack_adv1(oggpack_buffer *b);
  94233. extern long oggpack_read(oggpack_buffer *b,int bits);
  94234. extern long oggpack_read1(oggpack_buffer *b);
  94235. extern long oggpack_bytes(oggpack_buffer *b);
  94236. extern long oggpack_bits(oggpack_buffer *b);
  94237. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94238. extern void oggpackB_writeinit(oggpack_buffer *b);
  94239. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94240. extern void oggpackB_writealign(oggpack_buffer *b);
  94241. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94242. extern void oggpackB_reset(oggpack_buffer *b);
  94243. extern void oggpackB_writeclear(oggpack_buffer *b);
  94244. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94245. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94246. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94247. extern long oggpackB_look1(oggpack_buffer *b);
  94248. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94249. extern void oggpackB_adv1(oggpack_buffer *b);
  94250. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94251. extern long oggpackB_read1(oggpack_buffer *b);
  94252. extern long oggpackB_bytes(oggpack_buffer *b);
  94253. extern long oggpackB_bits(oggpack_buffer *b);
  94254. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94255. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94256. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94257. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94258. extern int ogg_sync_init(ogg_sync_state *oy);
  94259. extern int ogg_sync_clear(ogg_sync_state *oy);
  94260. extern int ogg_sync_reset(ogg_sync_state *oy);
  94261. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94262. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94263. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94264. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94265. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94266. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94267. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94268. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94269. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94270. extern int ogg_stream_clear(ogg_stream_state *os);
  94271. extern int ogg_stream_reset(ogg_stream_state *os);
  94272. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94273. extern int ogg_stream_destroy(ogg_stream_state *os);
  94274. extern int ogg_stream_eos(ogg_stream_state *os);
  94275. extern void ogg_page_checksum_set(ogg_page *og);
  94276. extern int ogg_page_version(ogg_page *og);
  94277. extern int ogg_page_continued(ogg_page *og);
  94278. extern int ogg_page_bos(ogg_page *og);
  94279. extern int ogg_page_eos(ogg_page *og);
  94280. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94281. extern int ogg_page_serialno(ogg_page *og);
  94282. extern long ogg_page_pageno(ogg_page *og);
  94283. extern int ogg_page_packets(ogg_page *og);
  94284. extern void ogg_packet_clear(ogg_packet *op);
  94285. #ifdef __cplusplus
  94286. }
  94287. #endif
  94288. #endif /* _OGG_H */
  94289. /*** End of inlined file: ogg.h ***/
  94290. typedef struct vorbis_info{
  94291. int version;
  94292. int channels;
  94293. long rate;
  94294. long bitrate_upper;
  94295. long bitrate_nominal;
  94296. long bitrate_lower;
  94297. long bitrate_window;
  94298. void *codec_setup;
  94299. } vorbis_info;
  94300. typedef struct vorbis_dsp_state{
  94301. int analysisp;
  94302. vorbis_info *vi;
  94303. float **pcm;
  94304. float **pcmret;
  94305. int pcm_storage;
  94306. int pcm_current;
  94307. int pcm_returned;
  94308. int preextrapolate;
  94309. int eofflag;
  94310. long lW;
  94311. long W;
  94312. long nW;
  94313. long centerW;
  94314. ogg_int64_t granulepos;
  94315. ogg_int64_t sequence;
  94316. ogg_int64_t glue_bits;
  94317. ogg_int64_t time_bits;
  94318. ogg_int64_t floor_bits;
  94319. ogg_int64_t res_bits;
  94320. void *backend_state;
  94321. } vorbis_dsp_state;
  94322. typedef struct vorbis_block{
  94323. float **pcm; /* this is a pointer into local storage */
  94324. oggpack_buffer opb;
  94325. long lW;
  94326. long W;
  94327. long nW;
  94328. int pcmend;
  94329. int mode;
  94330. int eofflag;
  94331. ogg_int64_t granulepos;
  94332. ogg_int64_t sequence;
  94333. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94334. void *localstore;
  94335. long localtop;
  94336. long localalloc;
  94337. long totaluse;
  94338. struct alloc_chain *reap;
  94339. long glue_bits;
  94340. long time_bits;
  94341. long floor_bits;
  94342. long res_bits;
  94343. void *internal;
  94344. } vorbis_block;
  94345. struct alloc_chain{
  94346. void *ptr;
  94347. struct alloc_chain *next;
  94348. };
  94349. typedef struct vorbis_comment{
  94350. char **user_comments;
  94351. int *comment_lengths;
  94352. int comments;
  94353. char *vendor;
  94354. } vorbis_comment;
  94355. extern void vorbis_info_init(vorbis_info *vi);
  94356. extern void vorbis_info_clear(vorbis_info *vi);
  94357. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94358. extern void vorbis_comment_init(vorbis_comment *vc);
  94359. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94360. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94361. const char *tag, char *contents);
  94362. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94363. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94364. extern void vorbis_comment_clear(vorbis_comment *vc);
  94365. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94366. extern int vorbis_block_clear(vorbis_block *vb);
  94367. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94368. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94369. ogg_int64_t granulepos);
  94370. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94371. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94372. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94373. vorbis_comment *vc,
  94374. ogg_packet *op,
  94375. ogg_packet *op_comm,
  94376. ogg_packet *op_code);
  94377. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94378. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94379. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94380. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94381. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94382. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94383. ogg_packet *op);
  94384. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94385. ogg_packet *op);
  94386. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94387. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94388. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94389. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94390. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94391. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94392. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94393. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94394. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94395. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94396. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94397. #define OV_FALSE -1
  94398. #define OV_EOF -2
  94399. #define OV_HOLE -3
  94400. #define OV_EREAD -128
  94401. #define OV_EFAULT -129
  94402. #define OV_EIMPL -130
  94403. #define OV_EINVAL -131
  94404. #define OV_ENOTVORBIS -132
  94405. #define OV_EBADHEADER -133
  94406. #define OV_EVERSION -134
  94407. #define OV_ENOTAUDIO -135
  94408. #define OV_EBADPACKET -136
  94409. #define OV_EBADLINK -137
  94410. #define OV_ENOSEEK -138
  94411. #ifdef __cplusplus
  94412. }
  94413. #endif /* __cplusplus */
  94414. #endif
  94415. /*** End of inlined file: codec.h ***/
  94416. extern int vorbis_encode_init(vorbis_info *vi,
  94417. long channels,
  94418. long rate,
  94419. long max_bitrate,
  94420. long nominal_bitrate,
  94421. long min_bitrate);
  94422. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94423. long channels,
  94424. long rate,
  94425. long max_bitrate,
  94426. long nominal_bitrate,
  94427. long min_bitrate);
  94428. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94429. long channels,
  94430. long rate,
  94431. float quality /* quality level from 0. (lo) to 1. (hi) */
  94432. );
  94433. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94434. long channels,
  94435. long rate,
  94436. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94437. );
  94438. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94439. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94440. #define OV_ECTL_RATEMANAGE_GET 0x10
  94441. #define OV_ECTL_RATEMANAGE_SET 0x11
  94442. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94443. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94444. struct ovectl_ratemanage_arg {
  94445. int management_active;
  94446. long bitrate_hard_min;
  94447. long bitrate_hard_max;
  94448. double bitrate_hard_window;
  94449. long bitrate_av_lo;
  94450. long bitrate_av_hi;
  94451. double bitrate_av_window;
  94452. double bitrate_av_window_center;
  94453. };
  94454. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94455. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94456. struct ovectl_ratemanage2_arg {
  94457. int management_active;
  94458. long bitrate_limit_min_kbps;
  94459. long bitrate_limit_max_kbps;
  94460. long bitrate_limit_reservoir_bits;
  94461. double bitrate_limit_reservoir_bias;
  94462. long bitrate_average_kbps;
  94463. double bitrate_average_damping;
  94464. };
  94465. #define OV_ECTL_LOWPASS_GET 0x20
  94466. #define OV_ECTL_LOWPASS_SET 0x21
  94467. #define OV_ECTL_IBLOCK_GET 0x30
  94468. #define OV_ECTL_IBLOCK_SET 0x31
  94469. #ifdef __cplusplus
  94470. }
  94471. #endif /* __cplusplus */
  94472. #endif
  94473. /*** End of inlined file: vorbisenc.h ***/
  94474. /*** Start of inlined file: vorbisfile.h ***/
  94475. #ifndef _OV_FILE_H_
  94476. #define _OV_FILE_H_
  94477. #ifdef __cplusplus
  94478. extern "C"
  94479. {
  94480. #endif /* __cplusplus */
  94481. #include <stdio.h>
  94482. typedef struct {
  94483. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94484. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94485. int (*close_func) (void *datasource);
  94486. long (*tell_func) (void *datasource);
  94487. } ov_callbacks;
  94488. #define NOTOPEN 0
  94489. #define PARTOPEN 1
  94490. #define OPENED 2
  94491. #define STREAMSET 3
  94492. #define INITSET 4
  94493. typedef struct OggVorbis_File {
  94494. void *datasource; /* Pointer to a FILE *, etc. */
  94495. int seekable;
  94496. ogg_int64_t offset;
  94497. ogg_int64_t end;
  94498. ogg_sync_state oy;
  94499. int links;
  94500. ogg_int64_t *offsets;
  94501. ogg_int64_t *dataoffsets;
  94502. long *serialnos;
  94503. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94504. compatability; x2 size, stores both
  94505. beginning and end values */
  94506. vorbis_info *vi;
  94507. vorbis_comment *vc;
  94508. ogg_int64_t pcm_offset;
  94509. int ready_state;
  94510. long current_serialno;
  94511. int current_link;
  94512. double bittrack;
  94513. double samptrack;
  94514. ogg_stream_state os; /* take physical pages, weld into a logical
  94515. stream of packets */
  94516. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94517. vorbis_block vb; /* local working space for packet->PCM decode */
  94518. ov_callbacks callbacks;
  94519. } OggVorbis_File;
  94520. extern int ov_clear(OggVorbis_File *vf);
  94521. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94522. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94523. char *initial, long ibytes, ov_callbacks callbacks);
  94524. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94525. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94526. char *initial, long ibytes, ov_callbacks callbacks);
  94527. extern int ov_test_open(OggVorbis_File *vf);
  94528. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94529. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94530. extern long ov_streams(OggVorbis_File *vf);
  94531. extern long ov_seekable(OggVorbis_File *vf);
  94532. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94533. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94534. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94535. extern double ov_time_total(OggVorbis_File *vf,int i);
  94536. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94537. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94538. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94539. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94540. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94541. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94542. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94543. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94544. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94545. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94546. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94547. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94548. extern double ov_time_tell(OggVorbis_File *vf);
  94549. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94550. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94551. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94552. int *bitstream);
  94553. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94554. int bigendianp,int word,int sgned,int *bitstream);
  94555. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94556. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94557. extern int ov_halfrate_p(OggVorbis_File *vf);
  94558. #ifdef __cplusplus
  94559. }
  94560. #endif /* __cplusplus */
  94561. #endif
  94562. /*** End of inlined file: vorbisfile.h ***/
  94563. /*** Start of inlined file: bitwise.c ***/
  94564. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94565. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94566. // tasks..
  94567. #if JUCE_MSVC
  94568. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94569. #endif
  94570. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94571. #if JUCE_USE_OGGVORBIS
  94572. #include <string.h>
  94573. #include <stdlib.h>
  94574. #define BUFFER_INCREMENT 256
  94575. static const unsigned long mask[]=
  94576. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94577. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94578. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94579. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94580. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94581. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94582. 0x3fffffff,0x7fffffff,0xffffffff };
  94583. static const unsigned int mask8B[]=
  94584. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94585. void oggpack_writeinit(oggpack_buffer *b){
  94586. memset(b,0,sizeof(*b));
  94587. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94588. b->buffer[0]='\0';
  94589. b->storage=BUFFER_INCREMENT;
  94590. }
  94591. void oggpackB_writeinit(oggpack_buffer *b){
  94592. oggpack_writeinit(b);
  94593. }
  94594. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94595. long bytes=bits>>3;
  94596. bits-=bytes*8;
  94597. b->ptr=b->buffer+bytes;
  94598. b->endbit=bits;
  94599. b->endbyte=bytes;
  94600. *b->ptr&=mask[bits];
  94601. }
  94602. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94603. long bytes=bits>>3;
  94604. bits-=bytes*8;
  94605. b->ptr=b->buffer+bytes;
  94606. b->endbit=bits;
  94607. b->endbyte=bytes;
  94608. *b->ptr&=mask8B[bits];
  94609. }
  94610. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94611. if(b->endbyte+4>=b->storage){
  94612. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94613. b->storage+=BUFFER_INCREMENT;
  94614. b->ptr=b->buffer+b->endbyte;
  94615. }
  94616. value&=mask[bits];
  94617. bits+=b->endbit;
  94618. b->ptr[0]|=value<<b->endbit;
  94619. if(bits>=8){
  94620. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94621. if(bits>=16){
  94622. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94623. if(bits>=24){
  94624. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94625. if(bits>=32){
  94626. if(b->endbit)
  94627. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94628. else
  94629. b->ptr[4]=0;
  94630. }
  94631. }
  94632. }
  94633. }
  94634. b->endbyte+=bits/8;
  94635. b->ptr+=bits/8;
  94636. b->endbit=bits&7;
  94637. }
  94638. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94639. if(b->endbyte+4>=b->storage){
  94640. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94641. b->storage+=BUFFER_INCREMENT;
  94642. b->ptr=b->buffer+b->endbyte;
  94643. }
  94644. value=(value&mask[bits])<<(32-bits);
  94645. bits+=b->endbit;
  94646. b->ptr[0]|=value>>(24+b->endbit);
  94647. if(bits>=8){
  94648. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94649. if(bits>=16){
  94650. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94651. if(bits>=24){
  94652. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94653. if(bits>=32){
  94654. if(b->endbit)
  94655. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94656. else
  94657. b->ptr[4]=0;
  94658. }
  94659. }
  94660. }
  94661. }
  94662. b->endbyte+=bits/8;
  94663. b->ptr+=bits/8;
  94664. b->endbit=bits&7;
  94665. }
  94666. void oggpack_writealign(oggpack_buffer *b){
  94667. int bits=8-b->endbit;
  94668. if(bits<8)
  94669. oggpack_write(b,0,bits);
  94670. }
  94671. void oggpackB_writealign(oggpack_buffer *b){
  94672. int bits=8-b->endbit;
  94673. if(bits<8)
  94674. oggpackB_write(b,0,bits);
  94675. }
  94676. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94677. void *source,
  94678. long bits,
  94679. void (*w)(oggpack_buffer *,
  94680. unsigned long,
  94681. int),
  94682. int msb){
  94683. unsigned char *ptr=(unsigned char *)source;
  94684. long bytes=bits/8;
  94685. bits-=bytes*8;
  94686. if(b->endbit){
  94687. int i;
  94688. for(i=0;i<bytes;i++)
  94689. w(b,(unsigned long)(ptr[i]),8);
  94690. }else{
  94691. if(b->endbyte+bytes+1>=b->storage){
  94692. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94693. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94694. b->ptr=b->buffer+b->endbyte;
  94695. }
  94696. memmove(b->ptr,source,bytes);
  94697. b->ptr+=bytes;
  94698. b->endbyte+=bytes;
  94699. *b->ptr=0;
  94700. }
  94701. if(bits){
  94702. if(msb)
  94703. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94704. else
  94705. w(b,(unsigned long)(ptr[bytes]),bits);
  94706. }
  94707. }
  94708. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94709. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94710. }
  94711. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94712. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94713. }
  94714. void oggpack_reset(oggpack_buffer *b){
  94715. b->ptr=b->buffer;
  94716. b->buffer[0]=0;
  94717. b->endbit=b->endbyte=0;
  94718. }
  94719. void oggpackB_reset(oggpack_buffer *b){
  94720. oggpack_reset(b);
  94721. }
  94722. void oggpack_writeclear(oggpack_buffer *b){
  94723. _ogg_free(b->buffer);
  94724. memset(b,0,sizeof(*b));
  94725. }
  94726. void oggpackB_writeclear(oggpack_buffer *b){
  94727. oggpack_writeclear(b);
  94728. }
  94729. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94730. memset(b,0,sizeof(*b));
  94731. b->buffer=b->ptr=buf;
  94732. b->storage=bytes;
  94733. }
  94734. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94735. oggpack_readinit(b,buf,bytes);
  94736. }
  94737. long oggpack_look(oggpack_buffer *b,int bits){
  94738. unsigned long ret;
  94739. unsigned long m=mask[bits];
  94740. bits+=b->endbit;
  94741. if(b->endbyte+4>=b->storage){
  94742. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94743. }
  94744. ret=b->ptr[0]>>b->endbit;
  94745. if(bits>8){
  94746. ret|=b->ptr[1]<<(8-b->endbit);
  94747. if(bits>16){
  94748. ret|=b->ptr[2]<<(16-b->endbit);
  94749. if(bits>24){
  94750. ret|=b->ptr[3]<<(24-b->endbit);
  94751. if(bits>32 && b->endbit)
  94752. ret|=b->ptr[4]<<(32-b->endbit);
  94753. }
  94754. }
  94755. }
  94756. return(m&ret);
  94757. }
  94758. long oggpackB_look(oggpack_buffer *b,int bits){
  94759. unsigned long ret;
  94760. int m=32-bits;
  94761. bits+=b->endbit;
  94762. if(b->endbyte+4>=b->storage){
  94763. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94764. }
  94765. ret=b->ptr[0]<<(24+b->endbit);
  94766. if(bits>8){
  94767. ret|=b->ptr[1]<<(16+b->endbit);
  94768. if(bits>16){
  94769. ret|=b->ptr[2]<<(8+b->endbit);
  94770. if(bits>24){
  94771. ret|=b->ptr[3]<<(b->endbit);
  94772. if(bits>32 && b->endbit)
  94773. ret|=b->ptr[4]>>(8-b->endbit);
  94774. }
  94775. }
  94776. }
  94777. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94778. }
  94779. long oggpack_look1(oggpack_buffer *b){
  94780. if(b->endbyte>=b->storage)return(-1);
  94781. return((b->ptr[0]>>b->endbit)&1);
  94782. }
  94783. long oggpackB_look1(oggpack_buffer *b){
  94784. if(b->endbyte>=b->storage)return(-1);
  94785. return((b->ptr[0]>>(7-b->endbit))&1);
  94786. }
  94787. void oggpack_adv(oggpack_buffer *b,int bits){
  94788. bits+=b->endbit;
  94789. b->ptr+=bits/8;
  94790. b->endbyte+=bits/8;
  94791. b->endbit=bits&7;
  94792. }
  94793. void oggpackB_adv(oggpack_buffer *b,int bits){
  94794. oggpack_adv(b,bits);
  94795. }
  94796. void oggpack_adv1(oggpack_buffer *b){
  94797. if(++(b->endbit)>7){
  94798. b->endbit=0;
  94799. b->ptr++;
  94800. b->endbyte++;
  94801. }
  94802. }
  94803. void oggpackB_adv1(oggpack_buffer *b){
  94804. oggpack_adv1(b);
  94805. }
  94806. long oggpack_read(oggpack_buffer *b,int bits){
  94807. long ret;
  94808. unsigned long m=mask[bits];
  94809. bits+=b->endbit;
  94810. if(b->endbyte+4>=b->storage){
  94811. ret=-1L;
  94812. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94813. }
  94814. ret=b->ptr[0]>>b->endbit;
  94815. if(bits>8){
  94816. ret|=b->ptr[1]<<(8-b->endbit);
  94817. if(bits>16){
  94818. ret|=b->ptr[2]<<(16-b->endbit);
  94819. if(bits>24){
  94820. ret|=b->ptr[3]<<(24-b->endbit);
  94821. if(bits>32 && b->endbit){
  94822. ret|=b->ptr[4]<<(32-b->endbit);
  94823. }
  94824. }
  94825. }
  94826. }
  94827. ret&=m;
  94828. overflow:
  94829. b->ptr+=bits/8;
  94830. b->endbyte+=bits/8;
  94831. b->endbit=bits&7;
  94832. return(ret);
  94833. }
  94834. long oggpackB_read(oggpack_buffer *b,int bits){
  94835. long ret;
  94836. long m=32-bits;
  94837. bits+=b->endbit;
  94838. if(b->endbyte+4>=b->storage){
  94839. ret=-1L;
  94840. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94841. }
  94842. ret=b->ptr[0]<<(24+b->endbit);
  94843. if(bits>8){
  94844. ret|=b->ptr[1]<<(16+b->endbit);
  94845. if(bits>16){
  94846. ret|=b->ptr[2]<<(8+b->endbit);
  94847. if(bits>24){
  94848. ret|=b->ptr[3]<<(b->endbit);
  94849. if(bits>32 && b->endbit)
  94850. ret|=b->ptr[4]>>(8-b->endbit);
  94851. }
  94852. }
  94853. }
  94854. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  94855. overflow:
  94856. b->ptr+=bits/8;
  94857. b->endbyte+=bits/8;
  94858. b->endbit=bits&7;
  94859. return(ret);
  94860. }
  94861. long oggpack_read1(oggpack_buffer *b){
  94862. long ret;
  94863. if(b->endbyte>=b->storage){
  94864. ret=-1L;
  94865. goto overflow;
  94866. }
  94867. ret=(b->ptr[0]>>b->endbit)&1;
  94868. overflow:
  94869. b->endbit++;
  94870. if(b->endbit>7){
  94871. b->endbit=0;
  94872. b->ptr++;
  94873. b->endbyte++;
  94874. }
  94875. return(ret);
  94876. }
  94877. long oggpackB_read1(oggpack_buffer *b){
  94878. long ret;
  94879. if(b->endbyte>=b->storage){
  94880. ret=-1L;
  94881. goto overflow;
  94882. }
  94883. ret=(b->ptr[0]>>(7-b->endbit))&1;
  94884. overflow:
  94885. b->endbit++;
  94886. if(b->endbit>7){
  94887. b->endbit=0;
  94888. b->ptr++;
  94889. b->endbyte++;
  94890. }
  94891. return(ret);
  94892. }
  94893. long oggpack_bytes(oggpack_buffer *b){
  94894. return(b->endbyte+(b->endbit+7)/8);
  94895. }
  94896. long oggpack_bits(oggpack_buffer *b){
  94897. return(b->endbyte*8+b->endbit);
  94898. }
  94899. long oggpackB_bytes(oggpack_buffer *b){
  94900. return oggpack_bytes(b);
  94901. }
  94902. long oggpackB_bits(oggpack_buffer *b){
  94903. return oggpack_bits(b);
  94904. }
  94905. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  94906. return(b->buffer);
  94907. }
  94908. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  94909. return oggpack_get_buffer(b);
  94910. }
  94911. #ifdef _V_SELFTEST
  94912. #include <stdio.h>
  94913. static int ilog(unsigned int v){
  94914. int ret=0;
  94915. while(v){
  94916. ret++;
  94917. v>>=1;
  94918. }
  94919. return(ret);
  94920. }
  94921. oggpack_buffer o;
  94922. oggpack_buffer r;
  94923. void report(char *in){
  94924. fprintf(stderr,"%s",in);
  94925. exit(1);
  94926. }
  94927. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  94928. long bytes,i;
  94929. unsigned char *buffer;
  94930. oggpack_reset(&o);
  94931. for(i=0;i<vals;i++)
  94932. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  94933. buffer=oggpack_get_buffer(&o);
  94934. bytes=oggpack_bytes(&o);
  94935. if(bytes!=compsize)report("wrong number of bytes!\n");
  94936. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  94937. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  94938. report("wrote incorrect value!\n");
  94939. }
  94940. oggpack_readinit(&r,buffer,bytes);
  94941. for(i=0;i<vals;i++){
  94942. int tbit=bits?bits:ilog(b[i]);
  94943. if(oggpack_look(&r,tbit)==-1)
  94944. report("out of data!\n");
  94945. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  94946. report("looked at incorrect value!\n");
  94947. if(tbit==1)
  94948. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  94949. report("looked at single bit incorrect value!\n");
  94950. if(tbit==1){
  94951. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  94952. report("read incorrect single bit value!\n");
  94953. }else{
  94954. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  94955. report("read incorrect value!\n");
  94956. }
  94957. }
  94958. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  94959. }
  94960. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  94961. long bytes,i;
  94962. unsigned char *buffer;
  94963. oggpackB_reset(&o);
  94964. for(i=0;i<vals;i++)
  94965. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  94966. buffer=oggpackB_get_buffer(&o);
  94967. bytes=oggpackB_bytes(&o);
  94968. if(bytes!=compsize)report("wrong number of bytes!\n");
  94969. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  94970. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  94971. report("wrote incorrect value!\n");
  94972. }
  94973. oggpackB_readinit(&r,buffer,bytes);
  94974. for(i=0;i<vals;i++){
  94975. int tbit=bits?bits:ilog(b[i]);
  94976. if(oggpackB_look(&r,tbit)==-1)
  94977. report("out of data!\n");
  94978. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  94979. report("looked at incorrect value!\n");
  94980. if(tbit==1)
  94981. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  94982. report("looked at single bit incorrect value!\n");
  94983. if(tbit==1){
  94984. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  94985. report("read incorrect single bit value!\n");
  94986. }else{
  94987. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  94988. report("read incorrect value!\n");
  94989. }
  94990. }
  94991. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  94992. }
  94993. int main(void){
  94994. unsigned char *buffer;
  94995. long bytes,i;
  94996. static unsigned long testbuffer1[]=
  94997. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  94998. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  94999. int test1size=43;
  95000. static unsigned long testbuffer2[]=
  95001. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95002. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95003. 85525151,0,12321,1,349528352};
  95004. int test2size=21;
  95005. static unsigned long testbuffer3[]=
  95006. {1,0,14,0,1,0,12,0,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,1,1,1,1,0,0,1,
  95007. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95008. int test3size=56;
  95009. static unsigned long large[]=
  95010. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95011. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95012. 85525151,0,12321,1,2146528352};
  95013. int onesize=33;
  95014. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95015. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95016. 223,4};
  95017. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95018. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95019. 245,251,128};
  95020. int twosize=6;
  95021. static int two[6]={61,255,255,251,231,29};
  95022. static int twoB[6]={247,63,255,253,249,120};
  95023. int threesize=54;
  95024. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95025. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95026. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95027. 100,52,4,14,18,86,77,1};
  95028. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95029. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95030. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95031. 200,20,254,4,58,106,176,144,0};
  95032. int foursize=38;
  95033. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95034. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95035. 28,2,133,0,1};
  95036. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95037. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95038. 129,10,4,32};
  95039. int fivesize=45;
  95040. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95041. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95042. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95043. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95044. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95045. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95046. int sixsize=7;
  95047. static int six[7]={17,177,170,242,169,19,148};
  95048. static int sixB[7]={136,141,85,79,149,200,41};
  95049. oggpack_writeinit(&o);
  95050. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95051. cliptest(testbuffer1,test1size,0,one,onesize);
  95052. fprintf(stderr,"ok.");
  95053. fprintf(stderr,"\nNull bit call (LSb): ");
  95054. cliptest(testbuffer3,test3size,0,two,twosize);
  95055. fprintf(stderr,"ok.");
  95056. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95057. cliptest(testbuffer2,test2size,0,three,threesize);
  95058. fprintf(stderr,"ok.");
  95059. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95060. oggpack_reset(&o);
  95061. for(i=0;i<test2size;i++)
  95062. oggpack_write(&o,large[i],32);
  95063. buffer=oggpack_get_buffer(&o);
  95064. bytes=oggpack_bytes(&o);
  95065. oggpack_readinit(&r,buffer,bytes);
  95066. for(i=0;i<test2size;i++){
  95067. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95068. if(oggpack_look(&r,32)!=large[i]){
  95069. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95070. oggpack_look(&r,32),large[i]);
  95071. report("read incorrect value!\n");
  95072. }
  95073. oggpack_adv(&r,32);
  95074. }
  95075. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95076. fprintf(stderr,"ok.");
  95077. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95078. cliptest(testbuffer1,test1size,7,four,foursize);
  95079. fprintf(stderr,"ok.");
  95080. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95081. cliptest(testbuffer2,test2size,17,five,fivesize);
  95082. fprintf(stderr,"ok.");
  95083. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95084. cliptest(testbuffer3,test3size,1,six,sixsize);
  95085. fprintf(stderr,"ok.");
  95086. fprintf(stderr,"\nTesting read past end (LSb): ");
  95087. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95088. for(i=0;i<64;i++){
  95089. if(oggpack_read(&r,1)!=0){
  95090. fprintf(stderr,"failed; got -1 prematurely.\n");
  95091. exit(1);
  95092. }
  95093. }
  95094. if(oggpack_look(&r,1)!=-1 ||
  95095. oggpack_read(&r,1)!=-1){
  95096. fprintf(stderr,"failed; read past end without -1.\n");
  95097. exit(1);
  95098. }
  95099. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95100. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95101. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95102. exit(1);
  95103. }
  95104. if(oggpack_look(&r,18)!=0 ||
  95105. oggpack_look(&r,18)!=0){
  95106. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95107. exit(1);
  95108. }
  95109. if(oggpack_look(&r,19)!=-1 ||
  95110. oggpack_look(&r,19)!=-1){
  95111. fprintf(stderr,"failed; read past end without -1.\n");
  95112. exit(1);
  95113. }
  95114. if(oggpack_look(&r,32)!=-1 ||
  95115. oggpack_look(&r,32)!=-1){
  95116. fprintf(stderr,"failed; read past end without -1.\n");
  95117. exit(1);
  95118. }
  95119. oggpack_writeclear(&o);
  95120. fprintf(stderr,"ok.\n");
  95121. oggpackB_writeinit(&o);
  95122. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95123. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95124. fprintf(stderr,"ok.");
  95125. fprintf(stderr,"\nNull bit call (MSb): ");
  95126. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95127. fprintf(stderr,"ok.");
  95128. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95129. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95130. fprintf(stderr,"ok.");
  95131. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95132. oggpackB_reset(&o);
  95133. for(i=0;i<test2size;i++)
  95134. oggpackB_write(&o,large[i],32);
  95135. buffer=oggpackB_get_buffer(&o);
  95136. bytes=oggpackB_bytes(&o);
  95137. oggpackB_readinit(&r,buffer,bytes);
  95138. for(i=0;i<test2size;i++){
  95139. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95140. if(oggpackB_look(&r,32)!=large[i]){
  95141. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95142. oggpackB_look(&r,32),large[i]);
  95143. report("read incorrect value!\n");
  95144. }
  95145. oggpackB_adv(&r,32);
  95146. }
  95147. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95148. fprintf(stderr,"ok.");
  95149. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95150. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95151. fprintf(stderr,"ok.");
  95152. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95153. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95154. fprintf(stderr,"ok.");
  95155. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95156. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95157. fprintf(stderr,"ok.");
  95158. fprintf(stderr,"\nTesting read past end (MSb): ");
  95159. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95160. for(i=0;i<64;i++){
  95161. if(oggpackB_read(&r,1)!=0){
  95162. fprintf(stderr,"failed; got -1 prematurely.\n");
  95163. exit(1);
  95164. }
  95165. }
  95166. if(oggpackB_look(&r,1)!=-1 ||
  95167. oggpackB_read(&r,1)!=-1){
  95168. fprintf(stderr,"failed; read past end without -1.\n");
  95169. exit(1);
  95170. }
  95171. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95172. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95173. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95174. exit(1);
  95175. }
  95176. if(oggpackB_look(&r,18)!=0 ||
  95177. oggpackB_look(&r,18)!=0){
  95178. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95179. exit(1);
  95180. }
  95181. if(oggpackB_look(&r,19)!=-1 ||
  95182. oggpackB_look(&r,19)!=-1){
  95183. fprintf(stderr,"failed; read past end without -1.\n");
  95184. exit(1);
  95185. }
  95186. if(oggpackB_look(&r,32)!=-1 ||
  95187. oggpackB_look(&r,32)!=-1){
  95188. fprintf(stderr,"failed; read past end without -1.\n");
  95189. exit(1);
  95190. }
  95191. oggpackB_writeclear(&o);
  95192. fprintf(stderr,"ok.\n\n");
  95193. return(0);
  95194. }
  95195. #endif /* _V_SELFTEST */
  95196. #undef BUFFER_INCREMENT
  95197. #endif
  95198. /*** End of inlined file: bitwise.c ***/
  95199. /*** Start of inlined file: framing.c ***/
  95200. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95201. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95202. // tasks..
  95203. #if JUCE_MSVC
  95204. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95205. #endif
  95206. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95207. #if JUCE_USE_OGGVORBIS
  95208. #include <stdlib.h>
  95209. #include <string.h>
  95210. int ogg_page_version(ogg_page *og){
  95211. return((int)(og->header[4]));
  95212. }
  95213. int ogg_page_continued(ogg_page *og){
  95214. return((int)(og->header[5]&0x01));
  95215. }
  95216. int ogg_page_bos(ogg_page *og){
  95217. return((int)(og->header[5]&0x02));
  95218. }
  95219. int ogg_page_eos(ogg_page *og){
  95220. return((int)(og->header[5]&0x04));
  95221. }
  95222. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95223. unsigned char *page=og->header;
  95224. ogg_int64_t granulepos=page[13]&(0xff);
  95225. granulepos= (granulepos<<8)|(page[12]&0xff);
  95226. granulepos= (granulepos<<8)|(page[11]&0xff);
  95227. granulepos= (granulepos<<8)|(page[10]&0xff);
  95228. granulepos= (granulepos<<8)|(page[9]&0xff);
  95229. granulepos= (granulepos<<8)|(page[8]&0xff);
  95230. granulepos= (granulepos<<8)|(page[7]&0xff);
  95231. granulepos= (granulepos<<8)|(page[6]&0xff);
  95232. return(granulepos);
  95233. }
  95234. int ogg_page_serialno(ogg_page *og){
  95235. return(og->header[14] |
  95236. (og->header[15]<<8) |
  95237. (og->header[16]<<16) |
  95238. (og->header[17]<<24));
  95239. }
  95240. long ogg_page_pageno(ogg_page *og){
  95241. return(og->header[18] |
  95242. (og->header[19]<<8) |
  95243. (og->header[20]<<16) |
  95244. (og->header[21]<<24));
  95245. }
  95246. int ogg_page_packets(ogg_page *og){
  95247. int i,n=og->header[26],count=0;
  95248. for(i=0;i<n;i++)
  95249. if(og->header[27+i]<255)count++;
  95250. return(count);
  95251. }
  95252. #if 0
  95253. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95254. int i;
  95255. unsigned long r;
  95256. r = index << 24;
  95257. for (i=0; i<8; i++)
  95258. if (r & 0x80000000UL)
  95259. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95260. polynomial, although we use an
  95261. unreflected alg and an init/final
  95262. of 0, not 0xffffffff */
  95263. else
  95264. r<<=1;
  95265. return (r & 0xffffffffUL);
  95266. }
  95267. #endif
  95268. static const ogg_uint32_t crc_lookup[256]={
  95269. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95270. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95271. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95272. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95273. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95274. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95275. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95276. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95277. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95278. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95279. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95280. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95281. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95282. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95283. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95284. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95285. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95286. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95287. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95288. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95289. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95290. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95291. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95292. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95293. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95294. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95295. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95296. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95297. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95298. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95299. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95300. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95301. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95302. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95303. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95304. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95305. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95306. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95307. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95308. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95309. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95310. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95311. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95312. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95313. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95314. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95315. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95316. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95317. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95318. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95319. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95320. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95321. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95322. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95323. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95324. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95325. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95326. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95327. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95328. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95329. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95330. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95331. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95332. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95333. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95334. if(os){
  95335. memset(os,0,sizeof(*os));
  95336. os->body_storage=16*1024;
  95337. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95338. os->lacing_storage=1024;
  95339. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95340. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95341. os->serialno=serialno;
  95342. return(0);
  95343. }
  95344. return(-1);
  95345. }
  95346. int ogg_stream_clear(ogg_stream_state *os){
  95347. if(os){
  95348. if(os->body_data)_ogg_free(os->body_data);
  95349. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95350. if(os->granule_vals)_ogg_free(os->granule_vals);
  95351. memset(os,0,sizeof(*os));
  95352. }
  95353. return(0);
  95354. }
  95355. int ogg_stream_destroy(ogg_stream_state *os){
  95356. if(os){
  95357. ogg_stream_clear(os);
  95358. _ogg_free(os);
  95359. }
  95360. return(0);
  95361. }
  95362. static void _os_body_expand(ogg_stream_state *os,int needed){
  95363. if(os->body_storage<=os->body_fill+needed){
  95364. os->body_storage+=(needed+1024);
  95365. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95366. }
  95367. }
  95368. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95369. if(os->lacing_storage<=os->lacing_fill+needed){
  95370. os->lacing_storage+=(needed+32);
  95371. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95372. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95373. }
  95374. }
  95375. void ogg_page_checksum_set(ogg_page *og){
  95376. if(og){
  95377. ogg_uint32_t crc_reg=0;
  95378. int i;
  95379. og->header[22]=0;
  95380. og->header[23]=0;
  95381. og->header[24]=0;
  95382. og->header[25]=0;
  95383. for(i=0;i<og->header_len;i++)
  95384. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95385. for(i=0;i<og->body_len;i++)
  95386. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95387. og->header[22]=(unsigned char)(crc_reg&0xff);
  95388. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95389. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95390. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95391. }
  95392. }
  95393. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95394. int lacing_vals=op->bytes/255+1,i;
  95395. if(os->body_returned){
  95396. os->body_fill-=os->body_returned;
  95397. if(os->body_fill)
  95398. memmove(os->body_data,os->body_data+os->body_returned,
  95399. os->body_fill);
  95400. os->body_returned=0;
  95401. }
  95402. _os_body_expand(os,op->bytes);
  95403. _os_lacing_expand(os,lacing_vals);
  95404. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95405. os->body_fill+=op->bytes;
  95406. for(i=0;i<lacing_vals-1;i++){
  95407. os->lacing_vals[os->lacing_fill+i]=255;
  95408. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95409. }
  95410. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95411. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95412. os->lacing_vals[os->lacing_fill]|= 0x100;
  95413. os->lacing_fill+=lacing_vals;
  95414. os->packetno++;
  95415. if(op->e_o_s)os->e_o_s=1;
  95416. return(0);
  95417. }
  95418. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95419. int i;
  95420. int vals=0;
  95421. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95422. int bytes=0;
  95423. long acc=0;
  95424. ogg_int64_t granule_pos=-1;
  95425. if(maxvals==0)return(0);
  95426. if(os->b_o_s==0){ /* 'initial header page' case */
  95427. granule_pos=0;
  95428. for(vals=0;vals<maxvals;vals++){
  95429. if((os->lacing_vals[vals]&0x0ff)<255){
  95430. vals++;
  95431. break;
  95432. }
  95433. }
  95434. }else{
  95435. for(vals=0;vals<maxvals;vals++){
  95436. if(acc>4096)break;
  95437. acc+=os->lacing_vals[vals]&0x0ff;
  95438. if((os->lacing_vals[vals]&0xff)<255)
  95439. granule_pos=os->granule_vals[vals];
  95440. }
  95441. }
  95442. memcpy(os->header,"OggS",4);
  95443. os->header[4]=0x00;
  95444. os->header[5]=0x00;
  95445. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95446. if(os->b_o_s==0)os->header[5]|=0x02;
  95447. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95448. os->b_o_s=1;
  95449. for(i=6;i<14;i++){
  95450. os->header[i]=(unsigned char)(granule_pos&0xff);
  95451. granule_pos>>=8;
  95452. }
  95453. {
  95454. long serialno=os->serialno;
  95455. for(i=14;i<18;i++){
  95456. os->header[i]=(unsigned char)(serialno&0xff);
  95457. serialno>>=8;
  95458. }
  95459. }
  95460. if(os->pageno==-1)os->pageno=0; /* because someone called
  95461. stream_reset; this would be a
  95462. strange thing to do in an
  95463. encode stream, but it has
  95464. plausible uses */
  95465. {
  95466. long pageno=os->pageno++;
  95467. for(i=18;i<22;i++){
  95468. os->header[i]=(unsigned char)(pageno&0xff);
  95469. pageno>>=8;
  95470. }
  95471. }
  95472. os->header[22]=0;
  95473. os->header[23]=0;
  95474. os->header[24]=0;
  95475. os->header[25]=0;
  95476. os->header[26]=(unsigned char)(vals&0xff);
  95477. for(i=0;i<vals;i++)
  95478. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95479. og->header=os->header;
  95480. og->header_len=os->header_fill=vals+27;
  95481. og->body=os->body_data+os->body_returned;
  95482. og->body_len=bytes;
  95483. os->lacing_fill-=vals;
  95484. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95485. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95486. os->body_returned+=bytes;
  95487. ogg_page_checksum_set(og);
  95488. return(1);
  95489. }
  95490. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95491. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95492. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95493. os->lacing_fill>=255 || /* 'segment table full' case */
  95494. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95495. return(ogg_stream_flush(os,og));
  95496. }
  95497. return(0);
  95498. }
  95499. int ogg_stream_eos(ogg_stream_state *os){
  95500. return os->e_o_s;
  95501. }
  95502. int ogg_sync_init(ogg_sync_state *oy){
  95503. if(oy){
  95504. memset(oy,0,sizeof(*oy));
  95505. }
  95506. return(0);
  95507. }
  95508. int ogg_sync_clear(ogg_sync_state *oy){
  95509. if(oy){
  95510. if(oy->data)_ogg_free(oy->data);
  95511. ogg_sync_init(oy);
  95512. }
  95513. return(0);
  95514. }
  95515. int ogg_sync_destroy(ogg_sync_state *oy){
  95516. if(oy){
  95517. ogg_sync_clear(oy);
  95518. _ogg_free(oy);
  95519. }
  95520. return(0);
  95521. }
  95522. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95523. if(oy->returned){
  95524. oy->fill-=oy->returned;
  95525. if(oy->fill>0)
  95526. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95527. oy->returned=0;
  95528. }
  95529. if(size>oy->storage-oy->fill){
  95530. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95531. if(oy->data)
  95532. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95533. else
  95534. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95535. oy->storage=newsize;
  95536. }
  95537. return((char *)oy->data+oy->fill);
  95538. }
  95539. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95540. if(oy->fill+bytes>oy->storage)return(-1);
  95541. oy->fill+=bytes;
  95542. return(0);
  95543. }
  95544. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95545. unsigned char *page=oy->data+oy->returned;
  95546. unsigned char *next;
  95547. long bytes=oy->fill-oy->returned;
  95548. if(oy->headerbytes==0){
  95549. int headerbytes,i;
  95550. if(bytes<27)return(0); /* not enough for a header */
  95551. if(memcmp(page,"OggS",4))goto sync_fail;
  95552. headerbytes=page[26]+27;
  95553. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95554. for(i=0;i<page[26];i++)
  95555. oy->bodybytes+=page[27+i];
  95556. oy->headerbytes=headerbytes;
  95557. }
  95558. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95559. {
  95560. char chksum[4];
  95561. ogg_page log;
  95562. memcpy(chksum,page+22,4);
  95563. memset(page+22,0,4);
  95564. log.header=page;
  95565. log.header_len=oy->headerbytes;
  95566. log.body=page+oy->headerbytes;
  95567. log.body_len=oy->bodybytes;
  95568. ogg_page_checksum_set(&log);
  95569. if(memcmp(chksum,page+22,4)){
  95570. memcpy(page+22,chksum,4);
  95571. goto sync_fail;
  95572. }
  95573. }
  95574. {
  95575. unsigned char *page=oy->data+oy->returned;
  95576. long bytes;
  95577. if(og){
  95578. og->header=page;
  95579. og->header_len=oy->headerbytes;
  95580. og->body=page+oy->headerbytes;
  95581. og->body_len=oy->bodybytes;
  95582. }
  95583. oy->unsynced=0;
  95584. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95585. oy->headerbytes=0;
  95586. oy->bodybytes=0;
  95587. return(bytes);
  95588. }
  95589. sync_fail:
  95590. oy->headerbytes=0;
  95591. oy->bodybytes=0;
  95592. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95593. if(!next)
  95594. next=oy->data+oy->fill;
  95595. oy->returned=next-oy->data;
  95596. return(-(next-page));
  95597. }
  95598. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95599. for(;;){
  95600. long ret=ogg_sync_pageseek(oy,og);
  95601. if(ret>0){
  95602. return(1);
  95603. }
  95604. if(ret==0){
  95605. return(0);
  95606. }
  95607. if(!oy->unsynced){
  95608. oy->unsynced=1;
  95609. return(-1);
  95610. }
  95611. }
  95612. }
  95613. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95614. unsigned char *header=og->header;
  95615. unsigned char *body=og->body;
  95616. long bodysize=og->body_len;
  95617. int segptr=0;
  95618. int version=ogg_page_version(og);
  95619. int continued=ogg_page_continued(og);
  95620. int bos=ogg_page_bos(og);
  95621. int eos=ogg_page_eos(og);
  95622. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95623. int serialno=ogg_page_serialno(og);
  95624. long pageno=ogg_page_pageno(og);
  95625. int segments=header[26];
  95626. {
  95627. long lr=os->lacing_returned;
  95628. long br=os->body_returned;
  95629. if(br){
  95630. os->body_fill-=br;
  95631. if(os->body_fill)
  95632. memmove(os->body_data,os->body_data+br,os->body_fill);
  95633. os->body_returned=0;
  95634. }
  95635. if(lr){
  95636. if(os->lacing_fill-lr){
  95637. memmove(os->lacing_vals,os->lacing_vals+lr,
  95638. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95639. memmove(os->granule_vals,os->granule_vals+lr,
  95640. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95641. }
  95642. os->lacing_fill-=lr;
  95643. os->lacing_packet-=lr;
  95644. os->lacing_returned=0;
  95645. }
  95646. }
  95647. if(serialno!=os->serialno)return(-1);
  95648. if(version>0)return(-1);
  95649. _os_lacing_expand(os,segments+1);
  95650. if(pageno!=os->pageno){
  95651. int i;
  95652. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95653. os->body_fill-=os->lacing_vals[i]&0xff;
  95654. os->lacing_fill=os->lacing_packet;
  95655. if(os->pageno!=-1){
  95656. os->lacing_vals[os->lacing_fill++]=0x400;
  95657. os->lacing_packet++;
  95658. }
  95659. }
  95660. if(continued){
  95661. if(os->lacing_fill<1 ||
  95662. os->lacing_vals[os->lacing_fill-1]==0x400){
  95663. bos=0;
  95664. for(;segptr<segments;segptr++){
  95665. int val=header[27+segptr];
  95666. body+=val;
  95667. bodysize-=val;
  95668. if(val<255){
  95669. segptr++;
  95670. break;
  95671. }
  95672. }
  95673. }
  95674. }
  95675. if(bodysize){
  95676. _os_body_expand(os,bodysize);
  95677. memcpy(os->body_data+os->body_fill,body,bodysize);
  95678. os->body_fill+=bodysize;
  95679. }
  95680. {
  95681. int saved=-1;
  95682. while(segptr<segments){
  95683. int val=header[27+segptr];
  95684. os->lacing_vals[os->lacing_fill]=val;
  95685. os->granule_vals[os->lacing_fill]=-1;
  95686. if(bos){
  95687. os->lacing_vals[os->lacing_fill]|=0x100;
  95688. bos=0;
  95689. }
  95690. if(val<255)saved=os->lacing_fill;
  95691. os->lacing_fill++;
  95692. segptr++;
  95693. if(val<255)os->lacing_packet=os->lacing_fill;
  95694. }
  95695. if(saved!=-1){
  95696. os->granule_vals[saved]=granulepos;
  95697. }
  95698. }
  95699. if(eos){
  95700. os->e_o_s=1;
  95701. if(os->lacing_fill>0)
  95702. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95703. }
  95704. os->pageno=pageno+1;
  95705. return(0);
  95706. }
  95707. int ogg_sync_reset(ogg_sync_state *oy){
  95708. oy->fill=0;
  95709. oy->returned=0;
  95710. oy->unsynced=0;
  95711. oy->headerbytes=0;
  95712. oy->bodybytes=0;
  95713. return(0);
  95714. }
  95715. int ogg_stream_reset(ogg_stream_state *os){
  95716. os->body_fill=0;
  95717. os->body_returned=0;
  95718. os->lacing_fill=0;
  95719. os->lacing_packet=0;
  95720. os->lacing_returned=0;
  95721. os->header_fill=0;
  95722. os->e_o_s=0;
  95723. os->b_o_s=0;
  95724. os->pageno=-1;
  95725. os->packetno=0;
  95726. os->granulepos=0;
  95727. return(0);
  95728. }
  95729. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95730. ogg_stream_reset(os);
  95731. os->serialno=serialno;
  95732. return(0);
  95733. }
  95734. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95735. int ptr=os->lacing_returned;
  95736. if(os->lacing_packet<=ptr)return(0);
  95737. if(os->lacing_vals[ptr]&0x400){
  95738. os->lacing_returned++;
  95739. os->packetno++;
  95740. return(-1);
  95741. }
  95742. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95743. to ask if there's a whole packet
  95744. waiting */
  95745. {
  95746. int size=os->lacing_vals[ptr]&0xff;
  95747. int bytes=size;
  95748. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95749. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95750. while(size==255){
  95751. int val=os->lacing_vals[++ptr];
  95752. size=val&0xff;
  95753. if(val&0x200)eos=0x200;
  95754. bytes+=size;
  95755. }
  95756. if(op){
  95757. op->e_o_s=eos;
  95758. op->b_o_s=bos;
  95759. op->packet=os->body_data+os->body_returned;
  95760. op->packetno=os->packetno;
  95761. op->granulepos=os->granule_vals[ptr];
  95762. op->bytes=bytes;
  95763. }
  95764. if(adv){
  95765. os->body_returned+=bytes;
  95766. os->lacing_returned=ptr+1;
  95767. os->packetno++;
  95768. }
  95769. }
  95770. return(1);
  95771. }
  95772. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95773. return _packetout(os,op,1);
  95774. }
  95775. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95776. return _packetout(os,op,0);
  95777. }
  95778. void ogg_packet_clear(ogg_packet *op) {
  95779. _ogg_free(op->packet);
  95780. memset(op, 0, sizeof(*op));
  95781. }
  95782. #ifdef _V_SELFTEST
  95783. #include <stdio.h>
  95784. ogg_stream_state os_en, os_de;
  95785. ogg_sync_state oy;
  95786. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95787. long j;
  95788. static int sequence=0;
  95789. static int lastno=0;
  95790. if(op->bytes!=len){
  95791. fprintf(stderr,"incorrect packet length!\n");
  95792. exit(1);
  95793. }
  95794. if(op->granulepos!=pos){
  95795. fprintf(stderr,"incorrect packet position!\n");
  95796. exit(1);
  95797. }
  95798. if(no==0){
  95799. sequence=0;
  95800. }else{
  95801. sequence++;
  95802. if(no>lastno+1)
  95803. sequence++;
  95804. }
  95805. lastno=no;
  95806. if(op->packetno!=sequence){
  95807. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95808. (long)(op->packetno),sequence);
  95809. exit(1);
  95810. }
  95811. for(j=0;j<op->bytes;j++)
  95812. if(op->packet[j]!=((j+no)&0xff)){
  95813. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  95814. j,op->packet[j],(j+no)&0xff);
  95815. exit(1);
  95816. }
  95817. }
  95818. void check_page(unsigned char *data,const int *header,ogg_page *og){
  95819. long j;
  95820. for(j=0;j<og->body_len;j++)
  95821. if(og->body[j]!=data[j]){
  95822. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  95823. j,data[j],og->body[j]);
  95824. exit(1);
  95825. }
  95826. for(j=0;j<og->header_len;j++){
  95827. if(og->header[j]!=header[j]){
  95828. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  95829. for(j=0;j<header[26]+27;j++)
  95830. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  95831. fprintf(stderr,"\n");
  95832. exit(1);
  95833. }
  95834. }
  95835. if(og->header_len!=header[26]+27){
  95836. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  95837. og->header_len,header[26]+27);
  95838. exit(1);
  95839. }
  95840. }
  95841. void print_header(ogg_page *og){
  95842. int j;
  95843. fprintf(stderr,"\nHEADER:\n");
  95844. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  95845. og->header[0],og->header[1],og->header[2],og->header[3],
  95846. (int)og->header[4],(int)og->header[5]);
  95847. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  95848. (og->header[9]<<24)|(og->header[8]<<16)|
  95849. (og->header[7]<<8)|og->header[6],
  95850. (og->header[17]<<24)|(og->header[16]<<16)|
  95851. (og->header[15]<<8)|og->header[14],
  95852. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  95853. (og->header[19]<<8)|og->header[18]);
  95854. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  95855. (int)og->header[22],(int)og->header[23],
  95856. (int)og->header[24],(int)og->header[25],
  95857. (int)og->header[26]);
  95858. for(j=27;j<og->header_len;j++)
  95859. fprintf(stderr,"%d ",(int)og->header[j]);
  95860. fprintf(stderr,")\n\n");
  95861. }
  95862. void copy_page(ogg_page *og){
  95863. unsigned char *temp=_ogg_malloc(og->header_len);
  95864. memcpy(temp,og->header,og->header_len);
  95865. og->header=temp;
  95866. temp=_ogg_malloc(og->body_len);
  95867. memcpy(temp,og->body,og->body_len);
  95868. og->body=temp;
  95869. }
  95870. void free_page(ogg_page *og){
  95871. _ogg_free (og->header);
  95872. _ogg_free (og->body);
  95873. }
  95874. void error(void){
  95875. fprintf(stderr,"error!\n");
  95876. exit(1);
  95877. }
  95878. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  95879. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95880. 0x01,0x02,0x03,0x04,0,0,0,0,
  95881. 0x15,0xed,0xec,0x91,
  95882. 1,
  95883. 17};
  95884. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95885. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95886. 0x01,0x02,0x03,0x04,0,0,0,0,
  95887. 0x59,0x10,0x6c,0x2c,
  95888. 1,
  95889. 17};
  95890. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95891. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  95892. 0x01,0x02,0x03,0x04,1,0,0,0,
  95893. 0x89,0x33,0x85,0xce,
  95894. 13,
  95895. 254,255,0,255,1,255,245,255,255,0,
  95896. 255,255,90};
  95897. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95898. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95899. 0x01,0x02,0x03,0x04,0,0,0,0,
  95900. 0xff,0x7b,0x23,0x17,
  95901. 1,
  95902. 0};
  95903. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95904. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  95905. 0x01,0x02,0x03,0x04,1,0,0,0,
  95906. 0x5c,0x3f,0x66,0xcb,
  95907. 17,
  95908. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  95909. 255,255,90,0};
  95910. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95911. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95912. 0x01,0x02,0x03,0x04,0,0,0,0,
  95913. 0x01,0x27,0x31,0xaa,
  95914. 18,
  95915. 255,255,255,255,255,255,255,255,
  95916. 255,255,255,255,255,255,255,255,255,10};
  95917. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95918. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  95919. 0x01,0x02,0x03,0x04,1,0,0,0,
  95920. 0x7f,0x4e,0x8a,0xd2,
  95921. 4,
  95922. 255,4,255,0};
  95923. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95924. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95925. 0x01,0x02,0x03,0x04,0,0,0,0,
  95926. 0xff,0x7b,0x23,0x17,
  95927. 1,
  95928. 0};
  95929. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95930. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  95931. 0x01,0x02,0x03,0x04,1,0,0,0,
  95932. 0x54,0x05,0x51,0xc8,
  95933. 17,
  95934. 255,255,255,255,255,255,255,255,
  95935. 255,255,255,255,255,255,255,255,255};
  95936. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  95937. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  95938. 0x01,0x02,0x03,0x04,2,0,0,0,
  95939. 0xc8,0xc3,0xcb,0xed,
  95940. 5,
  95941. 10,255,4,255,0};
  95942. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95943. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95944. 0x01,0x02,0x03,0x04,0,0,0,0,
  95945. 0xff,0x7b,0x23,0x17,
  95946. 1,
  95947. 0};
  95948. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95949. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  95950. 0x01,0x02,0x03,0x04,1,0,0,0,
  95951. 0xed,0x2a,0x2e,0xa7,
  95952. 255,
  95953. 10,10,10,10,10,10,10,10,
  95954. 10,10,10,10,10,10,10,10,
  95955. 10,10,10,10,10,10,10,10,
  95956. 10,10,10,10,10,10,10,10,
  95957. 10,10,10,10,10,10,10,10,
  95958. 10,10,10,10,10,10,10,10,
  95959. 10,10,10,10,10,10,10,10,
  95960. 10,10,10,10,10,10,10,10,
  95961. 10,10,10,10,10,10,10,10,
  95962. 10,10,10,10,10,10,10,10,
  95963. 10,10,10,10,10,10,10,10,
  95964. 10,10,10,10,10,10,10,10,
  95965. 10,10,10,10,10,10,10,10,
  95966. 10,10,10,10,10,10,10,10,
  95967. 10,10,10,10,10,10,10,10,
  95968. 10,10,10,10,10,10,10,10,
  95969. 10,10,10,10,10,10,10,10,
  95970. 10,10,10,10,10,10,10,10,
  95971. 10,10,10,10,10,10,10,10,
  95972. 10,10,10,10,10,10,10,10,
  95973. 10,10,10,10,10,10,10,10,
  95974. 10,10,10,10,10,10,10,10,
  95975. 10,10,10,10,10,10,10,10,
  95976. 10,10,10,10,10,10,10,10,
  95977. 10,10,10,10,10,10,10,10,
  95978. 10,10,10,10,10,10,10,10,
  95979. 10,10,10,10,10,10,10,10,
  95980. 10,10,10,10,10,10,10,10,
  95981. 10,10,10,10,10,10,10,10,
  95982. 10,10,10,10,10,10,10,10,
  95983. 10,10,10,10,10,10,10,10,
  95984. 10,10,10,10,10,10,10};
  95985. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95986. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  95987. 0x01,0x02,0x03,0x04,2,0,0,0,
  95988. 0x6c,0x3b,0x82,0x3d,
  95989. 1,
  95990. 50};
  95991. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95992. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95993. 0x01,0x02,0x03,0x04,0,0,0,0,
  95994. 0xff,0x7b,0x23,0x17,
  95995. 1,
  95996. 0};
  95997. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95998. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  95999. 0x01,0x02,0x03,0x04,1,0,0,0,
  96000. 0x3c,0xd9,0x4d,0x3f,
  96001. 17,
  96002. 100,255,255,255,255,255,255,255,255,
  96003. 255,255,255,255,255,255,255,255};
  96004. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96005. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96006. 0x01,0x02,0x03,0x04,2,0,0,0,
  96007. 0x01,0xd2,0xe5,0xe5,
  96008. 17,
  96009. 255,255,255,255,255,255,255,255,
  96010. 255,255,255,255,255,255,255,255,255};
  96011. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96012. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96013. 0x01,0x02,0x03,0x04,3,0,0,0,
  96014. 0xef,0xdd,0x88,0xde,
  96015. 7,
  96016. 255,255,75,255,4,255,0};
  96017. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96018. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96019. 0x01,0x02,0x03,0x04,0,0,0,0,
  96020. 0xff,0x7b,0x23,0x17,
  96021. 1,
  96022. 0};
  96023. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96024. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96025. 0x01,0x02,0x03,0x04,1,0,0,0,
  96026. 0x3c,0xd9,0x4d,0x3f,
  96027. 17,
  96028. 100,255,255,255,255,255,255,255,255,
  96029. 255,255,255,255,255,255,255,255};
  96030. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96031. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96032. 0x01,0x02,0x03,0x04,2,0,0,0,
  96033. 0xd4,0xe0,0x60,0xe5,
  96034. 1,0};
  96035. void test_pack(const int *pl, const int **headers, int byteskip,
  96036. int pageskip, int packetskip){
  96037. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96038. long inptr=0;
  96039. long outptr=0;
  96040. long deptr=0;
  96041. long depacket=0;
  96042. long granule_pos=7,pageno=0;
  96043. int i,j,packets,pageout=pageskip;
  96044. int eosflag=0;
  96045. int bosflag=0;
  96046. int byteskipcount=0;
  96047. ogg_stream_reset(&os_en);
  96048. ogg_stream_reset(&os_de);
  96049. ogg_sync_reset(&oy);
  96050. for(packets=0;packets<packetskip;packets++)
  96051. depacket+=pl[packets];
  96052. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96053. for(i=0;i<packets;i++){
  96054. ogg_packet op;
  96055. int len=pl[i];
  96056. op.packet=data+inptr;
  96057. op.bytes=len;
  96058. op.e_o_s=(pl[i+1]<0?1:0);
  96059. op.granulepos=granule_pos;
  96060. granule_pos+=1024;
  96061. for(j=0;j<len;j++)data[inptr++]=i+j;
  96062. ogg_stream_packetin(&os_en,&op);
  96063. {
  96064. ogg_page og;
  96065. while(ogg_stream_pageout(&os_en,&og)){
  96066. fprintf(stderr,"%ld, ",pageno);
  96067. if(headers[pageno]==NULL){
  96068. fprintf(stderr,"coded too many pages!\n");
  96069. exit(1);
  96070. }
  96071. check_page(data+outptr,headers[pageno],&og);
  96072. outptr+=og.body_len;
  96073. pageno++;
  96074. if(pageskip){
  96075. bosflag=1;
  96076. pageskip--;
  96077. deptr+=og.body_len;
  96078. }
  96079. {
  96080. ogg_page og_de;
  96081. ogg_packet op_de,op_de2;
  96082. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96083. char *next=buf;
  96084. byteskipcount+=og.header_len;
  96085. if(byteskipcount>byteskip){
  96086. memcpy(next,og.header,byteskipcount-byteskip);
  96087. next+=byteskipcount-byteskip;
  96088. byteskipcount=byteskip;
  96089. }
  96090. byteskipcount+=og.body_len;
  96091. if(byteskipcount>byteskip){
  96092. memcpy(next,og.body,byteskipcount-byteskip);
  96093. next+=byteskipcount-byteskip;
  96094. byteskipcount=byteskip;
  96095. }
  96096. ogg_sync_wrote(&oy,next-buf);
  96097. while(1){
  96098. int ret=ogg_sync_pageout(&oy,&og_de);
  96099. if(ret==0)break;
  96100. if(ret<0)continue;
  96101. fprintf(stderr,"(%ld), ",pageout);
  96102. check_page(data+deptr,headers[pageout],&og_de);
  96103. deptr+=og_de.body_len;
  96104. pageout++;
  96105. ogg_stream_pagein(&os_de,&og_de);
  96106. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96107. ogg_stream_packetpeek(&os_de,NULL);
  96108. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96109. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96110. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96111. depacket);
  96112. exit(1);
  96113. }
  96114. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96115. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96116. depacket);
  96117. exit(1);
  96118. }
  96119. if(bosflag==0 && op_de.b_o_s==0){
  96120. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96121. exit(1);
  96122. }
  96123. if(bosflag && op_de.b_o_s){
  96124. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96125. exit(1);
  96126. }
  96127. bosflag=1;
  96128. depacket+=op_de.bytes;
  96129. if(eosflag){
  96130. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96131. exit(1);
  96132. }
  96133. if(op_de.e_o_s)eosflag=1;
  96134. if(op_de.granulepos!=-1){
  96135. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96136. }
  96137. }
  96138. }
  96139. }
  96140. }
  96141. }
  96142. }
  96143. _ogg_free(data);
  96144. if(headers[pageno]!=NULL){
  96145. fprintf(stderr,"did not write last page!\n");
  96146. exit(1);
  96147. }
  96148. if(headers[pageout]!=NULL){
  96149. fprintf(stderr,"did not decode last page!\n");
  96150. exit(1);
  96151. }
  96152. if(inptr!=outptr){
  96153. fprintf(stderr,"encoded page data incomplete!\n");
  96154. exit(1);
  96155. }
  96156. if(inptr!=deptr){
  96157. fprintf(stderr,"decoded page data incomplete!\n");
  96158. exit(1);
  96159. }
  96160. if(inptr!=depacket){
  96161. fprintf(stderr,"decoded packet data incomplete!\n");
  96162. exit(1);
  96163. }
  96164. if(!eosflag){
  96165. fprintf(stderr,"Never got a packet with EOS set!\n");
  96166. exit(1);
  96167. }
  96168. fprintf(stderr,"ok.\n");
  96169. }
  96170. int main(void){
  96171. ogg_stream_init(&os_en,0x04030201);
  96172. ogg_stream_init(&os_de,0x04030201);
  96173. ogg_sync_init(&oy);
  96174. {
  96175. const int packets[]={17, -1};
  96176. const int *headret[]={head1_0,NULL};
  96177. fprintf(stderr,"testing single page encoding... ");
  96178. test_pack(packets,headret,0,0,0);
  96179. }
  96180. {
  96181. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96182. const int *headret[]={head1_1,head2_1,NULL};
  96183. fprintf(stderr,"testing basic page encoding... ");
  96184. test_pack(packets,headret,0,0,0);
  96185. }
  96186. {
  96187. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96188. const int *headret[]={head1_2,head2_2,NULL};
  96189. fprintf(stderr,"testing basic nil packets... ");
  96190. test_pack(packets,headret,0,0,0);
  96191. }
  96192. {
  96193. const int packets[]={4345,259,255,-1};
  96194. const int *headret[]={head1_3,head2_3,NULL};
  96195. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96196. test_pack(packets,headret,0,0,0);
  96197. }
  96198. {
  96199. const int packets[]={0,4345,259,255,-1};
  96200. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96201. fprintf(stderr,"testing single packet page span... ");
  96202. test_pack(packets,headret,0,0,0);
  96203. }
  96204. {
  96205. const int packets[]={0,10,10,10,10,10,10,10,10,
  96206. 10,10,10,10,10,10,10,10,
  96207. 10,10,10,10,10,10,10,10,
  96208. 10,10,10,10,10,10,10,10,
  96209. 10,10,10,10,10,10,10,10,
  96210. 10,10,10,10,10,10,10,10,
  96211. 10,10,10,10,10,10,10,10,
  96212. 10,10,10,10,10,10,10,10,
  96213. 10,10,10,10,10,10,10,10,
  96214. 10,10,10,10,10,10,10,10,
  96215. 10,10,10,10,10,10,10,10,
  96216. 10,10,10,10,10,10,10,10,
  96217. 10,10,10,10,10,10,10,10,
  96218. 10,10,10,10,10,10,10,10,
  96219. 10,10,10,10,10,10,10,10,
  96220. 10,10,10,10,10,10,10,10,
  96221. 10,10,10,10,10,10,10,10,
  96222. 10,10,10,10,10,10,10,10,
  96223. 10,10,10,10,10,10,10,10,
  96224. 10,10,10,10,10,10,10,10,
  96225. 10,10,10,10,10,10,10,10,
  96226. 10,10,10,10,10,10,10,10,
  96227. 10,10,10,10,10,10,10,10,
  96228. 10,10,10,10,10,10,10,10,
  96229. 10,10,10,10,10,10,10,10,
  96230. 10,10,10,10,10,10,10,10,
  96231. 10,10,10,10,10,10,10,10,
  96232. 10,10,10,10,10,10,10,10,
  96233. 10,10,10,10,10,10,10,10,
  96234. 10,10,10,10,10,10,10,10,
  96235. 10,10,10,10,10,10,10,10,
  96236. 10,10,10,10,10,10,10,50,-1};
  96237. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96238. fprintf(stderr,"testing max packet segments... ");
  96239. test_pack(packets,headret,0,0,0);
  96240. }
  96241. {
  96242. const int packets[]={0,100,9000,259,255,-1};
  96243. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96244. fprintf(stderr,"testing very large packets... ");
  96245. test_pack(packets,headret,0,0,0);
  96246. }
  96247. {
  96248. const int packets[]={0,100,9000,259,255,-1};
  96249. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96250. fprintf(stderr,"testing continuation resync in very large packets... ");
  96251. test_pack(packets,headret,100,2,3);
  96252. }
  96253. {
  96254. const int packets[]={0,100,4080,-1};
  96255. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96256. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96257. test_pack(packets,headret,0,0,0);
  96258. }
  96259. {
  96260. unsigned char *data=_ogg_malloc(1024*1024);
  96261. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96262. int inptr=0,i,j;
  96263. ogg_page og[5];
  96264. ogg_stream_reset(&os_en);
  96265. for(i=0;pl[i]!=-1;i++){
  96266. ogg_packet op;
  96267. int len=pl[i];
  96268. op.packet=data+inptr;
  96269. op.bytes=len;
  96270. op.e_o_s=(pl[i+1]<0?1:0);
  96271. op.granulepos=(i+1)*1000;
  96272. for(j=0;j<len;j++)data[inptr++]=i+j;
  96273. ogg_stream_packetin(&os_en,&op);
  96274. }
  96275. _ogg_free(data);
  96276. for(i=0;i<5;i++){
  96277. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96278. fprintf(stderr,"Too few pages output building sync tests!\n");
  96279. exit(1);
  96280. }
  96281. copy_page(&og[i]);
  96282. }
  96283. {
  96284. ogg_page temp;
  96285. ogg_packet test;
  96286. fprintf(stderr,"Testing loss of pages... ");
  96287. ogg_sync_reset(&oy);
  96288. ogg_stream_reset(&os_de);
  96289. for(i=0;i<5;i++){
  96290. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96291. og[i].header_len);
  96292. ogg_sync_wrote(&oy,og[i].header_len);
  96293. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96294. ogg_sync_wrote(&oy,og[i].body_len);
  96295. }
  96296. ogg_sync_pageout(&oy,&temp);
  96297. ogg_stream_pagein(&os_de,&temp);
  96298. ogg_sync_pageout(&oy,&temp);
  96299. ogg_stream_pagein(&os_de,&temp);
  96300. ogg_sync_pageout(&oy,&temp);
  96301. ogg_sync_pageout(&oy,&temp);
  96302. ogg_stream_pagein(&os_de,&temp);
  96303. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96304. checkpacket(&test,0,0,0);
  96305. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96306. checkpacket(&test,100,1,-1);
  96307. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96308. checkpacket(&test,4079,2,3000);
  96309. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96310. fprintf(stderr,"Error: loss of page did not return error\n");
  96311. exit(1);
  96312. }
  96313. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96314. checkpacket(&test,76,5,-1);
  96315. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96316. checkpacket(&test,34,6,-1);
  96317. fprintf(stderr,"ok.\n");
  96318. }
  96319. {
  96320. ogg_page temp;
  96321. ogg_packet test;
  96322. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96323. ogg_sync_reset(&oy);
  96324. ogg_stream_reset(&os_de);
  96325. for(i=0;i<5;i++){
  96326. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96327. og[i].header_len);
  96328. ogg_sync_wrote(&oy,og[i].header_len);
  96329. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96330. ogg_sync_wrote(&oy,og[i].body_len);
  96331. }
  96332. ogg_sync_pageout(&oy,&temp);
  96333. ogg_stream_pagein(&os_de,&temp);
  96334. ogg_sync_pageout(&oy,&temp);
  96335. ogg_stream_pagein(&os_de,&temp);
  96336. ogg_sync_pageout(&oy,&temp);
  96337. ogg_stream_pagein(&os_de,&temp);
  96338. ogg_sync_pageout(&oy,&temp);
  96339. ogg_sync_pageout(&oy,&temp);
  96340. ogg_stream_pagein(&os_de,&temp);
  96341. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96342. checkpacket(&test,0,0,0);
  96343. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96344. checkpacket(&test,100,1,-1);
  96345. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96346. checkpacket(&test,4079,2,3000);
  96347. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96348. checkpacket(&test,2956,3,4000);
  96349. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96350. fprintf(stderr,"Error: loss of page did not return error\n");
  96351. exit(1);
  96352. }
  96353. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96354. checkpacket(&test,300,13,14000);
  96355. fprintf(stderr,"ok.\n");
  96356. }
  96357. {
  96358. ogg_page og_de;
  96359. fprintf(stderr,"Testing sync on partial inputs... ");
  96360. ogg_sync_reset(&oy);
  96361. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96362. 3);
  96363. ogg_sync_wrote(&oy,3);
  96364. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96365. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96366. 20);
  96367. ogg_sync_wrote(&oy,20);
  96368. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96369. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96370. 5);
  96371. ogg_sync_wrote(&oy,5);
  96372. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96373. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96374. og[1].header_len-28);
  96375. ogg_sync_wrote(&oy,og[1].header_len-28);
  96376. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96377. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96378. ogg_sync_wrote(&oy,1000);
  96379. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96380. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96381. og[1].body_len-1000);
  96382. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96383. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96384. fprintf(stderr,"ok.\n");
  96385. }
  96386. {
  96387. ogg_page og_de;
  96388. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96389. ogg_sync_reset(&oy);
  96390. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96391. og[1].header_len);
  96392. ogg_sync_wrote(&oy,og[1].header_len);
  96393. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96394. og[1].body_len);
  96395. ogg_sync_wrote(&oy,og[1].body_len);
  96396. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96397. 20);
  96398. ogg_sync_wrote(&oy,20);
  96399. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96400. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96401. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96402. og[1].header_len-20);
  96403. ogg_sync_wrote(&oy,og[1].header_len-20);
  96404. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96405. og[1].body_len);
  96406. ogg_sync_wrote(&oy,og[1].body_len);
  96407. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96408. fprintf(stderr,"ok.\n");
  96409. }
  96410. {
  96411. ogg_page og_de;
  96412. fprintf(stderr,"Testing search for capture... ");
  96413. ogg_sync_reset(&oy);
  96414. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96415. og[1].body_len);
  96416. ogg_sync_wrote(&oy,og[1].body_len);
  96417. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96418. og[1].header_len);
  96419. ogg_sync_wrote(&oy,og[1].header_len);
  96420. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96421. og[1].body_len);
  96422. ogg_sync_wrote(&oy,og[1].body_len);
  96423. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96424. 20);
  96425. ogg_sync_wrote(&oy,20);
  96426. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96427. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96428. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96429. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96430. og[2].header_len-20);
  96431. ogg_sync_wrote(&oy,og[2].header_len-20);
  96432. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96433. og[2].body_len);
  96434. ogg_sync_wrote(&oy,og[2].body_len);
  96435. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96436. fprintf(stderr,"ok.\n");
  96437. }
  96438. {
  96439. ogg_page og_de;
  96440. fprintf(stderr,"Testing recapture... ");
  96441. ogg_sync_reset(&oy);
  96442. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96443. og[1].header_len);
  96444. ogg_sync_wrote(&oy,og[1].header_len);
  96445. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96446. og[1].body_len);
  96447. ogg_sync_wrote(&oy,og[1].body_len);
  96448. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96449. og[2].header_len);
  96450. ogg_sync_wrote(&oy,og[2].header_len);
  96451. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96452. og[2].header_len);
  96453. ogg_sync_wrote(&oy,og[2].header_len);
  96454. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96455. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96456. og[2].body_len-5);
  96457. ogg_sync_wrote(&oy,og[2].body_len-5);
  96458. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96459. og[3].header_len);
  96460. ogg_sync_wrote(&oy,og[3].header_len);
  96461. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96462. og[3].body_len);
  96463. ogg_sync_wrote(&oy,og[3].body_len);
  96464. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96465. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96466. fprintf(stderr,"ok.\n");
  96467. }
  96468. {
  96469. for(i=0;i<5;i++){
  96470. free_page(&og[i]);
  96471. }
  96472. }
  96473. }
  96474. return(0);
  96475. }
  96476. #endif
  96477. #endif
  96478. /*** End of inlined file: framing.c ***/
  96479. /*** Start of inlined file: analysis.c ***/
  96480. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96481. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96482. // tasks..
  96483. #if JUCE_MSVC
  96484. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96485. #endif
  96486. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96487. #if JUCE_USE_OGGVORBIS
  96488. #include <stdio.h>
  96489. #include <string.h>
  96490. #include <math.h>
  96491. /*** Start of inlined file: codec_internal.h ***/
  96492. #ifndef _V_CODECI_H_
  96493. #define _V_CODECI_H_
  96494. /*** Start of inlined file: envelope.h ***/
  96495. #ifndef _V_ENVELOPE_
  96496. #define _V_ENVELOPE_
  96497. /*** Start of inlined file: mdct.h ***/
  96498. #ifndef _OGG_mdct_H_
  96499. #define _OGG_mdct_H_
  96500. #ifdef MDCT_INTEGERIZED
  96501. #define DATA_TYPE int
  96502. #define REG_TYPE register int
  96503. #define TRIGBITS 14
  96504. #define cPI3_8 6270
  96505. #define cPI2_8 11585
  96506. #define cPI1_8 15137
  96507. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96508. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96509. #define HALVE(x) ((x)>>1)
  96510. #else
  96511. #define DATA_TYPE float
  96512. #define REG_TYPE float
  96513. #define cPI3_8 .38268343236508977175F
  96514. #define cPI2_8 .70710678118654752441F
  96515. #define cPI1_8 .92387953251128675613F
  96516. #define FLOAT_CONV(x) (x)
  96517. #define MULT_NORM(x) (x)
  96518. #define HALVE(x) ((x)*.5f)
  96519. #endif
  96520. typedef struct {
  96521. int n;
  96522. int log2n;
  96523. DATA_TYPE *trig;
  96524. int *bitrev;
  96525. DATA_TYPE scale;
  96526. } mdct_lookup;
  96527. extern void mdct_init(mdct_lookup *lookup,int n);
  96528. extern void mdct_clear(mdct_lookup *l);
  96529. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96530. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96531. #endif
  96532. /*** End of inlined file: mdct.h ***/
  96533. #define VE_PRE 16
  96534. #define VE_WIN 4
  96535. #define VE_POST 2
  96536. #define VE_AMP (VE_PRE+VE_POST-1)
  96537. #define VE_BANDS 7
  96538. #define VE_NEARDC 15
  96539. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96540. #define VE_MAXSTRETCH 12 /* one-third full block */
  96541. typedef struct {
  96542. float ampbuf[VE_AMP];
  96543. int ampptr;
  96544. float nearDC[VE_NEARDC];
  96545. float nearDC_acc;
  96546. float nearDC_partialacc;
  96547. int nearptr;
  96548. } envelope_filter_state;
  96549. typedef struct {
  96550. int begin;
  96551. int end;
  96552. float *window;
  96553. float total;
  96554. } envelope_band;
  96555. typedef struct {
  96556. int ch;
  96557. int winlength;
  96558. int searchstep;
  96559. float minenergy;
  96560. mdct_lookup mdct;
  96561. float *mdct_win;
  96562. envelope_band band[VE_BANDS];
  96563. envelope_filter_state *filter;
  96564. int stretch;
  96565. int *mark;
  96566. long storage;
  96567. long current;
  96568. long curmark;
  96569. long cursor;
  96570. } envelope_lookup;
  96571. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96572. extern void _ve_envelope_clear(envelope_lookup *e);
  96573. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96574. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96575. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96576. #endif
  96577. /*** End of inlined file: envelope.h ***/
  96578. /*** Start of inlined file: codebook.h ***/
  96579. #ifndef _V_CODEBOOK_H_
  96580. #define _V_CODEBOOK_H_
  96581. typedef struct static_codebook{
  96582. long dim; /* codebook dimensions (elements per vector) */
  96583. long entries; /* codebook entries */
  96584. long *lengthlist; /* codeword lengths in bits */
  96585. int maptype; /* 0=none
  96586. 1=implicitly populated values from map column
  96587. 2=listed arbitrary values */
  96588. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96589. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96590. int q_quant; /* bits: 0 < quant <= 16 */
  96591. int q_sequencep; /* bitflag */
  96592. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96593. map == 2: list of dim*entries quantized entry vals
  96594. */
  96595. struct encode_aux_nearestmatch *nearest_tree;
  96596. struct encode_aux_threshmatch *thresh_tree;
  96597. struct encode_aux_pigeonhole *pigeon_tree;
  96598. int allocedp;
  96599. } static_codebook;
  96600. typedef struct encode_aux_nearestmatch{
  96601. long *ptr0;
  96602. long *ptr1;
  96603. long *p; /* decision points (each is an entry) */
  96604. long *q; /* decision points (each is an entry) */
  96605. long aux; /* number of tree entries */
  96606. long alloc;
  96607. } encode_aux_nearestmatch;
  96608. typedef struct encode_aux_threshmatch{
  96609. float *quantthresh;
  96610. long *quantmap;
  96611. int quantvals;
  96612. int threshvals;
  96613. } encode_aux_threshmatch;
  96614. typedef struct encode_aux_pigeonhole{
  96615. float min;
  96616. float del;
  96617. int mapentries;
  96618. int quantvals;
  96619. long *pigeonmap;
  96620. long fittotal;
  96621. long *fitlist;
  96622. long *fitmap;
  96623. long *fitlength;
  96624. } encode_aux_pigeonhole;
  96625. typedef struct codebook{
  96626. long dim; /* codebook dimensions (elements per vector) */
  96627. long entries; /* codebook entries */
  96628. long used_entries; /* populated codebook entries */
  96629. const static_codebook *c;
  96630. float *valuelist; /* list of dim*entries actual entry values */
  96631. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96632. int *dec_index; /* only used if sparseness collapsed */
  96633. char *dec_codelengths;
  96634. ogg_uint32_t *dec_firsttable;
  96635. int dec_firsttablen;
  96636. int dec_maxlength;
  96637. } codebook;
  96638. extern void vorbis_staticbook_clear(static_codebook *b);
  96639. extern void vorbis_staticbook_destroy(static_codebook *b);
  96640. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96641. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96642. extern void vorbis_book_clear(codebook *b);
  96643. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96644. extern float *_book_logdist(const static_codebook *b,float *vals);
  96645. extern float _float32_unpack(long val);
  96646. extern long _float32_pack(float val);
  96647. extern int _best(codebook *book, float *a, int step);
  96648. extern int _ilog(unsigned int v);
  96649. extern long _book_maptype1_quantvals(const static_codebook *b);
  96650. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96651. extern long vorbis_book_codeword(codebook *book,int entry);
  96652. extern long vorbis_book_codelen(codebook *book,int entry);
  96653. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96654. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96655. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96656. extern int vorbis_book_errorv(codebook *book, float *a);
  96657. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96658. oggpack_buffer *b);
  96659. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96660. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96661. oggpack_buffer *b,int n);
  96662. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96663. oggpack_buffer *b,int n);
  96664. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96665. oggpack_buffer *b,int n);
  96666. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96667. long off,int ch,
  96668. oggpack_buffer *b,int n);
  96669. #endif
  96670. /*** End of inlined file: codebook.h ***/
  96671. #define BLOCKTYPE_IMPULSE 0
  96672. #define BLOCKTYPE_PADDING 1
  96673. #define BLOCKTYPE_TRANSITION 0
  96674. #define BLOCKTYPE_LONG 1
  96675. #define PACKETBLOBS 15
  96676. typedef struct vorbis_block_internal{
  96677. float **pcmdelay; /* this is a pointer into local storage */
  96678. float ampmax;
  96679. int blocktype;
  96680. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96681. blob [PACKETBLOBS/2] points to
  96682. the oggpack_buffer in the
  96683. main vorbis_block */
  96684. } vorbis_block_internal;
  96685. typedef void vorbis_look_floor;
  96686. typedef void vorbis_look_residue;
  96687. typedef void vorbis_look_transform;
  96688. typedef struct {
  96689. int blockflag;
  96690. int windowtype;
  96691. int transformtype;
  96692. int mapping;
  96693. } vorbis_info_mode;
  96694. typedef void vorbis_info_floor;
  96695. typedef void vorbis_info_residue;
  96696. typedef void vorbis_info_mapping;
  96697. /*** Start of inlined file: psy.h ***/
  96698. #ifndef _V_PSY_H_
  96699. #define _V_PSY_H_
  96700. /*** Start of inlined file: smallft.h ***/
  96701. #ifndef _V_SMFT_H_
  96702. #define _V_SMFT_H_
  96703. typedef struct {
  96704. int n;
  96705. float *trigcache;
  96706. int *splitcache;
  96707. } drft_lookup;
  96708. extern void drft_forward(drft_lookup *l,float *data);
  96709. extern void drft_backward(drft_lookup *l,float *data);
  96710. extern void drft_init(drft_lookup *l,int n);
  96711. extern void drft_clear(drft_lookup *l);
  96712. #endif
  96713. /*** End of inlined file: smallft.h ***/
  96714. /*** Start of inlined file: backends.h ***/
  96715. #ifndef _vorbis_backend_h_
  96716. #define _vorbis_backend_h_
  96717. typedef struct{
  96718. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96719. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96720. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96721. void (*free_info) (vorbis_info_floor *);
  96722. void (*free_look) (vorbis_look_floor *);
  96723. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96724. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96725. void *buffer,float *);
  96726. } vorbis_func_floor;
  96727. typedef struct{
  96728. int order;
  96729. long rate;
  96730. long barkmap;
  96731. int ampbits;
  96732. int ampdB;
  96733. int numbooks; /* <= 16 */
  96734. int books[16];
  96735. float lessthan; /* encode-only config setting hacks for libvorbis */
  96736. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96737. } vorbis_info_floor0;
  96738. #define VIF_POSIT 63
  96739. #define VIF_CLASS 16
  96740. #define VIF_PARTS 31
  96741. typedef struct{
  96742. int partitions; /* 0 to 31 */
  96743. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96744. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96745. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96746. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96747. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96748. int mult; /* 1 2 3 or 4 */
  96749. int postlist[VIF_POSIT+2]; /* first two implicit */
  96750. float maxover;
  96751. float maxunder;
  96752. float maxerr;
  96753. float twofitweight;
  96754. float twofitatten;
  96755. int n;
  96756. } vorbis_info_floor1;
  96757. typedef struct{
  96758. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96759. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96760. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96761. vorbis_info_residue *);
  96762. void (*free_info) (vorbis_info_residue *);
  96763. void (*free_look) (vorbis_look_residue *);
  96764. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96765. float **,int *,int);
  96766. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96767. vorbis_look_residue *,
  96768. float **,float **,int *,int,long **);
  96769. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96770. float **,int *,int);
  96771. } vorbis_func_residue;
  96772. typedef struct vorbis_info_residue0{
  96773. long begin;
  96774. long end;
  96775. int grouping; /* group n vectors per partition */
  96776. int partitions; /* possible codebooks for a partition */
  96777. int groupbook; /* huffbook for partitioning */
  96778. int secondstages[64]; /* expanded out to pointers in lookup */
  96779. int booklist[256]; /* list of second stage books */
  96780. float classmetric1[64];
  96781. float classmetric2[64];
  96782. } vorbis_info_residue0;
  96783. typedef struct{
  96784. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96785. oggpack_buffer *);
  96786. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96787. void (*free_info) (vorbis_info_mapping *);
  96788. int (*forward) (struct vorbis_block *vb);
  96789. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96790. } vorbis_func_mapping;
  96791. typedef struct vorbis_info_mapping0{
  96792. int submaps; /* <= 16 */
  96793. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96794. int floorsubmap[16]; /* [mux] submap to floors */
  96795. int residuesubmap[16]; /* [mux] submap to residue */
  96796. int coupling_steps;
  96797. int coupling_mag[256];
  96798. int coupling_ang[256];
  96799. } vorbis_info_mapping0;
  96800. #endif
  96801. /*** End of inlined file: backends.h ***/
  96802. #ifndef EHMER_MAX
  96803. #define EHMER_MAX 56
  96804. #endif
  96805. #define P_BANDS 17 /* 62Hz to 16kHz */
  96806. #define P_LEVELS 8 /* 30dB to 100dB */
  96807. #define P_LEVEL_0 30. /* 30 dB */
  96808. #define P_NOISECURVES 3
  96809. #define NOISE_COMPAND_LEVELS 40
  96810. typedef struct vorbis_info_psy{
  96811. int blockflag;
  96812. float ath_adjatt;
  96813. float ath_maxatt;
  96814. float tone_masteratt[P_NOISECURVES];
  96815. float tone_centerboost;
  96816. float tone_decay;
  96817. float tone_abs_limit;
  96818. float toneatt[P_BANDS];
  96819. int noisemaskp;
  96820. float noisemaxsupp;
  96821. float noisewindowlo;
  96822. float noisewindowhi;
  96823. int noisewindowlomin;
  96824. int noisewindowhimin;
  96825. int noisewindowfixed;
  96826. float noiseoff[P_NOISECURVES][P_BANDS];
  96827. float noisecompand[NOISE_COMPAND_LEVELS];
  96828. float max_curve_dB;
  96829. int normal_channel_p;
  96830. int normal_point_p;
  96831. int normal_start;
  96832. int normal_partition;
  96833. double normal_thresh;
  96834. } vorbis_info_psy;
  96835. typedef struct{
  96836. int eighth_octave_lines;
  96837. float preecho_thresh[VE_BANDS];
  96838. float postecho_thresh[VE_BANDS];
  96839. float stretch_penalty;
  96840. float preecho_minenergy;
  96841. float ampmax_att_per_sec;
  96842. int coupling_pkHz[PACKETBLOBS];
  96843. int coupling_pointlimit[2][PACKETBLOBS];
  96844. int coupling_prepointamp[PACKETBLOBS];
  96845. int coupling_postpointamp[PACKETBLOBS];
  96846. int sliding_lowpass[2][PACKETBLOBS];
  96847. } vorbis_info_psy_global;
  96848. typedef struct {
  96849. float ampmax;
  96850. int channels;
  96851. vorbis_info_psy_global *gi;
  96852. int coupling_pointlimit[2][P_NOISECURVES];
  96853. } vorbis_look_psy_global;
  96854. typedef struct {
  96855. int n;
  96856. struct vorbis_info_psy *vi;
  96857. float ***tonecurves;
  96858. float **noiseoffset;
  96859. float *ath;
  96860. long *octave; /* in n.ocshift format */
  96861. long *bark;
  96862. long firstoc;
  96863. long shiftoc;
  96864. int eighth_octave_lines; /* power of two, please */
  96865. int total_octave_lines;
  96866. long rate; /* cache it */
  96867. float m_val; /* Masking compensation value */
  96868. } vorbis_look_psy;
  96869. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  96870. vorbis_info_psy_global *gi,int n,long rate);
  96871. extern void _vp_psy_clear(vorbis_look_psy *p);
  96872. extern void *_vi_psy_dup(void *source);
  96873. extern void _vi_psy_free(vorbis_info_psy *i);
  96874. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  96875. extern void _vp_remove_floor(vorbis_look_psy *p,
  96876. float *mdct,
  96877. int *icodedflr,
  96878. float *residue,
  96879. int sliding_lowpass);
  96880. extern void _vp_noisemask(vorbis_look_psy *p,
  96881. float *logmdct,
  96882. float *logmask);
  96883. extern void _vp_tonemask(vorbis_look_psy *p,
  96884. float *logfft,
  96885. float *logmask,
  96886. float global_specmax,
  96887. float local_specmax);
  96888. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  96889. float *noise,
  96890. float *tone,
  96891. int offset_select,
  96892. float *logmask,
  96893. float *mdct,
  96894. float *logmdct);
  96895. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  96896. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  96897. vorbis_info_psy_global *g,
  96898. vorbis_look_psy *p,
  96899. vorbis_info_mapping0 *vi,
  96900. float **mdct);
  96901. extern void _vp_couple(int blobno,
  96902. vorbis_info_psy_global *g,
  96903. vorbis_look_psy *p,
  96904. vorbis_info_mapping0 *vi,
  96905. float **res,
  96906. float **mag_memo,
  96907. int **mag_sort,
  96908. int **ifloor,
  96909. int *nonzero,
  96910. int sliding_lowpass);
  96911. extern void _vp_noise_normalize(vorbis_look_psy *p,
  96912. float *in,float *out,int *sortedindex);
  96913. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  96914. float *magnitudes,int *sortedindex);
  96915. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  96916. vorbis_look_psy *p,
  96917. vorbis_info_mapping0 *vi,
  96918. float **mags);
  96919. extern void hf_reduction(vorbis_info_psy_global *g,
  96920. vorbis_look_psy *p,
  96921. vorbis_info_mapping0 *vi,
  96922. float **mdct);
  96923. #endif
  96924. /*** End of inlined file: psy.h ***/
  96925. /*** Start of inlined file: bitrate.h ***/
  96926. #ifndef _V_BITRATE_H_
  96927. #define _V_BITRATE_H_
  96928. /*** Start of inlined file: os.h ***/
  96929. #ifndef _OS_H
  96930. #define _OS_H
  96931. #ifdef HAVE_CONFIG_H
  96932. #include "config.h"
  96933. #endif
  96934. #include <math.h>
  96935. /*** Start of inlined file: misc.h ***/
  96936. #ifndef _V_RANDOM_H_
  96937. #define _V_RANDOM_H_
  96938. extern int analysis_noisy;
  96939. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  96940. extern void _vorbis_block_ripcord(vorbis_block *vb);
  96941. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  96942. ogg_int64_t off);
  96943. #ifdef DEBUG_MALLOC
  96944. #define _VDBG_GRAPHFILE "malloc.m"
  96945. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  96946. extern void _VDBG_free(void *ptr,char *file,long line);
  96947. #ifndef MISC_C
  96948. #undef _ogg_malloc
  96949. #undef _ogg_calloc
  96950. #undef _ogg_realloc
  96951. #undef _ogg_free
  96952. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  96953. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  96954. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  96955. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  96956. #endif
  96957. #endif
  96958. #endif
  96959. /*** End of inlined file: misc.h ***/
  96960. #ifndef _V_IFDEFJAIL_H_
  96961. # define _V_IFDEFJAIL_H_
  96962. # ifdef __GNUC__
  96963. # define STIN static __inline__
  96964. # elif _WIN32
  96965. # define STIN static __inline
  96966. # else
  96967. # define STIN static
  96968. # endif
  96969. #ifdef DJGPP
  96970. # define rint(x) (floor((x)+0.5f))
  96971. #endif
  96972. #ifndef M_PI
  96973. # define M_PI (3.1415926536f)
  96974. #endif
  96975. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  96976. # include <malloc.h>
  96977. # define rint(x) (floor((x)+0.5f))
  96978. # define NO_FLOAT_MATH_LIB
  96979. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  96980. #endif
  96981. #if defined(__SYMBIAN32__) && defined(__WINS__)
  96982. void *_alloca(size_t size);
  96983. # define alloca _alloca
  96984. #endif
  96985. #ifndef FAST_HYPOT
  96986. # define FAST_HYPOT hypot
  96987. #endif
  96988. #endif
  96989. #ifdef HAVE_ALLOCA_H
  96990. # include <alloca.h>
  96991. #endif
  96992. #ifdef USE_MEMORY_H
  96993. # include <memory.h>
  96994. #endif
  96995. #ifndef min
  96996. # define min(x,y) ((x)>(y)?(y):(x))
  96997. #endif
  96998. #ifndef max
  96999. # define max(x,y) ((x)<(y)?(y):(x))
  97000. #endif
  97001. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97002. # define VORBIS_FPU_CONTROL
  97003. typedef ogg_int16_t vorbis_fpu_control;
  97004. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97005. ogg_int16_t ret;
  97006. ogg_int16_t temp;
  97007. __asm__ __volatile__("fnstcw %0\n\t"
  97008. "movw %0,%%dx\n\t"
  97009. "orw $62463,%%dx\n\t"
  97010. "movw %%dx,%1\n\t"
  97011. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97012. *fpu=ret;
  97013. }
  97014. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97015. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97016. }
  97017. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97018. we get extra fst/fld to
  97019. truncate precision */
  97020. int i;
  97021. __asm__("fistl %0": "=m"(i) : "t"(f));
  97022. return(i);
  97023. }
  97024. #endif
  97025. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97026. # define VORBIS_FPU_CONTROL
  97027. typedef ogg_int16_t vorbis_fpu_control;
  97028. static __inline int vorbis_ftoi(double f){
  97029. int i;
  97030. __asm{
  97031. fld f
  97032. fistp i
  97033. }
  97034. return i;
  97035. }
  97036. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97037. }
  97038. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97039. }
  97040. #endif
  97041. #ifndef VORBIS_FPU_CONTROL
  97042. typedef int vorbis_fpu_control;
  97043. static int vorbis_ftoi(double f){
  97044. return (int)(f+.5);
  97045. }
  97046. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97047. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97048. #endif
  97049. #endif /* _OS_H */
  97050. /*** End of inlined file: os.h ***/
  97051. typedef struct bitrate_manager_state {
  97052. int managed;
  97053. long avg_reservoir;
  97054. long minmax_reservoir;
  97055. long avg_bitsper;
  97056. long min_bitsper;
  97057. long max_bitsper;
  97058. long short_per_long;
  97059. double avgfloat;
  97060. vorbis_block *vb;
  97061. int choice;
  97062. } bitrate_manager_state;
  97063. typedef struct bitrate_manager_info{
  97064. long avg_rate;
  97065. long min_rate;
  97066. long max_rate;
  97067. long reservoir_bits;
  97068. double reservoir_bias;
  97069. double slew_damp;
  97070. } bitrate_manager_info;
  97071. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97072. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97073. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97074. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97075. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97076. #endif
  97077. /*** End of inlined file: bitrate.h ***/
  97078. static int ilog(unsigned int v){
  97079. int ret=0;
  97080. while(v){
  97081. ret++;
  97082. v>>=1;
  97083. }
  97084. return(ret);
  97085. }
  97086. static int ilog2(unsigned int v){
  97087. int ret=0;
  97088. if(v)--v;
  97089. while(v){
  97090. ret++;
  97091. v>>=1;
  97092. }
  97093. return(ret);
  97094. }
  97095. typedef struct private_state {
  97096. envelope_lookup *ve; /* envelope lookup */
  97097. int window[2];
  97098. vorbis_look_transform **transform[2]; /* block, type */
  97099. drft_lookup fft_look[2];
  97100. int modebits;
  97101. vorbis_look_floor **flr;
  97102. vorbis_look_residue **residue;
  97103. vorbis_look_psy *psy;
  97104. vorbis_look_psy_global *psy_g_look;
  97105. unsigned char *header;
  97106. unsigned char *header1;
  97107. unsigned char *header2;
  97108. bitrate_manager_state bms;
  97109. ogg_int64_t sample_count;
  97110. } private_state;
  97111. /*** Start of inlined file: highlevel.h ***/
  97112. typedef struct highlevel_byblocktype {
  97113. double tone_mask_setting;
  97114. double tone_peaklimit_setting;
  97115. double noise_bias_setting;
  97116. double noise_compand_setting;
  97117. } highlevel_byblocktype;
  97118. typedef struct highlevel_encode_setup {
  97119. void *setup;
  97120. int set_in_stone;
  97121. double base_setting;
  97122. double long_setting;
  97123. double short_setting;
  97124. double impulse_noisetune;
  97125. int managed;
  97126. long bitrate_min;
  97127. long bitrate_av;
  97128. double bitrate_av_damp;
  97129. long bitrate_max;
  97130. long bitrate_reservoir;
  97131. double bitrate_reservoir_bias;
  97132. int impulse_block_p;
  97133. int noise_normalize_p;
  97134. double stereo_point_setting;
  97135. double lowpass_kHz;
  97136. double ath_floating_dB;
  97137. double ath_absolute_dB;
  97138. double amplitude_track_dBpersec;
  97139. double trigger_setting;
  97140. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97141. } highlevel_encode_setup;
  97142. /*** End of inlined file: highlevel.h ***/
  97143. typedef struct codec_setup_info {
  97144. long blocksizes[2];
  97145. int modes;
  97146. int maps;
  97147. int floors;
  97148. int residues;
  97149. int books;
  97150. int psys; /* encode only */
  97151. vorbis_info_mode *mode_param[64];
  97152. int map_type[64];
  97153. vorbis_info_mapping *map_param[64];
  97154. int floor_type[64];
  97155. vorbis_info_floor *floor_param[64];
  97156. int residue_type[64];
  97157. vorbis_info_residue *residue_param[64];
  97158. static_codebook *book_param[256];
  97159. codebook *fullbooks;
  97160. vorbis_info_psy *psy_param[4]; /* encode only */
  97161. vorbis_info_psy_global psy_g_param;
  97162. bitrate_manager_info bi;
  97163. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97164. highly redundant structure, but
  97165. improves clarity of program flow. */
  97166. int halfrate_flag; /* painless downsample for decode */
  97167. } codec_setup_info;
  97168. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97169. extern void _vp_global_free(vorbis_look_psy_global *look);
  97170. #endif
  97171. /*** End of inlined file: codec_internal.h ***/
  97172. /*** Start of inlined file: registry.h ***/
  97173. #ifndef _V_REG_H_
  97174. #define _V_REG_H_
  97175. #define VI_TRANSFORMB 1
  97176. #define VI_WINDOWB 1
  97177. #define VI_TIMEB 1
  97178. #define VI_FLOORB 2
  97179. #define VI_RESB 3
  97180. #define VI_MAPB 1
  97181. extern vorbis_func_floor *_floor_P[];
  97182. extern vorbis_func_residue *_residue_P[];
  97183. extern vorbis_func_mapping *_mapping_P[];
  97184. #endif
  97185. /*** End of inlined file: registry.h ***/
  97186. /*** Start of inlined file: scales.h ***/
  97187. #ifndef _V_SCALES_H_
  97188. #define _V_SCALES_H_
  97189. #include <math.h>
  97190. #define VORBIS_IEEE_FLOAT32 1
  97191. #ifdef VORBIS_IEEE_FLOAT32
  97192. static float unitnorm(float x){
  97193. union {
  97194. ogg_uint32_t i;
  97195. float f;
  97196. } ix;
  97197. ix.f = x;
  97198. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97199. return ix.f;
  97200. }
  97201. static float todB(const float *x){
  97202. union {
  97203. ogg_uint32_t i;
  97204. float f;
  97205. } ix;
  97206. ix.f = *x;
  97207. ix.i = ix.i&0x7fffffff;
  97208. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97209. }
  97210. #define todB_nn(x) todB(x)
  97211. #else
  97212. static float unitnorm(float x){
  97213. if(x<0)return(-1.f);
  97214. return(1.f);
  97215. }
  97216. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97217. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97218. #endif
  97219. #define fromdB(x) (exp((x)*.11512925f))
  97220. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97221. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97222. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97223. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97224. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97225. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97226. #endif
  97227. /*** End of inlined file: scales.h ***/
  97228. int analysis_noisy=1;
  97229. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97230. int ret,i;
  97231. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97232. vb->glue_bits=0;
  97233. vb->time_bits=0;
  97234. vb->floor_bits=0;
  97235. vb->res_bits=0;
  97236. for(i=0;i<PACKETBLOBS;i++)
  97237. oggpack_reset(vbi->packetblob[i]);
  97238. if((ret=_mapping_P[0]->forward(vb)))
  97239. return(ret);
  97240. if(op){
  97241. if(vorbis_bitrate_managed(vb))
  97242. return(OV_EINVAL);
  97243. op->packet=oggpack_get_buffer(&vb->opb);
  97244. op->bytes=oggpack_bytes(&vb->opb);
  97245. op->b_o_s=0;
  97246. op->e_o_s=vb->eofflag;
  97247. op->granulepos=vb->granulepos;
  97248. op->packetno=vb->sequence; /* for sake of completeness */
  97249. }
  97250. return(0);
  97251. }
  97252. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97253. int j;
  97254. FILE *of;
  97255. char buffer[80];
  97256. sprintf(buffer,"%s_%d.m",base,i);
  97257. of=fopen(buffer,"w");
  97258. if(!of)perror("failed to open data dump file");
  97259. for(j=0;j<n;j++){
  97260. if(bark){
  97261. float b=toBARK((4000.f*j/n)+.25);
  97262. fprintf(of,"%f ",b);
  97263. }else
  97264. if(off!=0)
  97265. fprintf(of,"%f ",(double)(j+off)/8000.);
  97266. else
  97267. fprintf(of,"%f ",(double)j);
  97268. if(dB){
  97269. float val;
  97270. if(v[j]==0.)
  97271. val=-140.;
  97272. else
  97273. val=todB(v+j);
  97274. fprintf(of,"%f\n",val);
  97275. }else{
  97276. fprintf(of,"%f\n",v[j]);
  97277. }
  97278. }
  97279. fclose(of);
  97280. }
  97281. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97282. ogg_int64_t off){
  97283. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97284. }
  97285. #endif
  97286. /*** End of inlined file: analysis.c ***/
  97287. /*** Start of inlined file: bitrate.c ***/
  97288. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97289. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97290. // tasks..
  97291. #if JUCE_MSVC
  97292. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97293. #endif
  97294. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97295. #if JUCE_USE_OGGVORBIS
  97296. #include <stdlib.h>
  97297. #include <string.h>
  97298. #include <math.h>
  97299. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97300. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97301. bitrate_manager_info *bi=&ci->bi;
  97302. memset(bm,0,sizeof(*bm));
  97303. if(bi && (bi->reservoir_bits>0)){
  97304. long ratesamples=vi->rate;
  97305. int halfsamples=ci->blocksizes[0]>>1;
  97306. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97307. bm->managed=1;
  97308. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97309. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97310. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97311. bm->avgfloat=PACKETBLOBS/2;
  97312. {
  97313. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97314. bm->minmax_reservoir=desired_fill;
  97315. bm->avg_reservoir=desired_fill;
  97316. }
  97317. }
  97318. }
  97319. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97320. memset(bm,0,sizeof(*bm));
  97321. return;
  97322. }
  97323. int vorbis_bitrate_managed(vorbis_block *vb){
  97324. vorbis_dsp_state *vd=vb->vd;
  97325. private_state *b=(private_state*)vd->backend_state;
  97326. bitrate_manager_state *bm=&b->bms;
  97327. if(bm && bm->managed)return(1);
  97328. return(0);
  97329. }
  97330. int vorbis_bitrate_addblock(vorbis_block *vb){
  97331. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97332. vorbis_dsp_state *vd=vb->vd;
  97333. private_state *b=(private_state*)vd->backend_state;
  97334. bitrate_manager_state *bm=&b->bms;
  97335. vorbis_info *vi=vd->vi;
  97336. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97337. bitrate_manager_info *bi=&ci->bi;
  97338. int choice=rint(bm->avgfloat);
  97339. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97340. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97341. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97342. int samples=ci->blocksizes[vb->W]>>1;
  97343. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97344. if(!bm->managed){
  97345. if(bm->vb)return(-1); /* one has been submitted without
  97346. being claimed */
  97347. bm->vb=vb;
  97348. return(0);
  97349. }
  97350. bm->vb=vb;
  97351. if(bm->avg_bitsper>0){
  97352. double slew=0.;
  97353. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97354. double slewlimit= 15./bi->slew_damp;
  97355. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97356. while(choice>0 && this_bits>avg_target_bits &&
  97357. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97358. choice--;
  97359. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97360. }
  97361. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97362. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97363. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97364. choice++;
  97365. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97366. }
  97367. }
  97368. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97369. if(slew<-slewlimit)slew=-slewlimit;
  97370. if(slew>slewlimit)slew=slewlimit;
  97371. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97372. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97373. }
  97374. if(bm->min_bitsper>0){
  97375. if(this_bits<min_target_bits){
  97376. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97377. choice++;
  97378. if(choice>=PACKETBLOBS)break;
  97379. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97380. }
  97381. }
  97382. }
  97383. if(bm->max_bitsper>0){
  97384. if(this_bits>max_target_bits){
  97385. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97386. choice--;
  97387. if(choice<0)break;
  97388. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97389. }
  97390. }
  97391. }
  97392. if(choice<0){
  97393. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97394. bm->choice=choice=0;
  97395. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97396. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97397. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97398. }
  97399. }else{
  97400. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97401. if(choice>=PACKETBLOBS)
  97402. choice=PACKETBLOBS-1;
  97403. bm->choice=choice;
  97404. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97405. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97406. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97407. }
  97408. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97409. if(max_target_bits>0 && this_bits>max_target_bits){
  97410. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97411. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97412. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97413. }else{
  97414. if(bm->minmax_reservoir>desired_fill){
  97415. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97416. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97417. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97418. }else{
  97419. bm->minmax_reservoir=desired_fill;
  97420. }
  97421. }else{
  97422. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97423. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97424. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97425. }else{
  97426. bm->minmax_reservoir=desired_fill;
  97427. }
  97428. }
  97429. }
  97430. }
  97431. if(bm->avg_bitsper>0){
  97432. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97433. bm->avg_reservoir+=this_bits-avg_target_bits;
  97434. }
  97435. return(0);
  97436. }
  97437. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97438. private_state *b=(private_state*)vd->backend_state;
  97439. bitrate_manager_state *bm=&b->bms;
  97440. vorbis_block *vb=bm->vb;
  97441. int choice=PACKETBLOBS/2;
  97442. if(!vb)return 0;
  97443. if(op){
  97444. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97445. if(vorbis_bitrate_managed(vb))
  97446. choice=bm->choice;
  97447. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97448. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97449. op->b_o_s=0;
  97450. op->e_o_s=vb->eofflag;
  97451. op->granulepos=vb->granulepos;
  97452. op->packetno=vb->sequence; /* for sake of completeness */
  97453. }
  97454. bm->vb=0;
  97455. return(1);
  97456. }
  97457. #endif
  97458. /*** End of inlined file: bitrate.c ***/
  97459. /*** Start of inlined file: block.c ***/
  97460. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97461. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97462. // tasks..
  97463. #if JUCE_MSVC
  97464. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97465. #endif
  97466. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97467. #if JUCE_USE_OGGVORBIS
  97468. #include <stdio.h>
  97469. #include <stdlib.h>
  97470. #include <string.h>
  97471. /*** Start of inlined file: window.h ***/
  97472. #ifndef _V_WINDOW_
  97473. #define _V_WINDOW_
  97474. extern float *_vorbis_window_get(int n);
  97475. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97476. int lW,int W,int nW);
  97477. #endif
  97478. /*** End of inlined file: window.h ***/
  97479. /*** Start of inlined file: lpc.h ***/
  97480. #ifndef _V_LPC_H_
  97481. #define _V_LPC_H_
  97482. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97483. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97484. float *data,long n);
  97485. #endif
  97486. /*** End of inlined file: lpc.h ***/
  97487. #ifndef WORD_ALIGN
  97488. #define WORD_ALIGN 8
  97489. #endif
  97490. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97491. int i;
  97492. memset(vb,0,sizeof(*vb));
  97493. vb->vd=v;
  97494. vb->localalloc=0;
  97495. vb->localstore=NULL;
  97496. if(v->analysisp){
  97497. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97498. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97499. vbi->ampmax=-9999;
  97500. for(i=0;i<PACKETBLOBS;i++){
  97501. if(i==PACKETBLOBS/2){
  97502. vbi->packetblob[i]=&vb->opb;
  97503. }else{
  97504. vbi->packetblob[i]=
  97505. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97506. }
  97507. oggpack_writeinit(vbi->packetblob[i]);
  97508. }
  97509. }
  97510. return(0);
  97511. }
  97512. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97513. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97514. if(bytes+vb->localtop>vb->localalloc){
  97515. if(vb->localstore){
  97516. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97517. vb->totaluse+=vb->localtop;
  97518. link->next=vb->reap;
  97519. link->ptr=vb->localstore;
  97520. vb->reap=link;
  97521. }
  97522. vb->localalloc=bytes;
  97523. vb->localstore=_ogg_malloc(vb->localalloc);
  97524. vb->localtop=0;
  97525. }
  97526. {
  97527. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97528. vb->localtop+=bytes;
  97529. return ret;
  97530. }
  97531. }
  97532. void _vorbis_block_ripcord(vorbis_block *vb){
  97533. struct alloc_chain *reap=vb->reap;
  97534. while(reap){
  97535. struct alloc_chain *next=reap->next;
  97536. _ogg_free(reap->ptr);
  97537. memset(reap,0,sizeof(*reap));
  97538. _ogg_free(reap);
  97539. reap=next;
  97540. }
  97541. if(vb->totaluse){
  97542. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97543. vb->localalloc+=vb->totaluse;
  97544. vb->totaluse=0;
  97545. }
  97546. vb->localtop=0;
  97547. vb->reap=NULL;
  97548. }
  97549. int vorbis_block_clear(vorbis_block *vb){
  97550. int i;
  97551. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97552. _vorbis_block_ripcord(vb);
  97553. if(vb->localstore)_ogg_free(vb->localstore);
  97554. if(vbi){
  97555. for(i=0;i<PACKETBLOBS;i++){
  97556. oggpack_writeclear(vbi->packetblob[i]);
  97557. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97558. }
  97559. _ogg_free(vbi);
  97560. }
  97561. memset(vb,0,sizeof(*vb));
  97562. return(0);
  97563. }
  97564. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97565. int i;
  97566. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97567. private_state *b=NULL;
  97568. int hs;
  97569. if(ci==NULL) return 1;
  97570. hs=ci->halfrate_flag;
  97571. memset(v,0,sizeof(*v));
  97572. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97573. v->vi=vi;
  97574. b->modebits=ilog2(ci->modes);
  97575. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97576. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97577. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97578. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97579. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97580. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97581. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97582. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97583. if(encp){ /* encode/decode differ here */
  97584. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97585. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97586. if(!ci->fullbooks){
  97587. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97588. for(i=0;i<ci->books;i++)
  97589. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97590. }
  97591. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97592. for(i=0;i<ci->psys;i++){
  97593. _vp_psy_init(b->psy+i,
  97594. ci->psy_param[i],
  97595. &ci->psy_g_param,
  97596. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97597. vi->rate);
  97598. }
  97599. v->analysisp=1;
  97600. }else{
  97601. if(!ci->fullbooks){
  97602. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97603. for(i=0;i<ci->books;i++){
  97604. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97605. vorbis_staticbook_destroy(ci->book_param[i]);
  97606. ci->book_param[i]=NULL;
  97607. }
  97608. }
  97609. }
  97610. v->pcm_storage=ci->blocksizes[1];
  97611. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97612. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97613. {
  97614. int i;
  97615. for(i=0;i<vi->channels;i++)
  97616. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97617. }
  97618. v->lW=0; /* previous window size */
  97619. v->W=0; /* current window size */
  97620. v->centerW=ci->blocksizes[1]/2;
  97621. v->pcm_current=v->centerW;
  97622. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97623. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97624. for(i=0;i<ci->floors;i++)
  97625. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97626. look(v,ci->floor_param[i]);
  97627. for(i=0;i<ci->residues;i++)
  97628. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97629. look(v,ci->residue_param[i]);
  97630. return 0;
  97631. }
  97632. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97633. private_state *b=NULL;
  97634. if(_vds_shared_init(v,vi,1))return 1;
  97635. b=(private_state*)v->backend_state;
  97636. b->psy_g_look=_vp_global_look(vi);
  97637. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97638. _ve_envelope_init(b->ve,vi);
  97639. vorbis_bitrate_init(vi,&b->bms);
  97640. v->sequence=3;
  97641. return(0);
  97642. }
  97643. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97644. int i;
  97645. if(v){
  97646. vorbis_info *vi=v->vi;
  97647. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97648. private_state *b=(private_state*)v->backend_state;
  97649. if(b){
  97650. if(b->ve){
  97651. _ve_envelope_clear(b->ve);
  97652. _ogg_free(b->ve);
  97653. }
  97654. if(b->transform[0]){
  97655. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97656. _ogg_free(b->transform[0][0]);
  97657. _ogg_free(b->transform[0]);
  97658. }
  97659. if(b->transform[1]){
  97660. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97661. _ogg_free(b->transform[1][0]);
  97662. _ogg_free(b->transform[1]);
  97663. }
  97664. if(b->flr){
  97665. for(i=0;i<ci->floors;i++)
  97666. _floor_P[ci->floor_type[i]]->
  97667. free_look(b->flr[i]);
  97668. _ogg_free(b->flr);
  97669. }
  97670. if(b->residue){
  97671. for(i=0;i<ci->residues;i++)
  97672. _residue_P[ci->residue_type[i]]->
  97673. free_look(b->residue[i]);
  97674. _ogg_free(b->residue);
  97675. }
  97676. if(b->psy){
  97677. for(i=0;i<ci->psys;i++)
  97678. _vp_psy_clear(b->psy+i);
  97679. _ogg_free(b->psy);
  97680. }
  97681. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97682. vorbis_bitrate_clear(&b->bms);
  97683. drft_clear(&b->fft_look[0]);
  97684. drft_clear(&b->fft_look[1]);
  97685. }
  97686. if(v->pcm){
  97687. for(i=0;i<vi->channels;i++)
  97688. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97689. _ogg_free(v->pcm);
  97690. if(v->pcmret)_ogg_free(v->pcmret);
  97691. }
  97692. if(b){
  97693. if(b->header)_ogg_free(b->header);
  97694. if(b->header1)_ogg_free(b->header1);
  97695. if(b->header2)_ogg_free(b->header2);
  97696. _ogg_free(b);
  97697. }
  97698. memset(v,0,sizeof(*v));
  97699. }
  97700. }
  97701. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97702. int i;
  97703. vorbis_info *vi=v->vi;
  97704. private_state *b=(private_state*)v->backend_state;
  97705. if(b->header)_ogg_free(b->header);b->header=NULL;
  97706. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97707. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97708. if(v->pcm_current+vals>=v->pcm_storage){
  97709. v->pcm_storage=v->pcm_current+vals*2;
  97710. for(i=0;i<vi->channels;i++){
  97711. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97712. }
  97713. }
  97714. for(i=0;i<vi->channels;i++)
  97715. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97716. return(v->pcmret);
  97717. }
  97718. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97719. int i;
  97720. int order=32;
  97721. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97722. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97723. long j;
  97724. v->preextrapolate=1;
  97725. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97726. for(i=0;i<v->vi->channels;i++){
  97727. for(j=0;j<v->pcm_current;j++)
  97728. work[j]=v->pcm[i][v->pcm_current-j-1];
  97729. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97730. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97731. order,
  97732. work+v->pcm_current-v->centerW,
  97733. v->centerW);
  97734. for(j=0;j<v->pcm_current;j++)
  97735. v->pcm[i][v->pcm_current-j-1]=work[j];
  97736. }
  97737. }
  97738. }
  97739. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97740. vorbis_info *vi=v->vi;
  97741. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97742. if(vals<=0){
  97743. int order=32;
  97744. int i;
  97745. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97746. if(!v->preextrapolate)
  97747. _preextrapolate_helper(v);
  97748. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97749. v->eofflag=v->pcm_current;
  97750. v->pcm_current+=ci->blocksizes[1]*3;
  97751. for(i=0;i<vi->channels;i++){
  97752. if(v->eofflag>order*2){
  97753. long n;
  97754. n=v->eofflag;
  97755. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97756. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97757. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97758. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97759. }else{
  97760. memset(v->pcm[i]+v->eofflag,0,
  97761. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97762. }
  97763. }
  97764. }else{
  97765. if(v->pcm_current+vals>v->pcm_storage)
  97766. return(OV_EINVAL);
  97767. v->pcm_current+=vals;
  97768. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97769. _preextrapolate_helper(v);
  97770. }
  97771. return(0);
  97772. }
  97773. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97774. int i;
  97775. vorbis_info *vi=v->vi;
  97776. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97777. private_state *b=(private_state*)v->backend_state;
  97778. vorbis_look_psy_global *g=b->psy_g_look;
  97779. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97780. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97781. if(!v->preextrapolate)return(0);
  97782. if(v->eofflag==-1)return(0);
  97783. {
  97784. long bp=_ve_envelope_search(v);
  97785. if(bp==-1){
  97786. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97787. full long block */
  97788. v->nW=0;
  97789. }else{
  97790. if(ci->blocksizes[0]==ci->blocksizes[1])
  97791. v->nW=0;
  97792. else
  97793. v->nW=bp;
  97794. }
  97795. }
  97796. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97797. {
  97798. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97799. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97800. although this check is
  97801. less strict that the
  97802. _ve_envelope_search,
  97803. the search is not run
  97804. if we only use one
  97805. block size */
  97806. }
  97807. _vorbis_block_ripcord(vb);
  97808. vb->lW=v->lW;
  97809. vb->W=v->W;
  97810. vb->nW=v->nW;
  97811. if(v->W){
  97812. if(!v->lW || !v->nW){
  97813. vbi->blocktype=BLOCKTYPE_TRANSITION;
  97814. }else{
  97815. vbi->blocktype=BLOCKTYPE_LONG;
  97816. }
  97817. }else{
  97818. if(_ve_envelope_mark(v)){
  97819. vbi->blocktype=BLOCKTYPE_IMPULSE;
  97820. }else{
  97821. vbi->blocktype=BLOCKTYPE_PADDING;
  97822. }
  97823. }
  97824. vb->vd=v;
  97825. vb->sequence=v->sequence++;
  97826. vb->granulepos=v->granulepos;
  97827. vb->pcmend=ci->blocksizes[v->W];
  97828. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  97829. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  97830. vbi->ampmax=g->ampmax;
  97831. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  97832. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  97833. for(i=0;i<vi->channels;i++){
  97834. vbi->pcmdelay[i]=
  97835. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97836. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97837. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  97838. }
  97839. if(v->eofflag){
  97840. if(v->centerW>=v->eofflag){
  97841. v->eofflag=-1;
  97842. vb->eofflag=1;
  97843. return(1);
  97844. }
  97845. }
  97846. {
  97847. int new_centerNext=ci->blocksizes[1]/2;
  97848. int movementW=centerNext-new_centerNext;
  97849. if(movementW>0){
  97850. _ve_envelope_shift(b->ve,movementW);
  97851. v->pcm_current-=movementW;
  97852. for(i=0;i<vi->channels;i++)
  97853. memmove(v->pcm[i],v->pcm[i]+movementW,
  97854. v->pcm_current*sizeof(*v->pcm[i]));
  97855. v->lW=v->W;
  97856. v->W=v->nW;
  97857. v->centerW=new_centerNext;
  97858. if(v->eofflag){
  97859. v->eofflag-=movementW;
  97860. if(v->eofflag<=0)v->eofflag=-1;
  97861. if(v->centerW>=v->eofflag){
  97862. v->granulepos+=movementW-(v->centerW-v->eofflag);
  97863. }else{
  97864. v->granulepos+=movementW;
  97865. }
  97866. }else{
  97867. v->granulepos+=movementW;
  97868. }
  97869. }
  97870. }
  97871. return(1);
  97872. }
  97873. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  97874. vorbis_info *vi=v->vi;
  97875. codec_setup_info *ci;
  97876. int hs;
  97877. if(!v->backend_state)return -1;
  97878. if(!vi)return -1;
  97879. ci=(codec_setup_info*) vi->codec_setup;
  97880. if(!ci)return -1;
  97881. hs=ci->halfrate_flag;
  97882. v->centerW=ci->blocksizes[1]>>(hs+1);
  97883. v->pcm_current=v->centerW>>hs;
  97884. v->pcm_returned=-1;
  97885. v->granulepos=-1;
  97886. v->sequence=-1;
  97887. v->eofflag=0;
  97888. ((private_state *)(v->backend_state))->sample_count=-1;
  97889. return(0);
  97890. }
  97891. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97892. if(_vds_shared_init(v,vi,0)) return 1;
  97893. vorbis_synthesis_restart(v);
  97894. return 0;
  97895. }
  97896. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  97897. vorbis_info *vi=v->vi;
  97898. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97899. private_state *b=(private_state*)v->backend_state;
  97900. int hs=ci->halfrate_flag;
  97901. int i,j;
  97902. if(!vb)return(OV_EINVAL);
  97903. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  97904. v->lW=v->W;
  97905. v->W=vb->W;
  97906. v->nW=-1;
  97907. if((v->sequence==-1)||
  97908. (v->sequence+1 != vb->sequence)){
  97909. v->granulepos=-1; /* out of sequence; lose count */
  97910. b->sample_count=-1;
  97911. }
  97912. v->sequence=vb->sequence;
  97913. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  97914. was called on block */
  97915. int n=ci->blocksizes[v->W]>>(hs+1);
  97916. int n0=ci->blocksizes[0]>>(hs+1);
  97917. int n1=ci->blocksizes[1]>>(hs+1);
  97918. int thisCenter;
  97919. int prevCenter;
  97920. v->glue_bits+=vb->glue_bits;
  97921. v->time_bits+=vb->time_bits;
  97922. v->floor_bits+=vb->floor_bits;
  97923. v->res_bits+=vb->res_bits;
  97924. if(v->centerW){
  97925. thisCenter=n1;
  97926. prevCenter=0;
  97927. }else{
  97928. thisCenter=0;
  97929. prevCenter=n1;
  97930. }
  97931. for(j=0;j<vi->channels;j++){
  97932. if(v->lW){
  97933. if(v->W){
  97934. float *w=_vorbis_window_get(b->window[1]-hs);
  97935. float *pcm=v->pcm[j]+prevCenter;
  97936. float *p=vb->pcm[j];
  97937. for(i=0;i<n1;i++)
  97938. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  97939. }else{
  97940. float *w=_vorbis_window_get(b->window[0]-hs);
  97941. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  97942. float *p=vb->pcm[j];
  97943. for(i=0;i<n0;i++)
  97944. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97945. }
  97946. }else{
  97947. if(v->W){
  97948. float *w=_vorbis_window_get(b->window[0]-hs);
  97949. float *pcm=v->pcm[j]+prevCenter;
  97950. float *p=vb->pcm[j]+n1/2-n0/2;
  97951. for(i=0;i<n0;i++)
  97952. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97953. for(;i<n1/2+n0/2;i++)
  97954. pcm[i]=p[i];
  97955. }else{
  97956. float *w=_vorbis_window_get(b->window[0]-hs);
  97957. float *pcm=v->pcm[j]+prevCenter;
  97958. float *p=vb->pcm[j];
  97959. for(i=0;i<n0;i++)
  97960. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97961. }
  97962. }
  97963. {
  97964. float *pcm=v->pcm[j]+thisCenter;
  97965. float *p=vb->pcm[j]+n;
  97966. for(i=0;i<n;i++)
  97967. pcm[i]=p[i];
  97968. }
  97969. }
  97970. if(v->centerW)
  97971. v->centerW=0;
  97972. else
  97973. v->centerW=n1;
  97974. if(v->pcm_returned==-1){
  97975. v->pcm_returned=thisCenter;
  97976. v->pcm_current=thisCenter;
  97977. }else{
  97978. v->pcm_returned=prevCenter;
  97979. v->pcm_current=prevCenter+
  97980. ((ci->blocksizes[v->lW]/4+
  97981. ci->blocksizes[v->W]/4)>>hs);
  97982. }
  97983. }
  97984. if(b->sample_count==-1){
  97985. b->sample_count=0;
  97986. }else{
  97987. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  97988. }
  97989. if(v->granulepos==-1){
  97990. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  97991. v->granulepos=vb->granulepos;
  97992. if(b->sample_count>v->granulepos){
  97993. if(vb->eofflag){
  97994. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  97995. }else{
  97996. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  97997. if(v->pcm_returned>v->pcm_current)
  97998. v->pcm_returned=v->pcm_current;
  97999. }
  98000. }
  98001. }
  98002. }else{
  98003. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98004. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98005. if(v->granulepos>vb->granulepos){
  98006. long extra=v->granulepos-vb->granulepos;
  98007. if(extra)
  98008. if(vb->eofflag){
  98009. v->pcm_current-=extra>>hs;
  98010. } /* else {Shouldn't happen *unless* the bitstream is out of
  98011. spec. Either way, believe the bitstream } */
  98012. } /* else {Shouldn't happen *unless* the bitstream is out of
  98013. spec. Either way, believe the bitstream } */
  98014. v->granulepos=vb->granulepos;
  98015. }
  98016. }
  98017. if(vb->eofflag)v->eofflag=1;
  98018. return(0);
  98019. }
  98020. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98021. vorbis_info *vi=v->vi;
  98022. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98023. if(pcm){
  98024. int i;
  98025. for(i=0;i<vi->channels;i++)
  98026. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98027. *pcm=v->pcmret;
  98028. }
  98029. return(v->pcm_current-v->pcm_returned);
  98030. }
  98031. return(0);
  98032. }
  98033. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98034. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98035. v->pcm_returned+=n;
  98036. return(0);
  98037. }
  98038. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98039. vorbis_info *vi=v->vi;
  98040. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98041. int hs=ci->halfrate_flag;
  98042. int n=ci->blocksizes[v->W]>>(hs+1);
  98043. int n0=ci->blocksizes[0]>>(hs+1);
  98044. int n1=ci->blocksizes[1]>>(hs+1);
  98045. int i,j;
  98046. if(v->pcm_returned<0)return 0;
  98047. if(v->centerW==n1){
  98048. for(j=0;j<vi->channels;j++){
  98049. float *p=v->pcm[j];
  98050. for(i=0;i<n1;i++){
  98051. float temp=p[i];
  98052. p[i]=p[i+n1];
  98053. p[i+n1]=temp;
  98054. }
  98055. }
  98056. v->pcm_current-=n1;
  98057. v->pcm_returned-=n1;
  98058. v->centerW=0;
  98059. }
  98060. if((v->lW^v->W)==1){
  98061. for(j=0;j<vi->channels;j++){
  98062. float *s=v->pcm[j];
  98063. float *d=v->pcm[j]+(n1-n0)/2;
  98064. for(i=(n1+n0)/2-1;i>=0;--i)
  98065. d[i]=s[i];
  98066. }
  98067. v->pcm_returned+=(n1-n0)/2;
  98068. v->pcm_current+=(n1-n0)/2;
  98069. }else{
  98070. if(v->lW==0){
  98071. for(j=0;j<vi->channels;j++){
  98072. float *s=v->pcm[j];
  98073. float *d=v->pcm[j]+n1-n0;
  98074. for(i=n0-1;i>=0;--i)
  98075. d[i]=s[i];
  98076. }
  98077. v->pcm_returned+=n1-n0;
  98078. v->pcm_current+=n1-n0;
  98079. }
  98080. }
  98081. if(pcm){
  98082. int i;
  98083. for(i=0;i<vi->channels;i++)
  98084. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98085. *pcm=v->pcmret;
  98086. }
  98087. return(n1+n-v->pcm_returned);
  98088. }
  98089. float *vorbis_window(vorbis_dsp_state *v,int W){
  98090. vorbis_info *vi=v->vi;
  98091. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98092. int hs=ci->halfrate_flag;
  98093. private_state *b=(private_state*)v->backend_state;
  98094. if(b->window[W]-1<0)return NULL;
  98095. return _vorbis_window_get(b->window[W]-hs);
  98096. }
  98097. #endif
  98098. /*** End of inlined file: block.c ***/
  98099. /*** Start of inlined file: codebook.c ***/
  98100. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98101. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98102. // tasks..
  98103. #if JUCE_MSVC
  98104. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98105. #endif
  98106. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98107. #if JUCE_USE_OGGVORBIS
  98108. #include <stdlib.h>
  98109. #include <string.h>
  98110. #include <math.h>
  98111. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98112. long i,j;
  98113. int ordered=0;
  98114. oggpack_write(opb,0x564342,24);
  98115. oggpack_write(opb,c->dim,16);
  98116. oggpack_write(opb,c->entries,24);
  98117. for(i=1;i<c->entries;i++)
  98118. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98119. if(i==c->entries)ordered=1;
  98120. if(ordered){
  98121. long count=0;
  98122. oggpack_write(opb,1,1); /* ordered */
  98123. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98124. for(i=1;i<c->entries;i++){
  98125. long thisx=c->lengthlist[i];
  98126. long last=c->lengthlist[i-1];
  98127. if(thisx>last){
  98128. for(j=last;j<thisx;j++){
  98129. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98130. count=i;
  98131. }
  98132. }
  98133. }
  98134. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98135. }else{
  98136. oggpack_write(opb,0,1); /* unordered */
  98137. for(i=0;i<c->entries;i++)
  98138. if(c->lengthlist[i]==0)break;
  98139. if(i==c->entries){
  98140. oggpack_write(opb,0,1); /* no unused entries */
  98141. for(i=0;i<c->entries;i++)
  98142. oggpack_write(opb,c->lengthlist[i]-1,5);
  98143. }else{
  98144. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98145. for(i=0;i<c->entries;i++){
  98146. if(c->lengthlist[i]==0){
  98147. oggpack_write(opb,0,1);
  98148. }else{
  98149. oggpack_write(opb,1,1);
  98150. oggpack_write(opb,c->lengthlist[i]-1,5);
  98151. }
  98152. }
  98153. }
  98154. }
  98155. oggpack_write(opb,c->maptype,4);
  98156. switch(c->maptype){
  98157. case 0:
  98158. break;
  98159. case 1:case 2:
  98160. if(!c->quantlist){
  98161. return(-1);
  98162. }
  98163. oggpack_write(opb,c->q_min,32);
  98164. oggpack_write(opb,c->q_delta,32);
  98165. oggpack_write(opb,c->q_quant-1,4);
  98166. oggpack_write(opb,c->q_sequencep,1);
  98167. {
  98168. int quantvals;
  98169. switch(c->maptype){
  98170. case 1:
  98171. quantvals=_book_maptype1_quantvals(c);
  98172. break;
  98173. case 2:
  98174. quantvals=c->entries*c->dim;
  98175. break;
  98176. default: /* NOT_REACHABLE */
  98177. quantvals=-1;
  98178. }
  98179. for(i=0;i<quantvals;i++)
  98180. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98181. }
  98182. break;
  98183. default:
  98184. return(-1);
  98185. }
  98186. return(0);
  98187. }
  98188. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98189. long i,j;
  98190. memset(s,0,sizeof(*s));
  98191. s->allocedp=1;
  98192. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98193. s->dim=oggpack_read(opb,16);
  98194. s->entries=oggpack_read(opb,24);
  98195. if(s->entries==-1)goto _eofout;
  98196. switch((int)oggpack_read(opb,1)){
  98197. case 0:
  98198. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98199. if(oggpack_read(opb,1)){
  98200. for(i=0;i<s->entries;i++){
  98201. if(oggpack_read(opb,1)){
  98202. long num=oggpack_read(opb,5);
  98203. if(num==-1)goto _eofout;
  98204. s->lengthlist[i]=num+1;
  98205. }else
  98206. s->lengthlist[i]=0;
  98207. }
  98208. }else{
  98209. for(i=0;i<s->entries;i++){
  98210. long num=oggpack_read(opb,5);
  98211. if(num==-1)goto _eofout;
  98212. s->lengthlist[i]=num+1;
  98213. }
  98214. }
  98215. break;
  98216. case 1:
  98217. {
  98218. long length=oggpack_read(opb,5)+1;
  98219. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98220. for(i=0;i<s->entries;){
  98221. long num=oggpack_read(opb,_ilog(s->entries-i));
  98222. if(num==-1)goto _eofout;
  98223. for(j=0;j<num && i<s->entries;j++,i++)
  98224. s->lengthlist[i]=length;
  98225. length++;
  98226. }
  98227. }
  98228. break;
  98229. default:
  98230. return(-1);
  98231. }
  98232. switch((s->maptype=oggpack_read(opb,4))){
  98233. case 0:
  98234. break;
  98235. case 1: case 2:
  98236. s->q_min=oggpack_read(opb,32);
  98237. s->q_delta=oggpack_read(opb,32);
  98238. s->q_quant=oggpack_read(opb,4)+1;
  98239. s->q_sequencep=oggpack_read(opb,1);
  98240. {
  98241. int quantvals=0;
  98242. switch(s->maptype){
  98243. case 1:
  98244. quantvals=_book_maptype1_quantvals(s);
  98245. break;
  98246. case 2:
  98247. quantvals=s->entries*s->dim;
  98248. break;
  98249. }
  98250. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98251. for(i=0;i<quantvals;i++)
  98252. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98253. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98254. }
  98255. break;
  98256. default:
  98257. goto _errout;
  98258. }
  98259. return(0);
  98260. _errout:
  98261. _eofout:
  98262. vorbis_staticbook_clear(s);
  98263. return(-1);
  98264. }
  98265. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98266. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98267. return(book->c->lengthlist[a]);
  98268. }
  98269. int vorbis_book_errorv(codebook *book,float *a){
  98270. int dim=book->dim,k;
  98271. int best=_best(book,a,1);
  98272. for(k=0;k<dim;k++)
  98273. a[k]=(book->valuelist+best*dim)[k];
  98274. return(best);
  98275. }
  98276. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98277. int k,dim=book->dim;
  98278. for(k=0;k<dim;k++)
  98279. a[k]=(book->valuelist+best*dim)[k];
  98280. return(vorbis_book_encode(book,best,b));
  98281. }
  98282. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98283. int read=book->dec_maxlength;
  98284. long lo,hi;
  98285. long lok = oggpack_look(b,book->dec_firsttablen);
  98286. if (lok >= 0) {
  98287. long entry = book->dec_firsttable[lok];
  98288. if(entry&0x80000000UL){
  98289. lo=(entry>>15)&0x7fff;
  98290. hi=book->used_entries-(entry&0x7fff);
  98291. }else{
  98292. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98293. return(entry-1);
  98294. }
  98295. }else{
  98296. lo=0;
  98297. hi=book->used_entries;
  98298. }
  98299. lok = oggpack_look(b, read);
  98300. while(lok<0 && read>1)
  98301. lok = oggpack_look(b, --read);
  98302. if(lok<0)return -1;
  98303. {
  98304. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98305. while(hi-lo>1){
  98306. long p=(hi-lo)>>1;
  98307. long test=book->codelist[lo+p]>testword;
  98308. lo+=p&(test-1);
  98309. hi-=p&(-test);
  98310. }
  98311. if(book->dec_codelengths[lo]<=read){
  98312. oggpack_adv(b, book->dec_codelengths[lo]);
  98313. return(lo);
  98314. }
  98315. }
  98316. oggpack_adv(b, read);
  98317. return(-1);
  98318. }
  98319. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98320. long packed_entry=decode_packed_entry_number(book,b);
  98321. if(packed_entry>=0)
  98322. return(book->dec_index[packed_entry]);
  98323. return(packed_entry);
  98324. }
  98325. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98326. int step=n/book->dim;
  98327. long *entry = (long*)alloca(sizeof(*entry)*step);
  98328. float **t = (float**)alloca(sizeof(*t)*step);
  98329. int i,j,o;
  98330. for (i = 0; i < step; i++) {
  98331. entry[i]=decode_packed_entry_number(book,b);
  98332. if(entry[i]==-1)return(-1);
  98333. t[i] = book->valuelist+entry[i]*book->dim;
  98334. }
  98335. for(i=0,o=0;i<book->dim;i++,o+=step)
  98336. for (j=0;j<step;j++)
  98337. a[o+j]+=t[j][i];
  98338. return(0);
  98339. }
  98340. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98341. int i,j,entry;
  98342. float *t;
  98343. if(book->dim>8){
  98344. for(i=0;i<n;){
  98345. entry = decode_packed_entry_number(book,b);
  98346. if(entry==-1)return(-1);
  98347. t = book->valuelist+entry*book->dim;
  98348. for (j=0;j<book->dim;)
  98349. a[i++]+=t[j++];
  98350. }
  98351. }else{
  98352. for(i=0;i<n;){
  98353. entry = decode_packed_entry_number(book,b);
  98354. if(entry==-1)return(-1);
  98355. t = book->valuelist+entry*book->dim;
  98356. j=0;
  98357. switch((int)book->dim){
  98358. case 8:
  98359. a[i++]+=t[j++];
  98360. case 7:
  98361. a[i++]+=t[j++];
  98362. case 6:
  98363. a[i++]+=t[j++];
  98364. case 5:
  98365. a[i++]+=t[j++];
  98366. case 4:
  98367. a[i++]+=t[j++];
  98368. case 3:
  98369. a[i++]+=t[j++];
  98370. case 2:
  98371. a[i++]+=t[j++];
  98372. case 1:
  98373. a[i++]+=t[j++];
  98374. case 0:
  98375. break;
  98376. }
  98377. }
  98378. }
  98379. return(0);
  98380. }
  98381. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98382. int i,j,entry;
  98383. float *t;
  98384. for(i=0;i<n;){
  98385. entry = decode_packed_entry_number(book,b);
  98386. if(entry==-1)return(-1);
  98387. t = book->valuelist+entry*book->dim;
  98388. for (j=0;j<book->dim;)
  98389. a[i++]=t[j++];
  98390. }
  98391. return(0);
  98392. }
  98393. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98394. oggpack_buffer *b,int n){
  98395. long i,j,entry;
  98396. int chptr=0;
  98397. for(i=offset/ch;i<(offset+n)/ch;){
  98398. entry = decode_packed_entry_number(book,b);
  98399. if(entry==-1)return(-1);
  98400. {
  98401. const float *t = book->valuelist+entry*book->dim;
  98402. for (j=0;j<book->dim;j++){
  98403. a[chptr++][i]+=t[j];
  98404. if(chptr==ch){
  98405. chptr=0;
  98406. i++;
  98407. }
  98408. }
  98409. }
  98410. }
  98411. return(0);
  98412. }
  98413. #ifdef _V_SELFTEST
  98414. #include <stdio.h>
  98415. #include "vorbis/book/lsp20_0.vqh"
  98416. #include "vorbis/book/res0a_13.vqh"
  98417. #define TESTSIZE 40
  98418. float test1[TESTSIZE]={
  98419. 0.105939f,
  98420. 0.215373f,
  98421. 0.429117f,
  98422. 0.587974f,
  98423. 0.181173f,
  98424. 0.296583f,
  98425. 0.515707f,
  98426. 0.715261f,
  98427. 0.162327f,
  98428. 0.263834f,
  98429. 0.342876f,
  98430. 0.406025f,
  98431. 0.103571f,
  98432. 0.223561f,
  98433. 0.368513f,
  98434. 0.540313f,
  98435. 0.136672f,
  98436. 0.395882f,
  98437. 0.587183f,
  98438. 0.652476f,
  98439. 0.114338f,
  98440. 0.417300f,
  98441. 0.525486f,
  98442. 0.698679f,
  98443. 0.147492f,
  98444. 0.324481f,
  98445. 0.643089f,
  98446. 0.757582f,
  98447. 0.139556f,
  98448. 0.215795f,
  98449. 0.324559f,
  98450. 0.399387f,
  98451. 0.120236f,
  98452. 0.267420f,
  98453. 0.446940f,
  98454. 0.608760f,
  98455. 0.115587f,
  98456. 0.287234f,
  98457. 0.571081f,
  98458. 0.708603f,
  98459. };
  98460. float test3[TESTSIZE]={
  98461. 0,1,-2,3,4,-5,6,7,8,9,
  98462. 8,-2,7,-1,4,6,8,3,1,-9,
  98463. 10,11,12,13,14,15,26,17,18,19,
  98464. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98465. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98466. &_vq_book_res0a_13,NULL};
  98467. float *testvec[]={test1,test3};
  98468. int main(){
  98469. oggpack_buffer write;
  98470. oggpack_buffer read;
  98471. long ptr=0,i;
  98472. oggpack_writeinit(&write);
  98473. fprintf(stderr,"Testing codebook abstraction...:\n");
  98474. while(testlist[ptr]){
  98475. codebook c;
  98476. static_codebook s;
  98477. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98478. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98479. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98480. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98481. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98482. oggpack_reset(&write);
  98483. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98484. we can write */
  98485. vorbis_staticbook_pack(testlist[ptr],&write);
  98486. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98487. for(i=0;i<TESTSIZE;i+=c.dim){
  98488. int best=_best(&c,qv+i,1);
  98489. vorbis_book_encodev(&c,best,qv+i,&write);
  98490. }
  98491. vorbis_book_clear(&c);
  98492. fprintf(stderr,"OK.\n");
  98493. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98494. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98495. if(vorbis_staticbook_unpack(&read,&s)){
  98496. fprintf(stderr,"Error unpacking codebook.\n");
  98497. exit(1);
  98498. }
  98499. if(vorbis_book_init_decode(&c,&s)){
  98500. fprintf(stderr,"Error initializing codebook.\n");
  98501. exit(1);
  98502. }
  98503. for(i=0;i<TESTSIZE;i+=c.dim)
  98504. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98505. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98506. exit(1);
  98507. }
  98508. for(i=0;i<TESTSIZE;i++)
  98509. if(fabs(qv[i]-iv[i])>.000001){
  98510. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98511. iv[i],qv[i],i);
  98512. exit(1);
  98513. }
  98514. fprintf(stderr,"OK\n");
  98515. ptr++;
  98516. }
  98517. exit(0);
  98518. }
  98519. #endif
  98520. #endif
  98521. /*** End of inlined file: codebook.c ***/
  98522. /*** Start of inlined file: envelope.c ***/
  98523. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98524. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98525. // tasks..
  98526. #if JUCE_MSVC
  98527. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98528. #endif
  98529. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98530. #if JUCE_USE_OGGVORBIS
  98531. #include <stdlib.h>
  98532. #include <string.h>
  98533. #include <stdio.h>
  98534. #include <math.h>
  98535. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98536. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98537. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98538. int ch=vi->channels;
  98539. int i,j;
  98540. int n=e->winlength=128;
  98541. e->searchstep=64; /* not random */
  98542. e->minenergy=gi->preecho_minenergy;
  98543. e->ch=ch;
  98544. e->storage=128;
  98545. e->cursor=ci->blocksizes[1]/2;
  98546. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98547. mdct_init(&e->mdct,n);
  98548. for(i=0;i<n;i++){
  98549. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98550. e->mdct_win[i]*=e->mdct_win[i];
  98551. }
  98552. e->band[0].begin=2; e->band[0].end=4;
  98553. e->band[1].begin=4; e->band[1].end=5;
  98554. e->band[2].begin=6; e->band[2].end=6;
  98555. e->band[3].begin=9; e->band[3].end=8;
  98556. e->band[4].begin=13; e->band[4].end=8;
  98557. e->band[5].begin=17; e->band[5].end=8;
  98558. e->band[6].begin=22; e->band[6].end=8;
  98559. for(j=0;j<VE_BANDS;j++){
  98560. n=e->band[j].end;
  98561. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98562. for(i=0;i<n;i++){
  98563. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98564. e->band[j].total+=e->band[j].window[i];
  98565. }
  98566. e->band[j].total=1./e->band[j].total;
  98567. }
  98568. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98569. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98570. }
  98571. void _ve_envelope_clear(envelope_lookup *e){
  98572. int i;
  98573. mdct_clear(&e->mdct);
  98574. for(i=0;i<VE_BANDS;i++)
  98575. _ogg_free(e->band[i].window);
  98576. _ogg_free(e->mdct_win);
  98577. _ogg_free(e->filter);
  98578. _ogg_free(e->mark);
  98579. memset(e,0,sizeof(*e));
  98580. }
  98581. static int _ve_amp(envelope_lookup *ve,
  98582. vorbis_info_psy_global *gi,
  98583. float *data,
  98584. envelope_band *bands,
  98585. envelope_filter_state *filters,
  98586. long pos){
  98587. long n=ve->winlength;
  98588. int ret=0;
  98589. long i,j;
  98590. float decay;
  98591. float minV=ve->minenergy;
  98592. float *vec=(float*) alloca(n*sizeof(*vec));
  98593. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98594. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98595. if(penalty<0.f)penalty=0.f;
  98596. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98597. for(i=0;i<n;i++)
  98598. vec[i]=data[i]*ve->mdct_win[i];
  98599. mdct_forward(&ve->mdct,vec,vec);
  98600. {
  98601. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98602. int ptr=filters->nearptr;
  98603. if(ptr==0){
  98604. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98605. filters->nearDC_partialacc=temp;
  98606. }else{
  98607. decay=filters->nearDC_acc+=temp;
  98608. filters->nearDC_partialacc+=temp;
  98609. }
  98610. filters->nearDC_acc-=filters->nearDC[ptr];
  98611. filters->nearDC[ptr]=temp;
  98612. decay*=(1./(VE_NEARDC+1));
  98613. filters->nearptr++;
  98614. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98615. decay=todB(&decay)*.5-15.f;
  98616. }
  98617. for(i=0;i<n/2;i+=2){
  98618. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98619. val=todB(&val)*.5f;
  98620. if(val<decay)val=decay;
  98621. if(val<minV)val=minV;
  98622. vec[i>>1]=val;
  98623. decay-=8.;
  98624. }
  98625. for(j=0;j<VE_BANDS;j++){
  98626. float acc=0.;
  98627. float valmax,valmin;
  98628. for(i=0;i<bands[j].end;i++)
  98629. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98630. acc*=bands[j].total;
  98631. {
  98632. int p,thisx=filters[j].ampptr;
  98633. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98634. p=thisx;
  98635. p--;
  98636. if(p<0)p+=VE_AMP;
  98637. postmax=max(acc,filters[j].ampbuf[p]);
  98638. postmin=min(acc,filters[j].ampbuf[p]);
  98639. for(i=0;i<stretch;i++){
  98640. p--;
  98641. if(p<0)p+=VE_AMP;
  98642. premax=max(premax,filters[j].ampbuf[p]);
  98643. premin=min(premin,filters[j].ampbuf[p]);
  98644. }
  98645. valmin=postmin-premin;
  98646. valmax=postmax-premax;
  98647. filters[j].ampbuf[thisx]=acc;
  98648. filters[j].ampptr++;
  98649. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98650. }
  98651. if(valmax>gi->preecho_thresh[j]+penalty){
  98652. ret|=1;
  98653. ret|=4;
  98654. }
  98655. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98656. }
  98657. return(ret);
  98658. }
  98659. #if 0
  98660. static int seq=0;
  98661. static ogg_int64_t totalshift=-1024;
  98662. #endif
  98663. long _ve_envelope_search(vorbis_dsp_state *v){
  98664. vorbis_info *vi=v->vi;
  98665. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98666. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98667. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98668. long i,j;
  98669. int first=ve->current/ve->searchstep;
  98670. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98671. if(first<0)first=0;
  98672. if(last+VE_WIN+VE_POST>ve->storage){
  98673. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98674. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98675. }
  98676. for(j=first;j<last;j++){
  98677. int ret=0;
  98678. ve->stretch++;
  98679. if(ve->stretch>VE_MAXSTRETCH*2)
  98680. ve->stretch=VE_MAXSTRETCH*2;
  98681. for(i=0;i<ve->ch;i++){
  98682. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98683. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98684. }
  98685. ve->mark[j+VE_POST]=0;
  98686. if(ret&1){
  98687. ve->mark[j]=1;
  98688. ve->mark[j+1]=1;
  98689. }
  98690. if(ret&2){
  98691. ve->mark[j]=1;
  98692. if(j>0)ve->mark[j-1]=1;
  98693. }
  98694. if(ret&4)ve->stretch=-1;
  98695. }
  98696. ve->current=last*ve->searchstep;
  98697. {
  98698. long centerW=v->centerW;
  98699. long testW=
  98700. centerW+
  98701. ci->blocksizes[v->W]/4+
  98702. ci->blocksizes[1]/2+
  98703. ci->blocksizes[0]/4;
  98704. j=ve->cursor;
  98705. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98706. working back one window */
  98707. if(j>=testW)return(1);
  98708. ve->cursor=j;
  98709. if(ve->mark[j/ve->searchstep]){
  98710. if(j>centerW){
  98711. #if 0
  98712. if(j>ve->curmark){
  98713. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98714. int l,m;
  98715. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98716. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98717. seq,
  98718. (totalshift+ve->cursor)/44100.,
  98719. (totalshift+j)/44100.);
  98720. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98721. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98722. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98723. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98724. for(m=0;m<VE_BANDS;m++){
  98725. char buf[80];
  98726. sprintf(buf,"delL%d",m);
  98727. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98728. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98729. }
  98730. for(m=0;m<VE_BANDS;m++){
  98731. char buf[80];
  98732. sprintf(buf,"delR%d",m);
  98733. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98734. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98735. }
  98736. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98737. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98738. seq++;
  98739. }
  98740. #endif
  98741. ve->curmark=j;
  98742. if(j>=testW)return(1);
  98743. return(0);
  98744. }
  98745. }
  98746. j+=ve->searchstep;
  98747. }
  98748. }
  98749. return(-1);
  98750. }
  98751. int _ve_envelope_mark(vorbis_dsp_state *v){
  98752. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98753. vorbis_info *vi=v->vi;
  98754. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98755. long centerW=v->centerW;
  98756. long beginW=centerW-ci->blocksizes[v->W]/4;
  98757. long endW=centerW+ci->blocksizes[v->W]/4;
  98758. if(v->W){
  98759. beginW-=ci->blocksizes[v->lW]/4;
  98760. endW+=ci->blocksizes[v->nW]/4;
  98761. }else{
  98762. beginW-=ci->blocksizes[0]/4;
  98763. endW+=ci->blocksizes[0]/4;
  98764. }
  98765. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98766. {
  98767. long first=beginW/ve->searchstep;
  98768. long last=endW/ve->searchstep;
  98769. long i;
  98770. for(i=first;i<last;i++)
  98771. if(ve->mark[i])return(1);
  98772. }
  98773. return(0);
  98774. }
  98775. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98776. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98777. ahead of ve->current */
  98778. int smallshift=shift/e->searchstep;
  98779. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98780. #if 0
  98781. for(i=0;i<VE_BANDS*e->ch;i++)
  98782. memmove(e->filter[i].markers,
  98783. e->filter[i].markers+smallshift,
  98784. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98785. totalshift+=shift;
  98786. #endif
  98787. e->current-=shift;
  98788. if(e->curmark>=0)
  98789. e->curmark-=shift;
  98790. e->cursor-=shift;
  98791. }
  98792. #endif
  98793. /*** End of inlined file: envelope.c ***/
  98794. /*** Start of inlined file: floor0.c ***/
  98795. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98796. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98797. // tasks..
  98798. #if JUCE_MSVC
  98799. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98800. #endif
  98801. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98802. #if JUCE_USE_OGGVORBIS
  98803. #include <stdlib.h>
  98804. #include <string.h>
  98805. #include <math.h>
  98806. /*** Start of inlined file: lsp.h ***/
  98807. #ifndef _V_LSP_H_
  98808. #define _V_LSP_H_
  98809. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  98810. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  98811. float *lsp,int m,
  98812. float amp,float ampoffset);
  98813. #endif
  98814. /*** End of inlined file: lsp.h ***/
  98815. #include <stdio.h>
  98816. typedef struct {
  98817. int ln;
  98818. int m;
  98819. int **linearmap;
  98820. int n[2];
  98821. vorbis_info_floor0 *vi;
  98822. long bits;
  98823. long frames;
  98824. } vorbis_look_floor0;
  98825. static void floor0_free_info(vorbis_info_floor *i){
  98826. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  98827. if(info){
  98828. memset(info,0,sizeof(*info));
  98829. _ogg_free(info);
  98830. }
  98831. }
  98832. static void floor0_free_look(vorbis_look_floor *i){
  98833. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98834. if(look){
  98835. if(look->linearmap){
  98836. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  98837. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  98838. _ogg_free(look->linearmap);
  98839. }
  98840. memset(look,0,sizeof(*look));
  98841. _ogg_free(look);
  98842. }
  98843. }
  98844. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98845. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98846. int j;
  98847. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  98848. info->order=oggpack_read(opb,8);
  98849. info->rate=oggpack_read(opb,16);
  98850. info->barkmap=oggpack_read(opb,16);
  98851. info->ampbits=oggpack_read(opb,6);
  98852. info->ampdB=oggpack_read(opb,8);
  98853. info->numbooks=oggpack_read(opb,4)+1;
  98854. if(info->order<1)goto err_out;
  98855. if(info->rate<1)goto err_out;
  98856. if(info->barkmap<1)goto err_out;
  98857. if(info->numbooks<1)goto err_out;
  98858. for(j=0;j<info->numbooks;j++){
  98859. info->books[j]=oggpack_read(opb,8);
  98860. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  98861. }
  98862. return(info);
  98863. err_out:
  98864. floor0_free_info(info);
  98865. return(NULL);
  98866. }
  98867. static void floor0_map_lazy_init(vorbis_block *vb,
  98868. vorbis_info_floor *infoX,
  98869. vorbis_look_floor0 *look){
  98870. if(!look->linearmap[vb->W]){
  98871. vorbis_dsp_state *vd=vb->vd;
  98872. vorbis_info *vi=vd->vi;
  98873. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98874. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  98875. int W=vb->W;
  98876. int n=ci->blocksizes[W]/2,j;
  98877. float scale=look->ln/toBARK(info->rate/2.f);
  98878. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  98879. for(j=0;j<n;j++){
  98880. int val=floor( toBARK((info->rate/2.f)/n*j)
  98881. *scale); /* bark numbers represent band edges */
  98882. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  98883. look->linearmap[W][j]=val;
  98884. }
  98885. look->linearmap[W][j]=-1;
  98886. look->n[W]=n;
  98887. }
  98888. }
  98889. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  98890. vorbis_info_floor *i){
  98891. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  98892. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  98893. look->m=info->order;
  98894. look->ln=info->barkmap;
  98895. look->vi=info;
  98896. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  98897. return look;
  98898. }
  98899. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  98900. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98901. vorbis_info_floor0 *info=look->vi;
  98902. int j,k;
  98903. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  98904. if(ampraw>0){ /* also handles the -1 out of data case */
  98905. long maxval=(1<<info->ampbits)-1;
  98906. float amp=(float)ampraw/maxval*info->ampdB;
  98907. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  98908. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  98909. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  98910. codebook *b=ci->fullbooks+info->books[booknum];
  98911. float last=0.f;
  98912. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  98913. for(j=0;j<look->m;j+=b->dim)
  98914. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  98915. for(j=0;j<look->m;){
  98916. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  98917. last=lsp[j-1];
  98918. }
  98919. lsp[look->m]=amp;
  98920. return(lsp);
  98921. }
  98922. }
  98923. eop:
  98924. return(NULL);
  98925. }
  98926. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  98927. void *memo,float *out){
  98928. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98929. vorbis_info_floor0 *info=look->vi;
  98930. floor0_map_lazy_init(vb,info,look);
  98931. if(memo){
  98932. float *lsp=(float *)memo;
  98933. float amp=lsp[look->m];
  98934. vorbis_lsp_to_curve(out,
  98935. look->linearmap[vb->W],
  98936. look->n[vb->W],
  98937. look->ln,
  98938. lsp,look->m,amp,(float)info->ampdB);
  98939. return(1);
  98940. }
  98941. memset(out,0,sizeof(*out)*look->n[vb->W]);
  98942. return(0);
  98943. }
  98944. vorbis_func_floor floor0_exportbundle={
  98945. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  98946. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  98947. };
  98948. #endif
  98949. /*** End of inlined file: floor0.c ***/
  98950. /*** Start of inlined file: floor1.c ***/
  98951. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98952. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98953. // tasks..
  98954. #if JUCE_MSVC
  98955. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98956. #endif
  98957. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98958. #if JUCE_USE_OGGVORBIS
  98959. #include <stdlib.h>
  98960. #include <string.h>
  98961. #include <math.h>
  98962. #include <stdio.h>
  98963. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  98964. typedef struct {
  98965. int sorted_index[VIF_POSIT+2];
  98966. int forward_index[VIF_POSIT+2];
  98967. int reverse_index[VIF_POSIT+2];
  98968. int hineighbor[VIF_POSIT];
  98969. int loneighbor[VIF_POSIT];
  98970. int posts;
  98971. int n;
  98972. int quant_q;
  98973. vorbis_info_floor1 *vi;
  98974. long phrasebits;
  98975. long postbits;
  98976. long frames;
  98977. } vorbis_look_floor1;
  98978. typedef struct lsfit_acc{
  98979. long x0;
  98980. long x1;
  98981. long xa;
  98982. long ya;
  98983. long x2a;
  98984. long y2a;
  98985. long xya;
  98986. long an;
  98987. } lsfit_acc;
  98988. static void floor1_free_info(vorbis_info_floor *i){
  98989. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  98990. if(info){
  98991. memset(info,0,sizeof(*info));
  98992. _ogg_free(info);
  98993. }
  98994. }
  98995. static void floor1_free_look(vorbis_look_floor *i){
  98996. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  98997. if(look){
  98998. memset(look,0,sizeof(*look));
  98999. _ogg_free(look);
  99000. }
  99001. }
  99002. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99003. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99004. int j,k;
  99005. int count=0;
  99006. int rangebits;
  99007. int maxposit=info->postlist[1];
  99008. int maxclass=-1;
  99009. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99010. for(j=0;j<info->partitions;j++){
  99011. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99012. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99013. }
  99014. for(j=0;j<maxclass+1;j++){
  99015. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99016. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99017. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99018. for(k=0;k<(1<<info->class_subs[j]);k++)
  99019. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99020. }
  99021. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99022. oggpack_write(opb,ilog2(maxposit),4);
  99023. rangebits=ilog2(maxposit);
  99024. for(j=0,k=0;j<info->partitions;j++){
  99025. count+=info->class_dim[info->partitionclass[j]];
  99026. for(;k<count;k++)
  99027. oggpack_write(opb,info->postlist[k+2],rangebits);
  99028. }
  99029. }
  99030. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99031. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99032. int j,k,count=0,maxclass=-1,rangebits;
  99033. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99034. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99035. for(j=0;j<info->partitions;j++){
  99036. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99037. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99038. }
  99039. for(j=0;j<maxclass+1;j++){
  99040. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99041. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99042. if(info->class_subs[j]<0)
  99043. goto err_out;
  99044. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99045. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99046. goto err_out;
  99047. for(k=0;k<(1<<info->class_subs[j]);k++){
  99048. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99049. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99050. goto err_out;
  99051. }
  99052. }
  99053. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99054. rangebits=oggpack_read(opb,4);
  99055. for(j=0,k=0;j<info->partitions;j++){
  99056. count+=info->class_dim[info->partitionclass[j]];
  99057. for(;k<count;k++){
  99058. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99059. if(t<0 || t>=(1<<rangebits))
  99060. goto err_out;
  99061. }
  99062. }
  99063. info->postlist[0]=0;
  99064. info->postlist[1]=1<<rangebits;
  99065. return(info);
  99066. err_out:
  99067. floor1_free_info(info);
  99068. return(NULL);
  99069. }
  99070. static int icomp(const void *a,const void *b){
  99071. return(**(int **)a-**(int **)b);
  99072. }
  99073. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99074. vorbis_info_floor *in){
  99075. int *sortpointer[VIF_POSIT+2];
  99076. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99077. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99078. int i,j,n=0;
  99079. look->vi=info;
  99080. look->n=info->postlist[1];
  99081. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99082. n+=2;
  99083. look->posts=n;
  99084. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99085. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99086. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99087. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99088. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99089. switch(info->mult){
  99090. case 1: /* 1024 -> 256 */
  99091. look->quant_q=256;
  99092. break;
  99093. case 2: /* 1024 -> 128 */
  99094. look->quant_q=128;
  99095. break;
  99096. case 3: /* 1024 -> 86 */
  99097. look->quant_q=86;
  99098. break;
  99099. case 4: /* 1024 -> 64 */
  99100. look->quant_q=64;
  99101. break;
  99102. }
  99103. for(i=0;i<n-2;i++){
  99104. int lo=0;
  99105. int hi=1;
  99106. int lx=0;
  99107. int hx=look->n;
  99108. int currentx=info->postlist[i+2];
  99109. for(j=0;j<i+2;j++){
  99110. int x=info->postlist[j];
  99111. if(x>lx && x<currentx){
  99112. lo=j;
  99113. lx=x;
  99114. }
  99115. if(x<hx && x>currentx){
  99116. hi=j;
  99117. hx=x;
  99118. }
  99119. }
  99120. look->loneighbor[i]=lo;
  99121. look->hineighbor[i]=hi;
  99122. }
  99123. return(look);
  99124. }
  99125. static int render_point(int x0,int x1,int y0,int y1,int x){
  99126. y0&=0x7fff; /* mask off flag */
  99127. y1&=0x7fff;
  99128. {
  99129. int dy=y1-y0;
  99130. int adx=x1-x0;
  99131. int ady=abs(dy);
  99132. int err=ady*(x-x0);
  99133. int off=err/adx;
  99134. if(dy<0)return(y0-off);
  99135. return(y0+off);
  99136. }
  99137. }
  99138. static int vorbis_dBquant(const float *x){
  99139. int i= *x*7.3142857f+1023.5f;
  99140. if(i>1023)return(1023);
  99141. if(i<0)return(0);
  99142. return i;
  99143. }
  99144. static float FLOOR1_fromdB_LOOKUP[256]={
  99145. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99146. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99147. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99148. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99149. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99150. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99151. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99152. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99153. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99154. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99155. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99156. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99157. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99158. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99159. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99160. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99161. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99162. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99163. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99164. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99165. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99166. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99167. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99168. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99169. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99170. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99171. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99172. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99173. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99174. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99175. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99176. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99177. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99178. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99179. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99180. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99181. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99182. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99183. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99184. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99185. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99186. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99187. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99188. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99189. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99190. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99191. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99192. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99193. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99194. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99195. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99196. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99197. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99198. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99199. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99200. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99201. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99202. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99203. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99204. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99205. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99206. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99207. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99208. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99209. };
  99210. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99211. int dy=y1-y0;
  99212. int adx=x1-x0;
  99213. int ady=abs(dy);
  99214. int base=dy/adx;
  99215. int sy=(dy<0?base-1:base+1);
  99216. int x=x0;
  99217. int y=y0;
  99218. int err=0;
  99219. ady-=abs(base*adx);
  99220. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99221. while(++x<x1){
  99222. err=err+ady;
  99223. if(err>=adx){
  99224. err-=adx;
  99225. y+=sy;
  99226. }else{
  99227. y+=base;
  99228. }
  99229. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99230. }
  99231. }
  99232. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99233. int dy=y1-y0;
  99234. int adx=x1-x0;
  99235. int ady=abs(dy);
  99236. int base=dy/adx;
  99237. int sy=(dy<0?base-1:base+1);
  99238. int x=x0;
  99239. int y=y0;
  99240. int err=0;
  99241. ady-=abs(base*adx);
  99242. d[x]=y;
  99243. while(++x<x1){
  99244. err=err+ady;
  99245. if(err>=adx){
  99246. err-=adx;
  99247. y+=sy;
  99248. }else{
  99249. y+=base;
  99250. }
  99251. d[x]=y;
  99252. }
  99253. }
  99254. static int accumulate_fit(const float *flr,const float *mdct,
  99255. int x0, int x1,lsfit_acc *a,
  99256. int n,vorbis_info_floor1 *info){
  99257. long i;
  99258. long xa=0,ya=0,x2a=0,y2a=0,xya=0,na=0, xb=0,yb=0,x2b=0,y2b=0,xyb=0,nb=0;
  99259. memset(a,0,sizeof(*a));
  99260. a->x0=x0;
  99261. a->x1=x1;
  99262. if(x1>=n)x1=n-1;
  99263. for(i=x0;i<=x1;i++){
  99264. int quantized=vorbis_dBquant(flr+i);
  99265. if(quantized){
  99266. if(mdct[i]+info->twofitatten>=flr[i]){
  99267. xa += i;
  99268. ya += quantized;
  99269. x2a += i*i;
  99270. y2a += quantized*quantized;
  99271. xya += i*quantized;
  99272. na++;
  99273. }else{
  99274. xb += i;
  99275. yb += quantized;
  99276. x2b += i*i;
  99277. y2b += quantized*quantized;
  99278. xyb += i*quantized;
  99279. nb++;
  99280. }
  99281. }
  99282. }
  99283. xb+=xa;
  99284. yb+=ya;
  99285. x2b+=x2a;
  99286. y2b+=y2a;
  99287. xyb+=xya;
  99288. nb+=na;
  99289. {
  99290. int weight=nb*info->twofitweight/(na+1);
  99291. a->xa=xa*weight+xb;
  99292. a->ya=ya*weight+yb;
  99293. a->x2a=x2a*weight+x2b;
  99294. a->y2a=y2a*weight+y2b;
  99295. a->xya=xya*weight+xyb;
  99296. a->an=na*weight+nb;
  99297. }
  99298. return(na);
  99299. }
  99300. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99301. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99302. long x0=a[0].x0;
  99303. long x1=a[fits-1].x1;
  99304. for(i=0;i<fits;i++){
  99305. x+=a[i].xa;
  99306. y+=a[i].ya;
  99307. x2+=a[i].x2a;
  99308. y2+=a[i].y2a;
  99309. xy+=a[i].xya;
  99310. an+=a[i].an;
  99311. }
  99312. if(*y0>=0){
  99313. x+= x0;
  99314. y+= *y0;
  99315. x2+= x0 * x0;
  99316. y2+= *y0 * *y0;
  99317. xy+= *y0 * x0;
  99318. an++;
  99319. }
  99320. if(*y1>=0){
  99321. x+= x1;
  99322. y+= *y1;
  99323. x2+= x1 * x1;
  99324. y2+= *y1 * *y1;
  99325. xy+= *y1 * x1;
  99326. an++;
  99327. }
  99328. if(an){
  99329. double fx=x;
  99330. double fy=y;
  99331. double fx2=x2;
  99332. double fxy=xy;
  99333. double denom=1./(an*fx2-fx*fx);
  99334. double a=(fy*fx2-fxy*fx)*denom;
  99335. double b=(an*fxy-fx*fy)*denom;
  99336. *y0=rint(a+b*x0);
  99337. *y1=rint(a+b*x1);
  99338. if(*y0>1023)*y0=1023;
  99339. if(*y1>1023)*y1=1023;
  99340. if(*y0<0)*y0=0;
  99341. if(*y1<0)*y1=0;
  99342. }else{
  99343. *y0=0;
  99344. *y1=0;
  99345. }
  99346. }
  99347. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99348. const float *mdct,
  99349. vorbis_info_floor1 *info){
  99350. int dy=y1-y0;
  99351. int adx=x1-x0;
  99352. int ady=abs(dy);
  99353. int base=dy/adx;
  99354. int sy=(dy<0?base-1:base+1);
  99355. int x=x0;
  99356. int y=y0;
  99357. int err=0;
  99358. int val=vorbis_dBquant(mask+x);
  99359. int mse=0;
  99360. int n=0;
  99361. ady-=abs(base*adx);
  99362. mse=(y-val);
  99363. mse*=mse;
  99364. n++;
  99365. if(mdct[x]+info->twofitatten>=mask[x]){
  99366. if(y+info->maxover<val)return(1);
  99367. if(y-info->maxunder>val)return(1);
  99368. }
  99369. while(++x<x1){
  99370. err=err+ady;
  99371. if(err>=adx){
  99372. err-=adx;
  99373. y+=sy;
  99374. }else{
  99375. y+=base;
  99376. }
  99377. val=vorbis_dBquant(mask+x);
  99378. mse+=((y-val)*(y-val));
  99379. n++;
  99380. if(mdct[x]+info->twofitatten>=mask[x]){
  99381. if(val){
  99382. if(y+info->maxover<val)return(1);
  99383. if(y-info->maxunder>val)return(1);
  99384. }
  99385. }
  99386. }
  99387. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99388. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99389. if(mse/n>info->maxerr)return(1);
  99390. return(0);
  99391. }
  99392. static int post_Y(int *A,int *B,int pos){
  99393. if(A[pos]<0)
  99394. return B[pos];
  99395. if(B[pos]<0)
  99396. return A[pos];
  99397. return (A[pos]+B[pos])>>1;
  99398. }
  99399. int *floor1_fit(vorbis_block *vb,void *look_,
  99400. const float *logmdct, /* in */
  99401. const float *logmask){
  99402. long i,j;
  99403. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99404. vorbis_info_floor1 *info=look->vi;
  99405. long n=look->n;
  99406. long posts=look->posts;
  99407. long nonzero=0;
  99408. lsfit_acc fits[VIF_POSIT+1];
  99409. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99410. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99411. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99412. int hineighbor[VIF_POSIT+2];
  99413. int *output=NULL;
  99414. int memo[VIF_POSIT+2];
  99415. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99416. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99417. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99418. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99419. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99420. if(posts==0){
  99421. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99422. }else{
  99423. for(i=0;i<posts-1;i++)
  99424. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99425. look->sorted_index[i+1],fits+i,
  99426. n,info);
  99427. }
  99428. if(nonzero){
  99429. int y0=-200;
  99430. int y1=-200;
  99431. fit_line(fits,posts-1,&y0,&y1);
  99432. fit_valueA[0]=y0;
  99433. fit_valueB[0]=y0;
  99434. fit_valueB[1]=y1;
  99435. fit_valueA[1]=y1;
  99436. for(i=2;i<posts;i++){
  99437. int sortpos=look->reverse_index[i];
  99438. int ln=loneighbor[sortpos];
  99439. int hn=hineighbor[sortpos];
  99440. if(memo[ln]!=hn){
  99441. int lsortpos=look->reverse_index[ln];
  99442. int hsortpos=look->reverse_index[hn];
  99443. memo[ln]=hn;
  99444. {
  99445. int lx=info->postlist[ln];
  99446. int hx=info->postlist[hn];
  99447. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99448. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99449. if(ly==-1 || hy==-1){
  99450. exit(1);
  99451. }
  99452. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99453. int ly0=-200;
  99454. int ly1=-200;
  99455. int hy0=-200;
  99456. int hy1=-200;
  99457. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99458. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99459. fit_valueB[ln]=ly0;
  99460. if(ln==0)fit_valueA[ln]=ly0;
  99461. fit_valueA[i]=ly1;
  99462. fit_valueB[i]=hy0;
  99463. fit_valueA[hn]=hy1;
  99464. if(hn==1)fit_valueB[hn]=hy1;
  99465. if(ly1>=0 || hy0>=0){
  99466. for(j=sortpos-1;j>=0;j--)
  99467. if(hineighbor[j]==hn)
  99468. hineighbor[j]=i;
  99469. else
  99470. break;
  99471. for(j=sortpos+1;j<posts;j++)
  99472. if(loneighbor[j]==ln)
  99473. loneighbor[j]=i;
  99474. else
  99475. break;
  99476. }
  99477. }else{
  99478. fit_valueA[i]=-200;
  99479. fit_valueB[i]=-200;
  99480. }
  99481. }
  99482. }
  99483. }
  99484. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99485. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99486. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99487. for(i=2;i<posts;i++){
  99488. int ln=look->loneighbor[i-2];
  99489. int hn=look->hineighbor[i-2];
  99490. int x0=info->postlist[ln];
  99491. int x1=info->postlist[hn];
  99492. int y0=output[ln];
  99493. int y1=output[hn];
  99494. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99495. int vx=post_Y(fit_valueA,fit_valueB,i);
  99496. if(vx>=0 && predicted!=vx){
  99497. output[i]=vx;
  99498. }else{
  99499. output[i]= predicted|0x8000;
  99500. }
  99501. }
  99502. }
  99503. return(output);
  99504. }
  99505. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99506. int *A,int *B,
  99507. int del){
  99508. long i;
  99509. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99510. long posts=look->posts;
  99511. int *output=NULL;
  99512. if(A && B){
  99513. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99514. for(i=0;i<posts;i++){
  99515. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99516. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99517. }
  99518. }
  99519. return(output);
  99520. }
  99521. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99522. void*look_,
  99523. int *post,int *ilogmask){
  99524. long i,j;
  99525. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99526. vorbis_info_floor1 *info=look->vi;
  99527. long posts=look->posts;
  99528. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99529. int out[VIF_POSIT+2];
  99530. static_codebook **sbooks=ci->book_param;
  99531. codebook *books=ci->fullbooks;
  99532. static long seq=0;
  99533. if(post){
  99534. for(i=0;i<posts;i++){
  99535. int val=post[i]&0x7fff;
  99536. switch(info->mult){
  99537. case 1: /* 1024 -> 256 */
  99538. val>>=2;
  99539. break;
  99540. case 2: /* 1024 -> 128 */
  99541. val>>=3;
  99542. break;
  99543. case 3: /* 1024 -> 86 */
  99544. val/=12;
  99545. break;
  99546. case 4: /* 1024 -> 64 */
  99547. val>>=4;
  99548. break;
  99549. }
  99550. post[i]=val | (post[i]&0x8000);
  99551. }
  99552. out[0]=post[0];
  99553. out[1]=post[1];
  99554. for(i=2;i<posts;i++){
  99555. int ln=look->loneighbor[i-2];
  99556. int hn=look->hineighbor[i-2];
  99557. int x0=info->postlist[ln];
  99558. int x1=info->postlist[hn];
  99559. int y0=post[ln];
  99560. int y1=post[hn];
  99561. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99562. if((post[i]&0x8000) || (predicted==post[i])){
  99563. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99564. in interpolation */
  99565. out[i]=0;
  99566. }else{
  99567. int headroom=(look->quant_q-predicted<predicted?
  99568. look->quant_q-predicted:predicted);
  99569. int val=post[i]-predicted;
  99570. if(val<0)
  99571. if(val<-headroom)
  99572. val=headroom-val-1;
  99573. else
  99574. val=-1-(val<<1);
  99575. else
  99576. if(val>=headroom)
  99577. val= val+headroom;
  99578. else
  99579. val<<=1;
  99580. out[i]=val;
  99581. post[ln]&=0x7fff;
  99582. post[hn]&=0x7fff;
  99583. }
  99584. }
  99585. oggpack_write(opb,1,1);
  99586. look->frames++;
  99587. look->postbits+=ilog(look->quant_q-1)*2;
  99588. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99589. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99590. for(i=0,j=2;i<info->partitions;i++){
  99591. int classx=info->partitionclass[i];
  99592. int cdim=info->class_dim[classx];
  99593. int csubbits=info->class_subs[classx];
  99594. int csub=1<<csubbits;
  99595. int bookas[8]={0,0,0,0,0,0,0,0};
  99596. int cval=0;
  99597. int cshift=0;
  99598. int k,l;
  99599. if(csubbits){
  99600. int maxval[8];
  99601. for(k=0;k<csub;k++){
  99602. int booknum=info->class_subbook[classx][k];
  99603. if(booknum<0){
  99604. maxval[k]=1;
  99605. }else{
  99606. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99607. }
  99608. }
  99609. for(k=0;k<cdim;k++){
  99610. for(l=0;l<csub;l++){
  99611. int val=out[j+k];
  99612. if(val<maxval[l]){
  99613. bookas[k]=l;
  99614. break;
  99615. }
  99616. }
  99617. cval|= bookas[k]<<cshift;
  99618. cshift+=csubbits;
  99619. }
  99620. look->phrasebits+=
  99621. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99622. #ifdef TRAIN_FLOOR1
  99623. {
  99624. FILE *of;
  99625. char buffer[80];
  99626. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99627. vb->pcmend/2,posts-2,class);
  99628. of=fopen(buffer,"a");
  99629. fprintf(of,"%d\n",cval);
  99630. fclose(of);
  99631. }
  99632. #endif
  99633. }
  99634. for(k=0;k<cdim;k++){
  99635. int book=info->class_subbook[classx][bookas[k]];
  99636. if(book>=0){
  99637. if(out[j+k]<(books+book)->entries)
  99638. look->postbits+=vorbis_book_encode(books+book,
  99639. out[j+k],opb);
  99640. #ifdef TRAIN_FLOOR1
  99641. {
  99642. FILE *of;
  99643. char buffer[80];
  99644. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99645. vb->pcmend/2,posts-2,class,bookas[k]);
  99646. of=fopen(buffer,"a");
  99647. fprintf(of,"%d\n",out[j+k]);
  99648. fclose(of);
  99649. }
  99650. #endif
  99651. }
  99652. }
  99653. j+=cdim;
  99654. }
  99655. {
  99656. int hx=0;
  99657. int lx=0;
  99658. int ly=post[0]*info->mult;
  99659. for(j=1;j<look->posts;j++){
  99660. int current=look->forward_index[j];
  99661. int hy=post[current]&0x7fff;
  99662. if(hy==post[current]){
  99663. hy*=info->mult;
  99664. hx=info->postlist[current];
  99665. render_line0(lx,hx,ly,hy,ilogmask);
  99666. lx=hx;
  99667. ly=hy;
  99668. }
  99669. }
  99670. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99671. seq++;
  99672. return(1);
  99673. }
  99674. }else{
  99675. oggpack_write(opb,0,1);
  99676. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99677. seq++;
  99678. return(0);
  99679. }
  99680. }
  99681. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99682. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99683. vorbis_info_floor1 *info=look->vi;
  99684. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99685. int i,j,k;
  99686. codebook *books=ci->fullbooks;
  99687. if(oggpack_read(&vb->opb,1)==1){
  99688. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99689. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99690. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99691. for(i=0,j=2;i<info->partitions;i++){
  99692. int classx=info->partitionclass[i];
  99693. int cdim=info->class_dim[classx];
  99694. int csubbits=info->class_subs[classx];
  99695. int csub=1<<csubbits;
  99696. int cval=0;
  99697. if(csubbits){
  99698. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99699. if(cval==-1)goto eop;
  99700. }
  99701. for(k=0;k<cdim;k++){
  99702. int book=info->class_subbook[classx][cval&(csub-1)];
  99703. cval>>=csubbits;
  99704. if(book>=0){
  99705. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99706. goto eop;
  99707. }else{
  99708. fit_value[j+k]=0;
  99709. }
  99710. }
  99711. j+=cdim;
  99712. }
  99713. for(i=2;i<look->posts;i++){
  99714. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99715. info->postlist[look->hineighbor[i-2]],
  99716. fit_value[look->loneighbor[i-2]],
  99717. fit_value[look->hineighbor[i-2]],
  99718. info->postlist[i]);
  99719. int hiroom=look->quant_q-predicted;
  99720. int loroom=predicted;
  99721. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99722. int val=fit_value[i];
  99723. if(val){
  99724. if(val>=room){
  99725. if(hiroom>loroom){
  99726. val = val-loroom;
  99727. }else{
  99728. val = -1-(val-hiroom);
  99729. }
  99730. }else{
  99731. if(val&1){
  99732. val= -((val+1)>>1);
  99733. }else{
  99734. val>>=1;
  99735. }
  99736. }
  99737. fit_value[i]=val+predicted;
  99738. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99739. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99740. }else{
  99741. fit_value[i]=predicted|0x8000;
  99742. }
  99743. }
  99744. return(fit_value);
  99745. }
  99746. eop:
  99747. return(NULL);
  99748. }
  99749. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99750. float *out){
  99751. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99752. vorbis_info_floor1 *info=look->vi;
  99753. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99754. int n=ci->blocksizes[vb->W]/2;
  99755. int j;
  99756. if(memo){
  99757. int *fit_value=(int *)memo;
  99758. int hx=0;
  99759. int lx=0;
  99760. int ly=fit_value[0]*info->mult;
  99761. for(j=1;j<look->posts;j++){
  99762. int current=look->forward_index[j];
  99763. int hy=fit_value[current]&0x7fff;
  99764. if(hy==fit_value[current]){
  99765. hy*=info->mult;
  99766. hx=info->postlist[current];
  99767. render_line(lx,hx,ly,hy,out);
  99768. lx=hx;
  99769. ly=hy;
  99770. }
  99771. }
  99772. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99773. return(1);
  99774. }
  99775. memset(out,0,sizeof(*out)*n);
  99776. return(0);
  99777. }
  99778. vorbis_func_floor floor1_exportbundle={
  99779. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99780. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99781. };
  99782. #endif
  99783. /*** End of inlined file: floor1.c ***/
  99784. /*** Start of inlined file: info.c ***/
  99785. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99786. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99787. // tasks..
  99788. #if JUCE_MSVC
  99789. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99790. #endif
  99791. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99792. #if JUCE_USE_OGGVORBIS
  99793. #include <stdlib.h>
  99794. #include <string.h>
  99795. #include <ctype.h>
  99796. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99797. while(bytes--){
  99798. oggpack_write(o,*s++,8);
  99799. }
  99800. }
  99801. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99802. while(bytes--){
  99803. *buf++=oggpack_read(o,8);
  99804. }
  99805. }
  99806. void vorbis_comment_init(vorbis_comment *vc){
  99807. memset(vc,0,sizeof(*vc));
  99808. }
  99809. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  99810. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  99811. (vc->comments+2)*sizeof(*vc->user_comments));
  99812. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  99813. (vc->comments+2)*sizeof(*vc->comment_lengths));
  99814. vc->comment_lengths[vc->comments]=strlen(comment);
  99815. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  99816. strcpy(vc->user_comments[vc->comments], comment);
  99817. vc->comments++;
  99818. vc->user_comments[vc->comments]=NULL;
  99819. }
  99820. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  99821. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  99822. strcpy(comment, tag);
  99823. strcat(comment, "=");
  99824. strcat(comment, contents);
  99825. vorbis_comment_add(vc, comment);
  99826. }
  99827. static int tagcompare(const char *s1, const char *s2, int n){
  99828. int c=0;
  99829. while(c < n){
  99830. if(toupper(s1[c]) != toupper(s2[c]))
  99831. return !0;
  99832. c++;
  99833. }
  99834. return 0;
  99835. }
  99836. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  99837. long i;
  99838. int found = 0;
  99839. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99840. char *fulltag = (char*)alloca(taglen+ 1);
  99841. strcpy(fulltag, tag);
  99842. strcat(fulltag, "=");
  99843. for(i=0;i<vc->comments;i++){
  99844. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  99845. if(count == found)
  99846. return vc->user_comments[i] + taglen;
  99847. else
  99848. found++;
  99849. }
  99850. }
  99851. return NULL; /* didn't find anything */
  99852. }
  99853. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  99854. int i,count=0;
  99855. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99856. char *fulltag = (char*)alloca(taglen+1);
  99857. strcpy(fulltag,tag);
  99858. strcat(fulltag, "=");
  99859. for(i=0;i<vc->comments;i++){
  99860. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  99861. count++;
  99862. }
  99863. return count;
  99864. }
  99865. void vorbis_comment_clear(vorbis_comment *vc){
  99866. if(vc){
  99867. long i;
  99868. for(i=0;i<vc->comments;i++)
  99869. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  99870. if(vc->user_comments)_ogg_free(vc->user_comments);
  99871. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  99872. if(vc->vendor)_ogg_free(vc->vendor);
  99873. }
  99874. memset(vc,0,sizeof(*vc));
  99875. }
  99876. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  99877. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  99878. return ci ? ci->blocksizes[zo] : -1;
  99879. }
  99880. void vorbis_info_init(vorbis_info *vi){
  99881. memset(vi,0,sizeof(*vi));
  99882. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  99883. }
  99884. void vorbis_info_clear(vorbis_info *vi){
  99885. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99886. int i;
  99887. if(ci){
  99888. for(i=0;i<ci->modes;i++)
  99889. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  99890. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  99891. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  99892. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  99893. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  99894. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  99895. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  99896. for(i=0;i<ci->books;i++){
  99897. if(ci->book_param[i]){
  99898. vorbis_staticbook_destroy(ci->book_param[i]);
  99899. }
  99900. if(ci->fullbooks)
  99901. vorbis_book_clear(ci->fullbooks+i);
  99902. }
  99903. if(ci->fullbooks)
  99904. _ogg_free(ci->fullbooks);
  99905. for(i=0;i<ci->psys;i++)
  99906. _vi_psy_free(ci->psy_param[i]);
  99907. _ogg_free(ci);
  99908. }
  99909. memset(vi,0,sizeof(*vi));
  99910. }
  99911. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  99912. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99913. if(!ci)return(OV_EFAULT);
  99914. vi->version=oggpack_read(opb,32);
  99915. if(vi->version!=0)return(OV_EVERSION);
  99916. vi->channels=oggpack_read(opb,8);
  99917. vi->rate=oggpack_read(opb,32);
  99918. vi->bitrate_upper=oggpack_read(opb,32);
  99919. vi->bitrate_nominal=oggpack_read(opb,32);
  99920. vi->bitrate_lower=oggpack_read(opb,32);
  99921. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  99922. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  99923. if(vi->rate<1)goto err_out;
  99924. if(vi->channels<1)goto err_out;
  99925. if(ci->blocksizes[0]<8)goto err_out;
  99926. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  99927. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  99928. return(0);
  99929. err_out:
  99930. vorbis_info_clear(vi);
  99931. return(OV_EBADHEADER);
  99932. }
  99933. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  99934. int i;
  99935. int vendorlen=oggpack_read(opb,32);
  99936. if(vendorlen<0)goto err_out;
  99937. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  99938. _v_readstring(opb,vc->vendor,vendorlen);
  99939. vc->comments=oggpack_read(opb,32);
  99940. if(vc->comments<0)goto err_out;
  99941. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  99942. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  99943. for(i=0;i<vc->comments;i++){
  99944. int len=oggpack_read(opb,32);
  99945. if(len<0)goto err_out;
  99946. vc->comment_lengths[i]=len;
  99947. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  99948. _v_readstring(opb,vc->user_comments[i],len);
  99949. }
  99950. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  99951. return(0);
  99952. err_out:
  99953. vorbis_comment_clear(vc);
  99954. return(OV_EBADHEADER);
  99955. }
  99956. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  99957. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99958. int i;
  99959. if(!ci)return(OV_EFAULT);
  99960. ci->books=oggpack_read(opb,8)+1;
  99961. for(i=0;i<ci->books;i++){
  99962. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  99963. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  99964. }
  99965. {
  99966. int times=oggpack_read(opb,6)+1;
  99967. for(i=0;i<times;i++){
  99968. int test=oggpack_read(opb,16);
  99969. if(test<0 || test>=VI_TIMEB)goto err_out;
  99970. }
  99971. }
  99972. ci->floors=oggpack_read(opb,6)+1;
  99973. for(i=0;i<ci->floors;i++){
  99974. ci->floor_type[i]=oggpack_read(opb,16);
  99975. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  99976. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  99977. if(!ci->floor_param[i])goto err_out;
  99978. }
  99979. ci->residues=oggpack_read(opb,6)+1;
  99980. for(i=0;i<ci->residues;i++){
  99981. ci->residue_type[i]=oggpack_read(opb,16);
  99982. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  99983. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  99984. if(!ci->residue_param[i])goto err_out;
  99985. }
  99986. ci->maps=oggpack_read(opb,6)+1;
  99987. for(i=0;i<ci->maps;i++){
  99988. ci->map_type[i]=oggpack_read(opb,16);
  99989. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  99990. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  99991. if(!ci->map_param[i])goto err_out;
  99992. }
  99993. ci->modes=oggpack_read(opb,6)+1;
  99994. for(i=0;i<ci->modes;i++){
  99995. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  99996. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  99997. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  99998. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  99999. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100000. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100001. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100002. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100003. }
  100004. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100005. return(0);
  100006. err_out:
  100007. vorbis_info_clear(vi);
  100008. return(OV_EBADHEADER);
  100009. }
  100010. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100011. oggpack_buffer opb;
  100012. if(op){
  100013. oggpack_readinit(&opb,op->packet,op->bytes);
  100014. {
  100015. char buffer[6];
  100016. int packtype=oggpack_read(&opb,8);
  100017. memset(buffer,0,6);
  100018. _v_readstring(&opb,buffer,6);
  100019. if(memcmp(buffer,"vorbis",6)){
  100020. return(OV_ENOTVORBIS);
  100021. }
  100022. switch(packtype){
  100023. case 0x01: /* least significant *bit* is read first */
  100024. if(!op->b_o_s){
  100025. return(OV_EBADHEADER);
  100026. }
  100027. if(vi->rate!=0){
  100028. return(OV_EBADHEADER);
  100029. }
  100030. return(_vorbis_unpack_info(vi,&opb));
  100031. case 0x03: /* least significant *bit* is read first */
  100032. if(vi->rate==0){
  100033. return(OV_EBADHEADER);
  100034. }
  100035. return(_vorbis_unpack_comment(vc,&opb));
  100036. case 0x05: /* least significant *bit* is read first */
  100037. if(vi->rate==0 || vc->vendor==NULL){
  100038. return(OV_EBADHEADER);
  100039. }
  100040. return(_vorbis_unpack_books(vi,&opb));
  100041. default:
  100042. return(OV_EBADHEADER);
  100043. break;
  100044. }
  100045. }
  100046. }
  100047. return(OV_EBADHEADER);
  100048. }
  100049. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100050. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100051. if(!ci)return(OV_EFAULT);
  100052. oggpack_write(opb,0x01,8);
  100053. _v_writestring(opb,"vorbis", 6);
  100054. oggpack_write(opb,0x00,32);
  100055. oggpack_write(opb,vi->channels,8);
  100056. oggpack_write(opb,vi->rate,32);
  100057. oggpack_write(opb,vi->bitrate_upper,32);
  100058. oggpack_write(opb,vi->bitrate_nominal,32);
  100059. oggpack_write(opb,vi->bitrate_lower,32);
  100060. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100061. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100062. oggpack_write(opb,1,1);
  100063. return(0);
  100064. }
  100065. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100066. char temp[]="Xiph.Org libVorbis I 20050304";
  100067. int bytes = strlen(temp);
  100068. oggpack_write(opb,0x03,8);
  100069. _v_writestring(opb,"vorbis", 6);
  100070. oggpack_write(opb,bytes,32);
  100071. _v_writestring(opb,temp, bytes);
  100072. oggpack_write(opb,vc->comments,32);
  100073. if(vc->comments){
  100074. int i;
  100075. for(i=0;i<vc->comments;i++){
  100076. if(vc->user_comments[i]){
  100077. oggpack_write(opb,vc->comment_lengths[i],32);
  100078. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100079. }else{
  100080. oggpack_write(opb,0,32);
  100081. }
  100082. }
  100083. }
  100084. oggpack_write(opb,1,1);
  100085. return(0);
  100086. }
  100087. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100088. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100089. int i;
  100090. if(!ci)return(OV_EFAULT);
  100091. oggpack_write(opb,0x05,8);
  100092. _v_writestring(opb,"vorbis", 6);
  100093. oggpack_write(opb,ci->books-1,8);
  100094. for(i=0;i<ci->books;i++)
  100095. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100096. oggpack_write(opb,0,6);
  100097. oggpack_write(opb,0,16);
  100098. oggpack_write(opb,ci->floors-1,6);
  100099. for(i=0;i<ci->floors;i++){
  100100. oggpack_write(opb,ci->floor_type[i],16);
  100101. if(_floor_P[ci->floor_type[i]]->pack)
  100102. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100103. else
  100104. goto err_out;
  100105. }
  100106. oggpack_write(opb,ci->residues-1,6);
  100107. for(i=0;i<ci->residues;i++){
  100108. oggpack_write(opb,ci->residue_type[i],16);
  100109. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100110. }
  100111. oggpack_write(opb,ci->maps-1,6);
  100112. for(i=0;i<ci->maps;i++){
  100113. oggpack_write(opb,ci->map_type[i],16);
  100114. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100115. }
  100116. oggpack_write(opb,ci->modes-1,6);
  100117. for(i=0;i<ci->modes;i++){
  100118. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100119. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100120. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100121. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100122. }
  100123. oggpack_write(opb,1,1);
  100124. return(0);
  100125. err_out:
  100126. return(-1);
  100127. }
  100128. int vorbis_commentheader_out(vorbis_comment *vc,
  100129. ogg_packet *op){
  100130. oggpack_buffer opb;
  100131. oggpack_writeinit(&opb);
  100132. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100133. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100134. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100135. op->bytes=oggpack_bytes(&opb);
  100136. op->b_o_s=0;
  100137. op->e_o_s=0;
  100138. op->granulepos=0;
  100139. op->packetno=1;
  100140. return 0;
  100141. }
  100142. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100143. vorbis_comment *vc,
  100144. ogg_packet *op,
  100145. ogg_packet *op_comm,
  100146. ogg_packet *op_code){
  100147. int ret=OV_EIMPL;
  100148. vorbis_info *vi=v->vi;
  100149. oggpack_buffer opb;
  100150. private_state *b=(private_state*)v->backend_state;
  100151. if(!b){
  100152. ret=OV_EFAULT;
  100153. goto err_out;
  100154. }
  100155. oggpack_writeinit(&opb);
  100156. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100157. if(b->header)_ogg_free(b->header);
  100158. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100159. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100160. op->packet=b->header;
  100161. op->bytes=oggpack_bytes(&opb);
  100162. op->b_o_s=1;
  100163. op->e_o_s=0;
  100164. op->granulepos=0;
  100165. op->packetno=0;
  100166. oggpack_reset(&opb);
  100167. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100168. if(b->header1)_ogg_free(b->header1);
  100169. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100170. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100171. op_comm->packet=b->header1;
  100172. op_comm->bytes=oggpack_bytes(&opb);
  100173. op_comm->b_o_s=0;
  100174. op_comm->e_o_s=0;
  100175. op_comm->granulepos=0;
  100176. op_comm->packetno=1;
  100177. oggpack_reset(&opb);
  100178. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100179. if(b->header2)_ogg_free(b->header2);
  100180. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100181. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100182. op_code->packet=b->header2;
  100183. op_code->bytes=oggpack_bytes(&opb);
  100184. op_code->b_o_s=0;
  100185. op_code->e_o_s=0;
  100186. op_code->granulepos=0;
  100187. op_code->packetno=2;
  100188. oggpack_writeclear(&opb);
  100189. return(0);
  100190. err_out:
  100191. oggpack_writeclear(&opb);
  100192. memset(op,0,sizeof(*op));
  100193. memset(op_comm,0,sizeof(*op_comm));
  100194. memset(op_code,0,sizeof(*op_code));
  100195. if(b->header)_ogg_free(b->header);
  100196. if(b->header1)_ogg_free(b->header1);
  100197. if(b->header2)_ogg_free(b->header2);
  100198. b->header=NULL;
  100199. b->header1=NULL;
  100200. b->header2=NULL;
  100201. return(ret);
  100202. }
  100203. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100204. if(granulepos>=0)
  100205. return((double)granulepos/v->vi->rate);
  100206. return(-1);
  100207. }
  100208. #endif
  100209. /*** End of inlined file: info.c ***/
  100210. /*** Start of inlined file: lpc.c ***/
  100211. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100212. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100213. // tasks..
  100214. #if JUCE_MSVC
  100215. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100216. #endif
  100217. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100218. #if JUCE_USE_OGGVORBIS
  100219. #include <stdlib.h>
  100220. #include <string.h>
  100221. #include <math.h>
  100222. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100223. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100224. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100225. double error;
  100226. int i,j;
  100227. j=m+1;
  100228. while(j--){
  100229. double d=0; /* double needed for accumulator depth */
  100230. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100231. aut[j]=d;
  100232. }
  100233. error=aut[0];
  100234. for(i=0;i<m;i++){
  100235. double r= -aut[i+1];
  100236. if(error==0){
  100237. memset(lpci,0,m*sizeof(*lpci));
  100238. return 0;
  100239. }
  100240. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100241. r/=error;
  100242. lpc[i]=r;
  100243. for(j=0;j<i/2;j++){
  100244. double tmp=lpc[j];
  100245. lpc[j]+=r*lpc[i-1-j];
  100246. lpc[i-1-j]+=r*tmp;
  100247. }
  100248. if(i%2)lpc[j]+=lpc[j]*r;
  100249. error*=1.f-r*r;
  100250. }
  100251. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100252. return error;
  100253. }
  100254. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100255. float *data,long n){
  100256. long i,j,o,p;
  100257. float y;
  100258. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100259. if(!prime)
  100260. for(i=0;i<m;i++)
  100261. work[i]=0.f;
  100262. else
  100263. for(i=0;i<m;i++)
  100264. work[i]=prime[i];
  100265. for(i=0;i<n;i++){
  100266. y=0;
  100267. o=i;
  100268. p=m;
  100269. for(j=0;j<m;j++)
  100270. y-=work[o++]*coeff[--p];
  100271. data[i]=work[o]=y;
  100272. }
  100273. }
  100274. #endif
  100275. /*** End of inlined file: lpc.c ***/
  100276. /*** Start of inlined file: lsp.c ***/
  100277. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100278. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100279. // tasks..
  100280. #if JUCE_MSVC
  100281. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100282. #endif
  100283. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100284. #if JUCE_USE_OGGVORBIS
  100285. #include <math.h>
  100286. #include <string.h>
  100287. #include <stdlib.h>
  100288. /*** Start of inlined file: lookup.h ***/
  100289. #ifndef _V_LOOKUP_H_
  100290. #ifdef FLOAT_LOOKUP
  100291. extern float vorbis_coslook(float a);
  100292. extern float vorbis_invsqlook(float a);
  100293. extern float vorbis_invsq2explook(int a);
  100294. extern float vorbis_fromdBlook(float a);
  100295. #endif
  100296. #ifdef INT_LOOKUP
  100297. extern long vorbis_invsqlook_i(long a,long e);
  100298. extern long vorbis_coslook_i(long a);
  100299. extern float vorbis_fromdBlook_i(long a);
  100300. #endif
  100301. #endif
  100302. /*** End of inlined file: lookup.h ***/
  100303. #define FLOAT_LOOKUP
  100304. #undef INT_LOOKUP
  100305. #ifdef FLOAT_LOOKUP
  100306. /*** Start of inlined file: lookup.c ***/
  100307. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100308. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100309. // tasks..
  100310. #if JUCE_MSVC
  100311. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100312. #endif
  100313. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100314. #if JUCE_USE_OGGVORBIS
  100315. #include <math.h>
  100316. /*** Start of inlined file: lookup.h ***/
  100317. #ifndef _V_LOOKUP_H_
  100318. #ifdef FLOAT_LOOKUP
  100319. extern float vorbis_coslook(float a);
  100320. extern float vorbis_invsqlook(float a);
  100321. extern float vorbis_invsq2explook(int a);
  100322. extern float vorbis_fromdBlook(float a);
  100323. #endif
  100324. #ifdef INT_LOOKUP
  100325. extern long vorbis_invsqlook_i(long a,long e);
  100326. extern long vorbis_coslook_i(long a);
  100327. extern float vorbis_fromdBlook_i(long a);
  100328. #endif
  100329. #endif
  100330. /*** End of inlined file: lookup.h ***/
  100331. /*** Start of inlined file: lookup_data.h ***/
  100332. #ifndef _V_LOOKUP_DATA_H_
  100333. #ifdef FLOAT_LOOKUP
  100334. #define COS_LOOKUP_SZ 128
  100335. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100336. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100337. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100338. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100339. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100340. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100341. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100342. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100343. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100344. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100345. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100346. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100347. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100348. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100349. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100350. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100351. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100352. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100353. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100354. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100355. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100356. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100357. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100358. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100359. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100360. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100361. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100362. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100363. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100364. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100365. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100366. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100367. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100368. -1.0000000000000f,
  100369. };
  100370. #define INVSQ_LOOKUP_SZ 32
  100371. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100372. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100373. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100374. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100375. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100376. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100377. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100378. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100379. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100380. 1.000000000000f,
  100381. };
  100382. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100383. #define INVSQ2EXP_LOOKUP_MAX 32
  100384. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100385. INVSQ2EXP_LOOKUP_MIN+1]={
  100386. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100387. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100388. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100389. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100390. 256.f, 181.019336f, 128.f, 90.50966799f,
  100391. 64.f, 45.254834f, 32.f, 22.627417f,
  100392. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100393. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100394. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100395. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100396. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100397. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100398. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100399. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100400. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100401. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100402. 1.525878906e-05f,
  100403. };
  100404. #endif
  100405. #define FROMdB_LOOKUP_SZ 35
  100406. #define FROMdB2_LOOKUP_SZ 32
  100407. #define FROMdB_SHIFT 5
  100408. #define FROMdB2_SHIFT 3
  100409. #define FROMdB2_MASK 31
  100410. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100411. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100412. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100413. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100414. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100415. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100416. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100417. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100418. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100419. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100420. };
  100421. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100422. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100423. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100424. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100425. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100426. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100427. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100428. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100429. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100430. };
  100431. #ifdef INT_LOOKUP
  100432. #define INVSQ_LOOKUP_I_SHIFT 10
  100433. #define INVSQ_LOOKUP_I_MASK 1023
  100434. static long INVSQ_LOOKUP_I[64+1]={
  100435. 92682l, 91966l, 91267l, 90583l,
  100436. 89915l, 89261l, 88621l, 87995l,
  100437. 87381l, 86781l, 86192l, 85616l,
  100438. 85051l, 84497l, 83953l, 83420l,
  100439. 82897l, 82384l, 81880l, 81385l,
  100440. 80899l, 80422l, 79953l, 79492l,
  100441. 79039l, 78594l, 78156l, 77726l,
  100442. 77302l, 76885l, 76475l, 76072l,
  100443. 75674l, 75283l, 74898l, 74519l,
  100444. 74146l, 73778l, 73415l, 73058l,
  100445. 72706l, 72359l, 72016l, 71679l,
  100446. 71347l, 71019l, 70695l, 70376l,
  100447. 70061l, 69750l, 69444l, 69141l,
  100448. 68842l, 68548l, 68256l, 67969l,
  100449. 67685l, 67405l, 67128l, 66855l,
  100450. 66585l, 66318l, 66054l, 65794l,
  100451. 65536l,
  100452. };
  100453. #define COS_LOOKUP_I_SHIFT 9
  100454. #define COS_LOOKUP_I_MASK 511
  100455. #define COS_LOOKUP_I_SZ 128
  100456. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100457. 16384l, 16379l, 16364l, 16340l,
  100458. 16305l, 16261l, 16207l, 16143l,
  100459. 16069l, 15986l, 15893l, 15791l,
  100460. 15679l, 15557l, 15426l, 15286l,
  100461. 15137l, 14978l, 14811l, 14635l,
  100462. 14449l, 14256l, 14053l, 13842l,
  100463. 13623l, 13395l, 13160l, 12916l,
  100464. 12665l, 12406l, 12140l, 11866l,
  100465. 11585l, 11297l, 11003l, 10702l,
  100466. 10394l, 10080l, 9760l, 9434l,
  100467. 9102l, 8765l, 8423l, 8076l,
  100468. 7723l, 7366l, 7005l, 6639l,
  100469. 6270l, 5897l, 5520l, 5139l,
  100470. 4756l, 4370l, 3981l, 3590l,
  100471. 3196l, 2801l, 2404l, 2006l,
  100472. 1606l, 1205l, 804l, 402l,
  100473. 0l, -401l, -803l, -1204l,
  100474. -1605l, -2005l, -2403l, -2800l,
  100475. -3195l, -3589l, -3980l, -4369l,
  100476. -4755l, -5138l, -5519l, -5896l,
  100477. -6269l, -6638l, -7004l, -7365l,
  100478. -7722l, -8075l, -8422l, -8764l,
  100479. -9101l, -9433l, -9759l, -10079l,
  100480. -10393l, -10701l, -11002l, -11296l,
  100481. -11584l, -11865l, -12139l, -12405l,
  100482. -12664l, -12915l, -13159l, -13394l,
  100483. -13622l, -13841l, -14052l, -14255l,
  100484. -14448l, -14634l, -14810l, -14977l,
  100485. -15136l, -15285l, -15425l, -15556l,
  100486. -15678l, -15790l, -15892l, -15985l,
  100487. -16068l, -16142l, -16206l, -16260l,
  100488. -16304l, -16339l, -16363l, -16378l,
  100489. -16383l,
  100490. };
  100491. #endif
  100492. #endif
  100493. /*** End of inlined file: lookup_data.h ***/
  100494. #ifdef FLOAT_LOOKUP
  100495. float vorbis_coslook(float a){
  100496. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100497. int i=vorbis_ftoi(d-.5);
  100498. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100499. }
  100500. float vorbis_invsqlook(float a){
  100501. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100502. int i=vorbis_ftoi(d-.5f);
  100503. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100504. }
  100505. float vorbis_invsq2explook(int a){
  100506. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100507. }
  100508. #include <stdio.h>
  100509. float vorbis_fromdBlook(float a){
  100510. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100511. return (i<0)?1.f:
  100512. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100513. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100514. }
  100515. #endif
  100516. #ifdef INT_LOOKUP
  100517. long vorbis_invsqlook_i(long a,long e){
  100518. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100519. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100520. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100521. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100522. d)>>16); /* result 1.16 */
  100523. e+=32;
  100524. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100525. e=(e>>1)-8;
  100526. return(val>>e);
  100527. }
  100528. float vorbis_fromdBlook_i(long a){
  100529. int i=(-a)>>(12-FROMdB2_SHIFT);
  100530. return (i<0)?1.f:
  100531. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100532. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100533. }
  100534. long vorbis_coslook_i(long a){
  100535. int i=a>>COS_LOOKUP_I_SHIFT;
  100536. int d=a&COS_LOOKUP_I_MASK;
  100537. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100538. COS_LOOKUP_I_SHIFT);
  100539. }
  100540. #endif
  100541. #endif
  100542. /*** End of inlined file: lookup.c ***/
  100543. /* catch this in the build system; we #include for
  100544. compilers (like gcc) that can't inline across
  100545. modules */
  100546. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100547. float amp,float ampoffset){
  100548. int i;
  100549. float wdel=M_PI/ln;
  100550. vorbis_fpu_control fpu;
  100551. (void) fpu; // to avoid an unused variable warning
  100552. vorbis_fpu_setround(&fpu);
  100553. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100554. i=0;
  100555. while(i<n){
  100556. int k=map[i];
  100557. int qexp;
  100558. float p=.7071067812f;
  100559. float q=.7071067812f;
  100560. float w=vorbis_coslook(wdel*k);
  100561. float *ftmp=lsp;
  100562. int c=m>>1;
  100563. do{
  100564. q*=ftmp[0]-w;
  100565. p*=ftmp[1]-w;
  100566. ftmp+=2;
  100567. }while(--c);
  100568. if(m&1){
  100569. q*=ftmp[0]-w;
  100570. q*=q;
  100571. p*=p*(1.f-w*w);
  100572. }else{
  100573. q*=q*(1.f+w);
  100574. p*=p*(1.f-w);
  100575. }
  100576. q=frexp(p+q,&qexp);
  100577. q=vorbis_fromdBlook(amp*
  100578. vorbis_invsqlook(q)*
  100579. vorbis_invsq2explook(qexp+m)-
  100580. ampoffset);
  100581. do{
  100582. curve[i++]*=q;
  100583. }while(map[i]==k);
  100584. }
  100585. vorbis_fpu_restore(fpu);
  100586. }
  100587. #else
  100588. #ifdef INT_LOOKUP
  100589. /*** Start of inlined file: lookup.c ***/
  100590. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100591. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100592. // tasks..
  100593. #if JUCE_MSVC
  100594. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100595. #endif
  100596. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100597. #if JUCE_USE_OGGVORBIS
  100598. #include <math.h>
  100599. /*** Start of inlined file: lookup.h ***/
  100600. #ifndef _V_LOOKUP_H_
  100601. #ifdef FLOAT_LOOKUP
  100602. extern float vorbis_coslook(float a);
  100603. extern float vorbis_invsqlook(float a);
  100604. extern float vorbis_invsq2explook(int a);
  100605. extern float vorbis_fromdBlook(float a);
  100606. #endif
  100607. #ifdef INT_LOOKUP
  100608. extern long vorbis_invsqlook_i(long a,long e);
  100609. extern long vorbis_coslook_i(long a);
  100610. extern float vorbis_fromdBlook_i(long a);
  100611. #endif
  100612. #endif
  100613. /*** End of inlined file: lookup.h ***/
  100614. /*** Start of inlined file: lookup_data.h ***/
  100615. #ifndef _V_LOOKUP_DATA_H_
  100616. #ifdef FLOAT_LOOKUP
  100617. #define COS_LOOKUP_SZ 128
  100618. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100619. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100620. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100621. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100622. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100623. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100624. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100625. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100626. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100627. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100628. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100629. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100630. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100631. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100632. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100633. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100634. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100635. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100636. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100637. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100638. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100639. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100640. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100641. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100642. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100643. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100644. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100645. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100646. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100647. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100648. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100649. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100650. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100651. -1.0000000000000f,
  100652. };
  100653. #define INVSQ_LOOKUP_SZ 32
  100654. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100655. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100656. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100657. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100658. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100659. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100660. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100661. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100662. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100663. 1.000000000000f,
  100664. };
  100665. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100666. #define INVSQ2EXP_LOOKUP_MAX 32
  100667. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100668. INVSQ2EXP_LOOKUP_MIN+1]={
  100669. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100670. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100671. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100672. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100673. 256.f, 181.019336f, 128.f, 90.50966799f,
  100674. 64.f, 45.254834f, 32.f, 22.627417f,
  100675. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100676. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100677. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100678. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100679. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100680. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100681. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100682. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100683. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100684. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100685. 1.525878906e-05f,
  100686. };
  100687. #endif
  100688. #define FROMdB_LOOKUP_SZ 35
  100689. #define FROMdB2_LOOKUP_SZ 32
  100690. #define FROMdB_SHIFT 5
  100691. #define FROMdB2_SHIFT 3
  100692. #define FROMdB2_MASK 31
  100693. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100694. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100695. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100696. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100697. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100698. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100699. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100700. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100701. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100702. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100703. };
  100704. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100705. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100706. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100707. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100708. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100709. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100710. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100711. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100712. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100713. };
  100714. #ifdef INT_LOOKUP
  100715. #define INVSQ_LOOKUP_I_SHIFT 10
  100716. #define INVSQ_LOOKUP_I_MASK 1023
  100717. static long INVSQ_LOOKUP_I[64+1]={
  100718. 92682l, 91966l, 91267l, 90583l,
  100719. 89915l, 89261l, 88621l, 87995l,
  100720. 87381l, 86781l, 86192l, 85616l,
  100721. 85051l, 84497l, 83953l, 83420l,
  100722. 82897l, 82384l, 81880l, 81385l,
  100723. 80899l, 80422l, 79953l, 79492l,
  100724. 79039l, 78594l, 78156l, 77726l,
  100725. 77302l, 76885l, 76475l, 76072l,
  100726. 75674l, 75283l, 74898l, 74519l,
  100727. 74146l, 73778l, 73415l, 73058l,
  100728. 72706l, 72359l, 72016l, 71679l,
  100729. 71347l, 71019l, 70695l, 70376l,
  100730. 70061l, 69750l, 69444l, 69141l,
  100731. 68842l, 68548l, 68256l, 67969l,
  100732. 67685l, 67405l, 67128l, 66855l,
  100733. 66585l, 66318l, 66054l, 65794l,
  100734. 65536l,
  100735. };
  100736. #define COS_LOOKUP_I_SHIFT 9
  100737. #define COS_LOOKUP_I_MASK 511
  100738. #define COS_LOOKUP_I_SZ 128
  100739. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100740. 16384l, 16379l, 16364l, 16340l,
  100741. 16305l, 16261l, 16207l, 16143l,
  100742. 16069l, 15986l, 15893l, 15791l,
  100743. 15679l, 15557l, 15426l, 15286l,
  100744. 15137l, 14978l, 14811l, 14635l,
  100745. 14449l, 14256l, 14053l, 13842l,
  100746. 13623l, 13395l, 13160l, 12916l,
  100747. 12665l, 12406l, 12140l, 11866l,
  100748. 11585l, 11297l, 11003l, 10702l,
  100749. 10394l, 10080l, 9760l, 9434l,
  100750. 9102l, 8765l, 8423l, 8076l,
  100751. 7723l, 7366l, 7005l, 6639l,
  100752. 6270l, 5897l, 5520l, 5139l,
  100753. 4756l, 4370l, 3981l, 3590l,
  100754. 3196l, 2801l, 2404l, 2006l,
  100755. 1606l, 1205l, 804l, 402l,
  100756. 0l, -401l, -803l, -1204l,
  100757. -1605l, -2005l, -2403l, -2800l,
  100758. -3195l, -3589l, -3980l, -4369l,
  100759. -4755l, -5138l, -5519l, -5896l,
  100760. -6269l, -6638l, -7004l, -7365l,
  100761. -7722l, -8075l, -8422l, -8764l,
  100762. -9101l, -9433l, -9759l, -10079l,
  100763. -10393l, -10701l, -11002l, -11296l,
  100764. -11584l, -11865l, -12139l, -12405l,
  100765. -12664l, -12915l, -13159l, -13394l,
  100766. -13622l, -13841l, -14052l, -14255l,
  100767. -14448l, -14634l, -14810l, -14977l,
  100768. -15136l, -15285l, -15425l, -15556l,
  100769. -15678l, -15790l, -15892l, -15985l,
  100770. -16068l, -16142l, -16206l, -16260l,
  100771. -16304l, -16339l, -16363l, -16378l,
  100772. -16383l,
  100773. };
  100774. #endif
  100775. #endif
  100776. /*** End of inlined file: lookup_data.h ***/
  100777. #ifdef FLOAT_LOOKUP
  100778. float vorbis_coslook(float a){
  100779. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100780. int i=vorbis_ftoi(d-.5);
  100781. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100782. }
  100783. float vorbis_invsqlook(float a){
  100784. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100785. int i=vorbis_ftoi(d-.5f);
  100786. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100787. }
  100788. float vorbis_invsq2explook(int a){
  100789. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100790. }
  100791. #include <stdio.h>
  100792. float vorbis_fromdBlook(float a){
  100793. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100794. return (i<0)?1.f:
  100795. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100796. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100797. }
  100798. #endif
  100799. #ifdef INT_LOOKUP
  100800. long vorbis_invsqlook_i(long a,long e){
  100801. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100802. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100803. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100804. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100805. d)>>16); /* result 1.16 */
  100806. e+=32;
  100807. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100808. e=(e>>1)-8;
  100809. return(val>>e);
  100810. }
  100811. float vorbis_fromdBlook_i(long a){
  100812. int i=(-a)>>(12-FROMdB2_SHIFT);
  100813. return (i<0)?1.f:
  100814. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100815. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100816. }
  100817. long vorbis_coslook_i(long a){
  100818. int i=a>>COS_LOOKUP_I_SHIFT;
  100819. int d=a&COS_LOOKUP_I_MASK;
  100820. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100821. COS_LOOKUP_I_SHIFT);
  100822. }
  100823. #endif
  100824. #endif
  100825. /*** End of inlined file: lookup.c ***/
  100826. /* catch this in the build system; we #include for
  100827. compilers (like gcc) that can't inline across
  100828. modules */
  100829. static int MLOOP_1[64]={
  100830. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  100831. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  100832. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100833. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100834. };
  100835. static int MLOOP_2[64]={
  100836. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  100837. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  100838. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100839. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100840. };
  100841. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  100842. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100843. float amp,float ampoffset){
  100844. int i;
  100845. int ampoffseti=rint(ampoffset*4096.f);
  100846. int ampi=rint(amp*16.f);
  100847. long *ilsp=alloca(m*sizeof(*ilsp));
  100848. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  100849. i=0;
  100850. while(i<n){
  100851. int j,k=map[i];
  100852. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  100853. unsigned long qi=46341;
  100854. int qexp=0,shift;
  100855. long wi=vorbis_coslook_i(k*65536/ln);
  100856. qi*=labs(ilsp[0]-wi);
  100857. pi*=labs(ilsp[1]-wi);
  100858. for(j=3;j<m;j+=2){
  100859. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100860. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100861. shift=MLOOP_3[(pi|qi)>>16];
  100862. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100863. pi=(pi>>shift)*labs(ilsp[j]-wi);
  100864. qexp+=shift;
  100865. }
  100866. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100867. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100868. shift=MLOOP_3[(pi|qi)>>16];
  100869. if(m&1){
  100870. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100871. pi=(pi>>shift)<<14;
  100872. qexp+=shift;
  100873. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100874. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100875. shift=MLOOP_3[(pi|qi)>>16];
  100876. pi>>=shift;
  100877. qi>>=shift;
  100878. qexp+=shift-14*((m+1)>>1);
  100879. pi=((pi*pi)>>16);
  100880. qi=((qi*qi)>>16);
  100881. qexp=qexp*2+m;
  100882. pi*=(1<<14)-((wi*wi)>>14);
  100883. qi+=pi>>14;
  100884. }else{
  100885. pi>>=shift;
  100886. qi>>=shift;
  100887. qexp+=shift-7*m;
  100888. pi=((pi*pi)>>16);
  100889. qi=((qi*qi)>>16);
  100890. qexp=qexp*2+m;
  100891. pi*=(1<<14)-wi;
  100892. qi*=(1<<14)+wi;
  100893. qi=(qi+pi)>>14;
  100894. }
  100895. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  100896. qi>>=1; qexp++;
  100897. }else
  100898. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  100899. qi<<=1; qexp--;
  100900. }
  100901. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  100902. vorbis_invsqlook_i(qi,qexp)-
  100903. ampoffseti); /* 8.12[0] */
  100904. curve[i]*=amp;
  100905. while(map[++i]==k)curve[i]*=amp;
  100906. }
  100907. }
  100908. #else
  100909. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100910. float amp,float ampoffset){
  100911. int i;
  100912. float wdel=M_PI/ln;
  100913. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  100914. i=0;
  100915. while(i<n){
  100916. int j,k=map[i];
  100917. float p=.5f;
  100918. float q=.5f;
  100919. float w=2.f*cos(wdel*k);
  100920. for(j=1;j<m;j+=2){
  100921. q *= w-lsp[j-1];
  100922. p *= w-lsp[j];
  100923. }
  100924. if(j==m){
  100925. q*=w-lsp[j-1];
  100926. p*=p*(4.f-w*w);
  100927. q*=q;
  100928. }else{
  100929. p*=p*(2.f-w);
  100930. q*=q*(2.f+w);
  100931. }
  100932. q=fromdB(amp/sqrt(p+q)-ampoffset);
  100933. curve[i]*=q;
  100934. while(map[++i]==k)curve[i]*=q;
  100935. }
  100936. }
  100937. #endif
  100938. #endif
  100939. static void cheby(float *g, int ord) {
  100940. int i, j;
  100941. g[0] *= .5f;
  100942. for(i=2; i<= ord; i++) {
  100943. for(j=ord; j >= i; j--) {
  100944. g[j-2] -= g[j];
  100945. g[j] += g[j];
  100946. }
  100947. }
  100948. }
  100949. static int comp(const void *a,const void *b){
  100950. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  100951. }
  100952. #define EPSILON 10e-7
  100953. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  100954. int i,m;
  100955. double lastdelta=0.f;
  100956. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  100957. for(i=0;i<=ord;i++)defl[i]=a[i];
  100958. for(m=ord;m>0;m--){
  100959. double newx=0.f,delta;
  100960. while(1){
  100961. double p=defl[m],pp=0.f,ppp=0.f,denom;
  100962. for(i=m;i>0;i--){
  100963. ppp = newx*ppp + pp;
  100964. pp = newx*pp + p;
  100965. p = newx*p + defl[i-1];
  100966. }
  100967. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  100968. if(denom<0)
  100969. return(-1); /* complex root! The LPC generator handed us a bad filter */
  100970. if(pp>0){
  100971. denom = pp + sqrt(denom);
  100972. if(denom<EPSILON)denom=EPSILON;
  100973. }else{
  100974. denom = pp - sqrt(denom);
  100975. if(denom>-(EPSILON))denom=-(EPSILON);
  100976. }
  100977. delta = m*p/denom;
  100978. newx -= delta;
  100979. if(delta<0.f)delta*=-1;
  100980. if(fabs(delta/newx)<10e-12)break;
  100981. lastdelta=delta;
  100982. }
  100983. r[m-1]=newx;
  100984. for(i=m;i>0;i--)
  100985. defl[i-1]+=newx*defl[i];
  100986. defl++;
  100987. }
  100988. return(0);
  100989. }
  100990. static int Newton_Raphson(float *a,int ord,float *r){
  100991. int i, k, count=0;
  100992. double error=1.f;
  100993. double *root=(double*)alloca(ord*sizeof(*root));
  100994. for(i=0; i<ord;i++) root[i] = r[i];
  100995. while(error>1e-20){
  100996. error=0;
  100997. for(i=0; i<ord; i++) { /* Update each point. */
  100998. double pp=0.,delta;
  100999. double rooti=root[i];
  101000. double p=a[ord];
  101001. for(k=ord-1; k>= 0; k--) {
  101002. pp= pp* rooti + p;
  101003. p = p * rooti + a[k];
  101004. }
  101005. delta = p/pp;
  101006. root[i] -= delta;
  101007. error+= delta*delta;
  101008. }
  101009. if(count>40)return(-1);
  101010. count++;
  101011. }
  101012. for(i=0; i<ord;i++) r[i] = root[i];
  101013. return(0);
  101014. }
  101015. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101016. int order2=(m+1)>>1;
  101017. int g1_order,g2_order;
  101018. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101019. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101020. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101021. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101022. int i;
  101023. g1_order=(m+1)>>1;
  101024. g2_order=(m) >>1;
  101025. g1[g1_order] = 1.f;
  101026. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101027. g2[g2_order] = 1.f;
  101028. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101029. if(g1_order>g2_order){
  101030. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101031. }else{
  101032. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101033. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101034. }
  101035. cheby(g1,g1_order);
  101036. cheby(g2,g2_order);
  101037. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101038. Laguerre_With_Deflation(g2,g2_order,g2r))
  101039. return(-1);
  101040. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101041. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101042. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101043. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101044. for(i=0;i<g1_order;i++)
  101045. lsp[i*2] = acos(g1r[i]);
  101046. for(i=0;i<g2_order;i++)
  101047. lsp[i*2+1] = acos(g2r[i]);
  101048. return(0);
  101049. }
  101050. #endif
  101051. /*** End of inlined file: lsp.c ***/
  101052. /*** Start of inlined file: mapping0.c ***/
  101053. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101054. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101055. // tasks..
  101056. #if JUCE_MSVC
  101057. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101058. #endif
  101059. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101060. #if JUCE_USE_OGGVORBIS
  101061. #include <stdlib.h>
  101062. #include <stdio.h>
  101063. #include <string.h>
  101064. #include <math.h>
  101065. static void mapping0_free_info(vorbis_info_mapping *i){
  101066. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101067. if(info){
  101068. memset(info,0,sizeof(*info));
  101069. _ogg_free(info);
  101070. }
  101071. }
  101072. static int ilog3(unsigned int v){
  101073. int ret=0;
  101074. if(v)--v;
  101075. while(v){
  101076. ret++;
  101077. v>>=1;
  101078. }
  101079. return(ret);
  101080. }
  101081. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101082. oggpack_buffer *opb){
  101083. int i;
  101084. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101085. if(info->submaps>1){
  101086. oggpack_write(opb,1,1);
  101087. oggpack_write(opb,info->submaps-1,4);
  101088. }else
  101089. oggpack_write(opb,0,1);
  101090. if(info->coupling_steps>0){
  101091. oggpack_write(opb,1,1);
  101092. oggpack_write(opb,info->coupling_steps-1,8);
  101093. for(i=0;i<info->coupling_steps;i++){
  101094. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101095. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101096. }
  101097. }else
  101098. oggpack_write(opb,0,1);
  101099. oggpack_write(opb,0,2); /* 2,3:reserved */
  101100. if(info->submaps>1){
  101101. for(i=0;i<vi->channels;i++)
  101102. oggpack_write(opb,info->chmuxlist[i],4);
  101103. }
  101104. for(i=0;i<info->submaps;i++){
  101105. oggpack_write(opb,0,8); /* time submap unused */
  101106. oggpack_write(opb,info->floorsubmap[i],8);
  101107. oggpack_write(opb,info->residuesubmap[i],8);
  101108. }
  101109. }
  101110. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101111. int i;
  101112. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101113. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101114. memset(info,0,sizeof(*info));
  101115. if(oggpack_read(opb,1))
  101116. info->submaps=oggpack_read(opb,4)+1;
  101117. else
  101118. info->submaps=1;
  101119. if(oggpack_read(opb,1)){
  101120. info->coupling_steps=oggpack_read(opb,8)+1;
  101121. for(i=0;i<info->coupling_steps;i++){
  101122. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101123. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101124. if(testM<0 ||
  101125. testA<0 ||
  101126. testM==testA ||
  101127. testM>=vi->channels ||
  101128. testA>=vi->channels) goto err_out;
  101129. }
  101130. }
  101131. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101132. if(info->submaps>1){
  101133. for(i=0;i<vi->channels;i++){
  101134. info->chmuxlist[i]=oggpack_read(opb,4);
  101135. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101136. }
  101137. }
  101138. for(i=0;i<info->submaps;i++){
  101139. oggpack_read(opb,8); /* time submap unused */
  101140. info->floorsubmap[i]=oggpack_read(opb,8);
  101141. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101142. info->residuesubmap[i]=oggpack_read(opb,8);
  101143. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101144. }
  101145. return info;
  101146. err_out:
  101147. mapping0_free_info(info);
  101148. return(NULL);
  101149. }
  101150. #if 0
  101151. static long seq=0;
  101152. static ogg_int64_t total=0;
  101153. static float FLOOR1_fromdB_LOOKUP[256]={
  101154. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101155. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101156. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101157. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101158. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101159. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101160. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101161. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101162. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101163. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101164. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101165. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101166. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101167. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101168. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101169. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101170. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101171. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101172. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101173. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101174. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101175. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101176. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101177. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101178. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101179. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101180. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101181. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101182. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101183. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101184. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101185. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101186. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101187. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101188. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101189. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101190. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101191. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101192. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101193. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101194. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101195. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101196. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101197. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101198. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101199. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101200. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101201. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101202. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101203. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101204. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101205. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101206. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101207. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101208. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101209. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101210. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101211. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101212. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101213. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101214. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101215. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101216. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101217. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101218. };
  101219. #endif
  101220. extern int *floor1_fit(vorbis_block *vb,void *look,
  101221. const float *logmdct, /* in */
  101222. const float *logmask);
  101223. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101224. int *A,int *B,
  101225. int del);
  101226. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101227. void*look,
  101228. int *post,int *ilogmask);
  101229. static int mapping0_forward(vorbis_block *vb){
  101230. vorbis_dsp_state *vd=vb->vd;
  101231. vorbis_info *vi=vd->vi;
  101232. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101233. private_state *b=(private_state*)vb->vd->backend_state;
  101234. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101235. int n=vb->pcmend;
  101236. int i,j,k;
  101237. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101238. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101239. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101240. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101241. float global_ampmax=vbi->ampmax;
  101242. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101243. int blocktype=vbi->blocktype;
  101244. int modenumber=vb->W;
  101245. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101246. vorbis_look_psy *psy_look=
  101247. b->psy+blocktype+(vb->W?2:0);
  101248. vb->mode=modenumber;
  101249. for(i=0;i<vi->channels;i++){
  101250. float scale=4.f/n;
  101251. float scale_dB;
  101252. float *pcm =vb->pcm[i];
  101253. float *logfft =pcm;
  101254. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101255. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101256. todB estimation used on IEEE 754
  101257. compliant machines had a bug that
  101258. returned dB values about a third
  101259. of a decibel too high. The bug
  101260. was harmless because tunings
  101261. implicitly took that into
  101262. account. However, fixing the bug
  101263. in the estimator requires
  101264. changing all the tunings as well.
  101265. For now, it's easier to sync
  101266. things back up here, and
  101267. recalibrate the tunings in the
  101268. next major model upgrade. */
  101269. #if 0
  101270. if(vi->channels==2)
  101271. if(i==0)
  101272. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101273. else
  101274. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101275. #endif
  101276. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101277. #if 0
  101278. if(vi->channels==2)
  101279. if(i==0)
  101280. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101281. else
  101282. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101283. #endif
  101284. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101285. drft_forward(&b->fft_look[vb->W],pcm);
  101286. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101287. original todB estimation used on
  101288. IEEE 754 compliant machines had a
  101289. bug that returned dB values about
  101290. a third of a decibel too high.
  101291. The bug was harmless because
  101292. tunings implicitly took that into
  101293. account. However, fixing the bug
  101294. in the estimator requires
  101295. changing all the tunings as well.
  101296. For now, it's easier to sync
  101297. things back up here, and
  101298. recalibrate the tunings in the
  101299. next major model upgrade. */
  101300. local_ampmax[i]=logfft[0];
  101301. for(j=1;j<n-1;j+=2){
  101302. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101303. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101304. .345 is a hack; the original todB
  101305. estimation used on IEEE 754
  101306. compliant machines had a bug that
  101307. returned dB values about a third
  101308. of a decibel too high. The bug
  101309. was harmless because tunings
  101310. implicitly took that into
  101311. account. However, fixing the bug
  101312. in the estimator requires
  101313. changing all the tunings as well.
  101314. For now, it's easier to sync
  101315. things back up here, and
  101316. recalibrate the tunings in the
  101317. next major model upgrade. */
  101318. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101319. }
  101320. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101321. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101322. #if 0
  101323. if(vi->channels==2){
  101324. if(i==0){
  101325. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101326. }else{
  101327. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101328. }
  101329. }
  101330. #endif
  101331. }
  101332. {
  101333. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101334. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101335. for(i=0;i<vi->channels;i++){
  101336. int submap=info->chmuxlist[i];
  101337. float *mdct =gmdct[i];
  101338. float *logfft =vb->pcm[i];
  101339. float *logmdct =logfft+n/2;
  101340. float *logmask =logfft;
  101341. vb->mode=modenumber;
  101342. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101343. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101344. for(j=0;j<n/2;j++)
  101345. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101346. todB estimation used on IEEE 754
  101347. compliant machines had a bug that
  101348. returned dB values about a third
  101349. of a decibel too high. The bug
  101350. was harmless because tunings
  101351. implicitly took that into
  101352. account. However, fixing the bug
  101353. in the estimator requires
  101354. changing all the tunings as well.
  101355. For now, it's easier to sync
  101356. things back up here, and
  101357. recalibrate the tunings in the
  101358. next major model upgrade. */
  101359. #if 0
  101360. if(vi->channels==2){
  101361. if(i==0)
  101362. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101363. else
  101364. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101365. }else{
  101366. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101367. }
  101368. #endif
  101369. _vp_noisemask(psy_look,
  101370. logmdct,
  101371. noise); /* noise does not have by-frequency offset
  101372. bias applied yet */
  101373. #if 0
  101374. if(vi->channels==2){
  101375. if(i==0)
  101376. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101377. else
  101378. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101379. }
  101380. #endif
  101381. _vp_tonemask(psy_look,
  101382. logfft,
  101383. tone,
  101384. global_ampmax,
  101385. local_ampmax[i]);
  101386. #if 0
  101387. if(vi->channels==2){
  101388. if(i==0)
  101389. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101390. else
  101391. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101392. }
  101393. #endif
  101394. #if 0
  101395. {
  101396. float aotuv[psy_look->n];
  101397. #endif
  101398. _vp_offset_and_mix(psy_look,
  101399. noise,
  101400. tone,
  101401. 1,
  101402. logmask,
  101403. mdct,
  101404. logmdct);
  101405. #if 0
  101406. if(vi->channels==2){
  101407. if(i==0)
  101408. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101409. else
  101410. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101411. }
  101412. }
  101413. #endif
  101414. #if 0
  101415. if(vi->channels==2){
  101416. if(i==0)
  101417. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101418. else
  101419. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101420. }
  101421. #endif
  101422. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101423. floor_posts[i][PACKETBLOBS/2]=
  101424. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101425. logmdct,
  101426. logmask);
  101427. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101428. _vp_offset_and_mix(psy_look,
  101429. noise,
  101430. tone,
  101431. 2,
  101432. logmask,
  101433. mdct,
  101434. logmdct);
  101435. #if 0
  101436. if(vi->channels==2){
  101437. if(i==0)
  101438. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101439. else
  101440. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101441. }
  101442. #endif
  101443. floor_posts[i][PACKETBLOBS-1]=
  101444. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101445. logmdct,
  101446. logmask);
  101447. _vp_offset_and_mix(psy_look,
  101448. noise,
  101449. tone,
  101450. 0,
  101451. logmask,
  101452. mdct,
  101453. logmdct);
  101454. #if 0
  101455. if(vi->channels==2)
  101456. if(i==0)
  101457. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101458. else
  101459. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101460. #endif
  101461. floor_posts[i][0]=
  101462. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101463. logmdct,
  101464. logmask);
  101465. for(k=1;k<PACKETBLOBS/2;k++)
  101466. floor_posts[i][k]=
  101467. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101468. floor_posts[i][0],
  101469. floor_posts[i][PACKETBLOBS/2],
  101470. k*65536/(PACKETBLOBS/2));
  101471. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101472. floor_posts[i][k]=
  101473. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101474. floor_posts[i][PACKETBLOBS/2],
  101475. floor_posts[i][PACKETBLOBS-1],
  101476. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101477. }
  101478. }
  101479. }
  101480. vbi->ampmax=global_ampmax;
  101481. {
  101482. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101483. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101484. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101485. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101486. float **mag_memo;
  101487. int **mag_sort;
  101488. if(info->coupling_steps){
  101489. mag_memo=_vp_quantize_couple_memo(vb,
  101490. &ci->psy_g_param,
  101491. psy_look,
  101492. info,
  101493. gmdct);
  101494. mag_sort=_vp_quantize_couple_sort(vb,
  101495. psy_look,
  101496. info,
  101497. mag_memo);
  101498. hf_reduction(&ci->psy_g_param,
  101499. psy_look,
  101500. info,
  101501. mag_memo);
  101502. }
  101503. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101504. if(psy_look->vi->normal_channel_p){
  101505. for(i=0;i<vi->channels;i++){
  101506. float *mdct =gmdct[i];
  101507. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101508. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101509. }
  101510. }
  101511. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101512. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101513. k++){
  101514. oggpack_buffer *opb=vbi->packetblob[k];
  101515. oggpack_write(opb,0,1);
  101516. oggpack_write(opb,modenumber,b->modebits);
  101517. if(vb->W){
  101518. oggpack_write(opb,vb->lW,1);
  101519. oggpack_write(opb,vb->nW,1);
  101520. }
  101521. for(i=0;i<vi->channels;i++){
  101522. int submap=info->chmuxlist[i];
  101523. float *mdct =gmdct[i];
  101524. float *res =vb->pcm[i];
  101525. int *ilogmask=ilogmaskch[i]=
  101526. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101527. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101528. floor_posts[i][k],
  101529. ilogmask);
  101530. #if 0
  101531. {
  101532. char buf[80];
  101533. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101534. float work[n/2];
  101535. for(j=0;j<n/2;j++)
  101536. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101537. _analysis_output(buf,seq,work,n/2,1,1,0);
  101538. }
  101539. #endif
  101540. _vp_remove_floor(psy_look,
  101541. mdct,
  101542. ilogmask,
  101543. res,
  101544. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101545. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101546. #if 0
  101547. {
  101548. char buf[80];
  101549. float work[n/2];
  101550. for(j=0;j<n/2;j++)
  101551. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101552. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101553. _analysis_output(buf,seq,work,n/2,1,1,0);
  101554. }
  101555. #endif
  101556. }
  101557. if(info->coupling_steps){
  101558. _vp_couple(k,
  101559. &ci->psy_g_param,
  101560. psy_look,
  101561. info,
  101562. vb->pcm,
  101563. mag_memo,
  101564. mag_sort,
  101565. ilogmaskch,
  101566. nonzero,
  101567. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101568. }
  101569. for(i=0;i<info->submaps;i++){
  101570. int ch_in_bundle=0;
  101571. long **classifications;
  101572. int resnum=info->residuesubmap[i];
  101573. for(j=0;j<vi->channels;j++){
  101574. if(info->chmuxlist[j]==i){
  101575. zerobundle[ch_in_bundle]=0;
  101576. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101577. res_bundle[ch_in_bundle]=vb->pcm[j];
  101578. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101579. }
  101580. }
  101581. classifications=_residue_P[ci->residue_type[resnum]]->
  101582. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101583. _residue_P[ci->residue_type[resnum]]->
  101584. forward(opb,vb,b->residue[resnum],
  101585. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101586. }
  101587. }
  101588. }
  101589. #if 0
  101590. seq++;
  101591. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101592. #endif
  101593. return(0);
  101594. }
  101595. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101596. vorbis_dsp_state *vd=vb->vd;
  101597. vorbis_info *vi=vd->vi;
  101598. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101599. private_state *b=(private_state*)vd->backend_state;
  101600. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101601. int i,j;
  101602. long n=vb->pcmend=ci->blocksizes[vb->W];
  101603. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101604. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101605. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101606. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101607. for(i=0;i<vi->channels;i++){
  101608. int submap=info->chmuxlist[i];
  101609. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101610. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101611. if(floormemo[i])
  101612. nonzero[i]=1;
  101613. else
  101614. nonzero[i]=0;
  101615. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101616. }
  101617. for(i=0;i<info->coupling_steps;i++){
  101618. if(nonzero[info->coupling_mag[i]] ||
  101619. nonzero[info->coupling_ang[i]]){
  101620. nonzero[info->coupling_mag[i]]=1;
  101621. nonzero[info->coupling_ang[i]]=1;
  101622. }
  101623. }
  101624. for(i=0;i<info->submaps;i++){
  101625. int ch_in_bundle=0;
  101626. for(j=0;j<vi->channels;j++){
  101627. if(info->chmuxlist[j]==i){
  101628. if(nonzero[j])
  101629. zerobundle[ch_in_bundle]=1;
  101630. else
  101631. zerobundle[ch_in_bundle]=0;
  101632. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101633. }
  101634. }
  101635. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101636. inverse(vb,b->residue[info->residuesubmap[i]],
  101637. pcmbundle,zerobundle,ch_in_bundle);
  101638. }
  101639. for(i=info->coupling_steps-1;i>=0;i--){
  101640. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101641. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101642. for(j=0;j<n/2;j++){
  101643. float mag=pcmM[j];
  101644. float ang=pcmA[j];
  101645. if(mag>0)
  101646. if(ang>0){
  101647. pcmM[j]=mag;
  101648. pcmA[j]=mag-ang;
  101649. }else{
  101650. pcmA[j]=mag;
  101651. pcmM[j]=mag+ang;
  101652. }
  101653. else
  101654. if(ang>0){
  101655. pcmM[j]=mag;
  101656. pcmA[j]=mag+ang;
  101657. }else{
  101658. pcmA[j]=mag;
  101659. pcmM[j]=mag-ang;
  101660. }
  101661. }
  101662. }
  101663. for(i=0;i<vi->channels;i++){
  101664. float *pcm=vb->pcm[i];
  101665. int submap=info->chmuxlist[i];
  101666. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101667. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101668. floormemo[i],pcm);
  101669. }
  101670. for(i=0;i<vi->channels;i++){
  101671. float *pcm=vb->pcm[i];
  101672. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101673. }
  101674. return(0);
  101675. }
  101676. vorbis_func_mapping mapping0_exportbundle={
  101677. &mapping0_pack,
  101678. &mapping0_unpack,
  101679. &mapping0_free_info,
  101680. &mapping0_forward,
  101681. &mapping0_inverse
  101682. };
  101683. #endif
  101684. /*** End of inlined file: mapping0.c ***/
  101685. /*** Start of inlined file: mdct.c ***/
  101686. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101687. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101688. // tasks..
  101689. #if JUCE_MSVC
  101690. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101691. #endif
  101692. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101693. #if JUCE_USE_OGGVORBIS
  101694. #include <stdio.h>
  101695. #include <stdlib.h>
  101696. #include <string.h>
  101697. #include <math.h>
  101698. void mdct_init(mdct_lookup *lookup,int n){
  101699. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101700. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101701. int i;
  101702. int n2=n>>1;
  101703. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101704. lookup->n=n;
  101705. lookup->trig=T;
  101706. lookup->bitrev=bitrev;
  101707. for(i=0;i<n/4;i++){
  101708. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101709. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101710. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101711. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101712. }
  101713. for(i=0;i<n/8;i++){
  101714. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101715. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101716. }
  101717. {
  101718. int mask=(1<<(log2n-1))-1,i,j;
  101719. int msb=1<<(log2n-2);
  101720. for(i=0;i<n/8;i++){
  101721. int acc=0;
  101722. for(j=0;msb>>j;j++)
  101723. if((msb>>j)&i)acc|=1<<j;
  101724. bitrev[i*2]=((~acc)&mask)-1;
  101725. bitrev[i*2+1]=acc;
  101726. }
  101727. }
  101728. lookup->scale=FLOAT_CONV(4.f/n);
  101729. }
  101730. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101731. REG_TYPE r0 = x[6] + x[2];
  101732. REG_TYPE r1 = x[6] - x[2];
  101733. REG_TYPE r2 = x[4] + x[0];
  101734. REG_TYPE r3 = x[4] - x[0];
  101735. x[6] = r0 + r2;
  101736. x[4] = r0 - r2;
  101737. r0 = x[5] - x[1];
  101738. r2 = x[7] - x[3];
  101739. x[0] = r1 + r0;
  101740. x[2] = r1 - r0;
  101741. r0 = x[5] + x[1];
  101742. r1 = x[7] + x[3];
  101743. x[3] = r2 + r3;
  101744. x[1] = r2 - r3;
  101745. x[7] = r1 + r0;
  101746. x[5] = r1 - r0;
  101747. }
  101748. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101749. REG_TYPE r0 = x[1] - x[9];
  101750. REG_TYPE r1 = x[0] - x[8];
  101751. x[8] += x[0];
  101752. x[9] += x[1];
  101753. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101754. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101755. r0 = x[3] - x[11];
  101756. r1 = x[10] - x[2];
  101757. x[10] += x[2];
  101758. x[11] += x[3];
  101759. x[2] = r0;
  101760. x[3] = r1;
  101761. r0 = x[12] - x[4];
  101762. r1 = x[13] - x[5];
  101763. x[12] += x[4];
  101764. x[13] += x[5];
  101765. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101766. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101767. r0 = x[14] - x[6];
  101768. r1 = x[15] - x[7];
  101769. x[14] += x[6];
  101770. x[15] += x[7];
  101771. x[6] = r0;
  101772. x[7] = r1;
  101773. mdct_butterfly_8(x);
  101774. mdct_butterfly_8(x+8);
  101775. }
  101776. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101777. REG_TYPE r0 = x[30] - x[14];
  101778. REG_TYPE r1 = x[31] - x[15];
  101779. x[30] += x[14];
  101780. x[31] += x[15];
  101781. x[14] = r0;
  101782. x[15] = r1;
  101783. r0 = x[28] - x[12];
  101784. r1 = x[29] - x[13];
  101785. x[28] += x[12];
  101786. x[29] += x[13];
  101787. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101788. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101789. r0 = x[26] - x[10];
  101790. r1 = x[27] - x[11];
  101791. x[26] += x[10];
  101792. x[27] += x[11];
  101793. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101794. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101795. r0 = x[24] - x[8];
  101796. r1 = x[25] - x[9];
  101797. x[24] += x[8];
  101798. x[25] += x[9];
  101799. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101800. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101801. r0 = x[22] - x[6];
  101802. r1 = x[7] - x[23];
  101803. x[22] += x[6];
  101804. x[23] += x[7];
  101805. x[6] = r1;
  101806. x[7] = r0;
  101807. r0 = x[4] - x[20];
  101808. r1 = x[5] - x[21];
  101809. x[20] += x[4];
  101810. x[21] += x[5];
  101811. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  101812. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  101813. r0 = x[2] - x[18];
  101814. r1 = x[3] - x[19];
  101815. x[18] += x[2];
  101816. x[19] += x[3];
  101817. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  101818. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  101819. r0 = x[0] - x[16];
  101820. r1 = x[1] - x[17];
  101821. x[16] += x[0];
  101822. x[17] += x[1];
  101823. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101824. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  101825. mdct_butterfly_16(x);
  101826. mdct_butterfly_16(x+16);
  101827. }
  101828. STIN void mdct_butterfly_first(DATA_TYPE *T,
  101829. DATA_TYPE *x,
  101830. int points){
  101831. DATA_TYPE *x1 = x + points - 8;
  101832. DATA_TYPE *x2 = x + (points>>1) - 8;
  101833. REG_TYPE r0;
  101834. REG_TYPE r1;
  101835. do{
  101836. r0 = x1[6] - x2[6];
  101837. r1 = x1[7] - x2[7];
  101838. x1[6] += x2[6];
  101839. x1[7] += x2[7];
  101840. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101841. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101842. r0 = x1[4] - x2[4];
  101843. r1 = x1[5] - x2[5];
  101844. x1[4] += x2[4];
  101845. x1[5] += x2[5];
  101846. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  101847. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  101848. r0 = x1[2] - x2[2];
  101849. r1 = x1[3] - x2[3];
  101850. x1[2] += x2[2];
  101851. x1[3] += x2[3];
  101852. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  101853. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  101854. r0 = x1[0] - x2[0];
  101855. r1 = x1[1] - x2[1];
  101856. x1[0] += x2[0];
  101857. x1[1] += x2[1];
  101858. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  101859. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  101860. x1-=8;
  101861. x2-=8;
  101862. T+=16;
  101863. }while(x2>=x);
  101864. }
  101865. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  101866. DATA_TYPE *x,
  101867. int points,
  101868. int trigint){
  101869. DATA_TYPE *x1 = x + points - 8;
  101870. DATA_TYPE *x2 = x + (points>>1) - 8;
  101871. REG_TYPE r0;
  101872. REG_TYPE r1;
  101873. do{
  101874. r0 = x1[6] - x2[6];
  101875. r1 = x1[7] - x2[7];
  101876. x1[6] += x2[6];
  101877. x1[7] += x2[7];
  101878. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101879. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101880. T+=trigint;
  101881. r0 = x1[4] - x2[4];
  101882. r1 = x1[5] - x2[5];
  101883. x1[4] += x2[4];
  101884. x1[5] += x2[5];
  101885. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101886. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101887. T+=trigint;
  101888. r0 = x1[2] - x2[2];
  101889. r1 = x1[3] - x2[3];
  101890. x1[2] += x2[2];
  101891. x1[3] += x2[3];
  101892. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101893. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101894. T+=trigint;
  101895. r0 = x1[0] - x2[0];
  101896. r1 = x1[1] - x2[1];
  101897. x1[0] += x2[0];
  101898. x1[1] += x2[1];
  101899. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101900. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101901. T+=trigint;
  101902. x1-=8;
  101903. x2-=8;
  101904. }while(x2>=x);
  101905. }
  101906. STIN void mdct_butterflies(mdct_lookup *init,
  101907. DATA_TYPE *x,
  101908. int points){
  101909. DATA_TYPE *T=init->trig;
  101910. int stages=init->log2n-5;
  101911. int i,j;
  101912. if(--stages>0){
  101913. mdct_butterfly_first(T,x,points);
  101914. }
  101915. for(i=1;--stages>0;i++){
  101916. for(j=0;j<(1<<i);j++)
  101917. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  101918. }
  101919. for(j=0;j<points;j+=32)
  101920. mdct_butterfly_32(x+j);
  101921. }
  101922. void mdct_clear(mdct_lookup *l){
  101923. if(l){
  101924. if(l->trig)_ogg_free(l->trig);
  101925. if(l->bitrev)_ogg_free(l->bitrev);
  101926. memset(l,0,sizeof(*l));
  101927. }
  101928. }
  101929. STIN void mdct_bitreverse(mdct_lookup *init,
  101930. DATA_TYPE *x){
  101931. int n = init->n;
  101932. int *bit = init->bitrev;
  101933. DATA_TYPE *w0 = x;
  101934. DATA_TYPE *w1 = x = w0+(n>>1);
  101935. DATA_TYPE *T = init->trig+n;
  101936. do{
  101937. DATA_TYPE *x0 = x+bit[0];
  101938. DATA_TYPE *x1 = x+bit[1];
  101939. REG_TYPE r0 = x0[1] - x1[1];
  101940. REG_TYPE r1 = x0[0] + x1[0];
  101941. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  101942. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  101943. w1 -= 4;
  101944. r0 = HALVE(x0[1] + x1[1]);
  101945. r1 = HALVE(x0[0] - x1[0]);
  101946. w0[0] = r0 + r2;
  101947. w1[2] = r0 - r2;
  101948. w0[1] = r1 + r3;
  101949. w1[3] = r3 - r1;
  101950. x0 = x+bit[2];
  101951. x1 = x+bit[3];
  101952. r0 = x0[1] - x1[1];
  101953. r1 = x0[0] + x1[0];
  101954. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  101955. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  101956. r0 = HALVE(x0[1] + x1[1]);
  101957. r1 = HALVE(x0[0] - x1[0]);
  101958. w0[2] = r0 + r2;
  101959. w1[0] = r0 - r2;
  101960. w0[3] = r1 + r3;
  101961. w1[1] = r3 - r1;
  101962. T += 4;
  101963. bit += 4;
  101964. w0 += 4;
  101965. }while(w0<w1);
  101966. }
  101967. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  101968. int n=init->n;
  101969. int n2=n>>1;
  101970. int n4=n>>2;
  101971. DATA_TYPE *iX = in+n2-7;
  101972. DATA_TYPE *oX = out+n2+n4;
  101973. DATA_TYPE *T = init->trig+n4;
  101974. do{
  101975. oX -= 4;
  101976. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  101977. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  101978. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  101979. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  101980. iX -= 8;
  101981. T += 4;
  101982. }while(iX>=in);
  101983. iX = in+n2-8;
  101984. oX = out+n2+n4;
  101985. T = init->trig+n4;
  101986. do{
  101987. T -= 4;
  101988. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  101989. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  101990. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  101991. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  101992. iX -= 8;
  101993. oX += 4;
  101994. }while(iX>=in);
  101995. mdct_butterflies(init,out+n2,n2);
  101996. mdct_bitreverse(init,out);
  101997. {
  101998. DATA_TYPE *oX1=out+n2+n4;
  101999. DATA_TYPE *oX2=out+n2+n4;
  102000. DATA_TYPE *iX =out;
  102001. T =init->trig+n2;
  102002. do{
  102003. oX1-=4;
  102004. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102005. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102006. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102007. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102008. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102009. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102010. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102011. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102012. oX2+=4;
  102013. iX += 8;
  102014. T += 8;
  102015. }while(iX<oX1);
  102016. iX=out+n2+n4;
  102017. oX1=out+n4;
  102018. oX2=oX1;
  102019. do{
  102020. oX1-=4;
  102021. iX-=4;
  102022. oX2[0] = -(oX1[3] = iX[3]);
  102023. oX2[1] = -(oX1[2] = iX[2]);
  102024. oX2[2] = -(oX1[1] = iX[1]);
  102025. oX2[3] = -(oX1[0] = iX[0]);
  102026. oX2+=4;
  102027. }while(oX2<iX);
  102028. iX=out+n2+n4;
  102029. oX1=out+n2+n4;
  102030. oX2=out+n2;
  102031. do{
  102032. oX1-=4;
  102033. oX1[0]= iX[3];
  102034. oX1[1]= iX[2];
  102035. oX1[2]= iX[1];
  102036. oX1[3]= iX[0];
  102037. iX+=4;
  102038. }while(oX1>oX2);
  102039. }
  102040. }
  102041. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102042. int n=init->n;
  102043. int n2=n>>1;
  102044. int n4=n>>2;
  102045. int n8=n>>3;
  102046. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102047. DATA_TYPE *w2=w+n2;
  102048. REG_TYPE r0;
  102049. REG_TYPE r1;
  102050. DATA_TYPE *x0=in+n2+n4;
  102051. DATA_TYPE *x1=x0+1;
  102052. DATA_TYPE *T=init->trig+n2;
  102053. int i=0;
  102054. for(i=0;i<n8;i+=2){
  102055. x0 -=4;
  102056. T-=2;
  102057. r0= x0[2] + x1[0];
  102058. r1= x0[0] + x1[2];
  102059. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102060. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102061. x1 +=4;
  102062. }
  102063. x1=in+1;
  102064. for(;i<n2-n8;i+=2){
  102065. T-=2;
  102066. x0 -=4;
  102067. r0= x0[2] - x1[0];
  102068. r1= x0[0] - x1[2];
  102069. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102070. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102071. x1 +=4;
  102072. }
  102073. x0=in+n;
  102074. for(;i<n2;i+=2){
  102075. T-=2;
  102076. x0 -=4;
  102077. r0= -x0[2] - x1[0];
  102078. r1= -x0[0] - x1[2];
  102079. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102080. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102081. x1 +=4;
  102082. }
  102083. mdct_butterflies(init,w+n2,n2);
  102084. mdct_bitreverse(init,w);
  102085. T=init->trig+n2;
  102086. x0=out+n2;
  102087. for(i=0;i<n4;i++){
  102088. x0--;
  102089. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102090. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102091. w+=2;
  102092. T+=2;
  102093. }
  102094. }
  102095. #endif
  102096. /*** End of inlined file: mdct.c ***/
  102097. /*** Start of inlined file: psy.c ***/
  102098. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102099. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102100. // tasks..
  102101. #if JUCE_MSVC
  102102. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102103. #endif
  102104. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102105. #if JUCE_USE_OGGVORBIS
  102106. #include <stdlib.h>
  102107. #include <math.h>
  102108. #include <string.h>
  102109. /*** Start of inlined file: masking.h ***/
  102110. #ifndef _V_MASKING_H_
  102111. #define _V_MASKING_H_
  102112. #define MAX_ATH 88
  102113. static float ATH[]={
  102114. -51, -52, -53, -54, -55, -56, -57, -58,
  102115. -59, -60, -61, -62, -63, -64, -65, -66,
  102116. -67, -68, -69, -70, -71, -72, -73, -74,
  102117. -75, -76, -77, -78, -80, -81, -82, -83,
  102118. -84, -85, -86, -87, -88, -88, -89, -89,
  102119. -90, -91, -91, -92, -93, -94, -95, -96,
  102120. -96, -97, -98, -98, -99, -99,-100,-100,
  102121. -101,-102,-103,-104,-106,-107,-107,-107,
  102122. -107,-105,-103,-102,-101, -99, -98, -96,
  102123. -95, -95, -96, -97, -96, -95, -93, -90,
  102124. -80, -70, -50, -40, -30, -30, -30, -30
  102125. };
  102126. #define EHMER_OFFSET 16
  102127. #define EHMER_MAX 56
  102128. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102129. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102130. -60, -60, -60, -60, -62, -62, -65, -73,
  102131. -69, -68, -68, -67, -70, -70, -72, -74,
  102132. -75, -79, -79, -80, -83, -88, -93, -100,
  102133. -110, -999, -999, -999, -999, -999, -999, -999,
  102134. -999, -999, -999, -999, -999, -999, -999, -999,
  102135. -999, -999, -999, -999, -999, -999, -999, -999},
  102136. { -48, -48, -48, -48, -48, -48, -48, -48,
  102137. -48, -48, -48, -48, -48, -53, -61, -66,
  102138. -66, -68, -67, -70, -76, -76, -72, -73,
  102139. -75, -76, -78, -79, -83, -88, -93, -100,
  102140. -110, -999, -999, -999, -999, -999, -999, -999,
  102141. -999, -999, -999, -999, -999, -999, -999, -999,
  102142. -999, -999, -999, -999, -999, -999, -999, -999},
  102143. { -37, -37, -37, -37, -37, -37, -37, -37,
  102144. -38, -40, -42, -46, -48, -53, -55, -62,
  102145. -65, -58, -56, -56, -61, -60, -65, -67,
  102146. -69, -71, -77, -77, -78, -80, -82, -84,
  102147. -88, -93, -98, -106, -112, -999, -999, -999,
  102148. -999, -999, -999, -999, -999, -999, -999, -999,
  102149. -999, -999, -999, -999, -999, -999, -999, -999},
  102150. { -25, -25, -25, -25, -25, -25, -25, -25,
  102151. -25, -26, -27, -29, -32, -38, -48, -52,
  102152. -52, -50, -48, -48, -51, -52, -54, -60,
  102153. -67, -67, -66, -68, -69, -73, -73, -76,
  102154. -80, -81, -81, -85, -85, -86, -88, -93,
  102155. -100, -110, -999, -999, -999, -999, -999, -999,
  102156. -999, -999, -999, -999, -999, -999, -999, -999},
  102157. { -16, -16, -16, -16, -16, -16, -16, -16,
  102158. -17, -19, -20, -22, -26, -28, -31, -40,
  102159. -47, -39, -39, -40, -42, -43, -47, -51,
  102160. -57, -52, -55, -55, -60, -58, -62, -63,
  102161. -70, -67, -69, -72, -73, -77, -80, -82,
  102162. -83, -87, -90, -94, -98, -104, -115, -999,
  102163. -999, -999, -999, -999, -999, -999, -999, -999},
  102164. { -8, -8, -8, -8, -8, -8, -8, -8,
  102165. -8, -8, -10, -11, -15, -19, -25, -30,
  102166. -34, -31, -30, -31, -29, -32, -35, -42,
  102167. -48, -42, -44, -46, -50, -50, -51, -52,
  102168. -59, -54, -55, -55, -58, -62, -63, -66,
  102169. -72, -73, -76, -75, -78, -80, -80, -81,
  102170. -84, -88, -90, -94, -98, -101, -106, -110}},
  102171. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102172. -66, -66, -66, -66, -66, -67, -67, -67,
  102173. -76, -72, -71, -74, -76, -76, -75, -78,
  102174. -79, -79, -81, -83, -86, -89, -93, -97,
  102175. -100, -105, -110, -999, -999, -999, -999, -999,
  102176. -999, -999, -999, -999, -999, -999, -999, -999,
  102177. -999, -999, -999, -999, -999, -999, -999, -999},
  102178. { -47, -47, -47, -47, -47, -47, -47, -47,
  102179. -47, -47, -47, -48, -51, -55, -59, -66,
  102180. -66, -66, -67, -66, -68, -69, -70, -74,
  102181. -79, -77, -77, -78, -80, -81, -82, -84,
  102182. -86, -88, -91, -95, -100, -108, -116, -999,
  102183. -999, -999, -999, -999, -999, -999, -999, -999,
  102184. -999, -999, -999, -999, -999, -999, -999, -999},
  102185. { -36, -36, -36, -36, -36, -36, -36, -36,
  102186. -36, -37, -37, -41, -44, -48, -51, -58,
  102187. -62, -60, -57, -59, -59, -60, -63, -65,
  102188. -72, -71, -70, -72, -74, -77, -76, -78,
  102189. -81, -81, -80, -83, -86, -91, -96, -100,
  102190. -105, -110, -999, -999, -999, -999, -999, -999,
  102191. -999, -999, -999, -999, -999, -999, -999, -999},
  102192. { -28, -28, -28, -28, -28, -28, -28, -28,
  102193. -28, -30, -32, -32, -33, -35, -41, -49,
  102194. -50, -49, -47, -48, -48, -52, -51, -57,
  102195. -65, -61, -59, -61, -64, -69, -70, -74,
  102196. -77, -77, -78, -81, -84, -85, -87, -90,
  102197. -92, -96, -100, -107, -112, -999, -999, -999,
  102198. -999, -999, -999, -999, -999, -999, -999, -999},
  102199. { -19, -19, -19, -19, -19, -19, -19, -19,
  102200. -20, -21, -23, -27, -30, -35, -36, -41,
  102201. -46, -44, -42, -40, -41, -41, -43, -48,
  102202. -55, -53, -52, -53, -56, -59, -58, -60,
  102203. -67, -66, -69, -71, -72, -75, -79, -81,
  102204. -84, -87, -90, -93, -97, -101, -107, -114,
  102205. -999, -999, -999, -999, -999, -999, -999, -999},
  102206. { -9, -9, -9, -9, -9, -9, -9, -9,
  102207. -11, -12, -12, -15, -16, -20, -23, -30,
  102208. -37, -34, -33, -34, -31, -32, -32, -38,
  102209. -47, -44, -41, -40, -47, -49, -46, -46,
  102210. -58, -50, -50, -54, -58, -62, -64, -67,
  102211. -67, -70, -72, -76, -79, -83, -87, -91,
  102212. -96, -100, -104, -110, -999, -999, -999, -999}},
  102213. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102214. -62, -62, -63, -64, -66, -67, -66, -68,
  102215. -75, -72, -76, -75, -76, -78, -79, -82,
  102216. -84, -85, -90, -94, -101, -110, -999, -999,
  102217. -999, -999, -999, -999, -999, -999, -999, -999,
  102218. -999, -999, -999, -999, -999, -999, -999, -999,
  102219. -999, -999, -999, -999, -999, -999, -999, -999},
  102220. { -59, -59, -59, -59, -59, -59, -59, -59,
  102221. -59, -59, -59, -60, -60, -61, -63, -66,
  102222. -71, -68, -70, -70, -71, -72, -72, -75,
  102223. -81, -78, -79, -82, -83, -86, -90, -97,
  102224. -103, -113, -999, -999, -999, -999, -999, -999,
  102225. -999, -999, -999, -999, -999, -999, -999, -999,
  102226. -999, -999, -999, -999, -999, -999, -999, -999},
  102227. { -53, -53, -53, -53, -53, -53, -53, -53,
  102228. -53, -54, -55, -57, -56, -57, -55, -61,
  102229. -65, -60, -60, -62, -63, -63, -66, -68,
  102230. -74, -73, -75, -75, -78, -80, -80, -82,
  102231. -85, -90, -96, -101, -108, -999, -999, -999,
  102232. -999, -999, -999, -999, -999, -999, -999, -999,
  102233. -999, -999, -999, -999, -999, -999, -999, -999},
  102234. { -46, -46, -46, -46, -46, -46, -46, -46,
  102235. -46, -46, -47, -47, -47, -47, -48, -51,
  102236. -57, -51, -49, -50, -51, -53, -54, -59,
  102237. -66, -60, -62, -67, -67, -70, -72, -75,
  102238. -76, -78, -81, -85, -88, -94, -97, -104,
  102239. -112, -999, -999, -999, -999, -999, -999, -999,
  102240. -999, -999, -999, -999, -999, -999, -999, -999},
  102241. { -36, -36, -36, -36, -36, -36, -36, -36,
  102242. -39, -41, -42, -42, -39, -38, -41, -43,
  102243. -52, -44, -40, -39, -37, -37, -40, -47,
  102244. -54, -50, -48, -50, -55, -61, -59, -62,
  102245. -66, -66, -66, -69, -69, -73, -74, -74,
  102246. -75, -77, -79, -82, -87, -91, -95, -100,
  102247. -108, -115, -999, -999, -999, -999, -999, -999},
  102248. { -28, -26, -24, -22, -20, -20, -23, -29,
  102249. -30, -31, -28, -27, -28, -28, -28, -35,
  102250. -40, -33, -32, -29, -30, -30, -30, -37,
  102251. -45, -41, -37, -38, -45, -47, -47, -48,
  102252. -53, -49, -48, -50, -49, -49, -51, -52,
  102253. -58, -56, -57, -56, -60, -61, -62, -70,
  102254. -72, -74, -78, -83, -88, -93, -100, -106}},
  102255. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102256. -999, -110, -105, -100, -95, -91, -87, -83,
  102257. -80, -78, -76, -78, -78, -81, -83, -85,
  102258. -86, -85, -86, -87, -90, -97, -107, -999,
  102259. -999, -999, -999, -999, -999, -999, -999, -999,
  102260. -999, -999, -999, -999, -999, -999, -999, -999,
  102261. -999, -999, -999, -999, -999, -999, -999, -999},
  102262. {-999, -999, -999, -110, -105, -100, -95, -90,
  102263. -85, -81, -77, -73, -70, -67, -67, -68,
  102264. -75, -73, -70, -69, -70, -72, -75, -79,
  102265. -84, -83, -84, -86, -88, -89, -89, -93,
  102266. -98, -105, -112, -999, -999, -999, -999, -999,
  102267. -999, -999, -999, -999, -999, -999, -999, -999,
  102268. -999, -999, -999, -999, -999, -999, -999, -999},
  102269. {-105, -100, -95, -90, -85, -80, -76, -71,
  102270. -68, -68, -65, -63, -63, -62, -62, -64,
  102271. -65, -64, -61, -62, -63, -64, -66, -68,
  102272. -73, -73, -74, -75, -76, -81, -83, -85,
  102273. -88, -89, -92, -95, -100, -108, -999, -999,
  102274. -999, -999, -999, -999, -999, -999, -999, -999,
  102275. -999, -999, -999, -999, -999, -999, -999, -999},
  102276. { -80, -75, -71, -68, -65, -63, -62, -61,
  102277. -61, -61, -61, -59, -56, -57, -53, -50,
  102278. -58, -52, -50, -50, -52, -53, -54, -58,
  102279. -67, -63, -67, -68, -72, -75, -78, -80,
  102280. -81, -81, -82, -85, -89, -90, -93, -97,
  102281. -101, -107, -114, -999, -999, -999, -999, -999,
  102282. -999, -999, -999, -999, -999, -999, -999, -999},
  102283. { -65, -61, -59, -57, -56, -55, -55, -56,
  102284. -56, -57, -55, -53, -52, -47, -44, -44,
  102285. -50, -44, -41, -39, -39, -42, -40, -46,
  102286. -51, -49, -50, -53, -54, -63, -60, -61,
  102287. -62, -66, -66, -66, -70, -73, -74, -75,
  102288. -76, -75, -79, -85, -89, -91, -96, -102,
  102289. -110, -999, -999, -999, -999, -999, -999, -999},
  102290. { -52, -50, -49, -49, -48, -48, -48, -49,
  102291. -50, -50, -49, -46, -43, -39, -35, -33,
  102292. -38, -36, -32, -29, -32, -32, -32, -35,
  102293. -44, -39, -38, -38, -46, -50, -45, -46,
  102294. -53, -50, -50, -50, -54, -54, -53, -53,
  102295. -56, -57, -59, -66, -70, -72, -74, -79,
  102296. -83, -85, -90, -97, -114, -999, -999, -999}},
  102297. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102298. -100, -95, -90, -86, -80, -75, -75, -79,
  102299. -80, -79, -80, -81, -82, -88, -95, -103,
  102300. -110, -999, -999, -999, -999, -999, -999, -999,
  102301. -999, -999, -999, -999, -999, -999, -999, -999,
  102302. -999, -999, -999, -999, -999, -999, -999, -999,
  102303. -999, -999, -999, -999, -999, -999, -999, -999},
  102304. {-999, -999, -999, -999, -108, -103, -98, -93,
  102305. -88, -83, -79, -78, -75, -71, -67, -68,
  102306. -73, -73, -72, -73, -75, -77, -80, -82,
  102307. -88, -93, -100, -107, -114, -999, -999, -999,
  102308. -999, -999, -999, -999, -999, -999, -999, -999,
  102309. -999, -999, -999, -999, -999, -999, -999, -999,
  102310. -999, -999, -999, -999, -999, -999, -999, -999},
  102311. {-999, -999, -999, -110, -105, -101, -96, -90,
  102312. -86, -81, -77, -73, -69, -66, -61, -62,
  102313. -66, -64, -62, -65, -66, -70, -72, -76,
  102314. -81, -80, -84, -90, -95, -102, -110, -999,
  102315. -999, -999, -999, -999, -999, -999, -999, -999,
  102316. -999, -999, -999, -999, -999, -999, -999, -999,
  102317. -999, -999, -999, -999, -999, -999, -999, -999},
  102318. {-999, -999, -999, -107, -103, -97, -92, -88,
  102319. -83, -79, -74, -70, -66, -59, -53, -58,
  102320. -62, -55, -54, -54, -54, -58, -61, -62,
  102321. -72, -70, -72, -75, -78, -80, -81, -80,
  102322. -83, -83, -88, -93, -100, -107, -115, -999,
  102323. -999, -999, -999, -999, -999, -999, -999, -999,
  102324. -999, -999, -999, -999, -999, -999, -999, -999},
  102325. {-999, -999, -999, -105, -100, -95, -90, -85,
  102326. -80, -75, -70, -66, -62, -56, -48, -44,
  102327. -48, -46, -46, -43, -46, -48, -48, -51,
  102328. -58, -58, -59, -60, -62, -62, -61, -61,
  102329. -65, -64, -65, -68, -70, -74, -75, -78,
  102330. -81, -86, -95, -110, -999, -999, -999, -999,
  102331. -999, -999, -999, -999, -999, -999, -999, -999},
  102332. {-999, -999, -105, -100, -95, -90, -85, -80,
  102333. -75, -70, -65, -61, -55, -49, -39, -33,
  102334. -40, -35, -32, -38, -40, -33, -35, -37,
  102335. -46, -41, -45, -44, -46, -42, -45, -46,
  102336. -52, -50, -50, -50, -54, -54, -55, -57,
  102337. -62, -64, -66, -68, -70, -76, -81, -90,
  102338. -100, -110, -999, -999, -999, -999, -999, -999}},
  102339. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102340. -105, -98, -90, -85, -82, -83, -80, -78,
  102341. -84, -79, -80, -83, -87, -89, -91, -93,
  102342. -99, -106, -117, -999, -999, -999, -999, -999,
  102343. -999, -999, -999, -999, -999, -999, -999, -999,
  102344. -999, -999, -999, -999, -999, -999, -999, -999,
  102345. -999, -999, -999, -999, -999, -999, -999, -999},
  102346. {-999, -999, -999, -999, -999, -999, -999, -999,
  102347. -105, -98, -90, -85, -80, -75, -70, -68,
  102348. -74, -72, -74, -77, -80, -82, -85, -87,
  102349. -92, -89, -91, -95, -100, -106, -112, -999,
  102350. -999, -999, -999, -999, -999, -999, -999, -999,
  102351. -999, -999, -999, -999, -999, -999, -999, -999,
  102352. -999, -999, -999, -999, -999, -999, -999, -999},
  102353. {-999, -999, -999, -999, -999, -999, -999, -999,
  102354. -105, -98, -90, -83, -75, -71, -63, -64,
  102355. -67, -62, -64, -67, -70, -73, -77, -81,
  102356. -84, -83, -85, -89, -90, -93, -98, -104,
  102357. -109, -114, -999, -999, -999, -999, -999, -999,
  102358. -999, -999, -999, -999, -999, -999, -999, -999,
  102359. -999, -999, -999, -999, -999, -999, -999, -999},
  102360. {-999, -999, -999, -999, -999, -999, -999, -999,
  102361. -103, -96, -88, -81, -75, -68, -58, -54,
  102362. -56, -54, -56, -56, -58, -60, -63, -66,
  102363. -74, -69, -72, -72, -75, -74, -77, -81,
  102364. -81, -82, -84, -87, -93, -96, -99, -104,
  102365. -110, -999, -999, -999, -999, -999, -999, -999,
  102366. -999, -999, -999, -999, -999, -999, -999, -999},
  102367. {-999, -999, -999, -999, -999, -108, -102, -96,
  102368. -91, -85, -80, -74, -68, -60, -51, -46,
  102369. -48, -46, -43, -45, -47, -47, -49, -48,
  102370. -56, -53, -55, -58, -57, -63, -58, -60,
  102371. -66, -64, -67, -70, -70, -74, -77, -84,
  102372. -86, -89, -91, -93, -94, -101, -109, -118,
  102373. -999, -999, -999, -999, -999, -999, -999, -999},
  102374. {-999, -999, -999, -108, -103, -98, -93, -88,
  102375. -83, -78, -73, -68, -60, -53, -44, -35,
  102376. -38, -38, -34, -34, -36, -40, -41, -44,
  102377. -51, -45, -46, -47, -46, -54, -50, -49,
  102378. -50, -50, -50, -51, -54, -57, -58, -60,
  102379. -66, -66, -66, -64, -65, -68, -77, -82,
  102380. -87, -95, -110, -999, -999, -999, -999, -999}},
  102381. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102382. -107, -102, -97, -92, -87, -83, -78, -75,
  102383. -82, -79, -83, -85, -89, -92, -95, -98,
  102384. -101, -105, -109, -113, -999, -999, -999, -999,
  102385. -999, -999, -999, -999, -999, -999, -999, -999,
  102386. -999, -999, -999, -999, -999, -999, -999, -999,
  102387. -999, -999, -999, -999, -999, -999, -999, -999},
  102388. {-999, -999, -999, -999, -999, -999, -999, -106,
  102389. -100, -95, -90, -86, -81, -78, -74, -69,
  102390. -74, -74, -76, -79, -83, -84, -86, -89,
  102391. -92, -97, -93, -100, -103, -107, -110, -999,
  102392. -999, -999, -999, -999, -999, -999, -999, -999,
  102393. -999, -999, -999, -999, -999, -999, -999, -999,
  102394. -999, -999, -999, -999, -999, -999, -999, -999},
  102395. {-999, -999, -999, -999, -999, -999, -106, -100,
  102396. -95, -90, -87, -83, -80, -75, -69, -60,
  102397. -66, -66, -68, -70, -74, -78, -79, -81,
  102398. -81, -83, -84, -87, -93, -96, -99, -103,
  102399. -107, -110, -999, -999, -999, -999, -999, -999,
  102400. -999, -999, -999, -999, -999, -999, -999, -999,
  102401. -999, -999, -999, -999, -999, -999, -999, -999},
  102402. {-999, -999, -999, -999, -999, -108, -103, -98,
  102403. -93, -89, -85, -82, -78, -71, -62, -55,
  102404. -58, -58, -54, -54, -55, -59, -61, -62,
  102405. -70, -66, -66, -67, -70, -72, -75, -78,
  102406. -84, -84, -84, -88, -91, -90, -95, -98,
  102407. -102, -103, -106, -110, -999, -999, -999, -999,
  102408. -999, -999, -999, -999, -999, -999, -999, -999},
  102409. {-999, -999, -999, -999, -108, -103, -98, -94,
  102410. -90, -87, -82, -79, -73, -67, -58, -47,
  102411. -50, -45, -41, -45, -48, -44, -44, -49,
  102412. -54, -51, -48, -47, -49, -50, -51, -57,
  102413. -58, -60, -63, -69, -70, -69, -71, -74,
  102414. -78, -82, -90, -95, -101, -105, -110, -999,
  102415. -999, -999, -999, -999, -999, -999, -999, -999},
  102416. {-999, -999, -999, -105, -101, -97, -93, -90,
  102417. -85, -80, -77, -72, -65, -56, -48, -37,
  102418. -40, -36, -34, -40, -50, -47, -38, -41,
  102419. -47, -38, -35, -39, -38, -43, -40, -45,
  102420. -50, -45, -44, -47, -50, -55, -48, -48,
  102421. -52, -66, -70, -76, -82, -90, -97, -105,
  102422. -110, -999, -999, -999, -999, -999, -999, -999}},
  102423. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102424. -999, -108, -103, -98, -93, -86, -79, -76,
  102425. -83, -81, -85, -87, -89, -93, -98, -102,
  102426. -107, -112, -999, -999, -999, -999, -999, -999,
  102427. -999, -999, -999, -999, -999, -999, -999, -999,
  102428. -999, -999, -999, -999, -999, -999, -999, -999,
  102429. -999, -999, -999, -999, -999, -999, -999, -999},
  102430. {-999, -999, -999, -999, -999, -999, -999, -999,
  102431. -999, -108, -103, -98, -93, -86, -79, -71,
  102432. -77, -74, -77, -79, -81, -84, -85, -90,
  102433. -92, -93, -92, -98, -101, -108, -112, -999,
  102434. -999, -999, -999, -999, -999, -999, -999, -999,
  102435. -999, -999, -999, -999, -999, -999, -999, -999,
  102436. -999, -999, -999, -999, -999, -999, -999, -999},
  102437. {-999, -999, -999, -999, -999, -999, -999, -999,
  102438. -108, -103, -98, -93, -87, -78, -68, -65,
  102439. -66, -62, -65, -67, -70, -73, -75, -78,
  102440. -82, -82, -83, -84, -91, -93, -98, -102,
  102441. -106, -110, -999, -999, -999, -999, -999, -999,
  102442. -999, -999, -999, -999, -999, -999, -999, -999,
  102443. -999, -999, -999, -999, -999, -999, -999, -999},
  102444. {-999, -999, -999, -999, -999, -999, -999, -999,
  102445. -105, -100, -95, -90, -82, -74, -62, -57,
  102446. -58, -56, -51, -52, -52, -54, -54, -58,
  102447. -66, -59, -60, -63, -66, -69, -73, -79,
  102448. -83, -84, -80, -81, -81, -82, -88, -92,
  102449. -98, -105, -113, -999, -999, -999, -999, -999,
  102450. -999, -999, -999, -999, -999, -999, -999, -999},
  102451. {-999, -999, -999, -999, -999, -999, -999, -107,
  102452. -102, -97, -92, -84, -79, -69, -57, -47,
  102453. -52, -47, -44, -45, -50, -52, -42, -42,
  102454. -53, -43, -43, -48, -51, -56, -55, -52,
  102455. -57, -59, -61, -62, -67, -71, -78, -83,
  102456. -86, -94, -98, -103, -110, -999, -999, -999,
  102457. -999, -999, -999, -999, -999, -999, -999, -999},
  102458. {-999, -999, -999, -999, -999, -999, -105, -100,
  102459. -95, -90, -84, -78, -70, -61, -51, -41,
  102460. -40, -38, -40, -46, -52, -51, -41, -40,
  102461. -46, -40, -38, -38, -41, -46, -41, -46,
  102462. -47, -43, -43, -45, -41, -45, -56, -67,
  102463. -68, -83, -87, -90, -95, -102, -107, -113,
  102464. -999, -999, -999, -999, -999, -999, -999, -999}},
  102465. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102466. -999, -109, -105, -101, -96, -91, -84, -77,
  102467. -82, -82, -85, -89, -94, -100, -106, -110,
  102468. -999, -999, -999, -999, -999, -999, -999, -999,
  102469. -999, -999, -999, -999, -999, -999, -999, -999,
  102470. -999, -999, -999, -999, -999, -999, -999, -999,
  102471. -999, -999, -999, -999, -999, -999, -999, -999},
  102472. {-999, -999, -999, -999, -999, -999, -999, -999,
  102473. -999, -106, -103, -98, -92, -85, -80, -71,
  102474. -75, -72, -76, -80, -84, -86, -89, -93,
  102475. -100, -107, -113, -999, -999, -999, -999, -999,
  102476. -999, -999, -999, -999, -999, -999, -999, -999,
  102477. -999, -999, -999, -999, -999, -999, -999, -999,
  102478. -999, -999, -999, -999, -999, -999, -999, -999},
  102479. {-999, -999, -999, -999, -999, -999, -999, -107,
  102480. -104, -101, -97, -92, -88, -84, -80, -64,
  102481. -66, -63, -64, -66, -69, -73, -77, -83,
  102482. -83, -86, -91, -98, -104, -111, -999, -999,
  102483. -999, -999, -999, -999, -999, -999, -999, -999,
  102484. -999, -999, -999, -999, -999, -999, -999, -999,
  102485. -999, -999, -999, -999, -999, -999, -999, -999},
  102486. {-999, -999, -999, -999, -999, -999, -999, -107,
  102487. -104, -101, -97, -92, -90, -84, -74, -57,
  102488. -58, -52, -55, -54, -50, -52, -50, -52,
  102489. -63, -62, -69, -76, -77, -78, -78, -79,
  102490. -82, -88, -94, -100, -106, -111, -999, -999,
  102491. -999, -999, -999, -999, -999, -999, -999, -999,
  102492. -999, -999, -999, -999, -999, -999, -999, -999},
  102493. {-999, -999, -999, -999, -999, -999, -106, -102,
  102494. -98, -95, -90, -85, -83, -78, -70, -50,
  102495. -50, -41, -44, -49, -47, -50, -50, -44,
  102496. -55, -46, -47, -48, -48, -54, -49, -49,
  102497. -58, -62, -71, -81, -87, -92, -97, -102,
  102498. -108, -114, -999, -999, -999, -999, -999, -999,
  102499. -999, -999, -999, -999, -999, -999, -999, -999},
  102500. {-999, -999, -999, -999, -999, -999, -106, -102,
  102501. -98, -95, -90, -85, -83, -78, -70, -45,
  102502. -43, -41, -47, -50, -51, -50, -49, -45,
  102503. -47, -41, -44, -41, -39, -43, -38, -37,
  102504. -40, -41, -44, -50, -58, -65, -73, -79,
  102505. -85, -92, -97, -101, -105, -109, -113, -999,
  102506. -999, -999, -999, -999, -999, -999, -999, -999}},
  102507. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102508. -999, -999, -999, -107, -100, -95, -87, -81,
  102509. -85, -83, -88, -93, -100, -107, -114, -999,
  102510. -999, -999, -999, -999, -999, -999, -999, -999,
  102511. -999, -999, -999, -999, -999, -999, -999, -999,
  102512. -999, -999, -999, -999, -999, -999, -999, -999,
  102513. -999, -999, -999, -999, -999, -999, -999, -999},
  102514. {-999, -999, -999, -999, -999, -999, -999, -999,
  102515. -999, -999, -107, -101, -95, -88, -83, -76,
  102516. -73, -72, -79, -84, -90, -95, -100, -105,
  102517. -110, -115, -999, -999, -999, -999, -999, -999,
  102518. -999, -999, -999, -999, -999, -999, -999, -999,
  102519. -999, -999, -999, -999, -999, -999, -999, -999,
  102520. -999, -999, -999, -999, -999, -999, -999, -999},
  102521. {-999, -999, -999, -999, -999, -999, -999, -999,
  102522. -999, -999, -104, -98, -92, -87, -81, -70,
  102523. -65, -62, -67, -71, -74, -80, -85, -91,
  102524. -95, -99, -103, -108, -111, -114, -999, -999,
  102525. -999, -999, -999, -999, -999, -999, -999, -999,
  102526. -999, -999, -999, -999, -999, -999, -999, -999,
  102527. -999, -999, -999, -999, -999, -999, -999, -999},
  102528. {-999, -999, -999, -999, -999, -999, -999, -999,
  102529. -999, -999, -103, -97, -90, -85, -76, -60,
  102530. -56, -54, -60, -62, -61, -56, -63, -65,
  102531. -73, -74, -77, -75, -78, -81, -86, -87,
  102532. -88, -91, -94, -98, -103, -110, -999, -999,
  102533. -999, -999, -999, -999, -999, -999, -999, -999,
  102534. -999, -999, -999, -999, -999, -999, -999, -999},
  102535. {-999, -999, -999, -999, -999, -999, -999, -105,
  102536. -100, -97, -92, -86, -81, -79, -70, -57,
  102537. -51, -47, -51, -58, -60, -56, -53, -50,
  102538. -58, -52, -50, -50, -53, -55, -64, -69,
  102539. -71, -85, -82, -78, -81, -85, -95, -102,
  102540. -112, -999, -999, -999, -999, -999, -999, -999,
  102541. -999, -999, -999, -999, -999, -999, -999, -999},
  102542. {-999, -999, -999, -999, -999, -999, -999, -105,
  102543. -100, -97, -92, -85, -83, -79, -72, -49,
  102544. -40, -43, -43, -54, -56, -51, -50, -40,
  102545. -43, -38, -36, -35, -37, -38, -37, -44,
  102546. -54, -60, -57, -60, -70, -75, -84, -92,
  102547. -103, -112, -999, -999, -999, -999, -999, -999,
  102548. -999, -999, -999, -999, -999, -999, -999, -999}},
  102549. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102550. -999, -999, -999, -110, -102, -95, -89, -82,
  102551. -83, -84, -90, -92, -99, -107, -113, -999,
  102552. -999, -999, -999, -999, -999, -999, -999, -999,
  102553. -999, -999, -999, -999, -999, -999, -999, -999,
  102554. -999, -999, -999, -999, -999, -999, -999, -999,
  102555. -999, -999, -999, -999, -999, -999, -999, -999},
  102556. {-999, -999, -999, -999, -999, -999, -999, -999,
  102557. -999, -999, -107, -101, -95, -89, -83, -72,
  102558. -74, -78, -85, -88, -88, -90, -92, -98,
  102559. -105, -111, -999, -999, -999, -999, -999, -999,
  102560. -999, -999, -999, -999, -999, -999, -999, -999,
  102561. -999, -999, -999, -999, -999, -999, -999, -999,
  102562. -999, -999, -999, -999, -999, -999, -999, -999},
  102563. {-999, -999, -999, -999, -999, -999, -999, -999,
  102564. -999, -109, -103, -97, -93, -87, -81, -70,
  102565. -70, -67, -75, -73, -76, -79, -81, -83,
  102566. -88, -89, -97, -103, -110, -999, -999, -999,
  102567. -999, -999, -999, -999, -999, -999, -999, -999,
  102568. -999, -999, -999, -999, -999, -999, -999, -999,
  102569. -999, -999, -999, -999, -999, -999, -999, -999},
  102570. {-999, -999, -999, -999, -999, -999, -999, -999,
  102571. -999, -107, -100, -94, -88, -83, -75, -63,
  102572. -59, -59, -63, -66, -60, -62, -67, -67,
  102573. -77, -76, -81, -88, -86, -92, -96, -102,
  102574. -109, -116, -999, -999, -999, -999, -999, -999,
  102575. -999, -999, -999, -999, -999, -999, -999, -999,
  102576. -999, -999, -999, -999, -999, -999, -999, -999},
  102577. {-999, -999, -999, -999, -999, -999, -999, -999,
  102578. -999, -105, -98, -92, -86, -81, -73, -56,
  102579. -52, -47, -55, -60, -58, -52, -51, -45,
  102580. -49, -50, -53, -54, -61, -71, -70, -69,
  102581. -78, -79, -87, -90, -96, -104, -112, -999,
  102582. -999, -999, -999, -999, -999, -999, -999, -999,
  102583. -999, -999, -999, -999, -999, -999, -999, -999},
  102584. {-999, -999, -999, -999, -999, -999, -999, -999,
  102585. -999, -103, -96, -90, -86, -78, -70, -51,
  102586. -42, -47, -48, -55, -54, -54, -53, -42,
  102587. -35, -28, -33, -38, -37, -44, -47, -49,
  102588. -54, -63, -68, -78, -82, -89, -94, -99,
  102589. -104, -109, -114, -999, -999, -999, -999, -999,
  102590. -999, -999, -999, -999, -999, -999, -999, -999}},
  102591. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102592. -999, -999, -999, -999, -110, -100, -90, -79,
  102593. -85, -81, -82, -82, -89, -94, -99, -103,
  102594. -109, -115, -999, -999, -999, -999, -999, -999,
  102595. -999, -999, -999, -999, -999, -999, -999, -999,
  102596. -999, -999, -999, -999, -999, -999, -999, -999,
  102597. -999, -999, -999, -999, -999, -999, -999, -999},
  102598. {-999, -999, -999, -999, -999, -999, -999, -999,
  102599. -999, -999, -999, -999, -105, -97, -85, -72,
  102600. -74, -70, -70, -70, -76, -85, -91, -93,
  102601. -97, -103, -109, -115, -999, -999, -999, -999,
  102602. -999, -999, -999, -999, -999, -999, -999, -999,
  102603. -999, -999, -999, -999, -999, -999, -999, -999,
  102604. -999, -999, -999, -999, -999, -999, -999, -999},
  102605. {-999, -999, -999, -999, -999, -999, -999, -999,
  102606. -999, -999, -999, -999, -112, -93, -81, -68,
  102607. -62, -60, -60, -57, -63, -70, -77, -82,
  102608. -90, -93, -98, -104, -109, -113, -999, -999,
  102609. -999, -999, -999, -999, -999, -999, -999, -999,
  102610. -999, -999, -999, -999, -999, -999, -999, -999,
  102611. -999, -999, -999, -999, -999, -999, -999, -999},
  102612. {-999, -999, -999, -999, -999, -999, -999, -999,
  102613. -999, -999, -999, -113, -100, -93, -84, -63,
  102614. -58, -48, -53, -54, -52, -52, -57, -64,
  102615. -66, -76, -83, -81, -85, -85, -90, -95,
  102616. -98, -101, -103, -106, -108, -111, -999, -999,
  102617. -999, -999, -999, -999, -999, -999, -999, -999,
  102618. -999, -999, -999, -999, -999, -999, -999, -999},
  102619. {-999, -999, -999, -999, -999, -999, -999, -999,
  102620. -999, -999, -999, -105, -95, -86, -74, -53,
  102621. -50, -38, -43, -49, -43, -42, -39, -39,
  102622. -46, -52, -57, -56, -72, -69, -74, -81,
  102623. -87, -92, -94, -97, -99, -102, -105, -108,
  102624. -999, -999, -999, -999, -999, -999, -999, -999,
  102625. -999, -999, -999, -999, -999, -999, -999, -999},
  102626. {-999, -999, -999, -999, -999, -999, -999, -999,
  102627. -999, -999, -108, -99, -90, -76, -66, -45,
  102628. -43, -41, -44, -47, -43, -47, -40, -30,
  102629. -31, -31, -39, -33, -40, -41, -43, -53,
  102630. -59, -70, -73, -77, -79, -82, -84, -87,
  102631. -999, -999, -999, -999, -999, -999, -999, -999,
  102632. -999, -999, -999, -999, -999, -999, -999, -999}},
  102633. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102634. -999, -999, -999, -999, -999, -110, -91, -76,
  102635. -75, -85, -93, -98, -104, -110, -999, -999,
  102636. -999, -999, -999, -999, -999, -999, -999, -999,
  102637. -999, -999, -999, -999, -999, -999, -999, -999,
  102638. -999, -999, -999, -999, -999, -999, -999, -999,
  102639. -999, -999, -999, -999, -999, -999, -999, -999},
  102640. {-999, -999, -999, -999, -999, -999, -999, -999,
  102641. -999, -999, -999, -999, -999, -110, -91, -70,
  102642. -70, -75, -86, -89, -94, -98, -101, -106,
  102643. -110, -999, -999, -999, -999, -999, -999, -999,
  102644. -999, -999, -999, -999, -999, -999, -999, -999,
  102645. -999, -999, -999, -999, -999, -999, -999, -999,
  102646. -999, -999, -999, -999, -999, -999, -999, -999},
  102647. {-999, -999, -999, -999, -999, -999, -999, -999,
  102648. -999, -999, -999, -999, -110, -95, -80, -60,
  102649. -65, -64, -74, -83, -88, -91, -95, -99,
  102650. -103, -107, -110, -999, -999, -999, -999, -999,
  102651. -999, -999, -999, -999, -999, -999, -999, -999,
  102652. -999, -999, -999, -999, -999, -999, -999, -999,
  102653. -999, -999, -999, -999, -999, -999, -999, -999},
  102654. {-999, -999, -999, -999, -999, -999, -999, -999,
  102655. -999, -999, -999, -999, -110, -95, -80, -58,
  102656. -55, -49, -66, -68, -71, -78, -78, -80,
  102657. -88, -85, -89, -97, -100, -105, -110, -999,
  102658. -999, -999, -999, -999, -999, -999, -999, -999,
  102659. -999, -999, -999, -999, -999, -999, -999, -999,
  102660. -999, -999, -999, -999, -999, -999, -999, -999},
  102661. {-999, -999, -999, -999, -999, -999, -999, -999,
  102662. -999, -999, -999, -999, -110, -95, -80, -53,
  102663. -52, -41, -59, -59, -49, -58, -56, -63,
  102664. -86, -79, -90, -93, -98, -103, -107, -112,
  102665. -999, -999, -999, -999, -999, -999, -999, -999,
  102666. -999, -999, -999, -999, -999, -999, -999, -999,
  102667. -999, -999, -999, -999, -999, -999, -999, -999},
  102668. {-999, -999, -999, -999, -999, -999, -999, -999,
  102669. -999, -999, -999, -110, -97, -91, -73, -45,
  102670. -40, -33, -53, -61, -49, -54, -50, -50,
  102671. -60, -52, -67, -74, -81, -92, -96, -100,
  102672. -105, -110, -999, -999, -999, -999, -999, -999,
  102673. -999, -999, -999, -999, -999, -999, -999, -999,
  102674. -999, -999, -999, -999, -999, -999, -999, -999}},
  102675. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102676. -999, -999, -999, -113, -106, -99, -92, -77,
  102677. -80, -88, -97, -106, -115, -999, -999, -999,
  102678. -999, -999, -999, -999, -999, -999, -999, -999,
  102679. -999, -999, -999, -999, -999, -999, -999, -999,
  102680. -999, -999, -999, -999, -999, -999, -999, -999,
  102681. -999, -999, -999, -999, -999, -999, -999, -999},
  102682. {-999, -999, -999, -999, -999, -999, -999, -999,
  102683. -999, -999, -116, -109, -102, -95, -89, -74,
  102684. -72, -88, -87, -95, -102, -109, -116, -999,
  102685. -999, -999, -999, -999, -999, -999, -999, -999,
  102686. -999, -999, -999, -999, -999, -999, -999, -999,
  102687. -999, -999, -999, -999, -999, -999, -999, -999,
  102688. -999, -999, -999, -999, -999, -999, -999, -999},
  102689. {-999, -999, -999, -999, -999, -999, -999, -999,
  102690. -999, -999, -116, -109, -102, -95, -89, -75,
  102691. -66, -74, -77, -78, -86, -87, -90, -96,
  102692. -105, -115, -999, -999, -999, -999, -999, -999,
  102693. -999, -999, -999, -999, -999, -999, -999, -999,
  102694. -999, -999, -999, -999, -999, -999, -999, -999,
  102695. -999, -999, -999, -999, -999, -999, -999, -999},
  102696. {-999, -999, -999, -999, -999, -999, -999, -999,
  102697. -999, -999, -115, -108, -101, -94, -88, -66,
  102698. -56, -61, -70, -65, -78, -72, -83, -84,
  102699. -93, -98, -105, -110, -999, -999, -999, -999,
  102700. -999, -999, -999, -999, -999, -999, -999, -999,
  102701. -999, -999, -999, -999, -999, -999, -999, -999,
  102702. -999, -999, -999, -999, -999, -999, -999, -999},
  102703. {-999, -999, -999, -999, -999, -999, -999, -999,
  102704. -999, -999, -110, -105, -95, -89, -82, -57,
  102705. -52, -52, -59, -56, -59, -58, -69, -67,
  102706. -88, -82, -82, -89, -94, -100, -108, -999,
  102707. -999, -999, -999, -999, -999, -999, -999, -999,
  102708. -999, -999, -999, -999, -999, -999, -999, -999,
  102709. -999, -999, -999, -999, -999, -999, -999, -999},
  102710. {-999, -999, -999, -999, -999, -999, -999, -999,
  102711. -999, -110, -101, -96, -90, -83, -77, -54,
  102712. -43, -38, -50, -48, -52, -48, -42, -42,
  102713. -51, -52, -53, -59, -65, -71, -78, -85,
  102714. -95, -999, -999, -999, -999, -999, -999, -999,
  102715. -999, -999, -999, -999, -999, -999, -999, -999,
  102716. -999, -999, -999, -999, -999, -999, -999, -999}},
  102717. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102718. -999, -999, -999, -999, -120, -105, -86, -68,
  102719. -78, -79, -90, -100, -110, -999, -999, -999,
  102720. -999, -999, -999, -999, -999, -999, -999, -999,
  102721. -999, -999, -999, -999, -999, -999, -999, -999,
  102722. -999, -999, -999, -999, -999, -999, -999, -999,
  102723. -999, -999, -999, -999, -999, -999, -999, -999},
  102724. {-999, -999, -999, -999, -999, -999, -999, -999,
  102725. -999, -999, -999, -999, -120, -105, -86, -66,
  102726. -73, -77, -88, -96, -105, -115, -999, -999,
  102727. -999, -999, -999, -999, -999, -999, -999, -999,
  102728. -999, -999, -999, -999, -999, -999, -999, -999,
  102729. -999, -999, -999, -999, -999, -999, -999, -999,
  102730. -999, -999, -999, -999, -999, -999, -999, -999},
  102731. {-999, -999, -999, -999, -999, -999, -999, -999,
  102732. -999, -999, -999, -120, -105, -92, -80, -61,
  102733. -64, -68, -80, -87, -92, -100, -110, -999,
  102734. -999, -999, -999, -999, -999, -999, -999, -999,
  102735. -999, -999, -999, -999, -999, -999, -999, -999,
  102736. -999, -999, -999, -999, -999, -999, -999, -999,
  102737. -999, -999, -999, -999, -999, -999, -999, -999},
  102738. {-999, -999, -999, -999, -999, -999, -999, -999,
  102739. -999, -999, -999, -120, -104, -91, -79, -52,
  102740. -60, -54, -64, -69, -77, -80, -82, -84,
  102741. -85, -87, -88, -90, -999, -999, -999, -999,
  102742. -999, -999, -999, -999, -999, -999, -999, -999,
  102743. -999, -999, -999, -999, -999, -999, -999, -999,
  102744. -999, -999, -999, -999, -999, -999, -999, -999},
  102745. {-999, -999, -999, -999, -999, -999, -999, -999,
  102746. -999, -999, -999, -118, -100, -87, -77, -49,
  102747. -50, -44, -58, -61, -61, -67, -65, -62,
  102748. -62, -62, -65, -68, -999, -999, -999, -999,
  102749. -999, -999, -999, -999, -999, -999, -999, -999,
  102750. -999, -999, -999, -999, -999, -999, -999, -999,
  102751. -999, -999, -999, -999, -999, -999, -999, -999},
  102752. {-999, -999, -999, -999, -999, -999, -999, -999,
  102753. -999, -999, -999, -115, -98, -84, -62, -49,
  102754. -44, -38, -46, -49, -49, -46, -39, -37,
  102755. -39, -40, -42, -43, -999, -999, -999, -999,
  102756. -999, -999, -999, -999, -999, -999, -999, -999,
  102757. -999, -999, -999, -999, -999, -999, -999, -999,
  102758. -999, -999, -999, -999, -999, -999, -999, -999}},
  102759. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102760. -999, -999, -999, -999, -999, -110, -88, -74,
  102761. -77, -82, -82, -85, -90, -94, -99, -104,
  102762. -999, -999, -999, -999, -999, -999, -999, -999,
  102763. -999, -999, -999, -999, -999, -999, -999, -999,
  102764. -999, -999, -999, -999, -999, -999, -999, -999,
  102765. -999, -999, -999, -999, -999, -999, -999, -999},
  102766. {-999, -999, -999, -999, -999, -999, -999, -999,
  102767. -999, -999, -999, -999, -999, -110, -88, -66,
  102768. -70, -81, -80, -81, -84, -88, -91, -93,
  102769. -999, -999, -999, -999, -999, -999, -999, -999,
  102770. -999, -999, -999, -999, -999, -999, -999, -999,
  102771. -999, -999, -999, -999, -999, -999, -999, -999,
  102772. -999, -999, -999, -999, -999, -999, -999, -999},
  102773. {-999, -999, -999, -999, -999, -999, -999, -999,
  102774. -999, -999, -999, -999, -999, -110, -88, -61,
  102775. -63, -70, -71, -74, -77, -80, -83, -85,
  102776. -999, -999, -999, -999, -999, -999, -999, -999,
  102777. -999, -999, -999, -999, -999, -999, -999, -999,
  102778. -999, -999, -999, -999, -999, -999, -999, -999,
  102779. -999, -999, -999, -999, -999, -999, -999, -999},
  102780. {-999, -999, -999, -999, -999, -999, -999, -999,
  102781. -999, -999, -999, -999, -999, -110, -86, -62,
  102782. -63, -62, -62, -58, -52, -50, -50, -52,
  102783. -54, -999, -999, -999, -999, -999, -999, -999,
  102784. -999, -999, -999, -999, -999, -999, -999, -999,
  102785. -999, -999, -999, -999, -999, -999, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999},
  102787. {-999, -999, -999, -999, -999, -999, -999, -999,
  102788. -999, -999, -999, -999, -118, -108, -84, -53,
  102789. -50, -50, -50, -55, -47, -45, -40, -40,
  102790. -40, -999, -999, -999, -999, -999, -999, -999,
  102791. -999, -999, -999, -999, -999, -999, -999, -999,
  102792. -999, -999, -999, -999, -999, -999, -999, -999,
  102793. -999, -999, -999, -999, -999, -999, -999, -999},
  102794. {-999, -999, -999, -999, -999, -999, -999, -999,
  102795. -999, -999, -999, -999, -118, -100, -73, -43,
  102796. -37, -42, -43, -53, -38, -37, -35, -35,
  102797. -38, -999, -999, -999, -999, -999, -999, -999,
  102798. -999, -999, -999, -999, -999, -999, -999, -999,
  102799. -999, -999, -999, -999, -999, -999, -999, -999,
  102800. -999, -999, -999, -999, -999, -999, -999, -999}},
  102801. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102802. -999, -999, -999, -110, -100, -91, -84, -74,
  102803. -80, -80, -80, -80, -80, -999, -999, -999,
  102804. -999, -999, -999, -999, -999, -999, -999, -999,
  102805. -999, -999, -999, -999, -999, -999, -999, -999,
  102806. -999, -999, -999, -999, -999, -999, -999, -999,
  102807. -999, -999, -999, -999, -999, -999, -999, -999},
  102808. {-999, -999, -999, -999, -999, -999, -999, -999,
  102809. -999, -999, -999, -110, -100, -91, -84, -74,
  102810. -68, -68, -68, -68, -68, -999, -999, -999,
  102811. -999, -999, -999, -999, -999, -999, -999, -999,
  102812. -999, -999, -999, -999, -999, -999, -999, -999,
  102813. -999, -999, -999, -999, -999, -999, -999, -999,
  102814. -999, -999, -999, -999, -999, -999, -999, -999},
  102815. {-999, -999, -999, -999, -999, -999, -999, -999,
  102816. -999, -999, -999, -110, -100, -86, -78, -70,
  102817. -60, -45, -30, -21, -999, -999, -999, -999,
  102818. -999, -999, -999, -999, -999, -999, -999, -999,
  102819. -999, -999, -999, -999, -999, -999, -999, -999,
  102820. -999, -999, -999, -999, -999, -999, -999, -999,
  102821. -999, -999, -999, -999, -999, -999, -999, -999},
  102822. {-999, -999, -999, -999, -999, -999, -999, -999,
  102823. -999, -999, -999, -110, -100, -87, -78, -67,
  102824. -48, -38, -29, -21, -999, -999, -999, -999,
  102825. -999, -999, -999, -999, -999, -999, -999, -999,
  102826. -999, -999, -999, -999, -999, -999, -999, -999,
  102827. -999, -999, -999, -999, -999, -999, -999, -999,
  102828. -999, -999, -999, -999, -999, -999, -999, -999},
  102829. {-999, -999, -999, -999, -999, -999, -999, -999,
  102830. -999, -999, -999, -110, -100, -86, -69, -56,
  102831. -45, -35, -33, -29, -999, -999, -999, -999,
  102832. -999, -999, -999, -999, -999, -999, -999, -999,
  102833. -999, -999, -999, -999, -999, -999, -999, -999,
  102834. -999, -999, -999, -999, -999, -999, -999, -999,
  102835. -999, -999, -999, -999, -999, -999, -999, -999},
  102836. {-999, -999, -999, -999, -999, -999, -999, -999,
  102837. -999, -999, -999, -110, -100, -83, -71, -48,
  102838. -27, -38, -37, -34, -999, -999, -999, -999,
  102839. -999, -999, -999, -999, -999, -999, -999, -999,
  102840. -999, -999, -999, -999, -999, -999, -999, -999,
  102841. -999, -999, -999, -999, -999, -999, -999, -999,
  102842. -999, -999, -999, -999, -999, -999, -999, -999}}
  102843. };
  102844. #endif
  102845. /*** End of inlined file: masking.h ***/
  102846. #define NEGINF -9999.f
  102847. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  102848. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  102849. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  102850. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102851. vorbis_info_psy_global *gi=&ci->psy_g_param;
  102852. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  102853. look->channels=vi->channels;
  102854. look->ampmax=-9999.;
  102855. look->gi=gi;
  102856. return(look);
  102857. }
  102858. void _vp_global_free(vorbis_look_psy_global *look){
  102859. if(look){
  102860. memset(look,0,sizeof(*look));
  102861. _ogg_free(look);
  102862. }
  102863. }
  102864. void _vi_gpsy_free(vorbis_info_psy_global *i){
  102865. if(i){
  102866. memset(i,0,sizeof(*i));
  102867. _ogg_free(i);
  102868. }
  102869. }
  102870. void _vi_psy_free(vorbis_info_psy *i){
  102871. if(i){
  102872. memset(i,0,sizeof(*i));
  102873. _ogg_free(i);
  102874. }
  102875. }
  102876. static void min_curve(float *c,
  102877. float *c2){
  102878. int i;
  102879. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  102880. }
  102881. static void max_curve(float *c,
  102882. float *c2){
  102883. int i;
  102884. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  102885. }
  102886. static void attenuate_curve(float *c,float att){
  102887. int i;
  102888. for(i=0;i<EHMER_MAX;i++)
  102889. c[i]+=att;
  102890. }
  102891. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  102892. float center_boost, float center_decay_rate){
  102893. int i,j,k,m;
  102894. float ath[EHMER_MAX];
  102895. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  102896. float athc[P_LEVELS][EHMER_MAX];
  102897. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  102898. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  102899. memset(workc,0,sizeof(workc));
  102900. for(i=0;i<P_BANDS;i++){
  102901. int ath_offset=i*4;
  102902. for(j=0;j<EHMER_MAX;j++){
  102903. float min=999.;
  102904. for(k=0;k<4;k++)
  102905. if(j+k+ath_offset<MAX_ATH){
  102906. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  102907. }else{
  102908. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  102909. }
  102910. ath[j]=min;
  102911. }
  102912. for(j=0;j<6;j++)
  102913. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  102914. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  102915. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  102916. for(j=0;j<P_LEVELS;j++){
  102917. for(k=0;k<EHMER_MAX;k++){
  102918. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  102919. if(adj<0. && center_boost>0)adj=0.;
  102920. if(adj>0. && center_boost<0)adj=0.;
  102921. workc[i][j][k]+=adj;
  102922. }
  102923. }
  102924. for(j=0;j<P_LEVELS;j++){
  102925. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  102926. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  102927. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  102928. max_curve(athc[j],workc[i][j]);
  102929. }
  102930. for(j=1;j<P_LEVELS;j++){
  102931. min_curve(athc[j],athc[j-1]);
  102932. min_curve(workc[i][j],athc[j]);
  102933. }
  102934. }
  102935. for(i=0;i<P_BANDS;i++){
  102936. int hi_curve,lo_curve,bin;
  102937. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  102938. bin=floor(fromOC(i*.5)/binHz);
  102939. lo_curve= ceil(toOC(bin*binHz+1)*2);
  102940. hi_curve= floor(toOC((bin+1)*binHz)*2);
  102941. if(lo_curve>i)lo_curve=i;
  102942. if(lo_curve<0)lo_curve=0;
  102943. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  102944. for(m=0;m<P_LEVELS;m++){
  102945. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  102946. for(j=0;j<n;j++)brute_buffer[j]=999.;
  102947. for(k=lo_curve;k<=hi_curve;k++){
  102948. int l=0;
  102949. for(j=0;j<EHMER_MAX;j++){
  102950. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  102951. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  102952. if(lo_bin<0)lo_bin=0;
  102953. if(lo_bin>n)lo_bin=n;
  102954. if(lo_bin<l)l=lo_bin;
  102955. if(hi_bin<0)hi_bin=0;
  102956. if(hi_bin>n)hi_bin=n;
  102957. for(;l<hi_bin && l<n;l++)
  102958. if(brute_buffer[l]>workc[k][m][j])
  102959. brute_buffer[l]=workc[k][m][j];
  102960. }
  102961. for(;l<n;l++)
  102962. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  102963. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  102964. }
  102965. if(i+1<P_BANDS){
  102966. int l=0;
  102967. k=i+1;
  102968. for(j=0;j<EHMER_MAX;j++){
  102969. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  102970. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  102971. if(lo_bin<0)lo_bin=0;
  102972. if(lo_bin>n)lo_bin=n;
  102973. if(lo_bin<l)l=lo_bin;
  102974. if(hi_bin<0)hi_bin=0;
  102975. if(hi_bin>n)hi_bin=n;
  102976. for(;l<hi_bin && l<n;l++)
  102977. if(brute_buffer[l]>workc[k][m][j])
  102978. brute_buffer[l]=workc[k][m][j];
  102979. }
  102980. for(;l<n;l++)
  102981. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  102982. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  102983. }
  102984. for(j=0;j<EHMER_MAX;j++){
  102985. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  102986. if(bin<0){
  102987. ret[i][m][j+2]=-999.;
  102988. }else{
  102989. if(bin>=n){
  102990. ret[i][m][j+2]=-999.;
  102991. }else{
  102992. ret[i][m][j+2]=brute_buffer[bin];
  102993. }
  102994. }
  102995. }
  102996. for(j=0;j<EHMER_OFFSET;j++)
  102997. if(ret[i][m][j+2]>-200.f)break;
  102998. ret[i][m][0]=j;
  102999. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103000. if(ret[i][m][j+2]>-200.f)
  103001. break;
  103002. ret[i][m][1]=j;
  103003. }
  103004. }
  103005. return(ret);
  103006. }
  103007. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103008. vorbis_info_psy_global *gi,int n,long rate){
  103009. long i,j,lo=-99,hi=1;
  103010. long maxoc;
  103011. memset(p,0,sizeof(*p));
  103012. p->eighth_octave_lines=gi->eighth_octave_lines;
  103013. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103014. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103015. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103016. p->total_octave_lines=maxoc-p->firstoc+1;
  103017. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103018. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103019. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103020. p->vi=vi;
  103021. p->n=n;
  103022. p->rate=rate;
  103023. p->m_val = 1.;
  103024. if(rate < 26000) p->m_val = 0;
  103025. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103026. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103027. for(i=0,j=0;i<MAX_ATH-1;i++){
  103028. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103029. float base=ATH[i];
  103030. if(j<endpos){
  103031. float delta=(ATH[i+1]-base)/(endpos-j);
  103032. for(;j<endpos && j<n;j++){
  103033. p->ath[j]=base+100.;
  103034. base+=delta;
  103035. }
  103036. }
  103037. }
  103038. for(i=0;i<n;i++){
  103039. float bark=toBARK(rate/(2*n)*i);
  103040. for(;lo+vi->noisewindowlomin<i &&
  103041. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103042. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103043. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103044. p->bark[i]=((lo-1)<<16)+(hi-1);
  103045. }
  103046. for(i=0;i<n;i++)
  103047. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103048. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103049. vi->tone_centerboost,vi->tone_decay);
  103050. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103051. for(i=0;i<P_NOISECURVES;i++)
  103052. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103053. for(i=0;i<n;i++){
  103054. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103055. int inthalfoc;
  103056. float del;
  103057. if(halfoc<0)halfoc=0;
  103058. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103059. inthalfoc=(int)halfoc;
  103060. del=halfoc-inthalfoc;
  103061. for(j=0;j<P_NOISECURVES;j++)
  103062. p->noiseoffset[j][i]=
  103063. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103064. p->vi->noiseoff[j][inthalfoc+1]*del;
  103065. }
  103066. #if 0
  103067. {
  103068. static int ls=0;
  103069. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103070. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103071. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103072. }
  103073. #endif
  103074. }
  103075. void _vp_psy_clear(vorbis_look_psy *p){
  103076. int i,j;
  103077. if(p){
  103078. if(p->ath)_ogg_free(p->ath);
  103079. if(p->octave)_ogg_free(p->octave);
  103080. if(p->bark)_ogg_free(p->bark);
  103081. if(p->tonecurves){
  103082. for(i=0;i<P_BANDS;i++){
  103083. for(j=0;j<P_LEVELS;j++){
  103084. _ogg_free(p->tonecurves[i][j]);
  103085. }
  103086. _ogg_free(p->tonecurves[i]);
  103087. }
  103088. _ogg_free(p->tonecurves);
  103089. }
  103090. if(p->noiseoffset){
  103091. for(i=0;i<P_NOISECURVES;i++){
  103092. _ogg_free(p->noiseoffset[i]);
  103093. }
  103094. _ogg_free(p->noiseoffset);
  103095. }
  103096. memset(p,0,sizeof(*p));
  103097. }
  103098. }
  103099. static void seed_curve(float *seed,
  103100. const float **curves,
  103101. float amp,
  103102. int oc, int n,
  103103. int linesper,float dBoffset){
  103104. int i,post1;
  103105. int seedptr;
  103106. const float *posts,*curve;
  103107. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103108. choice=max(choice,0);
  103109. choice=min(choice,P_LEVELS-1);
  103110. posts=curves[choice];
  103111. curve=posts+2;
  103112. post1=(int)posts[1];
  103113. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103114. for(i=posts[0];i<post1;i++){
  103115. if(seedptr>0){
  103116. float lin=amp+curve[i];
  103117. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103118. }
  103119. seedptr+=linesper;
  103120. if(seedptr>=n)break;
  103121. }
  103122. }
  103123. static void seed_loop(vorbis_look_psy *p,
  103124. const float ***curves,
  103125. const float *f,
  103126. const float *flr,
  103127. float *seed,
  103128. float specmax){
  103129. vorbis_info_psy *vi=p->vi;
  103130. long n=p->n,i;
  103131. float dBoffset=vi->max_curve_dB-specmax;
  103132. for(i=0;i<n;i++){
  103133. float max=f[i];
  103134. long oc=p->octave[i];
  103135. while(i+1<n && p->octave[i+1]==oc){
  103136. i++;
  103137. if(f[i]>max)max=f[i];
  103138. }
  103139. if(max+6.f>flr[i]){
  103140. oc=oc>>p->shiftoc;
  103141. if(oc>=P_BANDS)oc=P_BANDS-1;
  103142. if(oc<0)oc=0;
  103143. seed_curve(seed,
  103144. curves[oc],
  103145. max,
  103146. p->octave[i]-p->firstoc,
  103147. p->total_octave_lines,
  103148. p->eighth_octave_lines,
  103149. dBoffset);
  103150. }
  103151. }
  103152. }
  103153. static void seed_chase(float *seeds, int linesper, long n){
  103154. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103155. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103156. long stack=0;
  103157. long pos=0;
  103158. long i;
  103159. for(i=0;i<n;i++){
  103160. if(stack<2){
  103161. posstack[stack]=i;
  103162. ampstack[stack++]=seeds[i];
  103163. }else{
  103164. while(1){
  103165. if(seeds[i]<ampstack[stack-1]){
  103166. posstack[stack]=i;
  103167. ampstack[stack++]=seeds[i];
  103168. break;
  103169. }else{
  103170. if(i<posstack[stack-1]+linesper){
  103171. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103172. i<posstack[stack-2]+linesper){
  103173. stack--;
  103174. continue;
  103175. }
  103176. }
  103177. posstack[stack]=i;
  103178. ampstack[stack++]=seeds[i];
  103179. break;
  103180. }
  103181. }
  103182. }
  103183. }
  103184. for(i=0;i<stack;i++){
  103185. long endpos;
  103186. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103187. endpos=posstack[i+1];
  103188. }else{
  103189. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103190. discarded in short frames */
  103191. }
  103192. if(endpos>n)endpos=n;
  103193. for(;pos<endpos;pos++)
  103194. seeds[pos]=ampstack[i];
  103195. }
  103196. }
  103197. #include<stdio.h>
  103198. static void max_seeds(vorbis_look_psy *p,
  103199. float *seed,
  103200. float *flr){
  103201. long n=p->total_octave_lines;
  103202. int linesper=p->eighth_octave_lines;
  103203. long linpos=0;
  103204. long pos;
  103205. seed_chase(seed,linesper,n); /* for masking */
  103206. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103207. while(linpos+1<p->n){
  103208. float minV=seed[pos];
  103209. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103210. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103211. while(pos+1<=end){
  103212. pos++;
  103213. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103214. minV=seed[pos];
  103215. }
  103216. end=pos+p->firstoc;
  103217. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103218. if(flr[linpos]<minV)flr[linpos]=minV;
  103219. }
  103220. {
  103221. float minV=seed[p->total_octave_lines-1];
  103222. for(;linpos<p->n;linpos++)
  103223. if(flr[linpos]<minV)flr[linpos]=minV;
  103224. }
  103225. }
  103226. static void bark_noise_hybridmp(int n,const long *b,
  103227. const float *f,
  103228. float *noise,
  103229. const float offset,
  103230. const int fixed){
  103231. float *N=(float*) alloca(n*sizeof(*N));
  103232. float *X=(float*) alloca(n*sizeof(*N));
  103233. float *XX=(float*) alloca(n*sizeof(*N));
  103234. float *Y=(float*) alloca(n*sizeof(*N));
  103235. float *XY=(float*) alloca(n*sizeof(*N));
  103236. float tN, tX, tXX, tY, tXY;
  103237. int i;
  103238. int lo, hi;
  103239. float R, A, B, D;
  103240. float w, x, y;
  103241. tN = tX = tXX = tY = tXY = 0.f;
  103242. y = f[0] + offset;
  103243. if (y < 1.f) y = 1.f;
  103244. w = y * y * .5;
  103245. tN += w;
  103246. tX += w;
  103247. tY += w * y;
  103248. N[0] = tN;
  103249. X[0] = tX;
  103250. XX[0] = tXX;
  103251. Y[0] = tY;
  103252. XY[0] = tXY;
  103253. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103254. y = f[i] + offset;
  103255. if (y < 1.f) y = 1.f;
  103256. w = y * y;
  103257. tN += w;
  103258. tX += w * x;
  103259. tXX += w * x * x;
  103260. tY += w * y;
  103261. tXY += w * x * y;
  103262. N[i] = tN;
  103263. X[i] = tX;
  103264. XX[i] = tXX;
  103265. Y[i] = tY;
  103266. XY[i] = tXY;
  103267. }
  103268. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103269. lo = b[i] >> 16;
  103270. if( lo>=0 ) break;
  103271. hi = b[i] & 0xffff;
  103272. tN = N[hi] + N[-lo];
  103273. tX = X[hi] - X[-lo];
  103274. tXX = XX[hi] + XX[-lo];
  103275. tY = Y[hi] + Y[-lo];
  103276. tXY = XY[hi] - XY[-lo];
  103277. A = tY * tXX - tX * tXY;
  103278. B = tN * tXY - tX * tY;
  103279. D = tN * tXX - tX * tX;
  103280. R = (A + x * B) / D;
  103281. if (R < 0.f)
  103282. R = 0.f;
  103283. noise[i] = R - offset;
  103284. }
  103285. for ( ;; i++, x += 1.f) {
  103286. lo = b[i] >> 16;
  103287. hi = b[i] & 0xffff;
  103288. if(hi>=n)break;
  103289. tN = N[hi] - N[lo];
  103290. tX = X[hi] - X[lo];
  103291. tXX = XX[hi] - XX[lo];
  103292. tY = Y[hi] - Y[lo];
  103293. tXY = XY[hi] - XY[lo];
  103294. A = tY * tXX - tX * tXY;
  103295. B = tN * tXY - tX * tY;
  103296. D = tN * tXX - tX * tX;
  103297. R = (A + x * B) / D;
  103298. if (R < 0.f) R = 0.f;
  103299. noise[i] = R - offset;
  103300. }
  103301. for ( ; i < n; i++, x += 1.f) {
  103302. R = (A + x * B) / D;
  103303. if (R < 0.f) R = 0.f;
  103304. noise[i] = R - offset;
  103305. }
  103306. if (fixed <= 0) return;
  103307. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103308. hi = i + fixed / 2;
  103309. lo = hi - fixed;
  103310. if(lo>=0)break;
  103311. tN = N[hi] + N[-lo];
  103312. tX = X[hi] - X[-lo];
  103313. tXX = XX[hi] + XX[-lo];
  103314. tY = Y[hi] + Y[-lo];
  103315. tXY = XY[hi] - XY[-lo];
  103316. A = tY * tXX - tX * tXY;
  103317. B = tN * tXY - tX * tY;
  103318. D = tN * tXX - tX * tX;
  103319. R = (A + x * B) / D;
  103320. if (R - offset < noise[i]) noise[i] = R - offset;
  103321. }
  103322. for ( ;; i++, x += 1.f) {
  103323. hi = i + fixed / 2;
  103324. lo = hi - fixed;
  103325. if(hi>=n)break;
  103326. tN = N[hi] - N[lo];
  103327. tX = X[hi] - X[lo];
  103328. tXX = XX[hi] - XX[lo];
  103329. tY = Y[hi] - Y[lo];
  103330. tXY = XY[hi] - XY[lo];
  103331. A = tY * tXX - tX * tXY;
  103332. B = tN * tXY - tX * tY;
  103333. D = tN * tXX - tX * tX;
  103334. R = (A + x * B) / D;
  103335. if (R - offset < noise[i]) noise[i] = R - offset;
  103336. }
  103337. for ( ; i < n; i++, x += 1.f) {
  103338. R = (A + x * B) / D;
  103339. if (R - offset < noise[i]) noise[i] = R - offset;
  103340. }
  103341. }
  103342. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103343. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103344. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103345. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103346. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103347. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103348. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103349. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103350. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103351. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103352. 973377.F, 913981.F, 858210.F, 805842.F,
  103353. 756669.F, 710497.F, 667142.F, 626433.F,
  103354. 588208.F, 552316.F, 518613.F, 486967.F,
  103355. 457252.F, 429351.F, 403152.F, 378551.F,
  103356. 355452.F, 333762.F, 313396.F, 294273.F,
  103357. 276316.F, 259455.F, 243623.F, 228757.F,
  103358. 214798.F, 201691.F, 189384.F, 177828.F,
  103359. 166977.F, 156788.F, 147221.F, 138237.F,
  103360. 129802.F, 121881.F, 114444.F, 107461.F,
  103361. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103362. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103363. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103364. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103365. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103366. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103367. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103368. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103369. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103370. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103371. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103372. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103373. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103374. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103375. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103376. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103377. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103378. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103379. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103380. 842.910F, 791.475F, 743.179F, 697.830F,
  103381. 655.249F, 615.265F, 577.722F, 542.469F,
  103382. 509.367F, 478.286F, 449.101F, 421.696F,
  103383. 395.964F, 371.803F, 349.115F, 327.812F,
  103384. 307.809F, 289.026F, 271.390F, 254.830F,
  103385. 239.280F, 224.679F, 210.969F, 198.096F,
  103386. 186.008F, 174.658F, 164.000F, 153.993F,
  103387. 144.596F, 135.773F, 127.488F, 119.708F,
  103388. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103389. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103390. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103391. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103392. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103393. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103394. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103395. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103396. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103397. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103398. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103399. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103400. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103401. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103402. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103403. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103404. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103405. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103406. 1.20790F, 1.13419F, 1.06499F, 1.F
  103407. };
  103408. void _vp_remove_floor(vorbis_look_psy *p,
  103409. float *mdct,
  103410. int *codedflr,
  103411. float *residue,
  103412. int sliding_lowpass){
  103413. int i,n=p->n;
  103414. if(sliding_lowpass>n)sliding_lowpass=n;
  103415. for(i=0;i<sliding_lowpass;i++){
  103416. residue[i]=
  103417. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103418. }
  103419. for(;i<n;i++)
  103420. residue[i]=0.;
  103421. }
  103422. void _vp_noisemask(vorbis_look_psy *p,
  103423. float *logmdct,
  103424. float *logmask){
  103425. int i,n=p->n;
  103426. float *work=(float*) alloca(n*sizeof(*work));
  103427. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103428. 140.,-1);
  103429. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103430. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103431. p->vi->noisewindowfixed);
  103432. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103433. #if 0
  103434. {
  103435. static int seq=0;
  103436. float work2[n];
  103437. for(i=0;i<n;i++){
  103438. work2[i]=logmask[i]+work[i];
  103439. }
  103440. if(seq&1)
  103441. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103442. else
  103443. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103444. if(seq&1)
  103445. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103446. else
  103447. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103448. seq++;
  103449. }
  103450. #endif
  103451. for(i=0;i<n;i++){
  103452. int dB=logmask[i]+.5;
  103453. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103454. if(dB<0)dB=0;
  103455. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103456. }
  103457. }
  103458. void _vp_tonemask(vorbis_look_psy *p,
  103459. float *logfft,
  103460. float *logmask,
  103461. float global_specmax,
  103462. float local_specmax){
  103463. int i,n=p->n;
  103464. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103465. float att=local_specmax+p->vi->ath_adjatt;
  103466. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103467. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103468. for(i=0;i<n;i++)
  103469. logmask[i]=p->ath[i]+att;
  103470. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103471. max_seeds(p,seed,logmask);
  103472. }
  103473. void _vp_offset_and_mix(vorbis_look_psy *p,
  103474. float *noise,
  103475. float *tone,
  103476. int offset_select,
  103477. float *logmask,
  103478. float *mdct,
  103479. float *logmdct){
  103480. int i,n=p->n;
  103481. float de, coeffi, cx;/* AoTuV */
  103482. float toneatt=p->vi->tone_masteratt[offset_select];
  103483. cx = p->m_val;
  103484. for(i=0;i<n;i++){
  103485. float val= noise[i]+p->noiseoffset[offset_select][i];
  103486. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103487. logmask[i]=max(val,tone[i]+toneatt);
  103488. if(offset_select == 1) {
  103489. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103490. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103491. if(val > coeffi){
  103492. de = 1.0-((val-coeffi)*0.005*cx);
  103493. if(de < 0) de = 0.0001;
  103494. }else
  103495. de = 1.0-((val-coeffi)*0.0003*cx);
  103496. mdct[i] *= de;
  103497. }
  103498. }
  103499. }
  103500. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103501. vorbis_info *vi=vd->vi;
  103502. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103503. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103504. int n=ci->blocksizes[vd->W]/2;
  103505. float secs=(float)n/vi->rate;
  103506. amp+=secs*gi->ampmax_att_per_sec;
  103507. if(amp<-9999)amp=-9999;
  103508. return(amp);
  103509. }
  103510. static void couple_lossless(float A, float B,
  103511. float *qA, float *qB){
  103512. int test1=fabs(*qA)>fabs(*qB);
  103513. test1-= fabs(*qA)<fabs(*qB);
  103514. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103515. if(test1==1){
  103516. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103517. }else{
  103518. float temp=*qB;
  103519. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103520. *qA=temp;
  103521. }
  103522. if(*qB>fabs(*qA)*1.9999f){
  103523. *qB= -fabs(*qA)*2.f;
  103524. *qA= -*qA;
  103525. }
  103526. }
  103527. static float hypot_lookup[32]={
  103528. -0.009935, -0.011245, -0.012726, -0.014397,
  103529. -0.016282, -0.018407, -0.020800, -0.023494,
  103530. -0.026522, -0.029923, -0.033737, -0.038010,
  103531. -0.042787, -0.048121, -0.054064, -0.060671,
  103532. -0.068000, -0.076109, -0.085054, -0.094892,
  103533. -0.105675, -0.117451, -0.130260, -0.144134,
  103534. -0.159093, -0.175146, -0.192286, -0.210490,
  103535. -0.229718, -0.249913, -0.271001, -0.292893};
  103536. static void precomputed_couple_point(float premag,
  103537. int floorA,int floorB,
  103538. float *mag, float *ang){
  103539. int test=(floorA>floorB)-1;
  103540. int offset=31-abs(floorA-floorB);
  103541. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103542. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103543. *mag=premag*floormag;
  103544. *ang=0.f;
  103545. }
  103546. static float dipole_hypot(float a, float b){
  103547. if(a>0.){
  103548. if(b>0.)return sqrt(a*a+b*b);
  103549. if(a>-b)return sqrt(a*a-b*b);
  103550. return -sqrt(b*b-a*a);
  103551. }
  103552. if(b<0.)return -sqrt(a*a+b*b);
  103553. if(-a>b)return -sqrt(a*a-b*b);
  103554. return sqrt(b*b-a*a);
  103555. }
  103556. static float round_hypot(float a, float b){
  103557. if(a>0.){
  103558. if(b>0.)return sqrt(a*a+b*b);
  103559. if(a>-b)return sqrt(a*a+b*b);
  103560. return -sqrt(b*b+a*a);
  103561. }
  103562. if(b<0.)return -sqrt(a*a+b*b);
  103563. if(-a>b)return -sqrt(a*a+b*b);
  103564. return sqrt(b*b+a*a);
  103565. }
  103566. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103567. vorbis_info_psy_global *g,
  103568. vorbis_look_psy *p,
  103569. vorbis_info_mapping0 *vi,
  103570. float **mdct){
  103571. int i,j,n=p->n;
  103572. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103573. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103574. for(i=0;i<vi->coupling_steps;i++){
  103575. float *mdctM=mdct[vi->coupling_mag[i]];
  103576. float *mdctA=mdct[vi->coupling_ang[i]];
  103577. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103578. for(j=0;j<limit;j++)
  103579. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103580. for(;j<n;j++)
  103581. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103582. }
  103583. return(ret);
  103584. }
  103585. static int apsort(const void *a, const void *b){
  103586. float f1=fabs(**(float**)a);
  103587. float f2=fabs(**(float**)b);
  103588. return (f1<f2)-(f1>f2);
  103589. }
  103590. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103591. vorbis_look_psy *p,
  103592. vorbis_info_mapping0 *vi,
  103593. float **mags){
  103594. if(p->vi->normal_point_p){
  103595. int i,j,k,n=p->n;
  103596. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103597. int partition=p->vi->normal_partition;
  103598. float **work=(float**) alloca(sizeof(*work)*partition);
  103599. for(i=0;i<vi->coupling_steps;i++){
  103600. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103601. for(j=0;j<n;j+=partition){
  103602. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103603. qsort(work,partition,sizeof(*work),apsort);
  103604. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103605. }
  103606. }
  103607. return(ret);
  103608. }
  103609. return(NULL);
  103610. }
  103611. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103612. float *magnitudes,int *sortedindex){
  103613. int i,j,n=p->n;
  103614. vorbis_info_psy *vi=p->vi;
  103615. int partition=vi->normal_partition;
  103616. float **work=(float**) alloca(sizeof(*work)*partition);
  103617. int start=vi->normal_start;
  103618. for(j=start;j<n;j+=partition){
  103619. if(j+partition>n)partition=n-j;
  103620. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103621. qsort(work,partition,sizeof(*work),apsort);
  103622. for(i=0;i<partition;i++){
  103623. sortedindex[i+j-start]=work[i]-magnitudes;
  103624. }
  103625. }
  103626. }
  103627. void _vp_noise_normalize(vorbis_look_psy *p,
  103628. float *in,float *out,int *sortedindex){
  103629. int flag=0,i,j=0,n=p->n;
  103630. vorbis_info_psy *vi=p->vi;
  103631. int partition=vi->normal_partition;
  103632. int start=vi->normal_start;
  103633. if(start>n)start=n;
  103634. if(vi->normal_channel_p){
  103635. for(;j<start;j++)
  103636. out[j]=rint(in[j]);
  103637. for(;j+partition<=n;j+=partition){
  103638. float acc=0.;
  103639. int k;
  103640. for(i=j;i<j+partition;i++)
  103641. acc+=in[i]*in[i];
  103642. for(i=0;i<partition;i++){
  103643. k=sortedindex[i+j-start];
  103644. if(in[k]*in[k]>=.25f){
  103645. out[k]=rint(in[k]);
  103646. acc-=in[k]*in[k];
  103647. flag=1;
  103648. }else{
  103649. if(acc<vi->normal_thresh)break;
  103650. out[k]=unitnorm(in[k]);
  103651. acc-=1.;
  103652. }
  103653. }
  103654. for(;i<partition;i++){
  103655. k=sortedindex[i+j-start];
  103656. out[k]=0.;
  103657. }
  103658. }
  103659. }
  103660. for(;j<n;j++)
  103661. out[j]=rint(in[j]);
  103662. }
  103663. void _vp_couple(int blobno,
  103664. vorbis_info_psy_global *g,
  103665. vorbis_look_psy *p,
  103666. vorbis_info_mapping0 *vi,
  103667. float **res,
  103668. float **mag_memo,
  103669. int **mag_sort,
  103670. int **ifloor,
  103671. int *nonzero,
  103672. int sliding_lowpass){
  103673. int i,j,k,n=p->n;
  103674. for(i=0;i<vi->coupling_steps;i++){
  103675. if(nonzero[vi->coupling_mag[i]] ||
  103676. nonzero[vi->coupling_ang[i]]){
  103677. float *rM=res[vi->coupling_mag[i]];
  103678. float *rA=res[vi->coupling_ang[i]];
  103679. float *qM=rM+n;
  103680. float *qA=rA+n;
  103681. int *floorM=ifloor[vi->coupling_mag[i]];
  103682. int *floorA=ifloor[vi->coupling_ang[i]];
  103683. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103684. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103685. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103686. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103687. int pointlimit=limit;
  103688. nonzero[vi->coupling_mag[i]]=1;
  103689. nonzero[vi->coupling_ang[i]]=1;
  103690. if(n > 1000)
  103691. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103692. for(j=0;j<p->n;j+=partition){
  103693. float acc=0.f;
  103694. for(k=0;k<partition;k++){
  103695. int l=k+j;
  103696. if(l<sliding_lowpass){
  103697. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103698. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103699. precomputed_couple_point(mag_memo[i][l],
  103700. floorM[l],floorA[l],
  103701. qM+l,qA+l);
  103702. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103703. }else{
  103704. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103705. }
  103706. }else{
  103707. qM[l]=0.;
  103708. qA[l]=0.;
  103709. }
  103710. }
  103711. if(p->vi->normal_point_p){
  103712. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103713. int l=mag_sort[i][j+k];
  103714. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103715. qM[l]=unitnorm(qM[l]);
  103716. acc-=1.f;
  103717. }
  103718. }
  103719. }
  103720. }
  103721. }
  103722. }
  103723. }
  103724. void hf_reduction(vorbis_info_psy_global *g,
  103725. vorbis_look_psy *p,
  103726. vorbis_info_mapping0 *vi,
  103727. float **mdct){
  103728. int i,j,n=p->n, de=0.3*p->m_val;
  103729. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103730. for(i=0; i<vi->coupling_steps; i++){
  103731. for(j=limit; j<n; j++)
  103732. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103733. }
  103734. }
  103735. #endif
  103736. /*** End of inlined file: psy.c ***/
  103737. /*** Start of inlined file: registry.c ***/
  103738. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103739. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103740. // tasks..
  103741. #if JUCE_MSVC
  103742. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103743. #endif
  103744. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103745. #if JUCE_USE_OGGVORBIS
  103746. extern vorbis_func_floor floor0_exportbundle;
  103747. extern vorbis_func_floor floor1_exportbundle;
  103748. extern vorbis_func_residue residue0_exportbundle;
  103749. extern vorbis_func_residue residue1_exportbundle;
  103750. extern vorbis_func_residue residue2_exportbundle;
  103751. extern vorbis_func_mapping mapping0_exportbundle;
  103752. vorbis_func_floor *_floor_P[]={
  103753. &floor0_exportbundle,
  103754. &floor1_exportbundle,
  103755. };
  103756. vorbis_func_residue *_residue_P[]={
  103757. &residue0_exportbundle,
  103758. &residue1_exportbundle,
  103759. &residue2_exportbundle,
  103760. };
  103761. vorbis_func_mapping *_mapping_P[]={
  103762. &mapping0_exportbundle,
  103763. };
  103764. #endif
  103765. /*** End of inlined file: registry.c ***/
  103766. /*** Start of inlined file: res0.c ***/
  103767. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103768. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103769. // tasks..
  103770. #if JUCE_MSVC
  103771. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103772. #endif
  103773. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103774. #if JUCE_USE_OGGVORBIS
  103775. #include <stdlib.h>
  103776. #include <string.h>
  103777. #include <math.h>
  103778. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103779. #include <stdio.h>
  103780. #endif
  103781. typedef struct {
  103782. vorbis_info_residue0 *info;
  103783. int parts;
  103784. int stages;
  103785. codebook *fullbooks;
  103786. codebook *phrasebook;
  103787. codebook ***partbooks;
  103788. int partvals;
  103789. int **decodemap;
  103790. long postbits;
  103791. long phrasebits;
  103792. long frames;
  103793. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103794. int train_seq;
  103795. long *training_data[8][64];
  103796. float training_max[8][64];
  103797. float training_min[8][64];
  103798. float tmin;
  103799. float tmax;
  103800. #endif
  103801. } vorbis_look_residue0;
  103802. void res0_free_info(vorbis_info_residue *i){
  103803. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103804. if(info){
  103805. memset(info,0,sizeof(*info));
  103806. _ogg_free(info);
  103807. }
  103808. }
  103809. void res0_free_look(vorbis_look_residue *i){
  103810. int j;
  103811. if(i){
  103812. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  103813. #ifdef TRAIN_RES
  103814. {
  103815. int j,k,l;
  103816. for(j=0;j<look->parts;j++){
  103817. for(k=0;k<8;k++)
  103818. if(look->training_data[k][j]){
  103819. char buffer[80];
  103820. FILE *of;
  103821. codebook *statebook=look->partbooks[j][k];
  103822. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  103823. of=fopen(buffer,"a");
  103824. for(l=0;l<statebook->entries;l++)
  103825. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  103826. fclose(of);
  103827. _ogg_free(look->training_data[k][j]);
  103828. look->training_data[k][j]=NULL;
  103829. }
  103830. }
  103831. }
  103832. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  103833. #endif
  103834. for(j=0;j<look->parts;j++)
  103835. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  103836. _ogg_free(look->partbooks);
  103837. for(j=0;j<look->partvals;j++)
  103838. _ogg_free(look->decodemap[j]);
  103839. _ogg_free(look->decodemap);
  103840. memset(look,0,sizeof(*look));
  103841. _ogg_free(look);
  103842. }
  103843. }
  103844. static int icount(unsigned int v){
  103845. int ret=0;
  103846. while(v){
  103847. ret+=v&1;
  103848. v>>=1;
  103849. }
  103850. return(ret);
  103851. }
  103852. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  103853. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103854. int j,acc=0;
  103855. oggpack_write(opb,info->begin,24);
  103856. oggpack_write(opb,info->end,24);
  103857. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  103858. code with a partitioned book */
  103859. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  103860. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  103861. for(j=0;j<info->partitions;j++){
  103862. if(ilog(info->secondstages[j])>3){
  103863. oggpack_write(opb,info->secondstages[j],3);
  103864. oggpack_write(opb,1,1);
  103865. oggpack_write(opb,info->secondstages[j]>>3,5);
  103866. }else
  103867. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  103868. acc+=icount(info->secondstages[j]);
  103869. }
  103870. for(j=0;j<acc;j++)
  103871. oggpack_write(opb,info->booklist[j],8);
  103872. }
  103873. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  103874. int j,acc=0;
  103875. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  103876. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  103877. info->begin=oggpack_read(opb,24);
  103878. info->end=oggpack_read(opb,24);
  103879. info->grouping=oggpack_read(opb,24)+1;
  103880. info->partitions=oggpack_read(opb,6)+1;
  103881. info->groupbook=oggpack_read(opb,8);
  103882. for(j=0;j<info->partitions;j++){
  103883. int cascade=oggpack_read(opb,3);
  103884. if(oggpack_read(opb,1))
  103885. cascade|=(oggpack_read(opb,5)<<3);
  103886. info->secondstages[j]=cascade;
  103887. acc+=icount(cascade);
  103888. }
  103889. for(j=0;j<acc;j++)
  103890. info->booklist[j]=oggpack_read(opb,8);
  103891. if(info->groupbook>=ci->books)goto errout;
  103892. for(j=0;j<acc;j++)
  103893. if(info->booklist[j]>=ci->books)goto errout;
  103894. return(info);
  103895. errout:
  103896. res0_free_info(info);
  103897. return(NULL);
  103898. }
  103899. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  103900. vorbis_info_residue *vr){
  103901. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103902. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  103903. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  103904. int j,k,acc=0;
  103905. int dim;
  103906. int maxstage=0;
  103907. look->info=info;
  103908. look->parts=info->partitions;
  103909. look->fullbooks=ci->fullbooks;
  103910. look->phrasebook=ci->fullbooks+info->groupbook;
  103911. dim=look->phrasebook->dim;
  103912. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  103913. for(j=0;j<look->parts;j++){
  103914. int stages=ilog(info->secondstages[j]);
  103915. if(stages){
  103916. if(stages>maxstage)maxstage=stages;
  103917. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  103918. for(k=0;k<stages;k++)
  103919. if(info->secondstages[j]&(1<<k)){
  103920. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  103921. #ifdef TRAIN_RES
  103922. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  103923. sizeof(***look->training_data));
  103924. #endif
  103925. }
  103926. }
  103927. }
  103928. look->partvals=rint(pow((float)look->parts,(float)dim));
  103929. look->stages=maxstage;
  103930. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  103931. for(j=0;j<look->partvals;j++){
  103932. long val=j;
  103933. long mult=look->partvals/look->parts;
  103934. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  103935. for(k=0;k<dim;k++){
  103936. long deco=val/mult;
  103937. val-=deco*mult;
  103938. mult/=look->parts;
  103939. look->decodemap[j][k]=deco;
  103940. }
  103941. }
  103942. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103943. {
  103944. static int train_seq=0;
  103945. look->train_seq=train_seq++;
  103946. }
  103947. #endif
  103948. return(look);
  103949. }
  103950. static int local_book_besterror(codebook *book,float *a){
  103951. int dim=book->dim,i,k,o;
  103952. int best=0;
  103953. encode_aux_threshmatch *tt=book->c->thresh_tree;
  103954. for(k=0,o=dim;k<dim;++k){
  103955. float val=a[--o];
  103956. i=tt->threshvals>>1;
  103957. if(val<tt->quantthresh[i]){
  103958. if(val<tt->quantthresh[i-1]){
  103959. for(--i;i>0;--i)
  103960. if(val>=tt->quantthresh[i-1])
  103961. break;
  103962. }
  103963. }else{
  103964. for(++i;i<tt->threshvals-1;++i)
  103965. if(val<tt->quantthresh[i])break;
  103966. }
  103967. best=(best*tt->quantvals)+tt->quantmap[i];
  103968. }
  103969. if(book->c->lengthlist[best]<=0){
  103970. const static_codebook *c=book->c;
  103971. int i,j;
  103972. float bestf=0.f;
  103973. float *e=book->valuelist;
  103974. best=-1;
  103975. for(i=0;i<book->entries;i++){
  103976. if(c->lengthlist[i]>0){
  103977. float thisx=0.f;
  103978. for(j=0;j<dim;j++){
  103979. float val=(e[j]-a[j]);
  103980. thisx+=val*val;
  103981. }
  103982. if(best==-1 || thisx<bestf){
  103983. bestf=thisx;
  103984. best=i;
  103985. }
  103986. }
  103987. e+=dim;
  103988. }
  103989. }
  103990. {
  103991. float *ptr=book->valuelist+best*dim;
  103992. for(i=0;i<dim;i++)
  103993. *a++ -= *ptr++;
  103994. }
  103995. return(best);
  103996. }
  103997. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  103998. codebook *book,long *acc){
  103999. int i,bits=0;
  104000. int dim=book->dim;
  104001. int step=n/dim;
  104002. for(i=0;i<step;i++){
  104003. int entry=local_book_besterror(book,vec+i*dim);
  104004. #ifdef TRAIN_RES
  104005. acc[entry]++;
  104006. #endif
  104007. bits+=vorbis_book_encode(book,entry,opb);
  104008. }
  104009. return(bits);
  104010. }
  104011. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104012. float **in,int ch){
  104013. long i,j,k;
  104014. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104015. vorbis_info_residue0 *info=look->info;
  104016. int samples_per_partition=info->grouping;
  104017. int possible_partitions=info->partitions;
  104018. int n=info->end-info->begin;
  104019. int partvals=n/samples_per_partition;
  104020. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104021. float scale=100./samples_per_partition;
  104022. for(i=0;i<ch;i++){
  104023. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104024. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104025. }
  104026. for(i=0;i<partvals;i++){
  104027. int offset=i*samples_per_partition+info->begin;
  104028. for(j=0;j<ch;j++){
  104029. float max=0.;
  104030. float ent=0.;
  104031. for(k=0;k<samples_per_partition;k++){
  104032. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104033. ent+=fabs(rint(in[j][offset+k]));
  104034. }
  104035. ent*=scale;
  104036. for(k=0;k<possible_partitions-1;k++)
  104037. if(max<=info->classmetric1[k] &&
  104038. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104039. break;
  104040. partword[j][i]=k;
  104041. }
  104042. }
  104043. #ifdef TRAIN_RESAUX
  104044. {
  104045. FILE *of;
  104046. char buffer[80];
  104047. for(i=0;i<ch;i++){
  104048. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104049. of=fopen(buffer,"a");
  104050. for(j=0;j<partvals;j++)
  104051. fprintf(of,"%ld, ",partword[i][j]);
  104052. fprintf(of,"\n");
  104053. fclose(of);
  104054. }
  104055. }
  104056. #endif
  104057. look->frames++;
  104058. return(partword);
  104059. }
  104060. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104061. int ch){
  104062. long i,j,k,l;
  104063. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104064. vorbis_info_residue0 *info=look->info;
  104065. int samples_per_partition=info->grouping;
  104066. int possible_partitions=info->partitions;
  104067. int n=info->end-info->begin;
  104068. int partvals=n/samples_per_partition;
  104069. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104070. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104071. FILE *of;
  104072. char buffer[80];
  104073. #endif
  104074. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104075. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104076. for(i=0,l=info->begin/ch;i<partvals;i++){
  104077. float magmax=0.f;
  104078. float angmax=0.f;
  104079. for(j=0;j<samples_per_partition;j+=ch){
  104080. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104081. for(k=1;k<ch;k++)
  104082. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104083. l++;
  104084. }
  104085. for(j=0;j<possible_partitions-1;j++)
  104086. if(magmax<=info->classmetric1[j] &&
  104087. angmax<=info->classmetric2[j])
  104088. break;
  104089. partword[0][i]=j;
  104090. }
  104091. #ifdef TRAIN_RESAUX
  104092. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104093. of=fopen(buffer,"a");
  104094. for(i=0;i<partvals;i++)
  104095. fprintf(of,"%ld, ",partword[0][i]);
  104096. fprintf(of,"\n");
  104097. fclose(of);
  104098. #endif
  104099. look->frames++;
  104100. return(partword);
  104101. }
  104102. static int _01forward(oggpack_buffer *opb,
  104103. vorbis_block *vb,vorbis_look_residue *vl,
  104104. float **in,int ch,
  104105. long **partword,
  104106. int (*encode)(oggpack_buffer *,float *,int,
  104107. codebook *,long *)){
  104108. long i,j,k,s;
  104109. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104110. vorbis_info_residue0 *info=look->info;
  104111. int samples_per_partition=info->grouping;
  104112. int possible_partitions=info->partitions;
  104113. int partitions_per_word=look->phrasebook->dim;
  104114. int n=info->end-info->begin;
  104115. int partvals=n/samples_per_partition;
  104116. long resbits[128];
  104117. long resvals[128];
  104118. #ifdef TRAIN_RES
  104119. for(i=0;i<ch;i++)
  104120. for(j=info->begin;j<info->end;j++){
  104121. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104122. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104123. }
  104124. #endif
  104125. memset(resbits,0,sizeof(resbits));
  104126. memset(resvals,0,sizeof(resvals));
  104127. for(s=0;s<look->stages;s++){
  104128. for(i=0;i<partvals;){
  104129. if(s==0){
  104130. for(j=0;j<ch;j++){
  104131. long val=partword[j][i];
  104132. for(k=1;k<partitions_per_word;k++){
  104133. val*=possible_partitions;
  104134. if(i+k<partvals)
  104135. val+=partword[j][i+k];
  104136. }
  104137. if(val<look->phrasebook->entries)
  104138. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104139. #if 0 /*def TRAIN_RES*/
  104140. else
  104141. fprintf(stderr,"!");
  104142. #endif
  104143. }
  104144. }
  104145. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104146. long offset=i*samples_per_partition+info->begin;
  104147. for(j=0;j<ch;j++){
  104148. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104149. if(info->secondstages[partword[j][i]]&(1<<s)){
  104150. codebook *statebook=look->partbooks[partword[j][i]][s];
  104151. if(statebook){
  104152. int ret;
  104153. long *accumulator=NULL;
  104154. #ifdef TRAIN_RES
  104155. accumulator=look->training_data[s][partword[j][i]];
  104156. {
  104157. int l;
  104158. float *samples=in[j]+offset;
  104159. for(l=0;l<samples_per_partition;l++){
  104160. if(samples[l]<look->training_min[s][partword[j][i]])
  104161. look->training_min[s][partword[j][i]]=samples[l];
  104162. if(samples[l]>look->training_max[s][partword[j][i]])
  104163. look->training_max[s][partword[j][i]]=samples[l];
  104164. }
  104165. }
  104166. #endif
  104167. ret=encode(opb,in[j]+offset,samples_per_partition,
  104168. statebook,accumulator);
  104169. look->postbits+=ret;
  104170. resbits[partword[j][i]]+=ret;
  104171. }
  104172. }
  104173. }
  104174. }
  104175. }
  104176. }
  104177. return(0);
  104178. }
  104179. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104180. float **in,int ch,
  104181. long (*decodepart)(codebook *, float *,
  104182. oggpack_buffer *,int)){
  104183. long i,j,k,l,s;
  104184. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104185. vorbis_info_residue0 *info=look->info;
  104186. int samples_per_partition=info->grouping;
  104187. int partitions_per_word=look->phrasebook->dim;
  104188. int n=info->end-info->begin;
  104189. int partvals=n/samples_per_partition;
  104190. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104191. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104192. for(j=0;j<ch;j++)
  104193. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104194. for(s=0;s<look->stages;s++){
  104195. for(i=0,l=0;i<partvals;l++){
  104196. if(s==0){
  104197. for(j=0;j<ch;j++){
  104198. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104199. if(temp==-1)goto eopbreak;
  104200. partword[j][l]=look->decodemap[temp];
  104201. if(partword[j][l]==NULL)goto errout;
  104202. }
  104203. }
  104204. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104205. for(j=0;j<ch;j++){
  104206. long offset=info->begin+i*samples_per_partition;
  104207. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104208. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104209. if(stagebook){
  104210. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104211. samples_per_partition)==-1)goto eopbreak;
  104212. }
  104213. }
  104214. }
  104215. }
  104216. }
  104217. errout:
  104218. eopbreak:
  104219. return(0);
  104220. }
  104221. #if 0
  104222. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104223. float **in,int *nonzero,int ch){
  104224. int i,used=0;
  104225. for(i=0;i<ch;i++)
  104226. if(nonzero[i])
  104227. in[used++]=in[i];
  104228. if(used)
  104229. return(_01class(vb,vl,in,used));
  104230. else
  104231. return(0);
  104232. }
  104233. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104234. float **in,float **out,int *nonzero,int ch,
  104235. long **partword){
  104236. int i,j,used=0,n=vb->pcmend/2;
  104237. for(i=0;i<ch;i++)
  104238. if(nonzero[i]){
  104239. if(out)
  104240. for(j=0;j<n;j++)
  104241. out[i][j]+=in[i][j];
  104242. in[used++]=in[i];
  104243. }
  104244. if(used){
  104245. int ret=_01forward(vb,vl,in,used,partword,
  104246. _interleaved_encodepart);
  104247. if(out){
  104248. used=0;
  104249. for(i=0;i<ch;i++)
  104250. if(nonzero[i]){
  104251. for(j=0;j<n;j++)
  104252. out[i][j]-=in[used][j];
  104253. used++;
  104254. }
  104255. }
  104256. return(ret);
  104257. }else{
  104258. return(0);
  104259. }
  104260. }
  104261. #endif
  104262. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104263. float **in,int *nonzero,int ch){
  104264. int i,used=0;
  104265. for(i=0;i<ch;i++)
  104266. if(nonzero[i])
  104267. in[used++]=in[i];
  104268. if(used)
  104269. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104270. else
  104271. return(0);
  104272. }
  104273. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104274. float **in,float **out,int *nonzero,int ch,
  104275. long **partword){
  104276. int i,j,used=0,n=vb->pcmend/2;
  104277. for(i=0;i<ch;i++)
  104278. if(nonzero[i]){
  104279. if(out)
  104280. for(j=0;j<n;j++)
  104281. out[i][j]+=in[i][j];
  104282. in[used++]=in[i];
  104283. }
  104284. if(used){
  104285. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104286. if(out){
  104287. used=0;
  104288. for(i=0;i<ch;i++)
  104289. if(nonzero[i]){
  104290. for(j=0;j<n;j++)
  104291. out[i][j]-=in[used][j];
  104292. used++;
  104293. }
  104294. }
  104295. return(ret);
  104296. }else{
  104297. return(0);
  104298. }
  104299. }
  104300. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104301. float **in,int *nonzero,int ch){
  104302. int i,used=0;
  104303. for(i=0;i<ch;i++)
  104304. if(nonzero[i])
  104305. in[used++]=in[i];
  104306. if(used)
  104307. return(_01class(vb,vl,in,used));
  104308. else
  104309. return(0);
  104310. }
  104311. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104312. float **in,int *nonzero,int ch){
  104313. int i,used=0;
  104314. for(i=0;i<ch;i++)
  104315. if(nonzero[i])
  104316. in[used++]=in[i];
  104317. if(used)
  104318. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104319. else
  104320. return(0);
  104321. }
  104322. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104323. float **in,int *nonzero,int ch){
  104324. int i,used=0;
  104325. for(i=0;i<ch;i++)
  104326. if(nonzero[i])used++;
  104327. if(used)
  104328. return(_2class(vb,vl,in,ch));
  104329. else
  104330. return(0);
  104331. }
  104332. int res2_forward(oggpack_buffer *opb,
  104333. vorbis_block *vb,vorbis_look_residue *vl,
  104334. float **in,float **out,int *nonzero,int ch,
  104335. long **partword){
  104336. long i,j,k,n=vb->pcmend/2,used=0;
  104337. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104338. for(i=0;i<ch;i++){
  104339. float *pcm=in[i];
  104340. if(nonzero[i])used++;
  104341. for(j=0,k=i;j<n;j++,k+=ch)
  104342. work[k]=pcm[j];
  104343. }
  104344. if(used){
  104345. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104346. if(out){
  104347. for(i=0;i<ch;i++){
  104348. float *pcm=in[i];
  104349. float *sofar=out[i];
  104350. for(j=0,k=i;j<n;j++,k+=ch)
  104351. sofar[j]+=pcm[j]-work[k];
  104352. }
  104353. }
  104354. return(ret);
  104355. }else{
  104356. return(0);
  104357. }
  104358. }
  104359. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104360. float **in,int *nonzero,int ch){
  104361. long i,k,l,s;
  104362. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104363. vorbis_info_residue0 *info=look->info;
  104364. int samples_per_partition=info->grouping;
  104365. int partitions_per_word=look->phrasebook->dim;
  104366. int n=info->end-info->begin;
  104367. int partvals=n/samples_per_partition;
  104368. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104369. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104370. for(i=0;i<ch;i++)if(nonzero[i])break;
  104371. if(i==ch)return(0); /* no nonzero vectors */
  104372. for(s=0;s<look->stages;s++){
  104373. for(i=0,l=0;i<partvals;l++){
  104374. if(s==0){
  104375. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104376. if(temp==-1)goto eopbreak;
  104377. partword[l]=look->decodemap[temp];
  104378. if(partword[l]==NULL)goto errout;
  104379. }
  104380. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104381. if(info->secondstages[partword[l][k]]&(1<<s)){
  104382. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104383. if(stagebook){
  104384. if(vorbis_book_decodevv_add(stagebook,in,
  104385. i*samples_per_partition+info->begin,ch,
  104386. &vb->opb,samples_per_partition)==-1)
  104387. goto eopbreak;
  104388. }
  104389. }
  104390. }
  104391. }
  104392. errout:
  104393. eopbreak:
  104394. return(0);
  104395. }
  104396. vorbis_func_residue residue0_exportbundle={
  104397. NULL,
  104398. &res0_unpack,
  104399. &res0_look,
  104400. &res0_free_info,
  104401. &res0_free_look,
  104402. NULL,
  104403. NULL,
  104404. &res0_inverse
  104405. };
  104406. vorbis_func_residue residue1_exportbundle={
  104407. &res0_pack,
  104408. &res0_unpack,
  104409. &res0_look,
  104410. &res0_free_info,
  104411. &res0_free_look,
  104412. &res1_class,
  104413. &res1_forward,
  104414. &res1_inverse
  104415. };
  104416. vorbis_func_residue residue2_exportbundle={
  104417. &res0_pack,
  104418. &res0_unpack,
  104419. &res0_look,
  104420. &res0_free_info,
  104421. &res0_free_look,
  104422. &res2_class,
  104423. &res2_forward,
  104424. &res2_inverse
  104425. };
  104426. #endif
  104427. /*** End of inlined file: res0.c ***/
  104428. /*** Start of inlined file: sharedbook.c ***/
  104429. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104430. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104431. // tasks..
  104432. #if JUCE_MSVC
  104433. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104434. #endif
  104435. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104436. #if JUCE_USE_OGGVORBIS
  104437. #include <stdlib.h>
  104438. #include <math.h>
  104439. #include <string.h>
  104440. int _ilog(unsigned int v){
  104441. int ret=0;
  104442. while(v){
  104443. ret++;
  104444. v>>=1;
  104445. }
  104446. return(ret);
  104447. }
  104448. #define VQ_FEXP 10
  104449. #define VQ_FMAN 21
  104450. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104451. long _float32_pack(float val){
  104452. int sign=0;
  104453. long exp;
  104454. long mant;
  104455. if(val<0){
  104456. sign=0x80000000;
  104457. val= -val;
  104458. }
  104459. exp= floor(log(val)/log(2.f));
  104460. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104461. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104462. return(sign|exp|mant);
  104463. }
  104464. float _float32_unpack(long val){
  104465. double mant=val&0x1fffff;
  104466. int sign=val&0x80000000;
  104467. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104468. if(sign)mant= -mant;
  104469. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104470. }
  104471. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104472. long i,j,count=0;
  104473. ogg_uint32_t marker[33];
  104474. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104475. memset(marker,0,sizeof(marker));
  104476. for(i=0;i<n;i++){
  104477. long length=l[i];
  104478. if(length>0){
  104479. ogg_uint32_t entry=marker[length];
  104480. if(length<32 && (entry>>length)){
  104481. _ogg_free(r);
  104482. return(NULL);
  104483. }
  104484. r[count++]=entry;
  104485. {
  104486. for(j=length;j>0;j--){
  104487. if(marker[j]&1){
  104488. if(j==1)
  104489. marker[1]++;
  104490. else
  104491. marker[j]=marker[j-1]<<1;
  104492. break; /* invariant says next upper marker would already
  104493. have been moved if it was on the same path */
  104494. }
  104495. marker[j]++;
  104496. }
  104497. }
  104498. for(j=length+1;j<33;j++)
  104499. if((marker[j]>>1) == entry){
  104500. entry=marker[j];
  104501. marker[j]=marker[j-1]<<1;
  104502. }else
  104503. break;
  104504. }else
  104505. if(sparsecount==0)count++;
  104506. }
  104507. for(i=0,count=0;i<n;i++){
  104508. ogg_uint32_t temp=0;
  104509. for(j=0;j<l[i];j++){
  104510. temp<<=1;
  104511. temp|=(r[count]>>j)&1;
  104512. }
  104513. if(sparsecount){
  104514. if(l[i])
  104515. r[count++]=temp;
  104516. }else
  104517. r[count++]=temp;
  104518. }
  104519. return(r);
  104520. }
  104521. long _book_maptype1_quantvals(const static_codebook *b){
  104522. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104523. while(1){
  104524. long acc=1;
  104525. long acc1=1;
  104526. int i;
  104527. for(i=0;i<b->dim;i++){
  104528. acc*=vals;
  104529. acc1*=vals+1;
  104530. }
  104531. if(acc<=b->entries && acc1>b->entries){
  104532. return(vals);
  104533. }else{
  104534. if(acc>b->entries){
  104535. vals--;
  104536. }else{
  104537. vals++;
  104538. }
  104539. }
  104540. }
  104541. }
  104542. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104543. long j,k,count=0;
  104544. if(b->maptype==1 || b->maptype==2){
  104545. int quantvals;
  104546. float mindel=_float32_unpack(b->q_min);
  104547. float delta=_float32_unpack(b->q_delta);
  104548. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104549. switch(b->maptype){
  104550. case 1:
  104551. quantvals=_book_maptype1_quantvals(b);
  104552. for(j=0;j<b->entries;j++){
  104553. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104554. float last=0.f;
  104555. int indexdiv=1;
  104556. for(k=0;k<b->dim;k++){
  104557. int index= (j/indexdiv)%quantvals;
  104558. float val=b->quantlist[index];
  104559. val=fabs(val)*delta+mindel+last;
  104560. if(b->q_sequencep)last=val;
  104561. if(sparsemap)
  104562. r[sparsemap[count]*b->dim+k]=val;
  104563. else
  104564. r[count*b->dim+k]=val;
  104565. indexdiv*=quantvals;
  104566. }
  104567. count++;
  104568. }
  104569. }
  104570. break;
  104571. case 2:
  104572. for(j=0;j<b->entries;j++){
  104573. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104574. float last=0.f;
  104575. for(k=0;k<b->dim;k++){
  104576. float val=b->quantlist[j*b->dim+k];
  104577. val=fabs(val)*delta+mindel+last;
  104578. if(b->q_sequencep)last=val;
  104579. if(sparsemap)
  104580. r[sparsemap[count]*b->dim+k]=val;
  104581. else
  104582. r[count*b->dim+k]=val;
  104583. }
  104584. count++;
  104585. }
  104586. }
  104587. break;
  104588. }
  104589. return(r);
  104590. }
  104591. return(NULL);
  104592. }
  104593. void vorbis_staticbook_clear(static_codebook *b){
  104594. if(b->allocedp){
  104595. if(b->quantlist)_ogg_free(b->quantlist);
  104596. if(b->lengthlist)_ogg_free(b->lengthlist);
  104597. if(b->nearest_tree){
  104598. _ogg_free(b->nearest_tree->ptr0);
  104599. _ogg_free(b->nearest_tree->ptr1);
  104600. _ogg_free(b->nearest_tree->p);
  104601. _ogg_free(b->nearest_tree->q);
  104602. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104603. _ogg_free(b->nearest_tree);
  104604. }
  104605. if(b->thresh_tree){
  104606. _ogg_free(b->thresh_tree->quantthresh);
  104607. _ogg_free(b->thresh_tree->quantmap);
  104608. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104609. _ogg_free(b->thresh_tree);
  104610. }
  104611. memset(b,0,sizeof(*b));
  104612. }
  104613. }
  104614. void vorbis_staticbook_destroy(static_codebook *b){
  104615. if(b->allocedp){
  104616. vorbis_staticbook_clear(b);
  104617. _ogg_free(b);
  104618. }
  104619. }
  104620. void vorbis_book_clear(codebook *b){
  104621. if(b->valuelist)_ogg_free(b->valuelist);
  104622. if(b->codelist)_ogg_free(b->codelist);
  104623. if(b->dec_index)_ogg_free(b->dec_index);
  104624. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104625. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104626. memset(b,0,sizeof(*b));
  104627. }
  104628. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104629. memset(c,0,sizeof(*c));
  104630. c->c=s;
  104631. c->entries=s->entries;
  104632. c->used_entries=s->entries;
  104633. c->dim=s->dim;
  104634. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104635. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104636. return(0);
  104637. }
  104638. static int sort32a(const void *a,const void *b){
  104639. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104640. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104641. }
  104642. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104643. int i,j,n=0,tabn;
  104644. int *sortindex;
  104645. memset(c,0,sizeof(*c));
  104646. for(i=0;i<s->entries;i++)
  104647. if(s->lengthlist[i]>0)
  104648. n++;
  104649. c->entries=s->entries;
  104650. c->used_entries=n;
  104651. c->dim=s->dim;
  104652. {
  104653. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104654. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104655. if(codes==NULL)goto err_out;
  104656. for(i=0;i<n;i++){
  104657. codes[i]=ogg_bitreverse(codes[i]);
  104658. codep[i]=codes+i;
  104659. }
  104660. qsort(codep,n,sizeof(*codep),sort32a);
  104661. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104662. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104663. for(i=0;i<n;i++){
  104664. int position=codep[i]-codes;
  104665. sortindex[position]=i;
  104666. }
  104667. for(i=0;i<n;i++)
  104668. c->codelist[sortindex[i]]=codes[i];
  104669. _ogg_free(codes);
  104670. }
  104671. c->valuelist=_book_unquantize(s,n,sortindex);
  104672. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104673. for(n=0,i=0;i<s->entries;i++)
  104674. if(s->lengthlist[i]>0)
  104675. c->dec_index[sortindex[n++]]=i;
  104676. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104677. for(n=0,i=0;i<s->entries;i++)
  104678. if(s->lengthlist[i]>0)
  104679. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104680. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104681. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104682. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104683. tabn=1<<c->dec_firsttablen;
  104684. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104685. c->dec_maxlength=0;
  104686. for(i=0;i<n;i++){
  104687. if(c->dec_maxlength<c->dec_codelengths[i])
  104688. c->dec_maxlength=c->dec_codelengths[i];
  104689. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104690. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104691. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104692. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104693. }
  104694. }
  104695. {
  104696. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104697. long lo=0,hi=0;
  104698. for(i=0;i<tabn;i++){
  104699. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104700. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104701. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104702. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104703. {
  104704. unsigned long loval=lo;
  104705. unsigned long hival=n-hi;
  104706. if(loval>0x7fff)loval=0x7fff;
  104707. if(hival>0x7fff)hival=0x7fff;
  104708. c->dec_firsttable[ogg_bitreverse(word)]=
  104709. 0x80000000UL | (loval<<15) | hival;
  104710. }
  104711. }
  104712. }
  104713. }
  104714. return(0);
  104715. err_out:
  104716. vorbis_book_clear(c);
  104717. return(-1);
  104718. }
  104719. static float _dist(int el,float *ref, float *b,int step){
  104720. int i;
  104721. float acc=0.f;
  104722. for(i=0;i<el;i++){
  104723. float val=(ref[i]-b[i*step]);
  104724. acc+=val*val;
  104725. }
  104726. return(acc);
  104727. }
  104728. int _best(codebook *book, float *a, int step){
  104729. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104730. #if 0
  104731. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104732. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104733. #endif
  104734. int dim=book->dim;
  104735. int k,o;
  104736. if(tt){
  104737. int index=0,i;
  104738. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104739. i=tt->threshvals>>1;
  104740. if(a[o]<tt->quantthresh[i]){
  104741. for(;i>0;i--)
  104742. if(a[o]>=tt->quantthresh[i-1])
  104743. break;
  104744. }else{
  104745. for(i++;i<tt->threshvals-1;i++)
  104746. if(a[o]<tt->quantthresh[i])break;
  104747. }
  104748. index=(index*tt->quantvals)+tt->quantmap[i];
  104749. }
  104750. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104751. use a decision tree after all
  104752. and fall through*/
  104753. return(index);
  104754. }
  104755. #if 0
  104756. if(pt){
  104757. const static_codebook *c=book->c;
  104758. int i,besti=-1;
  104759. float best=0.f;
  104760. int entry=0;
  104761. if(c->q_sequencep){
  104762. int pv;
  104763. long mul=1;
  104764. float qlast=0;
  104765. for(k=0,o=0;k<dim;k++,o+=step){
  104766. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104767. if(pv<0 || pv>=pt->mapentries)break;
  104768. entry+=pt->pigeonmap[pv]*mul;
  104769. mul*=pt->quantvals;
  104770. qlast+=pv*pt->del+pt->min;
  104771. }
  104772. }else{
  104773. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104774. int pv=(int)((a[o]-pt->min)/pt->del);
  104775. if(pv<0 || pv>=pt->mapentries)break;
  104776. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104777. }
  104778. }
  104779. if(k==dim && pt->fitlength[entry]){
  104780. long *list=pt->fitlist+pt->fitmap[entry];
  104781. for(i=0;i<pt->fitlength[entry];i++){
  104782. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104783. if(besti==-1 || this<best){
  104784. best=this;
  104785. besti=list[i];
  104786. }
  104787. }
  104788. return(besti);
  104789. }
  104790. }
  104791. if(nt){
  104792. while(1){
  104793. float c=0.f;
  104794. float *p=book->valuelist+nt->p[ptr];
  104795. float *q=book->valuelist+nt->q[ptr];
  104796. for(k=0,o=0;k<dim;k++,o+=step)
  104797. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104798. if(c>0.f) /* in A */
  104799. ptr= -nt->ptr0[ptr];
  104800. else /* in B */
  104801. ptr= -nt->ptr1[ptr];
  104802. if(ptr<=0)break;
  104803. }
  104804. return(-ptr);
  104805. }
  104806. #endif
  104807. {
  104808. const static_codebook *c=book->c;
  104809. int i,besti=-1;
  104810. float best=0.f;
  104811. float *e=book->valuelist;
  104812. for(i=0;i<book->entries;i++){
  104813. if(c->lengthlist[i]>0){
  104814. float thisx=_dist(dim,e,a,step);
  104815. if(besti==-1 || thisx<best){
  104816. best=thisx;
  104817. besti=i;
  104818. }
  104819. }
  104820. e+=dim;
  104821. }
  104822. return(besti);
  104823. }
  104824. }
  104825. long vorbis_book_codeword(codebook *book,int entry){
  104826. if(book->c) /* only use with encode; decode optimizations are
  104827. allowed to break this */
  104828. return book->codelist[entry];
  104829. return -1;
  104830. }
  104831. long vorbis_book_codelen(codebook *book,int entry){
  104832. if(book->c) /* only use with encode; decode optimizations are
  104833. allowed to break this */
  104834. return book->c->lengthlist[entry];
  104835. return -1;
  104836. }
  104837. #ifdef _V_SELFTEST
  104838. #include <stdio.h>
  104839. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  104840. static long partial_quantlist1[]={0,7,2};
  104841. static_codebook test1={
  104842. 4,16,
  104843. NULL,
  104844. 0,
  104845. 0,0,0,0,
  104846. NULL,
  104847. NULL,NULL
  104848. };
  104849. static float *test1_result=NULL;
  104850. static_codebook test2={
  104851. 4,3,
  104852. NULL,
  104853. 2,
  104854. -533200896,1611661312,4,0,
  104855. full_quantlist1,
  104856. NULL,NULL
  104857. };
  104858. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  104859. static_codebook test3={
  104860. 4,3,
  104861. NULL,
  104862. 2,
  104863. -533200896,1611661312,4,1,
  104864. full_quantlist1,
  104865. NULL,NULL
  104866. };
  104867. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  104868. static_codebook test4={
  104869. 3,27,
  104870. NULL,
  104871. 1,
  104872. -533200896,1611661312,4,0,
  104873. partial_quantlist1,
  104874. NULL,NULL
  104875. };
  104876. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  104877. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  104878. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  104879. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  104880. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  104881. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  104882. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  104883. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  104884. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  104885. static_codebook test5={
  104886. 3,27,
  104887. NULL,
  104888. 1,
  104889. -533200896,1611661312,4,1,
  104890. partial_quantlist1,
  104891. NULL,NULL
  104892. };
  104893. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  104894. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  104895. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  104896. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  104897. -3, 1, 5, 4, 8,12, -1, 3, 7,
  104898. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  104899. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  104900. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  104901. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  104902. void run_test(static_codebook *b,float *comp){
  104903. float *out=_book_unquantize(b,b->entries,NULL);
  104904. int i;
  104905. if(comp){
  104906. if(!out){
  104907. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  104908. exit(1);
  104909. }
  104910. for(i=0;i<b->entries*b->dim;i++)
  104911. if(fabs(out[i]-comp[i])>.0001){
  104912. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  104913. "position %d, %g != %g\n",i,out[i],comp[i]);
  104914. exit(1);
  104915. }
  104916. }else{
  104917. if(out){
  104918. fprintf(stderr,"_book_unquantize returned a value array: \n"
  104919. " correct result should have been NULL\n");
  104920. exit(1);
  104921. }
  104922. }
  104923. }
  104924. int main(){
  104925. fprintf(stderr,"Dequant test 1... ");
  104926. run_test(&test1,test1_result);
  104927. fprintf(stderr,"OK\nDequant test 2... ");
  104928. run_test(&test2,test2_result);
  104929. fprintf(stderr,"OK\nDequant test 3... ");
  104930. run_test(&test3,test3_result);
  104931. fprintf(stderr,"OK\nDequant test 4... ");
  104932. run_test(&test4,test4_result);
  104933. fprintf(stderr,"OK\nDequant test 5... ");
  104934. run_test(&test5,test5_result);
  104935. fprintf(stderr,"OK\n\n");
  104936. return(0);
  104937. }
  104938. #endif
  104939. #endif
  104940. /*** End of inlined file: sharedbook.c ***/
  104941. /*** Start of inlined file: smallft.c ***/
  104942. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104943. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104944. // tasks..
  104945. #if JUCE_MSVC
  104946. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104947. #endif
  104948. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104949. #if JUCE_USE_OGGVORBIS
  104950. #include <stdlib.h>
  104951. #include <string.h>
  104952. #include <math.h>
  104953. static void drfti1(int n, float *wa, int *ifac){
  104954. static int ntryh[4] = { 4,2,3,5 };
  104955. static float tpi = 6.28318530717958648f;
  104956. float arg,argh,argld,fi;
  104957. int ntry=0,i,j=-1;
  104958. int k1, l1, l2, ib;
  104959. int ld, ii, ip, is, nq, nr;
  104960. int ido, ipm, nfm1;
  104961. int nl=n;
  104962. int nf=0;
  104963. L101:
  104964. j++;
  104965. if (j < 4)
  104966. ntry=ntryh[j];
  104967. else
  104968. ntry+=2;
  104969. L104:
  104970. nq=nl/ntry;
  104971. nr=nl-ntry*nq;
  104972. if (nr!=0) goto L101;
  104973. nf++;
  104974. ifac[nf+1]=ntry;
  104975. nl=nq;
  104976. if(ntry!=2)goto L107;
  104977. if(nf==1)goto L107;
  104978. for (i=1;i<nf;i++){
  104979. ib=nf-i+1;
  104980. ifac[ib+1]=ifac[ib];
  104981. }
  104982. ifac[2] = 2;
  104983. L107:
  104984. if(nl!=1)goto L104;
  104985. ifac[0]=n;
  104986. ifac[1]=nf;
  104987. argh=tpi/n;
  104988. is=0;
  104989. nfm1=nf-1;
  104990. l1=1;
  104991. if(nfm1==0)return;
  104992. for (k1=0;k1<nfm1;k1++){
  104993. ip=ifac[k1+2];
  104994. ld=0;
  104995. l2=l1*ip;
  104996. ido=n/l2;
  104997. ipm=ip-1;
  104998. for (j=0;j<ipm;j++){
  104999. ld+=l1;
  105000. i=is;
  105001. argld=(float)ld*argh;
  105002. fi=0.f;
  105003. for (ii=2;ii<ido;ii+=2){
  105004. fi+=1.f;
  105005. arg=fi*argld;
  105006. wa[i++]=cos(arg);
  105007. wa[i++]=sin(arg);
  105008. }
  105009. is+=ido;
  105010. }
  105011. l1=l2;
  105012. }
  105013. }
  105014. static void fdrffti(int n, float *wsave, int *ifac){
  105015. if (n == 1) return;
  105016. drfti1(n, wsave+n, ifac);
  105017. }
  105018. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105019. int i,k;
  105020. float ti2,tr2;
  105021. int t0,t1,t2,t3,t4,t5,t6;
  105022. t1=0;
  105023. t0=(t2=l1*ido);
  105024. t3=ido<<1;
  105025. for(k=0;k<l1;k++){
  105026. ch[t1<<1]=cc[t1]+cc[t2];
  105027. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105028. t1+=ido;
  105029. t2+=ido;
  105030. }
  105031. if(ido<2)return;
  105032. if(ido==2)goto L105;
  105033. t1=0;
  105034. t2=t0;
  105035. for(k=0;k<l1;k++){
  105036. t3=t2;
  105037. t4=(t1<<1)+(ido<<1);
  105038. t5=t1;
  105039. t6=t1+t1;
  105040. for(i=2;i<ido;i+=2){
  105041. t3+=2;
  105042. t4-=2;
  105043. t5+=2;
  105044. t6+=2;
  105045. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105046. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105047. ch[t6]=cc[t5]+ti2;
  105048. ch[t4]=ti2-cc[t5];
  105049. ch[t6-1]=cc[t5-1]+tr2;
  105050. ch[t4-1]=cc[t5-1]-tr2;
  105051. }
  105052. t1+=ido;
  105053. t2+=ido;
  105054. }
  105055. if(ido%2==1)return;
  105056. L105:
  105057. t3=(t2=(t1=ido)-1);
  105058. t2+=t0;
  105059. for(k=0;k<l1;k++){
  105060. ch[t1]=-cc[t2];
  105061. ch[t1-1]=cc[t3];
  105062. t1+=ido<<1;
  105063. t2+=ido;
  105064. t3+=ido;
  105065. }
  105066. }
  105067. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105068. float *wa2,float *wa3){
  105069. static float hsqt2 = .70710678118654752f;
  105070. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105071. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105072. t0=l1*ido;
  105073. t1=t0;
  105074. t4=t1<<1;
  105075. t2=t1+(t1<<1);
  105076. t3=0;
  105077. for(k=0;k<l1;k++){
  105078. tr1=cc[t1]+cc[t2];
  105079. tr2=cc[t3]+cc[t4];
  105080. ch[t5=t3<<2]=tr1+tr2;
  105081. ch[(ido<<2)+t5-1]=tr2-tr1;
  105082. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105083. ch[t5]=cc[t2]-cc[t1];
  105084. t1+=ido;
  105085. t2+=ido;
  105086. t3+=ido;
  105087. t4+=ido;
  105088. }
  105089. if(ido<2)return;
  105090. if(ido==2)goto L105;
  105091. t1=0;
  105092. for(k=0;k<l1;k++){
  105093. t2=t1;
  105094. t4=t1<<2;
  105095. t5=(t6=ido<<1)+t4;
  105096. for(i=2;i<ido;i+=2){
  105097. t3=(t2+=2);
  105098. t4+=2;
  105099. t5-=2;
  105100. t3+=t0;
  105101. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105102. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105103. t3+=t0;
  105104. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105105. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105106. t3+=t0;
  105107. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105108. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105109. tr1=cr2+cr4;
  105110. tr4=cr4-cr2;
  105111. ti1=ci2+ci4;
  105112. ti4=ci2-ci4;
  105113. ti2=cc[t2]+ci3;
  105114. ti3=cc[t2]-ci3;
  105115. tr2=cc[t2-1]+cr3;
  105116. tr3=cc[t2-1]-cr3;
  105117. ch[t4-1]=tr1+tr2;
  105118. ch[t4]=ti1+ti2;
  105119. ch[t5-1]=tr3-ti4;
  105120. ch[t5]=tr4-ti3;
  105121. ch[t4+t6-1]=ti4+tr3;
  105122. ch[t4+t6]=tr4+ti3;
  105123. ch[t5+t6-1]=tr2-tr1;
  105124. ch[t5+t6]=ti1-ti2;
  105125. }
  105126. t1+=ido;
  105127. }
  105128. if(ido&1)return;
  105129. L105:
  105130. t2=(t1=t0+ido-1)+(t0<<1);
  105131. t3=ido<<2;
  105132. t4=ido;
  105133. t5=ido<<1;
  105134. t6=ido;
  105135. for(k=0;k<l1;k++){
  105136. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105137. tr1=hsqt2*(cc[t1]-cc[t2]);
  105138. ch[t4-1]=tr1+cc[t6-1];
  105139. ch[t4+t5-1]=cc[t6-1]-tr1;
  105140. ch[t4]=ti1-cc[t1+t0];
  105141. ch[t4+t5]=ti1+cc[t1+t0];
  105142. t1+=ido;
  105143. t2+=ido;
  105144. t4+=t3;
  105145. t6+=ido;
  105146. }
  105147. }
  105148. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105149. float *c2,float *ch,float *ch2,float *wa){
  105150. static float tpi=6.283185307179586f;
  105151. int idij,ipph,i,j,k,l,ic,ik,is;
  105152. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105153. float dc2,ai1,ai2,ar1,ar2,ds2;
  105154. int nbd;
  105155. float dcp,arg,dsp,ar1h,ar2h;
  105156. int idp2,ipp2;
  105157. arg=tpi/(float)ip;
  105158. dcp=cos(arg);
  105159. dsp=sin(arg);
  105160. ipph=(ip+1)>>1;
  105161. ipp2=ip;
  105162. idp2=ido;
  105163. nbd=(ido-1)>>1;
  105164. t0=l1*ido;
  105165. t10=ip*ido;
  105166. if(ido==1)goto L119;
  105167. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105168. t1=0;
  105169. for(j=1;j<ip;j++){
  105170. t1+=t0;
  105171. t2=t1;
  105172. for(k=0;k<l1;k++){
  105173. ch[t2]=c1[t2];
  105174. t2+=ido;
  105175. }
  105176. }
  105177. is=-ido;
  105178. t1=0;
  105179. if(nbd>l1){
  105180. for(j=1;j<ip;j++){
  105181. t1+=t0;
  105182. is+=ido;
  105183. t2= -ido+t1;
  105184. for(k=0;k<l1;k++){
  105185. idij=is-1;
  105186. t2+=ido;
  105187. t3=t2;
  105188. for(i=2;i<ido;i+=2){
  105189. idij+=2;
  105190. t3+=2;
  105191. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105192. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105193. }
  105194. }
  105195. }
  105196. }else{
  105197. for(j=1;j<ip;j++){
  105198. is+=ido;
  105199. idij=is-1;
  105200. t1+=t0;
  105201. t2=t1;
  105202. for(i=2;i<ido;i+=2){
  105203. idij+=2;
  105204. t2+=2;
  105205. t3=t2;
  105206. for(k=0;k<l1;k++){
  105207. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105208. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105209. t3+=ido;
  105210. }
  105211. }
  105212. }
  105213. }
  105214. t1=0;
  105215. t2=ipp2*t0;
  105216. if(nbd<l1){
  105217. for(j=1;j<ipph;j++){
  105218. t1+=t0;
  105219. t2-=t0;
  105220. t3=t1;
  105221. t4=t2;
  105222. for(i=2;i<ido;i+=2){
  105223. t3+=2;
  105224. t4+=2;
  105225. t5=t3-ido;
  105226. t6=t4-ido;
  105227. for(k=0;k<l1;k++){
  105228. t5+=ido;
  105229. t6+=ido;
  105230. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105231. c1[t6-1]=ch[t5]-ch[t6];
  105232. c1[t5]=ch[t5]+ch[t6];
  105233. c1[t6]=ch[t6-1]-ch[t5-1];
  105234. }
  105235. }
  105236. }
  105237. }else{
  105238. for(j=1;j<ipph;j++){
  105239. t1+=t0;
  105240. t2-=t0;
  105241. t3=t1;
  105242. t4=t2;
  105243. for(k=0;k<l1;k++){
  105244. t5=t3;
  105245. t6=t4;
  105246. for(i=2;i<ido;i+=2){
  105247. t5+=2;
  105248. t6+=2;
  105249. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105250. c1[t6-1]=ch[t5]-ch[t6];
  105251. c1[t5]=ch[t5]+ch[t6];
  105252. c1[t6]=ch[t6-1]-ch[t5-1];
  105253. }
  105254. t3+=ido;
  105255. t4+=ido;
  105256. }
  105257. }
  105258. }
  105259. L119:
  105260. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105261. t1=0;
  105262. t2=ipp2*idl1;
  105263. for(j=1;j<ipph;j++){
  105264. t1+=t0;
  105265. t2-=t0;
  105266. t3=t1-ido;
  105267. t4=t2-ido;
  105268. for(k=0;k<l1;k++){
  105269. t3+=ido;
  105270. t4+=ido;
  105271. c1[t3]=ch[t3]+ch[t4];
  105272. c1[t4]=ch[t4]-ch[t3];
  105273. }
  105274. }
  105275. ar1=1.f;
  105276. ai1=0.f;
  105277. t1=0;
  105278. t2=ipp2*idl1;
  105279. t3=(ip-1)*idl1;
  105280. for(l=1;l<ipph;l++){
  105281. t1+=idl1;
  105282. t2-=idl1;
  105283. ar1h=dcp*ar1-dsp*ai1;
  105284. ai1=dcp*ai1+dsp*ar1;
  105285. ar1=ar1h;
  105286. t4=t1;
  105287. t5=t2;
  105288. t6=t3;
  105289. t7=idl1;
  105290. for(ik=0;ik<idl1;ik++){
  105291. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105292. ch2[t5++]=ai1*c2[t6++];
  105293. }
  105294. dc2=ar1;
  105295. ds2=ai1;
  105296. ar2=ar1;
  105297. ai2=ai1;
  105298. t4=idl1;
  105299. t5=(ipp2-1)*idl1;
  105300. for(j=2;j<ipph;j++){
  105301. t4+=idl1;
  105302. t5-=idl1;
  105303. ar2h=dc2*ar2-ds2*ai2;
  105304. ai2=dc2*ai2+ds2*ar2;
  105305. ar2=ar2h;
  105306. t6=t1;
  105307. t7=t2;
  105308. t8=t4;
  105309. t9=t5;
  105310. for(ik=0;ik<idl1;ik++){
  105311. ch2[t6++]+=ar2*c2[t8++];
  105312. ch2[t7++]+=ai2*c2[t9++];
  105313. }
  105314. }
  105315. }
  105316. t1=0;
  105317. for(j=1;j<ipph;j++){
  105318. t1+=idl1;
  105319. t2=t1;
  105320. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105321. }
  105322. if(ido<l1)goto L132;
  105323. t1=0;
  105324. t2=0;
  105325. for(k=0;k<l1;k++){
  105326. t3=t1;
  105327. t4=t2;
  105328. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105329. t1+=ido;
  105330. t2+=t10;
  105331. }
  105332. goto L135;
  105333. L132:
  105334. for(i=0;i<ido;i++){
  105335. t1=i;
  105336. t2=i;
  105337. for(k=0;k<l1;k++){
  105338. cc[t2]=ch[t1];
  105339. t1+=ido;
  105340. t2+=t10;
  105341. }
  105342. }
  105343. L135:
  105344. t1=0;
  105345. t2=ido<<1;
  105346. t3=0;
  105347. t4=ipp2*t0;
  105348. for(j=1;j<ipph;j++){
  105349. t1+=t2;
  105350. t3+=t0;
  105351. t4-=t0;
  105352. t5=t1;
  105353. t6=t3;
  105354. t7=t4;
  105355. for(k=0;k<l1;k++){
  105356. cc[t5-1]=ch[t6];
  105357. cc[t5]=ch[t7];
  105358. t5+=t10;
  105359. t6+=ido;
  105360. t7+=ido;
  105361. }
  105362. }
  105363. if(ido==1)return;
  105364. if(nbd<l1)goto L141;
  105365. t1=-ido;
  105366. t3=0;
  105367. t4=0;
  105368. t5=ipp2*t0;
  105369. for(j=1;j<ipph;j++){
  105370. t1+=t2;
  105371. t3+=t2;
  105372. t4+=t0;
  105373. t5-=t0;
  105374. t6=t1;
  105375. t7=t3;
  105376. t8=t4;
  105377. t9=t5;
  105378. for(k=0;k<l1;k++){
  105379. for(i=2;i<ido;i+=2){
  105380. ic=idp2-i;
  105381. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105382. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105383. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105384. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105385. }
  105386. t6+=t10;
  105387. t7+=t10;
  105388. t8+=ido;
  105389. t9+=ido;
  105390. }
  105391. }
  105392. return;
  105393. L141:
  105394. t1=-ido;
  105395. t3=0;
  105396. t4=0;
  105397. t5=ipp2*t0;
  105398. for(j=1;j<ipph;j++){
  105399. t1+=t2;
  105400. t3+=t2;
  105401. t4+=t0;
  105402. t5-=t0;
  105403. for(i=2;i<ido;i+=2){
  105404. t6=idp2+t1-i;
  105405. t7=i+t3;
  105406. t8=i+t4;
  105407. t9=i+t5;
  105408. for(k=0;k<l1;k++){
  105409. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105410. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105411. cc[t7]=ch[t8]+ch[t9];
  105412. cc[t6]=ch[t9]-ch[t8];
  105413. t6+=t10;
  105414. t7+=t10;
  105415. t8+=ido;
  105416. t9+=ido;
  105417. }
  105418. }
  105419. }
  105420. }
  105421. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105422. int i,k1,l1,l2;
  105423. int na,kh,nf;
  105424. int ip,iw,ido,idl1,ix2,ix3;
  105425. nf=ifac[1];
  105426. na=1;
  105427. l2=n;
  105428. iw=n;
  105429. for(k1=0;k1<nf;k1++){
  105430. kh=nf-k1;
  105431. ip=ifac[kh+1];
  105432. l1=l2/ip;
  105433. ido=n/l2;
  105434. idl1=ido*l1;
  105435. iw-=(ip-1)*ido;
  105436. na=1-na;
  105437. if(ip!=4)goto L102;
  105438. ix2=iw+ido;
  105439. ix3=ix2+ido;
  105440. if(na!=0)
  105441. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105442. else
  105443. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105444. goto L110;
  105445. L102:
  105446. if(ip!=2)goto L104;
  105447. if(na!=0)goto L103;
  105448. dradf2(ido,l1,c,ch,wa+iw-1);
  105449. goto L110;
  105450. L103:
  105451. dradf2(ido,l1,ch,c,wa+iw-1);
  105452. goto L110;
  105453. L104:
  105454. if(ido==1)na=1-na;
  105455. if(na!=0)goto L109;
  105456. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105457. na=1;
  105458. goto L110;
  105459. L109:
  105460. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105461. na=0;
  105462. L110:
  105463. l2=l1;
  105464. }
  105465. if(na==1)return;
  105466. for(i=0;i<n;i++)c[i]=ch[i];
  105467. }
  105468. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105469. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105470. float ti2,tr2;
  105471. t0=l1*ido;
  105472. t1=0;
  105473. t2=0;
  105474. t3=(ido<<1)-1;
  105475. for(k=0;k<l1;k++){
  105476. ch[t1]=cc[t2]+cc[t3+t2];
  105477. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105478. t2=(t1+=ido)<<1;
  105479. }
  105480. if(ido<2)return;
  105481. if(ido==2)goto L105;
  105482. t1=0;
  105483. t2=0;
  105484. for(k=0;k<l1;k++){
  105485. t3=t1;
  105486. t5=(t4=t2)+(ido<<1);
  105487. t6=t0+t1;
  105488. for(i=2;i<ido;i+=2){
  105489. t3+=2;
  105490. t4+=2;
  105491. t5-=2;
  105492. t6+=2;
  105493. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105494. tr2=cc[t4-1]-cc[t5-1];
  105495. ch[t3]=cc[t4]-cc[t5];
  105496. ti2=cc[t4]+cc[t5];
  105497. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105498. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105499. }
  105500. t2=(t1+=ido)<<1;
  105501. }
  105502. if(ido%2==1)return;
  105503. L105:
  105504. t1=ido-1;
  105505. t2=ido-1;
  105506. for(k=0;k<l1;k++){
  105507. ch[t1]=cc[t2]+cc[t2];
  105508. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105509. t1+=ido;
  105510. t2+=ido<<1;
  105511. }
  105512. }
  105513. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105514. float *wa2){
  105515. static float taur = -.5f;
  105516. static float taui = .8660254037844386f;
  105517. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105518. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105519. t0=l1*ido;
  105520. t1=0;
  105521. t2=t0<<1;
  105522. t3=ido<<1;
  105523. t4=ido+(ido<<1);
  105524. t5=0;
  105525. for(k=0;k<l1;k++){
  105526. tr2=cc[t3-1]+cc[t3-1];
  105527. cr2=cc[t5]+(taur*tr2);
  105528. ch[t1]=cc[t5]+tr2;
  105529. ci3=taui*(cc[t3]+cc[t3]);
  105530. ch[t1+t0]=cr2-ci3;
  105531. ch[t1+t2]=cr2+ci3;
  105532. t1+=ido;
  105533. t3+=t4;
  105534. t5+=t4;
  105535. }
  105536. if(ido==1)return;
  105537. t1=0;
  105538. t3=ido<<1;
  105539. for(k=0;k<l1;k++){
  105540. t7=t1+(t1<<1);
  105541. t6=(t5=t7+t3);
  105542. t8=t1;
  105543. t10=(t9=t1+t0)+t0;
  105544. for(i=2;i<ido;i+=2){
  105545. t5+=2;
  105546. t6-=2;
  105547. t7+=2;
  105548. t8+=2;
  105549. t9+=2;
  105550. t10+=2;
  105551. tr2=cc[t5-1]+cc[t6-1];
  105552. cr2=cc[t7-1]+(taur*tr2);
  105553. ch[t8-1]=cc[t7-1]+tr2;
  105554. ti2=cc[t5]-cc[t6];
  105555. ci2=cc[t7]+(taur*ti2);
  105556. ch[t8]=cc[t7]+ti2;
  105557. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105558. ci3=taui*(cc[t5]+cc[t6]);
  105559. dr2=cr2-ci3;
  105560. dr3=cr2+ci3;
  105561. di2=ci2+cr3;
  105562. di3=ci2-cr3;
  105563. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105564. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105565. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105566. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105567. }
  105568. t1+=ido;
  105569. }
  105570. }
  105571. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105572. float *wa2,float *wa3){
  105573. static float sqrt2=1.414213562373095f;
  105574. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105575. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105576. t0=l1*ido;
  105577. t1=0;
  105578. t2=ido<<2;
  105579. t3=0;
  105580. t6=ido<<1;
  105581. for(k=0;k<l1;k++){
  105582. t4=t3+t6;
  105583. t5=t1;
  105584. tr3=cc[t4-1]+cc[t4-1];
  105585. tr4=cc[t4]+cc[t4];
  105586. tr1=cc[t3]-cc[(t4+=t6)-1];
  105587. tr2=cc[t3]+cc[t4-1];
  105588. ch[t5]=tr2+tr3;
  105589. ch[t5+=t0]=tr1-tr4;
  105590. ch[t5+=t0]=tr2-tr3;
  105591. ch[t5+=t0]=tr1+tr4;
  105592. t1+=ido;
  105593. t3+=t2;
  105594. }
  105595. if(ido<2)return;
  105596. if(ido==2)goto L105;
  105597. t1=0;
  105598. for(k=0;k<l1;k++){
  105599. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105600. t7=t1;
  105601. for(i=2;i<ido;i+=2){
  105602. t2+=2;
  105603. t3+=2;
  105604. t4-=2;
  105605. t5-=2;
  105606. t7+=2;
  105607. ti1=cc[t2]+cc[t5];
  105608. ti2=cc[t2]-cc[t5];
  105609. ti3=cc[t3]-cc[t4];
  105610. tr4=cc[t3]+cc[t4];
  105611. tr1=cc[t2-1]-cc[t5-1];
  105612. tr2=cc[t2-1]+cc[t5-1];
  105613. ti4=cc[t3-1]-cc[t4-1];
  105614. tr3=cc[t3-1]+cc[t4-1];
  105615. ch[t7-1]=tr2+tr3;
  105616. cr3=tr2-tr3;
  105617. ch[t7]=ti2+ti3;
  105618. ci3=ti2-ti3;
  105619. cr2=tr1-tr4;
  105620. cr4=tr1+tr4;
  105621. ci2=ti1+ti4;
  105622. ci4=ti1-ti4;
  105623. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105624. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105625. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105626. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105627. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105628. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105629. }
  105630. t1+=ido;
  105631. }
  105632. if(ido%2 == 1)return;
  105633. L105:
  105634. t1=ido;
  105635. t2=ido<<2;
  105636. t3=ido-1;
  105637. t4=ido+(ido<<1);
  105638. for(k=0;k<l1;k++){
  105639. t5=t3;
  105640. ti1=cc[t1]+cc[t4];
  105641. ti2=cc[t4]-cc[t1];
  105642. tr1=cc[t1-1]-cc[t4-1];
  105643. tr2=cc[t1-1]+cc[t4-1];
  105644. ch[t5]=tr2+tr2;
  105645. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105646. ch[t5+=t0]=ti2+ti2;
  105647. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105648. t3+=ido;
  105649. t1+=t2;
  105650. t4+=t2;
  105651. }
  105652. }
  105653. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105654. float *c2,float *ch,float *ch2,float *wa){
  105655. static float tpi=6.283185307179586f;
  105656. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105657. t11,t12;
  105658. float dc2,ai1,ai2,ar1,ar2,ds2;
  105659. int nbd;
  105660. float dcp,arg,dsp,ar1h,ar2h;
  105661. int ipp2;
  105662. t10=ip*ido;
  105663. t0=l1*ido;
  105664. arg=tpi/(float)ip;
  105665. dcp=cos(arg);
  105666. dsp=sin(arg);
  105667. nbd=(ido-1)>>1;
  105668. ipp2=ip;
  105669. ipph=(ip+1)>>1;
  105670. if(ido<l1)goto L103;
  105671. t1=0;
  105672. t2=0;
  105673. for(k=0;k<l1;k++){
  105674. t3=t1;
  105675. t4=t2;
  105676. for(i=0;i<ido;i++){
  105677. ch[t3]=cc[t4];
  105678. t3++;
  105679. t4++;
  105680. }
  105681. t1+=ido;
  105682. t2+=t10;
  105683. }
  105684. goto L106;
  105685. L103:
  105686. t1=0;
  105687. for(i=0;i<ido;i++){
  105688. t2=t1;
  105689. t3=t1;
  105690. for(k=0;k<l1;k++){
  105691. ch[t2]=cc[t3];
  105692. t2+=ido;
  105693. t3+=t10;
  105694. }
  105695. t1++;
  105696. }
  105697. L106:
  105698. t1=0;
  105699. t2=ipp2*t0;
  105700. t7=(t5=ido<<1);
  105701. for(j=1;j<ipph;j++){
  105702. t1+=t0;
  105703. t2-=t0;
  105704. t3=t1;
  105705. t4=t2;
  105706. t6=t5;
  105707. for(k=0;k<l1;k++){
  105708. ch[t3]=cc[t6-1]+cc[t6-1];
  105709. ch[t4]=cc[t6]+cc[t6];
  105710. t3+=ido;
  105711. t4+=ido;
  105712. t6+=t10;
  105713. }
  105714. t5+=t7;
  105715. }
  105716. if (ido == 1)goto L116;
  105717. if(nbd<l1)goto L112;
  105718. t1=0;
  105719. t2=ipp2*t0;
  105720. t7=0;
  105721. for(j=1;j<ipph;j++){
  105722. t1+=t0;
  105723. t2-=t0;
  105724. t3=t1;
  105725. t4=t2;
  105726. t7+=(ido<<1);
  105727. t8=t7;
  105728. for(k=0;k<l1;k++){
  105729. t5=t3;
  105730. t6=t4;
  105731. t9=t8;
  105732. t11=t8;
  105733. for(i=2;i<ido;i+=2){
  105734. t5+=2;
  105735. t6+=2;
  105736. t9+=2;
  105737. t11-=2;
  105738. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105739. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105740. ch[t5]=cc[t9]-cc[t11];
  105741. ch[t6]=cc[t9]+cc[t11];
  105742. }
  105743. t3+=ido;
  105744. t4+=ido;
  105745. t8+=t10;
  105746. }
  105747. }
  105748. goto L116;
  105749. L112:
  105750. t1=0;
  105751. t2=ipp2*t0;
  105752. t7=0;
  105753. for(j=1;j<ipph;j++){
  105754. t1+=t0;
  105755. t2-=t0;
  105756. t3=t1;
  105757. t4=t2;
  105758. t7+=(ido<<1);
  105759. t8=t7;
  105760. t9=t7;
  105761. for(i=2;i<ido;i+=2){
  105762. t3+=2;
  105763. t4+=2;
  105764. t8+=2;
  105765. t9-=2;
  105766. t5=t3;
  105767. t6=t4;
  105768. t11=t8;
  105769. t12=t9;
  105770. for(k=0;k<l1;k++){
  105771. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105772. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105773. ch[t5]=cc[t11]-cc[t12];
  105774. ch[t6]=cc[t11]+cc[t12];
  105775. t5+=ido;
  105776. t6+=ido;
  105777. t11+=t10;
  105778. t12+=t10;
  105779. }
  105780. }
  105781. }
  105782. L116:
  105783. ar1=1.f;
  105784. ai1=0.f;
  105785. t1=0;
  105786. t9=(t2=ipp2*idl1);
  105787. t3=(ip-1)*idl1;
  105788. for(l=1;l<ipph;l++){
  105789. t1+=idl1;
  105790. t2-=idl1;
  105791. ar1h=dcp*ar1-dsp*ai1;
  105792. ai1=dcp*ai1+dsp*ar1;
  105793. ar1=ar1h;
  105794. t4=t1;
  105795. t5=t2;
  105796. t6=0;
  105797. t7=idl1;
  105798. t8=t3;
  105799. for(ik=0;ik<idl1;ik++){
  105800. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105801. c2[t5++]=ai1*ch2[t8++];
  105802. }
  105803. dc2=ar1;
  105804. ds2=ai1;
  105805. ar2=ar1;
  105806. ai2=ai1;
  105807. t6=idl1;
  105808. t7=t9-idl1;
  105809. for(j=2;j<ipph;j++){
  105810. t6+=idl1;
  105811. t7-=idl1;
  105812. ar2h=dc2*ar2-ds2*ai2;
  105813. ai2=dc2*ai2+ds2*ar2;
  105814. ar2=ar2h;
  105815. t4=t1;
  105816. t5=t2;
  105817. t11=t6;
  105818. t12=t7;
  105819. for(ik=0;ik<idl1;ik++){
  105820. c2[t4++]+=ar2*ch2[t11++];
  105821. c2[t5++]+=ai2*ch2[t12++];
  105822. }
  105823. }
  105824. }
  105825. t1=0;
  105826. for(j=1;j<ipph;j++){
  105827. t1+=idl1;
  105828. t2=t1;
  105829. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  105830. }
  105831. t1=0;
  105832. t2=ipp2*t0;
  105833. for(j=1;j<ipph;j++){
  105834. t1+=t0;
  105835. t2-=t0;
  105836. t3=t1;
  105837. t4=t2;
  105838. for(k=0;k<l1;k++){
  105839. ch[t3]=c1[t3]-c1[t4];
  105840. ch[t4]=c1[t3]+c1[t4];
  105841. t3+=ido;
  105842. t4+=ido;
  105843. }
  105844. }
  105845. if(ido==1)goto L132;
  105846. if(nbd<l1)goto L128;
  105847. t1=0;
  105848. t2=ipp2*t0;
  105849. for(j=1;j<ipph;j++){
  105850. t1+=t0;
  105851. t2-=t0;
  105852. t3=t1;
  105853. t4=t2;
  105854. for(k=0;k<l1;k++){
  105855. t5=t3;
  105856. t6=t4;
  105857. for(i=2;i<ido;i+=2){
  105858. t5+=2;
  105859. t6+=2;
  105860. ch[t5-1]=c1[t5-1]-c1[t6];
  105861. ch[t6-1]=c1[t5-1]+c1[t6];
  105862. ch[t5]=c1[t5]+c1[t6-1];
  105863. ch[t6]=c1[t5]-c1[t6-1];
  105864. }
  105865. t3+=ido;
  105866. t4+=ido;
  105867. }
  105868. }
  105869. goto L132;
  105870. L128:
  105871. t1=0;
  105872. t2=ipp2*t0;
  105873. for(j=1;j<ipph;j++){
  105874. t1+=t0;
  105875. t2-=t0;
  105876. t3=t1;
  105877. t4=t2;
  105878. for(i=2;i<ido;i+=2){
  105879. t3+=2;
  105880. t4+=2;
  105881. t5=t3;
  105882. t6=t4;
  105883. for(k=0;k<l1;k++){
  105884. ch[t5-1]=c1[t5-1]-c1[t6];
  105885. ch[t6-1]=c1[t5-1]+c1[t6];
  105886. ch[t5]=c1[t5]+c1[t6-1];
  105887. ch[t6]=c1[t5]-c1[t6-1];
  105888. t5+=ido;
  105889. t6+=ido;
  105890. }
  105891. }
  105892. }
  105893. L132:
  105894. if(ido==1)return;
  105895. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105896. t1=0;
  105897. for(j=1;j<ip;j++){
  105898. t2=(t1+=t0);
  105899. for(k=0;k<l1;k++){
  105900. c1[t2]=ch[t2];
  105901. t2+=ido;
  105902. }
  105903. }
  105904. if(nbd>l1)goto L139;
  105905. is= -ido-1;
  105906. t1=0;
  105907. for(j=1;j<ip;j++){
  105908. is+=ido;
  105909. t1+=t0;
  105910. idij=is;
  105911. t2=t1;
  105912. for(i=2;i<ido;i+=2){
  105913. t2+=2;
  105914. idij+=2;
  105915. t3=t2;
  105916. for(k=0;k<l1;k++){
  105917. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  105918. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  105919. t3+=ido;
  105920. }
  105921. }
  105922. }
  105923. return;
  105924. L139:
  105925. is= -ido-1;
  105926. t1=0;
  105927. for(j=1;j<ip;j++){
  105928. is+=ido;
  105929. t1+=t0;
  105930. t2=t1;
  105931. for(k=0;k<l1;k++){
  105932. idij=is;
  105933. t3=t2;
  105934. for(i=2;i<ido;i+=2){
  105935. idij+=2;
  105936. t3+=2;
  105937. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  105938. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  105939. }
  105940. t2+=ido;
  105941. }
  105942. }
  105943. }
  105944. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  105945. int i,k1,l1,l2;
  105946. int na;
  105947. int nf,ip,iw,ix2,ix3,ido,idl1;
  105948. nf=ifac[1];
  105949. na=0;
  105950. l1=1;
  105951. iw=1;
  105952. for(k1=0;k1<nf;k1++){
  105953. ip=ifac[k1 + 2];
  105954. l2=ip*l1;
  105955. ido=n/l2;
  105956. idl1=ido*l1;
  105957. if(ip!=4)goto L103;
  105958. ix2=iw+ido;
  105959. ix3=ix2+ido;
  105960. if(na!=0)
  105961. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105962. else
  105963. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105964. na=1-na;
  105965. goto L115;
  105966. L103:
  105967. if(ip!=2)goto L106;
  105968. if(na!=0)
  105969. dradb2(ido,l1,ch,c,wa+iw-1);
  105970. else
  105971. dradb2(ido,l1,c,ch,wa+iw-1);
  105972. na=1-na;
  105973. goto L115;
  105974. L106:
  105975. if(ip!=3)goto L109;
  105976. ix2=iw+ido;
  105977. if(na!=0)
  105978. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  105979. else
  105980. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  105981. na=1-na;
  105982. goto L115;
  105983. L109:
  105984. if(na!=0)
  105985. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105986. else
  105987. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105988. if(ido==1)na=1-na;
  105989. L115:
  105990. l1=l2;
  105991. iw+=(ip-1)*ido;
  105992. }
  105993. if(na==0)return;
  105994. for(i=0;i<n;i++)c[i]=ch[i];
  105995. }
  105996. void drft_forward(drft_lookup *l,float *data){
  105997. if(l->n==1)return;
  105998. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  105999. }
  106000. void drft_backward(drft_lookup *l,float *data){
  106001. if (l->n==1)return;
  106002. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106003. }
  106004. void drft_init(drft_lookup *l,int n){
  106005. l->n=n;
  106006. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106007. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106008. fdrffti(n, l->trigcache, l->splitcache);
  106009. }
  106010. void drft_clear(drft_lookup *l){
  106011. if(l){
  106012. if(l->trigcache)_ogg_free(l->trigcache);
  106013. if(l->splitcache)_ogg_free(l->splitcache);
  106014. memset(l,0,sizeof(*l));
  106015. }
  106016. }
  106017. #endif
  106018. /*** End of inlined file: smallft.c ***/
  106019. /*** Start of inlined file: synthesis.c ***/
  106020. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106021. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106022. // tasks..
  106023. #if JUCE_MSVC
  106024. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106025. #endif
  106026. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106027. #if JUCE_USE_OGGVORBIS
  106028. #include <stdio.h>
  106029. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106030. vorbis_dsp_state *vd=vb->vd;
  106031. private_state *b=(private_state*)vd->backend_state;
  106032. vorbis_info *vi=vd->vi;
  106033. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106034. oggpack_buffer *opb=&vb->opb;
  106035. int type,mode,i;
  106036. _vorbis_block_ripcord(vb);
  106037. oggpack_readinit(opb,op->packet,op->bytes);
  106038. if(oggpack_read(opb,1)!=0){
  106039. return(OV_ENOTAUDIO);
  106040. }
  106041. mode=oggpack_read(opb,b->modebits);
  106042. if(mode==-1)return(OV_EBADPACKET);
  106043. vb->mode=mode;
  106044. vb->W=ci->mode_param[mode]->blockflag;
  106045. if(vb->W){
  106046. vb->lW=oggpack_read(opb,1);
  106047. vb->nW=oggpack_read(opb,1);
  106048. if(vb->nW==-1) return(OV_EBADPACKET);
  106049. }else{
  106050. vb->lW=0;
  106051. vb->nW=0;
  106052. }
  106053. vb->granulepos=op->granulepos;
  106054. vb->sequence=op->packetno;
  106055. vb->eofflag=op->e_o_s;
  106056. vb->pcmend=ci->blocksizes[vb->W];
  106057. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106058. for(i=0;i<vi->channels;i++)
  106059. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106060. type=ci->map_type[ci->mode_param[mode]->mapping];
  106061. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106062. mapping]));
  106063. }
  106064. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106065. vorbis_dsp_state *vd=vb->vd;
  106066. private_state *b=(private_state*)vd->backend_state;
  106067. vorbis_info *vi=vd->vi;
  106068. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106069. oggpack_buffer *opb=&vb->opb;
  106070. int mode;
  106071. _vorbis_block_ripcord(vb);
  106072. oggpack_readinit(opb,op->packet,op->bytes);
  106073. if(oggpack_read(opb,1)!=0){
  106074. return(OV_ENOTAUDIO);
  106075. }
  106076. mode=oggpack_read(opb,b->modebits);
  106077. if(mode==-1)return(OV_EBADPACKET);
  106078. vb->mode=mode;
  106079. vb->W=ci->mode_param[mode]->blockflag;
  106080. if(vb->W){
  106081. vb->lW=oggpack_read(opb,1);
  106082. vb->nW=oggpack_read(opb,1);
  106083. if(vb->nW==-1) return(OV_EBADPACKET);
  106084. }else{
  106085. vb->lW=0;
  106086. vb->nW=0;
  106087. }
  106088. vb->granulepos=op->granulepos;
  106089. vb->sequence=op->packetno;
  106090. vb->eofflag=op->e_o_s;
  106091. vb->pcmend=0;
  106092. vb->pcm=NULL;
  106093. return(0);
  106094. }
  106095. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106096. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106097. oggpack_buffer opb;
  106098. int mode;
  106099. oggpack_readinit(&opb,op->packet,op->bytes);
  106100. if(oggpack_read(&opb,1)!=0){
  106101. return(OV_ENOTAUDIO);
  106102. }
  106103. {
  106104. int modebits=0;
  106105. int v=ci->modes;
  106106. while(v>1){
  106107. modebits++;
  106108. v>>=1;
  106109. }
  106110. mode=oggpack_read(&opb,modebits);
  106111. }
  106112. if(mode==-1)return(OV_EBADPACKET);
  106113. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106114. }
  106115. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106116. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106117. if(ci->blocksizes[0]<=64 && flag)return -1;
  106118. ci->halfrate_flag=(flag?1:0);
  106119. return 0;
  106120. }
  106121. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106122. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106123. return ci->halfrate_flag;
  106124. }
  106125. #endif
  106126. /*** End of inlined file: synthesis.c ***/
  106127. /*** Start of inlined file: vorbisenc.c ***/
  106128. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106129. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106130. // tasks..
  106131. #if JUCE_MSVC
  106132. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106133. #endif
  106134. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106135. #if JUCE_USE_OGGVORBIS
  106136. #include <stdlib.h>
  106137. #include <string.h>
  106138. #include <math.h>
  106139. typedef struct {
  106140. static_codebook *books[12][3];
  106141. } static_bookblock;
  106142. typedef struct {
  106143. int res_type;
  106144. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106145. vorbis_info_residue0 *res;
  106146. static_codebook *book_aux;
  106147. static_codebook *book_aux_managed;
  106148. static_bookblock *books_base;
  106149. static_bookblock *books_base_managed;
  106150. } vorbis_residue_template;
  106151. typedef struct {
  106152. vorbis_info_mapping0 *map;
  106153. vorbis_residue_template *res;
  106154. } vorbis_mapping_template;
  106155. typedef struct vp_adjblock{
  106156. int block[P_BANDS];
  106157. } vp_adjblock;
  106158. typedef struct {
  106159. int data[NOISE_COMPAND_LEVELS];
  106160. } compandblock;
  106161. typedef struct {
  106162. int att[P_NOISECURVES];
  106163. float boost;
  106164. float decay;
  106165. } att3;
  106166. typedef struct { int data[P_NOISECURVES]; } adj3;
  106167. typedef struct {
  106168. int pre[PACKETBLOBS];
  106169. int post[PACKETBLOBS];
  106170. float kHz[PACKETBLOBS];
  106171. float lowpasskHz[PACKETBLOBS];
  106172. } adj_stereo;
  106173. typedef struct {
  106174. int lo;
  106175. int hi;
  106176. int fixed;
  106177. } noiseguard;
  106178. typedef struct {
  106179. int data[P_NOISECURVES][17];
  106180. } noise3;
  106181. typedef struct {
  106182. int mappings;
  106183. double *rate_mapping;
  106184. double *quality_mapping;
  106185. int coupling_restriction;
  106186. long samplerate_min_restriction;
  106187. long samplerate_max_restriction;
  106188. int *blocksize_short;
  106189. int *blocksize_long;
  106190. att3 *psy_tone_masteratt;
  106191. int *psy_tone_0dB;
  106192. int *psy_tone_dBsuppress;
  106193. vp_adjblock *psy_tone_adj_impulse;
  106194. vp_adjblock *psy_tone_adj_long;
  106195. vp_adjblock *psy_tone_adj_other;
  106196. noiseguard *psy_noiseguards;
  106197. noise3 *psy_noise_bias_impulse;
  106198. noise3 *psy_noise_bias_padding;
  106199. noise3 *psy_noise_bias_trans;
  106200. noise3 *psy_noise_bias_long;
  106201. int *psy_noise_dBsuppress;
  106202. compandblock *psy_noise_compand;
  106203. double *psy_noise_compand_short_mapping;
  106204. double *psy_noise_compand_long_mapping;
  106205. int *psy_noise_normal_start[2];
  106206. int *psy_noise_normal_partition[2];
  106207. double *psy_noise_normal_thresh;
  106208. int *psy_ath_float;
  106209. int *psy_ath_abs;
  106210. double *psy_lowpass;
  106211. vorbis_info_psy_global *global_params;
  106212. double *global_mapping;
  106213. adj_stereo *stereo_modes;
  106214. static_codebook ***floor_books;
  106215. vorbis_info_floor1 *floor_params;
  106216. int *floor_short_mapping;
  106217. int *floor_long_mapping;
  106218. vorbis_mapping_template *maps;
  106219. } ve_setup_data_template;
  106220. static vorbis_info_mode _mode_template[2]={
  106221. {0,0,0,0},
  106222. {1,0,0,1}
  106223. };
  106224. static vorbis_info_mapping0 _map_nominal[2]={
  106225. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106226. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106227. };
  106228. /*** Start of inlined file: setup_44.h ***/
  106229. /*** Start of inlined file: floor_all.h ***/
  106230. /*** Start of inlined file: floor_books.h ***/
  106231. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106232. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106233. };
  106234. static static_codebook _huff_book_line_256x7_0sub1 = {
  106235. 1, 9,
  106236. _huff_lengthlist_line_256x7_0sub1,
  106237. 0, 0, 0, 0, 0,
  106238. NULL,
  106239. NULL,
  106240. NULL,
  106241. NULL,
  106242. 0
  106243. };
  106244. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106246. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106247. };
  106248. static static_codebook _huff_book_line_256x7_0sub2 = {
  106249. 1, 25,
  106250. _huff_lengthlist_line_256x7_0sub2,
  106251. 0, 0, 0, 0, 0,
  106252. NULL,
  106253. NULL,
  106254. NULL,
  106255. NULL,
  106256. 0
  106257. };
  106258. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106261. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106262. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106263. };
  106264. static static_codebook _huff_book_line_256x7_0sub3 = {
  106265. 1, 64,
  106266. _huff_lengthlist_line_256x7_0sub3,
  106267. 0, 0, 0, 0, 0,
  106268. NULL,
  106269. NULL,
  106270. NULL,
  106271. NULL,
  106272. 0
  106273. };
  106274. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106275. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106276. };
  106277. static static_codebook _huff_book_line_256x7_1sub1 = {
  106278. 1, 9,
  106279. _huff_lengthlist_line_256x7_1sub1,
  106280. 0, 0, 0, 0, 0,
  106281. NULL,
  106282. NULL,
  106283. NULL,
  106284. NULL,
  106285. 0
  106286. };
  106287. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106289. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106290. };
  106291. static static_codebook _huff_book_line_256x7_1sub2 = {
  106292. 1, 25,
  106293. _huff_lengthlist_line_256x7_1sub2,
  106294. 0, 0, 0, 0, 0,
  106295. NULL,
  106296. NULL,
  106297. NULL,
  106298. NULL,
  106299. 0
  106300. };
  106301. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106304. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106305. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106306. };
  106307. static static_codebook _huff_book_line_256x7_1sub3 = {
  106308. 1, 64,
  106309. _huff_lengthlist_line_256x7_1sub3,
  106310. 0, 0, 0, 0, 0,
  106311. NULL,
  106312. NULL,
  106313. NULL,
  106314. NULL,
  106315. 0
  106316. };
  106317. static long _huff_lengthlist_line_256x7_class0[] = {
  106318. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106319. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106320. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106321. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106322. };
  106323. static static_codebook _huff_book_line_256x7_class0 = {
  106324. 1, 64,
  106325. _huff_lengthlist_line_256x7_class0,
  106326. 0, 0, 0, 0, 0,
  106327. NULL,
  106328. NULL,
  106329. NULL,
  106330. NULL,
  106331. 0
  106332. };
  106333. static long _huff_lengthlist_line_256x7_class1[] = {
  106334. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106335. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106336. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106337. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106338. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106339. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106340. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106341. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106342. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106343. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106344. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106345. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106346. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106347. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106348. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106349. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106350. };
  106351. static static_codebook _huff_book_line_256x7_class1 = {
  106352. 1, 256,
  106353. _huff_lengthlist_line_256x7_class1,
  106354. 0, 0, 0, 0, 0,
  106355. NULL,
  106356. NULL,
  106357. NULL,
  106358. NULL,
  106359. 0
  106360. };
  106361. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106362. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106363. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106364. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106365. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106366. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106367. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106368. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106369. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106370. };
  106371. static static_codebook _huff_book_line_512x17_0sub0 = {
  106372. 1, 128,
  106373. _huff_lengthlist_line_512x17_0sub0,
  106374. 0, 0, 0, 0, 0,
  106375. NULL,
  106376. NULL,
  106377. NULL,
  106378. NULL,
  106379. 0
  106380. };
  106381. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106382. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106383. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106384. };
  106385. static static_codebook _huff_book_line_512x17_1sub0 = {
  106386. 1, 32,
  106387. _huff_lengthlist_line_512x17_1sub0,
  106388. 0, 0, 0, 0, 0,
  106389. NULL,
  106390. NULL,
  106391. NULL,
  106392. NULL,
  106393. 0
  106394. };
  106395. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106398. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106399. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106400. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106401. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106402. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106403. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106404. };
  106405. static static_codebook _huff_book_line_512x17_1sub1 = {
  106406. 1, 128,
  106407. _huff_lengthlist_line_512x17_1sub1,
  106408. 0, 0, 0, 0, 0,
  106409. NULL,
  106410. NULL,
  106411. NULL,
  106412. NULL,
  106413. 0
  106414. };
  106415. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106416. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106417. 5, 3,
  106418. };
  106419. static static_codebook _huff_book_line_512x17_2sub1 = {
  106420. 1, 18,
  106421. _huff_lengthlist_line_512x17_2sub1,
  106422. 0, 0, 0, 0, 0,
  106423. NULL,
  106424. NULL,
  106425. NULL,
  106426. NULL,
  106427. 0
  106428. };
  106429. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106431. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106432. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106433. 9, 8,
  106434. };
  106435. static static_codebook _huff_book_line_512x17_2sub2 = {
  106436. 1, 50,
  106437. _huff_lengthlist_line_512x17_2sub2,
  106438. 0, 0, 0, 0, 0,
  106439. NULL,
  106440. NULL,
  106441. NULL,
  106442. NULL,
  106443. 0
  106444. };
  106445. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106449. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106450. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106451. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106452. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106453. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106454. };
  106455. static static_codebook _huff_book_line_512x17_2sub3 = {
  106456. 1, 128,
  106457. _huff_lengthlist_line_512x17_2sub3,
  106458. 0, 0, 0, 0, 0,
  106459. NULL,
  106460. NULL,
  106461. NULL,
  106462. NULL,
  106463. 0
  106464. };
  106465. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106466. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106467. 5, 5,
  106468. };
  106469. static static_codebook _huff_book_line_512x17_3sub1 = {
  106470. 1, 18,
  106471. _huff_lengthlist_line_512x17_3sub1,
  106472. 0, 0, 0, 0, 0,
  106473. NULL,
  106474. NULL,
  106475. NULL,
  106476. NULL,
  106477. 0
  106478. };
  106479. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106481. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106482. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106483. 11,14,
  106484. };
  106485. static static_codebook _huff_book_line_512x17_3sub2 = {
  106486. 1, 50,
  106487. _huff_lengthlist_line_512x17_3sub2,
  106488. 0, 0, 0, 0, 0,
  106489. NULL,
  106490. NULL,
  106491. NULL,
  106492. NULL,
  106493. 0
  106494. };
  106495. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106499. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106500. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106501. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106502. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106503. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106504. };
  106505. static static_codebook _huff_book_line_512x17_3sub3 = {
  106506. 1, 128,
  106507. _huff_lengthlist_line_512x17_3sub3,
  106508. 0, 0, 0, 0, 0,
  106509. NULL,
  106510. NULL,
  106511. NULL,
  106512. NULL,
  106513. 0
  106514. };
  106515. static long _huff_lengthlist_line_512x17_class1[] = {
  106516. 1, 2, 3, 6, 5, 4, 7, 7,
  106517. };
  106518. static static_codebook _huff_book_line_512x17_class1 = {
  106519. 1, 8,
  106520. _huff_lengthlist_line_512x17_class1,
  106521. 0, 0, 0, 0, 0,
  106522. NULL,
  106523. NULL,
  106524. NULL,
  106525. NULL,
  106526. 0
  106527. };
  106528. static long _huff_lengthlist_line_512x17_class2[] = {
  106529. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106530. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106531. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106532. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106533. };
  106534. static static_codebook _huff_book_line_512x17_class2 = {
  106535. 1, 64,
  106536. _huff_lengthlist_line_512x17_class2,
  106537. 0, 0, 0, 0, 0,
  106538. NULL,
  106539. NULL,
  106540. NULL,
  106541. NULL,
  106542. 0
  106543. };
  106544. static long _huff_lengthlist_line_512x17_class3[] = {
  106545. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106546. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106547. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106548. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106549. };
  106550. static static_codebook _huff_book_line_512x17_class3 = {
  106551. 1, 64,
  106552. _huff_lengthlist_line_512x17_class3,
  106553. 0, 0, 0, 0, 0,
  106554. NULL,
  106555. NULL,
  106556. NULL,
  106557. NULL,
  106558. 0
  106559. };
  106560. static long _huff_lengthlist_line_128x4_class0[] = {
  106561. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106562. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106563. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106564. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106565. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106566. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106567. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106568. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106569. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106570. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106571. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106572. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106573. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106574. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106575. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106576. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106577. };
  106578. static static_codebook _huff_book_line_128x4_class0 = {
  106579. 1, 256,
  106580. _huff_lengthlist_line_128x4_class0,
  106581. 0, 0, 0, 0, 0,
  106582. NULL,
  106583. NULL,
  106584. NULL,
  106585. NULL,
  106586. 0
  106587. };
  106588. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106589. 2, 2, 2, 2,
  106590. };
  106591. static static_codebook _huff_book_line_128x4_0sub0 = {
  106592. 1, 4,
  106593. _huff_lengthlist_line_128x4_0sub0,
  106594. 0, 0, 0, 0, 0,
  106595. NULL,
  106596. NULL,
  106597. NULL,
  106598. NULL,
  106599. 0
  106600. };
  106601. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106602. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106603. };
  106604. static static_codebook _huff_book_line_128x4_0sub1 = {
  106605. 1, 10,
  106606. _huff_lengthlist_line_128x4_0sub1,
  106607. 0, 0, 0, 0, 0,
  106608. NULL,
  106609. NULL,
  106610. NULL,
  106611. NULL,
  106612. 0
  106613. };
  106614. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106616. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106617. };
  106618. static static_codebook _huff_book_line_128x4_0sub2 = {
  106619. 1, 25,
  106620. _huff_lengthlist_line_128x4_0sub2,
  106621. 0, 0, 0, 0, 0,
  106622. NULL,
  106623. NULL,
  106624. NULL,
  106625. NULL,
  106626. 0
  106627. };
  106628. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106631. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106632. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106633. };
  106634. static static_codebook _huff_book_line_128x4_0sub3 = {
  106635. 1, 64,
  106636. _huff_lengthlist_line_128x4_0sub3,
  106637. 0, 0, 0, 0, 0,
  106638. NULL,
  106639. NULL,
  106640. NULL,
  106641. NULL,
  106642. 0
  106643. };
  106644. static long _huff_lengthlist_line_256x4_class0[] = {
  106645. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106646. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106647. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106648. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106649. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106650. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106651. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106652. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106653. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106654. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106655. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106656. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106657. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106658. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106659. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106660. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106661. };
  106662. static static_codebook _huff_book_line_256x4_class0 = {
  106663. 1, 256,
  106664. _huff_lengthlist_line_256x4_class0,
  106665. 0, 0, 0, 0, 0,
  106666. NULL,
  106667. NULL,
  106668. NULL,
  106669. NULL,
  106670. 0
  106671. };
  106672. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106673. 2, 2, 2, 2,
  106674. };
  106675. static static_codebook _huff_book_line_256x4_0sub0 = {
  106676. 1, 4,
  106677. _huff_lengthlist_line_256x4_0sub0,
  106678. 0, 0, 0, 0, 0,
  106679. NULL,
  106680. NULL,
  106681. NULL,
  106682. NULL,
  106683. 0
  106684. };
  106685. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106686. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106687. };
  106688. static static_codebook _huff_book_line_256x4_0sub1 = {
  106689. 1, 10,
  106690. _huff_lengthlist_line_256x4_0sub1,
  106691. 0, 0, 0, 0, 0,
  106692. NULL,
  106693. NULL,
  106694. NULL,
  106695. NULL,
  106696. 0
  106697. };
  106698. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106700. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106701. };
  106702. static static_codebook _huff_book_line_256x4_0sub2 = {
  106703. 1, 25,
  106704. _huff_lengthlist_line_256x4_0sub2,
  106705. 0, 0, 0, 0, 0,
  106706. NULL,
  106707. NULL,
  106708. NULL,
  106709. NULL,
  106710. 0
  106711. };
  106712. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106715. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106716. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106717. };
  106718. static static_codebook _huff_book_line_256x4_0sub3 = {
  106719. 1, 64,
  106720. _huff_lengthlist_line_256x4_0sub3,
  106721. 0, 0, 0, 0, 0,
  106722. NULL,
  106723. NULL,
  106724. NULL,
  106725. NULL,
  106726. 0
  106727. };
  106728. static long _huff_lengthlist_line_128x7_class0[] = {
  106729. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106730. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106731. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106732. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106733. };
  106734. static static_codebook _huff_book_line_128x7_class0 = {
  106735. 1, 64,
  106736. _huff_lengthlist_line_128x7_class0,
  106737. 0, 0, 0, 0, 0,
  106738. NULL,
  106739. NULL,
  106740. NULL,
  106741. NULL,
  106742. 0
  106743. };
  106744. static long _huff_lengthlist_line_128x7_class1[] = {
  106745. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106746. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106747. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106748. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106749. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106750. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106751. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106752. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106753. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106754. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106755. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106756. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106757. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106758. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106759. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106760. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106761. };
  106762. static static_codebook _huff_book_line_128x7_class1 = {
  106763. 1, 256,
  106764. _huff_lengthlist_line_128x7_class1,
  106765. 0, 0, 0, 0, 0,
  106766. NULL,
  106767. NULL,
  106768. NULL,
  106769. NULL,
  106770. 0
  106771. };
  106772. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106773. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106774. };
  106775. static static_codebook _huff_book_line_128x7_0sub1 = {
  106776. 1, 9,
  106777. _huff_lengthlist_line_128x7_0sub1,
  106778. 0, 0, 0, 0, 0,
  106779. NULL,
  106780. NULL,
  106781. NULL,
  106782. NULL,
  106783. 0
  106784. };
  106785. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106787. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106788. };
  106789. static static_codebook _huff_book_line_128x7_0sub2 = {
  106790. 1, 25,
  106791. _huff_lengthlist_line_128x7_0sub2,
  106792. 0, 0, 0, 0, 0,
  106793. NULL,
  106794. NULL,
  106795. NULL,
  106796. NULL,
  106797. 0
  106798. };
  106799. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106802. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106803. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106804. };
  106805. static static_codebook _huff_book_line_128x7_0sub3 = {
  106806. 1, 64,
  106807. _huff_lengthlist_line_128x7_0sub3,
  106808. 0, 0, 0, 0, 0,
  106809. NULL,
  106810. NULL,
  106811. NULL,
  106812. NULL,
  106813. 0
  106814. };
  106815. static long _huff_lengthlist_line_128x7_1sub1[] = {
  106816. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  106817. };
  106818. static static_codebook _huff_book_line_128x7_1sub1 = {
  106819. 1, 9,
  106820. _huff_lengthlist_line_128x7_1sub1,
  106821. 0, 0, 0, 0, 0,
  106822. NULL,
  106823. NULL,
  106824. NULL,
  106825. NULL,
  106826. 0
  106827. };
  106828. static long _huff_lengthlist_line_128x7_1sub2[] = {
  106829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  106830. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  106831. };
  106832. static static_codebook _huff_book_line_128x7_1sub2 = {
  106833. 1, 25,
  106834. _huff_lengthlist_line_128x7_1sub2,
  106835. 0, 0, 0, 0, 0,
  106836. NULL,
  106837. NULL,
  106838. NULL,
  106839. NULL,
  106840. 0
  106841. };
  106842. static long _huff_lengthlist_line_128x7_1sub3[] = {
  106843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  106845. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  106846. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  106847. };
  106848. static static_codebook _huff_book_line_128x7_1sub3 = {
  106849. 1, 64,
  106850. _huff_lengthlist_line_128x7_1sub3,
  106851. 0, 0, 0, 0, 0,
  106852. NULL,
  106853. NULL,
  106854. NULL,
  106855. NULL,
  106856. 0
  106857. };
  106858. static long _huff_lengthlist_line_128x11_class1[] = {
  106859. 1, 6, 3, 7, 2, 4, 5, 7,
  106860. };
  106861. static static_codebook _huff_book_line_128x11_class1 = {
  106862. 1, 8,
  106863. _huff_lengthlist_line_128x11_class1,
  106864. 0, 0, 0, 0, 0,
  106865. NULL,
  106866. NULL,
  106867. NULL,
  106868. NULL,
  106869. 0
  106870. };
  106871. static long _huff_lengthlist_line_128x11_class2[] = {
  106872. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  106873. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  106874. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  106875. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  106876. };
  106877. static static_codebook _huff_book_line_128x11_class2 = {
  106878. 1, 64,
  106879. _huff_lengthlist_line_128x11_class2,
  106880. 0, 0, 0, 0, 0,
  106881. NULL,
  106882. NULL,
  106883. NULL,
  106884. NULL,
  106885. 0
  106886. };
  106887. static long _huff_lengthlist_line_128x11_class3[] = {
  106888. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  106889. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  106890. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  106891. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  106892. };
  106893. static static_codebook _huff_book_line_128x11_class3 = {
  106894. 1, 64,
  106895. _huff_lengthlist_line_128x11_class3,
  106896. 0, 0, 0, 0, 0,
  106897. NULL,
  106898. NULL,
  106899. NULL,
  106900. NULL,
  106901. 0
  106902. };
  106903. static long _huff_lengthlist_line_128x11_0sub0[] = {
  106904. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106905. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  106906. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  106907. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  106908. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  106909. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  106910. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  106911. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106912. };
  106913. static static_codebook _huff_book_line_128x11_0sub0 = {
  106914. 1, 128,
  106915. _huff_lengthlist_line_128x11_0sub0,
  106916. 0, 0, 0, 0, 0,
  106917. NULL,
  106918. NULL,
  106919. NULL,
  106920. NULL,
  106921. 0
  106922. };
  106923. static long _huff_lengthlist_line_128x11_1sub0[] = {
  106924. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  106925. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  106926. };
  106927. static static_codebook _huff_book_line_128x11_1sub0 = {
  106928. 1, 32,
  106929. _huff_lengthlist_line_128x11_1sub0,
  106930. 0, 0, 0, 0, 0,
  106931. NULL,
  106932. NULL,
  106933. NULL,
  106934. NULL,
  106935. 0
  106936. };
  106937. static long _huff_lengthlist_line_128x11_1sub1[] = {
  106938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106940. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  106941. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  106942. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  106943. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  106944. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  106945. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  106946. };
  106947. static static_codebook _huff_book_line_128x11_1sub1 = {
  106948. 1, 128,
  106949. _huff_lengthlist_line_128x11_1sub1,
  106950. 0, 0, 0, 0, 0,
  106951. NULL,
  106952. NULL,
  106953. NULL,
  106954. NULL,
  106955. 0
  106956. };
  106957. static long _huff_lengthlist_line_128x11_2sub1[] = {
  106958. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  106959. 5, 5,
  106960. };
  106961. static static_codebook _huff_book_line_128x11_2sub1 = {
  106962. 1, 18,
  106963. _huff_lengthlist_line_128x11_2sub1,
  106964. 0, 0, 0, 0, 0,
  106965. NULL,
  106966. NULL,
  106967. NULL,
  106968. NULL,
  106969. 0
  106970. };
  106971. static long _huff_lengthlist_line_128x11_2sub2[] = {
  106972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106973. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  106974. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  106975. 8,11,
  106976. };
  106977. static static_codebook _huff_book_line_128x11_2sub2 = {
  106978. 1, 50,
  106979. _huff_lengthlist_line_128x11_2sub2,
  106980. 0, 0, 0, 0, 0,
  106981. NULL,
  106982. NULL,
  106983. NULL,
  106984. NULL,
  106985. 0
  106986. };
  106987. static long _huff_lengthlist_line_128x11_2sub3[] = {
  106988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106991. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  106992. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106993. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106994. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106995. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106996. };
  106997. static static_codebook _huff_book_line_128x11_2sub3 = {
  106998. 1, 128,
  106999. _huff_lengthlist_line_128x11_2sub3,
  107000. 0, 0, 0, 0, 0,
  107001. NULL,
  107002. NULL,
  107003. NULL,
  107004. NULL,
  107005. 0
  107006. };
  107007. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107008. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107009. 5, 4,
  107010. };
  107011. static static_codebook _huff_book_line_128x11_3sub1 = {
  107012. 1, 18,
  107013. _huff_lengthlist_line_128x11_3sub1,
  107014. 0, 0, 0, 0, 0,
  107015. NULL,
  107016. NULL,
  107017. NULL,
  107018. NULL,
  107019. 0
  107020. };
  107021. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107023. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107024. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107025. 12, 6,
  107026. };
  107027. static static_codebook _huff_book_line_128x11_3sub2 = {
  107028. 1, 50,
  107029. _huff_lengthlist_line_128x11_3sub2,
  107030. 0, 0, 0, 0, 0,
  107031. NULL,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. 0
  107036. };
  107037. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107041. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107042. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107043. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107044. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107045. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107046. };
  107047. static static_codebook _huff_book_line_128x11_3sub3 = {
  107048. 1, 128,
  107049. _huff_lengthlist_line_128x11_3sub3,
  107050. 0, 0, 0, 0, 0,
  107051. NULL,
  107052. NULL,
  107053. NULL,
  107054. NULL,
  107055. 0
  107056. };
  107057. static long _huff_lengthlist_line_128x17_class1[] = {
  107058. 1, 3, 4, 7, 2, 5, 6, 7,
  107059. };
  107060. static static_codebook _huff_book_line_128x17_class1 = {
  107061. 1, 8,
  107062. _huff_lengthlist_line_128x17_class1,
  107063. 0, 0, 0, 0, 0,
  107064. NULL,
  107065. NULL,
  107066. NULL,
  107067. NULL,
  107068. 0
  107069. };
  107070. static long _huff_lengthlist_line_128x17_class2[] = {
  107071. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107072. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107073. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107074. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107075. };
  107076. static static_codebook _huff_book_line_128x17_class2 = {
  107077. 1, 64,
  107078. _huff_lengthlist_line_128x17_class2,
  107079. 0, 0, 0, 0, 0,
  107080. NULL,
  107081. NULL,
  107082. NULL,
  107083. NULL,
  107084. 0
  107085. };
  107086. static long _huff_lengthlist_line_128x17_class3[] = {
  107087. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107088. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107089. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107090. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107091. };
  107092. static static_codebook _huff_book_line_128x17_class3 = {
  107093. 1, 64,
  107094. _huff_lengthlist_line_128x17_class3,
  107095. 0, 0, 0, 0, 0,
  107096. NULL,
  107097. NULL,
  107098. NULL,
  107099. NULL,
  107100. 0
  107101. };
  107102. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107103. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107104. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107105. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107106. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107107. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107108. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107109. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107110. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107111. };
  107112. static static_codebook _huff_book_line_128x17_0sub0 = {
  107113. 1, 128,
  107114. _huff_lengthlist_line_128x17_0sub0,
  107115. 0, 0, 0, 0, 0,
  107116. NULL,
  107117. NULL,
  107118. NULL,
  107119. NULL,
  107120. 0
  107121. };
  107122. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107123. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107124. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107125. };
  107126. static static_codebook _huff_book_line_128x17_1sub0 = {
  107127. 1, 32,
  107128. _huff_lengthlist_line_128x17_1sub0,
  107129. 0, 0, 0, 0, 0,
  107130. NULL,
  107131. NULL,
  107132. NULL,
  107133. NULL,
  107134. 0
  107135. };
  107136. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107139. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107140. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107141. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107142. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107143. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107144. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107145. };
  107146. static static_codebook _huff_book_line_128x17_1sub1 = {
  107147. 1, 128,
  107148. _huff_lengthlist_line_128x17_1sub1,
  107149. 0, 0, 0, 0, 0,
  107150. NULL,
  107151. NULL,
  107152. NULL,
  107153. NULL,
  107154. 0
  107155. };
  107156. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107157. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107158. 9, 4,
  107159. };
  107160. static static_codebook _huff_book_line_128x17_2sub1 = {
  107161. 1, 18,
  107162. _huff_lengthlist_line_128x17_2sub1,
  107163. 0, 0, 0, 0, 0,
  107164. NULL,
  107165. NULL,
  107166. NULL,
  107167. NULL,
  107168. 0
  107169. };
  107170. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107172. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107173. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107174. 13,13,
  107175. };
  107176. static static_codebook _huff_book_line_128x17_2sub2 = {
  107177. 1, 50,
  107178. _huff_lengthlist_line_128x17_2sub2,
  107179. 0, 0, 0, 0, 0,
  107180. NULL,
  107181. NULL,
  107182. NULL,
  107183. NULL,
  107184. 0
  107185. };
  107186. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107190. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107191. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107192. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107193. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107194. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107195. };
  107196. static static_codebook _huff_book_line_128x17_2sub3 = {
  107197. 1, 128,
  107198. _huff_lengthlist_line_128x17_2sub3,
  107199. 0, 0, 0, 0, 0,
  107200. NULL,
  107201. NULL,
  107202. NULL,
  107203. NULL,
  107204. 0
  107205. };
  107206. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107207. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107208. 6, 4,
  107209. };
  107210. static static_codebook _huff_book_line_128x17_3sub1 = {
  107211. 1, 18,
  107212. _huff_lengthlist_line_128x17_3sub1,
  107213. 0, 0, 0, 0, 0,
  107214. NULL,
  107215. NULL,
  107216. NULL,
  107217. NULL,
  107218. 0
  107219. };
  107220. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107222. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107223. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107224. 10, 8,
  107225. };
  107226. static static_codebook _huff_book_line_128x17_3sub2 = {
  107227. 1, 50,
  107228. _huff_lengthlist_line_128x17_3sub2,
  107229. 0, 0, 0, 0, 0,
  107230. NULL,
  107231. NULL,
  107232. NULL,
  107233. NULL,
  107234. 0
  107235. };
  107236. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107240. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107241. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107242. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107243. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107244. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107245. };
  107246. static static_codebook _huff_book_line_128x17_3sub3 = {
  107247. 1, 128,
  107248. _huff_lengthlist_line_128x17_3sub3,
  107249. 0, 0, 0, 0, 0,
  107250. NULL,
  107251. NULL,
  107252. NULL,
  107253. NULL,
  107254. 0
  107255. };
  107256. static long _huff_lengthlist_line_1024x27_class1[] = {
  107257. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107258. };
  107259. static static_codebook _huff_book_line_1024x27_class1 = {
  107260. 1, 16,
  107261. _huff_lengthlist_line_1024x27_class1,
  107262. 0, 0, 0, 0, 0,
  107263. NULL,
  107264. NULL,
  107265. NULL,
  107266. NULL,
  107267. 0
  107268. };
  107269. static long _huff_lengthlist_line_1024x27_class2[] = {
  107270. 1, 4, 2, 6, 3, 7, 5, 7,
  107271. };
  107272. static static_codebook _huff_book_line_1024x27_class2 = {
  107273. 1, 8,
  107274. _huff_lengthlist_line_1024x27_class2,
  107275. 0, 0, 0, 0, 0,
  107276. NULL,
  107277. NULL,
  107278. NULL,
  107279. NULL,
  107280. 0
  107281. };
  107282. static long _huff_lengthlist_line_1024x27_class3[] = {
  107283. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107284. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107285. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107286. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107287. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107288. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107289. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107290. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107291. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107292. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107293. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107294. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107295. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107296. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107297. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107298. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107299. };
  107300. static static_codebook _huff_book_line_1024x27_class3 = {
  107301. 1, 256,
  107302. _huff_lengthlist_line_1024x27_class3,
  107303. 0, 0, 0, 0, 0,
  107304. NULL,
  107305. NULL,
  107306. NULL,
  107307. NULL,
  107308. 0
  107309. };
  107310. static long _huff_lengthlist_line_1024x27_class4[] = {
  107311. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107312. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107313. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107314. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107315. };
  107316. static static_codebook _huff_book_line_1024x27_class4 = {
  107317. 1, 64,
  107318. _huff_lengthlist_line_1024x27_class4,
  107319. 0, 0, 0, 0, 0,
  107320. NULL,
  107321. NULL,
  107322. NULL,
  107323. NULL,
  107324. 0
  107325. };
  107326. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107327. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107328. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107329. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107330. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107331. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107332. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107333. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107334. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107335. };
  107336. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107337. 1, 128,
  107338. _huff_lengthlist_line_1024x27_0sub0,
  107339. 0, 0, 0, 0, 0,
  107340. NULL,
  107341. NULL,
  107342. NULL,
  107343. NULL,
  107344. 0
  107345. };
  107346. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107347. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107348. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107349. };
  107350. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107351. 1, 32,
  107352. _huff_lengthlist_line_1024x27_1sub0,
  107353. 0, 0, 0, 0, 0,
  107354. NULL,
  107355. NULL,
  107356. NULL,
  107357. NULL,
  107358. 0
  107359. };
  107360. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107363. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107364. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107365. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107366. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107367. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107368. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107369. };
  107370. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107371. 1, 128,
  107372. _huff_lengthlist_line_1024x27_1sub1,
  107373. 0, 0, 0, 0, 0,
  107374. NULL,
  107375. NULL,
  107376. NULL,
  107377. NULL,
  107378. 0
  107379. };
  107380. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107381. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107382. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107383. };
  107384. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107385. 1, 32,
  107386. _huff_lengthlist_line_1024x27_2sub0,
  107387. 0, 0, 0, 0, 0,
  107388. NULL,
  107389. NULL,
  107390. NULL,
  107391. NULL,
  107392. 0
  107393. };
  107394. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107397. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107398. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107399. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107400. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107401. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107402. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107403. };
  107404. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107405. 1, 128,
  107406. _huff_lengthlist_line_1024x27_2sub1,
  107407. 0, 0, 0, 0, 0,
  107408. NULL,
  107409. NULL,
  107410. NULL,
  107411. NULL,
  107412. 0
  107413. };
  107414. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107415. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107416. 5, 5,
  107417. };
  107418. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107419. 1, 18,
  107420. _huff_lengthlist_line_1024x27_3sub1,
  107421. 0, 0, 0, 0, 0,
  107422. NULL,
  107423. NULL,
  107424. NULL,
  107425. NULL,
  107426. 0
  107427. };
  107428. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107430. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107431. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107432. 9,11,
  107433. };
  107434. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107435. 1, 50,
  107436. _huff_lengthlist_line_1024x27_3sub2,
  107437. 0, 0, 0, 0, 0,
  107438. NULL,
  107439. NULL,
  107440. NULL,
  107441. NULL,
  107442. 0
  107443. };
  107444. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107448. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107449. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107450. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107451. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107452. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107453. };
  107454. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107455. 1, 128,
  107456. _huff_lengthlist_line_1024x27_3sub3,
  107457. 0, 0, 0, 0, 0,
  107458. NULL,
  107459. NULL,
  107460. NULL,
  107461. NULL,
  107462. 0
  107463. };
  107464. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107465. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107466. 5, 4,
  107467. };
  107468. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107469. 1, 18,
  107470. _huff_lengthlist_line_1024x27_4sub1,
  107471. 0, 0, 0, 0, 0,
  107472. NULL,
  107473. NULL,
  107474. NULL,
  107475. NULL,
  107476. 0
  107477. };
  107478. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107480. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107481. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107482. 9,12,
  107483. };
  107484. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107485. 1, 50,
  107486. _huff_lengthlist_line_1024x27_4sub2,
  107487. 0, 0, 0, 0, 0,
  107488. NULL,
  107489. NULL,
  107490. NULL,
  107491. NULL,
  107492. 0
  107493. };
  107494. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107498. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107499. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107500. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107501. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107502. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107503. };
  107504. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107505. 1, 128,
  107506. _huff_lengthlist_line_1024x27_4sub3,
  107507. 0, 0, 0, 0, 0,
  107508. NULL,
  107509. NULL,
  107510. NULL,
  107511. NULL,
  107512. 0
  107513. };
  107514. static long _huff_lengthlist_line_2048x27_class1[] = {
  107515. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107516. };
  107517. static static_codebook _huff_book_line_2048x27_class1 = {
  107518. 1, 16,
  107519. _huff_lengthlist_line_2048x27_class1,
  107520. 0, 0, 0, 0, 0,
  107521. NULL,
  107522. NULL,
  107523. NULL,
  107524. NULL,
  107525. 0
  107526. };
  107527. static long _huff_lengthlist_line_2048x27_class2[] = {
  107528. 1, 2, 3, 6, 4, 7, 5, 7,
  107529. };
  107530. static static_codebook _huff_book_line_2048x27_class2 = {
  107531. 1, 8,
  107532. _huff_lengthlist_line_2048x27_class2,
  107533. 0, 0, 0, 0, 0,
  107534. NULL,
  107535. NULL,
  107536. NULL,
  107537. NULL,
  107538. 0
  107539. };
  107540. static long _huff_lengthlist_line_2048x27_class3[] = {
  107541. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107542. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107543. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107544. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107545. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107546. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107547. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107548. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107549. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107550. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107551. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107552. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107553. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107554. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107555. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107556. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107557. };
  107558. static static_codebook _huff_book_line_2048x27_class3 = {
  107559. 1, 256,
  107560. _huff_lengthlist_line_2048x27_class3,
  107561. 0, 0, 0, 0, 0,
  107562. NULL,
  107563. NULL,
  107564. NULL,
  107565. NULL,
  107566. 0
  107567. };
  107568. static long _huff_lengthlist_line_2048x27_class4[] = {
  107569. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107570. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107571. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107572. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107573. };
  107574. static static_codebook _huff_book_line_2048x27_class4 = {
  107575. 1, 64,
  107576. _huff_lengthlist_line_2048x27_class4,
  107577. 0, 0, 0, 0, 0,
  107578. NULL,
  107579. NULL,
  107580. NULL,
  107581. NULL,
  107582. 0
  107583. };
  107584. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107585. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107586. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107587. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107588. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107589. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107590. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107591. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107592. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107593. };
  107594. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107595. 1, 128,
  107596. _huff_lengthlist_line_2048x27_0sub0,
  107597. 0, 0, 0, 0, 0,
  107598. NULL,
  107599. NULL,
  107600. NULL,
  107601. NULL,
  107602. 0
  107603. };
  107604. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107605. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107606. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107607. };
  107608. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107609. 1, 32,
  107610. _huff_lengthlist_line_2048x27_1sub0,
  107611. 0, 0, 0, 0, 0,
  107612. NULL,
  107613. NULL,
  107614. NULL,
  107615. NULL,
  107616. 0
  107617. };
  107618. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107621. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107622. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107623. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107624. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107625. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107626. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107627. };
  107628. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107629. 1, 128,
  107630. _huff_lengthlist_line_2048x27_1sub1,
  107631. 0, 0, 0, 0, 0,
  107632. NULL,
  107633. NULL,
  107634. NULL,
  107635. NULL,
  107636. 0
  107637. };
  107638. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107639. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107640. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107641. };
  107642. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107643. 1, 32,
  107644. _huff_lengthlist_line_2048x27_2sub0,
  107645. 0, 0, 0, 0, 0,
  107646. NULL,
  107647. NULL,
  107648. NULL,
  107649. NULL,
  107650. 0
  107651. };
  107652. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107655. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107656. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107657. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107658. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107659. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107660. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107661. };
  107662. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107663. 1, 128,
  107664. _huff_lengthlist_line_2048x27_2sub1,
  107665. 0, 0, 0, 0, 0,
  107666. NULL,
  107667. NULL,
  107668. NULL,
  107669. NULL,
  107670. 0
  107671. };
  107672. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107673. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107674. 5, 5,
  107675. };
  107676. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107677. 1, 18,
  107678. _huff_lengthlist_line_2048x27_3sub1,
  107679. 0, 0, 0, 0, 0,
  107680. NULL,
  107681. NULL,
  107682. NULL,
  107683. NULL,
  107684. 0
  107685. };
  107686. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107688. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107689. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107690. 10,12,
  107691. };
  107692. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107693. 1, 50,
  107694. _huff_lengthlist_line_2048x27_3sub2,
  107695. 0, 0, 0, 0, 0,
  107696. NULL,
  107697. NULL,
  107698. NULL,
  107699. NULL,
  107700. 0
  107701. };
  107702. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107706. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107707. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107708. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107709. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107710. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107711. };
  107712. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107713. 1, 128,
  107714. _huff_lengthlist_line_2048x27_3sub3,
  107715. 0, 0, 0, 0, 0,
  107716. NULL,
  107717. NULL,
  107718. NULL,
  107719. NULL,
  107720. 0
  107721. };
  107722. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107723. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107724. 4, 5,
  107725. };
  107726. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107727. 1, 18,
  107728. _huff_lengthlist_line_2048x27_4sub1,
  107729. 0, 0, 0, 0, 0,
  107730. NULL,
  107731. NULL,
  107732. NULL,
  107733. NULL,
  107734. 0
  107735. };
  107736. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107738. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107739. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107740. 10,10,
  107741. };
  107742. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107743. 1, 50,
  107744. _huff_lengthlist_line_2048x27_4sub2,
  107745. 0, 0, 0, 0, 0,
  107746. NULL,
  107747. NULL,
  107748. NULL,
  107749. NULL,
  107750. 0
  107751. };
  107752. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107756. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107757. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107758. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107759. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107760. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107761. };
  107762. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107763. 1, 128,
  107764. _huff_lengthlist_line_2048x27_4sub3,
  107765. 0, 0, 0, 0, 0,
  107766. NULL,
  107767. NULL,
  107768. NULL,
  107769. NULL,
  107770. 0
  107771. };
  107772. static long _huff_lengthlist_line_256x4low_class0[] = {
  107773. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107774. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107775. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107776. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107777. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107778. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107779. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107780. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107781. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107782. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107783. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107784. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107785. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107786. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107787. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107788. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107789. };
  107790. static static_codebook _huff_book_line_256x4low_class0 = {
  107791. 1, 256,
  107792. _huff_lengthlist_line_256x4low_class0,
  107793. 0, 0, 0, 0, 0,
  107794. NULL,
  107795. NULL,
  107796. NULL,
  107797. NULL,
  107798. 0
  107799. };
  107800. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107801. 1, 3, 2, 3,
  107802. };
  107803. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107804. 1, 4,
  107805. _huff_lengthlist_line_256x4low_0sub0,
  107806. 0, 0, 0, 0, 0,
  107807. NULL,
  107808. NULL,
  107809. NULL,
  107810. NULL,
  107811. 0
  107812. };
  107813. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  107814. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  107815. };
  107816. static static_codebook _huff_book_line_256x4low_0sub1 = {
  107817. 1, 10,
  107818. _huff_lengthlist_line_256x4low_0sub1,
  107819. 0, 0, 0, 0, 0,
  107820. NULL,
  107821. NULL,
  107822. NULL,
  107823. NULL,
  107824. 0
  107825. };
  107826. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  107827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  107828. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  107829. };
  107830. static static_codebook _huff_book_line_256x4low_0sub2 = {
  107831. 1, 25,
  107832. _huff_lengthlist_line_256x4low_0sub2,
  107833. 0, 0, 0, 0, 0,
  107834. NULL,
  107835. NULL,
  107836. NULL,
  107837. NULL,
  107838. 0
  107839. };
  107840. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  107841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  107843. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  107844. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  107845. };
  107846. static static_codebook _huff_book_line_256x4low_0sub3 = {
  107847. 1, 64,
  107848. _huff_lengthlist_line_256x4low_0sub3,
  107849. 0, 0, 0, 0, 0,
  107850. NULL,
  107851. NULL,
  107852. NULL,
  107853. NULL,
  107854. 0
  107855. };
  107856. /*** End of inlined file: floor_books.h ***/
  107857. static static_codebook *_floor_128x4_books[]={
  107858. &_huff_book_line_128x4_class0,
  107859. &_huff_book_line_128x4_0sub0,
  107860. &_huff_book_line_128x4_0sub1,
  107861. &_huff_book_line_128x4_0sub2,
  107862. &_huff_book_line_128x4_0sub3,
  107863. };
  107864. static static_codebook *_floor_256x4_books[]={
  107865. &_huff_book_line_256x4_class0,
  107866. &_huff_book_line_256x4_0sub0,
  107867. &_huff_book_line_256x4_0sub1,
  107868. &_huff_book_line_256x4_0sub2,
  107869. &_huff_book_line_256x4_0sub3,
  107870. };
  107871. static static_codebook *_floor_128x7_books[]={
  107872. &_huff_book_line_128x7_class0,
  107873. &_huff_book_line_128x7_class1,
  107874. &_huff_book_line_128x7_0sub1,
  107875. &_huff_book_line_128x7_0sub2,
  107876. &_huff_book_line_128x7_0sub3,
  107877. &_huff_book_line_128x7_1sub1,
  107878. &_huff_book_line_128x7_1sub2,
  107879. &_huff_book_line_128x7_1sub3,
  107880. };
  107881. static static_codebook *_floor_256x7_books[]={
  107882. &_huff_book_line_256x7_class0,
  107883. &_huff_book_line_256x7_class1,
  107884. &_huff_book_line_256x7_0sub1,
  107885. &_huff_book_line_256x7_0sub2,
  107886. &_huff_book_line_256x7_0sub3,
  107887. &_huff_book_line_256x7_1sub1,
  107888. &_huff_book_line_256x7_1sub2,
  107889. &_huff_book_line_256x7_1sub3,
  107890. };
  107891. static static_codebook *_floor_128x11_books[]={
  107892. &_huff_book_line_128x11_class1,
  107893. &_huff_book_line_128x11_class2,
  107894. &_huff_book_line_128x11_class3,
  107895. &_huff_book_line_128x11_0sub0,
  107896. &_huff_book_line_128x11_1sub0,
  107897. &_huff_book_line_128x11_1sub1,
  107898. &_huff_book_line_128x11_2sub1,
  107899. &_huff_book_line_128x11_2sub2,
  107900. &_huff_book_line_128x11_2sub3,
  107901. &_huff_book_line_128x11_3sub1,
  107902. &_huff_book_line_128x11_3sub2,
  107903. &_huff_book_line_128x11_3sub3,
  107904. };
  107905. static static_codebook *_floor_128x17_books[]={
  107906. &_huff_book_line_128x17_class1,
  107907. &_huff_book_line_128x17_class2,
  107908. &_huff_book_line_128x17_class3,
  107909. &_huff_book_line_128x17_0sub0,
  107910. &_huff_book_line_128x17_1sub0,
  107911. &_huff_book_line_128x17_1sub1,
  107912. &_huff_book_line_128x17_2sub1,
  107913. &_huff_book_line_128x17_2sub2,
  107914. &_huff_book_line_128x17_2sub3,
  107915. &_huff_book_line_128x17_3sub1,
  107916. &_huff_book_line_128x17_3sub2,
  107917. &_huff_book_line_128x17_3sub3,
  107918. };
  107919. static static_codebook *_floor_256x4low_books[]={
  107920. &_huff_book_line_256x4low_class0,
  107921. &_huff_book_line_256x4low_0sub0,
  107922. &_huff_book_line_256x4low_0sub1,
  107923. &_huff_book_line_256x4low_0sub2,
  107924. &_huff_book_line_256x4low_0sub3,
  107925. };
  107926. static static_codebook *_floor_1024x27_books[]={
  107927. &_huff_book_line_1024x27_class1,
  107928. &_huff_book_line_1024x27_class2,
  107929. &_huff_book_line_1024x27_class3,
  107930. &_huff_book_line_1024x27_class4,
  107931. &_huff_book_line_1024x27_0sub0,
  107932. &_huff_book_line_1024x27_1sub0,
  107933. &_huff_book_line_1024x27_1sub1,
  107934. &_huff_book_line_1024x27_2sub0,
  107935. &_huff_book_line_1024x27_2sub1,
  107936. &_huff_book_line_1024x27_3sub1,
  107937. &_huff_book_line_1024x27_3sub2,
  107938. &_huff_book_line_1024x27_3sub3,
  107939. &_huff_book_line_1024x27_4sub1,
  107940. &_huff_book_line_1024x27_4sub2,
  107941. &_huff_book_line_1024x27_4sub3,
  107942. };
  107943. static static_codebook *_floor_2048x27_books[]={
  107944. &_huff_book_line_2048x27_class1,
  107945. &_huff_book_line_2048x27_class2,
  107946. &_huff_book_line_2048x27_class3,
  107947. &_huff_book_line_2048x27_class4,
  107948. &_huff_book_line_2048x27_0sub0,
  107949. &_huff_book_line_2048x27_1sub0,
  107950. &_huff_book_line_2048x27_1sub1,
  107951. &_huff_book_line_2048x27_2sub0,
  107952. &_huff_book_line_2048x27_2sub1,
  107953. &_huff_book_line_2048x27_3sub1,
  107954. &_huff_book_line_2048x27_3sub2,
  107955. &_huff_book_line_2048x27_3sub3,
  107956. &_huff_book_line_2048x27_4sub1,
  107957. &_huff_book_line_2048x27_4sub2,
  107958. &_huff_book_line_2048x27_4sub3,
  107959. };
  107960. static static_codebook *_floor_512x17_books[]={
  107961. &_huff_book_line_512x17_class1,
  107962. &_huff_book_line_512x17_class2,
  107963. &_huff_book_line_512x17_class3,
  107964. &_huff_book_line_512x17_0sub0,
  107965. &_huff_book_line_512x17_1sub0,
  107966. &_huff_book_line_512x17_1sub1,
  107967. &_huff_book_line_512x17_2sub1,
  107968. &_huff_book_line_512x17_2sub2,
  107969. &_huff_book_line_512x17_2sub3,
  107970. &_huff_book_line_512x17_3sub1,
  107971. &_huff_book_line_512x17_3sub2,
  107972. &_huff_book_line_512x17_3sub3,
  107973. };
  107974. static static_codebook **_floor_books[10]={
  107975. _floor_128x4_books,
  107976. _floor_256x4_books,
  107977. _floor_128x7_books,
  107978. _floor_256x7_books,
  107979. _floor_128x11_books,
  107980. _floor_128x17_books,
  107981. _floor_256x4low_books,
  107982. _floor_1024x27_books,
  107983. _floor_2048x27_books,
  107984. _floor_512x17_books,
  107985. };
  107986. static vorbis_info_floor1 _floor[10]={
  107987. {
  107988. 1,{0},{4},{2},{0},
  107989. {{1,2,3,4}},
  107990. 4,{0,128, 33,8,16,70},
  107991. 60,30,500, 1.,18., -1
  107992. },
  107993. {
  107994. 1,{0},{4},{2},{0},
  107995. {{1,2,3,4}},
  107996. 4,{0,256, 66,16,32,140},
  107997. 60,30,500, 1.,18., -1
  107998. },
  107999. {
  108000. 2,{0,1},{3,4},{2,2},{0,1},
  108001. {{-1,2,3,4},{-1,5,6,7}},
  108002. 4,{0,128, 14,4,58, 2,8,28,90},
  108003. 60,30,500, 1.,18., -1
  108004. },
  108005. {
  108006. 2,{0,1},{3,4},{2,2},{0,1},
  108007. {{-1,2,3,4},{-1,5,6,7}},
  108008. 4,{0,256, 28,8,116, 4,16,56,180},
  108009. 60,30,500, 1.,18., -1
  108010. },
  108011. {
  108012. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108013. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108014. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108015. 60,30,500, 1,18., -1
  108016. },
  108017. {
  108018. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108019. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108020. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108021. 60,30,500, 1,18., -1
  108022. },
  108023. {
  108024. 1,{0},{4},{2},{0},
  108025. {{1,2,3,4}},
  108026. 4,{0,256, 66,16,32,140},
  108027. 60,30,500, 1.,18., -1
  108028. },
  108029. {
  108030. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108031. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108032. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108033. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108034. 60,30,500, 3,18., -1 /* lowpass */
  108035. },
  108036. {
  108037. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108038. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108039. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108040. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108041. 60,30,500, 3,18., -1 /* lowpass */
  108042. },
  108043. {
  108044. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108045. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108046. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108047. 7,23,39, 55,79,110, 156,232,360},
  108048. 60,30,500, 1,18., -1 /* lowpass! */
  108049. },
  108050. };
  108051. /*** End of inlined file: floor_all.h ***/
  108052. /*** Start of inlined file: residue_44.h ***/
  108053. /*** Start of inlined file: res_books_stereo.h ***/
  108054. static long _vq_quantlist__16c0_s_p1_0[] = {
  108055. 1,
  108056. 0,
  108057. 2,
  108058. };
  108059. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108060. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108061. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108065. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108066. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108070. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108071. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108106. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108111. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108116. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108151. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108152. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108156. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108157. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 0,
  108158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108161. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108162. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108470. 0,
  108471. };
  108472. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108473. -0.5, 0.5,
  108474. };
  108475. static long _vq_quantmap__16c0_s_p1_0[] = {
  108476. 1, 0, 2,
  108477. };
  108478. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108479. _vq_quantthresh__16c0_s_p1_0,
  108480. _vq_quantmap__16c0_s_p1_0,
  108481. 3,
  108482. 3
  108483. };
  108484. static static_codebook _16c0_s_p1_0 = {
  108485. 8, 6561,
  108486. _vq_lengthlist__16c0_s_p1_0,
  108487. 1, -535822336, 1611661312, 2, 0,
  108488. _vq_quantlist__16c0_s_p1_0,
  108489. NULL,
  108490. &_vq_auxt__16c0_s_p1_0,
  108491. NULL,
  108492. 0
  108493. };
  108494. static long _vq_quantlist__16c0_s_p2_0[] = {
  108495. 2,
  108496. 1,
  108497. 3,
  108498. 0,
  108499. 4,
  108500. };
  108501. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108541. 0,
  108542. };
  108543. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108544. -1.5, -0.5, 0.5, 1.5,
  108545. };
  108546. static long _vq_quantmap__16c0_s_p2_0[] = {
  108547. 3, 1, 0, 2, 4,
  108548. };
  108549. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108550. _vq_quantthresh__16c0_s_p2_0,
  108551. _vq_quantmap__16c0_s_p2_0,
  108552. 5,
  108553. 5
  108554. };
  108555. static static_codebook _16c0_s_p2_0 = {
  108556. 4, 625,
  108557. _vq_lengthlist__16c0_s_p2_0,
  108558. 1, -533725184, 1611661312, 3, 0,
  108559. _vq_quantlist__16c0_s_p2_0,
  108560. NULL,
  108561. &_vq_auxt__16c0_s_p2_0,
  108562. NULL,
  108563. 0
  108564. };
  108565. static long _vq_quantlist__16c0_s_p3_0[] = {
  108566. 2,
  108567. 1,
  108568. 3,
  108569. 0,
  108570. 4,
  108571. };
  108572. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108573. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108576. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108579. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108612. 0,
  108613. };
  108614. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108615. -1.5, -0.5, 0.5, 1.5,
  108616. };
  108617. static long _vq_quantmap__16c0_s_p3_0[] = {
  108618. 3, 1, 0, 2, 4,
  108619. };
  108620. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108621. _vq_quantthresh__16c0_s_p3_0,
  108622. _vq_quantmap__16c0_s_p3_0,
  108623. 5,
  108624. 5
  108625. };
  108626. static static_codebook _16c0_s_p3_0 = {
  108627. 4, 625,
  108628. _vq_lengthlist__16c0_s_p3_0,
  108629. 1, -533725184, 1611661312, 3, 0,
  108630. _vq_quantlist__16c0_s_p3_0,
  108631. NULL,
  108632. &_vq_auxt__16c0_s_p3_0,
  108633. NULL,
  108634. 0
  108635. };
  108636. static long _vq_quantlist__16c0_s_p4_0[] = {
  108637. 4,
  108638. 3,
  108639. 5,
  108640. 2,
  108641. 6,
  108642. 1,
  108643. 7,
  108644. 0,
  108645. 8,
  108646. };
  108647. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108648. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108649. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108650. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108651. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108652. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108653. 0,
  108654. };
  108655. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108656. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108657. };
  108658. static long _vq_quantmap__16c0_s_p4_0[] = {
  108659. 7, 5, 3, 1, 0, 2, 4, 6,
  108660. 8,
  108661. };
  108662. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108663. _vq_quantthresh__16c0_s_p4_0,
  108664. _vq_quantmap__16c0_s_p4_0,
  108665. 9,
  108666. 9
  108667. };
  108668. static static_codebook _16c0_s_p4_0 = {
  108669. 2, 81,
  108670. _vq_lengthlist__16c0_s_p4_0,
  108671. 1, -531628032, 1611661312, 4, 0,
  108672. _vq_quantlist__16c0_s_p4_0,
  108673. NULL,
  108674. &_vq_auxt__16c0_s_p4_0,
  108675. NULL,
  108676. 0
  108677. };
  108678. static long _vq_quantlist__16c0_s_p5_0[] = {
  108679. 4,
  108680. 3,
  108681. 5,
  108682. 2,
  108683. 6,
  108684. 1,
  108685. 7,
  108686. 0,
  108687. 8,
  108688. };
  108689. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108690. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108691. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108692. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108693. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108694. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108695. 10,
  108696. };
  108697. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108698. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108699. };
  108700. static long _vq_quantmap__16c0_s_p5_0[] = {
  108701. 7, 5, 3, 1, 0, 2, 4, 6,
  108702. 8,
  108703. };
  108704. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108705. _vq_quantthresh__16c0_s_p5_0,
  108706. _vq_quantmap__16c0_s_p5_0,
  108707. 9,
  108708. 9
  108709. };
  108710. static static_codebook _16c0_s_p5_0 = {
  108711. 2, 81,
  108712. _vq_lengthlist__16c0_s_p5_0,
  108713. 1, -531628032, 1611661312, 4, 0,
  108714. _vq_quantlist__16c0_s_p5_0,
  108715. NULL,
  108716. &_vq_auxt__16c0_s_p5_0,
  108717. NULL,
  108718. 0
  108719. };
  108720. static long _vq_quantlist__16c0_s_p6_0[] = {
  108721. 8,
  108722. 7,
  108723. 9,
  108724. 6,
  108725. 10,
  108726. 5,
  108727. 11,
  108728. 4,
  108729. 12,
  108730. 3,
  108731. 13,
  108732. 2,
  108733. 14,
  108734. 1,
  108735. 15,
  108736. 0,
  108737. 16,
  108738. };
  108739. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108740. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108741. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108742. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108743. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108744. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108745. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108746. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108747. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108748. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108749. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108750. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108751. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108752. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108753. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108754. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108755. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108756. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108757. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108758. 14,
  108759. };
  108760. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108761. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108762. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108763. };
  108764. static long _vq_quantmap__16c0_s_p6_0[] = {
  108765. 15, 13, 11, 9, 7, 5, 3, 1,
  108766. 0, 2, 4, 6, 8, 10, 12, 14,
  108767. 16,
  108768. };
  108769. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108770. _vq_quantthresh__16c0_s_p6_0,
  108771. _vq_quantmap__16c0_s_p6_0,
  108772. 17,
  108773. 17
  108774. };
  108775. static static_codebook _16c0_s_p6_0 = {
  108776. 2, 289,
  108777. _vq_lengthlist__16c0_s_p6_0,
  108778. 1, -529530880, 1611661312, 5, 0,
  108779. _vq_quantlist__16c0_s_p6_0,
  108780. NULL,
  108781. &_vq_auxt__16c0_s_p6_0,
  108782. NULL,
  108783. 0
  108784. };
  108785. static long _vq_quantlist__16c0_s_p7_0[] = {
  108786. 1,
  108787. 0,
  108788. 2,
  108789. };
  108790. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108791. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108792. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108793. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108794. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108795. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108796. 13,
  108797. };
  108798. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108799. -5.5, 5.5,
  108800. };
  108801. static long _vq_quantmap__16c0_s_p7_0[] = {
  108802. 1, 0, 2,
  108803. };
  108804. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108805. _vq_quantthresh__16c0_s_p7_0,
  108806. _vq_quantmap__16c0_s_p7_0,
  108807. 3,
  108808. 3
  108809. };
  108810. static static_codebook _16c0_s_p7_0 = {
  108811. 4, 81,
  108812. _vq_lengthlist__16c0_s_p7_0,
  108813. 1, -529137664, 1618345984, 2, 0,
  108814. _vq_quantlist__16c0_s_p7_0,
  108815. NULL,
  108816. &_vq_auxt__16c0_s_p7_0,
  108817. NULL,
  108818. 0
  108819. };
  108820. static long _vq_quantlist__16c0_s_p7_1[] = {
  108821. 5,
  108822. 4,
  108823. 6,
  108824. 3,
  108825. 7,
  108826. 2,
  108827. 8,
  108828. 1,
  108829. 9,
  108830. 0,
  108831. 10,
  108832. };
  108833. static long _vq_lengthlist__16c0_s_p7_1[] = {
  108834. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  108835. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  108836. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  108837. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  108838. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  108839. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  108840. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  108841. 11,11,11, 9, 9, 9, 9,10,10,
  108842. };
  108843. static float _vq_quantthresh__16c0_s_p7_1[] = {
  108844. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  108845. 3.5, 4.5,
  108846. };
  108847. static long _vq_quantmap__16c0_s_p7_1[] = {
  108848. 9, 7, 5, 3, 1, 0, 2, 4,
  108849. 6, 8, 10,
  108850. };
  108851. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  108852. _vq_quantthresh__16c0_s_p7_1,
  108853. _vq_quantmap__16c0_s_p7_1,
  108854. 11,
  108855. 11
  108856. };
  108857. static static_codebook _16c0_s_p7_1 = {
  108858. 2, 121,
  108859. _vq_lengthlist__16c0_s_p7_1,
  108860. 1, -531365888, 1611661312, 4, 0,
  108861. _vq_quantlist__16c0_s_p7_1,
  108862. NULL,
  108863. &_vq_auxt__16c0_s_p7_1,
  108864. NULL,
  108865. 0
  108866. };
  108867. static long _vq_quantlist__16c0_s_p8_0[] = {
  108868. 6,
  108869. 5,
  108870. 7,
  108871. 4,
  108872. 8,
  108873. 3,
  108874. 9,
  108875. 2,
  108876. 10,
  108877. 1,
  108878. 11,
  108879. 0,
  108880. 12,
  108881. };
  108882. static long _vq_lengthlist__16c0_s_p8_0[] = {
  108883. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  108884. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  108885. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  108886. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  108887. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  108888. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  108889. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  108890. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  108891. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  108892. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  108893. 0,12,13,13,12,13,14,14,14,
  108894. };
  108895. static float _vq_quantthresh__16c0_s_p8_0[] = {
  108896. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  108897. 12.5, 17.5, 22.5, 27.5,
  108898. };
  108899. static long _vq_quantmap__16c0_s_p8_0[] = {
  108900. 11, 9, 7, 5, 3, 1, 0, 2,
  108901. 4, 6, 8, 10, 12,
  108902. };
  108903. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  108904. _vq_quantthresh__16c0_s_p8_0,
  108905. _vq_quantmap__16c0_s_p8_0,
  108906. 13,
  108907. 13
  108908. };
  108909. static static_codebook _16c0_s_p8_0 = {
  108910. 2, 169,
  108911. _vq_lengthlist__16c0_s_p8_0,
  108912. 1, -526516224, 1616117760, 4, 0,
  108913. _vq_quantlist__16c0_s_p8_0,
  108914. NULL,
  108915. &_vq_auxt__16c0_s_p8_0,
  108916. NULL,
  108917. 0
  108918. };
  108919. static long _vq_quantlist__16c0_s_p8_1[] = {
  108920. 2,
  108921. 1,
  108922. 3,
  108923. 0,
  108924. 4,
  108925. };
  108926. static long _vq_lengthlist__16c0_s_p8_1[] = {
  108927. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  108928. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  108929. };
  108930. static float _vq_quantthresh__16c0_s_p8_1[] = {
  108931. -1.5, -0.5, 0.5, 1.5,
  108932. };
  108933. static long _vq_quantmap__16c0_s_p8_1[] = {
  108934. 3, 1, 0, 2, 4,
  108935. };
  108936. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  108937. _vq_quantthresh__16c0_s_p8_1,
  108938. _vq_quantmap__16c0_s_p8_1,
  108939. 5,
  108940. 5
  108941. };
  108942. static static_codebook _16c0_s_p8_1 = {
  108943. 2, 25,
  108944. _vq_lengthlist__16c0_s_p8_1,
  108945. 1, -533725184, 1611661312, 3, 0,
  108946. _vq_quantlist__16c0_s_p8_1,
  108947. NULL,
  108948. &_vq_auxt__16c0_s_p8_1,
  108949. NULL,
  108950. 0
  108951. };
  108952. static long _vq_quantlist__16c0_s_p9_0[] = {
  108953. 1,
  108954. 0,
  108955. 2,
  108956. };
  108957. static long _vq_lengthlist__16c0_s_p9_0[] = {
  108958. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  108959. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  108960. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108961. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108962. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108963. 7,
  108964. };
  108965. static float _vq_quantthresh__16c0_s_p9_0[] = {
  108966. -157.5, 157.5,
  108967. };
  108968. static long _vq_quantmap__16c0_s_p9_0[] = {
  108969. 1, 0, 2,
  108970. };
  108971. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  108972. _vq_quantthresh__16c0_s_p9_0,
  108973. _vq_quantmap__16c0_s_p9_0,
  108974. 3,
  108975. 3
  108976. };
  108977. static static_codebook _16c0_s_p9_0 = {
  108978. 4, 81,
  108979. _vq_lengthlist__16c0_s_p9_0,
  108980. 1, -518803456, 1628680192, 2, 0,
  108981. _vq_quantlist__16c0_s_p9_0,
  108982. NULL,
  108983. &_vq_auxt__16c0_s_p9_0,
  108984. NULL,
  108985. 0
  108986. };
  108987. static long _vq_quantlist__16c0_s_p9_1[] = {
  108988. 7,
  108989. 6,
  108990. 8,
  108991. 5,
  108992. 9,
  108993. 4,
  108994. 10,
  108995. 3,
  108996. 11,
  108997. 2,
  108998. 12,
  108999. 1,
  109000. 13,
  109001. 0,
  109002. 14,
  109003. };
  109004. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109005. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109006. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109007. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109008. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109009. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109010. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109011. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109012. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109013. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109014. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109015. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109016. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109017. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109018. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109019. 10,
  109020. };
  109021. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109022. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109023. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109024. };
  109025. static long _vq_quantmap__16c0_s_p9_1[] = {
  109026. 13, 11, 9, 7, 5, 3, 1, 0,
  109027. 2, 4, 6, 8, 10, 12, 14,
  109028. };
  109029. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109030. _vq_quantthresh__16c0_s_p9_1,
  109031. _vq_quantmap__16c0_s_p9_1,
  109032. 15,
  109033. 15
  109034. };
  109035. static static_codebook _16c0_s_p9_1 = {
  109036. 2, 225,
  109037. _vq_lengthlist__16c0_s_p9_1,
  109038. 1, -520986624, 1620377600, 4, 0,
  109039. _vq_quantlist__16c0_s_p9_1,
  109040. NULL,
  109041. &_vq_auxt__16c0_s_p9_1,
  109042. NULL,
  109043. 0
  109044. };
  109045. static long _vq_quantlist__16c0_s_p9_2[] = {
  109046. 10,
  109047. 9,
  109048. 11,
  109049. 8,
  109050. 12,
  109051. 7,
  109052. 13,
  109053. 6,
  109054. 14,
  109055. 5,
  109056. 15,
  109057. 4,
  109058. 16,
  109059. 3,
  109060. 17,
  109061. 2,
  109062. 18,
  109063. 1,
  109064. 19,
  109065. 0,
  109066. 20,
  109067. };
  109068. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109069. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109070. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109071. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109072. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109073. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109074. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109075. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109076. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109077. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109078. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109079. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109080. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109081. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109082. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109083. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109084. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109085. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109086. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109087. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109088. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109089. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109090. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109091. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109092. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109093. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109094. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109095. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109096. 10,11,10,10,11, 9,10,10,10,
  109097. };
  109098. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109099. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109100. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109101. 6.5, 7.5, 8.5, 9.5,
  109102. };
  109103. static long _vq_quantmap__16c0_s_p9_2[] = {
  109104. 19, 17, 15, 13, 11, 9, 7, 5,
  109105. 3, 1, 0, 2, 4, 6, 8, 10,
  109106. 12, 14, 16, 18, 20,
  109107. };
  109108. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109109. _vq_quantthresh__16c0_s_p9_2,
  109110. _vq_quantmap__16c0_s_p9_2,
  109111. 21,
  109112. 21
  109113. };
  109114. static static_codebook _16c0_s_p9_2 = {
  109115. 2, 441,
  109116. _vq_lengthlist__16c0_s_p9_2,
  109117. 1, -529268736, 1611661312, 5, 0,
  109118. _vq_quantlist__16c0_s_p9_2,
  109119. NULL,
  109120. &_vq_auxt__16c0_s_p9_2,
  109121. NULL,
  109122. 0
  109123. };
  109124. static long _huff_lengthlist__16c0_s_single[] = {
  109125. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109126. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109127. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109128. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109129. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109130. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109131. 16,16,18,18,
  109132. };
  109133. static static_codebook _huff_book__16c0_s_single = {
  109134. 2, 100,
  109135. _huff_lengthlist__16c0_s_single,
  109136. 0, 0, 0, 0, 0,
  109137. NULL,
  109138. NULL,
  109139. NULL,
  109140. NULL,
  109141. 0
  109142. };
  109143. static long _huff_lengthlist__16c1_s_long[] = {
  109144. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109145. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109146. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109147. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109148. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109149. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109150. 12,11,11,13,
  109151. };
  109152. static static_codebook _huff_book__16c1_s_long = {
  109153. 2, 100,
  109154. _huff_lengthlist__16c1_s_long,
  109155. 0, 0, 0, 0, 0,
  109156. NULL,
  109157. NULL,
  109158. NULL,
  109159. NULL,
  109160. 0
  109161. };
  109162. static long _vq_quantlist__16c1_s_p1_0[] = {
  109163. 1,
  109164. 0,
  109165. 2,
  109166. };
  109167. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109168. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109169. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109173. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109174. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109178. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109179. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109214. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109219. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109224. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109259. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109260. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109264. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109265. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  109266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109269. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109270. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109578. 0,
  109579. };
  109580. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109581. -0.5, 0.5,
  109582. };
  109583. static long _vq_quantmap__16c1_s_p1_0[] = {
  109584. 1, 0, 2,
  109585. };
  109586. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109587. _vq_quantthresh__16c1_s_p1_0,
  109588. _vq_quantmap__16c1_s_p1_0,
  109589. 3,
  109590. 3
  109591. };
  109592. static static_codebook _16c1_s_p1_0 = {
  109593. 8, 6561,
  109594. _vq_lengthlist__16c1_s_p1_0,
  109595. 1, -535822336, 1611661312, 2, 0,
  109596. _vq_quantlist__16c1_s_p1_0,
  109597. NULL,
  109598. &_vq_auxt__16c1_s_p1_0,
  109599. NULL,
  109600. 0
  109601. };
  109602. static long _vq_quantlist__16c1_s_p2_0[] = {
  109603. 2,
  109604. 1,
  109605. 3,
  109606. 0,
  109607. 4,
  109608. };
  109609. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109649. 0,
  109650. };
  109651. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109652. -1.5, -0.5, 0.5, 1.5,
  109653. };
  109654. static long _vq_quantmap__16c1_s_p2_0[] = {
  109655. 3, 1, 0, 2, 4,
  109656. };
  109657. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109658. _vq_quantthresh__16c1_s_p2_0,
  109659. _vq_quantmap__16c1_s_p2_0,
  109660. 5,
  109661. 5
  109662. };
  109663. static static_codebook _16c1_s_p2_0 = {
  109664. 4, 625,
  109665. _vq_lengthlist__16c1_s_p2_0,
  109666. 1, -533725184, 1611661312, 3, 0,
  109667. _vq_quantlist__16c1_s_p2_0,
  109668. NULL,
  109669. &_vq_auxt__16c1_s_p2_0,
  109670. NULL,
  109671. 0
  109672. };
  109673. static long _vq_quantlist__16c1_s_p3_0[] = {
  109674. 2,
  109675. 1,
  109676. 3,
  109677. 0,
  109678. 4,
  109679. };
  109680. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109681. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109684. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109687. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109720. 0,
  109721. };
  109722. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109723. -1.5, -0.5, 0.5, 1.5,
  109724. };
  109725. static long _vq_quantmap__16c1_s_p3_0[] = {
  109726. 3, 1, 0, 2, 4,
  109727. };
  109728. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109729. _vq_quantthresh__16c1_s_p3_0,
  109730. _vq_quantmap__16c1_s_p3_0,
  109731. 5,
  109732. 5
  109733. };
  109734. static static_codebook _16c1_s_p3_0 = {
  109735. 4, 625,
  109736. _vq_lengthlist__16c1_s_p3_0,
  109737. 1, -533725184, 1611661312, 3, 0,
  109738. _vq_quantlist__16c1_s_p3_0,
  109739. NULL,
  109740. &_vq_auxt__16c1_s_p3_0,
  109741. NULL,
  109742. 0
  109743. };
  109744. static long _vq_quantlist__16c1_s_p4_0[] = {
  109745. 4,
  109746. 3,
  109747. 5,
  109748. 2,
  109749. 6,
  109750. 1,
  109751. 7,
  109752. 0,
  109753. 8,
  109754. };
  109755. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109756. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109757. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109758. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109759. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109760. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109761. 0,
  109762. };
  109763. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109764. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109765. };
  109766. static long _vq_quantmap__16c1_s_p4_0[] = {
  109767. 7, 5, 3, 1, 0, 2, 4, 6,
  109768. 8,
  109769. };
  109770. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109771. _vq_quantthresh__16c1_s_p4_0,
  109772. _vq_quantmap__16c1_s_p4_0,
  109773. 9,
  109774. 9
  109775. };
  109776. static static_codebook _16c1_s_p4_0 = {
  109777. 2, 81,
  109778. _vq_lengthlist__16c1_s_p4_0,
  109779. 1, -531628032, 1611661312, 4, 0,
  109780. _vq_quantlist__16c1_s_p4_0,
  109781. NULL,
  109782. &_vq_auxt__16c1_s_p4_0,
  109783. NULL,
  109784. 0
  109785. };
  109786. static long _vq_quantlist__16c1_s_p5_0[] = {
  109787. 4,
  109788. 3,
  109789. 5,
  109790. 2,
  109791. 6,
  109792. 1,
  109793. 7,
  109794. 0,
  109795. 8,
  109796. };
  109797. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109798. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109799. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109800. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109801. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109802. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109803. 10,
  109804. };
  109805. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109806. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109807. };
  109808. static long _vq_quantmap__16c1_s_p5_0[] = {
  109809. 7, 5, 3, 1, 0, 2, 4, 6,
  109810. 8,
  109811. };
  109812. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  109813. _vq_quantthresh__16c1_s_p5_0,
  109814. _vq_quantmap__16c1_s_p5_0,
  109815. 9,
  109816. 9
  109817. };
  109818. static static_codebook _16c1_s_p5_0 = {
  109819. 2, 81,
  109820. _vq_lengthlist__16c1_s_p5_0,
  109821. 1, -531628032, 1611661312, 4, 0,
  109822. _vq_quantlist__16c1_s_p5_0,
  109823. NULL,
  109824. &_vq_auxt__16c1_s_p5_0,
  109825. NULL,
  109826. 0
  109827. };
  109828. static long _vq_quantlist__16c1_s_p6_0[] = {
  109829. 8,
  109830. 7,
  109831. 9,
  109832. 6,
  109833. 10,
  109834. 5,
  109835. 11,
  109836. 4,
  109837. 12,
  109838. 3,
  109839. 13,
  109840. 2,
  109841. 14,
  109842. 1,
  109843. 15,
  109844. 0,
  109845. 16,
  109846. };
  109847. static long _vq_lengthlist__16c1_s_p6_0[] = {
  109848. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  109849. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  109850. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  109851. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  109852. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  109853. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109854. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109855. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109856. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  109857. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109858. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  109859. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  109860. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  109861. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  109862. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  109863. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  109864. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  109865. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  109866. 14,
  109867. };
  109868. static float _vq_quantthresh__16c1_s_p6_0[] = {
  109869. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109870. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109871. };
  109872. static long _vq_quantmap__16c1_s_p6_0[] = {
  109873. 15, 13, 11, 9, 7, 5, 3, 1,
  109874. 0, 2, 4, 6, 8, 10, 12, 14,
  109875. 16,
  109876. };
  109877. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  109878. _vq_quantthresh__16c1_s_p6_0,
  109879. _vq_quantmap__16c1_s_p6_0,
  109880. 17,
  109881. 17
  109882. };
  109883. static static_codebook _16c1_s_p6_0 = {
  109884. 2, 289,
  109885. _vq_lengthlist__16c1_s_p6_0,
  109886. 1, -529530880, 1611661312, 5, 0,
  109887. _vq_quantlist__16c1_s_p6_0,
  109888. NULL,
  109889. &_vq_auxt__16c1_s_p6_0,
  109890. NULL,
  109891. 0
  109892. };
  109893. static long _vq_quantlist__16c1_s_p7_0[] = {
  109894. 1,
  109895. 0,
  109896. 2,
  109897. };
  109898. static long _vq_lengthlist__16c1_s_p7_0[] = {
  109899. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  109900. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109901. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  109902. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  109903. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  109904. 11,
  109905. };
  109906. static float _vq_quantthresh__16c1_s_p7_0[] = {
  109907. -5.5, 5.5,
  109908. };
  109909. static long _vq_quantmap__16c1_s_p7_0[] = {
  109910. 1, 0, 2,
  109911. };
  109912. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  109913. _vq_quantthresh__16c1_s_p7_0,
  109914. _vq_quantmap__16c1_s_p7_0,
  109915. 3,
  109916. 3
  109917. };
  109918. static static_codebook _16c1_s_p7_0 = {
  109919. 4, 81,
  109920. _vq_lengthlist__16c1_s_p7_0,
  109921. 1, -529137664, 1618345984, 2, 0,
  109922. _vq_quantlist__16c1_s_p7_0,
  109923. NULL,
  109924. &_vq_auxt__16c1_s_p7_0,
  109925. NULL,
  109926. 0
  109927. };
  109928. static long _vq_quantlist__16c1_s_p7_1[] = {
  109929. 5,
  109930. 4,
  109931. 6,
  109932. 3,
  109933. 7,
  109934. 2,
  109935. 8,
  109936. 1,
  109937. 9,
  109938. 0,
  109939. 10,
  109940. };
  109941. static long _vq_lengthlist__16c1_s_p7_1[] = {
  109942. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  109943. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  109944. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  109945. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  109946. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  109947. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  109948. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  109949. 10,10,10, 8, 8, 8, 8, 9, 9,
  109950. };
  109951. static float _vq_quantthresh__16c1_s_p7_1[] = {
  109952. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109953. 3.5, 4.5,
  109954. };
  109955. static long _vq_quantmap__16c1_s_p7_1[] = {
  109956. 9, 7, 5, 3, 1, 0, 2, 4,
  109957. 6, 8, 10,
  109958. };
  109959. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  109960. _vq_quantthresh__16c1_s_p7_1,
  109961. _vq_quantmap__16c1_s_p7_1,
  109962. 11,
  109963. 11
  109964. };
  109965. static static_codebook _16c1_s_p7_1 = {
  109966. 2, 121,
  109967. _vq_lengthlist__16c1_s_p7_1,
  109968. 1, -531365888, 1611661312, 4, 0,
  109969. _vq_quantlist__16c1_s_p7_1,
  109970. NULL,
  109971. &_vq_auxt__16c1_s_p7_1,
  109972. NULL,
  109973. 0
  109974. };
  109975. static long _vq_quantlist__16c1_s_p8_0[] = {
  109976. 6,
  109977. 5,
  109978. 7,
  109979. 4,
  109980. 8,
  109981. 3,
  109982. 9,
  109983. 2,
  109984. 10,
  109985. 1,
  109986. 11,
  109987. 0,
  109988. 12,
  109989. };
  109990. static long _vq_lengthlist__16c1_s_p8_0[] = {
  109991. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  109992. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  109993. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  109994. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  109995. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  109996. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  109997. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  109998. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  109999. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110000. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110001. 0,12,12,12,12,13,13,14,15,
  110002. };
  110003. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110004. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110005. 12.5, 17.5, 22.5, 27.5,
  110006. };
  110007. static long _vq_quantmap__16c1_s_p8_0[] = {
  110008. 11, 9, 7, 5, 3, 1, 0, 2,
  110009. 4, 6, 8, 10, 12,
  110010. };
  110011. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110012. _vq_quantthresh__16c1_s_p8_0,
  110013. _vq_quantmap__16c1_s_p8_0,
  110014. 13,
  110015. 13
  110016. };
  110017. static static_codebook _16c1_s_p8_0 = {
  110018. 2, 169,
  110019. _vq_lengthlist__16c1_s_p8_0,
  110020. 1, -526516224, 1616117760, 4, 0,
  110021. _vq_quantlist__16c1_s_p8_0,
  110022. NULL,
  110023. &_vq_auxt__16c1_s_p8_0,
  110024. NULL,
  110025. 0
  110026. };
  110027. static long _vq_quantlist__16c1_s_p8_1[] = {
  110028. 2,
  110029. 1,
  110030. 3,
  110031. 0,
  110032. 4,
  110033. };
  110034. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110035. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110036. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110037. };
  110038. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110039. -1.5, -0.5, 0.5, 1.5,
  110040. };
  110041. static long _vq_quantmap__16c1_s_p8_1[] = {
  110042. 3, 1, 0, 2, 4,
  110043. };
  110044. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110045. _vq_quantthresh__16c1_s_p8_1,
  110046. _vq_quantmap__16c1_s_p8_1,
  110047. 5,
  110048. 5
  110049. };
  110050. static static_codebook _16c1_s_p8_1 = {
  110051. 2, 25,
  110052. _vq_lengthlist__16c1_s_p8_1,
  110053. 1, -533725184, 1611661312, 3, 0,
  110054. _vq_quantlist__16c1_s_p8_1,
  110055. NULL,
  110056. &_vq_auxt__16c1_s_p8_1,
  110057. NULL,
  110058. 0
  110059. };
  110060. static long _vq_quantlist__16c1_s_p9_0[] = {
  110061. 6,
  110062. 5,
  110063. 7,
  110064. 4,
  110065. 8,
  110066. 3,
  110067. 9,
  110068. 2,
  110069. 10,
  110070. 1,
  110071. 11,
  110072. 0,
  110073. 12,
  110074. };
  110075. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110076. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110077. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110078. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110079. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110080. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110081. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110082. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110083. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110084. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110085. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110086. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110087. };
  110088. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110089. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110090. 787.5, 1102.5, 1417.5, 1732.5,
  110091. };
  110092. static long _vq_quantmap__16c1_s_p9_0[] = {
  110093. 11, 9, 7, 5, 3, 1, 0, 2,
  110094. 4, 6, 8, 10, 12,
  110095. };
  110096. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110097. _vq_quantthresh__16c1_s_p9_0,
  110098. _vq_quantmap__16c1_s_p9_0,
  110099. 13,
  110100. 13
  110101. };
  110102. static static_codebook _16c1_s_p9_0 = {
  110103. 2, 169,
  110104. _vq_lengthlist__16c1_s_p9_0,
  110105. 1, -513964032, 1628680192, 4, 0,
  110106. _vq_quantlist__16c1_s_p9_0,
  110107. NULL,
  110108. &_vq_auxt__16c1_s_p9_0,
  110109. NULL,
  110110. 0
  110111. };
  110112. static long _vq_quantlist__16c1_s_p9_1[] = {
  110113. 7,
  110114. 6,
  110115. 8,
  110116. 5,
  110117. 9,
  110118. 4,
  110119. 10,
  110120. 3,
  110121. 11,
  110122. 2,
  110123. 12,
  110124. 1,
  110125. 13,
  110126. 0,
  110127. 14,
  110128. };
  110129. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110130. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110131. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110132. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110133. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110134. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110135. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110136. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110137. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110138. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110139. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110140. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110141. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110142. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110143. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110144. 13,
  110145. };
  110146. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110147. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110148. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110149. };
  110150. static long _vq_quantmap__16c1_s_p9_1[] = {
  110151. 13, 11, 9, 7, 5, 3, 1, 0,
  110152. 2, 4, 6, 8, 10, 12, 14,
  110153. };
  110154. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110155. _vq_quantthresh__16c1_s_p9_1,
  110156. _vq_quantmap__16c1_s_p9_1,
  110157. 15,
  110158. 15
  110159. };
  110160. static static_codebook _16c1_s_p9_1 = {
  110161. 2, 225,
  110162. _vq_lengthlist__16c1_s_p9_1,
  110163. 1, -520986624, 1620377600, 4, 0,
  110164. _vq_quantlist__16c1_s_p9_1,
  110165. NULL,
  110166. &_vq_auxt__16c1_s_p9_1,
  110167. NULL,
  110168. 0
  110169. };
  110170. static long _vq_quantlist__16c1_s_p9_2[] = {
  110171. 10,
  110172. 9,
  110173. 11,
  110174. 8,
  110175. 12,
  110176. 7,
  110177. 13,
  110178. 6,
  110179. 14,
  110180. 5,
  110181. 15,
  110182. 4,
  110183. 16,
  110184. 3,
  110185. 17,
  110186. 2,
  110187. 18,
  110188. 1,
  110189. 19,
  110190. 0,
  110191. 20,
  110192. };
  110193. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110194. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110195. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110196. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110197. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110198. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110199. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110200. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110201. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110202. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110203. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110204. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110205. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110206. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110207. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110208. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110209. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110210. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110211. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110212. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110213. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110214. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110215. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110216. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110217. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110218. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110219. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110220. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110221. 11,11,11,11,12,11,11,12,11,
  110222. };
  110223. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110224. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110225. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110226. 6.5, 7.5, 8.5, 9.5,
  110227. };
  110228. static long _vq_quantmap__16c1_s_p9_2[] = {
  110229. 19, 17, 15, 13, 11, 9, 7, 5,
  110230. 3, 1, 0, 2, 4, 6, 8, 10,
  110231. 12, 14, 16, 18, 20,
  110232. };
  110233. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110234. _vq_quantthresh__16c1_s_p9_2,
  110235. _vq_quantmap__16c1_s_p9_2,
  110236. 21,
  110237. 21
  110238. };
  110239. static static_codebook _16c1_s_p9_2 = {
  110240. 2, 441,
  110241. _vq_lengthlist__16c1_s_p9_2,
  110242. 1, -529268736, 1611661312, 5, 0,
  110243. _vq_quantlist__16c1_s_p9_2,
  110244. NULL,
  110245. &_vq_auxt__16c1_s_p9_2,
  110246. NULL,
  110247. 0
  110248. };
  110249. static long _huff_lengthlist__16c1_s_short[] = {
  110250. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110251. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110252. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110253. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110254. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110255. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110256. 9, 9,10,13,
  110257. };
  110258. static static_codebook _huff_book__16c1_s_short = {
  110259. 2, 100,
  110260. _huff_lengthlist__16c1_s_short,
  110261. 0, 0, 0, 0, 0,
  110262. NULL,
  110263. NULL,
  110264. NULL,
  110265. NULL,
  110266. 0
  110267. };
  110268. static long _huff_lengthlist__16c2_s_long[] = {
  110269. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110270. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110271. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110272. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110273. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110274. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110275. 14,14,16,18,
  110276. };
  110277. static static_codebook _huff_book__16c2_s_long = {
  110278. 2, 100,
  110279. _huff_lengthlist__16c2_s_long,
  110280. 0, 0, 0, 0, 0,
  110281. NULL,
  110282. NULL,
  110283. NULL,
  110284. NULL,
  110285. 0
  110286. };
  110287. static long _vq_quantlist__16c2_s_p1_0[] = {
  110288. 1,
  110289. 0,
  110290. 2,
  110291. };
  110292. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110293. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110294. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110298. 0,
  110299. };
  110300. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110301. -0.5, 0.5,
  110302. };
  110303. static long _vq_quantmap__16c2_s_p1_0[] = {
  110304. 1, 0, 2,
  110305. };
  110306. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110307. _vq_quantthresh__16c2_s_p1_0,
  110308. _vq_quantmap__16c2_s_p1_0,
  110309. 3,
  110310. 3
  110311. };
  110312. static static_codebook _16c2_s_p1_0 = {
  110313. 4, 81,
  110314. _vq_lengthlist__16c2_s_p1_0,
  110315. 1, -535822336, 1611661312, 2, 0,
  110316. _vq_quantlist__16c2_s_p1_0,
  110317. NULL,
  110318. &_vq_auxt__16c2_s_p1_0,
  110319. NULL,
  110320. 0
  110321. };
  110322. static long _vq_quantlist__16c2_s_p2_0[] = {
  110323. 2,
  110324. 1,
  110325. 3,
  110326. 0,
  110327. 4,
  110328. };
  110329. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110330. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110331. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110332. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110333. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110334. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110335. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110336. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110337. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110342. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110343. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110344. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110345. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110350. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110351. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110352. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110353. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110358. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110359. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110360. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110361. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110366. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110367. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110368. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110369. 13,
  110370. };
  110371. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110372. -1.5, -0.5, 0.5, 1.5,
  110373. };
  110374. static long _vq_quantmap__16c2_s_p2_0[] = {
  110375. 3, 1, 0, 2, 4,
  110376. };
  110377. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110378. _vq_quantthresh__16c2_s_p2_0,
  110379. _vq_quantmap__16c2_s_p2_0,
  110380. 5,
  110381. 5
  110382. };
  110383. static static_codebook _16c2_s_p2_0 = {
  110384. 4, 625,
  110385. _vq_lengthlist__16c2_s_p2_0,
  110386. 1, -533725184, 1611661312, 3, 0,
  110387. _vq_quantlist__16c2_s_p2_0,
  110388. NULL,
  110389. &_vq_auxt__16c2_s_p2_0,
  110390. NULL,
  110391. 0
  110392. };
  110393. static long _vq_quantlist__16c2_s_p3_0[] = {
  110394. 4,
  110395. 3,
  110396. 5,
  110397. 2,
  110398. 6,
  110399. 1,
  110400. 7,
  110401. 0,
  110402. 8,
  110403. };
  110404. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110405. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110406. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110407. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110408. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110410. 0,
  110411. };
  110412. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110413. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110414. };
  110415. static long _vq_quantmap__16c2_s_p3_0[] = {
  110416. 7, 5, 3, 1, 0, 2, 4, 6,
  110417. 8,
  110418. };
  110419. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110420. _vq_quantthresh__16c2_s_p3_0,
  110421. _vq_quantmap__16c2_s_p3_0,
  110422. 9,
  110423. 9
  110424. };
  110425. static static_codebook _16c2_s_p3_0 = {
  110426. 2, 81,
  110427. _vq_lengthlist__16c2_s_p3_0,
  110428. 1, -531628032, 1611661312, 4, 0,
  110429. _vq_quantlist__16c2_s_p3_0,
  110430. NULL,
  110431. &_vq_auxt__16c2_s_p3_0,
  110432. NULL,
  110433. 0
  110434. };
  110435. static long _vq_quantlist__16c2_s_p4_0[] = {
  110436. 8,
  110437. 7,
  110438. 9,
  110439. 6,
  110440. 10,
  110441. 5,
  110442. 11,
  110443. 4,
  110444. 12,
  110445. 3,
  110446. 13,
  110447. 2,
  110448. 14,
  110449. 1,
  110450. 15,
  110451. 0,
  110452. 16,
  110453. };
  110454. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110455. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110456. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110457. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110458. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110459. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110460. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110461. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110462. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110463. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110464. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110473. 0,
  110474. };
  110475. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110476. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110477. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110478. };
  110479. static long _vq_quantmap__16c2_s_p4_0[] = {
  110480. 15, 13, 11, 9, 7, 5, 3, 1,
  110481. 0, 2, 4, 6, 8, 10, 12, 14,
  110482. 16,
  110483. };
  110484. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110485. _vq_quantthresh__16c2_s_p4_0,
  110486. _vq_quantmap__16c2_s_p4_0,
  110487. 17,
  110488. 17
  110489. };
  110490. static static_codebook _16c2_s_p4_0 = {
  110491. 2, 289,
  110492. _vq_lengthlist__16c2_s_p4_0,
  110493. 1, -529530880, 1611661312, 5, 0,
  110494. _vq_quantlist__16c2_s_p4_0,
  110495. NULL,
  110496. &_vq_auxt__16c2_s_p4_0,
  110497. NULL,
  110498. 0
  110499. };
  110500. static long _vq_quantlist__16c2_s_p5_0[] = {
  110501. 1,
  110502. 0,
  110503. 2,
  110504. };
  110505. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110506. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110507. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110508. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110509. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110510. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110511. 12,
  110512. };
  110513. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110514. -5.5, 5.5,
  110515. };
  110516. static long _vq_quantmap__16c2_s_p5_0[] = {
  110517. 1, 0, 2,
  110518. };
  110519. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110520. _vq_quantthresh__16c2_s_p5_0,
  110521. _vq_quantmap__16c2_s_p5_0,
  110522. 3,
  110523. 3
  110524. };
  110525. static static_codebook _16c2_s_p5_0 = {
  110526. 4, 81,
  110527. _vq_lengthlist__16c2_s_p5_0,
  110528. 1, -529137664, 1618345984, 2, 0,
  110529. _vq_quantlist__16c2_s_p5_0,
  110530. NULL,
  110531. &_vq_auxt__16c2_s_p5_0,
  110532. NULL,
  110533. 0
  110534. };
  110535. static long _vq_quantlist__16c2_s_p5_1[] = {
  110536. 5,
  110537. 4,
  110538. 6,
  110539. 3,
  110540. 7,
  110541. 2,
  110542. 8,
  110543. 1,
  110544. 9,
  110545. 0,
  110546. 10,
  110547. };
  110548. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110549. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110550. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110551. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110552. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110553. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110554. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110555. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110556. 11,11,11, 7, 7, 8, 8, 8, 8,
  110557. };
  110558. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110559. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110560. 3.5, 4.5,
  110561. };
  110562. static long _vq_quantmap__16c2_s_p5_1[] = {
  110563. 9, 7, 5, 3, 1, 0, 2, 4,
  110564. 6, 8, 10,
  110565. };
  110566. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110567. _vq_quantthresh__16c2_s_p5_1,
  110568. _vq_quantmap__16c2_s_p5_1,
  110569. 11,
  110570. 11
  110571. };
  110572. static static_codebook _16c2_s_p5_1 = {
  110573. 2, 121,
  110574. _vq_lengthlist__16c2_s_p5_1,
  110575. 1, -531365888, 1611661312, 4, 0,
  110576. _vq_quantlist__16c2_s_p5_1,
  110577. NULL,
  110578. &_vq_auxt__16c2_s_p5_1,
  110579. NULL,
  110580. 0
  110581. };
  110582. static long _vq_quantlist__16c2_s_p6_0[] = {
  110583. 6,
  110584. 5,
  110585. 7,
  110586. 4,
  110587. 8,
  110588. 3,
  110589. 9,
  110590. 2,
  110591. 10,
  110592. 1,
  110593. 11,
  110594. 0,
  110595. 12,
  110596. };
  110597. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110598. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110599. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110600. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110601. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110602. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110603. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110608. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110609. };
  110610. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110611. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110612. 12.5, 17.5, 22.5, 27.5,
  110613. };
  110614. static long _vq_quantmap__16c2_s_p6_0[] = {
  110615. 11, 9, 7, 5, 3, 1, 0, 2,
  110616. 4, 6, 8, 10, 12,
  110617. };
  110618. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110619. _vq_quantthresh__16c2_s_p6_0,
  110620. _vq_quantmap__16c2_s_p6_0,
  110621. 13,
  110622. 13
  110623. };
  110624. static static_codebook _16c2_s_p6_0 = {
  110625. 2, 169,
  110626. _vq_lengthlist__16c2_s_p6_0,
  110627. 1, -526516224, 1616117760, 4, 0,
  110628. _vq_quantlist__16c2_s_p6_0,
  110629. NULL,
  110630. &_vq_auxt__16c2_s_p6_0,
  110631. NULL,
  110632. 0
  110633. };
  110634. static long _vq_quantlist__16c2_s_p6_1[] = {
  110635. 2,
  110636. 1,
  110637. 3,
  110638. 0,
  110639. 4,
  110640. };
  110641. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110642. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110643. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110644. };
  110645. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110646. -1.5, -0.5, 0.5, 1.5,
  110647. };
  110648. static long _vq_quantmap__16c2_s_p6_1[] = {
  110649. 3, 1, 0, 2, 4,
  110650. };
  110651. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110652. _vq_quantthresh__16c2_s_p6_1,
  110653. _vq_quantmap__16c2_s_p6_1,
  110654. 5,
  110655. 5
  110656. };
  110657. static static_codebook _16c2_s_p6_1 = {
  110658. 2, 25,
  110659. _vq_lengthlist__16c2_s_p6_1,
  110660. 1, -533725184, 1611661312, 3, 0,
  110661. _vq_quantlist__16c2_s_p6_1,
  110662. NULL,
  110663. &_vq_auxt__16c2_s_p6_1,
  110664. NULL,
  110665. 0
  110666. };
  110667. static long _vq_quantlist__16c2_s_p7_0[] = {
  110668. 6,
  110669. 5,
  110670. 7,
  110671. 4,
  110672. 8,
  110673. 3,
  110674. 9,
  110675. 2,
  110676. 10,
  110677. 1,
  110678. 11,
  110679. 0,
  110680. 12,
  110681. };
  110682. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110683. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110684. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110685. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110686. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110687. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110688. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110689. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110690. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110691. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110692. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110693. 18,13,14,13,13,14,13,15,14,
  110694. };
  110695. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110696. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110697. 27.5, 38.5, 49.5, 60.5,
  110698. };
  110699. static long _vq_quantmap__16c2_s_p7_0[] = {
  110700. 11, 9, 7, 5, 3, 1, 0, 2,
  110701. 4, 6, 8, 10, 12,
  110702. };
  110703. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110704. _vq_quantthresh__16c2_s_p7_0,
  110705. _vq_quantmap__16c2_s_p7_0,
  110706. 13,
  110707. 13
  110708. };
  110709. static static_codebook _16c2_s_p7_0 = {
  110710. 2, 169,
  110711. _vq_lengthlist__16c2_s_p7_0,
  110712. 1, -523206656, 1618345984, 4, 0,
  110713. _vq_quantlist__16c2_s_p7_0,
  110714. NULL,
  110715. &_vq_auxt__16c2_s_p7_0,
  110716. NULL,
  110717. 0
  110718. };
  110719. static long _vq_quantlist__16c2_s_p7_1[] = {
  110720. 5,
  110721. 4,
  110722. 6,
  110723. 3,
  110724. 7,
  110725. 2,
  110726. 8,
  110727. 1,
  110728. 9,
  110729. 0,
  110730. 10,
  110731. };
  110732. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110733. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110734. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110735. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110736. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110737. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110738. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110739. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110740. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110741. };
  110742. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110743. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110744. 3.5, 4.5,
  110745. };
  110746. static long _vq_quantmap__16c2_s_p7_1[] = {
  110747. 9, 7, 5, 3, 1, 0, 2, 4,
  110748. 6, 8, 10,
  110749. };
  110750. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110751. _vq_quantthresh__16c2_s_p7_1,
  110752. _vq_quantmap__16c2_s_p7_1,
  110753. 11,
  110754. 11
  110755. };
  110756. static static_codebook _16c2_s_p7_1 = {
  110757. 2, 121,
  110758. _vq_lengthlist__16c2_s_p7_1,
  110759. 1, -531365888, 1611661312, 4, 0,
  110760. _vq_quantlist__16c2_s_p7_1,
  110761. NULL,
  110762. &_vq_auxt__16c2_s_p7_1,
  110763. NULL,
  110764. 0
  110765. };
  110766. static long _vq_quantlist__16c2_s_p8_0[] = {
  110767. 7,
  110768. 6,
  110769. 8,
  110770. 5,
  110771. 9,
  110772. 4,
  110773. 10,
  110774. 3,
  110775. 11,
  110776. 2,
  110777. 12,
  110778. 1,
  110779. 13,
  110780. 0,
  110781. 14,
  110782. };
  110783. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110784. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110785. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110786. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110787. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110788. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110789. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110790. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110791. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110792. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110793. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110794. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110795. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110796. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110797. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110798. 13,
  110799. };
  110800. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110801. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110802. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110803. };
  110804. static long _vq_quantmap__16c2_s_p8_0[] = {
  110805. 13, 11, 9, 7, 5, 3, 1, 0,
  110806. 2, 4, 6, 8, 10, 12, 14,
  110807. };
  110808. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110809. _vq_quantthresh__16c2_s_p8_0,
  110810. _vq_quantmap__16c2_s_p8_0,
  110811. 15,
  110812. 15
  110813. };
  110814. static static_codebook _16c2_s_p8_0 = {
  110815. 2, 225,
  110816. _vq_lengthlist__16c2_s_p8_0,
  110817. 1, -520986624, 1620377600, 4, 0,
  110818. _vq_quantlist__16c2_s_p8_0,
  110819. NULL,
  110820. &_vq_auxt__16c2_s_p8_0,
  110821. NULL,
  110822. 0
  110823. };
  110824. static long _vq_quantlist__16c2_s_p8_1[] = {
  110825. 10,
  110826. 9,
  110827. 11,
  110828. 8,
  110829. 12,
  110830. 7,
  110831. 13,
  110832. 6,
  110833. 14,
  110834. 5,
  110835. 15,
  110836. 4,
  110837. 16,
  110838. 3,
  110839. 17,
  110840. 2,
  110841. 18,
  110842. 1,
  110843. 19,
  110844. 0,
  110845. 20,
  110846. };
  110847. static long _vq_lengthlist__16c2_s_p8_1[] = {
  110848. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  110849. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  110850. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  110851. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  110852. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  110853. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  110854. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  110855. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  110856. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  110857. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  110858. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  110859. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  110860. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  110861. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  110862. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  110863. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  110864. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  110865. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  110866. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  110867. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  110868. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  110869. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  110870. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  110871. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  110872. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  110873. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  110874. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  110875. 10,11,10,10,10,10,10,10,10,
  110876. };
  110877. static float _vq_quantthresh__16c2_s_p8_1[] = {
  110878. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110879. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110880. 6.5, 7.5, 8.5, 9.5,
  110881. };
  110882. static long _vq_quantmap__16c2_s_p8_1[] = {
  110883. 19, 17, 15, 13, 11, 9, 7, 5,
  110884. 3, 1, 0, 2, 4, 6, 8, 10,
  110885. 12, 14, 16, 18, 20,
  110886. };
  110887. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  110888. _vq_quantthresh__16c2_s_p8_1,
  110889. _vq_quantmap__16c2_s_p8_1,
  110890. 21,
  110891. 21
  110892. };
  110893. static static_codebook _16c2_s_p8_1 = {
  110894. 2, 441,
  110895. _vq_lengthlist__16c2_s_p8_1,
  110896. 1, -529268736, 1611661312, 5, 0,
  110897. _vq_quantlist__16c2_s_p8_1,
  110898. NULL,
  110899. &_vq_auxt__16c2_s_p8_1,
  110900. NULL,
  110901. 0
  110902. };
  110903. static long _vq_quantlist__16c2_s_p9_0[] = {
  110904. 6,
  110905. 5,
  110906. 7,
  110907. 4,
  110908. 8,
  110909. 3,
  110910. 9,
  110911. 2,
  110912. 10,
  110913. 1,
  110914. 11,
  110915. 0,
  110916. 12,
  110917. };
  110918. static long _vq_lengthlist__16c2_s_p9_0[] = {
  110919. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110920. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110921. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110922. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110923. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110924. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110925. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110926. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110927. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110928. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110929. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110930. };
  110931. static float _vq_quantthresh__16c2_s_p9_0[] = {
  110932. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  110933. 2327.5, 3258.5, 4189.5, 5120.5,
  110934. };
  110935. static long _vq_quantmap__16c2_s_p9_0[] = {
  110936. 11, 9, 7, 5, 3, 1, 0, 2,
  110937. 4, 6, 8, 10, 12,
  110938. };
  110939. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  110940. _vq_quantthresh__16c2_s_p9_0,
  110941. _vq_quantmap__16c2_s_p9_0,
  110942. 13,
  110943. 13
  110944. };
  110945. static static_codebook _16c2_s_p9_0 = {
  110946. 2, 169,
  110947. _vq_lengthlist__16c2_s_p9_0,
  110948. 1, -510275072, 1631393792, 4, 0,
  110949. _vq_quantlist__16c2_s_p9_0,
  110950. NULL,
  110951. &_vq_auxt__16c2_s_p9_0,
  110952. NULL,
  110953. 0
  110954. };
  110955. static long _vq_quantlist__16c2_s_p9_1[] = {
  110956. 8,
  110957. 7,
  110958. 9,
  110959. 6,
  110960. 10,
  110961. 5,
  110962. 11,
  110963. 4,
  110964. 12,
  110965. 3,
  110966. 13,
  110967. 2,
  110968. 14,
  110969. 1,
  110970. 15,
  110971. 0,
  110972. 16,
  110973. };
  110974. static long _vq_lengthlist__16c2_s_p9_1[] = {
  110975. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  110976. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  110977. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  110978. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  110979. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  110980. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  110981. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  110982. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  110983. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  110984. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  110985. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110986. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110987. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110988. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110989. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110990. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  110991. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  110992. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110993. 10,
  110994. };
  110995. static float _vq_quantthresh__16c2_s_p9_1[] = {
  110996. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  110997. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  110998. };
  110999. static long _vq_quantmap__16c2_s_p9_1[] = {
  111000. 15, 13, 11, 9, 7, 5, 3, 1,
  111001. 0, 2, 4, 6, 8, 10, 12, 14,
  111002. 16,
  111003. };
  111004. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111005. _vq_quantthresh__16c2_s_p9_1,
  111006. _vq_quantmap__16c2_s_p9_1,
  111007. 17,
  111008. 17
  111009. };
  111010. static static_codebook _16c2_s_p9_1 = {
  111011. 2, 289,
  111012. _vq_lengthlist__16c2_s_p9_1,
  111013. 1, -518488064, 1622704128, 5, 0,
  111014. _vq_quantlist__16c2_s_p9_1,
  111015. NULL,
  111016. &_vq_auxt__16c2_s_p9_1,
  111017. NULL,
  111018. 0
  111019. };
  111020. static long _vq_quantlist__16c2_s_p9_2[] = {
  111021. 13,
  111022. 12,
  111023. 14,
  111024. 11,
  111025. 15,
  111026. 10,
  111027. 16,
  111028. 9,
  111029. 17,
  111030. 8,
  111031. 18,
  111032. 7,
  111033. 19,
  111034. 6,
  111035. 20,
  111036. 5,
  111037. 21,
  111038. 4,
  111039. 22,
  111040. 3,
  111041. 23,
  111042. 2,
  111043. 24,
  111044. 1,
  111045. 25,
  111046. 0,
  111047. 26,
  111048. };
  111049. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111050. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111051. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111052. };
  111053. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111054. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111055. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111056. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111057. 11.5, 12.5,
  111058. };
  111059. static long _vq_quantmap__16c2_s_p9_2[] = {
  111060. 25, 23, 21, 19, 17, 15, 13, 11,
  111061. 9, 7, 5, 3, 1, 0, 2, 4,
  111062. 6, 8, 10, 12, 14, 16, 18, 20,
  111063. 22, 24, 26,
  111064. };
  111065. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111066. _vq_quantthresh__16c2_s_p9_2,
  111067. _vq_quantmap__16c2_s_p9_2,
  111068. 27,
  111069. 27
  111070. };
  111071. static static_codebook _16c2_s_p9_2 = {
  111072. 1, 27,
  111073. _vq_lengthlist__16c2_s_p9_2,
  111074. 1, -528875520, 1611661312, 5, 0,
  111075. _vq_quantlist__16c2_s_p9_2,
  111076. NULL,
  111077. &_vq_auxt__16c2_s_p9_2,
  111078. NULL,
  111079. 0
  111080. };
  111081. static long _huff_lengthlist__16c2_s_short[] = {
  111082. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111083. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111084. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111085. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111086. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111087. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111088. 15,12,14,14,
  111089. };
  111090. static static_codebook _huff_book__16c2_s_short = {
  111091. 2, 100,
  111092. _huff_lengthlist__16c2_s_short,
  111093. 0, 0, 0, 0, 0,
  111094. NULL,
  111095. NULL,
  111096. NULL,
  111097. NULL,
  111098. 0
  111099. };
  111100. static long _vq_quantlist__8c0_s_p1_0[] = {
  111101. 1,
  111102. 0,
  111103. 2,
  111104. };
  111105. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111106. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111107. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111111. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111112. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111116. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111117. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111152. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111157. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111162. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111197. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111198. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111202. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111203. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 0,
  111204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111207. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111208. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111516. 0,
  111517. };
  111518. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111519. -0.5, 0.5,
  111520. };
  111521. static long _vq_quantmap__8c0_s_p1_0[] = {
  111522. 1, 0, 2,
  111523. };
  111524. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111525. _vq_quantthresh__8c0_s_p1_0,
  111526. _vq_quantmap__8c0_s_p1_0,
  111527. 3,
  111528. 3
  111529. };
  111530. static static_codebook _8c0_s_p1_0 = {
  111531. 8, 6561,
  111532. _vq_lengthlist__8c0_s_p1_0,
  111533. 1, -535822336, 1611661312, 2, 0,
  111534. _vq_quantlist__8c0_s_p1_0,
  111535. NULL,
  111536. &_vq_auxt__8c0_s_p1_0,
  111537. NULL,
  111538. 0
  111539. };
  111540. static long _vq_quantlist__8c0_s_p2_0[] = {
  111541. 2,
  111542. 1,
  111543. 3,
  111544. 0,
  111545. 4,
  111546. };
  111547. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111587. 0,
  111588. };
  111589. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111590. -1.5, -0.5, 0.5, 1.5,
  111591. };
  111592. static long _vq_quantmap__8c0_s_p2_0[] = {
  111593. 3, 1, 0, 2, 4,
  111594. };
  111595. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111596. _vq_quantthresh__8c0_s_p2_0,
  111597. _vq_quantmap__8c0_s_p2_0,
  111598. 5,
  111599. 5
  111600. };
  111601. static static_codebook _8c0_s_p2_0 = {
  111602. 4, 625,
  111603. _vq_lengthlist__8c0_s_p2_0,
  111604. 1, -533725184, 1611661312, 3, 0,
  111605. _vq_quantlist__8c0_s_p2_0,
  111606. NULL,
  111607. &_vq_auxt__8c0_s_p2_0,
  111608. NULL,
  111609. 0
  111610. };
  111611. static long _vq_quantlist__8c0_s_p3_0[] = {
  111612. 2,
  111613. 1,
  111614. 3,
  111615. 0,
  111616. 4,
  111617. };
  111618. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111619. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111622. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111625. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111658. 0,
  111659. };
  111660. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111661. -1.5, -0.5, 0.5, 1.5,
  111662. };
  111663. static long _vq_quantmap__8c0_s_p3_0[] = {
  111664. 3, 1, 0, 2, 4,
  111665. };
  111666. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111667. _vq_quantthresh__8c0_s_p3_0,
  111668. _vq_quantmap__8c0_s_p3_0,
  111669. 5,
  111670. 5
  111671. };
  111672. static static_codebook _8c0_s_p3_0 = {
  111673. 4, 625,
  111674. _vq_lengthlist__8c0_s_p3_0,
  111675. 1, -533725184, 1611661312, 3, 0,
  111676. _vq_quantlist__8c0_s_p3_0,
  111677. NULL,
  111678. &_vq_auxt__8c0_s_p3_0,
  111679. NULL,
  111680. 0
  111681. };
  111682. static long _vq_quantlist__8c0_s_p4_0[] = {
  111683. 4,
  111684. 3,
  111685. 5,
  111686. 2,
  111687. 6,
  111688. 1,
  111689. 7,
  111690. 0,
  111691. 8,
  111692. };
  111693. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111694. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111695. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111696. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111697. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111698. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111699. 0,
  111700. };
  111701. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111702. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111703. };
  111704. static long _vq_quantmap__8c0_s_p4_0[] = {
  111705. 7, 5, 3, 1, 0, 2, 4, 6,
  111706. 8,
  111707. };
  111708. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111709. _vq_quantthresh__8c0_s_p4_0,
  111710. _vq_quantmap__8c0_s_p4_0,
  111711. 9,
  111712. 9
  111713. };
  111714. static static_codebook _8c0_s_p4_0 = {
  111715. 2, 81,
  111716. _vq_lengthlist__8c0_s_p4_0,
  111717. 1, -531628032, 1611661312, 4, 0,
  111718. _vq_quantlist__8c0_s_p4_0,
  111719. NULL,
  111720. &_vq_auxt__8c0_s_p4_0,
  111721. NULL,
  111722. 0
  111723. };
  111724. static long _vq_quantlist__8c0_s_p5_0[] = {
  111725. 4,
  111726. 3,
  111727. 5,
  111728. 2,
  111729. 6,
  111730. 1,
  111731. 7,
  111732. 0,
  111733. 8,
  111734. };
  111735. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111736. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111737. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111738. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111739. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111740. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111741. 10,
  111742. };
  111743. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111744. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111745. };
  111746. static long _vq_quantmap__8c0_s_p5_0[] = {
  111747. 7, 5, 3, 1, 0, 2, 4, 6,
  111748. 8,
  111749. };
  111750. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111751. _vq_quantthresh__8c0_s_p5_0,
  111752. _vq_quantmap__8c0_s_p5_0,
  111753. 9,
  111754. 9
  111755. };
  111756. static static_codebook _8c0_s_p5_0 = {
  111757. 2, 81,
  111758. _vq_lengthlist__8c0_s_p5_0,
  111759. 1, -531628032, 1611661312, 4, 0,
  111760. _vq_quantlist__8c0_s_p5_0,
  111761. NULL,
  111762. &_vq_auxt__8c0_s_p5_0,
  111763. NULL,
  111764. 0
  111765. };
  111766. static long _vq_quantlist__8c0_s_p6_0[] = {
  111767. 8,
  111768. 7,
  111769. 9,
  111770. 6,
  111771. 10,
  111772. 5,
  111773. 11,
  111774. 4,
  111775. 12,
  111776. 3,
  111777. 13,
  111778. 2,
  111779. 14,
  111780. 1,
  111781. 15,
  111782. 0,
  111783. 16,
  111784. };
  111785. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111786. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111787. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111788. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111789. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111790. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111791. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111792. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111793. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111794. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111795. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111796. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111797. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111798. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111799. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111800. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111801. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111802. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111803. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111804. 14,
  111805. };
  111806. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111807. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111808. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111809. };
  111810. static long _vq_quantmap__8c0_s_p6_0[] = {
  111811. 15, 13, 11, 9, 7, 5, 3, 1,
  111812. 0, 2, 4, 6, 8, 10, 12, 14,
  111813. 16,
  111814. };
  111815. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  111816. _vq_quantthresh__8c0_s_p6_0,
  111817. _vq_quantmap__8c0_s_p6_0,
  111818. 17,
  111819. 17
  111820. };
  111821. static static_codebook _8c0_s_p6_0 = {
  111822. 2, 289,
  111823. _vq_lengthlist__8c0_s_p6_0,
  111824. 1, -529530880, 1611661312, 5, 0,
  111825. _vq_quantlist__8c0_s_p6_0,
  111826. NULL,
  111827. &_vq_auxt__8c0_s_p6_0,
  111828. NULL,
  111829. 0
  111830. };
  111831. static long _vq_quantlist__8c0_s_p7_0[] = {
  111832. 1,
  111833. 0,
  111834. 2,
  111835. };
  111836. static long _vq_lengthlist__8c0_s_p7_0[] = {
  111837. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  111838. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  111839. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  111840. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  111841. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  111842. 10,
  111843. };
  111844. static float _vq_quantthresh__8c0_s_p7_0[] = {
  111845. -5.5, 5.5,
  111846. };
  111847. static long _vq_quantmap__8c0_s_p7_0[] = {
  111848. 1, 0, 2,
  111849. };
  111850. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  111851. _vq_quantthresh__8c0_s_p7_0,
  111852. _vq_quantmap__8c0_s_p7_0,
  111853. 3,
  111854. 3
  111855. };
  111856. static static_codebook _8c0_s_p7_0 = {
  111857. 4, 81,
  111858. _vq_lengthlist__8c0_s_p7_0,
  111859. 1, -529137664, 1618345984, 2, 0,
  111860. _vq_quantlist__8c0_s_p7_0,
  111861. NULL,
  111862. &_vq_auxt__8c0_s_p7_0,
  111863. NULL,
  111864. 0
  111865. };
  111866. static long _vq_quantlist__8c0_s_p7_1[] = {
  111867. 5,
  111868. 4,
  111869. 6,
  111870. 3,
  111871. 7,
  111872. 2,
  111873. 8,
  111874. 1,
  111875. 9,
  111876. 0,
  111877. 10,
  111878. };
  111879. static long _vq_lengthlist__8c0_s_p7_1[] = {
  111880. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  111881. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  111882. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  111883. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  111884. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  111885. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  111886. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  111887. 10,10,10, 9, 9, 9,10,10,10,
  111888. };
  111889. static float _vq_quantthresh__8c0_s_p7_1[] = {
  111890. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111891. 3.5, 4.5,
  111892. };
  111893. static long _vq_quantmap__8c0_s_p7_1[] = {
  111894. 9, 7, 5, 3, 1, 0, 2, 4,
  111895. 6, 8, 10,
  111896. };
  111897. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  111898. _vq_quantthresh__8c0_s_p7_1,
  111899. _vq_quantmap__8c0_s_p7_1,
  111900. 11,
  111901. 11
  111902. };
  111903. static static_codebook _8c0_s_p7_1 = {
  111904. 2, 121,
  111905. _vq_lengthlist__8c0_s_p7_1,
  111906. 1, -531365888, 1611661312, 4, 0,
  111907. _vq_quantlist__8c0_s_p7_1,
  111908. NULL,
  111909. &_vq_auxt__8c0_s_p7_1,
  111910. NULL,
  111911. 0
  111912. };
  111913. static long _vq_quantlist__8c0_s_p8_0[] = {
  111914. 6,
  111915. 5,
  111916. 7,
  111917. 4,
  111918. 8,
  111919. 3,
  111920. 9,
  111921. 2,
  111922. 10,
  111923. 1,
  111924. 11,
  111925. 0,
  111926. 12,
  111927. };
  111928. static long _vq_lengthlist__8c0_s_p8_0[] = {
  111929. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  111930. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  111931. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  111932. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  111933. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  111934. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  111935. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  111936. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  111937. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  111938. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  111939. 0, 0,13,13,11,13,13,11,12,
  111940. };
  111941. static float _vq_quantthresh__8c0_s_p8_0[] = {
  111942. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111943. 12.5, 17.5, 22.5, 27.5,
  111944. };
  111945. static long _vq_quantmap__8c0_s_p8_0[] = {
  111946. 11, 9, 7, 5, 3, 1, 0, 2,
  111947. 4, 6, 8, 10, 12,
  111948. };
  111949. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  111950. _vq_quantthresh__8c0_s_p8_0,
  111951. _vq_quantmap__8c0_s_p8_0,
  111952. 13,
  111953. 13
  111954. };
  111955. static static_codebook _8c0_s_p8_0 = {
  111956. 2, 169,
  111957. _vq_lengthlist__8c0_s_p8_0,
  111958. 1, -526516224, 1616117760, 4, 0,
  111959. _vq_quantlist__8c0_s_p8_0,
  111960. NULL,
  111961. &_vq_auxt__8c0_s_p8_0,
  111962. NULL,
  111963. 0
  111964. };
  111965. static long _vq_quantlist__8c0_s_p8_1[] = {
  111966. 2,
  111967. 1,
  111968. 3,
  111969. 0,
  111970. 4,
  111971. };
  111972. static long _vq_lengthlist__8c0_s_p8_1[] = {
  111973. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  111974. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  111975. };
  111976. static float _vq_quantthresh__8c0_s_p8_1[] = {
  111977. -1.5, -0.5, 0.5, 1.5,
  111978. };
  111979. static long _vq_quantmap__8c0_s_p8_1[] = {
  111980. 3, 1, 0, 2, 4,
  111981. };
  111982. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  111983. _vq_quantthresh__8c0_s_p8_1,
  111984. _vq_quantmap__8c0_s_p8_1,
  111985. 5,
  111986. 5
  111987. };
  111988. static static_codebook _8c0_s_p8_1 = {
  111989. 2, 25,
  111990. _vq_lengthlist__8c0_s_p8_1,
  111991. 1, -533725184, 1611661312, 3, 0,
  111992. _vq_quantlist__8c0_s_p8_1,
  111993. NULL,
  111994. &_vq_auxt__8c0_s_p8_1,
  111995. NULL,
  111996. 0
  111997. };
  111998. static long _vq_quantlist__8c0_s_p9_0[] = {
  111999. 1,
  112000. 0,
  112001. 2,
  112002. };
  112003. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112004. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112005. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112006. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112007. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112008. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112009. 7,
  112010. };
  112011. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112012. -157.5, 157.5,
  112013. };
  112014. static long _vq_quantmap__8c0_s_p9_0[] = {
  112015. 1, 0, 2,
  112016. };
  112017. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112018. _vq_quantthresh__8c0_s_p9_0,
  112019. _vq_quantmap__8c0_s_p9_0,
  112020. 3,
  112021. 3
  112022. };
  112023. static static_codebook _8c0_s_p9_0 = {
  112024. 4, 81,
  112025. _vq_lengthlist__8c0_s_p9_0,
  112026. 1, -518803456, 1628680192, 2, 0,
  112027. _vq_quantlist__8c0_s_p9_0,
  112028. NULL,
  112029. &_vq_auxt__8c0_s_p9_0,
  112030. NULL,
  112031. 0
  112032. };
  112033. static long _vq_quantlist__8c0_s_p9_1[] = {
  112034. 7,
  112035. 6,
  112036. 8,
  112037. 5,
  112038. 9,
  112039. 4,
  112040. 10,
  112041. 3,
  112042. 11,
  112043. 2,
  112044. 12,
  112045. 1,
  112046. 13,
  112047. 0,
  112048. 14,
  112049. };
  112050. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112051. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112052. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112053. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112054. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112055. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112056. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112057. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112058. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112059. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112060. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112061. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112062. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112063. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112064. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112065. 11,
  112066. };
  112067. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112068. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112069. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112070. };
  112071. static long _vq_quantmap__8c0_s_p9_1[] = {
  112072. 13, 11, 9, 7, 5, 3, 1, 0,
  112073. 2, 4, 6, 8, 10, 12, 14,
  112074. };
  112075. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112076. _vq_quantthresh__8c0_s_p9_1,
  112077. _vq_quantmap__8c0_s_p9_1,
  112078. 15,
  112079. 15
  112080. };
  112081. static static_codebook _8c0_s_p9_1 = {
  112082. 2, 225,
  112083. _vq_lengthlist__8c0_s_p9_1,
  112084. 1, -520986624, 1620377600, 4, 0,
  112085. _vq_quantlist__8c0_s_p9_1,
  112086. NULL,
  112087. &_vq_auxt__8c0_s_p9_1,
  112088. NULL,
  112089. 0
  112090. };
  112091. static long _vq_quantlist__8c0_s_p9_2[] = {
  112092. 10,
  112093. 9,
  112094. 11,
  112095. 8,
  112096. 12,
  112097. 7,
  112098. 13,
  112099. 6,
  112100. 14,
  112101. 5,
  112102. 15,
  112103. 4,
  112104. 16,
  112105. 3,
  112106. 17,
  112107. 2,
  112108. 18,
  112109. 1,
  112110. 19,
  112111. 0,
  112112. 20,
  112113. };
  112114. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112115. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112116. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112117. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112118. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112119. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112120. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112121. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112122. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112123. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112124. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112125. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112126. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112127. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112128. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112129. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112130. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112131. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112132. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112133. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112134. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112135. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112136. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112137. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112138. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112139. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112140. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112141. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112142. 10,11, 9,11,10, 9,10, 9,10,
  112143. };
  112144. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112145. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112146. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112147. 6.5, 7.5, 8.5, 9.5,
  112148. };
  112149. static long _vq_quantmap__8c0_s_p9_2[] = {
  112150. 19, 17, 15, 13, 11, 9, 7, 5,
  112151. 3, 1, 0, 2, 4, 6, 8, 10,
  112152. 12, 14, 16, 18, 20,
  112153. };
  112154. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112155. _vq_quantthresh__8c0_s_p9_2,
  112156. _vq_quantmap__8c0_s_p9_2,
  112157. 21,
  112158. 21
  112159. };
  112160. static static_codebook _8c0_s_p9_2 = {
  112161. 2, 441,
  112162. _vq_lengthlist__8c0_s_p9_2,
  112163. 1, -529268736, 1611661312, 5, 0,
  112164. _vq_quantlist__8c0_s_p9_2,
  112165. NULL,
  112166. &_vq_auxt__8c0_s_p9_2,
  112167. NULL,
  112168. 0
  112169. };
  112170. static long _huff_lengthlist__8c0_s_single[] = {
  112171. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112172. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112173. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112174. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112175. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112176. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112177. 17,16,17,17,
  112178. };
  112179. static static_codebook _huff_book__8c0_s_single = {
  112180. 2, 100,
  112181. _huff_lengthlist__8c0_s_single,
  112182. 0, 0, 0, 0, 0,
  112183. NULL,
  112184. NULL,
  112185. NULL,
  112186. NULL,
  112187. 0
  112188. };
  112189. static long _vq_quantlist__8c1_s_p1_0[] = {
  112190. 1,
  112191. 0,
  112192. 2,
  112193. };
  112194. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112195. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112196. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112200. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112201. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112205. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112206. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112241. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112246. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112251. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112286. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112287. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112291. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112292. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  112293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112296. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112297. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112605. 0,
  112606. };
  112607. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112608. -0.5, 0.5,
  112609. };
  112610. static long _vq_quantmap__8c1_s_p1_0[] = {
  112611. 1, 0, 2,
  112612. };
  112613. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112614. _vq_quantthresh__8c1_s_p1_0,
  112615. _vq_quantmap__8c1_s_p1_0,
  112616. 3,
  112617. 3
  112618. };
  112619. static static_codebook _8c1_s_p1_0 = {
  112620. 8, 6561,
  112621. _vq_lengthlist__8c1_s_p1_0,
  112622. 1, -535822336, 1611661312, 2, 0,
  112623. _vq_quantlist__8c1_s_p1_0,
  112624. NULL,
  112625. &_vq_auxt__8c1_s_p1_0,
  112626. NULL,
  112627. 0
  112628. };
  112629. static long _vq_quantlist__8c1_s_p2_0[] = {
  112630. 2,
  112631. 1,
  112632. 3,
  112633. 0,
  112634. 4,
  112635. };
  112636. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112676. 0,
  112677. };
  112678. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112679. -1.5, -0.5, 0.5, 1.5,
  112680. };
  112681. static long _vq_quantmap__8c1_s_p2_0[] = {
  112682. 3, 1, 0, 2, 4,
  112683. };
  112684. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112685. _vq_quantthresh__8c1_s_p2_0,
  112686. _vq_quantmap__8c1_s_p2_0,
  112687. 5,
  112688. 5
  112689. };
  112690. static static_codebook _8c1_s_p2_0 = {
  112691. 4, 625,
  112692. _vq_lengthlist__8c1_s_p2_0,
  112693. 1, -533725184, 1611661312, 3, 0,
  112694. _vq_quantlist__8c1_s_p2_0,
  112695. NULL,
  112696. &_vq_auxt__8c1_s_p2_0,
  112697. NULL,
  112698. 0
  112699. };
  112700. static long _vq_quantlist__8c1_s_p3_0[] = {
  112701. 2,
  112702. 1,
  112703. 3,
  112704. 0,
  112705. 4,
  112706. };
  112707. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112708. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112711. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112714. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112747. 0,
  112748. };
  112749. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112750. -1.5, -0.5, 0.5, 1.5,
  112751. };
  112752. static long _vq_quantmap__8c1_s_p3_0[] = {
  112753. 3, 1, 0, 2, 4,
  112754. };
  112755. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112756. _vq_quantthresh__8c1_s_p3_0,
  112757. _vq_quantmap__8c1_s_p3_0,
  112758. 5,
  112759. 5
  112760. };
  112761. static static_codebook _8c1_s_p3_0 = {
  112762. 4, 625,
  112763. _vq_lengthlist__8c1_s_p3_0,
  112764. 1, -533725184, 1611661312, 3, 0,
  112765. _vq_quantlist__8c1_s_p3_0,
  112766. NULL,
  112767. &_vq_auxt__8c1_s_p3_0,
  112768. NULL,
  112769. 0
  112770. };
  112771. static long _vq_quantlist__8c1_s_p4_0[] = {
  112772. 4,
  112773. 3,
  112774. 5,
  112775. 2,
  112776. 6,
  112777. 1,
  112778. 7,
  112779. 0,
  112780. 8,
  112781. };
  112782. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112783. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112784. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112785. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112786. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112787. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112788. 0,
  112789. };
  112790. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112791. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112792. };
  112793. static long _vq_quantmap__8c1_s_p4_0[] = {
  112794. 7, 5, 3, 1, 0, 2, 4, 6,
  112795. 8,
  112796. };
  112797. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112798. _vq_quantthresh__8c1_s_p4_0,
  112799. _vq_quantmap__8c1_s_p4_0,
  112800. 9,
  112801. 9
  112802. };
  112803. static static_codebook _8c1_s_p4_0 = {
  112804. 2, 81,
  112805. _vq_lengthlist__8c1_s_p4_0,
  112806. 1, -531628032, 1611661312, 4, 0,
  112807. _vq_quantlist__8c1_s_p4_0,
  112808. NULL,
  112809. &_vq_auxt__8c1_s_p4_0,
  112810. NULL,
  112811. 0
  112812. };
  112813. static long _vq_quantlist__8c1_s_p5_0[] = {
  112814. 4,
  112815. 3,
  112816. 5,
  112817. 2,
  112818. 6,
  112819. 1,
  112820. 7,
  112821. 0,
  112822. 8,
  112823. };
  112824. static long _vq_lengthlist__8c1_s_p5_0[] = {
  112825. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  112826. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  112827. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  112828. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  112829. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112830. 10,
  112831. };
  112832. static float _vq_quantthresh__8c1_s_p5_0[] = {
  112833. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112834. };
  112835. static long _vq_quantmap__8c1_s_p5_0[] = {
  112836. 7, 5, 3, 1, 0, 2, 4, 6,
  112837. 8,
  112838. };
  112839. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  112840. _vq_quantthresh__8c1_s_p5_0,
  112841. _vq_quantmap__8c1_s_p5_0,
  112842. 9,
  112843. 9
  112844. };
  112845. static static_codebook _8c1_s_p5_0 = {
  112846. 2, 81,
  112847. _vq_lengthlist__8c1_s_p5_0,
  112848. 1, -531628032, 1611661312, 4, 0,
  112849. _vq_quantlist__8c1_s_p5_0,
  112850. NULL,
  112851. &_vq_auxt__8c1_s_p5_0,
  112852. NULL,
  112853. 0
  112854. };
  112855. static long _vq_quantlist__8c1_s_p6_0[] = {
  112856. 8,
  112857. 7,
  112858. 9,
  112859. 6,
  112860. 10,
  112861. 5,
  112862. 11,
  112863. 4,
  112864. 12,
  112865. 3,
  112866. 13,
  112867. 2,
  112868. 14,
  112869. 1,
  112870. 15,
  112871. 0,
  112872. 16,
  112873. };
  112874. static long _vq_lengthlist__8c1_s_p6_0[] = {
  112875. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  112876. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112877. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  112878. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  112879. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  112880. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  112881. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  112882. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  112883. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  112884. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112885. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  112886. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  112887. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  112888. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  112889. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  112890. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  112891. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  112892. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  112893. 14,
  112894. };
  112895. static float _vq_quantthresh__8c1_s_p6_0[] = {
  112896. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112897. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112898. };
  112899. static long _vq_quantmap__8c1_s_p6_0[] = {
  112900. 15, 13, 11, 9, 7, 5, 3, 1,
  112901. 0, 2, 4, 6, 8, 10, 12, 14,
  112902. 16,
  112903. };
  112904. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  112905. _vq_quantthresh__8c1_s_p6_0,
  112906. _vq_quantmap__8c1_s_p6_0,
  112907. 17,
  112908. 17
  112909. };
  112910. static static_codebook _8c1_s_p6_0 = {
  112911. 2, 289,
  112912. _vq_lengthlist__8c1_s_p6_0,
  112913. 1, -529530880, 1611661312, 5, 0,
  112914. _vq_quantlist__8c1_s_p6_0,
  112915. NULL,
  112916. &_vq_auxt__8c1_s_p6_0,
  112917. NULL,
  112918. 0
  112919. };
  112920. static long _vq_quantlist__8c1_s_p7_0[] = {
  112921. 1,
  112922. 0,
  112923. 2,
  112924. };
  112925. static long _vq_lengthlist__8c1_s_p7_0[] = {
  112926. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  112927. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  112928. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  112929. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  112930. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  112931. 9,
  112932. };
  112933. static float _vq_quantthresh__8c1_s_p7_0[] = {
  112934. -5.5, 5.5,
  112935. };
  112936. static long _vq_quantmap__8c1_s_p7_0[] = {
  112937. 1, 0, 2,
  112938. };
  112939. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  112940. _vq_quantthresh__8c1_s_p7_0,
  112941. _vq_quantmap__8c1_s_p7_0,
  112942. 3,
  112943. 3
  112944. };
  112945. static static_codebook _8c1_s_p7_0 = {
  112946. 4, 81,
  112947. _vq_lengthlist__8c1_s_p7_0,
  112948. 1, -529137664, 1618345984, 2, 0,
  112949. _vq_quantlist__8c1_s_p7_0,
  112950. NULL,
  112951. &_vq_auxt__8c1_s_p7_0,
  112952. NULL,
  112953. 0
  112954. };
  112955. static long _vq_quantlist__8c1_s_p7_1[] = {
  112956. 5,
  112957. 4,
  112958. 6,
  112959. 3,
  112960. 7,
  112961. 2,
  112962. 8,
  112963. 1,
  112964. 9,
  112965. 0,
  112966. 10,
  112967. };
  112968. static long _vq_lengthlist__8c1_s_p7_1[] = {
  112969. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  112970. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  112971. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  112972. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  112973. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  112974. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  112975. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  112976. 10,10,10, 8, 8, 8, 8, 8, 8,
  112977. };
  112978. static float _vq_quantthresh__8c1_s_p7_1[] = {
  112979. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112980. 3.5, 4.5,
  112981. };
  112982. static long _vq_quantmap__8c1_s_p7_1[] = {
  112983. 9, 7, 5, 3, 1, 0, 2, 4,
  112984. 6, 8, 10,
  112985. };
  112986. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  112987. _vq_quantthresh__8c1_s_p7_1,
  112988. _vq_quantmap__8c1_s_p7_1,
  112989. 11,
  112990. 11
  112991. };
  112992. static static_codebook _8c1_s_p7_1 = {
  112993. 2, 121,
  112994. _vq_lengthlist__8c1_s_p7_1,
  112995. 1, -531365888, 1611661312, 4, 0,
  112996. _vq_quantlist__8c1_s_p7_1,
  112997. NULL,
  112998. &_vq_auxt__8c1_s_p7_1,
  112999. NULL,
  113000. 0
  113001. };
  113002. static long _vq_quantlist__8c1_s_p8_0[] = {
  113003. 6,
  113004. 5,
  113005. 7,
  113006. 4,
  113007. 8,
  113008. 3,
  113009. 9,
  113010. 2,
  113011. 10,
  113012. 1,
  113013. 11,
  113014. 0,
  113015. 12,
  113016. };
  113017. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113018. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113019. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113020. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113021. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113022. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113023. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113024. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113025. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113026. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113027. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113028. 0,12,12,11,10,12,11,13,12,
  113029. };
  113030. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113031. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113032. 12.5, 17.5, 22.5, 27.5,
  113033. };
  113034. static long _vq_quantmap__8c1_s_p8_0[] = {
  113035. 11, 9, 7, 5, 3, 1, 0, 2,
  113036. 4, 6, 8, 10, 12,
  113037. };
  113038. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113039. _vq_quantthresh__8c1_s_p8_0,
  113040. _vq_quantmap__8c1_s_p8_0,
  113041. 13,
  113042. 13
  113043. };
  113044. static static_codebook _8c1_s_p8_0 = {
  113045. 2, 169,
  113046. _vq_lengthlist__8c1_s_p8_0,
  113047. 1, -526516224, 1616117760, 4, 0,
  113048. _vq_quantlist__8c1_s_p8_0,
  113049. NULL,
  113050. &_vq_auxt__8c1_s_p8_0,
  113051. NULL,
  113052. 0
  113053. };
  113054. static long _vq_quantlist__8c1_s_p8_1[] = {
  113055. 2,
  113056. 1,
  113057. 3,
  113058. 0,
  113059. 4,
  113060. };
  113061. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113062. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113063. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113064. };
  113065. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113066. -1.5, -0.5, 0.5, 1.5,
  113067. };
  113068. static long _vq_quantmap__8c1_s_p8_1[] = {
  113069. 3, 1, 0, 2, 4,
  113070. };
  113071. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113072. _vq_quantthresh__8c1_s_p8_1,
  113073. _vq_quantmap__8c1_s_p8_1,
  113074. 5,
  113075. 5
  113076. };
  113077. static static_codebook _8c1_s_p8_1 = {
  113078. 2, 25,
  113079. _vq_lengthlist__8c1_s_p8_1,
  113080. 1, -533725184, 1611661312, 3, 0,
  113081. _vq_quantlist__8c1_s_p8_1,
  113082. NULL,
  113083. &_vq_auxt__8c1_s_p8_1,
  113084. NULL,
  113085. 0
  113086. };
  113087. static long _vq_quantlist__8c1_s_p9_0[] = {
  113088. 6,
  113089. 5,
  113090. 7,
  113091. 4,
  113092. 8,
  113093. 3,
  113094. 9,
  113095. 2,
  113096. 10,
  113097. 1,
  113098. 11,
  113099. 0,
  113100. 12,
  113101. };
  113102. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113103. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113104. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113105. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113106. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113107. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113108. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113109. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113110. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113111. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113112. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113113. 10,10,10,10,10, 9, 9, 9, 9,
  113114. };
  113115. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113116. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113117. 787.5, 1102.5, 1417.5, 1732.5,
  113118. };
  113119. static long _vq_quantmap__8c1_s_p9_0[] = {
  113120. 11, 9, 7, 5, 3, 1, 0, 2,
  113121. 4, 6, 8, 10, 12,
  113122. };
  113123. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113124. _vq_quantthresh__8c1_s_p9_0,
  113125. _vq_quantmap__8c1_s_p9_0,
  113126. 13,
  113127. 13
  113128. };
  113129. static static_codebook _8c1_s_p9_0 = {
  113130. 2, 169,
  113131. _vq_lengthlist__8c1_s_p9_0,
  113132. 1, -513964032, 1628680192, 4, 0,
  113133. _vq_quantlist__8c1_s_p9_0,
  113134. NULL,
  113135. &_vq_auxt__8c1_s_p9_0,
  113136. NULL,
  113137. 0
  113138. };
  113139. static long _vq_quantlist__8c1_s_p9_1[] = {
  113140. 7,
  113141. 6,
  113142. 8,
  113143. 5,
  113144. 9,
  113145. 4,
  113146. 10,
  113147. 3,
  113148. 11,
  113149. 2,
  113150. 12,
  113151. 1,
  113152. 13,
  113153. 0,
  113154. 14,
  113155. };
  113156. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113157. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113158. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113159. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113160. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113161. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113162. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113163. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113164. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113165. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113166. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113167. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113168. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113169. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113170. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113171. 15,
  113172. };
  113173. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113174. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113175. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113176. };
  113177. static long _vq_quantmap__8c1_s_p9_1[] = {
  113178. 13, 11, 9, 7, 5, 3, 1, 0,
  113179. 2, 4, 6, 8, 10, 12, 14,
  113180. };
  113181. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113182. _vq_quantthresh__8c1_s_p9_1,
  113183. _vq_quantmap__8c1_s_p9_1,
  113184. 15,
  113185. 15
  113186. };
  113187. static static_codebook _8c1_s_p9_1 = {
  113188. 2, 225,
  113189. _vq_lengthlist__8c1_s_p9_1,
  113190. 1, -520986624, 1620377600, 4, 0,
  113191. _vq_quantlist__8c1_s_p9_1,
  113192. NULL,
  113193. &_vq_auxt__8c1_s_p9_1,
  113194. NULL,
  113195. 0
  113196. };
  113197. static long _vq_quantlist__8c1_s_p9_2[] = {
  113198. 10,
  113199. 9,
  113200. 11,
  113201. 8,
  113202. 12,
  113203. 7,
  113204. 13,
  113205. 6,
  113206. 14,
  113207. 5,
  113208. 15,
  113209. 4,
  113210. 16,
  113211. 3,
  113212. 17,
  113213. 2,
  113214. 18,
  113215. 1,
  113216. 19,
  113217. 0,
  113218. 20,
  113219. };
  113220. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113221. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113222. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113223. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113224. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113225. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113226. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113227. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113228. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113229. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113230. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113231. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113232. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113233. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113234. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113235. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113236. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113237. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113238. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113239. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113240. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113241. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113242. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113243. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113244. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113245. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113246. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113247. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113248. 10,10,10,10,10,10,10,10,10,
  113249. };
  113250. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113251. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113252. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113253. 6.5, 7.5, 8.5, 9.5,
  113254. };
  113255. static long _vq_quantmap__8c1_s_p9_2[] = {
  113256. 19, 17, 15, 13, 11, 9, 7, 5,
  113257. 3, 1, 0, 2, 4, 6, 8, 10,
  113258. 12, 14, 16, 18, 20,
  113259. };
  113260. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113261. _vq_quantthresh__8c1_s_p9_2,
  113262. _vq_quantmap__8c1_s_p9_2,
  113263. 21,
  113264. 21
  113265. };
  113266. static static_codebook _8c1_s_p9_2 = {
  113267. 2, 441,
  113268. _vq_lengthlist__8c1_s_p9_2,
  113269. 1, -529268736, 1611661312, 5, 0,
  113270. _vq_quantlist__8c1_s_p9_2,
  113271. NULL,
  113272. &_vq_auxt__8c1_s_p9_2,
  113273. NULL,
  113274. 0
  113275. };
  113276. static long _huff_lengthlist__8c1_s_single[] = {
  113277. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113278. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113279. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113280. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113281. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113282. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113283. 9, 7, 7, 8,
  113284. };
  113285. static static_codebook _huff_book__8c1_s_single = {
  113286. 2, 100,
  113287. _huff_lengthlist__8c1_s_single,
  113288. 0, 0, 0, 0, 0,
  113289. NULL,
  113290. NULL,
  113291. NULL,
  113292. NULL,
  113293. 0
  113294. };
  113295. static long _huff_lengthlist__44c2_s_long[] = {
  113296. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113297. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113298. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113299. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113300. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113301. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113302. 10, 8, 8, 9,
  113303. };
  113304. static static_codebook _huff_book__44c2_s_long = {
  113305. 2, 100,
  113306. _huff_lengthlist__44c2_s_long,
  113307. 0, 0, 0, 0, 0,
  113308. NULL,
  113309. NULL,
  113310. NULL,
  113311. NULL,
  113312. 0
  113313. };
  113314. static long _vq_quantlist__44c2_s_p1_0[] = {
  113315. 1,
  113316. 0,
  113317. 2,
  113318. };
  113319. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113320. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113321. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113325. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113326. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113330. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113331. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113366. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113371. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113376. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113411. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113412. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113416. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113417. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  113418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113421. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113422. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113730. 0,
  113731. };
  113732. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113733. -0.5, 0.5,
  113734. };
  113735. static long _vq_quantmap__44c2_s_p1_0[] = {
  113736. 1, 0, 2,
  113737. };
  113738. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113739. _vq_quantthresh__44c2_s_p1_0,
  113740. _vq_quantmap__44c2_s_p1_0,
  113741. 3,
  113742. 3
  113743. };
  113744. static static_codebook _44c2_s_p1_0 = {
  113745. 8, 6561,
  113746. _vq_lengthlist__44c2_s_p1_0,
  113747. 1, -535822336, 1611661312, 2, 0,
  113748. _vq_quantlist__44c2_s_p1_0,
  113749. NULL,
  113750. &_vq_auxt__44c2_s_p1_0,
  113751. NULL,
  113752. 0
  113753. };
  113754. static long _vq_quantlist__44c2_s_p2_0[] = {
  113755. 2,
  113756. 1,
  113757. 3,
  113758. 0,
  113759. 4,
  113760. };
  113761. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113762. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113763. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113764. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113765. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113766. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113771. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113772. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113773. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113774. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113779. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113780. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113781. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  113782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113787. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113788. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113789. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  113790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113801. 0,
  113802. };
  113803. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113804. -1.5, -0.5, 0.5, 1.5,
  113805. };
  113806. static long _vq_quantmap__44c2_s_p2_0[] = {
  113807. 3, 1, 0, 2, 4,
  113808. };
  113809. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  113810. _vq_quantthresh__44c2_s_p2_0,
  113811. _vq_quantmap__44c2_s_p2_0,
  113812. 5,
  113813. 5
  113814. };
  113815. static static_codebook _44c2_s_p2_0 = {
  113816. 4, 625,
  113817. _vq_lengthlist__44c2_s_p2_0,
  113818. 1, -533725184, 1611661312, 3, 0,
  113819. _vq_quantlist__44c2_s_p2_0,
  113820. NULL,
  113821. &_vq_auxt__44c2_s_p2_0,
  113822. NULL,
  113823. 0
  113824. };
  113825. static long _vq_quantlist__44c2_s_p3_0[] = {
  113826. 2,
  113827. 1,
  113828. 3,
  113829. 0,
  113830. 4,
  113831. };
  113832. static long _vq_lengthlist__44c2_s_p3_0[] = {
  113833. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113836. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  113838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113839. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113872. 0,
  113873. };
  113874. static float _vq_quantthresh__44c2_s_p3_0[] = {
  113875. -1.5, -0.5, 0.5, 1.5,
  113876. };
  113877. static long _vq_quantmap__44c2_s_p3_0[] = {
  113878. 3, 1, 0, 2, 4,
  113879. };
  113880. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  113881. _vq_quantthresh__44c2_s_p3_0,
  113882. _vq_quantmap__44c2_s_p3_0,
  113883. 5,
  113884. 5
  113885. };
  113886. static static_codebook _44c2_s_p3_0 = {
  113887. 4, 625,
  113888. _vq_lengthlist__44c2_s_p3_0,
  113889. 1, -533725184, 1611661312, 3, 0,
  113890. _vq_quantlist__44c2_s_p3_0,
  113891. NULL,
  113892. &_vq_auxt__44c2_s_p3_0,
  113893. NULL,
  113894. 0
  113895. };
  113896. static long _vq_quantlist__44c2_s_p4_0[] = {
  113897. 4,
  113898. 3,
  113899. 5,
  113900. 2,
  113901. 6,
  113902. 1,
  113903. 7,
  113904. 0,
  113905. 8,
  113906. };
  113907. static long _vq_lengthlist__44c2_s_p4_0[] = {
  113908. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  113909. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  113910. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  113911. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  113912. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113913. 0,
  113914. };
  113915. static float _vq_quantthresh__44c2_s_p4_0[] = {
  113916. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113917. };
  113918. static long _vq_quantmap__44c2_s_p4_0[] = {
  113919. 7, 5, 3, 1, 0, 2, 4, 6,
  113920. 8,
  113921. };
  113922. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  113923. _vq_quantthresh__44c2_s_p4_0,
  113924. _vq_quantmap__44c2_s_p4_0,
  113925. 9,
  113926. 9
  113927. };
  113928. static static_codebook _44c2_s_p4_0 = {
  113929. 2, 81,
  113930. _vq_lengthlist__44c2_s_p4_0,
  113931. 1, -531628032, 1611661312, 4, 0,
  113932. _vq_quantlist__44c2_s_p4_0,
  113933. NULL,
  113934. &_vq_auxt__44c2_s_p4_0,
  113935. NULL,
  113936. 0
  113937. };
  113938. static long _vq_quantlist__44c2_s_p5_0[] = {
  113939. 4,
  113940. 3,
  113941. 5,
  113942. 2,
  113943. 6,
  113944. 1,
  113945. 7,
  113946. 0,
  113947. 8,
  113948. };
  113949. static long _vq_lengthlist__44c2_s_p5_0[] = {
  113950. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  113951. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  113952. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  113953. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  113954. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  113955. 11,
  113956. };
  113957. static float _vq_quantthresh__44c2_s_p5_0[] = {
  113958. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113959. };
  113960. static long _vq_quantmap__44c2_s_p5_0[] = {
  113961. 7, 5, 3, 1, 0, 2, 4, 6,
  113962. 8,
  113963. };
  113964. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  113965. _vq_quantthresh__44c2_s_p5_0,
  113966. _vq_quantmap__44c2_s_p5_0,
  113967. 9,
  113968. 9
  113969. };
  113970. static static_codebook _44c2_s_p5_0 = {
  113971. 2, 81,
  113972. _vq_lengthlist__44c2_s_p5_0,
  113973. 1, -531628032, 1611661312, 4, 0,
  113974. _vq_quantlist__44c2_s_p5_0,
  113975. NULL,
  113976. &_vq_auxt__44c2_s_p5_0,
  113977. NULL,
  113978. 0
  113979. };
  113980. static long _vq_quantlist__44c2_s_p6_0[] = {
  113981. 8,
  113982. 7,
  113983. 9,
  113984. 6,
  113985. 10,
  113986. 5,
  113987. 11,
  113988. 4,
  113989. 12,
  113990. 3,
  113991. 13,
  113992. 2,
  113993. 14,
  113994. 1,
  113995. 15,
  113996. 0,
  113997. 16,
  113998. };
  113999. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114000. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114001. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114002. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114003. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114004. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114005. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114006. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114007. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114008. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114009. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114010. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114011. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114012. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114013. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114014. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114015. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114016. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114017. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114018. 14,
  114019. };
  114020. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114021. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114022. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114023. };
  114024. static long _vq_quantmap__44c2_s_p6_0[] = {
  114025. 15, 13, 11, 9, 7, 5, 3, 1,
  114026. 0, 2, 4, 6, 8, 10, 12, 14,
  114027. 16,
  114028. };
  114029. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114030. _vq_quantthresh__44c2_s_p6_0,
  114031. _vq_quantmap__44c2_s_p6_0,
  114032. 17,
  114033. 17
  114034. };
  114035. static static_codebook _44c2_s_p6_0 = {
  114036. 2, 289,
  114037. _vq_lengthlist__44c2_s_p6_0,
  114038. 1, -529530880, 1611661312, 5, 0,
  114039. _vq_quantlist__44c2_s_p6_0,
  114040. NULL,
  114041. &_vq_auxt__44c2_s_p6_0,
  114042. NULL,
  114043. 0
  114044. };
  114045. static long _vq_quantlist__44c2_s_p7_0[] = {
  114046. 1,
  114047. 0,
  114048. 2,
  114049. };
  114050. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114051. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114052. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114053. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114054. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114055. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114056. 11,
  114057. };
  114058. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114059. -5.5, 5.5,
  114060. };
  114061. static long _vq_quantmap__44c2_s_p7_0[] = {
  114062. 1, 0, 2,
  114063. };
  114064. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114065. _vq_quantthresh__44c2_s_p7_0,
  114066. _vq_quantmap__44c2_s_p7_0,
  114067. 3,
  114068. 3
  114069. };
  114070. static static_codebook _44c2_s_p7_0 = {
  114071. 4, 81,
  114072. _vq_lengthlist__44c2_s_p7_0,
  114073. 1, -529137664, 1618345984, 2, 0,
  114074. _vq_quantlist__44c2_s_p7_0,
  114075. NULL,
  114076. &_vq_auxt__44c2_s_p7_0,
  114077. NULL,
  114078. 0
  114079. };
  114080. static long _vq_quantlist__44c2_s_p7_1[] = {
  114081. 5,
  114082. 4,
  114083. 6,
  114084. 3,
  114085. 7,
  114086. 2,
  114087. 8,
  114088. 1,
  114089. 9,
  114090. 0,
  114091. 10,
  114092. };
  114093. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114094. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114095. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114096. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114097. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114098. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114099. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114100. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114101. 10,10,10, 8, 8, 8, 8, 8, 8,
  114102. };
  114103. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114104. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114105. 3.5, 4.5,
  114106. };
  114107. static long _vq_quantmap__44c2_s_p7_1[] = {
  114108. 9, 7, 5, 3, 1, 0, 2, 4,
  114109. 6, 8, 10,
  114110. };
  114111. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114112. _vq_quantthresh__44c2_s_p7_1,
  114113. _vq_quantmap__44c2_s_p7_1,
  114114. 11,
  114115. 11
  114116. };
  114117. static static_codebook _44c2_s_p7_1 = {
  114118. 2, 121,
  114119. _vq_lengthlist__44c2_s_p7_1,
  114120. 1, -531365888, 1611661312, 4, 0,
  114121. _vq_quantlist__44c2_s_p7_1,
  114122. NULL,
  114123. &_vq_auxt__44c2_s_p7_1,
  114124. NULL,
  114125. 0
  114126. };
  114127. static long _vq_quantlist__44c2_s_p8_0[] = {
  114128. 6,
  114129. 5,
  114130. 7,
  114131. 4,
  114132. 8,
  114133. 3,
  114134. 9,
  114135. 2,
  114136. 10,
  114137. 1,
  114138. 11,
  114139. 0,
  114140. 12,
  114141. };
  114142. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114143. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114144. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114145. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114146. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114147. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114148. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114149. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114150. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114151. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114152. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114153. 0,12,12,12,12,13,12,14,14,
  114154. };
  114155. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114156. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114157. 12.5, 17.5, 22.5, 27.5,
  114158. };
  114159. static long _vq_quantmap__44c2_s_p8_0[] = {
  114160. 11, 9, 7, 5, 3, 1, 0, 2,
  114161. 4, 6, 8, 10, 12,
  114162. };
  114163. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114164. _vq_quantthresh__44c2_s_p8_0,
  114165. _vq_quantmap__44c2_s_p8_0,
  114166. 13,
  114167. 13
  114168. };
  114169. static static_codebook _44c2_s_p8_0 = {
  114170. 2, 169,
  114171. _vq_lengthlist__44c2_s_p8_0,
  114172. 1, -526516224, 1616117760, 4, 0,
  114173. _vq_quantlist__44c2_s_p8_0,
  114174. NULL,
  114175. &_vq_auxt__44c2_s_p8_0,
  114176. NULL,
  114177. 0
  114178. };
  114179. static long _vq_quantlist__44c2_s_p8_1[] = {
  114180. 2,
  114181. 1,
  114182. 3,
  114183. 0,
  114184. 4,
  114185. };
  114186. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114187. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114188. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114189. };
  114190. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114191. -1.5, -0.5, 0.5, 1.5,
  114192. };
  114193. static long _vq_quantmap__44c2_s_p8_1[] = {
  114194. 3, 1, 0, 2, 4,
  114195. };
  114196. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114197. _vq_quantthresh__44c2_s_p8_1,
  114198. _vq_quantmap__44c2_s_p8_1,
  114199. 5,
  114200. 5
  114201. };
  114202. static static_codebook _44c2_s_p8_1 = {
  114203. 2, 25,
  114204. _vq_lengthlist__44c2_s_p8_1,
  114205. 1, -533725184, 1611661312, 3, 0,
  114206. _vq_quantlist__44c2_s_p8_1,
  114207. NULL,
  114208. &_vq_auxt__44c2_s_p8_1,
  114209. NULL,
  114210. 0
  114211. };
  114212. static long _vq_quantlist__44c2_s_p9_0[] = {
  114213. 6,
  114214. 5,
  114215. 7,
  114216. 4,
  114217. 8,
  114218. 3,
  114219. 9,
  114220. 2,
  114221. 10,
  114222. 1,
  114223. 11,
  114224. 0,
  114225. 12,
  114226. };
  114227. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114228. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114229. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114230. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114231. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114232. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114233. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114234. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114235. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114236. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114237. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114238. 11,11,11,11,11,11,11,11,11,
  114239. };
  114240. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114241. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114242. 552.5, 773.5, 994.5, 1215.5,
  114243. };
  114244. static long _vq_quantmap__44c2_s_p9_0[] = {
  114245. 11, 9, 7, 5, 3, 1, 0, 2,
  114246. 4, 6, 8, 10, 12,
  114247. };
  114248. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114249. _vq_quantthresh__44c2_s_p9_0,
  114250. _vq_quantmap__44c2_s_p9_0,
  114251. 13,
  114252. 13
  114253. };
  114254. static static_codebook _44c2_s_p9_0 = {
  114255. 2, 169,
  114256. _vq_lengthlist__44c2_s_p9_0,
  114257. 1, -514541568, 1627103232, 4, 0,
  114258. _vq_quantlist__44c2_s_p9_0,
  114259. NULL,
  114260. &_vq_auxt__44c2_s_p9_0,
  114261. NULL,
  114262. 0
  114263. };
  114264. static long _vq_quantlist__44c2_s_p9_1[] = {
  114265. 6,
  114266. 5,
  114267. 7,
  114268. 4,
  114269. 8,
  114270. 3,
  114271. 9,
  114272. 2,
  114273. 10,
  114274. 1,
  114275. 11,
  114276. 0,
  114277. 12,
  114278. };
  114279. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114280. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114281. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114282. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114283. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114284. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114285. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114286. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114287. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114288. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114289. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114290. 17,13,12,12,10,13,11,14,14,
  114291. };
  114292. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114293. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114294. 42.5, 59.5, 76.5, 93.5,
  114295. };
  114296. static long _vq_quantmap__44c2_s_p9_1[] = {
  114297. 11, 9, 7, 5, 3, 1, 0, 2,
  114298. 4, 6, 8, 10, 12,
  114299. };
  114300. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114301. _vq_quantthresh__44c2_s_p9_1,
  114302. _vq_quantmap__44c2_s_p9_1,
  114303. 13,
  114304. 13
  114305. };
  114306. static static_codebook _44c2_s_p9_1 = {
  114307. 2, 169,
  114308. _vq_lengthlist__44c2_s_p9_1,
  114309. 1, -522616832, 1620115456, 4, 0,
  114310. _vq_quantlist__44c2_s_p9_1,
  114311. NULL,
  114312. &_vq_auxt__44c2_s_p9_1,
  114313. NULL,
  114314. 0
  114315. };
  114316. static long _vq_quantlist__44c2_s_p9_2[] = {
  114317. 8,
  114318. 7,
  114319. 9,
  114320. 6,
  114321. 10,
  114322. 5,
  114323. 11,
  114324. 4,
  114325. 12,
  114326. 3,
  114327. 13,
  114328. 2,
  114329. 14,
  114330. 1,
  114331. 15,
  114332. 0,
  114333. 16,
  114334. };
  114335. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114336. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114337. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114338. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114339. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114340. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114341. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114342. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114343. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114344. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114345. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114346. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114347. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114348. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114349. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114350. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114351. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114352. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114353. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114354. 10,
  114355. };
  114356. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114357. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114358. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114359. };
  114360. static long _vq_quantmap__44c2_s_p9_2[] = {
  114361. 15, 13, 11, 9, 7, 5, 3, 1,
  114362. 0, 2, 4, 6, 8, 10, 12, 14,
  114363. 16,
  114364. };
  114365. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114366. _vq_quantthresh__44c2_s_p9_2,
  114367. _vq_quantmap__44c2_s_p9_2,
  114368. 17,
  114369. 17
  114370. };
  114371. static static_codebook _44c2_s_p9_2 = {
  114372. 2, 289,
  114373. _vq_lengthlist__44c2_s_p9_2,
  114374. 1, -529530880, 1611661312, 5, 0,
  114375. _vq_quantlist__44c2_s_p9_2,
  114376. NULL,
  114377. &_vq_auxt__44c2_s_p9_2,
  114378. NULL,
  114379. 0
  114380. };
  114381. static long _huff_lengthlist__44c2_s_short[] = {
  114382. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114383. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114384. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114385. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114386. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114387. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114388. 6, 8, 9,12,
  114389. };
  114390. static static_codebook _huff_book__44c2_s_short = {
  114391. 2, 100,
  114392. _huff_lengthlist__44c2_s_short,
  114393. 0, 0, 0, 0, 0,
  114394. NULL,
  114395. NULL,
  114396. NULL,
  114397. NULL,
  114398. 0
  114399. };
  114400. static long _huff_lengthlist__44c3_s_long[] = {
  114401. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114402. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114403. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114404. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114405. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114406. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114407. 9, 8, 8, 8,
  114408. };
  114409. static static_codebook _huff_book__44c3_s_long = {
  114410. 2, 100,
  114411. _huff_lengthlist__44c3_s_long,
  114412. 0, 0, 0, 0, 0,
  114413. NULL,
  114414. NULL,
  114415. NULL,
  114416. NULL,
  114417. 0
  114418. };
  114419. static long _vq_quantlist__44c3_s_p1_0[] = {
  114420. 1,
  114421. 0,
  114422. 2,
  114423. };
  114424. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114425. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114426. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114430. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114431. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114435. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114436. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114471. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114476. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  114481. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114516. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114517. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114521. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114522. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  114523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114526. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114527. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  114528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114835. 0,
  114836. };
  114837. static float _vq_quantthresh__44c3_s_p1_0[] = {
  114838. -0.5, 0.5,
  114839. };
  114840. static long _vq_quantmap__44c3_s_p1_0[] = {
  114841. 1, 0, 2,
  114842. };
  114843. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  114844. _vq_quantthresh__44c3_s_p1_0,
  114845. _vq_quantmap__44c3_s_p1_0,
  114846. 3,
  114847. 3
  114848. };
  114849. static static_codebook _44c3_s_p1_0 = {
  114850. 8, 6561,
  114851. _vq_lengthlist__44c3_s_p1_0,
  114852. 1, -535822336, 1611661312, 2, 0,
  114853. _vq_quantlist__44c3_s_p1_0,
  114854. NULL,
  114855. &_vq_auxt__44c3_s_p1_0,
  114856. NULL,
  114857. 0
  114858. };
  114859. static long _vq_quantlist__44c3_s_p2_0[] = {
  114860. 2,
  114861. 1,
  114862. 3,
  114863. 0,
  114864. 4,
  114865. };
  114866. static long _vq_lengthlist__44c3_s_p2_0[] = {
  114867. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  114868. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  114869. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114870. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  114871. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114876. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  114877. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  114878. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  114879. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114884. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  114885. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  114886. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  114887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114892. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  114893. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  114894. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114906. 0,
  114907. };
  114908. static float _vq_quantthresh__44c3_s_p2_0[] = {
  114909. -1.5, -0.5, 0.5, 1.5,
  114910. };
  114911. static long _vq_quantmap__44c3_s_p2_0[] = {
  114912. 3, 1, 0, 2, 4,
  114913. };
  114914. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  114915. _vq_quantthresh__44c3_s_p2_0,
  114916. _vq_quantmap__44c3_s_p2_0,
  114917. 5,
  114918. 5
  114919. };
  114920. static static_codebook _44c3_s_p2_0 = {
  114921. 4, 625,
  114922. _vq_lengthlist__44c3_s_p2_0,
  114923. 1, -533725184, 1611661312, 3, 0,
  114924. _vq_quantlist__44c3_s_p2_0,
  114925. NULL,
  114926. &_vq_auxt__44c3_s_p2_0,
  114927. NULL,
  114928. 0
  114929. };
  114930. static long _vq_quantlist__44c3_s_p3_0[] = {
  114931. 2,
  114932. 1,
  114933. 3,
  114934. 0,
  114935. 4,
  114936. };
  114937. static long _vq_lengthlist__44c3_s_p3_0[] = {
  114938. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114941. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114944. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114977. 0,
  114978. };
  114979. static float _vq_quantthresh__44c3_s_p3_0[] = {
  114980. -1.5, -0.5, 0.5, 1.5,
  114981. };
  114982. static long _vq_quantmap__44c3_s_p3_0[] = {
  114983. 3, 1, 0, 2, 4,
  114984. };
  114985. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  114986. _vq_quantthresh__44c3_s_p3_0,
  114987. _vq_quantmap__44c3_s_p3_0,
  114988. 5,
  114989. 5
  114990. };
  114991. static static_codebook _44c3_s_p3_0 = {
  114992. 4, 625,
  114993. _vq_lengthlist__44c3_s_p3_0,
  114994. 1, -533725184, 1611661312, 3, 0,
  114995. _vq_quantlist__44c3_s_p3_0,
  114996. NULL,
  114997. &_vq_auxt__44c3_s_p3_0,
  114998. NULL,
  114999. 0
  115000. };
  115001. static long _vq_quantlist__44c3_s_p4_0[] = {
  115002. 4,
  115003. 3,
  115004. 5,
  115005. 2,
  115006. 6,
  115007. 1,
  115008. 7,
  115009. 0,
  115010. 8,
  115011. };
  115012. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115013. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115014. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115015. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115016. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115017. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115018. 0,
  115019. };
  115020. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115021. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115022. };
  115023. static long _vq_quantmap__44c3_s_p4_0[] = {
  115024. 7, 5, 3, 1, 0, 2, 4, 6,
  115025. 8,
  115026. };
  115027. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115028. _vq_quantthresh__44c3_s_p4_0,
  115029. _vq_quantmap__44c3_s_p4_0,
  115030. 9,
  115031. 9
  115032. };
  115033. static static_codebook _44c3_s_p4_0 = {
  115034. 2, 81,
  115035. _vq_lengthlist__44c3_s_p4_0,
  115036. 1, -531628032, 1611661312, 4, 0,
  115037. _vq_quantlist__44c3_s_p4_0,
  115038. NULL,
  115039. &_vq_auxt__44c3_s_p4_0,
  115040. NULL,
  115041. 0
  115042. };
  115043. static long _vq_quantlist__44c3_s_p5_0[] = {
  115044. 4,
  115045. 3,
  115046. 5,
  115047. 2,
  115048. 6,
  115049. 1,
  115050. 7,
  115051. 0,
  115052. 8,
  115053. };
  115054. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115055. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115056. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115057. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115058. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115059. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115060. 11,
  115061. };
  115062. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115063. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115064. };
  115065. static long _vq_quantmap__44c3_s_p5_0[] = {
  115066. 7, 5, 3, 1, 0, 2, 4, 6,
  115067. 8,
  115068. };
  115069. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115070. _vq_quantthresh__44c3_s_p5_0,
  115071. _vq_quantmap__44c3_s_p5_0,
  115072. 9,
  115073. 9
  115074. };
  115075. static static_codebook _44c3_s_p5_0 = {
  115076. 2, 81,
  115077. _vq_lengthlist__44c3_s_p5_0,
  115078. 1, -531628032, 1611661312, 4, 0,
  115079. _vq_quantlist__44c3_s_p5_0,
  115080. NULL,
  115081. &_vq_auxt__44c3_s_p5_0,
  115082. NULL,
  115083. 0
  115084. };
  115085. static long _vq_quantlist__44c3_s_p6_0[] = {
  115086. 8,
  115087. 7,
  115088. 9,
  115089. 6,
  115090. 10,
  115091. 5,
  115092. 11,
  115093. 4,
  115094. 12,
  115095. 3,
  115096. 13,
  115097. 2,
  115098. 14,
  115099. 1,
  115100. 15,
  115101. 0,
  115102. 16,
  115103. };
  115104. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115105. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115106. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115107. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115108. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115109. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115110. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115111. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115112. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115113. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115114. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115115. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115116. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115117. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115118. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115119. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115120. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115121. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115122. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115123. 13,
  115124. };
  115125. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115126. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115127. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115128. };
  115129. static long _vq_quantmap__44c3_s_p6_0[] = {
  115130. 15, 13, 11, 9, 7, 5, 3, 1,
  115131. 0, 2, 4, 6, 8, 10, 12, 14,
  115132. 16,
  115133. };
  115134. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115135. _vq_quantthresh__44c3_s_p6_0,
  115136. _vq_quantmap__44c3_s_p6_0,
  115137. 17,
  115138. 17
  115139. };
  115140. static static_codebook _44c3_s_p6_0 = {
  115141. 2, 289,
  115142. _vq_lengthlist__44c3_s_p6_0,
  115143. 1, -529530880, 1611661312, 5, 0,
  115144. _vq_quantlist__44c3_s_p6_0,
  115145. NULL,
  115146. &_vq_auxt__44c3_s_p6_0,
  115147. NULL,
  115148. 0
  115149. };
  115150. static long _vq_quantlist__44c3_s_p7_0[] = {
  115151. 1,
  115152. 0,
  115153. 2,
  115154. };
  115155. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115156. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115157. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115158. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115159. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115160. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115161. 10,
  115162. };
  115163. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115164. -5.5, 5.5,
  115165. };
  115166. static long _vq_quantmap__44c3_s_p7_0[] = {
  115167. 1, 0, 2,
  115168. };
  115169. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115170. _vq_quantthresh__44c3_s_p7_0,
  115171. _vq_quantmap__44c3_s_p7_0,
  115172. 3,
  115173. 3
  115174. };
  115175. static static_codebook _44c3_s_p7_0 = {
  115176. 4, 81,
  115177. _vq_lengthlist__44c3_s_p7_0,
  115178. 1, -529137664, 1618345984, 2, 0,
  115179. _vq_quantlist__44c3_s_p7_0,
  115180. NULL,
  115181. &_vq_auxt__44c3_s_p7_0,
  115182. NULL,
  115183. 0
  115184. };
  115185. static long _vq_quantlist__44c3_s_p7_1[] = {
  115186. 5,
  115187. 4,
  115188. 6,
  115189. 3,
  115190. 7,
  115191. 2,
  115192. 8,
  115193. 1,
  115194. 9,
  115195. 0,
  115196. 10,
  115197. };
  115198. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115199. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115200. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115201. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115202. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115203. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115204. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115205. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115206. 10,10,10, 8, 8, 8, 8, 8, 8,
  115207. };
  115208. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115209. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115210. 3.5, 4.5,
  115211. };
  115212. static long _vq_quantmap__44c3_s_p7_1[] = {
  115213. 9, 7, 5, 3, 1, 0, 2, 4,
  115214. 6, 8, 10,
  115215. };
  115216. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115217. _vq_quantthresh__44c3_s_p7_1,
  115218. _vq_quantmap__44c3_s_p7_1,
  115219. 11,
  115220. 11
  115221. };
  115222. static static_codebook _44c3_s_p7_1 = {
  115223. 2, 121,
  115224. _vq_lengthlist__44c3_s_p7_1,
  115225. 1, -531365888, 1611661312, 4, 0,
  115226. _vq_quantlist__44c3_s_p7_1,
  115227. NULL,
  115228. &_vq_auxt__44c3_s_p7_1,
  115229. NULL,
  115230. 0
  115231. };
  115232. static long _vq_quantlist__44c3_s_p8_0[] = {
  115233. 6,
  115234. 5,
  115235. 7,
  115236. 4,
  115237. 8,
  115238. 3,
  115239. 9,
  115240. 2,
  115241. 10,
  115242. 1,
  115243. 11,
  115244. 0,
  115245. 12,
  115246. };
  115247. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115248. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115249. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115250. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115251. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115252. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115253. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115254. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115255. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115256. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115257. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115258. 0,13,13,12,12,13,12,14,13,
  115259. };
  115260. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115261. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115262. 12.5, 17.5, 22.5, 27.5,
  115263. };
  115264. static long _vq_quantmap__44c3_s_p8_0[] = {
  115265. 11, 9, 7, 5, 3, 1, 0, 2,
  115266. 4, 6, 8, 10, 12,
  115267. };
  115268. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115269. _vq_quantthresh__44c3_s_p8_0,
  115270. _vq_quantmap__44c3_s_p8_0,
  115271. 13,
  115272. 13
  115273. };
  115274. static static_codebook _44c3_s_p8_0 = {
  115275. 2, 169,
  115276. _vq_lengthlist__44c3_s_p8_0,
  115277. 1, -526516224, 1616117760, 4, 0,
  115278. _vq_quantlist__44c3_s_p8_0,
  115279. NULL,
  115280. &_vq_auxt__44c3_s_p8_0,
  115281. NULL,
  115282. 0
  115283. };
  115284. static long _vq_quantlist__44c3_s_p8_1[] = {
  115285. 2,
  115286. 1,
  115287. 3,
  115288. 0,
  115289. 4,
  115290. };
  115291. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115292. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115293. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115294. };
  115295. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115296. -1.5, -0.5, 0.5, 1.5,
  115297. };
  115298. static long _vq_quantmap__44c3_s_p8_1[] = {
  115299. 3, 1, 0, 2, 4,
  115300. };
  115301. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115302. _vq_quantthresh__44c3_s_p8_1,
  115303. _vq_quantmap__44c3_s_p8_1,
  115304. 5,
  115305. 5
  115306. };
  115307. static static_codebook _44c3_s_p8_1 = {
  115308. 2, 25,
  115309. _vq_lengthlist__44c3_s_p8_1,
  115310. 1, -533725184, 1611661312, 3, 0,
  115311. _vq_quantlist__44c3_s_p8_1,
  115312. NULL,
  115313. &_vq_auxt__44c3_s_p8_1,
  115314. NULL,
  115315. 0
  115316. };
  115317. static long _vq_quantlist__44c3_s_p9_0[] = {
  115318. 6,
  115319. 5,
  115320. 7,
  115321. 4,
  115322. 8,
  115323. 3,
  115324. 9,
  115325. 2,
  115326. 10,
  115327. 1,
  115328. 11,
  115329. 0,
  115330. 12,
  115331. };
  115332. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115333. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115334. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115335. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115336. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115337. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115338. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115339. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115340. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115341. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115342. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115343. 11,11,11,11,11,11,11,11,11,
  115344. };
  115345. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115346. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115347. 637.5, 892.5, 1147.5, 1402.5,
  115348. };
  115349. static long _vq_quantmap__44c3_s_p9_0[] = {
  115350. 11, 9, 7, 5, 3, 1, 0, 2,
  115351. 4, 6, 8, 10, 12,
  115352. };
  115353. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115354. _vq_quantthresh__44c3_s_p9_0,
  115355. _vq_quantmap__44c3_s_p9_0,
  115356. 13,
  115357. 13
  115358. };
  115359. static static_codebook _44c3_s_p9_0 = {
  115360. 2, 169,
  115361. _vq_lengthlist__44c3_s_p9_0,
  115362. 1, -514332672, 1627381760, 4, 0,
  115363. _vq_quantlist__44c3_s_p9_0,
  115364. NULL,
  115365. &_vq_auxt__44c3_s_p9_0,
  115366. NULL,
  115367. 0
  115368. };
  115369. static long _vq_quantlist__44c3_s_p9_1[] = {
  115370. 7,
  115371. 6,
  115372. 8,
  115373. 5,
  115374. 9,
  115375. 4,
  115376. 10,
  115377. 3,
  115378. 11,
  115379. 2,
  115380. 12,
  115381. 1,
  115382. 13,
  115383. 0,
  115384. 14,
  115385. };
  115386. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115387. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115388. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115389. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115390. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115391. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115392. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115393. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115394. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115395. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115396. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115397. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115398. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115399. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115400. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115401. 15,
  115402. };
  115403. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115404. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115405. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115406. };
  115407. static long _vq_quantmap__44c3_s_p9_1[] = {
  115408. 13, 11, 9, 7, 5, 3, 1, 0,
  115409. 2, 4, 6, 8, 10, 12, 14,
  115410. };
  115411. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115412. _vq_quantthresh__44c3_s_p9_1,
  115413. _vq_quantmap__44c3_s_p9_1,
  115414. 15,
  115415. 15
  115416. };
  115417. static static_codebook _44c3_s_p9_1 = {
  115418. 2, 225,
  115419. _vq_lengthlist__44c3_s_p9_1,
  115420. 1, -522338304, 1620115456, 4, 0,
  115421. _vq_quantlist__44c3_s_p9_1,
  115422. NULL,
  115423. &_vq_auxt__44c3_s_p9_1,
  115424. NULL,
  115425. 0
  115426. };
  115427. static long _vq_quantlist__44c3_s_p9_2[] = {
  115428. 8,
  115429. 7,
  115430. 9,
  115431. 6,
  115432. 10,
  115433. 5,
  115434. 11,
  115435. 4,
  115436. 12,
  115437. 3,
  115438. 13,
  115439. 2,
  115440. 14,
  115441. 1,
  115442. 15,
  115443. 0,
  115444. 16,
  115445. };
  115446. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115447. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115448. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115449. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115450. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115451. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115452. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115453. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115454. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115455. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115456. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115457. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115458. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115459. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115460. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115461. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115462. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115463. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115464. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115465. 10,
  115466. };
  115467. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115468. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115469. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115470. };
  115471. static long _vq_quantmap__44c3_s_p9_2[] = {
  115472. 15, 13, 11, 9, 7, 5, 3, 1,
  115473. 0, 2, 4, 6, 8, 10, 12, 14,
  115474. 16,
  115475. };
  115476. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115477. _vq_quantthresh__44c3_s_p9_2,
  115478. _vq_quantmap__44c3_s_p9_2,
  115479. 17,
  115480. 17
  115481. };
  115482. static static_codebook _44c3_s_p9_2 = {
  115483. 2, 289,
  115484. _vq_lengthlist__44c3_s_p9_2,
  115485. 1, -529530880, 1611661312, 5, 0,
  115486. _vq_quantlist__44c3_s_p9_2,
  115487. NULL,
  115488. &_vq_auxt__44c3_s_p9_2,
  115489. NULL,
  115490. 0
  115491. };
  115492. static long _huff_lengthlist__44c3_s_short[] = {
  115493. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115494. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115495. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115496. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115497. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115498. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115499. 6, 8, 9,11,
  115500. };
  115501. static static_codebook _huff_book__44c3_s_short = {
  115502. 2, 100,
  115503. _huff_lengthlist__44c3_s_short,
  115504. 0, 0, 0, 0, 0,
  115505. NULL,
  115506. NULL,
  115507. NULL,
  115508. NULL,
  115509. 0
  115510. };
  115511. static long _huff_lengthlist__44c4_s_long[] = {
  115512. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115513. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115514. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115515. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115516. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115517. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115518. 9, 8, 7, 7,
  115519. };
  115520. static static_codebook _huff_book__44c4_s_long = {
  115521. 2, 100,
  115522. _huff_lengthlist__44c4_s_long,
  115523. 0, 0, 0, 0, 0,
  115524. NULL,
  115525. NULL,
  115526. NULL,
  115527. NULL,
  115528. 0
  115529. };
  115530. static long _vq_quantlist__44c4_s_p1_0[] = {
  115531. 1,
  115532. 0,
  115533. 2,
  115534. };
  115535. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115536. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115537. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115541. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115542. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115546. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115547. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115582. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115587. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115592. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115627. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115628. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115632. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115633. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115637. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115638. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115946. 0,
  115947. };
  115948. static float _vq_quantthresh__44c4_s_p1_0[] = {
  115949. -0.5, 0.5,
  115950. };
  115951. static long _vq_quantmap__44c4_s_p1_0[] = {
  115952. 1, 0, 2,
  115953. };
  115954. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  115955. _vq_quantthresh__44c4_s_p1_0,
  115956. _vq_quantmap__44c4_s_p1_0,
  115957. 3,
  115958. 3
  115959. };
  115960. static static_codebook _44c4_s_p1_0 = {
  115961. 8, 6561,
  115962. _vq_lengthlist__44c4_s_p1_0,
  115963. 1, -535822336, 1611661312, 2, 0,
  115964. _vq_quantlist__44c4_s_p1_0,
  115965. NULL,
  115966. &_vq_auxt__44c4_s_p1_0,
  115967. NULL,
  115968. 0
  115969. };
  115970. static long _vq_quantlist__44c4_s_p2_0[] = {
  115971. 2,
  115972. 1,
  115973. 3,
  115974. 0,
  115975. 4,
  115976. };
  115977. static long _vq_lengthlist__44c4_s_p2_0[] = {
  115978. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115979. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115980. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115981. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115982. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115987. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  115988. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115989. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115990. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115995. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115996. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115997. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116003. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116004. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116005. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116017. 0,
  116018. };
  116019. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116020. -1.5, -0.5, 0.5, 1.5,
  116021. };
  116022. static long _vq_quantmap__44c4_s_p2_0[] = {
  116023. 3, 1, 0, 2, 4,
  116024. };
  116025. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116026. _vq_quantthresh__44c4_s_p2_0,
  116027. _vq_quantmap__44c4_s_p2_0,
  116028. 5,
  116029. 5
  116030. };
  116031. static static_codebook _44c4_s_p2_0 = {
  116032. 4, 625,
  116033. _vq_lengthlist__44c4_s_p2_0,
  116034. 1, -533725184, 1611661312, 3, 0,
  116035. _vq_quantlist__44c4_s_p2_0,
  116036. NULL,
  116037. &_vq_auxt__44c4_s_p2_0,
  116038. NULL,
  116039. 0
  116040. };
  116041. static long _vq_quantlist__44c4_s_p3_0[] = {
  116042. 2,
  116043. 1,
  116044. 3,
  116045. 0,
  116046. 4,
  116047. };
  116048. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116049. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116052. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116055. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116088. 0,
  116089. };
  116090. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116091. -1.5, -0.5, 0.5, 1.5,
  116092. };
  116093. static long _vq_quantmap__44c4_s_p3_0[] = {
  116094. 3, 1, 0, 2, 4,
  116095. };
  116096. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116097. _vq_quantthresh__44c4_s_p3_0,
  116098. _vq_quantmap__44c4_s_p3_0,
  116099. 5,
  116100. 5
  116101. };
  116102. static static_codebook _44c4_s_p3_0 = {
  116103. 4, 625,
  116104. _vq_lengthlist__44c4_s_p3_0,
  116105. 1, -533725184, 1611661312, 3, 0,
  116106. _vq_quantlist__44c4_s_p3_0,
  116107. NULL,
  116108. &_vq_auxt__44c4_s_p3_0,
  116109. NULL,
  116110. 0
  116111. };
  116112. static long _vq_quantlist__44c4_s_p4_0[] = {
  116113. 4,
  116114. 3,
  116115. 5,
  116116. 2,
  116117. 6,
  116118. 1,
  116119. 7,
  116120. 0,
  116121. 8,
  116122. };
  116123. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116124. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116125. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116126. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116127. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116128. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116129. 0,
  116130. };
  116131. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116132. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116133. };
  116134. static long _vq_quantmap__44c4_s_p4_0[] = {
  116135. 7, 5, 3, 1, 0, 2, 4, 6,
  116136. 8,
  116137. };
  116138. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116139. _vq_quantthresh__44c4_s_p4_0,
  116140. _vq_quantmap__44c4_s_p4_0,
  116141. 9,
  116142. 9
  116143. };
  116144. static static_codebook _44c4_s_p4_0 = {
  116145. 2, 81,
  116146. _vq_lengthlist__44c4_s_p4_0,
  116147. 1, -531628032, 1611661312, 4, 0,
  116148. _vq_quantlist__44c4_s_p4_0,
  116149. NULL,
  116150. &_vq_auxt__44c4_s_p4_0,
  116151. NULL,
  116152. 0
  116153. };
  116154. static long _vq_quantlist__44c4_s_p5_0[] = {
  116155. 4,
  116156. 3,
  116157. 5,
  116158. 2,
  116159. 6,
  116160. 1,
  116161. 7,
  116162. 0,
  116163. 8,
  116164. };
  116165. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116166. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116167. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116168. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116169. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116170. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116171. 10,
  116172. };
  116173. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116174. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116175. };
  116176. static long _vq_quantmap__44c4_s_p5_0[] = {
  116177. 7, 5, 3, 1, 0, 2, 4, 6,
  116178. 8,
  116179. };
  116180. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116181. _vq_quantthresh__44c4_s_p5_0,
  116182. _vq_quantmap__44c4_s_p5_0,
  116183. 9,
  116184. 9
  116185. };
  116186. static static_codebook _44c4_s_p5_0 = {
  116187. 2, 81,
  116188. _vq_lengthlist__44c4_s_p5_0,
  116189. 1, -531628032, 1611661312, 4, 0,
  116190. _vq_quantlist__44c4_s_p5_0,
  116191. NULL,
  116192. &_vq_auxt__44c4_s_p5_0,
  116193. NULL,
  116194. 0
  116195. };
  116196. static long _vq_quantlist__44c4_s_p6_0[] = {
  116197. 8,
  116198. 7,
  116199. 9,
  116200. 6,
  116201. 10,
  116202. 5,
  116203. 11,
  116204. 4,
  116205. 12,
  116206. 3,
  116207. 13,
  116208. 2,
  116209. 14,
  116210. 1,
  116211. 15,
  116212. 0,
  116213. 16,
  116214. };
  116215. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116216. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116217. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116218. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116219. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116220. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116221. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116222. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116223. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116224. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116225. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116226. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116227. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116228. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116229. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116230. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116231. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116232. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116233. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116234. 13,
  116235. };
  116236. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116237. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116238. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116239. };
  116240. static long _vq_quantmap__44c4_s_p6_0[] = {
  116241. 15, 13, 11, 9, 7, 5, 3, 1,
  116242. 0, 2, 4, 6, 8, 10, 12, 14,
  116243. 16,
  116244. };
  116245. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116246. _vq_quantthresh__44c4_s_p6_0,
  116247. _vq_quantmap__44c4_s_p6_0,
  116248. 17,
  116249. 17
  116250. };
  116251. static static_codebook _44c4_s_p6_0 = {
  116252. 2, 289,
  116253. _vq_lengthlist__44c4_s_p6_0,
  116254. 1, -529530880, 1611661312, 5, 0,
  116255. _vq_quantlist__44c4_s_p6_0,
  116256. NULL,
  116257. &_vq_auxt__44c4_s_p6_0,
  116258. NULL,
  116259. 0
  116260. };
  116261. static long _vq_quantlist__44c4_s_p7_0[] = {
  116262. 1,
  116263. 0,
  116264. 2,
  116265. };
  116266. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116267. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116268. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116269. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116270. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116271. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116272. 10,
  116273. };
  116274. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116275. -5.5, 5.5,
  116276. };
  116277. static long _vq_quantmap__44c4_s_p7_0[] = {
  116278. 1, 0, 2,
  116279. };
  116280. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116281. _vq_quantthresh__44c4_s_p7_0,
  116282. _vq_quantmap__44c4_s_p7_0,
  116283. 3,
  116284. 3
  116285. };
  116286. static static_codebook _44c4_s_p7_0 = {
  116287. 4, 81,
  116288. _vq_lengthlist__44c4_s_p7_0,
  116289. 1, -529137664, 1618345984, 2, 0,
  116290. _vq_quantlist__44c4_s_p7_0,
  116291. NULL,
  116292. &_vq_auxt__44c4_s_p7_0,
  116293. NULL,
  116294. 0
  116295. };
  116296. static long _vq_quantlist__44c4_s_p7_1[] = {
  116297. 5,
  116298. 4,
  116299. 6,
  116300. 3,
  116301. 7,
  116302. 2,
  116303. 8,
  116304. 1,
  116305. 9,
  116306. 0,
  116307. 10,
  116308. };
  116309. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116310. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116311. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116312. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116313. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116314. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116315. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116316. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116317. 10,10,10, 8, 8, 8, 8, 9, 9,
  116318. };
  116319. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116320. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116321. 3.5, 4.5,
  116322. };
  116323. static long _vq_quantmap__44c4_s_p7_1[] = {
  116324. 9, 7, 5, 3, 1, 0, 2, 4,
  116325. 6, 8, 10,
  116326. };
  116327. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116328. _vq_quantthresh__44c4_s_p7_1,
  116329. _vq_quantmap__44c4_s_p7_1,
  116330. 11,
  116331. 11
  116332. };
  116333. static static_codebook _44c4_s_p7_1 = {
  116334. 2, 121,
  116335. _vq_lengthlist__44c4_s_p7_1,
  116336. 1, -531365888, 1611661312, 4, 0,
  116337. _vq_quantlist__44c4_s_p7_1,
  116338. NULL,
  116339. &_vq_auxt__44c4_s_p7_1,
  116340. NULL,
  116341. 0
  116342. };
  116343. static long _vq_quantlist__44c4_s_p8_0[] = {
  116344. 6,
  116345. 5,
  116346. 7,
  116347. 4,
  116348. 8,
  116349. 3,
  116350. 9,
  116351. 2,
  116352. 10,
  116353. 1,
  116354. 11,
  116355. 0,
  116356. 12,
  116357. };
  116358. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116359. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116360. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116361. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116362. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116363. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116364. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116365. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116366. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116367. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116368. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116369. 0,13,12,12,12,12,12,13,13,
  116370. };
  116371. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116372. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116373. 12.5, 17.5, 22.5, 27.5,
  116374. };
  116375. static long _vq_quantmap__44c4_s_p8_0[] = {
  116376. 11, 9, 7, 5, 3, 1, 0, 2,
  116377. 4, 6, 8, 10, 12,
  116378. };
  116379. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116380. _vq_quantthresh__44c4_s_p8_0,
  116381. _vq_quantmap__44c4_s_p8_0,
  116382. 13,
  116383. 13
  116384. };
  116385. static static_codebook _44c4_s_p8_0 = {
  116386. 2, 169,
  116387. _vq_lengthlist__44c4_s_p8_0,
  116388. 1, -526516224, 1616117760, 4, 0,
  116389. _vq_quantlist__44c4_s_p8_0,
  116390. NULL,
  116391. &_vq_auxt__44c4_s_p8_0,
  116392. NULL,
  116393. 0
  116394. };
  116395. static long _vq_quantlist__44c4_s_p8_1[] = {
  116396. 2,
  116397. 1,
  116398. 3,
  116399. 0,
  116400. 4,
  116401. };
  116402. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116403. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116404. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116405. };
  116406. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116407. -1.5, -0.5, 0.5, 1.5,
  116408. };
  116409. static long _vq_quantmap__44c4_s_p8_1[] = {
  116410. 3, 1, 0, 2, 4,
  116411. };
  116412. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116413. _vq_quantthresh__44c4_s_p8_1,
  116414. _vq_quantmap__44c4_s_p8_1,
  116415. 5,
  116416. 5
  116417. };
  116418. static static_codebook _44c4_s_p8_1 = {
  116419. 2, 25,
  116420. _vq_lengthlist__44c4_s_p8_1,
  116421. 1, -533725184, 1611661312, 3, 0,
  116422. _vq_quantlist__44c4_s_p8_1,
  116423. NULL,
  116424. &_vq_auxt__44c4_s_p8_1,
  116425. NULL,
  116426. 0
  116427. };
  116428. static long _vq_quantlist__44c4_s_p9_0[] = {
  116429. 6,
  116430. 5,
  116431. 7,
  116432. 4,
  116433. 8,
  116434. 3,
  116435. 9,
  116436. 2,
  116437. 10,
  116438. 1,
  116439. 11,
  116440. 0,
  116441. 12,
  116442. };
  116443. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116444. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116445. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116446. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116447. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116448. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116449. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116450. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116451. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116452. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116453. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116454. 12,12,12,12,12,12,12,12,12,
  116455. };
  116456. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116457. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116458. 787.5, 1102.5, 1417.5, 1732.5,
  116459. };
  116460. static long _vq_quantmap__44c4_s_p9_0[] = {
  116461. 11, 9, 7, 5, 3, 1, 0, 2,
  116462. 4, 6, 8, 10, 12,
  116463. };
  116464. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116465. _vq_quantthresh__44c4_s_p9_0,
  116466. _vq_quantmap__44c4_s_p9_0,
  116467. 13,
  116468. 13
  116469. };
  116470. static static_codebook _44c4_s_p9_0 = {
  116471. 2, 169,
  116472. _vq_lengthlist__44c4_s_p9_0,
  116473. 1, -513964032, 1628680192, 4, 0,
  116474. _vq_quantlist__44c4_s_p9_0,
  116475. NULL,
  116476. &_vq_auxt__44c4_s_p9_0,
  116477. NULL,
  116478. 0
  116479. };
  116480. static long _vq_quantlist__44c4_s_p9_1[] = {
  116481. 7,
  116482. 6,
  116483. 8,
  116484. 5,
  116485. 9,
  116486. 4,
  116487. 10,
  116488. 3,
  116489. 11,
  116490. 2,
  116491. 12,
  116492. 1,
  116493. 13,
  116494. 0,
  116495. 14,
  116496. };
  116497. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116498. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116499. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116500. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116501. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116502. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116503. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116504. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116505. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116506. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116507. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116508. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116509. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116510. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116511. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116512. 15,
  116513. };
  116514. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116515. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116516. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116517. };
  116518. static long _vq_quantmap__44c4_s_p9_1[] = {
  116519. 13, 11, 9, 7, 5, 3, 1, 0,
  116520. 2, 4, 6, 8, 10, 12, 14,
  116521. };
  116522. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116523. _vq_quantthresh__44c4_s_p9_1,
  116524. _vq_quantmap__44c4_s_p9_1,
  116525. 15,
  116526. 15
  116527. };
  116528. static static_codebook _44c4_s_p9_1 = {
  116529. 2, 225,
  116530. _vq_lengthlist__44c4_s_p9_1,
  116531. 1, -520986624, 1620377600, 4, 0,
  116532. _vq_quantlist__44c4_s_p9_1,
  116533. NULL,
  116534. &_vq_auxt__44c4_s_p9_1,
  116535. NULL,
  116536. 0
  116537. };
  116538. static long _vq_quantlist__44c4_s_p9_2[] = {
  116539. 10,
  116540. 9,
  116541. 11,
  116542. 8,
  116543. 12,
  116544. 7,
  116545. 13,
  116546. 6,
  116547. 14,
  116548. 5,
  116549. 15,
  116550. 4,
  116551. 16,
  116552. 3,
  116553. 17,
  116554. 2,
  116555. 18,
  116556. 1,
  116557. 19,
  116558. 0,
  116559. 20,
  116560. };
  116561. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116562. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116563. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116564. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116565. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116566. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116567. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116568. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116569. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116570. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116571. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116572. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116573. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116574. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116575. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116576. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116577. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116578. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116579. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116580. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116581. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116582. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116583. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116584. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116585. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116586. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116587. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116588. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116589. 10,10,10,10,10,10,10,10,10,
  116590. };
  116591. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116592. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116593. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116594. 6.5, 7.5, 8.5, 9.5,
  116595. };
  116596. static long _vq_quantmap__44c4_s_p9_2[] = {
  116597. 19, 17, 15, 13, 11, 9, 7, 5,
  116598. 3, 1, 0, 2, 4, 6, 8, 10,
  116599. 12, 14, 16, 18, 20,
  116600. };
  116601. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116602. _vq_quantthresh__44c4_s_p9_2,
  116603. _vq_quantmap__44c4_s_p9_2,
  116604. 21,
  116605. 21
  116606. };
  116607. static static_codebook _44c4_s_p9_2 = {
  116608. 2, 441,
  116609. _vq_lengthlist__44c4_s_p9_2,
  116610. 1, -529268736, 1611661312, 5, 0,
  116611. _vq_quantlist__44c4_s_p9_2,
  116612. NULL,
  116613. &_vq_auxt__44c4_s_p9_2,
  116614. NULL,
  116615. 0
  116616. };
  116617. static long _huff_lengthlist__44c4_s_short[] = {
  116618. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116619. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116620. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116621. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116622. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116623. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116624. 7, 9,12,17,
  116625. };
  116626. static static_codebook _huff_book__44c4_s_short = {
  116627. 2, 100,
  116628. _huff_lengthlist__44c4_s_short,
  116629. 0, 0, 0, 0, 0,
  116630. NULL,
  116631. NULL,
  116632. NULL,
  116633. NULL,
  116634. 0
  116635. };
  116636. static long _huff_lengthlist__44c5_s_long[] = {
  116637. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116638. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116639. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116640. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116641. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116642. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116643. 9, 8, 7, 7,
  116644. };
  116645. static static_codebook _huff_book__44c5_s_long = {
  116646. 2, 100,
  116647. _huff_lengthlist__44c5_s_long,
  116648. 0, 0, 0, 0, 0,
  116649. NULL,
  116650. NULL,
  116651. NULL,
  116652. NULL,
  116653. 0
  116654. };
  116655. static long _vq_quantlist__44c5_s_p1_0[] = {
  116656. 1,
  116657. 0,
  116658. 2,
  116659. };
  116660. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116661. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116662. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116666. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116667. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116671. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116672. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116707. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116712. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  116713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116717. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  116718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116752. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116753. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116757. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116758. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  116759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116762. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116763. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  116764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117071. 0,
  117072. };
  117073. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117074. -0.5, 0.5,
  117075. };
  117076. static long _vq_quantmap__44c5_s_p1_0[] = {
  117077. 1, 0, 2,
  117078. };
  117079. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117080. _vq_quantthresh__44c5_s_p1_0,
  117081. _vq_quantmap__44c5_s_p1_0,
  117082. 3,
  117083. 3
  117084. };
  117085. static static_codebook _44c5_s_p1_0 = {
  117086. 8, 6561,
  117087. _vq_lengthlist__44c5_s_p1_0,
  117088. 1, -535822336, 1611661312, 2, 0,
  117089. _vq_quantlist__44c5_s_p1_0,
  117090. NULL,
  117091. &_vq_auxt__44c5_s_p1_0,
  117092. NULL,
  117093. 0
  117094. };
  117095. static long _vq_quantlist__44c5_s_p2_0[] = {
  117096. 2,
  117097. 1,
  117098. 3,
  117099. 0,
  117100. 4,
  117101. };
  117102. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117103. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117104. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117105. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117106. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117107. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117112. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117113. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117114. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117115. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117120. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117121. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117122. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117128. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117129. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117130. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117142. 0,
  117143. };
  117144. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117145. -1.5, -0.5, 0.5, 1.5,
  117146. };
  117147. static long _vq_quantmap__44c5_s_p2_0[] = {
  117148. 3, 1, 0, 2, 4,
  117149. };
  117150. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117151. _vq_quantthresh__44c5_s_p2_0,
  117152. _vq_quantmap__44c5_s_p2_0,
  117153. 5,
  117154. 5
  117155. };
  117156. static static_codebook _44c5_s_p2_0 = {
  117157. 4, 625,
  117158. _vq_lengthlist__44c5_s_p2_0,
  117159. 1, -533725184, 1611661312, 3, 0,
  117160. _vq_quantlist__44c5_s_p2_0,
  117161. NULL,
  117162. &_vq_auxt__44c5_s_p2_0,
  117163. NULL,
  117164. 0
  117165. };
  117166. static long _vq_quantlist__44c5_s_p3_0[] = {
  117167. 2,
  117168. 1,
  117169. 3,
  117170. 0,
  117171. 4,
  117172. };
  117173. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117174. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117177. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117180. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117213. 0,
  117214. };
  117215. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117216. -1.5, -0.5, 0.5, 1.5,
  117217. };
  117218. static long _vq_quantmap__44c5_s_p3_0[] = {
  117219. 3, 1, 0, 2, 4,
  117220. };
  117221. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117222. _vq_quantthresh__44c5_s_p3_0,
  117223. _vq_quantmap__44c5_s_p3_0,
  117224. 5,
  117225. 5
  117226. };
  117227. static static_codebook _44c5_s_p3_0 = {
  117228. 4, 625,
  117229. _vq_lengthlist__44c5_s_p3_0,
  117230. 1, -533725184, 1611661312, 3, 0,
  117231. _vq_quantlist__44c5_s_p3_0,
  117232. NULL,
  117233. &_vq_auxt__44c5_s_p3_0,
  117234. NULL,
  117235. 0
  117236. };
  117237. static long _vq_quantlist__44c5_s_p4_0[] = {
  117238. 4,
  117239. 3,
  117240. 5,
  117241. 2,
  117242. 6,
  117243. 1,
  117244. 7,
  117245. 0,
  117246. 8,
  117247. };
  117248. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117249. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117250. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117251. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117252. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117253. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117254. 0,
  117255. };
  117256. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117257. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117258. };
  117259. static long _vq_quantmap__44c5_s_p4_0[] = {
  117260. 7, 5, 3, 1, 0, 2, 4, 6,
  117261. 8,
  117262. };
  117263. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117264. _vq_quantthresh__44c5_s_p4_0,
  117265. _vq_quantmap__44c5_s_p4_0,
  117266. 9,
  117267. 9
  117268. };
  117269. static static_codebook _44c5_s_p4_0 = {
  117270. 2, 81,
  117271. _vq_lengthlist__44c5_s_p4_0,
  117272. 1, -531628032, 1611661312, 4, 0,
  117273. _vq_quantlist__44c5_s_p4_0,
  117274. NULL,
  117275. &_vq_auxt__44c5_s_p4_0,
  117276. NULL,
  117277. 0
  117278. };
  117279. static long _vq_quantlist__44c5_s_p5_0[] = {
  117280. 4,
  117281. 3,
  117282. 5,
  117283. 2,
  117284. 6,
  117285. 1,
  117286. 7,
  117287. 0,
  117288. 8,
  117289. };
  117290. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117291. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117292. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117293. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117294. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117295. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117296. 10,
  117297. };
  117298. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117299. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117300. };
  117301. static long _vq_quantmap__44c5_s_p5_0[] = {
  117302. 7, 5, 3, 1, 0, 2, 4, 6,
  117303. 8,
  117304. };
  117305. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117306. _vq_quantthresh__44c5_s_p5_0,
  117307. _vq_quantmap__44c5_s_p5_0,
  117308. 9,
  117309. 9
  117310. };
  117311. static static_codebook _44c5_s_p5_0 = {
  117312. 2, 81,
  117313. _vq_lengthlist__44c5_s_p5_0,
  117314. 1, -531628032, 1611661312, 4, 0,
  117315. _vq_quantlist__44c5_s_p5_0,
  117316. NULL,
  117317. &_vq_auxt__44c5_s_p5_0,
  117318. NULL,
  117319. 0
  117320. };
  117321. static long _vq_quantlist__44c5_s_p6_0[] = {
  117322. 8,
  117323. 7,
  117324. 9,
  117325. 6,
  117326. 10,
  117327. 5,
  117328. 11,
  117329. 4,
  117330. 12,
  117331. 3,
  117332. 13,
  117333. 2,
  117334. 14,
  117335. 1,
  117336. 15,
  117337. 0,
  117338. 16,
  117339. };
  117340. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117341. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117342. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117343. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117344. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117345. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117346. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117347. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117348. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117349. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117350. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117351. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117352. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117353. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117354. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117355. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117356. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117357. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117358. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117359. 13,
  117360. };
  117361. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117362. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117363. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117364. };
  117365. static long _vq_quantmap__44c5_s_p6_0[] = {
  117366. 15, 13, 11, 9, 7, 5, 3, 1,
  117367. 0, 2, 4, 6, 8, 10, 12, 14,
  117368. 16,
  117369. };
  117370. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117371. _vq_quantthresh__44c5_s_p6_0,
  117372. _vq_quantmap__44c5_s_p6_0,
  117373. 17,
  117374. 17
  117375. };
  117376. static static_codebook _44c5_s_p6_0 = {
  117377. 2, 289,
  117378. _vq_lengthlist__44c5_s_p6_0,
  117379. 1, -529530880, 1611661312, 5, 0,
  117380. _vq_quantlist__44c5_s_p6_0,
  117381. NULL,
  117382. &_vq_auxt__44c5_s_p6_0,
  117383. NULL,
  117384. 0
  117385. };
  117386. static long _vq_quantlist__44c5_s_p7_0[] = {
  117387. 1,
  117388. 0,
  117389. 2,
  117390. };
  117391. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117392. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117393. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117394. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117395. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117396. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117397. 10,
  117398. };
  117399. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117400. -5.5, 5.5,
  117401. };
  117402. static long _vq_quantmap__44c5_s_p7_0[] = {
  117403. 1, 0, 2,
  117404. };
  117405. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117406. _vq_quantthresh__44c5_s_p7_0,
  117407. _vq_quantmap__44c5_s_p7_0,
  117408. 3,
  117409. 3
  117410. };
  117411. static static_codebook _44c5_s_p7_0 = {
  117412. 4, 81,
  117413. _vq_lengthlist__44c5_s_p7_0,
  117414. 1, -529137664, 1618345984, 2, 0,
  117415. _vq_quantlist__44c5_s_p7_0,
  117416. NULL,
  117417. &_vq_auxt__44c5_s_p7_0,
  117418. NULL,
  117419. 0
  117420. };
  117421. static long _vq_quantlist__44c5_s_p7_1[] = {
  117422. 5,
  117423. 4,
  117424. 6,
  117425. 3,
  117426. 7,
  117427. 2,
  117428. 8,
  117429. 1,
  117430. 9,
  117431. 0,
  117432. 10,
  117433. };
  117434. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117435. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117436. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117437. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117438. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117439. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117440. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117441. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117442. 10,10,10, 8, 8, 8, 8, 8, 8,
  117443. };
  117444. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117445. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117446. 3.5, 4.5,
  117447. };
  117448. static long _vq_quantmap__44c5_s_p7_1[] = {
  117449. 9, 7, 5, 3, 1, 0, 2, 4,
  117450. 6, 8, 10,
  117451. };
  117452. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117453. _vq_quantthresh__44c5_s_p7_1,
  117454. _vq_quantmap__44c5_s_p7_1,
  117455. 11,
  117456. 11
  117457. };
  117458. static static_codebook _44c5_s_p7_1 = {
  117459. 2, 121,
  117460. _vq_lengthlist__44c5_s_p7_1,
  117461. 1, -531365888, 1611661312, 4, 0,
  117462. _vq_quantlist__44c5_s_p7_1,
  117463. NULL,
  117464. &_vq_auxt__44c5_s_p7_1,
  117465. NULL,
  117466. 0
  117467. };
  117468. static long _vq_quantlist__44c5_s_p8_0[] = {
  117469. 6,
  117470. 5,
  117471. 7,
  117472. 4,
  117473. 8,
  117474. 3,
  117475. 9,
  117476. 2,
  117477. 10,
  117478. 1,
  117479. 11,
  117480. 0,
  117481. 12,
  117482. };
  117483. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117484. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117485. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117486. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117487. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117488. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117489. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117490. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117491. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117492. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117493. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117494. 0,12,12,12,12,12,12,13,13,
  117495. };
  117496. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117497. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117498. 12.5, 17.5, 22.5, 27.5,
  117499. };
  117500. static long _vq_quantmap__44c5_s_p8_0[] = {
  117501. 11, 9, 7, 5, 3, 1, 0, 2,
  117502. 4, 6, 8, 10, 12,
  117503. };
  117504. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117505. _vq_quantthresh__44c5_s_p8_0,
  117506. _vq_quantmap__44c5_s_p8_0,
  117507. 13,
  117508. 13
  117509. };
  117510. static static_codebook _44c5_s_p8_0 = {
  117511. 2, 169,
  117512. _vq_lengthlist__44c5_s_p8_0,
  117513. 1, -526516224, 1616117760, 4, 0,
  117514. _vq_quantlist__44c5_s_p8_0,
  117515. NULL,
  117516. &_vq_auxt__44c5_s_p8_0,
  117517. NULL,
  117518. 0
  117519. };
  117520. static long _vq_quantlist__44c5_s_p8_1[] = {
  117521. 2,
  117522. 1,
  117523. 3,
  117524. 0,
  117525. 4,
  117526. };
  117527. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117528. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117529. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117530. };
  117531. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117532. -1.5, -0.5, 0.5, 1.5,
  117533. };
  117534. static long _vq_quantmap__44c5_s_p8_1[] = {
  117535. 3, 1, 0, 2, 4,
  117536. };
  117537. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117538. _vq_quantthresh__44c5_s_p8_1,
  117539. _vq_quantmap__44c5_s_p8_1,
  117540. 5,
  117541. 5
  117542. };
  117543. static static_codebook _44c5_s_p8_1 = {
  117544. 2, 25,
  117545. _vq_lengthlist__44c5_s_p8_1,
  117546. 1, -533725184, 1611661312, 3, 0,
  117547. _vq_quantlist__44c5_s_p8_1,
  117548. NULL,
  117549. &_vq_auxt__44c5_s_p8_1,
  117550. NULL,
  117551. 0
  117552. };
  117553. static long _vq_quantlist__44c5_s_p9_0[] = {
  117554. 7,
  117555. 6,
  117556. 8,
  117557. 5,
  117558. 9,
  117559. 4,
  117560. 10,
  117561. 3,
  117562. 11,
  117563. 2,
  117564. 12,
  117565. 1,
  117566. 13,
  117567. 0,
  117568. 14,
  117569. };
  117570. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117571. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117572. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117573. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117574. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117575. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117576. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117577. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117578. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117579. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117580. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117581. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117582. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117583. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117584. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117585. 12,
  117586. };
  117587. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117588. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117589. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117590. };
  117591. static long _vq_quantmap__44c5_s_p9_0[] = {
  117592. 13, 11, 9, 7, 5, 3, 1, 0,
  117593. 2, 4, 6, 8, 10, 12, 14,
  117594. };
  117595. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117596. _vq_quantthresh__44c5_s_p9_0,
  117597. _vq_quantmap__44c5_s_p9_0,
  117598. 15,
  117599. 15
  117600. };
  117601. static static_codebook _44c5_s_p9_0 = {
  117602. 2, 225,
  117603. _vq_lengthlist__44c5_s_p9_0,
  117604. 1, -512522752, 1628852224, 4, 0,
  117605. _vq_quantlist__44c5_s_p9_0,
  117606. NULL,
  117607. &_vq_auxt__44c5_s_p9_0,
  117608. NULL,
  117609. 0
  117610. };
  117611. static long _vq_quantlist__44c5_s_p9_1[] = {
  117612. 8,
  117613. 7,
  117614. 9,
  117615. 6,
  117616. 10,
  117617. 5,
  117618. 11,
  117619. 4,
  117620. 12,
  117621. 3,
  117622. 13,
  117623. 2,
  117624. 14,
  117625. 1,
  117626. 15,
  117627. 0,
  117628. 16,
  117629. };
  117630. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117631. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117632. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117633. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117634. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117635. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117636. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117637. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117638. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117639. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117640. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117641. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117642. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117643. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117644. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117645. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117646. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117647. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117648. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117649. 15,
  117650. };
  117651. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117652. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117653. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117654. };
  117655. static long _vq_quantmap__44c5_s_p9_1[] = {
  117656. 15, 13, 11, 9, 7, 5, 3, 1,
  117657. 0, 2, 4, 6, 8, 10, 12, 14,
  117658. 16,
  117659. };
  117660. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117661. _vq_quantthresh__44c5_s_p9_1,
  117662. _vq_quantmap__44c5_s_p9_1,
  117663. 17,
  117664. 17
  117665. };
  117666. static static_codebook _44c5_s_p9_1 = {
  117667. 2, 289,
  117668. _vq_lengthlist__44c5_s_p9_1,
  117669. 1, -520814592, 1620377600, 5, 0,
  117670. _vq_quantlist__44c5_s_p9_1,
  117671. NULL,
  117672. &_vq_auxt__44c5_s_p9_1,
  117673. NULL,
  117674. 0
  117675. };
  117676. static long _vq_quantlist__44c5_s_p9_2[] = {
  117677. 10,
  117678. 9,
  117679. 11,
  117680. 8,
  117681. 12,
  117682. 7,
  117683. 13,
  117684. 6,
  117685. 14,
  117686. 5,
  117687. 15,
  117688. 4,
  117689. 16,
  117690. 3,
  117691. 17,
  117692. 2,
  117693. 18,
  117694. 1,
  117695. 19,
  117696. 0,
  117697. 20,
  117698. };
  117699. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117700. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117701. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117702. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117703. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117704. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117705. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117706. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117707. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117708. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117709. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117710. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117711. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117712. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117713. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117714. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117715. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117716. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117717. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117718. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117719. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117720. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117721. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117722. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117723. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117724. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117725. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117726. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117727. 10,10,10,10,10,10,10,10,10,
  117728. };
  117729. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117730. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117731. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117732. 6.5, 7.5, 8.5, 9.5,
  117733. };
  117734. static long _vq_quantmap__44c5_s_p9_2[] = {
  117735. 19, 17, 15, 13, 11, 9, 7, 5,
  117736. 3, 1, 0, 2, 4, 6, 8, 10,
  117737. 12, 14, 16, 18, 20,
  117738. };
  117739. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117740. _vq_quantthresh__44c5_s_p9_2,
  117741. _vq_quantmap__44c5_s_p9_2,
  117742. 21,
  117743. 21
  117744. };
  117745. static static_codebook _44c5_s_p9_2 = {
  117746. 2, 441,
  117747. _vq_lengthlist__44c5_s_p9_2,
  117748. 1, -529268736, 1611661312, 5, 0,
  117749. _vq_quantlist__44c5_s_p9_2,
  117750. NULL,
  117751. &_vq_auxt__44c5_s_p9_2,
  117752. NULL,
  117753. 0
  117754. };
  117755. static long _huff_lengthlist__44c5_s_short[] = {
  117756. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117757. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117758. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117759. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117760. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117761. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117762. 6, 8,11,16,
  117763. };
  117764. static static_codebook _huff_book__44c5_s_short = {
  117765. 2, 100,
  117766. _huff_lengthlist__44c5_s_short,
  117767. 0, 0, 0, 0, 0,
  117768. NULL,
  117769. NULL,
  117770. NULL,
  117771. NULL,
  117772. 0
  117773. };
  117774. static long _huff_lengthlist__44c6_s_long[] = {
  117775. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117776. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117777. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117778. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117779. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117780. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117781. 11,10,10,12,
  117782. };
  117783. static static_codebook _huff_book__44c6_s_long = {
  117784. 2, 100,
  117785. _huff_lengthlist__44c6_s_long,
  117786. 0, 0, 0, 0, 0,
  117787. NULL,
  117788. NULL,
  117789. NULL,
  117790. NULL,
  117791. 0
  117792. };
  117793. static long _vq_quantlist__44c6_s_p1_0[] = {
  117794. 1,
  117795. 0,
  117796. 2,
  117797. };
  117798. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117799. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117800. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117801. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117802. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117803. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117804. 8,
  117805. };
  117806. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117807. -0.5, 0.5,
  117808. };
  117809. static long _vq_quantmap__44c6_s_p1_0[] = {
  117810. 1, 0, 2,
  117811. };
  117812. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  117813. _vq_quantthresh__44c6_s_p1_0,
  117814. _vq_quantmap__44c6_s_p1_0,
  117815. 3,
  117816. 3
  117817. };
  117818. static static_codebook _44c6_s_p1_0 = {
  117819. 4, 81,
  117820. _vq_lengthlist__44c6_s_p1_0,
  117821. 1, -535822336, 1611661312, 2, 0,
  117822. _vq_quantlist__44c6_s_p1_0,
  117823. NULL,
  117824. &_vq_auxt__44c6_s_p1_0,
  117825. NULL,
  117826. 0
  117827. };
  117828. static long _vq_quantlist__44c6_s_p2_0[] = {
  117829. 2,
  117830. 1,
  117831. 3,
  117832. 0,
  117833. 4,
  117834. };
  117835. static long _vq_lengthlist__44c6_s_p2_0[] = {
  117836. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  117837. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  117838. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  117839. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  117840. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  117841. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  117842. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  117843. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  117844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117845. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  117846. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  117847. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  117848. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  117849. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  117850. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  117851. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  117852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117853. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  117854. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  117855. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  117856. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  117857. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  117858. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  117859. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117861. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  117862. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  117863. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  117864. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  117865. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  117866. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  117867. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  117872. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  117873. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  117874. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  117875. 13,
  117876. };
  117877. static float _vq_quantthresh__44c6_s_p2_0[] = {
  117878. -1.5, -0.5, 0.5, 1.5,
  117879. };
  117880. static long _vq_quantmap__44c6_s_p2_0[] = {
  117881. 3, 1, 0, 2, 4,
  117882. };
  117883. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  117884. _vq_quantthresh__44c6_s_p2_0,
  117885. _vq_quantmap__44c6_s_p2_0,
  117886. 5,
  117887. 5
  117888. };
  117889. static static_codebook _44c6_s_p2_0 = {
  117890. 4, 625,
  117891. _vq_lengthlist__44c6_s_p2_0,
  117892. 1, -533725184, 1611661312, 3, 0,
  117893. _vq_quantlist__44c6_s_p2_0,
  117894. NULL,
  117895. &_vq_auxt__44c6_s_p2_0,
  117896. NULL,
  117897. 0
  117898. };
  117899. static long _vq_quantlist__44c6_s_p3_0[] = {
  117900. 4,
  117901. 3,
  117902. 5,
  117903. 2,
  117904. 6,
  117905. 1,
  117906. 7,
  117907. 0,
  117908. 8,
  117909. };
  117910. static long _vq_lengthlist__44c6_s_p3_0[] = {
  117911. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117912. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  117913. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  117914. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  117915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117916. 0,
  117917. };
  117918. static float _vq_quantthresh__44c6_s_p3_0[] = {
  117919. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117920. };
  117921. static long _vq_quantmap__44c6_s_p3_0[] = {
  117922. 7, 5, 3, 1, 0, 2, 4, 6,
  117923. 8,
  117924. };
  117925. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  117926. _vq_quantthresh__44c6_s_p3_0,
  117927. _vq_quantmap__44c6_s_p3_0,
  117928. 9,
  117929. 9
  117930. };
  117931. static static_codebook _44c6_s_p3_0 = {
  117932. 2, 81,
  117933. _vq_lengthlist__44c6_s_p3_0,
  117934. 1, -531628032, 1611661312, 4, 0,
  117935. _vq_quantlist__44c6_s_p3_0,
  117936. NULL,
  117937. &_vq_auxt__44c6_s_p3_0,
  117938. NULL,
  117939. 0
  117940. };
  117941. static long _vq_quantlist__44c6_s_p4_0[] = {
  117942. 8,
  117943. 7,
  117944. 9,
  117945. 6,
  117946. 10,
  117947. 5,
  117948. 11,
  117949. 4,
  117950. 12,
  117951. 3,
  117952. 13,
  117953. 2,
  117954. 14,
  117955. 1,
  117956. 15,
  117957. 0,
  117958. 16,
  117959. };
  117960. static long _vq_lengthlist__44c6_s_p4_0[] = {
  117961. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  117962. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  117963. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  117964. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117965. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117966. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117967. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  117968. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  117969. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  117970. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  117971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117979. 0,
  117980. };
  117981. static float _vq_quantthresh__44c6_s_p4_0[] = {
  117982. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117983. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117984. };
  117985. static long _vq_quantmap__44c6_s_p4_0[] = {
  117986. 15, 13, 11, 9, 7, 5, 3, 1,
  117987. 0, 2, 4, 6, 8, 10, 12, 14,
  117988. 16,
  117989. };
  117990. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  117991. _vq_quantthresh__44c6_s_p4_0,
  117992. _vq_quantmap__44c6_s_p4_0,
  117993. 17,
  117994. 17
  117995. };
  117996. static static_codebook _44c6_s_p4_0 = {
  117997. 2, 289,
  117998. _vq_lengthlist__44c6_s_p4_0,
  117999. 1, -529530880, 1611661312, 5, 0,
  118000. _vq_quantlist__44c6_s_p4_0,
  118001. NULL,
  118002. &_vq_auxt__44c6_s_p4_0,
  118003. NULL,
  118004. 0
  118005. };
  118006. static long _vq_quantlist__44c6_s_p5_0[] = {
  118007. 1,
  118008. 0,
  118009. 2,
  118010. };
  118011. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118012. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118013. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118014. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118015. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118016. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118017. 12,
  118018. };
  118019. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118020. -5.5, 5.5,
  118021. };
  118022. static long _vq_quantmap__44c6_s_p5_0[] = {
  118023. 1, 0, 2,
  118024. };
  118025. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118026. _vq_quantthresh__44c6_s_p5_0,
  118027. _vq_quantmap__44c6_s_p5_0,
  118028. 3,
  118029. 3
  118030. };
  118031. static static_codebook _44c6_s_p5_0 = {
  118032. 4, 81,
  118033. _vq_lengthlist__44c6_s_p5_0,
  118034. 1, -529137664, 1618345984, 2, 0,
  118035. _vq_quantlist__44c6_s_p5_0,
  118036. NULL,
  118037. &_vq_auxt__44c6_s_p5_0,
  118038. NULL,
  118039. 0
  118040. };
  118041. static long _vq_quantlist__44c6_s_p5_1[] = {
  118042. 5,
  118043. 4,
  118044. 6,
  118045. 3,
  118046. 7,
  118047. 2,
  118048. 8,
  118049. 1,
  118050. 9,
  118051. 0,
  118052. 10,
  118053. };
  118054. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118055. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118056. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118057. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118058. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118059. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118060. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118061. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118062. 11,10,10, 7, 7, 8, 8, 8, 8,
  118063. };
  118064. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118065. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118066. 3.5, 4.5,
  118067. };
  118068. static long _vq_quantmap__44c6_s_p5_1[] = {
  118069. 9, 7, 5, 3, 1, 0, 2, 4,
  118070. 6, 8, 10,
  118071. };
  118072. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118073. _vq_quantthresh__44c6_s_p5_1,
  118074. _vq_quantmap__44c6_s_p5_1,
  118075. 11,
  118076. 11
  118077. };
  118078. static static_codebook _44c6_s_p5_1 = {
  118079. 2, 121,
  118080. _vq_lengthlist__44c6_s_p5_1,
  118081. 1, -531365888, 1611661312, 4, 0,
  118082. _vq_quantlist__44c6_s_p5_1,
  118083. NULL,
  118084. &_vq_auxt__44c6_s_p5_1,
  118085. NULL,
  118086. 0
  118087. };
  118088. static long _vq_quantlist__44c6_s_p6_0[] = {
  118089. 6,
  118090. 5,
  118091. 7,
  118092. 4,
  118093. 8,
  118094. 3,
  118095. 9,
  118096. 2,
  118097. 10,
  118098. 1,
  118099. 11,
  118100. 0,
  118101. 12,
  118102. };
  118103. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118104. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118105. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118106. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118107. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118108. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118109. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118114. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118115. };
  118116. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118117. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118118. 12.5, 17.5, 22.5, 27.5,
  118119. };
  118120. static long _vq_quantmap__44c6_s_p6_0[] = {
  118121. 11, 9, 7, 5, 3, 1, 0, 2,
  118122. 4, 6, 8, 10, 12,
  118123. };
  118124. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118125. _vq_quantthresh__44c6_s_p6_0,
  118126. _vq_quantmap__44c6_s_p6_0,
  118127. 13,
  118128. 13
  118129. };
  118130. static static_codebook _44c6_s_p6_0 = {
  118131. 2, 169,
  118132. _vq_lengthlist__44c6_s_p6_0,
  118133. 1, -526516224, 1616117760, 4, 0,
  118134. _vq_quantlist__44c6_s_p6_0,
  118135. NULL,
  118136. &_vq_auxt__44c6_s_p6_0,
  118137. NULL,
  118138. 0
  118139. };
  118140. static long _vq_quantlist__44c6_s_p6_1[] = {
  118141. 2,
  118142. 1,
  118143. 3,
  118144. 0,
  118145. 4,
  118146. };
  118147. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118148. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118149. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118150. };
  118151. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118152. -1.5, -0.5, 0.5, 1.5,
  118153. };
  118154. static long _vq_quantmap__44c6_s_p6_1[] = {
  118155. 3, 1, 0, 2, 4,
  118156. };
  118157. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118158. _vq_quantthresh__44c6_s_p6_1,
  118159. _vq_quantmap__44c6_s_p6_1,
  118160. 5,
  118161. 5
  118162. };
  118163. static static_codebook _44c6_s_p6_1 = {
  118164. 2, 25,
  118165. _vq_lengthlist__44c6_s_p6_1,
  118166. 1, -533725184, 1611661312, 3, 0,
  118167. _vq_quantlist__44c6_s_p6_1,
  118168. NULL,
  118169. &_vq_auxt__44c6_s_p6_1,
  118170. NULL,
  118171. 0
  118172. };
  118173. static long _vq_quantlist__44c6_s_p7_0[] = {
  118174. 6,
  118175. 5,
  118176. 7,
  118177. 4,
  118178. 8,
  118179. 3,
  118180. 9,
  118181. 2,
  118182. 10,
  118183. 1,
  118184. 11,
  118185. 0,
  118186. 12,
  118187. };
  118188. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118189. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118190. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118191. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118192. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118193. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118194. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118195. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118196. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118197. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118198. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118199. 20,13,13,13,13,13,13,14,14,
  118200. };
  118201. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118202. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118203. 27.5, 38.5, 49.5, 60.5,
  118204. };
  118205. static long _vq_quantmap__44c6_s_p7_0[] = {
  118206. 11, 9, 7, 5, 3, 1, 0, 2,
  118207. 4, 6, 8, 10, 12,
  118208. };
  118209. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118210. _vq_quantthresh__44c6_s_p7_0,
  118211. _vq_quantmap__44c6_s_p7_0,
  118212. 13,
  118213. 13
  118214. };
  118215. static static_codebook _44c6_s_p7_0 = {
  118216. 2, 169,
  118217. _vq_lengthlist__44c6_s_p7_0,
  118218. 1, -523206656, 1618345984, 4, 0,
  118219. _vq_quantlist__44c6_s_p7_0,
  118220. NULL,
  118221. &_vq_auxt__44c6_s_p7_0,
  118222. NULL,
  118223. 0
  118224. };
  118225. static long _vq_quantlist__44c6_s_p7_1[] = {
  118226. 5,
  118227. 4,
  118228. 6,
  118229. 3,
  118230. 7,
  118231. 2,
  118232. 8,
  118233. 1,
  118234. 9,
  118235. 0,
  118236. 10,
  118237. };
  118238. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118239. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118240. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118241. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118242. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118243. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118244. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118245. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118246. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118247. };
  118248. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118249. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118250. 3.5, 4.5,
  118251. };
  118252. static long _vq_quantmap__44c6_s_p7_1[] = {
  118253. 9, 7, 5, 3, 1, 0, 2, 4,
  118254. 6, 8, 10,
  118255. };
  118256. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118257. _vq_quantthresh__44c6_s_p7_1,
  118258. _vq_quantmap__44c6_s_p7_1,
  118259. 11,
  118260. 11
  118261. };
  118262. static static_codebook _44c6_s_p7_1 = {
  118263. 2, 121,
  118264. _vq_lengthlist__44c6_s_p7_1,
  118265. 1, -531365888, 1611661312, 4, 0,
  118266. _vq_quantlist__44c6_s_p7_1,
  118267. NULL,
  118268. &_vq_auxt__44c6_s_p7_1,
  118269. NULL,
  118270. 0
  118271. };
  118272. static long _vq_quantlist__44c6_s_p8_0[] = {
  118273. 7,
  118274. 6,
  118275. 8,
  118276. 5,
  118277. 9,
  118278. 4,
  118279. 10,
  118280. 3,
  118281. 11,
  118282. 2,
  118283. 12,
  118284. 1,
  118285. 13,
  118286. 0,
  118287. 14,
  118288. };
  118289. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118290. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118291. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118292. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118293. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118294. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118295. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118296. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118297. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118298. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118299. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118300. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118301. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118302. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118303. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118304. 14,
  118305. };
  118306. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118307. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118308. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118309. };
  118310. static long _vq_quantmap__44c6_s_p8_0[] = {
  118311. 13, 11, 9, 7, 5, 3, 1, 0,
  118312. 2, 4, 6, 8, 10, 12, 14,
  118313. };
  118314. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118315. _vq_quantthresh__44c6_s_p8_0,
  118316. _vq_quantmap__44c6_s_p8_0,
  118317. 15,
  118318. 15
  118319. };
  118320. static static_codebook _44c6_s_p8_0 = {
  118321. 2, 225,
  118322. _vq_lengthlist__44c6_s_p8_0,
  118323. 1, -520986624, 1620377600, 4, 0,
  118324. _vq_quantlist__44c6_s_p8_0,
  118325. NULL,
  118326. &_vq_auxt__44c6_s_p8_0,
  118327. NULL,
  118328. 0
  118329. };
  118330. static long _vq_quantlist__44c6_s_p8_1[] = {
  118331. 10,
  118332. 9,
  118333. 11,
  118334. 8,
  118335. 12,
  118336. 7,
  118337. 13,
  118338. 6,
  118339. 14,
  118340. 5,
  118341. 15,
  118342. 4,
  118343. 16,
  118344. 3,
  118345. 17,
  118346. 2,
  118347. 18,
  118348. 1,
  118349. 19,
  118350. 0,
  118351. 20,
  118352. };
  118353. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118354. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118355. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118356. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118357. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118358. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118359. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118360. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118361. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118362. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118363. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118364. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118365. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118366. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118367. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118368. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118369. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118370. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118371. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118372. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118373. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118374. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118375. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118376. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118377. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118378. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118379. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118380. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118381. 10,10,10,10,10,10,10,10,10,
  118382. };
  118383. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118384. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118385. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118386. 6.5, 7.5, 8.5, 9.5,
  118387. };
  118388. static long _vq_quantmap__44c6_s_p8_1[] = {
  118389. 19, 17, 15, 13, 11, 9, 7, 5,
  118390. 3, 1, 0, 2, 4, 6, 8, 10,
  118391. 12, 14, 16, 18, 20,
  118392. };
  118393. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118394. _vq_quantthresh__44c6_s_p8_1,
  118395. _vq_quantmap__44c6_s_p8_1,
  118396. 21,
  118397. 21
  118398. };
  118399. static static_codebook _44c6_s_p8_1 = {
  118400. 2, 441,
  118401. _vq_lengthlist__44c6_s_p8_1,
  118402. 1, -529268736, 1611661312, 5, 0,
  118403. _vq_quantlist__44c6_s_p8_1,
  118404. NULL,
  118405. &_vq_auxt__44c6_s_p8_1,
  118406. NULL,
  118407. 0
  118408. };
  118409. static long _vq_quantlist__44c6_s_p9_0[] = {
  118410. 6,
  118411. 5,
  118412. 7,
  118413. 4,
  118414. 8,
  118415. 3,
  118416. 9,
  118417. 2,
  118418. 10,
  118419. 1,
  118420. 11,
  118421. 0,
  118422. 12,
  118423. };
  118424. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118425. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118426. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118428. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118429. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118430. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118431. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118432. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118433. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118434. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118435. 10,10,10,10,10,10,10,10,10,
  118436. };
  118437. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118438. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118439. 1592.5, 2229.5, 2866.5, 3503.5,
  118440. };
  118441. static long _vq_quantmap__44c6_s_p9_0[] = {
  118442. 11, 9, 7, 5, 3, 1, 0, 2,
  118443. 4, 6, 8, 10, 12,
  118444. };
  118445. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118446. _vq_quantthresh__44c6_s_p9_0,
  118447. _vq_quantmap__44c6_s_p9_0,
  118448. 13,
  118449. 13
  118450. };
  118451. static static_codebook _44c6_s_p9_0 = {
  118452. 2, 169,
  118453. _vq_lengthlist__44c6_s_p9_0,
  118454. 1, -511845376, 1630791680, 4, 0,
  118455. _vq_quantlist__44c6_s_p9_0,
  118456. NULL,
  118457. &_vq_auxt__44c6_s_p9_0,
  118458. NULL,
  118459. 0
  118460. };
  118461. static long _vq_quantlist__44c6_s_p9_1[] = {
  118462. 6,
  118463. 5,
  118464. 7,
  118465. 4,
  118466. 8,
  118467. 3,
  118468. 9,
  118469. 2,
  118470. 10,
  118471. 1,
  118472. 11,
  118473. 0,
  118474. 12,
  118475. };
  118476. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118477. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118478. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118479. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118480. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118481. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118482. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118483. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118484. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118485. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118486. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118487. 15,12,10,11,11,13,11,12,13,
  118488. };
  118489. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118490. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118491. 122.5, 171.5, 220.5, 269.5,
  118492. };
  118493. static long _vq_quantmap__44c6_s_p9_1[] = {
  118494. 11, 9, 7, 5, 3, 1, 0, 2,
  118495. 4, 6, 8, 10, 12,
  118496. };
  118497. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118498. _vq_quantthresh__44c6_s_p9_1,
  118499. _vq_quantmap__44c6_s_p9_1,
  118500. 13,
  118501. 13
  118502. };
  118503. static static_codebook _44c6_s_p9_1 = {
  118504. 2, 169,
  118505. _vq_lengthlist__44c6_s_p9_1,
  118506. 1, -518889472, 1622704128, 4, 0,
  118507. _vq_quantlist__44c6_s_p9_1,
  118508. NULL,
  118509. &_vq_auxt__44c6_s_p9_1,
  118510. NULL,
  118511. 0
  118512. };
  118513. static long _vq_quantlist__44c6_s_p9_2[] = {
  118514. 24,
  118515. 23,
  118516. 25,
  118517. 22,
  118518. 26,
  118519. 21,
  118520. 27,
  118521. 20,
  118522. 28,
  118523. 19,
  118524. 29,
  118525. 18,
  118526. 30,
  118527. 17,
  118528. 31,
  118529. 16,
  118530. 32,
  118531. 15,
  118532. 33,
  118533. 14,
  118534. 34,
  118535. 13,
  118536. 35,
  118537. 12,
  118538. 36,
  118539. 11,
  118540. 37,
  118541. 10,
  118542. 38,
  118543. 9,
  118544. 39,
  118545. 8,
  118546. 40,
  118547. 7,
  118548. 41,
  118549. 6,
  118550. 42,
  118551. 5,
  118552. 43,
  118553. 4,
  118554. 44,
  118555. 3,
  118556. 45,
  118557. 2,
  118558. 46,
  118559. 1,
  118560. 47,
  118561. 0,
  118562. 48,
  118563. };
  118564. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118565. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118566. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118567. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118568. 7,
  118569. };
  118570. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118571. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118572. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118573. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118574. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118575. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118576. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118577. };
  118578. static long _vq_quantmap__44c6_s_p9_2[] = {
  118579. 47, 45, 43, 41, 39, 37, 35, 33,
  118580. 31, 29, 27, 25, 23, 21, 19, 17,
  118581. 15, 13, 11, 9, 7, 5, 3, 1,
  118582. 0, 2, 4, 6, 8, 10, 12, 14,
  118583. 16, 18, 20, 22, 24, 26, 28, 30,
  118584. 32, 34, 36, 38, 40, 42, 44, 46,
  118585. 48,
  118586. };
  118587. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118588. _vq_quantthresh__44c6_s_p9_2,
  118589. _vq_quantmap__44c6_s_p9_2,
  118590. 49,
  118591. 49
  118592. };
  118593. static static_codebook _44c6_s_p9_2 = {
  118594. 1, 49,
  118595. _vq_lengthlist__44c6_s_p9_2,
  118596. 1, -526909440, 1611661312, 6, 0,
  118597. _vq_quantlist__44c6_s_p9_2,
  118598. NULL,
  118599. &_vq_auxt__44c6_s_p9_2,
  118600. NULL,
  118601. 0
  118602. };
  118603. static long _huff_lengthlist__44c6_s_short[] = {
  118604. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118605. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118606. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118607. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118608. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118609. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118610. 9,10,17,18,
  118611. };
  118612. static static_codebook _huff_book__44c6_s_short = {
  118613. 2, 100,
  118614. _huff_lengthlist__44c6_s_short,
  118615. 0, 0, 0, 0, 0,
  118616. NULL,
  118617. NULL,
  118618. NULL,
  118619. NULL,
  118620. 0
  118621. };
  118622. static long _huff_lengthlist__44c7_s_long[] = {
  118623. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118624. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118625. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118626. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118627. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118628. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118629. 11,10,10,12,
  118630. };
  118631. static static_codebook _huff_book__44c7_s_long = {
  118632. 2, 100,
  118633. _huff_lengthlist__44c7_s_long,
  118634. 0, 0, 0, 0, 0,
  118635. NULL,
  118636. NULL,
  118637. NULL,
  118638. NULL,
  118639. 0
  118640. };
  118641. static long _vq_quantlist__44c7_s_p1_0[] = {
  118642. 1,
  118643. 0,
  118644. 2,
  118645. };
  118646. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118647. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118648. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118649. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118650. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118651. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118652. 8,
  118653. };
  118654. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118655. -0.5, 0.5,
  118656. };
  118657. static long _vq_quantmap__44c7_s_p1_0[] = {
  118658. 1, 0, 2,
  118659. };
  118660. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118661. _vq_quantthresh__44c7_s_p1_0,
  118662. _vq_quantmap__44c7_s_p1_0,
  118663. 3,
  118664. 3
  118665. };
  118666. static static_codebook _44c7_s_p1_0 = {
  118667. 4, 81,
  118668. _vq_lengthlist__44c7_s_p1_0,
  118669. 1, -535822336, 1611661312, 2, 0,
  118670. _vq_quantlist__44c7_s_p1_0,
  118671. NULL,
  118672. &_vq_auxt__44c7_s_p1_0,
  118673. NULL,
  118674. 0
  118675. };
  118676. static long _vq_quantlist__44c7_s_p2_0[] = {
  118677. 2,
  118678. 1,
  118679. 3,
  118680. 0,
  118681. 4,
  118682. };
  118683. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118684. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118685. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118686. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118687. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118688. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118689. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118690. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118691. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118693. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118694. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118695. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118696. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118697. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118698. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118699. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118701. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118702. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118703. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118704. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118705. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118706. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118707. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118709. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118710. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118711. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118712. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118713. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118714. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118715. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118720. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118721. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118722. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118723. 13,
  118724. };
  118725. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118726. -1.5, -0.5, 0.5, 1.5,
  118727. };
  118728. static long _vq_quantmap__44c7_s_p2_0[] = {
  118729. 3, 1, 0, 2, 4,
  118730. };
  118731. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118732. _vq_quantthresh__44c7_s_p2_0,
  118733. _vq_quantmap__44c7_s_p2_0,
  118734. 5,
  118735. 5
  118736. };
  118737. static static_codebook _44c7_s_p2_0 = {
  118738. 4, 625,
  118739. _vq_lengthlist__44c7_s_p2_0,
  118740. 1, -533725184, 1611661312, 3, 0,
  118741. _vq_quantlist__44c7_s_p2_0,
  118742. NULL,
  118743. &_vq_auxt__44c7_s_p2_0,
  118744. NULL,
  118745. 0
  118746. };
  118747. static long _vq_quantlist__44c7_s_p3_0[] = {
  118748. 4,
  118749. 3,
  118750. 5,
  118751. 2,
  118752. 6,
  118753. 1,
  118754. 7,
  118755. 0,
  118756. 8,
  118757. };
  118758. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118759. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118760. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118761. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118762. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118764. 0,
  118765. };
  118766. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118767. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118768. };
  118769. static long _vq_quantmap__44c7_s_p3_0[] = {
  118770. 7, 5, 3, 1, 0, 2, 4, 6,
  118771. 8,
  118772. };
  118773. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118774. _vq_quantthresh__44c7_s_p3_0,
  118775. _vq_quantmap__44c7_s_p3_0,
  118776. 9,
  118777. 9
  118778. };
  118779. static static_codebook _44c7_s_p3_0 = {
  118780. 2, 81,
  118781. _vq_lengthlist__44c7_s_p3_0,
  118782. 1, -531628032, 1611661312, 4, 0,
  118783. _vq_quantlist__44c7_s_p3_0,
  118784. NULL,
  118785. &_vq_auxt__44c7_s_p3_0,
  118786. NULL,
  118787. 0
  118788. };
  118789. static long _vq_quantlist__44c7_s_p4_0[] = {
  118790. 8,
  118791. 7,
  118792. 9,
  118793. 6,
  118794. 10,
  118795. 5,
  118796. 11,
  118797. 4,
  118798. 12,
  118799. 3,
  118800. 13,
  118801. 2,
  118802. 14,
  118803. 1,
  118804. 15,
  118805. 0,
  118806. 16,
  118807. };
  118808. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118809. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  118810. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  118811. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  118812. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  118813. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  118814. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  118815. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  118816. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118817. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  118818. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  118819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118827. 0,
  118828. };
  118829. static float _vq_quantthresh__44c7_s_p4_0[] = {
  118830. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118831. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118832. };
  118833. static long _vq_quantmap__44c7_s_p4_0[] = {
  118834. 15, 13, 11, 9, 7, 5, 3, 1,
  118835. 0, 2, 4, 6, 8, 10, 12, 14,
  118836. 16,
  118837. };
  118838. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  118839. _vq_quantthresh__44c7_s_p4_0,
  118840. _vq_quantmap__44c7_s_p4_0,
  118841. 17,
  118842. 17
  118843. };
  118844. static static_codebook _44c7_s_p4_0 = {
  118845. 2, 289,
  118846. _vq_lengthlist__44c7_s_p4_0,
  118847. 1, -529530880, 1611661312, 5, 0,
  118848. _vq_quantlist__44c7_s_p4_0,
  118849. NULL,
  118850. &_vq_auxt__44c7_s_p4_0,
  118851. NULL,
  118852. 0
  118853. };
  118854. static long _vq_quantlist__44c7_s_p5_0[] = {
  118855. 1,
  118856. 0,
  118857. 2,
  118858. };
  118859. static long _vq_lengthlist__44c7_s_p5_0[] = {
  118860. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  118861. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  118862. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  118863. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118864. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  118865. 12,
  118866. };
  118867. static float _vq_quantthresh__44c7_s_p5_0[] = {
  118868. -5.5, 5.5,
  118869. };
  118870. static long _vq_quantmap__44c7_s_p5_0[] = {
  118871. 1, 0, 2,
  118872. };
  118873. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  118874. _vq_quantthresh__44c7_s_p5_0,
  118875. _vq_quantmap__44c7_s_p5_0,
  118876. 3,
  118877. 3
  118878. };
  118879. static static_codebook _44c7_s_p5_0 = {
  118880. 4, 81,
  118881. _vq_lengthlist__44c7_s_p5_0,
  118882. 1, -529137664, 1618345984, 2, 0,
  118883. _vq_quantlist__44c7_s_p5_0,
  118884. NULL,
  118885. &_vq_auxt__44c7_s_p5_0,
  118886. NULL,
  118887. 0
  118888. };
  118889. static long _vq_quantlist__44c7_s_p5_1[] = {
  118890. 5,
  118891. 4,
  118892. 6,
  118893. 3,
  118894. 7,
  118895. 2,
  118896. 8,
  118897. 1,
  118898. 9,
  118899. 0,
  118900. 10,
  118901. };
  118902. static long _vq_lengthlist__44c7_s_p5_1[] = {
  118903. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118904. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  118905. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  118906. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  118907. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  118908. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  118909. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  118910. 11,11,11, 7, 7, 8, 8, 8, 8,
  118911. };
  118912. static float _vq_quantthresh__44c7_s_p5_1[] = {
  118913. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118914. 3.5, 4.5,
  118915. };
  118916. static long _vq_quantmap__44c7_s_p5_1[] = {
  118917. 9, 7, 5, 3, 1, 0, 2, 4,
  118918. 6, 8, 10,
  118919. };
  118920. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  118921. _vq_quantthresh__44c7_s_p5_1,
  118922. _vq_quantmap__44c7_s_p5_1,
  118923. 11,
  118924. 11
  118925. };
  118926. static static_codebook _44c7_s_p5_1 = {
  118927. 2, 121,
  118928. _vq_lengthlist__44c7_s_p5_1,
  118929. 1, -531365888, 1611661312, 4, 0,
  118930. _vq_quantlist__44c7_s_p5_1,
  118931. NULL,
  118932. &_vq_auxt__44c7_s_p5_1,
  118933. NULL,
  118934. 0
  118935. };
  118936. static long _vq_quantlist__44c7_s_p6_0[] = {
  118937. 6,
  118938. 5,
  118939. 7,
  118940. 4,
  118941. 8,
  118942. 3,
  118943. 9,
  118944. 2,
  118945. 10,
  118946. 1,
  118947. 11,
  118948. 0,
  118949. 12,
  118950. };
  118951. static long _vq_lengthlist__44c7_s_p6_0[] = {
  118952. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  118953. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  118954. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  118955. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  118956. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  118957. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  118958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118962. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118963. };
  118964. static float _vq_quantthresh__44c7_s_p6_0[] = {
  118965. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118966. 12.5, 17.5, 22.5, 27.5,
  118967. };
  118968. static long _vq_quantmap__44c7_s_p6_0[] = {
  118969. 11, 9, 7, 5, 3, 1, 0, 2,
  118970. 4, 6, 8, 10, 12,
  118971. };
  118972. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  118973. _vq_quantthresh__44c7_s_p6_0,
  118974. _vq_quantmap__44c7_s_p6_0,
  118975. 13,
  118976. 13
  118977. };
  118978. static static_codebook _44c7_s_p6_0 = {
  118979. 2, 169,
  118980. _vq_lengthlist__44c7_s_p6_0,
  118981. 1, -526516224, 1616117760, 4, 0,
  118982. _vq_quantlist__44c7_s_p6_0,
  118983. NULL,
  118984. &_vq_auxt__44c7_s_p6_0,
  118985. NULL,
  118986. 0
  118987. };
  118988. static long _vq_quantlist__44c7_s_p6_1[] = {
  118989. 2,
  118990. 1,
  118991. 3,
  118992. 0,
  118993. 4,
  118994. };
  118995. static long _vq_lengthlist__44c7_s_p6_1[] = {
  118996. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118997. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118998. };
  118999. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119000. -1.5, -0.5, 0.5, 1.5,
  119001. };
  119002. static long _vq_quantmap__44c7_s_p6_1[] = {
  119003. 3, 1, 0, 2, 4,
  119004. };
  119005. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119006. _vq_quantthresh__44c7_s_p6_1,
  119007. _vq_quantmap__44c7_s_p6_1,
  119008. 5,
  119009. 5
  119010. };
  119011. static static_codebook _44c7_s_p6_1 = {
  119012. 2, 25,
  119013. _vq_lengthlist__44c7_s_p6_1,
  119014. 1, -533725184, 1611661312, 3, 0,
  119015. _vq_quantlist__44c7_s_p6_1,
  119016. NULL,
  119017. &_vq_auxt__44c7_s_p6_1,
  119018. NULL,
  119019. 0
  119020. };
  119021. static long _vq_quantlist__44c7_s_p7_0[] = {
  119022. 6,
  119023. 5,
  119024. 7,
  119025. 4,
  119026. 8,
  119027. 3,
  119028. 9,
  119029. 2,
  119030. 10,
  119031. 1,
  119032. 11,
  119033. 0,
  119034. 12,
  119035. };
  119036. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119037. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119038. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119039. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119040. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119041. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119042. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119043. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119044. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119045. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119046. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119047. 19,13,13,13,13,14,14,15,15,
  119048. };
  119049. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119050. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119051. 27.5, 38.5, 49.5, 60.5,
  119052. };
  119053. static long _vq_quantmap__44c7_s_p7_0[] = {
  119054. 11, 9, 7, 5, 3, 1, 0, 2,
  119055. 4, 6, 8, 10, 12,
  119056. };
  119057. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119058. _vq_quantthresh__44c7_s_p7_0,
  119059. _vq_quantmap__44c7_s_p7_0,
  119060. 13,
  119061. 13
  119062. };
  119063. static static_codebook _44c7_s_p7_0 = {
  119064. 2, 169,
  119065. _vq_lengthlist__44c7_s_p7_0,
  119066. 1, -523206656, 1618345984, 4, 0,
  119067. _vq_quantlist__44c7_s_p7_0,
  119068. NULL,
  119069. &_vq_auxt__44c7_s_p7_0,
  119070. NULL,
  119071. 0
  119072. };
  119073. static long _vq_quantlist__44c7_s_p7_1[] = {
  119074. 5,
  119075. 4,
  119076. 6,
  119077. 3,
  119078. 7,
  119079. 2,
  119080. 8,
  119081. 1,
  119082. 9,
  119083. 0,
  119084. 10,
  119085. };
  119086. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119087. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119088. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119089. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119090. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119091. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119092. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119093. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119094. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119095. };
  119096. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119097. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119098. 3.5, 4.5,
  119099. };
  119100. static long _vq_quantmap__44c7_s_p7_1[] = {
  119101. 9, 7, 5, 3, 1, 0, 2, 4,
  119102. 6, 8, 10,
  119103. };
  119104. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119105. _vq_quantthresh__44c7_s_p7_1,
  119106. _vq_quantmap__44c7_s_p7_1,
  119107. 11,
  119108. 11
  119109. };
  119110. static static_codebook _44c7_s_p7_1 = {
  119111. 2, 121,
  119112. _vq_lengthlist__44c7_s_p7_1,
  119113. 1, -531365888, 1611661312, 4, 0,
  119114. _vq_quantlist__44c7_s_p7_1,
  119115. NULL,
  119116. &_vq_auxt__44c7_s_p7_1,
  119117. NULL,
  119118. 0
  119119. };
  119120. static long _vq_quantlist__44c7_s_p8_0[] = {
  119121. 7,
  119122. 6,
  119123. 8,
  119124. 5,
  119125. 9,
  119126. 4,
  119127. 10,
  119128. 3,
  119129. 11,
  119130. 2,
  119131. 12,
  119132. 1,
  119133. 13,
  119134. 0,
  119135. 14,
  119136. };
  119137. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119138. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119139. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119140. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119141. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119142. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119143. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119144. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119145. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119146. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119147. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119148. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119149. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119150. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119151. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119152. 14,
  119153. };
  119154. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119155. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119156. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119157. };
  119158. static long _vq_quantmap__44c7_s_p8_0[] = {
  119159. 13, 11, 9, 7, 5, 3, 1, 0,
  119160. 2, 4, 6, 8, 10, 12, 14,
  119161. };
  119162. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119163. _vq_quantthresh__44c7_s_p8_0,
  119164. _vq_quantmap__44c7_s_p8_0,
  119165. 15,
  119166. 15
  119167. };
  119168. static static_codebook _44c7_s_p8_0 = {
  119169. 2, 225,
  119170. _vq_lengthlist__44c7_s_p8_0,
  119171. 1, -520986624, 1620377600, 4, 0,
  119172. _vq_quantlist__44c7_s_p8_0,
  119173. NULL,
  119174. &_vq_auxt__44c7_s_p8_0,
  119175. NULL,
  119176. 0
  119177. };
  119178. static long _vq_quantlist__44c7_s_p8_1[] = {
  119179. 10,
  119180. 9,
  119181. 11,
  119182. 8,
  119183. 12,
  119184. 7,
  119185. 13,
  119186. 6,
  119187. 14,
  119188. 5,
  119189. 15,
  119190. 4,
  119191. 16,
  119192. 3,
  119193. 17,
  119194. 2,
  119195. 18,
  119196. 1,
  119197. 19,
  119198. 0,
  119199. 20,
  119200. };
  119201. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119202. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119203. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119204. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119205. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119206. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119207. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119208. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119209. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119210. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119211. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119212. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119213. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119214. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119215. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119216. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119217. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119218. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119219. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119220. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119221. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119222. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119223. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119224. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119225. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119226. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119227. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119228. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119229. 10,10,10,10,10,10,10,10,10,
  119230. };
  119231. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119232. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119233. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119234. 6.5, 7.5, 8.5, 9.5,
  119235. };
  119236. static long _vq_quantmap__44c7_s_p8_1[] = {
  119237. 19, 17, 15, 13, 11, 9, 7, 5,
  119238. 3, 1, 0, 2, 4, 6, 8, 10,
  119239. 12, 14, 16, 18, 20,
  119240. };
  119241. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119242. _vq_quantthresh__44c7_s_p8_1,
  119243. _vq_quantmap__44c7_s_p8_1,
  119244. 21,
  119245. 21
  119246. };
  119247. static static_codebook _44c7_s_p8_1 = {
  119248. 2, 441,
  119249. _vq_lengthlist__44c7_s_p8_1,
  119250. 1, -529268736, 1611661312, 5, 0,
  119251. _vq_quantlist__44c7_s_p8_1,
  119252. NULL,
  119253. &_vq_auxt__44c7_s_p8_1,
  119254. NULL,
  119255. 0
  119256. };
  119257. static long _vq_quantlist__44c7_s_p9_0[] = {
  119258. 6,
  119259. 5,
  119260. 7,
  119261. 4,
  119262. 8,
  119263. 3,
  119264. 9,
  119265. 2,
  119266. 10,
  119267. 1,
  119268. 11,
  119269. 0,
  119270. 12,
  119271. };
  119272. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119273. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119274. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119275. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119276. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119283. 11,11,11,11,11,11,11,11,11,
  119284. };
  119285. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119286. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119287. 1592.5, 2229.5, 2866.5, 3503.5,
  119288. };
  119289. static long _vq_quantmap__44c7_s_p9_0[] = {
  119290. 11, 9, 7, 5, 3, 1, 0, 2,
  119291. 4, 6, 8, 10, 12,
  119292. };
  119293. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119294. _vq_quantthresh__44c7_s_p9_0,
  119295. _vq_quantmap__44c7_s_p9_0,
  119296. 13,
  119297. 13
  119298. };
  119299. static static_codebook _44c7_s_p9_0 = {
  119300. 2, 169,
  119301. _vq_lengthlist__44c7_s_p9_0,
  119302. 1, -511845376, 1630791680, 4, 0,
  119303. _vq_quantlist__44c7_s_p9_0,
  119304. NULL,
  119305. &_vq_auxt__44c7_s_p9_0,
  119306. NULL,
  119307. 0
  119308. };
  119309. static long _vq_quantlist__44c7_s_p9_1[] = {
  119310. 6,
  119311. 5,
  119312. 7,
  119313. 4,
  119314. 8,
  119315. 3,
  119316. 9,
  119317. 2,
  119318. 10,
  119319. 1,
  119320. 11,
  119321. 0,
  119322. 12,
  119323. };
  119324. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119325. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119326. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119327. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119328. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119329. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119330. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119331. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119332. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119333. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119334. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119335. 15,11,11,10,10,12,12,12,12,
  119336. };
  119337. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119338. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119339. 122.5, 171.5, 220.5, 269.5,
  119340. };
  119341. static long _vq_quantmap__44c7_s_p9_1[] = {
  119342. 11, 9, 7, 5, 3, 1, 0, 2,
  119343. 4, 6, 8, 10, 12,
  119344. };
  119345. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119346. _vq_quantthresh__44c7_s_p9_1,
  119347. _vq_quantmap__44c7_s_p9_1,
  119348. 13,
  119349. 13
  119350. };
  119351. static static_codebook _44c7_s_p9_1 = {
  119352. 2, 169,
  119353. _vq_lengthlist__44c7_s_p9_1,
  119354. 1, -518889472, 1622704128, 4, 0,
  119355. _vq_quantlist__44c7_s_p9_1,
  119356. NULL,
  119357. &_vq_auxt__44c7_s_p9_1,
  119358. NULL,
  119359. 0
  119360. };
  119361. static long _vq_quantlist__44c7_s_p9_2[] = {
  119362. 24,
  119363. 23,
  119364. 25,
  119365. 22,
  119366. 26,
  119367. 21,
  119368. 27,
  119369. 20,
  119370. 28,
  119371. 19,
  119372. 29,
  119373. 18,
  119374. 30,
  119375. 17,
  119376. 31,
  119377. 16,
  119378. 32,
  119379. 15,
  119380. 33,
  119381. 14,
  119382. 34,
  119383. 13,
  119384. 35,
  119385. 12,
  119386. 36,
  119387. 11,
  119388. 37,
  119389. 10,
  119390. 38,
  119391. 9,
  119392. 39,
  119393. 8,
  119394. 40,
  119395. 7,
  119396. 41,
  119397. 6,
  119398. 42,
  119399. 5,
  119400. 43,
  119401. 4,
  119402. 44,
  119403. 3,
  119404. 45,
  119405. 2,
  119406. 46,
  119407. 1,
  119408. 47,
  119409. 0,
  119410. 48,
  119411. };
  119412. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119413. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119414. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119415. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119416. 7,
  119417. };
  119418. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119419. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119420. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119421. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119422. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119423. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119424. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119425. };
  119426. static long _vq_quantmap__44c7_s_p9_2[] = {
  119427. 47, 45, 43, 41, 39, 37, 35, 33,
  119428. 31, 29, 27, 25, 23, 21, 19, 17,
  119429. 15, 13, 11, 9, 7, 5, 3, 1,
  119430. 0, 2, 4, 6, 8, 10, 12, 14,
  119431. 16, 18, 20, 22, 24, 26, 28, 30,
  119432. 32, 34, 36, 38, 40, 42, 44, 46,
  119433. 48,
  119434. };
  119435. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119436. _vq_quantthresh__44c7_s_p9_2,
  119437. _vq_quantmap__44c7_s_p9_2,
  119438. 49,
  119439. 49
  119440. };
  119441. static static_codebook _44c7_s_p9_2 = {
  119442. 1, 49,
  119443. _vq_lengthlist__44c7_s_p9_2,
  119444. 1, -526909440, 1611661312, 6, 0,
  119445. _vq_quantlist__44c7_s_p9_2,
  119446. NULL,
  119447. &_vq_auxt__44c7_s_p9_2,
  119448. NULL,
  119449. 0
  119450. };
  119451. static long _huff_lengthlist__44c7_s_short[] = {
  119452. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119453. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119454. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119455. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119456. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119457. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119458. 10, 9,11,14,
  119459. };
  119460. static static_codebook _huff_book__44c7_s_short = {
  119461. 2, 100,
  119462. _huff_lengthlist__44c7_s_short,
  119463. 0, 0, 0, 0, 0,
  119464. NULL,
  119465. NULL,
  119466. NULL,
  119467. NULL,
  119468. 0
  119469. };
  119470. static long _huff_lengthlist__44c8_s_long[] = {
  119471. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119472. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119473. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119474. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119475. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119476. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119477. 11, 9, 9,10,
  119478. };
  119479. static static_codebook _huff_book__44c8_s_long = {
  119480. 2, 100,
  119481. _huff_lengthlist__44c8_s_long,
  119482. 0, 0, 0, 0, 0,
  119483. NULL,
  119484. NULL,
  119485. NULL,
  119486. NULL,
  119487. 0
  119488. };
  119489. static long _vq_quantlist__44c8_s_p1_0[] = {
  119490. 1,
  119491. 0,
  119492. 2,
  119493. };
  119494. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119495. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119496. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119497. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119498. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119499. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119500. 8,
  119501. };
  119502. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119503. -0.5, 0.5,
  119504. };
  119505. static long _vq_quantmap__44c8_s_p1_0[] = {
  119506. 1, 0, 2,
  119507. };
  119508. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119509. _vq_quantthresh__44c8_s_p1_0,
  119510. _vq_quantmap__44c8_s_p1_0,
  119511. 3,
  119512. 3
  119513. };
  119514. static static_codebook _44c8_s_p1_0 = {
  119515. 4, 81,
  119516. _vq_lengthlist__44c8_s_p1_0,
  119517. 1, -535822336, 1611661312, 2, 0,
  119518. _vq_quantlist__44c8_s_p1_0,
  119519. NULL,
  119520. &_vq_auxt__44c8_s_p1_0,
  119521. NULL,
  119522. 0
  119523. };
  119524. static long _vq_quantlist__44c8_s_p2_0[] = {
  119525. 2,
  119526. 1,
  119527. 3,
  119528. 0,
  119529. 4,
  119530. };
  119531. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119532. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119533. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119534. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119535. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119536. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119537. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119538. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119539. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119541. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119542. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119543. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119544. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119545. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119546. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119547. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119549. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119550. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119551. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119552. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119553. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119554. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119555. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119557. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119558. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119559. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119560. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119561. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119562. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119563. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119568. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119569. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119570. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119571. 13,
  119572. };
  119573. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119574. -1.5, -0.5, 0.5, 1.5,
  119575. };
  119576. static long _vq_quantmap__44c8_s_p2_0[] = {
  119577. 3, 1, 0, 2, 4,
  119578. };
  119579. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119580. _vq_quantthresh__44c8_s_p2_0,
  119581. _vq_quantmap__44c8_s_p2_0,
  119582. 5,
  119583. 5
  119584. };
  119585. static static_codebook _44c8_s_p2_0 = {
  119586. 4, 625,
  119587. _vq_lengthlist__44c8_s_p2_0,
  119588. 1, -533725184, 1611661312, 3, 0,
  119589. _vq_quantlist__44c8_s_p2_0,
  119590. NULL,
  119591. &_vq_auxt__44c8_s_p2_0,
  119592. NULL,
  119593. 0
  119594. };
  119595. static long _vq_quantlist__44c8_s_p3_0[] = {
  119596. 4,
  119597. 3,
  119598. 5,
  119599. 2,
  119600. 6,
  119601. 1,
  119602. 7,
  119603. 0,
  119604. 8,
  119605. };
  119606. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119607. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119608. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119609. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119610. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119612. 0,
  119613. };
  119614. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119615. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119616. };
  119617. static long _vq_quantmap__44c8_s_p3_0[] = {
  119618. 7, 5, 3, 1, 0, 2, 4, 6,
  119619. 8,
  119620. };
  119621. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119622. _vq_quantthresh__44c8_s_p3_0,
  119623. _vq_quantmap__44c8_s_p3_0,
  119624. 9,
  119625. 9
  119626. };
  119627. static static_codebook _44c8_s_p3_0 = {
  119628. 2, 81,
  119629. _vq_lengthlist__44c8_s_p3_0,
  119630. 1, -531628032, 1611661312, 4, 0,
  119631. _vq_quantlist__44c8_s_p3_0,
  119632. NULL,
  119633. &_vq_auxt__44c8_s_p3_0,
  119634. NULL,
  119635. 0
  119636. };
  119637. static long _vq_quantlist__44c8_s_p4_0[] = {
  119638. 8,
  119639. 7,
  119640. 9,
  119641. 6,
  119642. 10,
  119643. 5,
  119644. 11,
  119645. 4,
  119646. 12,
  119647. 3,
  119648. 13,
  119649. 2,
  119650. 14,
  119651. 1,
  119652. 15,
  119653. 0,
  119654. 16,
  119655. };
  119656. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119657. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119658. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119659. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119660. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119661. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119662. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119663. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119664. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119665. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119666. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119675. 0,
  119676. };
  119677. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119678. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119679. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119680. };
  119681. static long _vq_quantmap__44c8_s_p4_0[] = {
  119682. 15, 13, 11, 9, 7, 5, 3, 1,
  119683. 0, 2, 4, 6, 8, 10, 12, 14,
  119684. 16,
  119685. };
  119686. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119687. _vq_quantthresh__44c8_s_p4_0,
  119688. _vq_quantmap__44c8_s_p4_0,
  119689. 17,
  119690. 17
  119691. };
  119692. static static_codebook _44c8_s_p4_0 = {
  119693. 2, 289,
  119694. _vq_lengthlist__44c8_s_p4_0,
  119695. 1, -529530880, 1611661312, 5, 0,
  119696. _vq_quantlist__44c8_s_p4_0,
  119697. NULL,
  119698. &_vq_auxt__44c8_s_p4_0,
  119699. NULL,
  119700. 0
  119701. };
  119702. static long _vq_quantlist__44c8_s_p5_0[] = {
  119703. 1,
  119704. 0,
  119705. 2,
  119706. };
  119707. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119708. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119709. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119710. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119711. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119712. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119713. 12,
  119714. };
  119715. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119716. -5.5, 5.5,
  119717. };
  119718. static long _vq_quantmap__44c8_s_p5_0[] = {
  119719. 1, 0, 2,
  119720. };
  119721. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119722. _vq_quantthresh__44c8_s_p5_0,
  119723. _vq_quantmap__44c8_s_p5_0,
  119724. 3,
  119725. 3
  119726. };
  119727. static static_codebook _44c8_s_p5_0 = {
  119728. 4, 81,
  119729. _vq_lengthlist__44c8_s_p5_0,
  119730. 1, -529137664, 1618345984, 2, 0,
  119731. _vq_quantlist__44c8_s_p5_0,
  119732. NULL,
  119733. &_vq_auxt__44c8_s_p5_0,
  119734. NULL,
  119735. 0
  119736. };
  119737. static long _vq_quantlist__44c8_s_p5_1[] = {
  119738. 5,
  119739. 4,
  119740. 6,
  119741. 3,
  119742. 7,
  119743. 2,
  119744. 8,
  119745. 1,
  119746. 9,
  119747. 0,
  119748. 10,
  119749. };
  119750. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119751. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119752. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119753. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119754. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119755. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119756. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119757. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119758. 11,11,11, 7, 7, 7, 7, 8, 8,
  119759. };
  119760. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119761. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119762. 3.5, 4.5,
  119763. };
  119764. static long _vq_quantmap__44c8_s_p5_1[] = {
  119765. 9, 7, 5, 3, 1, 0, 2, 4,
  119766. 6, 8, 10,
  119767. };
  119768. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119769. _vq_quantthresh__44c8_s_p5_1,
  119770. _vq_quantmap__44c8_s_p5_1,
  119771. 11,
  119772. 11
  119773. };
  119774. static static_codebook _44c8_s_p5_1 = {
  119775. 2, 121,
  119776. _vq_lengthlist__44c8_s_p5_1,
  119777. 1, -531365888, 1611661312, 4, 0,
  119778. _vq_quantlist__44c8_s_p5_1,
  119779. NULL,
  119780. &_vq_auxt__44c8_s_p5_1,
  119781. NULL,
  119782. 0
  119783. };
  119784. static long _vq_quantlist__44c8_s_p6_0[] = {
  119785. 6,
  119786. 5,
  119787. 7,
  119788. 4,
  119789. 8,
  119790. 3,
  119791. 9,
  119792. 2,
  119793. 10,
  119794. 1,
  119795. 11,
  119796. 0,
  119797. 12,
  119798. };
  119799. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119800. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119801. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119802. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119803. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119804. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119805. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119810. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119811. };
  119812. static float _vq_quantthresh__44c8_s_p6_0[] = {
  119813. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119814. 12.5, 17.5, 22.5, 27.5,
  119815. };
  119816. static long _vq_quantmap__44c8_s_p6_0[] = {
  119817. 11, 9, 7, 5, 3, 1, 0, 2,
  119818. 4, 6, 8, 10, 12,
  119819. };
  119820. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  119821. _vq_quantthresh__44c8_s_p6_0,
  119822. _vq_quantmap__44c8_s_p6_0,
  119823. 13,
  119824. 13
  119825. };
  119826. static static_codebook _44c8_s_p6_0 = {
  119827. 2, 169,
  119828. _vq_lengthlist__44c8_s_p6_0,
  119829. 1, -526516224, 1616117760, 4, 0,
  119830. _vq_quantlist__44c8_s_p6_0,
  119831. NULL,
  119832. &_vq_auxt__44c8_s_p6_0,
  119833. NULL,
  119834. 0
  119835. };
  119836. static long _vq_quantlist__44c8_s_p6_1[] = {
  119837. 2,
  119838. 1,
  119839. 3,
  119840. 0,
  119841. 4,
  119842. };
  119843. static long _vq_lengthlist__44c8_s_p6_1[] = {
  119844. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119845. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119846. };
  119847. static float _vq_quantthresh__44c8_s_p6_1[] = {
  119848. -1.5, -0.5, 0.5, 1.5,
  119849. };
  119850. static long _vq_quantmap__44c8_s_p6_1[] = {
  119851. 3, 1, 0, 2, 4,
  119852. };
  119853. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  119854. _vq_quantthresh__44c8_s_p6_1,
  119855. _vq_quantmap__44c8_s_p6_1,
  119856. 5,
  119857. 5
  119858. };
  119859. static static_codebook _44c8_s_p6_1 = {
  119860. 2, 25,
  119861. _vq_lengthlist__44c8_s_p6_1,
  119862. 1, -533725184, 1611661312, 3, 0,
  119863. _vq_quantlist__44c8_s_p6_1,
  119864. NULL,
  119865. &_vq_auxt__44c8_s_p6_1,
  119866. NULL,
  119867. 0
  119868. };
  119869. static long _vq_quantlist__44c8_s_p7_0[] = {
  119870. 6,
  119871. 5,
  119872. 7,
  119873. 4,
  119874. 8,
  119875. 3,
  119876. 9,
  119877. 2,
  119878. 10,
  119879. 1,
  119880. 11,
  119881. 0,
  119882. 12,
  119883. };
  119884. static long _vq_lengthlist__44c8_s_p7_0[] = {
  119885. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  119886. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119887. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  119888. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  119889. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  119890. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  119891. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  119892. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  119893. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  119894. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  119895. 20,13,13,13,13,14,13,15,15,
  119896. };
  119897. static float _vq_quantthresh__44c8_s_p7_0[] = {
  119898. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119899. 27.5, 38.5, 49.5, 60.5,
  119900. };
  119901. static long _vq_quantmap__44c8_s_p7_0[] = {
  119902. 11, 9, 7, 5, 3, 1, 0, 2,
  119903. 4, 6, 8, 10, 12,
  119904. };
  119905. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  119906. _vq_quantthresh__44c8_s_p7_0,
  119907. _vq_quantmap__44c8_s_p7_0,
  119908. 13,
  119909. 13
  119910. };
  119911. static static_codebook _44c8_s_p7_0 = {
  119912. 2, 169,
  119913. _vq_lengthlist__44c8_s_p7_0,
  119914. 1, -523206656, 1618345984, 4, 0,
  119915. _vq_quantlist__44c8_s_p7_0,
  119916. NULL,
  119917. &_vq_auxt__44c8_s_p7_0,
  119918. NULL,
  119919. 0
  119920. };
  119921. static long _vq_quantlist__44c8_s_p7_1[] = {
  119922. 5,
  119923. 4,
  119924. 6,
  119925. 3,
  119926. 7,
  119927. 2,
  119928. 8,
  119929. 1,
  119930. 9,
  119931. 0,
  119932. 10,
  119933. };
  119934. static long _vq_lengthlist__44c8_s_p7_1[] = {
  119935. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  119936. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  119937. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119938. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119939. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119940. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119941. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119942. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119943. };
  119944. static float _vq_quantthresh__44c8_s_p7_1[] = {
  119945. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119946. 3.5, 4.5,
  119947. };
  119948. static long _vq_quantmap__44c8_s_p7_1[] = {
  119949. 9, 7, 5, 3, 1, 0, 2, 4,
  119950. 6, 8, 10,
  119951. };
  119952. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  119953. _vq_quantthresh__44c8_s_p7_1,
  119954. _vq_quantmap__44c8_s_p7_1,
  119955. 11,
  119956. 11
  119957. };
  119958. static static_codebook _44c8_s_p7_1 = {
  119959. 2, 121,
  119960. _vq_lengthlist__44c8_s_p7_1,
  119961. 1, -531365888, 1611661312, 4, 0,
  119962. _vq_quantlist__44c8_s_p7_1,
  119963. NULL,
  119964. &_vq_auxt__44c8_s_p7_1,
  119965. NULL,
  119966. 0
  119967. };
  119968. static long _vq_quantlist__44c8_s_p8_0[] = {
  119969. 7,
  119970. 6,
  119971. 8,
  119972. 5,
  119973. 9,
  119974. 4,
  119975. 10,
  119976. 3,
  119977. 11,
  119978. 2,
  119979. 12,
  119980. 1,
  119981. 13,
  119982. 0,
  119983. 14,
  119984. };
  119985. static long _vq_lengthlist__44c8_s_p8_0[] = {
  119986. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  119987. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  119988. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  119989. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  119990. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  119991. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  119992. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  119993. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  119994. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  119995. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  119996. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  119997. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119998. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  119999. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120000. 15,
  120001. };
  120002. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120003. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120004. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120005. };
  120006. static long _vq_quantmap__44c8_s_p8_0[] = {
  120007. 13, 11, 9, 7, 5, 3, 1, 0,
  120008. 2, 4, 6, 8, 10, 12, 14,
  120009. };
  120010. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120011. _vq_quantthresh__44c8_s_p8_0,
  120012. _vq_quantmap__44c8_s_p8_0,
  120013. 15,
  120014. 15
  120015. };
  120016. static static_codebook _44c8_s_p8_0 = {
  120017. 2, 225,
  120018. _vq_lengthlist__44c8_s_p8_0,
  120019. 1, -520986624, 1620377600, 4, 0,
  120020. _vq_quantlist__44c8_s_p8_0,
  120021. NULL,
  120022. &_vq_auxt__44c8_s_p8_0,
  120023. NULL,
  120024. 0
  120025. };
  120026. static long _vq_quantlist__44c8_s_p8_1[] = {
  120027. 10,
  120028. 9,
  120029. 11,
  120030. 8,
  120031. 12,
  120032. 7,
  120033. 13,
  120034. 6,
  120035. 14,
  120036. 5,
  120037. 15,
  120038. 4,
  120039. 16,
  120040. 3,
  120041. 17,
  120042. 2,
  120043. 18,
  120044. 1,
  120045. 19,
  120046. 0,
  120047. 20,
  120048. };
  120049. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120050. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120051. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120052. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120053. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120054. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120055. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120056. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120057. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120058. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120059. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120060. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120061. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120062. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120063. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120064. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120065. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120066. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120067. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120068. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120069. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120070. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120071. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120072. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120073. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120074. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120075. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120076. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120077. 10, 9, 9,10,10, 9,10, 9, 9,
  120078. };
  120079. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120080. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120081. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120082. 6.5, 7.5, 8.5, 9.5,
  120083. };
  120084. static long _vq_quantmap__44c8_s_p8_1[] = {
  120085. 19, 17, 15, 13, 11, 9, 7, 5,
  120086. 3, 1, 0, 2, 4, 6, 8, 10,
  120087. 12, 14, 16, 18, 20,
  120088. };
  120089. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120090. _vq_quantthresh__44c8_s_p8_1,
  120091. _vq_quantmap__44c8_s_p8_1,
  120092. 21,
  120093. 21
  120094. };
  120095. static static_codebook _44c8_s_p8_1 = {
  120096. 2, 441,
  120097. _vq_lengthlist__44c8_s_p8_1,
  120098. 1, -529268736, 1611661312, 5, 0,
  120099. _vq_quantlist__44c8_s_p8_1,
  120100. NULL,
  120101. &_vq_auxt__44c8_s_p8_1,
  120102. NULL,
  120103. 0
  120104. };
  120105. static long _vq_quantlist__44c8_s_p9_0[] = {
  120106. 8,
  120107. 7,
  120108. 9,
  120109. 6,
  120110. 10,
  120111. 5,
  120112. 11,
  120113. 4,
  120114. 12,
  120115. 3,
  120116. 13,
  120117. 2,
  120118. 14,
  120119. 1,
  120120. 15,
  120121. 0,
  120122. 16,
  120123. };
  120124. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120125. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120126. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120127. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120128. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120129. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120130. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120131. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120132. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120133. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120134. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120135. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120136. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120137. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120138. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120139. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120140. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120141. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120142. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120143. 10,
  120144. };
  120145. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120146. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120147. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120148. };
  120149. static long _vq_quantmap__44c8_s_p9_0[] = {
  120150. 15, 13, 11, 9, 7, 5, 3, 1,
  120151. 0, 2, 4, 6, 8, 10, 12, 14,
  120152. 16,
  120153. };
  120154. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120155. _vq_quantthresh__44c8_s_p9_0,
  120156. _vq_quantmap__44c8_s_p9_0,
  120157. 17,
  120158. 17
  120159. };
  120160. static static_codebook _44c8_s_p9_0 = {
  120161. 2, 289,
  120162. _vq_lengthlist__44c8_s_p9_0,
  120163. 1, -509798400, 1631393792, 5, 0,
  120164. _vq_quantlist__44c8_s_p9_0,
  120165. NULL,
  120166. &_vq_auxt__44c8_s_p9_0,
  120167. NULL,
  120168. 0
  120169. };
  120170. static long _vq_quantlist__44c8_s_p9_1[] = {
  120171. 9,
  120172. 8,
  120173. 10,
  120174. 7,
  120175. 11,
  120176. 6,
  120177. 12,
  120178. 5,
  120179. 13,
  120180. 4,
  120181. 14,
  120182. 3,
  120183. 15,
  120184. 2,
  120185. 16,
  120186. 1,
  120187. 17,
  120188. 0,
  120189. 18,
  120190. };
  120191. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120192. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120193. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120194. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120195. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120196. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120197. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120198. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120199. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120200. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120201. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120202. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120203. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120204. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120205. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120206. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120207. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120208. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120209. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120210. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120211. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120212. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120213. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120214. 14,13,13,14,14,15,14,15,14,
  120215. };
  120216. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120217. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120218. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120219. 367.5, 416.5,
  120220. };
  120221. static long _vq_quantmap__44c8_s_p9_1[] = {
  120222. 17, 15, 13, 11, 9, 7, 5, 3,
  120223. 1, 0, 2, 4, 6, 8, 10, 12,
  120224. 14, 16, 18,
  120225. };
  120226. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120227. _vq_quantthresh__44c8_s_p9_1,
  120228. _vq_quantmap__44c8_s_p9_1,
  120229. 19,
  120230. 19
  120231. };
  120232. static static_codebook _44c8_s_p9_1 = {
  120233. 2, 361,
  120234. _vq_lengthlist__44c8_s_p9_1,
  120235. 1, -518287360, 1622704128, 5, 0,
  120236. _vq_quantlist__44c8_s_p9_1,
  120237. NULL,
  120238. &_vq_auxt__44c8_s_p9_1,
  120239. NULL,
  120240. 0
  120241. };
  120242. static long _vq_quantlist__44c8_s_p9_2[] = {
  120243. 24,
  120244. 23,
  120245. 25,
  120246. 22,
  120247. 26,
  120248. 21,
  120249. 27,
  120250. 20,
  120251. 28,
  120252. 19,
  120253. 29,
  120254. 18,
  120255. 30,
  120256. 17,
  120257. 31,
  120258. 16,
  120259. 32,
  120260. 15,
  120261. 33,
  120262. 14,
  120263. 34,
  120264. 13,
  120265. 35,
  120266. 12,
  120267. 36,
  120268. 11,
  120269. 37,
  120270. 10,
  120271. 38,
  120272. 9,
  120273. 39,
  120274. 8,
  120275. 40,
  120276. 7,
  120277. 41,
  120278. 6,
  120279. 42,
  120280. 5,
  120281. 43,
  120282. 4,
  120283. 44,
  120284. 3,
  120285. 45,
  120286. 2,
  120287. 46,
  120288. 1,
  120289. 47,
  120290. 0,
  120291. 48,
  120292. };
  120293. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120294. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120295. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120296. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120297. 7,
  120298. };
  120299. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120300. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120301. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120302. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120303. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120304. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120305. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120306. };
  120307. static long _vq_quantmap__44c8_s_p9_2[] = {
  120308. 47, 45, 43, 41, 39, 37, 35, 33,
  120309. 31, 29, 27, 25, 23, 21, 19, 17,
  120310. 15, 13, 11, 9, 7, 5, 3, 1,
  120311. 0, 2, 4, 6, 8, 10, 12, 14,
  120312. 16, 18, 20, 22, 24, 26, 28, 30,
  120313. 32, 34, 36, 38, 40, 42, 44, 46,
  120314. 48,
  120315. };
  120316. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120317. _vq_quantthresh__44c8_s_p9_2,
  120318. _vq_quantmap__44c8_s_p9_2,
  120319. 49,
  120320. 49
  120321. };
  120322. static static_codebook _44c8_s_p9_2 = {
  120323. 1, 49,
  120324. _vq_lengthlist__44c8_s_p9_2,
  120325. 1, -526909440, 1611661312, 6, 0,
  120326. _vq_quantlist__44c8_s_p9_2,
  120327. NULL,
  120328. &_vq_auxt__44c8_s_p9_2,
  120329. NULL,
  120330. 0
  120331. };
  120332. static long _huff_lengthlist__44c8_s_short[] = {
  120333. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120334. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120335. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120336. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120337. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120338. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120339. 10, 9,11,14,
  120340. };
  120341. static static_codebook _huff_book__44c8_s_short = {
  120342. 2, 100,
  120343. _huff_lengthlist__44c8_s_short,
  120344. 0, 0, 0, 0, 0,
  120345. NULL,
  120346. NULL,
  120347. NULL,
  120348. NULL,
  120349. 0
  120350. };
  120351. static long _huff_lengthlist__44c9_s_long[] = {
  120352. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120353. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120354. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120355. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120356. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120357. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120358. 10, 9, 8, 9,
  120359. };
  120360. static static_codebook _huff_book__44c9_s_long = {
  120361. 2, 100,
  120362. _huff_lengthlist__44c9_s_long,
  120363. 0, 0, 0, 0, 0,
  120364. NULL,
  120365. NULL,
  120366. NULL,
  120367. NULL,
  120368. 0
  120369. };
  120370. static long _vq_quantlist__44c9_s_p1_0[] = {
  120371. 1,
  120372. 0,
  120373. 2,
  120374. };
  120375. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120376. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120377. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120378. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120379. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120380. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120381. 7,
  120382. };
  120383. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120384. -0.5, 0.5,
  120385. };
  120386. static long _vq_quantmap__44c9_s_p1_0[] = {
  120387. 1, 0, 2,
  120388. };
  120389. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120390. _vq_quantthresh__44c9_s_p1_0,
  120391. _vq_quantmap__44c9_s_p1_0,
  120392. 3,
  120393. 3
  120394. };
  120395. static static_codebook _44c9_s_p1_0 = {
  120396. 4, 81,
  120397. _vq_lengthlist__44c9_s_p1_0,
  120398. 1, -535822336, 1611661312, 2, 0,
  120399. _vq_quantlist__44c9_s_p1_0,
  120400. NULL,
  120401. &_vq_auxt__44c9_s_p1_0,
  120402. NULL,
  120403. 0
  120404. };
  120405. static long _vq_quantlist__44c9_s_p2_0[] = {
  120406. 2,
  120407. 1,
  120408. 3,
  120409. 0,
  120410. 4,
  120411. };
  120412. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120413. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120414. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120415. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120416. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120417. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120418. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120419. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120420. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120422. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120423. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120424. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120425. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120426. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120427. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120428. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120430. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120431. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120432. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120433. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120434. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120435. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120436. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120438. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120439. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120440. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120441. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120442. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120443. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120444. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120449. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120450. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120451. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120452. 12,
  120453. };
  120454. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120455. -1.5, -0.5, 0.5, 1.5,
  120456. };
  120457. static long _vq_quantmap__44c9_s_p2_0[] = {
  120458. 3, 1, 0, 2, 4,
  120459. };
  120460. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120461. _vq_quantthresh__44c9_s_p2_0,
  120462. _vq_quantmap__44c9_s_p2_0,
  120463. 5,
  120464. 5
  120465. };
  120466. static static_codebook _44c9_s_p2_0 = {
  120467. 4, 625,
  120468. _vq_lengthlist__44c9_s_p2_0,
  120469. 1, -533725184, 1611661312, 3, 0,
  120470. _vq_quantlist__44c9_s_p2_0,
  120471. NULL,
  120472. &_vq_auxt__44c9_s_p2_0,
  120473. NULL,
  120474. 0
  120475. };
  120476. static long _vq_quantlist__44c9_s_p3_0[] = {
  120477. 4,
  120478. 3,
  120479. 5,
  120480. 2,
  120481. 6,
  120482. 1,
  120483. 7,
  120484. 0,
  120485. 8,
  120486. };
  120487. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120488. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120489. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120490. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120491. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120493. 0,
  120494. };
  120495. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120496. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120497. };
  120498. static long _vq_quantmap__44c9_s_p3_0[] = {
  120499. 7, 5, 3, 1, 0, 2, 4, 6,
  120500. 8,
  120501. };
  120502. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120503. _vq_quantthresh__44c9_s_p3_0,
  120504. _vq_quantmap__44c9_s_p3_0,
  120505. 9,
  120506. 9
  120507. };
  120508. static static_codebook _44c9_s_p3_0 = {
  120509. 2, 81,
  120510. _vq_lengthlist__44c9_s_p3_0,
  120511. 1, -531628032, 1611661312, 4, 0,
  120512. _vq_quantlist__44c9_s_p3_0,
  120513. NULL,
  120514. &_vq_auxt__44c9_s_p3_0,
  120515. NULL,
  120516. 0
  120517. };
  120518. static long _vq_quantlist__44c9_s_p4_0[] = {
  120519. 8,
  120520. 7,
  120521. 9,
  120522. 6,
  120523. 10,
  120524. 5,
  120525. 11,
  120526. 4,
  120527. 12,
  120528. 3,
  120529. 13,
  120530. 2,
  120531. 14,
  120532. 1,
  120533. 15,
  120534. 0,
  120535. 16,
  120536. };
  120537. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120538. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120539. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120540. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120541. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120542. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120543. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120544. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120545. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120546. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120547. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120556. 0,
  120557. };
  120558. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120559. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120560. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120561. };
  120562. static long _vq_quantmap__44c9_s_p4_0[] = {
  120563. 15, 13, 11, 9, 7, 5, 3, 1,
  120564. 0, 2, 4, 6, 8, 10, 12, 14,
  120565. 16,
  120566. };
  120567. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120568. _vq_quantthresh__44c9_s_p4_0,
  120569. _vq_quantmap__44c9_s_p4_0,
  120570. 17,
  120571. 17
  120572. };
  120573. static static_codebook _44c9_s_p4_0 = {
  120574. 2, 289,
  120575. _vq_lengthlist__44c9_s_p4_0,
  120576. 1, -529530880, 1611661312, 5, 0,
  120577. _vq_quantlist__44c9_s_p4_0,
  120578. NULL,
  120579. &_vq_auxt__44c9_s_p4_0,
  120580. NULL,
  120581. 0
  120582. };
  120583. static long _vq_quantlist__44c9_s_p5_0[] = {
  120584. 1,
  120585. 0,
  120586. 2,
  120587. };
  120588. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120589. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120590. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120591. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120592. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120593. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120594. 12,
  120595. };
  120596. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120597. -5.5, 5.5,
  120598. };
  120599. static long _vq_quantmap__44c9_s_p5_0[] = {
  120600. 1, 0, 2,
  120601. };
  120602. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120603. _vq_quantthresh__44c9_s_p5_0,
  120604. _vq_quantmap__44c9_s_p5_0,
  120605. 3,
  120606. 3
  120607. };
  120608. static static_codebook _44c9_s_p5_0 = {
  120609. 4, 81,
  120610. _vq_lengthlist__44c9_s_p5_0,
  120611. 1, -529137664, 1618345984, 2, 0,
  120612. _vq_quantlist__44c9_s_p5_0,
  120613. NULL,
  120614. &_vq_auxt__44c9_s_p5_0,
  120615. NULL,
  120616. 0
  120617. };
  120618. static long _vq_quantlist__44c9_s_p5_1[] = {
  120619. 5,
  120620. 4,
  120621. 6,
  120622. 3,
  120623. 7,
  120624. 2,
  120625. 8,
  120626. 1,
  120627. 9,
  120628. 0,
  120629. 10,
  120630. };
  120631. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120632. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120633. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120634. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120635. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120636. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120637. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120638. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120639. 11,11,11, 7, 7, 7, 7, 7, 7,
  120640. };
  120641. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120642. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120643. 3.5, 4.5,
  120644. };
  120645. static long _vq_quantmap__44c9_s_p5_1[] = {
  120646. 9, 7, 5, 3, 1, 0, 2, 4,
  120647. 6, 8, 10,
  120648. };
  120649. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120650. _vq_quantthresh__44c9_s_p5_1,
  120651. _vq_quantmap__44c9_s_p5_1,
  120652. 11,
  120653. 11
  120654. };
  120655. static static_codebook _44c9_s_p5_1 = {
  120656. 2, 121,
  120657. _vq_lengthlist__44c9_s_p5_1,
  120658. 1, -531365888, 1611661312, 4, 0,
  120659. _vq_quantlist__44c9_s_p5_1,
  120660. NULL,
  120661. &_vq_auxt__44c9_s_p5_1,
  120662. NULL,
  120663. 0
  120664. };
  120665. static long _vq_quantlist__44c9_s_p6_0[] = {
  120666. 6,
  120667. 5,
  120668. 7,
  120669. 4,
  120670. 8,
  120671. 3,
  120672. 9,
  120673. 2,
  120674. 10,
  120675. 1,
  120676. 11,
  120677. 0,
  120678. 12,
  120679. };
  120680. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120681. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120682. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120683. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120684. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120685. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120686. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120691. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120692. };
  120693. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120694. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120695. 12.5, 17.5, 22.5, 27.5,
  120696. };
  120697. static long _vq_quantmap__44c9_s_p6_0[] = {
  120698. 11, 9, 7, 5, 3, 1, 0, 2,
  120699. 4, 6, 8, 10, 12,
  120700. };
  120701. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120702. _vq_quantthresh__44c9_s_p6_0,
  120703. _vq_quantmap__44c9_s_p6_0,
  120704. 13,
  120705. 13
  120706. };
  120707. static static_codebook _44c9_s_p6_0 = {
  120708. 2, 169,
  120709. _vq_lengthlist__44c9_s_p6_0,
  120710. 1, -526516224, 1616117760, 4, 0,
  120711. _vq_quantlist__44c9_s_p6_0,
  120712. NULL,
  120713. &_vq_auxt__44c9_s_p6_0,
  120714. NULL,
  120715. 0
  120716. };
  120717. static long _vq_quantlist__44c9_s_p6_1[] = {
  120718. 2,
  120719. 1,
  120720. 3,
  120721. 0,
  120722. 4,
  120723. };
  120724. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120725. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120726. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120727. };
  120728. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120729. -1.5, -0.5, 0.5, 1.5,
  120730. };
  120731. static long _vq_quantmap__44c9_s_p6_1[] = {
  120732. 3, 1, 0, 2, 4,
  120733. };
  120734. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120735. _vq_quantthresh__44c9_s_p6_1,
  120736. _vq_quantmap__44c9_s_p6_1,
  120737. 5,
  120738. 5
  120739. };
  120740. static static_codebook _44c9_s_p6_1 = {
  120741. 2, 25,
  120742. _vq_lengthlist__44c9_s_p6_1,
  120743. 1, -533725184, 1611661312, 3, 0,
  120744. _vq_quantlist__44c9_s_p6_1,
  120745. NULL,
  120746. &_vq_auxt__44c9_s_p6_1,
  120747. NULL,
  120748. 0
  120749. };
  120750. static long _vq_quantlist__44c9_s_p7_0[] = {
  120751. 6,
  120752. 5,
  120753. 7,
  120754. 4,
  120755. 8,
  120756. 3,
  120757. 9,
  120758. 2,
  120759. 10,
  120760. 1,
  120761. 11,
  120762. 0,
  120763. 12,
  120764. };
  120765. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120766. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120767. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120768. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120769. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120770. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120771. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120772. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120773. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120774. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120775. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120776. 19,12,12,12,12,13,13,14,14,
  120777. };
  120778. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120779. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120780. 27.5, 38.5, 49.5, 60.5,
  120781. };
  120782. static long _vq_quantmap__44c9_s_p7_0[] = {
  120783. 11, 9, 7, 5, 3, 1, 0, 2,
  120784. 4, 6, 8, 10, 12,
  120785. };
  120786. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120787. _vq_quantthresh__44c9_s_p7_0,
  120788. _vq_quantmap__44c9_s_p7_0,
  120789. 13,
  120790. 13
  120791. };
  120792. static static_codebook _44c9_s_p7_0 = {
  120793. 2, 169,
  120794. _vq_lengthlist__44c9_s_p7_0,
  120795. 1, -523206656, 1618345984, 4, 0,
  120796. _vq_quantlist__44c9_s_p7_0,
  120797. NULL,
  120798. &_vq_auxt__44c9_s_p7_0,
  120799. NULL,
  120800. 0
  120801. };
  120802. static long _vq_quantlist__44c9_s_p7_1[] = {
  120803. 5,
  120804. 4,
  120805. 6,
  120806. 3,
  120807. 7,
  120808. 2,
  120809. 8,
  120810. 1,
  120811. 9,
  120812. 0,
  120813. 10,
  120814. };
  120815. static long _vq_lengthlist__44c9_s_p7_1[] = {
  120816. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  120817. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120818. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  120819. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120820. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120821. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120822. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120823. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120824. };
  120825. static float _vq_quantthresh__44c9_s_p7_1[] = {
  120826. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120827. 3.5, 4.5,
  120828. };
  120829. static long _vq_quantmap__44c9_s_p7_1[] = {
  120830. 9, 7, 5, 3, 1, 0, 2, 4,
  120831. 6, 8, 10,
  120832. };
  120833. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  120834. _vq_quantthresh__44c9_s_p7_1,
  120835. _vq_quantmap__44c9_s_p7_1,
  120836. 11,
  120837. 11
  120838. };
  120839. static static_codebook _44c9_s_p7_1 = {
  120840. 2, 121,
  120841. _vq_lengthlist__44c9_s_p7_1,
  120842. 1, -531365888, 1611661312, 4, 0,
  120843. _vq_quantlist__44c9_s_p7_1,
  120844. NULL,
  120845. &_vq_auxt__44c9_s_p7_1,
  120846. NULL,
  120847. 0
  120848. };
  120849. static long _vq_quantlist__44c9_s_p8_0[] = {
  120850. 7,
  120851. 6,
  120852. 8,
  120853. 5,
  120854. 9,
  120855. 4,
  120856. 10,
  120857. 3,
  120858. 11,
  120859. 2,
  120860. 12,
  120861. 1,
  120862. 13,
  120863. 0,
  120864. 14,
  120865. };
  120866. static long _vq_lengthlist__44c9_s_p8_0[] = {
  120867. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  120868. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  120869. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  120870. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  120871. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  120872. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  120873. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  120874. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  120875. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  120876. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  120877. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  120878. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  120879. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  120880. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  120881. 14,
  120882. };
  120883. static float _vq_quantthresh__44c9_s_p8_0[] = {
  120884. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120885. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120886. };
  120887. static long _vq_quantmap__44c9_s_p8_0[] = {
  120888. 13, 11, 9, 7, 5, 3, 1, 0,
  120889. 2, 4, 6, 8, 10, 12, 14,
  120890. };
  120891. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  120892. _vq_quantthresh__44c9_s_p8_0,
  120893. _vq_quantmap__44c9_s_p8_0,
  120894. 15,
  120895. 15
  120896. };
  120897. static static_codebook _44c9_s_p8_0 = {
  120898. 2, 225,
  120899. _vq_lengthlist__44c9_s_p8_0,
  120900. 1, -520986624, 1620377600, 4, 0,
  120901. _vq_quantlist__44c9_s_p8_0,
  120902. NULL,
  120903. &_vq_auxt__44c9_s_p8_0,
  120904. NULL,
  120905. 0
  120906. };
  120907. static long _vq_quantlist__44c9_s_p8_1[] = {
  120908. 10,
  120909. 9,
  120910. 11,
  120911. 8,
  120912. 12,
  120913. 7,
  120914. 13,
  120915. 6,
  120916. 14,
  120917. 5,
  120918. 15,
  120919. 4,
  120920. 16,
  120921. 3,
  120922. 17,
  120923. 2,
  120924. 18,
  120925. 1,
  120926. 19,
  120927. 0,
  120928. 20,
  120929. };
  120930. static long _vq_lengthlist__44c9_s_p8_1[] = {
  120931. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120932. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120933. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120934. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120935. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120936. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120937. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  120938. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120939. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120940. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120941. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120942. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120943. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120944. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120945. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120946. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  120947. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  120948. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  120949. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  120950. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  120951. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  120952. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  120953. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  120954. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  120955. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  120956. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  120957. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  120958. 9, 9, 9,10, 9, 9, 9, 9, 9,
  120959. };
  120960. static float _vq_quantthresh__44c9_s_p8_1[] = {
  120961. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120962. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120963. 6.5, 7.5, 8.5, 9.5,
  120964. };
  120965. static long _vq_quantmap__44c9_s_p8_1[] = {
  120966. 19, 17, 15, 13, 11, 9, 7, 5,
  120967. 3, 1, 0, 2, 4, 6, 8, 10,
  120968. 12, 14, 16, 18, 20,
  120969. };
  120970. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  120971. _vq_quantthresh__44c9_s_p8_1,
  120972. _vq_quantmap__44c9_s_p8_1,
  120973. 21,
  120974. 21
  120975. };
  120976. static static_codebook _44c9_s_p8_1 = {
  120977. 2, 441,
  120978. _vq_lengthlist__44c9_s_p8_1,
  120979. 1, -529268736, 1611661312, 5, 0,
  120980. _vq_quantlist__44c9_s_p8_1,
  120981. NULL,
  120982. &_vq_auxt__44c9_s_p8_1,
  120983. NULL,
  120984. 0
  120985. };
  120986. static long _vq_quantlist__44c9_s_p9_0[] = {
  120987. 9,
  120988. 8,
  120989. 10,
  120990. 7,
  120991. 11,
  120992. 6,
  120993. 12,
  120994. 5,
  120995. 13,
  120996. 4,
  120997. 14,
  120998. 3,
  120999. 15,
  121000. 2,
  121001. 16,
  121002. 1,
  121003. 17,
  121004. 0,
  121005. 18,
  121006. };
  121007. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121008. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121009. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121010. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121011. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121012. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121013. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121014. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121015. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121016. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121017. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121018. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121019. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121020. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121021. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121022. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121023. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121024. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121025. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121026. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121027. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121028. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121029. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121030. 11,11,11,11,11,11,11,11,11,
  121031. };
  121032. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121033. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121034. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121035. 6982.5, 7913.5,
  121036. };
  121037. static long _vq_quantmap__44c9_s_p9_0[] = {
  121038. 17, 15, 13, 11, 9, 7, 5, 3,
  121039. 1, 0, 2, 4, 6, 8, 10, 12,
  121040. 14, 16, 18,
  121041. };
  121042. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121043. _vq_quantthresh__44c9_s_p9_0,
  121044. _vq_quantmap__44c9_s_p9_0,
  121045. 19,
  121046. 19
  121047. };
  121048. static static_codebook _44c9_s_p9_0 = {
  121049. 2, 361,
  121050. _vq_lengthlist__44c9_s_p9_0,
  121051. 1, -508535424, 1631393792, 5, 0,
  121052. _vq_quantlist__44c9_s_p9_0,
  121053. NULL,
  121054. &_vq_auxt__44c9_s_p9_0,
  121055. NULL,
  121056. 0
  121057. };
  121058. static long _vq_quantlist__44c9_s_p9_1[] = {
  121059. 9,
  121060. 8,
  121061. 10,
  121062. 7,
  121063. 11,
  121064. 6,
  121065. 12,
  121066. 5,
  121067. 13,
  121068. 4,
  121069. 14,
  121070. 3,
  121071. 15,
  121072. 2,
  121073. 16,
  121074. 1,
  121075. 17,
  121076. 0,
  121077. 18,
  121078. };
  121079. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121080. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121081. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121082. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121083. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121084. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121085. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121086. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121087. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121088. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121089. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121090. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121091. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121092. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121093. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121094. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121095. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121096. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121097. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121098. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121099. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121100. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121101. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121102. 13,13,13,14,13,14,15,15,15,
  121103. };
  121104. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121105. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121106. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121107. 367.5, 416.5,
  121108. };
  121109. static long _vq_quantmap__44c9_s_p9_1[] = {
  121110. 17, 15, 13, 11, 9, 7, 5, 3,
  121111. 1, 0, 2, 4, 6, 8, 10, 12,
  121112. 14, 16, 18,
  121113. };
  121114. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121115. _vq_quantthresh__44c9_s_p9_1,
  121116. _vq_quantmap__44c9_s_p9_1,
  121117. 19,
  121118. 19
  121119. };
  121120. static static_codebook _44c9_s_p9_1 = {
  121121. 2, 361,
  121122. _vq_lengthlist__44c9_s_p9_1,
  121123. 1, -518287360, 1622704128, 5, 0,
  121124. _vq_quantlist__44c9_s_p9_1,
  121125. NULL,
  121126. &_vq_auxt__44c9_s_p9_1,
  121127. NULL,
  121128. 0
  121129. };
  121130. static long _vq_quantlist__44c9_s_p9_2[] = {
  121131. 24,
  121132. 23,
  121133. 25,
  121134. 22,
  121135. 26,
  121136. 21,
  121137. 27,
  121138. 20,
  121139. 28,
  121140. 19,
  121141. 29,
  121142. 18,
  121143. 30,
  121144. 17,
  121145. 31,
  121146. 16,
  121147. 32,
  121148. 15,
  121149. 33,
  121150. 14,
  121151. 34,
  121152. 13,
  121153. 35,
  121154. 12,
  121155. 36,
  121156. 11,
  121157. 37,
  121158. 10,
  121159. 38,
  121160. 9,
  121161. 39,
  121162. 8,
  121163. 40,
  121164. 7,
  121165. 41,
  121166. 6,
  121167. 42,
  121168. 5,
  121169. 43,
  121170. 4,
  121171. 44,
  121172. 3,
  121173. 45,
  121174. 2,
  121175. 46,
  121176. 1,
  121177. 47,
  121178. 0,
  121179. 48,
  121180. };
  121181. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121182. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121183. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121184. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121185. 7,
  121186. };
  121187. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121188. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121189. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121190. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121191. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121192. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121193. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121194. };
  121195. static long _vq_quantmap__44c9_s_p9_2[] = {
  121196. 47, 45, 43, 41, 39, 37, 35, 33,
  121197. 31, 29, 27, 25, 23, 21, 19, 17,
  121198. 15, 13, 11, 9, 7, 5, 3, 1,
  121199. 0, 2, 4, 6, 8, 10, 12, 14,
  121200. 16, 18, 20, 22, 24, 26, 28, 30,
  121201. 32, 34, 36, 38, 40, 42, 44, 46,
  121202. 48,
  121203. };
  121204. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121205. _vq_quantthresh__44c9_s_p9_2,
  121206. _vq_quantmap__44c9_s_p9_2,
  121207. 49,
  121208. 49
  121209. };
  121210. static static_codebook _44c9_s_p9_2 = {
  121211. 1, 49,
  121212. _vq_lengthlist__44c9_s_p9_2,
  121213. 1, -526909440, 1611661312, 6, 0,
  121214. _vq_quantlist__44c9_s_p9_2,
  121215. NULL,
  121216. &_vq_auxt__44c9_s_p9_2,
  121217. NULL,
  121218. 0
  121219. };
  121220. static long _huff_lengthlist__44c9_s_short[] = {
  121221. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121222. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121223. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121224. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121225. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121226. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121227. 9, 8,10,13,
  121228. };
  121229. static static_codebook _huff_book__44c9_s_short = {
  121230. 2, 100,
  121231. _huff_lengthlist__44c9_s_short,
  121232. 0, 0, 0, 0, 0,
  121233. NULL,
  121234. NULL,
  121235. NULL,
  121236. NULL,
  121237. 0
  121238. };
  121239. static long _huff_lengthlist__44c0_s_long[] = {
  121240. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121241. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121242. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121243. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121244. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121245. 12,
  121246. };
  121247. static static_codebook _huff_book__44c0_s_long = {
  121248. 2, 81,
  121249. _huff_lengthlist__44c0_s_long,
  121250. 0, 0, 0, 0, 0,
  121251. NULL,
  121252. NULL,
  121253. NULL,
  121254. NULL,
  121255. 0
  121256. };
  121257. static long _vq_quantlist__44c0_s_p1_0[] = {
  121258. 1,
  121259. 0,
  121260. 2,
  121261. };
  121262. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121263. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121264. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121268. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121269. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121273. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121274. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121309. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121314. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121319. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121354. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121355. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121359. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121360. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  121361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121364. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121365. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121673. 0,
  121674. };
  121675. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121676. -0.5, 0.5,
  121677. };
  121678. static long _vq_quantmap__44c0_s_p1_0[] = {
  121679. 1, 0, 2,
  121680. };
  121681. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121682. _vq_quantthresh__44c0_s_p1_0,
  121683. _vq_quantmap__44c0_s_p1_0,
  121684. 3,
  121685. 3
  121686. };
  121687. static static_codebook _44c0_s_p1_0 = {
  121688. 8, 6561,
  121689. _vq_lengthlist__44c0_s_p1_0,
  121690. 1, -535822336, 1611661312, 2, 0,
  121691. _vq_quantlist__44c0_s_p1_0,
  121692. NULL,
  121693. &_vq_auxt__44c0_s_p1_0,
  121694. NULL,
  121695. 0
  121696. };
  121697. static long _vq_quantlist__44c0_s_p2_0[] = {
  121698. 2,
  121699. 1,
  121700. 3,
  121701. 0,
  121702. 4,
  121703. };
  121704. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121705. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121708. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121711. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  121712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121744. 0,
  121745. };
  121746. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121747. -1.5, -0.5, 0.5, 1.5,
  121748. };
  121749. static long _vq_quantmap__44c0_s_p2_0[] = {
  121750. 3, 1, 0, 2, 4,
  121751. };
  121752. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121753. _vq_quantthresh__44c0_s_p2_0,
  121754. _vq_quantmap__44c0_s_p2_0,
  121755. 5,
  121756. 5
  121757. };
  121758. static static_codebook _44c0_s_p2_0 = {
  121759. 4, 625,
  121760. _vq_lengthlist__44c0_s_p2_0,
  121761. 1, -533725184, 1611661312, 3, 0,
  121762. _vq_quantlist__44c0_s_p2_0,
  121763. NULL,
  121764. &_vq_auxt__44c0_s_p2_0,
  121765. NULL,
  121766. 0
  121767. };
  121768. static long _vq_quantlist__44c0_s_p3_0[] = {
  121769. 4,
  121770. 3,
  121771. 5,
  121772. 2,
  121773. 6,
  121774. 1,
  121775. 7,
  121776. 0,
  121777. 8,
  121778. };
  121779. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121780. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121781. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121782. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121783. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121784. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121785. 0,
  121786. };
  121787. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121788. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121789. };
  121790. static long _vq_quantmap__44c0_s_p3_0[] = {
  121791. 7, 5, 3, 1, 0, 2, 4, 6,
  121792. 8,
  121793. };
  121794. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121795. _vq_quantthresh__44c0_s_p3_0,
  121796. _vq_quantmap__44c0_s_p3_0,
  121797. 9,
  121798. 9
  121799. };
  121800. static static_codebook _44c0_s_p3_0 = {
  121801. 2, 81,
  121802. _vq_lengthlist__44c0_s_p3_0,
  121803. 1, -531628032, 1611661312, 4, 0,
  121804. _vq_quantlist__44c0_s_p3_0,
  121805. NULL,
  121806. &_vq_auxt__44c0_s_p3_0,
  121807. NULL,
  121808. 0
  121809. };
  121810. static long _vq_quantlist__44c0_s_p4_0[] = {
  121811. 4,
  121812. 3,
  121813. 5,
  121814. 2,
  121815. 6,
  121816. 1,
  121817. 7,
  121818. 0,
  121819. 8,
  121820. };
  121821. static long _vq_lengthlist__44c0_s_p4_0[] = {
  121822. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  121823. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  121824. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  121825. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  121826. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  121827. 10,
  121828. };
  121829. static float _vq_quantthresh__44c0_s_p4_0[] = {
  121830. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121831. };
  121832. static long _vq_quantmap__44c0_s_p4_0[] = {
  121833. 7, 5, 3, 1, 0, 2, 4, 6,
  121834. 8,
  121835. };
  121836. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  121837. _vq_quantthresh__44c0_s_p4_0,
  121838. _vq_quantmap__44c0_s_p4_0,
  121839. 9,
  121840. 9
  121841. };
  121842. static static_codebook _44c0_s_p4_0 = {
  121843. 2, 81,
  121844. _vq_lengthlist__44c0_s_p4_0,
  121845. 1, -531628032, 1611661312, 4, 0,
  121846. _vq_quantlist__44c0_s_p4_0,
  121847. NULL,
  121848. &_vq_auxt__44c0_s_p4_0,
  121849. NULL,
  121850. 0
  121851. };
  121852. static long _vq_quantlist__44c0_s_p5_0[] = {
  121853. 8,
  121854. 7,
  121855. 9,
  121856. 6,
  121857. 10,
  121858. 5,
  121859. 11,
  121860. 4,
  121861. 12,
  121862. 3,
  121863. 13,
  121864. 2,
  121865. 14,
  121866. 1,
  121867. 15,
  121868. 0,
  121869. 16,
  121870. };
  121871. static long _vq_lengthlist__44c0_s_p5_0[] = {
  121872. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  121873. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  121874. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  121875. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  121876. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  121877. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  121878. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  121879. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  121880. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  121881. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  121882. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  121883. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  121884. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  121885. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  121886. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  121887. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  121888. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  121889. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  121890. 14,
  121891. };
  121892. static float _vq_quantthresh__44c0_s_p5_0[] = {
  121893. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121894. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121895. };
  121896. static long _vq_quantmap__44c0_s_p5_0[] = {
  121897. 15, 13, 11, 9, 7, 5, 3, 1,
  121898. 0, 2, 4, 6, 8, 10, 12, 14,
  121899. 16,
  121900. };
  121901. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  121902. _vq_quantthresh__44c0_s_p5_0,
  121903. _vq_quantmap__44c0_s_p5_0,
  121904. 17,
  121905. 17
  121906. };
  121907. static static_codebook _44c0_s_p5_0 = {
  121908. 2, 289,
  121909. _vq_lengthlist__44c0_s_p5_0,
  121910. 1, -529530880, 1611661312, 5, 0,
  121911. _vq_quantlist__44c0_s_p5_0,
  121912. NULL,
  121913. &_vq_auxt__44c0_s_p5_0,
  121914. NULL,
  121915. 0
  121916. };
  121917. static long _vq_quantlist__44c0_s_p6_0[] = {
  121918. 1,
  121919. 0,
  121920. 2,
  121921. };
  121922. static long _vq_lengthlist__44c0_s_p6_0[] = {
  121923. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  121924. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  121925. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  121926. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  121927. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  121928. 10,
  121929. };
  121930. static float _vq_quantthresh__44c0_s_p6_0[] = {
  121931. -5.5, 5.5,
  121932. };
  121933. static long _vq_quantmap__44c0_s_p6_0[] = {
  121934. 1, 0, 2,
  121935. };
  121936. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  121937. _vq_quantthresh__44c0_s_p6_0,
  121938. _vq_quantmap__44c0_s_p6_0,
  121939. 3,
  121940. 3
  121941. };
  121942. static static_codebook _44c0_s_p6_0 = {
  121943. 4, 81,
  121944. _vq_lengthlist__44c0_s_p6_0,
  121945. 1, -529137664, 1618345984, 2, 0,
  121946. _vq_quantlist__44c0_s_p6_0,
  121947. NULL,
  121948. &_vq_auxt__44c0_s_p6_0,
  121949. NULL,
  121950. 0
  121951. };
  121952. static long _vq_quantlist__44c0_s_p6_1[] = {
  121953. 5,
  121954. 4,
  121955. 6,
  121956. 3,
  121957. 7,
  121958. 2,
  121959. 8,
  121960. 1,
  121961. 9,
  121962. 0,
  121963. 10,
  121964. };
  121965. static long _vq_lengthlist__44c0_s_p6_1[] = {
  121966. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  121967. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  121968. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  121969. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  121970. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  121971. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  121972. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  121973. 10,10,10, 8, 8, 8, 8, 8, 8,
  121974. };
  121975. static float _vq_quantthresh__44c0_s_p6_1[] = {
  121976. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121977. 3.5, 4.5,
  121978. };
  121979. static long _vq_quantmap__44c0_s_p6_1[] = {
  121980. 9, 7, 5, 3, 1, 0, 2, 4,
  121981. 6, 8, 10,
  121982. };
  121983. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  121984. _vq_quantthresh__44c0_s_p6_1,
  121985. _vq_quantmap__44c0_s_p6_1,
  121986. 11,
  121987. 11
  121988. };
  121989. static static_codebook _44c0_s_p6_1 = {
  121990. 2, 121,
  121991. _vq_lengthlist__44c0_s_p6_1,
  121992. 1, -531365888, 1611661312, 4, 0,
  121993. _vq_quantlist__44c0_s_p6_1,
  121994. NULL,
  121995. &_vq_auxt__44c0_s_p6_1,
  121996. NULL,
  121997. 0
  121998. };
  121999. static long _vq_quantlist__44c0_s_p7_0[] = {
  122000. 6,
  122001. 5,
  122002. 7,
  122003. 4,
  122004. 8,
  122005. 3,
  122006. 9,
  122007. 2,
  122008. 10,
  122009. 1,
  122010. 11,
  122011. 0,
  122012. 12,
  122013. };
  122014. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122015. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122016. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122017. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122018. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122019. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122020. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122021. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122022. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122023. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122024. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122025. 0,12,12,11,11,12,12,13,13,
  122026. };
  122027. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122028. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122029. 12.5, 17.5, 22.5, 27.5,
  122030. };
  122031. static long _vq_quantmap__44c0_s_p7_0[] = {
  122032. 11, 9, 7, 5, 3, 1, 0, 2,
  122033. 4, 6, 8, 10, 12,
  122034. };
  122035. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122036. _vq_quantthresh__44c0_s_p7_0,
  122037. _vq_quantmap__44c0_s_p7_0,
  122038. 13,
  122039. 13
  122040. };
  122041. static static_codebook _44c0_s_p7_0 = {
  122042. 2, 169,
  122043. _vq_lengthlist__44c0_s_p7_0,
  122044. 1, -526516224, 1616117760, 4, 0,
  122045. _vq_quantlist__44c0_s_p7_0,
  122046. NULL,
  122047. &_vq_auxt__44c0_s_p7_0,
  122048. NULL,
  122049. 0
  122050. };
  122051. static long _vq_quantlist__44c0_s_p7_1[] = {
  122052. 2,
  122053. 1,
  122054. 3,
  122055. 0,
  122056. 4,
  122057. };
  122058. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122059. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122060. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122061. };
  122062. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122063. -1.5, -0.5, 0.5, 1.5,
  122064. };
  122065. static long _vq_quantmap__44c0_s_p7_1[] = {
  122066. 3, 1, 0, 2, 4,
  122067. };
  122068. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122069. _vq_quantthresh__44c0_s_p7_1,
  122070. _vq_quantmap__44c0_s_p7_1,
  122071. 5,
  122072. 5
  122073. };
  122074. static static_codebook _44c0_s_p7_1 = {
  122075. 2, 25,
  122076. _vq_lengthlist__44c0_s_p7_1,
  122077. 1, -533725184, 1611661312, 3, 0,
  122078. _vq_quantlist__44c0_s_p7_1,
  122079. NULL,
  122080. &_vq_auxt__44c0_s_p7_1,
  122081. NULL,
  122082. 0
  122083. };
  122084. static long _vq_quantlist__44c0_s_p8_0[] = {
  122085. 2,
  122086. 1,
  122087. 3,
  122088. 0,
  122089. 4,
  122090. };
  122091. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122092. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122093. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122094. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122095. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122096. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122097. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122098. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122099. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122100. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122101. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122102. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122103. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122104. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122105. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122106. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122107. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122108. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122109. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122110. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122111. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122112. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122113. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122114. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122115. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122116. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122117. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122118. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122119. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122120. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122121. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122122. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122123. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122124. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122125. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122126. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122127. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122128. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122129. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122130. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122131. 11,
  122132. };
  122133. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122134. -331.5, -110.5, 110.5, 331.5,
  122135. };
  122136. static long _vq_quantmap__44c0_s_p8_0[] = {
  122137. 3, 1, 0, 2, 4,
  122138. };
  122139. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122140. _vq_quantthresh__44c0_s_p8_0,
  122141. _vq_quantmap__44c0_s_p8_0,
  122142. 5,
  122143. 5
  122144. };
  122145. static static_codebook _44c0_s_p8_0 = {
  122146. 4, 625,
  122147. _vq_lengthlist__44c0_s_p8_0,
  122148. 1, -518283264, 1627103232, 3, 0,
  122149. _vq_quantlist__44c0_s_p8_0,
  122150. NULL,
  122151. &_vq_auxt__44c0_s_p8_0,
  122152. NULL,
  122153. 0
  122154. };
  122155. static long _vq_quantlist__44c0_s_p8_1[] = {
  122156. 6,
  122157. 5,
  122158. 7,
  122159. 4,
  122160. 8,
  122161. 3,
  122162. 9,
  122163. 2,
  122164. 10,
  122165. 1,
  122166. 11,
  122167. 0,
  122168. 12,
  122169. };
  122170. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122171. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122172. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122173. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122174. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122175. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122176. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122177. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122178. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122179. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122180. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122181. 16,13,13,12,12,14,14,15,13,
  122182. };
  122183. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122184. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122185. 42.5, 59.5, 76.5, 93.5,
  122186. };
  122187. static long _vq_quantmap__44c0_s_p8_1[] = {
  122188. 11, 9, 7, 5, 3, 1, 0, 2,
  122189. 4, 6, 8, 10, 12,
  122190. };
  122191. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122192. _vq_quantthresh__44c0_s_p8_1,
  122193. _vq_quantmap__44c0_s_p8_1,
  122194. 13,
  122195. 13
  122196. };
  122197. static static_codebook _44c0_s_p8_1 = {
  122198. 2, 169,
  122199. _vq_lengthlist__44c0_s_p8_1,
  122200. 1, -522616832, 1620115456, 4, 0,
  122201. _vq_quantlist__44c0_s_p8_1,
  122202. NULL,
  122203. &_vq_auxt__44c0_s_p8_1,
  122204. NULL,
  122205. 0
  122206. };
  122207. static long _vq_quantlist__44c0_s_p8_2[] = {
  122208. 8,
  122209. 7,
  122210. 9,
  122211. 6,
  122212. 10,
  122213. 5,
  122214. 11,
  122215. 4,
  122216. 12,
  122217. 3,
  122218. 13,
  122219. 2,
  122220. 14,
  122221. 1,
  122222. 15,
  122223. 0,
  122224. 16,
  122225. };
  122226. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122227. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122228. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122229. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122230. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122231. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122232. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122233. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122234. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122235. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122236. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122237. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122238. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122239. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122240. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122241. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122242. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122243. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122244. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122245. 10,
  122246. };
  122247. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122248. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122249. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122250. };
  122251. static long _vq_quantmap__44c0_s_p8_2[] = {
  122252. 15, 13, 11, 9, 7, 5, 3, 1,
  122253. 0, 2, 4, 6, 8, 10, 12, 14,
  122254. 16,
  122255. };
  122256. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122257. _vq_quantthresh__44c0_s_p8_2,
  122258. _vq_quantmap__44c0_s_p8_2,
  122259. 17,
  122260. 17
  122261. };
  122262. static static_codebook _44c0_s_p8_2 = {
  122263. 2, 289,
  122264. _vq_lengthlist__44c0_s_p8_2,
  122265. 1, -529530880, 1611661312, 5, 0,
  122266. _vq_quantlist__44c0_s_p8_2,
  122267. NULL,
  122268. &_vq_auxt__44c0_s_p8_2,
  122269. NULL,
  122270. 0
  122271. };
  122272. static long _huff_lengthlist__44c0_s_short[] = {
  122273. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122274. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122275. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122276. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122277. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122278. 12,
  122279. };
  122280. static static_codebook _huff_book__44c0_s_short = {
  122281. 2, 81,
  122282. _huff_lengthlist__44c0_s_short,
  122283. 0, 0, 0, 0, 0,
  122284. NULL,
  122285. NULL,
  122286. NULL,
  122287. NULL,
  122288. 0
  122289. };
  122290. static long _huff_lengthlist__44c0_sm_long[] = {
  122291. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122292. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122293. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122294. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122295. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122296. 13,
  122297. };
  122298. static static_codebook _huff_book__44c0_sm_long = {
  122299. 2, 81,
  122300. _huff_lengthlist__44c0_sm_long,
  122301. 0, 0, 0, 0, 0,
  122302. NULL,
  122303. NULL,
  122304. NULL,
  122305. NULL,
  122306. 0
  122307. };
  122308. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122309. 1,
  122310. 0,
  122311. 2,
  122312. };
  122313. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122314. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122315. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122319. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122320. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122324. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122325. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122360. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122365. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122370. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122405. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122406. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122410. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122411. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  122412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122415. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122416. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122724. 0,
  122725. };
  122726. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122727. -0.5, 0.5,
  122728. };
  122729. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122730. 1, 0, 2,
  122731. };
  122732. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122733. _vq_quantthresh__44c0_sm_p1_0,
  122734. _vq_quantmap__44c0_sm_p1_0,
  122735. 3,
  122736. 3
  122737. };
  122738. static static_codebook _44c0_sm_p1_0 = {
  122739. 8, 6561,
  122740. _vq_lengthlist__44c0_sm_p1_0,
  122741. 1, -535822336, 1611661312, 2, 0,
  122742. _vq_quantlist__44c0_sm_p1_0,
  122743. NULL,
  122744. &_vq_auxt__44c0_sm_p1_0,
  122745. NULL,
  122746. 0
  122747. };
  122748. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122749. 2,
  122750. 1,
  122751. 3,
  122752. 0,
  122753. 4,
  122754. };
  122755. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122756. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122759. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122762. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122795. 0,
  122796. };
  122797. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122798. -1.5, -0.5, 0.5, 1.5,
  122799. };
  122800. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122801. 3, 1, 0, 2, 4,
  122802. };
  122803. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122804. _vq_quantthresh__44c0_sm_p2_0,
  122805. _vq_quantmap__44c0_sm_p2_0,
  122806. 5,
  122807. 5
  122808. };
  122809. static static_codebook _44c0_sm_p2_0 = {
  122810. 4, 625,
  122811. _vq_lengthlist__44c0_sm_p2_0,
  122812. 1, -533725184, 1611661312, 3, 0,
  122813. _vq_quantlist__44c0_sm_p2_0,
  122814. NULL,
  122815. &_vq_auxt__44c0_sm_p2_0,
  122816. NULL,
  122817. 0
  122818. };
  122819. static long _vq_quantlist__44c0_sm_p3_0[] = {
  122820. 4,
  122821. 3,
  122822. 5,
  122823. 2,
  122824. 6,
  122825. 1,
  122826. 7,
  122827. 0,
  122828. 8,
  122829. };
  122830. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  122831. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  122832. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  122833. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  122834. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  122835. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122836. 0,
  122837. };
  122838. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  122839. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122840. };
  122841. static long _vq_quantmap__44c0_sm_p3_0[] = {
  122842. 7, 5, 3, 1, 0, 2, 4, 6,
  122843. 8,
  122844. };
  122845. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  122846. _vq_quantthresh__44c0_sm_p3_0,
  122847. _vq_quantmap__44c0_sm_p3_0,
  122848. 9,
  122849. 9
  122850. };
  122851. static static_codebook _44c0_sm_p3_0 = {
  122852. 2, 81,
  122853. _vq_lengthlist__44c0_sm_p3_0,
  122854. 1, -531628032, 1611661312, 4, 0,
  122855. _vq_quantlist__44c0_sm_p3_0,
  122856. NULL,
  122857. &_vq_auxt__44c0_sm_p3_0,
  122858. NULL,
  122859. 0
  122860. };
  122861. static long _vq_quantlist__44c0_sm_p4_0[] = {
  122862. 4,
  122863. 3,
  122864. 5,
  122865. 2,
  122866. 6,
  122867. 1,
  122868. 7,
  122869. 0,
  122870. 8,
  122871. };
  122872. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  122873. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  122874. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  122875. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  122876. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  122877. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  122878. 11,
  122879. };
  122880. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  122881. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122882. };
  122883. static long _vq_quantmap__44c0_sm_p4_0[] = {
  122884. 7, 5, 3, 1, 0, 2, 4, 6,
  122885. 8,
  122886. };
  122887. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  122888. _vq_quantthresh__44c0_sm_p4_0,
  122889. _vq_quantmap__44c0_sm_p4_0,
  122890. 9,
  122891. 9
  122892. };
  122893. static static_codebook _44c0_sm_p4_0 = {
  122894. 2, 81,
  122895. _vq_lengthlist__44c0_sm_p4_0,
  122896. 1, -531628032, 1611661312, 4, 0,
  122897. _vq_quantlist__44c0_sm_p4_0,
  122898. NULL,
  122899. &_vq_auxt__44c0_sm_p4_0,
  122900. NULL,
  122901. 0
  122902. };
  122903. static long _vq_quantlist__44c0_sm_p5_0[] = {
  122904. 8,
  122905. 7,
  122906. 9,
  122907. 6,
  122908. 10,
  122909. 5,
  122910. 11,
  122911. 4,
  122912. 12,
  122913. 3,
  122914. 13,
  122915. 2,
  122916. 14,
  122917. 1,
  122918. 15,
  122919. 0,
  122920. 16,
  122921. };
  122922. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  122923. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  122924. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  122925. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122926. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  122927. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  122928. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  122929. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  122930. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122931. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  122932. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  122933. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122934. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122935. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  122936. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  122937. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  122938. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  122939. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  122940. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122941. 14,
  122942. };
  122943. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  122944. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122945. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122946. };
  122947. static long _vq_quantmap__44c0_sm_p5_0[] = {
  122948. 15, 13, 11, 9, 7, 5, 3, 1,
  122949. 0, 2, 4, 6, 8, 10, 12, 14,
  122950. 16,
  122951. };
  122952. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  122953. _vq_quantthresh__44c0_sm_p5_0,
  122954. _vq_quantmap__44c0_sm_p5_0,
  122955. 17,
  122956. 17
  122957. };
  122958. static static_codebook _44c0_sm_p5_0 = {
  122959. 2, 289,
  122960. _vq_lengthlist__44c0_sm_p5_0,
  122961. 1, -529530880, 1611661312, 5, 0,
  122962. _vq_quantlist__44c0_sm_p5_0,
  122963. NULL,
  122964. &_vq_auxt__44c0_sm_p5_0,
  122965. NULL,
  122966. 0
  122967. };
  122968. static long _vq_quantlist__44c0_sm_p6_0[] = {
  122969. 1,
  122970. 0,
  122971. 2,
  122972. };
  122973. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  122974. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  122975. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  122976. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  122977. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  122978. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122979. 11,
  122980. };
  122981. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  122982. -5.5, 5.5,
  122983. };
  122984. static long _vq_quantmap__44c0_sm_p6_0[] = {
  122985. 1, 0, 2,
  122986. };
  122987. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  122988. _vq_quantthresh__44c0_sm_p6_0,
  122989. _vq_quantmap__44c0_sm_p6_0,
  122990. 3,
  122991. 3
  122992. };
  122993. static static_codebook _44c0_sm_p6_0 = {
  122994. 4, 81,
  122995. _vq_lengthlist__44c0_sm_p6_0,
  122996. 1, -529137664, 1618345984, 2, 0,
  122997. _vq_quantlist__44c0_sm_p6_0,
  122998. NULL,
  122999. &_vq_auxt__44c0_sm_p6_0,
  123000. NULL,
  123001. 0
  123002. };
  123003. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123004. 5,
  123005. 4,
  123006. 6,
  123007. 3,
  123008. 7,
  123009. 2,
  123010. 8,
  123011. 1,
  123012. 9,
  123013. 0,
  123014. 10,
  123015. };
  123016. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123017. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123018. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123019. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123020. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123021. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123022. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123023. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123024. 10,10,10, 8, 8, 8, 8, 8, 8,
  123025. };
  123026. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123027. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123028. 3.5, 4.5,
  123029. };
  123030. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123031. 9, 7, 5, 3, 1, 0, 2, 4,
  123032. 6, 8, 10,
  123033. };
  123034. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123035. _vq_quantthresh__44c0_sm_p6_1,
  123036. _vq_quantmap__44c0_sm_p6_1,
  123037. 11,
  123038. 11
  123039. };
  123040. static static_codebook _44c0_sm_p6_1 = {
  123041. 2, 121,
  123042. _vq_lengthlist__44c0_sm_p6_1,
  123043. 1, -531365888, 1611661312, 4, 0,
  123044. _vq_quantlist__44c0_sm_p6_1,
  123045. NULL,
  123046. &_vq_auxt__44c0_sm_p6_1,
  123047. NULL,
  123048. 0
  123049. };
  123050. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123051. 6,
  123052. 5,
  123053. 7,
  123054. 4,
  123055. 8,
  123056. 3,
  123057. 9,
  123058. 2,
  123059. 10,
  123060. 1,
  123061. 11,
  123062. 0,
  123063. 12,
  123064. };
  123065. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123066. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123067. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123068. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123069. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123070. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123071. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123072. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123073. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123074. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123075. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123076. 0,12,12,11,11,13,12,14,14,
  123077. };
  123078. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123079. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123080. 12.5, 17.5, 22.5, 27.5,
  123081. };
  123082. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123083. 11, 9, 7, 5, 3, 1, 0, 2,
  123084. 4, 6, 8, 10, 12,
  123085. };
  123086. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123087. _vq_quantthresh__44c0_sm_p7_0,
  123088. _vq_quantmap__44c0_sm_p7_0,
  123089. 13,
  123090. 13
  123091. };
  123092. static static_codebook _44c0_sm_p7_0 = {
  123093. 2, 169,
  123094. _vq_lengthlist__44c0_sm_p7_0,
  123095. 1, -526516224, 1616117760, 4, 0,
  123096. _vq_quantlist__44c0_sm_p7_0,
  123097. NULL,
  123098. &_vq_auxt__44c0_sm_p7_0,
  123099. NULL,
  123100. 0
  123101. };
  123102. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123103. 2,
  123104. 1,
  123105. 3,
  123106. 0,
  123107. 4,
  123108. };
  123109. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123110. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123111. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123112. };
  123113. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123114. -1.5, -0.5, 0.5, 1.5,
  123115. };
  123116. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123117. 3, 1, 0, 2, 4,
  123118. };
  123119. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123120. _vq_quantthresh__44c0_sm_p7_1,
  123121. _vq_quantmap__44c0_sm_p7_1,
  123122. 5,
  123123. 5
  123124. };
  123125. static static_codebook _44c0_sm_p7_1 = {
  123126. 2, 25,
  123127. _vq_lengthlist__44c0_sm_p7_1,
  123128. 1, -533725184, 1611661312, 3, 0,
  123129. _vq_quantlist__44c0_sm_p7_1,
  123130. NULL,
  123131. &_vq_auxt__44c0_sm_p7_1,
  123132. NULL,
  123133. 0
  123134. };
  123135. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123136. 4,
  123137. 3,
  123138. 5,
  123139. 2,
  123140. 6,
  123141. 1,
  123142. 7,
  123143. 0,
  123144. 8,
  123145. };
  123146. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123147. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123148. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123149. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123150. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123151. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123152. 12,
  123153. };
  123154. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123155. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123156. };
  123157. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123158. 7, 5, 3, 1, 0, 2, 4, 6,
  123159. 8,
  123160. };
  123161. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123162. _vq_quantthresh__44c0_sm_p8_0,
  123163. _vq_quantmap__44c0_sm_p8_0,
  123164. 9,
  123165. 9
  123166. };
  123167. static static_codebook _44c0_sm_p8_0 = {
  123168. 2, 81,
  123169. _vq_lengthlist__44c0_sm_p8_0,
  123170. 1, -516186112, 1627103232, 4, 0,
  123171. _vq_quantlist__44c0_sm_p8_0,
  123172. NULL,
  123173. &_vq_auxt__44c0_sm_p8_0,
  123174. NULL,
  123175. 0
  123176. };
  123177. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123178. 6,
  123179. 5,
  123180. 7,
  123181. 4,
  123182. 8,
  123183. 3,
  123184. 9,
  123185. 2,
  123186. 10,
  123187. 1,
  123188. 11,
  123189. 0,
  123190. 12,
  123191. };
  123192. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123193. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123194. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123195. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123196. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123197. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123198. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123199. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123200. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123201. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123202. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123203. 20,13,13,12,12,16,13,15,13,
  123204. };
  123205. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123206. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123207. 42.5, 59.5, 76.5, 93.5,
  123208. };
  123209. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123210. 11, 9, 7, 5, 3, 1, 0, 2,
  123211. 4, 6, 8, 10, 12,
  123212. };
  123213. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123214. _vq_quantthresh__44c0_sm_p8_1,
  123215. _vq_quantmap__44c0_sm_p8_1,
  123216. 13,
  123217. 13
  123218. };
  123219. static static_codebook _44c0_sm_p8_1 = {
  123220. 2, 169,
  123221. _vq_lengthlist__44c0_sm_p8_1,
  123222. 1, -522616832, 1620115456, 4, 0,
  123223. _vq_quantlist__44c0_sm_p8_1,
  123224. NULL,
  123225. &_vq_auxt__44c0_sm_p8_1,
  123226. NULL,
  123227. 0
  123228. };
  123229. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123230. 8,
  123231. 7,
  123232. 9,
  123233. 6,
  123234. 10,
  123235. 5,
  123236. 11,
  123237. 4,
  123238. 12,
  123239. 3,
  123240. 13,
  123241. 2,
  123242. 14,
  123243. 1,
  123244. 15,
  123245. 0,
  123246. 16,
  123247. };
  123248. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123249. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123250. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123251. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123252. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123253. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123254. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123255. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123256. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123257. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123258. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123259. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123260. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123261. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123262. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123263. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123264. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123265. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123266. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123267. 9,
  123268. };
  123269. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123270. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123271. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123272. };
  123273. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123274. 15, 13, 11, 9, 7, 5, 3, 1,
  123275. 0, 2, 4, 6, 8, 10, 12, 14,
  123276. 16,
  123277. };
  123278. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123279. _vq_quantthresh__44c0_sm_p8_2,
  123280. _vq_quantmap__44c0_sm_p8_2,
  123281. 17,
  123282. 17
  123283. };
  123284. static static_codebook _44c0_sm_p8_2 = {
  123285. 2, 289,
  123286. _vq_lengthlist__44c0_sm_p8_2,
  123287. 1, -529530880, 1611661312, 5, 0,
  123288. _vq_quantlist__44c0_sm_p8_2,
  123289. NULL,
  123290. &_vq_auxt__44c0_sm_p8_2,
  123291. NULL,
  123292. 0
  123293. };
  123294. static long _huff_lengthlist__44c0_sm_short[] = {
  123295. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123296. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123297. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123298. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123299. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123300. 12,
  123301. };
  123302. static static_codebook _huff_book__44c0_sm_short = {
  123303. 2, 81,
  123304. _huff_lengthlist__44c0_sm_short,
  123305. 0, 0, 0, 0, 0,
  123306. NULL,
  123307. NULL,
  123308. NULL,
  123309. NULL,
  123310. 0
  123311. };
  123312. static long _huff_lengthlist__44c1_s_long[] = {
  123313. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123314. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123315. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123316. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123317. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123318. 11,
  123319. };
  123320. static static_codebook _huff_book__44c1_s_long = {
  123321. 2, 81,
  123322. _huff_lengthlist__44c1_s_long,
  123323. 0, 0, 0, 0, 0,
  123324. NULL,
  123325. NULL,
  123326. NULL,
  123327. NULL,
  123328. 0
  123329. };
  123330. static long _vq_quantlist__44c1_s_p1_0[] = {
  123331. 1,
  123332. 0,
  123333. 2,
  123334. };
  123335. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123336. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123337. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123341. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123342. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123346. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123347. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123382. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123387. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  123392. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123427. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123428. 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123432. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123433. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  123434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123437. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123438. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123746. 0,
  123747. };
  123748. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123749. -0.5, 0.5,
  123750. };
  123751. static long _vq_quantmap__44c1_s_p1_0[] = {
  123752. 1, 0, 2,
  123753. };
  123754. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123755. _vq_quantthresh__44c1_s_p1_0,
  123756. _vq_quantmap__44c1_s_p1_0,
  123757. 3,
  123758. 3
  123759. };
  123760. static static_codebook _44c1_s_p1_0 = {
  123761. 8, 6561,
  123762. _vq_lengthlist__44c1_s_p1_0,
  123763. 1, -535822336, 1611661312, 2, 0,
  123764. _vq_quantlist__44c1_s_p1_0,
  123765. NULL,
  123766. &_vq_auxt__44c1_s_p1_0,
  123767. NULL,
  123768. 0
  123769. };
  123770. static long _vq_quantlist__44c1_s_p2_0[] = {
  123771. 2,
  123772. 1,
  123773. 3,
  123774. 0,
  123775. 4,
  123776. };
  123777. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123778. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123781. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123784. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123817. 0,
  123818. };
  123819. static float _vq_quantthresh__44c1_s_p2_0[] = {
  123820. -1.5, -0.5, 0.5, 1.5,
  123821. };
  123822. static long _vq_quantmap__44c1_s_p2_0[] = {
  123823. 3, 1, 0, 2, 4,
  123824. };
  123825. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  123826. _vq_quantthresh__44c1_s_p2_0,
  123827. _vq_quantmap__44c1_s_p2_0,
  123828. 5,
  123829. 5
  123830. };
  123831. static static_codebook _44c1_s_p2_0 = {
  123832. 4, 625,
  123833. _vq_lengthlist__44c1_s_p2_0,
  123834. 1, -533725184, 1611661312, 3, 0,
  123835. _vq_quantlist__44c1_s_p2_0,
  123836. NULL,
  123837. &_vq_auxt__44c1_s_p2_0,
  123838. NULL,
  123839. 0
  123840. };
  123841. static long _vq_quantlist__44c1_s_p3_0[] = {
  123842. 4,
  123843. 3,
  123844. 5,
  123845. 2,
  123846. 6,
  123847. 1,
  123848. 7,
  123849. 0,
  123850. 8,
  123851. };
  123852. static long _vq_lengthlist__44c1_s_p3_0[] = {
  123853. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  123854. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  123855. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  123856. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  123857. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123858. 0,
  123859. };
  123860. static float _vq_quantthresh__44c1_s_p3_0[] = {
  123861. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123862. };
  123863. static long _vq_quantmap__44c1_s_p3_0[] = {
  123864. 7, 5, 3, 1, 0, 2, 4, 6,
  123865. 8,
  123866. };
  123867. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  123868. _vq_quantthresh__44c1_s_p3_0,
  123869. _vq_quantmap__44c1_s_p3_0,
  123870. 9,
  123871. 9
  123872. };
  123873. static static_codebook _44c1_s_p3_0 = {
  123874. 2, 81,
  123875. _vq_lengthlist__44c1_s_p3_0,
  123876. 1, -531628032, 1611661312, 4, 0,
  123877. _vq_quantlist__44c1_s_p3_0,
  123878. NULL,
  123879. &_vq_auxt__44c1_s_p3_0,
  123880. NULL,
  123881. 0
  123882. };
  123883. static long _vq_quantlist__44c1_s_p4_0[] = {
  123884. 4,
  123885. 3,
  123886. 5,
  123887. 2,
  123888. 6,
  123889. 1,
  123890. 7,
  123891. 0,
  123892. 8,
  123893. };
  123894. static long _vq_lengthlist__44c1_s_p4_0[] = {
  123895. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  123896. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  123897. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  123898. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  123899. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123900. 11,
  123901. };
  123902. static float _vq_quantthresh__44c1_s_p4_0[] = {
  123903. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123904. };
  123905. static long _vq_quantmap__44c1_s_p4_0[] = {
  123906. 7, 5, 3, 1, 0, 2, 4, 6,
  123907. 8,
  123908. };
  123909. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  123910. _vq_quantthresh__44c1_s_p4_0,
  123911. _vq_quantmap__44c1_s_p4_0,
  123912. 9,
  123913. 9
  123914. };
  123915. static static_codebook _44c1_s_p4_0 = {
  123916. 2, 81,
  123917. _vq_lengthlist__44c1_s_p4_0,
  123918. 1, -531628032, 1611661312, 4, 0,
  123919. _vq_quantlist__44c1_s_p4_0,
  123920. NULL,
  123921. &_vq_auxt__44c1_s_p4_0,
  123922. NULL,
  123923. 0
  123924. };
  123925. static long _vq_quantlist__44c1_s_p5_0[] = {
  123926. 8,
  123927. 7,
  123928. 9,
  123929. 6,
  123930. 10,
  123931. 5,
  123932. 11,
  123933. 4,
  123934. 12,
  123935. 3,
  123936. 13,
  123937. 2,
  123938. 14,
  123939. 1,
  123940. 15,
  123941. 0,
  123942. 16,
  123943. };
  123944. static long _vq_lengthlist__44c1_s_p5_0[] = {
  123945. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  123946. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  123947. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123948. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  123949. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  123950. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  123951. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  123952. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123953. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  123954. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  123955. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123956. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123957. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  123958. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  123959. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  123960. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  123961. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  123962. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123963. 14,
  123964. };
  123965. static float _vq_quantthresh__44c1_s_p5_0[] = {
  123966. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123967. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123968. };
  123969. static long _vq_quantmap__44c1_s_p5_0[] = {
  123970. 15, 13, 11, 9, 7, 5, 3, 1,
  123971. 0, 2, 4, 6, 8, 10, 12, 14,
  123972. 16,
  123973. };
  123974. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  123975. _vq_quantthresh__44c1_s_p5_0,
  123976. _vq_quantmap__44c1_s_p5_0,
  123977. 17,
  123978. 17
  123979. };
  123980. static static_codebook _44c1_s_p5_0 = {
  123981. 2, 289,
  123982. _vq_lengthlist__44c1_s_p5_0,
  123983. 1, -529530880, 1611661312, 5, 0,
  123984. _vq_quantlist__44c1_s_p5_0,
  123985. NULL,
  123986. &_vq_auxt__44c1_s_p5_0,
  123987. NULL,
  123988. 0
  123989. };
  123990. static long _vq_quantlist__44c1_s_p6_0[] = {
  123991. 1,
  123992. 0,
  123993. 2,
  123994. };
  123995. static long _vq_lengthlist__44c1_s_p6_0[] = {
  123996. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123997. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  123998. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  123999. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124000. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124001. 11,
  124002. };
  124003. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124004. -5.5, 5.5,
  124005. };
  124006. static long _vq_quantmap__44c1_s_p6_0[] = {
  124007. 1, 0, 2,
  124008. };
  124009. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124010. _vq_quantthresh__44c1_s_p6_0,
  124011. _vq_quantmap__44c1_s_p6_0,
  124012. 3,
  124013. 3
  124014. };
  124015. static static_codebook _44c1_s_p6_0 = {
  124016. 4, 81,
  124017. _vq_lengthlist__44c1_s_p6_0,
  124018. 1, -529137664, 1618345984, 2, 0,
  124019. _vq_quantlist__44c1_s_p6_0,
  124020. NULL,
  124021. &_vq_auxt__44c1_s_p6_0,
  124022. NULL,
  124023. 0
  124024. };
  124025. static long _vq_quantlist__44c1_s_p6_1[] = {
  124026. 5,
  124027. 4,
  124028. 6,
  124029. 3,
  124030. 7,
  124031. 2,
  124032. 8,
  124033. 1,
  124034. 9,
  124035. 0,
  124036. 10,
  124037. };
  124038. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124039. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124040. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124041. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124042. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124043. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124044. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124045. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124046. 10,10,10, 8, 8, 8, 8, 8, 8,
  124047. };
  124048. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124049. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124050. 3.5, 4.5,
  124051. };
  124052. static long _vq_quantmap__44c1_s_p6_1[] = {
  124053. 9, 7, 5, 3, 1, 0, 2, 4,
  124054. 6, 8, 10,
  124055. };
  124056. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124057. _vq_quantthresh__44c1_s_p6_1,
  124058. _vq_quantmap__44c1_s_p6_1,
  124059. 11,
  124060. 11
  124061. };
  124062. static static_codebook _44c1_s_p6_1 = {
  124063. 2, 121,
  124064. _vq_lengthlist__44c1_s_p6_1,
  124065. 1, -531365888, 1611661312, 4, 0,
  124066. _vq_quantlist__44c1_s_p6_1,
  124067. NULL,
  124068. &_vq_auxt__44c1_s_p6_1,
  124069. NULL,
  124070. 0
  124071. };
  124072. static long _vq_quantlist__44c1_s_p7_0[] = {
  124073. 6,
  124074. 5,
  124075. 7,
  124076. 4,
  124077. 8,
  124078. 3,
  124079. 9,
  124080. 2,
  124081. 10,
  124082. 1,
  124083. 11,
  124084. 0,
  124085. 12,
  124086. };
  124087. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124088. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124089. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124090. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124091. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124092. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124093. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124094. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124095. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124096. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124097. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124098. 0,12,11,11,11,13,10,14,13,
  124099. };
  124100. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124101. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124102. 12.5, 17.5, 22.5, 27.5,
  124103. };
  124104. static long _vq_quantmap__44c1_s_p7_0[] = {
  124105. 11, 9, 7, 5, 3, 1, 0, 2,
  124106. 4, 6, 8, 10, 12,
  124107. };
  124108. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124109. _vq_quantthresh__44c1_s_p7_0,
  124110. _vq_quantmap__44c1_s_p7_0,
  124111. 13,
  124112. 13
  124113. };
  124114. static static_codebook _44c1_s_p7_0 = {
  124115. 2, 169,
  124116. _vq_lengthlist__44c1_s_p7_0,
  124117. 1, -526516224, 1616117760, 4, 0,
  124118. _vq_quantlist__44c1_s_p7_0,
  124119. NULL,
  124120. &_vq_auxt__44c1_s_p7_0,
  124121. NULL,
  124122. 0
  124123. };
  124124. static long _vq_quantlist__44c1_s_p7_1[] = {
  124125. 2,
  124126. 1,
  124127. 3,
  124128. 0,
  124129. 4,
  124130. };
  124131. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124132. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124133. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124134. };
  124135. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124136. -1.5, -0.5, 0.5, 1.5,
  124137. };
  124138. static long _vq_quantmap__44c1_s_p7_1[] = {
  124139. 3, 1, 0, 2, 4,
  124140. };
  124141. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124142. _vq_quantthresh__44c1_s_p7_1,
  124143. _vq_quantmap__44c1_s_p7_1,
  124144. 5,
  124145. 5
  124146. };
  124147. static static_codebook _44c1_s_p7_1 = {
  124148. 2, 25,
  124149. _vq_lengthlist__44c1_s_p7_1,
  124150. 1, -533725184, 1611661312, 3, 0,
  124151. _vq_quantlist__44c1_s_p7_1,
  124152. NULL,
  124153. &_vq_auxt__44c1_s_p7_1,
  124154. NULL,
  124155. 0
  124156. };
  124157. static long _vq_quantlist__44c1_s_p8_0[] = {
  124158. 6,
  124159. 5,
  124160. 7,
  124161. 4,
  124162. 8,
  124163. 3,
  124164. 9,
  124165. 2,
  124166. 10,
  124167. 1,
  124168. 11,
  124169. 0,
  124170. 12,
  124171. };
  124172. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124173. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124174. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124175. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124176. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124177. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124178. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124179. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124180. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124181. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124182. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124183. 10,10,10,10,10,10,10,10,10,
  124184. };
  124185. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124186. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124187. 552.5, 773.5, 994.5, 1215.5,
  124188. };
  124189. static long _vq_quantmap__44c1_s_p8_0[] = {
  124190. 11, 9, 7, 5, 3, 1, 0, 2,
  124191. 4, 6, 8, 10, 12,
  124192. };
  124193. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124194. _vq_quantthresh__44c1_s_p8_0,
  124195. _vq_quantmap__44c1_s_p8_0,
  124196. 13,
  124197. 13
  124198. };
  124199. static static_codebook _44c1_s_p8_0 = {
  124200. 2, 169,
  124201. _vq_lengthlist__44c1_s_p8_0,
  124202. 1, -514541568, 1627103232, 4, 0,
  124203. _vq_quantlist__44c1_s_p8_0,
  124204. NULL,
  124205. &_vq_auxt__44c1_s_p8_0,
  124206. NULL,
  124207. 0
  124208. };
  124209. static long _vq_quantlist__44c1_s_p8_1[] = {
  124210. 6,
  124211. 5,
  124212. 7,
  124213. 4,
  124214. 8,
  124215. 3,
  124216. 9,
  124217. 2,
  124218. 10,
  124219. 1,
  124220. 11,
  124221. 0,
  124222. 12,
  124223. };
  124224. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124225. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124226. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124227. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124228. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124229. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124230. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124231. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124232. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124233. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124234. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124235. 16,13,12,12,11,14,12,15,13,
  124236. };
  124237. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124238. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124239. 42.5, 59.5, 76.5, 93.5,
  124240. };
  124241. static long _vq_quantmap__44c1_s_p8_1[] = {
  124242. 11, 9, 7, 5, 3, 1, 0, 2,
  124243. 4, 6, 8, 10, 12,
  124244. };
  124245. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124246. _vq_quantthresh__44c1_s_p8_1,
  124247. _vq_quantmap__44c1_s_p8_1,
  124248. 13,
  124249. 13
  124250. };
  124251. static static_codebook _44c1_s_p8_1 = {
  124252. 2, 169,
  124253. _vq_lengthlist__44c1_s_p8_1,
  124254. 1, -522616832, 1620115456, 4, 0,
  124255. _vq_quantlist__44c1_s_p8_1,
  124256. NULL,
  124257. &_vq_auxt__44c1_s_p8_1,
  124258. NULL,
  124259. 0
  124260. };
  124261. static long _vq_quantlist__44c1_s_p8_2[] = {
  124262. 8,
  124263. 7,
  124264. 9,
  124265. 6,
  124266. 10,
  124267. 5,
  124268. 11,
  124269. 4,
  124270. 12,
  124271. 3,
  124272. 13,
  124273. 2,
  124274. 14,
  124275. 1,
  124276. 15,
  124277. 0,
  124278. 16,
  124279. };
  124280. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124281. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124282. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124283. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124284. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124285. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124286. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124287. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124288. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124289. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124290. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124291. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124292. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124293. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124294. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124295. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124296. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124297. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124298. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124299. 9,
  124300. };
  124301. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124302. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124303. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124304. };
  124305. static long _vq_quantmap__44c1_s_p8_2[] = {
  124306. 15, 13, 11, 9, 7, 5, 3, 1,
  124307. 0, 2, 4, 6, 8, 10, 12, 14,
  124308. 16,
  124309. };
  124310. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124311. _vq_quantthresh__44c1_s_p8_2,
  124312. _vq_quantmap__44c1_s_p8_2,
  124313. 17,
  124314. 17
  124315. };
  124316. static static_codebook _44c1_s_p8_2 = {
  124317. 2, 289,
  124318. _vq_lengthlist__44c1_s_p8_2,
  124319. 1, -529530880, 1611661312, 5, 0,
  124320. _vq_quantlist__44c1_s_p8_2,
  124321. NULL,
  124322. &_vq_auxt__44c1_s_p8_2,
  124323. NULL,
  124324. 0
  124325. };
  124326. static long _huff_lengthlist__44c1_s_short[] = {
  124327. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124328. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124329. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124330. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124331. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124332. 11,
  124333. };
  124334. static static_codebook _huff_book__44c1_s_short = {
  124335. 2, 81,
  124336. _huff_lengthlist__44c1_s_short,
  124337. 0, 0, 0, 0, 0,
  124338. NULL,
  124339. NULL,
  124340. NULL,
  124341. NULL,
  124342. 0
  124343. };
  124344. static long _huff_lengthlist__44c1_sm_long[] = {
  124345. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124346. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124347. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124348. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124349. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124350. 11,
  124351. };
  124352. static static_codebook _huff_book__44c1_sm_long = {
  124353. 2, 81,
  124354. _huff_lengthlist__44c1_sm_long,
  124355. 0, 0, 0, 0, 0,
  124356. NULL,
  124357. NULL,
  124358. NULL,
  124359. NULL,
  124360. 0
  124361. };
  124362. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124363. 1,
  124364. 0,
  124365. 2,
  124366. };
  124367. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124368. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124369. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124373. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124374. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124378. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124379. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124414. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124419. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  124424. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124459. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124460. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124464. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124465. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  124466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124469. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124470. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  124471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124778. 0,
  124779. };
  124780. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124781. -0.5, 0.5,
  124782. };
  124783. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124784. 1, 0, 2,
  124785. };
  124786. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124787. _vq_quantthresh__44c1_sm_p1_0,
  124788. _vq_quantmap__44c1_sm_p1_0,
  124789. 3,
  124790. 3
  124791. };
  124792. static static_codebook _44c1_sm_p1_0 = {
  124793. 8, 6561,
  124794. _vq_lengthlist__44c1_sm_p1_0,
  124795. 1, -535822336, 1611661312, 2, 0,
  124796. _vq_quantlist__44c1_sm_p1_0,
  124797. NULL,
  124798. &_vq_auxt__44c1_sm_p1_0,
  124799. NULL,
  124800. 0
  124801. };
  124802. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124803. 2,
  124804. 1,
  124805. 3,
  124806. 0,
  124807. 4,
  124808. };
  124809. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  124810. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124813. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  124815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124816. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124849. 0,
  124850. };
  124851. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  124852. -1.5, -0.5, 0.5, 1.5,
  124853. };
  124854. static long _vq_quantmap__44c1_sm_p2_0[] = {
  124855. 3, 1, 0, 2, 4,
  124856. };
  124857. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  124858. _vq_quantthresh__44c1_sm_p2_0,
  124859. _vq_quantmap__44c1_sm_p2_0,
  124860. 5,
  124861. 5
  124862. };
  124863. static static_codebook _44c1_sm_p2_0 = {
  124864. 4, 625,
  124865. _vq_lengthlist__44c1_sm_p2_0,
  124866. 1, -533725184, 1611661312, 3, 0,
  124867. _vq_quantlist__44c1_sm_p2_0,
  124868. NULL,
  124869. &_vq_auxt__44c1_sm_p2_0,
  124870. NULL,
  124871. 0
  124872. };
  124873. static long _vq_quantlist__44c1_sm_p3_0[] = {
  124874. 4,
  124875. 3,
  124876. 5,
  124877. 2,
  124878. 6,
  124879. 1,
  124880. 7,
  124881. 0,
  124882. 8,
  124883. };
  124884. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  124885. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  124886. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  124887. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124888. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124889. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124890. 0,
  124891. };
  124892. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  124893. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124894. };
  124895. static long _vq_quantmap__44c1_sm_p3_0[] = {
  124896. 7, 5, 3, 1, 0, 2, 4, 6,
  124897. 8,
  124898. };
  124899. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  124900. _vq_quantthresh__44c1_sm_p3_0,
  124901. _vq_quantmap__44c1_sm_p3_0,
  124902. 9,
  124903. 9
  124904. };
  124905. static static_codebook _44c1_sm_p3_0 = {
  124906. 2, 81,
  124907. _vq_lengthlist__44c1_sm_p3_0,
  124908. 1, -531628032, 1611661312, 4, 0,
  124909. _vq_quantlist__44c1_sm_p3_0,
  124910. NULL,
  124911. &_vq_auxt__44c1_sm_p3_0,
  124912. NULL,
  124913. 0
  124914. };
  124915. static long _vq_quantlist__44c1_sm_p4_0[] = {
  124916. 4,
  124917. 3,
  124918. 5,
  124919. 2,
  124920. 6,
  124921. 1,
  124922. 7,
  124923. 0,
  124924. 8,
  124925. };
  124926. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  124927. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  124928. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  124929. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  124930. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  124931. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124932. 11,
  124933. };
  124934. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  124935. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124936. };
  124937. static long _vq_quantmap__44c1_sm_p4_0[] = {
  124938. 7, 5, 3, 1, 0, 2, 4, 6,
  124939. 8,
  124940. };
  124941. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  124942. _vq_quantthresh__44c1_sm_p4_0,
  124943. _vq_quantmap__44c1_sm_p4_0,
  124944. 9,
  124945. 9
  124946. };
  124947. static static_codebook _44c1_sm_p4_0 = {
  124948. 2, 81,
  124949. _vq_lengthlist__44c1_sm_p4_0,
  124950. 1, -531628032, 1611661312, 4, 0,
  124951. _vq_quantlist__44c1_sm_p4_0,
  124952. NULL,
  124953. &_vq_auxt__44c1_sm_p4_0,
  124954. NULL,
  124955. 0
  124956. };
  124957. static long _vq_quantlist__44c1_sm_p5_0[] = {
  124958. 8,
  124959. 7,
  124960. 9,
  124961. 6,
  124962. 10,
  124963. 5,
  124964. 11,
  124965. 4,
  124966. 12,
  124967. 3,
  124968. 13,
  124969. 2,
  124970. 14,
  124971. 1,
  124972. 15,
  124973. 0,
  124974. 16,
  124975. };
  124976. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  124977. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124978. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124979. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  124980. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124981. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124982. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  124983. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  124984. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124985. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124986. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  124987. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124988. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124989. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124990. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124991. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  124992. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124993. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  124994. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124995. 14,
  124996. };
  124997. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  124998. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124999. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125000. };
  125001. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125002. 15, 13, 11, 9, 7, 5, 3, 1,
  125003. 0, 2, 4, 6, 8, 10, 12, 14,
  125004. 16,
  125005. };
  125006. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125007. _vq_quantthresh__44c1_sm_p5_0,
  125008. _vq_quantmap__44c1_sm_p5_0,
  125009. 17,
  125010. 17
  125011. };
  125012. static static_codebook _44c1_sm_p5_0 = {
  125013. 2, 289,
  125014. _vq_lengthlist__44c1_sm_p5_0,
  125015. 1, -529530880, 1611661312, 5, 0,
  125016. _vq_quantlist__44c1_sm_p5_0,
  125017. NULL,
  125018. &_vq_auxt__44c1_sm_p5_0,
  125019. NULL,
  125020. 0
  125021. };
  125022. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125023. 1,
  125024. 0,
  125025. 2,
  125026. };
  125027. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125028. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125029. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125030. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125031. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125032. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125033. 11,
  125034. };
  125035. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125036. -5.5, 5.5,
  125037. };
  125038. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125039. 1, 0, 2,
  125040. };
  125041. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125042. _vq_quantthresh__44c1_sm_p6_0,
  125043. _vq_quantmap__44c1_sm_p6_0,
  125044. 3,
  125045. 3
  125046. };
  125047. static static_codebook _44c1_sm_p6_0 = {
  125048. 4, 81,
  125049. _vq_lengthlist__44c1_sm_p6_0,
  125050. 1, -529137664, 1618345984, 2, 0,
  125051. _vq_quantlist__44c1_sm_p6_0,
  125052. NULL,
  125053. &_vq_auxt__44c1_sm_p6_0,
  125054. NULL,
  125055. 0
  125056. };
  125057. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125058. 5,
  125059. 4,
  125060. 6,
  125061. 3,
  125062. 7,
  125063. 2,
  125064. 8,
  125065. 1,
  125066. 9,
  125067. 0,
  125068. 10,
  125069. };
  125070. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125071. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125072. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125073. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125074. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125075. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125076. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125077. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125078. 10,10,10, 8, 8, 8, 8, 8, 8,
  125079. };
  125080. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125081. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125082. 3.5, 4.5,
  125083. };
  125084. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125085. 9, 7, 5, 3, 1, 0, 2, 4,
  125086. 6, 8, 10,
  125087. };
  125088. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125089. _vq_quantthresh__44c1_sm_p6_1,
  125090. _vq_quantmap__44c1_sm_p6_1,
  125091. 11,
  125092. 11
  125093. };
  125094. static static_codebook _44c1_sm_p6_1 = {
  125095. 2, 121,
  125096. _vq_lengthlist__44c1_sm_p6_1,
  125097. 1, -531365888, 1611661312, 4, 0,
  125098. _vq_quantlist__44c1_sm_p6_1,
  125099. NULL,
  125100. &_vq_auxt__44c1_sm_p6_1,
  125101. NULL,
  125102. 0
  125103. };
  125104. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125105. 6,
  125106. 5,
  125107. 7,
  125108. 4,
  125109. 8,
  125110. 3,
  125111. 9,
  125112. 2,
  125113. 10,
  125114. 1,
  125115. 11,
  125116. 0,
  125117. 12,
  125118. };
  125119. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125120. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125121. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125122. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125123. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125124. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125125. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125126. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125127. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125128. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125129. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125130. 0,12,12,11,11,13,12,14,13,
  125131. };
  125132. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125133. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125134. 12.5, 17.5, 22.5, 27.5,
  125135. };
  125136. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125137. 11, 9, 7, 5, 3, 1, 0, 2,
  125138. 4, 6, 8, 10, 12,
  125139. };
  125140. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125141. _vq_quantthresh__44c1_sm_p7_0,
  125142. _vq_quantmap__44c1_sm_p7_0,
  125143. 13,
  125144. 13
  125145. };
  125146. static static_codebook _44c1_sm_p7_0 = {
  125147. 2, 169,
  125148. _vq_lengthlist__44c1_sm_p7_0,
  125149. 1, -526516224, 1616117760, 4, 0,
  125150. _vq_quantlist__44c1_sm_p7_0,
  125151. NULL,
  125152. &_vq_auxt__44c1_sm_p7_0,
  125153. NULL,
  125154. 0
  125155. };
  125156. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125157. 2,
  125158. 1,
  125159. 3,
  125160. 0,
  125161. 4,
  125162. };
  125163. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125164. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125165. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125166. };
  125167. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125168. -1.5, -0.5, 0.5, 1.5,
  125169. };
  125170. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125171. 3, 1, 0, 2, 4,
  125172. };
  125173. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125174. _vq_quantthresh__44c1_sm_p7_1,
  125175. _vq_quantmap__44c1_sm_p7_1,
  125176. 5,
  125177. 5
  125178. };
  125179. static static_codebook _44c1_sm_p7_1 = {
  125180. 2, 25,
  125181. _vq_lengthlist__44c1_sm_p7_1,
  125182. 1, -533725184, 1611661312, 3, 0,
  125183. _vq_quantlist__44c1_sm_p7_1,
  125184. NULL,
  125185. &_vq_auxt__44c1_sm_p7_1,
  125186. NULL,
  125187. 0
  125188. };
  125189. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125190. 6,
  125191. 5,
  125192. 7,
  125193. 4,
  125194. 8,
  125195. 3,
  125196. 9,
  125197. 2,
  125198. 10,
  125199. 1,
  125200. 11,
  125201. 0,
  125202. 12,
  125203. };
  125204. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125205. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125206. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125207. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125208. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125209. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125210. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125211. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125212. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125213. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125214. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125215. 13,13,13,13,13,13,13,13,13,
  125216. };
  125217. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125218. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125219. 552.5, 773.5, 994.5, 1215.5,
  125220. };
  125221. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125222. 11, 9, 7, 5, 3, 1, 0, 2,
  125223. 4, 6, 8, 10, 12,
  125224. };
  125225. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125226. _vq_quantthresh__44c1_sm_p8_0,
  125227. _vq_quantmap__44c1_sm_p8_0,
  125228. 13,
  125229. 13
  125230. };
  125231. static static_codebook _44c1_sm_p8_0 = {
  125232. 2, 169,
  125233. _vq_lengthlist__44c1_sm_p8_0,
  125234. 1, -514541568, 1627103232, 4, 0,
  125235. _vq_quantlist__44c1_sm_p8_0,
  125236. NULL,
  125237. &_vq_auxt__44c1_sm_p8_0,
  125238. NULL,
  125239. 0
  125240. };
  125241. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125242. 6,
  125243. 5,
  125244. 7,
  125245. 4,
  125246. 8,
  125247. 3,
  125248. 9,
  125249. 2,
  125250. 10,
  125251. 1,
  125252. 11,
  125253. 0,
  125254. 12,
  125255. };
  125256. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125257. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125258. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125259. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125260. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125261. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125262. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125263. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125264. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125265. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125266. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125267. 20,13,12,12,12,14,12,14,13,
  125268. };
  125269. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125270. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125271. 42.5, 59.5, 76.5, 93.5,
  125272. };
  125273. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125274. 11, 9, 7, 5, 3, 1, 0, 2,
  125275. 4, 6, 8, 10, 12,
  125276. };
  125277. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125278. _vq_quantthresh__44c1_sm_p8_1,
  125279. _vq_quantmap__44c1_sm_p8_1,
  125280. 13,
  125281. 13
  125282. };
  125283. static static_codebook _44c1_sm_p8_1 = {
  125284. 2, 169,
  125285. _vq_lengthlist__44c1_sm_p8_1,
  125286. 1, -522616832, 1620115456, 4, 0,
  125287. _vq_quantlist__44c1_sm_p8_1,
  125288. NULL,
  125289. &_vq_auxt__44c1_sm_p8_1,
  125290. NULL,
  125291. 0
  125292. };
  125293. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125294. 8,
  125295. 7,
  125296. 9,
  125297. 6,
  125298. 10,
  125299. 5,
  125300. 11,
  125301. 4,
  125302. 12,
  125303. 3,
  125304. 13,
  125305. 2,
  125306. 14,
  125307. 1,
  125308. 15,
  125309. 0,
  125310. 16,
  125311. };
  125312. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125313. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125314. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125315. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125316. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125317. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125318. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125319. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125320. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125321. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125322. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125323. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125324. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125325. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125326. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125327. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125328. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125329. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125330. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125331. 9,
  125332. };
  125333. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125334. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125335. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125336. };
  125337. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125338. 15, 13, 11, 9, 7, 5, 3, 1,
  125339. 0, 2, 4, 6, 8, 10, 12, 14,
  125340. 16,
  125341. };
  125342. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125343. _vq_quantthresh__44c1_sm_p8_2,
  125344. _vq_quantmap__44c1_sm_p8_2,
  125345. 17,
  125346. 17
  125347. };
  125348. static static_codebook _44c1_sm_p8_2 = {
  125349. 2, 289,
  125350. _vq_lengthlist__44c1_sm_p8_2,
  125351. 1, -529530880, 1611661312, 5, 0,
  125352. _vq_quantlist__44c1_sm_p8_2,
  125353. NULL,
  125354. &_vq_auxt__44c1_sm_p8_2,
  125355. NULL,
  125356. 0
  125357. };
  125358. static long _huff_lengthlist__44c1_sm_short[] = {
  125359. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125360. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125361. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125362. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125363. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125364. 11,
  125365. };
  125366. static static_codebook _huff_book__44c1_sm_short = {
  125367. 2, 81,
  125368. _huff_lengthlist__44c1_sm_short,
  125369. 0, 0, 0, 0, 0,
  125370. NULL,
  125371. NULL,
  125372. NULL,
  125373. NULL,
  125374. 0
  125375. };
  125376. static long _huff_lengthlist__44cn1_s_long[] = {
  125377. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125378. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125379. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125380. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125381. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125382. 20,
  125383. };
  125384. static static_codebook _huff_book__44cn1_s_long = {
  125385. 2, 81,
  125386. _huff_lengthlist__44cn1_s_long,
  125387. 0, 0, 0, 0, 0,
  125388. NULL,
  125389. NULL,
  125390. NULL,
  125391. NULL,
  125392. 0
  125393. };
  125394. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125395. 1,
  125396. 0,
  125397. 2,
  125398. };
  125399. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125400. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125401. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125405. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125406. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125410. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125411. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125446. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  125447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  125451. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  125456. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125491. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125492. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125496. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125497. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  125498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125501. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125502. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  125503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125810. 0,
  125811. };
  125812. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  125813. -0.5, 0.5,
  125814. };
  125815. static long _vq_quantmap__44cn1_s_p1_0[] = {
  125816. 1, 0, 2,
  125817. };
  125818. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  125819. _vq_quantthresh__44cn1_s_p1_0,
  125820. _vq_quantmap__44cn1_s_p1_0,
  125821. 3,
  125822. 3
  125823. };
  125824. static static_codebook _44cn1_s_p1_0 = {
  125825. 8, 6561,
  125826. _vq_lengthlist__44cn1_s_p1_0,
  125827. 1, -535822336, 1611661312, 2, 0,
  125828. _vq_quantlist__44cn1_s_p1_0,
  125829. NULL,
  125830. &_vq_auxt__44cn1_s_p1_0,
  125831. NULL,
  125832. 0
  125833. };
  125834. static long _vq_quantlist__44cn1_s_p2_0[] = {
  125835. 2,
  125836. 1,
  125837. 3,
  125838. 0,
  125839. 4,
  125840. };
  125841. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  125842. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  125844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125845. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  125847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125848. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125881. 0,
  125882. };
  125883. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  125884. -1.5, -0.5, 0.5, 1.5,
  125885. };
  125886. static long _vq_quantmap__44cn1_s_p2_0[] = {
  125887. 3, 1, 0, 2, 4,
  125888. };
  125889. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  125890. _vq_quantthresh__44cn1_s_p2_0,
  125891. _vq_quantmap__44cn1_s_p2_0,
  125892. 5,
  125893. 5
  125894. };
  125895. static static_codebook _44cn1_s_p2_0 = {
  125896. 4, 625,
  125897. _vq_lengthlist__44cn1_s_p2_0,
  125898. 1, -533725184, 1611661312, 3, 0,
  125899. _vq_quantlist__44cn1_s_p2_0,
  125900. NULL,
  125901. &_vq_auxt__44cn1_s_p2_0,
  125902. NULL,
  125903. 0
  125904. };
  125905. static long _vq_quantlist__44cn1_s_p3_0[] = {
  125906. 4,
  125907. 3,
  125908. 5,
  125909. 2,
  125910. 6,
  125911. 1,
  125912. 7,
  125913. 0,
  125914. 8,
  125915. };
  125916. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  125917. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  125918. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  125919. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125920. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125921. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125922. 0,
  125923. };
  125924. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  125925. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125926. };
  125927. static long _vq_quantmap__44cn1_s_p3_0[] = {
  125928. 7, 5, 3, 1, 0, 2, 4, 6,
  125929. 8,
  125930. };
  125931. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  125932. _vq_quantthresh__44cn1_s_p3_0,
  125933. _vq_quantmap__44cn1_s_p3_0,
  125934. 9,
  125935. 9
  125936. };
  125937. static static_codebook _44cn1_s_p3_0 = {
  125938. 2, 81,
  125939. _vq_lengthlist__44cn1_s_p3_0,
  125940. 1, -531628032, 1611661312, 4, 0,
  125941. _vq_quantlist__44cn1_s_p3_0,
  125942. NULL,
  125943. &_vq_auxt__44cn1_s_p3_0,
  125944. NULL,
  125945. 0
  125946. };
  125947. static long _vq_quantlist__44cn1_s_p4_0[] = {
  125948. 4,
  125949. 3,
  125950. 5,
  125951. 2,
  125952. 6,
  125953. 1,
  125954. 7,
  125955. 0,
  125956. 8,
  125957. };
  125958. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  125959. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  125960. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  125961. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  125962. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  125963. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  125964. 11,
  125965. };
  125966. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  125967. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125968. };
  125969. static long _vq_quantmap__44cn1_s_p4_0[] = {
  125970. 7, 5, 3, 1, 0, 2, 4, 6,
  125971. 8,
  125972. };
  125973. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  125974. _vq_quantthresh__44cn1_s_p4_0,
  125975. _vq_quantmap__44cn1_s_p4_0,
  125976. 9,
  125977. 9
  125978. };
  125979. static static_codebook _44cn1_s_p4_0 = {
  125980. 2, 81,
  125981. _vq_lengthlist__44cn1_s_p4_0,
  125982. 1, -531628032, 1611661312, 4, 0,
  125983. _vq_quantlist__44cn1_s_p4_0,
  125984. NULL,
  125985. &_vq_auxt__44cn1_s_p4_0,
  125986. NULL,
  125987. 0
  125988. };
  125989. static long _vq_quantlist__44cn1_s_p5_0[] = {
  125990. 8,
  125991. 7,
  125992. 9,
  125993. 6,
  125994. 10,
  125995. 5,
  125996. 11,
  125997. 4,
  125998. 12,
  125999. 3,
  126000. 13,
  126001. 2,
  126002. 14,
  126003. 1,
  126004. 15,
  126005. 0,
  126006. 16,
  126007. };
  126008. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126009. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126010. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126011. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126012. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126013. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126014. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126015. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126016. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126017. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126018. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126019. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126020. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126021. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126022. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126023. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126024. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126025. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126026. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126027. 14,
  126028. };
  126029. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126030. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126031. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126032. };
  126033. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126034. 15, 13, 11, 9, 7, 5, 3, 1,
  126035. 0, 2, 4, 6, 8, 10, 12, 14,
  126036. 16,
  126037. };
  126038. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126039. _vq_quantthresh__44cn1_s_p5_0,
  126040. _vq_quantmap__44cn1_s_p5_0,
  126041. 17,
  126042. 17
  126043. };
  126044. static static_codebook _44cn1_s_p5_0 = {
  126045. 2, 289,
  126046. _vq_lengthlist__44cn1_s_p5_0,
  126047. 1, -529530880, 1611661312, 5, 0,
  126048. _vq_quantlist__44cn1_s_p5_0,
  126049. NULL,
  126050. &_vq_auxt__44cn1_s_p5_0,
  126051. NULL,
  126052. 0
  126053. };
  126054. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126055. 1,
  126056. 0,
  126057. 2,
  126058. };
  126059. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126060. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126061. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126062. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126063. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126064. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126065. 10,
  126066. };
  126067. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126068. -5.5, 5.5,
  126069. };
  126070. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126071. 1, 0, 2,
  126072. };
  126073. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126074. _vq_quantthresh__44cn1_s_p6_0,
  126075. _vq_quantmap__44cn1_s_p6_0,
  126076. 3,
  126077. 3
  126078. };
  126079. static static_codebook _44cn1_s_p6_0 = {
  126080. 4, 81,
  126081. _vq_lengthlist__44cn1_s_p6_0,
  126082. 1, -529137664, 1618345984, 2, 0,
  126083. _vq_quantlist__44cn1_s_p6_0,
  126084. NULL,
  126085. &_vq_auxt__44cn1_s_p6_0,
  126086. NULL,
  126087. 0
  126088. };
  126089. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126090. 5,
  126091. 4,
  126092. 6,
  126093. 3,
  126094. 7,
  126095. 2,
  126096. 8,
  126097. 1,
  126098. 9,
  126099. 0,
  126100. 10,
  126101. };
  126102. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126103. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126104. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126105. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126106. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126107. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126108. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126109. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126110. 10,10,10, 9, 9, 9, 9, 9, 9,
  126111. };
  126112. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126113. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126114. 3.5, 4.5,
  126115. };
  126116. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126117. 9, 7, 5, 3, 1, 0, 2, 4,
  126118. 6, 8, 10,
  126119. };
  126120. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126121. _vq_quantthresh__44cn1_s_p6_1,
  126122. _vq_quantmap__44cn1_s_p6_1,
  126123. 11,
  126124. 11
  126125. };
  126126. static static_codebook _44cn1_s_p6_1 = {
  126127. 2, 121,
  126128. _vq_lengthlist__44cn1_s_p6_1,
  126129. 1, -531365888, 1611661312, 4, 0,
  126130. _vq_quantlist__44cn1_s_p6_1,
  126131. NULL,
  126132. &_vq_auxt__44cn1_s_p6_1,
  126133. NULL,
  126134. 0
  126135. };
  126136. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126137. 6,
  126138. 5,
  126139. 7,
  126140. 4,
  126141. 8,
  126142. 3,
  126143. 9,
  126144. 2,
  126145. 10,
  126146. 1,
  126147. 11,
  126148. 0,
  126149. 12,
  126150. };
  126151. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126152. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126153. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126154. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126155. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126156. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126157. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126158. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126159. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126160. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126161. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126162. 0,13,13,12,12,13,13,13,14,
  126163. };
  126164. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126165. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126166. 12.5, 17.5, 22.5, 27.5,
  126167. };
  126168. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126169. 11, 9, 7, 5, 3, 1, 0, 2,
  126170. 4, 6, 8, 10, 12,
  126171. };
  126172. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126173. _vq_quantthresh__44cn1_s_p7_0,
  126174. _vq_quantmap__44cn1_s_p7_0,
  126175. 13,
  126176. 13
  126177. };
  126178. static static_codebook _44cn1_s_p7_0 = {
  126179. 2, 169,
  126180. _vq_lengthlist__44cn1_s_p7_0,
  126181. 1, -526516224, 1616117760, 4, 0,
  126182. _vq_quantlist__44cn1_s_p7_0,
  126183. NULL,
  126184. &_vq_auxt__44cn1_s_p7_0,
  126185. NULL,
  126186. 0
  126187. };
  126188. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126189. 2,
  126190. 1,
  126191. 3,
  126192. 0,
  126193. 4,
  126194. };
  126195. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126196. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126197. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126198. };
  126199. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126200. -1.5, -0.5, 0.5, 1.5,
  126201. };
  126202. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126203. 3, 1, 0, 2, 4,
  126204. };
  126205. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126206. _vq_quantthresh__44cn1_s_p7_1,
  126207. _vq_quantmap__44cn1_s_p7_1,
  126208. 5,
  126209. 5
  126210. };
  126211. static static_codebook _44cn1_s_p7_1 = {
  126212. 2, 25,
  126213. _vq_lengthlist__44cn1_s_p7_1,
  126214. 1, -533725184, 1611661312, 3, 0,
  126215. _vq_quantlist__44cn1_s_p7_1,
  126216. NULL,
  126217. &_vq_auxt__44cn1_s_p7_1,
  126218. NULL,
  126219. 0
  126220. };
  126221. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126222. 2,
  126223. 1,
  126224. 3,
  126225. 0,
  126226. 4,
  126227. };
  126228. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126229. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126230. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126231. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126232. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126233. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126234. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126235. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126236. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126237. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126238. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126239. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126240. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126241. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126242. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126243. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126244. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126245. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126246. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126248. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126249. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126250. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126251. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126252. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126253. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126254. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126255. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126256. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126257. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126258. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126259. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126260. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126262. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126263. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126264. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126265. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126266. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126267. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126268. 12,
  126269. };
  126270. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126271. -331.5, -110.5, 110.5, 331.5,
  126272. };
  126273. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126274. 3, 1, 0, 2, 4,
  126275. };
  126276. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126277. _vq_quantthresh__44cn1_s_p8_0,
  126278. _vq_quantmap__44cn1_s_p8_0,
  126279. 5,
  126280. 5
  126281. };
  126282. static static_codebook _44cn1_s_p8_0 = {
  126283. 4, 625,
  126284. _vq_lengthlist__44cn1_s_p8_0,
  126285. 1, -518283264, 1627103232, 3, 0,
  126286. _vq_quantlist__44cn1_s_p8_0,
  126287. NULL,
  126288. &_vq_auxt__44cn1_s_p8_0,
  126289. NULL,
  126290. 0
  126291. };
  126292. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126293. 6,
  126294. 5,
  126295. 7,
  126296. 4,
  126297. 8,
  126298. 3,
  126299. 9,
  126300. 2,
  126301. 10,
  126302. 1,
  126303. 11,
  126304. 0,
  126305. 12,
  126306. };
  126307. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126308. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126309. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126310. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126311. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126312. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126313. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126314. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126315. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126316. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126317. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126318. 15,12,12,11,11,14,12,13,14,
  126319. };
  126320. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126321. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126322. 42.5, 59.5, 76.5, 93.5,
  126323. };
  126324. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126325. 11, 9, 7, 5, 3, 1, 0, 2,
  126326. 4, 6, 8, 10, 12,
  126327. };
  126328. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126329. _vq_quantthresh__44cn1_s_p8_1,
  126330. _vq_quantmap__44cn1_s_p8_1,
  126331. 13,
  126332. 13
  126333. };
  126334. static static_codebook _44cn1_s_p8_1 = {
  126335. 2, 169,
  126336. _vq_lengthlist__44cn1_s_p8_1,
  126337. 1, -522616832, 1620115456, 4, 0,
  126338. _vq_quantlist__44cn1_s_p8_1,
  126339. NULL,
  126340. &_vq_auxt__44cn1_s_p8_1,
  126341. NULL,
  126342. 0
  126343. };
  126344. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126345. 8,
  126346. 7,
  126347. 9,
  126348. 6,
  126349. 10,
  126350. 5,
  126351. 11,
  126352. 4,
  126353. 12,
  126354. 3,
  126355. 13,
  126356. 2,
  126357. 14,
  126358. 1,
  126359. 15,
  126360. 0,
  126361. 16,
  126362. };
  126363. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126364. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126365. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126366. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126367. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126368. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126369. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126370. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126371. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126372. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126373. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126374. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126375. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126376. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126377. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126378. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126379. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126380. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126381. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126382. 9,
  126383. };
  126384. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126385. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126386. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126387. };
  126388. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126389. 15, 13, 11, 9, 7, 5, 3, 1,
  126390. 0, 2, 4, 6, 8, 10, 12, 14,
  126391. 16,
  126392. };
  126393. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126394. _vq_quantthresh__44cn1_s_p8_2,
  126395. _vq_quantmap__44cn1_s_p8_2,
  126396. 17,
  126397. 17
  126398. };
  126399. static static_codebook _44cn1_s_p8_2 = {
  126400. 2, 289,
  126401. _vq_lengthlist__44cn1_s_p8_2,
  126402. 1, -529530880, 1611661312, 5, 0,
  126403. _vq_quantlist__44cn1_s_p8_2,
  126404. NULL,
  126405. &_vq_auxt__44cn1_s_p8_2,
  126406. NULL,
  126407. 0
  126408. };
  126409. static long _huff_lengthlist__44cn1_s_short[] = {
  126410. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126411. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126412. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126413. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126414. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126415. 10,
  126416. };
  126417. static static_codebook _huff_book__44cn1_s_short = {
  126418. 2, 81,
  126419. _huff_lengthlist__44cn1_s_short,
  126420. 0, 0, 0, 0, 0,
  126421. NULL,
  126422. NULL,
  126423. NULL,
  126424. NULL,
  126425. 0
  126426. };
  126427. static long _huff_lengthlist__44cn1_sm_long[] = {
  126428. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126429. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126430. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126431. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126432. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126433. 17,
  126434. };
  126435. static static_codebook _huff_book__44cn1_sm_long = {
  126436. 2, 81,
  126437. _huff_lengthlist__44cn1_sm_long,
  126438. 0, 0, 0, 0, 0,
  126439. NULL,
  126440. NULL,
  126441. NULL,
  126442. NULL,
  126443. 0
  126444. };
  126445. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126446. 1,
  126447. 0,
  126448. 2,
  126449. };
  126450. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126451. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126452. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126456. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126457. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126461. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126462. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126497. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  126502. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  126507. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  126508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126542. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126543. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126547. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126548. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  126549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126552. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126553. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  126554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126861. 0,
  126862. };
  126863. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  126864. -0.5, 0.5,
  126865. };
  126866. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  126867. 1, 0, 2,
  126868. };
  126869. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  126870. _vq_quantthresh__44cn1_sm_p1_0,
  126871. _vq_quantmap__44cn1_sm_p1_0,
  126872. 3,
  126873. 3
  126874. };
  126875. static static_codebook _44cn1_sm_p1_0 = {
  126876. 8, 6561,
  126877. _vq_lengthlist__44cn1_sm_p1_0,
  126878. 1, -535822336, 1611661312, 2, 0,
  126879. _vq_quantlist__44cn1_sm_p1_0,
  126880. NULL,
  126881. &_vq_auxt__44cn1_sm_p1_0,
  126882. NULL,
  126883. 0
  126884. };
  126885. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  126886. 2,
  126887. 1,
  126888. 3,
  126889. 0,
  126890. 4,
  126891. };
  126892. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  126893. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126896. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126899. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126932. 0,
  126933. };
  126934. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  126935. -1.5, -0.5, 0.5, 1.5,
  126936. };
  126937. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  126938. 3, 1, 0, 2, 4,
  126939. };
  126940. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  126941. _vq_quantthresh__44cn1_sm_p2_0,
  126942. _vq_quantmap__44cn1_sm_p2_0,
  126943. 5,
  126944. 5
  126945. };
  126946. static static_codebook _44cn1_sm_p2_0 = {
  126947. 4, 625,
  126948. _vq_lengthlist__44cn1_sm_p2_0,
  126949. 1, -533725184, 1611661312, 3, 0,
  126950. _vq_quantlist__44cn1_sm_p2_0,
  126951. NULL,
  126952. &_vq_auxt__44cn1_sm_p2_0,
  126953. NULL,
  126954. 0
  126955. };
  126956. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  126957. 4,
  126958. 3,
  126959. 5,
  126960. 2,
  126961. 6,
  126962. 1,
  126963. 7,
  126964. 0,
  126965. 8,
  126966. };
  126967. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  126968. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  126969. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  126970. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  126971. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  126972. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126973. 0,
  126974. };
  126975. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  126976. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126977. };
  126978. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  126979. 7, 5, 3, 1, 0, 2, 4, 6,
  126980. 8,
  126981. };
  126982. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  126983. _vq_quantthresh__44cn1_sm_p3_0,
  126984. _vq_quantmap__44cn1_sm_p3_0,
  126985. 9,
  126986. 9
  126987. };
  126988. static static_codebook _44cn1_sm_p3_0 = {
  126989. 2, 81,
  126990. _vq_lengthlist__44cn1_sm_p3_0,
  126991. 1, -531628032, 1611661312, 4, 0,
  126992. _vq_quantlist__44cn1_sm_p3_0,
  126993. NULL,
  126994. &_vq_auxt__44cn1_sm_p3_0,
  126995. NULL,
  126996. 0
  126997. };
  126998. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  126999. 4,
  127000. 3,
  127001. 5,
  127002. 2,
  127003. 6,
  127004. 1,
  127005. 7,
  127006. 0,
  127007. 8,
  127008. };
  127009. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127010. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127011. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127012. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127013. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127014. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127015. 11,
  127016. };
  127017. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127018. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127019. };
  127020. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127021. 7, 5, 3, 1, 0, 2, 4, 6,
  127022. 8,
  127023. };
  127024. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127025. _vq_quantthresh__44cn1_sm_p4_0,
  127026. _vq_quantmap__44cn1_sm_p4_0,
  127027. 9,
  127028. 9
  127029. };
  127030. static static_codebook _44cn1_sm_p4_0 = {
  127031. 2, 81,
  127032. _vq_lengthlist__44cn1_sm_p4_0,
  127033. 1, -531628032, 1611661312, 4, 0,
  127034. _vq_quantlist__44cn1_sm_p4_0,
  127035. NULL,
  127036. &_vq_auxt__44cn1_sm_p4_0,
  127037. NULL,
  127038. 0
  127039. };
  127040. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127041. 8,
  127042. 7,
  127043. 9,
  127044. 6,
  127045. 10,
  127046. 5,
  127047. 11,
  127048. 4,
  127049. 12,
  127050. 3,
  127051. 13,
  127052. 2,
  127053. 14,
  127054. 1,
  127055. 15,
  127056. 0,
  127057. 16,
  127058. };
  127059. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127060. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127061. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127062. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127063. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127064. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127065. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127066. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127067. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127068. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127069. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127070. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127071. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127072. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127073. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127074. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127075. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127076. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127077. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127078. 14,
  127079. };
  127080. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127081. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127082. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127083. };
  127084. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127085. 15, 13, 11, 9, 7, 5, 3, 1,
  127086. 0, 2, 4, 6, 8, 10, 12, 14,
  127087. 16,
  127088. };
  127089. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127090. _vq_quantthresh__44cn1_sm_p5_0,
  127091. _vq_quantmap__44cn1_sm_p5_0,
  127092. 17,
  127093. 17
  127094. };
  127095. static static_codebook _44cn1_sm_p5_0 = {
  127096. 2, 289,
  127097. _vq_lengthlist__44cn1_sm_p5_0,
  127098. 1, -529530880, 1611661312, 5, 0,
  127099. _vq_quantlist__44cn1_sm_p5_0,
  127100. NULL,
  127101. &_vq_auxt__44cn1_sm_p5_0,
  127102. NULL,
  127103. 0
  127104. };
  127105. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127106. 1,
  127107. 0,
  127108. 2,
  127109. };
  127110. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127111. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127112. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127113. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127114. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127115. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127116. 10,
  127117. };
  127118. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127119. -5.5, 5.5,
  127120. };
  127121. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127122. 1, 0, 2,
  127123. };
  127124. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127125. _vq_quantthresh__44cn1_sm_p6_0,
  127126. _vq_quantmap__44cn1_sm_p6_0,
  127127. 3,
  127128. 3
  127129. };
  127130. static static_codebook _44cn1_sm_p6_0 = {
  127131. 4, 81,
  127132. _vq_lengthlist__44cn1_sm_p6_0,
  127133. 1, -529137664, 1618345984, 2, 0,
  127134. _vq_quantlist__44cn1_sm_p6_0,
  127135. NULL,
  127136. &_vq_auxt__44cn1_sm_p6_0,
  127137. NULL,
  127138. 0
  127139. };
  127140. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127141. 5,
  127142. 4,
  127143. 6,
  127144. 3,
  127145. 7,
  127146. 2,
  127147. 8,
  127148. 1,
  127149. 9,
  127150. 0,
  127151. 10,
  127152. };
  127153. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127154. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127155. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127156. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127157. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127158. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127159. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127160. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127161. 10,10,10, 8, 9, 8, 8, 9, 8,
  127162. };
  127163. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127164. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127165. 3.5, 4.5,
  127166. };
  127167. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127168. 9, 7, 5, 3, 1, 0, 2, 4,
  127169. 6, 8, 10,
  127170. };
  127171. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127172. _vq_quantthresh__44cn1_sm_p6_1,
  127173. _vq_quantmap__44cn1_sm_p6_1,
  127174. 11,
  127175. 11
  127176. };
  127177. static static_codebook _44cn1_sm_p6_1 = {
  127178. 2, 121,
  127179. _vq_lengthlist__44cn1_sm_p6_1,
  127180. 1, -531365888, 1611661312, 4, 0,
  127181. _vq_quantlist__44cn1_sm_p6_1,
  127182. NULL,
  127183. &_vq_auxt__44cn1_sm_p6_1,
  127184. NULL,
  127185. 0
  127186. };
  127187. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127188. 6,
  127189. 5,
  127190. 7,
  127191. 4,
  127192. 8,
  127193. 3,
  127194. 9,
  127195. 2,
  127196. 10,
  127197. 1,
  127198. 11,
  127199. 0,
  127200. 12,
  127201. };
  127202. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127203. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127204. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127205. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127206. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127207. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127208. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127209. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127210. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127211. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127212. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127213. 0,13,12,12,12,13,13,13,14,
  127214. };
  127215. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127216. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127217. 12.5, 17.5, 22.5, 27.5,
  127218. };
  127219. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127220. 11, 9, 7, 5, 3, 1, 0, 2,
  127221. 4, 6, 8, 10, 12,
  127222. };
  127223. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127224. _vq_quantthresh__44cn1_sm_p7_0,
  127225. _vq_quantmap__44cn1_sm_p7_0,
  127226. 13,
  127227. 13
  127228. };
  127229. static static_codebook _44cn1_sm_p7_0 = {
  127230. 2, 169,
  127231. _vq_lengthlist__44cn1_sm_p7_0,
  127232. 1, -526516224, 1616117760, 4, 0,
  127233. _vq_quantlist__44cn1_sm_p7_0,
  127234. NULL,
  127235. &_vq_auxt__44cn1_sm_p7_0,
  127236. NULL,
  127237. 0
  127238. };
  127239. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127240. 2,
  127241. 1,
  127242. 3,
  127243. 0,
  127244. 4,
  127245. };
  127246. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127247. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127248. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127249. };
  127250. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127251. -1.5, -0.5, 0.5, 1.5,
  127252. };
  127253. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127254. 3, 1, 0, 2, 4,
  127255. };
  127256. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127257. _vq_quantthresh__44cn1_sm_p7_1,
  127258. _vq_quantmap__44cn1_sm_p7_1,
  127259. 5,
  127260. 5
  127261. };
  127262. static static_codebook _44cn1_sm_p7_1 = {
  127263. 2, 25,
  127264. _vq_lengthlist__44cn1_sm_p7_1,
  127265. 1, -533725184, 1611661312, 3, 0,
  127266. _vq_quantlist__44cn1_sm_p7_1,
  127267. NULL,
  127268. &_vq_auxt__44cn1_sm_p7_1,
  127269. NULL,
  127270. 0
  127271. };
  127272. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127273. 4,
  127274. 3,
  127275. 5,
  127276. 2,
  127277. 6,
  127278. 1,
  127279. 7,
  127280. 0,
  127281. 8,
  127282. };
  127283. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127284. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127285. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127286. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127287. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127288. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127289. 14,
  127290. };
  127291. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127292. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127293. };
  127294. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127295. 7, 5, 3, 1, 0, 2, 4, 6,
  127296. 8,
  127297. };
  127298. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127299. _vq_quantthresh__44cn1_sm_p8_0,
  127300. _vq_quantmap__44cn1_sm_p8_0,
  127301. 9,
  127302. 9
  127303. };
  127304. static static_codebook _44cn1_sm_p8_0 = {
  127305. 2, 81,
  127306. _vq_lengthlist__44cn1_sm_p8_0,
  127307. 1, -516186112, 1627103232, 4, 0,
  127308. _vq_quantlist__44cn1_sm_p8_0,
  127309. NULL,
  127310. &_vq_auxt__44cn1_sm_p8_0,
  127311. NULL,
  127312. 0
  127313. };
  127314. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127315. 6,
  127316. 5,
  127317. 7,
  127318. 4,
  127319. 8,
  127320. 3,
  127321. 9,
  127322. 2,
  127323. 10,
  127324. 1,
  127325. 11,
  127326. 0,
  127327. 12,
  127328. };
  127329. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127330. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127331. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127332. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127333. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127334. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127335. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127336. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127337. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127338. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127339. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127340. 17,12,12,11,10,13,11,13,13,
  127341. };
  127342. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127343. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127344. 42.5, 59.5, 76.5, 93.5,
  127345. };
  127346. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127347. 11, 9, 7, 5, 3, 1, 0, 2,
  127348. 4, 6, 8, 10, 12,
  127349. };
  127350. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127351. _vq_quantthresh__44cn1_sm_p8_1,
  127352. _vq_quantmap__44cn1_sm_p8_1,
  127353. 13,
  127354. 13
  127355. };
  127356. static static_codebook _44cn1_sm_p8_1 = {
  127357. 2, 169,
  127358. _vq_lengthlist__44cn1_sm_p8_1,
  127359. 1, -522616832, 1620115456, 4, 0,
  127360. _vq_quantlist__44cn1_sm_p8_1,
  127361. NULL,
  127362. &_vq_auxt__44cn1_sm_p8_1,
  127363. NULL,
  127364. 0
  127365. };
  127366. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127367. 8,
  127368. 7,
  127369. 9,
  127370. 6,
  127371. 10,
  127372. 5,
  127373. 11,
  127374. 4,
  127375. 12,
  127376. 3,
  127377. 13,
  127378. 2,
  127379. 14,
  127380. 1,
  127381. 15,
  127382. 0,
  127383. 16,
  127384. };
  127385. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127386. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127387. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127388. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127389. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127390. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127391. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127392. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127393. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127394. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127395. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127396. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127397. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127398. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127399. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127400. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127401. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127402. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127403. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127404. 9,
  127405. };
  127406. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127407. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127408. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127409. };
  127410. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127411. 15, 13, 11, 9, 7, 5, 3, 1,
  127412. 0, 2, 4, 6, 8, 10, 12, 14,
  127413. 16,
  127414. };
  127415. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127416. _vq_quantthresh__44cn1_sm_p8_2,
  127417. _vq_quantmap__44cn1_sm_p8_2,
  127418. 17,
  127419. 17
  127420. };
  127421. static static_codebook _44cn1_sm_p8_2 = {
  127422. 2, 289,
  127423. _vq_lengthlist__44cn1_sm_p8_2,
  127424. 1, -529530880, 1611661312, 5, 0,
  127425. _vq_quantlist__44cn1_sm_p8_2,
  127426. NULL,
  127427. &_vq_auxt__44cn1_sm_p8_2,
  127428. NULL,
  127429. 0
  127430. };
  127431. static long _huff_lengthlist__44cn1_sm_short[] = {
  127432. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127433. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127434. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127435. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127436. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127437. 9,
  127438. };
  127439. static static_codebook _huff_book__44cn1_sm_short = {
  127440. 2, 81,
  127441. _huff_lengthlist__44cn1_sm_short,
  127442. 0, 0, 0, 0, 0,
  127443. NULL,
  127444. NULL,
  127445. NULL,
  127446. NULL,
  127447. 0
  127448. };
  127449. /*** End of inlined file: res_books_stereo.h ***/
  127450. static vorbis_info_residue0 _residue_44_low={
  127451. 0,-1, -1, 9,-1,
  127452. {0},
  127453. {-1},
  127454. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127455. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127456. };
  127457. static vorbis_info_residue0 _residue_44_mid={
  127458. 0,-1, -1, 10,-1,
  127459. {0},
  127460. {-1},
  127461. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127462. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127463. };
  127464. static vorbis_info_residue0 _residue_44_high={
  127465. 0,-1, -1, 10,-1,
  127466. {0},
  127467. {-1},
  127468. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127469. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127470. };
  127471. static static_bookblock _resbook_44s_n1={
  127472. {
  127473. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127474. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127475. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127476. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127477. }
  127478. };
  127479. static static_bookblock _resbook_44sm_n1={
  127480. {
  127481. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127482. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127483. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127484. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127485. }
  127486. };
  127487. static static_bookblock _resbook_44s_0={
  127488. {
  127489. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127490. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127491. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127492. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127493. }
  127494. };
  127495. static static_bookblock _resbook_44sm_0={
  127496. {
  127497. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127498. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127499. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127500. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127501. }
  127502. };
  127503. static static_bookblock _resbook_44s_1={
  127504. {
  127505. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127506. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127507. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127508. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127509. }
  127510. };
  127511. static static_bookblock _resbook_44sm_1={
  127512. {
  127513. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127514. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127515. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127516. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127517. }
  127518. };
  127519. static static_bookblock _resbook_44s_2={
  127520. {
  127521. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127522. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127523. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127524. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127525. }
  127526. };
  127527. static static_bookblock _resbook_44s_3={
  127528. {
  127529. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127530. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127531. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127532. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127533. }
  127534. };
  127535. static static_bookblock _resbook_44s_4={
  127536. {
  127537. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127538. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127539. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127540. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127541. }
  127542. };
  127543. static static_bookblock _resbook_44s_5={
  127544. {
  127545. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127546. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127547. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127548. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127549. }
  127550. };
  127551. static static_bookblock _resbook_44s_6={
  127552. {
  127553. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127554. {0,0,&_44c6_s_p4_0},
  127555. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127556. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127557. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127558. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127559. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127560. }
  127561. };
  127562. static static_bookblock _resbook_44s_7={
  127563. {
  127564. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127565. {0,0,&_44c7_s_p4_0},
  127566. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127567. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127568. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127569. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127570. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127571. }
  127572. };
  127573. static static_bookblock _resbook_44s_8={
  127574. {
  127575. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127576. {0,0,&_44c8_s_p4_0},
  127577. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127578. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127579. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127580. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127581. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127582. }
  127583. };
  127584. static static_bookblock _resbook_44s_9={
  127585. {
  127586. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127587. {0,0,&_44c9_s_p4_0},
  127588. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127589. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127590. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127591. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127592. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127593. }
  127594. };
  127595. static vorbis_residue_template _res_44s_n1[]={
  127596. {2,0, &_residue_44_low,
  127597. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127598. &_resbook_44s_n1,&_resbook_44sm_n1},
  127599. {2,0, &_residue_44_low,
  127600. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127601. &_resbook_44s_n1,&_resbook_44sm_n1}
  127602. };
  127603. static vorbis_residue_template _res_44s_0[]={
  127604. {2,0, &_residue_44_low,
  127605. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127606. &_resbook_44s_0,&_resbook_44sm_0},
  127607. {2,0, &_residue_44_low,
  127608. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127609. &_resbook_44s_0,&_resbook_44sm_0}
  127610. };
  127611. static vorbis_residue_template _res_44s_1[]={
  127612. {2,0, &_residue_44_low,
  127613. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127614. &_resbook_44s_1,&_resbook_44sm_1},
  127615. {2,0, &_residue_44_low,
  127616. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127617. &_resbook_44s_1,&_resbook_44sm_1}
  127618. };
  127619. static vorbis_residue_template _res_44s_2[]={
  127620. {2,0, &_residue_44_mid,
  127621. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127622. &_resbook_44s_2,&_resbook_44s_2},
  127623. {2,0, &_residue_44_mid,
  127624. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127625. &_resbook_44s_2,&_resbook_44s_2}
  127626. };
  127627. static vorbis_residue_template _res_44s_3[]={
  127628. {2,0, &_residue_44_mid,
  127629. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127630. &_resbook_44s_3,&_resbook_44s_3},
  127631. {2,0, &_residue_44_mid,
  127632. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127633. &_resbook_44s_3,&_resbook_44s_3}
  127634. };
  127635. static vorbis_residue_template _res_44s_4[]={
  127636. {2,0, &_residue_44_mid,
  127637. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127638. &_resbook_44s_4,&_resbook_44s_4},
  127639. {2,0, &_residue_44_mid,
  127640. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127641. &_resbook_44s_4,&_resbook_44s_4}
  127642. };
  127643. static vorbis_residue_template _res_44s_5[]={
  127644. {2,0, &_residue_44_mid,
  127645. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127646. &_resbook_44s_5,&_resbook_44s_5},
  127647. {2,0, &_residue_44_mid,
  127648. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127649. &_resbook_44s_5,&_resbook_44s_5}
  127650. };
  127651. static vorbis_residue_template _res_44s_6[]={
  127652. {2,0, &_residue_44_high,
  127653. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127654. &_resbook_44s_6,&_resbook_44s_6},
  127655. {2,0, &_residue_44_high,
  127656. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127657. &_resbook_44s_6,&_resbook_44s_6}
  127658. };
  127659. static vorbis_residue_template _res_44s_7[]={
  127660. {2,0, &_residue_44_high,
  127661. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127662. &_resbook_44s_7,&_resbook_44s_7},
  127663. {2,0, &_residue_44_high,
  127664. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127665. &_resbook_44s_7,&_resbook_44s_7}
  127666. };
  127667. static vorbis_residue_template _res_44s_8[]={
  127668. {2,0, &_residue_44_high,
  127669. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127670. &_resbook_44s_8,&_resbook_44s_8},
  127671. {2,0, &_residue_44_high,
  127672. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127673. &_resbook_44s_8,&_resbook_44s_8}
  127674. };
  127675. static vorbis_residue_template _res_44s_9[]={
  127676. {2,0, &_residue_44_high,
  127677. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127678. &_resbook_44s_9,&_resbook_44s_9},
  127679. {2,0, &_residue_44_high,
  127680. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127681. &_resbook_44s_9,&_resbook_44s_9}
  127682. };
  127683. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127684. { _map_nominal, _res_44s_n1 }, /* -1 */
  127685. { _map_nominal, _res_44s_0 }, /* 0 */
  127686. { _map_nominal, _res_44s_1 }, /* 1 */
  127687. { _map_nominal, _res_44s_2 }, /* 2 */
  127688. { _map_nominal, _res_44s_3 }, /* 3 */
  127689. { _map_nominal, _res_44s_4 }, /* 4 */
  127690. { _map_nominal, _res_44s_5 }, /* 5 */
  127691. { _map_nominal, _res_44s_6 }, /* 6 */
  127692. { _map_nominal, _res_44s_7 }, /* 7 */
  127693. { _map_nominal, _res_44s_8 }, /* 8 */
  127694. { _map_nominal, _res_44s_9 }, /* 9 */
  127695. };
  127696. /*** End of inlined file: residue_44.h ***/
  127697. /*** Start of inlined file: psych_44.h ***/
  127698. static vorbis_info_psy_global _psy_global_44[5]={
  127699. {8, /* lines per eighth octave */
  127700. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127701. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127702. -6.f,
  127703. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127704. },
  127705. {8, /* lines per eighth octave */
  127706. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127707. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127708. -6.f,
  127709. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127710. },
  127711. {8, /* lines per eighth octave */
  127712. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127713. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127714. -6.f,
  127715. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127716. },
  127717. {8, /* lines per eighth octave */
  127718. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127719. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127720. -6.f,
  127721. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127722. },
  127723. {8, /* lines per eighth octave */
  127724. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127725. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127726. -6.f,
  127727. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127728. },
  127729. };
  127730. static compandblock _psy_compand_44[6]={
  127731. {{
  127732. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127733. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127734. 16,17,18,19,20,21,22, 23, /* 23dB */
  127735. 24,25,26,27,28,29,30, 31, /* 31dB */
  127736. 32,33,34,35,36,37,38, 39, /* 39dB */
  127737. }},
  127738. {{
  127739. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127740. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127741. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127742. 15,16,17,17,17,18,18, 19, /* 31dB */
  127743. 19,19,20,21,22,23,24, 25, /* 39dB */
  127744. }},
  127745. {{
  127746. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127747. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127748. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127749. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127750. 11,12,13,14,15,16,17, 18, /* 39dB */
  127751. }},
  127752. {{
  127753. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127754. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127755. 16,17,18,19,20,21,22, 23, /* 23dB */
  127756. 24,25,26,27,28,29,30, 31, /* 31dB */
  127757. 32,33,34,35,36,37,38, 39, /* 39dB */
  127758. }},
  127759. {{
  127760. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127761. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127762. 13,14,14,14,15,15,15, 15, /* 23dB */
  127763. 16,16,17,17,17,18,18, 19, /* 31dB */
  127764. 19,19,20,21,22,23,24, 25, /* 39dB */
  127765. }},
  127766. {{
  127767. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127768. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127769. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127770. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127771. 11,12,13,14,15,16,17, 18, /* 39dB */
  127772. }}
  127773. };
  127774. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127775. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127776. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127777. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127778. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127779. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127780. /* 4 */
  127781. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127782. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127783. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127784. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127785. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127786. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127787. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127788. };
  127789. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127790. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127791. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127792. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127793. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127794. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127795. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127796. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127797. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127798. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127799. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127800. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127801. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127802. };
  127803. static noise3 _psy_noisebias_trans[12]={
  127804. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127805. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127806. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127807. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127808. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127809. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127810. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127811. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127812. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127813. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127814. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127815. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  127816. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127817. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127818. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127819. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127820. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127821. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127822. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127823. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127824. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  127825. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127826. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127827. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127828. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127829. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  127830. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127831. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  127832. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  127833. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127834. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127835. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  127836. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  127837. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  127838. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  127839. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127840. };
  127841. static noise3 _psy_noisebias_long[12]={
  127842. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  127843. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  127844. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127845. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  127846. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  127847. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127848. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127849. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127850. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127851. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127852. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127853. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127854. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127855. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127856. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  127857. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127858. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127859. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  127860. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127861. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127862. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  127863. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127864. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127865. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  127866. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127867. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  127868. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127869. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  127870. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  127871. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127872. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127873. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  127874. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127875. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  127876. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  127877. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127878. };
  127879. static noise3 _psy_noisebias_impulse[12]={
  127880. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127881. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127882. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127883. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  127884. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  127885. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127886. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  127887. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  127888. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  127889. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  127890. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127891. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127892. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  127893. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127894. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127895. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  127896. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127897. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127898. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  127899. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  127900. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  127901. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  127902. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  127903. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  127904. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  127905. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  127906. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  127907. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  127908. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  127909. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  127910. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127911. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  127912. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127913. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  127914. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  127915. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127916. };
  127917. static noise3 _psy_noisebias_padding[12]={
  127918. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127919. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127920. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127921. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127922. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  127923. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  127924. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  127925. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  127926. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  127927. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  127928. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  127929. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127930. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  127931. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  127932. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127933. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  127934. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  127935. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127936. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127937. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  127938. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  127939. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127940. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  127941. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  127942. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127943. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  127944. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  127945. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  127946. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  127947. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  127948. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  127949. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  127950. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  127951. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  127952. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  127953. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127954. };
  127955. static noiseguard _psy_noiseguards_44[4]={
  127956. {3,3,15},
  127957. {3,3,15},
  127958. {10,10,100},
  127959. {10,10,100},
  127960. };
  127961. static int _psy_tone_suppress[12]={
  127962. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  127963. };
  127964. static int _psy_tone_0dB[12]={
  127965. 90,90,95,95,95,95,105,105,105,105,105,105,
  127966. };
  127967. static int _psy_noise_suppress[12]={
  127968. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  127969. };
  127970. static vorbis_info_psy _psy_info_template={
  127971. -1,
  127972. -140.,-140.,
  127973. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  127974. 1, -0.f, .5f, .5f, 0,0,0,
  127975. {{-1},{-1},{-1}},{-1},105.f,
  127976. 0,0,-1,-1,0.,
  127977. };
  127978. static int _psy_ath_floater[12]={
  127979. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  127980. };
  127981. static int _psy_ath_abs[12]={
  127982. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  127983. };
  127984. static adj_stereo _psy_stereo_modes_44[12]={
  127985. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  127986. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  127987. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  127988. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  127989. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  127990. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  127991. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  127992. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  127993. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  127994. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  127995. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  127996. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  127997. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  127998. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  127999. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128000. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128001. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128002. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128003. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128004. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128005. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128006. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128007. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128008. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128009. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128010. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128011. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128012. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128013. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128014. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128015. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128016. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128017. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128018. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128019. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128020. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128021. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128022. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128023. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128024. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128025. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128026. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128027. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128028. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128029. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128030. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128031. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128032. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128033. };
  128034. static att3 _psy_tone_masteratt_44[12]={
  128035. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128036. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128037. /* 1 */
  128038. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128039. /* 2 */
  128040. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128041. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128042. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128043. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128044. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128045. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128046. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128047. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128048. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128049. };
  128050. static double _psy_lowpass_44[12]={
  128051. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128052. };
  128053. static int _noise_start_short_44[11]={
  128054. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128055. };
  128056. static int _noise_start_long_44[11]={
  128057. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128058. };
  128059. static int _noise_part_short_44[11]={
  128060. 8,8,8,8,8,8,8,8,8,8,8
  128061. };
  128062. static int _noise_part_long_44[11]={
  128063. 32,32,32,32,32,32,32,32,32,32,32
  128064. };
  128065. static double _noise_thresh_44[11]={
  128066. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128067. };
  128068. static double _noise_thresh_5only[2]={
  128069. .5,.5,
  128070. };
  128071. /*** End of inlined file: psych_44.h ***/
  128072. static double rate_mapping_44_stereo[12]={
  128073. 22500.,32000.,40000.,48000.,56000.,64000.,
  128074. 80000.,96000.,112000.,128000.,160000.,250001.
  128075. };
  128076. static double quality_mapping_44[12]={
  128077. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128078. };
  128079. static int blocksize_short_44[11]={
  128080. 512,256,256,256,256,256,256,256,256,256,256
  128081. };
  128082. static int blocksize_long_44[11]={
  128083. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128084. };
  128085. static double _psy_compand_short_mapping[12]={
  128086. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128087. };
  128088. static double _psy_compand_long_mapping[12]={
  128089. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128090. };
  128091. static double _global_mapping_44[12]={
  128092. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128093. };
  128094. static int _floor_short_mapping_44[11]={
  128095. 1,0,0,2,2,4,5,5,5,5,5
  128096. };
  128097. static int _floor_long_mapping_44[11]={
  128098. 8,7,7,7,7,7,7,7,7,7,7
  128099. };
  128100. ve_setup_data_template ve_setup_44_stereo={
  128101. 11,
  128102. rate_mapping_44_stereo,
  128103. quality_mapping_44,
  128104. 2,
  128105. 40000,
  128106. 50000,
  128107. blocksize_short_44,
  128108. blocksize_long_44,
  128109. _psy_tone_masteratt_44,
  128110. _psy_tone_0dB,
  128111. _psy_tone_suppress,
  128112. _vp_tonemask_adj_otherblock,
  128113. _vp_tonemask_adj_longblock,
  128114. _vp_tonemask_adj_otherblock,
  128115. _psy_noiseguards_44,
  128116. _psy_noisebias_impulse,
  128117. _psy_noisebias_padding,
  128118. _psy_noisebias_trans,
  128119. _psy_noisebias_long,
  128120. _psy_noise_suppress,
  128121. _psy_compand_44,
  128122. _psy_compand_short_mapping,
  128123. _psy_compand_long_mapping,
  128124. {_noise_start_short_44,_noise_start_long_44},
  128125. {_noise_part_short_44,_noise_part_long_44},
  128126. _noise_thresh_44,
  128127. _psy_ath_floater,
  128128. _psy_ath_abs,
  128129. _psy_lowpass_44,
  128130. _psy_global_44,
  128131. _global_mapping_44,
  128132. _psy_stereo_modes_44,
  128133. _floor_books,
  128134. _floor,
  128135. _floor_short_mapping_44,
  128136. _floor_long_mapping_44,
  128137. _mapres_template_44_stereo
  128138. };
  128139. /*** End of inlined file: setup_44.h ***/
  128140. /*** Start of inlined file: setup_44u.h ***/
  128141. /*** Start of inlined file: residue_44u.h ***/
  128142. /*** Start of inlined file: res_books_uncoupled.h ***/
  128143. static long _vq_quantlist__16u0__p1_0[] = {
  128144. 1,
  128145. 0,
  128146. 2,
  128147. };
  128148. static long _vq_lengthlist__16u0__p1_0[] = {
  128149. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128150. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128151. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128152. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128153. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128154. 12,
  128155. };
  128156. static float _vq_quantthresh__16u0__p1_0[] = {
  128157. -0.5, 0.5,
  128158. };
  128159. static long _vq_quantmap__16u0__p1_0[] = {
  128160. 1, 0, 2,
  128161. };
  128162. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128163. _vq_quantthresh__16u0__p1_0,
  128164. _vq_quantmap__16u0__p1_0,
  128165. 3,
  128166. 3
  128167. };
  128168. static static_codebook _16u0__p1_0 = {
  128169. 4, 81,
  128170. _vq_lengthlist__16u0__p1_0,
  128171. 1, -535822336, 1611661312, 2, 0,
  128172. _vq_quantlist__16u0__p1_0,
  128173. NULL,
  128174. &_vq_auxt__16u0__p1_0,
  128175. NULL,
  128176. 0
  128177. };
  128178. static long _vq_quantlist__16u0__p2_0[] = {
  128179. 1,
  128180. 0,
  128181. 2,
  128182. };
  128183. static long _vq_lengthlist__16u0__p2_0[] = {
  128184. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128185. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128186. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128187. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128188. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128189. 8,
  128190. };
  128191. static float _vq_quantthresh__16u0__p2_0[] = {
  128192. -0.5, 0.5,
  128193. };
  128194. static long _vq_quantmap__16u0__p2_0[] = {
  128195. 1, 0, 2,
  128196. };
  128197. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128198. _vq_quantthresh__16u0__p2_0,
  128199. _vq_quantmap__16u0__p2_0,
  128200. 3,
  128201. 3
  128202. };
  128203. static static_codebook _16u0__p2_0 = {
  128204. 4, 81,
  128205. _vq_lengthlist__16u0__p2_0,
  128206. 1, -535822336, 1611661312, 2, 0,
  128207. _vq_quantlist__16u0__p2_0,
  128208. NULL,
  128209. &_vq_auxt__16u0__p2_0,
  128210. NULL,
  128211. 0
  128212. };
  128213. static long _vq_quantlist__16u0__p3_0[] = {
  128214. 2,
  128215. 1,
  128216. 3,
  128217. 0,
  128218. 4,
  128219. };
  128220. static long _vq_lengthlist__16u0__p3_0[] = {
  128221. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128222. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128223. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128224. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128225. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128226. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128227. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128228. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128229. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128230. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128231. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128232. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128233. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128234. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128235. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128236. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128237. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128238. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128239. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128240. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128241. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128242. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128243. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128244. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128245. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128246. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128247. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128248. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128249. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128250. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128251. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128252. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128253. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128254. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128255. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128256. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128257. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128258. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128259. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128260. 18,
  128261. };
  128262. static float _vq_quantthresh__16u0__p3_0[] = {
  128263. -1.5, -0.5, 0.5, 1.5,
  128264. };
  128265. static long _vq_quantmap__16u0__p3_0[] = {
  128266. 3, 1, 0, 2, 4,
  128267. };
  128268. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128269. _vq_quantthresh__16u0__p3_0,
  128270. _vq_quantmap__16u0__p3_0,
  128271. 5,
  128272. 5
  128273. };
  128274. static static_codebook _16u0__p3_0 = {
  128275. 4, 625,
  128276. _vq_lengthlist__16u0__p3_0,
  128277. 1, -533725184, 1611661312, 3, 0,
  128278. _vq_quantlist__16u0__p3_0,
  128279. NULL,
  128280. &_vq_auxt__16u0__p3_0,
  128281. NULL,
  128282. 0
  128283. };
  128284. static long _vq_quantlist__16u0__p4_0[] = {
  128285. 2,
  128286. 1,
  128287. 3,
  128288. 0,
  128289. 4,
  128290. };
  128291. static long _vq_lengthlist__16u0__p4_0[] = {
  128292. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128293. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128294. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128295. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128296. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128297. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128298. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128299. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128300. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128301. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128302. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128303. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128304. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128305. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128306. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128307. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128308. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128309. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128310. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128311. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128312. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128313. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128314. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128315. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128316. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128317. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128318. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128319. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128320. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128321. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128322. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128323. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128324. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128325. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128326. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128327. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128328. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128329. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128330. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128331. 11,
  128332. };
  128333. static float _vq_quantthresh__16u0__p4_0[] = {
  128334. -1.5, -0.5, 0.5, 1.5,
  128335. };
  128336. static long _vq_quantmap__16u0__p4_0[] = {
  128337. 3, 1, 0, 2, 4,
  128338. };
  128339. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128340. _vq_quantthresh__16u0__p4_0,
  128341. _vq_quantmap__16u0__p4_0,
  128342. 5,
  128343. 5
  128344. };
  128345. static static_codebook _16u0__p4_0 = {
  128346. 4, 625,
  128347. _vq_lengthlist__16u0__p4_0,
  128348. 1, -533725184, 1611661312, 3, 0,
  128349. _vq_quantlist__16u0__p4_0,
  128350. NULL,
  128351. &_vq_auxt__16u0__p4_0,
  128352. NULL,
  128353. 0
  128354. };
  128355. static long _vq_quantlist__16u0__p5_0[] = {
  128356. 4,
  128357. 3,
  128358. 5,
  128359. 2,
  128360. 6,
  128361. 1,
  128362. 7,
  128363. 0,
  128364. 8,
  128365. };
  128366. static long _vq_lengthlist__16u0__p5_0[] = {
  128367. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128368. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128369. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128370. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128371. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128372. 12,
  128373. };
  128374. static float _vq_quantthresh__16u0__p5_0[] = {
  128375. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128376. };
  128377. static long _vq_quantmap__16u0__p5_0[] = {
  128378. 7, 5, 3, 1, 0, 2, 4, 6,
  128379. 8,
  128380. };
  128381. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128382. _vq_quantthresh__16u0__p5_0,
  128383. _vq_quantmap__16u0__p5_0,
  128384. 9,
  128385. 9
  128386. };
  128387. static static_codebook _16u0__p5_0 = {
  128388. 2, 81,
  128389. _vq_lengthlist__16u0__p5_0,
  128390. 1, -531628032, 1611661312, 4, 0,
  128391. _vq_quantlist__16u0__p5_0,
  128392. NULL,
  128393. &_vq_auxt__16u0__p5_0,
  128394. NULL,
  128395. 0
  128396. };
  128397. static long _vq_quantlist__16u0__p6_0[] = {
  128398. 6,
  128399. 5,
  128400. 7,
  128401. 4,
  128402. 8,
  128403. 3,
  128404. 9,
  128405. 2,
  128406. 10,
  128407. 1,
  128408. 11,
  128409. 0,
  128410. 12,
  128411. };
  128412. static long _vq_lengthlist__16u0__p6_0[] = {
  128413. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128414. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128415. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128416. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128417. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128418. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128419. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128420. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128421. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128422. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128423. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128424. };
  128425. static float _vq_quantthresh__16u0__p6_0[] = {
  128426. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128427. 12.5, 17.5, 22.5, 27.5,
  128428. };
  128429. static long _vq_quantmap__16u0__p6_0[] = {
  128430. 11, 9, 7, 5, 3, 1, 0, 2,
  128431. 4, 6, 8, 10, 12,
  128432. };
  128433. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128434. _vq_quantthresh__16u0__p6_0,
  128435. _vq_quantmap__16u0__p6_0,
  128436. 13,
  128437. 13
  128438. };
  128439. static static_codebook _16u0__p6_0 = {
  128440. 2, 169,
  128441. _vq_lengthlist__16u0__p6_0,
  128442. 1, -526516224, 1616117760, 4, 0,
  128443. _vq_quantlist__16u0__p6_0,
  128444. NULL,
  128445. &_vq_auxt__16u0__p6_0,
  128446. NULL,
  128447. 0
  128448. };
  128449. static long _vq_quantlist__16u0__p6_1[] = {
  128450. 2,
  128451. 1,
  128452. 3,
  128453. 0,
  128454. 4,
  128455. };
  128456. static long _vq_lengthlist__16u0__p6_1[] = {
  128457. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128458. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128459. };
  128460. static float _vq_quantthresh__16u0__p6_1[] = {
  128461. -1.5, -0.5, 0.5, 1.5,
  128462. };
  128463. static long _vq_quantmap__16u0__p6_1[] = {
  128464. 3, 1, 0, 2, 4,
  128465. };
  128466. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128467. _vq_quantthresh__16u0__p6_1,
  128468. _vq_quantmap__16u0__p6_1,
  128469. 5,
  128470. 5
  128471. };
  128472. static static_codebook _16u0__p6_1 = {
  128473. 2, 25,
  128474. _vq_lengthlist__16u0__p6_1,
  128475. 1, -533725184, 1611661312, 3, 0,
  128476. _vq_quantlist__16u0__p6_1,
  128477. NULL,
  128478. &_vq_auxt__16u0__p6_1,
  128479. NULL,
  128480. 0
  128481. };
  128482. static long _vq_quantlist__16u0__p7_0[] = {
  128483. 1,
  128484. 0,
  128485. 2,
  128486. };
  128487. static long _vq_lengthlist__16u0__p7_0[] = {
  128488. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128489. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128490. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128491. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128492. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128493. 7,
  128494. };
  128495. static float _vq_quantthresh__16u0__p7_0[] = {
  128496. -157.5, 157.5,
  128497. };
  128498. static long _vq_quantmap__16u0__p7_0[] = {
  128499. 1, 0, 2,
  128500. };
  128501. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128502. _vq_quantthresh__16u0__p7_0,
  128503. _vq_quantmap__16u0__p7_0,
  128504. 3,
  128505. 3
  128506. };
  128507. static static_codebook _16u0__p7_0 = {
  128508. 4, 81,
  128509. _vq_lengthlist__16u0__p7_0,
  128510. 1, -518803456, 1628680192, 2, 0,
  128511. _vq_quantlist__16u0__p7_0,
  128512. NULL,
  128513. &_vq_auxt__16u0__p7_0,
  128514. NULL,
  128515. 0
  128516. };
  128517. static long _vq_quantlist__16u0__p7_1[] = {
  128518. 7,
  128519. 6,
  128520. 8,
  128521. 5,
  128522. 9,
  128523. 4,
  128524. 10,
  128525. 3,
  128526. 11,
  128527. 2,
  128528. 12,
  128529. 1,
  128530. 13,
  128531. 0,
  128532. 14,
  128533. };
  128534. static long _vq_lengthlist__16u0__p7_1[] = {
  128535. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128536. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128537. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128538. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128539. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128540. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128541. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128542. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128543. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128544. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128545. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128546. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128547. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128548. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128549. 10,
  128550. };
  128551. static float _vq_quantthresh__16u0__p7_1[] = {
  128552. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128553. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128554. };
  128555. static long _vq_quantmap__16u0__p7_1[] = {
  128556. 13, 11, 9, 7, 5, 3, 1, 0,
  128557. 2, 4, 6, 8, 10, 12, 14,
  128558. };
  128559. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128560. _vq_quantthresh__16u0__p7_1,
  128561. _vq_quantmap__16u0__p7_1,
  128562. 15,
  128563. 15
  128564. };
  128565. static static_codebook _16u0__p7_1 = {
  128566. 2, 225,
  128567. _vq_lengthlist__16u0__p7_1,
  128568. 1, -520986624, 1620377600, 4, 0,
  128569. _vq_quantlist__16u0__p7_1,
  128570. NULL,
  128571. &_vq_auxt__16u0__p7_1,
  128572. NULL,
  128573. 0
  128574. };
  128575. static long _vq_quantlist__16u0__p7_2[] = {
  128576. 10,
  128577. 9,
  128578. 11,
  128579. 8,
  128580. 12,
  128581. 7,
  128582. 13,
  128583. 6,
  128584. 14,
  128585. 5,
  128586. 15,
  128587. 4,
  128588. 16,
  128589. 3,
  128590. 17,
  128591. 2,
  128592. 18,
  128593. 1,
  128594. 19,
  128595. 0,
  128596. 20,
  128597. };
  128598. static long _vq_lengthlist__16u0__p7_2[] = {
  128599. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128600. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128601. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128602. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128603. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128604. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128605. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128606. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128607. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128608. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128609. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128610. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128611. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128612. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128613. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128614. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128615. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128616. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128617. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128618. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128619. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128620. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128621. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128622. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128623. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128624. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128625. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128626. 10,10,12,11,10,11,11,11,10,
  128627. };
  128628. static float _vq_quantthresh__16u0__p7_2[] = {
  128629. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128630. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128631. 6.5, 7.5, 8.5, 9.5,
  128632. };
  128633. static long _vq_quantmap__16u0__p7_2[] = {
  128634. 19, 17, 15, 13, 11, 9, 7, 5,
  128635. 3, 1, 0, 2, 4, 6, 8, 10,
  128636. 12, 14, 16, 18, 20,
  128637. };
  128638. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128639. _vq_quantthresh__16u0__p7_2,
  128640. _vq_quantmap__16u0__p7_2,
  128641. 21,
  128642. 21
  128643. };
  128644. static static_codebook _16u0__p7_2 = {
  128645. 2, 441,
  128646. _vq_lengthlist__16u0__p7_2,
  128647. 1, -529268736, 1611661312, 5, 0,
  128648. _vq_quantlist__16u0__p7_2,
  128649. NULL,
  128650. &_vq_auxt__16u0__p7_2,
  128651. NULL,
  128652. 0
  128653. };
  128654. static long _huff_lengthlist__16u0__single[] = {
  128655. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128656. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128657. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128658. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128659. };
  128660. static static_codebook _huff_book__16u0__single = {
  128661. 2, 64,
  128662. _huff_lengthlist__16u0__single,
  128663. 0, 0, 0, 0, 0,
  128664. NULL,
  128665. NULL,
  128666. NULL,
  128667. NULL,
  128668. 0
  128669. };
  128670. static long _huff_lengthlist__16u1__long[] = {
  128671. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128672. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128673. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128674. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128675. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128676. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128677. 16,13,16,18,
  128678. };
  128679. static static_codebook _huff_book__16u1__long = {
  128680. 2, 100,
  128681. _huff_lengthlist__16u1__long,
  128682. 0, 0, 0, 0, 0,
  128683. NULL,
  128684. NULL,
  128685. NULL,
  128686. NULL,
  128687. 0
  128688. };
  128689. static long _vq_quantlist__16u1__p1_0[] = {
  128690. 1,
  128691. 0,
  128692. 2,
  128693. };
  128694. static long _vq_lengthlist__16u1__p1_0[] = {
  128695. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128696. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128697. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128698. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128699. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128700. 11,
  128701. };
  128702. static float _vq_quantthresh__16u1__p1_0[] = {
  128703. -0.5, 0.5,
  128704. };
  128705. static long _vq_quantmap__16u1__p1_0[] = {
  128706. 1, 0, 2,
  128707. };
  128708. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128709. _vq_quantthresh__16u1__p1_0,
  128710. _vq_quantmap__16u1__p1_0,
  128711. 3,
  128712. 3
  128713. };
  128714. static static_codebook _16u1__p1_0 = {
  128715. 4, 81,
  128716. _vq_lengthlist__16u1__p1_0,
  128717. 1, -535822336, 1611661312, 2, 0,
  128718. _vq_quantlist__16u1__p1_0,
  128719. NULL,
  128720. &_vq_auxt__16u1__p1_0,
  128721. NULL,
  128722. 0
  128723. };
  128724. static long _vq_quantlist__16u1__p2_0[] = {
  128725. 1,
  128726. 0,
  128727. 2,
  128728. };
  128729. static long _vq_lengthlist__16u1__p2_0[] = {
  128730. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128731. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128732. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128733. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128734. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128735. 8,
  128736. };
  128737. static float _vq_quantthresh__16u1__p2_0[] = {
  128738. -0.5, 0.5,
  128739. };
  128740. static long _vq_quantmap__16u1__p2_0[] = {
  128741. 1, 0, 2,
  128742. };
  128743. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128744. _vq_quantthresh__16u1__p2_0,
  128745. _vq_quantmap__16u1__p2_0,
  128746. 3,
  128747. 3
  128748. };
  128749. static static_codebook _16u1__p2_0 = {
  128750. 4, 81,
  128751. _vq_lengthlist__16u1__p2_0,
  128752. 1, -535822336, 1611661312, 2, 0,
  128753. _vq_quantlist__16u1__p2_0,
  128754. NULL,
  128755. &_vq_auxt__16u1__p2_0,
  128756. NULL,
  128757. 0
  128758. };
  128759. static long _vq_quantlist__16u1__p3_0[] = {
  128760. 2,
  128761. 1,
  128762. 3,
  128763. 0,
  128764. 4,
  128765. };
  128766. static long _vq_lengthlist__16u1__p3_0[] = {
  128767. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128768. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128769. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128770. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128771. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128772. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128773. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128774. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128775. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128776. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128777. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128778. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128779. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128780. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128781. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128782. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128783. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128784. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128785. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128786. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128787. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128788. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128789. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128790. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128791. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128792. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128793. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128794. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128795. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128796. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128797. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128798. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128799. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128800. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128801. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128802. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128803. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128804. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128805. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128806. 16,
  128807. };
  128808. static float _vq_quantthresh__16u1__p3_0[] = {
  128809. -1.5, -0.5, 0.5, 1.5,
  128810. };
  128811. static long _vq_quantmap__16u1__p3_0[] = {
  128812. 3, 1, 0, 2, 4,
  128813. };
  128814. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  128815. _vq_quantthresh__16u1__p3_0,
  128816. _vq_quantmap__16u1__p3_0,
  128817. 5,
  128818. 5
  128819. };
  128820. static static_codebook _16u1__p3_0 = {
  128821. 4, 625,
  128822. _vq_lengthlist__16u1__p3_0,
  128823. 1, -533725184, 1611661312, 3, 0,
  128824. _vq_quantlist__16u1__p3_0,
  128825. NULL,
  128826. &_vq_auxt__16u1__p3_0,
  128827. NULL,
  128828. 0
  128829. };
  128830. static long _vq_quantlist__16u1__p4_0[] = {
  128831. 2,
  128832. 1,
  128833. 3,
  128834. 0,
  128835. 4,
  128836. };
  128837. static long _vq_lengthlist__16u1__p4_0[] = {
  128838. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  128839. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  128840. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  128841. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  128842. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  128843. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  128844. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  128845. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  128846. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  128847. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  128848. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  128849. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  128850. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  128851. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  128852. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  128853. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  128854. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  128855. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  128856. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  128857. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  128858. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  128859. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  128860. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  128861. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  128862. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  128863. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  128864. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  128865. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  128866. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  128867. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  128868. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  128869. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  128870. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  128871. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  128872. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  128873. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  128874. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  128875. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  128876. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  128877. 11,
  128878. };
  128879. static float _vq_quantthresh__16u1__p4_0[] = {
  128880. -1.5, -0.5, 0.5, 1.5,
  128881. };
  128882. static long _vq_quantmap__16u1__p4_0[] = {
  128883. 3, 1, 0, 2, 4,
  128884. };
  128885. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  128886. _vq_quantthresh__16u1__p4_0,
  128887. _vq_quantmap__16u1__p4_0,
  128888. 5,
  128889. 5
  128890. };
  128891. static static_codebook _16u1__p4_0 = {
  128892. 4, 625,
  128893. _vq_lengthlist__16u1__p4_0,
  128894. 1, -533725184, 1611661312, 3, 0,
  128895. _vq_quantlist__16u1__p4_0,
  128896. NULL,
  128897. &_vq_auxt__16u1__p4_0,
  128898. NULL,
  128899. 0
  128900. };
  128901. static long _vq_quantlist__16u1__p5_0[] = {
  128902. 4,
  128903. 3,
  128904. 5,
  128905. 2,
  128906. 6,
  128907. 1,
  128908. 7,
  128909. 0,
  128910. 8,
  128911. };
  128912. static long _vq_lengthlist__16u1__p5_0[] = {
  128913. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128914. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  128915. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  128916. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  128917. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  128918. 13,
  128919. };
  128920. static float _vq_quantthresh__16u1__p5_0[] = {
  128921. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128922. };
  128923. static long _vq_quantmap__16u1__p5_0[] = {
  128924. 7, 5, 3, 1, 0, 2, 4, 6,
  128925. 8,
  128926. };
  128927. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  128928. _vq_quantthresh__16u1__p5_0,
  128929. _vq_quantmap__16u1__p5_0,
  128930. 9,
  128931. 9
  128932. };
  128933. static static_codebook _16u1__p5_0 = {
  128934. 2, 81,
  128935. _vq_lengthlist__16u1__p5_0,
  128936. 1, -531628032, 1611661312, 4, 0,
  128937. _vq_quantlist__16u1__p5_0,
  128938. NULL,
  128939. &_vq_auxt__16u1__p5_0,
  128940. NULL,
  128941. 0
  128942. };
  128943. static long _vq_quantlist__16u1__p6_0[] = {
  128944. 4,
  128945. 3,
  128946. 5,
  128947. 2,
  128948. 6,
  128949. 1,
  128950. 7,
  128951. 0,
  128952. 8,
  128953. };
  128954. static long _vq_lengthlist__16u1__p6_0[] = {
  128955. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  128956. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  128957. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  128958. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  128959. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  128960. 11,
  128961. };
  128962. static float _vq_quantthresh__16u1__p6_0[] = {
  128963. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128964. };
  128965. static long _vq_quantmap__16u1__p6_0[] = {
  128966. 7, 5, 3, 1, 0, 2, 4, 6,
  128967. 8,
  128968. };
  128969. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  128970. _vq_quantthresh__16u1__p6_0,
  128971. _vq_quantmap__16u1__p6_0,
  128972. 9,
  128973. 9
  128974. };
  128975. static static_codebook _16u1__p6_0 = {
  128976. 2, 81,
  128977. _vq_lengthlist__16u1__p6_0,
  128978. 1, -531628032, 1611661312, 4, 0,
  128979. _vq_quantlist__16u1__p6_0,
  128980. NULL,
  128981. &_vq_auxt__16u1__p6_0,
  128982. NULL,
  128983. 0
  128984. };
  128985. static long _vq_quantlist__16u1__p7_0[] = {
  128986. 1,
  128987. 0,
  128988. 2,
  128989. };
  128990. static long _vq_lengthlist__16u1__p7_0[] = {
  128991. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  128992. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  128993. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  128994. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  128995. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  128996. 13,
  128997. };
  128998. static float _vq_quantthresh__16u1__p7_0[] = {
  128999. -5.5, 5.5,
  129000. };
  129001. static long _vq_quantmap__16u1__p7_0[] = {
  129002. 1, 0, 2,
  129003. };
  129004. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129005. _vq_quantthresh__16u1__p7_0,
  129006. _vq_quantmap__16u1__p7_0,
  129007. 3,
  129008. 3
  129009. };
  129010. static static_codebook _16u1__p7_0 = {
  129011. 4, 81,
  129012. _vq_lengthlist__16u1__p7_0,
  129013. 1, -529137664, 1618345984, 2, 0,
  129014. _vq_quantlist__16u1__p7_0,
  129015. NULL,
  129016. &_vq_auxt__16u1__p7_0,
  129017. NULL,
  129018. 0
  129019. };
  129020. static long _vq_quantlist__16u1__p7_1[] = {
  129021. 5,
  129022. 4,
  129023. 6,
  129024. 3,
  129025. 7,
  129026. 2,
  129027. 8,
  129028. 1,
  129029. 9,
  129030. 0,
  129031. 10,
  129032. };
  129033. static long _vq_lengthlist__16u1__p7_1[] = {
  129034. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129035. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129036. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129037. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129038. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129039. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129040. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129041. 8, 9, 9,10,10,10,10,10,10,
  129042. };
  129043. static float _vq_quantthresh__16u1__p7_1[] = {
  129044. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129045. 3.5, 4.5,
  129046. };
  129047. static long _vq_quantmap__16u1__p7_1[] = {
  129048. 9, 7, 5, 3, 1, 0, 2, 4,
  129049. 6, 8, 10,
  129050. };
  129051. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129052. _vq_quantthresh__16u1__p7_1,
  129053. _vq_quantmap__16u1__p7_1,
  129054. 11,
  129055. 11
  129056. };
  129057. static static_codebook _16u1__p7_1 = {
  129058. 2, 121,
  129059. _vq_lengthlist__16u1__p7_1,
  129060. 1, -531365888, 1611661312, 4, 0,
  129061. _vq_quantlist__16u1__p7_1,
  129062. NULL,
  129063. &_vq_auxt__16u1__p7_1,
  129064. NULL,
  129065. 0
  129066. };
  129067. static long _vq_quantlist__16u1__p8_0[] = {
  129068. 5,
  129069. 4,
  129070. 6,
  129071. 3,
  129072. 7,
  129073. 2,
  129074. 8,
  129075. 1,
  129076. 9,
  129077. 0,
  129078. 10,
  129079. };
  129080. static long _vq_lengthlist__16u1__p8_0[] = {
  129081. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129082. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129083. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129084. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129085. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129086. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129087. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129088. 13,14,14,15,15,16,16,15,16,
  129089. };
  129090. static float _vq_quantthresh__16u1__p8_0[] = {
  129091. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129092. 38.5, 49.5,
  129093. };
  129094. static long _vq_quantmap__16u1__p8_0[] = {
  129095. 9, 7, 5, 3, 1, 0, 2, 4,
  129096. 6, 8, 10,
  129097. };
  129098. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129099. _vq_quantthresh__16u1__p8_0,
  129100. _vq_quantmap__16u1__p8_0,
  129101. 11,
  129102. 11
  129103. };
  129104. static static_codebook _16u1__p8_0 = {
  129105. 2, 121,
  129106. _vq_lengthlist__16u1__p8_0,
  129107. 1, -524582912, 1618345984, 4, 0,
  129108. _vq_quantlist__16u1__p8_0,
  129109. NULL,
  129110. &_vq_auxt__16u1__p8_0,
  129111. NULL,
  129112. 0
  129113. };
  129114. static long _vq_quantlist__16u1__p8_1[] = {
  129115. 5,
  129116. 4,
  129117. 6,
  129118. 3,
  129119. 7,
  129120. 2,
  129121. 8,
  129122. 1,
  129123. 9,
  129124. 0,
  129125. 10,
  129126. };
  129127. static long _vq_lengthlist__16u1__p8_1[] = {
  129128. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129129. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129130. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129131. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129132. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129133. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129134. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129135. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129136. };
  129137. static float _vq_quantthresh__16u1__p8_1[] = {
  129138. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129139. 3.5, 4.5,
  129140. };
  129141. static long _vq_quantmap__16u1__p8_1[] = {
  129142. 9, 7, 5, 3, 1, 0, 2, 4,
  129143. 6, 8, 10,
  129144. };
  129145. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129146. _vq_quantthresh__16u1__p8_1,
  129147. _vq_quantmap__16u1__p8_1,
  129148. 11,
  129149. 11
  129150. };
  129151. static static_codebook _16u1__p8_1 = {
  129152. 2, 121,
  129153. _vq_lengthlist__16u1__p8_1,
  129154. 1, -531365888, 1611661312, 4, 0,
  129155. _vq_quantlist__16u1__p8_1,
  129156. NULL,
  129157. &_vq_auxt__16u1__p8_1,
  129158. NULL,
  129159. 0
  129160. };
  129161. static long _vq_quantlist__16u1__p9_0[] = {
  129162. 7,
  129163. 6,
  129164. 8,
  129165. 5,
  129166. 9,
  129167. 4,
  129168. 10,
  129169. 3,
  129170. 11,
  129171. 2,
  129172. 12,
  129173. 1,
  129174. 13,
  129175. 0,
  129176. 14,
  129177. };
  129178. static long _vq_lengthlist__16u1__p9_0[] = {
  129179. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129180. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129181. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129182. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129183. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129184. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129185. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129186. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129187. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129188. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129189. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129190. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129191. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129192. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129193. 8,
  129194. };
  129195. static float _vq_quantthresh__16u1__p9_0[] = {
  129196. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129197. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129198. };
  129199. static long _vq_quantmap__16u1__p9_0[] = {
  129200. 13, 11, 9, 7, 5, 3, 1, 0,
  129201. 2, 4, 6, 8, 10, 12, 14,
  129202. };
  129203. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129204. _vq_quantthresh__16u1__p9_0,
  129205. _vq_quantmap__16u1__p9_0,
  129206. 15,
  129207. 15
  129208. };
  129209. static static_codebook _16u1__p9_0 = {
  129210. 2, 225,
  129211. _vq_lengthlist__16u1__p9_0,
  129212. 1, -514071552, 1627381760, 4, 0,
  129213. _vq_quantlist__16u1__p9_0,
  129214. NULL,
  129215. &_vq_auxt__16u1__p9_0,
  129216. NULL,
  129217. 0
  129218. };
  129219. static long _vq_quantlist__16u1__p9_1[] = {
  129220. 7,
  129221. 6,
  129222. 8,
  129223. 5,
  129224. 9,
  129225. 4,
  129226. 10,
  129227. 3,
  129228. 11,
  129229. 2,
  129230. 12,
  129231. 1,
  129232. 13,
  129233. 0,
  129234. 14,
  129235. };
  129236. static long _vq_lengthlist__16u1__p9_1[] = {
  129237. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129238. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129239. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129240. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129241. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129242. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129243. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129244. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129245. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129246. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129247. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129248. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129249. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129250. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129251. 9,
  129252. };
  129253. static float _vq_quantthresh__16u1__p9_1[] = {
  129254. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129255. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129256. };
  129257. static long _vq_quantmap__16u1__p9_1[] = {
  129258. 13, 11, 9, 7, 5, 3, 1, 0,
  129259. 2, 4, 6, 8, 10, 12, 14,
  129260. };
  129261. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129262. _vq_quantthresh__16u1__p9_1,
  129263. _vq_quantmap__16u1__p9_1,
  129264. 15,
  129265. 15
  129266. };
  129267. static static_codebook _16u1__p9_1 = {
  129268. 2, 225,
  129269. _vq_lengthlist__16u1__p9_1,
  129270. 1, -522338304, 1620115456, 4, 0,
  129271. _vq_quantlist__16u1__p9_1,
  129272. NULL,
  129273. &_vq_auxt__16u1__p9_1,
  129274. NULL,
  129275. 0
  129276. };
  129277. static long _vq_quantlist__16u1__p9_2[] = {
  129278. 8,
  129279. 7,
  129280. 9,
  129281. 6,
  129282. 10,
  129283. 5,
  129284. 11,
  129285. 4,
  129286. 12,
  129287. 3,
  129288. 13,
  129289. 2,
  129290. 14,
  129291. 1,
  129292. 15,
  129293. 0,
  129294. 16,
  129295. };
  129296. static long _vq_lengthlist__16u1__p9_2[] = {
  129297. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129298. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129299. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129300. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129301. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129302. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129303. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129304. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129305. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129306. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129307. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129308. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129309. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129310. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129311. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129312. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129313. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129314. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129315. 10,
  129316. };
  129317. static float _vq_quantthresh__16u1__p9_2[] = {
  129318. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129319. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129320. };
  129321. static long _vq_quantmap__16u1__p9_2[] = {
  129322. 15, 13, 11, 9, 7, 5, 3, 1,
  129323. 0, 2, 4, 6, 8, 10, 12, 14,
  129324. 16,
  129325. };
  129326. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129327. _vq_quantthresh__16u1__p9_2,
  129328. _vq_quantmap__16u1__p9_2,
  129329. 17,
  129330. 17
  129331. };
  129332. static static_codebook _16u1__p9_2 = {
  129333. 2, 289,
  129334. _vq_lengthlist__16u1__p9_2,
  129335. 1, -529530880, 1611661312, 5, 0,
  129336. _vq_quantlist__16u1__p9_2,
  129337. NULL,
  129338. &_vq_auxt__16u1__p9_2,
  129339. NULL,
  129340. 0
  129341. };
  129342. static long _huff_lengthlist__16u1__short[] = {
  129343. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129344. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129345. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129346. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129347. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129348. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129349. 16,16,16,16,
  129350. };
  129351. static static_codebook _huff_book__16u1__short = {
  129352. 2, 100,
  129353. _huff_lengthlist__16u1__short,
  129354. 0, 0, 0, 0, 0,
  129355. NULL,
  129356. NULL,
  129357. NULL,
  129358. NULL,
  129359. 0
  129360. };
  129361. static long _huff_lengthlist__16u2__long[] = {
  129362. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129363. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129364. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129365. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129366. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129367. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129368. 13,14,18,18,
  129369. };
  129370. static static_codebook _huff_book__16u2__long = {
  129371. 2, 100,
  129372. _huff_lengthlist__16u2__long,
  129373. 0, 0, 0, 0, 0,
  129374. NULL,
  129375. NULL,
  129376. NULL,
  129377. NULL,
  129378. 0
  129379. };
  129380. static long _huff_lengthlist__16u2__short[] = {
  129381. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129382. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129383. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129384. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129385. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129386. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129387. 16,16,16,16,
  129388. };
  129389. static static_codebook _huff_book__16u2__short = {
  129390. 2, 100,
  129391. _huff_lengthlist__16u2__short,
  129392. 0, 0, 0, 0, 0,
  129393. NULL,
  129394. NULL,
  129395. NULL,
  129396. NULL,
  129397. 0
  129398. };
  129399. static long _vq_quantlist__16u2_p1_0[] = {
  129400. 1,
  129401. 0,
  129402. 2,
  129403. };
  129404. static long _vq_lengthlist__16u2_p1_0[] = {
  129405. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129406. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129407. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129408. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129409. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129410. 10,
  129411. };
  129412. static float _vq_quantthresh__16u2_p1_0[] = {
  129413. -0.5, 0.5,
  129414. };
  129415. static long _vq_quantmap__16u2_p1_0[] = {
  129416. 1, 0, 2,
  129417. };
  129418. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129419. _vq_quantthresh__16u2_p1_0,
  129420. _vq_quantmap__16u2_p1_0,
  129421. 3,
  129422. 3
  129423. };
  129424. static static_codebook _16u2_p1_0 = {
  129425. 4, 81,
  129426. _vq_lengthlist__16u2_p1_0,
  129427. 1, -535822336, 1611661312, 2, 0,
  129428. _vq_quantlist__16u2_p1_0,
  129429. NULL,
  129430. &_vq_auxt__16u2_p1_0,
  129431. NULL,
  129432. 0
  129433. };
  129434. static long _vq_quantlist__16u2_p2_0[] = {
  129435. 2,
  129436. 1,
  129437. 3,
  129438. 0,
  129439. 4,
  129440. };
  129441. static long _vq_lengthlist__16u2_p2_0[] = {
  129442. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129443. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129444. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129445. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129446. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129447. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129448. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129449. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129450. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129451. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129452. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129453. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129454. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129455. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129456. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129457. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129458. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129459. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129460. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129461. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129462. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129463. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129464. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129465. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129466. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129467. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129468. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129469. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129470. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129471. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129472. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129473. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129474. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129475. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129476. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129477. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129478. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129479. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129480. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129481. 13,
  129482. };
  129483. static float _vq_quantthresh__16u2_p2_0[] = {
  129484. -1.5, -0.5, 0.5, 1.5,
  129485. };
  129486. static long _vq_quantmap__16u2_p2_0[] = {
  129487. 3, 1, 0, 2, 4,
  129488. };
  129489. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129490. _vq_quantthresh__16u2_p2_0,
  129491. _vq_quantmap__16u2_p2_0,
  129492. 5,
  129493. 5
  129494. };
  129495. static static_codebook _16u2_p2_0 = {
  129496. 4, 625,
  129497. _vq_lengthlist__16u2_p2_0,
  129498. 1, -533725184, 1611661312, 3, 0,
  129499. _vq_quantlist__16u2_p2_0,
  129500. NULL,
  129501. &_vq_auxt__16u2_p2_0,
  129502. NULL,
  129503. 0
  129504. };
  129505. static long _vq_quantlist__16u2_p3_0[] = {
  129506. 4,
  129507. 3,
  129508. 5,
  129509. 2,
  129510. 6,
  129511. 1,
  129512. 7,
  129513. 0,
  129514. 8,
  129515. };
  129516. static long _vq_lengthlist__16u2_p3_0[] = {
  129517. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129518. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129519. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129520. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129521. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129522. 11,
  129523. };
  129524. static float _vq_quantthresh__16u2_p3_0[] = {
  129525. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129526. };
  129527. static long _vq_quantmap__16u2_p3_0[] = {
  129528. 7, 5, 3, 1, 0, 2, 4, 6,
  129529. 8,
  129530. };
  129531. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129532. _vq_quantthresh__16u2_p3_0,
  129533. _vq_quantmap__16u2_p3_0,
  129534. 9,
  129535. 9
  129536. };
  129537. static static_codebook _16u2_p3_0 = {
  129538. 2, 81,
  129539. _vq_lengthlist__16u2_p3_0,
  129540. 1, -531628032, 1611661312, 4, 0,
  129541. _vq_quantlist__16u2_p3_0,
  129542. NULL,
  129543. &_vq_auxt__16u2_p3_0,
  129544. NULL,
  129545. 0
  129546. };
  129547. static long _vq_quantlist__16u2_p4_0[] = {
  129548. 8,
  129549. 7,
  129550. 9,
  129551. 6,
  129552. 10,
  129553. 5,
  129554. 11,
  129555. 4,
  129556. 12,
  129557. 3,
  129558. 13,
  129559. 2,
  129560. 14,
  129561. 1,
  129562. 15,
  129563. 0,
  129564. 16,
  129565. };
  129566. static long _vq_lengthlist__16u2_p4_0[] = {
  129567. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129568. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129569. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129570. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129571. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129572. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129573. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129574. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129575. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129576. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129577. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129578. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129579. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129580. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129581. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129582. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129583. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129584. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129585. 14,
  129586. };
  129587. static float _vq_quantthresh__16u2_p4_0[] = {
  129588. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129589. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129590. };
  129591. static long _vq_quantmap__16u2_p4_0[] = {
  129592. 15, 13, 11, 9, 7, 5, 3, 1,
  129593. 0, 2, 4, 6, 8, 10, 12, 14,
  129594. 16,
  129595. };
  129596. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129597. _vq_quantthresh__16u2_p4_0,
  129598. _vq_quantmap__16u2_p4_0,
  129599. 17,
  129600. 17
  129601. };
  129602. static static_codebook _16u2_p4_0 = {
  129603. 2, 289,
  129604. _vq_lengthlist__16u2_p4_0,
  129605. 1, -529530880, 1611661312, 5, 0,
  129606. _vq_quantlist__16u2_p4_0,
  129607. NULL,
  129608. &_vq_auxt__16u2_p4_0,
  129609. NULL,
  129610. 0
  129611. };
  129612. static long _vq_quantlist__16u2_p5_0[] = {
  129613. 1,
  129614. 0,
  129615. 2,
  129616. };
  129617. static long _vq_lengthlist__16u2_p5_0[] = {
  129618. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129619. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129620. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129621. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129622. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129623. 10,
  129624. };
  129625. static float _vq_quantthresh__16u2_p5_0[] = {
  129626. -5.5, 5.5,
  129627. };
  129628. static long _vq_quantmap__16u2_p5_0[] = {
  129629. 1, 0, 2,
  129630. };
  129631. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129632. _vq_quantthresh__16u2_p5_0,
  129633. _vq_quantmap__16u2_p5_0,
  129634. 3,
  129635. 3
  129636. };
  129637. static static_codebook _16u2_p5_0 = {
  129638. 4, 81,
  129639. _vq_lengthlist__16u2_p5_0,
  129640. 1, -529137664, 1618345984, 2, 0,
  129641. _vq_quantlist__16u2_p5_0,
  129642. NULL,
  129643. &_vq_auxt__16u2_p5_0,
  129644. NULL,
  129645. 0
  129646. };
  129647. static long _vq_quantlist__16u2_p5_1[] = {
  129648. 5,
  129649. 4,
  129650. 6,
  129651. 3,
  129652. 7,
  129653. 2,
  129654. 8,
  129655. 1,
  129656. 9,
  129657. 0,
  129658. 10,
  129659. };
  129660. static long _vq_lengthlist__16u2_p5_1[] = {
  129661. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129662. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129663. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129664. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129665. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129666. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129667. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129668. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129669. };
  129670. static float _vq_quantthresh__16u2_p5_1[] = {
  129671. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129672. 3.5, 4.5,
  129673. };
  129674. static long _vq_quantmap__16u2_p5_1[] = {
  129675. 9, 7, 5, 3, 1, 0, 2, 4,
  129676. 6, 8, 10,
  129677. };
  129678. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129679. _vq_quantthresh__16u2_p5_1,
  129680. _vq_quantmap__16u2_p5_1,
  129681. 11,
  129682. 11
  129683. };
  129684. static static_codebook _16u2_p5_1 = {
  129685. 2, 121,
  129686. _vq_lengthlist__16u2_p5_1,
  129687. 1, -531365888, 1611661312, 4, 0,
  129688. _vq_quantlist__16u2_p5_1,
  129689. NULL,
  129690. &_vq_auxt__16u2_p5_1,
  129691. NULL,
  129692. 0
  129693. };
  129694. static long _vq_quantlist__16u2_p6_0[] = {
  129695. 6,
  129696. 5,
  129697. 7,
  129698. 4,
  129699. 8,
  129700. 3,
  129701. 9,
  129702. 2,
  129703. 10,
  129704. 1,
  129705. 11,
  129706. 0,
  129707. 12,
  129708. };
  129709. static long _vq_lengthlist__16u2_p6_0[] = {
  129710. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129711. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129712. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129713. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129714. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129715. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129716. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129717. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129718. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129719. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129720. 12,13,13,14,14,14,14,15,15,
  129721. };
  129722. static float _vq_quantthresh__16u2_p6_0[] = {
  129723. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129724. 12.5, 17.5, 22.5, 27.5,
  129725. };
  129726. static long _vq_quantmap__16u2_p6_0[] = {
  129727. 11, 9, 7, 5, 3, 1, 0, 2,
  129728. 4, 6, 8, 10, 12,
  129729. };
  129730. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129731. _vq_quantthresh__16u2_p6_0,
  129732. _vq_quantmap__16u2_p6_0,
  129733. 13,
  129734. 13
  129735. };
  129736. static static_codebook _16u2_p6_0 = {
  129737. 2, 169,
  129738. _vq_lengthlist__16u2_p6_0,
  129739. 1, -526516224, 1616117760, 4, 0,
  129740. _vq_quantlist__16u2_p6_0,
  129741. NULL,
  129742. &_vq_auxt__16u2_p6_0,
  129743. NULL,
  129744. 0
  129745. };
  129746. static long _vq_quantlist__16u2_p6_1[] = {
  129747. 2,
  129748. 1,
  129749. 3,
  129750. 0,
  129751. 4,
  129752. };
  129753. static long _vq_lengthlist__16u2_p6_1[] = {
  129754. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129755. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129756. };
  129757. static float _vq_quantthresh__16u2_p6_1[] = {
  129758. -1.5, -0.5, 0.5, 1.5,
  129759. };
  129760. static long _vq_quantmap__16u2_p6_1[] = {
  129761. 3, 1, 0, 2, 4,
  129762. };
  129763. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129764. _vq_quantthresh__16u2_p6_1,
  129765. _vq_quantmap__16u2_p6_1,
  129766. 5,
  129767. 5
  129768. };
  129769. static static_codebook _16u2_p6_1 = {
  129770. 2, 25,
  129771. _vq_lengthlist__16u2_p6_1,
  129772. 1, -533725184, 1611661312, 3, 0,
  129773. _vq_quantlist__16u2_p6_1,
  129774. NULL,
  129775. &_vq_auxt__16u2_p6_1,
  129776. NULL,
  129777. 0
  129778. };
  129779. static long _vq_quantlist__16u2_p7_0[] = {
  129780. 6,
  129781. 5,
  129782. 7,
  129783. 4,
  129784. 8,
  129785. 3,
  129786. 9,
  129787. 2,
  129788. 10,
  129789. 1,
  129790. 11,
  129791. 0,
  129792. 12,
  129793. };
  129794. static long _vq_lengthlist__16u2_p7_0[] = {
  129795. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129796. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129797. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129798. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129799. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129800. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129801. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129802. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129803. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129804. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129805. 12,13,13,13,14,14,14,15,14,
  129806. };
  129807. static float _vq_quantthresh__16u2_p7_0[] = {
  129808. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129809. 27.5, 38.5, 49.5, 60.5,
  129810. };
  129811. static long _vq_quantmap__16u2_p7_0[] = {
  129812. 11, 9, 7, 5, 3, 1, 0, 2,
  129813. 4, 6, 8, 10, 12,
  129814. };
  129815. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  129816. _vq_quantthresh__16u2_p7_0,
  129817. _vq_quantmap__16u2_p7_0,
  129818. 13,
  129819. 13
  129820. };
  129821. static static_codebook _16u2_p7_0 = {
  129822. 2, 169,
  129823. _vq_lengthlist__16u2_p7_0,
  129824. 1, -523206656, 1618345984, 4, 0,
  129825. _vq_quantlist__16u2_p7_0,
  129826. NULL,
  129827. &_vq_auxt__16u2_p7_0,
  129828. NULL,
  129829. 0
  129830. };
  129831. static long _vq_quantlist__16u2_p7_1[] = {
  129832. 5,
  129833. 4,
  129834. 6,
  129835. 3,
  129836. 7,
  129837. 2,
  129838. 8,
  129839. 1,
  129840. 9,
  129841. 0,
  129842. 10,
  129843. };
  129844. static long _vq_lengthlist__16u2_p7_1[] = {
  129845. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  129846. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  129847. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  129848. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  129849. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  129850. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  129851. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  129852. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129853. };
  129854. static float _vq_quantthresh__16u2_p7_1[] = {
  129855. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129856. 3.5, 4.5,
  129857. };
  129858. static long _vq_quantmap__16u2_p7_1[] = {
  129859. 9, 7, 5, 3, 1, 0, 2, 4,
  129860. 6, 8, 10,
  129861. };
  129862. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  129863. _vq_quantthresh__16u2_p7_1,
  129864. _vq_quantmap__16u2_p7_1,
  129865. 11,
  129866. 11
  129867. };
  129868. static static_codebook _16u2_p7_1 = {
  129869. 2, 121,
  129870. _vq_lengthlist__16u2_p7_1,
  129871. 1, -531365888, 1611661312, 4, 0,
  129872. _vq_quantlist__16u2_p7_1,
  129873. NULL,
  129874. &_vq_auxt__16u2_p7_1,
  129875. NULL,
  129876. 0
  129877. };
  129878. static long _vq_quantlist__16u2_p8_0[] = {
  129879. 7,
  129880. 6,
  129881. 8,
  129882. 5,
  129883. 9,
  129884. 4,
  129885. 10,
  129886. 3,
  129887. 11,
  129888. 2,
  129889. 12,
  129890. 1,
  129891. 13,
  129892. 0,
  129893. 14,
  129894. };
  129895. static long _vq_lengthlist__16u2_p8_0[] = {
  129896. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  129897. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  129898. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  129899. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  129900. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  129901. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  129902. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  129903. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  129904. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  129905. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  129906. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  129907. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  129908. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  129909. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  129910. 14,
  129911. };
  129912. static float _vq_quantthresh__16u2_p8_0[] = {
  129913. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129914. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129915. };
  129916. static long _vq_quantmap__16u2_p8_0[] = {
  129917. 13, 11, 9, 7, 5, 3, 1, 0,
  129918. 2, 4, 6, 8, 10, 12, 14,
  129919. };
  129920. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  129921. _vq_quantthresh__16u2_p8_0,
  129922. _vq_quantmap__16u2_p8_0,
  129923. 15,
  129924. 15
  129925. };
  129926. static static_codebook _16u2_p8_0 = {
  129927. 2, 225,
  129928. _vq_lengthlist__16u2_p8_0,
  129929. 1, -520986624, 1620377600, 4, 0,
  129930. _vq_quantlist__16u2_p8_0,
  129931. NULL,
  129932. &_vq_auxt__16u2_p8_0,
  129933. NULL,
  129934. 0
  129935. };
  129936. static long _vq_quantlist__16u2_p8_1[] = {
  129937. 10,
  129938. 9,
  129939. 11,
  129940. 8,
  129941. 12,
  129942. 7,
  129943. 13,
  129944. 6,
  129945. 14,
  129946. 5,
  129947. 15,
  129948. 4,
  129949. 16,
  129950. 3,
  129951. 17,
  129952. 2,
  129953. 18,
  129954. 1,
  129955. 19,
  129956. 0,
  129957. 20,
  129958. };
  129959. static long _vq_lengthlist__16u2_p8_1[] = {
  129960. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  129961. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  129962. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  129963. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  129964. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  129965. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  129966. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  129967. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  129968. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  129969. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  129970. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  129971. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  129972. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  129973. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  129974. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  129975. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  129976. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  129977. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  129978. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  129979. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  129980. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  129981. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  129982. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  129983. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  129984. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  129985. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  129986. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  129987. 11,11,10,11,11,11,10,11,11,
  129988. };
  129989. static float _vq_quantthresh__16u2_p8_1[] = {
  129990. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129991. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129992. 6.5, 7.5, 8.5, 9.5,
  129993. };
  129994. static long _vq_quantmap__16u2_p8_1[] = {
  129995. 19, 17, 15, 13, 11, 9, 7, 5,
  129996. 3, 1, 0, 2, 4, 6, 8, 10,
  129997. 12, 14, 16, 18, 20,
  129998. };
  129999. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130000. _vq_quantthresh__16u2_p8_1,
  130001. _vq_quantmap__16u2_p8_1,
  130002. 21,
  130003. 21
  130004. };
  130005. static static_codebook _16u2_p8_1 = {
  130006. 2, 441,
  130007. _vq_lengthlist__16u2_p8_1,
  130008. 1, -529268736, 1611661312, 5, 0,
  130009. _vq_quantlist__16u2_p8_1,
  130010. NULL,
  130011. &_vq_auxt__16u2_p8_1,
  130012. NULL,
  130013. 0
  130014. };
  130015. static long _vq_quantlist__16u2_p9_0[] = {
  130016. 5586,
  130017. 4655,
  130018. 6517,
  130019. 3724,
  130020. 7448,
  130021. 2793,
  130022. 8379,
  130023. 1862,
  130024. 9310,
  130025. 931,
  130026. 10241,
  130027. 0,
  130028. 11172,
  130029. 5521,
  130030. 5651,
  130031. };
  130032. static long _vq_lengthlist__16u2_p9_0[] = {
  130033. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130034. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130035. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130036. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130037. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130038. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130039. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130040. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130041. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130042. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130043. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130044. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130045. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130046. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130047. 5,
  130048. };
  130049. static float _vq_quantthresh__16u2_p9_0[] = {
  130050. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130051. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130052. };
  130053. static long _vq_quantmap__16u2_p9_0[] = {
  130054. 11, 9, 7, 5, 3, 1, 13, 0,
  130055. 14, 2, 4, 6, 8, 10, 12,
  130056. };
  130057. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130058. _vq_quantthresh__16u2_p9_0,
  130059. _vq_quantmap__16u2_p9_0,
  130060. 15,
  130061. 15
  130062. };
  130063. static static_codebook _16u2_p9_0 = {
  130064. 2, 225,
  130065. _vq_lengthlist__16u2_p9_0,
  130066. 1, -510275072, 1611661312, 14, 0,
  130067. _vq_quantlist__16u2_p9_0,
  130068. NULL,
  130069. &_vq_auxt__16u2_p9_0,
  130070. NULL,
  130071. 0
  130072. };
  130073. static long _vq_quantlist__16u2_p9_1[] = {
  130074. 392,
  130075. 343,
  130076. 441,
  130077. 294,
  130078. 490,
  130079. 245,
  130080. 539,
  130081. 196,
  130082. 588,
  130083. 147,
  130084. 637,
  130085. 98,
  130086. 686,
  130087. 49,
  130088. 735,
  130089. 0,
  130090. 784,
  130091. 388,
  130092. 396,
  130093. };
  130094. static long _vq_lengthlist__16u2_p9_1[] = {
  130095. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130096. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130097. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130098. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130099. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130100. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130101. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130102. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130103. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130104. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130105. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130106. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130107. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130108. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130109. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130110. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130111. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130112. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130113. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130114. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130115. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130116. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130117. 11,11,11,11,11,11,11, 5, 4,
  130118. };
  130119. static float _vq_quantthresh__16u2_p9_1[] = {
  130120. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130121. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130122. 318.5, 367.5,
  130123. };
  130124. static long _vq_quantmap__16u2_p9_1[] = {
  130125. 15, 13, 11, 9, 7, 5, 3, 1,
  130126. 17, 0, 18, 2, 4, 6, 8, 10,
  130127. 12, 14, 16,
  130128. };
  130129. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130130. _vq_quantthresh__16u2_p9_1,
  130131. _vq_quantmap__16u2_p9_1,
  130132. 19,
  130133. 19
  130134. };
  130135. static static_codebook _16u2_p9_1 = {
  130136. 2, 361,
  130137. _vq_lengthlist__16u2_p9_1,
  130138. 1, -518488064, 1611661312, 10, 0,
  130139. _vq_quantlist__16u2_p9_1,
  130140. NULL,
  130141. &_vq_auxt__16u2_p9_1,
  130142. NULL,
  130143. 0
  130144. };
  130145. static long _vq_quantlist__16u2_p9_2[] = {
  130146. 24,
  130147. 23,
  130148. 25,
  130149. 22,
  130150. 26,
  130151. 21,
  130152. 27,
  130153. 20,
  130154. 28,
  130155. 19,
  130156. 29,
  130157. 18,
  130158. 30,
  130159. 17,
  130160. 31,
  130161. 16,
  130162. 32,
  130163. 15,
  130164. 33,
  130165. 14,
  130166. 34,
  130167. 13,
  130168. 35,
  130169. 12,
  130170. 36,
  130171. 11,
  130172. 37,
  130173. 10,
  130174. 38,
  130175. 9,
  130176. 39,
  130177. 8,
  130178. 40,
  130179. 7,
  130180. 41,
  130181. 6,
  130182. 42,
  130183. 5,
  130184. 43,
  130185. 4,
  130186. 44,
  130187. 3,
  130188. 45,
  130189. 2,
  130190. 46,
  130191. 1,
  130192. 47,
  130193. 0,
  130194. 48,
  130195. };
  130196. static long _vq_lengthlist__16u2_p9_2[] = {
  130197. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130198. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130199. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130200. 11,
  130201. };
  130202. static float _vq_quantthresh__16u2_p9_2[] = {
  130203. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130204. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130205. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130206. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130207. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130208. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130209. };
  130210. static long _vq_quantmap__16u2_p9_2[] = {
  130211. 47, 45, 43, 41, 39, 37, 35, 33,
  130212. 31, 29, 27, 25, 23, 21, 19, 17,
  130213. 15, 13, 11, 9, 7, 5, 3, 1,
  130214. 0, 2, 4, 6, 8, 10, 12, 14,
  130215. 16, 18, 20, 22, 24, 26, 28, 30,
  130216. 32, 34, 36, 38, 40, 42, 44, 46,
  130217. 48,
  130218. };
  130219. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130220. _vq_quantthresh__16u2_p9_2,
  130221. _vq_quantmap__16u2_p9_2,
  130222. 49,
  130223. 49
  130224. };
  130225. static static_codebook _16u2_p9_2 = {
  130226. 1, 49,
  130227. _vq_lengthlist__16u2_p9_2,
  130228. 1, -526909440, 1611661312, 6, 0,
  130229. _vq_quantlist__16u2_p9_2,
  130230. NULL,
  130231. &_vq_auxt__16u2_p9_2,
  130232. NULL,
  130233. 0
  130234. };
  130235. static long _vq_quantlist__8u0__p1_0[] = {
  130236. 1,
  130237. 0,
  130238. 2,
  130239. };
  130240. static long _vq_lengthlist__8u0__p1_0[] = {
  130241. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130242. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130243. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130244. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130245. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130246. 11,
  130247. };
  130248. static float _vq_quantthresh__8u0__p1_0[] = {
  130249. -0.5, 0.5,
  130250. };
  130251. static long _vq_quantmap__8u0__p1_0[] = {
  130252. 1, 0, 2,
  130253. };
  130254. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130255. _vq_quantthresh__8u0__p1_0,
  130256. _vq_quantmap__8u0__p1_0,
  130257. 3,
  130258. 3
  130259. };
  130260. static static_codebook _8u0__p1_0 = {
  130261. 4, 81,
  130262. _vq_lengthlist__8u0__p1_0,
  130263. 1, -535822336, 1611661312, 2, 0,
  130264. _vq_quantlist__8u0__p1_0,
  130265. NULL,
  130266. &_vq_auxt__8u0__p1_0,
  130267. NULL,
  130268. 0
  130269. };
  130270. static long _vq_quantlist__8u0__p2_0[] = {
  130271. 1,
  130272. 0,
  130273. 2,
  130274. };
  130275. static long _vq_lengthlist__8u0__p2_0[] = {
  130276. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130277. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130278. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130279. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130280. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130281. 8,
  130282. };
  130283. static float _vq_quantthresh__8u0__p2_0[] = {
  130284. -0.5, 0.5,
  130285. };
  130286. static long _vq_quantmap__8u0__p2_0[] = {
  130287. 1, 0, 2,
  130288. };
  130289. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130290. _vq_quantthresh__8u0__p2_0,
  130291. _vq_quantmap__8u0__p2_0,
  130292. 3,
  130293. 3
  130294. };
  130295. static static_codebook _8u0__p2_0 = {
  130296. 4, 81,
  130297. _vq_lengthlist__8u0__p2_0,
  130298. 1, -535822336, 1611661312, 2, 0,
  130299. _vq_quantlist__8u0__p2_0,
  130300. NULL,
  130301. &_vq_auxt__8u0__p2_0,
  130302. NULL,
  130303. 0
  130304. };
  130305. static long _vq_quantlist__8u0__p3_0[] = {
  130306. 2,
  130307. 1,
  130308. 3,
  130309. 0,
  130310. 4,
  130311. };
  130312. static long _vq_lengthlist__8u0__p3_0[] = {
  130313. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130314. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130315. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130316. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130317. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130318. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130319. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130320. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130321. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130322. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130323. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130324. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130325. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130326. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130327. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130328. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130329. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130330. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130331. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130332. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130333. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130334. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130335. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130336. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130337. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130338. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130339. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130340. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130341. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130342. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130343. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130344. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130345. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130346. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130347. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130348. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130349. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130350. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130351. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130352. 16,
  130353. };
  130354. static float _vq_quantthresh__8u0__p3_0[] = {
  130355. -1.5, -0.5, 0.5, 1.5,
  130356. };
  130357. static long _vq_quantmap__8u0__p3_0[] = {
  130358. 3, 1, 0, 2, 4,
  130359. };
  130360. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130361. _vq_quantthresh__8u0__p3_0,
  130362. _vq_quantmap__8u0__p3_0,
  130363. 5,
  130364. 5
  130365. };
  130366. static static_codebook _8u0__p3_0 = {
  130367. 4, 625,
  130368. _vq_lengthlist__8u0__p3_0,
  130369. 1, -533725184, 1611661312, 3, 0,
  130370. _vq_quantlist__8u0__p3_0,
  130371. NULL,
  130372. &_vq_auxt__8u0__p3_0,
  130373. NULL,
  130374. 0
  130375. };
  130376. static long _vq_quantlist__8u0__p4_0[] = {
  130377. 2,
  130378. 1,
  130379. 3,
  130380. 0,
  130381. 4,
  130382. };
  130383. static long _vq_lengthlist__8u0__p4_0[] = {
  130384. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130385. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130386. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130387. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130388. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130389. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130390. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130391. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130392. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130393. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130394. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130395. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130396. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130397. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130398. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130399. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130400. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130401. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130402. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130403. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130404. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130405. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130406. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130407. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130408. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130409. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130410. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130411. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130412. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130413. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130414. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130415. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130416. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130417. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130418. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130419. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130420. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130421. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130422. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130423. 12,
  130424. };
  130425. static float _vq_quantthresh__8u0__p4_0[] = {
  130426. -1.5, -0.5, 0.5, 1.5,
  130427. };
  130428. static long _vq_quantmap__8u0__p4_0[] = {
  130429. 3, 1, 0, 2, 4,
  130430. };
  130431. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130432. _vq_quantthresh__8u0__p4_0,
  130433. _vq_quantmap__8u0__p4_0,
  130434. 5,
  130435. 5
  130436. };
  130437. static static_codebook _8u0__p4_0 = {
  130438. 4, 625,
  130439. _vq_lengthlist__8u0__p4_0,
  130440. 1, -533725184, 1611661312, 3, 0,
  130441. _vq_quantlist__8u0__p4_0,
  130442. NULL,
  130443. &_vq_auxt__8u0__p4_0,
  130444. NULL,
  130445. 0
  130446. };
  130447. static long _vq_quantlist__8u0__p5_0[] = {
  130448. 4,
  130449. 3,
  130450. 5,
  130451. 2,
  130452. 6,
  130453. 1,
  130454. 7,
  130455. 0,
  130456. 8,
  130457. };
  130458. static long _vq_lengthlist__8u0__p5_0[] = {
  130459. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130460. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130461. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130462. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130463. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130464. 12,
  130465. };
  130466. static float _vq_quantthresh__8u0__p5_0[] = {
  130467. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130468. };
  130469. static long _vq_quantmap__8u0__p5_0[] = {
  130470. 7, 5, 3, 1, 0, 2, 4, 6,
  130471. 8,
  130472. };
  130473. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130474. _vq_quantthresh__8u0__p5_0,
  130475. _vq_quantmap__8u0__p5_0,
  130476. 9,
  130477. 9
  130478. };
  130479. static static_codebook _8u0__p5_0 = {
  130480. 2, 81,
  130481. _vq_lengthlist__8u0__p5_0,
  130482. 1, -531628032, 1611661312, 4, 0,
  130483. _vq_quantlist__8u0__p5_0,
  130484. NULL,
  130485. &_vq_auxt__8u0__p5_0,
  130486. NULL,
  130487. 0
  130488. };
  130489. static long _vq_quantlist__8u0__p6_0[] = {
  130490. 6,
  130491. 5,
  130492. 7,
  130493. 4,
  130494. 8,
  130495. 3,
  130496. 9,
  130497. 2,
  130498. 10,
  130499. 1,
  130500. 11,
  130501. 0,
  130502. 12,
  130503. };
  130504. static long _vq_lengthlist__8u0__p6_0[] = {
  130505. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130506. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130507. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130508. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130509. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130510. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130511. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130512. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130513. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130514. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130515. 16, 0,15, 0,17, 0, 0, 0, 0,
  130516. };
  130517. static float _vq_quantthresh__8u0__p6_0[] = {
  130518. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130519. 12.5, 17.5, 22.5, 27.5,
  130520. };
  130521. static long _vq_quantmap__8u0__p6_0[] = {
  130522. 11, 9, 7, 5, 3, 1, 0, 2,
  130523. 4, 6, 8, 10, 12,
  130524. };
  130525. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130526. _vq_quantthresh__8u0__p6_0,
  130527. _vq_quantmap__8u0__p6_0,
  130528. 13,
  130529. 13
  130530. };
  130531. static static_codebook _8u0__p6_0 = {
  130532. 2, 169,
  130533. _vq_lengthlist__8u0__p6_0,
  130534. 1, -526516224, 1616117760, 4, 0,
  130535. _vq_quantlist__8u0__p6_0,
  130536. NULL,
  130537. &_vq_auxt__8u0__p6_0,
  130538. NULL,
  130539. 0
  130540. };
  130541. static long _vq_quantlist__8u0__p6_1[] = {
  130542. 2,
  130543. 1,
  130544. 3,
  130545. 0,
  130546. 4,
  130547. };
  130548. static long _vq_lengthlist__8u0__p6_1[] = {
  130549. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130550. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130551. };
  130552. static float _vq_quantthresh__8u0__p6_1[] = {
  130553. -1.5, -0.5, 0.5, 1.5,
  130554. };
  130555. static long _vq_quantmap__8u0__p6_1[] = {
  130556. 3, 1, 0, 2, 4,
  130557. };
  130558. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130559. _vq_quantthresh__8u0__p6_1,
  130560. _vq_quantmap__8u0__p6_1,
  130561. 5,
  130562. 5
  130563. };
  130564. static static_codebook _8u0__p6_1 = {
  130565. 2, 25,
  130566. _vq_lengthlist__8u0__p6_1,
  130567. 1, -533725184, 1611661312, 3, 0,
  130568. _vq_quantlist__8u0__p6_1,
  130569. NULL,
  130570. &_vq_auxt__8u0__p6_1,
  130571. NULL,
  130572. 0
  130573. };
  130574. static long _vq_quantlist__8u0__p7_0[] = {
  130575. 1,
  130576. 0,
  130577. 2,
  130578. };
  130579. static long _vq_lengthlist__8u0__p7_0[] = {
  130580. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130581. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130582. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130583. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130584. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130585. 7,
  130586. };
  130587. static float _vq_quantthresh__8u0__p7_0[] = {
  130588. -157.5, 157.5,
  130589. };
  130590. static long _vq_quantmap__8u0__p7_0[] = {
  130591. 1, 0, 2,
  130592. };
  130593. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130594. _vq_quantthresh__8u0__p7_0,
  130595. _vq_quantmap__8u0__p7_0,
  130596. 3,
  130597. 3
  130598. };
  130599. static static_codebook _8u0__p7_0 = {
  130600. 4, 81,
  130601. _vq_lengthlist__8u0__p7_0,
  130602. 1, -518803456, 1628680192, 2, 0,
  130603. _vq_quantlist__8u0__p7_0,
  130604. NULL,
  130605. &_vq_auxt__8u0__p7_0,
  130606. NULL,
  130607. 0
  130608. };
  130609. static long _vq_quantlist__8u0__p7_1[] = {
  130610. 7,
  130611. 6,
  130612. 8,
  130613. 5,
  130614. 9,
  130615. 4,
  130616. 10,
  130617. 3,
  130618. 11,
  130619. 2,
  130620. 12,
  130621. 1,
  130622. 13,
  130623. 0,
  130624. 14,
  130625. };
  130626. static long _vq_lengthlist__8u0__p7_1[] = {
  130627. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130628. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130629. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130630. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130631. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130632. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130633. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130634. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130635. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130636. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130637. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130638. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130639. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130640. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130641. 10,
  130642. };
  130643. static float _vq_quantthresh__8u0__p7_1[] = {
  130644. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130645. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130646. };
  130647. static long _vq_quantmap__8u0__p7_1[] = {
  130648. 13, 11, 9, 7, 5, 3, 1, 0,
  130649. 2, 4, 6, 8, 10, 12, 14,
  130650. };
  130651. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130652. _vq_quantthresh__8u0__p7_1,
  130653. _vq_quantmap__8u0__p7_1,
  130654. 15,
  130655. 15
  130656. };
  130657. static static_codebook _8u0__p7_1 = {
  130658. 2, 225,
  130659. _vq_lengthlist__8u0__p7_1,
  130660. 1, -520986624, 1620377600, 4, 0,
  130661. _vq_quantlist__8u0__p7_1,
  130662. NULL,
  130663. &_vq_auxt__8u0__p7_1,
  130664. NULL,
  130665. 0
  130666. };
  130667. static long _vq_quantlist__8u0__p7_2[] = {
  130668. 10,
  130669. 9,
  130670. 11,
  130671. 8,
  130672. 12,
  130673. 7,
  130674. 13,
  130675. 6,
  130676. 14,
  130677. 5,
  130678. 15,
  130679. 4,
  130680. 16,
  130681. 3,
  130682. 17,
  130683. 2,
  130684. 18,
  130685. 1,
  130686. 19,
  130687. 0,
  130688. 20,
  130689. };
  130690. static long _vq_lengthlist__8u0__p7_2[] = {
  130691. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130692. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130693. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130694. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130695. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130696. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130697. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130698. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130699. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130700. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130701. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130702. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130703. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130704. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130705. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130706. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130707. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130708. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130709. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130710. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130711. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130712. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130713. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130714. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130715. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130716. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130717. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130718. 11,12,11,11,11,10,10,11,11,
  130719. };
  130720. static float _vq_quantthresh__8u0__p7_2[] = {
  130721. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130722. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130723. 6.5, 7.5, 8.5, 9.5,
  130724. };
  130725. static long _vq_quantmap__8u0__p7_2[] = {
  130726. 19, 17, 15, 13, 11, 9, 7, 5,
  130727. 3, 1, 0, 2, 4, 6, 8, 10,
  130728. 12, 14, 16, 18, 20,
  130729. };
  130730. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130731. _vq_quantthresh__8u0__p7_2,
  130732. _vq_quantmap__8u0__p7_2,
  130733. 21,
  130734. 21
  130735. };
  130736. static static_codebook _8u0__p7_2 = {
  130737. 2, 441,
  130738. _vq_lengthlist__8u0__p7_2,
  130739. 1, -529268736, 1611661312, 5, 0,
  130740. _vq_quantlist__8u0__p7_2,
  130741. NULL,
  130742. &_vq_auxt__8u0__p7_2,
  130743. NULL,
  130744. 0
  130745. };
  130746. static long _huff_lengthlist__8u0__single[] = {
  130747. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130748. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130749. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130750. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130751. };
  130752. static static_codebook _huff_book__8u0__single = {
  130753. 2, 64,
  130754. _huff_lengthlist__8u0__single,
  130755. 0, 0, 0, 0, 0,
  130756. NULL,
  130757. NULL,
  130758. NULL,
  130759. NULL,
  130760. 0
  130761. };
  130762. static long _vq_quantlist__8u1__p1_0[] = {
  130763. 1,
  130764. 0,
  130765. 2,
  130766. };
  130767. static long _vq_lengthlist__8u1__p1_0[] = {
  130768. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130769. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130770. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130771. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130772. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130773. 10,
  130774. };
  130775. static float _vq_quantthresh__8u1__p1_0[] = {
  130776. -0.5, 0.5,
  130777. };
  130778. static long _vq_quantmap__8u1__p1_0[] = {
  130779. 1, 0, 2,
  130780. };
  130781. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130782. _vq_quantthresh__8u1__p1_0,
  130783. _vq_quantmap__8u1__p1_0,
  130784. 3,
  130785. 3
  130786. };
  130787. static static_codebook _8u1__p1_0 = {
  130788. 4, 81,
  130789. _vq_lengthlist__8u1__p1_0,
  130790. 1, -535822336, 1611661312, 2, 0,
  130791. _vq_quantlist__8u1__p1_0,
  130792. NULL,
  130793. &_vq_auxt__8u1__p1_0,
  130794. NULL,
  130795. 0
  130796. };
  130797. static long _vq_quantlist__8u1__p2_0[] = {
  130798. 1,
  130799. 0,
  130800. 2,
  130801. };
  130802. static long _vq_lengthlist__8u1__p2_0[] = {
  130803. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130804. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130805. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130806. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130807. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130808. 7,
  130809. };
  130810. static float _vq_quantthresh__8u1__p2_0[] = {
  130811. -0.5, 0.5,
  130812. };
  130813. static long _vq_quantmap__8u1__p2_0[] = {
  130814. 1, 0, 2,
  130815. };
  130816. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  130817. _vq_quantthresh__8u1__p2_0,
  130818. _vq_quantmap__8u1__p2_0,
  130819. 3,
  130820. 3
  130821. };
  130822. static static_codebook _8u1__p2_0 = {
  130823. 4, 81,
  130824. _vq_lengthlist__8u1__p2_0,
  130825. 1, -535822336, 1611661312, 2, 0,
  130826. _vq_quantlist__8u1__p2_0,
  130827. NULL,
  130828. &_vq_auxt__8u1__p2_0,
  130829. NULL,
  130830. 0
  130831. };
  130832. static long _vq_quantlist__8u1__p3_0[] = {
  130833. 2,
  130834. 1,
  130835. 3,
  130836. 0,
  130837. 4,
  130838. };
  130839. static long _vq_lengthlist__8u1__p3_0[] = {
  130840. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130841. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130842. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  130843. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  130844. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  130845. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  130846. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  130847. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  130848. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  130849. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  130850. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  130851. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  130852. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  130853. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  130854. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  130855. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  130856. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  130857. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  130858. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  130859. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  130860. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  130861. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  130862. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  130863. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  130864. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  130865. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  130866. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  130867. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  130868. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  130869. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  130870. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  130871. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  130872. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  130873. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  130874. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  130875. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  130876. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  130877. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  130878. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  130879. 16,
  130880. };
  130881. static float _vq_quantthresh__8u1__p3_0[] = {
  130882. -1.5, -0.5, 0.5, 1.5,
  130883. };
  130884. static long _vq_quantmap__8u1__p3_0[] = {
  130885. 3, 1, 0, 2, 4,
  130886. };
  130887. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  130888. _vq_quantthresh__8u1__p3_0,
  130889. _vq_quantmap__8u1__p3_0,
  130890. 5,
  130891. 5
  130892. };
  130893. static static_codebook _8u1__p3_0 = {
  130894. 4, 625,
  130895. _vq_lengthlist__8u1__p3_0,
  130896. 1, -533725184, 1611661312, 3, 0,
  130897. _vq_quantlist__8u1__p3_0,
  130898. NULL,
  130899. &_vq_auxt__8u1__p3_0,
  130900. NULL,
  130901. 0
  130902. };
  130903. static long _vq_quantlist__8u1__p4_0[] = {
  130904. 2,
  130905. 1,
  130906. 3,
  130907. 0,
  130908. 4,
  130909. };
  130910. static long _vq_lengthlist__8u1__p4_0[] = {
  130911. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  130912. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  130913. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  130914. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  130915. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  130916. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  130917. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  130918. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  130919. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  130920. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  130921. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  130922. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  130923. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  130924. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  130925. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  130926. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  130927. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  130928. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  130929. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  130930. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  130931. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  130932. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  130933. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  130934. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  130935. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  130936. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  130937. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  130938. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  130939. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  130940. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  130941. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  130942. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  130943. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  130944. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  130945. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  130946. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  130947. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  130948. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  130949. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  130950. 10,
  130951. };
  130952. static float _vq_quantthresh__8u1__p4_0[] = {
  130953. -1.5, -0.5, 0.5, 1.5,
  130954. };
  130955. static long _vq_quantmap__8u1__p4_0[] = {
  130956. 3, 1, 0, 2, 4,
  130957. };
  130958. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  130959. _vq_quantthresh__8u1__p4_0,
  130960. _vq_quantmap__8u1__p4_0,
  130961. 5,
  130962. 5
  130963. };
  130964. static static_codebook _8u1__p4_0 = {
  130965. 4, 625,
  130966. _vq_lengthlist__8u1__p4_0,
  130967. 1, -533725184, 1611661312, 3, 0,
  130968. _vq_quantlist__8u1__p4_0,
  130969. NULL,
  130970. &_vq_auxt__8u1__p4_0,
  130971. NULL,
  130972. 0
  130973. };
  130974. static long _vq_quantlist__8u1__p5_0[] = {
  130975. 4,
  130976. 3,
  130977. 5,
  130978. 2,
  130979. 6,
  130980. 1,
  130981. 7,
  130982. 0,
  130983. 8,
  130984. };
  130985. static long _vq_lengthlist__8u1__p5_0[] = {
  130986. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  130987. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  130988. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  130989. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  130990. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  130991. 13,
  130992. };
  130993. static float _vq_quantthresh__8u1__p5_0[] = {
  130994. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130995. };
  130996. static long _vq_quantmap__8u1__p5_0[] = {
  130997. 7, 5, 3, 1, 0, 2, 4, 6,
  130998. 8,
  130999. };
  131000. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131001. _vq_quantthresh__8u1__p5_0,
  131002. _vq_quantmap__8u1__p5_0,
  131003. 9,
  131004. 9
  131005. };
  131006. static static_codebook _8u1__p5_0 = {
  131007. 2, 81,
  131008. _vq_lengthlist__8u1__p5_0,
  131009. 1, -531628032, 1611661312, 4, 0,
  131010. _vq_quantlist__8u1__p5_0,
  131011. NULL,
  131012. &_vq_auxt__8u1__p5_0,
  131013. NULL,
  131014. 0
  131015. };
  131016. static long _vq_quantlist__8u1__p6_0[] = {
  131017. 4,
  131018. 3,
  131019. 5,
  131020. 2,
  131021. 6,
  131022. 1,
  131023. 7,
  131024. 0,
  131025. 8,
  131026. };
  131027. static long _vq_lengthlist__8u1__p6_0[] = {
  131028. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131029. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131030. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131031. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131032. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131033. 10,
  131034. };
  131035. static float _vq_quantthresh__8u1__p6_0[] = {
  131036. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131037. };
  131038. static long _vq_quantmap__8u1__p6_0[] = {
  131039. 7, 5, 3, 1, 0, 2, 4, 6,
  131040. 8,
  131041. };
  131042. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131043. _vq_quantthresh__8u1__p6_0,
  131044. _vq_quantmap__8u1__p6_0,
  131045. 9,
  131046. 9
  131047. };
  131048. static static_codebook _8u1__p6_0 = {
  131049. 2, 81,
  131050. _vq_lengthlist__8u1__p6_0,
  131051. 1, -531628032, 1611661312, 4, 0,
  131052. _vq_quantlist__8u1__p6_0,
  131053. NULL,
  131054. &_vq_auxt__8u1__p6_0,
  131055. NULL,
  131056. 0
  131057. };
  131058. static long _vq_quantlist__8u1__p7_0[] = {
  131059. 1,
  131060. 0,
  131061. 2,
  131062. };
  131063. static long _vq_lengthlist__8u1__p7_0[] = {
  131064. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131065. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131066. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131067. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131068. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131069. 11,
  131070. };
  131071. static float _vq_quantthresh__8u1__p7_0[] = {
  131072. -5.5, 5.5,
  131073. };
  131074. static long _vq_quantmap__8u1__p7_0[] = {
  131075. 1, 0, 2,
  131076. };
  131077. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131078. _vq_quantthresh__8u1__p7_0,
  131079. _vq_quantmap__8u1__p7_0,
  131080. 3,
  131081. 3
  131082. };
  131083. static static_codebook _8u1__p7_0 = {
  131084. 4, 81,
  131085. _vq_lengthlist__8u1__p7_0,
  131086. 1, -529137664, 1618345984, 2, 0,
  131087. _vq_quantlist__8u1__p7_0,
  131088. NULL,
  131089. &_vq_auxt__8u1__p7_0,
  131090. NULL,
  131091. 0
  131092. };
  131093. static long _vq_quantlist__8u1__p7_1[] = {
  131094. 5,
  131095. 4,
  131096. 6,
  131097. 3,
  131098. 7,
  131099. 2,
  131100. 8,
  131101. 1,
  131102. 9,
  131103. 0,
  131104. 10,
  131105. };
  131106. static long _vq_lengthlist__8u1__p7_1[] = {
  131107. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131108. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131109. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131110. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131111. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131112. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131113. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131114. 9, 9, 9, 9, 9,10,10,10,10,
  131115. };
  131116. static float _vq_quantthresh__8u1__p7_1[] = {
  131117. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131118. 3.5, 4.5,
  131119. };
  131120. static long _vq_quantmap__8u1__p7_1[] = {
  131121. 9, 7, 5, 3, 1, 0, 2, 4,
  131122. 6, 8, 10,
  131123. };
  131124. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131125. _vq_quantthresh__8u1__p7_1,
  131126. _vq_quantmap__8u1__p7_1,
  131127. 11,
  131128. 11
  131129. };
  131130. static static_codebook _8u1__p7_1 = {
  131131. 2, 121,
  131132. _vq_lengthlist__8u1__p7_1,
  131133. 1, -531365888, 1611661312, 4, 0,
  131134. _vq_quantlist__8u1__p7_1,
  131135. NULL,
  131136. &_vq_auxt__8u1__p7_1,
  131137. NULL,
  131138. 0
  131139. };
  131140. static long _vq_quantlist__8u1__p8_0[] = {
  131141. 5,
  131142. 4,
  131143. 6,
  131144. 3,
  131145. 7,
  131146. 2,
  131147. 8,
  131148. 1,
  131149. 9,
  131150. 0,
  131151. 10,
  131152. };
  131153. static long _vq_lengthlist__8u1__p8_0[] = {
  131154. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131155. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131156. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131157. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131158. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131159. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131160. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131161. 12,13,13,14,14,15,15,15,15,
  131162. };
  131163. static float _vq_quantthresh__8u1__p8_0[] = {
  131164. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131165. 38.5, 49.5,
  131166. };
  131167. static long _vq_quantmap__8u1__p8_0[] = {
  131168. 9, 7, 5, 3, 1, 0, 2, 4,
  131169. 6, 8, 10,
  131170. };
  131171. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131172. _vq_quantthresh__8u1__p8_0,
  131173. _vq_quantmap__8u1__p8_0,
  131174. 11,
  131175. 11
  131176. };
  131177. static static_codebook _8u1__p8_0 = {
  131178. 2, 121,
  131179. _vq_lengthlist__8u1__p8_0,
  131180. 1, -524582912, 1618345984, 4, 0,
  131181. _vq_quantlist__8u1__p8_0,
  131182. NULL,
  131183. &_vq_auxt__8u1__p8_0,
  131184. NULL,
  131185. 0
  131186. };
  131187. static long _vq_quantlist__8u1__p8_1[] = {
  131188. 5,
  131189. 4,
  131190. 6,
  131191. 3,
  131192. 7,
  131193. 2,
  131194. 8,
  131195. 1,
  131196. 9,
  131197. 0,
  131198. 10,
  131199. };
  131200. static long _vq_lengthlist__8u1__p8_1[] = {
  131201. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131202. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131203. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131204. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131205. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131206. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131207. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131208. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131209. };
  131210. static float _vq_quantthresh__8u1__p8_1[] = {
  131211. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131212. 3.5, 4.5,
  131213. };
  131214. static long _vq_quantmap__8u1__p8_1[] = {
  131215. 9, 7, 5, 3, 1, 0, 2, 4,
  131216. 6, 8, 10,
  131217. };
  131218. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131219. _vq_quantthresh__8u1__p8_1,
  131220. _vq_quantmap__8u1__p8_1,
  131221. 11,
  131222. 11
  131223. };
  131224. static static_codebook _8u1__p8_1 = {
  131225. 2, 121,
  131226. _vq_lengthlist__8u1__p8_1,
  131227. 1, -531365888, 1611661312, 4, 0,
  131228. _vq_quantlist__8u1__p8_1,
  131229. NULL,
  131230. &_vq_auxt__8u1__p8_1,
  131231. NULL,
  131232. 0
  131233. };
  131234. static long _vq_quantlist__8u1__p9_0[] = {
  131235. 7,
  131236. 6,
  131237. 8,
  131238. 5,
  131239. 9,
  131240. 4,
  131241. 10,
  131242. 3,
  131243. 11,
  131244. 2,
  131245. 12,
  131246. 1,
  131247. 13,
  131248. 0,
  131249. 14,
  131250. };
  131251. static long _vq_lengthlist__8u1__p9_0[] = {
  131252. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131253. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131254. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131255. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131256. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131257. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131258. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131259. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131260. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131264. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131265. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131266. 10,
  131267. };
  131268. static float _vq_quantthresh__8u1__p9_0[] = {
  131269. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131270. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131271. };
  131272. static long _vq_quantmap__8u1__p9_0[] = {
  131273. 13, 11, 9, 7, 5, 3, 1, 0,
  131274. 2, 4, 6, 8, 10, 12, 14,
  131275. };
  131276. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131277. _vq_quantthresh__8u1__p9_0,
  131278. _vq_quantmap__8u1__p9_0,
  131279. 15,
  131280. 15
  131281. };
  131282. static static_codebook _8u1__p9_0 = {
  131283. 2, 225,
  131284. _vq_lengthlist__8u1__p9_0,
  131285. 1, -514071552, 1627381760, 4, 0,
  131286. _vq_quantlist__8u1__p9_0,
  131287. NULL,
  131288. &_vq_auxt__8u1__p9_0,
  131289. NULL,
  131290. 0
  131291. };
  131292. static long _vq_quantlist__8u1__p9_1[] = {
  131293. 7,
  131294. 6,
  131295. 8,
  131296. 5,
  131297. 9,
  131298. 4,
  131299. 10,
  131300. 3,
  131301. 11,
  131302. 2,
  131303. 12,
  131304. 1,
  131305. 13,
  131306. 0,
  131307. 14,
  131308. };
  131309. static long _vq_lengthlist__8u1__p9_1[] = {
  131310. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131311. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131312. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131313. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131314. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131315. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131316. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131317. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131318. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131319. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131320. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131321. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131322. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131323. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131324. 13,
  131325. };
  131326. static float _vq_quantthresh__8u1__p9_1[] = {
  131327. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131328. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131329. };
  131330. static long _vq_quantmap__8u1__p9_1[] = {
  131331. 13, 11, 9, 7, 5, 3, 1, 0,
  131332. 2, 4, 6, 8, 10, 12, 14,
  131333. };
  131334. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131335. _vq_quantthresh__8u1__p9_1,
  131336. _vq_quantmap__8u1__p9_1,
  131337. 15,
  131338. 15
  131339. };
  131340. static static_codebook _8u1__p9_1 = {
  131341. 2, 225,
  131342. _vq_lengthlist__8u1__p9_1,
  131343. 1, -522338304, 1620115456, 4, 0,
  131344. _vq_quantlist__8u1__p9_1,
  131345. NULL,
  131346. &_vq_auxt__8u1__p9_1,
  131347. NULL,
  131348. 0
  131349. };
  131350. static long _vq_quantlist__8u1__p9_2[] = {
  131351. 8,
  131352. 7,
  131353. 9,
  131354. 6,
  131355. 10,
  131356. 5,
  131357. 11,
  131358. 4,
  131359. 12,
  131360. 3,
  131361. 13,
  131362. 2,
  131363. 14,
  131364. 1,
  131365. 15,
  131366. 0,
  131367. 16,
  131368. };
  131369. static long _vq_lengthlist__8u1__p9_2[] = {
  131370. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131371. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131372. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131373. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131374. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131375. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131376. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131377. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131378. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131379. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131380. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131381. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131382. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131383. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131384. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131385. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131386. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131387. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131388. 10,
  131389. };
  131390. static float _vq_quantthresh__8u1__p9_2[] = {
  131391. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131392. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131393. };
  131394. static long _vq_quantmap__8u1__p9_2[] = {
  131395. 15, 13, 11, 9, 7, 5, 3, 1,
  131396. 0, 2, 4, 6, 8, 10, 12, 14,
  131397. 16,
  131398. };
  131399. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131400. _vq_quantthresh__8u1__p9_2,
  131401. _vq_quantmap__8u1__p9_2,
  131402. 17,
  131403. 17
  131404. };
  131405. static static_codebook _8u1__p9_2 = {
  131406. 2, 289,
  131407. _vq_lengthlist__8u1__p9_2,
  131408. 1, -529530880, 1611661312, 5, 0,
  131409. _vq_quantlist__8u1__p9_2,
  131410. NULL,
  131411. &_vq_auxt__8u1__p9_2,
  131412. NULL,
  131413. 0
  131414. };
  131415. static long _huff_lengthlist__8u1__single[] = {
  131416. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131417. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131418. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131419. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131420. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131421. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131422. 13, 8, 8,15,
  131423. };
  131424. static static_codebook _huff_book__8u1__single = {
  131425. 2, 100,
  131426. _huff_lengthlist__8u1__single,
  131427. 0, 0, 0, 0, 0,
  131428. NULL,
  131429. NULL,
  131430. NULL,
  131431. NULL,
  131432. 0
  131433. };
  131434. static long _huff_lengthlist__44u0__long[] = {
  131435. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131436. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131437. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131438. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131439. };
  131440. static static_codebook _huff_book__44u0__long = {
  131441. 2, 64,
  131442. _huff_lengthlist__44u0__long,
  131443. 0, 0, 0, 0, 0,
  131444. NULL,
  131445. NULL,
  131446. NULL,
  131447. NULL,
  131448. 0
  131449. };
  131450. static long _vq_quantlist__44u0__p1_0[] = {
  131451. 1,
  131452. 0,
  131453. 2,
  131454. };
  131455. static long _vq_lengthlist__44u0__p1_0[] = {
  131456. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131457. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131458. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131459. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131460. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131461. 13,
  131462. };
  131463. static float _vq_quantthresh__44u0__p1_0[] = {
  131464. -0.5, 0.5,
  131465. };
  131466. static long _vq_quantmap__44u0__p1_0[] = {
  131467. 1, 0, 2,
  131468. };
  131469. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131470. _vq_quantthresh__44u0__p1_0,
  131471. _vq_quantmap__44u0__p1_0,
  131472. 3,
  131473. 3
  131474. };
  131475. static static_codebook _44u0__p1_0 = {
  131476. 4, 81,
  131477. _vq_lengthlist__44u0__p1_0,
  131478. 1, -535822336, 1611661312, 2, 0,
  131479. _vq_quantlist__44u0__p1_0,
  131480. NULL,
  131481. &_vq_auxt__44u0__p1_0,
  131482. NULL,
  131483. 0
  131484. };
  131485. static long _vq_quantlist__44u0__p2_0[] = {
  131486. 1,
  131487. 0,
  131488. 2,
  131489. };
  131490. static long _vq_lengthlist__44u0__p2_0[] = {
  131491. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131492. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131493. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131494. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131495. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131496. 9,
  131497. };
  131498. static float _vq_quantthresh__44u0__p2_0[] = {
  131499. -0.5, 0.5,
  131500. };
  131501. static long _vq_quantmap__44u0__p2_0[] = {
  131502. 1, 0, 2,
  131503. };
  131504. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131505. _vq_quantthresh__44u0__p2_0,
  131506. _vq_quantmap__44u0__p2_0,
  131507. 3,
  131508. 3
  131509. };
  131510. static static_codebook _44u0__p2_0 = {
  131511. 4, 81,
  131512. _vq_lengthlist__44u0__p2_0,
  131513. 1, -535822336, 1611661312, 2, 0,
  131514. _vq_quantlist__44u0__p2_0,
  131515. NULL,
  131516. &_vq_auxt__44u0__p2_0,
  131517. NULL,
  131518. 0
  131519. };
  131520. static long _vq_quantlist__44u0__p3_0[] = {
  131521. 2,
  131522. 1,
  131523. 3,
  131524. 0,
  131525. 4,
  131526. };
  131527. static long _vq_lengthlist__44u0__p3_0[] = {
  131528. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131529. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131530. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131531. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131532. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131533. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131534. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131535. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131536. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131537. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131538. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131539. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131540. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131541. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131542. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131543. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131544. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131545. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131546. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131547. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131548. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131549. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131550. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131551. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131552. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131553. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131554. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131555. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131556. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131557. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131558. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131559. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131560. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131561. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131562. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131563. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131564. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131565. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131566. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131567. 19,
  131568. };
  131569. static float _vq_quantthresh__44u0__p3_0[] = {
  131570. -1.5, -0.5, 0.5, 1.5,
  131571. };
  131572. static long _vq_quantmap__44u0__p3_0[] = {
  131573. 3, 1, 0, 2, 4,
  131574. };
  131575. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131576. _vq_quantthresh__44u0__p3_0,
  131577. _vq_quantmap__44u0__p3_0,
  131578. 5,
  131579. 5
  131580. };
  131581. static static_codebook _44u0__p3_0 = {
  131582. 4, 625,
  131583. _vq_lengthlist__44u0__p3_0,
  131584. 1, -533725184, 1611661312, 3, 0,
  131585. _vq_quantlist__44u0__p3_0,
  131586. NULL,
  131587. &_vq_auxt__44u0__p3_0,
  131588. NULL,
  131589. 0
  131590. };
  131591. static long _vq_quantlist__44u0__p4_0[] = {
  131592. 2,
  131593. 1,
  131594. 3,
  131595. 0,
  131596. 4,
  131597. };
  131598. static long _vq_lengthlist__44u0__p4_0[] = {
  131599. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131600. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131601. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131602. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131603. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131604. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131605. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131606. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131607. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131608. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131609. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131610. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131611. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131612. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131613. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131614. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131615. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131616. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131617. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131618. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131619. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131620. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131621. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131622. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131623. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131624. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131625. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131626. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131627. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131628. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131629. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131630. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131631. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131632. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131633. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131634. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131635. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131636. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131637. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131638. 12,
  131639. };
  131640. static float _vq_quantthresh__44u0__p4_0[] = {
  131641. -1.5, -0.5, 0.5, 1.5,
  131642. };
  131643. static long _vq_quantmap__44u0__p4_0[] = {
  131644. 3, 1, 0, 2, 4,
  131645. };
  131646. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131647. _vq_quantthresh__44u0__p4_0,
  131648. _vq_quantmap__44u0__p4_0,
  131649. 5,
  131650. 5
  131651. };
  131652. static static_codebook _44u0__p4_0 = {
  131653. 4, 625,
  131654. _vq_lengthlist__44u0__p4_0,
  131655. 1, -533725184, 1611661312, 3, 0,
  131656. _vq_quantlist__44u0__p4_0,
  131657. NULL,
  131658. &_vq_auxt__44u0__p4_0,
  131659. NULL,
  131660. 0
  131661. };
  131662. static long _vq_quantlist__44u0__p5_0[] = {
  131663. 4,
  131664. 3,
  131665. 5,
  131666. 2,
  131667. 6,
  131668. 1,
  131669. 7,
  131670. 0,
  131671. 8,
  131672. };
  131673. static long _vq_lengthlist__44u0__p5_0[] = {
  131674. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131675. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131676. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131677. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131678. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131679. 12,
  131680. };
  131681. static float _vq_quantthresh__44u0__p5_0[] = {
  131682. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131683. };
  131684. static long _vq_quantmap__44u0__p5_0[] = {
  131685. 7, 5, 3, 1, 0, 2, 4, 6,
  131686. 8,
  131687. };
  131688. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131689. _vq_quantthresh__44u0__p5_0,
  131690. _vq_quantmap__44u0__p5_0,
  131691. 9,
  131692. 9
  131693. };
  131694. static static_codebook _44u0__p5_0 = {
  131695. 2, 81,
  131696. _vq_lengthlist__44u0__p5_0,
  131697. 1, -531628032, 1611661312, 4, 0,
  131698. _vq_quantlist__44u0__p5_0,
  131699. NULL,
  131700. &_vq_auxt__44u0__p5_0,
  131701. NULL,
  131702. 0
  131703. };
  131704. static long _vq_quantlist__44u0__p6_0[] = {
  131705. 6,
  131706. 5,
  131707. 7,
  131708. 4,
  131709. 8,
  131710. 3,
  131711. 9,
  131712. 2,
  131713. 10,
  131714. 1,
  131715. 11,
  131716. 0,
  131717. 12,
  131718. };
  131719. static long _vq_lengthlist__44u0__p6_0[] = {
  131720. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131721. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131722. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131723. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131724. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131725. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131726. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131727. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131728. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131729. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131730. 15,17,16,17,18,17,17,18, 0,
  131731. };
  131732. static float _vq_quantthresh__44u0__p6_0[] = {
  131733. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131734. 12.5, 17.5, 22.5, 27.5,
  131735. };
  131736. static long _vq_quantmap__44u0__p6_0[] = {
  131737. 11, 9, 7, 5, 3, 1, 0, 2,
  131738. 4, 6, 8, 10, 12,
  131739. };
  131740. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131741. _vq_quantthresh__44u0__p6_0,
  131742. _vq_quantmap__44u0__p6_0,
  131743. 13,
  131744. 13
  131745. };
  131746. static static_codebook _44u0__p6_0 = {
  131747. 2, 169,
  131748. _vq_lengthlist__44u0__p6_0,
  131749. 1, -526516224, 1616117760, 4, 0,
  131750. _vq_quantlist__44u0__p6_0,
  131751. NULL,
  131752. &_vq_auxt__44u0__p6_0,
  131753. NULL,
  131754. 0
  131755. };
  131756. static long _vq_quantlist__44u0__p6_1[] = {
  131757. 2,
  131758. 1,
  131759. 3,
  131760. 0,
  131761. 4,
  131762. };
  131763. static long _vq_lengthlist__44u0__p6_1[] = {
  131764. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131765. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131766. };
  131767. static float _vq_quantthresh__44u0__p6_1[] = {
  131768. -1.5, -0.5, 0.5, 1.5,
  131769. };
  131770. static long _vq_quantmap__44u0__p6_1[] = {
  131771. 3, 1, 0, 2, 4,
  131772. };
  131773. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131774. _vq_quantthresh__44u0__p6_1,
  131775. _vq_quantmap__44u0__p6_1,
  131776. 5,
  131777. 5
  131778. };
  131779. static static_codebook _44u0__p6_1 = {
  131780. 2, 25,
  131781. _vq_lengthlist__44u0__p6_1,
  131782. 1, -533725184, 1611661312, 3, 0,
  131783. _vq_quantlist__44u0__p6_1,
  131784. NULL,
  131785. &_vq_auxt__44u0__p6_1,
  131786. NULL,
  131787. 0
  131788. };
  131789. static long _vq_quantlist__44u0__p7_0[] = {
  131790. 2,
  131791. 1,
  131792. 3,
  131793. 0,
  131794. 4,
  131795. };
  131796. static long _vq_lengthlist__44u0__p7_0[] = {
  131797. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131798. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131799. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131800. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131801. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131802. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131803. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131804. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131805. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131806. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131807. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131808. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131809. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131810. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131811. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131812. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131813. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131814. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131815. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131816. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131817. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131818. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131819. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131820. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131821. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131822. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131823. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131824. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131825. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131826. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131827. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  131828. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131829. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131830. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131831. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131832. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131833. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131834. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131835. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131836. 10,
  131837. };
  131838. static float _vq_quantthresh__44u0__p7_0[] = {
  131839. -253.5, -84.5, 84.5, 253.5,
  131840. };
  131841. static long _vq_quantmap__44u0__p7_0[] = {
  131842. 3, 1, 0, 2, 4,
  131843. };
  131844. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  131845. _vq_quantthresh__44u0__p7_0,
  131846. _vq_quantmap__44u0__p7_0,
  131847. 5,
  131848. 5
  131849. };
  131850. static static_codebook _44u0__p7_0 = {
  131851. 4, 625,
  131852. _vq_lengthlist__44u0__p7_0,
  131853. 1, -518709248, 1626677248, 3, 0,
  131854. _vq_quantlist__44u0__p7_0,
  131855. NULL,
  131856. &_vq_auxt__44u0__p7_0,
  131857. NULL,
  131858. 0
  131859. };
  131860. static long _vq_quantlist__44u0__p7_1[] = {
  131861. 6,
  131862. 5,
  131863. 7,
  131864. 4,
  131865. 8,
  131866. 3,
  131867. 9,
  131868. 2,
  131869. 10,
  131870. 1,
  131871. 11,
  131872. 0,
  131873. 12,
  131874. };
  131875. static long _vq_lengthlist__44u0__p7_1[] = {
  131876. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  131877. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  131878. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  131879. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  131880. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  131881. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  131882. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  131883. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  131884. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  131885. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  131886. 15,15,15,15,15,15,15,15,15,
  131887. };
  131888. static float _vq_quantthresh__44u0__p7_1[] = {
  131889. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  131890. 32.5, 45.5, 58.5, 71.5,
  131891. };
  131892. static long _vq_quantmap__44u0__p7_1[] = {
  131893. 11, 9, 7, 5, 3, 1, 0, 2,
  131894. 4, 6, 8, 10, 12,
  131895. };
  131896. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  131897. _vq_quantthresh__44u0__p7_1,
  131898. _vq_quantmap__44u0__p7_1,
  131899. 13,
  131900. 13
  131901. };
  131902. static static_codebook _44u0__p7_1 = {
  131903. 2, 169,
  131904. _vq_lengthlist__44u0__p7_1,
  131905. 1, -523010048, 1618608128, 4, 0,
  131906. _vq_quantlist__44u0__p7_1,
  131907. NULL,
  131908. &_vq_auxt__44u0__p7_1,
  131909. NULL,
  131910. 0
  131911. };
  131912. static long _vq_quantlist__44u0__p7_2[] = {
  131913. 6,
  131914. 5,
  131915. 7,
  131916. 4,
  131917. 8,
  131918. 3,
  131919. 9,
  131920. 2,
  131921. 10,
  131922. 1,
  131923. 11,
  131924. 0,
  131925. 12,
  131926. };
  131927. static long _vq_lengthlist__44u0__p7_2[] = {
  131928. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  131929. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  131930. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  131931. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  131932. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  131933. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  131934. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  131935. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  131936. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  131937. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  131938. 9, 9, 9,10, 9, 9,10,10, 9,
  131939. };
  131940. static float _vq_quantthresh__44u0__p7_2[] = {
  131941. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  131942. 2.5, 3.5, 4.5, 5.5,
  131943. };
  131944. static long _vq_quantmap__44u0__p7_2[] = {
  131945. 11, 9, 7, 5, 3, 1, 0, 2,
  131946. 4, 6, 8, 10, 12,
  131947. };
  131948. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  131949. _vq_quantthresh__44u0__p7_2,
  131950. _vq_quantmap__44u0__p7_2,
  131951. 13,
  131952. 13
  131953. };
  131954. static static_codebook _44u0__p7_2 = {
  131955. 2, 169,
  131956. _vq_lengthlist__44u0__p7_2,
  131957. 1, -531103744, 1611661312, 4, 0,
  131958. _vq_quantlist__44u0__p7_2,
  131959. NULL,
  131960. &_vq_auxt__44u0__p7_2,
  131961. NULL,
  131962. 0
  131963. };
  131964. static long _huff_lengthlist__44u0__short[] = {
  131965. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  131966. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  131967. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  131968. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  131969. };
  131970. static static_codebook _huff_book__44u0__short = {
  131971. 2, 64,
  131972. _huff_lengthlist__44u0__short,
  131973. 0, 0, 0, 0, 0,
  131974. NULL,
  131975. NULL,
  131976. NULL,
  131977. NULL,
  131978. 0
  131979. };
  131980. static long _huff_lengthlist__44u1__long[] = {
  131981. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131982. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131983. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131984. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131985. };
  131986. static static_codebook _huff_book__44u1__long = {
  131987. 2, 64,
  131988. _huff_lengthlist__44u1__long,
  131989. 0, 0, 0, 0, 0,
  131990. NULL,
  131991. NULL,
  131992. NULL,
  131993. NULL,
  131994. 0
  131995. };
  131996. static long _vq_quantlist__44u1__p1_0[] = {
  131997. 1,
  131998. 0,
  131999. 2,
  132000. };
  132001. static long _vq_lengthlist__44u1__p1_0[] = {
  132002. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132003. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132004. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132005. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132006. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132007. 13,
  132008. };
  132009. static float _vq_quantthresh__44u1__p1_0[] = {
  132010. -0.5, 0.5,
  132011. };
  132012. static long _vq_quantmap__44u1__p1_0[] = {
  132013. 1, 0, 2,
  132014. };
  132015. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132016. _vq_quantthresh__44u1__p1_0,
  132017. _vq_quantmap__44u1__p1_0,
  132018. 3,
  132019. 3
  132020. };
  132021. static static_codebook _44u1__p1_0 = {
  132022. 4, 81,
  132023. _vq_lengthlist__44u1__p1_0,
  132024. 1, -535822336, 1611661312, 2, 0,
  132025. _vq_quantlist__44u1__p1_0,
  132026. NULL,
  132027. &_vq_auxt__44u1__p1_0,
  132028. NULL,
  132029. 0
  132030. };
  132031. static long _vq_quantlist__44u1__p2_0[] = {
  132032. 1,
  132033. 0,
  132034. 2,
  132035. };
  132036. static long _vq_lengthlist__44u1__p2_0[] = {
  132037. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132038. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132039. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132040. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132041. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132042. 9,
  132043. };
  132044. static float _vq_quantthresh__44u1__p2_0[] = {
  132045. -0.5, 0.5,
  132046. };
  132047. static long _vq_quantmap__44u1__p2_0[] = {
  132048. 1, 0, 2,
  132049. };
  132050. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132051. _vq_quantthresh__44u1__p2_0,
  132052. _vq_quantmap__44u1__p2_0,
  132053. 3,
  132054. 3
  132055. };
  132056. static static_codebook _44u1__p2_0 = {
  132057. 4, 81,
  132058. _vq_lengthlist__44u1__p2_0,
  132059. 1, -535822336, 1611661312, 2, 0,
  132060. _vq_quantlist__44u1__p2_0,
  132061. NULL,
  132062. &_vq_auxt__44u1__p2_0,
  132063. NULL,
  132064. 0
  132065. };
  132066. static long _vq_quantlist__44u1__p3_0[] = {
  132067. 2,
  132068. 1,
  132069. 3,
  132070. 0,
  132071. 4,
  132072. };
  132073. static long _vq_lengthlist__44u1__p3_0[] = {
  132074. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132075. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132076. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132077. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132078. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132079. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132080. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132081. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132082. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132083. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132084. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132085. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132086. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132087. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132088. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132089. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132090. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132091. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132092. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132093. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132094. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132095. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132096. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132097. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132098. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132099. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132100. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132101. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132102. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132103. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132104. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132105. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132106. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132107. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132108. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132109. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132110. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132111. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132112. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132113. 19,
  132114. };
  132115. static float _vq_quantthresh__44u1__p3_0[] = {
  132116. -1.5, -0.5, 0.5, 1.5,
  132117. };
  132118. static long _vq_quantmap__44u1__p3_0[] = {
  132119. 3, 1, 0, 2, 4,
  132120. };
  132121. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132122. _vq_quantthresh__44u1__p3_0,
  132123. _vq_quantmap__44u1__p3_0,
  132124. 5,
  132125. 5
  132126. };
  132127. static static_codebook _44u1__p3_0 = {
  132128. 4, 625,
  132129. _vq_lengthlist__44u1__p3_0,
  132130. 1, -533725184, 1611661312, 3, 0,
  132131. _vq_quantlist__44u1__p3_0,
  132132. NULL,
  132133. &_vq_auxt__44u1__p3_0,
  132134. NULL,
  132135. 0
  132136. };
  132137. static long _vq_quantlist__44u1__p4_0[] = {
  132138. 2,
  132139. 1,
  132140. 3,
  132141. 0,
  132142. 4,
  132143. };
  132144. static long _vq_lengthlist__44u1__p4_0[] = {
  132145. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132146. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132147. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132148. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132149. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132150. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132151. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132152. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132153. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132154. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132155. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132156. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132157. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132158. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132159. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132160. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132161. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132162. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132163. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132164. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132165. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132166. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132167. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132168. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132169. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132170. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132171. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132172. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132173. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132174. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132175. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132176. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132177. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132178. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132179. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132180. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132181. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132182. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132183. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132184. 12,
  132185. };
  132186. static float _vq_quantthresh__44u1__p4_0[] = {
  132187. -1.5, -0.5, 0.5, 1.5,
  132188. };
  132189. static long _vq_quantmap__44u1__p4_0[] = {
  132190. 3, 1, 0, 2, 4,
  132191. };
  132192. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132193. _vq_quantthresh__44u1__p4_0,
  132194. _vq_quantmap__44u1__p4_0,
  132195. 5,
  132196. 5
  132197. };
  132198. static static_codebook _44u1__p4_0 = {
  132199. 4, 625,
  132200. _vq_lengthlist__44u1__p4_0,
  132201. 1, -533725184, 1611661312, 3, 0,
  132202. _vq_quantlist__44u1__p4_0,
  132203. NULL,
  132204. &_vq_auxt__44u1__p4_0,
  132205. NULL,
  132206. 0
  132207. };
  132208. static long _vq_quantlist__44u1__p5_0[] = {
  132209. 4,
  132210. 3,
  132211. 5,
  132212. 2,
  132213. 6,
  132214. 1,
  132215. 7,
  132216. 0,
  132217. 8,
  132218. };
  132219. static long _vq_lengthlist__44u1__p5_0[] = {
  132220. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132221. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132222. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132223. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132224. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132225. 12,
  132226. };
  132227. static float _vq_quantthresh__44u1__p5_0[] = {
  132228. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132229. };
  132230. static long _vq_quantmap__44u1__p5_0[] = {
  132231. 7, 5, 3, 1, 0, 2, 4, 6,
  132232. 8,
  132233. };
  132234. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132235. _vq_quantthresh__44u1__p5_0,
  132236. _vq_quantmap__44u1__p5_0,
  132237. 9,
  132238. 9
  132239. };
  132240. static static_codebook _44u1__p5_0 = {
  132241. 2, 81,
  132242. _vq_lengthlist__44u1__p5_0,
  132243. 1, -531628032, 1611661312, 4, 0,
  132244. _vq_quantlist__44u1__p5_0,
  132245. NULL,
  132246. &_vq_auxt__44u1__p5_0,
  132247. NULL,
  132248. 0
  132249. };
  132250. static long _vq_quantlist__44u1__p6_0[] = {
  132251. 6,
  132252. 5,
  132253. 7,
  132254. 4,
  132255. 8,
  132256. 3,
  132257. 9,
  132258. 2,
  132259. 10,
  132260. 1,
  132261. 11,
  132262. 0,
  132263. 12,
  132264. };
  132265. static long _vq_lengthlist__44u1__p6_0[] = {
  132266. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132267. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132268. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132269. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132270. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132271. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132272. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132273. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132274. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132275. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132276. 15,17,16,17,18,17,17,18, 0,
  132277. };
  132278. static float _vq_quantthresh__44u1__p6_0[] = {
  132279. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132280. 12.5, 17.5, 22.5, 27.5,
  132281. };
  132282. static long _vq_quantmap__44u1__p6_0[] = {
  132283. 11, 9, 7, 5, 3, 1, 0, 2,
  132284. 4, 6, 8, 10, 12,
  132285. };
  132286. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132287. _vq_quantthresh__44u1__p6_0,
  132288. _vq_quantmap__44u1__p6_0,
  132289. 13,
  132290. 13
  132291. };
  132292. static static_codebook _44u1__p6_0 = {
  132293. 2, 169,
  132294. _vq_lengthlist__44u1__p6_0,
  132295. 1, -526516224, 1616117760, 4, 0,
  132296. _vq_quantlist__44u1__p6_0,
  132297. NULL,
  132298. &_vq_auxt__44u1__p6_0,
  132299. NULL,
  132300. 0
  132301. };
  132302. static long _vq_quantlist__44u1__p6_1[] = {
  132303. 2,
  132304. 1,
  132305. 3,
  132306. 0,
  132307. 4,
  132308. };
  132309. static long _vq_lengthlist__44u1__p6_1[] = {
  132310. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132311. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132312. };
  132313. static float _vq_quantthresh__44u1__p6_1[] = {
  132314. -1.5, -0.5, 0.5, 1.5,
  132315. };
  132316. static long _vq_quantmap__44u1__p6_1[] = {
  132317. 3, 1, 0, 2, 4,
  132318. };
  132319. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132320. _vq_quantthresh__44u1__p6_1,
  132321. _vq_quantmap__44u1__p6_1,
  132322. 5,
  132323. 5
  132324. };
  132325. static static_codebook _44u1__p6_1 = {
  132326. 2, 25,
  132327. _vq_lengthlist__44u1__p6_1,
  132328. 1, -533725184, 1611661312, 3, 0,
  132329. _vq_quantlist__44u1__p6_1,
  132330. NULL,
  132331. &_vq_auxt__44u1__p6_1,
  132332. NULL,
  132333. 0
  132334. };
  132335. static long _vq_quantlist__44u1__p7_0[] = {
  132336. 3,
  132337. 2,
  132338. 4,
  132339. 1,
  132340. 5,
  132341. 0,
  132342. 6,
  132343. };
  132344. static long _vq_lengthlist__44u1__p7_0[] = {
  132345. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132346. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132347. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132348. 8,
  132349. };
  132350. static float _vq_quantthresh__44u1__p7_0[] = {
  132351. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132352. };
  132353. static long _vq_quantmap__44u1__p7_0[] = {
  132354. 5, 3, 1, 0, 2, 4, 6,
  132355. };
  132356. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132357. _vq_quantthresh__44u1__p7_0,
  132358. _vq_quantmap__44u1__p7_0,
  132359. 7,
  132360. 7
  132361. };
  132362. static static_codebook _44u1__p7_0 = {
  132363. 2, 49,
  132364. _vq_lengthlist__44u1__p7_0,
  132365. 1, -518017024, 1626677248, 3, 0,
  132366. _vq_quantlist__44u1__p7_0,
  132367. NULL,
  132368. &_vq_auxt__44u1__p7_0,
  132369. NULL,
  132370. 0
  132371. };
  132372. static long _vq_quantlist__44u1__p7_1[] = {
  132373. 6,
  132374. 5,
  132375. 7,
  132376. 4,
  132377. 8,
  132378. 3,
  132379. 9,
  132380. 2,
  132381. 10,
  132382. 1,
  132383. 11,
  132384. 0,
  132385. 12,
  132386. };
  132387. static long _vq_lengthlist__44u1__p7_1[] = {
  132388. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132389. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132390. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132391. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132392. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132393. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132394. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132395. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132396. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132397. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132398. 15,15,15,15,15,15,15,15,15,
  132399. };
  132400. static float _vq_quantthresh__44u1__p7_1[] = {
  132401. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132402. 32.5, 45.5, 58.5, 71.5,
  132403. };
  132404. static long _vq_quantmap__44u1__p7_1[] = {
  132405. 11, 9, 7, 5, 3, 1, 0, 2,
  132406. 4, 6, 8, 10, 12,
  132407. };
  132408. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132409. _vq_quantthresh__44u1__p7_1,
  132410. _vq_quantmap__44u1__p7_1,
  132411. 13,
  132412. 13
  132413. };
  132414. static static_codebook _44u1__p7_1 = {
  132415. 2, 169,
  132416. _vq_lengthlist__44u1__p7_1,
  132417. 1, -523010048, 1618608128, 4, 0,
  132418. _vq_quantlist__44u1__p7_1,
  132419. NULL,
  132420. &_vq_auxt__44u1__p7_1,
  132421. NULL,
  132422. 0
  132423. };
  132424. static long _vq_quantlist__44u1__p7_2[] = {
  132425. 6,
  132426. 5,
  132427. 7,
  132428. 4,
  132429. 8,
  132430. 3,
  132431. 9,
  132432. 2,
  132433. 10,
  132434. 1,
  132435. 11,
  132436. 0,
  132437. 12,
  132438. };
  132439. static long _vq_lengthlist__44u1__p7_2[] = {
  132440. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132441. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132442. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132443. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132444. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132445. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132446. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132447. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132448. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132449. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132450. 9, 9, 9,10, 9, 9,10,10, 9,
  132451. };
  132452. static float _vq_quantthresh__44u1__p7_2[] = {
  132453. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132454. 2.5, 3.5, 4.5, 5.5,
  132455. };
  132456. static long _vq_quantmap__44u1__p7_2[] = {
  132457. 11, 9, 7, 5, 3, 1, 0, 2,
  132458. 4, 6, 8, 10, 12,
  132459. };
  132460. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132461. _vq_quantthresh__44u1__p7_2,
  132462. _vq_quantmap__44u1__p7_2,
  132463. 13,
  132464. 13
  132465. };
  132466. static static_codebook _44u1__p7_2 = {
  132467. 2, 169,
  132468. _vq_lengthlist__44u1__p7_2,
  132469. 1, -531103744, 1611661312, 4, 0,
  132470. _vq_quantlist__44u1__p7_2,
  132471. NULL,
  132472. &_vq_auxt__44u1__p7_2,
  132473. NULL,
  132474. 0
  132475. };
  132476. static long _huff_lengthlist__44u1__short[] = {
  132477. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132478. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132479. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132480. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132481. };
  132482. static static_codebook _huff_book__44u1__short = {
  132483. 2, 64,
  132484. _huff_lengthlist__44u1__short,
  132485. 0, 0, 0, 0, 0,
  132486. NULL,
  132487. NULL,
  132488. NULL,
  132489. NULL,
  132490. 0
  132491. };
  132492. static long _huff_lengthlist__44u2__long[] = {
  132493. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132494. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132495. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132496. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132497. };
  132498. static static_codebook _huff_book__44u2__long = {
  132499. 2, 64,
  132500. _huff_lengthlist__44u2__long,
  132501. 0, 0, 0, 0, 0,
  132502. NULL,
  132503. NULL,
  132504. NULL,
  132505. NULL,
  132506. 0
  132507. };
  132508. static long _vq_quantlist__44u2__p1_0[] = {
  132509. 1,
  132510. 0,
  132511. 2,
  132512. };
  132513. static long _vq_lengthlist__44u2__p1_0[] = {
  132514. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132515. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132516. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132517. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132518. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132519. 13,
  132520. };
  132521. static float _vq_quantthresh__44u2__p1_0[] = {
  132522. -0.5, 0.5,
  132523. };
  132524. static long _vq_quantmap__44u2__p1_0[] = {
  132525. 1, 0, 2,
  132526. };
  132527. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132528. _vq_quantthresh__44u2__p1_0,
  132529. _vq_quantmap__44u2__p1_0,
  132530. 3,
  132531. 3
  132532. };
  132533. static static_codebook _44u2__p1_0 = {
  132534. 4, 81,
  132535. _vq_lengthlist__44u2__p1_0,
  132536. 1, -535822336, 1611661312, 2, 0,
  132537. _vq_quantlist__44u2__p1_0,
  132538. NULL,
  132539. &_vq_auxt__44u2__p1_0,
  132540. NULL,
  132541. 0
  132542. };
  132543. static long _vq_quantlist__44u2__p2_0[] = {
  132544. 1,
  132545. 0,
  132546. 2,
  132547. };
  132548. static long _vq_lengthlist__44u2__p2_0[] = {
  132549. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132550. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132551. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132552. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132553. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132554. 9,
  132555. };
  132556. static float _vq_quantthresh__44u2__p2_0[] = {
  132557. -0.5, 0.5,
  132558. };
  132559. static long _vq_quantmap__44u2__p2_0[] = {
  132560. 1, 0, 2,
  132561. };
  132562. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132563. _vq_quantthresh__44u2__p2_0,
  132564. _vq_quantmap__44u2__p2_0,
  132565. 3,
  132566. 3
  132567. };
  132568. static static_codebook _44u2__p2_0 = {
  132569. 4, 81,
  132570. _vq_lengthlist__44u2__p2_0,
  132571. 1, -535822336, 1611661312, 2, 0,
  132572. _vq_quantlist__44u2__p2_0,
  132573. NULL,
  132574. &_vq_auxt__44u2__p2_0,
  132575. NULL,
  132576. 0
  132577. };
  132578. static long _vq_quantlist__44u2__p3_0[] = {
  132579. 2,
  132580. 1,
  132581. 3,
  132582. 0,
  132583. 4,
  132584. };
  132585. static long _vq_lengthlist__44u2__p3_0[] = {
  132586. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132587. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132588. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132589. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132590. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132591. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132592. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132593. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132594. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132595. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132596. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132597. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132598. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132599. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132600. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132601. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132602. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132603. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132604. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132605. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132606. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132607. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132608. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132609. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132610. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132611. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132612. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132613. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132614. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132615. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132616. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132617. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132618. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132619. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132620. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132621. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132622. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132623. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132624. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132625. 0,
  132626. };
  132627. static float _vq_quantthresh__44u2__p3_0[] = {
  132628. -1.5, -0.5, 0.5, 1.5,
  132629. };
  132630. static long _vq_quantmap__44u2__p3_0[] = {
  132631. 3, 1, 0, 2, 4,
  132632. };
  132633. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132634. _vq_quantthresh__44u2__p3_0,
  132635. _vq_quantmap__44u2__p3_0,
  132636. 5,
  132637. 5
  132638. };
  132639. static static_codebook _44u2__p3_0 = {
  132640. 4, 625,
  132641. _vq_lengthlist__44u2__p3_0,
  132642. 1, -533725184, 1611661312, 3, 0,
  132643. _vq_quantlist__44u2__p3_0,
  132644. NULL,
  132645. &_vq_auxt__44u2__p3_0,
  132646. NULL,
  132647. 0
  132648. };
  132649. static long _vq_quantlist__44u2__p4_0[] = {
  132650. 2,
  132651. 1,
  132652. 3,
  132653. 0,
  132654. 4,
  132655. };
  132656. static long _vq_lengthlist__44u2__p4_0[] = {
  132657. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132658. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132659. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132660. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132661. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132662. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132663. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132664. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132665. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132666. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132667. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132668. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132669. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132670. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132671. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132672. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132673. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132674. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132675. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132676. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132677. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132678. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132679. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132680. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132681. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132682. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132683. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132684. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132685. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132686. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132687. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132688. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132689. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132690. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132691. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132692. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132693. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132694. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132695. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132696. 13,
  132697. };
  132698. static float _vq_quantthresh__44u2__p4_0[] = {
  132699. -1.5, -0.5, 0.5, 1.5,
  132700. };
  132701. static long _vq_quantmap__44u2__p4_0[] = {
  132702. 3, 1, 0, 2, 4,
  132703. };
  132704. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132705. _vq_quantthresh__44u2__p4_0,
  132706. _vq_quantmap__44u2__p4_0,
  132707. 5,
  132708. 5
  132709. };
  132710. static static_codebook _44u2__p4_0 = {
  132711. 4, 625,
  132712. _vq_lengthlist__44u2__p4_0,
  132713. 1, -533725184, 1611661312, 3, 0,
  132714. _vq_quantlist__44u2__p4_0,
  132715. NULL,
  132716. &_vq_auxt__44u2__p4_0,
  132717. NULL,
  132718. 0
  132719. };
  132720. static long _vq_quantlist__44u2__p5_0[] = {
  132721. 4,
  132722. 3,
  132723. 5,
  132724. 2,
  132725. 6,
  132726. 1,
  132727. 7,
  132728. 0,
  132729. 8,
  132730. };
  132731. static long _vq_lengthlist__44u2__p5_0[] = {
  132732. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132733. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132734. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132735. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132736. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132737. 13,
  132738. };
  132739. static float _vq_quantthresh__44u2__p5_0[] = {
  132740. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132741. };
  132742. static long _vq_quantmap__44u2__p5_0[] = {
  132743. 7, 5, 3, 1, 0, 2, 4, 6,
  132744. 8,
  132745. };
  132746. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132747. _vq_quantthresh__44u2__p5_0,
  132748. _vq_quantmap__44u2__p5_0,
  132749. 9,
  132750. 9
  132751. };
  132752. static static_codebook _44u2__p5_0 = {
  132753. 2, 81,
  132754. _vq_lengthlist__44u2__p5_0,
  132755. 1, -531628032, 1611661312, 4, 0,
  132756. _vq_quantlist__44u2__p5_0,
  132757. NULL,
  132758. &_vq_auxt__44u2__p5_0,
  132759. NULL,
  132760. 0
  132761. };
  132762. static long _vq_quantlist__44u2__p6_0[] = {
  132763. 6,
  132764. 5,
  132765. 7,
  132766. 4,
  132767. 8,
  132768. 3,
  132769. 9,
  132770. 2,
  132771. 10,
  132772. 1,
  132773. 11,
  132774. 0,
  132775. 12,
  132776. };
  132777. static long _vq_lengthlist__44u2__p6_0[] = {
  132778. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132779. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132780. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132781. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132782. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132783. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132784. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132785. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132786. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132787. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132788. 15,17,17,16,18,17,18, 0, 0,
  132789. };
  132790. static float _vq_quantthresh__44u2__p6_0[] = {
  132791. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132792. 12.5, 17.5, 22.5, 27.5,
  132793. };
  132794. static long _vq_quantmap__44u2__p6_0[] = {
  132795. 11, 9, 7, 5, 3, 1, 0, 2,
  132796. 4, 6, 8, 10, 12,
  132797. };
  132798. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132799. _vq_quantthresh__44u2__p6_0,
  132800. _vq_quantmap__44u2__p6_0,
  132801. 13,
  132802. 13
  132803. };
  132804. static static_codebook _44u2__p6_0 = {
  132805. 2, 169,
  132806. _vq_lengthlist__44u2__p6_0,
  132807. 1, -526516224, 1616117760, 4, 0,
  132808. _vq_quantlist__44u2__p6_0,
  132809. NULL,
  132810. &_vq_auxt__44u2__p6_0,
  132811. NULL,
  132812. 0
  132813. };
  132814. static long _vq_quantlist__44u2__p6_1[] = {
  132815. 2,
  132816. 1,
  132817. 3,
  132818. 0,
  132819. 4,
  132820. };
  132821. static long _vq_lengthlist__44u2__p6_1[] = {
  132822. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  132823. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  132824. };
  132825. static float _vq_quantthresh__44u2__p6_1[] = {
  132826. -1.5, -0.5, 0.5, 1.5,
  132827. };
  132828. static long _vq_quantmap__44u2__p6_1[] = {
  132829. 3, 1, 0, 2, 4,
  132830. };
  132831. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  132832. _vq_quantthresh__44u2__p6_1,
  132833. _vq_quantmap__44u2__p6_1,
  132834. 5,
  132835. 5
  132836. };
  132837. static static_codebook _44u2__p6_1 = {
  132838. 2, 25,
  132839. _vq_lengthlist__44u2__p6_1,
  132840. 1, -533725184, 1611661312, 3, 0,
  132841. _vq_quantlist__44u2__p6_1,
  132842. NULL,
  132843. &_vq_auxt__44u2__p6_1,
  132844. NULL,
  132845. 0
  132846. };
  132847. static long _vq_quantlist__44u2__p7_0[] = {
  132848. 4,
  132849. 3,
  132850. 5,
  132851. 2,
  132852. 6,
  132853. 1,
  132854. 7,
  132855. 0,
  132856. 8,
  132857. };
  132858. static long _vq_lengthlist__44u2__p7_0[] = {
  132859. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  132860. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  132861. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132862. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132863. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132864. 11,
  132865. };
  132866. static float _vq_quantthresh__44u2__p7_0[] = {
  132867. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  132868. };
  132869. static long _vq_quantmap__44u2__p7_0[] = {
  132870. 7, 5, 3, 1, 0, 2, 4, 6,
  132871. 8,
  132872. };
  132873. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  132874. _vq_quantthresh__44u2__p7_0,
  132875. _vq_quantmap__44u2__p7_0,
  132876. 9,
  132877. 9
  132878. };
  132879. static static_codebook _44u2__p7_0 = {
  132880. 2, 81,
  132881. _vq_lengthlist__44u2__p7_0,
  132882. 1, -516612096, 1626677248, 4, 0,
  132883. _vq_quantlist__44u2__p7_0,
  132884. NULL,
  132885. &_vq_auxt__44u2__p7_0,
  132886. NULL,
  132887. 0
  132888. };
  132889. static long _vq_quantlist__44u2__p7_1[] = {
  132890. 6,
  132891. 5,
  132892. 7,
  132893. 4,
  132894. 8,
  132895. 3,
  132896. 9,
  132897. 2,
  132898. 10,
  132899. 1,
  132900. 11,
  132901. 0,
  132902. 12,
  132903. };
  132904. static long _vq_lengthlist__44u2__p7_1[] = {
  132905. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  132906. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  132907. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  132908. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  132909. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  132910. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  132911. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  132912. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  132913. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  132914. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  132915. 14,14,14,17,15,17,17,17,17,
  132916. };
  132917. static float _vq_quantthresh__44u2__p7_1[] = {
  132918. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132919. 32.5, 45.5, 58.5, 71.5,
  132920. };
  132921. static long _vq_quantmap__44u2__p7_1[] = {
  132922. 11, 9, 7, 5, 3, 1, 0, 2,
  132923. 4, 6, 8, 10, 12,
  132924. };
  132925. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  132926. _vq_quantthresh__44u2__p7_1,
  132927. _vq_quantmap__44u2__p7_1,
  132928. 13,
  132929. 13
  132930. };
  132931. static static_codebook _44u2__p7_1 = {
  132932. 2, 169,
  132933. _vq_lengthlist__44u2__p7_1,
  132934. 1, -523010048, 1618608128, 4, 0,
  132935. _vq_quantlist__44u2__p7_1,
  132936. NULL,
  132937. &_vq_auxt__44u2__p7_1,
  132938. NULL,
  132939. 0
  132940. };
  132941. static long _vq_quantlist__44u2__p7_2[] = {
  132942. 6,
  132943. 5,
  132944. 7,
  132945. 4,
  132946. 8,
  132947. 3,
  132948. 9,
  132949. 2,
  132950. 10,
  132951. 1,
  132952. 11,
  132953. 0,
  132954. 12,
  132955. };
  132956. static long _vq_lengthlist__44u2__p7_2[] = {
  132957. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  132958. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  132959. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  132960. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132961. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  132962. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  132963. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  132964. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132965. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  132966. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  132967. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132968. };
  132969. static float _vq_quantthresh__44u2__p7_2[] = {
  132970. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132971. 2.5, 3.5, 4.5, 5.5,
  132972. };
  132973. static long _vq_quantmap__44u2__p7_2[] = {
  132974. 11, 9, 7, 5, 3, 1, 0, 2,
  132975. 4, 6, 8, 10, 12,
  132976. };
  132977. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  132978. _vq_quantthresh__44u2__p7_2,
  132979. _vq_quantmap__44u2__p7_2,
  132980. 13,
  132981. 13
  132982. };
  132983. static static_codebook _44u2__p7_2 = {
  132984. 2, 169,
  132985. _vq_lengthlist__44u2__p7_2,
  132986. 1, -531103744, 1611661312, 4, 0,
  132987. _vq_quantlist__44u2__p7_2,
  132988. NULL,
  132989. &_vq_auxt__44u2__p7_2,
  132990. NULL,
  132991. 0
  132992. };
  132993. static long _huff_lengthlist__44u2__short[] = {
  132994. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  132995. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  132996. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  132997. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  132998. };
  132999. static static_codebook _huff_book__44u2__short = {
  133000. 2, 64,
  133001. _huff_lengthlist__44u2__short,
  133002. 0, 0, 0, 0, 0,
  133003. NULL,
  133004. NULL,
  133005. NULL,
  133006. NULL,
  133007. 0
  133008. };
  133009. static long _huff_lengthlist__44u3__long[] = {
  133010. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133011. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133012. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133013. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133014. };
  133015. static static_codebook _huff_book__44u3__long = {
  133016. 2, 64,
  133017. _huff_lengthlist__44u3__long,
  133018. 0, 0, 0, 0, 0,
  133019. NULL,
  133020. NULL,
  133021. NULL,
  133022. NULL,
  133023. 0
  133024. };
  133025. static long _vq_quantlist__44u3__p1_0[] = {
  133026. 1,
  133027. 0,
  133028. 2,
  133029. };
  133030. static long _vq_lengthlist__44u3__p1_0[] = {
  133031. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133032. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133033. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133034. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133035. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133036. 13,
  133037. };
  133038. static float _vq_quantthresh__44u3__p1_0[] = {
  133039. -0.5, 0.5,
  133040. };
  133041. static long _vq_quantmap__44u3__p1_0[] = {
  133042. 1, 0, 2,
  133043. };
  133044. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133045. _vq_quantthresh__44u3__p1_0,
  133046. _vq_quantmap__44u3__p1_0,
  133047. 3,
  133048. 3
  133049. };
  133050. static static_codebook _44u3__p1_0 = {
  133051. 4, 81,
  133052. _vq_lengthlist__44u3__p1_0,
  133053. 1, -535822336, 1611661312, 2, 0,
  133054. _vq_quantlist__44u3__p1_0,
  133055. NULL,
  133056. &_vq_auxt__44u3__p1_0,
  133057. NULL,
  133058. 0
  133059. };
  133060. static long _vq_quantlist__44u3__p2_0[] = {
  133061. 1,
  133062. 0,
  133063. 2,
  133064. };
  133065. static long _vq_lengthlist__44u3__p2_0[] = {
  133066. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133067. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133068. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133069. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133070. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133071. 9,
  133072. };
  133073. static float _vq_quantthresh__44u3__p2_0[] = {
  133074. -0.5, 0.5,
  133075. };
  133076. static long _vq_quantmap__44u3__p2_0[] = {
  133077. 1, 0, 2,
  133078. };
  133079. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133080. _vq_quantthresh__44u3__p2_0,
  133081. _vq_quantmap__44u3__p2_0,
  133082. 3,
  133083. 3
  133084. };
  133085. static static_codebook _44u3__p2_0 = {
  133086. 4, 81,
  133087. _vq_lengthlist__44u3__p2_0,
  133088. 1, -535822336, 1611661312, 2, 0,
  133089. _vq_quantlist__44u3__p2_0,
  133090. NULL,
  133091. &_vq_auxt__44u3__p2_0,
  133092. NULL,
  133093. 0
  133094. };
  133095. static long _vq_quantlist__44u3__p3_0[] = {
  133096. 2,
  133097. 1,
  133098. 3,
  133099. 0,
  133100. 4,
  133101. };
  133102. static long _vq_lengthlist__44u3__p3_0[] = {
  133103. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133104. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133105. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133106. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133107. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133108. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133109. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133110. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133111. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133112. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133113. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133114. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133115. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133116. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133117. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133118. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133119. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133120. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133121. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133122. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133123. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133124. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133125. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133126. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133127. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133128. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133129. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133130. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133131. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133132. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133133. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133134. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133135. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133136. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133137. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133138. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133139. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133140. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133141. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133142. 0,
  133143. };
  133144. static float _vq_quantthresh__44u3__p3_0[] = {
  133145. -1.5, -0.5, 0.5, 1.5,
  133146. };
  133147. static long _vq_quantmap__44u3__p3_0[] = {
  133148. 3, 1, 0, 2, 4,
  133149. };
  133150. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133151. _vq_quantthresh__44u3__p3_0,
  133152. _vq_quantmap__44u3__p3_0,
  133153. 5,
  133154. 5
  133155. };
  133156. static static_codebook _44u3__p3_0 = {
  133157. 4, 625,
  133158. _vq_lengthlist__44u3__p3_0,
  133159. 1, -533725184, 1611661312, 3, 0,
  133160. _vq_quantlist__44u3__p3_0,
  133161. NULL,
  133162. &_vq_auxt__44u3__p3_0,
  133163. NULL,
  133164. 0
  133165. };
  133166. static long _vq_quantlist__44u3__p4_0[] = {
  133167. 2,
  133168. 1,
  133169. 3,
  133170. 0,
  133171. 4,
  133172. };
  133173. static long _vq_lengthlist__44u3__p4_0[] = {
  133174. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133175. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133176. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133177. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133178. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133179. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133180. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133181. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133182. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133183. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133184. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133185. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133186. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133187. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133188. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133189. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133190. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133191. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133192. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133193. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133194. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133195. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133196. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133197. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133198. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133199. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133200. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133201. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133202. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133203. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133204. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133205. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133206. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133207. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133208. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133209. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133210. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133211. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133212. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133213. 13,
  133214. };
  133215. static float _vq_quantthresh__44u3__p4_0[] = {
  133216. -1.5, -0.5, 0.5, 1.5,
  133217. };
  133218. static long _vq_quantmap__44u3__p4_0[] = {
  133219. 3, 1, 0, 2, 4,
  133220. };
  133221. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133222. _vq_quantthresh__44u3__p4_0,
  133223. _vq_quantmap__44u3__p4_0,
  133224. 5,
  133225. 5
  133226. };
  133227. static static_codebook _44u3__p4_0 = {
  133228. 4, 625,
  133229. _vq_lengthlist__44u3__p4_0,
  133230. 1, -533725184, 1611661312, 3, 0,
  133231. _vq_quantlist__44u3__p4_0,
  133232. NULL,
  133233. &_vq_auxt__44u3__p4_0,
  133234. NULL,
  133235. 0
  133236. };
  133237. static long _vq_quantlist__44u3__p5_0[] = {
  133238. 4,
  133239. 3,
  133240. 5,
  133241. 2,
  133242. 6,
  133243. 1,
  133244. 7,
  133245. 0,
  133246. 8,
  133247. };
  133248. static long _vq_lengthlist__44u3__p5_0[] = {
  133249. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133250. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133251. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133252. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133253. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133254. 12,
  133255. };
  133256. static float _vq_quantthresh__44u3__p5_0[] = {
  133257. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133258. };
  133259. static long _vq_quantmap__44u3__p5_0[] = {
  133260. 7, 5, 3, 1, 0, 2, 4, 6,
  133261. 8,
  133262. };
  133263. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133264. _vq_quantthresh__44u3__p5_0,
  133265. _vq_quantmap__44u3__p5_0,
  133266. 9,
  133267. 9
  133268. };
  133269. static static_codebook _44u3__p5_0 = {
  133270. 2, 81,
  133271. _vq_lengthlist__44u3__p5_0,
  133272. 1, -531628032, 1611661312, 4, 0,
  133273. _vq_quantlist__44u3__p5_0,
  133274. NULL,
  133275. &_vq_auxt__44u3__p5_0,
  133276. NULL,
  133277. 0
  133278. };
  133279. static long _vq_quantlist__44u3__p6_0[] = {
  133280. 6,
  133281. 5,
  133282. 7,
  133283. 4,
  133284. 8,
  133285. 3,
  133286. 9,
  133287. 2,
  133288. 10,
  133289. 1,
  133290. 11,
  133291. 0,
  133292. 12,
  133293. };
  133294. static long _vq_lengthlist__44u3__p6_0[] = {
  133295. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133296. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133297. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133298. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133299. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133300. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133301. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133302. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133303. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133304. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133305. 15,16,16,16,17,18,16,20,18,
  133306. };
  133307. static float _vq_quantthresh__44u3__p6_0[] = {
  133308. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133309. 12.5, 17.5, 22.5, 27.5,
  133310. };
  133311. static long _vq_quantmap__44u3__p6_0[] = {
  133312. 11, 9, 7, 5, 3, 1, 0, 2,
  133313. 4, 6, 8, 10, 12,
  133314. };
  133315. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133316. _vq_quantthresh__44u3__p6_0,
  133317. _vq_quantmap__44u3__p6_0,
  133318. 13,
  133319. 13
  133320. };
  133321. static static_codebook _44u3__p6_0 = {
  133322. 2, 169,
  133323. _vq_lengthlist__44u3__p6_0,
  133324. 1, -526516224, 1616117760, 4, 0,
  133325. _vq_quantlist__44u3__p6_0,
  133326. NULL,
  133327. &_vq_auxt__44u3__p6_0,
  133328. NULL,
  133329. 0
  133330. };
  133331. static long _vq_quantlist__44u3__p6_1[] = {
  133332. 2,
  133333. 1,
  133334. 3,
  133335. 0,
  133336. 4,
  133337. };
  133338. static long _vq_lengthlist__44u3__p6_1[] = {
  133339. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133340. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133341. };
  133342. static float _vq_quantthresh__44u3__p6_1[] = {
  133343. -1.5, -0.5, 0.5, 1.5,
  133344. };
  133345. static long _vq_quantmap__44u3__p6_1[] = {
  133346. 3, 1, 0, 2, 4,
  133347. };
  133348. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133349. _vq_quantthresh__44u3__p6_1,
  133350. _vq_quantmap__44u3__p6_1,
  133351. 5,
  133352. 5
  133353. };
  133354. static static_codebook _44u3__p6_1 = {
  133355. 2, 25,
  133356. _vq_lengthlist__44u3__p6_1,
  133357. 1, -533725184, 1611661312, 3, 0,
  133358. _vq_quantlist__44u3__p6_1,
  133359. NULL,
  133360. &_vq_auxt__44u3__p6_1,
  133361. NULL,
  133362. 0
  133363. };
  133364. static long _vq_quantlist__44u3__p7_0[] = {
  133365. 4,
  133366. 3,
  133367. 5,
  133368. 2,
  133369. 6,
  133370. 1,
  133371. 7,
  133372. 0,
  133373. 8,
  133374. };
  133375. static long _vq_lengthlist__44u3__p7_0[] = {
  133376. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133377. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133378. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133379. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133380. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133381. 9,
  133382. };
  133383. static float _vq_quantthresh__44u3__p7_0[] = {
  133384. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133385. };
  133386. static long _vq_quantmap__44u3__p7_0[] = {
  133387. 7, 5, 3, 1, 0, 2, 4, 6,
  133388. 8,
  133389. };
  133390. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133391. _vq_quantthresh__44u3__p7_0,
  133392. _vq_quantmap__44u3__p7_0,
  133393. 9,
  133394. 9
  133395. };
  133396. static static_codebook _44u3__p7_0 = {
  133397. 2, 81,
  133398. _vq_lengthlist__44u3__p7_0,
  133399. 1, -515907584, 1627381760, 4, 0,
  133400. _vq_quantlist__44u3__p7_0,
  133401. NULL,
  133402. &_vq_auxt__44u3__p7_0,
  133403. NULL,
  133404. 0
  133405. };
  133406. static long _vq_quantlist__44u3__p7_1[] = {
  133407. 7,
  133408. 6,
  133409. 8,
  133410. 5,
  133411. 9,
  133412. 4,
  133413. 10,
  133414. 3,
  133415. 11,
  133416. 2,
  133417. 12,
  133418. 1,
  133419. 13,
  133420. 0,
  133421. 14,
  133422. };
  133423. static long _vq_lengthlist__44u3__p7_1[] = {
  133424. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133425. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133426. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133427. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133428. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133429. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133430. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133431. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133432. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133433. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133434. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133435. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133436. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133437. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133438. 17,
  133439. };
  133440. static float _vq_quantthresh__44u3__p7_1[] = {
  133441. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133442. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133443. };
  133444. static long _vq_quantmap__44u3__p7_1[] = {
  133445. 13, 11, 9, 7, 5, 3, 1, 0,
  133446. 2, 4, 6, 8, 10, 12, 14,
  133447. };
  133448. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133449. _vq_quantthresh__44u3__p7_1,
  133450. _vq_quantmap__44u3__p7_1,
  133451. 15,
  133452. 15
  133453. };
  133454. static static_codebook _44u3__p7_1 = {
  133455. 2, 225,
  133456. _vq_lengthlist__44u3__p7_1,
  133457. 1, -522338304, 1620115456, 4, 0,
  133458. _vq_quantlist__44u3__p7_1,
  133459. NULL,
  133460. &_vq_auxt__44u3__p7_1,
  133461. NULL,
  133462. 0
  133463. };
  133464. static long _vq_quantlist__44u3__p7_2[] = {
  133465. 8,
  133466. 7,
  133467. 9,
  133468. 6,
  133469. 10,
  133470. 5,
  133471. 11,
  133472. 4,
  133473. 12,
  133474. 3,
  133475. 13,
  133476. 2,
  133477. 14,
  133478. 1,
  133479. 15,
  133480. 0,
  133481. 16,
  133482. };
  133483. static long _vq_lengthlist__44u3__p7_2[] = {
  133484. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133485. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133486. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133487. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133488. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133489. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133490. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133491. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133492. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133493. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133494. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133495. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133496. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133497. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133498. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133499. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133500. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133501. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133502. 11,
  133503. };
  133504. static float _vq_quantthresh__44u3__p7_2[] = {
  133505. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133506. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133507. };
  133508. static long _vq_quantmap__44u3__p7_2[] = {
  133509. 15, 13, 11, 9, 7, 5, 3, 1,
  133510. 0, 2, 4, 6, 8, 10, 12, 14,
  133511. 16,
  133512. };
  133513. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133514. _vq_quantthresh__44u3__p7_2,
  133515. _vq_quantmap__44u3__p7_2,
  133516. 17,
  133517. 17
  133518. };
  133519. static static_codebook _44u3__p7_2 = {
  133520. 2, 289,
  133521. _vq_lengthlist__44u3__p7_2,
  133522. 1, -529530880, 1611661312, 5, 0,
  133523. _vq_quantlist__44u3__p7_2,
  133524. NULL,
  133525. &_vq_auxt__44u3__p7_2,
  133526. NULL,
  133527. 0
  133528. };
  133529. static long _huff_lengthlist__44u3__short[] = {
  133530. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133531. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133532. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133533. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133534. };
  133535. static static_codebook _huff_book__44u3__short = {
  133536. 2, 64,
  133537. _huff_lengthlist__44u3__short,
  133538. 0, 0, 0, 0, 0,
  133539. NULL,
  133540. NULL,
  133541. NULL,
  133542. NULL,
  133543. 0
  133544. };
  133545. static long _huff_lengthlist__44u4__long[] = {
  133546. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133547. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133548. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133549. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133550. };
  133551. static static_codebook _huff_book__44u4__long = {
  133552. 2, 64,
  133553. _huff_lengthlist__44u4__long,
  133554. 0, 0, 0, 0, 0,
  133555. NULL,
  133556. NULL,
  133557. NULL,
  133558. NULL,
  133559. 0
  133560. };
  133561. static long _vq_quantlist__44u4__p1_0[] = {
  133562. 1,
  133563. 0,
  133564. 2,
  133565. };
  133566. static long _vq_lengthlist__44u4__p1_0[] = {
  133567. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133568. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133569. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133570. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133571. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133572. 13,
  133573. };
  133574. static float _vq_quantthresh__44u4__p1_0[] = {
  133575. -0.5, 0.5,
  133576. };
  133577. static long _vq_quantmap__44u4__p1_0[] = {
  133578. 1, 0, 2,
  133579. };
  133580. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133581. _vq_quantthresh__44u4__p1_0,
  133582. _vq_quantmap__44u4__p1_0,
  133583. 3,
  133584. 3
  133585. };
  133586. static static_codebook _44u4__p1_0 = {
  133587. 4, 81,
  133588. _vq_lengthlist__44u4__p1_0,
  133589. 1, -535822336, 1611661312, 2, 0,
  133590. _vq_quantlist__44u4__p1_0,
  133591. NULL,
  133592. &_vq_auxt__44u4__p1_0,
  133593. NULL,
  133594. 0
  133595. };
  133596. static long _vq_quantlist__44u4__p2_0[] = {
  133597. 1,
  133598. 0,
  133599. 2,
  133600. };
  133601. static long _vq_lengthlist__44u4__p2_0[] = {
  133602. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133603. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133604. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133605. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133606. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133607. 9,
  133608. };
  133609. static float _vq_quantthresh__44u4__p2_0[] = {
  133610. -0.5, 0.5,
  133611. };
  133612. static long _vq_quantmap__44u4__p2_0[] = {
  133613. 1, 0, 2,
  133614. };
  133615. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133616. _vq_quantthresh__44u4__p2_0,
  133617. _vq_quantmap__44u4__p2_0,
  133618. 3,
  133619. 3
  133620. };
  133621. static static_codebook _44u4__p2_0 = {
  133622. 4, 81,
  133623. _vq_lengthlist__44u4__p2_0,
  133624. 1, -535822336, 1611661312, 2, 0,
  133625. _vq_quantlist__44u4__p2_0,
  133626. NULL,
  133627. &_vq_auxt__44u4__p2_0,
  133628. NULL,
  133629. 0
  133630. };
  133631. static long _vq_quantlist__44u4__p3_0[] = {
  133632. 2,
  133633. 1,
  133634. 3,
  133635. 0,
  133636. 4,
  133637. };
  133638. static long _vq_lengthlist__44u4__p3_0[] = {
  133639. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133640. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133641. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133642. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133643. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133644. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133645. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133646. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133647. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133648. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133649. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133650. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133651. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133652. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133653. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133654. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133655. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133656. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133657. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133658. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133659. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133660. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133661. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133662. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133663. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133664. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133665. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133666. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133667. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133668. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133669. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133670. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133671. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133672. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133673. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133674. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133675. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133676. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133677. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133678. 0,
  133679. };
  133680. static float _vq_quantthresh__44u4__p3_0[] = {
  133681. -1.5, -0.5, 0.5, 1.5,
  133682. };
  133683. static long _vq_quantmap__44u4__p3_0[] = {
  133684. 3, 1, 0, 2, 4,
  133685. };
  133686. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133687. _vq_quantthresh__44u4__p3_0,
  133688. _vq_quantmap__44u4__p3_0,
  133689. 5,
  133690. 5
  133691. };
  133692. static static_codebook _44u4__p3_0 = {
  133693. 4, 625,
  133694. _vq_lengthlist__44u4__p3_0,
  133695. 1, -533725184, 1611661312, 3, 0,
  133696. _vq_quantlist__44u4__p3_0,
  133697. NULL,
  133698. &_vq_auxt__44u4__p3_0,
  133699. NULL,
  133700. 0
  133701. };
  133702. static long _vq_quantlist__44u4__p4_0[] = {
  133703. 2,
  133704. 1,
  133705. 3,
  133706. 0,
  133707. 4,
  133708. };
  133709. static long _vq_lengthlist__44u4__p4_0[] = {
  133710. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133711. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133712. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133713. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133714. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133715. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133716. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133717. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133718. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133719. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133720. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133721. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133722. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133723. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133724. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133725. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133726. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133727. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133728. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133729. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133730. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133731. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133732. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133733. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133734. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133735. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133736. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133737. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133738. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133739. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133740. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133741. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133742. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133743. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133744. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133745. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133746. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133747. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133748. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133749. 13,
  133750. };
  133751. static float _vq_quantthresh__44u4__p4_0[] = {
  133752. -1.5, -0.5, 0.5, 1.5,
  133753. };
  133754. static long _vq_quantmap__44u4__p4_0[] = {
  133755. 3, 1, 0, 2, 4,
  133756. };
  133757. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133758. _vq_quantthresh__44u4__p4_0,
  133759. _vq_quantmap__44u4__p4_0,
  133760. 5,
  133761. 5
  133762. };
  133763. static static_codebook _44u4__p4_0 = {
  133764. 4, 625,
  133765. _vq_lengthlist__44u4__p4_0,
  133766. 1, -533725184, 1611661312, 3, 0,
  133767. _vq_quantlist__44u4__p4_0,
  133768. NULL,
  133769. &_vq_auxt__44u4__p4_0,
  133770. NULL,
  133771. 0
  133772. };
  133773. static long _vq_quantlist__44u4__p5_0[] = {
  133774. 4,
  133775. 3,
  133776. 5,
  133777. 2,
  133778. 6,
  133779. 1,
  133780. 7,
  133781. 0,
  133782. 8,
  133783. };
  133784. static long _vq_lengthlist__44u4__p5_0[] = {
  133785. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133786. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133787. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133788. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133789. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133790. 12,
  133791. };
  133792. static float _vq_quantthresh__44u4__p5_0[] = {
  133793. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133794. };
  133795. static long _vq_quantmap__44u4__p5_0[] = {
  133796. 7, 5, 3, 1, 0, 2, 4, 6,
  133797. 8,
  133798. };
  133799. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133800. _vq_quantthresh__44u4__p5_0,
  133801. _vq_quantmap__44u4__p5_0,
  133802. 9,
  133803. 9
  133804. };
  133805. static static_codebook _44u4__p5_0 = {
  133806. 2, 81,
  133807. _vq_lengthlist__44u4__p5_0,
  133808. 1, -531628032, 1611661312, 4, 0,
  133809. _vq_quantlist__44u4__p5_0,
  133810. NULL,
  133811. &_vq_auxt__44u4__p5_0,
  133812. NULL,
  133813. 0
  133814. };
  133815. static long _vq_quantlist__44u4__p6_0[] = {
  133816. 6,
  133817. 5,
  133818. 7,
  133819. 4,
  133820. 8,
  133821. 3,
  133822. 9,
  133823. 2,
  133824. 10,
  133825. 1,
  133826. 11,
  133827. 0,
  133828. 12,
  133829. };
  133830. static long _vq_lengthlist__44u4__p6_0[] = {
  133831. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  133832. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133833. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133834. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133835. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  133836. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  133837. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  133838. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  133839. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  133840. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  133841. 16,16,16,17,17,18,17,20,21,
  133842. };
  133843. static float _vq_quantthresh__44u4__p6_0[] = {
  133844. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133845. 12.5, 17.5, 22.5, 27.5,
  133846. };
  133847. static long _vq_quantmap__44u4__p6_0[] = {
  133848. 11, 9, 7, 5, 3, 1, 0, 2,
  133849. 4, 6, 8, 10, 12,
  133850. };
  133851. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  133852. _vq_quantthresh__44u4__p6_0,
  133853. _vq_quantmap__44u4__p6_0,
  133854. 13,
  133855. 13
  133856. };
  133857. static static_codebook _44u4__p6_0 = {
  133858. 2, 169,
  133859. _vq_lengthlist__44u4__p6_0,
  133860. 1, -526516224, 1616117760, 4, 0,
  133861. _vq_quantlist__44u4__p6_0,
  133862. NULL,
  133863. &_vq_auxt__44u4__p6_0,
  133864. NULL,
  133865. 0
  133866. };
  133867. static long _vq_quantlist__44u4__p6_1[] = {
  133868. 2,
  133869. 1,
  133870. 3,
  133871. 0,
  133872. 4,
  133873. };
  133874. static long _vq_lengthlist__44u4__p6_1[] = {
  133875. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133876. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133877. };
  133878. static float _vq_quantthresh__44u4__p6_1[] = {
  133879. -1.5, -0.5, 0.5, 1.5,
  133880. };
  133881. static long _vq_quantmap__44u4__p6_1[] = {
  133882. 3, 1, 0, 2, 4,
  133883. };
  133884. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  133885. _vq_quantthresh__44u4__p6_1,
  133886. _vq_quantmap__44u4__p6_1,
  133887. 5,
  133888. 5
  133889. };
  133890. static static_codebook _44u4__p6_1 = {
  133891. 2, 25,
  133892. _vq_lengthlist__44u4__p6_1,
  133893. 1, -533725184, 1611661312, 3, 0,
  133894. _vq_quantlist__44u4__p6_1,
  133895. NULL,
  133896. &_vq_auxt__44u4__p6_1,
  133897. NULL,
  133898. 0
  133899. };
  133900. static long _vq_quantlist__44u4__p7_0[] = {
  133901. 6,
  133902. 5,
  133903. 7,
  133904. 4,
  133905. 8,
  133906. 3,
  133907. 9,
  133908. 2,
  133909. 10,
  133910. 1,
  133911. 11,
  133912. 0,
  133913. 12,
  133914. };
  133915. static long _vq_lengthlist__44u4__p7_0[] = {
  133916. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  133917. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  133918. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133919. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133920. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133921. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133922. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133923. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133924. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133925. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133926. 11,11,11,11,11,11,11,11,11,
  133927. };
  133928. static float _vq_quantthresh__44u4__p7_0[] = {
  133929. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  133930. 637.5, 892.5, 1147.5, 1402.5,
  133931. };
  133932. static long _vq_quantmap__44u4__p7_0[] = {
  133933. 11, 9, 7, 5, 3, 1, 0, 2,
  133934. 4, 6, 8, 10, 12,
  133935. };
  133936. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  133937. _vq_quantthresh__44u4__p7_0,
  133938. _vq_quantmap__44u4__p7_0,
  133939. 13,
  133940. 13
  133941. };
  133942. static static_codebook _44u4__p7_0 = {
  133943. 2, 169,
  133944. _vq_lengthlist__44u4__p7_0,
  133945. 1, -514332672, 1627381760, 4, 0,
  133946. _vq_quantlist__44u4__p7_0,
  133947. NULL,
  133948. &_vq_auxt__44u4__p7_0,
  133949. NULL,
  133950. 0
  133951. };
  133952. static long _vq_quantlist__44u4__p7_1[] = {
  133953. 7,
  133954. 6,
  133955. 8,
  133956. 5,
  133957. 9,
  133958. 4,
  133959. 10,
  133960. 3,
  133961. 11,
  133962. 2,
  133963. 12,
  133964. 1,
  133965. 13,
  133966. 0,
  133967. 14,
  133968. };
  133969. static long _vq_lengthlist__44u4__p7_1[] = {
  133970. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  133971. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  133972. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  133973. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  133974. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  133975. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  133976. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  133977. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  133978. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  133979. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  133980. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  133981. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  133982. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  133983. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  133984. 16,
  133985. };
  133986. static float _vq_quantthresh__44u4__p7_1[] = {
  133987. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133988. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133989. };
  133990. static long _vq_quantmap__44u4__p7_1[] = {
  133991. 13, 11, 9, 7, 5, 3, 1, 0,
  133992. 2, 4, 6, 8, 10, 12, 14,
  133993. };
  133994. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  133995. _vq_quantthresh__44u4__p7_1,
  133996. _vq_quantmap__44u4__p7_1,
  133997. 15,
  133998. 15
  133999. };
  134000. static static_codebook _44u4__p7_1 = {
  134001. 2, 225,
  134002. _vq_lengthlist__44u4__p7_1,
  134003. 1, -522338304, 1620115456, 4, 0,
  134004. _vq_quantlist__44u4__p7_1,
  134005. NULL,
  134006. &_vq_auxt__44u4__p7_1,
  134007. NULL,
  134008. 0
  134009. };
  134010. static long _vq_quantlist__44u4__p7_2[] = {
  134011. 8,
  134012. 7,
  134013. 9,
  134014. 6,
  134015. 10,
  134016. 5,
  134017. 11,
  134018. 4,
  134019. 12,
  134020. 3,
  134021. 13,
  134022. 2,
  134023. 14,
  134024. 1,
  134025. 15,
  134026. 0,
  134027. 16,
  134028. };
  134029. static long _vq_lengthlist__44u4__p7_2[] = {
  134030. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134031. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134032. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134033. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134034. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134035. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134036. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134037. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134038. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134039. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134040. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134041. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134042. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134043. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134044. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134045. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134046. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134047. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134048. 10,
  134049. };
  134050. static float _vq_quantthresh__44u4__p7_2[] = {
  134051. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134052. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134053. };
  134054. static long _vq_quantmap__44u4__p7_2[] = {
  134055. 15, 13, 11, 9, 7, 5, 3, 1,
  134056. 0, 2, 4, 6, 8, 10, 12, 14,
  134057. 16,
  134058. };
  134059. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134060. _vq_quantthresh__44u4__p7_2,
  134061. _vq_quantmap__44u4__p7_2,
  134062. 17,
  134063. 17
  134064. };
  134065. static static_codebook _44u4__p7_2 = {
  134066. 2, 289,
  134067. _vq_lengthlist__44u4__p7_2,
  134068. 1, -529530880, 1611661312, 5, 0,
  134069. _vq_quantlist__44u4__p7_2,
  134070. NULL,
  134071. &_vq_auxt__44u4__p7_2,
  134072. NULL,
  134073. 0
  134074. };
  134075. static long _huff_lengthlist__44u4__short[] = {
  134076. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134077. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134078. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134079. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134080. };
  134081. static static_codebook _huff_book__44u4__short = {
  134082. 2, 64,
  134083. _huff_lengthlist__44u4__short,
  134084. 0, 0, 0, 0, 0,
  134085. NULL,
  134086. NULL,
  134087. NULL,
  134088. NULL,
  134089. 0
  134090. };
  134091. static long _huff_lengthlist__44u5__long[] = {
  134092. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134093. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134094. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134095. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134096. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134097. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134098. 14, 8, 7, 8,
  134099. };
  134100. static static_codebook _huff_book__44u5__long = {
  134101. 2, 100,
  134102. _huff_lengthlist__44u5__long,
  134103. 0, 0, 0, 0, 0,
  134104. NULL,
  134105. NULL,
  134106. NULL,
  134107. NULL,
  134108. 0
  134109. };
  134110. static long _vq_quantlist__44u5__p1_0[] = {
  134111. 1,
  134112. 0,
  134113. 2,
  134114. };
  134115. static long _vq_lengthlist__44u5__p1_0[] = {
  134116. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134117. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134118. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134119. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134120. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134121. 12,
  134122. };
  134123. static float _vq_quantthresh__44u5__p1_0[] = {
  134124. -0.5, 0.5,
  134125. };
  134126. static long _vq_quantmap__44u5__p1_0[] = {
  134127. 1, 0, 2,
  134128. };
  134129. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134130. _vq_quantthresh__44u5__p1_0,
  134131. _vq_quantmap__44u5__p1_0,
  134132. 3,
  134133. 3
  134134. };
  134135. static static_codebook _44u5__p1_0 = {
  134136. 4, 81,
  134137. _vq_lengthlist__44u5__p1_0,
  134138. 1, -535822336, 1611661312, 2, 0,
  134139. _vq_quantlist__44u5__p1_0,
  134140. NULL,
  134141. &_vq_auxt__44u5__p1_0,
  134142. NULL,
  134143. 0
  134144. };
  134145. static long _vq_quantlist__44u5__p2_0[] = {
  134146. 1,
  134147. 0,
  134148. 2,
  134149. };
  134150. static long _vq_lengthlist__44u5__p2_0[] = {
  134151. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134152. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134153. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134154. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134155. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134156. 9,
  134157. };
  134158. static float _vq_quantthresh__44u5__p2_0[] = {
  134159. -0.5, 0.5,
  134160. };
  134161. static long _vq_quantmap__44u5__p2_0[] = {
  134162. 1, 0, 2,
  134163. };
  134164. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134165. _vq_quantthresh__44u5__p2_0,
  134166. _vq_quantmap__44u5__p2_0,
  134167. 3,
  134168. 3
  134169. };
  134170. static static_codebook _44u5__p2_0 = {
  134171. 4, 81,
  134172. _vq_lengthlist__44u5__p2_0,
  134173. 1, -535822336, 1611661312, 2, 0,
  134174. _vq_quantlist__44u5__p2_0,
  134175. NULL,
  134176. &_vq_auxt__44u5__p2_0,
  134177. NULL,
  134178. 0
  134179. };
  134180. static long _vq_quantlist__44u5__p3_0[] = {
  134181. 2,
  134182. 1,
  134183. 3,
  134184. 0,
  134185. 4,
  134186. };
  134187. static long _vq_lengthlist__44u5__p3_0[] = {
  134188. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134189. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134190. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134191. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134192. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134193. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134194. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134195. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134196. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134197. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134198. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134199. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134200. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134201. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134202. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134203. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134204. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134205. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134206. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134207. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134208. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134209. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134210. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134211. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134212. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134213. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134214. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134215. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134216. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134217. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134218. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134219. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134220. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134221. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134222. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134223. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134224. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134225. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134226. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134227. 0,
  134228. };
  134229. static float _vq_quantthresh__44u5__p3_0[] = {
  134230. -1.5, -0.5, 0.5, 1.5,
  134231. };
  134232. static long _vq_quantmap__44u5__p3_0[] = {
  134233. 3, 1, 0, 2, 4,
  134234. };
  134235. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134236. _vq_quantthresh__44u5__p3_0,
  134237. _vq_quantmap__44u5__p3_0,
  134238. 5,
  134239. 5
  134240. };
  134241. static static_codebook _44u5__p3_0 = {
  134242. 4, 625,
  134243. _vq_lengthlist__44u5__p3_0,
  134244. 1, -533725184, 1611661312, 3, 0,
  134245. _vq_quantlist__44u5__p3_0,
  134246. NULL,
  134247. &_vq_auxt__44u5__p3_0,
  134248. NULL,
  134249. 0
  134250. };
  134251. static long _vq_quantlist__44u5__p4_0[] = {
  134252. 2,
  134253. 1,
  134254. 3,
  134255. 0,
  134256. 4,
  134257. };
  134258. static long _vq_lengthlist__44u5__p4_0[] = {
  134259. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134260. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134261. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134262. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134263. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134264. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134265. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134266. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134267. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134268. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134269. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134270. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134271. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134272. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134273. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134274. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134275. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134276. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134277. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134278. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134279. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134280. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134281. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134282. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134283. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134284. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134285. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134286. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134287. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134288. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134289. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134290. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134291. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134292. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134293. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134294. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134295. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134296. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134297. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134298. 12,
  134299. };
  134300. static float _vq_quantthresh__44u5__p4_0[] = {
  134301. -1.5, -0.5, 0.5, 1.5,
  134302. };
  134303. static long _vq_quantmap__44u5__p4_0[] = {
  134304. 3, 1, 0, 2, 4,
  134305. };
  134306. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134307. _vq_quantthresh__44u5__p4_0,
  134308. _vq_quantmap__44u5__p4_0,
  134309. 5,
  134310. 5
  134311. };
  134312. static static_codebook _44u5__p4_0 = {
  134313. 4, 625,
  134314. _vq_lengthlist__44u5__p4_0,
  134315. 1, -533725184, 1611661312, 3, 0,
  134316. _vq_quantlist__44u5__p4_0,
  134317. NULL,
  134318. &_vq_auxt__44u5__p4_0,
  134319. NULL,
  134320. 0
  134321. };
  134322. static long _vq_quantlist__44u5__p5_0[] = {
  134323. 4,
  134324. 3,
  134325. 5,
  134326. 2,
  134327. 6,
  134328. 1,
  134329. 7,
  134330. 0,
  134331. 8,
  134332. };
  134333. static long _vq_lengthlist__44u5__p5_0[] = {
  134334. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134335. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134336. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134337. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134338. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134339. 14,
  134340. };
  134341. static float _vq_quantthresh__44u5__p5_0[] = {
  134342. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134343. };
  134344. static long _vq_quantmap__44u5__p5_0[] = {
  134345. 7, 5, 3, 1, 0, 2, 4, 6,
  134346. 8,
  134347. };
  134348. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134349. _vq_quantthresh__44u5__p5_0,
  134350. _vq_quantmap__44u5__p5_0,
  134351. 9,
  134352. 9
  134353. };
  134354. static static_codebook _44u5__p5_0 = {
  134355. 2, 81,
  134356. _vq_lengthlist__44u5__p5_0,
  134357. 1, -531628032, 1611661312, 4, 0,
  134358. _vq_quantlist__44u5__p5_0,
  134359. NULL,
  134360. &_vq_auxt__44u5__p5_0,
  134361. NULL,
  134362. 0
  134363. };
  134364. static long _vq_quantlist__44u5__p6_0[] = {
  134365. 4,
  134366. 3,
  134367. 5,
  134368. 2,
  134369. 6,
  134370. 1,
  134371. 7,
  134372. 0,
  134373. 8,
  134374. };
  134375. static long _vq_lengthlist__44u5__p6_0[] = {
  134376. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134377. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134378. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134379. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134380. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134381. 11,
  134382. };
  134383. static float _vq_quantthresh__44u5__p6_0[] = {
  134384. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134385. };
  134386. static long _vq_quantmap__44u5__p6_0[] = {
  134387. 7, 5, 3, 1, 0, 2, 4, 6,
  134388. 8,
  134389. };
  134390. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134391. _vq_quantthresh__44u5__p6_0,
  134392. _vq_quantmap__44u5__p6_0,
  134393. 9,
  134394. 9
  134395. };
  134396. static static_codebook _44u5__p6_0 = {
  134397. 2, 81,
  134398. _vq_lengthlist__44u5__p6_0,
  134399. 1, -531628032, 1611661312, 4, 0,
  134400. _vq_quantlist__44u5__p6_0,
  134401. NULL,
  134402. &_vq_auxt__44u5__p6_0,
  134403. NULL,
  134404. 0
  134405. };
  134406. static long _vq_quantlist__44u5__p7_0[] = {
  134407. 1,
  134408. 0,
  134409. 2,
  134410. };
  134411. static long _vq_lengthlist__44u5__p7_0[] = {
  134412. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134413. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134414. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134415. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134416. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134417. 12,
  134418. };
  134419. static float _vq_quantthresh__44u5__p7_0[] = {
  134420. -5.5, 5.5,
  134421. };
  134422. static long _vq_quantmap__44u5__p7_0[] = {
  134423. 1, 0, 2,
  134424. };
  134425. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134426. _vq_quantthresh__44u5__p7_0,
  134427. _vq_quantmap__44u5__p7_0,
  134428. 3,
  134429. 3
  134430. };
  134431. static static_codebook _44u5__p7_0 = {
  134432. 4, 81,
  134433. _vq_lengthlist__44u5__p7_0,
  134434. 1, -529137664, 1618345984, 2, 0,
  134435. _vq_quantlist__44u5__p7_0,
  134436. NULL,
  134437. &_vq_auxt__44u5__p7_0,
  134438. NULL,
  134439. 0
  134440. };
  134441. static long _vq_quantlist__44u5__p7_1[] = {
  134442. 5,
  134443. 4,
  134444. 6,
  134445. 3,
  134446. 7,
  134447. 2,
  134448. 8,
  134449. 1,
  134450. 9,
  134451. 0,
  134452. 10,
  134453. };
  134454. static long _vq_lengthlist__44u5__p7_1[] = {
  134455. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134456. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134457. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134458. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134459. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134460. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134461. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134462. 9, 9, 9, 9, 9,10,10,10,10,
  134463. };
  134464. static float _vq_quantthresh__44u5__p7_1[] = {
  134465. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134466. 3.5, 4.5,
  134467. };
  134468. static long _vq_quantmap__44u5__p7_1[] = {
  134469. 9, 7, 5, 3, 1, 0, 2, 4,
  134470. 6, 8, 10,
  134471. };
  134472. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134473. _vq_quantthresh__44u5__p7_1,
  134474. _vq_quantmap__44u5__p7_1,
  134475. 11,
  134476. 11
  134477. };
  134478. static static_codebook _44u5__p7_1 = {
  134479. 2, 121,
  134480. _vq_lengthlist__44u5__p7_1,
  134481. 1, -531365888, 1611661312, 4, 0,
  134482. _vq_quantlist__44u5__p7_1,
  134483. NULL,
  134484. &_vq_auxt__44u5__p7_1,
  134485. NULL,
  134486. 0
  134487. };
  134488. static long _vq_quantlist__44u5__p8_0[] = {
  134489. 5,
  134490. 4,
  134491. 6,
  134492. 3,
  134493. 7,
  134494. 2,
  134495. 8,
  134496. 1,
  134497. 9,
  134498. 0,
  134499. 10,
  134500. };
  134501. static long _vq_lengthlist__44u5__p8_0[] = {
  134502. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134503. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134504. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134505. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134506. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134507. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134508. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134509. 12,13,13,14,14,14,14,15,15,
  134510. };
  134511. static float _vq_quantthresh__44u5__p8_0[] = {
  134512. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134513. 38.5, 49.5,
  134514. };
  134515. static long _vq_quantmap__44u5__p8_0[] = {
  134516. 9, 7, 5, 3, 1, 0, 2, 4,
  134517. 6, 8, 10,
  134518. };
  134519. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134520. _vq_quantthresh__44u5__p8_0,
  134521. _vq_quantmap__44u5__p8_0,
  134522. 11,
  134523. 11
  134524. };
  134525. static static_codebook _44u5__p8_0 = {
  134526. 2, 121,
  134527. _vq_lengthlist__44u5__p8_0,
  134528. 1, -524582912, 1618345984, 4, 0,
  134529. _vq_quantlist__44u5__p8_0,
  134530. NULL,
  134531. &_vq_auxt__44u5__p8_0,
  134532. NULL,
  134533. 0
  134534. };
  134535. static long _vq_quantlist__44u5__p8_1[] = {
  134536. 5,
  134537. 4,
  134538. 6,
  134539. 3,
  134540. 7,
  134541. 2,
  134542. 8,
  134543. 1,
  134544. 9,
  134545. 0,
  134546. 10,
  134547. };
  134548. static long _vq_lengthlist__44u5__p8_1[] = {
  134549. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134550. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134551. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134552. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134553. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134554. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134555. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134556. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134557. };
  134558. static float _vq_quantthresh__44u5__p8_1[] = {
  134559. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134560. 3.5, 4.5,
  134561. };
  134562. static long _vq_quantmap__44u5__p8_1[] = {
  134563. 9, 7, 5, 3, 1, 0, 2, 4,
  134564. 6, 8, 10,
  134565. };
  134566. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134567. _vq_quantthresh__44u5__p8_1,
  134568. _vq_quantmap__44u5__p8_1,
  134569. 11,
  134570. 11
  134571. };
  134572. static static_codebook _44u5__p8_1 = {
  134573. 2, 121,
  134574. _vq_lengthlist__44u5__p8_1,
  134575. 1, -531365888, 1611661312, 4, 0,
  134576. _vq_quantlist__44u5__p8_1,
  134577. NULL,
  134578. &_vq_auxt__44u5__p8_1,
  134579. NULL,
  134580. 0
  134581. };
  134582. static long _vq_quantlist__44u5__p9_0[] = {
  134583. 6,
  134584. 5,
  134585. 7,
  134586. 4,
  134587. 8,
  134588. 3,
  134589. 9,
  134590. 2,
  134591. 10,
  134592. 1,
  134593. 11,
  134594. 0,
  134595. 12,
  134596. };
  134597. static long _vq_lengthlist__44u5__p9_0[] = {
  134598. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134599. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134600. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134601. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134602. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134603. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134604. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134605. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134606. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134607. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134608. 12,12,12,12,12,12,12,12,12,
  134609. };
  134610. static float _vq_quantthresh__44u5__p9_0[] = {
  134611. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134612. 637.5, 892.5, 1147.5, 1402.5,
  134613. };
  134614. static long _vq_quantmap__44u5__p9_0[] = {
  134615. 11, 9, 7, 5, 3, 1, 0, 2,
  134616. 4, 6, 8, 10, 12,
  134617. };
  134618. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134619. _vq_quantthresh__44u5__p9_0,
  134620. _vq_quantmap__44u5__p9_0,
  134621. 13,
  134622. 13
  134623. };
  134624. static static_codebook _44u5__p9_0 = {
  134625. 2, 169,
  134626. _vq_lengthlist__44u5__p9_0,
  134627. 1, -514332672, 1627381760, 4, 0,
  134628. _vq_quantlist__44u5__p9_0,
  134629. NULL,
  134630. &_vq_auxt__44u5__p9_0,
  134631. NULL,
  134632. 0
  134633. };
  134634. static long _vq_quantlist__44u5__p9_1[] = {
  134635. 7,
  134636. 6,
  134637. 8,
  134638. 5,
  134639. 9,
  134640. 4,
  134641. 10,
  134642. 3,
  134643. 11,
  134644. 2,
  134645. 12,
  134646. 1,
  134647. 13,
  134648. 0,
  134649. 14,
  134650. };
  134651. static long _vq_lengthlist__44u5__p9_1[] = {
  134652. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134653. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134654. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134655. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134656. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134657. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134658. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134659. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134660. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134661. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134662. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134663. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134664. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134665. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134666. 14,
  134667. };
  134668. static float _vq_quantthresh__44u5__p9_1[] = {
  134669. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134670. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134671. };
  134672. static long _vq_quantmap__44u5__p9_1[] = {
  134673. 13, 11, 9, 7, 5, 3, 1, 0,
  134674. 2, 4, 6, 8, 10, 12, 14,
  134675. };
  134676. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134677. _vq_quantthresh__44u5__p9_1,
  134678. _vq_quantmap__44u5__p9_1,
  134679. 15,
  134680. 15
  134681. };
  134682. static static_codebook _44u5__p9_1 = {
  134683. 2, 225,
  134684. _vq_lengthlist__44u5__p9_1,
  134685. 1, -522338304, 1620115456, 4, 0,
  134686. _vq_quantlist__44u5__p9_1,
  134687. NULL,
  134688. &_vq_auxt__44u5__p9_1,
  134689. NULL,
  134690. 0
  134691. };
  134692. static long _vq_quantlist__44u5__p9_2[] = {
  134693. 8,
  134694. 7,
  134695. 9,
  134696. 6,
  134697. 10,
  134698. 5,
  134699. 11,
  134700. 4,
  134701. 12,
  134702. 3,
  134703. 13,
  134704. 2,
  134705. 14,
  134706. 1,
  134707. 15,
  134708. 0,
  134709. 16,
  134710. };
  134711. static long _vq_lengthlist__44u5__p9_2[] = {
  134712. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134713. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134714. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134715. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134716. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134717. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134718. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134719. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134720. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134721. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134722. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134723. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134724. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134725. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134726. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134727. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134728. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134729. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134730. 10,
  134731. };
  134732. static float _vq_quantthresh__44u5__p9_2[] = {
  134733. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134734. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134735. };
  134736. static long _vq_quantmap__44u5__p9_2[] = {
  134737. 15, 13, 11, 9, 7, 5, 3, 1,
  134738. 0, 2, 4, 6, 8, 10, 12, 14,
  134739. 16,
  134740. };
  134741. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134742. _vq_quantthresh__44u5__p9_2,
  134743. _vq_quantmap__44u5__p9_2,
  134744. 17,
  134745. 17
  134746. };
  134747. static static_codebook _44u5__p9_2 = {
  134748. 2, 289,
  134749. _vq_lengthlist__44u5__p9_2,
  134750. 1, -529530880, 1611661312, 5, 0,
  134751. _vq_quantlist__44u5__p9_2,
  134752. NULL,
  134753. &_vq_auxt__44u5__p9_2,
  134754. NULL,
  134755. 0
  134756. };
  134757. static long _huff_lengthlist__44u5__short[] = {
  134758. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134759. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134760. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134761. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134762. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134763. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134764. 6, 8,15,17,
  134765. };
  134766. static static_codebook _huff_book__44u5__short = {
  134767. 2, 100,
  134768. _huff_lengthlist__44u5__short,
  134769. 0, 0, 0, 0, 0,
  134770. NULL,
  134771. NULL,
  134772. NULL,
  134773. NULL,
  134774. 0
  134775. };
  134776. static long _huff_lengthlist__44u6__long[] = {
  134777. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134778. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134779. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134780. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134781. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134782. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134783. 13, 8, 7, 7,
  134784. };
  134785. static static_codebook _huff_book__44u6__long = {
  134786. 2, 100,
  134787. _huff_lengthlist__44u6__long,
  134788. 0, 0, 0, 0, 0,
  134789. NULL,
  134790. NULL,
  134791. NULL,
  134792. NULL,
  134793. 0
  134794. };
  134795. static long _vq_quantlist__44u6__p1_0[] = {
  134796. 1,
  134797. 0,
  134798. 2,
  134799. };
  134800. static long _vq_lengthlist__44u6__p1_0[] = {
  134801. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134802. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134803. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134804. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134805. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134806. 12,
  134807. };
  134808. static float _vq_quantthresh__44u6__p1_0[] = {
  134809. -0.5, 0.5,
  134810. };
  134811. static long _vq_quantmap__44u6__p1_0[] = {
  134812. 1, 0, 2,
  134813. };
  134814. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  134815. _vq_quantthresh__44u6__p1_0,
  134816. _vq_quantmap__44u6__p1_0,
  134817. 3,
  134818. 3
  134819. };
  134820. static static_codebook _44u6__p1_0 = {
  134821. 4, 81,
  134822. _vq_lengthlist__44u6__p1_0,
  134823. 1, -535822336, 1611661312, 2, 0,
  134824. _vq_quantlist__44u6__p1_0,
  134825. NULL,
  134826. &_vq_auxt__44u6__p1_0,
  134827. NULL,
  134828. 0
  134829. };
  134830. static long _vq_quantlist__44u6__p2_0[] = {
  134831. 1,
  134832. 0,
  134833. 2,
  134834. };
  134835. static long _vq_lengthlist__44u6__p2_0[] = {
  134836. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134837. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134838. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  134839. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134840. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134841. 9,
  134842. };
  134843. static float _vq_quantthresh__44u6__p2_0[] = {
  134844. -0.5, 0.5,
  134845. };
  134846. static long _vq_quantmap__44u6__p2_0[] = {
  134847. 1, 0, 2,
  134848. };
  134849. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  134850. _vq_quantthresh__44u6__p2_0,
  134851. _vq_quantmap__44u6__p2_0,
  134852. 3,
  134853. 3
  134854. };
  134855. static static_codebook _44u6__p2_0 = {
  134856. 4, 81,
  134857. _vq_lengthlist__44u6__p2_0,
  134858. 1, -535822336, 1611661312, 2, 0,
  134859. _vq_quantlist__44u6__p2_0,
  134860. NULL,
  134861. &_vq_auxt__44u6__p2_0,
  134862. NULL,
  134863. 0
  134864. };
  134865. static long _vq_quantlist__44u6__p3_0[] = {
  134866. 2,
  134867. 1,
  134868. 3,
  134869. 0,
  134870. 4,
  134871. };
  134872. static long _vq_lengthlist__44u6__p3_0[] = {
  134873. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134874. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  134875. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134876. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  134877. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  134878. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  134879. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  134880. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  134881. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  134882. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134883. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  134884. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134885. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  134886. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  134887. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  134888. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  134889. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134890. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  134891. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  134892. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  134893. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  134894. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  134895. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  134896. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  134897. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  134898. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  134899. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  134900. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  134901. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  134902. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  134903. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  134904. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  134905. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  134906. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  134907. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  134908. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  134909. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  134910. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  134911. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  134912. 19,
  134913. };
  134914. static float _vq_quantthresh__44u6__p3_0[] = {
  134915. -1.5, -0.5, 0.5, 1.5,
  134916. };
  134917. static long _vq_quantmap__44u6__p3_0[] = {
  134918. 3, 1, 0, 2, 4,
  134919. };
  134920. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  134921. _vq_quantthresh__44u6__p3_0,
  134922. _vq_quantmap__44u6__p3_0,
  134923. 5,
  134924. 5
  134925. };
  134926. static static_codebook _44u6__p3_0 = {
  134927. 4, 625,
  134928. _vq_lengthlist__44u6__p3_0,
  134929. 1, -533725184, 1611661312, 3, 0,
  134930. _vq_quantlist__44u6__p3_0,
  134931. NULL,
  134932. &_vq_auxt__44u6__p3_0,
  134933. NULL,
  134934. 0
  134935. };
  134936. static long _vq_quantlist__44u6__p4_0[] = {
  134937. 2,
  134938. 1,
  134939. 3,
  134940. 0,
  134941. 4,
  134942. };
  134943. static long _vq_lengthlist__44u6__p4_0[] = {
  134944. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134945. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134946. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  134947. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  134948. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  134949. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  134950. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  134951. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  134952. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  134953. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  134954. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  134955. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  134956. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134957. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  134958. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  134959. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  134960. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  134961. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  134962. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134963. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  134964. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  134965. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  134966. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  134967. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  134968. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  134969. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  134970. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  134971. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  134972. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  134973. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  134974. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  134975. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  134976. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  134977. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  134978. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  134979. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  134980. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  134981. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  134982. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  134983. 13,
  134984. };
  134985. static float _vq_quantthresh__44u6__p4_0[] = {
  134986. -1.5, -0.5, 0.5, 1.5,
  134987. };
  134988. static long _vq_quantmap__44u6__p4_0[] = {
  134989. 3, 1, 0, 2, 4,
  134990. };
  134991. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  134992. _vq_quantthresh__44u6__p4_0,
  134993. _vq_quantmap__44u6__p4_0,
  134994. 5,
  134995. 5
  134996. };
  134997. static static_codebook _44u6__p4_0 = {
  134998. 4, 625,
  134999. _vq_lengthlist__44u6__p4_0,
  135000. 1, -533725184, 1611661312, 3, 0,
  135001. _vq_quantlist__44u6__p4_0,
  135002. NULL,
  135003. &_vq_auxt__44u6__p4_0,
  135004. NULL,
  135005. 0
  135006. };
  135007. static long _vq_quantlist__44u6__p5_0[] = {
  135008. 4,
  135009. 3,
  135010. 5,
  135011. 2,
  135012. 6,
  135013. 1,
  135014. 7,
  135015. 0,
  135016. 8,
  135017. };
  135018. static long _vq_lengthlist__44u6__p5_0[] = {
  135019. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135020. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135021. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135022. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135023. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135024. 14,
  135025. };
  135026. static float _vq_quantthresh__44u6__p5_0[] = {
  135027. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135028. };
  135029. static long _vq_quantmap__44u6__p5_0[] = {
  135030. 7, 5, 3, 1, 0, 2, 4, 6,
  135031. 8,
  135032. };
  135033. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135034. _vq_quantthresh__44u6__p5_0,
  135035. _vq_quantmap__44u6__p5_0,
  135036. 9,
  135037. 9
  135038. };
  135039. static static_codebook _44u6__p5_0 = {
  135040. 2, 81,
  135041. _vq_lengthlist__44u6__p5_0,
  135042. 1, -531628032, 1611661312, 4, 0,
  135043. _vq_quantlist__44u6__p5_0,
  135044. NULL,
  135045. &_vq_auxt__44u6__p5_0,
  135046. NULL,
  135047. 0
  135048. };
  135049. static long _vq_quantlist__44u6__p6_0[] = {
  135050. 4,
  135051. 3,
  135052. 5,
  135053. 2,
  135054. 6,
  135055. 1,
  135056. 7,
  135057. 0,
  135058. 8,
  135059. };
  135060. static long _vq_lengthlist__44u6__p6_0[] = {
  135061. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135062. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135063. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135064. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135065. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135066. 12,
  135067. };
  135068. static float _vq_quantthresh__44u6__p6_0[] = {
  135069. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135070. };
  135071. static long _vq_quantmap__44u6__p6_0[] = {
  135072. 7, 5, 3, 1, 0, 2, 4, 6,
  135073. 8,
  135074. };
  135075. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135076. _vq_quantthresh__44u6__p6_0,
  135077. _vq_quantmap__44u6__p6_0,
  135078. 9,
  135079. 9
  135080. };
  135081. static static_codebook _44u6__p6_0 = {
  135082. 2, 81,
  135083. _vq_lengthlist__44u6__p6_0,
  135084. 1, -531628032, 1611661312, 4, 0,
  135085. _vq_quantlist__44u6__p6_0,
  135086. NULL,
  135087. &_vq_auxt__44u6__p6_0,
  135088. NULL,
  135089. 0
  135090. };
  135091. static long _vq_quantlist__44u6__p7_0[] = {
  135092. 1,
  135093. 0,
  135094. 2,
  135095. };
  135096. static long _vq_lengthlist__44u6__p7_0[] = {
  135097. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135098. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135099. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135100. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135101. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135102. 10,
  135103. };
  135104. static float _vq_quantthresh__44u6__p7_0[] = {
  135105. -5.5, 5.5,
  135106. };
  135107. static long _vq_quantmap__44u6__p7_0[] = {
  135108. 1, 0, 2,
  135109. };
  135110. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135111. _vq_quantthresh__44u6__p7_0,
  135112. _vq_quantmap__44u6__p7_0,
  135113. 3,
  135114. 3
  135115. };
  135116. static static_codebook _44u6__p7_0 = {
  135117. 4, 81,
  135118. _vq_lengthlist__44u6__p7_0,
  135119. 1, -529137664, 1618345984, 2, 0,
  135120. _vq_quantlist__44u6__p7_0,
  135121. NULL,
  135122. &_vq_auxt__44u6__p7_0,
  135123. NULL,
  135124. 0
  135125. };
  135126. static long _vq_quantlist__44u6__p7_1[] = {
  135127. 5,
  135128. 4,
  135129. 6,
  135130. 3,
  135131. 7,
  135132. 2,
  135133. 8,
  135134. 1,
  135135. 9,
  135136. 0,
  135137. 10,
  135138. };
  135139. static long _vq_lengthlist__44u6__p7_1[] = {
  135140. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135141. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135142. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135143. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135144. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135145. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135146. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135147. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135148. };
  135149. static float _vq_quantthresh__44u6__p7_1[] = {
  135150. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135151. 3.5, 4.5,
  135152. };
  135153. static long _vq_quantmap__44u6__p7_1[] = {
  135154. 9, 7, 5, 3, 1, 0, 2, 4,
  135155. 6, 8, 10,
  135156. };
  135157. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135158. _vq_quantthresh__44u6__p7_1,
  135159. _vq_quantmap__44u6__p7_1,
  135160. 11,
  135161. 11
  135162. };
  135163. static static_codebook _44u6__p7_1 = {
  135164. 2, 121,
  135165. _vq_lengthlist__44u6__p7_1,
  135166. 1, -531365888, 1611661312, 4, 0,
  135167. _vq_quantlist__44u6__p7_1,
  135168. NULL,
  135169. &_vq_auxt__44u6__p7_1,
  135170. NULL,
  135171. 0
  135172. };
  135173. static long _vq_quantlist__44u6__p8_0[] = {
  135174. 5,
  135175. 4,
  135176. 6,
  135177. 3,
  135178. 7,
  135179. 2,
  135180. 8,
  135181. 1,
  135182. 9,
  135183. 0,
  135184. 10,
  135185. };
  135186. static long _vq_lengthlist__44u6__p8_0[] = {
  135187. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135188. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135189. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135190. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135191. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135192. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135193. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135194. 12,13,13,14,14,14,15,15,15,
  135195. };
  135196. static float _vq_quantthresh__44u6__p8_0[] = {
  135197. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135198. 38.5, 49.5,
  135199. };
  135200. static long _vq_quantmap__44u6__p8_0[] = {
  135201. 9, 7, 5, 3, 1, 0, 2, 4,
  135202. 6, 8, 10,
  135203. };
  135204. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135205. _vq_quantthresh__44u6__p8_0,
  135206. _vq_quantmap__44u6__p8_0,
  135207. 11,
  135208. 11
  135209. };
  135210. static static_codebook _44u6__p8_0 = {
  135211. 2, 121,
  135212. _vq_lengthlist__44u6__p8_0,
  135213. 1, -524582912, 1618345984, 4, 0,
  135214. _vq_quantlist__44u6__p8_0,
  135215. NULL,
  135216. &_vq_auxt__44u6__p8_0,
  135217. NULL,
  135218. 0
  135219. };
  135220. static long _vq_quantlist__44u6__p8_1[] = {
  135221. 5,
  135222. 4,
  135223. 6,
  135224. 3,
  135225. 7,
  135226. 2,
  135227. 8,
  135228. 1,
  135229. 9,
  135230. 0,
  135231. 10,
  135232. };
  135233. static long _vq_lengthlist__44u6__p8_1[] = {
  135234. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135235. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135236. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135237. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135238. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135239. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135240. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135241. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135242. };
  135243. static float _vq_quantthresh__44u6__p8_1[] = {
  135244. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135245. 3.5, 4.5,
  135246. };
  135247. static long _vq_quantmap__44u6__p8_1[] = {
  135248. 9, 7, 5, 3, 1, 0, 2, 4,
  135249. 6, 8, 10,
  135250. };
  135251. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135252. _vq_quantthresh__44u6__p8_1,
  135253. _vq_quantmap__44u6__p8_1,
  135254. 11,
  135255. 11
  135256. };
  135257. static static_codebook _44u6__p8_1 = {
  135258. 2, 121,
  135259. _vq_lengthlist__44u6__p8_1,
  135260. 1, -531365888, 1611661312, 4, 0,
  135261. _vq_quantlist__44u6__p8_1,
  135262. NULL,
  135263. &_vq_auxt__44u6__p8_1,
  135264. NULL,
  135265. 0
  135266. };
  135267. static long _vq_quantlist__44u6__p9_0[] = {
  135268. 7,
  135269. 6,
  135270. 8,
  135271. 5,
  135272. 9,
  135273. 4,
  135274. 10,
  135275. 3,
  135276. 11,
  135277. 2,
  135278. 12,
  135279. 1,
  135280. 13,
  135281. 0,
  135282. 14,
  135283. };
  135284. static long _vq_lengthlist__44u6__p9_0[] = {
  135285. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135286. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135287. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135288. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135289. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135290. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135291. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135292. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135293. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135294. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135295. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135296. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135297. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135298. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135299. 14,
  135300. };
  135301. static float _vq_quantthresh__44u6__p9_0[] = {
  135302. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135303. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135304. };
  135305. static long _vq_quantmap__44u6__p9_0[] = {
  135306. 13, 11, 9, 7, 5, 3, 1, 0,
  135307. 2, 4, 6, 8, 10, 12, 14,
  135308. };
  135309. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135310. _vq_quantthresh__44u6__p9_0,
  135311. _vq_quantmap__44u6__p9_0,
  135312. 15,
  135313. 15
  135314. };
  135315. static static_codebook _44u6__p9_0 = {
  135316. 2, 225,
  135317. _vq_lengthlist__44u6__p9_0,
  135318. 1, -514071552, 1627381760, 4, 0,
  135319. _vq_quantlist__44u6__p9_0,
  135320. NULL,
  135321. &_vq_auxt__44u6__p9_0,
  135322. NULL,
  135323. 0
  135324. };
  135325. static long _vq_quantlist__44u6__p9_1[] = {
  135326. 7,
  135327. 6,
  135328. 8,
  135329. 5,
  135330. 9,
  135331. 4,
  135332. 10,
  135333. 3,
  135334. 11,
  135335. 2,
  135336. 12,
  135337. 1,
  135338. 13,
  135339. 0,
  135340. 14,
  135341. };
  135342. static long _vq_lengthlist__44u6__p9_1[] = {
  135343. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135344. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135345. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135346. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135347. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135348. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135349. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135350. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135351. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135352. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135353. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135354. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135355. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135356. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135357. 13,
  135358. };
  135359. static float _vq_quantthresh__44u6__p9_1[] = {
  135360. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135361. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135362. };
  135363. static long _vq_quantmap__44u6__p9_1[] = {
  135364. 13, 11, 9, 7, 5, 3, 1, 0,
  135365. 2, 4, 6, 8, 10, 12, 14,
  135366. };
  135367. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135368. _vq_quantthresh__44u6__p9_1,
  135369. _vq_quantmap__44u6__p9_1,
  135370. 15,
  135371. 15
  135372. };
  135373. static static_codebook _44u6__p9_1 = {
  135374. 2, 225,
  135375. _vq_lengthlist__44u6__p9_1,
  135376. 1, -522338304, 1620115456, 4, 0,
  135377. _vq_quantlist__44u6__p9_1,
  135378. NULL,
  135379. &_vq_auxt__44u6__p9_1,
  135380. NULL,
  135381. 0
  135382. };
  135383. static long _vq_quantlist__44u6__p9_2[] = {
  135384. 8,
  135385. 7,
  135386. 9,
  135387. 6,
  135388. 10,
  135389. 5,
  135390. 11,
  135391. 4,
  135392. 12,
  135393. 3,
  135394. 13,
  135395. 2,
  135396. 14,
  135397. 1,
  135398. 15,
  135399. 0,
  135400. 16,
  135401. };
  135402. static long _vq_lengthlist__44u6__p9_2[] = {
  135403. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135404. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135405. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135406. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135407. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135408. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135409. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135410. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135411. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135412. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135413. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135414. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135415. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135416. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135417. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135418. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135419. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135420. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135421. 10,
  135422. };
  135423. static float _vq_quantthresh__44u6__p9_2[] = {
  135424. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135425. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135426. };
  135427. static long _vq_quantmap__44u6__p9_2[] = {
  135428. 15, 13, 11, 9, 7, 5, 3, 1,
  135429. 0, 2, 4, 6, 8, 10, 12, 14,
  135430. 16,
  135431. };
  135432. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135433. _vq_quantthresh__44u6__p9_2,
  135434. _vq_quantmap__44u6__p9_2,
  135435. 17,
  135436. 17
  135437. };
  135438. static static_codebook _44u6__p9_2 = {
  135439. 2, 289,
  135440. _vq_lengthlist__44u6__p9_2,
  135441. 1, -529530880, 1611661312, 5, 0,
  135442. _vq_quantlist__44u6__p9_2,
  135443. NULL,
  135444. &_vq_auxt__44u6__p9_2,
  135445. NULL,
  135446. 0
  135447. };
  135448. static long _huff_lengthlist__44u6__short[] = {
  135449. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135450. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135451. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135452. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135453. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135454. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135455. 7, 6, 9,16,
  135456. };
  135457. static static_codebook _huff_book__44u6__short = {
  135458. 2, 100,
  135459. _huff_lengthlist__44u6__short,
  135460. 0, 0, 0, 0, 0,
  135461. NULL,
  135462. NULL,
  135463. NULL,
  135464. NULL,
  135465. 0
  135466. };
  135467. static long _huff_lengthlist__44u7__long[] = {
  135468. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135469. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135470. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135471. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135472. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135473. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135474. 12, 8, 6, 7,
  135475. };
  135476. static static_codebook _huff_book__44u7__long = {
  135477. 2, 100,
  135478. _huff_lengthlist__44u7__long,
  135479. 0, 0, 0, 0, 0,
  135480. NULL,
  135481. NULL,
  135482. NULL,
  135483. NULL,
  135484. 0
  135485. };
  135486. static long _vq_quantlist__44u7__p1_0[] = {
  135487. 1,
  135488. 0,
  135489. 2,
  135490. };
  135491. static long _vq_lengthlist__44u7__p1_0[] = {
  135492. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135493. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135494. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135495. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135496. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135497. 12,
  135498. };
  135499. static float _vq_quantthresh__44u7__p1_0[] = {
  135500. -0.5, 0.5,
  135501. };
  135502. static long _vq_quantmap__44u7__p1_0[] = {
  135503. 1, 0, 2,
  135504. };
  135505. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135506. _vq_quantthresh__44u7__p1_0,
  135507. _vq_quantmap__44u7__p1_0,
  135508. 3,
  135509. 3
  135510. };
  135511. static static_codebook _44u7__p1_0 = {
  135512. 4, 81,
  135513. _vq_lengthlist__44u7__p1_0,
  135514. 1, -535822336, 1611661312, 2, 0,
  135515. _vq_quantlist__44u7__p1_0,
  135516. NULL,
  135517. &_vq_auxt__44u7__p1_0,
  135518. NULL,
  135519. 0
  135520. };
  135521. static long _vq_quantlist__44u7__p2_0[] = {
  135522. 1,
  135523. 0,
  135524. 2,
  135525. };
  135526. static long _vq_lengthlist__44u7__p2_0[] = {
  135527. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135528. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135529. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135530. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135531. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135532. 9,
  135533. };
  135534. static float _vq_quantthresh__44u7__p2_0[] = {
  135535. -0.5, 0.5,
  135536. };
  135537. static long _vq_quantmap__44u7__p2_0[] = {
  135538. 1, 0, 2,
  135539. };
  135540. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135541. _vq_quantthresh__44u7__p2_0,
  135542. _vq_quantmap__44u7__p2_0,
  135543. 3,
  135544. 3
  135545. };
  135546. static static_codebook _44u7__p2_0 = {
  135547. 4, 81,
  135548. _vq_lengthlist__44u7__p2_0,
  135549. 1, -535822336, 1611661312, 2, 0,
  135550. _vq_quantlist__44u7__p2_0,
  135551. NULL,
  135552. &_vq_auxt__44u7__p2_0,
  135553. NULL,
  135554. 0
  135555. };
  135556. static long _vq_quantlist__44u7__p3_0[] = {
  135557. 2,
  135558. 1,
  135559. 3,
  135560. 0,
  135561. 4,
  135562. };
  135563. static long _vq_lengthlist__44u7__p3_0[] = {
  135564. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135565. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135566. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135567. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135568. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135569. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135570. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135571. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135572. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135573. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135574. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135575. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135576. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135577. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135578. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135579. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135580. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135581. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135582. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135583. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135584. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135585. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135586. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135587. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135588. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135589. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135590. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135591. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135592. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135593. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135594. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135595. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135596. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135597. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135598. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135599. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135600. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135601. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135602. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135603. 0,
  135604. };
  135605. static float _vq_quantthresh__44u7__p3_0[] = {
  135606. -1.5, -0.5, 0.5, 1.5,
  135607. };
  135608. static long _vq_quantmap__44u7__p3_0[] = {
  135609. 3, 1, 0, 2, 4,
  135610. };
  135611. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135612. _vq_quantthresh__44u7__p3_0,
  135613. _vq_quantmap__44u7__p3_0,
  135614. 5,
  135615. 5
  135616. };
  135617. static static_codebook _44u7__p3_0 = {
  135618. 4, 625,
  135619. _vq_lengthlist__44u7__p3_0,
  135620. 1, -533725184, 1611661312, 3, 0,
  135621. _vq_quantlist__44u7__p3_0,
  135622. NULL,
  135623. &_vq_auxt__44u7__p3_0,
  135624. NULL,
  135625. 0
  135626. };
  135627. static long _vq_quantlist__44u7__p4_0[] = {
  135628. 2,
  135629. 1,
  135630. 3,
  135631. 0,
  135632. 4,
  135633. };
  135634. static long _vq_lengthlist__44u7__p4_0[] = {
  135635. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135636. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135637. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135638. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135639. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135640. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135641. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135642. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135643. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135644. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135645. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135646. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135647. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135648. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135649. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135650. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135651. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135652. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135653. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135654. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135655. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135656. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135657. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135658. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135659. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135660. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135661. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135662. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135663. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135664. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135665. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135666. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135667. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135668. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135669. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135670. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135671. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135672. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135673. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135674. 14,
  135675. };
  135676. static float _vq_quantthresh__44u7__p4_0[] = {
  135677. -1.5, -0.5, 0.5, 1.5,
  135678. };
  135679. static long _vq_quantmap__44u7__p4_0[] = {
  135680. 3, 1, 0, 2, 4,
  135681. };
  135682. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135683. _vq_quantthresh__44u7__p4_0,
  135684. _vq_quantmap__44u7__p4_0,
  135685. 5,
  135686. 5
  135687. };
  135688. static static_codebook _44u7__p4_0 = {
  135689. 4, 625,
  135690. _vq_lengthlist__44u7__p4_0,
  135691. 1, -533725184, 1611661312, 3, 0,
  135692. _vq_quantlist__44u7__p4_0,
  135693. NULL,
  135694. &_vq_auxt__44u7__p4_0,
  135695. NULL,
  135696. 0
  135697. };
  135698. static long _vq_quantlist__44u7__p5_0[] = {
  135699. 4,
  135700. 3,
  135701. 5,
  135702. 2,
  135703. 6,
  135704. 1,
  135705. 7,
  135706. 0,
  135707. 8,
  135708. };
  135709. static long _vq_lengthlist__44u7__p5_0[] = {
  135710. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135711. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135712. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135713. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135714. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135715. 14,
  135716. };
  135717. static float _vq_quantthresh__44u7__p5_0[] = {
  135718. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135719. };
  135720. static long _vq_quantmap__44u7__p5_0[] = {
  135721. 7, 5, 3, 1, 0, 2, 4, 6,
  135722. 8,
  135723. };
  135724. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135725. _vq_quantthresh__44u7__p5_0,
  135726. _vq_quantmap__44u7__p5_0,
  135727. 9,
  135728. 9
  135729. };
  135730. static static_codebook _44u7__p5_0 = {
  135731. 2, 81,
  135732. _vq_lengthlist__44u7__p5_0,
  135733. 1, -531628032, 1611661312, 4, 0,
  135734. _vq_quantlist__44u7__p5_0,
  135735. NULL,
  135736. &_vq_auxt__44u7__p5_0,
  135737. NULL,
  135738. 0
  135739. };
  135740. static long _vq_quantlist__44u7__p6_0[] = {
  135741. 4,
  135742. 3,
  135743. 5,
  135744. 2,
  135745. 6,
  135746. 1,
  135747. 7,
  135748. 0,
  135749. 8,
  135750. };
  135751. static long _vq_lengthlist__44u7__p6_0[] = {
  135752. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135753. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135754. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135755. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135756. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135757. 12,
  135758. };
  135759. static float _vq_quantthresh__44u7__p6_0[] = {
  135760. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135761. };
  135762. static long _vq_quantmap__44u7__p6_0[] = {
  135763. 7, 5, 3, 1, 0, 2, 4, 6,
  135764. 8,
  135765. };
  135766. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135767. _vq_quantthresh__44u7__p6_0,
  135768. _vq_quantmap__44u7__p6_0,
  135769. 9,
  135770. 9
  135771. };
  135772. static static_codebook _44u7__p6_0 = {
  135773. 2, 81,
  135774. _vq_lengthlist__44u7__p6_0,
  135775. 1, -531628032, 1611661312, 4, 0,
  135776. _vq_quantlist__44u7__p6_0,
  135777. NULL,
  135778. &_vq_auxt__44u7__p6_0,
  135779. NULL,
  135780. 0
  135781. };
  135782. static long _vq_quantlist__44u7__p7_0[] = {
  135783. 1,
  135784. 0,
  135785. 2,
  135786. };
  135787. static long _vq_lengthlist__44u7__p7_0[] = {
  135788. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135789. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135790. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135791. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135792. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135793. 10,
  135794. };
  135795. static float _vq_quantthresh__44u7__p7_0[] = {
  135796. -5.5, 5.5,
  135797. };
  135798. static long _vq_quantmap__44u7__p7_0[] = {
  135799. 1, 0, 2,
  135800. };
  135801. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135802. _vq_quantthresh__44u7__p7_0,
  135803. _vq_quantmap__44u7__p7_0,
  135804. 3,
  135805. 3
  135806. };
  135807. static static_codebook _44u7__p7_0 = {
  135808. 4, 81,
  135809. _vq_lengthlist__44u7__p7_0,
  135810. 1, -529137664, 1618345984, 2, 0,
  135811. _vq_quantlist__44u7__p7_0,
  135812. NULL,
  135813. &_vq_auxt__44u7__p7_0,
  135814. NULL,
  135815. 0
  135816. };
  135817. static long _vq_quantlist__44u7__p7_1[] = {
  135818. 5,
  135819. 4,
  135820. 6,
  135821. 3,
  135822. 7,
  135823. 2,
  135824. 8,
  135825. 1,
  135826. 9,
  135827. 0,
  135828. 10,
  135829. };
  135830. static long _vq_lengthlist__44u7__p7_1[] = {
  135831. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  135832. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  135833. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  135834. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  135835. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  135836. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135837. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  135838. 8, 9, 9, 9, 9, 9,10,10,10,
  135839. };
  135840. static float _vq_quantthresh__44u7__p7_1[] = {
  135841. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135842. 3.5, 4.5,
  135843. };
  135844. static long _vq_quantmap__44u7__p7_1[] = {
  135845. 9, 7, 5, 3, 1, 0, 2, 4,
  135846. 6, 8, 10,
  135847. };
  135848. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  135849. _vq_quantthresh__44u7__p7_1,
  135850. _vq_quantmap__44u7__p7_1,
  135851. 11,
  135852. 11
  135853. };
  135854. static static_codebook _44u7__p7_1 = {
  135855. 2, 121,
  135856. _vq_lengthlist__44u7__p7_1,
  135857. 1, -531365888, 1611661312, 4, 0,
  135858. _vq_quantlist__44u7__p7_1,
  135859. NULL,
  135860. &_vq_auxt__44u7__p7_1,
  135861. NULL,
  135862. 0
  135863. };
  135864. static long _vq_quantlist__44u7__p8_0[] = {
  135865. 5,
  135866. 4,
  135867. 6,
  135868. 3,
  135869. 7,
  135870. 2,
  135871. 8,
  135872. 1,
  135873. 9,
  135874. 0,
  135875. 10,
  135876. };
  135877. static long _vq_lengthlist__44u7__p8_0[] = {
  135878. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  135879. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  135880. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  135881. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  135882. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  135883. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  135884. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  135885. 12,13,13,14,14,15,15,15,16,
  135886. };
  135887. static float _vq_quantthresh__44u7__p8_0[] = {
  135888. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135889. 38.5, 49.5,
  135890. };
  135891. static long _vq_quantmap__44u7__p8_0[] = {
  135892. 9, 7, 5, 3, 1, 0, 2, 4,
  135893. 6, 8, 10,
  135894. };
  135895. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  135896. _vq_quantthresh__44u7__p8_0,
  135897. _vq_quantmap__44u7__p8_0,
  135898. 11,
  135899. 11
  135900. };
  135901. static static_codebook _44u7__p8_0 = {
  135902. 2, 121,
  135903. _vq_lengthlist__44u7__p8_0,
  135904. 1, -524582912, 1618345984, 4, 0,
  135905. _vq_quantlist__44u7__p8_0,
  135906. NULL,
  135907. &_vq_auxt__44u7__p8_0,
  135908. NULL,
  135909. 0
  135910. };
  135911. static long _vq_quantlist__44u7__p8_1[] = {
  135912. 5,
  135913. 4,
  135914. 6,
  135915. 3,
  135916. 7,
  135917. 2,
  135918. 8,
  135919. 1,
  135920. 9,
  135921. 0,
  135922. 10,
  135923. };
  135924. static long _vq_lengthlist__44u7__p8_1[] = {
  135925. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  135926. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  135927. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  135928. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  135929. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  135930. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  135931. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  135932. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  135933. };
  135934. static float _vq_quantthresh__44u7__p8_1[] = {
  135935. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135936. 3.5, 4.5,
  135937. };
  135938. static long _vq_quantmap__44u7__p8_1[] = {
  135939. 9, 7, 5, 3, 1, 0, 2, 4,
  135940. 6, 8, 10,
  135941. };
  135942. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  135943. _vq_quantthresh__44u7__p8_1,
  135944. _vq_quantmap__44u7__p8_1,
  135945. 11,
  135946. 11
  135947. };
  135948. static static_codebook _44u7__p8_1 = {
  135949. 2, 121,
  135950. _vq_lengthlist__44u7__p8_1,
  135951. 1, -531365888, 1611661312, 4, 0,
  135952. _vq_quantlist__44u7__p8_1,
  135953. NULL,
  135954. &_vq_auxt__44u7__p8_1,
  135955. NULL,
  135956. 0
  135957. };
  135958. static long _vq_quantlist__44u7__p9_0[] = {
  135959. 5,
  135960. 4,
  135961. 6,
  135962. 3,
  135963. 7,
  135964. 2,
  135965. 8,
  135966. 1,
  135967. 9,
  135968. 0,
  135969. 10,
  135970. };
  135971. static long _vq_lengthlist__44u7__p9_0[] = {
  135972. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  135973. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  135974. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135975. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135976. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135977. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135978. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135979. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135980. };
  135981. static float _vq_quantthresh__44u7__p9_0[] = {
  135982. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  135983. 2229.5, 2866.5,
  135984. };
  135985. static long _vq_quantmap__44u7__p9_0[] = {
  135986. 9, 7, 5, 3, 1, 0, 2, 4,
  135987. 6, 8, 10,
  135988. };
  135989. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  135990. _vq_quantthresh__44u7__p9_0,
  135991. _vq_quantmap__44u7__p9_0,
  135992. 11,
  135993. 11
  135994. };
  135995. static static_codebook _44u7__p9_0 = {
  135996. 2, 121,
  135997. _vq_lengthlist__44u7__p9_0,
  135998. 1, -512171520, 1630791680, 4, 0,
  135999. _vq_quantlist__44u7__p9_0,
  136000. NULL,
  136001. &_vq_auxt__44u7__p9_0,
  136002. NULL,
  136003. 0
  136004. };
  136005. static long _vq_quantlist__44u7__p9_1[] = {
  136006. 6,
  136007. 5,
  136008. 7,
  136009. 4,
  136010. 8,
  136011. 3,
  136012. 9,
  136013. 2,
  136014. 10,
  136015. 1,
  136016. 11,
  136017. 0,
  136018. 12,
  136019. };
  136020. static long _vq_lengthlist__44u7__p9_1[] = {
  136021. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136022. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136023. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136024. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136025. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136026. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136027. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136028. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136029. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136030. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136031. 15,15,15,15,17,17,16,17,16,
  136032. };
  136033. static float _vq_quantthresh__44u7__p9_1[] = {
  136034. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136035. 122.5, 171.5, 220.5, 269.5,
  136036. };
  136037. static long _vq_quantmap__44u7__p9_1[] = {
  136038. 11, 9, 7, 5, 3, 1, 0, 2,
  136039. 4, 6, 8, 10, 12,
  136040. };
  136041. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136042. _vq_quantthresh__44u7__p9_1,
  136043. _vq_quantmap__44u7__p9_1,
  136044. 13,
  136045. 13
  136046. };
  136047. static static_codebook _44u7__p9_1 = {
  136048. 2, 169,
  136049. _vq_lengthlist__44u7__p9_1,
  136050. 1, -518889472, 1622704128, 4, 0,
  136051. _vq_quantlist__44u7__p9_1,
  136052. NULL,
  136053. &_vq_auxt__44u7__p9_1,
  136054. NULL,
  136055. 0
  136056. };
  136057. static long _vq_quantlist__44u7__p9_2[] = {
  136058. 24,
  136059. 23,
  136060. 25,
  136061. 22,
  136062. 26,
  136063. 21,
  136064. 27,
  136065. 20,
  136066. 28,
  136067. 19,
  136068. 29,
  136069. 18,
  136070. 30,
  136071. 17,
  136072. 31,
  136073. 16,
  136074. 32,
  136075. 15,
  136076. 33,
  136077. 14,
  136078. 34,
  136079. 13,
  136080. 35,
  136081. 12,
  136082. 36,
  136083. 11,
  136084. 37,
  136085. 10,
  136086. 38,
  136087. 9,
  136088. 39,
  136089. 8,
  136090. 40,
  136091. 7,
  136092. 41,
  136093. 6,
  136094. 42,
  136095. 5,
  136096. 43,
  136097. 4,
  136098. 44,
  136099. 3,
  136100. 45,
  136101. 2,
  136102. 46,
  136103. 1,
  136104. 47,
  136105. 0,
  136106. 48,
  136107. };
  136108. static long _vq_lengthlist__44u7__p9_2[] = {
  136109. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136110. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136111. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136112. 8,
  136113. };
  136114. static float _vq_quantthresh__44u7__p9_2[] = {
  136115. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136116. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136117. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136118. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136119. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136120. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136121. };
  136122. static long _vq_quantmap__44u7__p9_2[] = {
  136123. 47, 45, 43, 41, 39, 37, 35, 33,
  136124. 31, 29, 27, 25, 23, 21, 19, 17,
  136125. 15, 13, 11, 9, 7, 5, 3, 1,
  136126. 0, 2, 4, 6, 8, 10, 12, 14,
  136127. 16, 18, 20, 22, 24, 26, 28, 30,
  136128. 32, 34, 36, 38, 40, 42, 44, 46,
  136129. 48,
  136130. };
  136131. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136132. _vq_quantthresh__44u7__p9_2,
  136133. _vq_quantmap__44u7__p9_2,
  136134. 49,
  136135. 49
  136136. };
  136137. static static_codebook _44u7__p9_2 = {
  136138. 1, 49,
  136139. _vq_lengthlist__44u7__p9_2,
  136140. 1, -526909440, 1611661312, 6, 0,
  136141. _vq_quantlist__44u7__p9_2,
  136142. NULL,
  136143. &_vq_auxt__44u7__p9_2,
  136144. NULL,
  136145. 0
  136146. };
  136147. static long _huff_lengthlist__44u7__short[] = {
  136148. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136149. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136150. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136151. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136152. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136153. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136154. 6, 8, 5, 9,
  136155. };
  136156. static static_codebook _huff_book__44u7__short = {
  136157. 2, 100,
  136158. _huff_lengthlist__44u7__short,
  136159. 0, 0, 0, 0, 0,
  136160. NULL,
  136161. NULL,
  136162. NULL,
  136163. NULL,
  136164. 0
  136165. };
  136166. static long _huff_lengthlist__44u8__long[] = {
  136167. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136168. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136169. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136170. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136171. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136172. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136173. 10, 8, 8, 9,
  136174. };
  136175. static static_codebook _huff_book__44u8__long = {
  136176. 2, 100,
  136177. _huff_lengthlist__44u8__long,
  136178. 0, 0, 0, 0, 0,
  136179. NULL,
  136180. NULL,
  136181. NULL,
  136182. NULL,
  136183. 0
  136184. };
  136185. static long _huff_lengthlist__44u8__short[] = {
  136186. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136187. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136188. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136189. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136190. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136191. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136192. 10,10,15,17,
  136193. };
  136194. static static_codebook _huff_book__44u8__short = {
  136195. 2, 100,
  136196. _huff_lengthlist__44u8__short,
  136197. 0, 0, 0, 0, 0,
  136198. NULL,
  136199. NULL,
  136200. NULL,
  136201. NULL,
  136202. 0
  136203. };
  136204. static long _vq_quantlist__44u8_p1_0[] = {
  136205. 1,
  136206. 0,
  136207. 2,
  136208. };
  136209. static long _vq_lengthlist__44u8_p1_0[] = {
  136210. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136211. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136212. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136213. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136214. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136215. 10,
  136216. };
  136217. static float _vq_quantthresh__44u8_p1_0[] = {
  136218. -0.5, 0.5,
  136219. };
  136220. static long _vq_quantmap__44u8_p1_0[] = {
  136221. 1, 0, 2,
  136222. };
  136223. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136224. _vq_quantthresh__44u8_p1_0,
  136225. _vq_quantmap__44u8_p1_0,
  136226. 3,
  136227. 3
  136228. };
  136229. static static_codebook _44u8_p1_0 = {
  136230. 4, 81,
  136231. _vq_lengthlist__44u8_p1_0,
  136232. 1, -535822336, 1611661312, 2, 0,
  136233. _vq_quantlist__44u8_p1_0,
  136234. NULL,
  136235. &_vq_auxt__44u8_p1_0,
  136236. NULL,
  136237. 0
  136238. };
  136239. static long _vq_quantlist__44u8_p2_0[] = {
  136240. 2,
  136241. 1,
  136242. 3,
  136243. 0,
  136244. 4,
  136245. };
  136246. static long _vq_lengthlist__44u8_p2_0[] = {
  136247. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136248. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136249. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136250. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136251. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136252. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136253. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136254. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136255. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136256. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136257. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136258. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136259. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136260. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136261. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136262. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136263. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136264. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136265. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136266. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136267. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136268. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136269. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136270. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136271. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136272. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136273. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136274. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136275. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136276. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136277. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136278. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136279. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136280. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136281. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136282. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136283. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136284. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136285. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136286. 14,
  136287. };
  136288. static float _vq_quantthresh__44u8_p2_0[] = {
  136289. -1.5, -0.5, 0.5, 1.5,
  136290. };
  136291. static long _vq_quantmap__44u8_p2_0[] = {
  136292. 3, 1, 0, 2, 4,
  136293. };
  136294. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136295. _vq_quantthresh__44u8_p2_0,
  136296. _vq_quantmap__44u8_p2_0,
  136297. 5,
  136298. 5
  136299. };
  136300. static static_codebook _44u8_p2_0 = {
  136301. 4, 625,
  136302. _vq_lengthlist__44u8_p2_0,
  136303. 1, -533725184, 1611661312, 3, 0,
  136304. _vq_quantlist__44u8_p2_0,
  136305. NULL,
  136306. &_vq_auxt__44u8_p2_0,
  136307. NULL,
  136308. 0
  136309. };
  136310. static long _vq_quantlist__44u8_p3_0[] = {
  136311. 4,
  136312. 3,
  136313. 5,
  136314. 2,
  136315. 6,
  136316. 1,
  136317. 7,
  136318. 0,
  136319. 8,
  136320. };
  136321. static long _vq_lengthlist__44u8_p3_0[] = {
  136322. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136323. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136324. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136325. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136326. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136327. 12,
  136328. };
  136329. static float _vq_quantthresh__44u8_p3_0[] = {
  136330. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136331. };
  136332. static long _vq_quantmap__44u8_p3_0[] = {
  136333. 7, 5, 3, 1, 0, 2, 4, 6,
  136334. 8,
  136335. };
  136336. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136337. _vq_quantthresh__44u8_p3_0,
  136338. _vq_quantmap__44u8_p3_0,
  136339. 9,
  136340. 9
  136341. };
  136342. static static_codebook _44u8_p3_0 = {
  136343. 2, 81,
  136344. _vq_lengthlist__44u8_p3_0,
  136345. 1, -531628032, 1611661312, 4, 0,
  136346. _vq_quantlist__44u8_p3_0,
  136347. NULL,
  136348. &_vq_auxt__44u8_p3_0,
  136349. NULL,
  136350. 0
  136351. };
  136352. static long _vq_quantlist__44u8_p4_0[] = {
  136353. 8,
  136354. 7,
  136355. 9,
  136356. 6,
  136357. 10,
  136358. 5,
  136359. 11,
  136360. 4,
  136361. 12,
  136362. 3,
  136363. 13,
  136364. 2,
  136365. 14,
  136366. 1,
  136367. 15,
  136368. 0,
  136369. 16,
  136370. };
  136371. static long _vq_lengthlist__44u8_p4_0[] = {
  136372. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136373. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136374. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136375. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136376. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136377. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136378. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136379. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136380. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136381. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136382. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136383. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136384. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136385. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136386. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136387. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136388. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136389. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136390. 14,
  136391. };
  136392. static float _vq_quantthresh__44u8_p4_0[] = {
  136393. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136394. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136395. };
  136396. static long _vq_quantmap__44u8_p4_0[] = {
  136397. 15, 13, 11, 9, 7, 5, 3, 1,
  136398. 0, 2, 4, 6, 8, 10, 12, 14,
  136399. 16,
  136400. };
  136401. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136402. _vq_quantthresh__44u8_p4_0,
  136403. _vq_quantmap__44u8_p4_0,
  136404. 17,
  136405. 17
  136406. };
  136407. static static_codebook _44u8_p4_0 = {
  136408. 2, 289,
  136409. _vq_lengthlist__44u8_p4_0,
  136410. 1, -529530880, 1611661312, 5, 0,
  136411. _vq_quantlist__44u8_p4_0,
  136412. NULL,
  136413. &_vq_auxt__44u8_p4_0,
  136414. NULL,
  136415. 0
  136416. };
  136417. static long _vq_quantlist__44u8_p5_0[] = {
  136418. 1,
  136419. 0,
  136420. 2,
  136421. };
  136422. static long _vq_lengthlist__44u8_p5_0[] = {
  136423. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136424. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136425. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136426. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136427. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136428. 10,
  136429. };
  136430. static float _vq_quantthresh__44u8_p5_0[] = {
  136431. -5.5, 5.5,
  136432. };
  136433. static long _vq_quantmap__44u8_p5_0[] = {
  136434. 1, 0, 2,
  136435. };
  136436. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136437. _vq_quantthresh__44u8_p5_0,
  136438. _vq_quantmap__44u8_p5_0,
  136439. 3,
  136440. 3
  136441. };
  136442. static static_codebook _44u8_p5_0 = {
  136443. 4, 81,
  136444. _vq_lengthlist__44u8_p5_0,
  136445. 1, -529137664, 1618345984, 2, 0,
  136446. _vq_quantlist__44u8_p5_0,
  136447. NULL,
  136448. &_vq_auxt__44u8_p5_0,
  136449. NULL,
  136450. 0
  136451. };
  136452. static long _vq_quantlist__44u8_p5_1[] = {
  136453. 5,
  136454. 4,
  136455. 6,
  136456. 3,
  136457. 7,
  136458. 2,
  136459. 8,
  136460. 1,
  136461. 9,
  136462. 0,
  136463. 10,
  136464. };
  136465. static long _vq_lengthlist__44u8_p5_1[] = {
  136466. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136467. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136468. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136469. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136470. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136471. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136472. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136473. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136474. };
  136475. static float _vq_quantthresh__44u8_p5_1[] = {
  136476. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136477. 3.5, 4.5,
  136478. };
  136479. static long _vq_quantmap__44u8_p5_1[] = {
  136480. 9, 7, 5, 3, 1, 0, 2, 4,
  136481. 6, 8, 10,
  136482. };
  136483. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136484. _vq_quantthresh__44u8_p5_1,
  136485. _vq_quantmap__44u8_p5_1,
  136486. 11,
  136487. 11
  136488. };
  136489. static static_codebook _44u8_p5_1 = {
  136490. 2, 121,
  136491. _vq_lengthlist__44u8_p5_1,
  136492. 1, -531365888, 1611661312, 4, 0,
  136493. _vq_quantlist__44u8_p5_1,
  136494. NULL,
  136495. &_vq_auxt__44u8_p5_1,
  136496. NULL,
  136497. 0
  136498. };
  136499. static long _vq_quantlist__44u8_p6_0[] = {
  136500. 6,
  136501. 5,
  136502. 7,
  136503. 4,
  136504. 8,
  136505. 3,
  136506. 9,
  136507. 2,
  136508. 10,
  136509. 1,
  136510. 11,
  136511. 0,
  136512. 12,
  136513. };
  136514. static long _vq_lengthlist__44u8_p6_0[] = {
  136515. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136516. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136517. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136518. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136519. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136520. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136521. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136522. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136523. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136524. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136525. 11,11,11,11,11,12,11,12,12,
  136526. };
  136527. static float _vq_quantthresh__44u8_p6_0[] = {
  136528. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136529. 12.5, 17.5, 22.5, 27.5,
  136530. };
  136531. static long _vq_quantmap__44u8_p6_0[] = {
  136532. 11, 9, 7, 5, 3, 1, 0, 2,
  136533. 4, 6, 8, 10, 12,
  136534. };
  136535. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136536. _vq_quantthresh__44u8_p6_0,
  136537. _vq_quantmap__44u8_p6_0,
  136538. 13,
  136539. 13
  136540. };
  136541. static static_codebook _44u8_p6_0 = {
  136542. 2, 169,
  136543. _vq_lengthlist__44u8_p6_0,
  136544. 1, -526516224, 1616117760, 4, 0,
  136545. _vq_quantlist__44u8_p6_0,
  136546. NULL,
  136547. &_vq_auxt__44u8_p6_0,
  136548. NULL,
  136549. 0
  136550. };
  136551. static long _vq_quantlist__44u8_p6_1[] = {
  136552. 2,
  136553. 1,
  136554. 3,
  136555. 0,
  136556. 4,
  136557. };
  136558. static long _vq_lengthlist__44u8_p6_1[] = {
  136559. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136560. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136561. };
  136562. static float _vq_quantthresh__44u8_p6_1[] = {
  136563. -1.5, -0.5, 0.5, 1.5,
  136564. };
  136565. static long _vq_quantmap__44u8_p6_1[] = {
  136566. 3, 1, 0, 2, 4,
  136567. };
  136568. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136569. _vq_quantthresh__44u8_p6_1,
  136570. _vq_quantmap__44u8_p6_1,
  136571. 5,
  136572. 5
  136573. };
  136574. static static_codebook _44u8_p6_1 = {
  136575. 2, 25,
  136576. _vq_lengthlist__44u8_p6_1,
  136577. 1, -533725184, 1611661312, 3, 0,
  136578. _vq_quantlist__44u8_p6_1,
  136579. NULL,
  136580. &_vq_auxt__44u8_p6_1,
  136581. NULL,
  136582. 0
  136583. };
  136584. static long _vq_quantlist__44u8_p7_0[] = {
  136585. 6,
  136586. 5,
  136587. 7,
  136588. 4,
  136589. 8,
  136590. 3,
  136591. 9,
  136592. 2,
  136593. 10,
  136594. 1,
  136595. 11,
  136596. 0,
  136597. 12,
  136598. };
  136599. static long _vq_lengthlist__44u8_p7_0[] = {
  136600. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136601. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136602. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136603. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136604. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136605. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136606. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136607. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136608. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136609. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136610. 13,13,14,14,14,15,15,15,16,
  136611. };
  136612. static float _vq_quantthresh__44u8_p7_0[] = {
  136613. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136614. 27.5, 38.5, 49.5, 60.5,
  136615. };
  136616. static long _vq_quantmap__44u8_p7_0[] = {
  136617. 11, 9, 7, 5, 3, 1, 0, 2,
  136618. 4, 6, 8, 10, 12,
  136619. };
  136620. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136621. _vq_quantthresh__44u8_p7_0,
  136622. _vq_quantmap__44u8_p7_0,
  136623. 13,
  136624. 13
  136625. };
  136626. static static_codebook _44u8_p7_0 = {
  136627. 2, 169,
  136628. _vq_lengthlist__44u8_p7_0,
  136629. 1, -523206656, 1618345984, 4, 0,
  136630. _vq_quantlist__44u8_p7_0,
  136631. NULL,
  136632. &_vq_auxt__44u8_p7_0,
  136633. NULL,
  136634. 0
  136635. };
  136636. static long _vq_quantlist__44u8_p7_1[] = {
  136637. 5,
  136638. 4,
  136639. 6,
  136640. 3,
  136641. 7,
  136642. 2,
  136643. 8,
  136644. 1,
  136645. 9,
  136646. 0,
  136647. 10,
  136648. };
  136649. static long _vq_lengthlist__44u8_p7_1[] = {
  136650. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136651. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136652. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136653. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136654. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136655. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136656. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136657. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136658. };
  136659. static float _vq_quantthresh__44u8_p7_1[] = {
  136660. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136661. 3.5, 4.5,
  136662. };
  136663. static long _vq_quantmap__44u8_p7_1[] = {
  136664. 9, 7, 5, 3, 1, 0, 2, 4,
  136665. 6, 8, 10,
  136666. };
  136667. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136668. _vq_quantthresh__44u8_p7_1,
  136669. _vq_quantmap__44u8_p7_1,
  136670. 11,
  136671. 11
  136672. };
  136673. static static_codebook _44u8_p7_1 = {
  136674. 2, 121,
  136675. _vq_lengthlist__44u8_p7_1,
  136676. 1, -531365888, 1611661312, 4, 0,
  136677. _vq_quantlist__44u8_p7_1,
  136678. NULL,
  136679. &_vq_auxt__44u8_p7_1,
  136680. NULL,
  136681. 0
  136682. };
  136683. static long _vq_quantlist__44u8_p8_0[] = {
  136684. 7,
  136685. 6,
  136686. 8,
  136687. 5,
  136688. 9,
  136689. 4,
  136690. 10,
  136691. 3,
  136692. 11,
  136693. 2,
  136694. 12,
  136695. 1,
  136696. 13,
  136697. 0,
  136698. 14,
  136699. };
  136700. static long _vq_lengthlist__44u8_p8_0[] = {
  136701. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136702. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136703. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136704. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136705. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136706. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136707. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136708. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136709. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136710. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136711. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136712. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136713. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136714. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136715. 17,
  136716. };
  136717. static float _vq_quantthresh__44u8_p8_0[] = {
  136718. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136719. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136720. };
  136721. static long _vq_quantmap__44u8_p8_0[] = {
  136722. 13, 11, 9, 7, 5, 3, 1, 0,
  136723. 2, 4, 6, 8, 10, 12, 14,
  136724. };
  136725. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136726. _vq_quantthresh__44u8_p8_0,
  136727. _vq_quantmap__44u8_p8_0,
  136728. 15,
  136729. 15
  136730. };
  136731. static static_codebook _44u8_p8_0 = {
  136732. 2, 225,
  136733. _vq_lengthlist__44u8_p8_0,
  136734. 1, -520986624, 1620377600, 4, 0,
  136735. _vq_quantlist__44u8_p8_0,
  136736. NULL,
  136737. &_vq_auxt__44u8_p8_0,
  136738. NULL,
  136739. 0
  136740. };
  136741. static long _vq_quantlist__44u8_p8_1[] = {
  136742. 10,
  136743. 9,
  136744. 11,
  136745. 8,
  136746. 12,
  136747. 7,
  136748. 13,
  136749. 6,
  136750. 14,
  136751. 5,
  136752. 15,
  136753. 4,
  136754. 16,
  136755. 3,
  136756. 17,
  136757. 2,
  136758. 18,
  136759. 1,
  136760. 19,
  136761. 0,
  136762. 20,
  136763. };
  136764. static long _vq_lengthlist__44u8_p8_1[] = {
  136765. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136766. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136767. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136768. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136769. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136770. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136771. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136772. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136773. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136774. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136775. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136776. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136777. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136778. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136779. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136780. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136781. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136782. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136783. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136784. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136785. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136786. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136787. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136788. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136789. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136790. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136791. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136792. 10,10,10,10,10,10,10,10,10,
  136793. };
  136794. static float _vq_quantthresh__44u8_p8_1[] = {
  136795. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136796. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136797. 6.5, 7.5, 8.5, 9.5,
  136798. };
  136799. static long _vq_quantmap__44u8_p8_1[] = {
  136800. 19, 17, 15, 13, 11, 9, 7, 5,
  136801. 3, 1, 0, 2, 4, 6, 8, 10,
  136802. 12, 14, 16, 18, 20,
  136803. };
  136804. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136805. _vq_quantthresh__44u8_p8_1,
  136806. _vq_quantmap__44u8_p8_1,
  136807. 21,
  136808. 21
  136809. };
  136810. static static_codebook _44u8_p8_1 = {
  136811. 2, 441,
  136812. _vq_lengthlist__44u8_p8_1,
  136813. 1, -529268736, 1611661312, 5, 0,
  136814. _vq_quantlist__44u8_p8_1,
  136815. NULL,
  136816. &_vq_auxt__44u8_p8_1,
  136817. NULL,
  136818. 0
  136819. };
  136820. static long _vq_quantlist__44u8_p9_0[] = {
  136821. 4,
  136822. 3,
  136823. 5,
  136824. 2,
  136825. 6,
  136826. 1,
  136827. 7,
  136828. 0,
  136829. 8,
  136830. };
  136831. static long _vq_lengthlist__44u8_p9_0[] = {
  136832. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  136833. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136834. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136835. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136836. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136837. 8,
  136838. };
  136839. static float _vq_quantthresh__44u8_p9_0[] = {
  136840. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  136841. };
  136842. static long _vq_quantmap__44u8_p9_0[] = {
  136843. 7, 5, 3, 1, 0, 2, 4, 6,
  136844. 8,
  136845. };
  136846. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  136847. _vq_quantthresh__44u8_p9_0,
  136848. _vq_quantmap__44u8_p9_0,
  136849. 9,
  136850. 9
  136851. };
  136852. static static_codebook _44u8_p9_0 = {
  136853. 2, 81,
  136854. _vq_lengthlist__44u8_p9_0,
  136855. 1, -511895552, 1631393792, 4, 0,
  136856. _vq_quantlist__44u8_p9_0,
  136857. NULL,
  136858. &_vq_auxt__44u8_p9_0,
  136859. NULL,
  136860. 0
  136861. };
  136862. static long _vq_quantlist__44u8_p9_1[] = {
  136863. 9,
  136864. 8,
  136865. 10,
  136866. 7,
  136867. 11,
  136868. 6,
  136869. 12,
  136870. 5,
  136871. 13,
  136872. 4,
  136873. 14,
  136874. 3,
  136875. 15,
  136876. 2,
  136877. 16,
  136878. 1,
  136879. 17,
  136880. 0,
  136881. 18,
  136882. };
  136883. static long _vq_lengthlist__44u8_p9_1[] = {
  136884. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  136885. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  136886. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  136887. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  136888. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  136889. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  136890. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  136891. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  136892. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  136893. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  136894. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  136895. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  136896. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  136897. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  136898. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  136899. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  136900. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  136901. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  136902. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  136903. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  136904. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  136905. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  136906. 16,15,16,16,16,16,16,16,16,
  136907. };
  136908. static float _vq_quantthresh__44u8_p9_1[] = {
  136909. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  136910. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  136911. 367.5, 416.5,
  136912. };
  136913. static long _vq_quantmap__44u8_p9_1[] = {
  136914. 17, 15, 13, 11, 9, 7, 5, 3,
  136915. 1, 0, 2, 4, 6, 8, 10, 12,
  136916. 14, 16, 18,
  136917. };
  136918. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  136919. _vq_quantthresh__44u8_p9_1,
  136920. _vq_quantmap__44u8_p9_1,
  136921. 19,
  136922. 19
  136923. };
  136924. static static_codebook _44u8_p9_1 = {
  136925. 2, 361,
  136926. _vq_lengthlist__44u8_p9_1,
  136927. 1, -518287360, 1622704128, 5, 0,
  136928. _vq_quantlist__44u8_p9_1,
  136929. NULL,
  136930. &_vq_auxt__44u8_p9_1,
  136931. NULL,
  136932. 0
  136933. };
  136934. static long _vq_quantlist__44u8_p9_2[] = {
  136935. 24,
  136936. 23,
  136937. 25,
  136938. 22,
  136939. 26,
  136940. 21,
  136941. 27,
  136942. 20,
  136943. 28,
  136944. 19,
  136945. 29,
  136946. 18,
  136947. 30,
  136948. 17,
  136949. 31,
  136950. 16,
  136951. 32,
  136952. 15,
  136953. 33,
  136954. 14,
  136955. 34,
  136956. 13,
  136957. 35,
  136958. 12,
  136959. 36,
  136960. 11,
  136961. 37,
  136962. 10,
  136963. 38,
  136964. 9,
  136965. 39,
  136966. 8,
  136967. 40,
  136968. 7,
  136969. 41,
  136970. 6,
  136971. 42,
  136972. 5,
  136973. 43,
  136974. 4,
  136975. 44,
  136976. 3,
  136977. 45,
  136978. 2,
  136979. 46,
  136980. 1,
  136981. 47,
  136982. 0,
  136983. 48,
  136984. };
  136985. static long _vq_lengthlist__44u8_p9_2[] = {
  136986. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  136987. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136988. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136989. 7,
  136990. };
  136991. static float _vq_quantthresh__44u8_p9_2[] = {
  136992. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136993. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136994. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136995. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136996. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136997. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136998. };
  136999. static long _vq_quantmap__44u8_p9_2[] = {
  137000. 47, 45, 43, 41, 39, 37, 35, 33,
  137001. 31, 29, 27, 25, 23, 21, 19, 17,
  137002. 15, 13, 11, 9, 7, 5, 3, 1,
  137003. 0, 2, 4, 6, 8, 10, 12, 14,
  137004. 16, 18, 20, 22, 24, 26, 28, 30,
  137005. 32, 34, 36, 38, 40, 42, 44, 46,
  137006. 48,
  137007. };
  137008. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137009. _vq_quantthresh__44u8_p9_2,
  137010. _vq_quantmap__44u8_p9_2,
  137011. 49,
  137012. 49
  137013. };
  137014. static static_codebook _44u8_p9_2 = {
  137015. 1, 49,
  137016. _vq_lengthlist__44u8_p9_2,
  137017. 1, -526909440, 1611661312, 6, 0,
  137018. _vq_quantlist__44u8_p9_2,
  137019. NULL,
  137020. &_vq_auxt__44u8_p9_2,
  137021. NULL,
  137022. 0
  137023. };
  137024. static long _huff_lengthlist__44u9__long[] = {
  137025. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137026. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137027. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137028. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137029. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137030. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137031. 10, 8, 8, 9,
  137032. };
  137033. static static_codebook _huff_book__44u9__long = {
  137034. 2, 100,
  137035. _huff_lengthlist__44u9__long,
  137036. 0, 0, 0, 0, 0,
  137037. NULL,
  137038. NULL,
  137039. NULL,
  137040. NULL,
  137041. 0
  137042. };
  137043. static long _huff_lengthlist__44u9__short[] = {
  137044. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137045. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137046. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137047. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137048. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137049. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137050. 9, 9,12,15,
  137051. };
  137052. static static_codebook _huff_book__44u9__short = {
  137053. 2, 100,
  137054. _huff_lengthlist__44u9__short,
  137055. 0, 0, 0, 0, 0,
  137056. NULL,
  137057. NULL,
  137058. NULL,
  137059. NULL,
  137060. 0
  137061. };
  137062. static long _vq_quantlist__44u9_p1_0[] = {
  137063. 1,
  137064. 0,
  137065. 2,
  137066. };
  137067. static long _vq_lengthlist__44u9_p1_0[] = {
  137068. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137069. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137070. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137071. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137072. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137073. 10,
  137074. };
  137075. static float _vq_quantthresh__44u9_p1_0[] = {
  137076. -0.5, 0.5,
  137077. };
  137078. static long _vq_quantmap__44u9_p1_0[] = {
  137079. 1, 0, 2,
  137080. };
  137081. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137082. _vq_quantthresh__44u9_p1_0,
  137083. _vq_quantmap__44u9_p1_0,
  137084. 3,
  137085. 3
  137086. };
  137087. static static_codebook _44u9_p1_0 = {
  137088. 4, 81,
  137089. _vq_lengthlist__44u9_p1_0,
  137090. 1, -535822336, 1611661312, 2, 0,
  137091. _vq_quantlist__44u9_p1_0,
  137092. NULL,
  137093. &_vq_auxt__44u9_p1_0,
  137094. NULL,
  137095. 0
  137096. };
  137097. static long _vq_quantlist__44u9_p2_0[] = {
  137098. 2,
  137099. 1,
  137100. 3,
  137101. 0,
  137102. 4,
  137103. };
  137104. static long _vq_lengthlist__44u9_p2_0[] = {
  137105. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137106. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137107. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137108. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137109. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137110. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137111. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137112. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137113. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137114. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137115. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137116. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137117. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137118. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137119. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137120. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137121. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137122. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137123. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137124. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137125. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137126. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137127. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137128. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137129. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137130. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137131. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137132. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137133. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137134. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137135. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137136. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137137. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137138. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137139. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137140. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137141. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137142. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137143. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137144. 14,
  137145. };
  137146. static float _vq_quantthresh__44u9_p2_0[] = {
  137147. -1.5, -0.5, 0.5, 1.5,
  137148. };
  137149. static long _vq_quantmap__44u9_p2_0[] = {
  137150. 3, 1, 0, 2, 4,
  137151. };
  137152. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137153. _vq_quantthresh__44u9_p2_0,
  137154. _vq_quantmap__44u9_p2_0,
  137155. 5,
  137156. 5
  137157. };
  137158. static static_codebook _44u9_p2_0 = {
  137159. 4, 625,
  137160. _vq_lengthlist__44u9_p2_0,
  137161. 1, -533725184, 1611661312, 3, 0,
  137162. _vq_quantlist__44u9_p2_0,
  137163. NULL,
  137164. &_vq_auxt__44u9_p2_0,
  137165. NULL,
  137166. 0
  137167. };
  137168. static long _vq_quantlist__44u9_p3_0[] = {
  137169. 4,
  137170. 3,
  137171. 5,
  137172. 2,
  137173. 6,
  137174. 1,
  137175. 7,
  137176. 0,
  137177. 8,
  137178. };
  137179. static long _vq_lengthlist__44u9_p3_0[] = {
  137180. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137181. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137182. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137183. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137184. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137185. 11,
  137186. };
  137187. static float _vq_quantthresh__44u9_p3_0[] = {
  137188. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137189. };
  137190. static long _vq_quantmap__44u9_p3_0[] = {
  137191. 7, 5, 3, 1, 0, 2, 4, 6,
  137192. 8,
  137193. };
  137194. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137195. _vq_quantthresh__44u9_p3_0,
  137196. _vq_quantmap__44u9_p3_0,
  137197. 9,
  137198. 9
  137199. };
  137200. static static_codebook _44u9_p3_0 = {
  137201. 2, 81,
  137202. _vq_lengthlist__44u9_p3_0,
  137203. 1, -531628032, 1611661312, 4, 0,
  137204. _vq_quantlist__44u9_p3_0,
  137205. NULL,
  137206. &_vq_auxt__44u9_p3_0,
  137207. NULL,
  137208. 0
  137209. };
  137210. static long _vq_quantlist__44u9_p4_0[] = {
  137211. 8,
  137212. 7,
  137213. 9,
  137214. 6,
  137215. 10,
  137216. 5,
  137217. 11,
  137218. 4,
  137219. 12,
  137220. 3,
  137221. 13,
  137222. 2,
  137223. 14,
  137224. 1,
  137225. 15,
  137226. 0,
  137227. 16,
  137228. };
  137229. static long _vq_lengthlist__44u9_p4_0[] = {
  137230. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137231. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137232. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137233. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137234. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137235. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137236. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137237. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137238. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137239. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137240. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137241. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137242. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137243. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137244. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137245. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137246. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137247. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137248. 14,
  137249. };
  137250. static float _vq_quantthresh__44u9_p4_0[] = {
  137251. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137252. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137253. };
  137254. static long _vq_quantmap__44u9_p4_0[] = {
  137255. 15, 13, 11, 9, 7, 5, 3, 1,
  137256. 0, 2, 4, 6, 8, 10, 12, 14,
  137257. 16,
  137258. };
  137259. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137260. _vq_quantthresh__44u9_p4_0,
  137261. _vq_quantmap__44u9_p4_0,
  137262. 17,
  137263. 17
  137264. };
  137265. static static_codebook _44u9_p4_0 = {
  137266. 2, 289,
  137267. _vq_lengthlist__44u9_p4_0,
  137268. 1, -529530880, 1611661312, 5, 0,
  137269. _vq_quantlist__44u9_p4_0,
  137270. NULL,
  137271. &_vq_auxt__44u9_p4_0,
  137272. NULL,
  137273. 0
  137274. };
  137275. static long _vq_quantlist__44u9_p5_0[] = {
  137276. 1,
  137277. 0,
  137278. 2,
  137279. };
  137280. static long _vq_lengthlist__44u9_p5_0[] = {
  137281. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137282. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137283. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137284. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137285. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137286. 10,
  137287. };
  137288. static float _vq_quantthresh__44u9_p5_0[] = {
  137289. -5.5, 5.5,
  137290. };
  137291. static long _vq_quantmap__44u9_p5_0[] = {
  137292. 1, 0, 2,
  137293. };
  137294. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137295. _vq_quantthresh__44u9_p5_0,
  137296. _vq_quantmap__44u9_p5_0,
  137297. 3,
  137298. 3
  137299. };
  137300. static static_codebook _44u9_p5_0 = {
  137301. 4, 81,
  137302. _vq_lengthlist__44u9_p5_0,
  137303. 1, -529137664, 1618345984, 2, 0,
  137304. _vq_quantlist__44u9_p5_0,
  137305. NULL,
  137306. &_vq_auxt__44u9_p5_0,
  137307. NULL,
  137308. 0
  137309. };
  137310. static long _vq_quantlist__44u9_p5_1[] = {
  137311. 5,
  137312. 4,
  137313. 6,
  137314. 3,
  137315. 7,
  137316. 2,
  137317. 8,
  137318. 1,
  137319. 9,
  137320. 0,
  137321. 10,
  137322. };
  137323. static long _vq_lengthlist__44u9_p5_1[] = {
  137324. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137325. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137326. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137327. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137328. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137329. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137330. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137331. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137332. };
  137333. static float _vq_quantthresh__44u9_p5_1[] = {
  137334. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137335. 3.5, 4.5,
  137336. };
  137337. static long _vq_quantmap__44u9_p5_1[] = {
  137338. 9, 7, 5, 3, 1, 0, 2, 4,
  137339. 6, 8, 10,
  137340. };
  137341. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137342. _vq_quantthresh__44u9_p5_1,
  137343. _vq_quantmap__44u9_p5_1,
  137344. 11,
  137345. 11
  137346. };
  137347. static static_codebook _44u9_p5_1 = {
  137348. 2, 121,
  137349. _vq_lengthlist__44u9_p5_1,
  137350. 1, -531365888, 1611661312, 4, 0,
  137351. _vq_quantlist__44u9_p5_1,
  137352. NULL,
  137353. &_vq_auxt__44u9_p5_1,
  137354. NULL,
  137355. 0
  137356. };
  137357. static long _vq_quantlist__44u9_p6_0[] = {
  137358. 6,
  137359. 5,
  137360. 7,
  137361. 4,
  137362. 8,
  137363. 3,
  137364. 9,
  137365. 2,
  137366. 10,
  137367. 1,
  137368. 11,
  137369. 0,
  137370. 12,
  137371. };
  137372. static long _vq_lengthlist__44u9_p6_0[] = {
  137373. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137374. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137375. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137376. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137377. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137378. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137379. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137380. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137381. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137382. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137383. 10,11,11,11,11,12,11,12,12,
  137384. };
  137385. static float _vq_quantthresh__44u9_p6_0[] = {
  137386. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137387. 12.5, 17.5, 22.5, 27.5,
  137388. };
  137389. static long _vq_quantmap__44u9_p6_0[] = {
  137390. 11, 9, 7, 5, 3, 1, 0, 2,
  137391. 4, 6, 8, 10, 12,
  137392. };
  137393. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137394. _vq_quantthresh__44u9_p6_0,
  137395. _vq_quantmap__44u9_p6_0,
  137396. 13,
  137397. 13
  137398. };
  137399. static static_codebook _44u9_p6_0 = {
  137400. 2, 169,
  137401. _vq_lengthlist__44u9_p6_0,
  137402. 1, -526516224, 1616117760, 4, 0,
  137403. _vq_quantlist__44u9_p6_0,
  137404. NULL,
  137405. &_vq_auxt__44u9_p6_0,
  137406. NULL,
  137407. 0
  137408. };
  137409. static long _vq_quantlist__44u9_p6_1[] = {
  137410. 2,
  137411. 1,
  137412. 3,
  137413. 0,
  137414. 4,
  137415. };
  137416. static long _vq_lengthlist__44u9_p6_1[] = {
  137417. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137418. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137419. };
  137420. static float _vq_quantthresh__44u9_p6_1[] = {
  137421. -1.5, -0.5, 0.5, 1.5,
  137422. };
  137423. static long _vq_quantmap__44u9_p6_1[] = {
  137424. 3, 1, 0, 2, 4,
  137425. };
  137426. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137427. _vq_quantthresh__44u9_p6_1,
  137428. _vq_quantmap__44u9_p6_1,
  137429. 5,
  137430. 5
  137431. };
  137432. static static_codebook _44u9_p6_1 = {
  137433. 2, 25,
  137434. _vq_lengthlist__44u9_p6_1,
  137435. 1, -533725184, 1611661312, 3, 0,
  137436. _vq_quantlist__44u9_p6_1,
  137437. NULL,
  137438. &_vq_auxt__44u9_p6_1,
  137439. NULL,
  137440. 0
  137441. };
  137442. static long _vq_quantlist__44u9_p7_0[] = {
  137443. 6,
  137444. 5,
  137445. 7,
  137446. 4,
  137447. 8,
  137448. 3,
  137449. 9,
  137450. 2,
  137451. 10,
  137452. 1,
  137453. 11,
  137454. 0,
  137455. 12,
  137456. };
  137457. static long _vq_lengthlist__44u9_p7_0[] = {
  137458. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137459. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137460. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137461. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137462. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137463. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137464. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137465. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137466. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137467. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137468. 12,13,13,14,14,14,15,15,15,
  137469. };
  137470. static float _vq_quantthresh__44u9_p7_0[] = {
  137471. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137472. 27.5, 38.5, 49.5, 60.5,
  137473. };
  137474. static long _vq_quantmap__44u9_p7_0[] = {
  137475. 11, 9, 7, 5, 3, 1, 0, 2,
  137476. 4, 6, 8, 10, 12,
  137477. };
  137478. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137479. _vq_quantthresh__44u9_p7_0,
  137480. _vq_quantmap__44u9_p7_0,
  137481. 13,
  137482. 13
  137483. };
  137484. static static_codebook _44u9_p7_0 = {
  137485. 2, 169,
  137486. _vq_lengthlist__44u9_p7_0,
  137487. 1, -523206656, 1618345984, 4, 0,
  137488. _vq_quantlist__44u9_p7_0,
  137489. NULL,
  137490. &_vq_auxt__44u9_p7_0,
  137491. NULL,
  137492. 0
  137493. };
  137494. static long _vq_quantlist__44u9_p7_1[] = {
  137495. 5,
  137496. 4,
  137497. 6,
  137498. 3,
  137499. 7,
  137500. 2,
  137501. 8,
  137502. 1,
  137503. 9,
  137504. 0,
  137505. 10,
  137506. };
  137507. static long _vq_lengthlist__44u9_p7_1[] = {
  137508. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137509. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137510. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137511. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137512. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137513. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137514. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137515. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137516. };
  137517. static float _vq_quantthresh__44u9_p7_1[] = {
  137518. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137519. 3.5, 4.5,
  137520. };
  137521. static long _vq_quantmap__44u9_p7_1[] = {
  137522. 9, 7, 5, 3, 1, 0, 2, 4,
  137523. 6, 8, 10,
  137524. };
  137525. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137526. _vq_quantthresh__44u9_p7_1,
  137527. _vq_quantmap__44u9_p7_1,
  137528. 11,
  137529. 11
  137530. };
  137531. static static_codebook _44u9_p7_1 = {
  137532. 2, 121,
  137533. _vq_lengthlist__44u9_p7_1,
  137534. 1, -531365888, 1611661312, 4, 0,
  137535. _vq_quantlist__44u9_p7_1,
  137536. NULL,
  137537. &_vq_auxt__44u9_p7_1,
  137538. NULL,
  137539. 0
  137540. };
  137541. static long _vq_quantlist__44u9_p8_0[] = {
  137542. 7,
  137543. 6,
  137544. 8,
  137545. 5,
  137546. 9,
  137547. 4,
  137548. 10,
  137549. 3,
  137550. 11,
  137551. 2,
  137552. 12,
  137553. 1,
  137554. 13,
  137555. 0,
  137556. 14,
  137557. };
  137558. static long _vq_lengthlist__44u9_p8_0[] = {
  137559. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137560. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137561. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137562. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137563. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137564. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137565. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137566. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137567. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137568. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137569. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137570. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137571. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137572. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137573. 15,
  137574. };
  137575. static float _vq_quantthresh__44u9_p8_0[] = {
  137576. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137577. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137578. };
  137579. static long _vq_quantmap__44u9_p8_0[] = {
  137580. 13, 11, 9, 7, 5, 3, 1, 0,
  137581. 2, 4, 6, 8, 10, 12, 14,
  137582. };
  137583. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137584. _vq_quantthresh__44u9_p8_0,
  137585. _vq_quantmap__44u9_p8_0,
  137586. 15,
  137587. 15
  137588. };
  137589. static static_codebook _44u9_p8_0 = {
  137590. 2, 225,
  137591. _vq_lengthlist__44u9_p8_0,
  137592. 1, -520986624, 1620377600, 4, 0,
  137593. _vq_quantlist__44u9_p8_0,
  137594. NULL,
  137595. &_vq_auxt__44u9_p8_0,
  137596. NULL,
  137597. 0
  137598. };
  137599. static long _vq_quantlist__44u9_p8_1[] = {
  137600. 10,
  137601. 9,
  137602. 11,
  137603. 8,
  137604. 12,
  137605. 7,
  137606. 13,
  137607. 6,
  137608. 14,
  137609. 5,
  137610. 15,
  137611. 4,
  137612. 16,
  137613. 3,
  137614. 17,
  137615. 2,
  137616. 18,
  137617. 1,
  137618. 19,
  137619. 0,
  137620. 20,
  137621. };
  137622. static long _vq_lengthlist__44u9_p8_1[] = {
  137623. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137624. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137625. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137626. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137627. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137628. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137629. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137630. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137631. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137632. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137633. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137634. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137635. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137636. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137637. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137638. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137639. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137640. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137641. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137642. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137643. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137644. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137645. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137646. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137647. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137648. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137649. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137650. 10,10,10,10,10,10,10,10,10,
  137651. };
  137652. static float _vq_quantthresh__44u9_p8_1[] = {
  137653. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137654. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137655. 6.5, 7.5, 8.5, 9.5,
  137656. };
  137657. static long _vq_quantmap__44u9_p8_1[] = {
  137658. 19, 17, 15, 13, 11, 9, 7, 5,
  137659. 3, 1, 0, 2, 4, 6, 8, 10,
  137660. 12, 14, 16, 18, 20,
  137661. };
  137662. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137663. _vq_quantthresh__44u9_p8_1,
  137664. _vq_quantmap__44u9_p8_1,
  137665. 21,
  137666. 21
  137667. };
  137668. static static_codebook _44u9_p8_1 = {
  137669. 2, 441,
  137670. _vq_lengthlist__44u9_p8_1,
  137671. 1, -529268736, 1611661312, 5, 0,
  137672. _vq_quantlist__44u9_p8_1,
  137673. NULL,
  137674. &_vq_auxt__44u9_p8_1,
  137675. NULL,
  137676. 0
  137677. };
  137678. static long _vq_quantlist__44u9_p9_0[] = {
  137679. 7,
  137680. 6,
  137681. 8,
  137682. 5,
  137683. 9,
  137684. 4,
  137685. 10,
  137686. 3,
  137687. 11,
  137688. 2,
  137689. 12,
  137690. 1,
  137691. 13,
  137692. 0,
  137693. 14,
  137694. };
  137695. static long _vq_lengthlist__44u9_p9_0[] = {
  137696. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137697. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137698. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137699. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137700. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137701. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137702. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137703. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137704. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137705. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137706. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137707. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137708. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137709. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137710. 10,
  137711. };
  137712. static float _vq_quantthresh__44u9_p9_0[] = {
  137713. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137714. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137715. };
  137716. static long _vq_quantmap__44u9_p9_0[] = {
  137717. 13, 11, 9, 7, 5, 3, 1, 0,
  137718. 2, 4, 6, 8, 10, 12, 14,
  137719. };
  137720. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137721. _vq_quantthresh__44u9_p9_0,
  137722. _vq_quantmap__44u9_p9_0,
  137723. 15,
  137724. 15
  137725. };
  137726. static static_codebook _44u9_p9_0 = {
  137727. 2, 225,
  137728. _vq_lengthlist__44u9_p9_0,
  137729. 1, -510036736, 1631393792, 4, 0,
  137730. _vq_quantlist__44u9_p9_0,
  137731. NULL,
  137732. &_vq_auxt__44u9_p9_0,
  137733. NULL,
  137734. 0
  137735. };
  137736. static long _vq_quantlist__44u9_p9_1[] = {
  137737. 9,
  137738. 8,
  137739. 10,
  137740. 7,
  137741. 11,
  137742. 6,
  137743. 12,
  137744. 5,
  137745. 13,
  137746. 4,
  137747. 14,
  137748. 3,
  137749. 15,
  137750. 2,
  137751. 16,
  137752. 1,
  137753. 17,
  137754. 0,
  137755. 18,
  137756. };
  137757. static long _vq_lengthlist__44u9_p9_1[] = {
  137758. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137759. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137760. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137761. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137762. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137763. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137764. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137765. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137766. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137767. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137768. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137769. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137770. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137771. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137772. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137773. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137774. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137775. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137776. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137777. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137778. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137779. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137780. 17,17,15,17,15,17,16,16,17,
  137781. };
  137782. static float _vq_quantthresh__44u9_p9_1[] = {
  137783. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137784. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137785. 367.5, 416.5,
  137786. };
  137787. static long _vq_quantmap__44u9_p9_1[] = {
  137788. 17, 15, 13, 11, 9, 7, 5, 3,
  137789. 1, 0, 2, 4, 6, 8, 10, 12,
  137790. 14, 16, 18,
  137791. };
  137792. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137793. _vq_quantthresh__44u9_p9_1,
  137794. _vq_quantmap__44u9_p9_1,
  137795. 19,
  137796. 19
  137797. };
  137798. static static_codebook _44u9_p9_1 = {
  137799. 2, 361,
  137800. _vq_lengthlist__44u9_p9_1,
  137801. 1, -518287360, 1622704128, 5, 0,
  137802. _vq_quantlist__44u9_p9_1,
  137803. NULL,
  137804. &_vq_auxt__44u9_p9_1,
  137805. NULL,
  137806. 0
  137807. };
  137808. static long _vq_quantlist__44u9_p9_2[] = {
  137809. 24,
  137810. 23,
  137811. 25,
  137812. 22,
  137813. 26,
  137814. 21,
  137815. 27,
  137816. 20,
  137817. 28,
  137818. 19,
  137819. 29,
  137820. 18,
  137821. 30,
  137822. 17,
  137823. 31,
  137824. 16,
  137825. 32,
  137826. 15,
  137827. 33,
  137828. 14,
  137829. 34,
  137830. 13,
  137831. 35,
  137832. 12,
  137833. 36,
  137834. 11,
  137835. 37,
  137836. 10,
  137837. 38,
  137838. 9,
  137839. 39,
  137840. 8,
  137841. 40,
  137842. 7,
  137843. 41,
  137844. 6,
  137845. 42,
  137846. 5,
  137847. 43,
  137848. 4,
  137849. 44,
  137850. 3,
  137851. 45,
  137852. 2,
  137853. 46,
  137854. 1,
  137855. 47,
  137856. 0,
  137857. 48,
  137858. };
  137859. static long _vq_lengthlist__44u9_p9_2[] = {
  137860. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  137861. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137862. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137863. 7,
  137864. };
  137865. static float _vq_quantthresh__44u9_p9_2[] = {
  137866. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137867. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137868. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137869. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137870. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137871. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137872. };
  137873. static long _vq_quantmap__44u9_p9_2[] = {
  137874. 47, 45, 43, 41, 39, 37, 35, 33,
  137875. 31, 29, 27, 25, 23, 21, 19, 17,
  137876. 15, 13, 11, 9, 7, 5, 3, 1,
  137877. 0, 2, 4, 6, 8, 10, 12, 14,
  137878. 16, 18, 20, 22, 24, 26, 28, 30,
  137879. 32, 34, 36, 38, 40, 42, 44, 46,
  137880. 48,
  137881. };
  137882. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  137883. _vq_quantthresh__44u9_p9_2,
  137884. _vq_quantmap__44u9_p9_2,
  137885. 49,
  137886. 49
  137887. };
  137888. static static_codebook _44u9_p9_2 = {
  137889. 1, 49,
  137890. _vq_lengthlist__44u9_p9_2,
  137891. 1, -526909440, 1611661312, 6, 0,
  137892. _vq_quantlist__44u9_p9_2,
  137893. NULL,
  137894. &_vq_auxt__44u9_p9_2,
  137895. NULL,
  137896. 0
  137897. };
  137898. static long _huff_lengthlist__44un1__long[] = {
  137899. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  137900. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  137901. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  137902. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  137903. };
  137904. static static_codebook _huff_book__44un1__long = {
  137905. 2, 64,
  137906. _huff_lengthlist__44un1__long,
  137907. 0, 0, 0, 0, 0,
  137908. NULL,
  137909. NULL,
  137910. NULL,
  137911. NULL,
  137912. 0
  137913. };
  137914. static long _vq_quantlist__44un1__p1_0[] = {
  137915. 1,
  137916. 0,
  137917. 2,
  137918. };
  137919. static long _vq_lengthlist__44un1__p1_0[] = {
  137920. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  137921. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  137922. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  137923. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  137924. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  137925. 12,
  137926. };
  137927. static float _vq_quantthresh__44un1__p1_0[] = {
  137928. -0.5, 0.5,
  137929. };
  137930. static long _vq_quantmap__44un1__p1_0[] = {
  137931. 1, 0, 2,
  137932. };
  137933. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  137934. _vq_quantthresh__44un1__p1_0,
  137935. _vq_quantmap__44un1__p1_0,
  137936. 3,
  137937. 3
  137938. };
  137939. static static_codebook _44un1__p1_0 = {
  137940. 4, 81,
  137941. _vq_lengthlist__44un1__p1_0,
  137942. 1, -535822336, 1611661312, 2, 0,
  137943. _vq_quantlist__44un1__p1_0,
  137944. NULL,
  137945. &_vq_auxt__44un1__p1_0,
  137946. NULL,
  137947. 0
  137948. };
  137949. static long _vq_quantlist__44un1__p2_0[] = {
  137950. 1,
  137951. 0,
  137952. 2,
  137953. };
  137954. static long _vq_lengthlist__44un1__p2_0[] = {
  137955. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  137956. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  137957. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  137958. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  137959. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  137960. 8,
  137961. };
  137962. static float _vq_quantthresh__44un1__p2_0[] = {
  137963. -0.5, 0.5,
  137964. };
  137965. static long _vq_quantmap__44un1__p2_0[] = {
  137966. 1, 0, 2,
  137967. };
  137968. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  137969. _vq_quantthresh__44un1__p2_0,
  137970. _vq_quantmap__44un1__p2_0,
  137971. 3,
  137972. 3
  137973. };
  137974. static static_codebook _44un1__p2_0 = {
  137975. 4, 81,
  137976. _vq_lengthlist__44un1__p2_0,
  137977. 1, -535822336, 1611661312, 2, 0,
  137978. _vq_quantlist__44un1__p2_0,
  137979. NULL,
  137980. &_vq_auxt__44un1__p2_0,
  137981. NULL,
  137982. 0
  137983. };
  137984. static long _vq_quantlist__44un1__p3_0[] = {
  137985. 2,
  137986. 1,
  137987. 3,
  137988. 0,
  137989. 4,
  137990. };
  137991. static long _vq_lengthlist__44un1__p3_0[] = {
  137992. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  137993. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  137994. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  137995. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  137996. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  137997. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  137998. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  137999. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138000. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138001. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138002. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138003. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138004. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138005. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138006. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138007. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138008. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138009. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138010. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138011. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138012. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138013. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138014. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138015. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138016. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138017. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138018. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138019. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138020. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138021. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138022. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138023. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138024. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138025. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138026. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138027. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138028. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138029. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138030. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138031. 17,
  138032. };
  138033. static float _vq_quantthresh__44un1__p3_0[] = {
  138034. -1.5, -0.5, 0.5, 1.5,
  138035. };
  138036. static long _vq_quantmap__44un1__p3_0[] = {
  138037. 3, 1, 0, 2, 4,
  138038. };
  138039. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138040. _vq_quantthresh__44un1__p3_0,
  138041. _vq_quantmap__44un1__p3_0,
  138042. 5,
  138043. 5
  138044. };
  138045. static static_codebook _44un1__p3_0 = {
  138046. 4, 625,
  138047. _vq_lengthlist__44un1__p3_0,
  138048. 1, -533725184, 1611661312, 3, 0,
  138049. _vq_quantlist__44un1__p3_0,
  138050. NULL,
  138051. &_vq_auxt__44un1__p3_0,
  138052. NULL,
  138053. 0
  138054. };
  138055. static long _vq_quantlist__44un1__p4_0[] = {
  138056. 2,
  138057. 1,
  138058. 3,
  138059. 0,
  138060. 4,
  138061. };
  138062. static long _vq_lengthlist__44un1__p4_0[] = {
  138063. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138064. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138065. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138066. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138067. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138068. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138069. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138070. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138071. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138072. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138073. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138074. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138075. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138076. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138077. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138078. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138079. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138080. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138081. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138082. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138083. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138084. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138085. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138086. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138087. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138088. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138089. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138090. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138091. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138092. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138093. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138094. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138095. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138096. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138097. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138098. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138099. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138100. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138101. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138102. 12,
  138103. };
  138104. static float _vq_quantthresh__44un1__p4_0[] = {
  138105. -1.5, -0.5, 0.5, 1.5,
  138106. };
  138107. static long _vq_quantmap__44un1__p4_0[] = {
  138108. 3, 1, 0, 2, 4,
  138109. };
  138110. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138111. _vq_quantthresh__44un1__p4_0,
  138112. _vq_quantmap__44un1__p4_0,
  138113. 5,
  138114. 5
  138115. };
  138116. static static_codebook _44un1__p4_0 = {
  138117. 4, 625,
  138118. _vq_lengthlist__44un1__p4_0,
  138119. 1, -533725184, 1611661312, 3, 0,
  138120. _vq_quantlist__44un1__p4_0,
  138121. NULL,
  138122. &_vq_auxt__44un1__p4_0,
  138123. NULL,
  138124. 0
  138125. };
  138126. static long _vq_quantlist__44un1__p5_0[] = {
  138127. 4,
  138128. 3,
  138129. 5,
  138130. 2,
  138131. 6,
  138132. 1,
  138133. 7,
  138134. 0,
  138135. 8,
  138136. };
  138137. static long _vq_lengthlist__44un1__p5_0[] = {
  138138. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138139. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138140. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138141. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138142. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138143. 12,
  138144. };
  138145. static float _vq_quantthresh__44un1__p5_0[] = {
  138146. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138147. };
  138148. static long _vq_quantmap__44un1__p5_0[] = {
  138149. 7, 5, 3, 1, 0, 2, 4, 6,
  138150. 8,
  138151. };
  138152. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138153. _vq_quantthresh__44un1__p5_0,
  138154. _vq_quantmap__44un1__p5_0,
  138155. 9,
  138156. 9
  138157. };
  138158. static static_codebook _44un1__p5_0 = {
  138159. 2, 81,
  138160. _vq_lengthlist__44un1__p5_0,
  138161. 1, -531628032, 1611661312, 4, 0,
  138162. _vq_quantlist__44un1__p5_0,
  138163. NULL,
  138164. &_vq_auxt__44un1__p5_0,
  138165. NULL,
  138166. 0
  138167. };
  138168. static long _vq_quantlist__44un1__p6_0[] = {
  138169. 6,
  138170. 5,
  138171. 7,
  138172. 4,
  138173. 8,
  138174. 3,
  138175. 9,
  138176. 2,
  138177. 10,
  138178. 1,
  138179. 11,
  138180. 0,
  138181. 12,
  138182. };
  138183. static long _vq_lengthlist__44un1__p6_0[] = {
  138184. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138185. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138186. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138187. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138188. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138189. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138190. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138191. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138192. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138193. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138194. 16, 0,15,18,18, 0,16, 0, 0,
  138195. };
  138196. static float _vq_quantthresh__44un1__p6_0[] = {
  138197. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138198. 12.5, 17.5, 22.5, 27.5,
  138199. };
  138200. static long _vq_quantmap__44un1__p6_0[] = {
  138201. 11, 9, 7, 5, 3, 1, 0, 2,
  138202. 4, 6, 8, 10, 12,
  138203. };
  138204. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138205. _vq_quantthresh__44un1__p6_0,
  138206. _vq_quantmap__44un1__p6_0,
  138207. 13,
  138208. 13
  138209. };
  138210. static static_codebook _44un1__p6_0 = {
  138211. 2, 169,
  138212. _vq_lengthlist__44un1__p6_0,
  138213. 1, -526516224, 1616117760, 4, 0,
  138214. _vq_quantlist__44un1__p6_0,
  138215. NULL,
  138216. &_vq_auxt__44un1__p6_0,
  138217. NULL,
  138218. 0
  138219. };
  138220. static long _vq_quantlist__44un1__p6_1[] = {
  138221. 2,
  138222. 1,
  138223. 3,
  138224. 0,
  138225. 4,
  138226. };
  138227. static long _vq_lengthlist__44un1__p6_1[] = {
  138228. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138229. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138230. };
  138231. static float _vq_quantthresh__44un1__p6_1[] = {
  138232. -1.5, -0.5, 0.5, 1.5,
  138233. };
  138234. static long _vq_quantmap__44un1__p6_1[] = {
  138235. 3, 1, 0, 2, 4,
  138236. };
  138237. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138238. _vq_quantthresh__44un1__p6_1,
  138239. _vq_quantmap__44un1__p6_1,
  138240. 5,
  138241. 5
  138242. };
  138243. static static_codebook _44un1__p6_1 = {
  138244. 2, 25,
  138245. _vq_lengthlist__44un1__p6_1,
  138246. 1, -533725184, 1611661312, 3, 0,
  138247. _vq_quantlist__44un1__p6_1,
  138248. NULL,
  138249. &_vq_auxt__44un1__p6_1,
  138250. NULL,
  138251. 0
  138252. };
  138253. static long _vq_quantlist__44un1__p7_0[] = {
  138254. 2,
  138255. 1,
  138256. 3,
  138257. 0,
  138258. 4,
  138259. };
  138260. static long _vq_lengthlist__44un1__p7_0[] = {
  138261. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138262. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138264. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138266. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138267. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138268. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138269. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138270. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138271. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138272. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138273. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138274. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138275. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138276. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138278. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138283. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138284. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138285. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138286. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138287. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138288. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138289. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138290. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138291. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138292. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138293. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138294. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138295. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138296. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138297. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138298. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138299. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138300. 10,
  138301. };
  138302. static float _vq_quantthresh__44un1__p7_0[] = {
  138303. -253.5, -84.5, 84.5, 253.5,
  138304. };
  138305. static long _vq_quantmap__44un1__p7_0[] = {
  138306. 3, 1, 0, 2, 4,
  138307. };
  138308. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138309. _vq_quantthresh__44un1__p7_0,
  138310. _vq_quantmap__44un1__p7_0,
  138311. 5,
  138312. 5
  138313. };
  138314. static static_codebook _44un1__p7_0 = {
  138315. 4, 625,
  138316. _vq_lengthlist__44un1__p7_0,
  138317. 1, -518709248, 1626677248, 3, 0,
  138318. _vq_quantlist__44un1__p7_0,
  138319. NULL,
  138320. &_vq_auxt__44un1__p7_0,
  138321. NULL,
  138322. 0
  138323. };
  138324. static long _vq_quantlist__44un1__p7_1[] = {
  138325. 6,
  138326. 5,
  138327. 7,
  138328. 4,
  138329. 8,
  138330. 3,
  138331. 9,
  138332. 2,
  138333. 10,
  138334. 1,
  138335. 11,
  138336. 0,
  138337. 12,
  138338. };
  138339. static long _vq_lengthlist__44un1__p7_1[] = {
  138340. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138341. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138342. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138343. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138344. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138345. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138346. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138347. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138348. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138349. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138350. 12,13,13,12,13,13,14,14,14,
  138351. };
  138352. static float _vq_quantthresh__44un1__p7_1[] = {
  138353. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138354. 32.5, 45.5, 58.5, 71.5,
  138355. };
  138356. static long _vq_quantmap__44un1__p7_1[] = {
  138357. 11, 9, 7, 5, 3, 1, 0, 2,
  138358. 4, 6, 8, 10, 12,
  138359. };
  138360. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138361. _vq_quantthresh__44un1__p7_1,
  138362. _vq_quantmap__44un1__p7_1,
  138363. 13,
  138364. 13
  138365. };
  138366. static static_codebook _44un1__p7_1 = {
  138367. 2, 169,
  138368. _vq_lengthlist__44un1__p7_1,
  138369. 1, -523010048, 1618608128, 4, 0,
  138370. _vq_quantlist__44un1__p7_1,
  138371. NULL,
  138372. &_vq_auxt__44un1__p7_1,
  138373. NULL,
  138374. 0
  138375. };
  138376. static long _vq_quantlist__44un1__p7_2[] = {
  138377. 6,
  138378. 5,
  138379. 7,
  138380. 4,
  138381. 8,
  138382. 3,
  138383. 9,
  138384. 2,
  138385. 10,
  138386. 1,
  138387. 11,
  138388. 0,
  138389. 12,
  138390. };
  138391. static long _vq_lengthlist__44un1__p7_2[] = {
  138392. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138393. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138394. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138395. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138396. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138397. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138398. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138399. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138400. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138401. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138402. 9, 9, 9,10,10,10,10,10,10,
  138403. };
  138404. static float _vq_quantthresh__44un1__p7_2[] = {
  138405. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138406. 2.5, 3.5, 4.5, 5.5,
  138407. };
  138408. static long _vq_quantmap__44un1__p7_2[] = {
  138409. 11, 9, 7, 5, 3, 1, 0, 2,
  138410. 4, 6, 8, 10, 12,
  138411. };
  138412. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138413. _vq_quantthresh__44un1__p7_2,
  138414. _vq_quantmap__44un1__p7_2,
  138415. 13,
  138416. 13
  138417. };
  138418. static static_codebook _44un1__p7_2 = {
  138419. 2, 169,
  138420. _vq_lengthlist__44un1__p7_2,
  138421. 1, -531103744, 1611661312, 4, 0,
  138422. _vq_quantlist__44un1__p7_2,
  138423. NULL,
  138424. &_vq_auxt__44un1__p7_2,
  138425. NULL,
  138426. 0
  138427. };
  138428. static long _huff_lengthlist__44un1__short[] = {
  138429. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138430. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138431. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138432. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138433. };
  138434. static static_codebook _huff_book__44un1__short = {
  138435. 2, 64,
  138436. _huff_lengthlist__44un1__short,
  138437. 0, 0, 0, 0, 0,
  138438. NULL,
  138439. NULL,
  138440. NULL,
  138441. NULL,
  138442. 0
  138443. };
  138444. /*** End of inlined file: res_books_uncoupled.h ***/
  138445. static vorbis_info_residue0 _residue_44_low_un={
  138446. 0,-1, -1, 8,-1,
  138447. {0},
  138448. {-1},
  138449. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138450. { -1, 25, -1, 45, -1, -1, -1}
  138451. };
  138452. static vorbis_info_residue0 _residue_44_mid_un={
  138453. 0,-1, -1, 10,-1,
  138454. {0},
  138455. {-1},
  138456. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138457. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138458. };
  138459. static vorbis_info_residue0 _residue_44_hi_un={
  138460. 0,-1, -1, 10,-1,
  138461. {0},
  138462. {-1},
  138463. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138464. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138465. };
  138466. static vorbis_info_mapping0 _map_nominal_u[2]={
  138467. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138468. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138469. };
  138470. static static_bookblock _resbook_44u_n1={
  138471. {
  138472. {0},
  138473. {0,0,&_44un1__p1_0},
  138474. {0,0,&_44un1__p2_0},
  138475. {0,0,&_44un1__p3_0},
  138476. {0,0,&_44un1__p4_0},
  138477. {0,0,&_44un1__p5_0},
  138478. {&_44un1__p6_0,&_44un1__p6_1},
  138479. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138480. }
  138481. };
  138482. static static_bookblock _resbook_44u_0={
  138483. {
  138484. {0},
  138485. {0,0,&_44u0__p1_0},
  138486. {0,0,&_44u0__p2_0},
  138487. {0,0,&_44u0__p3_0},
  138488. {0,0,&_44u0__p4_0},
  138489. {0,0,&_44u0__p5_0},
  138490. {&_44u0__p6_0,&_44u0__p6_1},
  138491. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138492. }
  138493. };
  138494. static static_bookblock _resbook_44u_1={
  138495. {
  138496. {0},
  138497. {0,0,&_44u1__p1_0},
  138498. {0,0,&_44u1__p2_0},
  138499. {0,0,&_44u1__p3_0},
  138500. {0,0,&_44u1__p4_0},
  138501. {0,0,&_44u1__p5_0},
  138502. {&_44u1__p6_0,&_44u1__p6_1},
  138503. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138504. }
  138505. };
  138506. static static_bookblock _resbook_44u_2={
  138507. {
  138508. {0},
  138509. {0,0,&_44u2__p1_0},
  138510. {0,0,&_44u2__p2_0},
  138511. {0,0,&_44u2__p3_0},
  138512. {0,0,&_44u2__p4_0},
  138513. {0,0,&_44u2__p5_0},
  138514. {&_44u2__p6_0,&_44u2__p6_1},
  138515. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138516. }
  138517. };
  138518. static static_bookblock _resbook_44u_3={
  138519. {
  138520. {0},
  138521. {0,0,&_44u3__p1_0},
  138522. {0,0,&_44u3__p2_0},
  138523. {0,0,&_44u3__p3_0},
  138524. {0,0,&_44u3__p4_0},
  138525. {0,0,&_44u3__p5_0},
  138526. {&_44u3__p6_0,&_44u3__p6_1},
  138527. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138528. }
  138529. };
  138530. static static_bookblock _resbook_44u_4={
  138531. {
  138532. {0},
  138533. {0,0,&_44u4__p1_0},
  138534. {0,0,&_44u4__p2_0},
  138535. {0,0,&_44u4__p3_0},
  138536. {0,0,&_44u4__p4_0},
  138537. {0,0,&_44u4__p5_0},
  138538. {&_44u4__p6_0,&_44u4__p6_1},
  138539. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138540. }
  138541. };
  138542. static static_bookblock _resbook_44u_5={
  138543. {
  138544. {0},
  138545. {0,0,&_44u5__p1_0},
  138546. {0,0,&_44u5__p2_0},
  138547. {0,0,&_44u5__p3_0},
  138548. {0,0,&_44u5__p4_0},
  138549. {0,0,&_44u5__p5_0},
  138550. {0,0,&_44u5__p6_0},
  138551. {&_44u5__p7_0,&_44u5__p7_1},
  138552. {&_44u5__p8_0,&_44u5__p8_1},
  138553. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138554. }
  138555. };
  138556. static static_bookblock _resbook_44u_6={
  138557. {
  138558. {0},
  138559. {0,0,&_44u6__p1_0},
  138560. {0,0,&_44u6__p2_0},
  138561. {0,0,&_44u6__p3_0},
  138562. {0,0,&_44u6__p4_0},
  138563. {0,0,&_44u6__p5_0},
  138564. {0,0,&_44u6__p6_0},
  138565. {&_44u6__p7_0,&_44u6__p7_1},
  138566. {&_44u6__p8_0,&_44u6__p8_1},
  138567. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138568. }
  138569. };
  138570. static static_bookblock _resbook_44u_7={
  138571. {
  138572. {0},
  138573. {0,0,&_44u7__p1_0},
  138574. {0,0,&_44u7__p2_0},
  138575. {0,0,&_44u7__p3_0},
  138576. {0,0,&_44u7__p4_0},
  138577. {0,0,&_44u7__p5_0},
  138578. {0,0,&_44u7__p6_0},
  138579. {&_44u7__p7_0,&_44u7__p7_1},
  138580. {&_44u7__p8_0,&_44u7__p8_1},
  138581. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138582. }
  138583. };
  138584. static static_bookblock _resbook_44u_8={
  138585. {
  138586. {0},
  138587. {0,0,&_44u8_p1_0},
  138588. {0,0,&_44u8_p2_0},
  138589. {0,0,&_44u8_p3_0},
  138590. {0,0,&_44u8_p4_0},
  138591. {&_44u8_p5_0,&_44u8_p5_1},
  138592. {&_44u8_p6_0,&_44u8_p6_1},
  138593. {&_44u8_p7_0,&_44u8_p7_1},
  138594. {&_44u8_p8_0,&_44u8_p8_1},
  138595. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138596. }
  138597. };
  138598. static static_bookblock _resbook_44u_9={
  138599. {
  138600. {0},
  138601. {0,0,&_44u9_p1_0},
  138602. {0,0,&_44u9_p2_0},
  138603. {0,0,&_44u9_p3_0},
  138604. {0,0,&_44u9_p4_0},
  138605. {&_44u9_p5_0,&_44u9_p5_1},
  138606. {&_44u9_p6_0,&_44u9_p6_1},
  138607. {&_44u9_p7_0,&_44u9_p7_1},
  138608. {&_44u9_p8_0,&_44u9_p8_1},
  138609. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138610. }
  138611. };
  138612. static vorbis_residue_template _res_44u_n1[]={
  138613. {1,0, &_residue_44_low_un,
  138614. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138615. &_resbook_44u_n1,&_resbook_44u_n1},
  138616. {1,0, &_residue_44_low_un,
  138617. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138618. &_resbook_44u_n1,&_resbook_44u_n1}
  138619. };
  138620. static vorbis_residue_template _res_44u_0[]={
  138621. {1,0, &_residue_44_low_un,
  138622. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138623. &_resbook_44u_0,&_resbook_44u_0},
  138624. {1,0, &_residue_44_low_un,
  138625. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138626. &_resbook_44u_0,&_resbook_44u_0}
  138627. };
  138628. static vorbis_residue_template _res_44u_1[]={
  138629. {1,0, &_residue_44_low_un,
  138630. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138631. &_resbook_44u_1,&_resbook_44u_1},
  138632. {1,0, &_residue_44_low_un,
  138633. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138634. &_resbook_44u_1,&_resbook_44u_1}
  138635. };
  138636. static vorbis_residue_template _res_44u_2[]={
  138637. {1,0, &_residue_44_low_un,
  138638. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138639. &_resbook_44u_2,&_resbook_44u_2},
  138640. {1,0, &_residue_44_low_un,
  138641. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138642. &_resbook_44u_2,&_resbook_44u_2}
  138643. };
  138644. static vorbis_residue_template _res_44u_3[]={
  138645. {1,0, &_residue_44_low_un,
  138646. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138647. &_resbook_44u_3,&_resbook_44u_3},
  138648. {1,0, &_residue_44_low_un,
  138649. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138650. &_resbook_44u_3,&_resbook_44u_3}
  138651. };
  138652. static vorbis_residue_template _res_44u_4[]={
  138653. {1,0, &_residue_44_low_un,
  138654. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138655. &_resbook_44u_4,&_resbook_44u_4},
  138656. {1,0, &_residue_44_low_un,
  138657. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138658. &_resbook_44u_4,&_resbook_44u_4}
  138659. };
  138660. static vorbis_residue_template _res_44u_5[]={
  138661. {1,0, &_residue_44_mid_un,
  138662. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138663. &_resbook_44u_5,&_resbook_44u_5},
  138664. {1,0, &_residue_44_mid_un,
  138665. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138666. &_resbook_44u_5,&_resbook_44u_5}
  138667. };
  138668. static vorbis_residue_template _res_44u_6[]={
  138669. {1,0, &_residue_44_mid_un,
  138670. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138671. &_resbook_44u_6,&_resbook_44u_6},
  138672. {1,0, &_residue_44_mid_un,
  138673. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138674. &_resbook_44u_6,&_resbook_44u_6}
  138675. };
  138676. static vorbis_residue_template _res_44u_7[]={
  138677. {1,0, &_residue_44_mid_un,
  138678. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138679. &_resbook_44u_7,&_resbook_44u_7},
  138680. {1,0, &_residue_44_mid_un,
  138681. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138682. &_resbook_44u_7,&_resbook_44u_7}
  138683. };
  138684. static vorbis_residue_template _res_44u_8[]={
  138685. {1,0, &_residue_44_hi_un,
  138686. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138687. &_resbook_44u_8,&_resbook_44u_8},
  138688. {1,0, &_residue_44_hi_un,
  138689. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138690. &_resbook_44u_8,&_resbook_44u_8}
  138691. };
  138692. static vorbis_residue_template _res_44u_9[]={
  138693. {1,0, &_residue_44_hi_un,
  138694. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138695. &_resbook_44u_9,&_resbook_44u_9},
  138696. {1,0, &_residue_44_hi_un,
  138697. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138698. &_resbook_44u_9,&_resbook_44u_9}
  138699. };
  138700. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138701. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138702. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138703. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138704. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138705. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138706. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138707. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138708. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138709. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138710. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138711. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138712. };
  138713. /*** End of inlined file: residue_44u.h ***/
  138714. static double rate_mapping_44_un[12]={
  138715. 32000.,48000.,60000.,70000.,80000.,86000.,
  138716. 96000.,110000.,120000.,140000.,160000.,240001.
  138717. };
  138718. ve_setup_data_template ve_setup_44_uncoupled={
  138719. 11,
  138720. rate_mapping_44_un,
  138721. quality_mapping_44,
  138722. -1,
  138723. 40000,
  138724. 50000,
  138725. blocksize_short_44,
  138726. blocksize_long_44,
  138727. _psy_tone_masteratt_44,
  138728. _psy_tone_0dB,
  138729. _psy_tone_suppress,
  138730. _vp_tonemask_adj_otherblock,
  138731. _vp_tonemask_adj_longblock,
  138732. _vp_tonemask_adj_otherblock,
  138733. _psy_noiseguards_44,
  138734. _psy_noisebias_impulse,
  138735. _psy_noisebias_padding,
  138736. _psy_noisebias_trans,
  138737. _psy_noisebias_long,
  138738. _psy_noise_suppress,
  138739. _psy_compand_44,
  138740. _psy_compand_short_mapping,
  138741. _psy_compand_long_mapping,
  138742. {_noise_start_short_44,_noise_start_long_44},
  138743. {_noise_part_short_44,_noise_part_long_44},
  138744. _noise_thresh_44,
  138745. _psy_ath_floater,
  138746. _psy_ath_abs,
  138747. _psy_lowpass_44,
  138748. _psy_global_44,
  138749. _global_mapping_44,
  138750. NULL,
  138751. _floor_books,
  138752. _floor,
  138753. _floor_short_mapping_44,
  138754. _floor_long_mapping_44,
  138755. _mapres_template_44_uncoupled
  138756. };
  138757. /*** End of inlined file: setup_44u.h ***/
  138758. /*** Start of inlined file: setup_32.h ***/
  138759. static double rate_mapping_32[12]={
  138760. 18000.,28000.,35000.,45000.,56000.,60000.,
  138761. 75000.,90000.,100000.,115000.,150000.,190000.,
  138762. };
  138763. static double rate_mapping_32_un[12]={
  138764. 30000.,42000.,52000.,64000.,72000.,78000.,
  138765. 86000.,92000.,110000.,120000.,140000.,190000.,
  138766. };
  138767. static double _psy_lowpass_32[12]={
  138768. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138769. };
  138770. ve_setup_data_template ve_setup_32_stereo={
  138771. 11,
  138772. rate_mapping_32,
  138773. quality_mapping_44,
  138774. 2,
  138775. 26000,
  138776. 40000,
  138777. blocksize_short_44,
  138778. blocksize_long_44,
  138779. _psy_tone_masteratt_44,
  138780. _psy_tone_0dB,
  138781. _psy_tone_suppress,
  138782. _vp_tonemask_adj_otherblock,
  138783. _vp_tonemask_adj_longblock,
  138784. _vp_tonemask_adj_otherblock,
  138785. _psy_noiseguards_44,
  138786. _psy_noisebias_impulse,
  138787. _psy_noisebias_padding,
  138788. _psy_noisebias_trans,
  138789. _psy_noisebias_long,
  138790. _psy_noise_suppress,
  138791. _psy_compand_44,
  138792. _psy_compand_short_mapping,
  138793. _psy_compand_long_mapping,
  138794. {_noise_start_short_44,_noise_start_long_44},
  138795. {_noise_part_short_44,_noise_part_long_44},
  138796. _noise_thresh_44,
  138797. _psy_ath_floater,
  138798. _psy_ath_abs,
  138799. _psy_lowpass_32,
  138800. _psy_global_44,
  138801. _global_mapping_44,
  138802. _psy_stereo_modes_44,
  138803. _floor_books,
  138804. _floor,
  138805. _floor_short_mapping_44,
  138806. _floor_long_mapping_44,
  138807. _mapres_template_44_stereo
  138808. };
  138809. ve_setup_data_template ve_setup_32_uncoupled={
  138810. 11,
  138811. rate_mapping_32_un,
  138812. quality_mapping_44,
  138813. -1,
  138814. 26000,
  138815. 40000,
  138816. blocksize_short_44,
  138817. blocksize_long_44,
  138818. _psy_tone_masteratt_44,
  138819. _psy_tone_0dB,
  138820. _psy_tone_suppress,
  138821. _vp_tonemask_adj_otherblock,
  138822. _vp_tonemask_adj_longblock,
  138823. _vp_tonemask_adj_otherblock,
  138824. _psy_noiseguards_44,
  138825. _psy_noisebias_impulse,
  138826. _psy_noisebias_padding,
  138827. _psy_noisebias_trans,
  138828. _psy_noisebias_long,
  138829. _psy_noise_suppress,
  138830. _psy_compand_44,
  138831. _psy_compand_short_mapping,
  138832. _psy_compand_long_mapping,
  138833. {_noise_start_short_44,_noise_start_long_44},
  138834. {_noise_part_short_44,_noise_part_long_44},
  138835. _noise_thresh_44,
  138836. _psy_ath_floater,
  138837. _psy_ath_abs,
  138838. _psy_lowpass_32,
  138839. _psy_global_44,
  138840. _global_mapping_44,
  138841. NULL,
  138842. _floor_books,
  138843. _floor,
  138844. _floor_short_mapping_44,
  138845. _floor_long_mapping_44,
  138846. _mapres_template_44_uncoupled
  138847. };
  138848. /*** End of inlined file: setup_32.h ***/
  138849. /*** Start of inlined file: setup_8.h ***/
  138850. /*** Start of inlined file: psych_8.h ***/
  138851. static att3 _psy_tone_masteratt_8[3]={
  138852. {{ 32, 25, 12}, 0, 0}, /* 0 */
  138853. {{ 30, 25, 12}, 0, 0}, /* 0 */
  138854. {{ 20, 0, -14}, 0, 0}, /* 0 */
  138855. };
  138856. static vp_adjblock _vp_tonemask_adj_8[3]={
  138857. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138858. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138859. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  138860. };
  138861. static noise3 _psy_noisebias_8[3]={
  138862. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138863. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  138864. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138865. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138866. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  138867. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138868. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  138869. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  138870. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  138871. };
  138872. static adj_stereo _psy_stereo_modes_8[3]={
  138873. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138874. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138875. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138876. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138877. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138878. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138879. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138880. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138881. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138882. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138883. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138884. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138885. };
  138886. static noiseguard _psy_noiseguards_8[2]={
  138887. {10,10,-1},
  138888. {10,10,-1},
  138889. };
  138890. static compandblock _psy_compand_8[2]={
  138891. {{
  138892. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  138893. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  138894. 12,12,13,13,14,14,15, 15, /* 23dB */
  138895. 16,16,17,17,17,18,18, 19, /* 31dB */
  138896. 19,19,20,21,22,23,24, 25, /* 39dB */
  138897. }},
  138898. {{
  138899. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  138900. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  138901. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  138902. 9,10,11,12,13,14,15, 16, /* 31dB */
  138903. 17,18,19,20,21,22,23, 24, /* 39dB */
  138904. }},
  138905. };
  138906. static double _psy_lowpass_8[3]={3.,4.,4.};
  138907. static int _noise_start_8[2]={
  138908. 64,64,
  138909. };
  138910. static int _noise_part_8[2]={
  138911. 8,8,
  138912. };
  138913. static int _psy_ath_floater_8[3]={
  138914. -100,-100,-105,
  138915. };
  138916. static int _psy_ath_abs_8[3]={
  138917. -130,-130,-140,
  138918. };
  138919. /*** End of inlined file: psych_8.h ***/
  138920. /*** Start of inlined file: residue_8.h ***/
  138921. static static_bookblock _resbook_8s_0={
  138922. {
  138923. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  138924. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  138925. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  138926. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  138927. }
  138928. };
  138929. static static_bookblock _resbook_8s_1={
  138930. {
  138931. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  138932. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  138933. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  138934. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  138935. }
  138936. };
  138937. static vorbis_residue_template _res_8s_0[]={
  138938. {2,0, &_residue_44_mid,
  138939. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  138940. &_resbook_8s_0,&_resbook_8s_0},
  138941. };
  138942. static vorbis_residue_template _res_8s_1[]={
  138943. {2,0, &_residue_44_mid,
  138944. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  138945. &_resbook_8s_1,&_resbook_8s_1},
  138946. };
  138947. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  138948. { _map_nominal, _res_8s_0 }, /* 0 */
  138949. { _map_nominal, _res_8s_1 }, /* 1 */
  138950. };
  138951. static static_bookblock _resbook_8u_0={
  138952. {
  138953. {0},
  138954. {0,0,&_8u0__p1_0},
  138955. {0,0,&_8u0__p2_0},
  138956. {0,0,&_8u0__p3_0},
  138957. {0,0,&_8u0__p4_0},
  138958. {0,0,&_8u0__p5_0},
  138959. {&_8u0__p6_0,&_8u0__p6_1},
  138960. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  138961. }
  138962. };
  138963. static static_bookblock _resbook_8u_1={
  138964. {
  138965. {0},
  138966. {0,0,&_8u1__p1_0},
  138967. {0,0,&_8u1__p2_0},
  138968. {0,0,&_8u1__p3_0},
  138969. {0,0,&_8u1__p4_0},
  138970. {0,0,&_8u1__p5_0},
  138971. {0,0,&_8u1__p6_0},
  138972. {&_8u1__p7_0,&_8u1__p7_1},
  138973. {&_8u1__p8_0,&_8u1__p8_1},
  138974. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  138975. }
  138976. };
  138977. static vorbis_residue_template _res_8u_0[]={
  138978. {1,0, &_residue_44_low_un,
  138979. &_huff_book__8u0__single,&_huff_book__8u0__single,
  138980. &_resbook_8u_0,&_resbook_8u_0},
  138981. };
  138982. static vorbis_residue_template _res_8u_1[]={
  138983. {1,0, &_residue_44_mid_un,
  138984. &_huff_book__8u1__single,&_huff_book__8u1__single,
  138985. &_resbook_8u_1,&_resbook_8u_1},
  138986. };
  138987. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  138988. { _map_nominal_u, _res_8u_0 }, /* 0 */
  138989. { _map_nominal_u, _res_8u_1 }, /* 1 */
  138990. };
  138991. /*** End of inlined file: residue_8.h ***/
  138992. static int blocksize_8[2]={
  138993. 512,512
  138994. };
  138995. static int _floor_mapping_8[2]={
  138996. 6,6,
  138997. };
  138998. static double rate_mapping_8[3]={
  138999. 6000.,9000.,32000.,
  139000. };
  139001. static double rate_mapping_8_uncoupled[3]={
  139002. 8000.,14000.,42000.,
  139003. };
  139004. static double quality_mapping_8[3]={
  139005. -.1,.0,1.
  139006. };
  139007. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139008. static double _global_mapping_8[3]={ 1., 2., 3. };
  139009. ve_setup_data_template ve_setup_8_stereo={
  139010. 2,
  139011. rate_mapping_8,
  139012. quality_mapping_8,
  139013. 2,
  139014. 8000,
  139015. 9000,
  139016. blocksize_8,
  139017. blocksize_8,
  139018. _psy_tone_masteratt_8,
  139019. _psy_tone_0dB,
  139020. _psy_tone_suppress,
  139021. _vp_tonemask_adj_8,
  139022. NULL,
  139023. _vp_tonemask_adj_8,
  139024. _psy_noiseguards_8,
  139025. _psy_noisebias_8,
  139026. _psy_noisebias_8,
  139027. NULL,
  139028. NULL,
  139029. _psy_noise_suppress,
  139030. _psy_compand_8,
  139031. _psy_compand_8_mapping,
  139032. NULL,
  139033. {_noise_start_8,_noise_start_8},
  139034. {_noise_part_8,_noise_part_8},
  139035. _noise_thresh_5only,
  139036. _psy_ath_floater_8,
  139037. _psy_ath_abs_8,
  139038. _psy_lowpass_8,
  139039. _psy_global_44,
  139040. _global_mapping_8,
  139041. _psy_stereo_modes_8,
  139042. _floor_books,
  139043. _floor,
  139044. _floor_mapping_8,
  139045. NULL,
  139046. _mapres_template_8_stereo
  139047. };
  139048. ve_setup_data_template ve_setup_8_uncoupled={
  139049. 2,
  139050. rate_mapping_8_uncoupled,
  139051. quality_mapping_8,
  139052. -1,
  139053. 8000,
  139054. 9000,
  139055. blocksize_8,
  139056. blocksize_8,
  139057. _psy_tone_masteratt_8,
  139058. _psy_tone_0dB,
  139059. _psy_tone_suppress,
  139060. _vp_tonemask_adj_8,
  139061. NULL,
  139062. _vp_tonemask_adj_8,
  139063. _psy_noiseguards_8,
  139064. _psy_noisebias_8,
  139065. _psy_noisebias_8,
  139066. NULL,
  139067. NULL,
  139068. _psy_noise_suppress,
  139069. _psy_compand_8,
  139070. _psy_compand_8_mapping,
  139071. NULL,
  139072. {_noise_start_8,_noise_start_8},
  139073. {_noise_part_8,_noise_part_8},
  139074. _noise_thresh_5only,
  139075. _psy_ath_floater_8,
  139076. _psy_ath_abs_8,
  139077. _psy_lowpass_8,
  139078. _psy_global_44,
  139079. _global_mapping_8,
  139080. _psy_stereo_modes_8,
  139081. _floor_books,
  139082. _floor,
  139083. _floor_mapping_8,
  139084. NULL,
  139085. _mapres_template_8_uncoupled
  139086. };
  139087. /*** End of inlined file: setup_8.h ***/
  139088. /*** Start of inlined file: setup_11.h ***/
  139089. /*** Start of inlined file: psych_11.h ***/
  139090. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139091. static att3 _psy_tone_masteratt_11[3]={
  139092. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139093. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139094. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139095. };
  139096. static vp_adjblock _vp_tonemask_adj_11[3]={
  139097. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139098. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139099. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139100. };
  139101. static noise3 _psy_noisebias_11[3]={
  139102. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139103. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139104. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139105. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139106. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139107. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139108. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139109. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139110. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139111. };
  139112. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139113. /*** End of inlined file: psych_11.h ***/
  139114. static int blocksize_11[2]={
  139115. 512,512
  139116. };
  139117. static int _floor_mapping_11[2]={
  139118. 6,6,
  139119. };
  139120. static double rate_mapping_11[3]={
  139121. 8000.,13000.,44000.,
  139122. };
  139123. static double rate_mapping_11_uncoupled[3]={
  139124. 12000.,20000.,50000.,
  139125. };
  139126. static double quality_mapping_11[3]={
  139127. -.1,.0,1.
  139128. };
  139129. ve_setup_data_template ve_setup_11_stereo={
  139130. 2,
  139131. rate_mapping_11,
  139132. quality_mapping_11,
  139133. 2,
  139134. 9000,
  139135. 15000,
  139136. blocksize_11,
  139137. blocksize_11,
  139138. _psy_tone_masteratt_11,
  139139. _psy_tone_0dB,
  139140. _psy_tone_suppress,
  139141. _vp_tonemask_adj_11,
  139142. NULL,
  139143. _vp_tonemask_adj_11,
  139144. _psy_noiseguards_8,
  139145. _psy_noisebias_11,
  139146. _psy_noisebias_11,
  139147. NULL,
  139148. NULL,
  139149. _psy_noise_suppress,
  139150. _psy_compand_8,
  139151. _psy_compand_8_mapping,
  139152. NULL,
  139153. {_noise_start_8,_noise_start_8},
  139154. {_noise_part_8,_noise_part_8},
  139155. _noise_thresh_11,
  139156. _psy_ath_floater_8,
  139157. _psy_ath_abs_8,
  139158. _psy_lowpass_11,
  139159. _psy_global_44,
  139160. _global_mapping_8,
  139161. _psy_stereo_modes_8,
  139162. _floor_books,
  139163. _floor,
  139164. _floor_mapping_11,
  139165. NULL,
  139166. _mapres_template_8_stereo
  139167. };
  139168. ve_setup_data_template ve_setup_11_uncoupled={
  139169. 2,
  139170. rate_mapping_11_uncoupled,
  139171. quality_mapping_11,
  139172. -1,
  139173. 9000,
  139174. 15000,
  139175. blocksize_11,
  139176. blocksize_11,
  139177. _psy_tone_masteratt_11,
  139178. _psy_tone_0dB,
  139179. _psy_tone_suppress,
  139180. _vp_tonemask_adj_11,
  139181. NULL,
  139182. _vp_tonemask_adj_11,
  139183. _psy_noiseguards_8,
  139184. _psy_noisebias_11,
  139185. _psy_noisebias_11,
  139186. NULL,
  139187. NULL,
  139188. _psy_noise_suppress,
  139189. _psy_compand_8,
  139190. _psy_compand_8_mapping,
  139191. NULL,
  139192. {_noise_start_8,_noise_start_8},
  139193. {_noise_part_8,_noise_part_8},
  139194. _noise_thresh_11,
  139195. _psy_ath_floater_8,
  139196. _psy_ath_abs_8,
  139197. _psy_lowpass_11,
  139198. _psy_global_44,
  139199. _global_mapping_8,
  139200. _psy_stereo_modes_8,
  139201. _floor_books,
  139202. _floor,
  139203. _floor_mapping_11,
  139204. NULL,
  139205. _mapres_template_8_uncoupled
  139206. };
  139207. /*** End of inlined file: setup_11.h ***/
  139208. /*** Start of inlined file: setup_16.h ***/
  139209. /*** Start of inlined file: psych_16.h ***/
  139210. static adj_stereo _psy_stereo_modes_16[4]={
  139211. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139212. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139213. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139214. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139215. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139216. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139217. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139218. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139219. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139220. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139221. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139222. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139223. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139224. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139225. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139226. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139227. };
  139228. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139229. static att3 _psy_tone_masteratt_16[4]={
  139230. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139231. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139232. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139233. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139234. };
  139235. static vp_adjblock _vp_tonemask_adj_16[4]={
  139236. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139237. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139238. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139239. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139240. };
  139241. static noise3 _psy_noisebias_16_short[4]={
  139242. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139243. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139244. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139245. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139246. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139247. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139248. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139249. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139250. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139251. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139252. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139253. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139254. };
  139255. static noise3 _psy_noisebias_16_impulse[4]={
  139256. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139257. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139258. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139259. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139260. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139261. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139262. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139263. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139264. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139265. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139266. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139267. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139268. };
  139269. static noise3 _psy_noisebias_16[4]={
  139270. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139271. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139272. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139273. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139274. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139275. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139276. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139277. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139278. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139279. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139280. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139281. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139282. };
  139283. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139284. static int _noise_start_16[3]={ 256,256,9999 };
  139285. static int _noise_part_16[4]={ 8,8,8,8 };
  139286. static int _psy_ath_floater_16[4]={
  139287. -100,-100,-100,-105,
  139288. };
  139289. static int _psy_ath_abs_16[4]={
  139290. -130,-130,-130,-140,
  139291. };
  139292. /*** End of inlined file: psych_16.h ***/
  139293. /*** Start of inlined file: residue_16.h ***/
  139294. static static_bookblock _resbook_16s_0={
  139295. {
  139296. {0},
  139297. {0,0,&_16c0_s_p1_0},
  139298. {0,0,&_16c0_s_p2_0},
  139299. {0,0,&_16c0_s_p3_0},
  139300. {0,0,&_16c0_s_p4_0},
  139301. {0,0,&_16c0_s_p5_0},
  139302. {0,0,&_16c0_s_p6_0},
  139303. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139304. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139305. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139306. }
  139307. };
  139308. static static_bookblock _resbook_16s_1={
  139309. {
  139310. {0},
  139311. {0,0,&_16c1_s_p1_0},
  139312. {0,0,&_16c1_s_p2_0},
  139313. {0,0,&_16c1_s_p3_0},
  139314. {0,0,&_16c1_s_p4_0},
  139315. {0,0,&_16c1_s_p5_0},
  139316. {0,0,&_16c1_s_p6_0},
  139317. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139318. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139319. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139320. }
  139321. };
  139322. static static_bookblock _resbook_16s_2={
  139323. {
  139324. {0},
  139325. {0,0,&_16c2_s_p1_0},
  139326. {0,0,&_16c2_s_p2_0},
  139327. {0,0,&_16c2_s_p3_0},
  139328. {0,0,&_16c2_s_p4_0},
  139329. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139330. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139331. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139332. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139333. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139334. }
  139335. };
  139336. static vorbis_residue_template _res_16s_0[]={
  139337. {2,0, &_residue_44_mid,
  139338. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139339. &_resbook_16s_0,&_resbook_16s_0},
  139340. };
  139341. static vorbis_residue_template _res_16s_1[]={
  139342. {2,0, &_residue_44_mid,
  139343. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139344. &_resbook_16s_1,&_resbook_16s_1},
  139345. {2,0, &_residue_44_mid,
  139346. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139347. &_resbook_16s_1,&_resbook_16s_1}
  139348. };
  139349. static vorbis_residue_template _res_16s_2[]={
  139350. {2,0, &_residue_44_high,
  139351. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139352. &_resbook_16s_2,&_resbook_16s_2},
  139353. {2,0, &_residue_44_high,
  139354. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139355. &_resbook_16s_2,&_resbook_16s_2}
  139356. };
  139357. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139358. { _map_nominal, _res_16s_0 }, /* 0 */
  139359. { _map_nominal, _res_16s_1 }, /* 1 */
  139360. { _map_nominal, _res_16s_2 }, /* 2 */
  139361. };
  139362. static static_bookblock _resbook_16u_0={
  139363. {
  139364. {0},
  139365. {0,0,&_16u0__p1_0},
  139366. {0,0,&_16u0__p2_0},
  139367. {0,0,&_16u0__p3_0},
  139368. {0,0,&_16u0__p4_0},
  139369. {0,0,&_16u0__p5_0},
  139370. {&_16u0__p6_0,&_16u0__p6_1},
  139371. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139372. }
  139373. };
  139374. static static_bookblock _resbook_16u_1={
  139375. {
  139376. {0},
  139377. {0,0,&_16u1__p1_0},
  139378. {0,0,&_16u1__p2_0},
  139379. {0,0,&_16u1__p3_0},
  139380. {0,0,&_16u1__p4_0},
  139381. {0,0,&_16u1__p5_0},
  139382. {0,0,&_16u1__p6_0},
  139383. {&_16u1__p7_0,&_16u1__p7_1},
  139384. {&_16u1__p8_0,&_16u1__p8_1},
  139385. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139386. }
  139387. };
  139388. static static_bookblock _resbook_16u_2={
  139389. {
  139390. {0},
  139391. {0,0,&_16u2_p1_0},
  139392. {0,0,&_16u2_p2_0},
  139393. {0,0,&_16u2_p3_0},
  139394. {0,0,&_16u2_p4_0},
  139395. {&_16u2_p5_0,&_16u2_p5_1},
  139396. {&_16u2_p6_0,&_16u2_p6_1},
  139397. {&_16u2_p7_0,&_16u2_p7_1},
  139398. {&_16u2_p8_0,&_16u2_p8_1},
  139399. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139400. }
  139401. };
  139402. static vorbis_residue_template _res_16u_0[]={
  139403. {1,0, &_residue_44_low_un,
  139404. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139405. &_resbook_16u_0,&_resbook_16u_0},
  139406. };
  139407. static vorbis_residue_template _res_16u_1[]={
  139408. {1,0, &_residue_44_mid_un,
  139409. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139410. &_resbook_16u_1,&_resbook_16u_1},
  139411. {1,0, &_residue_44_mid_un,
  139412. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139413. &_resbook_16u_1,&_resbook_16u_1}
  139414. };
  139415. static vorbis_residue_template _res_16u_2[]={
  139416. {1,0, &_residue_44_hi_un,
  139417. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139418. &_resbook_16u_2,&_resbook_16u_2},
  139419. {1,0, &_residue_44_hi_un,
  139420. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139421. &_resbook_16u_2,&_resbook_16u_2}
  139422. };
  139423. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139424. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139425. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139426. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139427. };
  139428. /*** End of inlined file: residue_16.h ***/
  139429. static int blocksize_16_short[3]={
  139430. 1024,512,512
  139431. };
  139432. static int blocksize_16_long[3]={
  139433. 1024,1024,1024
  139434. };
  139435. static int _floor_mapping_16_short[3]={
  139436. 9,3,3
  139437. };
  139438. static int _floor_mapping_16[3]={
  139439. 9,9,9
  139440. };
  139441. static double rate_mapping_16[4]={
  139442. 12000.,20000.,44000.,86000.
  139443. };
  139444. static double rate_mapping_16_uncoupled[4]={
  139445. 16000.,28000.,64000.,100000.
  139446. };
  139447. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139448. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139449. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139450. ve_setup_data_template ve_setup_16_stereo={
  139451. 3,
  139452. rate_mapping_16,
  139453. quality_mapping_16,
  139454. 2,
  139455. 15000,
  139456. 19000,
  139457. blocksize_16_short,
  139458. blocksize_16_long,
  139459. _psy_tone_masteratt_16,
  139460. _psy_tone_0dB,
  139461. _psy_tone_suppress,
  139462. _vp_tonemask_adj_16,
  139463. _vp_tonemask_adj_16,
  139464. _vp_tonemask_adj_16,
  139465. _psy_noiseguards_8,
  139466. _psy_noisebias_16_impulse,
  139467. _psy_noisebias_16_short,
  139468. _psy_noisebias_16_short,
  139469. _psy_noisebias_16,
  139470. _psy_noise_suppress,
  139471. _psy_compand_8,
  139472. _psy_compand_16_mapping,
  139473. _psy_compand_16_mapping,
  139474. {_noise_start_16,_noise_start_16},
  139475. { _noise_part_16, _noise_part_16},
  139476. _noise_thresh_16,
  139477. _psy_ath_floater_16,
  139478. _psy_ath_abs_16,
  139479. _psy_lowpass_16,
  139480. _psy_global_44,
  139481. _global_mapping_16,
  139482. _psy_stereo_modes_16,
  139483. _floor_books,
  139484. _floor,
  139485. _floor_mapping_16_short,
  139486. _floor_mapping_16,
  139487. _mapres_template_16_stereo
  139488. };
  139489. ve_setup_data_template ve_setup_16_uncoupled={
  139490. 3,
  139491. rate_mapping_16_uncoupled,
  139492. quality_mapping_16,
  139493. -1,
  139494. 15000,
  139495. 19000,
  139496. blocksize_16_short,
  139497. blocksize_16_long,
  139498. _psy_tone_masteratt_16,
  139499. _psy_tone_0dB,
  139500. _psy_tone_suppress,
  139501. _vp_tonemask_adj_16,
  139502. _vp_tonemask_adj_16,
  139503. _vp_tonemask_adj_16,
  139504. _psy_noiseguards_8,
  139505. _psy_noisebias_16_impulse,
  139506. _psy_noisebias_16_short,
  139507. _psy_noisebias_16_short,
  139508. _psy_noisebias_16,
  139509. _psy_noise_suppress,
  139510. _psy_compand_8,
  139511. _psy_compand_16_mapping,
  139512. _psy_compand_16_mapping,
  139513. {_noise_start_16,_noise_start_16},
  139514. { _noise_part_16, _noise_part_16},
  139515. _noise_thresh_16,
  139516. _psy_ath_floater_16,
  139517. _psy_ath_abs_16,
  139518. _psy_lowpass_16,
  139519. _psy_global_44,
  139520. _global_mapping_16,
  139521. _psy_stereo_modes_16,
  139522. _floor_books,
  139523. _floor,
  139524. _floor_mapping_16_short,
  139525. _floor_mapping_16,
  139526. _mapres_template_16_uncoupled
  139527. };
  139528. /*** End of inlined file: setup_16.h ***/
  139529. /*** Start of inlined file: setup_22.h ***/
  139530. static double rate_mapping_22[4]={
  139531. 15000.,20000.,44000.,86000.
  139532. };
  139533. static double rate_mapping_22_uncoupled[4]={
  139534. 16000.,28000.,50000.,90000.
  139535. };
  139536. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139537. ve_setup_data_template ve_setup_22_stereo={
  139538. 3,
  139539. rate_mapping_22,
  139540. quality_mapping_16,
  139541. 2,
  139542. 19000,
  139543. 26000,
  139544. blocksize_16_short,
  139545. blocksize_16_long,
  139546. _psy_tone_masteratt_16,
  139547. _psy_tone_0dB,
  139548. _psy_tone_suppress,
  139549. _vp_tonemask_adj_16,
  139550. _vp_tonemask_adj_16,
  139551. _vp_tonemask_adj_16,
  139552. _psy_noiseguards_8,
  139553. _psy_noisebias_16_impulse,
  139554. _psy_noisebias_16_short,
  139555. _psy_noisebias_16_short,
  139556. _psy_noisebias_16,
  139557. _psy_noise_suppress,
  139558. _psy_compand_8,
  139559. _psy_compand_8_mapping,
  139560. _psy_compand_8_mapping,
  139561. {_noise_start_16,_noise_start_16},
  139562. { _noise_part_16, _noise_part_16},
  139563. _noise_thresh_16,
  139564. _psy_ath_floater_16,
  139565. _psy_ath_abs_16,
  139566. _psy_lowpass_22,
  139567. _psy_global_44,
  139568. _global_mapping_16,
  139569. _psy_stereo_modes_16,
  139570. _floor_books,
  139571. _floor,
  139572. _floor_mapping_16_short,
  139573. _floor_mapping_16,
  139574. _mapres_template_16_stereo
  139575. };
  139576. ve_setup_data_template ve_setup_22_uncoupled={
  139577. 3,
  139578. rate_mapping_22_uncoupled,
  139579. quality_mapping_16,
  139580. -1,
  139581. 19000,
  139582. 26000,
  139583. blocksize_16_short,
  139584. blocksize_16_long,
  139585. _psy_tone_masteratt_16,
  139586. _psy_tone_0dB,
  139587. _psy_tone_suppress,
  139588. _vp_tonemask_adj_16,
  139589. _vp_tonemask_adj_16,
  139590. _vp_tonemask_adj_16,
  139591. _psy_noiseguards_8,
  139592. _psy_noisebias_16_impulse,
  139593. _psy_noisebias_16_short,
  139594. _psy_noisebias_16_short,
  139595. _psy_noisebias_16,
  139596. _psy_noise_suppress,
  139597. _psy_compand_8,
  139598. _psy_compand_8_mapping,
  139599. _psy_compand_8_mapping,
  139600. {_noise_start_16,_noise_start_16},
  139601. { _noise_part_16, _noise_part_16},
  139602. _noise_thresh_16,
  139603. _psy_ath_floater_16,
  139604. _psy_ath_abs_16,
  139605. _psy_lowpass_22,
  139606. _psy_global_44,
  139607. _global_mapping_16,
  139608. _psy_stereo_modes_16,
  139609. _floor_books,
  139610. _floor,
  139611. _floor_mapping_16_short,
  139612. _floor_mapping_16,
  139613. _mapres_template_16_uncoupled
  139614. };
  139615. /*** End of inlined file: setup_22.h ***/
  139616. /*** Start of inlined file: setup_X.h ***/
  139617. static double rate_mapping_X[12]={
  139618. -1.,-1.,-1.,-1.,-1.,-1.,
  139619. -1.,-1.,-1.,-1.,-1.,-1.
  139620. };
  139621. ve_setup_data_template ve_setup_X_stereo={
  139622. 11,
  139623. rate_mapping_X,
  139624. quality_mapping_44,
  139625. 2,
  139626. 50000,
  139627. 200000,
  139628. blocksize_short_44,
  139629. blocksize_long_44,
  139630. _psy_tone_masteratt_44,
  139631. _psy_tone_0dB,
  139632. _psy_tone_suppress,
  139633. _vp_tonemask_adj_otherblock,
  139634. _vp_tonemask_adj_longblock,
  139635. _vp_tonemask_adj_otherblock,
  139636. _psy_noiseguards_44,
  139637. _psy_noisebias_impulse,
  139638. _psy_noisebias_padding,
  139639. _psy_noisebias_trans,
  139640. _psy_noisebias_long,
  139641. _psy_noise_suppress,
  139642. _psy_compand_44,
  139643. _psy_compand_short_mapping,
  139644. _psy_compand_long_mapping,
  139645. {_noise_start_short_44,_noise_start_long_44},
  139646. {_noise_part_short_44,_noise_part_long_44},
  139647. _noise_thresh_44,
  139648. _psy_ath_floater,
  139649. _psy_ath_abs,
  139650. _psy_lowpass_44,
  139651. _psy_global_44,
  139652. _global_mapping_44,
  139653. _psy_stereo_modes_44,
  139654. _floor_books,
  139655. _floor,
  139656. _floor_short_mapping_44,
  139657. _floor_long_mapping_44,
  139658. _mapres_template_44_stereo
  139659. };
  139660. ve_setup_data_template ve_setup_X_uncoupled={
  139661. 11,
  139662. rate_mapping_X,
  139663. quality_mapping_44,
  139664. -1,
  139665. 50000,
  139666. 200000,
  139667. blocksize_short_44,
  139668. blocksize_long_44,
  139669. _psy_tone_masteratt_44,
  139670. _psy_tone_0dB,
  139671. _psy_tone_suppress,
  139672. _vp_tonemask_adj_otherblock,
  139673. _vp_tonemask_adj_longblock,
  139674. _vp_tonemask_adj_otherblock,
  139675. _psy_noiseguards_44,
  139676. _psy_noisebias_impulse,
  139677. _psy_noisebias_padding,
  139678. _psy_noisebias_trans,
  139679. _psy_noisebias_long,
  139680. _psy_noise_suppress,
  139681. _psy_compand_44,
  139682. _psy_compand_short_mapping,
  139683. _psy_compand_long_mapping,
  139684. {_noise_start_short_44,_noise_start_long_44},
  139685. {_noise_part_short_44,_noise_part_long_44},
  139686. _noise_thresh_44,
  139687. _psy_ath_floater,
  139688. _psy_ath_abs,
  139689. _psy_lowpass_44,
  139690. _psy_global_44,
  139691. _global_mapping_44,
  139692. NULL,
  139693. _floor_books,
  139694. _floor,
  139695. _floor_short_mapping_44,
  139696. _floor_long_mapping_44,
  139697. _mapres_template_44_uncoupled
  139698. };
  139699. ve_setup_data_template ve_setup_XX_stereo={
  139700. 2,
  139701. rate_mapping_X,
  139702. quality_mapping_8,
  139703. 2,
  139704. 0,
  139705. 8000,
  139706. blocksize_8,
  139707. blocksize_8,
  139708. _psy_tone_masteratt_8,
  139709. _psy_tone_0dB,
  139710. _psy_tone_suppress,
  139711. _vp_tonemask_adj_8,
  139712. NULL,
  139713. _vp_tonemask_adj_8,
  139714. _psy_noiseguards_8,
  139715. _psy_noisebias_8,
  139716. _psy_noisebias_8,
  139717. NULL,
  139718. NULL,
  139719. _psy_noise_suppress,
  139720. _psy_compand_8,
  139721. _psy_compand_8_mapping,
  139722. NULL,
  139723. {_noise_start_8,_noise_start_8},
  139724. {_noise_part_8,_noise_part_8},
  139725. _noise_thresh_5only,
  139726. _psy_ath_floater_8,
  139727. _psy_ath_abs_8,
  139728. _psy_lowpass_8,
  139729. _psy_global_44,
  139730. _global_mapping_8,
  139731. _psy_stereo_modes_8,
  139732. _floor_books,
  139733. _floor,
  139734. _floor_mapping_8,
  139735. NULL,
  139736. _mapres_template_8_stereo
  139737. };
  139738. ve_setup_data_template ve_setup_XX_uncoupled={
  139739. 2,
  139740. rate_mapping_X,
  139741. quality_mapping_8,
  139742. -1,
  139743. 0,
  139744. 8000,
  139745. blocksize_8,
  139746. blocksize_8,
  139747. _psy_tone_masteratt_8,
  139748. _psy_tone_0dB,
  139749. _psy_tone_suppress,
  139750. _vp_tonemask_adj_8,
  139751. NULL,
  139752. _vp_tonemask_adj_8,
  139753. _psy_noiseguards_8,
  139754. _psy_noisebias_8,
  139755. _psy_noisebias_8,
  139756. NULL,
  139757. NULL,
  139758. _psy_noise_suppress,
  139759. _psy_compand_8,
  139760. _psy_compand_8_mapping,
  139761. NULL,
  139762. {_noise_start_8,_noise_start_8},
  139763. {_noise_part_8,_noise_part_8},
  139764. _noise_thresh_5only,
  139765. _psy_ath_floater_8,
  139766. _psy_ath_abs_8,
  139767. _psy_lowpass_8,
  139768. _psy_global_44,
  139769. _global_mapping_8,
  139770. _psy_stereo_modes_8,
  139771. _floor_books,
  139772. _floor,
  139773. _floor_mapping_8,
  139774. NULL,
  139775. _mapres_template_8_uncoupled
  139776. };
  139777. /*** End of inlined file: setup_X.h ***/
  139778. static ve_setup_data_template *setup_list[]={
  139779. &ve_setup_44_stereo,
  139780. &ve_setup_44_uncoupled,
  139781. &ve_setup_32_stereo,
  139782. &ve_setup_32_uncoupled,
  139783. &ve_setup_22_stereo,
  139784. &ve_setup_22_uncoupled,
  139785. &ve_setup_16_stereo,
  139786. &ve_setup_16_uncoupled,
  139787. &ve_setup_11_stereo,
  139788. &ve_setup_11_uncoupled,
  139789. &ve_setup_8_stereo,
  139790. &ve_setup_8_uncoupled,
  139791. &ve_setup_X_stereo,
  139792. &ve_setup_X_uncoupled,
  139793. &ve_setup_XX_stereo,
  139794. &ve_setup_XX_uncoupled,
  139795. 0
  139796. };
  139797. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139798. if(vi && vi->codec_setup){
  139799. vi->version=0;
  139800. vi->channels=ch;
  139801. vi->rate=rate;
  139802. return(0);
  139803. }
  139804. return(OV_EINVAL);
  139805. }
  139806. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139807. static_codebook ***books,
  139808. vorbis_info_floor1 *in,
  139809. int *x){
  139810. int i,k,is=s;
  139811. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  139812. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139813. memcpy(f,in+x[is],sizeof(*f));
  139814. f->n=ci->blocksizes[block]>>1;
  139815. {
  139816. int partitions=f->partitions;
  139817. int maxclass=-1;
  139818. int maxbook=-1;
  139819. for(i=0;i<partitions;i++)
  139820. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  139821. for(i=0;i<=maxclass;i++){
  139822. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  139823. f->class_book[i]+=ci->books;
  139824. for(k=0;k<(1<<f->class_subs[i]);k++){
  139825. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  139826. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  139827. }
  139828. }
  139829. for(i=0;i<=maxbook;i++)
  139830. ci->book_param[ci->books++]=books[x[is]][i];
  139831. }
  139832. ci->floor_type[ci->floors]=1;
  139833. ci->floor_param[ci->floors]=f;
  139834. ci->floors++;
  139835. return;
  139836. }
  139837. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  139838. vorbis_info_psy_global *in,
  139839. double *x){
  139840. int i,is=s;
  139841. double ds=s-is;
  139842. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139843. vorbis_info_psy_global *g=&ci->psy_g_param;
  139844. memcpy(g,in+(int)x[is],sizeof(*g));
  139845. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139846. is=(int)ds;
  139847. ds-=is;
  139848. if(ds==0 && is>0){
  139849. is--;
  139850. ds=1.;
  139851. }
  139852. for(i=0;i<4;i++){
  139853. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  139854. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  139855. }
  139856. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  139857. return;
  139858. }
  139859. static void vorbis_encode_global_stereo(vorbis_info *vi,
  139860. highlevel_encode_setup *hi,
  139861. adj_stereo *p){
  139862. float s=hi->stereo_point_setting;
  139863. int i,is=s;
  139864. double ds=s-is;
  139865. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139866. vorbis_info_psy_global *g=&ci->psy_g_param;
  139867. if(p){
  139868. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  139869. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  139870. if(hi->managed){
  139871. for(i=0;i<PACKETBLOBS;i++){
  139872. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  139873. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139874. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139875. g->coupling_pkHz[i]=kHz;
  139876. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  139877. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139878. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139879. }
  139880. }else{
  139881. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  139882. for(i=0;i<PACKETBLOBS;i++){
  139883. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139884. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139885. g->coupling_pkHz[i]=kHz;
  139886. }
  139887. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  139888. for(i=0;i<PACKETBLOBS;i++){
  139889. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139890. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139891. }
  139892. }
  139893. }else{
  139894. for(i=0;i<PACKETBLOBS;i++){
  139895. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  139896. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  139897. }
  139898. }
  139899. return;
  139900. }
  139901. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  139902. int *nn_start,
  139903. int *nn_partition,
  139904. double *nn_thresh,
  139905. int block){
  139906. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  139907. vorbis_info_psy *p=ci->psy_param[block];
  139908. highlevel_encode_setup *hi=&ci->hi;
  139909. int is=s;
  139910. if(block>=ci->psys)
  139911. ci->psys=block+1;
  139912. if(!p){
  139913. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  139914. ci->psy_param[block]=p;
  139915. }
  139916. memcpy(p,&_psy_info_template,sizeof(*p));
  139917. p->blockflag=block>>1;
  139918. if(hi->noise_normalize_p){
  139919. p->normal_channel_p=1;
  139920. p->normal_point_p=1;
  139921. p->normal_start=nn_start[is];
  139922. p->normal_partition=nn_partition[is];
  139923. p->normal_thresh=nn_thresh[is];
  139924. }
  139925. return;
  139926. }
  139927. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  139928. att3 *att,
  139929. int *max,
  139930. vp_adjblock *in){
  139931. int i,is=s;
  139932. double ds=s-is;
  139933. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  139934. vorbis_info_psy *p=ci->psy_param[block];
  139935. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  139936. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  139937. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  139938. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  139939. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  139940. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  139941. for(i=0;i<P_BANDS;i++)
  139942. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  139943. return;
  139944. }
  139945. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  139946. compandblock *in, double *x){
  139947. int i,is=s;
  139948. double ds=s-is;
  139949. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139950. vorbis_info_psy *p=ci->psy_param[block];
  139951. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139952. is=(int)ds;
  139953. ds-=is;
  139954. if(ds==0 && is>0){
  139955. is--;
  139956. ds=1.;
  139957. }
  139958. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  139959. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  139960. return;
  139961. }
  139962. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  139963. int *suppress){
  139964. int is=s;
  139965. double ds=s-is;
  139966. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139967. vorbis_info_psy *p=ci->psy_param[block];
  139968. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  139969. return;
  139970. }
  139971. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  139972. int *suppress,
  139973. noise3 *in,
  139974. noiseguard *guard,
  139975. double userbias){
  139976. int i,is=s,j;
  139977. double ds=s-is;
  139978. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139979. vorbis_info_psy *p=ci->psy_param[block];
  139980. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  139981. p->noisewindowlomin=guard[block].lo;
  139982. p->noisewindowhimin=guard[block].hi;
  139983. p->noisewindowfixed=guard[block].fixed;
  139984. for(j=0;j<P_NOISECURVES;j++)
  139985. for(i=0;i<P_BANDS;i++)
  139986. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  139987. for(j=0;j<P_NOISECURVES;j++){
  139988. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  139989. for(i=0;i<P_BANDS;i++){
  139990. p->noiseoff[j][i]+=userbias;
  139991. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  139992. }
  139993. }
  139994. return;
  139995. }
  139996. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  139997. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139998. vorbis_info_psy *p=ci->psy_param[block];
  139999. p->ath_adjatt=ci->hi.ath_floating_dB;
  140000. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140001. return;
  140002. }
  140003. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140004. int i;
  140005. for(i=0;i<ci->books;i++)
  140006. if(ci->book_param[i]==book)return(i);
  140007. return(ci->books++);
  140008. }
  140009. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140010. int *shortb,int *longb){
  140011. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140012. int is=s;
  140013. int blockshort=shortb[is];
  140014. int blocklong=longb[is];
  140015. ci->blocksizes[0]=blockshort;
  140016. ci->blocksizes[1]=blocklong;
  140017. }
  140018. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140019. int number, int block,
  140020. vorbis_residue_template *res){
  140021. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140022. int i,n;
  140023. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140024. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140025. memcpy(r,res->res,sizeof(*r));
  140026. if(ci->residues<=number)ci->residues=number+1;
  140027. switch(ci->blocksizes[block]){
  140028. case 64:case 128:case 256:
  140029. r->grouping=16;
  140030. break;
  140031. default:
  140032. r->grouping=32;
  140033. break;
  140034. }
  140035. ci->residue_type[number]=res->res_type;
  140036. n=r->end=ci->blocksizes[block]>>1;
  140037. if(res->res_type==2)
  140038. n=r->end*=vi->channels;
  140039. {
  140040. int booklist=0,k;
  140041. if(ci->hi.managed){
  140042. for(i=0;i<r->partitions;i++)
  140043. for(k=0;k<3;k++)
  140044. if(res->books_base_managed->books[i][k])
  140045. r->secondstages[i]|=(1<<k);
  140046. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140047. ci->book_param[r->groupbook]=res->book_aux_managed;
  140048. for(i=0;i<r->partitions;i++){
  140049. for(k=0;k<3;k++){
  140050. if(res->books_base_managed->books[i][k]){
  140051. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140052. r->booklist[booklist++]=bookid;
  140053. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140054. }
  140055. }
  140056. }
  140057. }else{
  140058. for(i=0;i<r->partitions;i++)
  140059. for(k=0;k<3;k++)
  140060. if(res->books_base->books[i][k])
  140061. r->secondstages[i]|=(1<<k);
  140062. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140063. ci->book_param[r->groupbook]=res->book_aux;
  140064. for(i=0;i<r->partitions;i++){
  140065. for(k=0;k<3;k++){
  140066. if(res->books_base->books[i][k]){
  140067. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140068. r->booklist[booklist++]=bookid;
  140069. ci->book_param[bookid]=res->books_base->books[i][k];
  140070. }
  140071. }
  140072. }
  140073. }
  140074. }
  140075. {
  140076. double freq=ci->hi.lowpass_kHz*1000.;
  140077. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140078. double nyq=vi->rate/2.;
  140079. long blocksize=ci->blocksizes[block]>>1;
  140080. if(freq>nyq)freq=nyq;
  140081. f->n=freq/nyq*blocksize;
  140082. if(res->limit_type){
  140083. if(ci->hi.managed)
  140084. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140085. else
  140086. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140087. if(freq>nyq)freq=nyq;
  140088. }
  140089. if(ci->residue_type[block]==2)
  140090. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140091. r->grouping;
  140092. else
  140093. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140094. r->grouping;
  140095. }
  140096. }
  140097. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140098. vorbis_mapping_template *maps){
  140099. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140100. int i,j,is=s,modes=2;
  140101. vorbis_info_mapping0 *map=maps[is].map;
  140102. vorbis_info_mode *mode=_mode_template;
  140103. vorbis_residue_template *res=maps[is].res;
  140104. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140105. for(i=0;i<modes;i++){
  140106. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140107. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140108. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140109. if(i>=ci->modes)ci->modes=i+1;
  140110. ci->map_type[i]=0;
  140111. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140112. if(i>=ci->maps)ci->maps=i+1;
  140113. for(j=0;j<map[i].submaps;j++)
  140114. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140115. ,res+map[i].residuesubmap[j]);
  140116. }
  140117. }
  140118. static double setting_to_approx_bitrate(vorbis_info *vi){
  140119. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140120. highlevel_encode_setup *hi=&ci->hi;
  140121. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140122. int is=hi->base_setting;
  140123. double ds=hi->base_setting-is;
  140124. int ch=vi->channels;
  140125. double *r=setup->rate_mapping;
  140126. if(r==NULL)
  140127. return(-1);
  140128. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140129. }
  140130. static void get_setup_template(vorbis_info *vi,
  140131. long ch,long srate,
  140132. double req,int q_or_bitrate){
  140133. int i=0,j;
  140134. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140135. highlevel_encode_setup *hi=&ci->hi;
  140136. if(q_or_bitrate)req/=ch;
  140137. while(setup_list[i]){
  140138. if(setup_list[i]->coupling_restriction==-1 ||
  140139. setup_list[i]->coupling_restriction==ch){
  140140. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140141. srate<=setup_list[i]->samplerate_max_restriction){
  140142. int mappings=setup_list[i]->mappings;
  140143. double *map=(q_or_bitrate?
  140144. setup_list[i]->rate_mapping:
  140145. setup_list[i]->quality_mapping);
  140146. if(req<map[0]){++i;continue;}
  140147. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140148. for(j=0;j<mappings;j++)
  140149. if(req>=map[j] && req<map[j+1])break;
  140150. hi->setup=setup_list[i];
  140151. if(j==mappings)
  140152. hi->base_setting=j-.001;
  140153. else{
  140154. float low=map[j];
  140155. float high=map[j+1];
  140156. float del=(req-low)/(high-low);
  140157. hi->base_setting=j+del;
  140158. }
  140159. return;
  140160. }
  140161. }
  140162. i++;
  140163. }
  140164. hi->setup=NULL;
  140165. }
  140166. int vorbis_encode_setup_init(vorbis_info *vi){
  140167. int i0=0,singleblock=0;
  140168. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140169. ve_setup_data_template *setup=NULL;
  140170. highlevel_encode_setup *hi=&ci->hi;
  140171. if(ci==NULL)return(OV_EINVAL);
  140172. if(!hi->impulse_block_p)i0=1;
  140173. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140174. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140175. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140176. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140177. setup=(ve_setup_data_template *)hi->setup;
  140178. if(setup==NULL)return(OV_EINVAL);
  140179. hi->set_in_stone=1;
  140180. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140181. setup->blocksize_short,
  140182. setup->blocksize_long);
  140183. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140184. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140185. setup->floor_books,
  140186. setup->floor_params,
  140187. setup->floor_short_mapping);
  140188. if(!singleblock)
  140189. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140190. setup->floor_books,
  140191. setup->floor_params,
  140192. setup->floor_long_mapping);
  140193. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140194. setup->global_params,
  140195. setup->global_mapping);
  140196. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140197. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140198. setup->psy_noise_normal_start[0],
  140199. setup->psy_noise_normal_partition[0],
  140200. setup->psy_noise_normal_thresh,
  140201. 0);
  140202. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140203. setup->psy_noise_normal_start[0],
  140204. setup->psy_noise_normal_partition[0],
  140205. setup->psy_noise_normal_thresh,
  140206. 1);
  140207. if(!singleblock){
  140208. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140209. setup->psy_noise_normal_start[1],
  140210. setup->psy_noise_normal_partition[1],
  140211. setup->psy_noise_normal_thresh,
  140212. 2);
  140213. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140214. setup->psy_noise_normal_start[1],
  140215. setup->psy_noise_normal_partition[1],
  140216. setup->psy_noise_normal_thresh,
  140217. 3);
  140218. }
  140219. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140220. setup->psy_tone_masteratt,
  140221. setup->psy_tone_0dB,
  140222. setup->psy_tone_adj_impulse);
  140223. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140224. setup->psy_tone_masteratt,
  140225. setup->psy_tone_0dB,
  140226. setup->psy_tone_adj_other);
  140227. if(!singleblock){
  140228. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140229. setup->psy_tone_masteratt,
  140230. setup->psy_tone_0dB,
  140231. setup->psy_tone_adj_other);
  140232. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140233. setup->psy_tone_masteratt,
  140234. setup->psy_tone_0dB,
  140235. setup->psy_tone_adj_long);
  140236. }
  140237. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140238. setup->psy_noise_compand,
  140239. setup->psy_noise_compand_short_mapping);
  140240. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140241. setup->psy_noise_compand,
  140242. setup->psy_noise_compand_short_mapping);
  140243. if(!singleblock){
  140244. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140245. setup->psy_noise_compand,
  140246. setup->psy_noise_compand_long_mapping);
  140247. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140248. setup->psy_noise_compand,
  140249. setup->psy_noise_compand_long_mapping);
  140250. }
  140251. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140252. setup->psy_tone_dBsuppress);
  140253. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140254. setup->psy_tone_dBsuppress);
  140255. if(!singleblock){
  140256. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140257. setup->psy_tone_dBsuppress);
  140258. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140259. setup->psy_tone_dBsuppress);
  140260. }
  140261. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140262. setup->psy_noise_dBsuppress,
  140263. setup->psy_noise_bias_impulse,
  140264. setup->psy_noiseguards,
  140265. (i0==0?hi->impulse_noisetune:0.));
  140266. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140267. setup->psy_noise_dBsuppress,
  140268. setup->psy_noise_bias_padding,
  140269. setup->psy_noiseguards,0.);
  140270. if(!singleblock){
  140271. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140272. setup->psy_noise_dBsuppress,
  140273. setup->psy_noise_bias_trans,
  140274. setup->psy_noiseguards,0.);
  140275. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140276. setup->psy_noise_dBsuppress,
  140277. setup->psy_noise_bias_long,
  140278. setup->psy_noiseguards,0.);
  140279. }
  140280. vorbis_encode_ath_setup(vi,0);
  140281. vorbis_encode_ath_setup(vi,1);
  140282. if(!singleblock){
  140283. vorbis_encode_ath_setup(vi,2);
  140284. vorbis_encode_ath_setup(vi,3);
  140285. }
  140286. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140287. if(hi->bitrate_av>0)
  140288. vi->bitrate_nominal=hi->bitrate_av;
  140289. else{
  140290. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140291. }
  140292. vi->bitrate_lower=hi->bitrate_min;
  140293. vi->bitrate_upper=hi->bitrate_max;
  140294. if(hi->bitrate_av)
  140295. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140296. else
  140297. vi->bitrate_window=0.;
  140298. if(hi->managed){
  140299. ci->bi.avg_rate=hi->bitrate_av;
  140300. ci->bi.min_rate=hi->bitrate_min;
  140301. ci->bi.max_rate=hi->bitrate_max;
  140302. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140303. ci->bi.reservoir_bias=
  140304. hi->bitrate_reservoir_bias;
  140305. ci->bi.slew_damp=hi->bitrate_av_damp;
  140306. }
  140307. return(0);
  140308. }
  140309. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140310. long channels,
  140311. long rate){
  140312. int ret=0,i,is;
  140313. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140314. highlevel_encode_setup *hi=&ci->hi;
  140315. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140316. double ds;
  140317. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140318. if(ret)return(ret);
  140319. is=hi->base_setting;
  140320. ds=hi->base_setting-is;
  140321. hi->short_setting=hi->base_setting;
  140322. hi->long_setting=hi->base_setting;
  140323. hi->managed=0;
  140324. hi->impulse_block_p=1;
  140325. hi->noise_normalize_p=1;
  140326. hi->stereo_point_setting=hi->base_setting;
  140327. hi->lowpass_kHz=
  140328. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140329. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140330. setup->psy_ath_float[is+1]*ds;
  140331. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140332. setup->psy_ath_abs[is+1]*ds;
  140333. hi->amplitude_track_dBpersec=-6.;
  140334. hi->trigger_setting=hi->base_setting;
  140335. for(i=0;i<4;i++){
  140336. hi->block[i].tone_mask_setting=hi->base_setting;
  140337. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140338. hi->block[i].noise_bias_setting=hi->base_setting;
  140339. hi->block[i].noise_compand_setting=hi->base_setting;
  140340. }
  140341. return(ret);
  140342. }
  140343. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140344. long channels,
  140345. long rate,
  140346. float quality){
  140347. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140348. highlevel_encode_setup *hi=&ci->hi;
  140349. quality+=.0000001;
  140350. if(quality>=1.)quality=.9999;
  140351. get_setup_template(vi,channels,rate,quality,0);
  140352. if(!hi->setup)return OV_EIMPL;
  140353. return vorbis_encode_setup_setting(vi,channels,rate);
  140354. }
  140355. int vorbis_encode_init_vbr(vorbis_info *vi,
  140356. long channels,
  140357. long rate,
  140358. float base_quality /* 0. to 1. */
  140359. ){
  140360. int ret=0;
  140361. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140362. if(ret){
  140363. vorbis_info_clear(vi);
  140364. return ret;
  140365. }
  140366. ret=vorbis_encode_setup_init(vi);
  140367. if(ret)
  140368. vorbis_info_clear(vi);
  140369. return(ret);
  140370. }
  140371. int vorbis_encode_setup_managed(vorbis_info *vi,
  140372. long channels,
  140373. long rate,
  140374. long max_bitrate,
  140375. long nominal_bitrate,
  140376. long min_bitrate){
  140377. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140378. highlevel_encode_setup *hi=&ci->hi;
  140379. double tnominal=nominal_bitrate;
  140380. int ret=0;
  140381. if(nominal_bitrate<=0.){
  140382. if(max_bitrate>0.){
  140383. if(min_bitrate>0.)
  140384. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140385. else
  140386. nominal_bitrate=max_bitrate*.875;
  140387. }else{
  140388. if(min_bitrate>0.){
  140389. nominal_bitrate=min_bitrate;
  140390. }else{
  140391. return(OV_EINVAL);
  140392. }
  140393. }
  140394. }
  140395. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140396. if(!hi->setup)return OV_EIMPL;
  140397. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140398. if(ret){
  140399. vorbis_info_clear(vi);
  140400. return ret;
  140401. }
  140402. hi->managed=1;
  140403. hi->bitrate_min=min_bitrate;
  140404. hi->bitrate_max=max_bitrate;
  140405. hi->bitrate_av=tnominal;
  140406. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140407. hi->bitrate_reservoir=nominal_bitrate*2;
  140408. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140409. return(ret);
  140410. }
  140411. int vorbis_encode_init(vorbis_info *vi,
  140412. long channels,
  140413. long rate,
  140414. long max_bitrate,
  140415. long nominal_bitrate,
  140416. long min_bitrate){
  140417. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140418. max_bitrate,
  140419. nominal_bitrate,
  140420. min_bitrate);
  140421. if(ret){
  140422. vorbis_info_clear(vi);
  140423. return(ret);
  140424. }
  140425. ret=vorbis_encode_setup_init(vi);
  140426. if(ret)
  140427. vorbis_info_clear(vi);
  140428. return(ret);
  140429. }
  140430. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140431. if(vi){
  140432. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140433. highlevel_encode_setup *hi=&ci->hi;
  140434. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140435. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140436. switch(number){
  140437. case OV_ECTL_RATEMANAGE_GET:
  140438. {
  140439. struct ovectl_ratemanage_arg *ai=
  140440. (struct ovectl_ratemanage_arg *)arg;
  140441. ai->management_active=hi->managed;
  140442. ai->bitrate_hard_window=ai->bitrate_av_window=
  140443. (double)hi->bitrate_reservoir/vi->rate;
  140444. ai->bitrate_av_window_center=1.;
  140445. ai->bitrate_hard_min=hi->bitrate_min;
  140446. ai->bitrate_hard_max=hi->bitrate_max;
  140447. ai->bitrate_av_lo=hi->bitrate_av;
  140448. ai->bitrate_av_hi=hi->bitrate_av;
  140449. }
  140450. return(0);
  140451. case OV_ECTL_RATEMANAGE_SET:
  140452. {
  140453. struct ovectl_ratemanage_arg *ai=
  140454. (struct ovectl_ratemanage_arg *)arg;
  140455. if(ai==NULL){
  140456. hi->managed=0;
  140457. }else{
  140458. hi->managed=ai->management_active;
  140459. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140460. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140461. }
  140462. }
  140463. return 0;
  140464. case OV_ECTL_RATEMANAGE_AVG:
  140465. {
  140466. struct ovectl_ratemanage_arg *ai=
  140467. (struct ovectl_ratemanage_arg *)arg;
  140468. if(ai==NULL){
  140469. hi->bitrate_av=0;
  140470. }else{
  140471. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140472. }
  140473. }
  140474. return(0);
  140475. case OV_ECTL_RATEMANAGE_HARD:
  140476. {
  140477. struct ovectl_ratemanage_arg *ai=
  140478. (struct ovectl_ratemanage_arg *)arg;
  140479. if(ai==NULL){
  140480. hi->bitrate_min=0;
  140481. hi->bitrate_max=0;
  140482. }else{
  140483. hi->bitrate_min=ai->bitrate_hard_min;
  140484. hi->bitrate_max=ai->bitrate_hard_max;
  140485. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140486. (hi->bitrate_max+hi->bitrate_min)*.5;
  140487. }
  140488. if(hi->bitrate_reservoir<128.)
  140489. hi->bitrate_reservoir=128.;
  140490. }
  140491. return(0);
  140492. case OV_ECTL_RATEMANAGE2_GET:
  140493. {
  140494. struct ovectl_ratemanage2_arg *ai=
  140495. (struct ovectl_ratemanage2_arg *)arg;
  140496. if(ai==NULL)return OV_EINVAL;
  140497. ai->management_active=hi->managed;
  140498. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140499. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140500. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140501. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140502. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140503. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140504. }
  140505. return (0);
  140506. case OV_ECTL_RATEMANAGE2_SET:
  140507. {
  140508. struct ovectl_ratemanage2_arg *ai=
  140509. (struct ovectl_ratemanage2_arg *)arg;
  140510. if(ai==NULL){
  140511. hi->managed=0;
  140512. }else{
  140513. if(ai->bitrate_limit_min_kbps>0 &&
  140514. ai->bitrate_average_kbps>0 &&
  140515. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140516. return OV_EINVAL;
  140517. if(ai->bitrate_limit_max_kbps>0 &&
  140518. ai->bitrate_average_kbps>0 &&
  140519. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140520. return OV_EINVAL;
  140521. if(ai->bitrate_limit_min_kbps>0 &&
  140522. ai->bitrate_limit_max_kbps>0 &&
  140523. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140524. return OV_EINVAL;
  140525. if(ai->bitrate_average_damping <= 0.)
  140526. return OV_EINVAL;
  140527. if(ai->bitrate_limit_reservoir_bits < 0)
  140528. return OV_EINVAL;
  140529. if(ai->bitrate_limit_reservoir_bias < 0.)
  140530. return OV_EINVAL;
  140531. if(ai->bitrate_limit_reservoir_bias > 1.)
  140532. return OV_EINVAL;
  140533. hi->managed=ai->management_active;
  140534. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140535. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140536. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140537. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140538. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140539. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140540. }
  140541. }
  140542. return 0;
  140543. case OV_ECTL_LOWPASS_GET:
  140544. {
  140545. double *farg=(double *)arg;
  140546. *farg=hi->lowpass_kHz;
  140547. }
  140548. return(0);
  140549. case OV_ECTL_LOWPASS_SET:
  140550. {
  140551. double *farg=(double *)arg;
  140552. hi->lowpass_kHz=*farg;
  140553. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140554. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140555. }
  140556. return(0);
  140557. case OV_ECTL_IBLOCK_GET:
  140558. {
  140559. double *farg=(double *)arg;
  140560. *farg=hi->impulse_noisetune;
  140561. }
  140562. return(0);
  140563. case OV_ECTL_IBLOCK_SET:
  140564. {
  140565. double *farg=(double *)arg;
  140566. hi->impulse_noisetune=*farg;
  140567. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140568. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140569. }
  140570. return(0);
  140571. }
  140572. return(OV_EIMPL);
  140573. }
  140574. return(OV_EINVAL);
  140575. }
  140576. #endif
  140577. /*** End of inlined file: vorbisenc.c ***/
  140578. /*** Start of inlined file: vorbisfile.c ***/
  140579. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140580. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140581. // tasks..
  140582. #if JUCE_MSVC
  140583. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140584. #endif
  140585. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140586. #if JUCE_USE_OGGVORBIS
  140587. #include <stdlib.h>
  140588. #include <stdio.h>
  140589. #include <errno.h>
  140590. #include <string.h>
  140591. #include <math.h>
  140592. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140593. over 8k gets what they deserve */
  140594. static long _get_data(OggVorbis_File *vf){
  140595. errno=0;
  140596. if(vf->datasource){
  140597. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140598. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140599. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140600. if(bytes==0 && errno)return(-1);
  140601. return(bytes);
  140602. }else
  140603. return(0);
  140604. }
  140605. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140606. if(vf->datasource){
  140607. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140608. vf->offset=offset;
  140609. ogg_sync_reset(&vf->oy);
  140610. }else{
  140611. return;
  140612. }
  140613. }
  140614. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140615. ogg_int64_t boundary){
  140616. if(boundary>0)boundary+=vf->offset;
  140617. while(1){
  140618. long more;
  140619. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140620. more=ogg_sync_pageseek(&vf->oy,og);
  140621. if(more<0){
  140622. vf->offset-=more;
  140623. }else{
  140624. if(more==0){
  140625. if(!boundary)return(OV_FALSE);
  140626. {
  140627. long ret=_get_data(vf);
  140628. if(ret==0)return(OV_EOF);
  140629. if(ret<0)return(OV_EREAD);
  140630. }
  140631. }else{
  140632. ogg_int64_t ret=vf->offset;
  140633. vf->offset+=more;
  140634. return(ret);
  140635. }
  140636. }
  140637. }
  140638. }
  140639. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140640. ogg_int64_t begin=vf->offset;
  140641. ogg_int64_t end=begin;
  140642. ogg_int64_t ret;
  140643. ogg_int64_t offset=-1;
  140644. while(offset==-1){
  140645. begin-=CHUNKSIZE;
  140646. if(begin<0)
  140647. begin=0;
  140648. _seek_helper(vf,begin);
  140649. while(vf->offset<end){
  140650. ret=_get_next_page(vf,og,end-vf->offset);
  140651. if(ret==OV_EREAD)return(OV_EREAD);
  140652. if(ret<0){
  140653. break;
  140654. }else{
  140655. offset=ret;
  140656. }
  140657. }
  140658. }
  140659. _seek_helper(vf,offset);
  140660. ret=_get_next_page(vf,og,CHUNKSIZE);
  140661. if(ret<0)
  140662. return(OV_EFAULT);
  140663. return(offset);
  140664. }
  140665. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140666. ogg_int64_t begin,
  140667. ogg_int64_t searched,
  140668. ogg_int64_t end,
  140669. long currentno,
  140670. long m){
  140671. ogg_int64_t endsearched=end;
  140672. ogg_int64_t next=end;
  140673. ogg_page og;
  140674. ogg_int64_t ret;
  140675. while(searched<endsearched){
  140676. ogg_int64_t bisect;
  140677. if(endsearched-searched<CHUNKSIZE){
  140678. bisect=searched;
  140679. }else{
  140680. bisect=(searched+endsearched)/2;
  140681. }
  140682. _seek_helper(vf,bisect);
  140683. ret=_get_next_page(vf,&og,-1);
  140684. if(ret==OV_EREAD)return(OV_EREAD);
  140685. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140686. endsearched=bisect;
  140687. if(ret>=0)next=ret;
  140688. }else{
  140689. searched=ret+og.header_len+og.body_len;
  140690. }
  140691. }
  140692. _seek_helper(vf,next);
  140693. ret=_get_next_page(vf,&og,-1);
  140694. if(ret==OV_EREAD)return(OV_EREAD);
  140695. if(searched>=end || ret<0){
  140696. vf->links=m+1;
  140697. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140698. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140699. vf->offsets[m+1]=searched;
  140700. }else{
  140701. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140702. end,ogg_page_serialno(&og),m+1);
  140703. if(ret==OV_EREAD)return(OV_EREAD);
  140704. }
  140705. vf->offsets[m]=begin;
  140706. vf->serialnos[m]=currentno;
  140707. return(0);
  140708. }
  140709. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140710. long *serialno,ogg_page *og_ptr){
  140711. ogg_page og;
  140712. ogg_packet op;
  140713. int i,ret;
  140714. if(!og_ptr){
  140715. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140716. if(llret==OV_EREAD)return(OV_EREAD);
  140717. if(llret<0)return OV_ENOTVORBIS;
  140718. og_ptr=&og;
  140719. }
  140720. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140721. if(serialno)*serialno=vf->os.serialno;
  140722. vf->ready_state=STREAMSET;
  140723. vorbis_info_init(vi);
  140724. vorbis_comment_init(vc);
  140725. i=0;
  140726. while(i<3){
  140727. ogg_stream_pagein(&vf->os,og_ptr);
  140728. while(i<3){
  140729. int result=ogg_stream_packetout(&vf->os,&op);
  140730. if(result==0)break;
  140731. if(result==-1){
  140732. ret=OV_EBADHEADER;
  140733. goto bail_header;
  140734. }
  140735. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140736. goto bail_header;
  140737. }
  140738. i++;
  140739. }
  140740. if(i<3)
  140741. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140742. ret=OV_EBADHEADER;
  140743. goto bail_header;
  140744. }
  140745. }
  140746. return 0;
  140747. bail_header:
  140748. vorbis_info_clear(vi);
  140749. vorbis_comment_clear(vc);
  140750. vf->ready_state=OPENED;
  140751. return ret;
  140752. }
  140753. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140754. ogg_page og;
  140755. int i;
  140756. ogg_int64_t ret;
  140757. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140758. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140759. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140760. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140761. for(i=0;i<vf->links;i++){
  140762. if(i==0){
  140763. vf->dataoffsets[i]=dataoffset;
  140764. _seek_helper(vf,dataoffset);
  140765. }else{
  140766. _seek_helper(vf,vf->offsets[i]);
  140767. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140768. vf->dataoffsets[i]=-1;
  140769. }else{
  140770. vf->dataoffsets[i]=vf->offset;
  140771. }
  140772. }
  140773. if(vf->dataoffsets[i]!=-1){
  140774. ogg_int64_t accumulated=0;
  140775. long lastblock=-1;
  140776. int result;
  140777. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140778. while(1){
  140779. ogg_packet op;
  140780. ret=_get_next_page(vf,&og,-1);
  140781. if(ret<0)
  140782. break;
  140783. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140784. break;
  140785. ogg_stream_pagein(&vf->os,&og);
  140786. while((result=ogg_stream_packetout(&vf->os,&op))){
  140787. if(result>0){ /* ignore holes */
  140788. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140789. if(lastblock!=-1)
  140790. accumulated+=(lastblock+thisblock)>>2;
  140791. lastblock=thisblock;
  140792. }
  140793. }
  140794. if(ogg_page_granulepos(&og)!=-1){
  140795. accumulated= ogg_page_granulepos(&og)-accumulated;
  140796. break;
  140797. }
  140798. }
  140799. if(accumulated<0)accumulated=0;
  140800. vf->pcmlengths[i*2]=accumulated;
  140801. }
  140802. {
  140803. ogg_int64_t end=vf->offsets[i+1];
  140804. _seek_helper(vf,end);
  140805. while(1){
  140806. ret=_get_prev_page(vf,&og);
  140807. if(ret<0){
  140808. vorbis_info_clear(vf->vi+i);
  140809. vorbis_comment_clear(vf->vc+i);
  140810. break;
  140811. }
  140812. if(ogg_page_granulepos(&og)!=-1){
  140813. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  140814. break;
  140815. }
  140816. vf->offset=ret;
  140817. }
  140818. }
  140819. }
  140820. }
  140821. static int _make_decode_ready(OggVorbis_File *vf){
  140822. if(vf->ready_state>STREAMSET)return 0;
  140823. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  140824. if(vf->seekable){
  140825. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  140826. return OV_EBADLINK;
  140827. }else{
  140828. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  140829. return OV_EBADLINK;
  140830. }
  140831. vorbis_block_init(&vf->vd,&vf->vb);
  140832. vf->ready_state=INITSET;
  140833. vf->bittrack=0.f;
  140834. vf->samptrack=0.f;
  140835. return 0;
  140836. }
  140837. static int _open_seekable2(OggVorbis_File *vf){
  140838. long serialno=vf->current_serialno;
  140839. ogg_int64_t dataoffset=vf->offset, end;
  140840. ogg_page og;
  140841. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  140842. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  140843. end=_get_prev_page(vf,&og);
  140844. if(end<0)return(end);
  140845. if(ogg_page_serialno(&og)!=serialno){
  140846. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  140847. }else{
  140848. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  140849. }
  140850. _prefetch_all_headers(vf,dataoffset);
  140851. return(ov_raw_seek(vf,0));
  140852. }
  140853. static void _decode_clear(OggVorbis_File *vf){
  140854. vorbis_dsp_clear(&vf->vd);
  140855. vorbis_block_clear(&vf->vb);
  140856. vf->ready_state=OPENED;
  140857. }
  140858. static int _fetch_and_process_packet(OggVorbis_File *vf,
  140859. ogg_packet *op_in,
  140860. int readp,
  140861. int spanp){
  140862. ogg_page og;
  140863. while(1){
  140864. if(vf->ready_state==INITSET){
  140865. while(1) {
  140866. ogg_packet op;
  140867. ogg_packet *op_ptr=(op_in?op_in:&op);
  140868. int result=ogg_stream_packetout(&vf->os,op_ptr);
  140869. ogg_int64_t granulepos;
  140870. op_in=NULL;
  140871. if(result==-1)return(OV_HOLE); /* hole in the data. */
  140872. if(result>0){
  140873. granulepos=op_ptr->granulepos;
  140874. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  140875. header handling. The
  140876. header packets aren't
  140877. audio, so if/when we
  140878. submit them,
  140879. vorbis_synthesis will
  140880. reject them */
  140881. {
  140882. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  140883. if(oldsamples)return(OV_EFAULT);
  140884. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  140885. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  140886. vf->bittrack+=op_ptr->bytes*8;
  140887. }
  140888. if(granulepos!=-1 && !op_ptr->e_o_s){
  140889. int link=(vf->seekable?vf->current_link:0);
  140890. int i,samples;
  140891. if(vf->seekable && link>0)
  140892. granulepos-=vf->pcmlengths[link*2];
  140893. if(granulepos<0)granulepos=0; /* actually, this
  140894. shouldn't be possible
  140895. here unless the stream
  140896. is very broken */
  140897. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  140898. granulepos-=samples;
  140899. for(i=0;i<link;i++)
  140900. granulepos+=vf->pcmlengths[i*2+1];
  140901. vf->pcm_offset=granulepos;
  140902. }
  140903. return(1);
  140904. }
  140905. }
  140906. else
  140907. break;
  140908. }
  140909. }
  140910. if(vf->ready_state>=OPENED){
  140911. ogg_int64_t ret;
  140912. if(!readp)return(0);
  140913. if((ret=_get_next_page(vf,&og,-1))<0){
  140914. return(OV_EOF); /* eof.
  140915. leave unitialized */
  140916. }
  140917. vf->bittrack+=og.header_len*8;
  140918. if(vf->ready_state==INITSET){
  140919. if(vf->current_serialno!=ogg_page_serialno(&og)){
  140920. if(!spanp)
  140921. return(OV_EOF);
  140922. _decode_clear(vf);
  140923. if(!vf->seekable){
  140924. vorbis_info_clear(vf->vi);
  140925. vorbis_comment_clear(vf->vc);
  140926. }
  140927. }
  140928. }
  140929. }
  140930. if(vf->ready_state!=INITSET){
  140931. int link;
  140932. if(vf->ready_state<STREAMSET){
  140933. if(vf->seekable){
  140934. vf->current_serialno=ogg_page_serialno(&og);
  140935. for(link=0;link<vf->links;link++)
  140936. if(vf->serialnos[link]==vf->current_serialno)break;
  140937. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  140938. stream. error out,
  140939. leave machine
  140940. uninitialized */
  140941. vf->current_link=link;
  140942. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  140943. vf->ready_state=STREAMSET;
  140944. }else{
  140945. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  140946. if(ret)return(ret);
  140947. vf->current_link++;
  140948. link=0;
  140949. }
  140950. }
  140951. {
  140952. int ret=_make_decode_ready(vf);
  140953. if(ret<0)return ret;
  140954. }
  140955. }
  140956. ogg_stream_pagein(&vf->os,&og);
  140957. }
  140958. }
  140959. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  140960. if(f==NULL)return(-1);
  140961. return fseek(f,off,whence);
  140962. }
  140963. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  140964. long ibytes, ov_callbacks callbacks){
  140965. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  140966. int ret;
  140967. memset(vf,0,sizeof(*vf));
  140968. vf->datasource=f;
  140969. vf->callbacks = callbacks;
  140970. ogg_sync_init(&vf->oy);
  140971. if(initial){
  140972. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  140973. memcpy(buffer,initial,ibytes);
  140974. ogg_sync_wrote(&vf->oy,ibytes);
  140975. }
  140976. if(offsettest!=-1)vf->seekable=1;
  140977. vf->links=1;
  140978. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  140979. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  140980. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  140981. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  140982. vf->datasource=NULL;
  140983. ov_clear(vf);
  140984. }else
  140985. vf->ready_state=PARTOPEN;
  140986. return(ret);
  140987. }
  140988. static int _ov_open2(OggVorbis_File *vf){
  140989. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  140990. vf->ready_state=OPENED;
  140991. if(vf->seekable){
  140992. int ret=_open_seekable2(vf);
  140993. if(ret){
  140994. vf->datasource=NULL;
  140995. ov_clear(vf);
  140996. }
  140997. return(ret);
  140998. }else
  140999. vf->ready_state=STREAMSET;
  141000. return 0;
  141001. }
  141002. int ov_clear(OggVorbis_File *vf){
  141003. if(vf){
  141004. vorbis_block_clear(&vf->vb);
  141005. vorbis_dsp_clear(&vf->vd);
  141006. ogg_stream_clear(&vf->os);
  141007. if(vf->vi && vf->links){
  141008. int i;
  141009. for(i=0;i<vf->links;i++){
  141010. vorbis_info_clear(vf->vi+i);
  141011. vorbis_comment_clear(vf->vc+i);
  141012. }
  141013. _ogg_free(vf->vi);
  141014. _ogg_free(vf->vc);
  141015. }
  141016. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141017. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141018. if(vf->serialnos)_ogg_free(vf->serialnos);
  141019. if(vf->offsets)_ogg_free(vf->offsets);
  141020. ogg_sync_clear(&vf->oy);
  141021. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141022. memset(vf,0,sizeof(*vf));
  141023. }
  141024. #ifdef DEBUG_LEAKS
  141025. _VDBG_dump();
  141026. #endif
  141027. return(0);
  141028. }
  141029. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141030. ov_callbacks callbacks){
  141031. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141032. if(ret)return ret;
  141033. return _ov_open2(vf);
  141034. }
  141035. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141036. ov_callbacks callbacks = {
  141037. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141038. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141039. (int (*)(void *)) fclose,
  141040. (long (*)(void *)) ftell
  141041. };
  141042. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141043. }
  141044. int ov_halfrate(OggVorbis_File *vf,int flag){
  141045. int i;
  141046. if(vf->vi==NULL)return OV_EINVAL;
  141047. if(!vf->seekable)return OV_EINVAL;
  141048. if(vf->ready_state>=STREAMSET)
  141049. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141050. will be able to swap this on the fly, but
  141051. for now dumping the decode machine is needed
  141052. to reinit the MDCT lookups. 1.1 libvorbis
  141053. is planned to be able to switch on the fly */
  141054. for(i=0;i<vf->links;i++){
  141055. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141056. ov_halfrate(vf,0);
  141057. return OV_EINVAL;
  141058. }
  141059. }
  141060. return 0;
  141061. }
  141062. int ov_halfrate_p(OggVorbis_File *vf){
  141063. if(vf->vi==NULL)return OV_EINVAL;
  141064. return vorbis_synthesis_halfrate_p(vf->vi);
  141065. }
  141066. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141067. ov_callbacks callbacks)
  141068. {
  141069. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141070. }
  141071. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141072. ov_callbacks callbacks = {
  141073. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141074. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141075. (int (*)(void *)) fclose,
  141076. (long (*)(void *)) ftell
  141077. };
  141078. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141079. }
  141080. int ov_test_open(OggVorbis_File *vf){
  141081. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141082. return _ov_open2(vf);
  141083. }
  141084. long ov_streams(OggVorbis_File *vf){
  141085. return vf->links;
  141086. }
  141087. long ov_seekable(OggVorbis_File *vf){
  141088. return vf->seekable;
  141089. }
  141090. long ov_bitrate(OggVorbis_File *vf,int i){
  141091. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141092. if(i>=vf->links)return(OV_EINVAL);
  141093. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141094. if(i<0){
  141095. ogg_int64_t bits=0;
  141096. int i;
  141097. float br;
  141098. for(i=0;i<vf->links;i++)
  141099. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141100. br = bits/ov_time_total(vf,-1);
  141101. return(rint(br));
  141102. }else{
  141103. if(vf->seekable){
  141104. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141105. }else{
  141106. if(vf->vi[i].bitrate_nominal>0){
  141107. return vf->vi[i].bitrate_nominal;
  141108. }else{
  141109. if(vf->vi[i].bitrate_upper>0){
  141110. if(vf->vi[i].bitrate_lower>0){
  141111. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141112. }else{
  141113. return vf->vi[i].bitrate_upper;
  141114. }
  141115. }
  141116. return(OV_FALSE);
  141117. }
  141118. }
  141119. }
  141120. }
  141121. long ov_bitrate_instant(OggVorbis_File *vf){
  141122. int link=(vf->seekable?vf->current_link:0);
  141123. long ret;
  141124. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141125. if(vf->samptrack==0)return(OV_FALSE);
  141126. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141127. vf->bittrack=0.f;
  141128. vf->samptrack=0.f;
  141129. return(ret);
  141130. }
  141131. long ov_serialnumber(OggVorbis_File *vf,int i){
  141132. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141133. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141134. if(i<0){
  141135. return(vf->current_serialno);
  141136. }else{
  141137. return(vf->serialnos[i]);
  141138. }
  141139. }
  141140. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141141. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141142. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141143. if(i<0){
  141144. ogg_int64_t acc=0;
  141145. int i;
  141146. for(i=0;i<vf->links;i++)
  141147. acc+=ov_raw_total(vf,i);
  141148. return(acc);
  141149. }else{
  141150. return(vf->offsets[i+1]-vf->offsets[i]);
  141151. }
  141152. }
  141153. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141154. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141155. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141156. if(i<0){
  141157. ogg_int64_t acc=0;
  141158. int i;
  141159. for(i=0;i<vf->links;i++)
  141160. acc+=ov_pcm_total(vf,i);
  141161. return(acc);
  141162. }else{
  141163. return(vf->pcmlengths[i*2+1]);
  141164. }
  141165. }
  141166. double ov_time_total(OggVorbis_File *vf,int i){
  141167. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141168. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141169. if(i<0){
  141170. double acc=0;
  141171. int i;
  141172. for(i=0;i<vf->links;i++)
  141173. acc+=ov_time_total(vf,i);
  141174. return(acc);
  141175. }else{
  141176. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141177. }
  141178. }
  141179. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141180. ogg_stream_state work_os;
  141181. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141182. if(!vf->seekable)
  141183. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141184. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141185. vf->pcm_offset=-1;
  141186. ogg_stream_reset_serialno(&vf->os,
  141187. vf->current_serialno); /* must set serialno */
  141188. vorbis_synthesis_restart(&vf->vd);
  141189. _seek_helper(vf,pos);
  141190. {
  141191. ogg_page og;
  141192. ogg_packet op;
  141193. int lastblock=0;
  141194. int accblock=0;
  141195. int thisblock;
  141196. int eosflag;
  141197. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141198. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141199. return from not necessarily
  141200. starting from the beginning */
  141201. while(1){
  141202. if(vf->ready_state>=STREAMSET){
  141203. int result=ogg_stream_packetout(&work_os,&op);
  141204. if(result>0){
  141205. if(vf->vi[vf->current_link].codec_setup){
  141206. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141207. if(thisblock<0){
  141208. ogg_stream_packetout(&vf->os,NULL);
  141209. thisblock=0;
  141210. }else{
  141211. if(eosflag)
  141212. ogg_stream_packetout(&vf->os,NULL);
  141213. else
  141214. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141215. }
  141216. if(op.granulepos!=-1){
  141217. int i,link=vf->current_link;
  141218. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141219. if(granulepos<0)granulepos=0;
  141220. for(i=0;i<link;i++)
  141221. granulepos+=vf->pcmlengths[i*2+1];
  141222. vf->pcm_offset=granulepos-accblock;
  141223. break;
  141224. }
  141225. lastblock=thisblock;
  141226. continue;
  141227. }else
  141228. ogg_stream_packetout(&vf->os,NULL);
  141229. }
  141230. }
  141231. if(!lastblock){
  141232. if(_get_next_page(vf,&og,-1)<0){
  141233. vf->pcm_offset=ov_pcm_total(vf,-1);
  141234. break;
  141235. }
  141236. }else{
  141237. vf->pcm_offset=-1;
  141238. break;
  141239. }
  141240. if(vf->ready_state>=STREAMSET)
  141241. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141242. _decode_clear(vf); /* clear out stream state */
  141243. ogg_stream_clear(&work_os);
  141244. }
  141245. if(vf->ready_state<STREAMSET){
  141246. int link;
  141247. vf->current_serialno=ogg_page_serialno(&og);
  141248. for(link=0;link<vf->links;link++)
  141249. if(vf->serialnos[link]==vf->current_serialno)break;
  141250. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141251. error out, leave
  141252. machine uninitialized */
  141253. vf->current_link=link;
  141254. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141255. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141256. vf->ready_state=STREAMSET;
  141257. }
  141258. ogg_stream_pagein(&vf->os,&og);
  141259. ogg_stream_pagein(&work_os,&og);
  141260. eosflag=ogg_page_eos(&og);
  141261. }
  141262. }
  141263. ogg_stream_clear(&work_os);
  141264. vf->bittrack=0.f;
  141265. vf->samptrack=0.f;
  141266. return(0);
  141267. seek_error:
  141268. vf->pcm_offset=-1;
  141269. ogg_stream_clear(&work_os);
  141270. _decode_clear(vf);
  141271. return OV_EBADLINK;
  141272. }
  141273. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141274. int link=-1;
  141275. ogg_int64_t result=0;
  141276. ogg_int64_t total=ov_pcm_total(vf,-1);
  141277. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141278. if(!vf->seekable)return(OV_ENOSEEK);
  141279. if(pos<0 || pos>total)return(OV_EINVAL);
  141280. for(link=vf->links-1;link>=0;link--){
  141281. total-=vf->pcmlengths[link*2+1];
  141282. if(pos>=total)break;
  141283. }
  141284. {
  141285. ogg_int64_t end=vf->offsets[link+1];
  141286. ogg_int64_t begin=vf->offsets[link];
  141287. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141288. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141289. ogg_int64_t target=pos-total+begintime;
  141290. ogg_int64_t best=begin;
  141291. ogg_page og;
  141292. while(begin<end){
  141293. ogg_int64_t bisect;
  141294. if(end-begin<CHUNKSIZE){
  141295. bisect=begin;
  141296. }else{
  141297. bisect=begin +
  141298. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141299. if(bisect<=begin)
  141300. bisect=begin+1;
  141301. }
  141302. _seek_helper(vf,bisect);
  141303. while(begin<end){
  141304. result=_get_next_page(vf,&og,end-vf->offset);
  141305. if(result==OV_EREAD) goto seek_error;
  141306. if(result<0){
  141307. if(bisect<=begin+1)
  141308. end=begin; /* found it */
  141309. else{
  141310. if(bisect==0) goto seek_error;
  141311. bisect-=CHUNKSIZE;
  141312. if(bisect<=begin)bisect=begin+1;
  141313. _seek_helper(vf,bisect);
  141314. }
  141315. }else{
  141316. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141317. if(granulepos==-1)continue;
  141318. if(granulepos<target){
  141319. best=result; /* raw offset of packet with granulepos */
  141320. begin=vf->offset; /* raw offset of next page */
  141321. begintime=granulepos;
  141322. if(target-begintime>44100)break;
  141323. bisect=begin; /* *not* begin + 1 */
  141324. }else{
  141325. if(bisect<=begin+1)
  141326. end=begin; /* found it */
  141327. else{
  141328. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141329. end=result;
  141330. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141331. if(bisect<=begin)bisect=begin+1;
  141332. _seek_helper(vf,bisect);
  141333. }else{
  141334. end=result;
  141335. endtime=granulepos;
  141336. break;
  141337. }
  141338. }
  141339. }
  141340. }
  141341. }
  141342. }
  141343. {
  141344. ogg_page og;
  141345. ogg_packet op;
  141346. _seek_helper(vf,best);
  141347. vf->pcm_offset=-1;
  141348. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141349. if(link!=vf->current_link){
  141350. _decode_clear(vf);
  141351. vf->current_link=link;
  141352. vf->current_serialno=ogg_page_serialno(&og);
  141353. vf->ready_state=STREAMSET;
  141354. }else{
  141355. vorbis_synthesis_restart(&vf->vd);
  141356. }
  141357. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141358. ogg_stream_pagein(&vf->os,&og);
  141359. while(1){
  141360. result=ogg_stream_packetpeek(&vf->os,&op);
  141361. if(result==0){
  141362. _seek_helper(vf,best);
  141363. while(1){
  141364. result=_get_prev_page(vf,&og);
  141365. if(result<0) goto seek_error;
  141366. if(ogg_page_granulepos(&og)>-1 ||
  141367. !ogg_page_continued(&og)){
  141368. return ov_raw_seek(vf,result);
  141369. }
  141370. vf->offset=result;
  141371. }
  141372. }
  141373. if(result<0){
  141374. result = OV_EBADPACKET;
  141375. goto seek_error;
  141376. }
  141377. if(op.granulepos!=-1){
  141378. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141379. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141380. vf->pcm_offset+=total;
  141381. break;
  141382. }else
  141383. result=ogg_stream_packetout(&vf->os,NULL);
  141384. }
  141385. }
  141386. }
  141387. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141388. result=OV_EFAULT;
  141389. goto seek_error;
  141390. }
  141391. vf->bittrack=0.f;
  141392. vf->samptrack=0.f;
  141393. return(0);
  141394. seek_error:
  141395. vf->pcm_offset=-1;
  141396. _decode_clear(vf);
  141397. return (int)result;
  141398. }
  141399. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141400. int thisblock,lastblock=0;
  141401. int ret=ov_pcm_seek_page(vf,pos);
  141402. if(ret<0)return(ret);
  141403. if((ret=_make_decode_ready(vf)))return ret;
  141404. while(1){
  141405. ogg_packet op;
  141406. ogg_page og;
  141407. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141408. if(ret>0){
  141409. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141410. if(thisblock<0){
  141411. ogg_stream_packetout(&vf->os,NULL);
  141412. continue; /* non audio packet */
  141413. }
  141414. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141415. if(vf->pcm_offset+((thisblock+
  141416. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141417. ogg_stream_packetout(&vf->os,NULL);
  141418. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141419. only tracking, no
  141420. pcm_decode */
  141421. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141422. if(op.granulepos>-1){
  141423. int i;
  141424. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141425. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141426. for(i=0;i<vf->current_link;i++)
  141427. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141428. }
  141429. lastblock=thisblock;
  141430. }else{
  141431. if(ret<0 && ret!=OV_HOLE)break;
  141432. if(_get_next_page(vf,&og,-1)<0)break;
  141433. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141434. if(vf->ready_state<STREAMSET){
  141435. int link;
  141436. vf->current_serialno=ogg_page_serialno(&og);
  141437. for(link=0;link<vf->links;link++)
  141438. if(vf->serialnos[link]==vf->current_serialno)break;
  141439. if(link==vf->links)return(OV_EBADLINK);
  141440. vf->current_link=link;
  141441. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141442. vf->ready_state=STREAMSET;
  141443. ret=_make_decode_ready(vf);
  141444. if(ret)return ret;
  141445. lastblock=0;
  141446. }
  141447. ogg_stream_pagein(&vf->os,&og);
  141448. }
  141449. }
  141450. vf->bittrack=0.f;
  141451. vf->samptrack=0.f;
  141452. while(vf->pcm_offset<pos){
  141453. ogg_int64_t target=pos-vf->pcm_offset;
  141454. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141455. if(samples>target)samples=target;
  141456. vorbis_synthesis_read(&vf->vd,samples);
  141457. vf->pcm_offset+=samples;
  141458. if(samples<target)
  141459. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141460. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141461. }
  141462. return 0;
  141463. }
  141464. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141465. int link=-1;
  141466. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141467. double time_total=ov_time_total(vf,-1);
  141468. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141469. if(!vf->seekable)return(OV_ENOSEEK);
  141470. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141471. for(link=vf->links-1;link>=0;link--){
  141472. pcm_total-=vf->pcmlengths[link*2+1];
  141473. time_total-=ov_time_total(vf,link);
  141474. if(seconds>=time_total)break;
  141475. }
  141476. {
  141477. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141478. return(ov_pcm_seek(vf,target));
  141479. }
  141480. }
  141481. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141482. int link=-1;
  141483. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141484. double time_total=ov_time_total(vf,-1);
  141485. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141486. if(!vf->seekable)return(OV_ENOSEEK);
  141487. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141488. for(link=vf->links-1;link>=0;link--){
  141489. pcm_total-=vf->pcmlengths[link*2+1];
  141490. time_total-=ov_time_total(vf,link);
  141491. if(seconds>=time_total)break;
  141492. }
  141493. {
  141494. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141495. return(ov_pcm_seek_page(vf,target));
  141496. }
  141497. }
  141498. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141499. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141500. return(vf->offset);
  141501. }
  141502. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141503. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141504. return(vf->pcm_offset);
  141505. }
  141506. double ov_time_tell(OggVorbis_File *vf){
  141507. int link=0;
  141508. ogg_int64_t pcm_total=0;
  141509. double time_total=0.f;
  141510. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141511. if(vf->seekable){
  141512. pcm_total=ov_pcm_total(vf,-1);
  141513. time_total=ov_time_total(vf,-1);
  141514. for(link=vf->links-1;link>=0;link--){
  141515. pcm_total-=vf->pcmlengths[link*2+1];
  141516. time_total-=ov_time_total(vf,link);
  141517. if(vf->pcm_offset>=pcm_total)break;
  141518. }
  141519. }
  141520. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141521. }
  141522. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141523. if(vf->seekable){
  141524. if(link<0)
  141525. if(vf->ready_state>=STREAMSET)
  141526. return vf->vi+vf->current_link;
  141527. else
  141528. return vf->vi;
  141529. else
  141530. if(link>=vf->links)
  141531. return NULL;
  141532. else
  141533. return vf->vi+link;
  141534. }else{
  141535. return vf->vi;
  141536. }
  141537. }
  141538. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141539. if(vf->seekable){
  141540. if(link<0)
  141541. if(vf->ready_state>=STREAMSET)
  141542. return vf->vc+vf->current_link;
  141543. else
  141544. return vf->vc;
  141545. else
  141546. if(link>=vf->links)
  141547. return NULL;
  141548. else
  141549. return vf->vc+link;
  141550. }else{
  141551. return vf->vc;
  141552. }
  141553. }
  141554. static int host_is_big_endian() {
  141555. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141556. unsigned char *bytewise = (unsigned char *)&pattern;
  141557. if (bytewise[0] == 0xfe) return 1;
  141558. return 0;
  141559. }
  141560. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141561. int bigendianp,int word,int sgned,int *bitstream){
  141562. int i,j;
  141563. int host_endian = host_is_big_endian();
  141564. float **pcm;
  141565. long samples;
  141566. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141567. while(1){
  141568. if(vf->ready_state==INITSET){
  141569. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141570. if(samples)break;
  141571. }
  141572. {
  141573. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141574. if(ret==OV_EOF)
  141575. return(0);
  141576. if(ret<=0)
  141577. return(ret);
  141578. }
  141579. }
  141580. if(samples>0){
  141581. long channels=ov_info(vf,-1)->channels;
  141582. long bytespersample=word * channels;
  141583. vorbis_fpu_control fpu;
  141584. (void) fpu; // (to avoid a warning about it being unused)
  141585. if(samples>length/bytespersample)samples=length/bytespersample;
  141586. if(samples <= 0)
  141587. return OV_EINVAL;
  141588. {
  141589. int val;
  141590. if(word==1){
  141591. int off=(sgned?0:128);
  141592. vorbis_fpu_setround(&fpu);
  141593. for(j=0;j<samples;j++)
  141594. for(i=0;i<channels;i++){
  141595. val=vorbis_ftoi(pcm[i][j]*128.f);
  141596. if(val>127)val=127;
  141597. else if(val<-128)val=-128;
  141598. *buffer++=val+off;
  141599. }
  141600. vorbis_fpu_restore(fpu);
  141601. }else{
  141602. int off=(sgned?0:32768);
  141603. if(host_endian==bigendianp){
  141604. if(sgned){
  141605. vorbis_fpu_setround(&fpu);
  141606. for(i=0;i<channels;i++) { /* It's faster in this order */
  141607. float *src=pcm[i];
  141608. short *dest=((short *)buffer)+i;
  141609. for(j=0;j<samples;j++) {
  141610. val=vorbis_ftoi(src[j]*32768.f);
  141611. if(val>32767)val=32767;
  141612. else if(val<-32768)val=-32768;
  141613. *dest=val;
  141614. dest+=channels;
  141615. }
  141616. }
  141617. vorbis_fpu_restore(fpu);
  141618. }else{
  141619. vorbis_fpu_setround(&fpu);
  141620. for(i=0;i<channels;i++) {
  141621. float *src=pcm[i];
  141622. short *dest=((short *)buffer)+i;
  141623. for(j=0;j<samples;j++) {
  141624. val=vorbis_ftoi(src[j]*32768.f);
  141625. if(val>32767)val=32767;
  141626. else if(val<-32768)val=-32768;
  141627. *dest=val+off;
  141628. dest+=channels;
  141629. }
  141630. }
  141631. vorbis_fpu_restore(fpu);
  141632. }
  141633. }else if(bigendianp){
  141634. vorbis_fpu_setround(&fpu);
  141635. for(j=0;j<samples;j++)
  141636. for(i=0;i<channels;i++){
  141637. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141638. if(val>32767)val=32767;
  141639. else if(val<-32768)val=-32768;
  141640. val+=off;
  141641. *buffer++=(val>>8);
  141642. *buffer++=(val&0xff);
  141643. }
  141644. vorbis_fpu_restore(fpu);
  141645. }else{
  141646. int val;
  141647. vorbis_fpu_setround(&fpu);
  141648. for(j=0;j<samples;j++)
  141649. for(i=0;i<channels;i++){
  141650. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141651. if(val>32767)val=32767;
  141652. else if(val<-32768)val=-32768;
  141653. val+=off;
  141654. *buffer++=(val&0xff);
  141655. *buffer++=(val>>8);
  141656. }
  141657. vorbis_fpu_restore(fpu);
  141658. }
  141659. }
  141660. }
  141661. vorbis_synthesis_read(&vf->vd,samples);
  141662. vf->pcm_offset+=samples;
  141663. if(bitstream)*bitstream=vf->current_link;
  141664. return(samples*bytespersample);
  141665. }else{
  141666. return(samples);
  141667. }
  141668. }
  141669. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141670. int *bitstream){
  141671. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141672. while(1){
  141673. if(vf->ready_state==INITSET){
  141674. float **pcm;
  141675. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141676. if(samples){
  141677. if(pcm_channels)*pcm_channels=pcm;
  141678. if(samples>length)samples=length;
  141679. vorbis_synthesis_read(&vf->vd,samples);
  141680. vf->pcm_offset+=samples;
  141681. if(bitstream)*bitstream=vf->current_link;
  141682. return samples;
  141683. }
  141684. }
  141685. {
  141686. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141687. if(ret==OV_EOF)return(0);
  141688. if(ret<=0)return(ret);
  141689. }
  141690. }
  141691. }
  141692. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141693. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141694. ogg_int64_t off);
  141695. static void _ov_splice(float **pcm,float **lappcm,
  141696. int n1, int n2,
  141697. int ch1, int ch2,
  141698. float *w1, float *w2){
  141699. int i,j;
  141700. float *w=w1;
  141701. int n=n1;
  141702. if(n1>n2){
  141703. n=n2;
  141704. w=w2;
  141705. }
  141706. for(j=0;j<ch1 && j<ch2;j++){
  141707. float *s=lappcm[j];
  141708. float *d=pcm[j];
  141709. for(i=0;i<n;i++){
  141710. float wd=w[i]*w[i];
  141711. float ws=1.-wd;
  141712. d[i]=d[i]*wd + s[i]*ws;
  141713. }
  141714. }
  141715. for(;j<ch2;j++){
  141716. float *d=pcm[j];
  141717. for(i=0;i<n;i++){
  141718. float wd=w[i]*w[i];
  141719. d[i]=d[i]*wd;
  141720. }
  141721. }
  141722. }
  141723. static int _ov_initset(OggVorbis_File *vf){
  141724. while(1){
  141725. if(vf->ready_state==INITSET)break;
  141726. {
  141727. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141728. if(ret<0 && ret!=OV_HOLE)return(ret);
  141729. }
  141730. }
  141731. return 0;
  141732. }
  141733. static int _ov_initprime(OggVorbis_File *vf){
  141734. vorbis_dsp_state *vd=&vf->vd;
  141735. while(1){
  141736. if(vf->ready_state==INITSET)
  141737. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141738. {
  141739. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141740. if(ret<0 && ret!=OV_HOLE)return(ret);
  141741. }
  141742. }
  141743. return 0;
  141744. }
  141745. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141746. float **lappcm,int lapsize){
  141747. int lapcount=0,i;
  141748. float **pcm;
  141749. while(lapcount<lapsize){
  141750. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141751. if(samples){
  141752. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141753. for(i=0;i<vi->channels;i++)
  141754. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141755. lapcount+=samples;
  141756. vorbis_synthesis_read(vd,samples);
  141757. }else{
  141758. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141759. if(ret==OV_EOF)break;
  141760. }
  141761. }
  141762. if(lapcount<lapsize){
  141763. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141764. if(samples==0){
  141765. for(i=0;i<vi->channels;i++)
  141766. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141767. lapcount=lapsize;
  141768. }else{
  141769. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141770. for(i=0;i<vi->channels;i++)
  141771. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141772. lapcount+=samples;
  141773. }
  141774. }
  141775. }
  141776. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141777. vorbis_info *vi1,*vi2;
  141778. float **lappcm;
  141779. float **pcm;
  141780. float *w1,*w2;
  141781. int n1,n2,i,ret,hs1,hs2;
  141782. if(vf1==vf2)return(0); /* degenerate case */
  141783. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141784. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141785. ret=_ov_initset(vf1);
  141786. if(ret)return(ret);
  141787. ret=_ov_initprime(vf2);
  141788. if(ret)return(ret);
  141789. vi1=ov_info(vf1,-1);
  141790. vi2=ov_info(vf2,-1);
  141791. hs1=ov_halfrate_p(vf1);
  141792. hs2=ov_halfrate_p(vf2);
  141793. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141794. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141795. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141796. w1=vorbis_window(&vf1->vd,0);
  141797. w2=vorbis_window(&vf2->vd,0);
  141798. for(i=0;i<vi1->channels;i++)
  141799. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141800. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141801. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141802. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141803. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141804. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141805. return(0);
  141806. }
  141807. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141808. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141809. vorbis_info *vi;
  141810. float **lappcm;
  141811. float **pcm;
  141812. float *w1,*w2;
  141813. int n1,n2,ch1,ch2,hs;
  141814. int i,ret;
  141815. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141816. ret=_ov_initset(vf);
  141817. if(ret)return(ret);
  141818. vi=ov_info(vf,-1);
  141819. hs=ov_halfrate_p(vf);
  141820. ch1=vi->channels;
  141821. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141822. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141823. persistent; even if the decode state
  141824. from this link gets dumped, this
  141825. window array continues to exist */
  141826. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141827. for(i=0;i<ch1;i++)
  141828. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141829. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141830. ret=localseek(vf,pos);
  141831. if(ret)return ret;
  141832. ret=_ov_initprime(vf);
  141833. if(ret)return(ret);
  141834. vi=ov_info(vf,-1);
  141835. ch2=vi->channels;
  141836. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141837. w2=vorbis_window(&vf->vd,0);
  141838. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141839. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141840. return(0);
  141841. }
  141842. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141843. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  141844. }
  141845. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141846. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  141847. }
  141848. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141849. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  141850. }
  141851. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  141852. int (*localseek)(OggVorbis_File *,double)){
  141853. vorbis_info *vi;
  141854. float **lappcm;
  141855. float **pcm;
  141856. float *w1,*w2;
  141857. int n1,n2,ch1,ch2,hs;
  141858. int i,ret;
  141859. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141860. ret=_ov_initset(vf);
  141861. if(ret)return(ret);
  141862. vi=ov_info(vf,-1);
  141863. hs=ov_halfrate_p(vf);
  141864. ch1=vi->channels;
  141865. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141866. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141867. persistent; even if the decode state
  141868. from this link gets dumped, this
  141869. window array continues to exist */
  141870. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141871. for(i=0;i<ch1;i++)
  141872. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141873. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141874. ret=localseek(vf,pos);
  141875. if(ret)return ret;
  141876. ret=_ov_initprime(vf);
  141877. if(ret)return(ret);
  141878. vi=ov_info(vf,-1);
  141879. ch2=vi->channels;
  141880. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141881. w2=vorbis_window(&vf->vd,0);
  141882. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141883. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141884. return(0);
  141885. }
  141886. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  141887. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  141888. }
  141889. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  141890. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  141891. }
  141892. #endif
  141893. /*** End of inlined file: vorbisfile.c ***/
  141894. /*** Start of inlined file: window.c ***/
  141895. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141896. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141897. // tasks..
  141898. #if JUCE_MSVC
  141899. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141900. #endif
  141901. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141902. #if JUCE_USE_OGGVORBIS
  141903. #include <stdlib.h>
  141904. #include <math.h>
  141905. static float vwin64[32] = {
  141906. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  141907. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  141908. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  141909. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  141910. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  141911. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  141912. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  141913. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  141914. };
  141915. static float vwin128[64] = {
  141916. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  141917. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  141918. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  141919. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  141920. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  141921. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  141922. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  141923. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  141924. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  141925. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  141926. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  141927. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  141928. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  141929. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  141930. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  141931. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  141932. };
  141933. static float vwin256[128] = {
  141934. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  141935. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  141936. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  141937. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  141938. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  141939. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  141940. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  141941. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  141942. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  141943. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  141944. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  141945. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  141946. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  141947. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  141948. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  141949. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  141950. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  141951. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  141952. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  141953. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  141954. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  141955. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  141956. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  141957. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  141958. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  141959. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  141960. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  141961. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  141962. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  141963. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  141964. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  141965. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  141966. };
  141967. static float vwin512[256] = {
  141968. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  141969. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  141970. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  141971. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  141972. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  141973. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  141974. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  141975. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  141976. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  141977. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  141978. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  141979. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  141980. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  141981. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  141982. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  141983. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  141984. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  141985. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  141986. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  141987. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  141988. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  141989. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  141990. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  141991. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  141992. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  141993. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  141994. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  141995. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  141996. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  141997. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  141998. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  141999. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142000. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142001. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142002. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142003. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142004. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142005. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142006. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142007. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142008. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142009. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142010. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142011. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142012. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142013. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142014. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142015. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142016. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142017. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142018. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142019. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142020. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142021. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142022. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142023. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142024. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142025. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142026. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142027. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142028. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142029. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142030. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142031. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142032. };
  142033. static float vwin1024[512] = {
  142034. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142035. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142036. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142037. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142038. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142039. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142040. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142041. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142042. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142043. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142044. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142045. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142046. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142047. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142048. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142049. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142050. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142051. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142052. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142053. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142054. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142055. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142056. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142057. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142058. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142059. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142060. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142061. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142062. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142063. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142064. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142065. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142066. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142067. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142068. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142069. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142070. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142071. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142072. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142073. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142074. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142075. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142076. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142077. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142078. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142079. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142080. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142081. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142082. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142083. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142084. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142085. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142086. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142087. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142088. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142089. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142090. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142091. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142092. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142093. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142094. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142095. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142096. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142097. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142098. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142099. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142100. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142101. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142102. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142103. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142104. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142105. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142106. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142107. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142108. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142109. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142110. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142111. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142112. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142113. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142114. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142115. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142116. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142117. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142118. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142119. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142120. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142121. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142122. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142123. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142124. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142125. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142126. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142127. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142128. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142129. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142130. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142131. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142132. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142133. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142134. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142135. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142136. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142137. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142138. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142139. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142140. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142141. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142142. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142143. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142144. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142145. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142146. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142147. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142148. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142149. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142150. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142151. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142152. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142153. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142154. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142155. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142156. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142157. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142158. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142159. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142160. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142161. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142162. };
  142163. static float vwin2048[1024] = {
  142164. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142165. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142166. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142167. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142168. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142169. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142170. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142171. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142172. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142173. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142174. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142175. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142176. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142177. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142178. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142179. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142180. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142181. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142182. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142183. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142184. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142185. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142186. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142187. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142188. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142189. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142190. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142191. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142192. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142193. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142194. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142195. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142196. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142197. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142198. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142199. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142200. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142201. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142202. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142203. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142204. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142205. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142206. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142207. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142208. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142209. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142210. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142211. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142212. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142213. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142214. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142215. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142216. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142217. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142218. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142219. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142220. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142221. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142222. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142223. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142224. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142225. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142226. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142227. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142228. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142229. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142230. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142231. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142232. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142233. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142234. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142235. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142236. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142237. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142238. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142239. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142240. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142241. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142242. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142243. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142244. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142245. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142246. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142247. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142248. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142249. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142250. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142251. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142252. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142253. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142254. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142255. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142256. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142257. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142258. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142259. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142260. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142261. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142262. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142263. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142264. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142265. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142266. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142267. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142268. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142269. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142270. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142271. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142272. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142273. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142274. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142275. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142276. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142277. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142278. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142279. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142280. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142281. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142282. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142283. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142284. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142285. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142286. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142287. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142288. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142289. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142290. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142291. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142292. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142293. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142294. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142295. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142296. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142297. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142298. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142299. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142300. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142301. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142302. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142303. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142304. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142305. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142306. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142307. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142308. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142309. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142310. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142311. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142312. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142313. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142314. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142315. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142316. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142317. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142318. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142319. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142320. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142321. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142322. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142323. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142324. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142325. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142326. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142327. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142328. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142329. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142330. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142331. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142332. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142333. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142334. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142335. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142336. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142337. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142338. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142339. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142340. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142341. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142342. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142343. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142344. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142345. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142346. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142347. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142348. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142349. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142350. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142351. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142352. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142353. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142354. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142355. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142356. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142357. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142358. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142359. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142360. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142361. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142362. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142363. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142364. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142365. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142366. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142367. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142368. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142369. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142370. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142371. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142372. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142373. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142374. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142375. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142376. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142377. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142378. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142379. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142380. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142381. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142382. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142383. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142384. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142385. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142386. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142387. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142388. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142389. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142390. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142391. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142392. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142393. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142394. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142395. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142396. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142397. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142398. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142399. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142400. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142401. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142402. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142403. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142404. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142405. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142406. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142407. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142408. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142409. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142410. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142411. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142412. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142413. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142414. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142415. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142416. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142417. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142418. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142419. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142420. };
  142421. static float vwin4096[2048] = {
  142422. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142423. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142424. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142425. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142426. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142427. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142428. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142429. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142430. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142431. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142432. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142433. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142434. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142435. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142436. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142437. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142438. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142439. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142440. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142441. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142442. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142443. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142444. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142445. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142446. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142447. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142448. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142449. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142450. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142451. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142452. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142453. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142454. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142455. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142456. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142457. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142458. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142459. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142460. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142461. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142462. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142463. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142464. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142465. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142466. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142467. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142468. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142469. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142470. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142471. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142472. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142473. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142474. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142475. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142476. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142477. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142478. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142479. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142480. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142481. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142482. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142483. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142484. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142485. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142486. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142487. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142488. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142489. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142490. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142491. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142492. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142493. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142494. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142495. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142496. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142497. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142498. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142499. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142500. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142501. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142502. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142503. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142504. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142505. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142506. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142507. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142508. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142509. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142510. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142511. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142512. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142513. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142514. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142515. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142516. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142517. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142518. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142519. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142520. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142521. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142522. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142523. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142524. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142525. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142526. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142527. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142528. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142529. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142530. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142531. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142532. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142533. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142534. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142535. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142536. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142537. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142538. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142539. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142540. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142541. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142542. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142543. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142544. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142545. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142546. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142547. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142548. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142549. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142550. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142551. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142552. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142553. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142554. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142555. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142556. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142557. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142558. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142559. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142560. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142561. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142562. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142563. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142564. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142565. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142566. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142567. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142568. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142569. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142570. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142571. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142572. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142573. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142574. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142575. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142576. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142577. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142578. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142579. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142580. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142581. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142582. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142583. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142584. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142585. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142586. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142587. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142588. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142589. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142590. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142591. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142592. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142593. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142594. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142595. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142596. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142597. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142598. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142599. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142600. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142601. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142602. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142603. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142604. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142605. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142606. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142607. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142608. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142609. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142610. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142611. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142612. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142613. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142614. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142615. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142616. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142617. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142618. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142619. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142620. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142621. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142622. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142623. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142624. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142625. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142626. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142627. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142628. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142629. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142630. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142631. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142632. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142633. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142634. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142635. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142636. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142637. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142638. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142639. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142640. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142641. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142642. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142643. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142644. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142645. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142646. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142647. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142648. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142649. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142650. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142651. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142652. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142653. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142654. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142655. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142656. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142657. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142658. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142659. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142660. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142661. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142662. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142663. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142664. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142665. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142666. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142667. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142668. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142669. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142670. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142671. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142672. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142673. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142674. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142675. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142676. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142677. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142678. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142679. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142680. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142681. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142682. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142683. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142684. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142685. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142686. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142687. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142688. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142689. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142690. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142691. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142692. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142693. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142694. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142695. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142696. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142697. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142698. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142699. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142700. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142701. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142702. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142703. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142704. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142705. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142706. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142707. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142708. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142709. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142710. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142711. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142712. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142713. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142714. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142715. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142716. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142717. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142718. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142719. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142720. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142721. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142722. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142723. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142724. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142725. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142726. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142727. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142728. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142729. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142730. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142731. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142732. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142733. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142734. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142735. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142736. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142737. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142738. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142739. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142740. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142741. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142742. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142743. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142744. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142745. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142746. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142747. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142748. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142749. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142750. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142751. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142752. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142753. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142754. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142755. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142756. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142757. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142758. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142759. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142760. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142761. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142762. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142763. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142764. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142765. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142766. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142767. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142768. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142769. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142770. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142771. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142772. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142773. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142774. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142775. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142776. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142777. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142778. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142779. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142780. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142781. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142782. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142783. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142784. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142785. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142786. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142787. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142788. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142789. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142790. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142791. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142792. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142793. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142794. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142795. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142796. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142797. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142798. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142799. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142800. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142801. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142802. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142803. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142804. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142805. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142806. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142807. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142808. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142809. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  142810. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  142811. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  142812. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  142813. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  142814. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  142815. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  142816. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  142817. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  142818. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  142819. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  142820. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  142821. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  142822. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  142823. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  142824. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  142825. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  142826. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  142827. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  142828. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  142829. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  142830. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  142831. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  142832. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  142833. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  142834. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  142835. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  142836. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  142837. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  142838. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  142839. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  142840. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  142841. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  142842. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  142843. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  142844. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  142845. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  142846. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  142847. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  142848. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  142849. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  142850. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  142851. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  142852. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  142853. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  142854. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  142855. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  142856. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  142857. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  142858. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  142859. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  142860. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  142861. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  142862. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  142863. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  142864. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  142865. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  142866. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  142867. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  142868. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  142869. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  142870. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  142871. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  142872. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  142873. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  142874. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  142875. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  142876. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  142877. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  142878. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  142879. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  142880. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  142881. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  142882. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  142883. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  142884. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  142885. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  142886. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  142887. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  142888. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  142889. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  142890. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  142891. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  142892. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  142893. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  142894. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  142895. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  142896. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  142897. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  142898. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  142899. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  142900. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  142901. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  142902. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  142903. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  142904. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  142905. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  142906. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  142907. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  142908. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  142909. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  142910. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  142911. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  142912. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  142913. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  142914. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  142915. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  142916. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  142917. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  142918. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  142919. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  142920. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  142921. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  142922. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  142923. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  142924. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  142925. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  142926. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  142927. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  142928. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  142929. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  142930. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  142931. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  142932. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  142933. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  142934. };
  142935. static float vwin8192[4096] = {
  142936. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  142937. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  142938. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  142939. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  142940. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  142941. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  142942. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  142943. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  142944. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  142945. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  142946. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  142947. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  142948. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  142949. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  142950. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  142951. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  142952. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  142953. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  142954. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  142955. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  142956. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  142957. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  142958. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  142959. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  142960. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  142961. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  142962. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  142963. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  142964. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  142965. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  142966. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  142967. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  142968. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  142969. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  142970. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  142971. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  142972. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  142973. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  142974. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  142975. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  142976. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  142977. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  142978. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  142979. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  142980. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  142981. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  142982. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  142983. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  142984. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  142985. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  142986. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  142987. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  142988. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  142989. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  142990. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  142991. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  142992. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  142993. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  142994. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  142995. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  142996. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  142997. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  142998. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  142999. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143000. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143001. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143002. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143003. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143004. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143005. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143006. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143007. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143008. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143009. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143010. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143011. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143012. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143013. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143014. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143015. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143016. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143017. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143018. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143019. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143020. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143021. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143022. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143023. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143024. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143025. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143026. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143027. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143028. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143029. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143030. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143031. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143032. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143033. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143034. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143035. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143036. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143037. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143038. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143039. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143040. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143041. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143042. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143043. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143044. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143045. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143046. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143047. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143048. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143049. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143050. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143051. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143052. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143053. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143054. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143055. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143056. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143057. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143058. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143059. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143060. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143061. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143062. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143063. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143064. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143065. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143066. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143067. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143068. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143069. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143070. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143071. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143072. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143073. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143074. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143075. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143076. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143077. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143078. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143079. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143080. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143081. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143082. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143083. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143084. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143085. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143086. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143087. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143088. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143089. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143090. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143091. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143092. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143093. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143094. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143095. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143096. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143097. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143098. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143099. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143100. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143101. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143102. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143103. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143104. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143105. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143106. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143107. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143108. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143109. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143110. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143111. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143112. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143113. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143114. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143115. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143116. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143117. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143118. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143119. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143120. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143121. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143122. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143123. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143124. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143125. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143126. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143127. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143128. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143129. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143130. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143131. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143132. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143133. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143134. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143135. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143136. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143137. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143138. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143139. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143140. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143141. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143142. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143143. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143144. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143145. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143146. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143147. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143148. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143149. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143150. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143151. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143152. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143153. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143154. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143155. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143156. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143157. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143158. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143159. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143160. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143161. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143162. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143163. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143164. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143165. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143166. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143167. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143168. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143169. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143170. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143171. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143172. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143173. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143174. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143175. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143176. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143177. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143178. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143179. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143180. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143181. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143182. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143183. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143184. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143185. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143186. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143187. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143188. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143189. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143190. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143191. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143192. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143193. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143194. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143195. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143196. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143197. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143198. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143199. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143200. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143201. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143202. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143203. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143204. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143205. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143206. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143207. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143208. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143209. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143210. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143211. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143212. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143213. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143214. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143215. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143216. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143217. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143218. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143219. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143220. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143221. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143222. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143223. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143224. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143225. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143226. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143227. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143228. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143229. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143230. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143231. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143232. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143233. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143234. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143235. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143236. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143237. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143238. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143239. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143240. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143241. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143242. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143243. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143244. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143245. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143246. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143247. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143248. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143249. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143250. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143251. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143252. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143253. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143254. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143255. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143256. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143257. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143258. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143259. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143260. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143261. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143262. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143263. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143264. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143265. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143266. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143267. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143268. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143269. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143270. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143271. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143272. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143273. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143274. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143275. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143276. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143277. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143278. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143279. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143280. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143281. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143282. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143283. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143284. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143285. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143286. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143287. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143288. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143289. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143290. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143291. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143292. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143293. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143294. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143295. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143296. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143297. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143298. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143299. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143300. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143301. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143302. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143303. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143304. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143305. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143306. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143307. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143308. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143309. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143310. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143311. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143312. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143313. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143314. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143315. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143316. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143317. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143318. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143319. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143320. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143321. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143322. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143323. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143324. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143325. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143326. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143327. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143328. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143329. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143330. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143331. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143332. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143333. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143334. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143335. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143336. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143337. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143338. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143339. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143340. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143341. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143342. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143343. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143344. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143345. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143346. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143347. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143348. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143349. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143350. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143351. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143352. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143353. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143354. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143355. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143356. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143357. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143358. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143359. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143360. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143361. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143362. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143363. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143364. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143365. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143366. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143367. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143368. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143369. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143370. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143371. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143372. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143373. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143374. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143375. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143376. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143377. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143378. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143379. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143380. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143381. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143382. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143383. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143384. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143385. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143386. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143387. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143388. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143389. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143390. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143391. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143392. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143393. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143394. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143395. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143396. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143397. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143398. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143399. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143400. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143401. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143402. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143403. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143404. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143405. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143406. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143407. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143408. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143409. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143410. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143411. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143412. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143413. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143414. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143415. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143416. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143417. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143418. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143419. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143420. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143421. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143422. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143423. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143424. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143425. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143426. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143427. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143428. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143429. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143430. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143431. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143432. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143433. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143434. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143435. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143436. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143437. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143438. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143439. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143440. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143441. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143442. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143443. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143444. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143445. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143446. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143447. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143448. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143449. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143450. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143451. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143452. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143453. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143454. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143455. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143456. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143457. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143458. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143459. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143460. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143461. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143462. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143463. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143464. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143465. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143466. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143467. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143468. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143469. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143470. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143471. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143472. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143473. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143474. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143475. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143476. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143477. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143478. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143479. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143480. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143481. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143482. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143483. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143484. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143485. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143486. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143487. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143488. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143489. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143490. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143491. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143492. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143493. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143494. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143495. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143496. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143497. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143498. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143499. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143500. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143501. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143502. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143503. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143504. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143505. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143506. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143507. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143508. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143509. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143510. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143511. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143512. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143513. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143514. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143515. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143516. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143517. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143518. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143519. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143520. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143521. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143522. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143523. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143524. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143525. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143526. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143527. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143528. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143529. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143530. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143531. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143532. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143533. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143534. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143535. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143536. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143537. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143538. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143539. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143540. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143541. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143542. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143543. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143544. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143545. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143546. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143547. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143548. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143549. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143550. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143551. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143552. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143553. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143554. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143555. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143556. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143557. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143558. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143559. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143560. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143561. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143562. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143563. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143564. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143565. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143566. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143567. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143568. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143569. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143570. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143571. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143572. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143573. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143574. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143575. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143576. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143577. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143578. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143579. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143580. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143581. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143582. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143583. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143584. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143585. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143586. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143587. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143588. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143589. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143590. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143591. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143592. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143593. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143594. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143595. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143596. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143597. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143598. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143599. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143600. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143601. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143602. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143603. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143604. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143605. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143606. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143607. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143608. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143609. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143610. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143611. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143612. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143613. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143614. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143615. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143616. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143617. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143618. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143619. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143620. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143621. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143622. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143623. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143624. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143625. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143626. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143627. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143628. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143629. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143630. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143631. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143632. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143633. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143634. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143635. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143636. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143637. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143638. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143639. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143640. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143641. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143642. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143643. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143644. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143645. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143646. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143647. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143648. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143649. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143650. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143651. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143652. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143653. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143654. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143655. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143656. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143657. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143658. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143659. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143660. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143661. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143662. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143663. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143664. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143665. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143666. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143667. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143668. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143669. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143670. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143671. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143672. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143673. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143674. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143675. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143676. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143677. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143678. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143679. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143680. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143681. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143682. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143683. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143684. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143685. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143686. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143687. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143688. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143689. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143690. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143691. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143692. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143693. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143694. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143695. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143696. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143697. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143698. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143699. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143700. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143701. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143702. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143703. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143704. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143705. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143706. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143707. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143708. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143709. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143710. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143711. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143712. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143713. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143714. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143715. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143716. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143717. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143718. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143719. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143720. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143721. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143722. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143723. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143724. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143725. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143726. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143727. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143728. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143729. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143730. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143731. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143732. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143733. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143734. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143735. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143736. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143737. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143738. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143739. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143740. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143741. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143742. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143743. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143744. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143745. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143746. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143747. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143748. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143749. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143750. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143751. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143752. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143753. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143754. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143755. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143756. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143757. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143758. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143759. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143760. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143761. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143762. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143763. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143764. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143765. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143766. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143767. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143768. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143769. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143770. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143771. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143772. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143773. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143774. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143775. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143776. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143777. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143778. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143779. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143780. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143781. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143782. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143783. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143784. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143785. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143786. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143787. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143788. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143789. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143790. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143791. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143792. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143793. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143794. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143795. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143796. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143797. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143798. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143799. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143800. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143801. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143802. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143803. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143804. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143805. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143806. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143807. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143808. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143809. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  143810. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  143811. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  143812. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  143813. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  143814. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  143815. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  143816. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  143817. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  143818. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  143819. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  143820. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  143821. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  143822. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  143823. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  143824. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  143825. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  143826. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  143827. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  143828. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  143829. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  143830. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  143831. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  143832. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  143833. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  143834. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  143835. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  143836. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  143837. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  143838. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  143839. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  143840. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  143841. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  143842. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  143843. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  143844. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  143845. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  143846. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  143847. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  143848. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  143849. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  143850. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  143851. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  143852. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  143853. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  143854. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  143855. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  143856. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  143857. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  143858. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  143859. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  143860. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  143861. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  143862. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  143863. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  143864. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  143865. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  143866. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  143867. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  143868. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  143869. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  143870. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  143871. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  143872. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  143873. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  143874. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  143875. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  143876. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  143877. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  143878. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  143879. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  143880. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  143881. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  143882. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  143883. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  143884. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  143885. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  143886. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  143887. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  143888. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  143889. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  143890. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  143891. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  143892. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  143893. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  143894. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  143895. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  143896. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  143897. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  143898. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  143899. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  143900. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  143901. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  143902. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  143903. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  143904. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  143905. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  143906. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  143907. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  143908. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  143909. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  143910. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  143911. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  143912. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  143913. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  143914. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  143915. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  143916. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  143917. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  143918. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  143919. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  143920. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  143921. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  143922. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  143923. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  143924. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  143925. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  143926. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  143927. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  143928. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  143929. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  143930. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  143931. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  143932. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  143933. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  143934. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  143935. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  143936. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  143937. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  143938. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  143939. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  143940. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  143941. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  143942. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  143943. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  143944. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  143945. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  143946. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  143947. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  143948. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  143949. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  143950. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  143951. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  143952. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  143953. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  143954. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  143955. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  143956. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  143957. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  143958. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143959. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143960. };
  143961. static float *vwin[8] = {
  143962. vwin64,
  143963. vwin128,
  143964. vwin256,
  143965. vwin512,
  143966. vwin1024,
  143967. vwin2048,
  143968. vwin4096,
  143969. vwin8192,
  143970. };
  143971. float *_vorbis_window_get(int n){
  143972. return vwin[n];
  143973. }
  143974. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  143975. int lW,int W,int nW){
  143976. lW=(W?lW:0);
  143977. nW=(W?nW:0);
  143978. {
  143979. float *windowLW=vwin[winno[lW]];
  143980. float *windowNW=vwin[winno[nW]];
  143981. long n=blocksizes[W];
  143982. long ln=blocksizes[lW];
  143983. long rn=blocksizes[nW];
  143984. long leftbegin=n/4-ln/4;
  143985. long leftend=leftbegin+ln/2;
  143986. long rightbegin=n/2+n/4-rn/4;
  143987. long rightend=rightbegin+rn/2;
  143988. int i,p;
  143989. for(i=0;i<leftbegin;i++)
  143990. d[i]=0.f;
  143991. for(p=0;i<leftend;i++,p++)
  143992. d[i]*=windowLW[p];
  143993. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  143994. d[i]*=windowNW[p];
  143995. for(;i<n;i++)
  143996. d[i]=0.f;
  143997. }
  143998. }
  143999. #endif
  144000. /*** End of inlined file: window.c ***/
  144001. #else
  144002. #include <vorbis/vorbisenc.h>
  144003. #include <vorbis/codec.h>
  144004. #include <vorbis/vorbisfile.h>
  144005. #endif
  144006. }
  144007. #undef max
  144008. #undef min
  144009. BEGIN_JUCE_NAMESPACE
  144010. static const char* const oggFormatName = "Ogg-Vorbis file";
  144011. static const juce_wchar* const oggExtensions[] = { T(".ogg"), 0 };
  144012. class OggReader : public AudioFormatReader
  144013. {
  144014. OggVorbisNamespace::OggVorbis_File ovFile;
  144015. OggVorbisNamespace::ov_callbacks callbacks;
  144016. AudioSampleBuffer reservoir;
  144017. int reservoirStart, samplesInReservoir;
  144018. public:
  144019. OggReader (InputStream* const inp)
  144020. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144021. reservoir (2, 4096),
  144022. reservoirStart (0),
  144023. samplesInReservoir (0)
  144024. {
  144025. using namespace OggVorbisNamespace;
  144026. sampleRate = 0;
  144027. usesFloatingPointData = true;
  144028. callbacks.read_func = &oggReadCallback;
  144029. callbacks.seek_func = &oggSeekCallback;
  144030. callbacks.close_func = &oggCloseCallback;
  144031. callbacks.tell_func = &oggTellCallback;
  144032. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144033. if (err == 0)
  144034. {
  144035. vorbis_info* info = ov_info (&ovFile, -1);
  144036. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144037. numChannels = info->channels;
  144038. bitsPerSample = 16;
  144039. sampleRate = info->rate;
  144040. reservoir.setSize (numChannels,
  144041. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144042. }
  144043. }
  144044. ~OggReader()
  144045. {
  144046. OggVorbisNamespace::ov_clear (&ovFile);
  144047. }
  144048. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144049. int64 startSampleInFile, int numSamples)
  144050. {
  144051. while (numSamples > 0)
  144052. {
  144053. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144054. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144055. {
  144056. // got a few samples overlapping, so use them before seeking..
  144057. const int numToUse = jmin (numSamples, numAvailable);
  144058. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144059. if (destSamples[i] != 0)
  144060. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144061. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144062. sizeof (float) * numToUse);
  144063. startSampleInFile += numToUse;
  144064. numSamples -= numToUse;
  144065. startOffsetInDestBuffer += numToUse;
  144066. if (numSamples == 0)
  144067. break;
  144068. }
  144069. if (startSampleInFile < reservoirStart
  144070. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144071. {
  144072. // buffer miss, so refill the reservoir
  144073. int bitStream = 0;
  144074. reservoirStart = jmax (0, (int) startSampleInFile);
  144075. samplesInReservoir = reservoir.getNumSamples();
  144076. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  144077. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  144078. int offset = 0;
  144079. int numToRead = samplesInReservoir;
  144080. while (numToRead > 0)
  144081. {
  144082. float** dataIn = 0;
  144083. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144084. if (samps <= 0)
  144085. break;
  144086. jassert (samps <= numToRead);
  144087. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144088. {
  144089. memcpy (reservoir.getSampleData (i, offset),
  144090. dataIn[i],
  144091. sizeof (float) * samps);
  144092. }
  144093. numToRead -= samps;
  144094. offset += samps;
  144095. }
  144096. if (numToRead > 0)
  144097. reservoir.clear (offset, numToRead);
  144098. }
  144099. }
  144100. if (numSamples > 0)
  144101. {
  144102. for (int i = numDestChannels; --i >= 0;)
  144103. if (destSamples[i] != 0)
  144104. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144105. sizeof (int) * numSamples);
  144106. }
  144107. return true;
  144108. }
  144109. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144110. {
  144111. return (size_t) (static_cast <InputStream*> (datasource)->read (ptr, (int) (size * nmemb)) / size);
  144112. }
  144113. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144114. {
  144115. InputStream* const in = static_cast <InputStream*> (datasource);
  144116. if (whence == SEEK_CUR)
  144117. offset += in->getPosition();
  144118. else if (whence == SEEK_END)
  144119. offset += in->getTotalLength();
  144120. in->setPosition (offset);
  144121. return 0;
  144122. }
  144123. static int oggCloseCallback (void*)
  144124. {
  144125. return 0;
  144126. }
  144127. static long oggTellCallback (void* datasource)
  144128. {
  144129. return (long) static_cast <InputStream*> (datasource)->getPosition();
  144130. }
  144131. juce_UseDebuggingNewOperator
  144132. };
  144133. class OggWriter : public AudioFormatWriter
  144134. {
  144135. OggVorbisNamespace::ogg_stream_state os;
  144136. OggVorbisNamespace::ogg_page og;
  144137. OggVorbisNamespace::ogg_packet op;
  144138. OggVorbisNamespace::vorbis_info vi;
  144139. OggVorbisNamespace::vorbis_comment vc;
  144140. OggVorbisNamespace::vorbis_dsp_state vd;
  144141. OggVorbisNamespace::vorbis_block vb;
  144142. public:
  144143. bool ok;
  144144. OggWriter (OutputStream* const out,
  144145. const double sampleRate,
  144146. const int numChannels,
  144147. const int bitsPerSample,
  144148. const int qualityIndex)
  144149. : AudioFormatWriter (out, TRANS (oggFormatName),
  144150. sampleRate,
  144151. numChannels,
  144152. bitsPerSample)
  144153. {
  144154. using namespace OggVorbisNamespace;
  144155. ok = false;
  144156. vorbis_info_init (&vi);
  144157. if (vorbis_encode_init_vbr (&vi,
  144158. numChannels,
  144159. (int) sampleRate,
  144160. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144161. {
  144162. vorbis_comment_init (&vc);
  144163. if (JUCEApplication::getInstance() != 0)
  144164. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144165. vorbis_analysis_init (&vd, &vi);
  144166. vorbis_block_init (&vd, &vb);
  144167. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144168. ogg_packet header;
  144169. ogg_packet header_comm;
  144170. ogg_packet header_code;
  144171. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144172. ogg_stream_packetin (&os, &header);
  144173. ogg_stream_packetin (&os, &header_comm);
  144174. ogg_stream_packetin (&os, &header_code);
  144175. for (;;)
  144176. {
  144177. if (ogg_stream_flush (&os, &og) == 0)
  144178. break;
  144179. output->write (og.header, og.header_len);
  144180. output->write (og.body, og.body_len);
  144181. }
  144182. ok = true;
  144183. }
  144184. }
  144185. ~OggWriter()
  144186. {
  144187. using namespace OggVorbisNamespace;
  144188. if (ok)
  144189. {
  144190. // write a zero-length packet to show ogg that we're finished..
  144191. write (0, 0);
  144192. ogg_stream_clear (&os);
  144193. vorbis_block_clear (&vb);
  144194. vorbis_dsp_clear (&vd);
  144195. vorbis_comment_clear (&vc);
  144196. vorbis_info_clear (&vi);
  144197. output->flush();
  144198. }
  144199. else
  144200. {
  144201. vorbis_info_clear (&vi);
  144202. output = 0; // to stop the base class deleting this, as it needs to be returned
  144203. // to the caller of createWriter()
  144204. }
  144205. }
  144206. bool write (const int** samplesToWrite, int numSamples)
  144207. {
  144208. using namespace OggVorbisNamespace;
  144209. if (! ok)
  144210. return false;
  144211. if (numSamples > 0)
  144212. {
  144213. const double gain = 1.0 / 0x80000000u;
  144214. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144215. for (int i = numChannels; --i >= 0;)
  144216. {
  144217. float* const dst = vorbisBuffer[i];
  144218. const int* const src = samplesToWrite [i];
  144219. if (src != 0 && dst != 0)
  144220. {
  144221. for (int j = 0; j < numSamples; ++j)
  144222. dst[j] = (float) (src[j] * gain);
  144223. }
  144224. }
  144225. }
  144226. vorbis_analysis_wrote (&vd, numSamples);
  144227. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144228. {
  144229. vorbis_analysis (&vb, 0);
  144230. vorbis_bitrate_addblock (&vb);
  144231. while (vorbis_bitrate_flushpacket (&vd, &op))
  144232. {
  144233. ogg_stream_packetin (&os, &op);
  144234. for (;;)
  144235. {
  144236. if (ogg_stream_pageout (&os, &og) == 0)
  144237. break;
  144238. output->write (og.header, og.header_len);
  144239. output->write (og.body, og.body_len);
  144240. if (ogg_page_eos (&og))
  144241. break;
  144242. }
  144243. }
  144244. }
  144245. return true;
  144246. }
  144247. juce_UseDebuggingNewOperator
  144248. };
  144249. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144250. : AudioFormat (TRANS (oggFormatName), (const juce_wchar**) oggExtensions)
  144251. {
  144252. }
  144253. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144254. {
  144255. }
  144256. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144257. {
  144258. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144259. return Array <int> (rates);
  144260. }
  144261. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144262. {
  144263. Array <int> depths;
  144264. depths.add (32);
  144265. return depths;
  144266. }
  144267. bool OggVorbisAudioFormat::canDoStereo()
  144268. {
  144269. return true;
  144270. }
  144271. bool OggVorbisAudioFormat::canDoMono()
  144272. {
  144273. return true;
  144274. }
  144275. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144276. const bool deleteStreamIfOpeningFails)
  144277. {
  144278. ScopedPointer <OggReader> r (new OggReader (in));
  144279. if (r->sampleRate != 0)
  144280. return r.release();
  144281. if (! deleteStreamIfOpeningFails)
  144282. r->input = 0;
  144283. return 0;
  144284. }
  144285. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144286. double sampleRate,
  144287. unsigned int numChannels,
  144288. int bitsPerSample,
  144289. const StringPairArray& /*metadataValues*/,
  144290. int qualityOptionIndex)
  144291. {
  144292. ScopedPointer <OggWriter> w (new OggWriter (out,
  144293. sampleRate,
  144294. numChannels,
  144295. bitsPerSample,
  144296. qualityOptionIndex));
  144297. return w->ok ? w.release() : 0;
  144298. }
  144299. bool OggVorbisAudioFormat::isCompressed()
  144300. {
  144301. return true;
  144302. }
  144303. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144304. {
  144305. StringArray s;
  144306. s.add ("Low Quality");
  144307. s.add ("Medium Quality");
  144308. s.add ("High Quality");
  144309. return s;
  144310. }
  144311. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144312. {
  144313. FileInputStream* const in = source.createInputStream();
  144314. if (in != 0)
  144315. {
  144316. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144317. if (r != 0)
  144318. {
  144319. const int64 numSamps = r->lengthInSamples;
  144320. r = 0;
  144321. const int64 fileNumSamps = source.getSize() / 4;
  144322. const double ratio = numSamps / (double) fileNumSamps;
  144323. if (ratio > 12.0)
  144324. return 0;
  144325. else if (ratio > 6.0)
  144326. return 1;
  144327. else
  144328. return 2;
  144329. }
  144330. }
  144331. return 1;
  144332. }
  144333. END_JUCE_NAMESPACE
  144334. #endif
  144335. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144336. #endif
  144337. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144338. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144339. #if JUCE_MSVC
  144340. #pragma warning (push)
  144341. #endif
  144342. namespace jpeglibNamespace
  144343. {
  144344. #if JUCE_INCLUDE_JPEGLIB_CODE
  144345. #if JUCE_MINGW
  144346. typedef unsigned char boolean;
  144347. #endif
  144348. extern "C"
  144349. {
  144350. #define JPEG_INTERNALS
  144351. #undef FAR
  144352. /*** Start of inlined file: jpeglib.h ***/
  144353. #ifndef JPEGLIB_H
  144354. #define JPEGLIB_H
  144355. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144356. /*** Start of inlined file: jconfig.h ***/
  144357. // disable all the warnings under MSVC
  144358. #ifdef _MSC_VER
  144359. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144360. #endif
  144361. #ifdef __BORLANDC__
  144362. #pragma warn -8057
  144363. #pragma warn -8019
  144364. #pragma warn -8004
  144365. #pragma warn -8008
  144366. #endif
  144367. #define HAVE_PROTOTYPES
  144368. #define HAVE_UNSIGNED_CHAR
  144369. #define HAVE_UNSIGNED_SHORT
  144370. #undef CHAR_IS_UNSIGNED
  144371. #define HAVE_STDDEF_H
  144372. #define HAVE_STDLIB_H
  144373. #undef NEED_BSD_STRINGS
  144374. #undef NEED_SYS_TYPES_H
  144375. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144376. #undef NEED_SHORT_EXTERNAL_NAMES
  144377. #undef INCOMPLETE_TYPES_BROKEN
  144378. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144379. typedef unsigned char boolean;
  144380. #endif
  144381. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144382. #ifdef JPEG_INTERNALS
  144383. #undef RIGHT_SHIFT_IS_UNSIGNED
  144384. #endif /* JPEG_INTERNALS */
  144385. #ifdef JPEG_CJPEG_DJPEG
  144386. #define BMP_SUPPORTED /* BMP image file format */
  144387. #define GIF_SUPPORTED /* GIF image file format */
  144388. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144389. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144390. #define TARGA_SUPPORTED /* Targa image file format */
  144391. #define TWO_FILE_COMMANDLINE /* optional */
  144392. #define USE_SETMODE /* Microsoft has setmode() */
  144393. #undef NEED_SIGNAL_CATCHER
  144394. #undef DONT_USE_B_MODE
  144395. #undef PROGRESS_REPORT /* optional */
  144396. #endif /* JPEG_CJPEG_DJPEG */
  144397. /*** End of inlined file: jconfig.h ***/
  144398. /* widely used configuration options */
  144399. #endif
  144400. /*** Start of inlined file: jmorecfg.h ***/
  144401. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144402. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144403. #if BITS_IN_JSAMPLE == 8
  144404. #ifdef HAVE_UNSIGNED_CHAR
  144405. typedef unsigned char JSAMPLE;
  144406. #define GETJSAMPLE(value) ((int) (value))
  144407. #else /* not HAVE_UNSIGNED_CHAR */
  144408. typedef char JSAMPLE;
  144409. #ifdef CHAR_IS_UNSIGNED
  144410. #define GETJSAMPLE(value) ((int) (value))
  144411. #else
  144412. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144413. #endif /* CHAR_IS_UNSIGNED */
  144414. #endif /* HAVE_UNSIGNED_CHAR */
  144415. #define MAXJSAMPLE 255
  144416. #define CENTERJSAMPLE 128
  144417. #endif /* BITS_IN_JSAMPLE == 8 */
  144418. #if BITS_IN_JSAMPLE == 12
  144419. typedef short JSAMPLE;
  144420. #define GETJSAMPLE(value) ((int) (value))
  144421. #define MAXJSAMPLE 4095
  144422. #define CENTERJSAMPLE 2048
  144423. #endif /* BITS_IN_JSAMPLE == 12 */
  144424. typedef short JCOEF;
  144425. #ifdef HAVE_UNSIGNED_CHAR
  144426. typedef unsigned char JOCTET;
  144427. #define GETJOCTET(value) (value)
  144428. #else /* not HAVE_UNSIGNED_CHAR */
  144429. typedef char JOCTET;
  144430. #ifdef CHAR_IS_UNSIGNED
  144431. #define GETJOCTET(value) (value)
  144432. #else
  144433. #define GETJOCTET(value) ((value) & 0xFF)
  144434. #endif /* CHAR_IS_UNSIGNED */
  144435. #endif /* HAVE_UNSIGNED_CHAR */
  144436. #ifdef HAVE_UNSIGNED_CHAR
  144437. typedef unsigned char UINT8;
  144438. #else /* not HAVE_UNSIGNED_CHAR */
  144439. #ifdef CHAR_IS_UNSIGNED
  144440. typedef char UINT8;
  144441. #else /* not CHAR_IS_UNSIGNED */
  144442. typedef short UINT8;
  144443. #endif /* CHAR_IS_UNSIGNED */
  144444. #endif /* HAVE_UNSIGNED_CHAR */
  144445. #ifdef HAVE_UNSIGNED_SHORT
  144446. typedef unsigned short UINT16;
  144447. #else /* not HAVE_UNSIGNED_SHORT */
  144448. typedef unsigned int UINT16;
  144449. #endif /* HAVE_UNSIGNED_SHORT */
  144450. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144451. typedef short INT16;
  144452. #endif
  144453. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144454. typedef long INT32;
  144455. #endif
  144456. typedef unsigned int JDIMENSION;
  144457. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144458. #define METHODDEF(type) static type
  144459. #define LOCAL(type) static type
  144460. #define GLOBAL(type) type
  144461. #define EXTERN(type) extern type
  144462. #ifdef HAVE_PROTOTYPES
  144463. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144464. #else
  144465. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144466. #endif
  144467. #ifdef NEED_FAR_POINTERS
  144468. #define FAR far
  144469. #else
  144470. #define FAR
  144471. #endif
  144472. #ifndef HAVE_BOOLEAN
  144473. typedef int boolean;
  144474. #endif
  144475. #ifndef FALSE /* in case these macros already exist */
  144476. #define FALSE 0 /* values of boolean */
  144477. #endif
  144478. #ifndef TRUE
  144479. #define TRUE 1
  144480. #endif
  144481. #ifdef JPEG_INTERNALS
  144482. #define JPEG_INTERNAL_OPTIONS
  144483. #endif
  144484. #ifdef JPEG_INTERNAL_OPTIONS
  144485. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144486. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144487. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144488. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144489. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144490. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144491. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144492. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144493. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144494. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144495. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144496. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144497. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144498. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144499. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144500. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144501. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144502. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144503. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144504. #define RGB_GREEN 1 /* Offset of Green */
  144505. #define RGB_BLUE 2 /* Offset of Blue */
  144506. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144507. #ifndef INLINE
  144508. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144509. #define INLINE __inline__
  144510. #endif
  144511. #ifndef INLINE
  144512. #define INLINE /* default is to define it as empty */
  144513. #endif
  144514. #endif
  144515. #ifndef MULTIPLIER
  144516. #define MULTIPLIER int /* type for fastest integer multiply */
  144517. #endif
  144518. #ifndef FAST_FLOAT
  144519. #ifdef HAVE_PROTOTYPES
  144520. #define FAST_FLOAT float
  144521. #else
  144522. #define FAST_FLOAT double
  144523. #endif
  144524. #endif
  144525. #endif /* JPEG_INTERNAL_OPTIONS */
  144526. /*** End of inlined file: jmorecfg.h ***/
  144527. /* seldom changed options */
  144528. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144529. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144530. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144531. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144532. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144533. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144534. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144535. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144536. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144537. #ifndef D_MAX_BLOCKS_IN_MCU
  144538. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144539. #endif
  144540. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144541. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144542. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144543. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144544. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144545. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144546. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144547. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144548. typedef struct {
  144549. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144550. boolean sent_table; /* TRUE when table has been output */
  144551. } JQUANT_TBL;
  144552. typedef struct {
  144553. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144554. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144555. boolean sent_table; /* TRUE when table has been output */
  144556. } JHUFF_TBL;
  144557. typedef struct {
  144558. int component_id; /* identifier for this component (0..255) */
  144559. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144560. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144561. int v_samp_factor; /* vertical sampling factor (1..4) */
  144562. int quant_tbl_no; /* quantization table selector (0..3) */
  144563. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144564. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144565. JDIMENSION width_in_blocks;
  144566. JDIMENSION height_in_blocks;
  144567. int DCT_scaled_size;
  144568. JDIMENSION downsampled_width; /* actual width in samples */
  144569. JDIMENSION downsampled_height; /* actual height in samples */
  144570. boolean component_needed; /* do we need the value of this component? */
  144571. int MCU_width; /* number of blocks per MCU, horizontally */
  144572. int MCU_height; /* number of blocks per MCU, vertically */
  144573. int MCU_blocks; /* MCU_width * MCU_height */
  144574. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144575. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144576. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144577. JQUANT_TBL * quant_table;
  144578. void * dct_table;
  144579. } jpeg_component_info;
  144580. typedef struct {
  144581. int comps_in_scan; /* number of components encoded in this scan */
  144582. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144583. int Ss, Se; /* progressive JPEG spectral selection parms */
  144584. int Ah, Al; /* progressive JPEG successive approx. parms */
  144585. } jpeg_scan_info;
  144586. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144587. struct jpeg_marker_struct {
  144588. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144589. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144590. unsigned int original_length; /* # bytes of data in the file */
  144591. unsigned int data_length; /* # bytes of data saved at data[] */
  144592. JOCTET FAR * data; /* the data contained in the marker */
  144593. };
  144594. typedef enum {
  144595. JCS_UNKNOWN, /* error/unspecified */
  144596. JCS_GRAYSCALE, /* monochrome */
  144597. JCS_RGB, /* red/green/blue */
  144598. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144599. JCS_CMYK, /* C/M/Y/K */
  144600. JCS_YCCK /* Y/Cb/Cr/K */
  144601. } J_COLOR_SPACE;
  144602. typedef enum {
  144603. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144604. JDCT_IFAST, /* faster, less accurate integer method */
  144605. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144606. } J_DCT_METHOD;
  144607. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144608. #define JDCT_DEFAULT JDCT_ISLOW
  144609. #endif
  144610. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144611. #define JDCT_FASTEST JDCT_IFAST
  144612. #endif
  144613. typedef enum {
  144614. JDITHER_NONE, /* no dithering */
  144615. JDITHER_ORDERED, /* simple ordered dither */
  144616. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144617. } J_DITHER_MODE;
  144618. #define jpeg_common_fields \
  144619. struct jpeg_error_mgr * err; /* Error handler module */\
  144620. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144621. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144622. void * client_data; /* Available for use by application */\
  144623. boolean is_decompressor; /* So common code can tell which is which */\
  144624. int global_state /* For checking call sequence validity */
  144625. struct jpeg_common_struct {
  144626. jpeg_common_fields; /* Fields common to both master struct types */
  144627. };
  144628. typedef struct jpeg_common_struct * j_common_ptr;
  144629. typedef struct jpeg_compress_struct * j_compress_ptr;
  144630. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144631. struct jpeg_compress_struct {
  144632. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144633. struct jpeg_destination_mgr * dest;
  144634. JDIMENSION image_width; /* input image width */
  144635. JDIMENSION image_height; /* input image height */
  144636. int input_components; /* # of color components in input image */
  144637. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144638. double input_gamma; /* image gamma of input image */
  144639. int data_precision; /* bits of precision in image data */
  144640. int num_components; /* # of color components in JPEG image */
  144641. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144642. jpeg_component_info * comp_info;
  144643. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144644. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144645. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144646. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144647. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144648. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144649. int num_scans; /* # of entries in scan_info array */
  144650. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144651. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144652. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144653. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144654. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144655. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144656. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144657. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144658. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144659. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144660. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144661. UINT8 JFIF_minor_version;
  144662. UINT8 density_unit; /* JFIF code for pixel size units */
  144663. UINT16 X_density; /* Horizontal pixel density */
  144664. UINT16 Y_density; /* Vertical pixel density */
  144665. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144666. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144667. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144668. int max_h_samp_factor; /* largest h_samp_factor */
  144669. int max_v_samp_factor; /* largest v_samp_factor */
  144670. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144671. int comps_in_scan; /* # of JPEG components in this scan */
  144672. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144673. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144674. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144675. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144676. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144677. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144678. struct jpeg_comp_master * master;
  144679. struct jpeg_c_main_controller * main;
  144680. struct jpeg_c_prep_controller * prep;
  144681. struct jpeg_c_coef_controller * coef;
  144682. struct jpeg_marker_writer * marker;
  144683. struct jpeg_color_converter * cconvert;
  144684. struct jpeg_downsampler * downsample;
  144685. struct jpeg_forward_dct * fdct;
  144686. struct jpeg_entropy_encoder * entropy;
  144687. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144688. int script_space_size;
  144689. };
  144690. struct jpeg_decompress_struct {
  144691. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144692. struct jpeg_source_mgr * src;
  144693. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144694. JDIMENSION image_height; /* nominal image height */
  144695. int num_components; /* # of color components in JPEG image */
  144696. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144697. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144698. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144699. double output_gamma; /* image gamma wanted in output */
  144700. boolean buffered_image; /* TRUE=multiple output passes */
  144701. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144702. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144703. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144704. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144705. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144706. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144707. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144708. int desired_number_of_colors; /* max # colors to use in created colormap */
  144709. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144710. boolean enable_external_quant;/* enable future use of external colormap */
  144711. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144712. JDIMENSION output_width; /* scaled image width */
  144713. JDIMENSION output_height; /* scaled image height */
  144714. int out_color_components; /* # of color components in out_color_space */
  144715. int output_components; /* # of color components returned */
  144716. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144717. int actual_number_of_colors; /* number of entries in use */
  144718. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144719. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144720. int input_scan_number; /* Number of SOS markers seen so far */
  144721. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144722. int output_scan_number; /* Nominal scan number being displayed */
  144723. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144724. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144725. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144726. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144727. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144728. int data_precision; /* bits of precision in image data */
  144729. jpeg_component_info * comp_info;
  144730. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144731. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144732. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144733. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144734. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144735. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144736. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144737. UINT8 JFIF_major_version; /* JFIF version number */
  144738. UINT8 JFIF_minor_version;
  144739. UINT8 density_unit; /* JFIF code for pixel size units */
  144740. UINT16 X_density; /* Horizontal pixel density */
  144741. UINT16 Y_density; /* Vertical pixel density */
  144742. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144743. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144744. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144745. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144746. int max_h_samp_factor; /* largest h_samp_factor */
  144747. int max_v_samp_factor; /* largest v_samp_factor */
  144748. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144749. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144750. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144751. int comps_in_scan; /* # of JPEG components in this scan */
  144752. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144753. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144754. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144755. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144756. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144757. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144758. int unread_marker;
  144759. struct jpeg_decomp_master * master;
  144760. struct jpeg_d_main_controller * main;
  144761. struct jpeg_d_coef_controller * coef;
  144762. struct jpeg_d_post_controller * post;
  144763. struct jpeg_input_controller * inputctl;
  144764. struct jpeg_marker_reader * marker;
  144765. struct jpeg_entropy_decoder * entropy;
  144766. struct jpeg_inverse_dct * idct;
  144767. struct jpeg_upsampler * upsample;
  144768. struct jpeg_color_deconverter * cconvert;
  144769. struct jpeg_color_quantizer * cquantize;
  144770. };
  144771. struct jpeg_error_mgr {
  144772. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144773. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144774. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144775. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144776. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144777. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144778. int msg_code;
  144779. #define JMSG_STR_PARM_MAX 80
  144780. union {
  144781. int i[8];
  144782. char s[JMSG_STR_PARM_MAX];
  144783. } msg_parm;
  144784. int trace_level; /* max msg_level that will be displayed */
  144785. long num_warnings; /* number of corrupt-data warnings */
  144786. const char * const * jpeg_message_table; /* Library errors */
  144787. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144788. const char * const * addon_message_table; /* Non-library errors */
  144789. int first_addon_message; /* code for first string in addon table */
  144790. int last_addon_message; /* code for last string in addon table */
  144791. };
  144792. struct jpeg_progress_mgr {
  144793. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144794. long pass_counter; /* work units completed in this pass */
  144795. long pass_limit; /* total number of work units in this pass */
  144796. int completed_passes; /* passes completed so far */
  144797. int total_passes; /* total number of passes expected */
  144798. };
  144799. struct jpeg_destination_mgr {
  144800. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144801. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144802. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144803. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144804. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144805. };
  144806. struct jpeg_source_mgr {
  144807. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144808. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144809. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144810. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144811. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  144812. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  144813. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  144814. };
  144815. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  144816. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  144817. #define JPOOL_NUMPOOLS 2
  144818. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  144819. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  144820. struct jpeg_memory_mgr {
  144821. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  144822. size_t sizeofobject));
  144823. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  144824. size_t sizeofobject));
  144825. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  144826. JDIMENSION samplesperrow,
  144827. JDIMENSION numrows));
  144828. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  144829. JDIMENSION blocksperrow,
  144830. JDIMENSION numrows));
  144831. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  144832. int pool_id,
  144833. boolean pre_zero,
  144834. JDIMENSION samplesperrow,
  144835. JDIMENSION numrows,
  144836. JDIMENSION maxaccess));
  144837. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  144838. int pool_id,
  144839. boolean pre_zero,
  144840. JDIMENSION blocksperrow,
  144841. JDIMENSION numrows,
  144842. JDIMENSION maxaccess));
  144843. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  144844. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  144845. jvirt_sarray_ptr ptr,
  144846. JDIMENSION start_row,
  144847. JDIMENSION num_rows,
  144848. boolean writable));
  144849. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  144850. jvirt_barray_ptr ptr,
  144851. JDIMENSION start_row,
  144852. JDIMENSION num_rows,
  144853. boolean writable));
  144854. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  144855. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  144856. long max_memory_to_use;
  144857. long max_alloc_chunk;
  144858. };
  144859. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  144860. #ifdef HAVE_PROTOTYPES
  144861. #define JPP(arglist) arglist
  144862. #else
  144863. #define JPP(arglist) ()
  144864. #endif
  144865. #ifdef NEED_SHORT_EXTERNAL_NAMES
  144866. #define jpeg_std_error jStdError
  144867. #define jpeg_CreateCompress jCreaCompress
  144868. #define jpeg_CreateDecompress jCreaDecompress
  144869. #define jpeg_destroy_compress jDestCompress
  144870. #define jpeg_destroy_decompress jDestDecompress
  144871. #define jpeg_stdio_dest jStdDest
  144872. #define jpeg_stdio_src jStdSrc
  144873. #define jpeg_set_defaults jSetDefaults
  144874. #define jpeg_set_colorspace jSetColorspace
  144875. #define jpeg_default_colorspace jDefColorspace
  144876. #define jpeg_set_quality jSetQuality
  144877. #define jpeg_set_linear_quality jSetLQuality
  144878. #define jpeg_add_quant_table jAddQuantTable
  144879. #define jpeg_quality_scaling jQualityScaling
  144880. #define jpeg_simple_progression jSimProgress
  144881. #define jpeg_suppress_tables jSuppressTables
  144882. #define jpeg_alloc_quant_table jAlcQTable
  144883. #define jpeg_alloc_huff_table jAlcHTable
  144884. #define jpeg_start_compress jStrtCompress
  144885. #define jpeg_write_scanlines jWrtScanlines
  144886. #define jpeg_finish_compress jFinCompress
  144887. #define jpeg_write_raw_data jWrtRawData
  144888. #define jpeg_write_marker jWrtMarker
  144889. #define jpeg_write_m_header jWrtMHeader
  144890. #define jpeg_write_m_byte jWrtMByte
  144891. #define jpeg_write_tables jWrtTables
  144892. #define jpeg_read_header jReadHeader
  144893. #define jpeg_start_decompress jStrtDecompress
  144894. #define jpeg_read_scanlines jReadScanlines
  144895. #define jpeg_finish_decompress jFinDecompress
  144896. #define jpeg_read_raw_data jReadRawData
  144897. #define jpeg_has_multiple_scans jHasMultScn
  144898. #define jpeg_start_output jStrtOutput
  144899. #define jpeg_finish_output jFinOutput
  144900. #define jpeg_input_complete jInComplete
  144901. #define jpeg_new_colormap jNewCMap
  144902. #define jpeg_consume_input jConsumeInput
  144903. #define jpeg_calc_output_dimensions jCalcDimensions
  144904. #define jpeg_save_markers jSaveMarkers
  144905. #define jpeg_set_marker_processor jSetMarker
  144906. #define jpeg_read_coefficients jReadCoefs
  144907. #define jpeg_write_coefficients jWrtCoefs
  144908. #define jpeg_copy_critical_parameters jCopyCrit
  144909. #define jpeg_abort_compress jAbrtCompress
  144910. #define jpeg_abort_decompress jAbrtDecompress
  144911. #define jpeg_abort jAbort
  144912. #define jpeg_destroy jDestroy
  144913. #define jpeg_resync_to_restart jResyncRestart
  144914. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  144915. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  144916. JPP((struct jpeg_error_mgr * err));
  144917. #define jpeg_create_compress(cinfo) \
  144918. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  144919. (size_t) sizeof(struct jpeg_compress_struct))
  144920. #define jpeg_create_decompress(cinfo) \
  144921. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  144922. (size_t) sizeof(struct jpeg_decompress_struct))
  144923. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  144924. int version, size_t structsize));
  144925. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  144926. int version, size_t structsize));
  144927. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  144928. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  144929. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  144930. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  144931. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  144932. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  144933. J_COLOR_SPACE colorspace));
  144934. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  144935. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  144936. boolean force_baseline));
  144937. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  144938. int scale_factor,
  144939. boolean force_baseline));
  144940. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  144941. const unsigned int *basic_table,
  144942. int scale_factor,
  144943. boolean force_baseline));
  144944. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  144945. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  144946. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  144947. boolean suppress));
  144948. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  144949. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  144950. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  144951. boolean write_all_tables));
  144952. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  144953. JSAMPARRAY scanlines,
  144954. JDIMENSION num_lines));
  144955. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  144956. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  144957. JSAMPIMAGE data,
  144958. JDIMENSION num_lines));
  144959. EXTERN(void) jpeg_write_marker
  144960. JPP((j_compress_ptr cinfo, int marker,
  144961. const JOCTET * dataptr, unsigned int datalen));
  144962. EXTERN(void) jpeg_write_m_header
  144963. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  144964. EXTERN(void) jpeg_write_m_byte
  144965. JPP((j_compress_ptr cinfo, int val));
  144966. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  144967. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  144968. boolean require_image));
  144969. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  144970. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  144971. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  144972. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  144973. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  144974. JSAMPARRAY scanlines,
  144975. JDIMENSION max_lines));
  144976. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  144977. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  144978. JSAMPIMAGE data,
  144979. JDIMENSION max_lines));
  144980. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  144981. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  144982. int scan_number));
  144983. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  144984. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  144985. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  144986. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  144987. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  144988. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  144989. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  144990. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  144991. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  144992. EXTERN(void) jpeg_save_markers
  144993. JPP((j_decompress_ptr cinfo, int marker_code,
  144994. unsigned int length_limit));
  144995. EXTERN(void) jpeg_set_marker_processor
  144996. JPP((j_decompress_ptr cinfo, int marker_code,
  144997. jpeg_marker_parser_method routine));
  144998. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  144999. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145000. jvirt_barray_ptr * coef_arrays));
  145001. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145002. j_compress_ptr dstinfo));
  145003. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145004. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145005. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145006. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145007. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145008. int desired));
  145009. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145010. #define JPEG_EOI 0xD9 /* EOI marker code */
  145011. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145012. #define JPEG_COM 0xFE /* COM marker code */
  145013. #ifdef INCOMPLETE_TYPES_BROKEN
  145014. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145015. struct jvirt_sarray_control { long dummy; };
  145016. struct jvirt_barray_control { long dummy; };
  145017. struct jpeg_comp_master { long dummy; };
  145018. struct jpeg_c_main_controller { long dummy; };
  145019. struct jpeg_c_prep_controller { long dummy; };
  145020. struct jpeg_c_coef_controller { long dummy; };
  145021. struct jpeg_marker_writer { long dummy; };
  145022. struct jpeg_color_converter { long dummy; };
  145023. struct jpeg_downsampler { long dummy; };
  145024. struct jpeg_forward_dct { long dummy; };
  145025. struct jpeg_entropy_encoder { long dummy; };
  145026. struct jpeg_decomp_master { long dummy; };
  145027. struct jpeg_d_main_controller { long dummy; };
  145028. struct jpeg_d_coef_controller { long dummy; };
  145029. struct jpeg_d_post_controller { long dummy; };
  145030. struct jpeg_input_controller { long dummy; };
  145031. struct jpeg_marker_reader { long dummy; };
  145032. struct jpeg_entropy_decoder { long dummy; };
  145033. struct jpeg_inverse_dct { long dummy; };
  145034. struct jpeg_upsampler { long dummy; };
  145035. struct jpeg_color_deconverter { long dummy; };
  145036. struct jpeg_color_quantizer { long dummy; };
  145037. #endif /* JPEG_INTERNALS */
  145038. #endif /* INCOMPLETE_TYPES_BROKEN */
  145039. #ifdef JPEG_INTERNALS
  145040. /*** Start of inlined file: jpegint.h ***/
  145041. typedef enum { /* Operating modes for buffer controllers */
  145042. JBUF_PASS_THRU, /* Plain stripwise operation */
  145043. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145044. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145045. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145046. } J_BUF_MODE;
  145047. #define CSTATE_START 100 /* after create_compress */
  145048. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145049. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145050. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145051. #define DSTATE_START 200 /* after create_decompress */
  145052. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145053. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145054. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145055. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145056. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145057. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145058. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145059. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145060. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145061. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145062. struct jpeg_comp_master {
  145063. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145064. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145065. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145066. boolean call_pass_startup; /* True if pass_startup must be called */
  145067. boolean is_last_pass; /* True during last pass */
  145068. };
  145069. struct jpeg_c_main_controller {
  145070. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145071. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145072. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145073. JDIMENSION in_rows_avail));
  145074. };
  145075. struct jpeg_c_prep_controller {
  145076. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145077. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145078. JSAMPARRAY input_buf,
  145079. JDIMENSION *in_row_ctr,
  145080. JDIMENSION in_rows_avail,
  145081. JSAMPIMAGE output_buf,
  145082. JDIMENSION *out_row_group_ctr,
  145083. JDIMENSION out_row_groups_avail));
  145084. };
  145085. struct jpeg_c_coef_controller {
  145086. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145087. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145088. JSAMPIMAGE input_buf));
  145089. };
  145090. struct jpeg_color_converter {
  145091. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145092. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145093. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145094. JDIMENSION output_row, int num_rows));
  145095. };
  145096. struct jpeg_downsampler {
  145097. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145098. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145099. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145100. JSAMPIMAGE output_buf,
  145101. JDIMENSION out_row_group_index));
  145102. boolean need_context_rows; /* TRUE if need rows above & below */
  145103. };
  145104. struct jpeg_forward_dct {
  145105. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145106. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145107. jpeg_component_info * compptr,
  145108. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145109. JDIMENSION start_row, JDIMENSION start_col,
  145110. JDIMENSION num_blocks));
  145111. };
  145112. struct jpeg_entropy_encoder {
  145113. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145114. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145115. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145116. };
  145117. struct jpeg_marker_writer {
  145118. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145119. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145120. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145121. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145122. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145123. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145124. unsigned int datalen));
  145125. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145126. };
  145127. struct jpeg_decomp_master {
  145128. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145129. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145130. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145131. };
  145132. struct jpeg_input_controller {
  145133. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145134. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145135. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145136. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145137. boolean has_multiple_scans; /* True if file has multiple scans */
  145138. boolean eoi_reached; /* True when EOI has been consumed */
  145139. };
  145140. struct jpeg_d_main_controller {
  145141. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145142. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145143. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145144. JDIMENSION out_rows_avail));
  145145. };
  145146. struct jpeg_d_coef_controller {
  145147. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145148. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145149. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145150. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145151. JSAMPIMAGE output_buf));
  145152. jvirt_barray_ptr *coef_arrays;
  145153. };
  145154. struct jpeg_d_post_controller {
  145155. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145156. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145157. JSAMPIMAGE input_buf,
  145158. JDIMENSION *in_row_group_ctr,
  145159. JDIMENSION in_row_groups_avail,
  145160. JSAMPARRAY output_buf,
  145161. JDIMENSION *out_row_ctr,
  145162. JDIMENSION out_rows_avail));
  145163. };
  145164. struct jpeg_marker_reader {
  145165. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145166. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145167. jpeg_marker_parser_method read_restart_marker;
  145168. boolean saw_SOI; /* found SOI? */
  145169. boolean saw_SOF; /* found SOF? */
  145170. int next_restart_num; /* next restart number expected (0-7) */
  145171. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145172. };
  145173. struct jpeg_entropy_decoder {
  145174. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145175. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145176. JBLOCKROW *MCU_data));
  145177. boolean insufficient_data; /* set TRUE after emitting warning */
  145178. };
  145179. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145180. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145181. JCOEFPTR coef_block,
  145182. JSAMPARRAY output_buf, JDIMENSION output_col));
  145183. struct jpeg_inverse_dct {
  145184. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145185. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145186. };
  145187. struct jpeg_upsampler {
  145188. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145189. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145190. JSAMPIMAGE input_buf,
  145191. JDIMENSION *in_row_group_ctr,
  145192. JDIMENSION in_row_groups_avail,
  145193. JSAMPARRAY output_buf,
  145194. JDIMENSION *out_row_ctr,
  145195. JDIMENSION out_rows_avail));
  145196. boolean need_context_rows; /* TRUE if need rows above & below */
  145197. };
  145198. struct jpeg_color_deconverter {
  145199. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145200. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145201. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145202. JSAMPARRAY output_buf, int num_rows));
  145203. };
  145204. struct jpeg_color_quantizer {
  145205. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145206. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145207. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145208. int num_rows));
  145209. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145210. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145211. };
  145212. #undef MAX
  145213. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145214. #undef MIN
  145215. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145216. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145217. #define SHIFT_TEMPS INT32 shift_temp;
  145218. #define RIGHT_SHIFT(x,shft) \
  145219. ((shift_temp = (x)) < 0 ? \
  145220. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145221. (shift_temp >> (shft)))
  145222. #else
  145223. #define SHIFT_TEMPS
  145224. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145225. #endif
  145226. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145227. #define jinit_compress_master jICompress
  145228. #define jinit_c_master_control jICMaster
  145229. #define jinit_c_main_controller jICMainC
  145230. #define jinit_c_prep_controller jICPrepC
  145231. #define jinit_c_coef_controller jICCoefC
  145232. #define jinit_color_converter jICColor
  145233. #define jinit_downsampler jIDownsampler
  145234. #define jinit_forward_dct jIFDCT
  145235. #define jinit_huff_encoder jIHEncoder
  145236. #define jinit_phuff_encoder jIPHEncoder
  145237. #define jinit_marker_writer jIMWriter
  145238. #define jinit_master_decompress jIDMaster
  145239. #define jinit_d_main_controller jIDMainC
  145240. #define jinit_d_coef_controller jIDCoefC
  145241. #define jinit_d_post_controller jIDPostC
  145242. #define jinit_input_controller jIInCtlr
  145243. #define jinit_marker_reader jIMReader
  145244. #define jinit_huff_decoder jIHDecoder
  145245. #define jinit_phuff_decoder jIPHDecoder
  145246. #define jinit_inverse_dct jIIDCT
  145247. #define jinit_upsampler jIUpsampler
  145248. #define jinit_color_deconverter jIDColor
  145249. #define jinit_1pass_quantizer jI1Quant
  145250. #define jinit_2pass_quantizer jI2Quant
  145251. #define jinit_merged_upsampler jIMUpsampler
  145252. #define jinit_memory_mgr jIMemMgr
  145253. #define jdiv_round_up jDivRound
  145254. #define jround_up jRound
  145255. #define jcopy_sample_rows jCopySamples
  145256. #define jcopy_block_row jCopyBlocks
  145257. #define jzero_far jZeroFar
  145258. #define jpeg_zigzag_order jZIGTable
  145259. #define jpeg_natural_order jZAGTable
  145260. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145261. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145262. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145263. boolean transcode_only));
  145264. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145265. boolean need_full_buffer));
  145266. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145267. boolean need_full_buffer));
  145268. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145269. boolean need_full_buffer));
  145270. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145271. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145272. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145273. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145274. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145275. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145276. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145277. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145278. boolean need_full_buffer));
  145279. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145280. boolean need_full_buffer));
  145281. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145282. boolean need_full_buffer));
  145283. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145284. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145285. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145286. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145287. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145288. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145289. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145290. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145291. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145292. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145293. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145294. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145295. EXTERN(long) jround_up JPP((long a, long b));
  145296. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145297. JSAMPARRAY output_array, int dest_row,
  145298. int num_rows, JDIMENSION num_cols));
  145299. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145300. JDIMENSION num_blocks));
  145301. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145302. #if 0 /* This table is not actually needed in v6a */
  145303. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145304. #endif
  145305. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145306. #ifdef INCOMPLETE_TYPES_BROKEN
  145307. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145308. struct jvirt_sarray_control { long dummy; };
  145309. struct jvirt_barray_control { long dummy; };
  145310. #endif
  145311. #endif /* INCOMPLETE_TYPES_BROKEN */
  145312. /*** End of inlined file: jpegint.h ***/
  145313. /* fetch private declarations */
  145314. /*** Start of inlined file: jerror.h ***/
  145315. #ifndef JMESSAGE
  145316. #ifndef JERROR_H
  145317. #define JMAKE_ENUM_LIST
  145318. #else
  145319. #define JMESSAGE(code,string)
  145320. #endif /* JERROR_H */
  145321. #endif /* JMESSAGE */
  145322. #ifdef JMAKE_ENUM_LIST
  145323. typedef enum {
  145324. #define JMESSAGE(code,string) code ,
  145325. #endif /* JMAKE_ENUM_LIST */
  145326. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145327. JMESSAGE(JERR_ARITH_NOTIMPL,
  145328. "Sorry, there are legal restrictions on arithmetic coding")
  145329. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145330. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145331. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145332. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145333. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145334. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145335. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145336. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145337. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145338. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145339. JMESSAGE(JERR_BAD_LIB_VERSION,
  145340. "Wrong JPEG library version: library is %d, caller expects %d")
  145341. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145342. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145343. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145344. JMESSAGE(JERR_BAD_PROGRESSION,
  145345. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145346. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145347. "Invalid progressive parameters at scan script entry %d")
  145348. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145349. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145350. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145351. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145352. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145353. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145354. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145355. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145356. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145357. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145358. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145359. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145360. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145361. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145362. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145363. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145364. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145365. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145366. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145367. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145368. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145369. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145370. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145371. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145372. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145373. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145374. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145375. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145376. "Cannot transcode due to multiple use of quantization table %d")
  145377. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145378. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145379. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145380. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145381. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145382. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145383. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145384. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145385. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145386. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145387. JMESSAGE(JERR_QUANT_COMPONENTS,
  145388. "Cannot quantize more than %d color components")
  145389. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145390. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145391. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145392. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145393. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145394. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145395. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145396. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145397. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145398. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145399. JMESSAGE(JERR_TFILE_WRITE,
  145400. "Write failed on temporary file --- out of disk space?")
  145401. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145402. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145403. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145404. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145405. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145406. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145407. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145408. JMESSAGE(JMSG_VERSION, JVERSION)
  145409. JMESSAGE(JTRC_16BIT_TABLES,
  145410. "Caution: quantization tables are too coarse for baseline JPEG")
  145411. JMESSAGE(JTRC_ADOBE,
  145412. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145413. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145414. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145415. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145416. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145417. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145418. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145419. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145420. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145421. JMESSAGE(JTRC_EOI, "End Of Image")
  145422. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145423. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145424. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145425. "Warning: thumbnail image size does not match data length %u")
  145426. JMESSAGE(JTRC_JFIF_EXTENSION,
  145427. "JFIF extension marker: type 0x%02x, length %u")
  145428. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145429. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145430. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145431. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145432. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145433. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145434. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145435. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145436. JMESSAGE(JTRC_RST, "RST%d")
  145437. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145438. "Smoothing not supported with nonstandard sampling ratios")
  145439. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145440. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145441. JMESSAGE(JTRC_SOI, "Start of Image")
  145442. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145443. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145444. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145445. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145446. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145447. JMESSAGE(JTRC_THUMB_JPEG,
  145448. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145449. JMESSAGE(JTRC_THUMB_PALETTE,
  145450. "JFIF extension marker: palette thumbnail image, length %u")
  145451. JMESSAGE(JTRC_THUMB_RGB,
  145452. "JFIF extension marker: RGB thumbnail image, length %u")
  145453. JMESSAGE(JTRC_UNKNOWN_IDS,
  145454. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145455. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145456. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145457. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145458. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145459. "Inconsistent progression sequence for component %d coefficient %d")
  145460. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145461. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145462. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145463. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145464. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145465. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145466. JMESSAGE(JWRN_MUST_RESYNC,
  145467. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145468. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145469. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145470. #ifdef JMAKE_ENUM_LIST
  145471. JMSG_LASTMSGCODE
  145472. } J_MESSAGE_CODE;
  145473. #undef JMAKE_ENUM_LIST
  145474. #endif /* JMAKE_ENUM_LIST */
  145475. #undef JMESSAGE
  145476. #ifndef JERROR_H
  145477. #define JERROR_H
  145478. #define ERREXIT(cinfo,code) \
  145479. ((cinfo)->err->msg_code = (code), \
  145480. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145481. #define ERREXIT1(cinfo,code,p1) \
  145482. ((cinfo)->err->msg_code = (code), \
  145483. (cinfo)->err->msg_parm.i[0] = (p1), \
  145484. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145485. #define ERREXIT2(cinfo,code,p1,p2) \
  145486. ((cinfo)->err->msg_code = (code), \
  145487. (cinfo)->err->msg_parm.i[0] = (p1), \
  145488. (cinfo)->err->msg_parm.i[1] = (p2), \
  145489. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145490. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145491. ((cinfo)->err->msg_code = (code), \
  145492. (cinfo)->err->msg_parm.i[0] = (p1), \
  145493. (cinfo)->err->msg_parm.i[1] = (p2), \
  145494. (cinfo)->err->msg_parm.i[2] = (p3), \
  145495. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145496. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145497. ((cinfo)->err->msg_code = (code), \
  145498. (cinfo)->err->msg_parm.i[0] = (p1), \
  145499. (cinfo)->err->msg_parm.i[1] = (p2), \
  145500. (cinfo)->err->msg_parm.i[2] = (p3), \
  145501. (cinfo)->err->msg_parm.i[3] = (p4), \
  145502. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145503. #define ERREXITS(cinfo,code,str) \
  145504. ((cinfo)->err->msg_code = (code), \
  145505. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145506. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145507. #define MAKESTMT(stuff) do { stuff } while (0)
  145508. #define WARNMS(cinfo,code) \
  145509. ((cinfo)->err->msg_code = (code), \
  145510. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145511. #define WARNMS1(cinfo,code,p1) \
  145512. ((cinfo)->err->msg_code = (code), \
  145513. (cinfo)->err->msg_parm.i[0] = (p1), \
  145514. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145515. #define WARNMS2(cinfo,code,p1,p2) \
  145516. ((cinfo)->err->msg_code = (code), \
  145517. (cinfo)->err->msg_parm.i[0] = (p1), \
  145518. (cinfo)->err->msg_parm.i[1] = (p2), \
  145519. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145520. #define TRACEMS(cinfo,lvl,code) \
  145521. ((cinfo)->err->msg_code = (code), \
  145522. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145523. #define TRACEMS1(cinfo,lvl,code,p1) \
  145524. ((cinfo)->err->msg_code = (code), \
  145525. (cinfo)->err->msg_parm.i[0] = (p1), \
  145526. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145527. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145528. ((cinfo)->err->msg_code = (code), \
  145529. (cinfo)->err->msg_parm.i[0] = (p1), \
  145530. (cinfo)->err->msg_parm.i[1] = (p2), \
  145531. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145532. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145533. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145534. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145535. (cinfo)->err->msg_code = (code); \
  145536. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145537. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145538. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145539. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145540. (cinfo)->err->msg_code = (code); \
  145541. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145542. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145543. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145544. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145545. _mp[4] = (p5); \
  145546. (cinfo)->err->msg_code = (code); \
  145547. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145548. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145549. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145550. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145551. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145552. (cinfo)->err->msg_code = (code); \
  145553. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145554. #define TRACEMSS(cinfo,lvl,code,str) \
  145555. ((cinfo)->err->msg_code = (code), \
  145556. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145557. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145558. #endif /* JERROR_H */
  145559. /*** End of inlined file: jerror.h ***/
  145560. /* fetch error codes too */
  145561. #endif
  145562. #endif /* JPEGLIB_H */
  145563. /*** End of inlined file: jpeglib.h ***/
  145564. /*** Start of inlined file: jcapimin.c ***/
  145565. #define JPEG_INTERNALS
  145566. /*** Start of inlined file: jinclude.h ***/
  145567. #ifndef __jinclude_h__
  145568. #define __jinclude_h__
  145569. /*** Start of inlined file: jconfig.h ***/
  145570. // disable all the warnings under MSVC
  145571. #ifdef _MSC_VER
  145572. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145573. #endif
  145574. #ifdef __BORLANDC__
  145575. #pragma warn -8057
  145576. #pragma warn -8019
  145577. #pragma warn -8004
  145578. #pragma warn -8008
  145579. #endif
  145580. #define HAVE_PROTOTYPES
  145581. #define HAVE_UNSIGNED_CHAR
  145582. #define HAVE_UNSIGNED_SHORT
  145583. #undef CHAR_IS_UNSIGNED
  145584. #define HAVE_STDDEF_H
  145585. #define HAVE_STDLIB_H
  145586. #undef NEED_BSD_STRINGS
  145587. #undef NEED_SYS_TYPES_H
  145588. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145589. #undef NEED_SHORT_EXTERNAL_NAMES
  145590. #undef INCOMPLETE_TYPES_BROKEN
  145591. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145592. typedef unsigned char boolean;
  145593. #endif
  145594. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145595. #ifdef JPEG_INTERNALS
  145596. #undef RIGHT_SHIFT_IS_UNSIGNED
  145597. #endif /* JPEG_INTERNALS */
  145598. #ifdef JPEG_CJPEG_DJPEG
  145599. #define BMP_SUPPORTED /* BMP image file format */
  145600. #define GIF_SUPPORTED /* GIF image file format */
  145601. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145602. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145603. #define TARGA_SUPPORTED /* Targa image file format */
  145604. #define TWO_FILE_COMMANDLINE /* optional */
  145605. #define USE_SETMODE /* Microsoft has setmode() */
  145606. #undef NEED_SIGNAL_CATCHER
  145607. #undef DONT_USE_B_MODE
  145608. #undef PROGRESS_REPORT /* optional */
  145609. #endif /* JPEG_CJPEG_DJPEG */
  145610. /*** End of inlined file: jconfig.h ***/
  145611. /* auto configuration options */
  145612. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145613. #ifdef HAVE_STDDEF_H
  145614. #include <stddef.h>
  145615. #endif
  145616. #ifdef HAVE_STDLIB_H
  145617. #include <stdlib.h>
  145618. #endif
  145619. #ifdef NEED_SYS_TYPES_H
  145620. #include <sys/types.h>
  145621. #endif
  145622. #include <stdio.h>
  145623. #ifdef NEED_BSD_STRINGS
  145624. #include <strings.h>
  145625. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145626. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145627. #else /* not BSD, assume ANSI/SysV string lib */
  145628. #include <string.h>
  145629. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145630. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145631. #endif
  145632. #define SIZEOF(object) ((size_t) sizeof(object))
  145633. #define JFREAD(file,buf,sizeofbuf) \
  145634. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145635. #define JFWRITE(file,buf,sizeofbuf) \
  145636. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145637. typedef enum { /* JPEG marker codes */
  145638. M_SOF0 = 0xc0,
  145639. M_SOF1 = 0xc1,
  145640. M_SOF2 = 0xc2,
  145641. M_SOF3 = 0xc3,
  145642. M_SOF5 = 0xc5,
  145643. M_SOF6 = 0xc6,
  145644. M_SOF7 = 0xc7,
  145645. M_JPG = 0xc8,
  145646. M_SOF9 = 0xc9,
  145647. M_SOF10 = 0xca,
  145648. M_SOF11 = 0xcb,
  145649. M_SOF13 = 0xcd,
  145650. M_SOF14 = 0xce,
  145651. M_SOF15 = 0xcf,
  145652. M_DHT = 0xc4,
  145653. M_DAC = 0xcc,
  145654. M_RST0 = 0xd0,
  145655. M_RST1 = 0xd1,
  145656. M_RST2 = 0xd2,
  145657. M_RST3 = 0xd3,
  145658. M_RST4 = 0xd4,
  145659. M_RST5 = 0xd5,
  145660. M_RST6 = 0xd6,
  145661. M_RST7 = 0xd7,
  145662. M_SOI = 0xd8,
  145663. M_EOI = 0xd9,
  145664. M_SOS = 0xda,
  145665. M_DQT = 0xdb,
  145666. M_DNL = 0xdc,
  145667. M_DRI = 0xdd,
  145668. M_DHP = 0xde,
  145669. M_EXP = 0xdf,
  145670. M_APP0 = 0xe0,
  145671. M_APP1 = 0xe1,
  145672. M_APP2 = 0xe2,
  145673. M_APP3 = 0xe3,
  145674. M_APP4 = 0xe4,
  145675. M_APP5 = 0xe5,
  145676. M_APP6 = 0xe6,
  145677. M_APP7 = 0xe7,
  145678. M_APP8 = 0xe8,
  145679. M_APP9 = 0xe9,
  145680. M_APP10 = 0xea,
  145681. M_APP11 = 0xeb,
  145682. M_APP12 = 0xec,
  145683. M_APP13 = 0xed,
  145684. M_APP14 = 0xee,
  145685. M_APP15 = 0xef,
  145686. M_JPG0 = 0xf0,
  145687. M_JPG13 = 0xfd,
  145688. M_COM = 0xfe,
  145689. M_TEM = 0x01,
  145690. M_ERROR = 0x100
  145691. } JPEG_MARKER;
  145692. #ifdef AVOID_TABLES
  145693. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145694. #else
  145695. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145696. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145697. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145698. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145699. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145700. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145701. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145702. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145703. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145704. #endif /* AVOID_TABLES */
  145705. #endif
  145706. /*** End of inlined file: jinclude.h ***/
  145707. GLOBAL(void)
  145708. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145709. {
  145710. int i;
  145711. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145712. if (version != JPEG_LIB_VERSION)
  145713. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145714. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145715. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145716. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145717. {
  145718. struct jpeg_error_mgr * err = cinfo->err;
  145719. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145720. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145721. cinfo->err = err;
  145722. cinfo->client_data = client_data;
  145723. }
  145724. cinfo->is_decompressor = FALSE;
  145725. jinit_memory_mgr((j_common_ptr) cinfo);
  145726. cinfo->progress = NULL;
  145727. cinfo->dest = NULL;
  145728. cinfo->comp_info = NULL;
  145729. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145730. cinfo->quant_tbl_ptrs[i] = NULL;
  145731. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145732. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145733. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145734. }
  145735. cinfo->script_space = NULL;
  145736. cinfo->input_gamma = 1.0; /* in case application forgets */
  145737. cinfo->global_state = CSTATE_START;
  145738. }
  145739. GLOBAL(void)
  145740. jpeg_destroy_compress (j_compress_ptr cinfo)
  145741. {
  145742. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145743. }
  145744. GLOBAL(void)
  145745. jpeg_abort_compress (j_compress_ptr cinfo)
  145746. {
  145747. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145748. }
  145749. GLOBAL(void)
  145750. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145751. {
  145752. int i;
  145753. JQUANT_TBL * qtbl;
  145754. JHUFF_TBL * htbl;
  145755. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145756. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145757. qtbl->sent_table = suppress;
  145758. }
  145759. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145760. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145761. htbl->sent_table = suppress;
  145762. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145763. htbl->sent_table = suppress;
  145764. }
  145765. }
  145766. GLOBAL(void)
  145767. jpeg_finish_compress (j_compress_ptr cinfo)
  145768. {
  145769. JDIMENSION iMCU_row;
  145770. if (cinfo->global_state == CSTATE_SCANNING ||
  145771. cinfo->global_state == CSTATE_RAW_OK) {
  145772. if (cinfo->next_scanline < cinfo->image_height)
  145773. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145774. (*cinfo->master->finish_pass) (cinfo);
  145775. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145776. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145777. while (! cinfo->master->is_last_pass) {
  145778. (*cinfo->master->prepare_for_pass) (cinfo);
  145779. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145780. if (cinfo->progress != NULL) {
  145781. cinfo->progress->pass_counter = (long) iMCU_row;
  145782. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145783. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145784. }
  145785. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145786. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145787. }
  145788. (*cinfo->master->finish_pass) (cinfo);
  145789. }
  145790. (*cinfo->marker->write_file_trailer) (cinfo);
  145791. (*cinfo->dest->term_destination) (cinfo);
  145792. jpeg_abort((j_common_ptr) cinfo);
  145793. }
  145794. GLOBAL(void)
  145795. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145796. const JOCTET *dataptr, unsigned int datalen)
  145797. {
  145798. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145799. if (cinfo->next_scanline != 0 ||
  145800. (cinfo->global_state != CSTATE_SCANNING &&
  145801. cinfo->global_state != CSTATE_RAW_OK &&
  145802. cinfo->global_state != CSTATE_WRCOEFS))
  145803. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145804. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145805. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145806. while (datalen--) {
  145807. (*write_marker_byte) (cinfo, *dataptr);
  145808. dataptr++;
  145809. }
  145810. }
  145811. GLOBAL(void)
  145812. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  145813. {
  145814. if (cinfo->next_scanline != 0 ||
  145815. (cinfo->global_state != CSTATE_SCANNING &&
  145816. cinfo->global_state != CSTATE_RAW_OK &&
  145817. cinfo->global_state != CSTATE_WRCOEFS))
  145818. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145819. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145820. }
  145821. GLOBAL(void)
  145822. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  145823. {
  145824. (*cinfo->marker->write_marker_byte) (cinfo, val);
  145825. }
  145826. GLOBAL(void)
  145827. jpeg_write_tables (j_compress_ptr cinfo)
  145828. {
  145829. if (cinfo->global_state != CSTATE_START)
  145830. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145831. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145832. (*cinfo->dest->init_destination) (cinfo);
  145833. jinit_marker_writer(cinfo);
  145834. (*cinfo->marker->write_tables_only) (cinfo);
  145835. (*cinfo->dest->term_destination) (cinfo);
  145836. }
  145837. /*** End of inlined file: jcapimin.c ***/
  145838. /*** Start of inlined file: jcapistd.c ***/
  145839. #define JPEG_INTERNALS
  145840. GLOBAL(void)
  145841. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  145842. {
  145843. if (cinfo->global_state != CSTATE_START)
  145844. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145845. if (write_all_tables)
  145846. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  145847. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145848. (*cinfo->dest->init_destination) (cinfo);
  145849. jinit_compress_master(cinfo);
  145850. (*cinfo->master->prepare_for_pass) (cinfo);
  145851. cinfo->next_scanline = 0;
  145852. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  145853. }
  145854. GLOBAL(JDIMENSION)
  145855. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  145856. JDIMENSION num_lines)
  145857. {
  145858. JDIMENSION row_ctr, rows_left;
  145859. if (cinfo->global_state != CSTATE_SCANNING)
  145860. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145861. if (cinfo->next_scanline >= cinfo->image_height)
  145862. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145863. if (cinfo->progress != NULL) {
  145864. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145865. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145866. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145867. }
  145868. if (cinfo->master->call_pass_startup)
  145869. (*cinfo->master->pass_startup) (cinfo);
  145870. rows_left = cinfo->image_height - cinfo->next_scanline;
  145871. if (num_lines > rows_left)
  145872. num_lines = rows_left;
  145873. row_ctr = 0;
  145874. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  145875. cinfo->next_scanline += row_ctr;
  145876. return row_ctr;
  145877. }
  145878. GLOBAL(JDIMENSION)
  145879. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  145880. JDIMENSION num_lines)
  145881. {
  145882. JDIMENSION lines_per_iMCU_row;
  145883. if (cinfo->global_state != CSTATE_RAW_OK)
  145884. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145885. if (cinfo->next_scanline >= cinfo->image_height) {
  145886. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145887. return 0;
  145888. }
  145889. if (cinfo->progress != NULL) {
  145890. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145891. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145892. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145893. }
  145894. if (cinfo->master->call_pass_startup)
  145895. (*cinfo->master->pass_startup) (cinfo);
  145896. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  145897. if (num_lines < lines_per_iMCU_row)
  145898. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  145899. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  145900. return 0;
  145901. }
  145902. cinfo->next_scanline += lines_per_iMCU_row;
  145903. return lines_per_iMCU_row;
  145904. }
  145905. /*** End of inlined file: jcapistd.c ***/
  145906. /*** Start of inlined file: jccoefct.c ***/
  145907. #define JPEG_INTERNALS
  145908. #ifdef ENTROPY_OPT_SUPPORTED
  145909. #define FULL_COEF_BUFFER_SUPPORTED
  145910. #else
  145911. #ifdef C_MULTISCAN_FILES_SUPPORTED
  145912. #define FULL_COEF_BUFFER_SUPPORTED
  145913. #endif
  145914. #endif
  145915. typedef struct {
  145916. struct jpeg_c_coef_controller pub; /* public fields */
  145917. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  145918. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  145919. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  145920. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  145921. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  145922. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  145923. } my_coef_controller;
  145924. typedef my_coef_controller * my_coef_ptr;
  145925. METHODDEF(boolean) compress_data
  145926. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145927. #ifdef FULL_COEF_BUFFER_SUPPORTED
  145928. METHODDEF(boolean) compress_first_pass
  145929. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145930. METHODDEF(boolean) compress_output
  145931. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145932. #endif
  145933. LOCAL(void)
  145934. start_iMCU_row (j_compress_ptr cinfo)
  145935. {
  145936. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145937. if (cinfo->comps_in_scan > 1) {
  145938. coef->MCU_rows_per_iMCU_row = 1;
  145939. } else {
  145940. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  145941. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  145942. else
  145943. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  145944. }
  145945. coef->mcu_ctr = 0;
  145946. coef->MCU_vert_offset = 0;
  145947. }
  145948. METHODDEF(void)
  145949. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  145950. {
  145951. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145952. coef->iMCU_row_num = 0;
  145953. start_iMCU_row(cinfo);
  145954. switch (pass_mode) {
  145955. case JBUF_PASS_THRU:
  145956. if (coef->whole_image[0] != NULL)
  145957. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145958. coef->pub.compress_data = compress_data;
  145959. break;
  145960. #ifdef FULL_COEF_BUFFER_SUPPORTED
  145961. case JBUF_SAVE_AND_PASS:
  145962. if (coef->whole_image[0] == NULL)
  145963. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145964. coef->pub.compress_data = compress_first_pass;
  145965. break;
  145966. case JBUF_CRANK_DEST:
  145967. if (coef->whole_image[0] == NULL)
  145968. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145969. coef->pub.compress_data = compress_output;
  145970. break;
  145971. #endif
  145972. default:
  145973. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145974. break;
  145975. }
  145976. }
  145977. METHODDEF(boolean)
  145978. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  145979. {
  145980. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145981. JDIMENSION MCU_col_num; /* index of current MCU within row */
  145982. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  145983. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  145984. int blkn, bi, ci, yindex, yoffset, blockcnt;
  145985. JDIMENSION ypos, xpos;
  145986. jpeg_component_info *compptr;
  145987. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  145988. yoffset++) {
  145989. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  145990. MCU_col_num++) {
  145991. blkn = 0;
  145992. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  145993. compptr = cinfo->cur_comp_info[ci];
  145994. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  145995. : compptr->last_col_width;
  145996. xpos = MCU_col_num * compptr->MCU_sample_width;
  145997. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  145998. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  145999. if (coef->iMCU_row_num < last_iMCU_row ||
  146000. yoffset+yindex < compptr->last_row_height) {
  146001. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146002. input_buf[compptr->component_index],
  146003. coef->MCU_buffer[blkn],
  146004. ypos, xpos, (JDIMENSION) blockcnt);
  146005. if (blockcnt < compptr->MCU_width) {
  146006. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146007. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146008. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146009. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146010. }
  146011. }
  146012. } else {
  146013. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146014. compptr->MCU_width * SIZEOF(JBLOCK));
  146015. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146016. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146017. }
  146018. }
  146019. blkn += compptr->MCU_width;
  146020. ypos += DCTSIZE;
  146021. }
  146022. }
  146023. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146024. coef->MCU_vert_offset = yoffset;
  146025. coef->mcu_ctr = MCU_col_num;
  146026. return FALSE;
  146027. }
  146028. }
  146029. coef->mcu_ctr = 0;
  146030. }
  146031. coef->iMCU_row_num++;
  146032. start_iMCU_row(cinfo);
  146033. return TRUE;
  146034. }
  146035. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146036. METHODDEF(boolean)
  146037. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146038. {
  146039. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146040. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146041. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146042. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146043. JCOEF lastDC;
  146044. jpeg_component_info *compptr;
  146045. JBLOCKARRAY buffer;
  146046. JBLOCKROW thisblockrow, lastblockrow;
  146047. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146048. ci++, compptr++) {
  146049. buffer = (*cinfo->mem->access_virt_barray)
  146050. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146051. coef->iMCU_row_num * compptr->v_samp_factor,
  146052. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146053. if (coef->iMCU_row_num < last_iMCU_row)
  146054. block_rows = compptr->v_samp_factor;
  146055. else {
  146056. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146057. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146058. }
  146059. blocks_across = compptr->width_in_blocks;
  146060. h_samp_factor = compptr->h_samp_factor;
  146061. ndummy = (int) (blocks_across % h_samp_factor);
  146062. if (ndummy > 0)
  146063. ndummy = h_samp_factor - ndummy;
  146064. for (block_row = 0; block_row < block_rows; block_row++) {
  146065. thisblockrow = buffer[block_row];
  146066. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146067. input_buf[ci], thisblockrow,
  146068. (JDIMENSION) (block_row * DCTSIZE),
  146069. (JDIMENSION) 0, blocks_across);
  146070. if (ndummy > 0) {
  146071. thisblockrow += blocks_across; /* => first dummy block */
  146072. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146073. lastDC = thisblockrow[-1][0];
  146074. for (bi = 0; bi < ndummy; bi++) {
  146075. thisblockrow[bi][0] = lastDC;
  146076. }
  146077. }
  146078. }
  146079. if (coef->iMCU_row_num == last_iMCU_row) {
  146080. blocks_across += ndummy; /* include lower right corner */
  146081. MCUs_across = blocks_across / h_samp_factor;
  146082. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146083. block_row++) {
  146084. thisblockrow = buffer[block_row];
  146085. lastblockrow = buffer[block_row-1];
  146086. jzero_far((void FAR *) thisblockrow,
  146087. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146088. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146089. lastDC = lastblockrow[h_samp_factor-1][0];
  146090. for (bi = 0; bi < h_samp_factor; bi++) {
  146091. thisblockrow[bi][0] = lastDC;
  146092. }
  146093. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146094. lastblockrow += h_samp_factor;
  146095. }
  146096. }
  146097. }
  146098. }
  146099. return compress_output(cinfo, input_buf);
  146100. }
  146101. METHODDEF(boolean)
  146102. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146103. {
  146104. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146105. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146106. int blkn, ci, xindex, yindex, yoffset;
  146107. JDIMENSION start_col;
  146108. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146109. JBLOCKROW buffer_ptr;
  146110. jpeg_component_info *compptr;
  146111. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146112. compptr = cinfo->cur_comp_info[ci];
  146113. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146114. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146115. coef->iMCU_row_num * compptr->v_samp_factor,
  146116. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146117. }
  146118. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146119. yoffset++) {
  146120. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146121. MCU_col_num++) {
  146122. blkn = 0; /* index of current DCT block within MCU */
  146123. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146124. compptr = cinfo->cur_comp_info[ci];
  146125. start_col = MCU_col_num * compptr->MCU_width;
  146126. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146127. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146128. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146129. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146130. }
  146131. }
  146132. }
  146133. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146134. coef->MCU_vert_offset = yoffset;
  146135. coef->mcu_ctr = MCU_col_num;
  146136. return FALSE;
  146137. }
  146138. }
  146139. coef->mcu_ctr = 0;
  146140. }
  146141. coef->iMCU_row_num++;
  146142. start_iMCU_row(cinfo);
  146143. return TRUE;
  146144. }
  146145. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146146. GLOBAL(void)
  146147. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146148. {
  146149. my_coef_ptr coef;
  146150. coef = (my_coef_ptr)
  146151. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146152. SIZEOF(my_coef_controller));
  146153. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146154. coef->pub.start_pass = start_pass_coef;
  146155. if (need_full_buffer) {
  146156. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146157. int ci;
  146158. jpeg_component_info *compptr;
  146159. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146160. ci++, compptr++) {
  146161. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146162. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146163. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146164. (long) compptr->h_samp_factor),
  146165. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146166. (long) compptr->v_samp_factor),
  146167. (JDIMENSION) compptr->v_samp_factor);
  146168. }
  146169. #else
  146170. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146171. #endif
  146172. } else {
  146173. JBLOCKROW buffer;
  146174. int i;
  146175. buffer = (JBLOCKROW)
  146176. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146177. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146178. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146179. coef->MCU_buffer[i] = buffer + i;
  146180. }
  146181. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146182. }
  146183. }
  146184. /*** End of inlined file: jccoefct.c ***/
  146185. /*** Start of inlined file: jccolor.c ***/
  146186. #define JPEG_INTERNALS
  146187. typedef struct {
  146188. struct jpeg_color_converter pub; /* public fields */
  146189. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146190. } my_color_converter;
  146191. typedef my_color_converter * my_cconvert_ptr;
  146192. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146193. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146194. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146195. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146196. #define R_Y_OFF 0 /* offset to R => Y section */
  146197. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146198. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146199. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146200. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146201. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146202. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146203. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146204. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146205. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146206. METHODDEF(void)
  146207. rgb_ycc_start (j_compress_ptr cinfo)
  146208. {
  146209. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146210. INT32 * rgb_ycc_tab;
  146211. INT32 i;
  146212. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146213. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146214. (TABLE_SIZE * SIZEOF(INT32)));
  146215. for (i = 0; i <= MAXJSAMPLE; i++) {
  146216. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146217. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146218. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146219. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146220. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146221. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146222. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146223. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146224. }
  146225. }
  146226. METHODDEF(void)
  146227. rgb_ycc_convert (j_compress_ptr cinfo,
  146228. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146229. JDIMENSION output_row, int num_rows)
  146230. {
  146231. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146232. register int r, g, b;
  146233. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146234. register JSAMPROW inptr;
  146235. register JSAMPROW outptr0, outptr1, outptr2;
  146236. register JDIMENSION col;
  146237. JDIMENSION num_cols = cinfo->image_width;
  146238. while (--num_rows >= 0) {
  146239. inptr = *input_buf++;
  146240. outptr0 = output_buf[0][output_row];
  146241. outptr1 = output_buf[1][output_row];
  146242. outptr2 = output_buf[2][output_row];
  146243. output_row++;
  146244. for (col = 0; col < num_cols; col++) {
  146245. r = GETJSAMPLE(inptr[RGB_RED]);
  146246. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146247. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146248. inptr += RGB_PIXELSIZE;
  146249. outptr0[col] = (JSAMPLE)
  146250. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146251. >> SCALEBITS);
  146252. outptr1[col] = (JSAMPLE)
  146253. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146254. >> SCALEBITS);
  146255. outptr2[col] = (JSAMPLE)
  146256. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146257. >> SCALEBITS);
  146258. }
  146259. }
  146260. }
  146261. METHODDEF(void)
  146262. rgb_gray_convert (j_compress_ptr cinfo,
  146263. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146264. JDIMENSION output_row, int num_rows)
  146265. {
  146266. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146267. register int r, g, b;
  146268. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146269. register JSAMPROW inptr;
  146270. register JSAMPROW outptr;
  146271. register JDIMENSION col;
  146272. JDIMENSION num_cols = cinfo->image_width;
  146273. while (--num_rows >= 0) {
  146274. inptr = *input_buf++;
  146275. outptr = output_buf[0][output_row];
  146276. output_row++;
  146277. for (col = 0; col < num_cols; col++) {
  146278. r = GETJSAMPLE(inptr[RGB_RED]);
  146279. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146280. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146281. inptr += RGB_PIXELSIZE;
  146282. outptr[col] = (JSAMPLE)
  146283. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146284. >> SCALEBITS);
  146285. }
  146286. }
  146287. }
  146288. METHODDEF(void)
  146289. cmyk_ycck_convert (j_compress_ptr cinfo,
  146290. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146291. JDIMENSION output_row, int num_rows)
  146292. {
  146293. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146294. register int r, g, b;
  146295. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146296. register JSAMPROW inptr;
  146297. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146298. register JDIMENSION col;
  146299. JDIMENSION num_cols = cinfo->image_width;
  146300. while (--num_rows >= 0) {
  146301. inptr = *input_buf++;
  146302. outptr0 = output_buf[0][output_row];
  146303. outptr1 = output_buf[1][output_row];
  146304. outptr2 = output_buf[2][output_row];
  146305. outptr3 = output_buf[3][output_row];
  146306. output_row++;
  146307. for (col = 0; col < num_cols; col++) {
  146308. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146309. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146310. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146311. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146312. inptr += 4;
  146313. outptr0[col] = (JSAMPLE)
  146314. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146315. >> SCALEBITS);
  146316. outptr1[col] = (JSAMPLE)
  146317. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146318. >> SCALEBITS);
  146319. outptr2[col] = (JSAMPLE)
  146320. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146321. >> SCALEBITS);
  146322. }
  146323. }
  146324. }
  146325. METHODDEF(void)
  146326. grayscale_convert (j_compress_ptr cinfo,
  146327. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146328. JDIMENSION output_row, int num_rows)
  146329. {
  146330. register JSAMPROW inptr;
  146331. register JSAMPROW outptr;
  146332. register JDIMENSION col;
  146333. JDIMENSION num_cols = cinfo->image_width;
  146334. int instride = cinfo->input_components;
  146335. while (--num_rows >= 0) {
  146336. inptr = *input_buf++;
  146337. outptr = output_buf[0][output_row];
  146338. output_row++;
  146339. for (col = 0; col < num_cols; col++) {
  146340. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146341. inptr += instride;
  146342. }
  146343. }
  146344. }
  146345. METHODDEF(void)
  146346. null_convert (j_compress_ptr cinfo,
  146347. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146348. JDIMENSION output_row, int num_rows)
  146349. {
  146350. register JSAMPROW inptr;
  146351. register JSAMPROW outptr;
  146352. register JDIMENSION col;
  146353. register int ci;
  146354. int nc = cinfo->num_components;
  146355. JDIMENSION num_cols = cinfo->image_width;
  146356. while (--num_rows >= 0) {
  146357. for (ci = 0; ci < nc; ci++) {
  146358. inptr = *input_buf;
  146359. outptr = output_buf[ci][output_row];
  146360. for (col = 0; col < num_cols; col++) {
  146361. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146362. inptr += nc;
  146363. }
  146364. }
  146365. input_buf++;
  146366. output_row++;
  146367. }
  146368. }
  146369. METHODDEF(void)
  146370. null_method (j_compress_ptr cinfo)
  146371. {
  146372. }
  146373. GLOBAL(void)
  146374. jinit_color_converter (j_compress_ptr cinfo)
  146375. {
  146376. my_cconvert_ptr cconvert;
  146377. cconvert = (my_cconvert_ptr)
  146378. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146379. SIZEOF(my_color_converter));
  146380. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146381. cconvert->pub.start_pass = null_method;
  146382. switch (cinfo->in_color_space) {
  146383. case JCS_GRAYSCALE:
  146384. if (cinfo->input_components != 1)
  146385. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146386. break;
  146387. case JCS_RGB:
  146388. #if RGB_PIXELSIZE != 3
  146389. if (cinfo->input_components != RGB_PIXELSIZE)
  146390. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146391. break;
  146392. #endif /* else share code with YCbCr */
  146393. case JCS_YCbCr:
  146394. if (cinfo->input_components != 3)
  146395. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146396. break;
  146397. case JCS_CMYK:
  146398. case JCS_YCCK:
  146399. if (cinfo->input_components != 4)
  146400. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146401. break;
  146402. default: /* JCS_UNKNOWN can be anything */
  146403. if (cinfo->input_components < 1)
  146404. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146405. break;
  146406. }
  146407. switch (cinfo->jpeg_color_space) {
  146408. case JCS_GRAYSCALE:
  146409. if (cinfo->num_components != 1)
  146410. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146411. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146412. cconvert->pub.color_convert = grayscale_convert;
  146413. else if (cinfo->in_color_space == JCS_RGB) {
  146414. cconvert->pub.start_pass = rgb_ycc_start;
  146415. cconvert->pub.color_convert = rgb_gray_convert;
  146416. } else if (cinfo->in_color_space == JCS_YCbCr)
  146417. cconvert->pub.color_convert = grayscale_convert;
  146418. else
  146419. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146420. break;
  146421. case JCS_RGB:
  146422. if (cinfo->num_components != 3)
  146423. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146424. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146425. cconvert->pub.color_convert = null_convert;
  146426. else
  146427. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146428. break;
  146429. case JCS_YCbCr:
  146430. if (cinfo->num_components != 3)
  146431. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146432. if (cinfo->in_color_space == JCS_RGB) {
  146433. cconvert->pub.start_pass = rgb_ycc_start;
  146434. cconvert->pub.color_convert = rgb_ycc_convert;
  146435. } else if (cinfo->in_color_space == JCS_YCbCr)
  146436. cconvert->pub.color_convert = null_convert;
  146437. else
  146438. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146439. break;
  146440. case JCS_CMYK:
  146441. if (cinfo->num_components != 4)
  146442. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146443. if (cinfo->in_color_space == JCS_CMYK)
  146444. cconvert->pub.color_convert = null_convert;
  146445. else
  146446. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146447. break;
  146448. case JCS_YCCK:
  146449. if (cinfo->num_components != 4)
  146450. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146451. if (cinfo->in_color_space == JCS_CMYK) {
  146452. cconvert->pub.start_pass = rgb_ycc_start;
  146453. cconvert->pub.color_convert = cmyk_ycck_convert;
  146454. } else if (cinfo->in_color_space == JCS_YCCK)
  146455. cconvert->pub.color_convert = null_convert;
  146456. else
  146457. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146458. break;
  146459. default: /* allow null conversion of JCS_UNKNOWN */
  146460. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146461. cinfo->num_components != cinfo->input_components)
  146462. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146463. cconvert->pub.color_convert = null_convert;
  146464. break;
  146465. }
  146466. }
  146467. /*** End of inlined file: jccolor.c ***/
  146468. #undef FIX
  146469. /*** Start of inlined file: jcdctmgr.c ***/
  146470. #define JPEG_INTERNALS
  146471. /*** Start of inlined file: jdct.h ***/
  146472. #ifndef __jdct_h__
  146473. #define __jdct_h__
  146474. #if BITS_IN_JSAMPLE == 8
  146475. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146476. #else
  146477. typedef INT32 DCTELEM; /* must have 32 bits */
  146478. #endif
  146479. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146480. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146481. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146482. #if BITS_IN_JSAMPLE == 8
  146483. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146484. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146485. #else
  146486. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146487. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146488. #endif
  146489. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146490. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146491. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146492. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146493. #define jpeg_fdct_islow jFDislow
  146494. #define jpeg_fdct_ifast jFDifast
  146495. #define jpeg_fdct_float jFDfloat
  146496. #define jpeg_idct_islow jRDislow
  146497. #define jpeg_idct_ifast jRDifast
  146498. #define jpeg_idct_float jRDfloat
  146499. #define jpeg_idct_4x4 jRD4x4
  146500. #define jpeg_idct_2x2 jRD2x2
  146501. #define jpeg_idct_1x1 jRD1x1
  146502. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146503. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146504. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146505. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146506. EXTERN(void) jpeg_idct_islow
  146507. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146508. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146509. EXTERN(void) jpeg_idct_ifast
  146510. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146511. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146512. EXTERN(void) jpeg_idct_float
  146513. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146514. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146515. EXTERN(void) jpeg_idct_4x4
  146516. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146517. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146518. EXTERN(void) jpeg_idct_2x2
  146519. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146520. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146521. EXTERN(void) jpeg_idct_1x1
  146522. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146523. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146524. #define ONE ((INT32) 1)
  146525. #define CONST_SCALE (ONE << CONST_BITS)
  146526. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146527. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146528. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146529. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146530. #endif
  146531. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146532. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146533. #endif
  146534. #ifndef MULTIPLY16C16 /* default definition */
  146535. #define MULTIPLY16C16(var,const) ((var) * (const))
  146536. #endif
  146537. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146538. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146539. #endif
  146540. #ifndef MULTIPLY16V16 /* default definition */
  146541. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146542. #endif
  146543. #endif
  146544. /*** End of inlined file: jdct.h ***/
  146545. /* Private declarations for DCT subsystem */
  146546. typedef struct {
  146547. struct jpeg_forward_dct pub; /* public fields */
  146548. forward_DCT_method_ptr do_dct;
  146549. DCTELEM * divisors[NUM_QUANT_TBLS];
  146550. #ifdef DCT_FLOAT_SUPPORTED
  146551. float_DCT_method_ptr do_float_dct;
  146552. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146553. #endif
  146554. } my_fdct_controller;
  146555. typedef my_fdct_controller * my_fdct_ptr;
  146556. METHODDEF(void)
  146557. start_pass_fdctmgr (j_compress_ptr cinfo)
  146558. {
  146559. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146560. int ci, qtblno, i;
  146561. jpeg_component_info *compptr;
  146562. JQUANT_TBL * qtbl;
  146563. DCTELEM * dtbl;
  146564. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146565. ci++, compptr++) {
  146566. qtblno = compptr->quant_tbl_no;
  146567. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146568. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146569. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146570. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146571. switch (cinfo->dct_method) {
  146572. #ifdef DCT_ISLOW_SUPPORTED
  146573. case JDCT_ISLOW:
  146574. if (fdct->divisors[qtblno] == NULL) {
  146575. fdct->divisors[qtblno] = (DCTELEM *)
  146576. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146577. DCTSIZE2 * SIZEOF(DCTELEM));
  146578. }
  146579. dtbl = fdct->divisors[qtblno];
  146580. for (i = 0; i < DCTSIZE2; i++) {
  146581. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146582. }
  146583. break;
  146584. #endif
  146585. #ifdef DCT_IFAST_SUPPORTED
  146586. case JDCT_IFAST:
  146587. {
  146588. #define CONST_BITS 14
  146589. static const INT16 aanscales[DCTSIZE2] = {
  146590. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146591. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146592. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146593. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146594. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146595. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146596. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146597. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146598. };
  146599. SHIFT_TEMPS
  146600. if (fdct->divisors[qtblno] == NULL) {
  146601. fdct->divisors[qtblno] = (DCTELEM *)
  146602. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146603. DCTSIZE2 * SIZEOF(DCTELEM));
  146604. }
  146605. dtbl = fdct->divisors[qtblno];
  146606. for (i = 0; i < DCTSIZE2; i++) {
  146607. dtbl[i] = (DCTELEM)
  146608. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146609. (INT32) aanscales[i]),
  146610. CONST_BITS-3);
  146611. }
  146612. }
  146613. break;
  146614. #endif
  146615. #ifdef DCT_FLOAT_SUPPORTED
  146616. case JDCT_FLOAT:
  146617. {
  146618. FAST_FLOAT * fdtbl;
  146619. int row, col;
  146620. static const double aanscalefactor[DCTSIZE] = {
  146621. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146622. 1.0, 0.785694958, 0.541196100, 0.275899379
  146623. };
  146624. if (fdct->float_divisors[qtblno] == NULL) {
  146625. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146626. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146627. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146628. }
  146629. fdtbl = fdct->float_divisors[qtblno];
  146630. i = 0;
  146631. for (row = 0; row < DCTSIZE; row++) {
  146632. for (col = 0; col < DCTSIZE; col++) {
  146633. fdtbl[i] = (FAST_FLOAT)
  146634. (1.0 / (((double) qtbl->quantval[i] *
  146635. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146636. i++;
  146637. }
  146638. }
  146639. }
  146640. break;
  146641. #endif
  146642. default:
  146643. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146644. break;
  146645. }
  146646. }
  146647. }
  146648. METHODDEF(void)
  146649. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146650. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146651. JDIMENSION start_row, JDIMENSION start_col,
  146652. JDIMENSION num_blocks)
  146653. {
  146654. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146655. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146656. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146657. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146658. JDIMENSION bi;
  146659. sample_data += start_row; /* fold in the vertical offset once */
  146660. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146661. { register DCTELEM *workspaceptr;
  146662. register JSAMPROW elemptr;
  146663. register int elemr;
  146664. workspaceptr = workspace;
  146665. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146666. elemptr = sample_data[elemr] + start_col;
  146667. #if DCTSIZE == 8 /* unroll the inner loop */
  146668. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146669. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146670. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146671. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146672. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146673. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146674. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146675. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146676. #else
  146677. { register int elemc;
  146678. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146679. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146680. }
  146681. }
  146682. #endif
  146683. }
  146684. }
  146685. (*do_dct) (workspace);
  146686. { register DCTELEM temp, qval;
  146687. register int i;
  146688. register JCOEFPTR output_ptr = coef_blocks[bi];
  146689. for (i = 0; i < DCTSIZE2; i++) {
  146690. qval = divisors[i];
  146691. temp = workspace[i];
  146692. #ifdef FAST_DIVIDE
  146693. #define DIVIDE_BY(a,b) a /= b
  146694. #else
  146695. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146696. #endif
  146697. if (temp < 0) {
  146698. temp = -temp;
  146699. temp += qval>>1; /* for rounding */
  146700. DIVIDE_BY(temp, qval);
  146701. temp = -temp;
  146702. } else {
  146703. temp += qval>>1; /* for rounding */
  146704. DIVIDE_BY(temp, qval);
  146705. }
  146706. output_ptr[i] = (JCOEF) temp;
  146707. }
  146708. }
  146709. }
  146710. }
  146711. #ifdef DCT_FLOAT_SUPPORTED
  146712. METHODDEF(void)
  146713. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146714. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146715. JDIMENSION start_row, JDIMENSION start_col,
  146716. JDIMENSION num_blocks)
  146717. {
  146718. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146719. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146720. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146721. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146722. JDIMENSION bi;
  146723. sample_data += start_row; /* fold in the vertical offset once */
  146724. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146725. { register FAST_FLOAT *workspaceptr;
  146726. register JSAMPROW elemptr;
  146727. register int elemr;
  146728. workspaceptr = workspace;
  146729. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146730. elemptr = sample_data[elemr] + start_col;
  146731. #if DCTSIZE == 8 /* unroll the inner loop */
  146732. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146733. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146734. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146735. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146736. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146737. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146738. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146739. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146740. #else
  146741. { register int elemc;
  146742. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146743. *workspaceptr++ = (FAST_FLOAT)
  146744. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146745. }
  146746. }
  146747. #endif
  146748. }
  146749. }
  146750. (*do_dct) (workspace);
  146751. { register FAST_FLOAT temp;
  146752. register int i;
  146753. register JCOEFPTR output_ptr = coef_blocks[bi];
  146754. for (i = 0; i < DCTSIZE2; i++) {
  146755. temp = workspace[i] * divisors[i];
  146756. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146757. }
  146758. }
  146759. }
  146760. }
  146761. #endif /* DCT_FLOAT_SUPPORTED */
  146762. GLOBAL(void)
  146763. jinit_forward_dct (j_compress_ptr cinfo)
  146764. {
  146765. my_fdct_ptr fdct;
  146766. int i;
  146767. fdct = (my_fdct_ptr)
  146768. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146769. SIZEOF(my_fdct_controller));
  146770. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146771. fdct->pub.start_pass = start_pass_fdctmgr;
  146772. switch (cinfo->dct_method) {
  146773. #ifdef DCT_ISLOW_SUPPORTED
  146774. case JDCT_ISLOW:
  146775. fdct->pub.forward_DCT = forward_DCT;
  146776. fdct->do_dct = jpeg_fdct_islow;
  146777. break;
  146778. #endif
  146779. #ifdef DCT_IFAST_SUPPORTED
  146780. case JDCT_IFAST:
  146781. fdct->pub.forward_DCT = forward_DCT;
  146782. fdct->do_dct = jpeg_fdct_ifast;
  146783. break;
  146784. #endif
  146785. #ifdef DCT_FLOAT_SUPPORTED
  146786. case JDCT_FLOAT:
  146787. fdct->pub.forward_DCT = forward_DCT_float;
  146788. fdct->do_float_dct = jpeg_fdct_float;
  146789. break;
  146790. #endif
  146791. default:
  146792. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146793. break;
  146794. }
  146795. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146796. fdct->divisors[i] = NULL;
  146797. #ifdef DCT_FLOAT_SUPPORTED
  146798. fdct->float_divisors[i] = NULL;
  146799. #endif
  146800. }
  146801. }
  146802. /*** End of inlined file: jcdctmgr.c ***/
  146803. #undef CONST_BITS
  146804. /*** Start of inlined file: jchuff.c ***/
  146805. #define JPEG_INTERNALS
  146806. /*** Start of inlined file: jchuff.h ***/
  146807. #ifndef _jchuff_h_
  146808. #define _jchuff_h_
  146809. #if BITS_IN_JSAMPLE == 8
  146810. #define MAX_COEF_BITS 10
  146811. #else
  146812. #define MAX_COEF_BITS 14
  146813. #endif
  146814. typedef struct {
  146815. unsigned int ehufco[256]; /* code for each symbol */
  146816. char ehufsi[256]; /* length of code for each symbol */
  146817. } c_derived_tbl;
  146818. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146819. #define jpeg_make_c_derived_tbl jMkCDerived
  146820. #define jpeg_gen_optimal_table jGenOptTbl
  146821. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146822. EXTERN(void) jpeg_make_c_derived_tbl
  146823. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  146824. c_derived_tbl ** pdtbl));
  146825. EXTERN(void) jpeg_gen_optimal_table
  146826. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  146827. #endif
  146828. /*** End of inlined file: jchuff.h ***/
  146829. /* Declarations shared with jcphuff.c */
  146830. typedef struct {
  146831. INT32 put_buffer; /* current bit-accumulation buffer */
  146832. int put_bits; /* # of bits now in it */
  146833. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  146834. } savable_state;
  146835. #ifndef NO_STRUCT_ASSIGN
  146836. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  146837. #else
  146838. #if MAX_COMPS_IN_SCAN == 4
  146839. #define ASSIGN_STATE(dest,src) \
  146840. ((dest).put_buffer = (src).put_buffer, \
  146841. (dest).put_bits = (src).put_bits, \
  146842. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  146843. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  146844. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  146845. (dest).last_dc_val[3] = (src).last_dc_val[3])
  146846. #endif
  146847. #endif
  146848. typedef struct {
  146849. struct jpeg_entropy_encoder pub; /* public fields */
  146850. savable_state saved; /* Bit buffer & DC state at start of MCU */
  146851. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  146852. int next_restart_num; /* next restart number to write (0-7) */
  146853. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  146854. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  146855. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  146856. long * dc_count_ptrs[NUM_HUFF_TBLS];
  146857. long * ac_count_ptrs[NUM_HUFF_TBLS];
  146858. #endif
  146859. } huff_entropy_encoder;
  146860. typedef huff_entropy_encoder * huff_entropy_ptr;
  146861. typedef struct {
  146862. JOCTET * next_output_byte; /* => next byte to write in buffer */
  146863. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  146864. savable_state cur; /* Current bit buffer & DC state */
  146865. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  146866. } working_state;
  146867. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  146868. JBLOCKROW *MCU_data));
  146869. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  146870. #ifdef ENTROPY_OPT_SUPPORTED
  146871. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  146872. JBLOCKROW *MCU_data));
  146873. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  146874. #endif
  146875. METHODDEF(void)
  146876. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  146877. {
  146878. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  146879. int ci, dctbl, actbl;
  146880. jpeg_component_info * compptr;
  146881. if (gather_statistics) {
  146882. #ifdef ENTROPY_OPT_SUPPORTED
  146883. entropy->pub.encode_mcu = encode_mcu_gather;
  146884. entropy->pub.finish_pass = finish_pass_gather;
  146885. #else
  146886. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146887. #endif
  146888. } else {
  146889. entropy->pub.encode_mcu = encode_mcu_huff;
  146890. entropy->pub.finish_pass = finish_pass_huff;
  146891. }
  146892. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146893. compptr = cinfo->cur_comp_info[ci];
  146894. dctbl = compptr->dc_tbl_no;
  146895. actbl = compptr->ac_tbl_no;
  146896. if (gather_statistics) {
  146897. #ifdef ENTROPY_OPT_SUPPORTED
  146898. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  146899. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  146900. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  146901. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  146902. if (entropy->dc_count_ptrs[dctbl] == NULL)
  146903. entropy->dc_count_ptrs[dctbl] = (long *)
  146904. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146905. 257 * SIZEOF(long));
  146906. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  146907. if (entropy->ac_count_ptrs[actbl] == NULL)
  146908. entropy->ac_count_ptrs[actbl] = (long *)
  146909. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146910. 257 * SIZEOF(long));
  146911. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  146912. #endif
  146913. } else {
  146914. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  146915. & entropy->dc_derived_tbls[dctbl]);
  146916. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  146917. & entropy->ac_derived_tbls[actbl]);
  146918. }
  146919. entropy->saved.last_dc_val[ci] = 0;
  146920. }
  146921. entropy->saved.put_buffer = 0;
  146922. entropy->saved.put_bits = 0;
  146923. entropy->restarts_to_go = cinfo->restart_interval;
  146924. entropy->next_restart_num = 0;
  146925. }
  146926. GLOBAL(void)
  146927. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  146928. c_derived_tbl ** pdtbl)
  146929. {
  146930. JHUFF_TBL *htbl;
  146931. c_derived_tbl *dtbl;
  146932. int p, i, l, lastp, si, maxsymbol;
  146933. char huffsize[257];
  146934. unsigned int huffcode[257];
  146935. unsigned int code;
  146936. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  146937. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  146938. htbl =
  146939. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  146940. if (htbl == NULL)
  146941. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  146942. if (*pdtbl == NULL)
  146943. *pdtbl = (c_derived_tbl *)
  146944. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146945. SIZEOF(c_derived_tbl));
  146946. dtbl = *pdtbl;
  146947. p = 0;
  146948. for (l = 1; l <= 16; l++) {
  146949. i = (int) htbl->bits[l];
  146950. if (i < 0 || p + i > 256) /* protect against table overrun */
  146951. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  146952. while (i--)
  146953. huffsize[p++] = (char) l;
  146954. }
  146955. huffsize[p] = 0;
  146956. lastp = p;
  146957. code = 0;
  146958. si = huffsize[0];
  146959. p = 0;
  146960. while (huffsize[p]) {
  146961. while (((int) huffsize[p]) == si) {
  146962. huffcode[p++] = code;
  146963. code++;
  146964. }
  146965. if (((INT32) code) >= (((INT32) 1) << si))
  146966. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  146967. code <<= 1;
  146968. si++;
  146969. }
  146970. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  146971. maxsymbol = isDC ? 15 : 255;
  146972. for (p = 0; p < lastp; p++) {
  146973. i = htbl->huffval[p];
  146974. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  146975. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  146976. dtbl->ehufco[i] = huffcode[p];
  146977. dtbl->ehufsi[i] = huffsize[p];
  146978. }
  146979. }
  146980. #define emit_byte(state,val,action) \
  146981. { *(state)->next_output_byte++ = (JOCTET) (val); \
  146982. if (--(state)->free_in_buffer == 0) \
  146983. if (! dump_buffer(state)) \
  146984. { action; } }
  146985. LOCAL(boolean)
  146986. dump_buffer (working_state * state)
  146987. {
  146988. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  146989. if (! (*dest->empty_output_buffer) (state->cinfo))
  146990. return FALSE;
  146991. state->next_output_byte = dest->next_output_byte;
  146992. state->free_in_buffer = dest->free_in_buffer;
  146993. return TRUE;
  146994. }
  146995. INLINE
  146996. LOCAL(boolean)
  146997. emit_bits (working_state * state, unsigned int code, int size)
  146998. {
  146999. register INT32 put_buffer = (INT32) code;
  147000. register int put_bits = state->cur.put_bits;
  147001. if (size == 0)
  147002. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147003. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147004. put_bits += size; /* new number of bits in buffer */
  147005. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147006. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147007. while (put_bits >= 8) {
  147008. int c = (int) ((put_buffer >> 16) & 0xFF);
  147009. emit_byte(state, c, return FALSE);
  147010. if (c == 0xFF) { /* need to stuff a zero byte? */
  147011. emit_byte(state, 0, return FALSE);
  147012. }
  147013. put_buffer <<= 8;
  147014. put_bits -= 8;
  147015. }
  147016. state->cur.put_buffer = put_buffer; /* update state variables */
  147017. state->cur.put_bits = put_bits;
  147018. return TRUE;
  147019. }
  147020. LOCAL(boolean)
  147021. flush_bits (working_state * state)
  147022. {
  147023. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147024. return FALSE;
  147025. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147026. state->cur.put_bits = 0;
  147027. return TRUE;
  147028. }
  147029. LOCAL(boolean)
  147030. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147031. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147032. {
  147033. register int temp, temp2;
  147034. register int nbits;
  147035. register int k, r, i;
  147036. temp = temp2 = block[0] - last_dc_val;
  147037. if (temp < 0) {
  147038. temp = -temp; /* temp is abs value of input */
  147039. temp2--;
  147040. }
  147041. nbits = 0;
  147042. while (temp) {
  147043. nbits++;
  147044. temp >>= 1;
  147045. }
  147046. if (nbits > MAX_COEF_BITS+1)
  147047. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147048. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147049. return FALSE;
  147050. if (nbits) /* emit_bits rejects calls with size 0 */
  147051. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147052. return FALSE;
  147053. r = 0; /* r = run length of zeros */
  147054. for (k = 1; k < DCTSIZE2; k++) {
  147055. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147056. r++;
  147057. } else {
  147058. while (r > 15) {
  147059. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147060. return FALSE;
  147061. r -= 16;
  147062. }
  147063. temp2 = temp;
  147064. if (temp < 0) {
  147065. temp = -temp; /* temp is abs value of input */
  147066. temp2--;
  147067. }
  147068. nbits = 1; /* there must be at least one 1 bit */
  147069. while ((temp >>= 1))
  147070. nbits++;
  147071. if (nbits > MAX_COEF_BITS)
  147072. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147073. i = (r << 4) + nbits;
  147074. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147075. return FALSE;
  147076. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147077. return FALSE;
  147078. r = 0;
  147079. }
  147080. }
  147081. if (r > 0)
  147082. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147083. return FALSE;
  147084. return TRUE;
  147085. }
  147086. LOCAL(boolean)
  147087. emit_restart (working_state * state, int restart_num)
  147088. {
  147089. int ci;
  147090. if (! flush_bits(state))
  147091. return FALSE;
  147092. emit_byte(state, 0xFF, return FALSE);
  147093. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147094. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147095. state->cur.last_dc_val[ci] = 0;
  147096. return TRUE;
  147097. }
  147098. METHODDEF(boolean)
  147099. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147100. {
  147101. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147102. working_state state;
  147103. int blkn, ci;
  147104. jpeg_component_info * compptr;
  147105. state.next_output_byte = cinfo->dest->next_output_byte;
  147106. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147107. ASSIGN_STATE(state.cur, entropy->saved);
  147108. state.cinfo = cinfo;
  147109. if (cinfo->restart_interval) {
  147110. if (entropy->restarts_to_go == 0)
  147111. if (! emit_restart(&state, entropy->next_restart_num))
  147112. return FALSE;
  147113. }
  147114. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147115. ci = cinfo->MCU_membership[blkn];
  147116. compptr = cinfo->cur_comp_info[ci];
  147117. if (! encode_one_block(&state,
  147118. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147119. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147120. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147121. return FALSE;
  147122. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147123. }
  147124. cinfo->dest->next_output_byte = state.next_output_byte;
  147125. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147126. ASSIGN_STATE(entropy->saved, state.cur);
  147127. if (cinfo->restart_interval) {
  147128. if (entropy->restarts_to_go == 0) {
  147129. entropy->restarts_to_go = cinfo->restart_interval;
  147130. entropy->next_restart_num++;
  147131. entropy->next_restart_num &= 7;
  147132. }
  147133. entropy->restarts_to_go--;
  147134. }
  147135. return TRUE;
  147136. }
  147137. METHODDEF(void)
  147138. finish_pass_huff (j_compress_ptr cinfo)
  147139. {
  147140. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147141. working_state state;
  147142. state.next_output_byte = cinfo->dest->next_output_byte;
  147143. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147144. ASSIGN_STATE(state.cur, entropy->saved);
  147145. state.cinfo = cinfo;
  147146. if (! flush_bits(&state))
  147147. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147148. cinfo->dest->next_output_byte = state.next_output_byte;
  147149. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147150. ASSIGN_STATE(entropy->saved, state.cur);
  147151. }
  147152. #ifdef ENTROPY_OPT_SUPPORTED
  147153. LOCAL(void)
  147154. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147155. long dc_counts[], long ac_counts[])
  147156. {
  147157. register int temp;
  147158. register int nbits;
  147159. register int k, r;
  147160. temp = block[0] - last_dc_val;
  147161. if (temp < 0)
  147162. temp = -temp;
  147163. nbits = 0;
  147164. while (temp) {
  147165. nbits++;
  147166. temp >>= 1;
  147167. }
  147168. if (nbits > MAX_COEF_BITS+1)
  147169. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147170. dc_counts[nbits]++;
  147171. r = 0; /* r = run length of zeros */
  147172. for (k = 1; k < DCTSIZE2; k++) {
  147173. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147174. r++;
  147175. } else {
  147176. while (r > 15) {
  147177. ac_counts[0xF0]++;
  147178. r -= 16;
  147179. }
  147180. if (temp < 0)
  147181. temp = -temp;
  147182. nbits = 1; /* there must be at least one 1 bit */
  147183. while ((temp >>= 1))
  147184. nbits++;
  147185. if (nbits > MAX_COEF_BITS)
  147186. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147187. ac_counts[(r << 4) + nbits]++;
  147188. r = 0;
  147189. }
  147190. }
  147191. if (r > 0)
  147192. ac_counts[0]++;
  147193. }
  147194. METHODDEF(boolean)
  147195. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147196. {
  147197. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147198. int blkn, ci;
  147199. jpeg_component_info * compptr;
  147200. if (cinfo->restart_interval) {
  147201. if (entropy->restarts_to_go == 0) {
  147202. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147203. entropy->saved.last_dc_val[ci] = 0;
  147204. entropy->restarts_to_go = cinfo->restart_interval;
  147205. }
  147206. entropy->restarts_to_go--;
  147207. }
  147208. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147209. ci = cinfo->MCU_membership[blkn];
  147210. compptr = cinfo->cur_comp_info[ci];
  147211. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147212. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147213. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147214. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147215. }
  147216. return TRUE;
  147217. }
  147218. GLOBAL(void)
  147219. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147220. {
  147221. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147222. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147223. int codesize[257]; /* codesize[k] = code length of symbol k */
  147224. int others[257]; /* next symbol in current branch of tree */
  147225. int c1, c2;
  147226. int p, i, j;
  147227. long v;
  147228. MEMZERO(bits, SIZEOF(bits));
  147229. MEMZERO(codesize, SIZEOF(codesize));
  147230. for (i = 0; i < 257; i++)
  147231. others[i] = -1; /* init links to empty */
  147232. freq[256] = 1; /* make sure 256 has a nonzero count */
  147233. for (;;) {
  147234. c1 = -1;
  147235. v = 1000000000L;
  147236. for (i = 0; i <= 256; i++) {
  147237. if (freq[i] && freq[i] <= v) {
  147238. v = freq[i];
  147239. c1 = i;
  147240. }
  147241. }
  147242. c2 = -1;
  147243. v = 1000000000L;
  147244. for (i = 0; i <= 256; i++) {
  147245. if (freq[i] && freq[i] <= v && i != c1) {
  147246. v = freq[i];
  147247. c2 = i;
  147248. }
  147249. }
  147250. if (c2 < 0)
  147251. break;
  147252. freq[c1] += freq[c2];
  147253. freq[c2] = 0;
  147254. codesize[c1]++;
  147255. while (others[c1] >= 0) {
  147256. c1 = others[c1];
  147257. codesize[c1]++;
  147258. }
  147259. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147260. codesize[c2]++;
  147261. while (others[c2] >= 0) {
  147262. c2 = others[c2];
  147263. codesize[c2]++;
  147264. }
  147265. }
  147266. for (i = 0; i <= 256; i++) {
  147267. if (codesize[i]) {
  147268. if (codesize[i] > MAX_CLEN)
  147269. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147270. bits[codesize[i]]++;
  147271. }
  147272. }
  147273. for (i = MAX_CLEN; i > 16; i--) {
  147274. while (bits[i] > 0) {
  147275. j = i - 2; /* find length of new prefix to be used */
  147276. while (bits[j] == 0)
  147277. j--;
  147278. bits[i] -= 2; /* remove two symbols */
  147279. bits[i-1]++; /* one goes in this length */
  147280. bits[j+1] += 2; /* two new symbols in this length */
  147281. bits[j]--; /* symbol of this length is now a prefix */
  147282. }
  147283. }
  147284. while (bits[i] == 0) /* find largest codelength still in use */
  147285. i--;
  147286. bits[i]--;
  147287. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147288. p = 0;
  147289. for (i = 1; i <= MAX_CLEN; i++) {
  147290. for (j = 0; j <= 255; j++) {
  147291. if (codesize[j] == i) {
  147292. htbl->huffval[p] = (UINT8) j;
  147293. p++;
  147294. }
  147295. }
  147296. }
  147297. htbl->sent_table = FALSE;
  147298. }
  147299. METHODDEF(void)
  147300. finish_pass_gather (j_compress_ptr cinfo)
  147301. {
  147302. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147303. int ci, dctbl, actbl;
  147304. jpeg_component_info * compptr;
  147305. JHUFF_TBL **htblptr;
  147306. boolean did_dc[NUM_HUFF_TBLS];
  147307. boolean did_ac[NUM_HUFF_TBLS];
  147308. MEMZERO(did_dc, SIZEOF(did_dc));
  147309. MEMZERO(did_ac, SIZEOF(did_ac));
  147310. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147311. compptr = cinfo->cur_comp_info[ci];
  147312. dctbl = compptr->dc_tbl_no;
  147313. actbl = compptr->ac_tbl_no;
  147314. if (! did_dc[dctbl]) {
  147315. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147316. if (*htblptr == NULL)
  147317. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147318. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147319. did_dc[dctbl] = TRUE;
  147320. }
  147321. if (! did_ac[actbl]) {
  147322. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147323. if (*htblptr == NULL)
  147324. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147325. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147326. did_ac[actbl] = TRUE;
  147327. }
  147328. }
  147329. }
  147330. #endif /* ENTROPY_OPT_SUPPORTED */
  147331. GLOBAL(void)
  147332. jinit_huff_encoder (j_compress_ptr cinfo)
  147333. {
  147334. huff_entropy_ptr entropy;
  147335. int i;
  147336. entropy = (huff_entropy_ptr)
  147337. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147338. SIZEOF(huff_entropy_encoder));
  147339. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147340. entropy->pub.start_pass = start_pass_huff;
  147341. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147342. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147343. #ifdef ENTROPY_OPT_SUPPORTED
  147344. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147345. #endif
  147346. }
  147347. }
  147348. /*** End of inlined file: jchuff.c ***/
  147349. #undef emit_byte
  147350. /*** Start of inlined file: jcinit.c ***/
  147351. #define JPEG_INTERNALS
  147352. GLOBAL(void)
  147353. jinit_compress_master (j_compress_ptr cinfo)
  147354. {
  147355. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147356. if (! cinfo->raw_data_in) {
  147357. jinit_color_converter(cinfo);
  147358. jinit_downsampler(cinfo);
  147359. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147360. }
  147361. jinit_forward_dct(cinfo);
  147362. if (cinfo->arith_code) {
  147363. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147364. } else {
  147365. if (cinfo->progressive_mode) {
  147366. #ifdef C_PROGRESSIVE_SUPPORTED
  147367. jinit_phuff_encoder(cinfo);
  147368. #else
  147369. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147370. #endif
  147371. } else
  147372. jinit_huff_encoder(cinfo);
  147373. }
  147374. jinit_c_coef_controller(cinfo,
  147375. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147376. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147377. jinit_marker_writer(cinfo);
  147378. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147379. (*cinfo->marker->write_file_header) (cinfo);
  147380. }
  147381. /*** End of inlined file: jcinit.c ***/
  147382. /*** Start of inlined file: jcmainct.c ***/
  147383. #define JPEG_INTERNALS
  147384. #undef FULL_MAIN_BUFFER_SUPPORTED
  147385. typedef struct {
  147386. struct jpeg_c_main_controller pub; /* public fields */
  147387. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147388. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147389. boolean suspended; /* remember if we suspended output */
  147390. J_BUF_MODE pass_mode; /* current operating mode */
  147391. JSAMPARRAY buffer[MAX_COMPONENTS];
  147392. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147393. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147394. #endif
  147395. } my_main_controller;
  147396. typedef my_main_controller * my_main_ptr;
  147397. METHODDEF(void) process_data_simple_main
  147398. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147399. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147400. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147401. METHODDEF(void) process_data_buffer_main
  147402. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147403. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147404. #endif
  147405. METHODDEF(void)
  147406. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147407. {
  147408. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147409. if (cinfo->raw_data_in)
  147410. return;
  147411. main_->cur_iMCU_row = 0; /* initialize counters */
  147412. main_->rowgroup_ctr = 0;
  147413. main_->suspended = FALSE;
  147414. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147415. switch (pass_mode) {
  147416. case JBUF_PASS_THRU:
  147417. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147418. if (main_->whole_image[0] != NULL)
  147419. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147420. #endif
  147421. main_->pub.process_data = process_data_simple_main;
  147422. break;
  147423. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147424. case JBUF_SAVE_SOURCE:
  147425. case JBUF_CRANK_DEST:
  147426. case JBUF_SAVE_AND_PASS:
  147427. if (main_->whole_image[0] == NULL)
  147428. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147429. main_->pub.process_data = process_data_buffer_main;
  147430. break;
  147431. #endif
  147432. default:
  147433. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147434. break;
  147435. }
  147436. }
  147437. METHODDEF(void)
  147438. process_data_simple_main (j_compress_ptr cinfo,
  147439. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147440. JDIMENSION in_rows_avail)
  147441. {
  147442. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147443. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147444. if (main_->rowgroup_ctr < DCTSIZE)
  147445. (*cinfo->prep->pre_process_data) (cinfo,
  147446. input_buf, in_row_ctr, in_rows_avail,
  147447. main_->buffer, &main_->rowgroup_ctr,
  147448. (JDIMENSION) DCTSIZE);
  147449. if (main_->rowgroup_ctr != DCTSIZE)
  147450. return;
  147451. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147452. if (! main_->suspended) {
  147453. (*in_row_ctr)--;
  147454. main_->suspended = TRUE;
  147455. }
  147456. return;
  147457. }
  147458. if (main_->suspended) {
  147459. (*in_row_ctr)++;
  147460. main_->suspended = FALSE;
  147461. }
  147462. main_->rowgroup_ctr = 0;
  147463. main_->cur_iMCU_row++;
  147464. }
  147465. }
  147466. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147467. METHODDEF(void)
  147468. process_data_buffer_main (j_compress_ptr cinfo,
  147469. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147470. JDIMENSION in_rows_avail)
  147471. {
  147472. my_main_ptr main = (my_main_ptr) cinfo->main;
  147473. int ci;
  147474. jpeg_component_info *compptr;
  147475. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147476. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147477. if (main->rowgroup_ctr == 0) {
  147478. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147479. ci++, compptr++) {
  147480. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147481. ((j_common_ptr) cinfo, main->whole_image[ci],
  147482. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147483. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147484. }
  147485. if (! writing) {
  147486. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147487. main->rowgroup_ctr = DCTSIZE;
  147488. }
  147489. }
  147490. if (writing) {
  147491. (*cinfo->prep->pre_process_data) (cinfo,
  147492. input_buf, in_row_ctr, in_rows_avail,
  147493. main->buffer, &main->rowgroup_ctr,
  147494. (JDIMENSION) DCTSIZE);
  147495. if (main->rowgroup_ctr < DCTSIZE)
  147496. return;
  147497. }
  147498. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147499. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147500. if (! main->suspended) {
  147501. (*in_row_ctr)--;
  147502. main->suspended = TRUE;
  147503. }
  147504. return;
  147505. }
  147506. if (main->suspended) {
  147507. (*in_row_ctr)++;
  147508. main->suspended = FALSE;
  147509. }
  147510. }
  147511. main->rowgroup_ctr = 0;
  147512. main->cur_iMCU_row++;
  147513. }
  147514. }
  147515. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147516. GLOBAL(void)
  147517. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147518. {
  147519. my_main_ptr main_;
  147520. int ci;
  147521. jpeg_component_info *compptr;
  147522. main_ = (my_main_ptr)
  147523. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147524. SIZEOF(my_main_controller));
  147525. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147526. main_->pub.start_pass = start_pass_main;
  147527. if (cinfo->raw_data_in)
  147528. return;
  147529. if (need_full_buffer) {
  147530. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147531. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147532. ci++, compptr++) {
  147533. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147534. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147535. compptr->width_in_blocks * DCTSIZE,
  147536. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147537. (long) compptr->v_samp_factor) * DCTSIZE,
  147538. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147539. }
  147540. #else
  147541. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147542. #endif
  147543. } else {
  147544. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147545. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147546. #endif
  147547. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147548. ci++, compptr++) {
  147549. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147550. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147551. compptr->width_in_blocks * DCTSIZE,
  147552. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147553. }
  147554. }
  147555. }
  147556. /*** End of inlined file: jcmainct.c ***/
  147557. /*** Start of inlined file: jcmarker.c ***/
  147558. #define JPEG_INTERNALS
  147559. typedef struct {
  147560. struct jpeg_marker_writer pub; /* public fields */
  147561. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147562. } my_marker_writer;
  147563. typedef my_marker_writer * my_marker_ptr;
  147564. LOCAL(void)
  147565. emit_byte (j_compress_ptr cinfo, int val)
  147566. {
  147567. struct jpeg_destination_mgr * dest = cinfo->dest;
  147568. *(dest->next_output_byte)++ = (JOCTET) val;
  147569. if (--dest->free_in_buffer == 0) {
  147570. if (! (*dest->empty_output_buffer) (cinfo))
  147571. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147572. }
  147573. }
  147574. LOCAL(void)
  147575. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147576. {
  147577. emit_byte(cinfo, 0xFF);
  147578. emit_byte(cinfo, (int) mark);
  147579. }
  147580. LOCAL(void)
  147581. emit_2bytes (j_compress_ptr cinfo, int value)
  147582. {
  147583. emit_byte(cinfo, (value >> 8) & 0xFF);
  147584. emit_byte(cinfo, value & 0xFF);
  147585. }
  147586. LOCAL(int)
  147587. emit_dqt (j_compress_ptr cinfo, int index)
  147588. {
  147589. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147590. int prec;
  147591. int i;
  147592. if (qtbl == NULL)
  147593. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147594. prec = 0;
  147595. for (i = 0; i < DCTSIZE2; i++) {
  147596. if (qtbl->quantval[i] > 255)
  147597. prec = 1;
  147598. }
  147599. if (! qtbl->sent_table) {
  147600. emit_marker(cinfo, M_DQT);
  147601. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147602. emit_byte(cinfo, index + (prec<<4));
  147603. for (i = 0; i < DCTSIZE2; i++) {
  147604. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147605. if (prec)
  147606. emit_byte(cinfo, (int) (qval >> 8));
  147607. emit_byte(cinfo, (int) (qval & 0xFF));
  147608. }
  147609. qtbl->sent_table = TRUE;
  147610. }
  147611. return prec;
  147612. }
  147613. LOCAL(void)
  147614. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147615. {
  147616. JHUFF_TBL * htbl;
  147617. int length, i;
  147618. if (is_ac) {
  147619. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147620. index += 0x10; /* output index has AC bit set */
  147621. } else {
  147622. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147623. }
  147624. if (htbl == NULL)
  147625. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147626. if (! htbl->sent_table) {
  147627. emit_marker(cinfo, M_DHT);
  147628. length = 0;
  147629. for (i = 1; i <= 16; i++)
  147630. length += htbl->bits[i];
  147631. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147632. emit_byte(cinfo, index);
  147633. for (i = 1; i <= 16; i++)
  147634. emit_byte(cinfo, htbl->bits[i]);
  147635. for (i = 0; i < length; i++)
  147636. emit_byte(cinfo, htbl->huffval[i]);
  147637. htbl->sent_table = TRUE;
  147638. }
  147639. }
  147640. LOCAL(void)
  147641. emit_dac (j_compress_ptr cinfo)
  147642. {
  147643. #ifdef C_ARITH_CODING_SUPPORTED
  147644. char dc_in_use[NUM_ARITH_TBLS];
  147645. char ac_in_use[NUM_ARITH_TBLS];
  147646. int length, i;
  147647. jpeg_component_info *compptr;
  147648. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147649. dc_in_use[i] = ac_in_use[i] = 0;
  147650. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147651. compptr = cinfo->cur_comp_info[i];
  147652. dc_in_use[compptr->dc_tbl_no] = 1;
  147653. ac_in_use[compptr->ac_tbl_no] = 1;
  147654. }
  147655. length = 0;
  147656. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147657. length += dc_in_use[i] + ac_in_use[i];
  147658. emit_marker(cinfo, M_DAC);
  147659. emit_2bytes(cinfo, length*2 + 2);
  147660. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147661. if (dc_in_use[i]) {
  147662. emit_byte(cinfo, i);
  147663. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147664. }
  147665. if (ac_in_use[i]) {
  147666. emit_byte(cinfo, i + 0x10);
  147667. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147668. }
  147669. }
  147670. #endif /* C_ARITH_CODING_SUPPORTED */
  147671. }
  147672. LOCAL(void)
  147673. emit_dri (j_compress_ptr cinfo)
  147674. {
  147675. emit_marker(cinfo, M_DRI);
  147676. emit_2bytes(cinfo, 4); /* fixed length */
  147677. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147678. }
  147679. LOCAL(void)
  147680. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147681. {
  147682. int ci;
  147683. jpeg_component_info *compptr;
  147684. emit_marker(cinfo, code);
  147685. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147686. if ((long) cinfo->image_height > 65535L ||
  147687. (long) cinfo->image_width > 65535L)
  147688. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147689. emit_byte(cinfo, cinfo->data_precision);
  147690. emit_2bytes(cinfo, (int) cinfo->image_height);
  147691. emit_2bytes(cinfo, (int) cinfo->image_width);
  147692. emit_byte(cinfo, cinfo->num_components);
  147693. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147694. ci++, compptr++) {
  147695. emit_byte(cinfo, compptr->component_id);
  147696. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147697. emit_byte(cinfo, compptr->quant_tbl_no);
  147698. }
  147699. }
  147700. LOCAL(void)
  147701. emit_sos (j_compress_ptr cinfo)
  147702. {
  147703. int i, td, ta;
  147704. jpeg_component_info *compptr;
  147705. emit_marker(cinfo, M_SOS);
  147706. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147707. emit_byte(cinfo, cinfo->comps_in_scan);
  147708. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147709. compptr = cinfo->cur_comp_info[i];
  147710. emit_byte(cinfo, compptr->component_id);
  147711. td = compptr->dc_tbl_no;
  147712. ta = compptr->ac_tbl_no;
  147713. if (cinfo->progressive_mode) {
  147714. if (cinfo->Ss == 0) {
  147715. ta = 0; /* DC scan */
  147716. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147717. td = 0; /* no DC table either */
  147718. } else {
  147719. td = 0; /* AC scan */
  147720. }
  147721. }
  147722. emit_byte(cinfo, (td << 4) + ta);
  147723. }
  147724. emit_byte(cinfo, cinfo->Ss);
  147725. emit_byte(cinfo, cinfo->Se);
  147726. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147727. }
  147728. LOCAL(void)
  147729. emit_jfif_app0 (j_compress_ptr cinfo)
  147730. {
  147731. emit_marker(cinfo, M_APP0);
  147732. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147733. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147734. emit_byte(cinfo, 0x46);
  147735. emit_byte(cinfo, 0x49);
  147736. emit_byte(cinfo, 0x46);
  147737. emit_byte(cinfo, 0);
  147738. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147739. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147740. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147741. emit_2bytes(cinfo, (int) cinfo->X_density);
  147742. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147743. emit_byte(cinfo, 0); /* No thumbnail image */
  147744. emit_byte(cinfo, 0);
  147745. }
  147746. LOCAL(void)
  147747. emit_adobe_app14 (j_compress_ptr cinfo)
  147748. {
  147749. emit_marker(cinfo, M_APP14);
  147750. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147751. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147752. emit_byte(cinfo, 0x64);
  147753. emit_byte(cinfo, 0x6F);
  147754. emit_byte(cinfo, 0x62);
  147755. emit_byte(cinfo, 0x65);
  147756. emit_2bytes(cinfo, 100); /* Version */
  147757. emit_2bytes(cinfo, 0); /* Flags0 */
  147758. emit_2bytes(cinfo, 0); /* Flags1 */
  147759. switch (cinfo->jpeg_color_space) {
  147760. case JCS_YCbCr:
  147761. emit_byte(cinfo, 1); /* Color transform = 1 */
  147762. break;
  147763. case JCS_YCCK:
  147764. emit_byte(cinfo, 2); /* Color transform = 2 */
  147765. break;
  147766. default:
  147767. emit_byte(cinfo, 0); /* Color transform = 0 */
  147768. break;
  147769. }
  147770. }
  147771. METHODDEF(void)
  147772. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147773. {
  147774. if (datalen > (unsigned int) 65533) /* safety check */
  147775. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147776. emit_marker(cinfo, (JPEG_MARKER) marker);
  147777. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147778. }
  147779. METHODDEF(void)
  147780. write_marker_byte (j_compress_ptr cinfo, int val)
  147781. {
  147782. emit_byte(cinfo, val);
  147783. }
  147784. METHODDEF(void)
  147785. write_file_header (j_compress_ptr cinfo)
  147786. {
  147787. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147788. emit_marker(cinfo, M_SOI); /* first the SOI */
  147789. marker->last_restart_interval = 0;
  147790. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147791. emit_jfif_app0(cinfo);
  147792. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147793. emit_adobe_app14(cinfo);
  147794. }
  147795. METHODDEF(void)
  147796. write_frame_header (j_compress_ptr cinfo)
  147797. {
  147798. int ci, prec;
  147799. boolean is_baseline;
  147800. jpeg_component_info *compptr;
  147801. prec = 0;
  147802. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147803. ci++, compptr++) {
  147804. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147805. }
  147806. if (cinfo->arith_code || cinfo->progressive_mode ||
  147807. cinfo->data_precision != 8) {
  147808. is_baseline = FALSE;
  147809. } else {
  147810. is_baseline = TRUE;
  147811. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147812. ci++, compptr++) {
  147813. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  147814. is_baseline = FALSE;
  147815. }
  147816. if (prec && is_baseline) {
  147817. is_baseline = FALSE;
  147818. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  147819. }
  147820. }
  147821. if (cinfo->arith_code) {
  147822. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  147823. } else {
  147824. if (cinfo->progressive_mode)
  147825. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  147826. else if (is_baseline)
  147827. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  147828. else
  147829. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  147830. }
  147831. }
  147832. METHODDEF(void)
  147833. write_scan_header (j_compress_ptr cinfo)
  147834. {
  147835. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147836. int i;
  147837. jpeg_component_info *compptr;
  147838. if (cinfo->arith_code) {
  147839. emit_dac(cinfo);
  147840. } else {
  147841. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147842. compptr = cinfo->cur_comp_info[i];
  147843. if (cinfo->progressive_mode) {
  147844. if (cinfo->Ss == 0) {
  147845. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  147846. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147847. } else {
  147848. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147849. }
  147850. } else {
  147851. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147852. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147853. }
  147854. }
  147855. }
  147856. if (cinfo->restart_interval != marker->last_restart_interval) {
  147857. emit_dri(cinfo);
  147858. marker->last_restart_interval = cinfo->restart_interval;
  147859. }
  147860. emit_sos(cinfo);
  147861. }
  147862. METHODDEF(void)
  147863. write_file_trailer (j_compress_ptr cinfo)
  147864. {
  147865. emit_marker(cinfo, M_EOI);
  147866. }
  147867. METHODDEF(void)
  147868. write_tables_only (j_compress_ptr cinfo)
  147869. {
  147870. int i;
  147871. emit_marker(cinfo, M_SOI);
  147872. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147873. if (cinfo->quant_tbl_ptrs[i] != NULL)
  147874. (void) emit_dqt(cinfo, i);
  147875. }
  147876. if (! cinfo->arith_code) {
  147877. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147878. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  147879. emit_dht(cinfo, i, FALSE);
  147880. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  147881. emit_dht(cinfo, i, TRUE);
  147882. }
  147883. }
  147884. emit_marker(cinfo, M_EOI);
  147885. }
  147886. GLOBAL(void)
  147887. jinit_marker_writer (j_compress_ptr cinfo)
  147888. {
  147889. my_marker_ptr marker;
  147890. marker = (my_marker_ptr)
  147891. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147892. SIZEOF(my_marker_writer));
  147893. cinfo->marker = (struct jpeg_marker_writer *) marker;
  147894. marker->pub.write_file_header = write_file_header;
  147895. marker->pub.write_frame_header = write_frame_header;
  147896. marker->pub.write_scan_header = write_scan_header;
  147897. marker->pub.write_file_trailer = write_file_trailer;
  147898. marker->pub.write_tables_only = write_tables_only;
  147899. marker->pub.write_marker_header = write_marker_header;
  147900. marker->pub.write_marker_byte = write_marker_byte;
  147901. marker->last_restart_interval = 0;
  147902. }
  147903. /*** End of inlined file: jcmarker.c ***/
  147904. /*** Start of inlined file: jcmaster.c ***/
  147905. #define JPEG_INTERNALS
  147906. typedef enum {
  147907. main_pass, /* input data, also do first output step */
  147908. huff_opt_pass, /* Huffman code optimization pass */
  147909. output_pass /* data output pass */
  147910. } c_pass_type;
  147911. typedef struct {
  147912. struct jpeg_comp_master pub; /* public fields */
  147913. c_pass_type pass_type; /* the type of the current pass */
  147914. int pass_number; /* # of passes completed */
  147915. int total_passes; /* total # of passes needed */
  147916. int scan_number; /* current index in scan_info[] */
  147917. } my_comp_master;
  147918. typedef my_comp_master * my_master_ptr;
  147919. LOCAL(void)
  147920. initial_setup (j_compress_ptr cinfo)
  147921. {
  147922. int ci;
  147923. jpeg_component_info *compptr;
  147924. long samplesperrow;
  147925. JDIMENSION jd_samplesperrow;
  147926. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  147927. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  147928. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  147929. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  147930. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  147931. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  147932. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  147933. jd_samplesperrow = (JDIMENSION) samplesperrow;
  147934. if ((long) jd_samplesperrow != samplesperrow)
  147935. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  147936. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  147937. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  147938. if (cinfo->num_components > MAX_COMPONENTS)
  147939. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  147940. MAX_COMPONENTS);
  147941. cinfo->max_h_samp_factor = 1;
  147942. cinfo->max_v_samp_factor = 1;
  147943. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147944. ci++, compptr++) {
  147945. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  147946. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  147947. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  147948. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  147949. compptr->h_samp_factor);
  147950. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  147951. compptr->v_samp_factor);
  147952. }
  147953. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147954. ci++, compptr++) {
  147955. compptr->component_index = ci;
  147956. compptr->DCT_scaled_size = DCTSIZE;
  147957. compptr->width_in_blocks = (JDIMENSION)
  147958. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  147959. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  147960. compptr->height_in_blocks = (JDIMENSION)
  147961. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  147962. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  147963. compptr->downsampled_width = (JDIMENSION)
  147964. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  147965. (long) cinfo->max_h_samp_factor);
  147966. compptr->downsampled_height = (JDIMENSION)
  147967. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  147968. (long) cinfo->max_v_samp_factor);
  147969. compptr->component_needed = TRUE;
  147970. }
  147971. cinfo->total_iMCU_rows = (JDIMENSION)
  147972. jdiv_round_up((long) cinfo->image_height,
  147973. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  147974. }
  147975. #ifdef C_MULTISCAN_FILES_SUPPORTED
  147976. LOCAL(void)
  147977. validate_script (j_compress_ptr cinfo)
  147978. {
  147979. const jpeg_scan_info * scanptr;
  147980. int scanno, ncomps, ci, coefi, thisi;
  147981. int Ss, Se, Ah, Al;
  147982. boolean component_sent[MAX_COMPONENTS];
  147983. #ifdef C_PROGRESSIVE_SUPPORTED
  147984. int * last_bitpos_ptr;
  147985. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  147986. #endif
  147987. if (cinfo->num_scans <= 0)
  147988. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  147989. scanptr = cinfo->scan_info;
  147990. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  147991. #ifdef C_PROGRESSIVE_SUPPORTED
  147992. cinfo->progressive_mode = TRUE;
  147993. last_bitpos_ptr = & last_bitpos[0][0];
  147994. for (ci = 0; ci < cinfo->num_components; ci++)
  147995. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  147996. *last_bitpos_ptr++ = -1;
  147997. #else
  147998. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147999. #endif
  148000. } else {
  148001. cinfo->progressive_mode = FALSE;
  148002. for (ci = 0; ci < cinfo->num_components; ci++)
  148003. component_sent[ci] = FALSE;
  148004. }
  148005. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148006. ncomps = scanptr->comps_in_scan;
  148007. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148008. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148009. for (ci = 0; ci < ncomps; ci++) {
  148010. thisi = scanptr->component_index[ci];
  148011. if (thisi < 0 || thisi >= cinfo->num_components)
  148012. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148013. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148014. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148015. }
  148016. Ss = scanptr->Ss;
  148017. Se = scanptr->Se;
  148018. Ah = scanptr->Ah;
  148019. Al = scanptr->Al;
  148020. if (cinfo->progressive_mode) {
  148021. #ifdef C_PROGRESSIVE_SUPPORTED
  148022. #if BITS_IN_JSAMPLE == 8
  148023. #define MAX_AH_AL 10
  148024. #else
  148025. #define MAX_AH_AL 13
  148026. #endif
  148027. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148028. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148029. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148030. if (Ss == 0) {
  148031. if (Se != 0) /* DC and AC together not OK */
  148032. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148033. } else {
  148034. if (ncomps != 1) /* AC scans must be for only one component */
  148035. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148036. }
  148037. for (ci = 0; ci < ncomps; ci++) {
  148038. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148039. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148040. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148041. for (coefi = Ss; coefi <= Se; coefi++) {
  148042. if (last_bitpos_ptr[coefi] < 0) {
  148043. if (Ah != 0)
  148044. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148045. } else {
  148046. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148047. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148048. }
  148049. last_bitpos_ptr[coefi] = Al;
  148050. }
  148051. }
  148052. #endif
  148053. } else {
  148054. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148055. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148056. for (ci = 0; ci < ncomps; ci++) {
  148057. thisi = scanptr->component_index[ci];
  148058. if (component_sent[thisi])
  148059. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148060. component_sent[thisi] = TRUE;
  148061. }
  148062. }
  148063. }
  148064. if (cinfo->progressive_mode) {
  148065. #ifdef C_PROGRESSIVE_SUPPORTED
  148066. for (ci = 0; ci < cinfo->num_components; ci++) {
  148067. if (last_bitpos[ci][0] < 0)
  148068. ERREXIT(cinfo, JERR_MISSING_DATA);
  148069. }
  148070. #endif
  148071. } else {
  148072. for (ci = 0; ci < cinfo->num_components; ci++) {
  148073. if (! component_sent[ci])
  148074. ERREXIT(cinfo, JERR_MISSING_DATA);
  148075. }
  148076. }
  148077. }
  148078. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148079. LOCAL(void)
  148080. select_scan_parameters (j_compress_ptr cinfo)
  148081. {
  148082. int ci;
  148083. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148084. if (cinfo->scan_info != NULL) {
  148085. my_master_ptr master = (my_master_ptr) cinfo->master;
  148086. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148087. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148088. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148089. cinfo->cur_comp_info[ci] =
  148090. &cinfo->comp_info[scanptr->component_index[ci]];
  148091. }
  148092. cinfo->Ss = scanptr->Ss;
  148093. cinfo->Se = scanptr->Se;
  148094. cinfo->Ah = scanptr->Ah;
  148095. cinfo->Al = scanptr->Al;
  148096. }
  148097. else
  148098. #endif
  148099. {
  148100. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148101. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148102. MAX_COMPS_IN_SCAN);
  148103. cinfo->comps_in_scan = cinfo->num_components;
  148104. for (ci = 0; ci < cinfo->num_components; ci++) {
  148105. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148106. }
  148107. cinfo->Ss = 0;
  148108. cinfo->Se = DCTSIZE2-1;
  148109. cinfo->Ah = 0;
  148110. cinfo->Al = 0;
  148111. }
  148112. }
  148113. LOCAL(void)
  148114. per_scan_setup (j_compress_ptr cinfo)
  148115. {
  148116. int ci, mcublks, tmp;
  148117. jpeg_component_info *compptr;
  148118. if (cinfo->comps_in_scan == 1) {
  148119. compptr = cinfo->cur_comp_info[0];
  148120. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148121. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148122. compptr->MCU_width = 1;
  148123. compptr->MCU_height = 1;
  148124. compptr->MCU_blocks = 1;
  148125. compptr->MCU_sample_width = DCTSIZE;
  148126. compptr->last_col_width = 1;
  148127. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148128. if (tmp == 0) tmp = compptr->v_samp_factor;
  148129. compptr->last_row_height = tmp;
  148130. cinfo->blocks_in_MCU = 1;
  148131. cinfo->MCU_membership[0] = 0;
  148132. } else {
  148133. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148134. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148135. MAX_COMPS_IN_SCAN);
  148136. cinfo->MCUs_per_row = (JDIMENSION)
  148137. jdiv_round_up((long) cinfo->image_width,
  148138. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148139. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148140. jdiv_round_up((long) cinfo->image_height,
  148141. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148142. cinfo->blocks_in_MCU = 0;
  148143. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148144. compptr = cinfo->cur_comp_info[ci];
  148145. compptr->MCU_width = compptr->h_samp_factor;
  148146. compptr->MCU_height = compptr->v_samp_factor;
  148147. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148148. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148149. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148150. if (tmp == 0) tmp = compptr->MCU_width;
  148151. compptr->last_col_width = tmp;
  148152. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148153. if (tmp == 0) tmp = compptr->MCU_height;
  148154. compptr->last_row_height = tmp;
  148155. mcublks = compptr->MCU_blocks;
  148156. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148157. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148158. while (mcublks-- > 0) {
  148159. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148160. }
  148161. }
  148162. }
  148163. if (cinfo->restart_in_rows > 0) {
  148164. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148165. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148166. }
  148167. }
  148168. METHODDEF(void)
  148169. prepare_for_pass (j_compress_ptr cinfo)
  148170. {
  148171. my_master_ptr master = (my_master_ptr) cinfo->master;
  148172. switch (master->pass_type) {
  148173. case main_pass:
  148174. select_scan_parameters(cinfo);
  148175. per_scan_setup(cinfo);
  148176. if (! cinfo->raw_data_in) {
  148177. (*cinfo->cconvert->start_pass) (cinfo);
  148178. (*cinfo->downsample->start_pass) (cinfo);
  148179. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148180. }
  148181. (*cinfo->fdct->start_pass) (cinfo);
  148182. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148183. (*cinfo->coef->start_pass) (cinfo,
  148184. (master->total_passes > 1 ?
  148185. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148186. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148187. if (cinfo->optimize_coding) {
  148188. master->pub.call_pass_startup = FALSE;
  148189. } else {
  148190. master->pub.call_pass_startup = TRUE;
  148191. }
  148192. break;
  148193. #ifdef ENTROPY_OPT_SUPPORTED
  148194. case huff_opt_pass:
  148195. select_scan_parameters(cinfo);
  148196. per_scan_setup(cinfo);
  148197. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148198. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148199. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148200. master->pub.call_pass_startup = FALSE;
  148201. break;
  148202. }
  148203. master->pass_type = output_pass;
  148204. master->pass_number++;
  148205. #endif
  148206. case output_pass:
  148207. if (! cinfo->optimize_coding) {
  148208. select_scan_parameters(cinfo);
  148209. per_scan_setup(cinfo);
  148210. }
  148211. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148212. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148213. if (master->scan_number == 0)
  148214. (*cinfo->marker->write_frame_header) (cinfo);
  148215. (*cinfo->marker->write_scan_header) (cinfo);
  148216. master->pub.call_pass_startup = FALSE;
  148217. break;
  148218. default:
  148219. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148220. }
  148221. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148222. if (cinfo->progress != NULL) {
  148223. cinfo->progress->completed_passes = master->pass_number;
  148224. cinfo->progress->total_passes = master->total_passes;
  148225. }
  148226. }
  148227. METHODDEF(void)
  148228. pass_startup (j_compress_ptr cinfo)
  148229. {
  148230. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148231. (*cinfo->marker->write_frame_header) (cinfo);
  148232. (*cinfo->marker->write_scan_header) (cinfo);
  148233. }
  148234. METHODDEF(void)
  148235. finish_pass_master (j_compress_ptr cinfo)
  148236. {
  148237. my_master_ptr master = (my_master_ptr) cinfo->master;
  148238. (*cinfo->entropy->finish_pass) (cinfo);
  148239. switch (master->pass_type) {
  148240. case main_pass:
  148241. master->pass_type = output_pass;
  148242. if (! cinfo->optimize_coding)
  148243. master->scan_number++;
  148244. break;
  148245. case huff_opt_pass:
  148246. master->pass_type = output_pass;
  148247. break;
  148248. case output_pass:
  148249. if (cinfo->optimize_coding)
  148250. master->pass_type = huff_opt_pass;
  148251. master->scan_number++;
  148252. break;
  148253. }
  148254. master->pass_number++;
  148255. }
  148256. GLOBAL(void)
  148257. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148258. {
  148259. my_master_ptr master;
  148260. master = (my_master_ptr)
  148261. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148262. SIZEOF(my_comp_master));
  148263. cinfo->master = (struct jpeg_comp_master *) master;
  148264. master->pub.prepare_for_pass = prepare_for_pass;
  148265. master->pub.pass_startup = pass_startup;
  148266. master->pub.finish_pass = finish_pass_master;
  148267. master->pub.is_last_pass = FALSE;
  148268. initial_setup(cinfo);
  148269. if (cinfo->scan_info != NULL) {
  148270. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148271. validate_script(cinfo);
  148272. #else
  148273. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148274. #endif
  148275. } else {
  148276. cinfo->progressive_mode = FALSE;
  148277. cinfo->num_scans = 1;
  148278. }
  148279. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148280. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148281. if (transcode_only) {
  148282. if (cinfo->optimize_coding)
  148283. master->pass_type = huff_opt_pass;
  148284. else
  148285. master->pass_type = output_pass;
  148286. } else {
  148287. master->pass_type = main_pass;
  148288. }
  148289. master->scan_number = 0;
  148290. master->pass_number = 0;
  148291. if (cinfo->optimize_coding)
  148292. master->total_passes = cinfo->num_scans * 2;
  148293. else
  148294. master->total_passes = cinfo->num_scans;
  148295. }
  148296. /*** End of inlined file: jcmaster.c ***/
  148297. /*** Start of inlined file: jcomapi.c ***/
  148298. #define JPEG_INTERNALS
  148299. GLOBAL(void)
  148300. jpeg_abort (j_common_ptr cinfo)
  148301. {
  148302. int pool;
  148303. if (cinfo->mem == NULL)
  148304. return;
  148305. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148306. (*cinfo->mem->free_pool) (cinfo, pool);
  148307. }
  148308. if (cinfo->is_decompressor) {
  148309. cinfo->global_state = DSTATE_START;
  148310. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148311. } else {
  148312. cinfo->global_state = CSTATE_START;
  148313. }
  148314. }
  148315. GLOBAL(void)
  148316. jpeg_destroy (j_common_ptr cinfo)
  148317. {
  148318. if (cinfo->mem != NULL)
  148319. (*cinfo->mem->self_destruct) (cinfo);
  148320. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148321. cinfo->global_state = 0; /* mark it destroyed */
  148322. }
  148323. GLOBAL(JQUANT_TBL *)
  148324. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148325. {
  148326. JQUANT_TBL *tbl;
  148327. tbl = (JQUANT_TBL *)
  148328. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148329. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148330. return tbl;
  148331. }
  148332. GLOBAL(JHUFF_TBL *)
  148333. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148334. {
  148335. JHUFF_TBL *tbl;
  148336. tbl = (JHUFF_TBL *)
  148337. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148338. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148339. return tbl;
  148340. }
  148341. /*** End of inlined file: jcomapi.c ***/
  148342. /*** Start of inlined file: jcparam.c ***/
  148343. #define JPEG_INTERNALS
  148344. GLOBAL(void)
  148345. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148346. const unsigned int *basic_table,
  148347. int scale_factor, boolean force_baseline)
  148348. {
  148349. JQUANT_TBL ** qtblptr;
  148350. int i;
  148351. long temp;
  148352. if (cinfo->global_state != CSTATE_START)
  148353. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148354. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148355. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148356. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148357. if (*qtblptr == NULL)
  148358. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148359. for (i = 0; i < DCTSIZE2; i++) {
  148360. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148361. if (temp <= 0L) temp = 1L;
  148362. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148363. if (force_baseline && temp > 255L)
  148364. temp = 255L; /* limit to baseline range if requested */
  148365. (*qtblptr)->quantval[i] = (UINT16) temp;
  148366. }
  148367. (*qtblptr)->sent_table = FALSE;
  148368. }
  148369. GLOBAL(void)
  148370. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148371. boolean force_baseline)
  148372. {
  148373. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148374. 16, 11, 10, 16, 24, 40, 51, 61,
  148375. 12, 12, 14, 19, 26, 58, 60, 55,
  148376. 14, 13, 16, 24, 40, 57, 69, 56,
  148377. 14, 17, 22, 29, 51, 87, 80, 62,
  148378. 18, 22, 37, 56, 68, 109, 103, 77,
  148379. 24, 35, 55, 64, 81, 104, 113, 92,
  148380. 49, 64, 78, 87, 103, 121, 120, 101,
  148381. 72, 92, 95, 98, 112, 100, 103, 99
  148382. };
  148383. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148384. 17, 18, 24, 47, 99, 99, 99, 99,
  148385. 18, 21, 26, 66, 99, 99, 99, 99,
  148386. 24, 26, 56, 99, 99, 99, 99, 99,
  148387. 47, 66, 99, 99, 99, 99, 99, 99,
  148388. 99, 99, 99, 99, 99, 99, 99, 99,
  148389. 99, 99, 99, 99, 99, 99, 99, 99,
  148390. 99, 99, 99, 99, 99, 99, 99, 99,
  148391. 99, 99, 99, 99, 99, 99, 99, 99
  148392. };
  148393. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148394. scale_factor, force_baseline);
  148395. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148396. scale_factor, force_baseline);
  148397. }
  148398. GLOBAL(int)
  148399. jpeg_quality_scaling (int quality)
  148400. {
  148401. if (quality <= 0) quality = 1;
  148402. if (quality > 100) quality = 100;
  148403. if (quality < 50)
  148404. quality = 5000 / quality;
  148405. else
  148406. quality = 200 - quality*2;
  148407. return quality;
  148408. }
  148409. GLOBAL(void)
  148410. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148411. {
  148412. quality = jpeg_quality_scaling(quality);
  148413. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148414. }
  148415. LOCAL(void)
  148416. add_huff_table (j_compress_ptr cinfo,
  148417. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148418. {
  148419. int nsymbols, len;
  148420. if (*htblptr == NULL)
  148421. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148422. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148423. nsymbols = 0;
  148424. for (len = 1; len <= 16; len++)
  148425. nsymbols += bits[len];
  148426. if (nsymbols < 1 || nsymbols > 256)
  148427. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148428. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148429. (*htblptr)->sent_table = FALSE;
  148430. }
  148431. LOCAL(void)
  148432. std_huff_tables (j_compress_ptr cinfo)
  148433. {
  148434. static const UINT8 bits_dc_luminance[17] =
  148435. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148436. static const UINT8 val_dc_luminance[] =
  148437. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148438. static const UINT8 bits_dc_chrominance[17] =
  148439. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148440. static const UINT8 val_dc_chrominance[] =
  148441. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148442. static const UINT8 bits_ac_luminance[17] =
  148443. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148444. static const UINT8 val_ac_luminance[] =
  148445. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148446. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148447. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148448. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148449. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148450. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148451. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148452. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148453. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148454. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148455. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148456. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148457. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148458. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148459. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148460. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148461. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148462. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148463. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148464. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148465. 0xf9, 0xfa };
  148466. static const UINT8 bits_ac_chrominance[17] =
  148467. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148468. static const UINT8 val_ac_chrominance[] =
  148469. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148470. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148471. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148472. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148473. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148474. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148475. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148476. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148477. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148478. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148479. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148480. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148481. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148482. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148483. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148484. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148485. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148486. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148487. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148488. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148489. 0xf9, 0xfa };
  148490. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148491. bits_dc_luminance, val_dc_luminance);
  148492. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148493. bits_ac_luminance, val_ac_luminance);
  148494. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148495. bits_dc_chrominance, val_dc_chrominance);
  148496. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148497. bits_ac_chrominance, val_ac_chrominance);
  148498. }
  148499. GLOBAL(void)
  148500. jpeg_set_defaults (j_compress_ptr cinfo)
  148501. {
  148502. int i;
  148503. if (cinfo->global_state != CSTATE_START)
  148504. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148505. if (cinfo->comp_info == NULL)
  148506. cinfo->comp_info = (jpeg_component_info *)
  148507. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148508. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148509. cinfo->data_precision = BITS_IN_JSAMPLE;
  148510. jpeg_set_quality(cinfo, 75, TRUE);
  148511. std_huff_tables(cinfo);
  148512. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148513. cinfo->arith_dc_L[i] = 0;
  148514. cinfo->arith_dc_U[i] = 1;
  148515. cinfo->arith_ac_K[i] = 5;
  148516. }
  148517. cinfo->scan_info = NULL;
  148518. cinfo->num_scans = 0;
  148519. cinfo->raw_data_in = FALSE;
  148520. cinfo->arith_code = FALSE;
  148521. cinfo->optimize_coding = FALSE;
  148522. if (cinfo->data_precision > 8)
  148523. cinfo->optimize_coding = TRUE;
  148524. cinfo->CCIR601_sampling = FALSE;
  148525. cinfo->smoothing_factor = 0;
  148526. cinfo->dct_method = JDCT_DEFAULT;
  148527. cinfo->restart_interval = 0;
  148528. cinfo->restart_in_rows = 0;
  148529. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148530. cinfo->JFIF_minor_version = 1;
  148531. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148532. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148533. cinfo->Y_density = 1;
  148534. jpeg_default_colorspace(cinfo);
  148535. }
  148536. GLOBAL(void)
  148537. jpeg_default_colorspace (j_compress_ptr cinfo)
  148538. {
  148539. switch (cinfo->in_color_space) {
  148540. case JCS_GRAYSCALE:
  148541. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148542. break;
  148543. case JCS_RGB:
  148544. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148545. break;
  148546. case JCS_YCbCr:
  148547. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148548. break;
  148549. case JCS_CMYK:
  148550. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148551. break;
  148552. case JCS_YCCK:
  148553. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148554. break;
  148555. case JCS_UNKNOWN:
  148556. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148557. break;
  148558. default:
  148559. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148560. }
  148561. }
  148562. GLOBAL(void)
  148563. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148564. {
  148565. jpeg_component_info * compptr;
  148566. int ci;
  148567. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148568. (compptr = &cinfo->comp_info[index], \
  148569. compptr->component_id = (id), \
  148570. compptr->h_samp_factor = (hsamp), \
  148571. compptr->v_samp_factor = (vsamp), \
  148572. compptr->quant_tbl_no = (quant), \
  148573. compptr->dc_tbl_no = (dctbl), \
  148574. compptr->ac_tbl_no = (actbl) )
  148575. if (cinfo->global_state != CSTATE_START)
  148576. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148577. cinfo->jpeg_color_space = colorspace;
  148578. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148579. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148580. switch (colorspace) {
  148581. case JCS_GRAYSCALE:
  148582. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148583. cinfo->num_components = 1;
  148584. SET_COMP(0, 1, 1,1, 0, 0,0);
  148585. break;
  148586. case JCS_RGB:
  148587. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148588. cinfo->num_components = 3;
  148589. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148590. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148591. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148592. break;
  148593. case JCS_YCbCr:
  148594. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148595. cinfo->num_components = 3;
  148596. SET_COMP(0, 1, 2,2, 0, 0,0);
  148597. SET_COMP(1, 2, 1,1, 1, 1,1);
  148598. SET_COMP(2, 3, 1,1, 1, 1,1);
  148599. break;
  148600. case JCS_CMYK:
  148601. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148602. cinfo->num_components = 4;
  148603. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148604. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148605. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148606. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148607. break;
  148608. case JCS_YCCK:
  148609. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148610. cinfo->num_components = 4;
  148611. SET_COMP(0, 1, 2,2, 0, 0,0);
  148612. SET_COMP(1, 2, 1,1, 1, 1,1);
  148613. SET_COMP(2, 3, 1,1, 1, 1,1);
  148614. SET_COMP(3, 4, 2,2, 0, 0,0);
  148615. break;
  148616. case JCS_UNKNOWN:
  148617. cinfo->num_components = cinfo->input_components;
  148618. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148619. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148620. MAX_COMPONENTS);
  148621. for (ci = 0; ci < cinfo->num_components; ci++) {
  148622. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148623. }
  148624. break;
  148625. default:
  148626. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148627. }
  148628. }
  148629. #ifdef C_PROGRESSIVE_SUPPORTED
  148630. LOCAL(jpeg_scan_info *)
  148631. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148632. int Ss, int Se, int Ah, int Al)
  148633. {
  148634. scanptr->comps_in_scan = 1;
  148635. scanptr->component_index[0] = ci;
  148636. scanptr->Ss = Ss;
  148637. scanptr->Se = Se;
  148638. scanptr->Ah = Ah;
  148639. scanptr->Al = Al;
  148640. scanptr++;
  148641. return scanptr;
  148642. }
  148643. LOCAL(jpeg_scan_info *)
  148644. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148645. int Ss, int Se, int Ah, int Al)
  148646. {
  148647. int ci;
  148648. for (ci = 0; ci < ncomps; ci++) {
  148649. scanptr->comps_in_scan = 1;
  148650. scanptr->component_index[0] = ci;
  148651. scanptr->Ss = Ss;
  148652. scanptr->Se = Se;
  148653. scanptr->Ah = Ah;
  148654. scanptr->Al = Al;
  148655. scanptr++;
  148656. }
  148657. return scanptr;
  148658. }
  148659. LOCAL(jpeg_scan_info *)
  148660. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148661. {
  148662. int ci;
  148663. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148664. scanptr->comps_in_scan = ncomps;
  148665. for (ci = 0; ci < ncomps; ci++)
  148666. scanptr->component_index[ci] = ci;
  148667. scanptr->Ss = scanptr->Se = 0;
  148668. scanptr->Ah = Ah;
  148669. scanptr->Al = Al;
  148670. scanptr++;
  148671. } else {
  148672. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148673. }
  148674. return scanptr;
  148675. }
  148676. GLOBAL(void)
  148677. jpeg_simple_progression (j_compress_ptr cinfo)
  148678. {
  148679. int ncomps = cinfo->num_components;
  148680. int nscans;
  148681. jpeg_scan_info * scanptr;
  148682. if (cinfo->global_state != CSTATE_START)
  148683. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148684. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148685. nscans = 10;
  148686. } else {
  148687. if (ncomps > MAX_COMPS_IN_SCAN)
  148688. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148689. else
  148690. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148691. }
  148692. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148693. cinfo->script_space_size = MAX(nscans, 10);
  148694. cinfo->script_space = (jpeg_scan_info *)
  148695. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148696. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148697. }
  148698. scanptr = cinfo->script_space;
  148699. cinfo->scan_info = scanptr;
  148700. cinfo->num_scans = nscans;
  148701. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148702. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148703. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148704. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148705. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148706. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148707. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148708. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148709. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148710. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148711. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148712. } else {
  148713. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148714. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148715. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148716. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148717. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148718. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148719. }
  148720. }
  148721. #endif /* C_PROGRESSIVE_SUPPORTED */
  148722. /*** End of inlined file: jcparam.c ***/
  148723. /*** Start of inlined file: jcphuff.c ***/
  148724. #define JPEG_INTERNALS
  148725. #ifdef C_PROGRESSIVE_SUPPORTED
  148726. typedef struct {
  148727. struct jpeg_entropy_encoder pub; /* public fields */
  148728. boolean gather_statistics;
  148729. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148730. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148731. INT32 put_buffer; /* current bit-accumulation buffer */
  148732. int put_bits; /* # of bits now in it */
  148733. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148734. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148735. int ac_tbl_no; /* the table number of the single component */
  148736. unsigned int EOBRUN; /* run length of EOBs */
  148737. unsigned int BE; /* # of buffered correction bits before MCU */
  148738. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148739. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148740. int next_restart_num; /* next restart number to write (0-7) */
  148741. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148742. long * count_ptrs[NUM_HUFF_TBLS];
  148743. } phuff_entropy_encoder;
  148744. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148745. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148746. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148747. #define ISHIFT_TEMPS int ishift_temp;
  148748. #define IRIGHT_SHIFT(x,shft) \
  148749. ((ishift_temp = (x)) < 0 ? \
  148750. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148751. (ishift_temp >> (shft)))
  148752. #else
  148753. #define ISHIFT_TEMPS
  148754. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148755. #endif
  148756. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148757. JBLOCKROW *MCU_data));
  148758. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148759. JBLOCKROW *MCU_data));
  148760. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148761. JBLOCKROW *MCU_data));
  148762. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148763. JBLOCKROW *MCU_data));
  148764. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148765. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148766. METHODDEF(void)
  148767. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148768. {
  148769. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148770. boolean is_DC_band;
  148771. int ci, tbl;
  148772. jpeg_component_info * compptr;
  148773. entropy->cinfo = cinfo;
  148774. entropy->gather_statistics = gather_statistics;
  148775. is_DC_band = (cinfo->Ss == 0);
  148776. if (cinfo->Ah == 0) {
  148777. if (is_DC_band)
  148778. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148779. else
  148780. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148781. } else {
  148782. if (is_DC_band)
  148783. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148784. else {
  148785. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148786. if (entropy->bit_buffer == NULL)
  148787. entropy->bit_buffer = (char *)
  148788. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148789. MAX_CORR_BITS * SIZEOF(char));
  148790. }
  148791. }
  148792. if (gather_statistics)
  148793. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148794. else
  148795. entropy->pub.finish_pass = finish_pass_phuff;
  148796. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148797. compptr = cinfo->cur_comp_info[ci];
  148798. entropy->last_dc_val[ci] = 0;
  148799. if (is_DC_band) {
  148800. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148801. continue;
  148802. tbl = compptr->dc_tbl_no;
  148803. } else {
  148804. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148805. }
  148806. if (gather_statistics) {
  148807. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148808. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148809. if (entropy->count_ptrs[tbl] == NULL)
  148810. entropy->count_ptrs[tbl] = (long *)
  148811. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148812. 257 * SIZEOF(long));
  148813. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  148814. } else {
  148815. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  148816. & entropy->derived_tbls[tbl]);
  148817. }
  148818. }
  148819. entropy->EOBRUN = 0;
  148820. entropy->BE = 0;
  148821. entropy->put_buffer = 0;
  148822. entropy->put_bits = 0;
  148823. entropy->restarts_to_go = cinfo->restart_interval;
  148824. entropy->next_restart_num = 0;
  148825. }
  148826. #define emit_byte(entropy,val) \
  148827. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  148828. if (--(entropy)->free_in_buffer == 0) \
  148829. dump_buffer_p(entropy); }
  148830. LOCAL(void)
  148831. dump_buffer_p (phuff_entropy_ptr entropy)
  148832. {
  148833. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  148834. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  148835. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  148836. entropy->next_output_byte = dest->next_output_byte;
  148837. entropy->free_in_buffer = dest->free_in_buffer;
  148838. }
  148839. INLINE
  148840. LOCAL(void)
  148841. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  148842. {
  148843. register INT32 put_buffer = (INT32) code;
  148844. register int put_bits = entropy->put_bits;
  148845. if (size == 0)
  148846. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148847. if (entropy->gather_statistics)
  148848. return; /* do nothing if we're only getting stats */
  148849. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  148850. put_bits += size; /* new number of bits in buffer */
  148851. put_buffer <<= 24 - put_bits; /* align incoming bits */
  148852. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  148853. while (put_bits >= 8) {
  148854. int c = (int) ((put_buffer >> 16) & 0xFF);
  148855. emit_byte(entropy, c);
  148856. if (c == 0xFF) { /* need to stuff a zero byte? */
  148857. emit_byte(entropy, 0);
  148858. }
  148859. put_buffer <<= 8;
  148860. put_bits -= 8;
  148861. }
  148862. entropy->put_buffer = put_buffer; /* update variables */
  148863. entropy->put_bits = put_bits;
  148864. }
  148865. LOCAL(void)
  148866. flush_bits_p (phuff_entropy_ptr entropy)
  148867. {
  148868. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  148869. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  148870. entropy->put_bits = 0;
  148871. }
  148872. INLINE
  148873. LOCAL(void)
  148874. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  148875. {
  148876. if (entropy->gather_statistics)
  148877. entropy->count_ptrs[tbl_no][symbol]++;
  148878. else {
  148879. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  148880. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  148881. }
  148882. }
  148883. LOCAL(void)
  148884. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  148885. unsigned int nbits)
  148886. {
  148887. if (entropy->gather_statistics)
  148888. return; /* no real work */
  148889. while (nbits > 0) {
  148890. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  148891. bufstart++;
  148892. nbits--;
  148893. }
  148894. }
  148895. LOCAL(void)
  148896. emit_eobrun (phuff_entropy_ptr entropy)
  148897. {
  148898. register int temp, nbits;
  148899. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  148900. temp = entropy->EOBRUN;
  148901. nbits = 0;
  148902. while ((temp >>= 1))
  148903. nbits++;
  148904. if (nbits > 14)
  148905. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148906. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  148907. if (nbits)
  148908. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  148909. entropy->EOBRUN = 0;
  148910. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  148911. entropy->BE = 0;
  148912. }
  148913. }
  148914. LOCAL(void)
  148915. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  148916. {
  148917. int ci;
  148918. emit_eobrun(entropy);
  148919. if (! entropy->gather_statistics) {
  148920. flush_bits_p(entropy);
  148921. emit_byte(entropy, 0xFF);
  148922. emit_byte(entropy, JPEG_RST0 + restart_num);
  148923. }
  148924. if (entropy->cinfo->Ss == 0) {
  148925. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  148926. entropy->last_dc_val[ci] = 0;
  148927. } else {
  148928. entropy->EOBRUN = 0;
  148929. entropy->BE = 0;
  148930. }
  148931. }
  148932. METHODDEF(boolean)
  148933. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148934. {
  148935. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148936. register int temp, temp2;
  148937. register int nbits;
  148938. int blkn, ci;
  148939. int Al = cinfo->Al;
  148940. JBLOCKROW block;
  148941. jpeg_component_info * compptr;
  148942. ISHIFT_TEMPS
  148943. entropy->next_output_byte = cinfo->dest->next_output_byte;
  148944. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  148945. if (cinfo->restart_interval)
  148946. if (entropy->restarts_to_go == 0)
  148947. emit_restart_p(entropy, entropy->next_restart_num);
  148948. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148949. block = MCU_data[blkn];
  148950. ci = cinfo->MCU_membership[blkn];
  148951. compptr = cinfo->cur_comp_info[ci];
  148952. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  148953. temp = temp2 - entropy->last_dc_val[ci];
  148954. entropy->last_dc_val[ci] = temp2;
  148955. temp2 = temp;
  148956. if (temp < 0) {
  148957. temp = -temp; /* temp is abs value of input */
  148958. temp2--;
  148959. }
  148960. nbits = 0;
  148961. while (temp) {
  148962. nbits++;
  148963. temp >>= 1;
  148964. }
  148965. if (nbits > MAX_COEF_BITS+1)
  148966. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  148967. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  148968. if (nbits) /* emit_bits rejects calls with size 0 */
  148969. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  148970. }
  148971. cinfo->dest->next_output_byte = entropy->next_output_byte;
  148972. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  148973. if (cinfo->restart_interval) {
  148974. if (entropy->restarts_to_go == 0) {
  148975. entropy->restarts_to_go = cinfo->restart_interval;
  148976. entropy->next_restart_num++;
  148977. entropy->next_restart_num &= 7;
  148978. }
  148979. entropy->restarts_to_go--;
  148980. }
  148981. return TRUE;
  148982. }
  148983. METHODDEF(boolean)
  148984. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148985. {
  148986. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148987. register int temp, temp2;
  148988. register int nbits;
  148989. register int r, k;
  148990. int Se = cinfo->Se;
  148991. int Al = cinfo->Al;
  148992. JBLOCKROW block;
  148993. entropy->next_output_byte = cinfo->dest->next_output_byte;
  148994. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  148995. if (cinfo->restart_interval)
  148996. if (entropy->restarts_to_go == 0)
  148997. emit_restart_p(entropy, entropy->next_restart_num);
  148998. block = MCU_data[0];
  148999. r = 0; /* r = run length of zeros */
  149000. for (k = cinfo->Ss; k <= Se; k++) {
  149001. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149002. r++;
  149003. continue;
  149004. }
  149005. if (temp < 0) {
  149006. temp = -temp; /* temp is abs value of input */
  149007. temp >>= Al; /* apply the point transform */
  149008. temp2 = ~temp;
  149009. } else {
  149010. temp >>= Al; /* apply the point transform */
  149011. temp2 = temp;
  149012. }
  149013. if (temp == 0) {
  149014. r++;
  149015. continue;
  149016. }
  149017. if (entropy->EOBRUN > 0)
  149018. emit_eobrun(entropy);
  149019. while (r > 15) {
  149020. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149021. r -= 16;
  149022. }
  149023. nbits = 1; /* there must be at least one 1 bit */
  149024. while ((temp >>= 1))
  149025. nbits++;
  149026. if (nbits > MAX_COEF_BITS)
  149027. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149028. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149029. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149030. r = 0; /* reset zero run length */
  149031. }
  149032. if (r > 0) { /* If there are trailing zeroes, */
  149033. entropy->EOBRUN++; /* count an EOB */
  149034. if (entropy->EOBRUN == 0x7FFF)
  149035. emit_eobrun(entropy); /* force it out to avoid overflow */
  149036. }
  149037. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149038. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149039. if (cinfo->restart_interval) {
  149040. if (entropy->restarts_to_go == 0) {
  149041. entropy->restarts_to_go = cinfo->restart_interval;
  149042. entropy->next_restart_num++;
  149043. entropy->next_restart_num &= 7;
  149044. }
  149045. entropy->restarts_to_go--;
  149046. }
  149047. return TRUE;
  149048. }
  149049. METHODDEF(boolean)
  149050. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149051. {
  149052. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149053. register int temp;
  149054. int blkn;
  149055. int Al = cinfo->Al;
  149056. JBLOCKROW block;
  149057. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149058. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149059. if (cinfo->restart_interval)
  149060. if (entropy->restarts_to_go == 0)
  149061. emit_restart_p(entropy, entropy->next_restart_num);
  149062. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149063. block = MCU_data[blkn];
  149064. temp = (*block)[0];
  149065. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149066. }
  149067. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149068. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149069. if (cinfo->restart_interval) {
  149070. if (entropy->restarts_to_go == 0) {
  149071. entropy->restarts_to_go = cinfo->restart_interval;
  149072. entropy->next_restart_num++;
  149073. entropy->next_restart_num &= 7;
  149074. }
  149075. entropy->restarts_to_go--;
  149076. }
  149077. return TRUE;
  149078. }
  149079. METHODDEF(boolean)
  149080. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149081. {
  149082. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149083. register int temp;
  149084. register int r, k;
  149085. int EOB;
  149086. char *BR_buffer;
  149087. unsigned int BR;
  149088. int Se = cinfo->Se;
  149089. int Al = cinfo->Al;
  149090. JBLOCKROW block;
  149091. int absvalues[DCTSIZE2];
  149092. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149093. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149094. if (cinfo->restart_interval)
  149095. if (entropy->restarts_to_go == 0)
  149096. emit_restart_p(entropy, entropy->next_restart_num);
  149097. block = MCU_data[0];
  149098. EOB = 0;
  149099. for (k = cinfo->Ss; k <= Se; k++) {
  149100. temp = (*block)[jpeg_natural_order[k]];
  149101. if (temp < 0)
  149102. temp = -temp; /* temp is abs value of input */
  149103. temp >>= Al; /* apply the point transform */
  149104. absvalues[k] = temp; /* save abs value for main pass */
  149105. if (temp == 1)
  149106. EOB = k; /* EOB = index of last newly-nonzero coef */
  149107. }
  149108. r = 0; /* r = run length of zeros */
  149109. BR = 0; /* BR = count of buffered bits added now */
  149110. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149111. for (k = cinfo->Ss; k <= Se; k++) {
  149112. if ((temp = absvalues[k]) == 0) {
  149113. r++;
  149114. continue;
  149115. }
  149116. while (r > 15 && k <= EOB) {
  149117. emit_eobrun(entropy);
  149118. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149119. r -= 16;
  149120. emit_buffered_bits(entropy, BR_buffer, BR);
  149121. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149122. BR = 0;
  149123. }
  149124. if (temp > 1) {
  149125. BR_buffer[BR++] = (char) (temp & 1);
  149126. continue;
  149127. }
  149128. emit_eobrun(entropy);
  149129. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149130. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149131. emit_bits_p(entropy, (unsigned int) temp, 1);
  149132. emit_buffered_bits(entropy, BR_buffer, BR);
  149133. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149134. BR = 0;
  149135. r = 0; /* reset zero run length */
  149136. }
  149137. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149138. entropy->EOBRUN++; /* count an EOB */
  149139. entropy->BE += BR; /* concat my correction bits to older ones */
  149140. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149141. emit_eobrun(entropy);
  149142. }
  149143. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149144. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149145. if (cinfo->restart_interval) {
  149146. if (entropy->restarts_to_go == 0) {
  149147. entropy->restarts_to_go = cinfo->restart_interval;
  149148. entropy->next_restart_num++;
  149149. entropy->next_restart_num &= 7;
  149150. }
  149151. entropy->restarts_to_go--;
  149152. }
  149153. return TRUE;
  149154. }
  149155. METHODDEF(void)
  149156. finish_pass_phuff (j_compress_ptr cinfo)
  149157. {
  149158. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149159. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149160. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149161. emit_eobrun(entropy);
  149162. flush_bits_p(entropy);
  149163. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149164. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149165. }
  149166. METHODDEF(void)
  149167. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149168. {
  149169. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149170. boolean is_DC_band;
  149171. int ci, tbl;
  149172. jpeg_component_info * compptr;
  149173. JHUFF_TBL **htblptr;
  149174. boolean did[NUM_HUFF_TBLS];
  149175. emit_eobrun(entropy);
  149176. is_DC_band = (cinfo->Ss == 0);
  149177. MEMZERO(did, SIZEOF(did));
  149178. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149179. compptr = cinfo->cur_comp_info[ci];
  149180. if (is_DC_band) {
  149181. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149182. continue;
  149183. tbl = compptr->dc_tbl_no;
  149184. } else {
  149185. tbl = compptr->ac_tbl_no;
  149186. }
  149187. if (! did[tbl]) {
  149188. if (is_DC_band)
  149189. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149190. else
  149191. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149192. if (*htblptr == NULL)
  149193. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149194. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149195. did[tbl] = TRUE;
  149196. }
  149197. }
  149198. }
  149199. GLOBAL(void)
  149200. jinit_phuff_encoder (j_compress_ptr cinfo)
  149201. {
  149202. phuff_entropy_ptr entropy;
  149203. int i;
  149204. entropy = (phuff_entropy_ptr)
  149205. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149206. SIZEOF(phuff_entropy_encoder));
  149207. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149208. entropy->pub.start_pass = start_pass_phuff;
  149209. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149210. entropy->derived_tbls[i] = NULL;
  149211. entropy->count_ptrs[i] = NULL;
  149212. }
  149213. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149214. }
  149215. #endif /* C_PROGRESSIVE_SUPPORTED */
  149216. /*** End of inlined file: jcphuff.c ***/
  149217. /*** Start of inlined file: jcprepct.c ***/
  149218. #define JPEG_INTERNALS
  149219. #ifdef INPUT_SMOOTHING_SUPPORTED
  149220. #define CONTEXT_ROWS_SUPPORTED
  149221. #endif
  149222. typedef struct {
  149223. struct jpeg_c_prep_controller pub; /* public fields */
  149224. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149225. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149226. int next_buf_row; /* index of next row to store in color_buf */
  149227. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149228. int this_row_group; /* starting row index of group to process */
  149229. int next_buf_stop; /* downsample when we reach this index */
  149230. #endif
  149231. } my_prep_controller;
  149232. typedef my_prep_controller * my_prep_ptr;
  149233. METHODDEF(void)
  149234. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149235. {
  149236. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149237. if (pass_mode != JBUF_PASS_THRU)
  149238. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149239. prep->rows_to_go = cinfo->image_height;
  149240. prep->next_buf_row = 0;
  149241. #ifdef CONTEXT_ROWS_SUPPORTED
  149242. prep->this_row_group = 0;
  149243. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149244. #endif
  149245. }
  149246. LOCAL(void)
  149247. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149248. int input_rows, int output_rows)
  149249. {
  149250. register int row;
  149251. for (row = input_rows; row < output_rows; row++) {
  149252. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149253. 1, num_cols);
  149254. }
  149255. }
  149256. METHODDEF(void)
  149257. pre_process_data (j_compress_ptr cinfo,
  149258. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149259. JDIMENSION in_rows_avail,
  149260. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149261. JDIMENSION out_row_groups_avail)
  149262. {
  149263. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149264. int numrows, ci;
  149265. JDIMENSION inrows;
  149266. jpeg_component_info * compptr;
  149267. while (*in_row_ctr < in_rows_avail &&
  149268. *out_row_group_ctr < out_row_groups_avail) {
  149269. inrows = in_rows_avail - *in_row_ctr;
  149270. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149271. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149272. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149273. prep->color_buf,
  149274. (JDIMENSION) prep->next_buf_row,
  149275. numrows);
  149276. *in_row_ctr += numrows;
  149277. prep->next_buf_row += numrows;
  149278. prep->rows_to_go -= numrows;
  149279. if (prep->rows_to_go == 0 &&
  149280. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149281. for (ci = 0; ci < cinfo->num_components; ci++) {
  149282. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149283. prep->next_buf_row, cinfo->max_v_samp_factor);
  149284. }
  149285. prep->next_buf_row = cinfo->max_v_samp_factor;
  149286. }
  149287. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149288. (*cinfo->downsample->downsample) (cinfo,
  149289. prep->color_buf, (JDIMENSION) 0,
  149290. output_buf, *out_row_group_ctr);
  149291. prep->next_buf_row = 0;
  149292. (*out_row_group_ctr)++;
  149293. }
  149294. if (prep->rows_to_go == 0 &&
  149295. *out_row_group_ctr < out_row_groups_avail) {
  149296. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149297. ci++, compptr++) {
  149298. expand_bottom_edge(output_buf[ci],
  149299. compptr->width_in_blocks * DCTSIZE,
  149300. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149301. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149302. }
  149303. *out_row_group_ctr = out_row_groups_avail;
  149304. break; /* can exit outer loop without test */
  149305. }
  149306. }
  149307. }
  149308. #ifdef CONTEXT_ROWS_SUPPORTED
  149309. METHODDEF(void)
  149310. pre_process_context (j_compress_ptr cinfo,
  149311. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149312. JDIMENSION in_rows_avail,
  149313. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149314. JDIMENSION out_row_groups_avail)
  149315. {
  149316. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149317. int numrows, ci;
  149318. int buf_height = cinfo->max_v_samp_factor * 3;
  149319. JDIMENSION inrows;
  149320. while (*out_row_group_ctr < out_row_groups_avail) {
  149321. if (*in_row_ctr < in_rows_avail) {
  149322. inrows = in_rows_avail - *in_row_ctr;
  149323. numrows = prep->next_buf_stop - prep->next_buf_row;
  149324. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149325. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149326. prep->color_buf,
  149327. (JDIMENSION) prep->next_buf_row,
  149328. numrows);
  149329. if (prep->rows_to_go == cinfo->image_height) {
  149330. for (ci = 0; ci < cinfo->num_components; ci++) {
  149331. int row;
  149332. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149333. jcopy_sample_rows(prep->color_buf[ci], 0,
  149334. prep->color_buf[ci], -row,
  149335. 1, cinfo->image_width);
  149336. }
  149337. }
  149338. }
  149339. *in_row_ctr += numrows;
  149340. prep->next_buf_row += numrows;
  149341. prep->rows_to_go -= numrows;
  149342. } else {
  149343. if (prep->rows_to_go != 0)
  149344. break;
  149345. if (prep->next_buf_row < prep->next_buf_stop) {
  149346. for (ci = 0; ci < cinfo->num_components; ci++) {
  149347. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149348. prep->next_buf_row, prep->next_buf_stop);
  149349. }
  149350. prep->next_buf_row = prep->next_buf_stop;
  149351. }
  149352. }
  149353. if (prep->next_buf_row == prep->next_buf_stop) {
  149354. (*cinfo->downsample->downsample) (cinfo,
  149355. prep->color_buf,
  149356. (JDIMENSION) prep->this_row_group,
  149357. output_buf, *out_row_group_ctr);
  149358. (*out_row_group_ctr)++;
  149359. prep->this_row_group += cinfo->max_v_samp_factor;
  149360. if (prep->this_row_group >= buf_height)
  149361. prep->this_row_group = 0;
  149362. if (prep->next_buf_row >= buf_height)
  149363. prep->next_buf_row = 0;
  149364. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149365. }
  149366. }
  149367. }
  149368. LOCAL(void)
  149369. create_context_buffer (j_compress_ptr cinfo)
  149370. {
  149371. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149372. int rgroup_height = cinfo->max_v_samp_factor;
  149373. int ci, i;
  149374. jpeg_component_info * compptr;
  149375. JSAMPARRAY true_buffer, fake_buffer;
  149376. fake_buffer = (JSAMPARRAY)
  149377. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149378. (cinfo->num_components * 5 * rgroup_height) *
  149379. SIZEOF(JSAMPROW));
  149380. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149381. ci++, compptr++) {
  149382. true_buffer = (*cinfo->mem->alloc_sarray)
  149383. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149384. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149385. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149386. (JDIMENSION) (3 * rgroup_height));
  149387. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149388. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149389. for (i = 0; i < rgroup_height; i++) {
  149390. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149391. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149392. }
  149393. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149394. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149395. }
  149396. }
  149397. #endif /* CONTEXT_ROWS_SUPPORTED */
  149398. GLOBAL(void)
  149399. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149400. {
  149401. my_prep_ptr prep;
  149402. int ci;
  149403. jpeg_component_info * compptr;
  149404. if (need_full_buffer) /* safety check */
  149405. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149406. prep = (my_prep_ptr)
  149407. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149408. SIZEOF(my_prep_controller));
  149409. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149410. prep->pub.start_pass = start_pass_prep;
  149411. if (cinfo->downsample->need_context_rows) {
  149412. #ifdef CONTEXT_ROWS_SUPPORTED
  149413. prep->pub.pre_process_data = pre_process_context;
  149414. create_context_buffer(cinfo);
  149415. #else
  149416. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149417. #endif
  149418. } else {
  149419. prep->pub.pre_process_data = pre_process_data;
  149420. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149421. ci++, compptr++) {
  149422. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149423. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149424. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149425. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149426. (JDIMENSION) cinfo->max_v_samp_factor);
  149427. }
  149428. }
  149429. }
  149430. /*** End of inlined file: jcprepct.c ***/
  149431. /*** Start of inlined file: jcsample.c ***/
  149432. #define JPEG_INTERNALS
  149433. typedef JMETHOD(void, downsample1_ptr,
  149434. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149435. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149436. typedef struct {
  149437. struct jpeg_downsampler pub; /* public fields */
  149438. downsample1_ptr methods[MAX_COMPONENTS];
  149439. } my_downsampler;
  149440. typedef my_downsampler * my_downsample_ptr;
  149441. METHODDEF(void)
  149442. start_pass_downsample (j_compress_ptr cinfo)
  149443. {
  149444. }
  149445. LOCAL(void)
  149446. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149447. JDIMENSION input_cols, JDIMENSION output_cols)
  149448. {
  149449. register JSAMPROW ptr;
  149450. register JSAMPLE pixval;
  149451. register int count;
  149452. int row;
  149453. int numcols = (int) (output_cols - input_cols);
  149454. if (numcols > 0) {
  149455. for (row = 0; row < num_rows; row++) {
  149456. ptr = image_data[row] + input_cols;
  149457. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149458. for (count = numcols; count > 0; count--)
  149459. *ptr++ = pixval;
  149460. }
  149461. }
  149462. }
  149463. METHODDEF(void)
  149464. sep_downsample (j_compress_ptr cinfo,
  149465. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149466. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149467. {
  149468. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149469. int ci;
  149470. jpeg_component_info * compptr;
  149471. JSAMPARRAY in_ptr, out_ptr;
  149472. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149473. ci++, compptr++) {
  149474. in_ptr = input_buf[ci] + in_row_index;
  149475. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149476. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149477. }
  149478. }
  149479. METHODDEF(void)
  149480. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149481. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149482. {
  149483. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149484. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149485. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149486. JSAMPROW inptr, outptr;
  149487. INT32 outvalue;
  149488. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149489. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149490. numpix = h_expand * v_expand;
  149491. numpix2 = numpix/2;
  149492. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149493. cinfo->image_width, output_cols * h_expand);
  149494. inrow = 0;
  149495. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149496. outptr = output_data[outrow];
  149497. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149498. outcol++, outcol_h += h_expand) {
  149499. outvalue = 0;
  149500. for (v = 0; v < v_expand; v++) {
  149501. inptr = input_data[inrow+v] + outcol_h;
  149502. for (h = 0; h < h_expand; h++) {
  149503. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149504. }
  149505. }
  149506. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149507. }
  149508. inrow += v_expand;
  149509. }
  149510. }
  149511. METHODDEF(void)
  149512. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149513. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149514. {
  149515. jcopy_sample_rows(input_data, 0, output_data, 0,
  149516. cinfo->max_v_samp_factor, cinfo->image_width);
  149517. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149518. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149519. }
  149520. METHODDEF(void)
  149521. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149522. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149523. {
  149524. int outrow;
  149525. JDIMENSION outcol;
  149526. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149527. register JSAMPROW inptr, outptr;
  149528. register int bias;
  149529. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149530. cinfo->image_width, output_cols * 2);
  149531. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149532. outptr = output_data[outrow];
  149533. inptr = input_data[outrow];
  149534. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149535. for (outcol = 0; outcol < output_cols; outcol++) {
  149536. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149537. + bias) >> 1);
  149538. bias ^= 1; /* 0=>1, 1=>0 */
  149539. inptr += 2;
  149540. }
  149541. }
  149542. }
  149543. METHODDEF(void)
  149544. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149545. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149546. {
  149547. int inrow, outrow;
  149548. JDIMENSION outcol;
  149549. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149550. register JSAMPROW inptr0, inptr1, outptr;
  149551. register int bias;
  149552. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149553. cinfo->image_width, output_cols * 2);
  149554. inrow = 0;
  149555. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149556. outptr = output_data[outrow];
  149557. inptr0 = input_data[inrow];
  149558. inptr1 = input_data[inrow+1];
  149559. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149560. for (outcol = 0; outcol < output_cols; outcol++) {
  149561. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149562. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149563. + bias) >> 2);
  149564. bias ^= 3; /* 1=>2, 2=>1 */
  149565. inptr0 += 2; inptr1 += 2;
  149566. }
  149567. inrow += 2;
  149568. }
  149569. }
  149570. #ifdef INPUT_SMOOTHING_SUPPORTED
  149571. METHODDEF(void)
  149572. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149573. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149574. {
  149575. int inrow, outrow;
  149576. JDIMENSION colctr;
  149577. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149578. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149579. INT32 membersum, neighsum, memberscale, neighscale;
  149580. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149581. cinfo->image_width, output_cols * 2);
  149582. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149583. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149584. inrow = 0;
  149585. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149586. outptr = output_data[outrow];
  149587. inptr0 = input_data[inrow];
  149588. inptr1 = input_data[inrow+1];
  149589. above_ptr = input_data[inrow-1];
  149590. below_ptr = input_data[inrow+2];
  149591. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149592. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149593. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149594. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149595. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149596. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149597. neighsum += neighsum;
  149598. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149599. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149600. membersum = membersum * memberscale + neighsum * neighscale;
  149601. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149602. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149603. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149604. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149605. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149606. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149607. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149608. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149609. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149610. neighsum += neighsum;
  149611. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149612. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149613. membersum = membersum * memberscale + neighsum * neighscale;
  149614. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149615. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149616. }
  149617. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149618. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149619. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149620. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149621. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149622. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149623. neighsum += neighsum;
  149624. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149625. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149626. membersum = membersum * memberscale + neighsum * neighscale;
  149627. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149628. inrow += 2;
  149629. }
  149630. }
  149631. METHODDEF(void)
  149632. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149633. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149634. {
  149635. int outrow;
  149636. JDIMENSION colctr;
  149637. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149638. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149639. INT32 membersum, neighsum, memberscale, neighscale;
  149640. int colsum, lastcolsum, nextcolsum;
  149641. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149642. cinfo->image_width, output_cols);
  149643. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149644. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149645. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149646. outptr = output_data[outrow];
  149647. inptr = input_data[outrow];
  149648. above_ptr = input_data[outrow-1];
  149649. below_ptr = input_data[outrow+1];
  149650. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149651. GETJSAMPLE(*inptr);
  149652. membersum = GETJSAMPLE(*inptr++);
  149653. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149654. GETJSAMPLE(*inptr);
  149655. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149656. membersum = membersum * memberscale + neighsum * neighscale;
  149657. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149658. lastcolsum = colsum; colsum = nextcolsum;
  149659. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149660. membersum = GETJSAMPLE(*inptr++);
  149661. above_ptr++; below_ptr++;
  149662. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149663. GETJSAMPLE(*inptr);
  149664. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149665. membersum = membersum * memberscale + neighsum * neighscale;
  149666. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149667. lastcolsum = colsum; colsum = nextcolsum;
  149668. }
  149669. membersum = GETJSAMPLE(*inptr);
  149670. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149671. membersum = membersum * memberscale + neighsum * neighscale;
  149672. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149673. }
  149674. }
  149675. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149676. GLOBAL(void)
  149677. jinit_downsampler (j_compress_ptr cinfo)
  149678. {
  149679. my_downsample_ptr downsample;
  149680. int ci;
  149681. jpeg_component_info * compptr;
  149682. boolean smoothok = TRUE;
  149683. downsample = (my_downsample_ptr)
  149684. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149685. SIZEOF(my_downsampler));
  149686. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149687. downsample->pub.start_pass = start_pass_downsample;
  149688. downsample->pub.downsample = sep_downsample;
  149689. downsample->pub.need_context_rows = FALSE;
  149690. if (cinfo->CCIR601_sampling)
  149691. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149692. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149693. ci++, compptr++) {
  149694. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149695. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149696. #ifdef INPUT_SMOOTHING_SUPPORTED
  149697. if (cinfo->smoothing_factor) {
  149698. downsample->methods[ci] = fullsize_smooth_downsample;
  149699. downsample->pub.need_context_rows = TRUE;
  149700. } else
  149701. #endif
  149702. downsample->methods[ci] = fullsize_downsample;
  149703. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149704. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149705. smoothok = FALSE;
  149706. downsample->methods[ci] = h2v1_downsample;
  149707. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149708. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149709. #ifdef INPUT_SMOOTHING_SUPPORTED
  149710. if (cinfo->smoothing_factor) {
  149711. downsample->methods[ci] = h2v2_smooth_downsample;
  149712. downsample->pub.need_context_rows = TRUE;
  149713. } else
  149714. #endif
  149715. downsample->methods[ci] = h2v2_downsample;
  149716. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149717. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149718. smoothok = FALSE;
  149719. downsample->methods[ci] = int_downsample;
  149720. } else
  149721. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149722. }
  149723. #ifdef INPUT_SMOOTHING_SUPPORTED
  149724. if (cinfo->smoothing_factor && !smoothok)
  149725. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149726. #endif
  149727. }
  149728. /*** End of inlined file: jcsample.c ***/
  149729. /*** Start of inlined file: jctrans.c ***/
  149730. #define JPEG_INTERNALS
  149731. LOCAL(void) transencode_master_selection
  149732. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149733. LOCAL(void) transencode_coef_controller
  149734. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149735. GLOBAL(void)
  149736. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149737. {
  149738. if (cinfo->global_state != CSTATE_START)
  149739. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149740. jpeg_suppress_tables(cinfo, FALSE);
  149741. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149742. (*cinfo->dest->init_destination) (cinfo);
  149743. transencode_master_selection(cinfo, coef_arrays);
  149744. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149745. cinfo->global_state = CSTATE_WRCOEFS;
  149746. }
  149747. GLOBAL(void)
  149748. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149749. j_compress_ptr dstinfo)
  149750. {
  149751. JQUANT_TBL ** qtblptr;
  149752. jpeg_component_info *incomp, *outcomp;
  149753. JQUANT_TBL *c_quant, *slot_quant;
  149754. int tblno, ci, coefi;
  149755. if (dstinfo->global_state != CSTATE_START)
  149756. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149757. dstinfo->image_width = srcinfo->image_width;
  149758. dstinfo->image_height = srcinfo->image_height;
  149759. dstinfo->input_components = srcinfo->num_components;
  149760. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149761. jpeg_set_defaults(dstinfo);
  149762. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149763. dstinfo->data_precision = srcinfo->data_precision;
  149764. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149765. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149766. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149767. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149768. if (*qtblptr == NULL)
  149769. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149770. MEMCOPY((*qtblptr)->quantval,
  149771. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149772. SIZEOF((*qtblptr)->quantval));
  149773. (*qtblptr)->sent_table = FALSE;
  149774. }
  149775. }
  149776. dstinfo->num_components = srcinfo->num_components;
  149777. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149778. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149779. MAX_COMPONENTS);
  149780. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149781. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149782. outcomp->component_id = incomp->component_id;
  149783. outcomp->h_samp_factor = incomp->h_samp_factor;
  149784. outcomp->v_samp_factor = incomp->v_samp_factor;
  149785. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149786. tblno = outcomp->quant_tbl_no;
  149787. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149788. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149789. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149790. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149791. c_quant = incomp->quant_table;
  149792. if (c_quant != NULL) {
  149793. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149794. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149795. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149796. }
  149797. }
  149798. }
  149799. if (srcinfo->saw_JFIF_marker) {
  149800. if (srcinfo->JFIF_major_version == 1) {
  149801. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149802. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149803. }
  149804. dstinfo->density_unit = srcinfo->density_unit;
  149805. dstinfo->X_density = srcinfo->X_density;
  149806. dstinfo->Y_density = srcinfo->Y_density;
  149807. }
  149808. }
  149809. LOCAL(void)
  149810. transencode_master_selection (j_compress_ptr cinfo,
  149811. jvirt_barray_ptr * coef_arrays)
  149812. {
  149813. cinfo->input_components = 1;
  149814. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  149815. if (cinfo->arith_code) {
  149816. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  149817. } else {
  149818. if (cinfo->progressive_mode) {
  149819. #ifdef C_PROGRESSIVE_SUPPORTED
  149820. jinit_phuff_encoder(cinfo);
  149821. #else
  149822. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149823. #endif
  149824. } else
  149825. jinit_huff_encoder(cinfo);
  149826. }
  149827. transencode_coef_controller(cinfo, coef_arrays);
  149828. jinit_marker_writer(cinfo);
  149829. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  149830. (*cinfo->marker->write_file_header) (cinfo);
  149831. }
  149832. typedef struct {
  149833. struct jpeg_c_coef_controller pub; /* public fields */
  149834. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  149835. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  149836. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  149837. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  149838. jvirt_barray_ptr * whole_image;
  149839. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  149840. } my_coef_controller2;
  149841. typedef my_coef_controller2 * my_coef_ptr2;
  149842. LOCAL(void)
  149843. start_iMCU_row2 (j_compress_ptr cinfo)
  149844. {
  149845. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149846. if (cinfo->comps_in_scan > 1) {
  149847. coef->MCU_rows_per_iMCU_row = 1;
  149848. } else {
  149849. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  149850. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  149851. else
  149852. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  149853. }
  149854. coef->mcu_ctr = 0;
  149855. coef->MCU_vert_offset = 0;
  149856. }
  149857. METHODDEF(void)
  149858. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149859. {
  149860. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149861. if (pass_mode != JBUF_CRANK_DEST)
  149862. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149863. coef->iMCU_row_num = 0;
  149864. start_iMCU_row2(cinfo);
  149865. }
  149866. METHODDEF(boolean)
  149867. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  149868. {
  149869. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149870. JDIMENSION MCU_col_num; /* index of current MCU within row */
  149871. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  149872. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  149873. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  149874. JDIMENSION start_col;
  149875. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  149876. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  149877. JBLOCKROW buffer_ptr;
  149878. jpeg_component_info *compptr;
  149879. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149880. compptr = cinfo->cur_comp_info[ci];
  149881. buffer[ci] = (*cinfo->mem->access_virt_barray)
  149882. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  149883. coef->iMCU_row_num * compptr->v_samp_factor,
  149884. (JDIMENSION) compptr->v_samp_factor, FALSE);
  149885. }
  149886. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  149887. yoffset++) {
  149888. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  149889. MCU_col_num++) {
  149890. blkn = 0; /* index of current DCT block within MCU */
  149891. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149892. compptr = cinfo->cur_comp_info[ci];
  149893. start_col = MCU_col_num * compptr->MCU_width;
  149894. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  149895. : compptr->last_col_width;
  149896. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  149897. if (coef->iMCU_row_num < last_iMCU_row ||
  149898. yindex+yoffset < compptr->last_row_height) {
  149899. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  149900. for (xindex = 0; xindex < blockcnt; xindex++)
  149901. MCU_buffer[blkn++] = buffer_ptr++;
  149902. } else {
  149903. xindex = 0;
  149904. }
  149905. for (; xindex < compptr->MCU_width; xindex++) {
  149906. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  149907. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  149908. blkn++;
  149909. }
  149910. }
  149911. }
  149912. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  149913. coef->MCU_vert_offset = yoffset;
  149914. coef->mcu_ctr = MCU_col_num;
  149915. return FALSE;
  149916. }
  149917. }
  149918. coef->mcu_ctr = 0;
  149919. }
  149920. coef->iMCU_row_num++;
  149921. start_iMCU_row2(cinfo);
  149922. return TRUE;
  149923. }
  149924. LOCAL(void)
  149925. transencode_coef_controller (j_compress_ptr cinfo,
  149926. jvirt_barray_ptr * coef_arrays)
  149927. {
  149928. my_coef_ptr2 coef;
  149929. JBLOCKROW buffer;
  149930. int i;
  149931. coef = (my_coef_ptr2)
  149932. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149933. SIZEOF(my_coef_controller2));
  149934. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  149935. coef->pub.start_pass = start_pass_coef2;
  149936. coef->pub.compress_data = compress_output2;
  149937. coef->whole_image = coef_arrays;
  149938. buffer = (JBLOCKROW)
  149939. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149940. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  149941. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  149942. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  149943. coef->dummy_buffer[i] = buffer + i;
  149944. }
  149945. }
  149946. /*** End of inlined file: jctrans.c ***/
  149947. /*** Start of inlined file: jdapistd.c ***/
  149948. #define JPEG_INTERNALS
  149949. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  149950. GLOBAL(boolean)
  149951. jpeg_start_decompress (j_decompress_ptr cinfo)
  149952. {
  149953. if (cinfo->global_state == DSTATE_READY) {
  149954. jinit_master_decompress(cinfo);
  149955. if (cinfo->buffered_image) {
  149956. cinfo->global_state = DSTATE_BUFIMAGE;
  149957. return TRUE;
  149958. }
  149959. cinfo->global_state = DSTATE_PRELOAD;
  149960. }
  149961. if (cinfo->global_state == DSTATE_PRELOAD) {
  149962. if (cinfo->inputctl->has_multiple_scans) {
  149963. #ifdef D_MULTISCAN_FILES_SUPPORTED
  149964. for (;;) {
  149965. int retcode;
  149966. if (cinfo->progress != NULL)
  149967. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  149968. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  149969. if (retcode == JPEG_SUSPENDED)
  149970. return FALSE;
  149971. if (retcode == JPEG_REACHED_EOI)
  149972. break;
  149973. if (cinfo->progress != NULL &&
  149974. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  149975. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  149976. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  149977. }
  149978. }
  149979. }
  149980. #else
  149981. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149982. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  149983. }
  149984. cinfo->output_scan_number = cinfo->input_scan_number;
  149985. } else if (cinfo->global_state != DSTATE_PRESCAN)
  149986. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149987. return output_pass_setup(cinfo);
  149988. }
  149989. LOCAL(boolean)
  149990. output_pass_setup (j_decompress_ptr cinfo)
  149991. {
  149992. if (cinfo->global_state != DSTATE_PRESCAN) {
  149993. (*cinfo->master->prepare_for_output_pass) (cinfo);
  149994. cinfo->output_scanline = 0;
  149995. cinfo->global_state = DSTATE_PRESCAN;
  149996. }
  149997. while (cinfo->master->is_dummy_pass) {
  149998. #ifdef QUANT_2PASS_SUPPORTED
  149999. while (cinfo->output_scanline < cinfo->output_height) {
  150000. JDIMENSION last_scanline;
  150001. if (cinfo->progress != NULL) {
  150002. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150003. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150004. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150005. }
  150006. last_scanline = cinfo->output_scanline;
  150007. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150008. &cinfo->output_scanline, (JDIMENSION) 0);
  150009. if (cinfo->output_scanline == last_scanline)
  150010. return FALSE; /* No progress made, must suspend */
  150011. }
  150012. (*cinfo->master->finish_output_pass) (cinfo);
  150013. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150014. cinfo->output_scanline = 0;
  150015. #else
  150016. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150017. #endif /* QUANT_2PASS_SUPPORTED */
  150018. }
  150019. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150020. return TRUE;
  150021. }
  150022. GLOBAL(JDIMENSION)
  150023. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150024. JDIMENSION max_lines)
  150025. {
  150026. JDIMENSION row_ctr;
  150027. if (cinfo->global_state != DSTATE_SCANNING)
  150028. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150029. if (cinfo->output_scanline >= cinfo->output_height) {
  150030. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150031. return 0;
  150032. }
  150033. if (cinfo->progress != NULL) {
  150034. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150035. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150036. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150037. }
  150038. row_ctr = 0;
  150039. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150040. cinfo->output_scanline += row_ctr;
  150041. return row_ctr;
  150042. }
  150043. GLOBAL(JDIMENSION)
  150044. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150045. JDIMENSION max_lines)
  150046. {
  150047. JDIMENSION lines_per_iMCU_row;
  150048. if (cinfo->global_state != DSTATE_RAW_OK)
  150049. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150050. if (cinfo->output_scanline >= cinfo->output_height) {
  150051. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150052. return 0;
  150053. }
  150054. if (cinfo->progress != NULL) {
  150055. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150056. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150057. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150058. }
  150059. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150060. if (max_lines < lines_per_iMCU_row)
  150061. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150062. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150063. return 0; /* suspension forced, can do nothing more */
  150064. cinfo->output_scanline += lines_per_iMCU_row;
  150065. return lines_per_iMCU_row;
  150066. }
  150067. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150068. GLOBAL(boolean)
  150069. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150070. {
  150071. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150072. cinfo->global_state != DSTATE_PRESCAN)
  150073. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150074. if (scan_number <= 0)
  150075. scan_number = 1;
  150076. if (cinfo->inputctl->eoi_reached &&
  150077. scan_number > cinfo->input_scan_number)
  150078. scan_number = cinfo->input_scan_number;
  150079. cinfo->output_scan_number = scan_number;
  150080. return output_pass_setup(cinfo);
  150081. }
  150082. GLOBAL(boolean)
  150083. jpeg_finish_output (j_decompress_ptr cinfo)
  150084. {
  150085. if ((cinfo->global_state == DSTATE_SCANNING ||
  150086. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150087. (*cinfo->master->finish_output_pass) (cinfo);
  150088. cinfo->global_state = DSTATE_BUFPOST;
  150089. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150090. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150091. }
  150092. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150093. ! cinfo->inputctl->eoi_reached) {
  150094. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150095. return FALSE; /* Suspend, come back later */
  150096. }
  150097. cinfo->global_state = DSTATE_BUFIMAGE;
  150098. return TRUE;
  150099. }
  150100. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150101. /*** End of inlined file: jdapistd.c ***/
  150102. /*** Start of inlined file: jdapimin.c ***/
  150103. #define JPEG_INTERNALS
  150104. GLOBAL(void)
  150105. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150106. {
  150107. int i;
  150108. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150109. if (version != JPEG_LIB_VERSION)
  150110. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150111. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150112. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150113. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150114. {
  150115. struct jpeg_error_mgr * err = cinfo->err;
  150116. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150117. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150118. cinfo->err = err;
  150119. cinfo->client_data = client_data;
  150120. }
  150121. cinfo->is_decompressor = TRUE;
  150122. jinit_memory_mgr((j_common_ptr) cinfo);
  150123. cinfo->progress = NULL;
  150124. cinfo->src = NULL;
  150125. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150126. cinfo->quant_tbl_ptrs[i] = NULL;
  150127. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150128. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150129. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150130. }
  150131. cinfo->marker_list = NULL;
  150132. jinit_marker_reader(cinfo);
  150133. jinit_input_controller(cinfo);
  150134. cinfo->global_state = DSTATE_START;
  150135. }
  150136. GLOBAL(void)
  150137. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150138. {
  150139. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150140. }
  150141. GLOBAL(void)
  150142. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150143. {
  150144. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150145. }
  150146. LOCAL(void)
  150147. default_decompress_parms (j_decompress_ptr cinfo)
  150148. {
  150149. switch (cinfo->num_components) {
  150150. case 1:
  150151. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150152. cinfo->out_color_space = JCS_GRAYSCALE;
  150153. break;
  150154. case 3:
  150155. if (cinfo->saw_JFIF_marker) {
  150156. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150157. } else if (cinfo->saw_Adobe_marker) {
  150158. switch (cinfo->Adobe_transform) {
  150159. case 0:
  150160. cinfo->jpeg_color_space = JCS_RGB;
  150161. break;
  150162. case 1:
  150163. cinfo->jpeg_color_space = JCS_YCbCr;
  150164. break;
  150165. default:
  150166. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150167. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150168. break;
  150169. }
  150170. } else {
  150171. int cid0 = cinfo->comp_info[0].component_id;
  150172. int cid1 = cinfo->comp_info[1].component_id;
  150173. int cid2 = cinfo->comp_info[2].component_id;
  150174. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150175. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150176. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150177. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150178. else {
  150179. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150180. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150181. }
  150182. }
  150183. cinfo->out_color_space = JCS_RGB;
  150184. break;
  150185. case 4:
  150186. if (cinfo->saw_Adobe_marker) {
  150187. switch (cinfo->Adobe_transform) {
  150188. case 0:
  150189. cinfo->jpeg_color_space = JCS_CMYK;
  150190. break;
  150191. case 2:
  150192. cinfo->jpeg_color_space = JCS_YCCK;
  150193. break;
  150194. default:
  150195. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150196. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150197. break;
  150198. }
  150199. } else {
  150200. cinfo->jpeg_color_space = JCS_CMYK;
  150201. }
  150202. cinfo->out_color_space = JCS_CMYK;
  150203. break;
  150204. default:
  150205. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150206. cinfo->out_color_space = JCS_UNKNOWN;
  150207. break;
  150208. }
  150209. cinfo->scale_num = 1; /* 1:1 scaling */
  150210. cinfo->scale_denom = 1;
  150211. cinfo->output_gamma = 1.0;
  150212. cinfo->buffered_image = FALSE;
  150213. cinfo->raw_data_out = FALSE;
  150214. cinfo->dct_method = JDCT_DEFAULT;
  150215. cinfo->do_fancy_upsampling = TRUE;
  150216. cinfo->do_block_smoothing = TRUE;
  150217. cinfo->quantize_colors = FALSE;
  150218. cinfo->dither_mode = JDITHER_FS;
  150219. #ifdef QUANT_2PASS_SUPPORTED
  150220. cinfo->two_pass_quantize = TRUE;
  150221. #else
  150222. cinfo->two_pass_quantize = FALSE;
  150223. #endif
  150224. cinfo->desired_number_of_colors = 256;
  150225. cinfo->colormap = NULL;
  150226. cinfo->enable_1pass_quant = FALSE;
  150227. cinfo->enable_external_quant = FALSE;
  150228. cinfo->enable_2pass_quant = FALSE;
  150229. }
  150230. GLOBAL(int)
  150231. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150232. {
  150233. int retcode;
  150234. if (cinfo->global_state != DSTATE_START &&
  150235. cinfo->global_state != DSTATE_INHEADER)
  150236. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150237. retcode = jpeg_consume_input(cinfo);
  150238. switch (retcode) {
  150239. case JPEG_REACHED_SOS:
  150240. retcode = JPEG_HEADER_OK;
  150241. break;
  150242. case JPEG_REACHED_EOI:
  150243. if (require_image) /* Complain if application wanted an image */
  150244. ERREXIT(cinfo, JERR_NO_IMAGE);
  150245. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150246. retcode = JPEG_HEADER_TABLES_ONLY;
  150247. break;
  150248. case JPEG_SUSPENDED:
  150249. break;
  150250. }
  150251. return retcode;
  150252. }
  150253. GLOBAL(int)
  150254. jpeg_consume_input (j_decompress_ptr cinfo)
  150255. {
  150256. int retcode = JPEG_SUSPENDED;
  150257. switch (cinfo->global_state) {
  150258. case DSTATE_START:
  150259. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150260. (*cinfo->src->init_source) (cinfo);
  150261. cinfo->global_state = DSTATE_INHEADER;
  150262. case DSTATE_INHEADER:
  150263. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150264. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150265. default_decompress_parms(cinfo);
  150266. cinfo->global_state = DSTATE_READY;
  150267. }
  150268. break;
  150269. case DSTATE_READY:
  150270. retcode = JPEG_REACHED_SOS;
  150271. break;
  150272. case DSTATE_PRELOAD:
  150273. case DSTATE_PRESCAN:
  150274. case DSTATE_SCANNING:
  150275. case DSTATE_RAW_OK:
  150276. case DSTATE_BUFIMAGE:
  150277. case DSTATE_BUFPOST:
  150278. case DSTATE_STOPPING:
  150279. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150280. break;
  150281. default:
  150282. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150283. }
  150284. return retcode;
  150285. }
  150286. GLOBAL(boolean)
  150287. jpeg_input_complete (j_decompress_ptr cinfo)
  150288. {
  150289. if (cinfo->global_state < DSTATE_START ||
  150290. cinfo->global_state > DSTATE_STOPPING)
  150291. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150292. return cinfo->inputctl->eoi_reached;
  150293. }
  150294. GLOBAL(boolean)
  150295. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150296. {
  150297. if (cinfo->global_state < DSTATE_READY ||
  150298. cinfo->global_state > DSTATE_STOPPING)
  150299. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150300. return cinfo->inputctl->has_multiple_scans;
  150301. }
  150302. GLOBAL(boolean)
  150303. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150304. {
  150305. if ((cinfo->global_state == DSTATE_SCANNING ||
  150306. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150307. if (cinfo->output_scanline < cinfo->output_height)
  150308. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150309. (*cinfo->master->finish_output_pass) (cinfo);
  150310. cinfo->global_state = DSTATE_STOPPING;
  150311. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150312. cinfo->global_state = DSTATE_STOPPING;
  150313. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150314. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150315. }
  150316. while (! cinfo->inputctl->eoi_reached) {
  150317. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150318. return FALSE; /* Suspend, come back later */
  150319. }
  150320. (*cinfo->src->term_source) (cinfo);
  150321. jpeg_abort((j_common_ptr) cinfo);
  150322. return TRUE;
  150323. }
  150324. /*** End of inlined file: jdapimin.c ***/
  150325. /*** Start of inlined file: jdatasrc.c ***/
  150326. /*** Start of inlined file: jerror.h ***/
  150327. #ifndef JMESSAGE
  150328. #ifndef JERROR_H
  150329. #define JMAKE_ENUM_LIST
  150330. #else
  150331. #define JMESSAGE(code,string)
  150332. #endif /* JERROR_H */
  150333. #endif /* JMESSAGE */
  150334. #ifdef JMAKE_ENUM_LIST
  150335. typedef enum {
  150336. #define JMESSAGE(code,string) code ,
  150337. #endif /* JMAKE_ENUM_LIST */
  150338. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150339. JMESSAGE(JERR_ARITH_NOTIMPL,
  150340. "Sorry, there are legal restrictions on arithmetic coding")
  150341. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150342. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150343. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150344. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150345. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150346. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150347. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150348. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150349. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150350. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150351. JMESSAGE(JERR_BAD_LIB_VERSION,
  150352. "Wrong JPEG library version: library is %d, caller expects %d")
  150353. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150354. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150355. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150356. JMESSAGE(JERR_BAD_PROGRESSION,
  150357. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150358. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150359. "Invalid progressive parameters at scan script entry %d")
  150360. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150361. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150362. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150363. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150364. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150365. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150366. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150367. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150368. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150369. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150370. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150371. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150372. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150373. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150374. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150375. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150376. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150377. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150378. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150379. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150380. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150381. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150382. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150383. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150384. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150385. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150386. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150387. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150388. "Cannot transcode due to multiple use of quantization table %d")
  150389. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150390. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150391. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150392. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150393. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150394. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150395. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150396. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150397. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150398. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150399. JMESSAGE(JERR_QUANT_COMPONENTS,
  150400. "Cannot quantize more than %d color components")
  150401. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150402. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150403. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150404. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150405. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150406. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150407. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150408. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150409. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150410. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150411. JMESSAGE(JERR_TFILE_WRITE,
  150412. "Write failed on temporary file --- out of disk space?")
  150413. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150414. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150415. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150416. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150417. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150418. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150419. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150420. JMESSAGE(JMSG_VERSION, JVERSION)
  150421. JMESSAGE(JTRC_16BIT_TABLES,
  150422. "Caution: quantization tables are too coarse for baseline JPEG")
  150423. JMESSAGE(JTRC_ADOBE,
  150424. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150425. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150426. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150427. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150428. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150429. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150430. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150431. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150432. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150433. JMESSAGE(JTRC_EOI, "End Of Image")
  150434. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150435. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150436. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150437. "Warning: thumbnail image size does not match data length %u")
  150438. JMESSAGE(JTRC_JFIF_EXTENSION,
  150439. "JFIF extension marker: type 0x%02x, length %u")
  150440. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150441. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150442. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150443. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150444. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150445. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150446. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150447. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150448. JMESSAGE(JTRC_RST, "RST%d")
  150449. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150450. "Smoothing not supported with nonstandard sampling ratios")
  150451. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150452. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150453. JMESSAGE(JTRC_SOI, "Start of Image")
  150454. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150455. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150456. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150457. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150458. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150459. JMESSAGE(JTRC_THUMB_JPEG,
  150460. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150461. JMESSAGE(JTRC_THUMB_PALETTE,
  150462. "JFIF extension marker: palette thumbnail image, length %u")
  150463. JMESSAGE(JTRC_THUMB_RGB,
  150464. "JFIF extension marker: RGB thumbnail image, length %u")
  150465. JMESSAGE(JTRC_UNKNOWN_IDS,
  150466. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150467. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150468. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150469. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150470. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150471. "Inconsistent progression sequence for component %d coefficient %d")
  150472. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150473. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150474. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150475. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150476. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150477. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150478. JMESSAGE(JWRN_MUST_RESYNC,
  150479. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150480. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150481. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150482. #ifdef JMAKE_ENUM_LIST
  150483. JMSG_LASTMSGCODE
  150484. } J_MESSAGE_CODE;
  150485. #undef JMAKE_ENUM_LIST
  150486. #endif /* JMAKE_ENUM_LIST */
  150487. #undef JMESSAGE
  150488. #ifndef JERROR_H
  150489. #define JERROR_H
  150490. #define ERREXIT(cinfo,code) \
  150491. ((cinfo)->err->msg_code = (code), \
  150492. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150493. #define ERREXIT1(cinfo,code,p1) \
  150494. ((cinfo)->err->msg_code = (code), \
  150495. (cinfo)->err->msg_parm.i[0] = (p1), \
  150496. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150497. #define ERREXIT2(cinfo,code,p1,p2) \
  150498. ((cinfo)->err->msg_code = (code), \
  150499. (cinfo)->err->msg_parm.i[0] = (p1), \
  150500. (cinfo)->err->msg_parm.i[1] = (p2), \
  150501. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150502. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150503. ((cinfo)->err->msg_code = (code), \
  150504. (cinfo)->err->msg_parm.i[0] = (p1), \
  150505. (cinfo)->err->msg_parm.i[1] = (p2), \
  150506. (cinfo)->err->msg_parm.i[2] = (p3), \
  150507. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150508. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150509. ((cinfo)->err->msg_code = (code), \
  150510. (cinfo)->err->msg_parm.i[0] = (p1), \
  150511. (cinfo)->err->msg_parm.i[1] = (p2), \
  150512. (cinfo)->err->msg_parm.i[2] = (p3), \
  150513. (cinfo)->err->msg_parm.i[3] = (p4), \
  150514. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150515. #define ERREXITS(cinfo,code,str) \
  150516. ((cinfo)->err->msg_code = (code), \
  150517. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150518. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150519. #define MAKESTMT(stuff) do { stuff } while (0)
  150520. #define WARNMS(cinfo,code) \
  150521. ((cinfo)->err->msg_code = (code), \
  150522. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150523. #define WARNMS1(cinfo,code,p1) \
  150524. ((cinfo)->err->msg_code = (code), \
  150525. (cinfo)->err->msg_parm.i[0] = (p1), \
  150526. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150527. #define WARNMS2(cinfo,code,p1,p2) \
  150528. ((cinfo)->err->msg_code = (code), \
  150529. (cinfo)->err->msg_parm.i[0] = (p1), \
  150530. (cinfo)->err->msg_parm.i[1] = (p2), \
  150531. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150532. #define TRACEMS(cinfo,lvl,code) \
  150533. ((cinfo)->err->msg_code = (code), \
  150534. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150535. #define TRACEMS1(cinfo,lvl,code,p1) \
  150536. ((cinfo)->err->msg_code = (code), \
  150537. (cinfo)->err->msg_parm.i[0] = (p1), \
  150538. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150539. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150540. ((cinfo)->err->msg_code = (code), \
  150541. (cinfo)->err->msg_parm.i[0] = (p1), \
  150542. (cinfo)->err->msg_parm.i[1] = (p2), \
  150543. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150544. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150545. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150546. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150547. (cinfo)->err->msg_code = (code); \
  150548. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150549. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150550. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150551. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150552. (cinfo)->err->msg_code = (code); \
  150553. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150554. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150555. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150556. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150557. _mp[4] = (p5); \
  150558. (cinfo)->err->msg_code = (code); \
  150559. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150560. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150561. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150562. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150563. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150564. (cinfo)->err->msg_code = (code); \
  150565. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150566. #define TRACEMSS(cinfo,lvl,code,str) \
  150567. ((cinfo)->err->msg_code = (code), \
  150568. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150569. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150570. #endif /* JERROR_H */
  150571. /*** End of inlined file: jerror.h ***/
  150572. typedef struct {
  150573. struct jpeg_source_mgr pub; /* public fields */
  150574. FILE * infile; /* source stream */
  150575. JOCTET * buffer; /* start of buffer */
  150576. boolean start_of_file; /* have we gotten any data yet? */
  150577. } my_source_mgr;
  150578. typedef my_source_mgr * my_src_ptr;
  150579. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150580. METHODDEF(void)
  150581. init_source (j_decompress_ptr cinfo)
  150582. {
  150583. my_src_ptr src = (my_src_ptr) cinfo->src;
  150584. src->start_of_file = TRUE;
  150585. }
  150586. METHODDEF(boolean)
  150587. fill_input_buffer (j_decompress_ptr cinfo)
  150588. {
  150589. my_src_ptr src = (my_src_ptr) cinfo->src;
  150590. size_t nbytes;
  150591. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150592. if (nbytes <= 0) {
  150593. if (src->start_of_file) /* Treat empty input file as fatal error */
  150594. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150595. WARNMS(cinfo, JWRN_JPEG_EOF);
  150596. src->buffer[0] = (JOCTET) 0xFF;
  150597. src->buffer[1] = (JOCTET) JPEG_EOI;
  150598. nbytes = 2;
  150599. }
  150600. src->pub.next_input_byte = src->buffer;
  150601. src->pub.bytes_in_buffer = nbytes;
  150602. src->start_of_file = FALSE;
  150603. return TRUE;
  150604. }
  150605. METHODDEF(void)
  150606. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150607. {
  150608. my_src_ptr src = (my_src_ptr) cinfo->src;
  150609. if (num_bytes > 0) {
  150610. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150611. num_bytes -= (long) src->pub.bytes_in_buffer;
  150612. (void) fill_input_buffer(cinfo);
  150613. }
  150614. src->pub.next_input_byte += (size_t) num_bytes;
  150615. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150616. }
  150617. }
  150618. METHODDEF(void)
  150619. term_source (j_decompress_ptr cinfo)
  150620. {
  150621. }
  150622. GLOBAL(void)
  150623. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150624. {
  150625. my_src_ptr src;
  150626. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150627. cinfo->src = (struct jpeg_source_mgr *)
  150628. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150629. SIZEOF(my_source_mgr));
  150630. src = (my_src_ptr) cinfo->src;
  150631. src->buffer = (JOCTET *)
  150632. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150633. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150634. }
  150635. src = (my_src_ptr) cinfo->src;
  150636. src->pub.init_source = init_source;
  150637. src->pub.fill_input_buffer = fill_input_buffer;
  150638. src->pub.skip_input_data = skip_input_data;
  150639. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150640. src->pub.term_source = term_source;
  150641. src->infile = infile;
  150642. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150643. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150644. }
  150645. /*** End of inlined file: jdatasrc.c ***/
  150646. /*** Start of inlined file: jdcoefct.c ***/
  150647. #define JPEG_INTERNALS
  150648. #ifndef D_PROGRESSIVE_SUPPORTED
  150649. #undef BLOCK_SMOOTHING_SUPPORTED
  150650. #endif
  150651. typedef struct {
  150652. struct jpeg_d_coef_controller pub; /* public fields */
  150653. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150654. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150655. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150656. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150657. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150658. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150659. #endif
  150660. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150661. int * coef_bits_latch;
  150662. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150663. #endif
  150664. } my_coef_controller3;
  150665. typedef my_coef_controller3 * my_coef_ptr3;
  150666. METHODDEF(int) decompress_onepass
  150667. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150668. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150669. METHODDEF(int) decompress_data
  150670. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150671. #endif
  150672. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150673. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150674. METHODDEF(int) decompress_smooth_data
  150675. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150676. #endif
  150677. LOCAL(void)
  150678. start_iMCU_row3 (j_decompress_ptr cinfo)
  150679. {
  150680. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150681. if (cinfo->comps_in_scan > 1) {
  150682. coef->MCU_rows_per_iMCU_row = 1;
  150683. } else {
  150684. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150685. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150686. else
  150687. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150688. }
  150689. coef->MCU_ctr = 0;
  150690. coef->MCU_vert_offset = 0;
  150691. }
  150692. METHODDEF(void)
  150693. start_input_pass (j_decompress_ptr cinfo)
  150694. {
  150695. cinfo->input_iMCU_row = 0;
  150696. start_iMCU_row3(cinfo);
  150697. }
  150698. METHODDEF(void)
  150699. start_output_pass (j_decompress_ptr cinfo)
  150700. {
  150701. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150702. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150703. if (coef->pub.coef_arrays != NULL) {
  150704. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150705. coef->pub.decompress_data = decompress_smooth_data;
  150706. else
  150707. coef->pub.decompress_data = decompress_data;
  150708. }
  150709. #endif
  150710. cinfo->output_iMCU_row = 0;
  150711. }
  150712. METHODDEF(int)
  150713. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150714. {
  150715. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150716. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150717. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150718. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150719. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150720. JSAMPARRAY output_ptr;
  150721. JDIMENSION start_col, output_col;
  150722. jpeg_component_info *compptr;
  150723. inverse_DCT_method_ptr inverse_DCT;
  150724. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150725. yoffset++) {
  150726. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150727. MCU_col_num++) {
  150728. jzero_far((void FAR *) coef->MCU_buffer[0],
  150729. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150730. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150731. coef->MCU_vert_offset = yoffset;
  150732. coef->MCU_ctr = MCU_col_num;
  150733. return JPEG_SUSPENDED;
  150734. }
  150735. blkn = 0; /* index of current DCT block within MCU */
  150736. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150737. compptr = cinfo->cur_comp_info[ci];
  150738. if (! compptr->component_needed) {
  150739. blkn += compptr->MCU_blocks;
  150740. continue;
  150741. }
  150742. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150743. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150744. : compptr->last_col_width;
  150745. output_ptr = output_buf[compptr->component_index] +
  150746. yoffset * compptr->DCT_scaled_size;
  150747. start_col = MCU_col_num * compptr->MCU_sample_width;
  150748. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150749. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150750. yoffset+yindex < compptr->last_row_height) {
  150751. output_col = start_col;
  150752. for (xindex = 0; xindex < useful_width; xindex++) {
  150753. (*inverse_DCT) (cinfo, compptr,
  150754. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150755. output_ptr, output_col);
  150756. output_col += compptr->DCT_scaled_size;
  150757. }
  150758. }
  150759. blkn += compptr->MCU_width;
  150760. output_ptr += compptr->DCT_scaled_size;
  150761. }
  150762. }
  150763. }
  150764. coef->MCU_ctr = 0;
  150765. }
  150766. cinfo->output_iMCU_row++;
  150767. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150768. start_iMCU_row3(cinfo);
  150769. return JPEG_ROW_COMPLETED;
  150770. }
  150771. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150772. return JPEG_SCAN_COMPLETED;
  150773. }
  150774. METHODDEF(int)
  150775. dummy_consume_data (j_decompress_ptr cinfo)
  150776. {
  150777. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150778. }
  150779. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150780. METHODDEF(int)
  150781. consume_data (j_decompress_ptr cinfo)
  150782. {
  150783. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150784. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150785. int blkn, ci, xindex, yindex, yoffset;
  150786. JDIMENSION start_col;
  150787. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150788. JBLOCKROW buffer_ptr;
  150789. jpeg_component_info *compptr;
  150790. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150791. compptr = cinfo->cur_comp_info[ci];
  150792. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150793. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150794. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150795. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150796. }
  150797. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150798. yoffset++) {
  150799. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150800. MCU_col_num++) {
  150801. blkn = 0; /* index of current DCT block within MCU */
  150802. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150803. compptr = cinfo->cur_comp_info[ci];
  150804. start_col = MCU_col_num * compptr->MCU_width;
  150805. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150806. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150807. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150808. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150809. }
  150810. }
  150811. }
  150812. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150813. coef->MCU_vert_offset = yoffset;
  150814. coef->MCU_ctr = MCU_col_num;
  150815. return JPEG_SUSPENDED;
  150816. }
  150817. }
  150818. coef->MCU_ctr = 0;
  150819. }
  150820. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150821. start_iMCU_row3(cinfo);
  150822. return JPEG_ROW_COMPLETED;
  150823. }
  150824. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150825. return JPEG_SCAN_COMPLETED;
  150826. }
  150827. METHODDEF(int)
  150828. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150829. {
  150830. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150831. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150832. JDIMENSION block_num;
  150833. int ci, block_row, block_rows;
  150834. JBLOCKARRAY buffer;
  150835. JBLOCKROW buffer_ptr;
  150836. JSAMPARRAY output_ptr;
  150837. JDIMENSION output_col;
  150838. jpeg_component_info *compptr;
  150839. inverse_DCT_method_ptr inverse_DCT;
  150840. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  150841. (cinfo->input_scan_number == cinfo->output_scan_number &&
  150842. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  150843. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150844. return JPEG_SUSPENDED;
  150845. }
  150846. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150847. ci++, compptr++) {
  150848. if (! compptr->component_needed)
  150849. continue;
  150850. buffer = (*cinfo->mem->access_virt_barray)
  150851. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150852. cinfo->output_iMCU_row * compptr->v_samp_factor,
  150853. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150854. if (cinfo->output_iMCU_row < last_iMCU_row)
  150855. block_rows = compptr->v_samp_factor;
  150856. else {
  150857. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150858. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150859. }
  150860. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  150861. output_ptr = output_buf[ci];
  150862. for (block_row = 0; block_row < block_rows; block_row++) {
  150863. buffer_ptr = buffer[block_row];
  150864. output_col = 0;
  150865. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  150866. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  150867. output_ptr, output_col);
  150868. buffer_ptr++;
  150869. output_col += compptr->DCT_scaled_size;
  150870. }
  150871. output_ptr += compptr->DCT_scaled_size;
  150872. }
  150873. }
  150874. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  150875. return JPEG_ROW_COMPLETED;
  150876. return JPEG_SCAN_COMPLETED;
  150877. }
  150878. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150879. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150880. #define Q01_POS 1
  150881. #define Q10_POS 8
  150882. #define Q20_POS 16
  150883. #define Q11_POS 9
  150884. #define Q02_POS 2
  150885. LOCAL(boolean)
  150886. smoothing_ok (j_decompress_ptr cinfo)
  150887. {
  150888. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150889. boolean smoothing_useful = FALSE;
  150890. int ci, coefi;
  150891. jpeg_component_info *compptr;
  150892. JQUANT_TBL * qtable;
  150893. int * coef_bits;
  150894. int * coef_bits_latch;
  150895. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  150896. return FALSE;
  150897. if (coef->coef_bits_latch == NULL)
  150898. coef->coef_bits_latch = (int *)
  150899. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150900. cinfo->num_components *
  150901. (SAVED_COEFS * SIZEOF(int)));
  150902. coef_bits_latch = coef->coef_bits_latch;
  150903. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150904. ci++, compptr++) {
  150905. if ((qtable = compptr->quant_table) == NULL)
  150906. return FALSE;
  150907. if (qtable->quantval[0] == 0 ||
  150908. qtable->quantval[Q01_POS] == 0 ||
  150909. qtable->quantval[Q10_POS] == 0 ||
  150910. qtable->quantval[Q20_POS] == 0 ||
  150911. qtable->quantval[Q11_POS] == 0 ||
  150912. qtable->quantval[Q02_POS] == 0)
  150913. return FALSE;
  150914. coef_bits = cinfo->coef_bits[ci];
  150915. if (coef_bits[0] < 0)
  150916. return FALSE;
  150917. for (coefi = 1; coefi <= 5; coefi++) {
  150918. coef_bits_latch[coefi] = coef_bits[coefi];
  150919. if (coef_bits[coefi] != 0)
  150920. smoothing_useful = TRUE;
  150921. }
  150922. coef_bits_latch += SAVED_COEFS;
  150923. }
  150924. return smoothing_useful;
  150925. }
  150926. METHODDEF(int)
  150927. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150928. {
  150929. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150930. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150931. JDIMENSION block_num, last_block_column;
  150932. int ci, block_row, block_rows, access_rows;
  150933. JBLOCKARRAY buffer;
  150934. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  150935. JSAMPARRAY output_ptr;
  150936. JDIMENSION output_col;
  150937. jpeg_component_info *compptr;
  150938. inverse_DCT_method_ptr inverse_DCT;
  150939. boolean first_row, last_row;
  150940. JBLOCK workspace;
  150941. int *coef_bits;
  150942. JQUANT_TBL *quanttbl;
  150943. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  150944. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  150945. int Al, pred;
  150946. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150947. ! cinfo->inputctl->eoi_reached) {
  150948. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  150949. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  150950. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  150951. break;
  150952. }
  150953. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150954. return JPEG_SUSPENDED;
  150955. }
  150956. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150957. ci++, compptr++) {
  150958. if (! compptr->component_needed)
  150959. continue;
  150960. if (cinfo->output_iMCU_row < last_iMCU_row) {
  150961. block_rows = compptr->v_samp_factor;
  150962. access_rows = block_rows * 2; /* this and next iMCU row */
  150963. last_row = FALSE;
  150964. } else {
  150965. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150966. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150967. access_rows = block_rows; /* this iMCU row only */
  150968. last_row = TRUE;
  150969. }
  150970. if (cinfo->output_iMCU_row > 0) {
  150971. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  150972. buffer = (*cinfo->mem->access_virt_barray)
  150973. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150974. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  150975. (JDIMENSION) access_rows, FALSE);
  150976. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  150977. first_row = FALSE;
  150978. } else {
  150979. buffer = (*cinfo->mem->access_virt_barray)
  150980. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150981. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  150982. first_row = TRUE;
  150983. }
  150984. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  150985. quanttbl = compptr->quant_table;
  150986. Q00 = quanttbl->quantval[0];
  150987. Q01 = quanttbl->quantval[Q01_POS];
  150988. Q10 = quanttbl->quantval[Q10_POS];
  150989. Q20 = quanttbl->quantval[Q20_POS];
  150990. Q11 = quanttbl->quantval[Q11_POS];
  150991. Q02 = quanttbl->quantval[Q02_POS];
  150992. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  150993. output_ptr = output_buf[ci];
  150994. for (block_row = 0; block_row < block_rows; block_row++) {
  150995. buffer_ptr = buffer[block_row];
  150996. if (first_row && block_row == 0)
  150997. prev_block_row = buffer_ptr;
  150998. else
  150999. prev_block_row = buffer[block_row-1];
  151000. if (last_row && block_row == block_rows-1)
  151001. next_block_row = buffer_ptr;
  151002. else
  151003. next_block_row = buffer[block_row+1];
  151004. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151005. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151006. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151007. output_col = 0;
  151008. last_block_column = compptr->width_in_blocks - 1;
  151009. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151010. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151011. if (block_num < last_block_column) {
  151012. DC3 = (int) prev_block_row[1][0];
  151013. DC6 = (int) buffer_ptr[1][0];
  151014. DC9 = (int) next_block_row[1][0];
  151015. }
  151016. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151017. num = 36 * Q00 * (DC4 - DC6);
  151018. if (num >= 0) {
  151019. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151020. if (Al > 0 && pred >= (1<<Al))
  151021. pred = (1<<Al)-1;
  151022. } else {
  151023. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151024. if (Al > 0 && pred >= (1<<Al))
  151025. pred = (1<<Al)-1;
  151026. pred = -pred;
  151027. }
  151028. workspace[1] = (JCOEF) pred;
  151029. }
  151030. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151031. num = 36 * Q00 * (DC2 - DC8);
  151032. if (num >= 0) {
  151033. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151034. if (Al > 0 && pred >= (1<<Al))
  151035. pred = (1<<Al)-1;
  151036. } else {
  151037. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151038. if (Al > 0 && pred >= (1<<Al))
  151039. pred = (1<<Al)-1;
  151040. pred = -pred;
  151041. }
  151042. workspace[8] = (JCOEF) pred;
  151043. }
  151044. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151045. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151046. if (num >= 0) {
  151047. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151048. if (Al > 0 && pred >= (1<<Al))
  151049. pred = (1<<Al)-1;
  151050. } else {
  151051. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151052. if (Al > 0 && pred >= (1<<Al))
  151053. pred = (1<<Al)-1;
  151054. pred = -pred;
  151055. }
  151056. workspace[16] = (JCOEF) pred;
  151057. }
  151058. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151059. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151060. if (num >= 0) {
  151061. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151062. if (Al > 0 && pred >= (1<<Al))
  151063. pred = (1<<Al)-1;
  151064. } else {
  151065. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151066. if (Al > 0 && pred >= (1<<Al))
  151067. pred = (1<<Al)-1;
  151068. pred = -pred;
  151069. }
  151070. workspace[9] = (JCOEF) pred;
  151071. }
  151072. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151073. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151074. if (num >= 0) {
  151075. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151076. if (Al > 0 && pred >= (1<<Al))
  151077. pred = (1<<Al)-1;
  151078. } else {
  151079. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151080. if (Al > 0 && pred >= (1<<Al))
  151081. pred = (1<<Al)-1;
  151082. pred = -pred;
  151083. }
  151084. workspace[2] = (JCOEF) pred;
  151085. }
  151086. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151087. output_ptr, output_col);
  151088. DC1 = DC2; DC2 = DC3;
  151089. DC4 = DC5; DC5 = DC6;
  151090. DC7 = DC8; DC8 = DC9;
  151091. buffer_ptr++, prev_block_row++, next_block_row++;
  151092. output_col += compptr->DCT_scaled_size;
  151093. }
  151094. output_ptr += compptr->DCT_scaled_size;
  151095. }
  151096. }
  151097. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151098. return JPEG_ROW_COMPLETED;
  151099. return JPEG_SCAN_COMPLETED;
  151100. }
  151101. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151102. GLOBAL(void)
  151103. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151104. {
  151105. my_coef_ptr3 coef;
  151106. coef = (my_coef_ptr3)
  151107. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151108. SIZEOF(my_coef_controller3));
  151109. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151110. coef->pub.start_input_pass = start_input_pass;
  151111. coef->pub.start_output_pass = start_output_pass;
  151112. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151113. coef->coef_bits_latch = NULL;
  151114. #endif
  151115. if (need_full_buffer) {
  151116. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151117. int ci, access_rows;
  151118. jpeg_component_info *compptr;
  151119. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151120. ci++, compptr++) {
  151121. access_rows = compptr->v_samp_factor;
  151122. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151123. if (cinfo->progressive_mode)
  151124. access_rows *= 3;
  151125. #endif
  151126. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151127. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151128. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151129. (long) compptr->h_samp_factor),
  151130. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151131. (long) compptr->v_samp_factor),
  151132. (JDIMENSION) access_rows);
  151133. }
  151134. coef->pub.consume_data = consume_data;
  151135. coef->pub.decompress_data = decompress_data;
  151136. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151137. #else
  151138. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151139. #endif
  151140. } else {
  151141. JBLOCKROW buffer;
  151142. int i;
  151143. buffer = (JBLOCKROW)
  151144. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151145. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151146. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151147. coef->MCU_buffer[i] = buffer + i;
  151148. }
  151149. coef->pub.consume_data = dummy_consume_data;
  151150. coef->pub.decompress_data = decompress_onepass;
  151151. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151152. }
  151153. }
  151154. /*** End of inlined file: jdcoefct.c ***/
  151155. #undef FIX
  151156. /*** Start of inlined file: jdcolor.c ***/
  151157. #define JPEG_INTERNALS
  151158. typedef struct {
  151159. struct jpeg_color_deconverter pub; /* public fields */
  151160. int * Cr_r_tab; /* => table for Cr to R conversion */
  151161. int * Cb_b_tab; /* => table for Cb to B conversion */
  151162. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151163. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151164. } my_color_deconverter2;
  151165. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151166. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151167. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151168. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151169. LOCAL(void)
  151170. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151171. {
  151172. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151173. int i;
  151174. INT32 x;
  151175. SHIFT_TEMPS
  151176. cconvert->Cr_r_tab = (int *)
  151177. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151178. (MAXJSAMPLE+1) * SIZEOF(int));
  151179. cconvert->Cb_b_tab = (int *)
  151180. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151181. (MAXJSAMPLE+1) * SIZEOF(int));
  151182. cconvert->Cr_g_tab = (INT32 *)
  151183. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151184. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151185. cconvert->Cb_g_tab = (INT32 *)
  151186. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151187. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151188. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151189. cconvert->Cr_r_tab[i] = (int)
  151190. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151191. cconvert->Cb_b_tab[i] = (int)
  151192. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151193. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151194. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151195. }
  151196. }
  151197. METHODDEF(void)
  151198. ycc_rgb_convert (j_decompress_ptr cinfo,
  151199. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151200. JSAMPARRAY output_buf, int num_rows)
  151201. {
  151202. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151203. register int y, cb, cr;
  151204. register JSAMPROW outptr;
  151205. register JSAMPROW inptr0, inptr1, inptr2;
  151206. register JDIMENSION col;
  151207. JDIMENSION num_cols = cinfo->output_width;
  151208. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151209. register int * Crrtab = cconvert->Cr_r_tab;
  151210. register int * Cbbtab = cconvert->Cb_b_tab;
  151211. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151212. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151213. SHIFT_TEMPS
  151214. while (--num_rows >= 0) {
  151215. inptr0 = input_buf[0][input_row];
  151216. inptr1 = input_buf[1][input_row];
  151217. inptr2 = input_buf[2][input_row];
  151218. input_row++;
  151219. outptr = *output_buf++;
  151220. for (col = 0; col < num_cols; col++) {
  151221. y = GETJSAMPLE(inptr0[col]);
  151222. cb = GETJSAMPLE(inptr1[col]);
  151223. cr = GETJSAMPLE(inptr2[col]);
  151224. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151225. outptr[RGB_GREEN] = range_limit[y +
  151226. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151227. SCALEBITS))];
  151228. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151229. outptr += RGB_PIXELSIZE;
  151230. }
  151231. }
  151232. }
  151233. METHODDEF(void)
  151234. null_convert2 (j_decompress_ptr cinfo,
  151235. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151236. JSAMPARRAY output_buf, int num_rows)
  151237. {
  151238. register JSAMPROW inptr, outptr;
  151239. register JDIMENSION count;
  151240. register int num_components = cinfo->num_components;
  151241. JDIMENSION num_cols = cinfo->output_width;
  151242. int ci;
  151243. while (--num_rows >= 0) {
  151244. for (ci = 0; ci < num_components; ci++) {
  151245. inptr = input_buf[ci][input_row];
  151246. outptr = output_buf[0] + ci;
  151247. for (count = num_cols; count > 0; count--) {
  151248. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151249. outptr += num_components;
  151250. }
  151251. }
  151252. input_row++;
  151253. output_buf++;
  151254. }
  151255. }
  151256. METHODDEF(void)
  151257. grayscale_convert2 (j_decompress_ptr cinfo,
  151258. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151259. JSAMPARRAY output_buf, int num_rows)
  151260. {
  151261. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151262. num_rows, cinfo->output_width);
  151263. }
  151264. METHODDEF(void)
  151265. gray_rgb_convert (j_decompress_ptr cinfo,
  151266. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151267. JSAMPARRAY output_buf, int num_rows)
  151268. {
  151269. register JSAMPROW inptr, outptr;
  151270. register JDIMENSION col;
  151271. JDIMENSION num_cols = cinfo->output_width;
  151272. while (--num_rows >= 0) {
  151273. inptr = input_buf[0][input_row++];
  151274. outptr = *output_buf++;
  151275. for (col = 0; col < num_cols; col++) {
  151276. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151277. outptr += RGB_PIXELSIZE;
  151278. }
  151279. }
  151280. }
  151281. METHODDEF(void)
  151282. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151283. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151284. JSAMPARRAY output_buf, int num_rows)
  151285. {
  151286. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151287. register int y, cb, cr;
  151288. register JSAMPROW outptr;
  151289. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151290. register JDIMENSION col;
  151291. JDIMENSION num_cols = cinfo->output_width;
  151292. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151293. register int * Crrtab = cconvert->Cr_r_tab;
  151294. register int * Cbbtab = cconvert->Cb_b_tab;
  151295. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151296. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151297. SHIFT_TEMPS
  151298. while (--num_rows >= 0) {
  151299. inptr0 = input_buf[0][input_row];
  151300. inptr1 = input_buf[1][input_row];
  151301. inptr2 = input_buf[2][input_row];
  151302. inptr3 = input_buf[3][input_row];
  151303. input_row++;
  151304. outptr = *output_buf++;
  151305. for (col = 0; col < num_cols; col++) {
  151306. y = GETJSAMPLE(inptr0[col]);
  151307. cb = GETJSAMPLE(inptr1[col]);
  151308. cr = GETJSAMPLE(inptr2[col]);
  151309. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151310. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151311. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151312. SCALEBITS)))];
  151313. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151314. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151315. outptr += 4;
  151316. }
  151317. }
  151318. }
  151319. METHODDEF(void)
  151320. start_pass_dcolor (j_decompress_ptr cinfo)
  151321. {
  151322. }
  151323. GLOBAL(void)
  151324. jinit_color_deconverter (j_decompress_ptr cinfo)
  151325. {
  151326. my_cconvert_ptr2 cconvert;
  151327. int ci;
  151328. cconvert = (my_cconvert_ptr2)
  151329. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151330. SIZEOF(my_color_deconverter2));
  151331. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151332. cconvert->pub.start_pass = start_pass_dcolor;
  151333. switch (cinfo->jpeg_color_space) {
  151334. case JCS_GRAYSCALE:
  151335. if (cinfo->num_components != 1)
  151336. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151337. break;
  151338. case JCS_RGB:
  151339. case JCS_YCbCr:
  151340. if (cinfo->num_components != 3)
  151341. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151342. break;
  151343. case JCS_CMYK:
  151344. case JCS_YCCK:
  151345. if (cinfo->num_components != 4)
  151346. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151347. break;
  151348. default: /* JCS_UNKNOWN can be anything */
  151349. if (cinfo->num_components < 1)
  151350. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151351. break;
  151352. }
  151353. switch (cinfo->out_color_space) {
  151354. case JCS_GRAYSCALE:
  151355. cinfo->out_color_components = 1;
  151356. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151357. cinfo->jpeg_color_space == JCS_YCbCr) {
  151358. cconvert->pub.color_convert = grayscale_convert2;
  151359. for (ci = 1; ci < cinfo->num_components; ci++)
  151360. cinfo->comp_info[ci].component_needed = FALSE;
  151361. } else
  151362. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151363. break;
  151364. case JCS_RGB:
  151365. cinfo->out_color_components = RGB_PIXELSIZE;
  151366. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151367. cconvert->pub.color_convert = ycc_rgb_convert;
  151368. build_ycc_rgb_table(cinfo);
  151369. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151370. cconvert->pub.color_convert = gray_rgb_convert;
  151371. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151372. cconvert->pub.color_convert = null_convert2;
  151373. } else
  151374. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151375. break;
  151376. case JCS_CMYK:
  151377. cinfo->out_color_components = 4;
  151378. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151379. cconvert->pub.color_convert = ycck_cmyk_convert;
  151380. build_ycc_rgb_table(cinfo);
  151381. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151382. cconvert->pub.color_convert = null_convert2;
  151383. } else
  151384. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151385. break;
  151386. default:
  151387. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151388. cinfo->out_color_components = cinfo->num_components;
  151389. cconvert->pub.color_convert = null_convert2;
  151390. } else /* unsupported non-null conversion */
  151391. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151392. break;
  151393. }
  151394. if (cinfo->quantize_colors)
  151395. cinfo->output_components = 1; /* single colormapped output component */
  151396. else
  151397. cinfo->output_components = cinfo->out_color_components;
  151398. }
  151399. /*** End of inlined file: jdcolor.c ***/
  151400. #undef FIX
  151401. /*** Start of inlined file: jddctmgr.c ***/
  151402. #define JPEG_INTERNALS
  151403. typedef struct {
  151404. struct jpeg_inverse_dct pub; /* public fields */
  151405. int cur_method[MAX_COMPONENTS];
  151406. } my_idct_controller;
  151407. typedef my_idct_controller * my_idct_ptr;
  151408. typedef union {
  151409. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151410. #ifdef DCT_IFAST_SUPPORTED
  151411. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151412. #endif
  151413. #ifdef DCT_FLOAT_SUPPORTED
  151414. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151415. #endif
  151416. } multiplier_table;
  151417. #ifdef DCT_ISLOW_SUPPORTED
  151418. #define PROVIDE_ISLOW_TABLES
  151419. #else
  151420. #ifdef IDCT_SCALING_SUPPORTED
  151421. #define PROVIDE_ISLOW_TABLES
  151422. #endif
  151423. #endif
  151424. METHODDEF(void)
  151425. start_pass (j_decompress_ptr cinfo)
  151426. {
  151427. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151428. int ci, i;
  151429. jpeg_component_info *compptr;
  151430. int method = 0;
  151431. inverse_DCT_method_ptr method_ptr = NULL;
  151432. JQUANT_TBL * qtbl;
  151433. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151434. ci++, compptr++) {
  151435. switch (compptr->DCT_scaled_size) {
  151436. #ifdef IDCT_SCALING_SUPPORTED
  151437. case 1:
  151438. method_ptr = jpeg_idct_1x1;
  151439. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151440. break;
  151441. case 2:
  151442. method_ptr = jpeg_idct_2x2;
  151443. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151444. break;
  151445. case 4:
  151446. method_ptr = jpeg_idct_4x4;
  151447. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151448. break;
  151449. #endif
  151450. case DCTSIZE:
  151451. switch (cinfo->dct_method) {
  151452. #ifdef DCT_ISLOW_SUPPORTED
  151453. case JDCT_ISLOW:
  151454. method_ptr = jpeg_idct_islow;
  151455. method = JDCT_ISLOW;
  151456. break;
  151457. #endif
  151458. #ifdef DCT_IFAST_SUPPORTED
  151459. case JDCT_IFAST:
  151460. method_ptr = jpeg_idct_ifast;
  151461. method = JDCT_IFAST;
  151462. break;
  151463. #endif
  151464. #ifdef DCT_FLOAT_SUPPORTED
  151465. case JDCT_FLOAT:
  151466. method_ptr = jpeg_idct_float;
  151467. method = JDCT_FLOAT;
  151468. break;
  151469. #endif
  151470. default:
  151471. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151472. break;
  151473. }
  151474. break;
  151475. default:
  151476. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151477. break;
  151478. }
  151479. idct->pub.inverse_DCT[ci] = method_ptr;
  151480. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151481. continue;
  151482. qtbl = compptr->quant_table;
  151483. if (qtbl == NULL) /* happens if no data yet for component */
  151484. continue;
  151485. idct->cur_method[ci] = method;
  151486. switch (method) {
  151487. #ifdef PROVIDE_ISLOW_TABLES
  151488. case JDCT_ISLOW:
  151489. {
  151490. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151491. for (i = 0; i < DCTSIZE2; i++) {
  151492. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151493. }
  151494. }
  151495. break;
  151496. #endif
  151497. #ifdef DCT_IFAST_SUPPORTED
  151498. case JDCT_IFAST:
  151499. {
  151500. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151501. #define CONST_BITS 14
  151502. static const INT16 aanscales[DCTSIZE2] = {
  151503. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151504. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151505. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151506. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151507. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151508. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151509. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151510. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151511. };
  151512. SHIFT_TEMPS
  151513. for (i = 0; i < DCTSIZE2; i++) {
  151514. ifmtbl[i] = (IFAST_MULT_TYPE)
  151515. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151516. (INT32) aanscales[i]),
  151517. CONST_BITS-IFAST_SCALE_BITS);
  151518. }
  151519. }
  151520. break;
  151521. #endif
  151522. #ifdef DCT_FLOAT_SUPPORTED
  151523. case JDCT_FLOAT:
  151524. {
  151525. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151526. int row, col;
  151527. static const double aanscalefactor[DCTSIZE] = {
  151528. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151529. 1.0, 0.785694958, 0.541196100, 0.275899379
  151530. };
  151531. i = 0;
  151532. for (row = 0; row < DCTSIZE; row++) {
  151533. for (col = 0; col < DCTSIZE; col++) {
  151534. fmtbl[i] = (FLOAT_MULT_TYPE)
  151535. ((double) qtbl->quantval[i] *
  151536. aanscalefactor[row] * aanscalefactor[col]);
  151537. i++;
  151538. }
  151539. }
  151540. }
  151541. break;
  151542. #endif
  151543. default:
  151544. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151545. break;
  151546. }
  151547. }
  151548. }
  151549. GLOBAL(void)
  151550. jinit_inverse_dct (j_decompress_ptr cinfo)
  151551. {
  151552. my_idct_ptr idct;
  151553. int ci;
  151554. jpeg_component_info *compptr;
  151555. idct = (my_idct_ptr)
  151556. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151557. SIZEOF(my_idct_controller));
  151558. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151559. idct->pub.start_pass = start_pass;
  151560. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151561. ci++, compptr++) {
  151562. compptr->dct_table =
  151563. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151564. SIZEOF(multiplier_table));
  151565. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151566. idct->cur_method[ci] = -1;
  151567. }
  151568. }
  151569. /*** End of inlined file: jddctmgr.c ***/
  151570. #undef CONST_BITS
  151571. #undef ASSIGN_STATE
  151572. /*** Start of inlined file: jdhuff.c ***/
  151573. #define JPEG_INTERNALS
  151574. /*** Start of inlined file: jdhuff.h ***/
  151575. #ifndef __jdhuff_h__
  151576. #define __jdhuff_h__
  151577. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151578. #define jpeg_make_d_derived_tbl jMkDDerived
  151579. #define jpeg_fill_bit_buffer jFilBitBuf
  151580. #define jpeg_huff_decode jHufDecode
  151581. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151582. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151583. typedef struct {
  151584. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151585. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151586. JHUFF_TBL *pub;
  151587. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151588. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151589. } d_derived_tbl;
  151590. EXTERN(void) jpeg_make_d_derived_tbl
  151591. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151592. d_derived_tbl ** pdtbl));
  151593. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151594. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151595. typedef struct { /* Bitreading state saved across MCUs */
  151596. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151597. int bits_left; /* # of unused bits in it */
  151598. } bitread_perm_state;
  151599. typedef struct { /* Bitreading working state within an MCU */
  151600. const JOCTET * next_input_byte; /* => next byte to read from source */
  151601. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151602. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151603. int bits_left; /* # of unused bits in it */
  151604. j_decompress_ptr cinfo; /* back link to decompress master record */
  151605. } bitread_working_state;
  151606. #define BITREAD_STATE_VARS \
  151607. register bit_buf_type get_buffer; \
  151608. register int bits_left; \
  151609. bitread_working_state br_state
  151610. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151611. br_state.cinfo = cinfop; \
  151612. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151613. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151614. get_buffer = permstate.get_buffer; \
  151615. bits_left = permstate.bits_left;
  151616. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151617. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151618. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151619. permstate.get_buffer = get_buffer; \
  151620. permstate.bits_left = bits_left
  151621. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151622. { if (bits_left < (nbits)) { \
  151623. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151624. { action; } \
  151625. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151626. #define GET_BITS(nbits) \
  151627. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151628. #define PEEK_BITS(nbits) \
  151629. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151630. #define DROP_BITS(nbits) \
  151631. (bits_left -= (nbits))
  151632. EXTERN(boolean) jpeg_fill_bit_buffer
  151633. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151634. register int bits_left, int nbits));
  151635. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151636. { register int nb, look; \
  151637. if (bits_left < HUFF_LOOKAHEAD) { \
  151638. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151639. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151640. if (bits_left < HUFF_LOOKAHEAD) { \
  151641. nb = 1; goto slowlabel; \
  151642. } \
  151643. } \
  151644. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151645. if ((nb = htbl->look_nbits[look]) != 0) { \
  151646. DROP_BITS(nb); \
  151647. result = htbl->look_sym[look]; \
  151648. } else { \
  151649. nb = HUFF_LOOKAHEAD+1; \
  151650. slowlabel: \
  151651. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151652. { failaction; } \
  151653. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151654. } \
  151655. }
  151656. EXTERN(int) jpeg_huff_decode
  151657. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151658. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151659. #endif
  151660. /*** End of inlined file: jdhuff.h ***/
  151661. /* Declarations shared with jdphuff.c */
  151662. typedef struct {
  151663. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151664. } savable_state2;
  151665. #ifndef NO_STRUCT_ASSIGN
  151666. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151667. #else
  151668. #if MAX_COMPS_IN_SCAN == 4
  151669. #define ASSIGN_STATE(dest,src) \
  151670. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151671. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151672. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151673. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151674. #endif
  151675. #endif
  151676. typedef struct {
  151677. struct jpeg_entropy_decoder pub; /* public fields */
  151678. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151679. savable_state2 saved; /* Other state at start of MCU */
  151680. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151681. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151682. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151683. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151684. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151685. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151686. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151687. } huff_entropy_decoder2;
  151688. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151689. METHODDEF(void)
  151690. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151691. {
  151692. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151693. int ci, blkn, dctbl, actbl;
  151694. jpeg_component_info * compptr;
  151695. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151696. cinfo->Ah != 0 || cinfo->Al != 0)
  151697. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151698. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151699. compptr = cinfo->cur_comp_info[ci];
  151700. dctbl = compptr->dc_tbl_no;
  151701. actbl = compptr->ac_tbl_no;
  151702. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151703. & entropy->dc_derived_tbls[dctbl]);
  151704. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151705. & entropy->ac_derived_tbls[actbl]);
  151706. entropy->saved.last_dc_val[ci] = 0;
  151707. }
  151708. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151709. ci = cinfo->MCU_membership[blkn];
  151710. compptr = cinfo->cur_comp_info[ci];
  151711. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151712. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151713. if (compptr->component_needed) {
  151714. entropy->dc_needed[blkn] = TRUE;
  151715. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151716. } else {
  151717. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151718. }
  151719. }
  151720. entropy->bitstate.bits_left = 0;
  151721. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151722. entropy->pub.insufficient_data = FALSE;
  151723. entropy->restarts_to_go = cinfo->restart_interval;
  151724. }
  151725. GLOBAL(void)
  151726. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151727. d_derived_tbl ** pdtbl)
  151728. {
  151729. JHUFF_TBL *htbl;
  151730. d_derived_tbl *dtbl;
  151731. int p, i, l, si, numsymbols;
  151732. int lookbits, ctr;
  151733. char huffsize[257];
  151734. unsigned int huffcode[257];
  151735. unsigned int code;
  151736. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151737. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151738. htbl =
  151739. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151740. if (htbl == NULL)
  151741. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151742. if (*pdtbl == NULL)
  151743. *pdtbl = (d_derived_tbl *)
  151744. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151745. SIZEOF(d_derived_tbl));
  151746. dtbl = *pdtbl;
  151747. dtbl->pub = htbl; /* fill in back link */
  151748. p = 0;
  151749. for (l = 1; l <= 16; l++) {
  151750. i = (int) htbl->bits[l];
  151751. if (i < 0 || p + i > 256) /* protect against table overrun */
  151752. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151753. while (i--)
  151754. huffsize[p++] = (char) l;
  151755. }
  151756. huffsize[p] = 0;
  151757. numsymbols = p;
  151758. code = 0;
  151759. si = huffsize[0];
  151760. p = 0;
  151761. while (huffsize[p]) {
  151762. while (((int) huffsize[p]) == si) {
  151763. huffcode[p++] = code;
  151764. code++;
  151765. }
  151766. if (((INT32) code) >= (((INT32) 1) << si))
  151767. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151768. code <<= 1;
  151769. si++;
  151770. }
  151771. p = 0;
  151772. for (l = 1; l <= 16; l++) {
  151773. if (htbl->bits[l]) {
  151774. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151775. p += htbl->bits[l];
  151776. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151777. } else {
  151778. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151779. }
  151780. }
  151781. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151782. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151783. p = 0;
  151784. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151785. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151786. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151787. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151788. dtbl->look_nbits[lookbits] = l;
  151789. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151790. lookbits++;
  151791. }
  151792. }
  151793. }
  151794. if (isDC) {
  151795. for (i = 0; i < numsymbols; i++) {
  151796. int sym = htbl->huffval[i];
  151797. if (sym < 0 || sym > 15)
  151798. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151799. }
  151800. }
  151801. }
  151802. #ifdef SLOW_SHIFT_32
  151803. #define MIN_GET_BITS 15 /* minimum allowable value */
  151804. #else
  151805. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151806. #endif
  151807. GLOBAL(boolean)
  151808. jpeg_fill_bit_buffer (bitread_working_state * state,
  151809. register bit_buf_type get_buffer, register int bits_left,
  151810. int nbits)
  151811. {
  151812. register const JOCTET * next_input_byte = state->next_input_byte;
  151813. register size_t bytes_in_buffer = state->bytes_in_buffer;
  151814. j_decompress_ptr cinfo = state->cinfo;
  151815. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  151816. while (bits_left < MIN_GET_BITS) {
  151817. register int c;
  151818. if (bytes_in_buffer == 0) {
  151819. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151820. return FALSE;
  151821. next_input_byte = cinfo->src->next_input_byte;
  151822. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151823. }
  151824. bytes_in_buffer--;
  151825. c = GETJOCTET(*next_input_byte++);
  151826. if (c == 0xFF) {
  151827. do {
  151828. if (bytes_in_buffer == 0) {
  151829. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151830. return FALSE;
  151831. next_input_byte = cinfo->src->next_input_byte;
  151832. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151833. }
  151834. bytes_in_buffer--;
  151835. c = GETJOCTET(*next_input_byte++);
  151836. } while (c == 0xFF);
  151837. if (c == 0) {
  151838. c = 0xFF;
  151839. } else {
  151840. cinfo->unread_marker = c;
  151841. goto no_more_bytes;
  151842. }
  151843. }
  151844. get_buffer = (get_buffer << 8) | c;
  151845. bits_left += 8;
  151846. } /* end while */
  151847. } else {
  151848. no_more_bytes:
  151849. if (nbits > bits_left) {
  151850. if (! cinfo->entropy->insufficient_data) {
  151851. WARNMS(cinfo, JWRN_HIT_MARKER);
  151852. cinfo->entropy->insufficient_data = TRUE;
  151853. }
  151854. get_buffer <<= MIN_GET_BITS - bits_left;
  151855. bits_left = MIN_GET_BITS;
  151856. }
  151857. }
  151858. state->next_input_byte = next_input_byte;
  151859. state->bytes_in_buffer = bytes_in_buffer;
  151860. state->get_buffer = get_buffer;
  151861. state->bits_left = bits_left;
  151862. return TRUE;
  151863. }
  151864. GLOBAL(int)
  151865. jpeg_huff_decode (bitread_working_state * state,
  151866. register bit_buf_type get_buffer, register int bits_left,
  151867. d_derived_tbl * htbl, int min_bits)
  151868. {
  151869. register int l = min_bits;
  151870. register INT32 code;
  151871. CHECK_BIT_BUFFER(*state, l, return -1);
  151872. code = GET_BITS(l);
  151873. while (code > htbl->maxcode[l]) {
  151874. code <<= 1;
  151875. CHECK_BIT_BUFFER(*state, 1, return -1);
  151876. code |= GET_BITS(1);
  151877. l++;
  151878. }
  151879. state->get_buffer = get_buffer;
  151880. state->bits_left = bits_left;
  151881. if (l > 16) {
  151882. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  151883. return 0; /* fake a zero as the safest result */
  151884. }
  151885. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  151886. }
  151887. LOCAL(boolean)
  151888. process_restart (j_decompress_ptr cinfo)
  151889. {
  151890. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151891. int ci;
  151892. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  151893. entropy->bitstate.bits_left = 0;
  151894. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  151895. return FALSE;
  151896. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  151897. entropy->saved.last_dc_val[ci] = 0;
  151898. entropy->restarts_to_go = cinfo->restart_interval;
  151899. if (cinfo->unread_marker == 0)
  151900. entropy->pub.insufficient_data = FALSE;
  151901. return TRUE;
  151902. }
  151903. METHODDEF(boolean)
  151904. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  151905. {
  151906. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151907. int blkn;
  151908. BITREAD_STATE_VARS;
  151909. savable_state2 state;
  151910. if (cinfo->restart_interval) {
  151911. if (entropy->restarts_to_go == 0)
  151912. if (! process_restart(cinfo))
  151913. return FALSE;
  151914. }
  151915. if (! entropy->pub.insufficient_data) {
  151916. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  151917. ASSIGN_STATE(state, entropy->saved);
  151918. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151919. JBLOCKROW block = MCU_data[blkn];
  151920. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  151921. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  151922. register int s, k, r;
  151923. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  151924. if (s) {
  151925. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151926. r = GET_BITS(s);
  151927. s = HUFF_EXTEND(r, s);
  151928. }
  151929. if (entropy->dc_needed[blkn]) {
  151930. int ci = cinfo->MCU_membership[blkn];
  151931. s += state.last_dc_val[ci];
  151932. state.last_dc_val[ci] = s;
  151933. (*block)[0] = (JCOEF) s;
  151934. }
  151935. if (entropy->ac_needed[blkn]) {
  151936. for (k = 1; k < DCTSIZE2; k++) {
  151937. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  151938. r = s >> 4;
  151939. s &= 15;
  151940. if (s) {
  151941. k += r;
  151942. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151943. r = GET_BITS(s);
  151944. s = HUFF_EXTEND(r, s);
  151945. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  151946. } else {
  151947. if (r != 15)
  151948. break;
  151949. k += 15;
  151950. }
  151951. }
  151952. } else {
  151953. for (k = 1; k < DCTSIZE2; k++) {
  151954. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  151955. r = s >> 4;
  151956. s &= 15;
  151957. if (s) {
  151958. k += r;
  151959. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151960. DROP_BITS(s);
  151961. } else {
  151962. if (r != 15)
  151963. break;
  151964. k += 15;
  151965. }
  151966. }
  151967. }
  151968. }
  151969. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  151970. ASSIGN_STATE(entropy->saved, state);
  151971. }
  151972. entropy->restarts_to_go--;
  151973. return TRUE;
  151974. }
  151975. GLOBAL(void)
  151976. jinit_huff_decoder (j_decompress_ptr cinfo)
  151977. {
  151978. huff_entropy_ptr2 entropy;
  151979. int i;
  151980. entropy = (huff_entropy_ptr2)
  151981. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151982. SIZEOF(huff_entropy_decoder2));
  151983. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  151984. entropy->pub.start_pass = start_pass_huff_decoder;
  151985. entropy->pub.decode_mcu = decode_mcu;
  151986. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  151987. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  151988. }
  151989. }
  151990. /*** End of inlined file: jdhuff.c ***/
  151991. /*** Start of inlined file: jdinput.c ***/
  151992. #define JPEG_INTERNALS
  151993. typedef struct {
  151994. struct jpeg_input_controller pub; /* public fields */
  151995. boolean inheaders; /* TRUE until first SOS is reached */
  151996. } my_input_controller;
  151997. typedef my_input_controller * my_inputctl_ptr;
  151998. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  151999. LOCAL(void)
  152000. initial_setup2 (j_decompress_ptr cinfo)
  152001. {
  152002. int ci;
  152003. jpeg_component_info *compptr;
  152004. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152005. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152006. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152007. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152008. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152009. if (cinfo->num_components > MAX_COMPONENTS)
  152010. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152011. MAX_COMPONENTS);
  152012. cinfo->max_h_samp_factor = 1;
  152013. cinfo->max_v_samp_factor = 1;
  152014. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152015. ci++, compptr++) {
  152016. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152017. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152018. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152019. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152020. compptr->h_samp_factor);
  152021. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152022. compptr->v_samp_factor);
  152023. }
  152024. cinfo->min_DCT_scaled_size = DCTSIZE;
  152025. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152026. ci++, compptr++) {
  152027. compptr->DCT_scaled_size = DCTSIZE;
  152028. compptr->width_in_blocks = (JDIMENSION)
  152029. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152030. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152031. compptr->height_in_blocks = (JDIMENSION)
  152032. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152033. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152034. compptr->downsampled_width = (JDIMENSION)
  152035. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152036. (long) cinfo->max_h_samp_factor);
  152037. compptr->downsampled_height = (JDIMENSION)
  152038. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152039. (long) cinfo->max_v_samp_factor);
  152040. compptr->component_needed = TRUE;
  152041. compptr->quant_table = NULL;
  152042. }
  152043. cinfo->total_iMCU_rows = (JDIMENSION)
  152044. jdiv_round_up((long) cinfo->image_height,
  152045. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152046. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152047. cinfo->inputctl->has_multiple_scans = TRUE;
  152048. else
  152049. cinfo->inputctl->has_multiple_scans = FALSE;
  152050. }
  152051. LOCAL(void)
  152052. per_scan_setup2 (j_decompress_ptr cinfo)
  152053. {
  152054. int ci, mcublks, tmp;
  152055. jpeg_component_info *compptr;
  152056. if (cinfo->comps_in_scan == 1) {
  152057. compptr = cinfo->cur_comp_info[0];
  152058. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152059. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152060. compptr->MCU_width = 1;
  152061. compptr->MCU_height = 1;
  152062. compptr->MCU_blocks = 1;
  152063. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152064. compptr->last_col_width = 1;
  152065. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152066. if (tmp == 0) tmp = compptr->v_samp_factor;
  152067. compptr->last_row_height = tmp;
  152068. cinfo->blocks_in_MCU = 1;
  152069. cinfo->MCU_membership[0] = 0;
  152070. } else {
  152071. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152072. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152073. MAX_COMPS_IN_SCAN);
  152074. cinfo->MCUs_per_row = (JDIMENSION)
  152075. jdiv_round_up((long) cinfo->image_width,
  152076. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152077. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152078. jdiv_round_up((long) cinfo->image_height,
  152079. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152080. cinfo->blocks_in_MCU = 0;
  152081. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152082. compptr = cinfo->cur_comp_info[ci];
  152083. compptr->MCU_width = compptr->h_samp_factor;
  152084. compptr->MCU_height = compptr->v_samp_factor;
  152085. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152086. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152087. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152088. if (tmp == 0) tmp = compptr->MCU_width;
  152089. compptr->last_col_width = tmp;
  152090. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152091. if (tmp == 0) tmp = compptr->MCU_height;
  152092. compptr->last_row_height = tmp;
  152093. mcublks = compptr->MCU_blocks;
  152094. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152095. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152096. while (mcublks-- > 0) {
  152097. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152098. }
  152099. }
  152100. }
  152101. }
  152102. LOCAL(void)
  152103. latch_quant_tables (j_decompress_ptr cinfo)
  152104. {
  152105. int ci, qtblno;
  152106. jpeg_component_info *compptr;
  152107. JQUANT_TBL * qtbl;
  152108. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152109. compptr = cinfo->cur_comp_info[ci];
  152110. if (compptr->quant_table != NULL)
  152111. continue;
  152112. qtblno = compptr->quant_tbl_no;
  152113. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152114. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152115. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152116. qtbl = (JQUANT_TBL *)
  152117. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152118. SIZEOF(JQUANT_TBL));
  152119. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152120. compptr->quant_table = qtbl;
  152121. }
  152122. }
  152123. METHODDEF(void)
  152124. start_input_pass2 (j_decompress_ptr cinfo)
  152125. {
  152126. per_scan_setup2(cinfo);
  152127. latch_quant_tables(cinfo);
  152128. (*cinfo->entropy->start_pass) (cinfo);
  152129. (*cinfo->coef->start_input_pass) (cinfo);
  152130. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152131. }
  152132. METHODDEF(void)
  152133. finish_input_pass (j_decompress_ptr cinfo)
  152134. {
  152135. cinfo->inputctl->consume_input = consume_markers;
  152136. }
  152137. METHODDEF(int)
  152138. consume_markers (j_decompress_ptr cinfo)
  152139. {
  152140. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152141. int val;
  152142. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152143. return JPEG_REACHED_EOI;
  152144. val = (*cinfo->marker->read_markers) (cinfo);
  152145. switch (val) {
  152146. case JPEG_REACHED_SOS: /* Found SOS */
  152147. if (inputctl->inheaders) { /* 1st SOS */
  152148. initial_setup2(cinfo);
  152149. inputctl->inheaders = FALSE;
  152150. } else { /* 2nd or later SOS marker */
  152151. if (! inputctl->pub.has_multiple_scans)
  152152. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152153. start_input_pass2(cinfo);
  152154. }
  152155. break;
  152156. case JPEG_REACHED_EOI: /* Found EOI */
  152157. inputctl->pub.eoi_reached = TRUE;
  152158. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152159. if (cinfo->marker->saw_SOF)
  152160. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152161. } else {
  152162. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152163. cinfo->output_scan_number = cinfo->input_scan_number;
  152164. }
  152165. break;
  152166. case JPEG_SUSPENDED:
  152167. break;
  152168. }
  152169. return val;
  152170. }
  152171. METHODDEF(void)
  152172. reset_input_controller (j_decompress_ptr cinfo)
  152173. {
  152174. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152175. inputctl->pub.consume_input = consume_markers;
  152176. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152177. inputctl->pub.eoi_reached = FALSE;
  152178. inputctl->inheaders = TRUE;
  152179. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152180. (*cinfo->marker->reset_marker_reader) (cinfo);
  152181. cinfo->coef_bits = NULL;
  152182. }
  152183. GLOBAL(void)
  152184. jinit_input_controller (j_decompress_ptr cinfo)
  152185. {
  152186. my_inputctl_ptr inputctl;
  152187. inputctl = (my_inputctl_ptr)
  152188. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152189. SIZEOF(my_input_controller));
  152190. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152191. inputctl->pub.consume_input = consume_markers;
  152192. inputctl->pub.reset_input_controller = reset_input_controller;
  152193. inputctl->pub.start_input_pass = start_input_pass2;
  152194. inputctl->pub.finish_input_pass = finish_input_pass;
  152195. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152196. inputctl->pub.eoi_reached = FALSE;
  152197. inputctl->inheaders = TRUE;
  152198. }
  152199. /*** End of inlined file: jdinput.c ***/
  152200. /*** Start of inlined file: jdmainct.c ***/
  152201. #define JPEG_INTERNALS
  152202. typedef struct {
  152203. struct jpeg_d_main_controller pub; /* public fields */
  152204. JSAMPARRAY buffer[MAX_COMPONENTS];
  152205. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152206. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152207. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152208. int whichptr; /* indicates which pointer set is now in use */
  152209. int context_state; /* process_data state machine status */
  152210. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152211. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152212. } my_main_controller4;
  152213. typedef my_main_controller4 * my_main_ptr4;
  152214. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152215. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152216. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152217. METHODDEF(void) process_data_simple_main2
  152218. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152219. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152220. METHODDEF(void) process_data_context_main
  152221. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152222. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152223. #ifdef QUANT_2PASS_SUPPORTED
  152224. METHODDEF(void) process_data_crank_post
  152225. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152226. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152227. #endif
  152228. LOCAL(void)
  152229. alloc_funny_pointers (j_decompress_ptr cinfo)
  152230. {
  152231. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152232. int ci, rgroup;
  152233. int M = cinfo->min_DCT_scaled_size;
  152234. jpeg_component_info *compptr;
  152235. JSAMPARRAY xbuf;
  152236. main_->xbuffer[0] = (JSAMPIMAGE)
  152237. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152238. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152239. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152240. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152241. ci++, compptr++) {
  152242. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152243. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152244. xbuf = (JSAMPARRAY)
  152245. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152246. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152247. xbuf += rgroup; /* want one row group at negative offsets */
  152248. main_->xbuffer[0][ci] = xbuf;
  152249. xbuf += rgroup * (M + 4);
  152250. main_->xbuffer[1][ci] = xbuf;
  152251. }
  152252. }
  152253. LOCAL(void)
  152254. make_funny_pointers (j_decompress_ptr cinfo)
  152255. {
  152256. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152257. int ci, i, rgroup;
  152258. int M = cinfo->min_DCT_scaled_size;
  152259. jpeg_component_info *compptr;
  152260. JSAMPARRAY buf, xbuf0, xbuf1;
  152261. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152262. ci++, compptr++) {
  152263. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152264. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152265. xbuf0 = main_->xbuffer[0][ci];
  152266. xbuf1 = main_->xbuffer[1][ci];
  152267. buf = main_->buffer[ci];
  152268. for (i = 0; i < rgroup * (M + 2); i++) {
  152269. xbuf0[i] = xbuf1[i] = buf[i];
  152270. }
  152271. for (i = 0; i < rgroup * 2; i++) {
  152272. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152273. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152274. }
  152275. for (i = 0; i < rgroup; i++) {
  152276. xbuf0[i - rgroup] = xbuf0[0];
  152277. }
  152278. }
  152279. }
  152280. LOCAL(void)
  152281. set_wraparound_pointers (j_decompress_ptr cinfo)
  152282. {
  152283. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152284. int ci, i, rgroup;
  152285. int M = cinfo->min_DCT_scaled_size;
  152286. jpeg_component_info *compptr;
  152287. JSAMPARRAY xbuf0, xbuf1;
  152288. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152289. ci++, compptr++) {
  152290. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152291. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152292. xbuf0 = main_->xbuffer[0][ci];
  152293. xbuf1 = main_->xbuffer[1][ci];
  152294. for (i = 0; i < rgroup; i++) {
  152295. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152296. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152297. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152298. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152299. }
  152300. }
  152301. }
  152302. LOCAL(void)
  152303. set_bottom_pointers (j_decompress_ptr cinfo)
  152304. {
  152305. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152306. int ci, i, rgroup, iMCUheight, rows_left;
  152307. jpeg_component_info *compptr;
  152308. JSAMPARRAY xbuf;
  152309. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152310. ci++, compptr++) {
  152311. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152312. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152313. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152314. if (rows_left == 0) rows_left = iMCUheight;
  152315. if (ci == 0) {
  152316. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152317. }
  152318. xbuf = main_->xbuffer[main_->whichptr][ci];
  152319. for (i = 0; i < rgroup * 2; i++) {
  152320. xbuf[rows_left + i] = xbuf[rows_left-1];
  152321. }
  152322. }
  152323. }
  152324. METHODDEF(void)
  152325. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152326. {
  152327. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152328. switch (pass_mode) {
  152329. case JBUF_PASS_THRU:
  152330. if (cinfo->upsample->need_context_rows) {
  152331. main_->pub.process_data = process_data_context_main;
  152332. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152333. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152334. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152335. main_->iMCU_row_ctr = 0;
  152336. } else {
  152337. main_->pub.process_data = process_data_simple_main2;
  152338. }
  152339. main_->buffer_full = FALSE; /* Mark buffer empty */
  152340. main_->rowgroup_ctr = 0;
  152341. break;
  152342. #ifdef QUANT_2PASS_SUPPORTED
  152343. case JBUF_CRANK_DEST:
  152344. main_->pub.process_data = process_data_crank_post;
  152345. break;
  152346. #endif
  152347. default:
  152348. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152349. break;
  152350. }
  152351. }
  152352. METHODDEF(void)
  152353. process_data_simple_main2 (j_decompress_ptr cinfo,
  152354. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152355. JDIMENSION out_rows_avail)
  152356. {
  152357. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152358. JDIMENSION rowgroups_avail;
  152359. if (! main_->buffer_full) {
  152360. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152361. return; /* suspension forced, can do nothing more */
  152362. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152363. }
  152364. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152365. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152366. &main_->rowgroup_ctr, rowgroups_avail,
  152367. output_buf, out_row_ctr, out_rows_avail);
  152368. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152369. main_->buffer_full = FALSE;
  152370. main_->rowgroup_ctr = 0;
  152371. }
  152372. }
  152373. METHODDEF(void)
  152374. process_data_context_main (j_decompress_ptr cinfo,
  152375. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152376. JDIMENSION out_rows_avail)
  152377. {
  152378. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152379. if (! main_->buffer_full) {
  152380. if (! (*cinfo->coef->decompress_data) (cinfo,
  152381. main_->xbuffer[main_->whichptr]))
  152382. return; /* suspension forced, can do nothing more */
  152383. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152384. main_->iMCU_row_ctr++; /* count rows received */
  152385. }
  152386. switch (main_->context_state) {
  152387. case CTX_POSTPONED_ROW:
  152388. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152389. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152390. output_buf, out_row_ctr, out_rows_avail);
  152391. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152392. return; /* Need to suspend */
  152393. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152394. if (*out_row_ctr >= out_rows_avail)
  152395. return; /* Postprocessor exactly filled output buf */
  152396. case CTX_PREPARE_FOR_IMCU:
  152397. main_->rowgroup_ctr = 0;
  152398. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152399. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152400. set_bottom_pointers(cinfo);
  152401. main_->context_state = CTX_PROCESS_IMCU;
  152402. case CTX_PROCESS_IMCU:
  152403. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152404. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152405. output_buf, out_row_ctr, out_rows_avail);
  152406. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152407. return; /* Need to suspend */
  152408. if (main_->iMCU_row_ctr == 1)
  152409. set_wraparound_pointers(cinfo);
  152410. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152411. main_->buffer_full = FALSE;
  152412. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152413. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152414. main_->context_state = CTX_POSTPONED_ROW;
  152415. }
  152416. }
  152417. #ifdef QUANT_2PASS_SUPPORTED
  152418. METHODDEF(void)
  152419. process_data_crank_post (j_decompress_ptr cinfo,
  152420. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152421. JDIMENSION out_rows_avail)
  152422. {
  152423. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152424. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152425. output_buf, out_row_ctr, out_rows_avail);
  152426. }
  152427. #endif /* QUANT_2PASS_SUPPORTED */
  152428. GLOBAL(void)
  152429. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152430. {
  152431. my_main_ptr4 main_;
  152432. int ci, rgroup, ngroups;
  152433. jpeg_component_info *compptr;
  152434. main_ = (my_main_ptr4)
  152435. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152436. SIZEOF(my_main_controller4));
  152437. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152438. main_->pub.start_pass = start_pass_main2;
  152439. if (need_full_buffer) /* shouldn't happen */
  152440. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152441. if (cinfo->upsample->need_context_rows) {
  152442. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152443. ERREXIT(cinfo, JERR_NOTIMPL);
  152444. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152445. ngroups = cinfo->min_DCT_scaled_size + 2;
  152446. } else {
  152447. ngroups = cinfo->min_DCT_scaled_size;
  152448. }
  152449. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152450. ci++, compptr++) {
  152451. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152452. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152453. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152454. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152455. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152456. (JDIMENSION) (rgroup * ngroups));
  152457. }
  152458. }
  152459. /*** End of inlined file: jdmainct.c ***/
  152460. /*** Start of inlined file: jdmarker.c ***/
  152461. #define JPEG_INTERNALS
  152462. typedef struct {
  152463. struct jpeg_marker_reader pub; /* public fields */
  152464. jpeg_marker_parser_method process_COM;
  152465. jpeg_marker_parser_method process_APPn[16];
  152466. unsigned int length_limit_COM;
  152467. unsigned int length_limit_APPn[16];
  152468. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152469. unsigned int bytes_read; /* data bytes read so far in marker */
  152470. } my_marker_reader;
  152471. typedef my_marker_reader * my_marker_ptr2;
  152472. #define INPUT_VARS(cinfo) \
  152473. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152474. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152475. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152476. #define INPUT_SYNC(cinfo) \
  152477. ( datasrc->next_input_byte = next_input_byte, \
  152478. datasrc->bytes_in_buffer = bytes_in_buffer )
  152479. #define INPUT_RELOAD(cinfo) \
  152480. ( next_input_byte = datasrc->next_input_byte, \
  152481. bytes_in_buffer = datasrc->bytes_in_buffer )
  152482. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152483. if (bytes_in_buffer == 0) { \
  152484. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152485. { action; } \
  152486. INPUT_RELOAD(cinfo); \
  152487. }
  152488. #define INPUT_BYTE(cinfo,V,action) \
  152489. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152490. bytes_in_buffer--; \
  152491. V = GETJOCTET(*next_input_byte++); )
  152492. #define INPUT_2BYTES(cinfo,V,action) \
  152493. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152494. bytes_in_buffer--; \
  152495. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152496. MAKE_BYTE_AVAIL(cinfo,action); \
  152497. bytes_in_buffer--; \
  152498. V += GETJOCTET(*next_input_byte++); )
  152499. LOCAL(boolean)
  152500. get_soi (j_decompress_ptr cinfo)
  152501. {
  152502. int i;
  152503. TRACEMS(cinfo, 1, JTRC_SOI);
  152504. if (cinfo->marker->saw_SOI)
  152505. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152506. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152507. cinfo->arith_dc_L[i] = 0;
  152508. cinfo->arith_dc_U[i] = 1;
  152509. cinfo->arith_ac_K[i] = 5;
  152510. }
  152511. cinfo->restart_interval = 0;
  152512. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152513. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152514. cinfo->saw_JFIF_marker = FALSE;
  152515. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152516. cinfo->JFIF_minor_version = 1;
  152517. cinfo->density_unit = 0;
  152518. cinfo->X_density = 1;
  152519. cinfo->Y_density = 1;
  152520. cinfo->saw_Adobe_marker = FALSE;
  152521. cinfo->Adobe_transform = 0;
  152522. cinfo->marker->saw_SOI = TRUE;
  152523. return TRUE;
  152524. }
  152525. LOCAL(boolean)
  152526. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152527. {
  152528. INT32 length;
  152529. int c, ci;
  152530. jpeg_component_info * compptr;
  152531. INPUT_VARS(cinfo);
  152532. cinfo->progressive_mode = is_prog;
  152533. cinfo->arith_code = is_arith;
  152534. INPUT_2BYTES(cinfo, length, return FALSE);
  152535. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152536. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152537. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152538. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152539. length -= 8;
  152540. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152541. (int) cinfo->image_width, (int) cinfo->image_height,
  152542. cinfo->num_components);
  152543. if (cinfo->marker->saw_SOF)
  152544. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152545. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152546. || cinfo->num_components <= 0)
  152547. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152548. if (length != (cinfo->num_components * 3))
  152549. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152550. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152551. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152552. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152553. cinfo->num_components * SIZEOF(jpeg_component_info));
  152554. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152555. ci++, compptr++) {
  152556. compptr->component_index = ci;
  152557. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152558. INPUT_BYTE(cinfo, c, return FALSE);
  152559. compptr->h_samp_factor = (c >> 4) & 15;
  152560. compptr->v_samp_factor = (c ) & 15;
  152561. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152562. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152563. compptr->component_id, compptr->h_samp_factor,
  152564. compptr->v_samp_factor, compptr->quant_tbl_no);
  152565. }
  152566. cinfo->marker->saw_SOF = TRUE;
  152567. INPUT_SYNC(cinfo);
  152568. return TRUE;
  152569. }
  152570. LOCAL(boolean)
  152571. get_sos (j_decompress_ptr cinfo)
  152572. {
  152573. INT32 length;
  152574. int i, ci, n, c, cc;
  152575. jpeg_component_info * compptr;
  152576. INPUT_VARS(cinfo);
  152577. if (! cinfo->marker->saw_SOF)
  152578. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152579. INPUT_2BYTES(cinfo, length, return FALSE);
  152580. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152581. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152582. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152583. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152584. cinfo->comps_in_scan = n;
  152585. for (i = 0; i < n; i++) {
  152586. INPUT_BYTE(cinfo, cc, return FALSE);
  152587. INPUT_BYTE(cinfo, c, return FALSE);
  152588. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152589. ci++, compptr++) {
  152590. if (cc == compptr->component_id)
  152591. goto id_found;
  152592. }
  152593. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152594. id_found:
  152595. cinfo->cur_comp_info[i] = compptr;
  152596. compptr->dc_tbl_no = (c >> 4) & 15;
  152597. compptr->ac_tbl_no = (c ) & 15;
  152598. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152599. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152600. }
  152601. INPUT_BYTE(cinfo, c, return FALSE);
  152602. cinfo->Ss = c;
  152603. INPUT_BYTE(cinfo, c, return FALSE);
  152604. cinfo->Se = c;
  152605. INPUT_BYTE(cinfo, c, return FALSE);
  152606. cinfo->Ah = (c >> 4) & 15;
  152607. cinfo->Al = (c ) & 15;
  152608. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152609. cinfo->Ah, cinfo->Al);
  152610. cinfo->marker->next_restart_num = 0;
  152611. cinfo->input_scan_number++;
  152612. INPUT_SYNC(cinfo);
  152613. return TRUE;
  152614. }
  152615. #ifdef D_ARITH_CODING_SUPPORTED
  152616. LOCAL(boolean)
  152617. get_dac (j_decompress_ptr cinfo)
  152618. {
  152619. INT32 length;
  152620. int index, val;
  152621. INPUT_VARS(cinfo);
  152622. INPUT_2BYTES(cinfo, length, return FALSE);
  152623. length -= 2;
  152624. while (length > 0) {
  152625. INPUT_BYTE(cinfo, index, return FALSE);
  152626. INPUT_BYTE(cinfo, val, return FALSE);
  152627. length -= 2;
  152628. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152629. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152630. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152631. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152632. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152633. } else { /* define DC table */
  152634. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152635. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152636. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152637. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152638. }
  152639. }
  152640. if (length != 0)
  152641. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152642. INPUT_SYNC(cinfo);
  152643. return TRUE;
  152644. }
  152645. #else /* ! D_ARITH_CODING_SUPPORTED */
  152646. #define get_dac(cinfo) skip_variable(cinfo)
  152647. #endif /* D_ARITH_CODING_SUPPORTED */
  152648. LOCAL(boolean)
  152649. get_dht (j_decompress_ptr cinfo)
  152650. {
  152651. INT32 length;
  152652. UINT8 bits[17];
  152653. UINT8 huffval[256];
  152654. int i, index, count;
  152655. JHUFF_TBL **htblptr;
  152656. INPUT_VARS(cinfo);
  152657. INPUT_2BYTES(cinfo, length, return FALSE);
  152658. length -= 2;
  152659. while (length > 16) {
  152660. INPUT_BYTE(cinfo, index, return FALSE);
  152661. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152662. bits[0] = 0;
  152663. count = 0;
  152664. for (i = 1; i <= 16; i++) {
  152665. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152666. count += bits[i];
  152667. }
  152668. length -= 1 + 16;
  152669. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152670. bits[1], bits[2], bits[3], bits[4],
  152671. bits[5], bits[6], bits[7], bits[8]);
  152672. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152673. bits[9], bits[10], bits[11], bits[12],
  152674. bits[13], bits[14], bits[15], bits[16]);
  152675. if (count > 256 || ((INT32) count) > length)
  152676. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152677. for (i = 0; i < count; i++)
  152678. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152679. length -= count;
  152680. if (index & 0x10) { /* AC table definition */
  152681. index -= 0x10;
  152682. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152683. } else { /* DC table definition */
  152684. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152685. }
  152686. if (index < 0 || index >= NUM_HUFF_TBLS)
  152687. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152688. if (*htblptr == NULL)
  152689. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152690. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152691. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152692. }
  152693. if (length != 0)
  152694. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152695. INPUT_SYNC(cinfo);
  152696. return TRUE;
  152697. }
  152698. LOCAL(boolean)
  152699. get_dqt (j_decompress_ptr cinfo)
  152700. {
  152701. INT32 length;
  152702. int n, i, prec;
  152703. unsigned int tmp;
  152704. JQUANT_TBL *quant_ptr;
  152705. INPUT_VARS(cinfo);
  152706. INPUT_2BYTES(cinfo, length, return FALSE);
  152707. length -= 2;
  152708. while (length > 0) {
  152709. INPUT_BYTE(cinfo, n, return FALSE);
  152710. prec = n >> 4;
  152711. n &= 0x0F;
  152712. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152713. if (n >= NUM_QUANT_TBLS)
  152714. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152715. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152716. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152717. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152718. for (i = 0; i < DCTSIZE2; i++) {
  152719. if (prec)
  152720. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152721. else
  152722. INPUT_BYTE(cinfo, tmp, return FALSE);
  152723. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152724. }
  152725. if (cinfo->err->trace_level >= 2) {
  152726. for (i = 0; i < DCTSIZE2; i += 8) {
  152727. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152728. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152729. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152730. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152731. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152732. }
  152733. }
  152734. length -= DCTSIZE2+1;
  152735. if (prec) length -= DCTSIZE2;
  152736. }
  152737. if (length != 0)
  152738. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152739. INPUT_SYNC(cinfo);
  152740. return TRUE;
  152741. }
  152742. LOCAL(boolean)
  152743. get_dri (j_decompress_ptr cinfo)
  152744. {
  152745. INT32 length;
  152746. unsigned int tmp;
  152747. INPUT_VARS(cinfo);
  152748. INPUT_2BYTES(cinfo, length, return FALSE);
  152749. if (length != 4)
  152750. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152751. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152752. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152753. cinfo->restart_interval = tmp;
  152754. INPUT_SYNC(cinfo);
  152755. return TRUE;
  152756. }
  152757. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152758. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152759. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152760. LOCAL(void)
  152761. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152762. unsigned int datalen, INT32 remaining)
  152763. {
  152764. INT32 totallen = (INT32) datalen + remaining;
  152765. if (datalen >= APP0_DATA_LEN &&
  152766. GETJOCTET(data[0]) == 0x4A &&
  152767. GETJOCTET(data[1]) == 0x46 &&
  152768. GETJOCTET(data[2]) == 0x49 &&
  152769. GETJOCTET(data[3]) == 0x46 &&
  152770. GETJOCTET(data[4]) == 0) {
  152771. cinfo->saw_JFIF_marker = TRUE;
  152772. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152773. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152774. cinfo->density_unit = GETJOCTET(data[7]);
  152775. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152776. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152777. if (cinfo->JFIF_major_version != 1)
  152778. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152779. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152780. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152781. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152782. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152783. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152784. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152785. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152786. totallen -= APP0_DATA_LEN;
  152787. if (totallen !=
  152788. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152789. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152790. } else if (datalen >= 6 &&
  152791. GETJOCTET(data[0]) == 0x4A &&
  152792. GETJOCTET(data[1]) == 0x46 &&
  152793. GETJOCTET(data[2]) == 0x58 &&
  152794. GETJOCTET(data[3]) == 0x58 &&
  152795. GETJOCTET(data[4]) == 0) {
  152796. switch (GETJOCTET(data[5])) {
  152797. case 0x10:
  152798. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152799. break;
  152800. case 0x11:
  152801. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152802. break;
  152803. case 0x13:
  152804. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152805. break;
  152806. default:
  152807. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152808. GETJOCTET(data[5]), (int) totallen);
  152809. break;
  152810. }
  152811. } else {
  152812. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  152813. }
  152814. }
  152815. LOCAL(void)
  152816. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152817. unsigned int datalen, INT32 remaining)
  152818. {
  152819. unsigned int version, flags0, flags1, transform;
  152820. if (datalen >= APP14_DATA_LEN &&
  152821. GETJOCTET(data[0]) == 0x41 &&
  152822. GETJOCTET(data[1]) == 0x64 &&
  152823. GETJOCTET(data[2]) == 0x6F &&
  152824. GETJOCTET(data[3]) == 0x62 &&
  152825. GETJOCTET(data[4]) == 0x65) {
  152826. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  152827. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  152828. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  152829. transform = GETJOCTET(data[11]);
  152830. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  152831. cinfo->saw_Adobe_marker = TRUE;
  152832. cinfo->Adobe_transform = (UINT8) transform;
  152833. } else {
  152834. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  152835. }
  152836. }
  152837. METHODDEF(boolean)
  152838. get_interesting_appn (j_decompress_ptr cinfo)
  152839. {
  152840. INT32 length;
  152841. JOCTET b[APPN_DATA_LEN];
  152842. unsigned int i, numtoread;
  152843. INPUT_VARS(cinfo);
  152844. INPUT_2BYTES(cinfo, length, return FALSE);
  152845. length -= 2;
  152846. if (length >= APPN_DATA_LEN)
  152847. numtoread = APPN_DATA_LEN;
  152848. else if (length > 0)
  152849. numtoread = (unsigned int) length;
  152850. else
  152851. numtoread = 0;
  152852. for (i = 0; i < numtoread; i++)
  152853. INPUT_BYTE(cinfo, b[i], return FALSE);
  152854. length -= numtoread;
  152855. switch (cinfo->unread_marker) {
  152856. case M_APP0:
  152857. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  152858. break;
  152859. case M_APP14:
  152860. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  152861. break;
  152862. default:
  152863. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  152864. break;
  152865. }
  152866. INPUT_SYNC(cinfo);
  152867. if (length > 0)
  152868. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152869. return TRUE;
  152870. }
  152871. #ifdef SAVE_MARKERS_SUPPORTED
  152872. METHODDEF(boolean)
  152873. save_marker (j_decompress_ptr cinfo)
  152874. {
  152875. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  152876. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  152877. unsigned int bytes_read, data_length;
  152878. JOCTET FAR * data;
  152879. INT32 length = 0;
  152880. INPUT_VARS(cinfo);
  152881. if (cur_marker == NULL) {
  152882. INPUT_2BYTES(cinfo, length, return FALSE);
  152883. length -= 2;
  152884. if (length >= 0) { /* watch out for bogus length word */
  152885. unsigned int limit;
  152886. if (cinfo->unread_marker == (int) M_COM)
  152887. limit = marker->length_limit_COM;
  152888. else
  152889. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  152890. if ((unsigned int) length < limit)
  152891. limit = (unsigned int) length;
  152892. cur_marker = (jpeg_saved_marker_ptr)
  152893. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152894. SIZEOF(struct jpeg_marker_struct) + limit);
  152895. cur_marker->next = NULL;
  152896. cur_marker->marker = (UINT8) cinfo->unread_marker;
  152897. cur_marker->original_length = (unsigned int) length;
  152898. cur_marker->data_length = limit;
  152899. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  152900. marker->cur_marker = cur_marker;
  152901. marker->bytes_read = 0;
  152902. bytes_read = 0;
  152903. data_length = limit;
  152904. } else {
  152905. bytes_read = data_length = 0;
  152906. data = NULL;
  152907. }
  152908. } else {
  152909. bytes_read = marker->bytes_read;
  152910. data_length = cur_marker->data_length;
  152911. data = cur_marker->data + bytes_read;
  152912. }
  152913. while (bytes_read < data_length) {
  152914. INPUT_SYNC(cinfo); /* move the restart point to here */
  152915. marker->bytes_read = bytes_read;
  152916. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  152917. while (bytes_read < data_length && bytes_in_buffer > 0) {
  152918. *data++ = *next_input_byte++;
  152919. bytes_in_buffer--;
  152920. bytes_read++;
  152921. }
  152922. }
  152923. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  152924. if (cinfo->marker_list == NULL) {
  152925. cinfo->marker_list = cur_marker;
  152926. } else {
  152927. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  152928. while (prev->next != NULL)
  152929. prev = prev->next;
  152930. prev->next = cur_marker;
  152931. }
  152932. data = cur_marker->data;
  152933. length = cur_marker->original_length - data_length;
  152934. }
  152935. marker->cur_marker = NULL;
  152936. switch (cinfo->unread_marker) {
  152937. case M_APP0:
  152938. examine_app0(cinfo, data, data_length, length);
  152939. break;
  152940. case M_APP14:
  152941. examine_app14(cinfo, data, data_length, length);
  152942. break;
  152943. default:
  152944. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  152945. (int) (data_length + length));
  152946. break;
  152947. }
  152948. INPUT_SYNC(cinfo); /* do before skip_input_data */
  152949. if (length > 0)
  152950. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152951. return TRUE;
  152952. }
  152953. #endif /* SAVE_MARKERS_SUPPORTED */
  152954. METHODDEF(boolean)
  152955. skip_variable (j_decompress_ptr cinfo)
  152956. {
  152957. INT32 length;
  152958. INPUT_VARS(cinfo);
  152959. INPUT_2BYTES(cinfo, length, return FALSE);
  152960. length -= 2;
  152961. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  152962. INPUT_SYNC(cinfo); /* do before skip_input_data */
  152963. if (length > 0)
  152964. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152965. return TRUE;
  152966. }
  152967. LOCAL(boolean)
  152968. next_marker (j_decompress_ptr cinfo)
  152969. {
  152970. int c;
  152971. INPUT_VARS(cinfo);
  152972. for (;;) {
  152973. INPUT_BYTE(cinfo, c, return FALSE);
  152974. while (c != 0xFF) {
  152975. cinfo->marker->discarded_bytes++;
  152976. INPUT_SYNC(cinfo);
  152977. INPUT_BYTE(cinfo, c, return FALSE);
  152978. }
  152979. do {
  152980. INPUT_BYTE(cinfo, c, return FALSE);
  152981. } while (c == 0xFF);
  152982. if (c != 0)
  152983. break; /* found a valid marker, exit loop */
  152984. cinfo->marker->discarded_bytes += 2;
  152985. INPUT_SYNC(cinfo);
  152986. }
  152987. if (cinfo->marker->discarded_bytes != 0) {
  152988. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  152989. cinfo->marker->discarded_bytes = 0;
  152990. }
  152991. cinfo->unread_marker = c;
  152992. INPUT_SYNC(cinfo);
  152993. return TRUE;
  152994. }
  152995. LOCAL(boolean)
  152996. first_marker (j_decompress_ptr cinfo)
  152997. {
  152998. int c, c2;
  152999. INPUT_VARS(cinfo);
  153000. INPUT_BYTE(cinfo, c, return FALSE);
  153001. INPUT_BYTE(cinfo, c2, return FALSE);
  153002. if (c != 0xFF || c2 != (int) M_SOI)
  153003. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153004. cinfo->unread_marker = c2;
  153005. INPUT_SYNC(cinfo);
  153006. return TRUE;
  153007. }
  153008. METHODDEF(int)
  153009. read_markers (j_decompress_ptr cinfo)
  153010. {
  153011. for (;;) {
  153012. if (cinfo->unread_marker == 0) {
  153013. if (! cinfo->marker->saw_SOI) {
  153014. if (! first_marker(cinfo))
  153015. return JPEG_SUSPENDED;
  153016. } else {
  153017. if (! next_marker(cinfo))
  153018. return JPEG_SUSPENDED;
  153019. }
  153020. }
  153021. switch (cinfo->unread_marker) {
  153022. case M_SOI:
  153023. if (! get_soi(cinfo))
  153024. return JPEG_SUSPENDED;
  153025. break;
  153026. case M_SOF0: /* Baseline */
  153027. case M_SOF1: /* Extended sequential, Huffman */
  153028. if (! get_sof(cinfo, FALSE, FALSE))
  153029. return JPEG_SUSPENDED;
  153030. break;
  153031. case M_SOF2: /* Progressive, Huffman */
  153032. if (! get_sof(cinfo, TRUE, FALSE))
  153033. return JPEG_SUSPENDED;
  153034. break;
  153035. case M_SOF9: /* Extended sequential, arithmetic */
  153036. if (! get_sof(cinfo, FALSE, TRUE))
  153037. return JPEG_SUSPENDED;
  153038. break;
  153039. case M_SOF10: /* Progressive, arithmetic */
  153040. if (! get_sof(cinfo, TRUE, TRUE))
  153041. return JPEG_SUSPENDED;
  153042. break;
  153043. case M_SOF3: /* Lossless, Huffman */
  153044. case M_SOF5: /* Differential sequential, Huffman */
  153045. case M_SOF6: /* Differential progressive, Huffman */
  153046. case M_SOF7: /* Differential lossless, Huffman */
  153047. case M_JPG: /* Reserved for JPEG extensions */
  153048. case M_SOF11: /* Lossless, arithmetic */
  153049. case M_SOF13: /* Differential sequential, arithmetic */
  153050. case M_SOF14: /* Differential progressive, arithmetic */
  153051. case M_SOF15: /* Differential lossless, arithmetic */
  153052. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153053. break;
  153054. case M_SOS:
  153055. if (! get_sos(cinfo))
  153056. return JPEG_SUSPENDED;
  153057. cinfo->unread_marker = 0; /* processed the marker */
  153058. return JPEG_REACHED_SOS;
  153059. case M_EOI:
  153060. TRACEMS(cinfo, 1, JTRC_EOI);
  153061. cinfo->unread_marker = 0; /* processed the marker */
  153062. return JPEG_REACHED_EOI;
  153063. case M_DAC:
  153064. if (! get_dac(cinfo))
  153065. return JPEG_SUSPENDED;
  153066. break;
  153067. case M_DHT:
  153068. if (! get_dht(cinfo))
  153069. return JPEG_SUSPENDED;
  153070. break;
  153071. case M_DQT:
  153072. if (! get_dqt(cinfo))
  153073. return JPEG_SUSPENDED;
  153074. break;
  153075. case M_DRI:
  153076. if (! get_dri(cinfo))
  153077. return JPEG_SUSPENDED;
  153078. break;
  153079. case M_APP0:
  153080. case M_APP1:
  153081. case M_APP2:
  153082. case M_APP3:
  153083. case M_APP4:
  153084. case M_APP5:
  153085. case M_APP6:
  153086. case M_APP7:
  153087. case M_APP8:
  153088. case M_APP9:
  153089. case M_APP10:
  153090. case M_APP11:
  153091. case M_APP12:
  153092. case M_APP13:
  153093. case M_APP14:
  153094. case M_APP15:
  153095. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153096. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153097. return JPEG_SUSPENDED;
  153098. break;
  153099. case M_COM:
  153100. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153101. return JPEG_SUSPENDED;
  153102. break;
  153103. case M_RST0: /* these are all parameterless */
  153104. case M_RST1:
  153105. case M_RST2:
  153106. case M_RST3:
  153107. case M_RST4:
  153108. case M_RST5:
  153109. case M_RST6:
  153110. case M_RST7:
  153111. case M_TEM:
  153112. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153113. break;
  153114. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153115. if (! skip_variable(cinfo))
  153116. return JPEG_SUSPENDED;
  153117. break;
  153118. default: /* must be DHP, EXP, JPGn, or RESn */
  153119. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153120. break;
  153121. }
  153122. cinfo->unread_marker = 0;
  153123. } /* end loop */
  153124. }
  153125. METHODDEF(boolean)
  153126. read_restart_marker (j_decompress_ptr cinfo)
  153127. {
  153128. if (cinfo->unread_marker == 0) {
  153129. if (! next_marker(cinfo))
  153130. return FALSE;
  153131. }
  153132. if (cinfo->unread_marker ==
  153133. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153134. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153135. cinfo->unread_marker = 0;
  153136. } else {
  153137. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153138. cinfo->marker->next_restart_num))
  153139. return FALSE;
  153140. }
  153141. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153142. return TRUE;
  153143. }
  153144. GLOBAL(boolean)
  153145. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153146. {
  153147. int marker = cinfo->unread_marker;
  153148. int action = 1;
  153149. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153150. for (;;) {
  153151. if (marker < (int) M_SOF0)
  153152. action = 2; /* invalid marker */
  153153. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153154. action = 3; /* valid non-restart marker */
  153155. else {
  153156. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153157. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153158. action = 3; /* one of the next two expected restarts */
  153159. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153160. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153161. action = 2; /* a prior restart, so advance */
  153162. else
  153163. action = 1; /* desired restart or too far away */
  153164. }
  153165. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153166. switch (action) {
  153167. case 1:
  153168. cinfo->unread_marker = 0;
  153169. return TRUE;
  153170. case 2:
  153171. if (! next_marker(cinfo))
  153172. return FALSE;
  153173. marker = cinfo->unread_marker;
  153174. break;
  153175. case 3:
  153176. return TRUE;
  153177. }
  153178. } /* end loop */
  153179. }
  153180. METHODDEF(void)
  153181. reset_marker_reader (j_decompress_ptr cinfo)
  153182. {
  153183. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153184. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153185. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153186. cinfo->unread_marker = 0; /* no pending marker */
  153187. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153188. marker->pub.saw_SOF = FALSE;
  153189. marker->pub.discarded_bytes = 0;
  153190. marker->cur_marker = NULL;
  153191. }
  153192. GLOBAL(void)
  153193. jinit_marker_reader (j_decompress_ptr cinfo)
  153194. {
  153195. my_marker_ptr2 marker;
  153196. int i;
  153197. marker = (my_marker_ptr2)
  153198. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153199. SIZEOF(my_marker_reader));
  153200. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153201. marker->pub.reset_marker_reader = reset_marker_reader;
  153202. marker->pub.read_markers = read_markers;
  153203. marker->pub.read_restart_marker = read_restart_marker;
  153204. marker->process_COM = skip_variable;
  153205. marker->length_limit_COM = 0;
  153206. for (i = 0; i < 16; i++) {
  153207. marker->process_APPn[i] = skip_variable;
  153208. marker->length_limit_APPn[i] = 0;
  153209. }
  153210. marker->process_APPn[0] = get_interesting_appn;
  153211. marker->process_APPn[14] = get_interesting_appn;
  153212. reset_marker_reader(cinfo);
  153213. }
  153214. #ifdef SAVE_MARKERS_SUPPORTED
  153215. GLOBAL(void)
  153216. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153217. unsigned int length_limit)
  153218. {
  153219. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153220. long maxlength;
  153221. jpeg_marker_parser_method processor;
  153222. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153223. if (((long) length_limit) > maxlength)
  153224. length_limit = (unsigned int) maxlength;
  153225. if (length_limit) {
  153226. processor = save_marker;
  153227. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153228. length_limit = APP0_DATA_LEN;
  153229. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153230. length_limit = APP14_DATA_LEN;
  153231. } else {
  153232. processor = skip_variable;
  153233. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153234. processor = get_interesting_appn;
  153235. }
  153236. if (marker_code == (int) M_COM) {
  153237. marker->process_COM = processor;
  153238. marker->length_limit_COM = length_limit;
  153239. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153240. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153241. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153242. } else
  153243. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153244. }
  153245. #endif /* SAVE_MARKERS_SUPPORTED */
  153246. GLOBAL(void)
  153247. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153248. jpeg_marker_parser_method routine)
  153249. {
  153250. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153251. if (marker_code == (int) M_COM)
  153252. marker->process_COM = routine;
  153253. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153254. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153255. else
  153256. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153257. }
  153258. /*** End of inlined file: jdmarker.c ***/
  153259. /*** Start of inlined file: jdmaster.c ***/
  153260. #define JPEG_INTERNALS
  153261. typedef struct {
  153262. struct jpeg_decomp_master pub; /* public fields */
  153263. int pass_number; /* # of passes completed */
  153264. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153265. struct jpeg_color_quantizer * quantizer_1pass;
  153266. struct jpeg_color_quantizer * quantizer_2pass;
  153267. } my_decomp_master;
  153268. typedef my_decomp_master * my_master_ptr6;
  153269. LOCAL(boolean)
  153270. use_merged_upsample (j_decompress_ptr cinfo)
  153271. {
  153272. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153273. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153274. return FALSE;
  153275. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153276. cinfo->out_color_space != JCS_RGB ||
  153277. cinfo->out_color_components != RGB_PIXELSIZE)
  153278. return FALSE;
  153279. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153280. cinfo->comp_info[1].h_samp_factor != 1 ||
  153281. cinfo->comp_info[2].h_samp_factor != 1 ||
  153282. cinfo->comp_info[0].v_samp_factor > 2 ||
  153283. cinfo->comp_info[1].v_samp_factor != 1 ||
  153284. cinfo->comp_info[2].v_samp_factor != 1)
  153285. return FALSE;
  153286. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153287. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153288. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153289. return FALSE;
  153290. return TRUE; /* by golly, it'll work... */
  153291. #else
  153292. return FALSE;
  153293. #endif
  153294. }
  153295. GLOBAL(void)
  153296. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153297. {
  153298. #ifdef IDCT_SCALING_SUPPORTED
  153299. int ci;
  153300. jpeg_component_info *compptr;
  153301. #endif
  153302. if (cinfo->global_state != DSTATE_READY)
  153303. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153304. #ifdef IDCT_SCALING_SUPPORTED
  153305. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153306. cinfo->output_width = (JDIMENSION)
  153307. jdiv_round_up((long) cinfo->image_width, 8L);
  153308. cinfo->output_height = (JDIMENSION)
  153309. jdiv_round_up((long) cinfo->image_height, 8L);
  153310. cinfo->min_DCT_scaled_size = 1;
  153311. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153312. cinfo->output_width = (JDIMENSION)
  153313. jdiv_round_up((long) cinfo->image_width, 4L);
  153314. cinfo->output_height = (JDIMENSION)
  153315. jdiv_round_up((long) cinfo->image_height, 4L);
  153316. cinfo->min_DCT_scaled_size = 2;
  153317. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153318. cinfo->output_width = (JDIMENSION)
  153319. jdiv_round_up((long) cinfo->image_width, 2L);
  153320. cinfo->output_height = (JDIMENSION)
  153321. jdiv_round_up((long) cinfo->image_height, 2L);
  153322. cinfo->min_DCT_scaled_size = 4;
  153323. } else {
  153324. cinfo->output_width = cinfo->image_width;
  153325. cinfo->output_height = cinfo->image_height;
  153326. cinfo->min_DCT_scaled_size = DCTSIZE;
  153327. }
  153328. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153329. ci++, compptr++) {
  153330. int ssize = cinfo->min_DCT_scaled_size;
  153331. while (ssize < DCTSIZE &&
  153332. (compptr->h_samp_factor * ssize * 2 <=
  153333. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153334. (compptr->v_samp_factor * ssize * 2 <=
  153335. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153336. ssize = ssize * 2;
  153337. }
  153338. compptr->DCT_scaled_size = ssize;
  153339. }
  153340. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153341. ci++, compptr++) {
  153342. compptr->downsampled_width = (JDIMENSION)
  153343. jdiv_round_up((long) cinfo->image_width *
  153344. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153345. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153346. compptr->downsampled_height = (JDIMENSION)
  153347. jdiv_round_up((long) cinfo->image_height *
  153348. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153349. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153350. }
  153351. #else /* !IDCT_SCALING_SUPPORTED */
  153352. cinfo->output_width = cinfo->image_width;
  153353. cinfo->output_height = cinfo->image_height;
  153354. #endif /* IDCT_SCALING_SUPPORTED */
  153355. switch (cinfo->out_color_space) {
  153356. case JCS_GRAYSCALE:
  153357. cinfo->out_color_components = 1;
  153358. break;
  153359. case JCS_RGB:
  153360. #if RGB_PIXELSIZE != 3
  153361. cinfo->out_color_components = RGB_PIXELSIZE;
  153362. break;
  153363. #endif /* else share code with YCbCr */
  153364. case JCS_YCbCr:
  153365. cinfo->out_color_components = 3;
  153366. break;
  153367. case JCS_CMYK:
  153368. case JCS_YCCK:
  153369. cinfo->out_color_components = 4;
  153370. break;
  153371. default: /* else must be same colorspace as in file */
  153372. cinfo->out_color_components = cinfo->num_components;
  153373. break;
  153374. }
  153375. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153376. cinfo->out_color_components);
  153377. if (use_merged_upsample(cinfo))
  153378. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153379. else
  153380. cinfo->rec_outbuf_height = 1;
  153381. }
  153382. LOCAL(void)
  153383. prepare_range_limit_table (j_decompress_ptr cinfo)
  153384. {
  153385. JSAMPLE * table;
  153386. int i;
  153387. table = (JSAMPLE *)
  153388. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153389. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153390. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153391. cinfo->sample_range_limit = table;
  153392. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153393. for (i = 0; i <= MAXJSAMPLE; i++)
  153394. table[i] = (JSAMPLE) i;
  153395. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153396. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153397. table[i] = MAXJSAMPLE;
  153398. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153399. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153400. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153401. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153402. }
  153403. LOCAL(void)
  153404. master_selection (j_decompress_ptr cinfo)
  153405. {
  153406. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153407. boolean use_c_buffer;
  153408. long samplesperrow;
  153409. JDIMENSION jd_samplesperrow;
  153410. jpeg_calc_output_dimensions(cinfo);
  153411. prepare_range_limit_table(cinfo);
  153412. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153413. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153414. if ((long) jd_samplesperrow != samplesperrow)
  153415. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153416. master->pass_number = 0;
  153417. master->using_merged_upsample = use_merged_upsample(cinfo);
  153418. master->quantizer_1pass = NULL;
  153419. master->quantizer_2pass = NULL;
  153420. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153421. cinfo->enable_1pass_quant = FALSE;
  153422. cinfo->enable_external_quant = FALSE;
  153423. cinfo->enable_2pass_quant = FALSE;
  153424. }
  153425. if (cinfo->quantize_colors) {
  153426. if (cinfo->raw_data_out)
  153427. ERREXIT(cinfo, JERR_NOTIMPL);
  153428. if (cinfo->out_color_components != 3) {
  153429. cinfo->enable_1pass_quant = TRUE;
  153430. cinfo->enable_external_quant = FALSE;
  153431. cinfo->enable_2pass_quant = FALSE;
  153432. cinfo->colormap = NULL;
  153433. } else if (cinfo->colormap != NULL) {
  153434. cinfo->enable_external_quant = TRUE;
  153435. } else if (cinfo->two_pass_quantize) {
  153436. cinfo->enable_2pass_quant = TRUE;
  153437. } else {
  153438. cinfo->enable_1pass_quant = TRUE;
  153439. }
  153440. if (cinfo->enable_1pass_quant) {
  153441. #ifdef QUANT_1PASS_SUPPORTED
  153442. jinit_1pass_quantizer(cinfo);
  153443. master->quantizer_1pass = cinfo->cquantize;
  153444. #else
  153445. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153446. #endif
  153447. }
  153448. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153449. #ifdef QUANT_2PASS_SUPPORTED
  153450. jinit_2pass_quantizer(cinfo);
  153451. master->quantizer_2pass = cinfo->cquantize;
  153452. #else
  153453. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153454. #endif
  153455. }
  153456. }
  153457. if (! cinfo->raw_data_out) {
  153458. if (master->using_merged_upsample) {
  153459. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153460. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153461. #else
  153462. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153463. #endif
  153464. } else {
  153465. jinit_color_deconverter(cinfo);
  153466. jinit_upsampler(cinfo);
  153467. }
  153468. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153469. }
  153470. jinit_inverse_dct(cinfo);
  153471. if (cinfo->arith_code) {
  153472. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153473. } else {
  153474. if (cinfo->progressive_mode) {
  153475. #ifdef D_PROGRESSIVE_SUPPORTED
  153476. jinit_phuff_decoder(cinfo);
  153477. #else
  153478. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153479. #endif
  153480. } else
  153481. jinit_huff_decoder(cinfo);
  153482. }
  153483. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153484. jinit_d_coef_controller(cinfo, use_c_buffer);
  153485. if (! cinfo->raw_data_out)
  153486. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153487. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153488. (*cinfo->inputctl->start_input_pass) (cinfo);
  153489. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153490. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153491. cinfo->inputctl->has_multiple_scans) {
  153492. int nscans;
  153493. if (cinfo->progressive_mode) {
  153494. nscans = 2 + 3 * cinfo->num_components;
  153495. } else {
  153496. nscans = cinfo->num_components;
  153497. }
  153498. cinfo->progress->pass_counter = 0L;
  153499. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153500. cinfo->progress->completed_passes = 0;
  153501. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153502. master->pass_number++;
  153503. }
  153504. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153505. }
  153506. METHODDEF(void)
  153507. prepare_for_output_pass (j_decompress_ptr cinfo)
  153508. {
  153509. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153510. if (master->pub.is_dummy_pass) {
  153511. #ifdef QUANT_2PASS_SUPPORTED
  153512. master->pub.is_dummy_pass = FALSE;
  153513. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153514. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153515. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153516. #else
  153517. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153518. #endif /* QUANT_2PASS_SUPPORTED */
  153519. } else {
  153520. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153521. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153522. cinfo->cquantize = master->quantizer_2pass;
  153523. master->pub.is_dummy_pass = TRUE;
  153524. } else if (cinfo->enable_1pass_quant) {
  153525. cinfo->cquantize = master->quantizer_1pass;
  153526. } else {
  153527. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153528. }
  153529. }
  153530. (*cinfo->idct->start_pass) (cinfo);
  153531. (*cinfo->coef->start_output_pass) (cinfo);
  153532. if (! cinfo->raw_data_out) {
  153533. if (! master->using_merged_upsample)
  153534. (*cinfo->cconvert->start_pass) (cinfo);
  153535. (*cinfo->upsample->start_pass) (cinfo);
  153536. if (cinfo->quantize_colors)
  153537. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153538. (*cinfo->post->start_pass) (cinfo,
  153539. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153540. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153541. }
  153542. }
  153543. if (cinfo->progress != NULL) {
  153544. cinfo->progress->completed_passes = master->pass_number;
  153545. cinfo->progress->total_passes = master->pass_number +
  153546. (master->pub.is_dummy_pass ? 2 : 1);
  153547. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153548. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153549. }
  153550. }
  153551. }
  153552. METHODDEF(void)
  153553. finish_output_pass (j_decompress_ptr cinfo)
  153554. {
  153555. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153556. if (cinfo->quantize_colors)
  153557. (*cinfo->cquantize->finish_pass) (cinfo);
  153558. master->pass_number++;
  153559. }
  153560. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153561. GLOBAL(void)
  153562. jpeg_new_colormap (j_decompress_ptr cinfo)
  153563. {
  153564. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153565. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153566. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153567. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153568. cinfo->colormap != NULL) {
  153569. cinfo->cquantize = master->quantizer_2pass;
  153570. (*cinfo->cquantize->new_color_map) (cinfo);
  153571. master->pub.is_dummy_pass = FALSE; /* just in case */
  153572. } else
  153573. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153574. }
  153575. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153576. GLOBAL(void)
  153577. jinit_master_decompress (j_decompress_ptr cinfo)
  153578. {
  153579. my_master_ptr6 master;
  153580. master = (my_master_ptr6)
  153581. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153582. SIZEOF(my_decomp_master));
  153583. cinfo->master = (struct jpeg_decomp_master *) master;
  153584. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153585. master->pub.finish_output_pass = finish_output_pass;
  153586. master->pub.is_dummy_pass = FALSE;
  153587. master_selection(cinfo);
  153588. }
  153589. /*** End of inlined file: jdmaster.c ***/
  153590. #undef FIX
  153591. /*** Start of inlined file: jdmerge.c ***/
  153592. #define JPEG_INTERNALS
  153593. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153594. typedef struct {
  153595. struct jpeg_upsampler pub; /* public fields */
  153596. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153597. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153598. JSAMPARRAY output_buf));
  153599. int * Cr_r_tab; /* => table for Cr to R conversion */
  153600. int * Cb_b_tab; /* => table for Cb to B conversion */
  153601. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153602. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153603. JSAMPROW spare_row;
  153604. boolean spare_full; /* T if spare buffer is occupied */
  153605. JDIMENSION out_row_width; /* samples per output row */
  153606. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153607. } my_upsampler;
  153608. typedef my_upsampler * my_upsample_ptr;
  153609. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153610. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153611. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153612. LOCAL(void)
  153613. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153614. {
  153615. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153616. int i;
  153617. INT32 x;
  153618. SHIFT_TEMPS
  153619. upsample->Cr_r_tab = (int *)
  153620. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153621. (MAXJSAMPLE+1) * SIZEOF(int));
  153622. upsample->Cb_b_tab = (int *)
  153623. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153624. (MAXJSAMPLE+1) * SIZEOF(int));
  153625. upsample->Cr_g_tab = (INT32 *)
  153626. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153627. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153628. upsample->Cb_g_tab = (INT32 *)
  153629. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153630. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153631. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153632. upsample->Cr_r_tab[i] = (int)
  153633. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153634. upsample->Cb_b_tab[i] = (int)
  153635. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153636. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153637. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153638. }
  153639. }
  153640. METHODDEF(void)
  153641. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153642. {
  153643. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153644. upsample->spare_full = FALSE;
  153645. upsample->rows_to_go = cinfo->output_height;
  153646. }
  153647. METHODDEF(void)
  153648. merged_2v_upsample (j_decompress_ptr cinfo,
  153649. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153650. JDIMENSION in_row_groups_avail,
  153651. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153652. JDIMENSION out_rows_avail)
  153653. {
  153654. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153655. JSAMPROW work_ptrs[2];
  153656. JDIMENSION num_rows; /* number of rows returned to caller */
  153657. if (upsample->spare_full) {
  153658. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153659. 1, upsample->out_row_width);
  153660. num_rows = 1;
  153661. upsample->spare_full = FALSE;
  153662. } else {
  153663. num_rows = 2;
  153664. if (num_rows > upsample->rows_to_go)
  153665. num_rows = upsample->rows_to_go;
  153666. out_rows_avail -= *out_row_ctr;
  153667. if (num_rows > out_rows_avail)
  153668. num_rows = out_rows_avail;
  153669. work_ptrs[0] = output_buf[*out_row_ctr];
  153670. if (num_rows > 1) {
  153671. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153672. } else {
  153673. work_ptrs[1] = upsample->spare_row;
  153674. upsample->spare_full = TRUE;
  153675. }
  153676. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153677. }
  153678. *out_row_ctr += num_rows;
  153679. upsample->rows_to_go -= num_rows;
  153680. if (! upsample->spare_full)
  153681. (*in_row_group_ctr)++;
  153682. }
  153683. METHODDEF(void)
  153684. merged_1v_upsample (j_decompress_ptr cinfo,
  153685. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153686. JDIMENSION in_row_groups_avail,
  153687. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153688. JDIMENSION out_rows_avail)
  153689. {
  153690. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153691. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153692. output_buf + *out_row_ctr);
  153693. (*out_row_ctr)++;
  153694. (*in_row_group_ctr)++;
  153695. }
  153696. METHODDEF(void)
  153697. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153698. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153699. JSAMPARRAY output_buf)
  153700. {
  153701. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153702. register int y, cred, cgreen, cblue;
  153703. int cb, cr;
  153704. register JSAMPROW outptr;
  153705. JSAMPROW inptr0, inptr1, inptr2;
  153706. JDIMENSION col;
  153707. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153708. int * Crrtab = upsample->Cr_r_tab;
  153709. int * Cbbtab = upsample->Cb_b_tab;
  153710. INT32 * Crgtab = upsample->Cr_g_tab;
  153711. INT32 * Cbgtab = upsample->Cb_g_tab;
  153712. SHIFT_TEMPS
  153713. inptr0 = input_buf[0][in_row_group_ctr];
  153714. inptr1 = input_buf[1][in_row_group_ctr];
  153715. inptr2 = input_buf[2][in_row_group_ctr];
  153716. outptr = output_buf[0];
  153717. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153718. cb = GETJSAMPLE(*inptr1++);
  153719. cr = GETJSAMPLE(*inptr2++);
  153720. cred = Crrtab[cr];
  153721. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153722. cblue = Cbbtab[cb];
  153723. y = GETJSAMPLE(*inptr0++);
  153724. outptr[RGB_RED] = range_limit[y + cred];
  153725. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153726. outptr[RGB_BLUE] = range_limit[y + cblue];
  153727. outptr += RGB_PIXELSIZE;
  153728. y = GETJSAMPLE(*inptr0++);
  153729. outptr[RGB_RED] = range_limit[y + cred];
  153730. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153731. outptr[RGB_BLUE] = range_limit[y + cblue];
  153732. outptr += RGB_PIXELSIZE;
  153733. }
  153734. if (cinfo->output_width & 1) {
  153735. cb = GETJSAMPLE(*inptr1);
  153736. cr = GETJSAMPLE(*inptr2);
  153737. cred = Crrtab[cr];
  153738. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153739. cblue = Cbbtab[cb];
  153740. y = GETJSAMPLE(*inptr0);
  153741. outptr[RGB_RED] = range_limit[y + cred];
  153742. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153743. outptr[RGB_BLUE] = range_limit[y + cblue];
  153744. }
  153745. }
  153746. METHODDEF(void)
  153747. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153748. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153749. JSAMPARRAY output_buf)
  153750. {
  153751. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153752. register int y, cred, cgreen, cblue;
  153753. int cb, cr;
  153754. register JSAMPROW outptr0, outptr1;
  153755. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153756. JDIMENSION col;
  153757. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153758. int * Crrtab = upsample->Cr_r_tab;
  153759. int * Cbbtab = upsample->Cb_b_tab;
  153760. INT32 * Crgtab = upsample->Cr_g_tab;
  153761. INT32 * Cbgtab = upsample->Cb_g_tab;
  153762. SHIFT_TEMPS
  153763. inptr00 = input_buf[0][in_row_group_ctr*2];
  153764. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153765. inptr1 = input_buf[1][in_row_group_ctr];
  153766. inptr2 = input_buf[2][in_row_group_ctr];
  153767. outptr0 = output_buf[0];
  153768. outptr1 = output_buf[1];
  153769. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153770. cb = GETJSAMPLE(*inptr1++);
  153771. cr = GETJSAMPLE(*inptr2++);
  153772. cred = Crrtab[cr];
  153773. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153774. cblue = Cbbtab[cb];
  153775. y = GETJSAMPLE(*inptr00++);
  153776. outptr0[RGB_RED] = range_limit[y + cred];
  153777. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153778. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153779. outptr0 += RGB_PIXELSIZE;
  153780. y = GETJSAMPLE(*inptr00++);
  153781. outptr0[RGB_RED] = range_limit[y + cred];
  153782. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153783. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153784. outptr0 += RGB_PIXELSIZE;
  153785. y = GETJSAMPLE(*inptr01++);
  153786. outptr1[RGB_RED] = range_limit[y + cred];
  153787. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153788. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153789. outptr1 += RGB_PIXELSIZE;
  153790. y = GETJSAMPLE(*inptr01++);
  153791. outptr1[RGB_RED] = range_limit[y + cred];
  153792. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153793. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153794. outptr1 += RGB_PIXELSIZE;
  153795. }
  153796. if (cinfo->output_width & 1) {
  153797. cb = GETJSAMPLE(*inptr1);
  153798. cr = GETJSAMPLE(*inptr2);
  153799. cred = Crrtab[cr];
  153800. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153801. cblue = Cbbtab[cb];
  153802. y = GETJSAMPLE(*inptr00);
  153803. outptr0[RGB_RED] = range_limit[y + cred];
  153804. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153805. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153806. y = GETJSAMPLE(*inptr01);
  153807. outptr1[RGB_RED] = range_limit[y + cred];
  153808. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153809. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153810. }
  153811. }
  153812. GLOBAL(void)
  153813. jinit_merged_upsampler (j_decompress_ptr cinfo)
  153814. {
  153815. my_upsample_ptr upsample;
  153816. upsample = (my_upsample_ptr)
  153817. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153818. SIZEOF(my_upsampler));
  153819. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  153820. upsample->pub.start_pass = start_pass_merged_upsample;
  153821. upsample->pub.need_context_rows = FALSE;
  153822. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  153823. if (cinfo->max_v_samp_factor == 2) {
  153824. upsample->pub.upsample = merged_2v_upsample;
  153825. upsample->upmethod = h2v2_merged_upsample;
  153826. upsample->spare_row = (JSAMPROW)
  153827. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153828. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  153829. } else {
  153830. upsample->pub.upsample = merged_1v_upsample;
  153831. upsample->upmethod = h2v1_merged_upsample;
  153832. upsample->spare_row = NULL;
  153833. }
  153834. build_ycc_rgb_table2(cinfo);
  153835. }
  153836. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  153837. /*** End of inlined file: jdmerge.c ***/
  153838. #undef ASSIGN_STATE
  153839. /*** Start of inlined file: jdphuff.c ***/
  153840. #define JPEG_INTERNALS
  153841. #ifdef D_PROGRESSIVE_SUPPORTED
  153842. typedef struct {
  153843. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  153844. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  153845. } savable_state3;
  153846. #ifndef NO_STRUCT_ASSIGN
  153847. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  153848. #else
  153849. #if MAX_COMPS_IN_SCAN == 4
  153850. #define ASSIGN_STATE(dest,src) \
  153851. ((dest).EOBRUN = (src).EOBRUN, \
  153852. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  153853. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  153854. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  153855. (dest).last_dc_val[3] = (src).last_dc_val[3])
  153856. #endif
  153857. #endif
  153858. typedef struct {
  153859. struct jpeg_entropy_decoder pub; /* public fields */
  153860. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  153861. savable_state3 saved; /* Other state at start of MCU */
  153862. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  153863. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  153864. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  153865. } phuff_entropy_decoder;
  153866. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  153867. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  153868. JBLOCKROW *MCU_data));
  153869. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  153870. JBLOCKROW *MCU_data));
  153871. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  153872. JBLOCKROW *MCU_data));
  153873. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  153874. JBLOCKROW *MCU_data));
  153875. METHODDEF(void)
  153876. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  153877. {
  153878. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153879. boolean is_DC_band, bad;
  153880. int ci, coefi, tbl;
  153881. int *coef_bit_ptr;
  153882. jpeg_component_info * compptr;
  153883. is_DC_band = (cinfo->Ss == 0);
  153884. bad = FALSE;
  153885. if (is_DC_band) {
  153886. if (cinfo->Se != 0)
  153887. bad = TRUE;
  153888. } else {
  153889. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  153890. bad = TRUE;
  153891. if (cinfo->comps_in_scan != 1)
  153892. bad = TRUE;
  153893. }
  153894. if (cinfo->Ah != 0) {
  153895. if (cinfo->Al != cinfo->Ah-1)
  153896. bad = TRUE;
  153897. }
  153898. if (cinfo->Al > 13) /* need not check for < 0 */
  153899. bad = TRUE;
  153900. if (bad)
  153901. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  153902. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  153903. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153904. int cindex = cinfo->cur_comp_info[ci]->component_index;
  153905. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  153906. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  153907. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  153908. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  153909. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  153910. if (cinfo->Ah != expected)
  153911. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  153912. coef_bit_ptr[coefi] = cinfo->Al;
  153913. }
  153914. }
  153915. if (cinfo->Ah == 0) {
  153916. if (is_DC_band)
  153917. entropy->pub.decode_mcu = decode_mcu_DC_first;
  153918. else
  153919. entropy->pub.decode_mcu = decode_mcu_AC_first;
  153920. } else {
  153921. if (is_DC_band)
  153922. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  153923. else
  153924. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  153925. }
  153926. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153927. compptr = cinfo->cur_comp_info[ci];
  153928. if (is_DC_band) {
  153929. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  153930. tbl = compptr->dc_tbl_no;
  153931. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  153932. & entropy->derived_tbls[tbl]);
  153933. }
  153934. } else {
  153935. tbl = compptr->ac_tbl_no;
  153936. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  153937. & entropy->derived_tbls[tbl]);
  153938. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  153939. }
  153940. entropy->saved.last_dc_val[ci] = 0;
  153941. }
  153942. entropy->bitstate.bits_left = 0;
  153943. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  153944. entropy->pub.insufficient_data = FALSE;
  153945. entropy->saved.EOBRUN = 0;
  153946. entropy->restarts_to_go = cinfo->restart_interval;
  153947. }
  153948. LOCAL(boolean)
  153949. process_restartp (j_decompress_ptr cinfo)
  153950. {
  153951. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153952. int ci;
  153953. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  153954. entropy->bitstate.bits_left = 0;
  153955. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  153956. return FALSE;
  153957. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  153958. entropy->saved.last_dc_val[ci] = 0;
  153959. entropy->saved.EOBRUN = 0;
  153960. entropy->restarts_to_go = cinfo->restart_interval;
  153961. if (cinfo->unread_marker == 0)
  153962. entropy->pub.insufficient_data = FALSE;
  153963. return TRUE;
  153964. }
  153965. METHODDEF(boolean)
  153966. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  153967. {
  153968. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153969. int Al = cinfo->Al;
  153970. register int s, r;
  153971. int blkn, ci;
  153972. JBLOCKROW block;
  153973. BITREAD_STATE_VARS;
  153974. savable_state3 state;
  153975. d_derived_tbl * tbl;
  153976. jpeg_component_info * compptr;
  153977. if (cinfo->restart_interval) {
  153978. if (entropy->restarts_to_go == 0)
  153979. if (! process_restartp(cinfo))
  153980. return FALSE;
  153981. }
  153982. if (! entropy->pub.insufficient_data) {
  153983. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  153984. ASSIGN_STATE(state, entropy->saved);
  153985. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  153986. block = MCU_data[blkn];
  153987. ci = cinfo->MCU_membership[blkn];
  153988. compptr = cinfo->cur_comp_info[ci];
  153989. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  153990. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  153991. if (s) {
  153992. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  153993. r = GET_BITS(s);
  153994. s = HUFF_EXTEND(r, s);
  153995. }
  153996. s += state.last_dc_val[ci];
  153997. state.last_dc_val[ci] = s;
  153998. (*block)[0] = (JCOEF) (s << Al);
  153999. }
  154000. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154001. ASSIGN_STATE(entropy->saved, state);
  154002. }
  154003. entropy->restarts_to_go--;
  154004. return TRUE;
  154005. }
  154006. METHODDEF(boolean)
  154007. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154008. {
  154009. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154010. int Se = cinfo->Se;
  154011. int Al = cinfo->Al;
  154012. register int s, k, r;
  154013. unsigned int EOBRUN;
  154014. JBLOCKROW block;
  154015. BITREAD_STATE_VARS;
  154016. d_derived_tbl * tbl;
  154017. if (cinfo->restart_interval) {
  154018. if (entropy->restarts_to_go == 0)
  154019. if (! process_restartp(cinfo))
  154020. return FALSE;
  154021. }
  154022. if (! entropy->pub.insufficient_data) {
  154023. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154024. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154025. EOBRUN--; /* ...process it now (we do nothing) */
  154026. else {
  154027. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154028. block = MCU_data[0];
  154029. tbl = entropy->ac_derived_tbl;
  154030. for (k = cinfo->Ss; k <= Se; k++) {
  154031. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154032. r = s >> 4;
  154033. s &= 15;
  154034. if (s) {
  154035. k += r;
  154036. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154037. r = GET_BITS(s);
  154038. s = HUFF_EXTEND(r, s);
  154039. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154040. } else {
  154041. if (r == 15) { /* ZRL */
  154042. k += 15; /* skip 15 zeroes in band */
  154043. } else { /* EOBr, run length is 2^r + appended bits */
  154044. EOBRUN = 1 << r;
  154045. if (r) { /* EOBr, r > 0 */
  154046. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154047. r = GET_BITS(r);
  154048. EOBRUN += r;
  154049. }
  154050. EOBRUN--; /* this band is processed at this moment */
  154051. break; /* force end-of-band */
  154052. }
  154053. }
  154054. }
  154055. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154056. }
  154057. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154058. }
  154059. entropy->restarts_to_go--;
  154060. return TRUE;
  154061. }
  154062. METHODDEF(boolean)
  154063. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154064. {
  154065. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154066. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154067. int blkn;
  154068. JBLOCKROW block;
  154069. BITREAD_STATE_VARS;
  154070. if (cinfo->restart_interval) {
  154071. if (entropy->restarts_to_go == 0)
  154072. if (! process_restartp(cinfo))
  154073. return FALSE;
  154074. }
  154075. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154076. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154077. block = MCU_data[blkn];
  154078. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154079. if (GET_BITS(1))
  154080. (*block)[0] |= p1;
  154081. }
  154082. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154083. entropy->restarts_to_go--;
  154084. return TRUE;
  154085. }
  154086. METHODDEF(boolean)
  154087. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154088. {
  154089. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154090. int Se = cinfo->Se;
  154091. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154092. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154093. register int s, k, r;
  154094. unsigned int EOBRUN;
  154095. JBLOCKROW block;
  154096. JCOEFPTR thiscoef;
  154097. BITREAD_STATE_VARS;
  154098. d_derived_tbl * tbl;
  154099. int num_newnz;
  154100. int newnz_pos[DCTSIZE2];
  154101. if (cinfo->restart_interval) {
  154102. if (entropy->restarts_to_go == 0)
  154103. if (! process_restartp(cinfo))
  154104. return FALSE;
  154105. }
  154106. if (! entropy->pub.insufficient_data) {
  154107. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154108. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154109. block = MCU_data[0];
  154110. tbl = entropy->ac_derived_tbl;
  154111. num_newnz = 0;
  154112. k = cinfo->Ss;
  154113. if (EOBRUN == 0) {
  154114. for (; k <= Se; k++) {
  154115. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154116. r = s >> 4;
  154117. s &= 15;
  154118. if (s) {
  154119. if (s != 1) /* size of new coef should always be 1 */
  154120. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154121. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154122. if (GET_BITS(1))
  154123. s = p1; /* newly nonzero coef is positive */
  154124. else
  154125. s = m1; /* newly nonzero coef is negative */
  154126. } else {
  154127. if (r != 15) {
  154128. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154129. if (r) {
  154130. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154131. r = GET_BITS(r);
  154132. EOBRUN += r;
  154133. }
  154134. break; /* rest of block is handled by EOB logic */
  154135. }
  154136. }
  154137. do {
  154138. thiscoef = *block + jpeg_natural_order[k];
  154139. if (*thiscoef != 0) {
  154140. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154141. if (GET_BITS(1)) {
  154142. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154143. if (*thiscoef >= 0)
  154144. *thiscoef += p1;
  154145. else
  154146. *thiscoef += m1;
  154147. }
  154148. }
  154149. } else {
  154150. if (--r < 0)
  154151. break; /* reached target zero coefficient */
  154152. }
  154153. k++;
  154154. } while (k <= Se);
  154155. if (s) {
  154156. int pos = jpeg_natural_order[k];
  154157. (*block)[pos] = (JCOEF) s;
  154158. newnz_pos[num_newnz++] = pos;
  154159. }
  154160. }
  154161. }
  154162. if (EOBRUN > 0) {
  154163. for (; k <= Se; k++) {
  154164. thiscoef = *block + jpeg_natural_order[k];
  154165. if (*thiscoef != 0) {
  154166. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154167. if (GET_BITS(1)) {
  154168. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154169. if (*thiscoef >= 0)
  154170. *thiscoef += p1;
  154171. else
  154172. *thiscoef += m1;
  154173. }
  154174. }
  154175. }
  154176. }
  154177. EOBRUN--;
  154178. }
  154179. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154180. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154181. }
  154182. entropy->restarts_to_go--;
  154183. return TRUE;
  154184. undoit:
  154185. while (num_newnz > 0)
  154186. (*block)[newnz_pos[--num_newnz]] = 0;
  154187. return FALSE;
  154188. }
  154189. GLOBAL(void)
  154190. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154191. {
  154192. phuff_entropy_ptr2 entropy;
  154193. int *coef_bit_ptr;
  154194. int ci, i;
  154195. entropy = (phuff_entropy_ptr2)
  154196. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154197. SIZEOF(phuff_entropy_decoder));
  154198. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154199. entropy->pub.start_pass = start_pass_phuff_decoder;
  154200. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154201. entropy->derived_tbls[i] = NULL;
  154202. }
  154203. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154204. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154205. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154206. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154207. for (ci = 0; ci < cinfo->num_components; ci++)
  154208. for (i = 0; i < DCTSIZE2; i++)
  154209. *coef_bit_ptr++ = -1;
  154210. }
  154211. #endif /* D_PROGRESSIVE_SUPPORTED */
  154212. /*** End of inlined file: jdphuff.c ***/
  154213. /*** Start of inlined file: jdpostct.c ***/
  154214. #define JPEG_INTERNALS
  154215. typedef struct {
  154216. struct jpeg_d_post_controller pub; /* public fields */
  154217. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154218. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154219. JDIMENSION strip_height; /* buffer size in rows */
  154220. JDIMENSION starting_row; /* row # of first row in current strip */
  154221. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154222. } my_post_controller;
  154223. typedef my_post_controller * my_post_ptr;
  154224. METHODDEF(void) post_process_1pass
  154225. JPP((j_decompress_ptr cinfo,
  154226. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154227. JDIMENSION in_row_groups_avail,
  154228. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154229. JDIMENSION out_rows_avail));
  154230. #ifdef QUANT_2PASS_SUPPORTED
  154231. METHODDEF(void) post_process_prepass
  154232. JPP((j_decompress_ptr cinfo,
  154233. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154234. JDIMENSION in_row_groups_avail,
  154235. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154236. JDIMENSION out_rows_avail));
  154237. METHODDEF(void) post_process_2pass
  154238. JPP((j_decompress_ptr cinfo,
  154239. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154240. JDIMENSION in_row_groups_avail,
  154241. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154242. JDIMENSION out_rows_avail));
  154243. #endif
  154244. METHODDEF(void)
  154245. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154246. {
  154247. my_post_ptr post = (my_post_ptr) cinfo->post;
  154248. switch (pass_mode) {
  154249. case JBUF_PASS_THRU:
  154250. if (cinfo->quantize_colors) {
  154251. post->pub.post_process_data = post_process_1pass;
  154252. if (post->buffer == NULL) {
  154253. post->buffer = (*cinfo->mem->access_virt_sarray)
  154254. ((j_common_ptr) cinfo, post->whole_image,
  154255. (JDIMENSION) 0, post->strip_height, TRUE);
  154256. }
  154257. } else {
  154258. post->pub.post_process_data = cinfo->upsample->upsample;
  154259. }
  154260. break;
  154261. #ifdef QUANT_2PASS_SUPPORTED
  154262. case JBUF_SAVE_AND_PASS:
  154263. if (post->whole_image == NULL)
  154264. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154265. post->pub.post_process_data = post_process_prepass;
  154266. break;
  154267. case JBUF_CRANK_DEST:
  154268. if (post->whole_image == NULL)
  154269. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154270. post->pub.post_process_data = post_process_2pass;
  154271. break;
  154272. #endif /* QUANT_2PASS_SUPPORTED */
  154273. default:
  154274. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154275. break;
  154276. }
  154277. post->starting_row = post->next_row = 0;
  154278. }
  154279. METHODDEF(void)
  154280. post_process_1pass (j_decompress_ptr cinfo,
  154281. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154282. JDIMENSION in_row_groups_avail,
  154283. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154284. JDIMENSION out_rows_avail)
  154285. {
  154286. my_post_ptr post = (my_post_ptr) cinfo->post;
  154287. JDIMENSION num_rows, max_rows;
  154288. max_rows = out_rows_avail - *out_row_ctr;
  154289. if (max_rows > post->strip_height)
  154290. max_rows = post->strip_height;
  154291. num_rows = 0;
  154292. (*cinfo->upsample->upsample) (cinfo,
  154293. input_buf, in_row_group_ctr, in_row_groups_avail,
  154294. post->buffer, &num_rows, max_rows);
  154295. (*cinfo->cquantize->color_quantize) (cinfo,
  154296. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154297. *out_row_ctr += num_rows;
  154298. }
  154299. #ifdef QUANT_2PASS_SUPPORTED
  154300. METHODDEF(void)
  154301. post_process_prepass (j_decompress_ptr cinfo,
  154302. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154303. JDIMENSION in_row_groups_avail,
  154304. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154305. JDIMENSION out_rows_avail)
  154306. {
  154307. my_post_ptr post = (my_post_ptr) cinfo->post;
  154308. JDIMENSION old_next_row, num_rows;
  154309. if (post->next_row == 0) {
  154310. post->buffer = (*cinfo->mem->access_virt_sarray)
  154311. ((j_common_ptr) cinfo, post->whole_image,
  154312. post->starting_row, post->strip_height, TRUE);
  154313. }
  154314. old_next_row = post->next_row;
  154315. (*cinfo->upsample->upsample) (cinfo,
  154316. input_buf, in_row_group_ctr, in_row_groups_avail,
  154317. post->buffer, &post->next_row, post->strip_height);
  154318. if (post->next_row > old_next_row) {
  154319. num_rows = post->next_row - old_next_row;
  154320. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154321. (JSAMPARRAY) NULL, (int) num_rows);
  154322. *out_row_ctr += num_rows;
  154323. }
  154324. if (post->next_row >= post->strip_height) {
  154325. post->starting_row += post->strip_height;
  154326. post->next_row = 0;
  154327. }
  154328. }
  154329. METHODDEF(void)
  154330. post_process_2pass (j_decompress_ptr cinfo,
  154331. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154332. JDIMENSION in_row_groups_avail,
  154333. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154334. JDIMENSION out_rows_avail)
  154335. {
  154336. my_post_ptr post = (my_post_ptr) cinfo->post;
  154337. JDIMENSION num_rows, max_rows;
  154338. if (post->next_row == 0) {
  154339. post->buffer = (*cinfo->mem->access_virt_sarray)
  154340. ((j_common_ptr) cinfo, post->whole_image,
  154341. post->starting_row, post->strip_height, FALSE);
  154342. }
  154343. num_rows = post->strip_height - post->next_row; /* available in strip */
  154344. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154345. if (num_rows > max_rows)
  154346. num_rows = max_rows;
  154347. max_rows = cinfo->output_height - post->starting_row;
  154348. if (num_rows > max_rows)
  154349. num_rows = max_rows;
  154350. (*cinfo->cquantize->color_quantize) (cinfo,
  154351. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154352. (int) num_rows);
  154353. *out_row_ctr += num_rows;
  154354. post->next_row += num_rows;
  154355. if (post->next_row >= post->strip_height) {
  154356. post->starting_row += post->strip_height;
  154357. post->next_row = 0;
  154358. }
  154359. }
  154360. #endif /* QUANT_2PASS_SUPPORTED */
  154361. GLOBAL(void)
  154362. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154363. {
  154364. my_post_ptr post;
  154365. post = (my_post_ptr)
  154366. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154367. SIZEOF(my_post_controller));
  154368. cinfo->post = (struct jpeg_d_post_controller *) post;
  154369. post->pub.start_pass = start_pass_dpost;
  154370. post->whole_image = NULL; /* flag for no virtual arrays */
  154371. post->buffer = NULL; /* flag for no strip buffer */
  154372. if (cinfo->quantize_colors) {
  154373. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154374. if (need_full_buffer) {
  154375. #ifdef QUANT_2PASS_SUPPORTED
  154376. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154377. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154378. cinfo->output_width * cinfo->out_color_components,
  154379. (JDIMENSION) jround_up((long) cinfo->output_height,
  154380. (long) post->strip_height),
  154381. post->strip_height);
  154382. #else
  154383. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154384. #endif /* QUANT_2PASS_SUPPORTED */
  154385. } else {
  154386. post->buffer = (*cinfo->mem->alloc_sarray)
  154387. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154388. cinfo->output_width * cinfo->out_color_components,
  154389. post->strip_height);
  154390. }
  154391. }
  154392. }
  154393. /*** End of inlined file: jdpostct.c ***/
  154394. #undef FIX
  154395. /*** Start of inlined file: jdsample.c ***/
  154396. #define JPEG_INTERNALS
  154397. typedef JMETHOD(void, upsample1_ptr,
  154398. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154399. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154400. typedef struct {
  154401. struct jpeg_upsampler pub; /* public fields */
  154402. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154403. upsample1_ptr methods[MAX_COMPONENTS];
  154404. int next_row_out; /* counts rows emitted from color_buf */
  154405. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154406. int rowgroup_height[MAX_COMPONENTS];
  154407. UINT8 h_expand[MAX_COMPONENTS];
  154408. UINT8 v_expand[MAX_COMPONENTS];
  154409. } my_upsampler2;
  154410. typedef my_upsampler2 * my_upsample_ptr2;
  154411. METHODDEF(void)
  154412. start_pass_upsample (j_decompress_ptr cinfo)
  154413. {
  154414. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154415. upsample->next_row_out = cinfo->max_v_samp_factor;
  154416. upsample->rows_to_go = cinfo->output_height;
  154417. }
  154418. METHODDEF(void)
  154419. sep_upsample (j_decompress_ptr cinfo,
  154420. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154421. JDIMENSION in_row_groups_avail,
  154422. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154423. JDIMENSION out_rows_avail)
  154424. {
  154425. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154426. int ci;
  154427. jpeg_component_info * compptr;
  154428. JDIMENSION num_rows;
  154429. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154430. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154431. ci++, compptr++) {
  154432. (*upsample->methods[ci]) (cinfo, compptr,
  154433. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154434. upsample->color_buf + ci);
  154435. }
  154436. upsample->next_row_out = 0;
  154437. }
  154438. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154439. if (num_rows > upsample->rows_to_go)
  154440. num_rows = upsample->rows_to_go;
  154441. out_rows_avail -= *out_row_ctr;
  154442. if (num_rows > out_rows_avail)
  154443. num_rows = out_rows_avail;
  154444. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154445. (JDIMENSION) upsample->next_row_out,
  154446. output_buf + *out_row_ctr,
  154447. (int) num_rows);
  154448. *out_row_ctr += num_rows;
  154449. upsample->rows_to_go -= num_rows;
  154450. upsample->next_row_out += num_rows;
  154451. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154452. (*in_row_group_ctr)++;
  154453. }
  154454. METHODDEF(void)
  154455. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154456. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154457. {
  154458. *output_data_ptr = input_data;
  154459. }
  154460. METHODDEF(void)
  154461. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154462. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154463. {
  154464. *output_data_ptr = NULL; /* safety check */
  154465. }
  154466. METHODDEF(void)
  154467. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154468. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154469. {
  154470. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154471. JSAMPARRAY output_data = *output_data_ptr;
  154472. register JSAMPROW inptr, outptr;
  154473. register JSAMPLE invalue;
  154474. register int h;
  154475. JSAMPROW outend;
  154476. int h_expand, v_expand;
  154477. int inrow, outrow;
  154478. h_expand = upsample->h_expand[compptr->component_index];
  154479. v_expand = upsample->v_expand[compptr->component_index];
  154480. inrow = outrow = 0;
  154481. while (outrow < cinfo->max_v_samp_factor) {
  154482. inptr = input_data[inrow];
  154483. outptr = output_data[outrow];
  154484. outend = outptr + cinfo->output_width;
  154485. while (outptr < outend) {
  154486. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154487. for (h = h_expand; h > 0; h--) {
  154488. *outptr++ = invalue;
  154489. }
  154490. }
  154491. if (v_expand > 1) {
  154492. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154493. v_expand-1, cinfo->output_width);
  154494. }
  154495. inrow++;
  154496. outrow += v_expand;
  154497. }
  154498. }
  154499. METHODDEF(void)
  154500. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154501. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154502. {
  154503. JSAMPARRAY output_data = *output_data_ptr;
  154504. register JSAMPROW inptr, outptr;
  154505. register JSAMPLE invalue;
  154506. JSAMPROW outend;
  154507. int inrow;
  154508. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154509. inptr = input_data[inrow];
  154510. outptr = output_data[inrow];
  154511. outend = outptr + cinfo->output_width;
  154512. while (outptr < outend) {
  154513. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154514. *outptr++ = invalue;
  154515. *outptr++ = invalue;
  154516. }
  154517. }
  154518. }
  154519. METHODDEF(void)
  154520. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154521. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154522. {
  154523. JSAMPARRAY output_data = *output_data_ptr;
  154524. register JSAMPROW inptr, outptr;
  154525. register JSAMPLE invalue;
  154526. JSAMPROW outend;
  154527. int inrow, outrow;
  154528. inrow = outrow = 0;
  154529. while (outrow < cinfo->max_v_samp_factor) {
  154530. inptr = input_data[inrow];
  154531. outptr = output_data[outrow];
  154532. outend = outptr + cinfo->output_width;
  154533. while (outptr < outend) {
  154534. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154535. *outptr++ = invalue;
  154536. *outptr++ = invalue;
  154537. }
  154538. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154539. 1, cinfo->output_width);
  154540. inrow++;
  154541. outrow += 2;
  154542. }
  154543. }
  154544. METHODDEF(void)
  154545. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154546. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154547. {
  154548. JSAMPARRAY output_data = *output_data_ptr;
  154549. register JSAMPROW inptr, outptr;
  154550. register int invalue;
  154551. register JDIMENSION colctr;
  154552. int inrow;
  154553. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154554. inptr = input_data[inrow];
  154555. outptr = output_data[inrow];
  154556. invalue = GETJSAMPLE(*inptr++);
  154557. *outptr++ = (JSAMPLE) invalue;
  154558. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154559. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154560. invalue = GETJSAMPLE(*inptr++) * 3;
  154561. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154562. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154563. }
  154564. invalue = GETJSAMPLE(*inptr);
  154565. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154566. *outptr++ = (JSAMPLE) invalue;
  154567. }
  154568. }
  154569. METHODDEF(void)
  154570. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154571. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154572. {
  154573. JSAMPARRAY output_data = *output_data_ptr;
  154574. register JSAMPROW inptr0, inptr1, outptr;
  154575. #if BITS_IN_JSAMPLE == 8
  154576. register int thiscolsum, lastcolsum, nextcolsum;
  154577. #else
  154578. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154579. #endif
  154580. register JDIMENSION colctr;
  154581. int inrow, outrow, v;
  154582. inrow = outrow = 0;
  154583. while (outrow < cinfo->max_v_samp_factor) {
  154584. for (v = 0; v < 2; v++) {
  154585. inptr0 = input_data[inrow];
  154586. if (v == 0) /* next nearest is row above */
  154587. inptr1 = input_data[inrow-1];
  154588. else /* next nearest is row below */
  154589. inptr1 = input_data[inrow+1];
  154590. outptr = output_data[outrow++];
  154591. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154592. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154593. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154594. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154595. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154596. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154597. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154598. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154599. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154600. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154601. }
  154602. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154603. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154604. }
  154605. inrow++;
  154606. }
  154607. }
  154608. GLOBAL(void)
  154609. jinit_upsampler (j_decompress_ptr cinfo)
  154610. {
  154611. my_upsample_ptr2 upsample;
  154612. int ci;
  154613. jpeg_component_info * compptr;
  154614. boolean need_buffer, do_fancy;
  154615. int h_in_group, v_in_group, h_out_group, v_out_group;
  154616. upsample = (my_upsample_ptr2)
  154617. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154618. SIZEOF(my_upsampler2));
  154619. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154620. upsample->pub.start_pass = start_pass_upsample;
  154621. upsample->pub.upsample = sep_upsample;
  154622. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154623. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154624. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154625. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154626. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154627. ci++, compptr++) {
  154628. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154629. cinfo->min_DCT_scaled_size;
  154630. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154631. cinfo->min_DCT_scaled_size;
  154632. h_out_group = cinfo->max_h_samp_factor;
  154633. v_out_group = cinfo->max_v_samp_factor;
  154634. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154635. need_buffer = TRUE;
  154636. if (! compptr->component_needed) {
  154637. upsample->methods[ci] = noop_upsample;
  154638. need_buffer = FALSE;
  154639. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154640. upsample->methods[ci] = fullsize_upsample;
  154641. need_buffer = FALSE;
  154642. } else if (h_in_group * 2 == h_out_group &&
  154643. v_in_group == v_out_group) {
  154644. if (do_fancy && compptr->downsampled_width > 2)
  154645. upsample->methods[ci] = h2v1_fancy_upsample;
  154646. else
  154647. upsample->methods[ci] = h2v1_upsample;
  154648. } else if (h_in_group * 2 == h_out_group &&
  154649. v_in_group * 2 == v_out_group) {
  154650. if (do_fancy && compptr->downsampled_width > 2) {
  154651. upsample->methods[ci] = h2v2_fancy_upsample;
  154652. upsample->pub.need_context_rows = TRUE;
  154653. } else
  154654. upsample->methods[ci] = h2v2_upsample;
  154655. } else if ((h_out_group % h_in_group) == 0 &&
  154656. (v_out_group % v_in_group) == 0) {
  154657. upsample->methods[ci] = int_upsample;
  154658. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154659. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154660. } else
  154661. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154662. if (need_buffer) {
  154663. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154664. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154665. (JDIMENSION) jround_up((long) cinfo->output_width,
  154666. (long) cinfo->max_h_samp_factor),
  154667. (JDIMENSION) cinfo->max_v_samp_factor);
  154668. }
  154669. }
  154670. }
  154671. /*** End of inlined file: jdsample.c ***/
  154672. /*** Start of inlined file: jdtrans.c ***/
  154673. #define JPEG_INTERNALS
  154674. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154675. GLOBAL(jvirt_barray_ptr *)
  154676. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154677. {
  154678. if (cinfo->global_state == DSTATE_READY) {
  154679. transdecode_master_selection(cinfo);
  154680. cinfo->global_state = DSTATE_RDCOEFS;
  154681. }
  154682. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154683. for (;;) {
  154684. int retcode;
  154685. if (cinfo->progress != NULL)
  154686. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154687. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154688. if (retcode == JPEG_SUSPENDED)
  154689. return NULL;
  154690. if (retcode == JPEG_REACHED_EOI)
  154691. break;
  154692. if (cinfo->progress != NULL &&
  154693. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154694. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154695. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154696. }
  154697. }
  154698. }
  154699. cinfo->global_state = DSTATE_STOPPING;
  154700. }
  154701. if ((cinfo->global_state == DSTATE_STOPPING ||
  154702. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154703. return cinfo->coef->coef_arrays;
  154704. }
  154705. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154706. return NULL; /* keep compiler happy */
  154707. }
  154708. LOCAL(void)
  154709. transdecode_master_selection (j_decompress_ptr cinfo)
  154710. {
  154711. cinfo->buffered_image = TRUE;
  154712. if (cinfo->arith_code) {
  154713. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154714. } else {
  154715. if (cinfo->progressive_mode) {
  154716. #ifdef D_PROGRESSIVE_SUPPORTED
  154717. jinit_phuff_decoder(cinfo);
  154718. #else
  154719. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154720. #endif
  154721. } else
  154722. jinit_huff_decoder(cinfo);
  154723. }
  154724. jinit_d_coef_controller(cinfo, TRUE);
  154725. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154726. (*cinfo->inputctl->start_input_pass) (cinfo);
  154727. if (cinfo->progress != NULL) {
  154728. int nscans;
  154729. if (cinfo->progressive_mode) {
  154730. nscans = 2 + 3 * cinfo->num_components;
  154731. } else if (cinfo->inputctl->has_multiple_scans) {
  154732. nscans = cinfo->num_components;
  154733. } else {
  154734. nscans = 1;
  154735. }
  154736. cinfo->progress->pass_counter = 0L;
  154737. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154738. cinfo->progress->completed_passes = 0;
  154739. cinfo->progress->total_passes = 1;
  154740. }
  154741. }
  154742. /*** End of inlined file: jdtrans.c ***/
  154743. /*** Start of inlined file: jfdctflt.c ***/
  154744. #define JPEG_INTERNALS
  154745. #ifdef DCT_FLOAT_SUPPORTED
  154746. #if DCTSIZE != 8
  154747. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154748. #endif
  154749. GLOBAL(void)
  154750. jpeg_fdct_float (FAST_FLOAT * data)
  154751. {
  154752. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154753. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154754. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154755. FAST_FLOAT *dataptr;
  154756. int ctr;
  154757. dataptr = data;
  154758. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154759. tmp0 = dataptr[0] + dataptr[7];
  154760. tmp7 = dataptr[0] - dataptr[7];
  154761. tmp1 = dataptr[1] + dataptr[6];
  154762. tmp6 = dataptr[1] - dataptr[6];
  154763. tmp2 = dataptr[2] + dataptr[5];
  154764. tmp5 = dataptr[2] - dataptr[5];
  154765. tmp3 = dataptr[3] + dataptr[4];
  154766. tmp4 = dataptr[3] - dataptr[4];
  154767. tmp10 = tmp0 + tmp3; /* phase 2 */
  154768. tmp13 = tmp0 - tmp3;
  154769. tmp11 = tmp1 + tmp2;
  154770. tmp12 = tmp1 - tmp2;
  154771. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154772. dataptr[4] = tmp10 - tmp11;
  154773. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154774. dataptr[2] = tmp13 + z1; /* phase 5 */
  154775. dataptr[6] = tmp13 - z1;
  154776. tmp10 = tmp4 + tmp5; /* phase 2 */
  154777. tmp11 = tmp5 + tmp6;
  154778. tmp12 = tmp6 + tmp7;
  154779. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154780. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154781. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154782. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154783. z11 = tmp7 + z3; /* phase 5 */
  154784. z13 = tmp7 - z3;
  154785. dataptr[5] = z13 + z2; /* phase 6 */
  154786. dataptr[3] = z13 - z2;
  154787. dataptr[1] = z11 + z4;
  154788. dataptr[7] = z11 - z4;
  154789. dataptr += DCTSIZE; /* advance pointer to next row */
  154790. }
  154791. dataptr = data;
  154792. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154793. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154794. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154795. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154796. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154797. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154798. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154799. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154800. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154801. tmp10 = tmp0 + tmp3; /* phase 2 */
  154802. tmp13 = tmp0 - tmp3;
  154803. tmp11 = tmp1 + tmp2;
  154804. tmp12 = tmp1 - tmp2;
  154805. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154806. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154807. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154808. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154809. dataptr[DCTSIZE*6] = tmp13 - z1;
  154810. tmp10 = tmp4 + tmp5; /* phase 2 */
  154811. tmp11 = tmp5 + tmp6;
  154812. tmp12 = tmp6 + tmp7;
  154813. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154814. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154815. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154816. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154817. z11 = tmp7 + z3; /* phase 5 */
  154818. z13 = tmp7 - z3;
  154819. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154820. dataptr[DCTSIZE*3] = z13 - z2;
  154821. dataptr[DCTSIZE*1] = z11 + z4;
  154822. dataptr[DCTSIZE*7] = z11 - z4;
  154823. dataptr++; /* advance pointer to next column */
  154824. }
  154825. }
  154826. #endif /* DCT_FLOAT_SUPPORTED */
  154827. /*** End of inlined file: jfdctflt.c ***/
  154828. /*** Start of inlined file: jfdctint.c ***/
  154829. #define JPEG_INTERNALS
  154830. #ifdef DCT_ISLOW_SUPPORTED
  154831. #if DCTSIZE != 8
  154832. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154833. #endif
  154834. #if BITS_IN_JSAMPLE == 8
  154835. #define CONST_BITS 13
  154836. #define PASS1_BITS 2
  154837. #else
  154838. #define CONST_BITS 13
  154839. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  154840. #endif
  154841. #if CONST_BITS == 13
  154842. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  154843. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  154844. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  154845. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  154846. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  154847. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  154848. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  154849. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  154850. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  154851. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  154852. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  154853. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  154854. #else
  154855. #define FIX_0_298631336 FIX(0.298631336)
  154856. #define FIX_0_390180644 FIX(0.390180644)
  154857. #define FIX_0_541196100 FIX(0.541196100)
  154858. #define FIX_0_765366865 FIX(0.765366865)
  154859. #define FIX_0_899976223 FIX(0.899976223)
  154860. #define FIX_1_175875602 FIX(1.175875602)
  154861. #define FIX_1_501321110 FIX(1.501321110)
  154862. #define FIX_1_847759065 FIX(1.847759065)
  154863. #define FIX_1_961570560 FIX(1.961570560)
  154864. #define FIX_2_053119869 FIX(2.053119869)
  154865. #define FIX_2_562915447 FIX(2.562915447)
  154866. #define FIX_3_072711026 FIX(3.072711026)
  154867. #endif
  154868. #if BITS_IN_JSAMPLE == 8
  154869. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  154870. #else
  154871. #define MULTIPLY(var,const) ((var) * (const))
  154872. #endif
  154873. GLOBAL(void)
  154874. jpeg_fdct_islow (DCTELEM * data)
  154875. {
  154876. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154877. INT32 tmp10, tmp11, tmp12, tmp13;
  154878. INT32 z1, z2, z3, z4, z5;
  154879. DCTELEM *dataptr;
  154880. int ctr;
  154881. SHIFT_TEMPS
  154882. dataptr = data;
  154883. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154884. tmp0 = dataptr[0] + dataptr[7];
  154885. tmp7 = dataptr[0] - dataptr[7];
  154886. tmp1 = dataptr[1] + dataptr[6];
  154887. tmp6 = dataptr[1] - dataptr[6];
  154888. tmp2 = dataptr[2] + dataptr[5];
  154889. tmp5 = dataptr[2] - dataptr[5];
  154890. tmp3 = dataptr[3] + dataptr[4];
  154891. tmp4 = dataptr[3] - dataptr[4];
  154892. tmp10 = tmp0 + tmp3;
  154893. tmp13 = tmp0 - tmp3;
  154894. tmp11 = tmp1 + tmp2;
  154895. tmp12 = tmp1 - tmp2;
  154896. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  154897. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  154898. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  154899. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  154900. CONST_BITS-PASS1_BITS);
  154901. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  154902. CONST_BITS-PASS1_BITS);
  154903. z1 = tmp4 + tmp7;
  154904. z2 = tmp5 + tmp6;
  154905. z3 = tmp4 + tmp6;
  154906. z4 = tmp5 + tmp7;
  154907. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  154908. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  154909. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  154910. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  154911. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  154912. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  154913. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  154914. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  154915. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  154916. z3 += z5;
  154917. z4 += z5;
  154918. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  154919. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  154920. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  154921. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  154922. dataptr += DCTSIZE; /* advance pointer to next row */
  154923. }
  154924. dataptr = data;
  154925. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154926. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154927. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154928. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154929. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154930. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154931. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154932. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154933. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154934. tmp10 = tmp0 + tmp3;
  154935. tmp13 = tmp0 - tmp3;
  154936. tmp11 = tmp1 + tmp2;
  154937. tmp12 = tmp1 - tmp2;
  154938. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  154939. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  154940. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  154941. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  154942. CONST_BITS+PASS1_BITS);
  154943. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  154944. CONST_BITS+PASS1_BITS);
  154945. z1 = tmp4 + tmp7;
  154946. z2 = tmp5 + tmp6;
  154947. z3 = tmp4 + tmp6;
  154948. z4 = tmp5 + tmp7;
  154949. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  154950. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  154951. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  154952. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  154953. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  154954. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  154955. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  154956. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  154957. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  154958. z3 += z5;
  154959. z4 += z5;
  154960. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  154961. CONST_BITS+PASS1_BITS);
  154962. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  154963. CONST_BITS+PASS1_BITS);
  154964. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  154965. CONST_BITS+PASS1_BITS);
  154966. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  154967. CONST_BITS+PASS1_BITS);
  154968. dataptr++; /* advance pointer to next column */
  154969. }
  154970. }
  154971. #endif /* DCT_ISLOW_SUPPORTED */
  154972. /*** End of inlined file: jfdctint.c ***/
  154973. #undef CONST_BITS
  154974. #undef MULTIPLY
  154975. #undef FIX_0_541196100
  154976. /*** Start of inlined file: jfdctfst.c ***/
  154977. #define JPEG_INTERNALS
  154978. #ifdef DCT_IFAST_SUPPORTED
  154979. #if DCTSIZE != 8
  154980. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154981. #endif
  154982. #define CONST_BITS 8
  154983. #if CONST_BITS == 8
  154984. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  154985. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  154986. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  154987. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  154988. #else
  154989. #define FIX_0_382683433 FIX(0.382683433)
  154990. #define FIX_0_541196100 FIX(0.541196100)
  154991. #define FIX_0_707106781 FIX(0.707106781)
  154992. #define FIX_1_306562965 FIX(1.306562965)
  154993. #endif
  154994. #ifndef USE_ACCURATE_ROUNDING
  154995. #undef DESCALE
  154996. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  154997. #endif
  154998. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  154999. GLOBAL(void)
  155000. jpeg_fdct_ifast (DCTELEM * data)
  155001. {
  155002. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155003. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155004. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155005. DCTELEM *dataptr;
  155006. int ctr;
  155007. SHIFT_TEMPS
  155008. dataptr = data;
  155009. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155010. tmp0 = dataptr[0] + dataptr[7];
  155011. tmp7 = dataptr[0] - dataptr[7];
  155012. tmp1 = dataptr[1] + dataptr[6];
  155013. tmp6 = dataptr[1] - dataptr[6];
  155014. tmp2 = dataptr[2] + dataptr[5];
  155015. tmp5 = dataptr[2] - dataptr[5];
  155016. tmp3 = dataptr[3] + dataptr[4];
  155017. tmp4 = dataptr[3] - dataptr[4];
  155018. tmp10 = tmp0 + tmp3; /* phase 2 */
  155019. tmp13 = tmp0 - tmp3;
  155020. tmp11 = tmp1 + tmp2;
  155021. tmp12 = tmp1 - tmp2;
  155022. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155023. dataptr[4] = tmp10 - tmp11;
  155024. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155025. dataptr[2] = tmp13 + z1; /* phase 5 */
  155026. dataptr[6] = tmp13 - z1;
  155027. tmp10 = tmp4 + tmp5; /* phase 2 */
  155028. tmp11 = tmp5 + tmp6;
  155029. tmp12 = tmp6 + tmp7;
  155030. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155031. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155032. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155033. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155034. z11 = tmp7 + z3; /* phase 5 */
  155035. z13 = tmp7 - z3;
  155036. dataptr[5] = z13 + z2; /* phase 6 */
  155037. dataptr[3] = z13 - z2;
  155038. dataptr[1] = z11 + z4;
  155039. dataptr[7] = z11 - z4;
  155040. dataptr += DCTSIZE; /* advance pointer to next row */
  155041. }
  155042. dataptr = data;
  155043. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155044. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155045. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155046. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155047. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155048. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155049. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155050. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155051. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155052. tmp10 = tmp0 + tmp3; /* phase 2 */
  155053. tmp13 = tmp0 - tmp3;
  155054. tmp11 = tmp1 + tmp2;
  155055. tmp12 = tmp1 - tmp2;
  155056. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155057. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155058. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155059. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155060. dataptr[DCTSIZE*6] = tmp13 - z1;
  155061. tmp10 = tmp4 + tmp5; /* phase 2 */
  155062. tmp11 = tmp5 + tmp6;
  155063. tmp12 = tmp6 + tmp7;
  155064. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155065. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155066. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155067. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155068. z11 = tmp7 + z3; /* phase 5 */
  155069. z13 = tmp7 - z3;
  155070. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155071. dataptr[DCTSIZE*3] = z13 - z2;
  155072. dataptr[DCTSIZE*1] = z11 + z4;
  155073. dataptr[DCTSIZE*7] = z11 - z4;
  155074. dataptr++; /* advance pointer to next column */
  155075. }
  155076. }
  155077. #endif /* DCT_IFAST_SUPPORTED */
  155078. /*** End of inlined file: jfdctfst.c ***/
  155079. #undef FIX_0_541196100
  155080. /*** Start of inlined file: jidctflt.c ***/
  155081. #define JPEG_INTERNALS
  155082. #ifdef DCT_FLOAT_SUPPORTED
  155083. #if DCTSIZE != 8
  155084. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155085. #endif
  155086. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155087. GLOBAL(void)
  155088. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155089. JCOEFPTR coef_block,
  155090. JSAMPARRAY output_buf, JDIMENSION output_col)
  155091. {
  155092. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155093. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155094. FAST_FLOAT z5, z10, z11, z12, z13;
  155095. JCOEFPTR inptr;
  155096. FLOAT_MULT_TYPE * quantptr;
  155097. FAST_FLOAT * wsptr;
  155098. JSAMPROW outptr;
  155099. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155100. int ctr;
  155101. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155102. SHIFT_TEMPS
  155103. inptr = coef_block;
  155104. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155105. wsptr = workspace;
  155106. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155107. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155108. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155109. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155110. inptr[DCTSIZE*7] == 0) {
  155111. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155112. wsptr[DCTSIZE*0] = dcval;
  155113. wsptr[DCTSIZE*1] = dcval;
  155114. wsptr[DCTSIZE*2] = dcval;
  155115. wsptr[DCTSIZE*3] = dcval;
  155116. wsptr[DCTSIZE*4] = dcval;
  155117. wsptr[DCTSIZE*5] = dcval;
  155118. wsptr[DCTSIZE*6] = dcval;
  155119. wsptr[DCTSIZE*7] = dcval;
  155120. inptr++; /* advance pointers to next column */
  155121. quantptr++;
  155122. wsptr++;
  155123. continue;
  155124. }
  155125. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155126. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155127. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155128. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155129. tmp10 = tmp0 + tmp2; /* phase 3 */
  155130. tmp11 = tmp0 - tmp2;
  155131. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155132. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155133. tmp0 = tmp10 + tmp13; /* phase 2 */
  155134. tmp3 = tmp10 - tmp13;
  155135. tmp1 = tmp11 + tmp12;
  155136. tmp2 = tmp11 - tmp12;
  155137. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155138. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155139. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155140. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155141. z13 = tmp6 + tmp5; /* phase 6 */
  155142. z10 = tmp6 - tmp5;
  155143. z11 = tmp4 + tmp7;
  155144. z12 = tmp4 - tmp7;
  155145. tmp7 = z11 + z13; /* phase 5 */
  155146. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155147. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155148. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155149. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155150. tmp6 = tmp12 - tmp7; /* phase 2 */
  155151. tmp5 = tmp11 - tmp6;
  155152. tmp4 = tmp10 + tmp5;
  155153. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155154. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155155. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155156. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155157. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155158. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155159. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155160. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155161. inptr++; /* advance pointers to next column */
  155162. quantptr++;
  155163. wsptr++;
  155164. }
  155165. wsptr = workspace;
  155166. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155167. outptr = output_buf[ctr] + output_col;
  155168. tmp10 = wsptr[0] + wsptr[4];
  155169. tmp11 = wsptr[0] - wsptr[4];
  155170. tmp13 = wsptr[2] + wsptr[6];
  155171. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155172. tmp0 = tmp10 + tmp13;
  155173. tmp3 = tmp10 - tmp13;
  155174. tmp1 = tmp11 + tmp12;
  155175. tmp2 = tmp11 - tmp12;
  155176. z13 = wsptr[5] + wsptr[3];
  155177. z10 = wsptr[5] - wsptr[3];
  155178. z11 = wsptr[1] + wsptr[7];
  155179. z12 = wsptr[1] - wsptr[7];
  155180. tmp7 = z11 + z13;
  155181. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155182. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155183. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155184. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155185. tmp6 = tmp12 - tmp7;
  155186. tmp5 = tmp11 - tmp6;
  155187. tmp4 = tmp10 + tmp5;
  155188. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155189. & RANGE_MASK];
  155190. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155191. & RANGE_MASK];
  155192. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155193. & RANGE_MASK];
  155194. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155195. & RANGE_MASK];
  155196. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155197. & RANGE_MASK];
  155198. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155199. & RANGE_MASK];
  155200. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155201. & RANGE_MASK];
  155202. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155203. & RANGE_MASK];
  155204. wsptr += DCTSIZE; /* advance pointer to next row */
  155205. }
  155206. }
  155207. #endif /* DCT_FLOAT_SUPPORTED */
  155208. /*** End of inlined file: jidctflt.c ***/
  155209. #undef CONST_BITS
  155210. #undef FIX_1_847759065
  155211. #undef MULTIPLY
  155212. #undef DEQUANTIZE
  155213. #undef DESCALE
  155214. /*** Start of inlined file: jidctfst.c ***/
  155215. #define JPEG_INTERNALS
  155216. #ifdef DCT_IFAST_SUPPORTED
  155217. #if DCTSIZE != 8
  155218. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155219. #endif
  155220. #if BITS_IN_JSAMPLE == 8
  155221. #define CONST_BITS 8
  155222. #define PASS1_BITS 2
  155223. #else
  155224. #define CONST_BITS 8
  155225. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155226. #endif
  155227. #if CONST_BITS == 8
  155228. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155229. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155230. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155231. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155232. #else
  155233. #define FIX_1_082392200 FIX(1.082392200)
  155234. #define FIX_1_414213562 FIX(1.414213562)
  155235. #define FIX_1_847759065 FIX(1.847759065)
  155236. #define FIX_2_613125930 FIX(2.613125930)
  155237. #endif
  155238. #ifndef USE_ACCURATE_ROUNDING
  155239. #undef DESCALE
  155240. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155241. #endif
  155242. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155243. #if BITS_IN_JSAMPLE == 8
  155244. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155245. #else
  155246. #define DEQUANTIZE(coef,quantval) \
  155247. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155248. #endif
  155249. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155250. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155251. #if BITS_IN_JSAMPLE == 8
  155252. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155253. #else
  155254. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155255. #endif
  155256. #define IRIGHT_SHIFT(x,shft) \
  155257. ((ishift_temp = (x)) < 0 ? \
  155258. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155259. (ishift_temp >> (shft)))
  155260. #else
  155261. #define ISHIFT_TEMPS
  155262. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155263. #endif
  155264. #ifdef USE_ACCURATE_ROUNDING
  155265. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155266. #else
  155267. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155268. #endif
  155269. GLOBAL(void)
  155270. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155271. JCOEFPTR coef_block,
  155272. JSAMPARRAY output_buf, JDIMENSION output_col)
  155273. {
  155274. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155275. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155276. DCTELEM z5, z10, z11, z12, z13;
  155277. JCOEFPTR inptr;
  155278. IFAST_MULT_TYPE * quantptr;
  155279. int * wsptr;
  155280. JSAMPROW outptr;
  155281. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155282. int ctr;
  155283. int workspace[DCTSIZE2]; /* buffers data between passes */
  155284. SHIFT_TEMPS /* for DESCALE */
  155285. ISHIFT_TEMPS /* for IDESCALE */
  155286. inptr = coef_block;
  155287. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155288. wsptr = workspace;
  155289. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155290. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155291. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155292. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155293. inptr[DCTSIZE*7] == 0) {
  155294. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155295. wsptr[DCTSIZE*0] = dcval;
  155296. wsptr[DCTSIZE*1] = dcval;
  155297. wsptr[DCTSIZE*2] = dcval;
  155298. wsptr[DCTSIZE*3] = dcval;
  155299. wsptr[DCTSIZE*4] = dcval;
  155300. wsptr[DCTSIZE*5] = dcval;
  155301. wsptr[DCTSIZE*6] = dcval;
  155302. wsptr[DCTSIZE*7] = dcval;
  155303. inptr++; /* advance pointers to next column */
  155304. quantptr++;
  155305. wsptr++;
  155306. continue;
  155307. }
  155308. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155309. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155310. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155311. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155312. tmp10 = tmp0 + tmp2; /* phase 3 */
  155313. tmp11 = tmp0 - tmp2;
  155314. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155315. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155316. tmp0 = tmp10 + tmp13; /* phase 2 */
  155317. tmp3 = tmp10 - tmp13;
  155318. tmp1 = tmp11 + tmp12;
  155319. tmp2 = tmp11 - tmp12;
  155320. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155321. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155322. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155323. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155324. z13 = tmp6 + tmp5; /* phase 6 */
  155325. z10 = tmp6 - tmp5;
  155326. z11 = tmp4 + tmp7;
  155327. z12 = tmp4 - tmp7;
  155328. tmp7 = z11 + z13; /* phase 5 */
  155329. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155330. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155331. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155332. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155333. tmp6 = tmp12 - tmp7; /* phase 2 */
  155334. tmp5 = tmp11 - tmp6;
  155335. tmp4 = tmp10 + tmp5;
  155336. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155337. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155338. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155339. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155340. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155341. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155342. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155343. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155344. inptr++; /* advance pointers to next column */
  155345. quantptr++;
  155346. wsptr++;
  155347. }
  155348. wsptr = workspace;
  155349. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155350. outptr = output_buf[ctr] + output_col;
  155351. #ifndef NO_ZERO_ROW_TEST
  155352. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155353. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155354. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155355. & RANGE_MASK];
  155356. outptr[0] = dcval;
  155357. outptr[1] = dcval;
  155358. outptr[2] = dcval;
  155359. outptr[3] = dcval;
  155360. outptr[4] = dcval;
  155361. outptr[5] = dcval;
  155362. outptr[6] = dcval;
  155363. outptr[7] = dcval;
  155364. wsptr += DCTSIZE; /* advance pointer to next row */
  155365. continue;
  155366. }
  155367. #endif
  155368. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155369. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155370. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155371. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155372. - tmp13;
  155373. tmp0 = tmp10 + tmp13;
  155374. tmp3 = tmp10 - tmp13;
  155375. tmp1 = tmp11 + tmp12;
  155376. tmp2 = tmp11 - tmp12;
  155377. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155378. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155379. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155380. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155381. tmp7 = z11 + z13; /* phase 5 */
  155382. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155383. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155384. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155385. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155386. tmp6 = tmp12 - tmp7; /* phase 2 */
  155387. tmp5 = tmp11 - tmp6;
  155388. tmp4 = tmp10 + tmp5;
  155389. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155390. & RANGE_MASK];
  155391. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155392. & RANGE_MASK];
  155393. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155394. & RANGE_MASK];
  155395. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155396. & RANGE_MASK];
  155397. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155398. & RANGE_MASK];
  155399. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155400. & RANGE_MASK];
  155401. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155402. & RANGE_MASK];
  155403. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155404. & RANGE_MASK];
  155405. wsptr += DCTSIZE; /* advance pointer to next row */
  155406. }
  155407. }
  155408. #endif /* DCT_IFAST_SUPPORTED */
  155409. /*** End of inlined file: jidctfst.c ***/
  155410. #undef CONST_BITS
  155411. #undef FIX_1_847759065
  155412. #undef MULTIPLY
  155413. #undef DEQUANTIZE
  155414. /*** Start of inlined file: jidctint.c ***/
  155415. #define JPEG_INTERNALS
  155416. #ifdef DCT_ISLOW_SUPPORTED
  155417. #if DCTSIZE != 8
  155418. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155419. #endif
  155420. #if BITS_IN_JSAMPLE == 8
  155421. #define CONST_BITS 13
  155422. #define PASS1_BITS 2
  155423. #else
  155424. #define CONST_BITS 13
  155425. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155426. #endif
  155427. #if CONST_BITS == 13
  155428. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155429. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155430. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155431. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155432. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155433. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155434. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155435. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155436. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155437. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155438. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155439. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155440. #else
  155441. #define FIX_0_298631336 FIX(0.298631336)
  155442. #define FIX_0_390180644 FIX(0.390180644)
  155443. #define FIX_0_541196100 FIX(0.541196100)
  155444. #define FIX_0_765366865 FIX(0.765366865)
  155445. #define FIX_0_899976223 FIX(0.899976223)
  155446. #define FIX_1_175875602 FIX(1.175875602)
  155447. #define FIX_1_501321110 FIX(1.501321110)
  155448. #define FIX_1_847759065 FIX(1.847759065)
  155449. #define FIX_1_961570560 FIX(1.961570560)
  155450. #define FIX_2_053119869 FIX(2.053119869)
  155451. #define FIX_2_562915447 FIX(2.562915447)
  155452. #define FIX_3_072711026 FIX(3.072711026)
  155453. #endif
  155454. #if BITS_IN_JSAMPLE == 8
  155455. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155456. #else
  155457. #define MULTIPLY(var,const) ((var) * (const))
  155458. #endif
  155459. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155460. GLOBAL(void)
  155461. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155462. JCOEFPTR coef_block,
  155463. JSAMPARRAY output_buf, JDIMENSION output_col)
  155464. {
  155465. INT32 tmp0, tmp1, tmp2, tmp3;
  155466. INT32 tmp10, tmp11, tmp12, tmp13;
  155467. INT32 z1, z2, z3, z4, z5;
  155468. JCOEFPTR inptr;
  155469. ISLOW_MULT_TYPE * quantptr;
  155470. int * wsptr;
  155471. JSAMPROW outptr;
  155472. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155473. int ctr;
  155474. int workspace[DCTSIZE2]; /* buffers data between passes */
  155475. SHIFT_TEMPS
  155476. inptr = coef_block;
  155477. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155478. wsptr = workspace;
  155479. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155480. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155481. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155482. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155483. inptr[DCTSIZE*7] == 0) {
  155484. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155485. wsptr[DCTSIZE*0] = dcval;
  155486. wsptr[DCTSIZE*1] = dcval;
  155487. wsptr[DCTSIZE*2] = dcval;
  155488. wsptr[DCTSIZE*3] = dcval;
  155489. wsptr[DCTSIZE*4] = dcval;
  155490. wsptr[DCTSIZE*5] = dcval;
  155491. wsptr[DCTSIZE*6] = dcval;
  155492. wsptr[DCTSIZE*7] = dcval;
  155493. inptr++; /* advance pointers to next column */
  155494. quantptr++;
  155495. wsptr++;
  155496. continue;
  155497. }
  155498. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155499. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155500. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155501. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155502. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155503. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155504. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155505. tmp0 = (z2 + z3) << CONST_BITS;
  155506. tmp1 = (z2 - z3) << CONST_BITS;
  155507. tmp10 = tmp0 + tmp3;
  155508. tmp13 = tmp0 - tmp3;
  155509. tmp11 = tmp1 + tmp2;
  155510. tmp12 = tmp1 - tmp2;
  155511. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155512. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155513. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155514. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155515. z1 = tmp0 + tmp3;
  155516. z2 = tmp1 + tmp2;
  155517. z3 = tmp0 + tmp2;
  155518. z4 = tmp1 + tmp3;
  155519. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155520. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155521. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155522. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155523. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155524. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155525. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155526. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155527. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155528. z3 += z5;
  155529. z4 += z5;
  155530. tmp0 += z1 + z3;
  155531. tmp1 += z2 + z4;
  155532. tmp2 += z2 + z3;
  155533. tmp3 += z1 + z4;
  155534. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155535. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155536. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155537. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155538. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155539. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155540. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155541. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155542. inptr++; /* advance pointers to next column */
  155543. quantptr++;
  155544. wsptr++;
  155545. }
  155546. wsptr = workspace;
  155547. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155548. outptr = output_buf[ctr] + output_col;
  155549. #ifndef NO_ZERO_ROW_TEST
  155550. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155551. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155552. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155553. & RANGE_MASK];
  155554. outptr[0] = dcval;
  155555. outptr[1] = dcval;
  155556. outptr[2] = dcval;
  155557. outptr[3] = dcval;
  155558. outptr[4] = dcval;
  155559. outptr[5] = dcval;
  155560. outptr[6] = dcval;
  155561. outptr[7] = dcval;
  155562. wsptr += DCTSIZE; /* advance pointer to next row */
  155563. continue;
  155564. }
  155565. #endif
  155566. z2 = (INT32) wsptr[2];
  155567. z3 = (INT32) wsptr[6];
  155568. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155569. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155570. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155571. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155572. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155573. tmp10 = tmp0 + tmp3;
  155574. tmp13 = tmp0 - tmp3;
  155575. tmp11 = tmp1 + tmp2;
  155576. tmp12 = tmp1 - tmp2;
  155577. tmp0 = (INT32) wsptr[7];
  155578. tmp1 = (INT32) wsptr[5];
  155579. tmp2 = (INT32) wsptr[3];
  155580. tmp3 = (INT32) wsptr[1];
  155581. z1 = tmp0 + tmp3;
  155582. z2 = tmp1 + tmp2;
  155583. z3 = tmp0 + tmp2;
  155584. z4 = tmp1 + tmp3;
  155585. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155586. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155587. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155588. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155589. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155590. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155591. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155592. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155593. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155594. z3 += z5;
  155595. z4 += z5;
  155596. tmp0 += z1 + z3;
  155597. tmp1 += z2 + z4;
  155598. tmp2 += z2 + z3;
  155599. tmp3 += z1 + z4;
  155600. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155601. CONST_BITS+PASS1_BITS+3)
  155602. & RANGE_MASK];
  155603. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155604. CONST_BITS+PASS1_BITS+3)
  155605. & RANGE_MASK];
  155606. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155607. CONST_BITS+PASS1_BITS+3)
  155608. & RANGE_MASK];
  155609. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155610. CONST_BITS+PASS1_BITS+3)
  155611. & RANGE_MASK];
  155612. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155613. CONST_BITS+PASS1_BITS+3)
  155614. & RANGE_MASK];
  155615. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155616. CONST_BITS+PASS1_BITS+3)
  155617. & RANGE_MASK];
  155618. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155619. CONST_BITS+PASS1_BITS+3)
  155620. & RANGE_MASK];
  155621. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155622. CONST_BITS+PASS1_BITS+3)
  155623. & RANGE_MASK];
  155624. wsptr += DCTSIZE; /* advance pointer to next row */
  155625. }
  155626. }
  155627. #endif /* DCT_ISLOW_SUPPORTED */
  155628. /*** End of inlined file: jidctint.c ***/
  155629. /*** Start of inlined file: jidctred.c ***/
  155630. #define JPEG_INTERNALS
  155631. #ifdef IDCT_SCALING_SUPPORTED
  155632. #if DCTSIZE != 8
  155633. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155634. #endif
  155635. #if BITS_IN_JSAMPLE == 8
  155636. #define CONST_BITS 13
  155637. #define PASS1_BITS 2
  155638. #else
  155639. #define CONST_BITS 13
  155640. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155641. #endif
  155642. #if CONST_BITS == 13
  155643. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155644. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155645. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155646. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155647. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155648. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155649. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155650. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155651. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155652. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155653. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155654. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155655. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155656. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155657. #else
  155658. #define FIX_0_211164243 FIX(0.211164243)
  155659. #define FIX_0_509795579 FIX(0.509795579)
  155660. #define FIX_0_601344887 FIX(0.601344887)
  155661. #define FIX_0_720959822 FIX(0.720959822)
  155662. #define FIX_0_765366865 FIX(0.765366865)
  155663. #define FIX_0_850430095 FIX(0.850430095)
  155664. #define FIX_0_899976223 FIX(0.899976223)
  155665. #define FIX_1_061594337 FIX(1.061594337)
  155666. #define FIX_1_272758580 FIX(1.272758580)
  155667. #define FIX_1_451774981 FIX(1.451774981)
  155668. #define FIX_1_847759065 FIX(1.847759065)
  155669. #define FIX_2_172734803 FIX(2.172734803)
  155670. #define FIX_2_562915447 FIX(2.562915447)
  155671. #define FIX_3_624509785 FIX(3.624509785)
  155672. #endif
  155673. #if BITS_IN_JSAMPLE == 8
  155674. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155675. #else
  155676. #define MULTIPLY(var,const) ((var) * (const))
  155677. #endif
  155678. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155679. GLOBAL(void)
  155680. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155681. JCOEFPTR coef_block,
  155682. JSAMPARRAY output_buf, JDIMENSION output_col)
  155683. {
  155684. INT32 tmp0, tmp2, tmp10, tmp12;
  155685. INT32 z1, z2, z3, z4;
  155686. JCOEFPTR inptr;
  155687. ISLOW_MULT_TYPE * quantptr;
  155688. int * wsptr;
  155689. JSAMPROW outptr;
  155690. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155691. int ctr;
  155692. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155693. SHIFT_TEMPS
  155694. inptr = coef_block;
  155695. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155696. wsptr = workspace;
  155697. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155698. if (ctr == DCTSIZE-4)
  155699. continue;
  155700. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155701. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155702. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155703. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155704. wsptr[DCTSIZE*0] = dcval;
  155705. wsptr[DCTSIZE*1] = dcval;
  155706. wsptr[DCTSIZE*2] = dcval;
  155707. wsptr[DCTSIZE*3] = dcval;
  155708. continue;
  155709. }
  155710. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155711. tmp0 <<= (CONST_BITS+1);
  155712. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155713. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155714. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155715. tmp10 = tmp0 + tmp2;
  155716. tmp12 = tmp0 - tmp2;
  155717. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155718. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155719. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155720. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155721. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155722. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155723. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155724. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155725. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155726. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155727. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155728. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155729. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155730. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155731. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155732. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155733. }
  155734. wsptr = workspace;
  155735. for (ctr = 0; ctr < 4; ctr++) {
  155736. outptr = output_buf[ctr] + output_col;
  155737. #ifndef NO_ZERO_ROW_TEST
  155738. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155739. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155740. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155741. & RANGE_MASK];
  155742. outptr[0] = dcval;
  155743. outptr[1] = dcval;
  155744. outptr[2] = dcval;
  155745. outptr[3] = dcval;
  155746. wsptr += DCTSIZE; /* advance pointer to next row */
  155747. continue;
  155748. }
  155749. #endif
  155750. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155751. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155752. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155753. tmp10 = tmp0 + tmp2;
  155754. tmp12 = tmp0 - tmp2;
  155755. z1 = (INT32) wsptr[7];
  155756. z2 = (INT32) wsptr[5];
  155757. z3 = (INT32) wsptr[3];
  155758. z4 = (INT32) wsptr[1];
  155759. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155760. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155761. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155762. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155763. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155764. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155765. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155766. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155767. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155768. CONST_BITS+PASS1_BITS+3+1)
  155769. & RANGE_MASK];
  155770. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155771. CONST_BITS+PASS1_BITS+3+1)
  155772. & RANGE_MASK];
  155773. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155774. CONST_BITS+PASS1_BITS+3+1)
  155775. & RANGE_MASK];
  155776. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155777. CONST_BITS+PASS1_BITS+3+1)
  155778. & RANGE_MASK];
  155779. wsptr += DCTSIZE; /* advance pointer to next row */
  155780. }
  155781. }
  155782. GLOBAL(void)
  155783. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155784. JCOEFPTR coef_block,
  155785. JSAMPARRAY output_buf, JDIMENSION output_col)
  155786. {
  155787. INT32 tmp0, tmp10, z1;
  155788. JCOEFPTR inptr;
  155789. ISLOW_MULT_TYPE * quantptr;
  155790. int * wsptr;
  155791. JSAMPROW outptr;
  155792. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155793. int ctr;
  155794. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155795. SHIFT_TEMPS
  155796. inptr = coef_block;
  155797. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155798. wsptr = workspace;
  155799. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155800. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155801. continue;
  155802. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155803. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155804. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155805. wsptr[DCTSIZE*0] = dcval;
  155806. wsptr[DCTSIZE*1] = dcval;
  155807. continue;
  155808. }
  155809. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155810. tmp10 = z1 << (CONST_BITS+2);
  155811. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155812. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  155813. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155814. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  155815. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155816. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  155817. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155818. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155819. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  155820. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  155821. }
  155822. wsptr = workspace;
  155823. for (ctr = 0; ctr < 2; ctr++) {
  155824. outptr = output_buf[ctr] + output_col;
  155825. #ifndef NO_ZERO_ROW_TEST
  155826. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  155827. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155828. & RANGE_MASK];
  155829. outptr[0] = dcval;
  155830. outptr[1] = dcval;
  155831. wsptr += DCTSIZE; /* advance pointer to next row */
  155832. continue;
  155833. }
  155834. #endif
  155835. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  155836. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  155837. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  155838. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  155839. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155840. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  155841. CONST_BITS+PASS1_BITS+3+2)
  155842. & RANGE_MASK];
  155843. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  155844. CONST_BITS+PASS1_BITS+3+2)
  155845. & RANGE_MASK];
  155846. wsptr += DCTSIZE; /* advance pointer to next row */
  155847. }
  155848. }
  155849. GLOBAL(void)
  155850. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155851. JCOEFPTR coef_block,
  155852. JSAMPARRAY output_buf, JDIMENSION output_col)
  155853. {
  155854. int dcval;
  155855. ISLOW_MULT_TYPE * quantptr;
  155856. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155857. SHIFT_TEMPS
  155858. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155859. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  155860. dcval = (int) DESCALE((INT32) dcval, 3);
  155861. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  155862. }
  155863. #endif /* IDCT_SCALING_SUPPORTED */
  155864. /*** End of inlined file: jidctred.c ***/
  155865. /*** Start of inlined file: jmemmgr.c ***/
  155866. #define JPEG_INTERNALS
  155867. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  155868. /*** Start of inlined file: jmemsys.h ***/
  155869. #ifndef __jmemsys_h__
  155870. #define __jmemsys_h__
  155871. #ifdef NEED_SHORT_EXTERNAL_NAMES
  155872. #define jpeg_get_small jGetSmall
  155873. #define jpeg_free_small jFreeSmall
  155874. #define jpeg_get_large jGetLarge
  155875. #define jpeg_free_large jFreeLarge
  155876. #define jpeg_mem_available jMemAvail
  155877. #define jpeg_open_backing_store jOpenBackStore
  155878. #define jpeg_mem_init jMemInit
  155879. #define jpeg_mem_term jMemTerm
  155880. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  155881. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  155882. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  155883. size_t sizeofobject));
  155884. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  155885. size_t sizeofobject));
  155886. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  155887. size_t sizeofobject));
  155888. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  155889. #define MAX_ALLOC_CHUNK 1000000000L
  155890. #endif
  155891. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  155892. long min_bytes_needed,
  155893. long max_bytes_needed,
  155894. long already_allocated));
  155895. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  155896. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  155897. typedef unsigned short XMSH; /* type of extended-memory handles */
  155898. typedef unsigned short EMSH; /* type of expanded-memory handles */
  155899. typedef union {
  155900. short file_handle; /* DOS file handle if it's a temp file */
  155901. XMSH xms_handle; /* handle if it's a chunk of XMS */
  155902. EMSH ems_handle; /* handle if it's a chunk of EMS */
  155903. } handle_union;
  155904. #endif /* USE_MSDOS_MEMMGR */
  155905. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  155906. #include <Files.h>
  155907. #endif /* USE_MAC_MEMMGR */
  155908. //typedef struct backing_store_struct * backing_store_ptr;
  155909. typedef struct backing_store_struct {
  155910. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  155911. struct backing_store_struct *info,
  155912. void FAR * buffer_address,
  155913. long file_offset, long byte_count));
  155914. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  155915. struct backing_store_struct *info,
  155916. void FAR * buffer_address,
  155917. long file_offset, long byte_count));
  155918. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  155919. struct backing_store_struct *info));
  155920. #ifdef USE_MSDOS_MEMMGR
  155921. handle_union handle; /* reference to backing-store storage object */
  155922. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  155923. #else
  155924. #ifdef USE_MAC_MEMMGR
  155925. short temp_file; /* file reference number to temp file */
  155926. FSSpec tempSpec; /* the FSSpec for the temp file */
  155927. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  155928. #else
  155929. FILE * temp_file; /* stdio reference to temp file */
  155930. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  155931. #endif
  155932. #endif
  155933. } backing_store_info;
  155934. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  155935. struct backing_store_struct *info,
  155936. long total_bytes_needed));
  155937. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  155938. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  155939. #endif
  155940. /*** End of inlined file: jmemsys.h ***/
  155941. /* import the system-dependent declarations */
  155942. #ifndef NO_GETENV
  155943. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  155944. extern char * getenv JPP((const char * name));
  155945. #endif
  155946. #endif
  155947. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  155948. #define ALIGN_TYPE double
  155949. #endif
  155950. typedef union small_pool_struct * small_pool_ptr;
  155951. typedef union small_pool_struct {
  155952. struct {
  155953. small_pool_ptr next; /* next in list of pools */
  155954. size_t bytes_used; /* how many bytes already used within pool */
  155955. size_t bytes_left; /* bytes still available in this pool */
  155956. } hdr;
  155957. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  155958. } small_pool_hdr;
  155959. typedef union large_pool_struct FAR * large_pool_ptr;
  155960. typedef union large_pool_struct {
  155961. struct {
  155962. large_pool_ptr next; /* next in list of pools */
  155963. size_t bytes_used; /* how many bytes already used within pool */
  155964. size_t bytes_left; /* bytes still available in this pool */
  155965. } hdr;
  155966. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  155967. } large_pool_hdr;
  155968. typedef struct {
  155969. struct jpeg_memory_mgr pub; /* public fields */
  155970. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  155971. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  155972. jvirt_sarray_ptr virt_sarray_list;
  155973. jvirt_barray_ptr virt_barray_list;
  155974. long total_space_allocated;
  155975. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  155976. } my_memory_mgr;
  155977. typedef my_memory_mgr * my_mem_ptr;
  155978. struct jvirt_sarray_control {
  155979. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  155980. JDIMENSION rows_in_array; /* total virtual array height */
  155981. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  155982. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  155983. JDIMENSION rows_in_mem; /* height of memory buffer */
  155984. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  155985. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  155986. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  155987. boolean pre_zero; /* pre-zero mode requested? */
  155988. boolean dirty; /* do current buffer contents need written? */
  155989. boolean b_s_open; /* is backing-store data valid? */
  155990. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  155991. backing_store_info b_s_info; /* System-dependent control info */
  155992. };
  155993. struct jvirt_barray_control {
  155994. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  155995. JDIMENSION rows_in_array; /* total virtual array height */
  155996. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  155997. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  155998. JDIMENSION rows_in_mem; /* height of memory buffer */
  155999. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156000. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156001. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156002. boolean pre_zero; /* pre-zero mode requested? */
  156003. boolean dirty; /* do current buffer contents need written? */
  156004. boolean b_s_open; /* is backing-store data valid? */
  156005. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156006. backing_store_info b_s_info; /* System-dependent control info */
  156007. };
  156008. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156009. LOCAL(void)
  156010. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156011. {
  156012. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156013. small_pool_ptr shdr_ptr;
  156014. large_pool_ptr lhdr_ptr;
  156015. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156016. pool_id, mem->total_space_allocated);
  156017. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156018. lhdr_ptr = lhdr_ptr->hdr.next) {
  156019. fprintf(stderr, " Large chunk used %ld\n",
  156020. (long) lhdr_ptr->hdr.bytes_used);
  156021. }
  156022. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156023. shdr_ptr = shdr_ptr->hdr.next) {
  156024. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156025. (long) shdr_ptr->hdr.bytes_used,
  156026. (long) shdr_ptr->hdr.bytes_left);
  156027. }
  156028. }
  156029. #endif /* MEM_STATS */
  156030. LOCAL(void)
  156031. out_of_memory (j_common_ptr cinfo, int which)
  156032. {
  156033. #ifdef MEM_STATS
  156034. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156035. #endif
  156036. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156037. }
  156038. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156039. {
  156040. 1600, /* first PERMANENT pool */
  156041. 16000 /* first IMAGE pool */
  156042. };
  156043. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156044. {
  156045. 0, /* additional PERMANENT pools */
  156046. 5000 /* additional IMAGE pools */
  156047. };
  156048. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156049. METHODDEF(void *)
  156050. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156051. {
  156052. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156053. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156054. char * data_ptr;
  156055. size_t odd_bytes, min_request, slop;
  156056. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156057. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156058. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156059. if (odd_bytes > 0)
  156060. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156061. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156062. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156063. prev_hdr_ptr = NULL;
  156064. hdr_ptr = mem->small_list[pool_id];
  156065. while (hdr_ptr != NULL) {
  156066. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156067. break; /* found pool with enough space */
  156068. prev_hdr_ptr = hdr_ptr;
  156069. hdr_ptr = hdr_ptr->hdr.next;
  156070. }
  156071. if (hdr_ptr == NULL) {
  156072. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156073. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156074. slop = first_pool_slop[pool_id];
  156075. else
  156076. slop = extra_pool_slop[pool_id];
  156077. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156078. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156079. for (;;) {
  156080. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156081. if (hdr_ptr != NULL)
  156082. break;
  156083. slop /= 2;
  156084. if (slop < MIN_SLOP) /* give up when it gets real small */
  156085. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156086. }
  156087. mem->total_space_allocated += min_request + slop;
  156088. hdr_ptr->hdr.next = NULL;
  156089. hdr_ptr->hdr.bytes_used = 0;
  156090. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156091. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156092. mem->small_list[pool_id] = hdr_ptr;
  156093. else
  156094. prev_hdr_ptr->hdr.next = hdr_ptr;
  156095. }
  156096. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156097. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156098. hdr_ptr->hdr.bytes_used += sizeofobject;
  156099. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156100. return (void *) data_ptr;
  156101. }
  156102. METHODDEF(void FAR *)
  156103. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156104. {
  156105. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156106. large_pool_ptr hdr_ptr;
  156107. size_t odd_bytes;
  156108. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156109. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156110. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156111. if (odd_bytes > 0)
  156112. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156113. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156114. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156115. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156116. SIZEOF(large_pool_hdr));
  156117. if (hdr_ptr == NULL)
  156118. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156119. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156120. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156121. hdr_ptr->hdr.bytes_used = sizeofobject;
  156122. hdr_ptr->hdr.bytes_left = 0;
  156123. mem->large_list[pool_id] = hdr_ptr;
  156124. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156125. }
  156126. METHODDEF(JSAMPARRAY)
  156127. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156128. JDIMENSION samplesperrow, JDIMENSION numrows)
  156129. {
  156130. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156131. JSAMPARRAY result;
  156132. JSAMPROW workspace;
  156133. JDIMENSION rowsperchunk, currow, i;
  156134. long ltemp;
  156135. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156136. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156137. if (ltemp <= 0)
  156138. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156139. if (ltemp < (long) numrows)
  156140. rowsperchunk = (JDIMENSION) ltemp;
  156141. else
  156142. rowsperchunk = numrows;
  156143. mem->last_rowsperchunk = rowsperchunk;
  156144. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156145. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156146. currow = 0;
  156147. while (currow < numrows) {
  156148. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156149. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156150. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156151. * SIZEOF(JSAMPLE)));
  156152. for (i = rowsperchunk; i > 0; i--) {
  156153. result[currow++] = workspace;
  156154. workspace += samplesperrow;
  156155. }
  156156. }
  156157. return result;
  156158. }
  156159. METHODDEF(JBLOCKARRAY)
  156160. alloc_barray (j_common_ptr cinfo, int pool_id,
  156161. JDIMENSION blocksperrow, JDIMENSION numrows)
  156162. {
  156163. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156164. JBLOCKARRAY result;
  156165. JBLOCKROW workspace;
  156166. JDIMENSION rowsperchunk, currow, i;
  156167. long ltemp;
  156168. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156169. ((long) blocksperrow * SIZEOF(JBLOCK));
  156170. if (ltemp <= 0)
  156171. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156172. if (ltemp < (long) numrows)
  156173. rowsperchunk = (JDIMENSION) ltemp;
  156174. else
  156175. rowsperchunk = numrows;
  156176. mem->last_rowsperchunk = rowsperchunk;
  156177. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156178. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156179. currow = 0;
  156180. while (currow < numrows) {
  156181. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156182. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156183. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156184. * SIZEOF(JBLOCK)));
  156185. for (i = rowsperchunk; i > 0; i--) {
  156186. result[currow++] = workspace;
  156187. workspace += blocksperrow;
  156188. }
  156189. }
  156190. return result;
  156191. }
  156192. METHODDEF(jvirt_sarray_ptr)
  156193. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156194. JDIMENSION samplesperrow, JDIMENSION numrows,
  156195. JDIMENSION maxaccess)
  156196. {
  156197. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156198. jvirt_sarray_ptr result;
  156199. if (pool_id != JPOOL_IMAGE)
  156200. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156201. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156202. SIZEOF(struct jvirt_sarray_control));
  156203. result->mem_buffer = NULL; /* marks array not yet realized */
  156204. result->rows_in_array = numrows;
  156205. result->samplesperrow = samplesperrow;
  156206. result->maxaccess = maxaccess;
  156207. result->pre_zero = pre_zero;
  156208. result->b_s_open = FALSE; /* no associated backing-store object */
  156209. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156210. mem->virt_sarray_list = result;
  156211. return result;
  156212. }
  156213. METHODDEF(jvirt_barray_ptr)
  156214. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156215. JDIMENSION blocksperrow, JDIMENSION numrows,
  156216. JDIMENSION maxaccess)
  156217. {
  156218. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156219. jvirt_barray_ptr result;
  156220. if (pool_id != JPOOL_IMAGE)
  156221. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156222. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156223. SIZEOF(struct jvirt_barray_control));
  156224. result->mem_buffer = NULL; /* marks array not yet realized */
  156225. result->rows_in_array = numrows;
  156226. result->blocksperrow = blocksperrow;
  156227. result->maxaccess = maxaccess;
  156228. result->pre_zero = pre_zero;
  156229. result->b_s_open = FALSE; /* no associated backing-store object */
  156230. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156231. mem->virt_barray_list = result;
  156232. return result;
  156233. }
  156234. METHODDEF(void)
  156235. realize_virt_arrays (j_common_ptr cinfo)
  156236. {
  156237. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156238. long space_per_minheight, maximum_space, avail_mem;
  156239. long minheights, max_minheights;
  156240. jvirt_sarray_ptr sptr;
  156241. jvirt_barray_ptr bptr;
  156242. space_per_minheight = 0;
  156243. maximum_space = 0;
  156244. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156245. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156246. space_per_minheight += (long) sptr->maxaccess *
  156247. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156248. maximum_space += (long) sptr->rows_in_array *
  156249. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156250. }
  156251. }
  156252. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156253. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156254. space_per_minheight += (long) bptr->maxaccess *
  156255. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156256. maximum_space += (long) bptr->rows_in_array *
  156257. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156258. }
  156259. }
  156260. if (space_per_minheight <= 0)
  156261. return; /* no unrealized arrays, no work */
  156262. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156263. mem->total_space_allocated);
  156264. if (avail_mem >= maximum_space)
  156265. max_minheights = 1000000000L;
  156266. else {
  156267. max_minheights = avail_mem / space_per_minheight;
  156268. if (max_minheights <= 0)
  156269. max_minheights = 1;
  156270. }
  156271. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156272. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156273. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156274. if (minheights <= max_minheights) {
  156275. sptr->rows_in_mem = sptr->rows_in_array;
  156276. } else {
  156277. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156278. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156279. (long) sptr->rows_in_array *
  156280. (long) sptr->samplesperrow *
  156281. (long) SIZEOF(JSAMPLE));
  156282. sptr->b_s_open = TRUE;
  156283. }
  156284. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156285. sptr->samplesperrow, sptr->rows_in_mem);
  156286. sptr->rowsperchunk = mem->last_rowsperchunk;
  156287. sptr->cur_start_row = 0;
  156288. sptr->first_undef_row = 0;
  156289. sptr->dirty = FALSE;
  156290. }
  156291. }
  156292. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156293. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156294. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156295. if (minheights <= max_minheights) {
  156296. bptr->rows_in_mem = bptr->rows_in_array;
  156297. } else {
  156298. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156299. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156300. (long) bptr->rows_in_array *
  156301. (long) bptr->blocksperrow *
  156302. (long) SIZEOF(JBLOCK));
  156303. bptr->b_s_open = TRUE;
  156304. }
  156305. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156306. bptr->blocksperrow, bptr->rows_in_mem);
  156307. bptr->rowsperchunk = mem->last_rowsperchunk;
  156308. bptr->cur_start_row = 0;
  156309. bptr->first_undef_row = 0;
  156310. bptr->dirty = FALSE;
  156311. }
  156312. }
  156313. }
  156314. LOCAL(void)
  156315. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156316. {
  156317. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156318. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156319. file_offset = ptr->cur_start_row * bytesperrow;
  156320. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156321. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156322. thisrow = (long) ptr->cur_start_row + i;
  156323. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156324. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156325. if (rows <= 0) /* this chunk might be past end of file! */
  156326. break;
  156327. byte_count = rows * bytesperrow;
  156328. if (writing)
  156329. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156330. (void FAR *) ptr->mem_buffer[i],
  156331. file_offset, byte_count);
  156332. else
  156333. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156334. (void FAR *) ptr->mem_buffer[i],
  156335. file_offset, byte_count);
  156336. file_offset += byte_count;
  156337. }
  156338. }
  156339. LOCAL(void)
  156340. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156341. {
  156342. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156343. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156344. file_offset = ptr->cur_start_row * bytesperrow;
  156345. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156346. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156347. thisrow = (long) ptr->cur_start_row + i;
  156348. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156349. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156350. if (rows <= 0) /* this chunk might be past end of file! */
  156351. break;
  156352. byte_count = rows * bytesperrow;
  156353. if (writing)
  156354. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156355. (void FAR *) ptr->mem_buffer[i],
  156356. file_offset, byte_count);
  156357. else
  156358. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156359. (void FAR *) ptr->mem_buffer[i],
  156360. file_offset, byte_count);
  156361. file_offset += byte_count;
  156362. }
  156363. }
  156364. METHODDEF(JSAMPARRAY)
  156365. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156366. JDIMENSION start_row, JDIMENSION num_rows,
  156367. boolean writable)
  156368. {
  156369. JDIMENSION end_row = start_row + num_rows;
  156370. JDIMENSION undef_row;
  156371. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156372. ptr->mem_buffer == NULL)
  156373. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156374. if (start_row < ptr->cur_start_row ||
  156375. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156376. if (! ptr->b_s_open)
  156377. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156378. if (ptr->dirty) {
  156379. do_sarray_io(cinfo, ptr, TRUE);
  156380. ptr->dirty = FALSE;
  156381. }
  156382. if (start_row > ptr->cur_start_row) {
  156383. ptr->cur_start_row = start_row;
  156384. } else {
  156385. long ltemp;
  156386. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156387. if (ltemp < 0)
  156388. ltemp = 0; /* don't fall off front end of file */
  156389. ptr->cur_start_row = (JDIMENSION) ltemp;
  156390. }
  156391. do_sarray_io(cinfo, ptr, FALSE);
  156392. }
  156393. if (ptr->first_undef_row < end_row) {
  156394. if (ptr->first_undef_row < start_row) {
  156395. if (writable) /* writer skipped over a section of array */
  156396. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156397. undef_row = start_row; /* but reader is allowed to read ahead */
  156398. } else {
  156399. undef_row = ptr->first_undef_row;
  156400. }
  156401. if (writable)
  156402. ptr->first_undef_row = end_row;
  156403. if (ptr->pre_zero) {
  156404. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156405. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156406. end_row -= ptr->cur_start_row;
  156407. while (undef_row < end_row) {
  156408. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156409. undef_row++;
  156410. }
  156411. } else {
  156412. if (! writable) /* reader looking at undefined data */
  156413. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156414. }
  156415. }
  156416. if (writable)
  156417. ptr->dirty = TRUE;
  156418. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156419. }
  156420. METHODDEF(JBLOCKARRAY)
  156421. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156422. JDIMENSION start_row, JDIMENSION num_rows,
  156423. boolean writable)
  156424. {
  156425. JDIMENSION end_row = start_row + num_rows;
  156426. JDIMENSION undef_row;
  156427. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156428. ptr->mem_buffer == NULL)
  156429. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156430. if (start_row < ptr->cur_start_row ||
  156431. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156432. if (! ptr->b_s_open)
  156433. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156434. if (ptr->dirty) {
  156435. do_barray_io(cinfo, ptr, TRUE);
  156436. ptr->dirty = FALSE;
  156437. }
  156438. if (start_row > ptr->cur_start_row) {
  156439. ptr->cur_start_row = start_row;
  156440. } else {
  156441. long ltemp;
  156442. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156443. if (ltemp < 0)
  156444. ltemp = 0; /* don't fall off front end of file */
  156445. ptr->cur_start_row = (JDIMENSION) ltemp;
  156446. }
  156447. do_barray_io(cinfo, ptr, FALSE);
  156448. }
  156449. if (ptr->first_undef_row < end_row) {
  156450. if (ptr->first_undef_row < start_row) {
  156451. if (writable) /* writer skipped over a section of array */
  156452. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156453. undef_row = start_row; /* but reader is allowed to read ahead */
  156454. } else {
  156455. undef_row = ptr->first_undef_row;
  156456. }
  156457. if (writable)
  156458. ptr->first_undef_row = end_row;
  156459. if (ptr->pre_zero) {
  156460. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156461. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156462. end_row -= ptr->cur_start_row;
  156463. while (undef_row < end_row) {
  156464. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156465. undef_row++;
  156466. }
  156467. } else {
  156468. if (! writable) /* reader looking at undefined data */
  156469. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156470. }
  156471. }
  156472. if (writable)
  156473. ptr->dirty = TRUE;
  156474. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156475. }
  156476. METHODDEF(void)
  156477. free_pool (j_common_ptr cinfo, int pool_id)
  156478. {
  156479. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156480. small_pool_ptr shdr_ptr;
  156481. large_pool_ptr lhdr_ptr;
  156482. size_t space_freed;
  156483. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156484. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156485. #ifdef MEM_STATS
  156486. if (cinfo->err->trace_level > 1)
  156487. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156488. #endif
  156489. if (pool_id == JPOOL_IMAGE) {
  156490. jvirt_sarray_ptr sptr;
  156491. jvirt_barray_ptr bptr;
  156492. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156493. if (sptr->b_s_open) { /* there may be no backing store */
  156494. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156495. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156496. }
  156497. }
  156498. mem->virt_sarray_list = NULL;
  156499. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156500. if (bptr->b_s_open) { /* there may be no backing store */
  156501. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156502. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156503. }
  156504. }
  156505. mem->virt_barray_list = NULL;
  156506. }
  156507. lhdr_ptr = mem->large_list[pool_id];
  156508. mem->large_list[pool_id] = NULL;
  156509. while (lhdr_ptr != NULL) {
  156510. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156511. space_freed = lhdr_ptr->hdr.bytes_used +
  156512. lhdr_ptr->hdr.bytes_left +
  156513. SIZEOF(large_pool_hdr);
  156514. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156515. mem->total_space_allocated -= space_freed;
  156516. lhdr_ptr = next_lhdr_ptr;
  156517. }
  156518. shdr_ptr = mem->small_list[pool_id];
  156519. mem->small_list[pool_id] = NULL;
  156520. while (shdr_ptr != NULL) {
  156521. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156522. space_freed = shdr_ptr->hdr.bytes_used +
  156523. shdr_ptr->hdr.bytes_left +
  156524. SIZEOF(small_pool_hdr);
  156525. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156526. mem->total_space_allocated -= space_freed;
  156527. shdr_ptr = next_shdr_ptr;
  156528. }
  156529. }
  156530. METHODDEF(void)
  156531. self_destruct (j_common_ptr cinfo)
  156532. {
  156533. int pool;
  156534. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156535. free_pool(cinfo, pool);
  156536. }
  156537. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156538. cinfo->mem = NULL; /* ensures I will be called only once */
  156539. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156540. }
  156541. GLOBAL(void)
  156542. jinit_memory_mgr (j_common_ptr cinfo)
  156543. {
  156544. my_mem_ptr mem;
  156545. long max_to_use;
  156546. int pool;
  156547. size_t test_mac;
  156548. cinfo->mem = NULL; /* for safety if init fails */
  156549. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156550. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156551. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156552. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156553. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156554. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156555. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156556. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156557. if (mem == NULL) {
  156558. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156559. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156560. }
  156561. mem->pub.alloc_small = alloc_small;
  156562. mem->pub.alloc_large = alloc_large;
  156563. mem->pub.alloc_sarray = alloc_sarray;
  156564. mem->pub.alloc_barray = alloc_barray;
  156565. mem->pub.request_virt_sarray = request_virt_sarray;
  156566. mem->pub.request_virt_barray = request_virt_barray;
  156567. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156568. mem->pub.access_virt_sarray = access_virt_sarray;
  156569. mem->pub.access_virt_barray = access_virt_barray;
  156570. mem->pub.free_pool = free_pool;
  156571. mem->pub.self_destruct = self_destruct;
  156572. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156573. mem->pub.max_memory_to_use = max_to_use;
  156574. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156575. mem->small_list[pool] = NULL;
  156576. mem->large_list[pool] = NULL;
  156577. }
  156578. mem->virt_sarray_list = NULL;
  156579. mem->virt_barray_list = NULL;
  156580. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156581. cinfo->mem = & mem->pub;
  156582. #ifndef NO_GETENV
  156583. { char * memenv;
  156584. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156585. char ch = 'x';
  156586. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156587. if (ch == 'm' || ch == 'M')
  156588. max_to_use *= 1000L;
  156589. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156590. }
  156591. }
  156592. }
  156593. #endif
  156594. }
  156595. /*** End of inlined file: jmemmgr.c ***/
  156596. /*** Start of inlined file: jmemnobs.c ***/
  156597. #define JPEG_INTERNALS
  156598. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156599. extern void * malloc JPP((size_t size));
  156600. extern void free JPP((void *ptr));
  156601. #endif
  156602. GLOBAL(void *)
  156603. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156604. {
  156605. return (void *) malloc(sizeofobject);
  156606. }
  156607. GLOBAL(void)
  156608. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156609. {
  156610. free(object);
  156611. }
  156612. GLOBAL(void FAR *)
  156613. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156614. {
  156615. return (void FAR *) malloc(sizeofobject);
  156616. }
  156617. GLOBAL(void)
  156618. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156619. {
  156620. free(object);
  156621. }
  156622. GLOBAL(long)
  156623. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156624. long max_bytes_needed, long already_allocated)
  156625. {
  156626. return max_bytes_needed;
  156627. }
  156628. GLOBAL(void)
  156629. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156630. long total_bytes_needed)
  156631. {
  156632. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156633. }
  156634. GLOBAL(long)
  156635. jpeg_mem_init (j_common_ptr cinfo)
  156636. {
  156637. return 0; /* just set max_memory_to_use to 0 */
  156638. }
  156639. GLOBAL(void)
  156640. jpeg_mem_term (j_common_ptr cinfo)
  156641. {
  156642. }
  156643. /*** End of inlined file: jmemnobs.c ***/
  156644. /*** Start of inlined file: jquant1.c ***/
  156645. #define JPEG_INTERNALS
  156646. #ifdef QUANT_1PASS_SUPPORTED
  156647. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156648. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156649. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156650. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156651. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156652. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156653. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156654. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156655. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156656. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156657. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156658. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156659. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156660. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156661. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156662. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156663. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156664. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156665. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156666. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156667. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156668. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156669. };
  156670. #if BITS_IN_JSAMPLE == 8
  156671. typedef INT16 FSERROR; /* 16 bits should be enough */
  156672. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156673. #else
  156674. typedef INT32 FSERROR; /* may need more than 16 bits */
  156675. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156676. #endif
  156677. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156678. #define MAX_Q_COMPS 4 /* max components I can handle */
  156679. typedef struct {
  156680. struct jpeg_color_quantizer pub; /* public fields */
  156681. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156682. int sv_actual; /* number of entries in use */
  156683. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156684. boolean is_padded; /* is the colorindex padded for odither? */
  156685. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156686. int row_index; /* cur row's vertical index in dither matrix */
  156687. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156688. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156689. boolean on_odd_row; /* flag to remember which row we are on */
  156690. } my_cquantizer;
  156691. typedef my_cquantizer * my_cquantize_ptr;
  156692. LOCAL(int)
  156693. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156694. {
  156695. int nc = cinfo->out_color_components; /* number of color components */
  156696. int max_colors = cinfo->desired_number_of_colors;
  156697. int total_colors, iroot, i, j;
  156698. boolean changed;
  156699. long temp;
  156700. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156701. iroot = 1;
  156702. do {
  156703. iroot++;
  156704. temp = iroot; /* set temp = iroot ** nc */
  156705. for (i = 1; i < nc; i++)
  156706. temp *= iroot;
  156707. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156708. iroot--; /* now iroot = floor(root) */
  156709. if (iroot < 2)
  156710. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156711. total_colors = 1;
  156712. for (i = 0; i < nc; i++) {
  156713. Ncolors[i] = iroot;
  156714. total_colors *= iroot;
  156715. }
  156716. do {
  156717. changed = FALSE;
  156718. for (i = 0; i < nc; i++) {
  156719. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156720. temp = total_colors / Ncolors[j];
  156721. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156722. if (temp > (long) max_colors)
  156723. break; /* won't fit, done with this pass */
  156724. Ncolors[j]++; /* OK, apply the increment */
  156725. total_colors = (int) temp;
  156726. changed = TRUE;
  156727. }
  156728. } while (changed);
  156729. return total_colors;
  156730. }
  156731. LOCAL(int)
  156732. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156733. {
  156734. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156735. }
  156736. LOCAL(int)
  156737. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156738. {
  156739. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156740. }
  156741. LOCAL(void)
  156742. create_colormap (j_decompress_ptr cinfo)
  156743. {
  156744. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156745. JSAMPARRAY colormap; /* Created colormap */
  156746. int total_colors; /* Number of distinct output colors */
  156747. int i,j,k, nci, blksize, blkdist, ptr, val;
  156748. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156749. if (cinfo->out_color_components == 3)
  156750. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156751. total_colors, cquantize->Ncolors[0],
  156752. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156753. else
  156754. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156755. colormap = (*cinfo->mem->alloc_sarray)
  156756. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156757. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156758. blkdist = total_colors;
  156759. for (i = 0; i < cinfo->out_color_components; i++) {
  156760. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156761. blksize = blkdist / nci;
  156762. for (j = 0; j < nci; j++) {
  156763. val = output_value(cinfo, i, j, nci-1);
  156764. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156765. for (k = 0; k < blksize; k++)
  156766. colormap[i][ptr+k] = (JSAMPLE) val;
  156767. }
  156768. }
  156769. blkdist = blksize; /* blksize of this color is blkdist of next */
  156770. }
  156771. cquantize->sv_colormap = colormap;
  156772. cquantize->sv_actual = total_colors;
  156773. }
  156774. LOCAL(void)
  156775. create_colorindex (j_decompress_ptr cinfo)
  156776. {
  156777. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156778. JSAMPROW indexptr;
  156779. int i,j,k, nci, blksize, val, pad;
  156780. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156781. pad = MAXJSAMPLE*2;
  156782. cquantize->is_padded = TRUE;
  156783. } else {
  156784. pad = 0;
  156785. cquantize->is_padded = FALSE;
  156786. }
  156787. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156788. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156789. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156790. (JDIMENSION) cinfo->out_color_components);
  156791. blksize = cquantize->sv_actual;
  156792. for (i = 0; i < cinfo->out_color_components; i++) {
  156793. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156794. blksize = blksize / nci;
  156795. if (pad)
  156796. cquantize->colorindex[i] += MAXJSAMPLE;
  156797. indexptr = cquantize->colorindex[i];
  156798. val = 0;
  156799. k = largest_input_value(cinfo, i, 0, nci-1);
  156800. for (j = 0; j <= MAXJSAMPLE; j++) {
  156801. while (j > k) /* advance val if past boundary */
  156802. k = largest_input_value(cinfo, i, ++val, nci-1);
  156803. indexptr[j] = (JSAMPLE) (val * blksize);
  156804. }
  156805. if (pad)
  156806. for (j = 1; j <= MAXJSAMPLE; j++) {
  156807. indexptr[-j] = indexptr[0];
  156808. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156809. }
  156810. }
  156811. }
  156812. LOCAL(ODITHER_MATRIX_PTR)
  156813. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  156814. {
  156815. ODITHER_MATRIX_PTR odither;
  156816. int j,k;
  156817. INT32 num,den;
  156818. odither = (ODITHER_MATRIX_PTR)
  156819. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156820. SIZEOF(ODITHER_MATRIX));
  156821. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  156822. for (j = 0; j < ODITHER_SIZE; j++) {
  156823. for (k = 0; k < ODITHER_SIZE; k++) {
  156824. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  156825. * MAXJSAMPLE;
  156826. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  156827. }
  156828. }
  156829. return odither;
  156830. }
  156831. LOCAL(void)
  156832. create_odither_tables (j_decompress_ptr cinfo)
  156833. {
  156834. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156835. ODITHER_MATRIX_PTR odither;
  156836. int i, j, nci;
  156837. for (i = 0; i < cinfo->out_color_components; i++) {
  156838. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156839. odither = NULL; /* search for matching prior component */
  156840. for (j = 0; j < i; j++) {
  156841. if (nci == cquantize->Ncolors[j]) {
  156842. odither = cquantize->odither[j];
  156843. break;
  156844. }
  156845. }
  156846. if (odither == NULL) /* need a new table? */
  156847. odither = make_odither_array(cinfo, nci);
  156848. cquantize->odither[i] = odither;
  156849. }
  156850. }
  156851. METHODDEF(void)
  156852. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156853. JSAMPARRAY output_buf, int num_rows)
  156854. {
  156855. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156856. JSAMPARRAY colorindex = cquantize->colorindex;
  156857. register int pixcode, ci;
  156858. register JSAMPROW ptrin, ptrout;
  156859. int row;
  156860. JDIMENSION col;
  156861. JDIMENSION width = cinfo->output_width;
  156862. register int nc = cinfo->out_color_components;
  156863. for (row = 0; row < num_rows; row++) {
  156864. ptrin = input_buf[row];
  156865. ptrout = output_buf[row];
  156866. for (col = width; col > 0; col--) {
  156867. pixcode = 0;
  156868. for (ci = 0; ci < nc; ci++) {
  156869. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  156870. }
  156871. *ptrout++ = (JSAMPLE) pixcode;
  156872. }
  156873. }
  156874. }
  156875. METHODDEF(void)
  156876. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156877. JSAMPARRAY output_buf, int num_rows)
  156878. {
  156879. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156880. register int pixcode;
  156881. register JSAMPROW ptrin, ptrout;
  156882. JSAMPROW colorindex0 = cquantize->colorindex[0];
  156883. JSAMPROW colorindex1 = cquantize->colorindex[1];
  156884. JSAMPROW colorindex2 = cquantize->colorindex[2];
  156885. int row;
  156886. JDIMENSION col;
  156887. JDIMENSION width = cinfo->output_width;
  156888. for (row = 0; row < num_rows; row++) {
  156889. ptrin = input_buf[row];
  156890. ptrout = output_buf[row];
  156891. for (col = width; col > 0; col--) {
  156892. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  156893. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  156894. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  156895. *ptrout++ = (JSAMPLE) pixcode;
  156896. }
  156897. }
  156898. }
  156899. METHODDEF(void)
  156900. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156901. JSAMPARRAY output_buf, int num_rows)
  156902. {
  156903. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156904. register JSAMPROW input_ptr;
  156905. register JSAMPROW output_ptr;
  156906. JSAMPROW colorindex_ci;
  156907. int * dither; /* points to active row of dither matrix */
  156908. int row_index, col_index; /* current indexes into dither matrix */
  156909. int nc = cinfo->out_color_components;
  156910. int ci;
  156911. int row;
  156912. JDIMENSION col;
  156913. JDIMENSION width = cinfo->output_width;
  156914. for (row = 0; row < num_rows; row++) {
  156915. jzero_far((void FAR *) output_buf[row],
  156916. (size_t) (width * SIZEOF(JSAMPLE)));
  156917. row_index = cquantize->row_index;
  156918. for (ci = 0; ci < nc; ci++) {
  156919. input_ptr = input_buf[row] + ci;
  156920. output_ptr = output_buf[row];
  156921. colorindex_ci = cquantize->colorindex[ci];
  156922. dither = cquantize->odither[ci][row_index];
  156923. col_index = 0;
  156924. for (col = width; col > 0; col--) {
  156925. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  156926. input_ptr += nc;
  156927. output_ptr++;
  156928. col_index = (col_index + 1) & ODITHER_MASK;
  156929. }
  156930. }
  156931. row_index = (row_index + 1) & ODITHER_MASK;
  156932. cquantize->row_index = row_index;
  156933. }
  156934. }
  156935. METHODDEF(void)
  156936. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156937. JSAMPARRAY output_buf, int num_rows)
  156938. {
  156939. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156940. register int pixcode;
  156941. register JSAMPROW input_ptr;
  156942. register JSAMPROW output_ptr;
  156943. JSAMPROW colorindex0 = cquantize->colorindex[0];
  156944. JSAMPROW colorindex1 = cquantize->colorindex[1];
  156945. JSAMPROW colorindex2 = cquantize->colorindex[2];
  156946. int * dither0; /* points to active row of dither matrix */
  156947. int * dither1;
  156948. int * dither2;
  156949. int row_index, col_index; /* current indexes into dither matrix */
  156950. int row;
  156951. JDIMENSION col;
  156952. JDIMENSION width = cinfo->output_width;
  156953. for (row = 0; row < num_rows; row++) {
  156954. row_index = cquantize->row_index;
  156955. input_ptr = input_buf[row];
  156956. output_ptr = output_buf[row];
  156957. dither0 = cquantize->odither[0][row_index];
  156958. dither1 = cquantize->odither[1][row_index];
  156959. dither2 = cquantize->odither[2][row_index];
  156960. col_index = 0;
  156961. for (col = width; col > 0; col--) {
  156962. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  156963. dither0[col_index]]);
  156964. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  156965. dither1[col_index]]);
  156966. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  156967. dither2[col_index]]);
  156968. *output_ptr++ = (JSAMPLE) pixcode;
  156969. col_index = (col_index + 1) & ODITHER_MASK;
  156970. }
  156971. row_index = (row_index + 1) & ODITHER_MASK;
  156972. cquantize->row_index = row_index;
  156973. }
  156974. }
  156975. METHODDEF(void)
  156976. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156977. JSAMPARRAY output_buf, int num_rows)
  156978. {
  156979. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156980. register LOCFSERROR cur; /* current error or pixel value */
  156981. LOCFSERROR belowerr; /* error for pixel below cur */
  156982. LOCFSERROR bpreverr; /* error for below/prev col */
  156983. LOCFSERROR bnexterr; /* error for below/next col */
  156984. LOCFSERROR delta;
  156985. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  156986. register JSAMPROW input_ptr;
  156987. register JSAMPROW output_ptr;
  156988. JSAMPROW colorindex_ci;
  156989. JSAMPROW colormap_ci;
  156990. int pixcode;
  156991. int nc = cinfo->out_color_components;
  156992. int dir; /* 1 for left-to-right, -1 for right-to-left */
  156993. int dirnc; /* dir * nc */
  156994. int ci;
  156995. int row;
  156996. JDIMENSION col;
  156997. JDIMENSION width = cinfo->output_width;
  156998. JSAMPLE *range_limit = cinfo->sample_range_limit;
  156999. SHIFT_TEMPS
  157000. for (row = 0; row < num_rows; row++) {
  157001. jzero_far((void FAR *) output_buf[row],
  157002. (size_t) (width * SIZEOF(JSAMPLE)));
  157003. for (ci = 0; ci < nc; ci++) {
  157004. input_ptr = input_buf[row] + ci;
  157005. output_ptr = output_buf[row];
  157006. if (cquantize->on_odd_row) {
  157007. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157008. output_ptr += width-1;
  157009. dir = -1;
  157010. dirnc = -nc;
  157011. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157012. } else {
  157013. dir = 1;
  157014. dirnc = nc;
  157015. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157016. }
  157017. colorindex_ci = cquantize->colorindex[ci];
  157018. colormap_ci = cquantize->sv_colormap[ci];
  157019. cur = 0;
  157020. belowerr = bpreverr = 0;
  157021. for (col = width; col > 0; col--) {
  157022. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157023. cur += GETJSAMPLE(*input_ptr);
  157024. cur = GETJSAMPLE(range_limit[cur]);
  157025. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157026. *output_ptr += (JSAMPLE) pixcode;
  157027. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157028. bnexterr = cur;
  157029. delta = cur * 2;
  157030. cur += delta; /* form error * 3 */
  157031. errorptr[0] = (FSERROR) (bpreverr + cur);
  157032. cur += delta; /* form error * 5 */
  157033. bpreverr = belowerr + cur;
  157034. belowerr = bnexterr;
  157035. cur += delta; /* form error * 7 */
  157036. input_ptr += dirnc; /* advance input ptr to next column */
  157037. output_ptr += dir; /* advance output ptr to next column */
  157038. errorptr += dir; /* advance errorptr to current column */
  157039. }
  157040. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157041. }
  157042. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157043. }
  157044. }
  157045. LOCAL(void)
  157046. alloc_fs_workspace (j_decompress_ptr cinfo)
  157047. {
  157048. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157049. size_t arraysize;
  157050. int i;
  157051. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157052. for (i = 0; i < cinfo->out_color_components; i++) {
  157053. cquantize->fserrors[i] = (FSERRPTR)
  157054. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157055. }
  157056. }
  157057. METHODDEF(void)
  157058. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157059. {
  157060. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157061. size_t arraysize;
  157062. int i;
  157063. cinfo->colormap = cquantize->sv_colormap;
  157064. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157065. switch (cinfo->dither_mode) {
  157066. case JDITHER_NONE:
  157067. if (cinfo->out_color_components == 3)
  157068. cquantize->pub.color_quantize = color_quantize3;
  157069. else
  157070. cquantize->pub.color_quantize = color_quantize;
  157071. break;
  157072. case JDITHER_ORDERED:
  157073. if (cinfo->out_color_components == 3)
  157074. cquantize->pub.color_quantize = quantize3_ord_dither;
  157075. else
  157076. cquantize->pub.color_quantize = quantize_ord_dither;
  157077. cquantize->row_index = 0; /* initialize state for ordered dither */
  157078. if (! cquantize->is_padded)
  157079. create_colorindex(cinfo);
  157080. if (cquantize->odither[0] == NULL)
  157081. create_odither_tables(cinfo);
  157082. break;
  157083. case JDITHER_FS:
  157084. cquantize->pub.color_quantize = quantize_fs_dither;
  157085. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157086. if (cquantize->fserrors[0] == NULL)
  157087. alloc_fs_workspace(cinfo);
  157088. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157089. for (i = 0; i < cinfo->out_color_components; i++)
  157090. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157091. break;
  157092. default:
  157093. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157094. break;
  157095. }
  157096. }
  157097. METHODDEF(void)
  157098. finish_pass_1_quant (j_decompress_ptr cinfo)
  157099. {
  157100. }
  157101. METHODDEF(void)
  157102. new_color_map_1_quant (j_decompress_ptr cinfo)
  157103. {
  157104. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157105. }
  157106. GLOBAL(void)
  157107. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157108. {
  157109. my_cquantize_ptr cquantize;
  157110. cquantize = (my_cquantize_ptr)
  157111. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157112. SIZEOF(my_cquantizer));
  157113. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157114. cquantize->pub.start_pass = start_pass_1_quant;
  157115. cquantize->pub.finish_pass = finish_pass_1_quant;
  157116. cquantize->pub.new_color_map = new_color_map_1_quant;
  157117. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157118. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157119. if (cinfo->out_color_components > MAX_Q_COMPS)
  157120. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157121. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157122. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157123. create_colormap(cinfo);
  157124. create_colorindex(cinfo);
  157125. if (cinfo->dither_mode == JDITHER_FS)
  157126. alloc_fs_workspace(cinfo);
  157127. }
  157128. #endif /* QUANT_1PASS_SUPPORTED */
  157129. /*** End of inlined file: jquant1.c ***/
  157130. /*** Start of inlined file: jquant2.c ***/
  157131. #define JPEG_INTERNALS
  157132. #ifdef QUANT_2PASS_SUPPORTED
  157133. #define R_SCALE 2 /* scale R distances by this much */
  157134. #define G_SCALE 3 /* scale G distances by this much */
  157135. #define B_SCALE 1 /* and B by this much */
  157136. #if RGB_RED == 0
  157137. #define C0_SCALE R_SCALE
  157138. #endif
  157139. #if RGB_BLUE == 0
  157140. #define C0_SCALE B_SCALE
  157141. #endif
  157142. #if RGB_GREEN == 1
  157143. #define C1_SCALE G_SCALE
  157144. #endif
  157145. #if RGB_RED == 2
  157146. #define C2_SCALE R_SCALE
  157147. #endif
  157148. #if RGB_BLUE == 2
  157149. #define C2_SCALE B_SCALE
  157150. #endif
  157151. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157152. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157153. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157154. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157155. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157156. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157157. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157158. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157159. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157160. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157161. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157162. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157163. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157164. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157165. typedef hist2d * hist3d; /* type for top-level pointer */
  157166. #if BITS_IN_JSAMPLE == 8
  157167. typedef INT16 FSERROR; /* 16 bits should be enough */
  157168. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157169. #else
  157170. typedef INT32 FSERROR; /* may need more than 16 bits */
  157171. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157172. #endif
  157173. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157174. typedef struct {
  157175. struct jpeg_color_quantizer pub; /* public fields */
  157176. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157177. int desired; /* desired # of colors = size of colormap */
  157178. hist3d histogram; /* pointer to the histogram */
  157179. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157180. FSERRPTR fserrors; /* accumulated errors */
  157181. boolean on_odd_row; /* flag to remember which row we are on */
  157182. int * error_limiter; /* table for clamping the applied error */
  157183. } my_cquantizer2;
  157184. typedef my_cquantizer2 * my_cquantize_ptr2;
  157185. METHODDEF(void)
  157186. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157187. JSAMPARRAY output_buf, int num_rows)
  157188. {
  157189. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157190. register JSAMPROW ptr;
  157191. register histptr histp;
  157192. register hist3d histogram = cquantize->histogram;
  157193. int row;
  157194. JDIMENSION col;
  157195. JDIMENSION width = cinfo->output_width;
  157196. for (row = 0; row < num_rows; row++) {
  157197. ptr = input_buf[row];
  157198. for (col = width; col > 0; col--) {
  157199. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157200. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157201. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157202. if (++(*histp) <= 0)
  157203. (*histp)--;
  157204. ptr += 3;
  157205. }
  157206. }
  157207. }
  157208. typedef struct {
  157209. int c0min, c0max;
  157210. int c1min, c1max;
  157211. int c2min, c2max;
  157212. INT32 volume;
  157213. long colorcount;
  157214. } box;
  157215. typedef box * boxptr;
  157216. LOCAL(boxptr)
  157217. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157218. {
  157219. register boxptr boxp;
  157220. register int i;
  157221. register long maxc = 0;
  157222. boxptr which = NULL;
  157223. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157224. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157225. which = boxp;
  157226. maxc = boxp->colorcount;
  157227. }
  157228. }
  157229. return which;
  157230. }
  157231. LOCAL(boxptr)
  157232. find_biggest_volume (boxptr boxlist, int numboxes)
  157233. {
  157234. register boxptr boxp;
  157235. register int i;
  157236. register INT32 maxv = 0;
  157237. boxptr which = NULL;
  157238. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157239. if (boxp->volume > maxv) {
  157240. which = boxp;
  157241. maxv = boxp->volume;
  157242. }
  157243. }
  157244. return which;
  157245. }
  157246. LOCAL(void)
  157247. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157248. {
  157249. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157250. hist3d histogram = cquantize->histogram;
  157251. histptr histp;
  157252. int c0,c1,c2;
  157253. int c0min,c0max,c1min,c1max,c2min,c2max;
  157254. INT32 dist0,dist1,dist2;
  157255. long ccount;
  157256. c0min = boxp->c0min; c0max = boxp->c0max;
  157257. c1min = boxp->c1min; c1max = boxp->c1max;
  157258. c2min = boxp->c2min; c2max = boxp->c2max;
  157259. if (c0max > c0min)
  157260. for (c0 = c0min; c0 <= c0max; c0++)
  157261. for (c1 = c1min; c1 <= c1max; c1++) {
  157262. histp = & histogram[c0][c1][c2min];
  157263. for (c2 = c2min; c2 <= c2max; c2++)
  157264. if (*histp++ != 0) {
  157265. boxp->c0min = c0min = c0;
  157266. goto have_c0min;
  157267. }
  157268. }
  157269. have_c0min:
  157270. if (c0max > c0min)
  157271. for (c0 = c0max; c0 >= c0min; c0--)
  157272. for (c1 = c1min; c1 <= c1max; c1++) {
  157273. histp = & histogram[c0][c1][c2min];
  157274. for (c2 = c2min; c2 <= c2max; c2++)
  157275. if (*histp++ != 0) {
  157276. boxp->c0max = c0max = c0;
  157277. goto have_c0max;
  157278. }
  157279. }
  157280. have_c0max:
  157281. if (c1max > c1min)
  157282. for (c1 = c1min; c1 <= c1max; c1++)
  157283. for (c0 = c0min; c0 <= c0max; c0++) {
  157284. histp = & histogram[c0][c1][c2min];
  157285. for (c2 = c2min; c2 <= c2max; c2++)
  157286. if (*histp++ != 0) {
  157287. boxp->c1min = c1min = c1;
  157288. goto have_c1min;
  157289. }
  157290. }
  157291. have_c1min:
  157292. if (c1max > c1min)
  157293. for (c1 = c1max; c1 >= c1min; c1--)
  157294. for (c0 = c0min; c0 <= c0max; c0++) {
  157295. histp = & histogram[c0][c1][c2min];
  157296. for (c2 = c2min; c2 <= c2max; c2++)
  157297. if (*histp++ != 0) {
  157298. boxp->c1max = c1max = c1;
  157299. goto have_c1max;
  157300. }
  157301. }
  157302. have_c1max:
  157303. if (c2max > c2min)
  157304. for (c2 = c2min; c2 <= c2max; c2++)
  157305. for (c0 = c0min; c0 <= c0max; c0++) {
  157306. histp = & histogram[c0][c1min][c2];
  157307. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157308. if (*histp != 0) {
  157309. boxp->c2min = c2min = c2;
  157310. goto have_c2min;
  157311. }
  157312. }
  157313. have_c2min:
  157314. if (c2max > c2min)
  157315. for (c2 = c2max; c2 >= c2min; c2--)
  157316. for (c0 = c0min; c0 <= c0max; c0++) {
  157317. histp = & histogram[c0][c1min][c2];
  157318. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157319. if (*histp != 0) {
  157320. boxp->c2max = c2max = c2;
  157321. goto have_c2max;
  157322. }
  157323. }
  157324. have_c2max:
  157325. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157326. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157327. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157328. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157329. ccount = 0;
  157330. for (c0 = c0min; c0 <= c0max; c0++)
  157331. for (c1 = c1min; c1 <= c1max; c1++) {
  157332. histp = & histogram[c0][c1][c2min];
  157333. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157334. if (*histp != 0) {
  157335. ccount++;
  157336. }
  157337. }
  157338. boxp->colorcount = ccount;
  157339. }
  157340. LOCAL(int)
  157341. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157342. int desired_colors)
  157343. {
  157344. int n,lb;
  157345. int c0,c1,c2,cmax;
  157346. register boxptr b1,b2;
  157347. while (numboxes < desired_colors) {
  157348. if (numboxes*2 <= desired_colors) {
  157349. b1 = find_biggest_color_pop(boxlist, numboxes);
  157350. } else {
  157351. b1 = find_biggest_volume(boxlist, numboxes);
  157352. }
  157353. if (b1 == NULL) /* no splittable boxes left! */
  157354. break;
  157355. b2 = &boxlist[numboxes]; /* where new box will go */
  157356. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157357. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157358. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157359. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157360. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157361. #if RGB_RED == 0
  157362. cmax = c1; n = 1;
  157363. if (c0 > cmax) { cmax = c0; n = 0; }
  157364. if (c2 > cmax) { n = 2; }
  157365. #else
  157366. cmax = c1; n = 1;
  157367. if (c2 > cmax) { cmax = c2; n = 2; }
  157368. if (c0 > cmax) { n = 0; }
  157369. #endif
  157370. switch (n) {
  157371. case 0:
  157372. lb = (b1->c0max + b1->c0min) / 2;
  157373. b1->c0max = lb;
  157374. b2->c0min = lb+1;
  157375. break;
  157376. case 1:
  157377. lb = (b1->c1max + b1->c1min) / 2;
  157378. b1->c1max = lb;
  157379. b2->c1min = lb+1;
  157380. break;
  157381. case 2:
  157382. lb = (b1->c2max + b1->c2min) / 2;
  157383. b1->c2max = lb;
  157384. b2->c2min = lb+1;
  157385. break;
  157386. }
  157387. update_box(cinfo, b1);
  157388. update_box(cinfo, b2);
  157389. numboxes++;
  157390. }
  157391. return numboxes;
  157392. }
  157393. LOCAL(void)
  157394. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157395. {
  157396. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157397. hist3d histogram = cquantize->histogram;
  157398. histptr histp;
  157399. int c0,c1,c2;
  157400. int c0min,c0max,c1min,c1max,c2min,c2max;
  157401. long count;
  157402. long total = 0;
  157403. long c0total = 0;
  157404. long c1total = 0;
  157405. long c2total = 0;
  157406. c0min = boxp->c0min; c0max = boxp->c0max;
  157407. c1min = boxp->c1min; c1max = boxp->c1max;
  157408. c2min = boxp->c2min; c2max = boxp->c2max;
  157409. for (c0 = c0min; c0 <= c0max; c0++)
  157410. for (c1 = c1min; c1 <= c1max; c1++) {
  157411. histp = & histogram[c0][c1][c2min];
  157412. for (c2 = c2min; c2 <= c2max; c2++) {
  157413. if ((count = *histp++) != 0) {
  157414. total += count;
  157415. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157416. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157417. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157418. }
  157419. }
  157420. }
  157421. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157422. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157423. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157424. }
  157425. LOCAL(void)
  157426. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157427. {
  157428. boxptr boxlist;
  157429. int numboxes;
  157430. int i;
  157431. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157432. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157433. numboxes = 1;
  157434. boxlist[0].c0min = 0;
  157435. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157436. boxlist[0].c1min = 0;
  157437. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157438. boxlist[0].c2min = 0;
  157439. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157440. update_box(cinfo, & boxlist[0]);
  157441. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157442. for (i = 0; i < numboxes; i++)
  157443. compute_color(cinfo, & boxlist[i], i);
  157444. cinfo->actual_number_of_colors = numboxes;
  157445. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157446. }
  157447. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157448. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157449. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157450. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157451. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157452. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157453. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157454. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157455. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157456. LOCAL(int)
  157457. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157458. JSAMPLE colorlist[])
  157459. {
  157460. int numcolors = cinfo->actual_number_of_colors;
  157461. int maxc0, maxc1, maxc2;
  157462. int centerc0, centerc1, centerc2;
  157463. int i, x, ncolors;
  157464. INT32 minmaxdist, min_dist, max_dist, tdist;
  157465. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157466. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157467. centerc0 = (minc0 + maxc0) >> 1;
  157468. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157469. centerc1 = (minc1 + maxc1) >> 1;
  157470. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157471. centerc2 = (minc2 + maxc2) >> 1;
  157472. minmaxdist = 0x7FFFFFFFL;
  157473. for (i = 0; i < numcolors; i++) {
  157474. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157475. if (x < minc0) {
  157476. tdist = (x - minc0) * C0_SCALE;
  157477. min_dist = tdist*tdist;
  157478. tdist = (x - maxc0) * C0_SCALE;
  157479. max_dist = tdist*tdist;
  157480. } else if (x > maxc0) {
  157481. tdist = (x - maxc0) * C0_SCALE;
  157482. min_dist = tdist*tdist;
  157483. tdist = (x - minc0) * C0_SCALE;
  157484. max_dist = tdist*tdist;
  157485. } else {
  157486. min_dist = 0;
  157487. if (x <= centerc0) {
  157488. tdist = (x - maxc0) * C0_SCALE;
  157489. max_dist = tdist*tdist;
  157490. } else {
  157491. tdist = (x - minc0) * C0_SCALE;
  157492. max_dist = tdist*tdist;
  157493. }
  157494. }
  157495. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157496. if (x < minc1) {
  157497. tdist = (x - minc1) * C1_SCALE;
  157498. min_dist += tdist*tdist;
  157499. tdist = (x - maxc1) * C1_SCALE;
  157500. max_dist += tdist*tdist;
  157501. } else if (x > maxc1) {
  157502. tdist = (x - maxc1) * C1_SCALE;
  157503. min_dist += tdist*tdist;
  157504. tdist = (x - minc1) * C1_SCALE;
  157505. max_dist += tdist*tdist;
  157506. } else {
  157507. if (x <= centerc1) {
  157508. tdist = (x - maxc1) * C1_SCALE;
  157509. max_dist += tdist*tdist;
  157510. } else {
  157511. tdist = (x - minc1) * C1_SCALE;
  157512. max_dist += tdist*tdist;
  157513. }
  157514. }
  157515. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157516. if (x < minc2) {
  157517. tdist = (x - minc2) * C2_SCALE;
  157518. min_dist += tdist*tdist;
  157519. tdist = (x - maxc2) * C2_SCALE;
  157520. max_dist += tdist*tdist;
  157521. } else if (x > maxc2) {
  157522. tdist = (x - maxc2) * C2_SCALE;
  157523. min_dist += tdist*tdist;
  157524. tdist = (x - minc2) * C2_SCALE;
  157525. max_dist += tdist*tdist;
  157526. } else {
  157527. if (x <= centerc2) {
  157528. tdist = (x - maxc2) * C2_SCALE;
  157529. max_dist += tdist*tdist;
  157530. } else {
  157531. tdist = (x - minc2) * C2_SCALE;
  157532. max_dist += tdist*tdist;
  157533. }
  157534. }
  157535. mindist[i] = min_dist; /* save away the results */
  157536. if (max_dist < minmaxdist)
  157537. minmaxdist = max_dist;
  157538. }
  157539. ncolors = 0;
  157540. for (i = 0; i < numcolors; i++) {
  157541. if (mindist[i] <= minmaxdist)
  157542. colorlist[ncolors++] = (JSAMPLE) i;
  157543. }
  157544. return ncolors;
  157545. }
  157546. LOCAL(void)
  157547. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157548. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157549. {
  157550. int ic0, ic1, ic2;
  157551. int i, icolor;
  157552. register INT32 * bptr; /* pointer into bestdist[] array */
  157553. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157554. INT32 dist0, dist1; /* initial distance values */
  157555. register INT32 dist2; /* current distance in inner loop */
  157556. INT32 xx0, xx1; /* distance increments */
  157557. register INT32 xx2;
  157558. INT32 inc0, inc1, inc2; /* initial values for increments */
  157559. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157560. bptr = bestdist;
  157561. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157562. *bptr++ = 0x7FFFFFFFL;
  157563. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157564. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157565. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157566. for (i = 0; i < numcolors; i++) {
  157567. icolor = GETJSAMPLE(colorlist[i]);
  157568. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157569. dist0 = inc0*inc0;
  157570. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157571. dist0 += inc1*inc1;
  157572. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157573. dist0 += inc2*inc2;
  157574. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157575. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157576. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157577. bptr = bestdist;
  157578. cptr = bestcolor;
  157579. xx0 = inc0;
  157580. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157581. dist1 = dist0;
  157582. xx1 = inc1;
  157583. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157584. dist2 = dist1;
  157585. xx2 = inc2;
  157586. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157587. if (dist2 < *bptr) {
  157588. *bptr = dist2;
  157589. *cptr = (JSAMPLE) icolor;
  157590. }
  157591. dist2 += xx2;
  157592. xx2 += 2 * STEP_C2 * STEP_C2;
  157593. bptr++;
  157594. cptr++;
  157595. }
  157596. dist1 += xx1;
  157597. xx1 += 2 * STEP_C1 * STEP_C1;
  157598. }
  157599. dist0 += xx0;
  157600. xx0 += 2 * STEP_C0 * STEP_C0;
  157601. }
  157602. }
  157603. }
  157604. LOCAL(void)
  157605. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157606. {
  157607. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157608. hist3d histogram = cquantize->histogram;
  157609. int minc0, minc1, minc2; /* lower left corner of update box */
  157610. int ic0, ic1, ic2;
  157611. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157612. register histptr cachep; /* pointer into main cache array */
  157613. JSAMPLE colorlist[MAXNUMCOLORS];
  157614. int numcolors; /* number of candidate colors */
  157615. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157616. c0 >>= BOX_C0_LOG;
  157617. c1 >>= BOX_C1_LOG;
  157618. c2 >>= BOX_C2_LOG;
  157619. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157620. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157621. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157622. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157623. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157624. bestcolor);
  157625. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157626. c1 <<= BOX_C1_LOG;
  157627. c2 <<= BOX_C2_LOG;
  157628. cptr = bestcolor;
  157629. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157630. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157631. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157632. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157633. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157634. }
  157635. }
  157636. }
  157637. }
  157638. METHODDEF(void)
  157639. pass2_no_dither (j_decompress_ptr cinfo,
  157640. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157641. {
  157642. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157643. hist3d histogram = cquantize->histogram;
  157644. register JSAMPROW inptr, outptr;
  157645. register histptr cachep;
  157646. register int c0, c1, c2;
  157647. int row;
  157648. JDIMENSION col;
  157649. JDIMENSION width = cinfo->output_width;
  157650. for (row = 0; row < num_rows; row++) {
  157651. inptr = input_buf[row];
  157652. outptr = output_buf[row];
  157653. for (col = width; col > 0; col--) {
  157654. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157655. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157656. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157657. cachep = & histogram[c0][c1][c2];
  157658. if (*cachep == 0)
  157659. fill_inverse_cmap(cinfo, c0,c1,c2);
  157660. *outptr++ = (JSAMPLE) (*cachep - 1);
  157661. }
  157662. }
  157663. }
  157664. METHODDEF(void)
  157665. pass2_fs_dither (j_decompress_ptr cinfo,
  157666. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157667. {
  157668. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157669. hist3d histogram = cquantize->histogram;
  157670. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157671. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157672. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157673. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157674. JSAMPROW inptr; /* => current input pixel */
  157675. JSAMPROW outptr; /* => current output pixel */
  157676. histptr cachep;
  157677. int dir; /* +1 or -1 depending on direction */
  157678. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157679. int row;
  157680. JDIMENSION col;
  157681. JDIMENSION width = cinfo->output_width;
  157682. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157683. int *error_limit = cquantize->error_limiter;
  157684. JSAMPROW colormap0 = cinfo->colormap[0];
  157685. JSAMPROW colormap1 = cinfo->colormap[1];
  157686. JSAMPROW colormap2 = cinfo->colormap[2];
  157687. SHIFT_TEMPS
  157688. for (row = 0; row < num_rows; row++) {
  157689. inptr = input_buf[row];
  157690. outptr = output_buf[row];
  157691. if (cquantize->on_odd_row) {
  157692. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157693. outptr += width-1;
  157694. dir = -1;
  157695. dir3 = -3;
  157696. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157697. cquantize->on_odd_row = FALSE; /* flip for next time */
  157698. } else {
  157699. dir = 1;
  157700. dir3 = 3;
  157701. errorptr = cquantize->fserrors; /* => entry before first real column */
  157702. cquantize->on_odd_row = TRUE; /* flip for next time */
  157703. }
  157704. cur0 = cur1 = cur2 = 0;
  157705. belowerr0 = belowerr1 = belowerr2 = 0;
  157706. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157707. for (col = width; col > 0; col--) {
  157708. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157709. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157710. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157711. cur0 = error_limit[cur0];
  157712. cur1 = error_limit[cur1];
  157713. cur2 = error_limit[cur2];
  157714. cur0 += GETJSAMPLE(inptr[0]);
  157715. cur1 += GETJSAMPLE(inptr[1]);
  157716. cur2 += GETJSAMPLE(inptr[2]);
  157717. cur0 = GETJSAMPLE(range_limit[cur0]);
  157718. cur1 = GETJSAMPLE(range_limit[cur1]);
  157719. cur2 = GETJSAMPLE(range_limit[cur2]);
  157720. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157721. if (*cachep == 0)
  157722. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157723. { register int pixcode = *cachep - 1;
  157724. *outptr = (JSAMPLE) pixcode;
  157725. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157726. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157727. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157728. }
  157729. { register LOCFSERROR bnexterr, delta;
  157730. bnexterr = cur0; /* Process component 0 */
  157731. delta = cur0 * 2;
  157732. cur0 += delta; /* form error * 3 */
  157733. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157734. cur0 += delta; /* form error * 5 */
  157735. bpreverr0 = belowerr0 + cur0;
  157736. belowerr0 = bnexterr;
  157737. cur0 += delta; /* form error * 7 */
  157738. bnexterr = cur1; /* Process component 1 */
  157739. delta = cur1 * 2;
  157740. cur1 += delta; /* form error * 3 */
  157741. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157742. cur1 += delta; /* form error * 5 */
  157743. bpreverr1 = belowerr1 + cur1;
  157744. belowerr1 = bnexterr;
  157745. cur1 += delta; /* form error * 7 */
  157746. bnexterr = cur2; /* Process component 2 */
  157747. delta = cur2 * 2;
  157748. cur2 += delta; /* form error * 3 */
  157749. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157750. cur2 += delta; /* form error * 5 */
  157751. bpreverr2 = belowerr2 + cur2;
  157752. belowerr2 = bnexterr;
  157753. cur2 += delta; /* form error * 7 */
  157754. }
  157755. inptr += dir3; /* Advance pixel pointers to next column */
  157756. outptr += dir;
  157757. errorptr += dir3; /* advance errorptr to current column */
  157758. }
  157759. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157760. errorptr[1] = (FSERROR) bpreverr1;
  157761. errorptr[2] = (FSERROR) bpreverr2;
  157762. }
  157763. }
  157764. LOCAL(void)
  157765. init_error_limit (j_decompress_ptr cinfo)
  157766. {
  157767. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157768. int * table;
  157769. int in, out;
  157770. table = (int *) (*cinfo->mem->alloc_small)
  157771. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157772. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157773. cquantize->error_limiter = table;
  157774. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157775. out = 0;
  157776. for (in = 0; in < STEPSIZE; in++, out++) {
  157777. table[in] = out; table[-in] = -out;
  157778. }
  157779. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157780. table[in] = out; table[-in] = -out;
  157781. }
  157782. for (; in <= MAXJSAMPLE; in++) {
  157783. table[in] = out; table[-in] = -out;
  157784. }
  157785. #undef STEPSIZE
  157786. }
  157787. METHODDEF(void)
  157788. finish_pass1 (j_decompress_ptr cinfo)
  157789. {
  157790. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157791. cinfo->colormap = cquantize->sv_colormap;
  157792. select_colors(cinfo, cquantize->desired);
  157793. cquantize->needs_zeroed = TRUE;
  157794. }
  157795. METHODDEF(void)
  157796. finish_pass2 (j_decompress_ptr cinfo)
  157797. {
  157798. }
  157799. METHODDEF(void)
  157800. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157801. {
  157802. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157803. hist3d histogram = cquantize->histogram;
  157804. int i;
  157805. if (cinfo->dither_mode != JDITHER_NONE)
  157806. cinfo->dither_mode = JDITHER_FS;
  157807. if (is_pre_scan) {
  157808. cquantize->pub.color_quantize = prescan_quantize;
  157809. cquantize->pub.finish_pass = finish_pass1;
  157810. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157811. } else {
  157812. if (cinfo->dither_mode == JDITHER_FS)
  157813. cquantize->pub.color_quantize = pass2_fs_dither;
  157814. else
  157815. cquantize->pub.color_quantize = pass2_no_dither;
  157816. cquantize->pub.finish_pass = finish_pass2;
  157817. i = cinfo->actual_number_of_colors;
  157818. if (i < 1)
  157819. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  157820. if (i > MAXNUMCOLORS)
  157821. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157822. if (cinfo->dither_mode == JDITHER_FS) {
  157823. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  157824. (3 * SIZEOF(FSERROR)));
  157825. if (cquantize->fserrors == NULL)
  157826. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157827. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157828. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  157829. if (cquantize->error_limiter == NULL)
  157830. init_error_limit(cinfo);
  157831. cquantize->on_odd_row = FALSE;
  157832. }
  157833. }
  157834. if (cquantize->needs_zeroed) {
  157835. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157836. jzero_far((void FAR *) histogram[i],
  157837. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157838. }
  157839. cquantize->needs_zeroed = FALSE;
  157840. }
  157841. }
  157842. METHODDEF(void)
  157843. new_color_map_2_quant (j_decompress_ptr cinfo)
  157844. {
  157845. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157846. cquantize->needs_zeroed = TRUE;
  157847. }
  157848. GLOBAL(void)
  157849. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  157850. {
  157851. my_cquantize_ptr2 cquantize;
  157852. int i;
  157853. cquantize = (my_cquantize_ptr2)
  157854. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157855. SIZEOF(my_cquantizer2));
  157856. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157857. cquantize->pub.start_pass = start_pass_2_quant;
  157858. cquantize->pub.new_color_map = new_color_map_2_quant;
  157859. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  157860. cquantize->error_limiter = NULL;
  157861. if (cinfo->out_color_components != 3)
  157862. ERREXIT(cinfo, JERR_NOTIMPL);
  157863. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  157864. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  157865. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157866. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  157867. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157868. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157869. }
  157870. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  157871. if (cinfo->enable_2pass_quant) {
  157872. int desired = cinfo->desired_number_of_colors;
  157873. if (desired < 8)
  157874. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  157875. if (desired > MAXNUMCOLORS)
  157876. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157877. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  157878. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  157879. cquantize->desired = desired;
  157880. } else
  157881. cquantize->sv_colormap = NULL;
  157882. if (cinfo->dither_mode != JDITHER_NONE)
  157883. cinfo->dither_mode = JDITHER_FS;
  157884. if (cinfo->dither_mode == JDITHER_FS) {
  157885. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157886. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157887. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  157888. init_error_limit(cinfo);
  157889. }
  157890. }
  157891. #endif /* QUANT_2PASS_SUPPORTED */
  157892. /*** End of inlined file: jquant2.c ***/
  157893. /*** Start of inlined file: jutils.c ***/
  157894. #define JPEG_INTERNALS
  157895. #if 0 /* This table is not actually needed in v6a */
  157896. const int jpeg_zigzag_order[DCTSIZE2] = {
  157897. 0, 1, 5, 6, 14, 15, 27, 28,
  157898. 2, 4, 7, 13, 16, 26, 29, 42,
  157899. 3, 8, 12, 17, 25, 30, 41, 43,
  157900. 9, 11, 18, 24, 31, 40, 44, 53,
  157901. 10, 19, 23, 32, 39, 45, 52, 54,
  157902. 20, 22, 33, 38, 46, 51, 55, 60,
  157903. 21, 34, 37, 47, 50, 56, 59, 61,
  157904. 35, 36, 48, 49, 57, 58, 62, 63
  157905. };
  157906. #endif
  157907. const int jpeg_natural_order[DCTSIZE2+16] = {
  157908. 0, 1, 8, 16, 9, 2, 3, 10,
  157909. 17, 24, 32, 25, 18, 11, 4, 5,
  157910. 12, 19, 26, 33, 40, 48, 41, 34,
  157911. 27, 20, 13, 6, 7, 14, 21, 28,
  157912. 35, 42, 49, 56, 57, 50, 43, 36,
  157913. 29, 22, 15, 23, 30, 37, 44, 51,
  157914. 58, 59, 52, 45, 38, 31, 39, 46,
  157915. 53, 60, 61, 54, 47, 55, 62, 63,
  157916. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  157917. 63, 63, 63, 63, 63, 63, 63, 63
  157918. };
  157919. GLOBAL(long)
  157920. jdiv_round_up (long a, long b)
  157921. {
  157922. return (a + b - 1L) / b;
  157923. }
  157924. GLOBAL(long)
  157925. jround_up (long a, long b)
  157926. {
  157927. a += b - 1L;
  157928. return a - (a % b);
  157929. }
  157930. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  157931. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  157932. #define FMEMZERO(target,size) MEMZERO(target,size)
  157933. #else /* 80x86 case, define if we can */
  157934. #ifdef USE_FMEM
  157935. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  157936. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  157937. #endif
  157938. #endif
  157939. GLOBAL(void)
  157940. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  157941. JSAMPARRAY output_array, int dest_row,
  157942. int num_rows, JDIMENSION num_cols)
  157943. {
  157944. register JSAMPROW inptr, outptr;
  157945. #ifdef FMEMCOPY
  157946. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  157947. #else
  157948. register JDIMENSION count;
  157949. #endif
  157950. register int row;
  157951. input_array += source_row;
  157952. output_array += dest_row;
  157953. for (row = num_rows; row > 0; row--) {
  157954. inptr = *input_array++;
  157955. outptr = *output_array++;
  157956. #ifdef FMEMCOPY
  157957. FMEMCOPY(outptr, inptr, count);
  157958. #else
  157959. for (count = num_cols; count > 0; count--)
  157960. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  157961. #endif
  157962. }
  157963. }
  157964. GLOBAL(void)
  157965. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  157966. JDIMENSION num_blocks)
  157967. {
  157968. #ifdef FMEMCOPY
  157969. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  157970. #else
  157971. register JCOEFPTR inptr, outptr;
  157972. register long count;
  157973. inptr = (JCOEFPTR) input_row;
  157974. outptr = (JCOEFPTR) output_row;
  157975. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  157976. *outptr++ = *inptr++;
  157977. }
  157978. #endif
  157979. }
  157980. GLOBAL(void)
  157981. jzero_far (void FAR * target, size_t bytestozero)
  157982. {
  157983. #ifdef FMEMZERO
  157984. FMEMZERO(target, bytestozero);
  157985. #else
  157986. register char FAR * ptr = (char FAR *) target;
  157987. register size_t count;
  157988. for (count = bytestozero; count > 0; count--) {
  157989. *ptr++ = 0;
  157990. }
  157991. #endif
  157992. }
  157993. /*** End of inlined file: jutils.c ***/
  157994. /*** Start of inlined file: transupp.c ***/
  157995. #define JPEG_INTERNALS
  157996. /*** Start of inlined file: transupp.h ***/
  157997. #ifndef TRANSFORMS_SUPPORTED
  157998. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  157999. #endif
  158000. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158001. #define jtransform_request_workspace jTrRequest
  158002. #define jtransform_adjust_parameters jTrAdjust
  158003. #define jtransform_execute_transformation jTrExec
  158004. #define jcopy_markers_setup jCMrkSetup
  158005. #define jcopy_markers_execute jCMrkExec
  158006. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158007. typedef enum {
  158008. JXFORM_NONE, /* no transformation */
  158009. JXFORM_FLIP_H, /* horizontal flip */
  158010. JXFORM_FLIP_V, /* vertical flip */
  158011. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158012. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158013. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158014. JXFORM_ROT_180, /* 180-degree rotation */
  158015. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158016. } JXFORM_CODE;
  158017. typedef struct {
  158018. JXFORM_CODE transform; /* image transform operator */
  158019. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158020. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158021. int num_components; /* # of components in workspace */
  158022. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158023. } jpeg_transform_info;
  158024. #if TRANSFORMS_SUPPORTED
  158025. EXTERN(void) jtransform_request_workspace
  158026. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158027. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158028. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158029. jvirt_barray_ptr *src_coef_arrays,
  158030. jpeg_transform_info *info));
  158031. EXTERN(void) jtransform_execute_transformation
  158032. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158033. jvirt_barray_ptr *src_coef_arrays,
  158034. jpeg_transform_info *info));
  158035. #endif /* TRANSFORMS_SUPPORTED */
  158036. typedef enum {
  158037. JCOPYOPT_NONE, /* copy no optional markers */
  158038. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158039. JCOPYOPT_ALL /* copy all optional markers */
  158040. } JCOPY_OPTION;
  158041. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158042. EXTERN(void) jcopy_markers_setup
  158043. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158044. EXTERN(void) jcopy_markers_execute
  158045. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158046. JCOPY_OPTION option));
  158047. /*** End of inlined file: transupp.h ***/
  158048. /* My own external interface */
  158049. #if TRANSFORMS_SUPPORTED
  158050. LOCAL(void)
  158051. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158052. jvirt_barray_ptr *src_coef_arrays)
  158053. {
  158054. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158055. int ci, k, offset_y;
  158056. JBLOCKARRAY buffer;
  158057. JCOEFPTR ptr1, ptr2;
  158058. JCOEF temp1, temp2;
  158059. jpeg_component_info *compptr;
  158060. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158061. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158062. compptr = dstinfo->comp_info + ci;
  158063. comp_width = MCU_cols * compptr->h_samp_factor;
  158064. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158065. blk_y += compptr->v_samp_factor) {
  158066. buffer = (*srcinfo->mem->access_virt_barray)
  158067. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158068. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158069. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158070. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158071. ptr1 = buffer[offset_y][blk_x];
  158072. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158073. for (k = 0; k < DCTSIZE2; k += 2) {
  158074. temp1 = *ptr1; /* swap even column */
  158075. temp2 = *ptr2;
  158076. *ptr1++ = temp2;
  158077. *ptr2++ = temp1;
  158078. temp1 = *ptr1; /* swap odd column with sign change */
  158079. temp2 = *ptr2;
  158080. *ptr1++ = -temp2;
  158081. *ptr2++ = -temp1;
  158082. }
  158083. }
  158084. }
  158085. }
  158086. }
  158087. }
  158088. LOCAL(void)
  158089. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158090. jvirt_barray_ptr *src_coef_arrays,
  158091. jvirt_barray_ptr *dst_coef_arrays)
  158092. {
  158093. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158094. int ci, i, j, offset_y;
  158095. JBLOCKARRAY src_buffer, dst_buffer;
  158096. JBLOCKROW src_row_ptr, dst_row_ptr;
  158097. JCOEFPTR src_ptr, dst_ptr;
  158098. jpeg_component_info *compptr;
  158099. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158100. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158101. compptr = dstinfo->comp_info + ci;
  158102. comp_height = MCU_rows * compptr->v_samp_factor;
  158103. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158104. dst_blk_y += compptr->v_samp_factor) {
  158105. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158106. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158107. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158108. if (dst_blk_y < comp_height) {
  158109. src_buffer = (*srcinfo->mem->access_virt_barray)
  158110. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158111. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158112. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158113. } else {
  158114. src_buffer = (*srcinfo->mem->access_virt_barray)
  158115. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158116. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158117. }
  158118. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158119. if (dst_blk_y < comp_height) {
  158120. dst_row_ptr = dst_buffer[offset_y];
  158121. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158122. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158123. dst_blk_x++) {
  158124. dst_ptr = dst_row_ptr[dst_blk_x];
  158125. src_ptr = src_row_ptr[dst_blk_x];
  158126. for (i = 0; i < DCTSIZE; i += 2) {
  158127. for (j = 0; j < DCTSIZE; j++)
  158128. *dst_ptr++ = *src_ptr++;
  158129. for (j = 0; j < DCTSIZE; j++)
  158130. *dst_ptr++ = - *src_ptr++;
  158131. }
  158132. }
  158133. } else {
  158134. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158135. compptr->width_in_blocks);
  158136. }
  158137. }
  158138. }
  158139. }
  158140. }
  158141. LOCAL(void)
  158142. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158143. jvirt_barray_ptr *src_coef_arrays,
  158144. jvirt_barray_ptr *dst_coef_arrays)
  158145. {
  158146. JDIMENSION dst_blk_x, dst_blk_y;
  158147. int ci, i, j, offset_x, offset_y;
  158148. JBLOCKARRAY src_buffer, dst_buffer;
  158149. JCOEFPTR src_ptr, dst_ptr;
  158150. jpeg_component_info *compptr;
  158151. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158152. compptr = dstinfo->comp_info + ci;
  158153. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158154. dst_blk_y += compptr->v_samp_factor) {
  158155. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158156. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158157. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158158. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158159. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158160. dst_blk_x += compptr->h_samp_factor) {
  158161. src_buffer = (*srcinfo->mem->access_virt_barray)
  158162. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158163. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158164. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158165. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158166. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158167. for (i = 0; i < DCTSIZE; i++)
  158168. for (j = 0; j < DCTSIZE; j++)
  158169. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158170. }
  158171. }
  158172. }
  158173. }
  158174. }
  158175. }
  158176. LOCAL(void)
  158177. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158178. jvirt_barray_ptr *src_coef_arrays,
  158179. jvirt_barray_ptr *dst_coef_arrays)
  158180. {
  158181. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158182. int ci, i, j, offset_x, offset_y;
  158183. JBLOCKARRAY src_buffer, dst_buffer;
  158184. JCOEFPTR src_ptr, dst_ptr;
  158185. jpeg_component_info *compptr;
  158186. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158187. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158188. compptr = dstinfo->comp_info + ci;
  158189. comp_width = MCU_cols * compptr->h_samp_factor;
  158190. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158191. dst_blk_y += compptr->v_samp_factor) {
  158192. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158193. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158194. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158195. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158196. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158197. dst_blk_x += compptr->h_samp_factor) {
  158198. src_buffer = (*srcinfo->mem->access_virt_barray)
  158199. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158200. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158201. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158202. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158203. if (dst_blk_x < comp_width) {
  158204. dst_ptr = dst_buffer[offset_y]
  158205. [comp_width - dst_blk_x - offset_x - 1];
  158206. for (i = 0; i < DCTSIZE; i++) {
  158207. for (j = 0; j < DCTSIZE; j++)
  158208. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158209. i++;
  158210. for (j = 0; j < DCTSIZE; j++)
  158211. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158212. }
  158213. } else {
  158214. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158215. for (i = 0; i < DCTSIZE; i++)
  158216. for (j = 0; j < DCTSIZE; j++)
  158217. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158218. }
  158219. }
  158220. }
  158221. }
  158222. }
  158223. }
  158224. }
  158225. LOCAL(void)
  158226. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158227. jvirt_barray_ptr *src_coef_arrays,
  158228. jvirt_barray_ptr *dst_coef_arrays)
  158229. {
  158230. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158231. int ci, i, j, offset_x, offset_y;
  158232. JBLOCKARRAY src_buffer, dst_buffer;
  158233. JCOEFPTR src_ptr, dst_ptr;
  158234. jpeg_component_info *compptr;
  158235. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158236. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158237. compptr = dstinfo->comp_info + ci;
  158238. comp_height = MCU_rows * compptr->v_samp_factor;
  158239. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158240. dst_blk_y += compptr->v_samp_factor) {
  158241. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158242. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158243. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158244. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158245. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158246. dst_blk_x += compptr->h_samp_factor) {
  158247. src_buffer = (*srcinfo->mem->access_virt_barray)
  158248. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158249. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158250. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158251. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158252. if (dst_blk_y < comp_height) {
  158253. src_ptr = src_buffer[offset_x]
  158254. [comp_height - dst_blk_y - offset_y - 1];
  158255. for (i = 0; i < DCTSIZE; i++) {
  158256. for (j = 0; j < DCTSIZE; j++) {
  158257. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158258. j++;
  158259. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158260. }
  158261. }
  158262. } else {
  158263. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158264. for (i = 0; i < DCTSIZE; i++)
  158265. for (j = 0; j < DCTSIZE; j++)
  158266. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158267. }
  158268. }
  158269. }
  158270. }
  158271. }
  158272. }
  158273. }
  158274. LOCAL(void)
  158275. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158276. jvirt_barray_ptr *src_coef_arrays,
  158277. jvirt_barray_ptr *dst_coef_arrays)
  158278. {
  158279. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158280. int ci, i, j, offset_y;
  158281. JBLOCKARRAY src_buffer, dst_buffer;
  158282. JBLOCKROW src_row_ptr, dst_row_ptr;
  158283. JCOEFPTR src_ptr, dst_ptr;
  158284. jpeg_component_info *compptr;
  158285. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158286. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158287. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158288. compptr = dstinfo->comp_info + ci;
  158289. comp_width = MCU_cols * compptr->h_samp_factor;
  158290. comp_height = MCU_rows * compptr->v_samp_factor;
  158291. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158292. dst_blk_y += compptr->v_samp_factor) {
  158293. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158294. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158295. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158296. if (dst_blk_y < comp_height) {
  158297. src_buffer = (*srcinfo->mem->access_virt_barray)
  158298. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158299. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158300. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158301. } else {
  158302. src_buffer = (*srcinfo->mem->access_virt_barray)
  158303. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158304. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158305. }
  158306. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158307. if (dst_blk_y < comp_height) {
  158308. dst_row_ptr = dst_buffer[offset_y];
  158309. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158310. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158311. dst_ptr = dst_row_ptr[dst_blk_x];
  158312. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158313. for (i = 0; i < DCTSIZE; i += 2) {
  158314. for (j = 0; j < DCTSIZE; j += 2) {
  158315. *dst_ptr++ = *src_ptr++;
  158316. *dst_ptr++ = - *src_ptr++;
  158317. }
  158318. for (j = 0; j < DCTSIZE; j += 2) {
  158319. *dst_ptr++ = - *src_ptr++;
  158320. *dst_ptr++ = *src_ptr++;
  158321. }
  158322. }
  158323. }
  158324. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158325. dst_ptr = dst_row_ptr[dst_blk_x];
  158326. src_ptr = src_row_ptr[dst_blk_x];
  158327. for (i = 0; i < DCTSIZE; i += 2) {
  158328. for (j = 0; j < DCTSIZE; j++)
  158329. *dst_ptr++ = *src_ptr++;
  158330. for (j = 0; j < DCTSIZE; j++)
  158331. *dst_ptr++ = - *src_ptr++;
  158332. }
  158333. }
  158334. } else {
  158335. dst_row_ptr = dst_buffer[offset_y];
  158336. src_row_ptr = src_buffer[offset_y];
  158337. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158338. dst_ptr = dst_row_ptr[dst_blk_x];
  158339. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158340. for (i = 0; i < DCTSIZE2; i += 2) {
  158341. *dst_ptr++ = *src_ptr++;
  158342. *dst_ptr++ = - *src_ptr++;
  158343. }
  158344. }
  158345. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158346. dst_ptr = dst_row_ptr[dst_blk_x];
  158347. src_ptr = src_row_ptr[dst_blk_x];
  158348. for (i = 0; i < DCTSIZE2; i++)
  158349. *dst_ptr++ = *src_ptr++;
  158350. }
  158351. }
  158352. }
  158353. }
  158354. }
  158355. }
  158356. LOCAL(void)
  158357. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158358. jvirt_barray_ptr *src_coef_arrays,
  158359. jvirt_barray_ptr *dst_coef_arrays)
  158360. {
  158361. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158362. int ci, i, j, offset_x, offset_y;
  158363. JBLOCKARRAY src_buffer, dst_buffer;
  158364. JCOEFPTR src_ptr, dst_ptr;
  158365. jpeg_component_info *compptr;
  158366. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158367. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158368. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158369. compptr = dstinfo->comp_info + ci;
  158370. comp_width = MCU_cols * compptr->h_samp_factor;
  158371. comp_height = MCU_rows * compptr->v_samp_factor;
  158372. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158373. dst_blk_y += compptr->v_samp_factor) {
  158374. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158375. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158376. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158377. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158378. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158379. dst_blk_x += compptr->h_samp_factor) {
  158380. src_buffer = (*srcinfo->mem->access_virt_barray)
  158381. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158382. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158383. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158384. if (dst_blk_y < comp_height) {
  158385. src_ptr = src_buffer[offset_x]
  158386. [comp_height - dst_blk_y - offset_y - 1];
  158387. if (dst_blk_x < comp_width) {
  158388. dst_ptr = dst_buffer[offset_y]
  158389. [comp_width - dst_blk_x - offset_x - 1];
  158390. for (i = 0; i < DCTSIZE; i++) {
  158391. for (j = 0; j < DCTSIZE; j++) {
  158392. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158393. j++;
  158394. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158395. }
  158396. i++;
  158397. for (j = 0; j < DCTSIZE; j++) {
  158398. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158399. j++;
  158400. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158401. }
  158402. }
  158403. } else {
  158404. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158405. for (i = 0; i < DCTSIZE; i++) {
  158406. for (j = 0; j < DCTSIZE; j++) {
  158407. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158408. j++;
  158409. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158410. }
  158411. }
  158412. }
  158413. } else {
  158414. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158415. if (dst_blk_x < comp_width) {
  158416. dst_ptr = dst_buffer[offset_y]
  158417. [comp_width - dst_blk_x - offset_x - 1];
  158418. for (i = 0; i < DCTSIZE; i++) {
  158419. for (j = 0; j < DCTSIZE; j++)
  158420. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158421. i++;
  158422. for (j = 0; j < DCTSIZE; j++)
  158423. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158424. }
  158425. } else {
  158426. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158427. for (i = 0; i < DCTSIZE; i++)
  158428. for (j = 0; j < DCTSIZE; j++)
  158429. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158430. }
  158431. }
  158432. }
  158433. }
  158434. }
  158435. }
  158436. }
  158437. }
  158438. GLOBAL(void)
  158439. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158440. jpeg_transform_info *info)
  158441. {
  158442. jvirt_barray_ptr *coef_arrays = NULL;
  158443. jpeg_component_info *compptr;
  158444. int ci;
  158445. if (info->force_grayscale &&
  158446. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158447. srcinfo->num_components == 3) {
  158448. info->num_components = 1;
  158449. } else {
  158450. info->num_components = srcinfo->num_components;
  158451. }
  158452. switch (info->transform) {
  158453. case JXFORM_NONE:
  158454. case JXFORM_FLIP_H:
  158455. break;
  158456. case JXFORM_FLIP_V:
  158457. case JXFORM_ROT_180:
  158458. coef_arrays = (jvirt_barray_ptr *)
  158459. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158460. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158461. for (ci = 0; ci < info->num_components; ci++) {
  158462. compptr = srcinfo->comp_info + ci;
  158463. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158464. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158465. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158466. (long) compptr->h_samp_factor),
  158467. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158468. (long) compptr->v_samp_factor),
  158469. (JDIMENSION) compptr->v_samp_factor);
  158470. }
  158471. break;
  158472. case JXFORM_TRANSPOSE:
  158473. case JXFORM_TRANSVERSE:
  158474. case JXFORM_ROT_90:
  158475. case JXFORM_ROT_270:
  158476. coef_arrays = (jvirt_barray_ptr *)
  158477. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158478. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158479. for (ci = 0; ci < info->num_components; ci++) {
  158480. compptr = srcinfo->comp_info + ci;
  158481. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158482. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158483. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158484. (long) compptr->v_samp_factor),
  158485. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158486. (long) compptr->h_samp_factor),
  158487. (JDIMENSION) compptr->h_samp_factor);
  158488. }
  158489. break;
  158490. }
  158491. info->workspace_coef_arrays = coef_arrays;
  158492. }
  158493. LOCAL(void)
  158494. transpose_critical_parameters (j_compress_ptr dstinfo)
  158495. {
  158496. int tblno, i, j, ci, itemp;
  158497. jpeg_component_info *compptr;
  158498. JQUANT_TBL *qtblptr;
  158499. JDIMENSION dtemp;
  158500. UINT16 qtemp;
  158501. dtemp = dstinfo->image_width;
  158502. dstinfo->image_width = dstinfo->image_height;
  158503. dstinfo->image_height = dtemp;
  158504. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158505. compptr = dstinfo->comp_info + ci;
  158506. itemp = compptr->h_samp_factor;
  158507. compptr->h_samp_factor = compptr->v_samp_factor;
  158508. compptr->v_samp_factor = itemp;
  158509. }
  158510. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158511. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158512. if (qtblptr != NULL) {
  158513. for (i = 0; i < DCTSIZE; i++) {
  158514. for (j = 0; j < i; j++) {
  158515. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158516. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158517. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158518. }
  158519. }
  158520. }
  158521. }
  158522. }
  158523. LOCAL(void)
  158524. trim_right_edge (j_compress_ptr dstinfo)
  158525. {
  158526. int ci, max_h_samp_factor;
  158527. JDIMENSION MCU_cols;
  158528. max_h_samp_factor = 1;
  158529. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158530. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158531. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158532. }
  158533. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158534. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158535. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158536. }
  158537. LOCAL(void)
  158538. trim_bottom_edge (j_compress_ptr dstinfo)
  158539. {
  158540. int ci, max_v_samp_factor;
  158541. JDIMENSION MCU_rows;
  158542. max_v_samp_factor = 1;
  158543. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158544. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158545. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158546. }
  158547. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158548. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158549. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158550. }
  158551. GLOBAL(jvirt_barray_ptr *)
  158552. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158553. j_compress_ptr dstinfo,
  158554. jvirt_barray_ptr *src_coef_arrays,
  158555. jpeg_transform_info *info)
  158556. {
  158557. if (info->force_grayscale) {
  158558. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158559. dstinfo->num_components == 3) ||
  158560. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158561. dstinfo->num_components == 1)) {
  158562. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158563. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158564. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158565. } else {
  158566. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158567. }
  158568. }
  158569. switch (info->transform) {
  158570. case JXFORM_NONE:
  158571. break;
  158572. case JXFORM_FLIP_H:
  158573. if (info->trim)
  158574. trim_right_edge(dstinfo);
  158575. break;
  158576. case JXFORM_FLIP_V:
  158577. if (info->trim)
  158578. trim_bottom_edge(dstinfo);
  158579. break;
  158580. case JXFORM_TRANSPOSE:
  158581. transpose_critical_parameters(dstinfo);
  158582. break;
  158583. case JXFORM_TRANSVERSE:
  158584. transpose_critical_parameters(dstinfo);
  158585. if (info->trim) {
  158586. trim_right_edge(dstinfo);
  158587. trim_bottom_edge(dstinfo);
  158588. }
  158589. break;
  158590. case JXFORM_ROT_90:
  158591. transpose_critical_parameters(dstinfo);
  158592. if (info->trim)
  158593. trim_right_edge(dstinfo);
  158594. break;
  158595. case JXFORM_ROT_180:
  158596. if (info->trim) {
  158597. trim_right_edge(dstinfo);
  158598. trim_bottom_edge(dstinfo);
  158599. }
  158600. break;
  158601. case JXFORM_ROT_270:
  158602. transpose_critical_parameters(dstinfo);
  158603. if (info->trim)
  158604. trim_bottom_edge(dstinfo);
  158605. break;
  158606. }
  158607. if (info->workspace_coef_arrays != NULL)
  158608. return info->workspace_coef_arrays;
  158609. return src_coef_arrays;
  158610. }
  158611. GLOBAL(void)
  158612. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158613. j_compress_ptr dstinfo,
  158614. jvirt_barray_ptr *src_coef_arrays,
  158615. jpeg_transform_info *info)
  158616. {
  158617. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158618. switch (info->transform) {
  158619. case JXFORM_NONE:
  158620. break;
  158621. case JXFORM_FLIP_H:
  158622. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158623. break;
  158624. case JXFORM_FLIP_V:
  158625. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158626. break;
  158627. case JXFORM_TRANSPOSE:
  158628. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158629. break;
  158630. case JXFORM_TRANSVERSE:
  158631. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158632. break;
  158633. case JXFORM_ROT_90:
  158634. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158635. break;
  158636. case JXFORM_ROT_180:
  158637. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158638. break;
  158639. case JXFORM_ROT_270:
  158640. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158641. break;
  158642. }
  158643. }
  158644. #endif /* TRANSFORMS_SUPPORTED */
  158645. GLOBAL(void)
  158646. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158647. {
  158648. #ifdef SAVE_MARKERS_SUPPORTED
  158649. int m;
  158650. if (option != JCOPYOPT_NONE) {
  158651. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158652. }
  158653. if (option == JCOPYOPT_ALL) {
  158654. for (m = 0; m < 16; m++)
  158655. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158656. }
  158657. #endif /* SAVE_MARKERS_SUPPORTED */
  158658. }
  158659. GLOBAL(void)
  158660. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158661. JCOPY_OPTION option)
  158662. {
  158663. jpeg_saved_marker_ptr marker;
  158664. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158665. if (dstinfo->write_JFIF_header &&
  158666. marker->marker == JPEG_APP0 &&
  158667. marker->data_length >= 5 &&
  158668. GETJOCTET(marker->data[0]) == 0x4A &&
  158669. GETJOCTET(marker->data[1]) == 0x46 &&
  158670. GETJOCTET(marker->data[2]) == 0x49 &&
  158671. GETJOCTET(marker->data[3]) == 0x46 &&
  158672. GETJOCTET(marker->data[4]) == 0)
  158673. continue; /* reject duplicate JFIF */
  158674. if (dstinfo->write_Adobe_marker &&
  158675. marker->marker == JPEG_APP0+14 &&
  158676. marker->data_length >= 5 &&
  158677. GETJOCTET(marker->data[0]) == 0x41 &&
  158678. GETJOCTET(marker->data[1]) == 0x64 &&
  158679. GETJOCTET(marker->data[2]) == 0x6F &&
  158680. GETJOCTET(marker->data[3]) == 0x62 &&
  158681. GETJOCTET(marker->data[4]) == 0x65)
  158682. continue; /* reject duplicate Adobe */
  158683. #ifdef NEED_FAR_POINTERS
  158684. {
  158685. unsigned int i;
  158686. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158687. for (i = 0; i < marker->data_length; i++)
  158688. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158689. }
  158690. #else
  158691. jpeg_write_marker(dstinfo, marker->marker,
  158692. marker->data, marker->data_length);
  158693. #endif
  158694. }
  158695. }
  158696. /*** End of inlined file: transupp.c ***/
  158697. }
  158698. #else
  158699. #define JPEG_INTERNALS
  158700. #undef FAR
  158701. #include <jpeglib.h>
  158702. #endif
  158703. }
  158704. #undef max
  158705. #undef min
  158706. #if JUCE_MSVC
  158707. #pragma warning (pop)
  158708. #endif
  158709. BEGIN_JUCE_NAMESPACE
  158710. namespace JPEGHelpers
  158711. {
  158712. using namespace jpeglibNamespace;
  158713. #if ! JUCE_MSVC
  158714. using jpeglibNamespace::boolean;
  158715. #endif
  158716. struct JPEGDecodingFailure {};
  158717. static void fatalErrorHandler (j_common_ptr)
  158718. {
  158719. throw JPEGDecodingFailure();
  158720. }
  158721. static void silentErrorCallback1 (j_common_ptr) {}
  158722. static void silentErrorCallback2 (j_common_ptr, int) {}
  158723. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158724. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158725. {
  158726. zerostruct (err);
  158727. err.error_exit = fatalErrorHandler;
  158728. err.emit_message = silentErrorCallback2;
  158729. err.output_message = silentErrorCallback1;
  158730. err.format_message = silentErrorCallback3;
  158731. err.reset_error_mgr = silentErrorCallback1;
  158732. }
  158733. static void dummyCallback1 (j_decompress_ptr)
  158734. {
  158735. }
  158736. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158737. {
  158738. decompStruct->src->next_input_byte += num;
  158739. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158740. decompStruct->src->bytes_in_buffer -= num;
  158741. }
  158742. static boolean jpegFill (j_decompress_ptr)
  158743. {
  158744. return 0;
  158745. }
  158746. static const int jpegBufferSize = 512;
  158747. struct JuceJpegDest : public jpeg_destination_mgr
  158748. {
  158749. OutputStream* output;
  158750. char* buffer;
  158751. };
  158752. static void jpegWriteInit (j_compress_ptr)
  158753. {
  158754. }
  158755. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158756. {
  158757. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158758. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158759. dest->output->write (dest->buffer, (int) numToWrite);
  158760. }
  158761. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158762. {
  158763. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158764. const int numToWrite = jpegBufferSize;
  158765. dest->next_output_byte = (JOCTET*) dest->buffer;
  158766. dest->free_in_buffer = jpegBufferSize;
  158767. return dest->output->write (dest->buffer, numToWrite);
  158768. }
  158769. }
  158770. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158771. {
  158772. using namespace jpeglibNamespace;
  158773. using namespace JPEGHelpers;
  158774. MemoryBlock mb;
  158775. in.readIntoMemoryBlock (mb);
  158776. Image* image = 0;
  158777. if (mb.getSize() > 16)
  158778. {
  158779. struct jpeg_decompress_struct jpegDecompStruct;
  158780. struct jpeg_error_mgr jerr;
  158781. setupSilentErrorHandler (jerr);
  158782. jpegDecompStruct.err = &jerr;
  158783. jpeg_create_decompress (&jpegDecompStruct);
  158784. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158785. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158786. jpegDecompStruct.src->init_source = dummyCallback1;
  158787. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158788. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158789. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158790. jpegDecompStruct.src->term_source = dummyCallback1;
  158791. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  158792. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158793. try
  158794. {
  158795. jpeg_read_header (&jpegDecompStruct, TRUE);
  158796. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158797. const int width = jpegDecompStruct.output_width;
  158798. const int height = jpegDecompStruct.output_height;
  158799. jpegDecompStruct.out_color_space = JCS_RGB;
  158800. JSAMPARRAY buffer
  158801. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158802. JPOOL_IMAGE,
  158803. width * 3, 1);
  158804. if (jpeg_start_decompress (&jpegDecompStruct))
  158805. {
  158806. image = Image::createNativeImage (Image::RGB, width, height, false);
  158807. const bool hasAlphaChan = image->hasAlphaChannel();
  158808. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158809. for (int y = 0; y < height; ++y)
  158810. {
  158811. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158812. const uint8* src = *buffer;
  158813. uint8* dest = destData.getLinePointer (y);
  158814. if (hasAlphaChan)
  158815. {
  158816. for (int i = width; --i >= 0;)
  158817. {
  158818. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158819. ((PixelARGB*) dest)->premultiply();
  158820. dest += destData.pixelStride;
  158821. src += 3;
  158822. }
  158823. }
  158824. else
  158825. {
  158826. for (int i = width; --i >= 0;)
  158827. {
  158828. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158829. dest += destData.pixelStride;
  158830. src += 3;
  158831. }
  158832. }
  158833. }
  158834. jpeg_finish_decompress (&jpegDecompStruct);
  158835. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  158836. }
  158837. jpeg_destroy_decompress (&jpegDecompStruct);
  158838. }
  158839. catch (...)
  158840. {}
  158841. }
  158842. return image;
  158843. }
  158844. bool juce_writeJPEGImageToStream (const Image& image,
  158845. OutputStream& out,
  158846. float quality)
  158847. {
  158848. using namespace jpeglibNamespace;
  158849. using namespace JPEGHelpers;
  158850. if (image.hasAlphaChannel())
  158851. {
  158852. // this method could fill the background in white and still save the image..
  158853. jassertfalse
  158854. return true;
  158855. }
  158856. struct jpeg_compress_struct jpegCompStruct;
  158857. struct jpeg_error_mgr jerr;
  158858. setupSilentErrorHandler (jerr);
  158859. jpegCompStruct.err = &jerr;
  158860. jpeg_create_compress (&jpegCompStruct);
  158861. JuceJpegDest dest;
  158862. jpegCompStruct.dest = &dest;
  158863. dest.output = &out;
  158864. HeapBlock <char> tempBuffer (jpegBufferSize);
  158865. dest.buffer = (char*) tempBuffer;
  158866. dest.next_output_byte = (JOCTET*) dest.buffer;
  158867. dest.free_in_buffer = jpegBufferSize;
  158868. dest.init_destination = jpegWriteInit;
  158869. dest.empty_output_buffer = jpegWriteFlush;
  158870. dest.term_destination = jpegWriteTerminate;
  158871. jpegCompStruct.image_width = image.getWidth();
  158872. jpegCompStruct.image_height = image.getHeight();
  158873. jpegCompStruct.input_components = 3;
  158874. jpegCompStruct.in_color_space = JCS_RGB;
  158875. jpegCompStruct.write_JFIF_header = 1;
  158876. jpegCompStruct.X_density = 72;
  158877. jpegCompStruct.Y_density = 72;
  158878. jpeg_set_defaults (&jpegCompStruct);
  158879. jpegCompStruct.dct_method = JDCT_FLOAT;
  158880. jpegCompStruct.optimize_coding = 1;
  158881. //jpegCompStruct.smoothing_factor = 10;
  158882. if (quality < 0.0f)
  158883. quality = 0.85f;
  158884. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  158885. jpeg_start_compress (&jpegCompStruct, TRUE);
  158886. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  158887. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  158888. JPOOL_IMAGE, strideBytes, 1);
  158889. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  158890. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  158891. {
  158892. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  158893. uint8* dst = *buffer;
  158894. for (int i = jpegCompStruct.image_width; --i >= 0;)
  158895. {
  158896. *dst++ = ((const PixelRGB*) src)->getRed();
  158897. *dst++ = ((const PixelRGB*) src)->getGreen();
  158898. *dst++ = ((const PixelRGB*) src)->getBlue();
  158899. src += srcData.pixelStride;
  158900. }
  158901. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  158902. }
  158903. jpeg_finish_compress (&jpegCompStruct);
  158904. jpeg_destroy_compress (&jpegCompStruct);
  158905. out.flush();
  158906. return true;
  158907. }
  158908. END_JUCE_NAMESPACE
  158909. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  158910. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  158911. #ifdef _MSC_VER
  158912. #pragma warning (push)
  158913. #pragma warning (disable: 4390 4611)
  158914. #endif
  158915. namespace zlibNamespace
  158916. {
  158917. #if JUCE_INCLUDE_ZLIB_CODE
  158918. #undef OS_CODE
  158919. #undef fdopen
  158920. #undef OS_CODE
  158921. #else
  158922. #include <zlib.h>
  158923. #endif
  158924. }
  158925. namespace pnglibNamespace
  158926. {
  158927. using namespace zlibNamespace;
  158928. #if JUCE_INCLUDE_PNGLIB_CODE
  158929. #if _MSC_VER != 1310
  158930. using ::calloc; // (causes conflict in VS.NET 2003)
  158931. using ::malloc;
  158932. using ::free;
  158933. #endif
  158934. extern "C"
  158935. {
  158936. using ::abs;
  158937. #define PNG_INTERNAL
  158938. #define NO_DUMMY_DECL
  158939. #define PNG_SETJMP_NOT_SUPPORTED
  158940. /*** Start of inlined file: png.h ***/
  158941. #ifndef PNG_H
  158942. #define PNG_H
  158943. #define PNG_LIBPNG_VER_STRING "1.2.21"
  158944. #define PNG_HEADER_VERSION_STRING \
  158945. " libpng version 1.2.21 - October 4, 2007\n"
  158946. #define PNG_LIBPNG_VER_SONUM 0
  158947. #define PNG_LIBPNG_VER_DLLNUM 13
  158948. #define PNG_LIBPNG_VER_MAJOR 1
  158949. #define PNG_LIBPNG_VER_MINOR 2
  158950. #define PNG_LIBPNG_VER_RELEASE 21
  158951. #define PNG_LIBPNG_VER_BUILD 0
  158952. #define PNG_LIBPNG_BUILD_ALPHA 1
  158953. #define PNG_LIBPNG_BUILD_BETA 2
  158954. #define PNG_LIBPNG_BUILD_RC 3
  158955. #define PNG_LIBPNG_BUILD_STABLE 4
  158956. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  158957. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  158958. PNG_LIBPNG_BUILD_STABLE only */
  158959. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  158960. PNG_LIBPNG_BUILD_SPECIAL */
  158961. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  158962. PNG_LIBPNG_BUILD_PRIVATE */
  158963. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  158964. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  158965. #ifndef PNG_VERSION_INFO_ONLY
  158966. #endif
  158967. /*** Start of inlined file: pngconf.h ***/
  158968. #ifndef PNGCONF_H
  158969. #define PNGCONF_H
  158970. #define PNG_1_2_X
  158971. // These are some Juce config settings that should remove any unnecessary code bloat..
  158972. #define PNG_NO_STDIO 1
  158973. #define PNG_DEBUG 0
  158974. #define PNG_NO_WARNINGS 1
  158975. #define PNG_NO_ERROR_TEXT 1
  158976. #define PNG_NO_ERROR_NUMBERS 1
  158977. #define PNG_NO_USER_MEM 1
  158978. #define PNG_NO_READ_iCCP 1
  158979. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  158980. #define PNG_NO_READ_USER_CHUNKS 1
  158981. #define PNG_NO_READ_iTXt 1
  158982. #define PNG_NO_READ_sCAL 1
  158983. #define PNG_NO_READ_sPLT 1
  158984. #define png_error(a, b) png_err(a)
  158985. #define png_warning(a, b)
  158986. #define png_chunk_error(a, b) png_err(a)
  158987. #define png_chunk_warning(a, b)
  158988. #ifdef PNG_USER_CONFIG
  158989. # ifndef PNG_USER_PRIVATEBUILD
  158990. # define PNG_USER_PRIVATEBUILD
  158991. # endif
  158992. #include "pngusr.h"
  158993. #endif
  158994. #ifdef PNG_CONFIGURE_LIBPNG
  158995. #ifdef HAVE_CONFIG_H
  158996. #include "config.h"
  158997. #endif
  158998. #endif
  158999. #ifdef __STDC__
  159000. #ifdef SPECIALBUILD
  159001. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159002. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159003. #endif
  159004. #ifdef PRIVATEBUILD
  159005. # pragma message("PRIVATEBUILD is deprecated.\
  159006. Use PNG_USER_PRIVATEBUILD instead.")
  159007. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159008. #endif
  159009. #endif /* __STDC__ */
  159010. #ifndef PNG_VERSION_INFO_ONLY
  159011. # define PNG_WARN_UNINITIALIZED_ROW 1
  159012. #ifndef PNG_ZBUF_SIZE
  159013. # define PNG_ZBUF_SIZE 8192
  159014. #endif
  159015. #ifndef PNG_NO_READ_SUPPORTED
  159016. # define PNG_READ_SUPPORTED
  159017. #endif
  159018. #ifndef PNG_NO_WRITE_SUPPORTED
  159019. # define PNG_WRITE_SUPPORTED
  159020. #endif
  159021. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159022. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159023. # define PNG_MNG_FEATURES_SUPPORTED
  159024. # endif
  159025. #endif
  159026. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159027. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159028. # define PNG_FLOATING_POINT_SUPPORTED
  159029. # endif
  159030. #endif
  159031. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159032. # define PNG_MAX_MALLOC_64K
  159033. #endif
  159034. #if defined(__CYGWIN__)
  159035. # if defined(ALL_STATIC)
  159036. # if defined(PNG_BUILD_DLL)
  159037. # undef PNG_BUILD_DLL
  159038. # endif
  159039. # if defined(PNG_USE_DLL)
  159040. # undef PNG_USE_DLL
  159041. # endif
  159042. # if defined(PNG_DLL)
  159043. # undef PNG_DLL
  159044. # endif
  159045. # if !defined(PNG_STATIC)
  159046. # define PNG_STATIC
  159047. # endif
  159048. # else
  159049. # if defined (PNG_BUILD_DLL)
  159050. # if defined(PNG_STATIC)
  159051. # undef PNG_STATIC
  159052. # endif
  159053. # if defined(PNG_USE_DLL)
  159054. # undef PNG_USE_DLL
  159055. # endif
  159056. # if !defined(PNG_DLL)
  159057. # define PNG_DLL
  159058. # endif
  159059. # else
  159060. # if defined(PNG_STATIC)
  159061. # if defined(PNG_USE_DLL)
  159062. # undef PNG_USE_DLL
  159063. # endif
  159064. # if defined(PNG_DLL)
  159065. # undef PNG_DLL
  159066. # endif
  159067. # else
  159068. # if !defined(PNG_USE_DLL)
  159069. # define PNG_USE_DLL
  159070. # endif
  159071. # if !defined(PNG_DLL)
  159072. # define PNG_DLL
  159073. # endif
  159074. # endif
  159075. # endif
  159076. # endif
  159077. #endif
  159078. #if defined(_WIN32_WCE)
  159079. # include <windows.h>
  159080. # define PNG_NO_CONSOLE_IO
  159081. # ifdef PNG_DEBUG
  159082. # undef PNG_DEBUG
  159083. # endif
  159084. #endif
  159085. #ifdef PNG_BUILD_DLL
  159086. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159087. # ifndef PNG_NO_CONSOLE_IO
  159088. # define PNG_NO_CONSOLE_IO
  159089. # endif
  159090. # endif
  159091. #endif
  159092. # ifdef PNG_NO_STDIO
  159093. # ifndef PNG_NO_CONSOLE_IO
  159094. # define PNG_NO_CONSOLE_IO
  159095. # endif
  159096. # ifdef PNG_DEBUG
  159097. # if (PNG_DEBUG > 0)
  159098. # include <stdio.h>
  159099. # endif
  159100. # endif
  159101. # else
  159102. # if !defined(_WIN32_WCE)
  159103. # include <stdio.h>
  159104. # endif
  159105. # endif
  159106. #ifndef PNGARG
  159107. #ifdef OF /* zlib prototype munger */
  159108. # define PNGARG(arglist) OF(arglist)
  159109. #else
  159110. #ifdef _NO_PROTO
  159111. # define PNGARG(arglist) ()
  159112. # ifndef PNG_TYPECAST_NULL
  159113. # define PNG_TYPECAST_NULL
  159114. # endif
  159115. #else
  159116. # define PNGARG(arglist) arglist
  159117. #endif /* _NO_PROTO */
  159118. #endif /* OF */
  159119. #endif /* PNGARG */
  159120. #ifndef MACOS
  159121. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159122. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159123. # define MACOS
  159124. # endif
  159125. #endif
  159126. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159127. # include <sys/types.h>
  159128. #endif
  159129. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159130. # define PNG_SETJMP_SUPPORTED
  159131. #endif
  159132. #ifdef PNG_SETJMP_SUPPORTED
  159133. # ifdef __linux__
  159134. # ifdef _BSD_SOURCE
  159135. # define PNG_SAVE_BSD_SOURCE
  159136. # undef _BSD_SOURCE
  159137. # endif
  159138. # ifdef _SETJMP_H
  159139. __png.h__ already includes setjmp.h;
  159140. __dont__ include it again.;
  159141. # endif
  159142. # endif /* __linux__ */
  159143. # include <setjmp.h>
  159144. # ifdef __linux__
  159145. # ifdef PNG_SAVE_BSD_SOURCE
  159146. # define _BSD_SOURCE
  159147. # undef PNG_SAVE_BSD_SOURCE
  159148. # endif
  159149. # endif /* __linux__ */
  159150. #endif /* PNG_SETJMP_SUPPORTED */
  159151. #ifdef BSD
  159152. #if ! JUCE_MAC
  159153. # include <strings.h>
  159154. #endif
  159155. #else
  159156. # include <string.h>
  159157. #endif
  159158. #ifdef PNG_INTERNAL
  159159. #include <stdlib.h>
  159160. #define PNG_EXTERN
  159161. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159162. # if defined(MACOS)
  159163. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159164. # include <fp.h>
  159165. # endif
  159166. # else
  159167. # include <math.h>
  159168. # endif
  159169. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159170. # include <m68881.h>
  159171. # endif
  159172. #endif
  159173. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159174. # define PNG_ALWAYS_EXTERN
  159175. #endif
  159176. #if defined(__TURBOC__) && defined(__MSDOS__)
  159177. # include <mem.h>
  159178. # include <alloc.h>
  159179. #endif
  159180. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159181. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159182. # include <malloc.h>
  159183. #endif
  159184. #ifndef PNG_DITHER_RED_BITS
  159185. # define PNG_DITHER_RED_BITS 5
  159186. #endif
  159187. #ifndef PNG_DITHER_GREEN_BITS
  159188. # define PNG_DITHER_GREEN_BITS 5
  159189. #endif
  159190. #ifndef PNG_DITHER_BLUE_BITS
  159191. # define PNG_DITHER_BLUE_BITS 5
  159192. #endif
  159193. #ifndef PNG_MAX_GAMMA_8
  159194. # define PNG_MAX_GAMMA_8 11
  159195. #endif
  159196. #ifndef PNG_GAMMA_THRESHOLD
  159197. # define PNG_GAMMA_THRESHOLD 0.05
  159198. #endif
  159199. #endif /* PNG_INTERNAL */
  159200. #ifndef PNG_NO_CONST
  159201. # define PNG_CONST const
  159202. #else
  159203. # define PNG_CONST
  159204. #endif
  159205. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159206. # ifndef PNG_NO_iTXt_SUPPORTED
  159207. # define PNG_NO_iTXt_SUPPORTED
  159208. # endif
  159209. # ifndef PNG_NO_READ_iTXt
  159210. # define PNG_NO_READ_iTXt
  159211. # endif
  159212. # ifndef PNG_NO_WRITE_iTXt
  159213. # define PNG_NO_WRITE_iTXt
  159214. # endif
  159215. #endif
  159216. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159217. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159218. # define PNG_READ_iTXt
  159219. # endif
  159220. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159221. # define PNG_WRITE_iTXt
  159222. # endif
  159223. #endif
  159224. #ifdef PNG_LEGACY_SUPPORTED
  159225. # define PNG_NO_FREE_ME
  159226. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159227. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159228. # define PNG_NO_READ_USER_CHUNKS
  159229. # define PNG_NO_READ_iCCP
  159230. # define PNG_NO_WRITE_iCCP
  159231. # define PNG_NO_READ_iTXt
  159232. # define PNG_NO_WRITE_iTXt
  159233. # define PNG_NO_READ_sCAL
  159234. # define PNG_NO_WRITE_sCAL
  159235. # define PNG_NO_READ_sPLT
  159236. # define PNG_NO_WRITE_sPLT
  159237. # define PNG_NO_INFO_IMAGE
  159238. # define PNG_NO_READ_RGB_TO_GRAY
  159239. # define PNG_NO_READ_USER_TRANSFORM
  159240. # define PNG_NO_WRITE_USER_TRANSFORM
  159241. # define PNG_NO_USER_MEM
  159242. # define PNG_NO_READ_EMPTY_PLTE
  159243. # define PNG_NO_MNG_FEATURES
  159244. # define PNG_NO_FIXED_POINT_SUPPORTED
  159245. #endif
  159246. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159247. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159248. # define PNG_FIXED_POINT_SUPPORTED
  159249. #endif
  159250. #ifndef PNG_NO_FREE_ME
  159251. # define PNG_FREE_ME_SUPPORTED
  159252. #endif
  159253. #if defined(PNG_READ_SUPPORTED)
  159254. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159255. !defined(PNG_NO_READ_TRANSFORMS)
  159256. # define PNG_READ_TRANSFORMS_SUPPORTED
  159257. #endif
  159258. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159259. # ifndef PNG_NO_READ_EXPAND
  159260. # define PNG_READ_EXPAND_SUPPORTED
  159261. # endif
  159262. # ifndef PNG_NO_READ_SHIFT
  159263. # define PNG_READ_SHIFT_SUPPORTED
  159264. # endif
  159265. # ifndef PNG_NO_READ_PACK
  159266. # define PNG_READ_PACK_SUPPORTED
  159267. # endif
  159268. # ifndef PNG_NO_READ_BGR
  159269. # define PNG_READ_BGR_SUPPORTED
  159270. # endif
  159271. # ifndef PNG_NO_READ_SWAP
  159272. # define PNG_READ_SWAP_SUPPORTED
  159273. # endif
  159274. # ifndef PNG_NO_READ_PACKSWAP
  159275. # define PNG_READ_PACKSWAP_SUPPORTED
  159276. # endif
  159277. # ifndef PNG_NO_READ_INVERT
  159278. # define PNG_READ_INVERT_SUPPORTED
  159279. # endif
  159280. # ifndef PNG_NO_READ_DITHER
  159281. # define PNG_READ_DITHER_SUPPORTED
  159282. # endif
  159283. # ifndef PNG_NO_READ_BACKGROUND
  159284. # define PNG_READ_BACKGROUND_SUPPORTED
  159285. # endif
  159286. # ifndef PNG_NO_READ_16_TO_8
  159287. # define PNG_READ_16_TO_8_SUPPORTED
  159288. # endif
  159289. # ifndef PNG_NO_READ_FILLER
  159290. # define PNG_READ_FILLER_SUPPORTED
  159291. # endif
  159292. # ifndef PNG_NO_READ_GAMMA
  159293. # define PNG_READ_GAMMA_SUPPORTED
  159294. # endif
  159295. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159296. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159297. # endif
  159298. # ifndef PNG_NO_READ_SWAP_ALPHA
  159299. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159300. # endif
  159301. # ifndef PNG_NO_READ_INVERT_ALPHA
  159302. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159303. # endif
  159304. # ifndef PNG_NO_READ_STRIP_ALPHA
  159305. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159306. # endif
  159307. # ifndef PNG_NO_READ_USER_TRANSFORM
  159308. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159309. # endif
  159310. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159311. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159312. # endif
  159313. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159314. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159315. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159316. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159317. #endif /* about interlacing capability! You'll */
  159318. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159319. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159320. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159321. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159322. # endif
  159323. #endif
  159324. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159325. #ifndef PNG_NO_READ_EMPTY_PLTE
  159326. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159327. #endif
  159328. #endif
  159329. #endif /* PNG_READ_SUPPORTED */
  159330. #if defined(PNG_WRITE_SUPPORTED)
  159331. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159332. !defined(PNG_NO_WRITE_TRANSFORMS)
  159333. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159334. #endif
  159335. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159336. # ifndef PNG_NO_WRITE_SHIFT
  159337. # define PNG_WRITE_SHIFT_SUPPORTED
  159338. # endif
  159339. # ifndef PNG_NO_WRITE_PACK
  159340. # define PNG_WRITE_PACK_SUPPORTED
  159341. # endif
  159342. # ifndef PNG_NO_WRITE_BGR
  159343. # define PNG_WRITE_BGR_SUPPORTED
  159344. # endif
  159345. # ifndef PNG_NO_WRITE_SWAP
  159346. # define PNG_WRITE_SWAP_SUPPORTED
  159347. # endif
  159348. # ifndef PNG_NO_WRITE_PACKSWAP
  159349. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159350. # endif
  159351. # ifndef PNG_NO_WRITE_INVERT
  159352. # define PNG_WRITE_INVERT_SUPPORTED
  159353. # endif
  159354. # ifndef PNG_NO_WRITE_FILLER
  159355. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159356. # endif
  159357. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159358. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159359. # endif
  159360. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159361. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159362. # endif
  159363. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159364. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159365. # endif
  159366. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159367. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159368. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159369. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159370. encoders, but can cause trouble
  159371. if left undefined */
  159372. #endif
  159373. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159374. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159375. defined(PNG_FLOATING_POINT_SUPPORTED)
  159376. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159377. #endif
  159378. #ifndef PNG_NO_WRITE_FLUSH
  159379. # define PNG_WRITE_FLUSH_SUPPORTED
  159380. #endif
  159381. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159382. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159383. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159384. #endif
  159385. #endif
  159386. #endif /* PNG_WRITE_SUPPORTED */
  159387. #ifndef PNG_1_0_X
  159388. # ifndef PNG_NO_ERROR_NUMBERS
  159389. # define PNG_ERROR_NUMBERS_SUPPORTED
  159390. # endif
  159391. #endif /* PNG_1_0_X */
  159392. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159393. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159394. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159395. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159396. # endif
  159397. #endif
  159398. #ifndef PNG_NO_STDIO
  159399. # define PNG_TIME_RFC1123_SUPPORTED
  159400. #endif
  159401. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159402. # define PNG_EASY_ACCESS_SUPPORTED
  159403. #endif
  159404. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159405. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159406. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159407. # endif
  159408. #endif
  159409. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159410. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159411. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159412. # endif
  159413. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159414. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159415. # define PNG_NO_MMX_CODE
  159416. # endif
  159417. # endif
  159418. # if defined(__APPLE__)
  159419. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159420. # define PNG_NO_MMX_CODE
  159421. # endif
  159422. # endif
  159423. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159424. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159425. # define PNG_NO_MMX_CODE
  159426. # endif
  159427. # endif
  159428. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159429. # define PNG_MMX_CODE_SUPPORTED
  159430. # endif
  159431. #endif
  159432. #if !defined(PNG_1_0_X)
  159433. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159434. # define PNG_USER_MEM_SUPPORTED
  159435. #endif
  159436. #endif /* PNG_1_0_X */
  159437. #if !defined(PNG_1_0_X)
  159438. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159439. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159440. # define PNG_SET_USER_LIMITS_SUPPORTED
  159441. #endif
  159442. #endif
  159443. #endif /* PNG_1_0_X */
  159444. #ifndef PNG_USER_WIDTH_MAX
  159445. # define PNG_USER_WIDTH_MAX 1000000L
  159446. #endif
  159447. #ifndef PNG_USER_HEIGHT_MAX
  159448. # define PNG_USER_HEIGHT_MAX 1000000L
  159449. #endif
  159450. #if defined(PNG_READ_SUPPORTED) && \
  159451. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159452. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159453. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159454. #endif
  159455. #if defined(PNG_WRITE_SUPPORTED) && \
  159456. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159457. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159458. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159459. #endif
  159460. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159461. #ifdef PNG_NO_READ_TEXT
  159462. # define PNG_NO_READ_iTXt
  159463. # define PNG_NO_READ_tEXt
  159464. # define PNG_NO_READ_zTXt
  159465. #endif
  159466. #ifndef PNG_NO_READ_bKGD
  159467. # define PNG_READ_bKGD_SUPPORTED
  159468. # define PNG_bKGD_SUPPORTED
  159469. #endif
  159470. #ifndef PNG_NO_READ_cHRM
  159471. # define PNG_READ_cHRM_SUPPORTED
  159472. # define PNG_cHRM_SUPPORTED
  159473. #endif
  159474. #ifndef PNG_NO_READ_gAMA
  159475. # define PNG_READ_gAMA_SUPPORTED
  159476. # define PNG_gAMA_SUPPORTED
  159477. #endif
  159478. #ifndef PNG_NO_READ_hIST
  159479. # define PNG_READ_hIST_SUPPORTED
  159480. # define PNG_hIST_SUPPORTED
  159481. #endif
  159482. #ifndef PNG_NO_READ_iCCP
  159483. # define PNG_READ_iCCP_SUPPORTED
  159484. # define PNG_iCCP_SUPPORTED
  159485. #endif
  159486. #ifndef PNG_NO_READ_iTXt
  159487. # ifndef PNG_READ_iTXt_SUPPORTED
  159488. # define PNG_READ_iTXt_SUPPORTED
  159489. # endif
  159490. # ifndef PNG_iTXt_SUPPORTED
  159491. # define PNG_iTXt_SUPPORTED
  159492. # endif
  159493. #endif
  159494. #ifndef PNG_NO_READ_oFFs
  159495. # define PNG_READ_oFFs_SUPPORTED
  159496. # define PNG_oFFs_SUPPORTED
  159497. #endif
  159498. #ifndef PNG_NO_READ_pCAL
  159499. # define PNG_READ_pCAL_SUPPORTED
  159500. # define PNG_pCAL_SUPPORTED
  159501. #endif
  159502. #ifndef PNG_NO_READ_sCAL
  159503. # define PNG_READ_sCAL_SUPPORTED
  159504. # define PNG_sCAL_SUPPORTED
  159505. #endif
  159506. #ifndef PNG_NO_READ_pHYs
  159507. # define PNG_READ_pHYs_SUPPORTED
  159508. # define PNG_pHYs_SUPPORTED
  159509. #endif
  159510. #ifndef PNG_NO_READ_sBIT
  159511. # define PNG_READ_sBIT_SUPPORTED
  159512. # define PNG_sBIT_SUPPORTED
  159513. #endif
  159514. #ifndef PNG_NO_READ_sPLT
  159515. # define PNG_READ_sPLT_SUPPORTED
  159516. # define PNG_sPLT_SUPPORTED
  159517. #endif
  159518. #ifndef PNG_NO_READ_sRGB
  159519. # define PNG_READ_sRGB_SUPPORTED
  159520. # define PNG_sRGB_SUPPORTED
  159521. #endif
  159522. #ifndef PNG_NO_READ_tEXt
  159523. # define PNG_READ_tEXt_SUPPORTED
  159524. # define PNG_tEXt_SUPPORTED
  159525. #endif
  159526. #ifndef PNG_NO_READ_tIME
  159527. # define PNG_READ_tIME_SUPPORTED
  159528. # define PNG_tIME_SUPPORTED
  159529. #endif
  159530. #ifndef PNG_NO_READ_tRNS
  159531. # define PNG_READ_tRNS_SUPPORTED
  159532. # define PNG_tRNS_SUPPORTED
  159533. #endif
  159534. #ifndef PNG_NO_READ_zTXt
  159535. # define PNG_READ_zTXt_SUPPORTED
  159536. # define PNG_zTXt_SUPPORTED
  159537. #endif
  159538. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159539. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159540. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159541. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159542. # endif
  159543. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159544. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159545. # endif
  159546. #endif
  159547. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159548. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159549. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159550. # define PNG_USER_CHUNKS_SUPPORTED
  159551. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159552. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159553. # endif
  159554. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159555. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159556. # endif
  159557. #endif
  159558. #ifndef PNG_NO_READ_OPT_PLTE
  159559. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159560. #endif /* optional PLTE chunk in RGB and RGBA images */
  159561. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159562. defined(PNG_READ_zTXt_SUPPORTED)
  159563. # define PNG_READ_TEXT_SUPPORTED
  159564. # define PNG_TEXT_SUPPORTED
  159565. #endif
  159566. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159567. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159568. #ifdef PNG_NO_WRITE_TEXT
  159569. # define PNG_NO_WRITE_iTXt
  159570. # define PNG_NO_WRITE_tEXt
  159571. # define PNG_NO_WRITE_zTXt
  159572. #endif
  159573. #ifndef PNG_NO_WRITE_bKGD
  159574. # define PNG_WRITE_bKGD_SUPPORTED
  159575. # ifndef PNG_bKGD_SUPPORTED
  159576. # define PNG_bKGD_SUPPORTED
  159577. # endif
  159578. #endif
  159579. #ifndef PNG_NO_WRITE_cHRM
  159580. # define PNG_WRITE_cHRM_SUPPORTED
  159581. # ifndef PNG_cHRM_SUPPORTED
  159582. # define PNG_cHRM_SUPPORTED
  159583. # endif
  159584. #endif
  159585. #ifndef PNG_NO_WRITE_gAMA
  159586. # define PNG_WRITE_gAMA_SUPPORTED
  159587. # ifndef PNG_gAMA_SUPPORTED
  159588. # define PNG_gAMA_SUPPORTED
  159589. # endif
  159590. #endif
  159591. #ifndef PNG_NO_WRITE_hIST
  159592. # define PNG_WRITE_hIST_SUPPORTED
  159593. # ifndef PNG_hIST_SUPPORTED
  159594. # define PNG_hIST_SUPPORTED
  159595. # endif
  159596. #endif
  159597. #ifndef PNG_NO_WRITE_iCCP
  159598. # define PNG_WRITE_iCCP_SUPPORTED
  159599. # ifndef PNG_iCCP_SUPPORTED
  159600. # define PNG_iCCP_SUPPORTED
  159601. # endif
  159602. #endif
  159603. #ifndef PNG_NO_WRITE_iTXt
  159604. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159605. # define PNG_WRITE_iTXt_SUPPORTED
  159606. # endif
  159607. # ifndef PNG_iTXt_SUPPORTED
  159608. # define PNG_iTXt_SUPPORTED
  159609. # endif
  159610. #endif
  159611. #ifndef PNG_NO_WRITE_oFFs
  159612. # define PNG_WRITE_oFFs_SUPPORTED
  159613. # ifndef PNG_oFFs_SUPPORTED
  159614. # define PNG_oFFs_SUPPORTED
  159615. # endif
  159616. #endif
  159617. #ifndef PNG_NO_WRITE_pCAL
  159618. # define PNG_WRITE_pCAL_SUPPORTED
  159619. # ifndef PNG_pCAL_SUPPORTED
  159620. # define PNG_pCAL_SUPPORTED
  159621. # endif
  159622. #endif
  159623. #ifndef PNG_NO_WRITE_sCAL
  159624. # define PNG_WRITE_sCAL_SUPPORTED
  159625. # ifndef PNG_sCAL_SUPPORTED
  159626. # define PNG_sCAL_SUPPORTED
  159627. # endif
  159628. #endif
  159629. #ifndef PNG_NO_WRITE_pHYs
  159630. # define PNG_WRITE_pHYs_SUPPORTED
  159631. # ifndef PNG_pHYs_SUPPORTED
  159632. # define PNG_pHYs_SUPPORTED
  159633. # endif
  159634. #endif
  159635. #ifndef PNG_NO_WRITE_sBIT
  159636. # define PNG_WRITE_sBIT_SUPPORTED
  159637. # ifndef PNG_sBIT_SUPPORTED
  159638. # define PNG_sBIT_SUPPORTED
  159639. # endif
  159640. #endif
  159641. #ifndef PNG_NO_WRITE_sPLT
  159642. # define PNG_WRITE_sPLT_SUPPORTED
  159643. # ifndef PNG_sPLT_SUPPORTED
  159644. # define PNG_sPLT_SUPPORTED
  159645. # endif
  159646. #endif
  159647. #ifndef PNG_NO_WRITE_sRGB
  159648. # define PNG_WRITE_sRGB_SUPPORTED
  159649. # ifndef PNG_sRGB_SUPPORTED
  159650. # define PNG_sRGB_SUPPORTED
  159651. # endif
  159652. #endif
  159653. #ifndef PNG_NO_WRITE_tEXt
  159654. # define PNG_WRITE_tEXt_SUPPORTED
  159655. # ifndef PNG_tEXt_SUPPORTED
  159656. # define PNG_tEXt_SUPPORTED
  159657. # endif
  159658. #endif
  159659. #ifndef PNG_NO_WRITE_tIME
  159660. # define PNG_WRITE_tIME_SUPPORTED
  159661. # ifndef PNG_tIME_SUPPORTED
  159662. # define PNG_tIME_SUPPORTED
  159663. # endif
  159664. #endif
  159665. #ifndef PNG_NO_WRITE_tRNS
  159666. # define PNG_WRITE_tRNS_SUPPORTED
  159667. # ifndef PNG_tRNS_SUPPORTED
  159668. # define PNG_tRNS_SUPPORTED
  159669. # endif
  159670. #endif
  159671. #ifndef PNG_NO_WRITE_zTXt
  159672. # define PNG_WRITE_zTXt_SUPPORTED
  159673. # ifndef PNG_zTXt_SUPPORTED
  159674. # define PNG_zTXt_SUPPORTED
  159675. # endif
  159676. #endif
  159677. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159678. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159679. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159680. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159681. # endif
  159682. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159683. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159684. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159685. # endif
  159686. # endif
  159687. #endif
  159688. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159689. defined(PNG_WRITE_zTXt_SUPPORTED)
  159690. # define PNG_WRITE_TEXT_SUPPORTED
  159691. # ifndef PNG_TEXT_SUPPORTED
  159692. # define PNG_TEXT_SUPPORTED
  159693. # endif
  159694. #endif
  159695. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159696. #ifndef PNG_NO_INFO_IMAGE
  159697. # define PNG_INFO_IMAGE_SUPPORTED
  159698. #endif
  159699. #if defined(PNG_tIME_SUPPORTED)
  159700. # if !defined(_WIN32_WCE)
  159701. # include <time.h>
  159702. # endif
  159703. #endif
  159704. typedef unsigned long png_uint_32;
  159705. typedef long png_int_32;
  159706. typedef unsigned short png_uint_16;
  159707. typedef short png_int_16;
  159708. typedef unsigned char png_byte;
  159709. #ifdef PNG_SIZE_T
  159710. typedef PNG_SIZE_T png_size_t;
  159711. # define png_sizeof(x) png_convert_size(sizeof (x))
  159712. #else
  159713. typedef size_t png_size_t;
  159714. # define png_sizeof(x) sizeof (x)
  159715. #endif
  159716. #ifdef __BORLANDC__
  159717. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159718. # define LDATA 1
  159719. # else
  159720. # define LDATA 0
  159721. # endif
  159722. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159723. # define PNG_MAX_MALLOC_64K
  159724. # if (LDATA != 1)
  159725. # ifndef FAR
  159726. # define FAR __far
  159727. # endif
  159728. # define USE_FAR_KEYWORD
  159729. # endif /* LDATA != 1 */
  159730. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159731. #endif /* __BORLANDC__ */
  159732. #if defined(FAR)
  159733. # if defined(M_I86MM)
  159734. # define USE_FAR_KEYWORD
  159735. # define FARDATA FAR
  159736. # include <dos.h>
  159737. # endif
  159738. #endif
  159739. #ifndef FAR
  159740. # define FAR
  159741. #endif
  159742. #ifndef FARDATA
  159743. # define FARDATA
  159744. #endif
  159745. typedef png_int_32 png_fixed_point;
  159746. typedef void FAR * png_voidp;
  159747. typedef png_byte FAR * png_bytep;
  159748. typedef png_uint_32 FAR * png_uint_32p;
  159749. typedef png_int_32 FAR * png_int_32p;
  159750. typedef png_uint_16 FAR * png_uint_16p;
  159751. typedef png_int_16 FAR * png_int_16p;
  159752. typedef PNG_CONST char FAR * png_const_charp;
  159753. typedef char FAR * png_charp;
  159754. typedef png_fixed_point FAR * png_fixed_point_p;
  159755. #ifndef PNG_NO_STDIO
  159756. #if defined(_WIN32_WCE)
  159757. typedef HANDLE png_FILE_p;
  159758. #else
  159759. typedef FILE * png_FILE_p;
  159760. #endif
  159761. #endif
  159762. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159763. typedef double FAR * png_doublep;
  159764. #endif
  159765. typedef png_byte FAR * FAR * png_bytepp;
  159766. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159767. typedef png_int_32 FAR * FAR * png_int_32pp;
  159768. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159769. typedef png_int_16 FAR * FAR * png_int_16pp;
  159770. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159771. typedef char FAR * FAR * png_charpp;
  159772. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159773. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159774. typedef double FAR * FAR * png_doublepp;
  159775. #endif
  159776. typedef char FAR * FAR * FAR * png_charppp;
  159777. #if 0
  159778. typedef charf * png_zcharp;
  159779. typedef charf * FAR * png_zcharpp;
  159780. typedef z_stream FAR * png_zstreamp;
  159781. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159782. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159783. # define PNG_DLL
  159784. #endif
  159785. #if defined(__CYGWIN__)
  159786. # if !defined(PNG_STATIC)
  159787. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159788. # undef PNG_USE_GLOBAL_ARRAYS
  159789. # endif
  159790. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159791. # define PNG_USE_LOCAL_ARRAYS
  159792. # endif
  159793. # else
  159794. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159795. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159796. # undef PNG_USE_GLOBAL_ARRAYS
  159797. # endif
  159798. # endif
  159799. # endif
  159800. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159801. # define PNG_USE_LOCAL_ARRAYS
  159802. # endif
  159803. #endif
  159804. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159805. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159806. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159807. # define PNG_USE_LOCAL_ARRAYS
  159808. # else
  159809. # define PNG_USE_GLOBAL_ARRAYS
  159810. # endif
  159811. #endif
  159812. #if defined(__CYGWIN__)
  159813. # undef PNGAPI
  159814. # define PNGAPI __cdecl
  159815. # undef PNG_IMPEXP
  159816. # define PNG_IMPEXP
  159817. #endif
  159818. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  159819. # ifndef PNG_NO_MODULEDEF
  159820. # define PNG_NO_MODULEDEF
  159821. # endif
  159822. #endif
  159823. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  159824. # define PNG_IMPEXP
  159825. #endif
  159826. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  159827. (( defined(_Windows) || defined(_WINDOWS) || \
  159828. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  159829. # ifndef PNGAPI
  159830. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  159831. # define PNGAPI __cdecl
  159832. # else
  159833. # define PNGAPI _cdecl
  159834. # endif
  159835. # endif
  159836. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  159837. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  159838. # define PNG_IMPEXP
  159839. # endif
  159840. # if !defined(PNG_IMPEXP)
  159841. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159842. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  159843. # if defined(_MSC_VER) || defined(__BORLANDC__)
  159844. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  159845. # define PNG_EXPORT PNG_EXPORT_TYPE1
  159846. # else
  159847. # define PNG_EXPORT PNG_EXPORT_TYPE2
  159848. # if defined(PNG_BUILD_DLL)
  159849. # define PNG_IMPEXP __export
  159850. # else
  159851. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  159852. VC++ */
  159853. # endif /* Exists in Borland C++ for
  159854. C++ classes (== huge) */
  159855. # endif
  159856. # endif
  159857. # if !defined(PNG_IMPEXP)
  159858. # if defined(PNG_BUILD_DLL)
  159859. # define PNG_IMPEXP __declspec(dllexport)
  159860. # else
  159861. # define PNG_IMPEXP __declspec(dllimport)
  159862. # endif
  159863. # endif
  159864. # endif /* PNG_IMPEXP */
  159865. #else /* !(DLL || non-cygwin WINDOWS) */
  159866. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  159867. # ifndef PNGAPI
  159868. # define PNGAPI _System
  159869. # endif
  159870. # else
  159871. # if 0 /* ... other platforms, with other meanings */
  159872. # endif
  159873. # endif
  159874. #endif
  159875. #ifndef PNGAPI
  159876. # define PNGAPI
  159877. #endif
  159878. #ifndef PNG_IMPEXP
  159879. # define PNG_IMPEXP
  159880. #endif
  159881. #ifdef PNG_BUILDSYMS
  159882. # ifndef PNG_EXPORT
  159883. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  159884. # endif
  159885. # ifdef PNG_USE_GLOBAL_ARRAYS
  159886. # ifndef PNG_EXPORT_VAR
  159887. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  159888. # endif
  159889. # endif
  159890. #endif
  159891. #ifndef PNG_EXPORT
  159892. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159893. #endif
  159894. #ifdef PNG_USE_GLOBAL_ARRAYS
  159895. # ifndef PNG_EXPORT_VAR
  159896. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  159897. # endif
  159898. #endif
  159899. #ifndef PNG_ABORT
  159900. # define PNG_ABORT() abort()
  159901. #endif
  159902. #ifdef PNG_SETJMP_SUPPORTED
  159903. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  159904. #else
  159905. # define png_jmpbuf(png_ptr) \
  159906. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  159907. #endif
  159908. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  159909. # define CHECK 1
  159910. # define NOCHECK 0
  159911. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  159912. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  159913. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  159914. # define png_strcpy _fstrcpy
  159915. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  159916. # define png_strlen _fstrlen
  159917. # define png_memcmp _fmemcmp /* SJT: added */
  159918. # define png_memcpy _fmemcpy
  159919. # define png_memset _fmemset
  159920. #else /* use the usual functions */
  159921. # define CVT_PTR(ptr) (ptr)
  159922. # define CVT_PTR_NOCHECK(ptr) (ptr)
  159923. # ifndef PNG_NO_SNPRINTF
  159924. # ifdef _MSC_VER
  159925. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  159926. # define png_snprintf2 _snprintf
  159927. # define png_snprintf6 _snprintf
  159928. # else
  159929. # define png_snprintf snprintf /* Added to v 1.2.19 */
  159930. # define png_snprintf2 snprintf
  159931. # define png_snprintf6 snprintf
  159932. # endif
  159933. # else
  159934. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  159935. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  159936. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  159937. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  159938. # endif
  159939. # define png_strcpy strcpy
  159940. # define png_strncpy strncpy /* Added to v 1.2.6 */
  159941. # define png_strlen strlen
  159942. # define png_memcmp memcmp /* SJT: added */
  159943. # define png_memcpy memcpy
  159944. # define png_memset memset
  159945. #endif
  159946. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  159947. # undef PNG_ZBUF_SIZE
  159948. # define PNG_ZBUF_SIZE 65536L
  159949. #endif
  159950. #endif /* PNG_VERSION_INFO_ONLY */
  159951. #endif /* PNGCONF_H */
  159952. /*** End of inlined file: pngconf.h ***/
  159953. #ifdef _MSC_VER
  159954. #pragma warning (disable: 4996 4100)
  159955. #endif
  159956. #if defined(PNG_USER_PRIVATEBUILD)
  159957. # define PNG_LIBPNG_BUILD_TYPE \
  159958. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  159959. #else
  159960. # if defined(PNG_LIBPNG_SPECIALBUILD)
  159961. # define PNG_LIBPNG_BUILD_TYPE \
  159962. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  159963. # else
  159964. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  159965. # endif
  159966. #endif
  159967. #ifndef PNG_VERSION_INFO_ONLY
  159968. #ifdef __cplusplus
  159969. extern "C" {
  159970. #endif /* __cplusplus */
  159971. #ifndef PNG_NO_TYPECAST_NULL
  159972. #define int_p_NULL (int *)NULL
  159973. #define png_bytep_NULL (png_bytep)NULL
  159974. #define png_bytepp_NULL (png_bytepp)NULL
  159975. #define png_doublep_NULL (png_doublep)NULL
  159976. #define png_error_ptr_NULL (png_error_ptr)NULL
  159977. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  159978. #define png_free_ptr_NULL (png_free_ptr)NULL
  159979. #define png_infopp_NULL (png_infopp)NULL
  159980. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  159981. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  159982. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  159983. #define png_structp_NULL (png_structp)NULL
  159984. #define png_uint_16p_NULL (png_uint_16p)NULL
  159985. #define png_voidp_NULL (png_voidp)NULL
  159986. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  159987. #else
  159988. #define int_p_NULL NULL
  159989. #define png_bytep_NULL NULL
  159990. #define png_bytepp_NULL NULL
  159991. #define png_doublep_NULL NULL
  159992. #define png_error_ptr_NULL NULL
  159993. #define png_flush_ptr_NULL NULL
  159994. #define png_free_ptr_NULL NULL
  159995. #define png_infopp_NULL NULL
  159996. #define png_malloc_ptr_NULL NULL
  159997. #define png_read_status_ptr_NULL NULL
  159998. #define png_rw_ptr_NULL NULL
  159999. #define png_structp_NULL NULL
  160000. #define png_uint_16p_NULL NULL
  160001. #define png_voidp_NULL NULL
  160002. #define png_write_status_ptr_NULL NULL
  160003. #endif
  160004. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160005. #ifdef PNG_USE_GLOBAL_ARRAYS
  160006. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160007. #else
  160008. #define png_libpng_ver png_get_header_ver(NULL)
  160009. #endif
  160010. #ifdef PNG_USE_GLOBAL_ARRAYS
  160011. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160012. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160013. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160014. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160015. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160016. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160017. #endif
  160018. #endif /* PNG_NO_EXTERN */
  160019. typedef struct png_color_struct
  160020. {
  160021. png_byte red;
  160022. png_byte green;
  160023. png_byte blue;
  160024. } png_color;
  160025. typedef png_color FAR * png_colorp;
  160026. typedef png_color FAR * FAR * png_colorpp;
  160027. typedef struct png_color_16_struct
  160028. {
  160029. png_byte index; /* used for palette files */
  160030. png_uint_16 red; /* for use in red green blue files */
  160031. png_uint_16 green;
  160032. png_uint_16 blue;
  160033. png_uint_16 gray; /* for use in grayscale files */
  160034. } png_color_16;
  160035. typedef png_color_16 FAR * png_color_16p;
  160036. typedef png_color_16 FAR * FAR * png_color_16pp;
  160037. typedef struct png_color_8_struct
  160038. {
  160039. png_byte red; /* for use in red green blue files */
  160040. png_byte green;
  160041. png_byte blue;
  160042. png_byte gray; /* for use in grayscale files */
  160043. png_byte alpha; /* for alpha channel files */
  160044. } png_color_8;
  160045. typedef png_color_8 FAR * png_color_8p;
  160046. typedef png_color_8 FAR * FAR * png_color_8pp;
  160047. typedef struct png_sPLT_entry_struct
  160048. {
  160049. png_uint_16 red;
  160050. png_uint_16 green;
  160051. png_uint_16 blue;
  160052. png_uint_16 alpha;
  160053. png_uint_16 frequency;
  160054. } png_sPLT_entry;
  160055. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160056. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160057. typedef struct png_sPLT_struct
  160058. {
  160059. png_charp name; /* palette name */
  160060. png_byte depth; /* depth of palette samples */
  160061. png_sPLT_entryp entries; /* palette entries */
  160062. png_int_32 nentries; /* number of palette entries */
  160063. } png_sPLT_t;
  160064. typedef png_sPLT_t FAR * png_sPLT_tp;
  160065. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160066. #ifdef PNG_TEXT_SUPPORTED
  160067. typedef struct png_text_struct
  160068. {
  160069. int compression; /* compression value:
  160070. -1: tEXt, none
  160071. 0: zTXt, deflate
  160072. 1: iTXt, none
  160073. 2: iTXt, deflate */
  160074. png_charp key; /* keyword, 1-79 character description of "text" */
  160075. png_charp text; /* comment, may be an empty string (ie "")
  160076. or a NULL pointer */
  160077. png_size_t text_length; /* length of the text string */
  160078. #ifdef PNG_iTXt_SUPPORTED
  160079. png_size_t itxt_length; /* length of the itxt string */
  160080. png_charp lang; /* language code, 0-79 characters
  160081. or a NULL pointer */
  160082. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160083. chars or a NULL pointer */
  160084. #endif
  160085. } png_text;
  160086. typedef png_text FAR * png_textp;
  160087. typedef png_text FAR * FAR * png_textpp;
  160088. #endif
  160089. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160090. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160091. #define PNG_TEXT_COMPRESSION_NONE -1
  160092. #define PNG_TEXT_COMPRESSION_zTXt 0
  160093. #define PNG_ITXT_COMPRESSION_NONE 1
  160094. #define PNG_ITXT_COMPRESSION_zTXt 2
  160095. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160096. typedef struct png_time_struct
  160097. {
  160098. png_uint_16 year; /* full year, as in, 1995 */
  160099. png_byte month; /* month of year, 1 - 12 */
  160100. png_byte day; /* day of month, 1 - 31 */
  160101. png_byte hour; /* hour of day, 0 - 23 */
  160102. png_byte minute; /* minute of hour, 0 - 59 */
  160103. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160104. } png_time;
  160105. typedef png_time FAR * png_timep;
  160106. typedef png_time FAR * FAR * png_timepp;
  160107. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160108. typedef struct png_unknown_chunk_t
  160109. {
  160110. png_byte name[5];
  160111. png_byte *data;
  160112. png_size_t size;
  160113. png_byte location; /* mode of operation at read time */
  160114. }
  160115. png_unknown_chunk;
  160116. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160117. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160118. #endif
  160119. typedef struct png_info_struct
  160120. {
  160121. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160122. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160123. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160124. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160125. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160126. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160127. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160128. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160129. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160130. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160131. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160132. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160133. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160134. png_byte pixel_depth; /* number of bits per pixel */
  160135. png_byte spare_byte; /* to align the data, and for future use */
  160136. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160137. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160138. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160139. #endif
  160140. #if defined(PNG_sRGB_SUPPORTED)
  160141. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160142. #endif
  160143. #if defined(PNG_TEXT_SUPPORTED)
  160144. int num_text; /* number of comments read/to write */
  160145. int max_text; /* current size of text array */
  160146. png_textp text; /* array of comments read/to write */
  160147. #endif /* PNG_TEXT_SUPPORTED */
  160148. #if defined(PNG_tIME_SUPPORTED)
  160149. png_time mod_time;
  160150. #endif
  160151. #if defined(PNG_sBIT_SUPPORTED)
  160152. png_color_8 sig_bit; /* significant bits in color channels */
  160153. #endif
  160154. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160155. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160156. png_bytep trans; /* transparent values for paletted image */
  160157. png_color_16 trans_values; /* transparent color for non-palette image */
  160158. #endif
  160159. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160160. png_color_16 background;
  160161. #endif
  160162. #if defined(PNG_oFFs_SUPPORTED)
  160163. png_int_32 x_offset; /* x offset on page */
  160164. png_int_32 y_offset; /* y offset on page */
  160165. png_byte offset_unit_type; /* offset units type */
  160166. #endif
  160167. #if defined(PNG_pHYs_SUPPORTED)
  160168. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160169. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160170. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160171. #endif
  160172. #if defined(PNG_hIST_SUPPORTED)
  160173. png_uint_16p hist;
  160174. #endif
  160175. #ifdef PNG_cHRM_SUPPORTED
  160176. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160177. float x_white;
  160178. float y_white;
  160179. float x_red;
  160180. float y_red;
  160181. float x_green;
  160182. float y_green;
  160183. float x_blue;
  160184. float y_blue;
  160185. #endif
  160186. #endif
  160187. #if defined(PNG_pCAL_SUPPORTED)
  160188. png_charp pcal_purpose; /* pCAL chunk description string */
  160189. png_int_32 pcal_X0; /* minimum value */
  160190. png_int_32 pcal_X1; /* maximum value */
  160191. png_charp pcal_units; /* Latin-1 string giving physical units */
  160192. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160193. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160194. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160195. #endif
  160196. #ifdef PNG_FREE_ME_SUPPORTED
  160197. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160198. #endif
  160199. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160200. png_unknown_chunkp unknown_chunks;
  160201. png_size_t unknown_chunks_num;
  160202. #endif
  160203. #if defined(PNG_iCCP_SUPPORTED)
  160204. png_charp iccp_name; /* profile name */
  160205. png_charp iccp_profile; /* International Color Consortium profile data */
  160206. png_uint_32 iccp_proflen; /* ICC profile data length */
  160207. png_byte iccp_compression; /* Always zero */
  160208. #endif
  160209. #if defined(PNG_sPLT_SUPPORTED)
  160210. png_sPLT_tp splt_palettes;
  160211. png_uint_32 splt_palettes_num;
  160212. #endif
  160213. #if defined(PNG_sCAL_SUPPORTED)
  160214. png_byte scal_unit; /* unit of physical scale */
  160215. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160216. double scal_pixel_width; /* width of one pixel */
  160217. double scal_pixel_height; /* height of one pixel */
  160218. #endif
  160219. #ifdef PNG_FIXED_POINT_SUPPORTED
  160220. png_charp scal_s_width; /* string containing height */
  160221. png_charp scal_s_height; /* string containing width */
  160222. #endif
  160223. #endif
  160224. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160225. png_bytepp row_pointers; /* the image bits */
  160226. #endif
  160227. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160228. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160229. #endif
  160230. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160231. png_fixed_point int_x_white;
  160232. png_fixed_point int_y_white;
  160233. png_fixed_point int_x_red;
  160234. png_fixed_point int_y_red;
  160235. png_fixed_point int_x_green;
  160236. png_fixed_point int_y_green;
  160237. png_fixed_point int_x_blue;
  160238. png_fixed_point int_y_blue;
  160239. #endif
  160240. } png_info;
  160241. typedef png_info FAR * png_infop;
  160242. typedef png_info FAR * FAR * png_infopp;
  160243. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160244. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160245. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160246. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160247. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160248. #endif
  160249. #define PNG_COLOR_MASK_PALETTE 1
  160250. #define PNG_COLOR_MASK_COLOR 2
  160251. #define PNG_COLOR_MASK_ALPHA 4
  160252. #define PNG_COLOR_TYPE_GRAY 0
  160253. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160254. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160255. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160256. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160257. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160258. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160259. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160260. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160261. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160262. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160263. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160264. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160265. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160266. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160267. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160268. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160269. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160270. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160271. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160272. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160273. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160274. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160275. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160276. #define PNG_SCALE_METER 1 /* meters per pixel */
  160277. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160278. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160279. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160280. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160281. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160282. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160283. #define PNG_sRGB_INTENT_RELATIVE 1
  160284. #define PNG_sRGB_INTENT_SATURATION 2
  160285. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160286. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160287. #define PNG_KEYWORD_MAX_LENGTH 79
  160288. #define PNG_MAX_PALETTE_LENGTH 256
  160289. #define PNG_INFO_gAMA 0x0001
  160290. #define PNG_INFO_sBIT 0x0002
  160291. #define PNG_INFO_cHRM 0x0004
  160292. #define PNG_INFO_PLTE 0x0008
  160293. #define PNG_INFO_tRNS 0x0010
  160294. #define PNG_INFO_bKGD 0x0020
  160295. #define PNG_INFO_hIST 0x0040
  160296. #define PNG_INFO_pHYs 0x0080
  160297. #define PNG_INFO_oFFs 0x0100
  160298. #define PNG_INFO_tIME 0x0200
  160299. #define PNG_INFO_pCAL 0x0400
  160300. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160301. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160302. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160303. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160304. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160305. typedef struct png_row_info_struct
  160306. {
  160307. png_uint_32 width; /* width of row */
  160308. png_uint_32 rowbytes; /* number of bytes in row */
  160309. png_byte color_type; /* color type of row */
  160310. png_byte bit_depth; /* bit depth of row */
  160311. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160312. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160313. } png_row_info;
  160314. typedef png_row_info FAR * png_row_infop;
  160315. typedef png_row_info FAR * FAR * png_row_infopp;
  160316. typedef struct png_struct_def png_struct;
  160317. typedef png_struct FAR * png_structp;
  160318. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160319. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160320. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160321. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160322. int));
  160323. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160324. int));
  160325. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160326. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160327. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160328. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160329. png_uint_32, int));
  160330. #endif
  160331. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160332. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160333. defined(PNG_LEGACY_SUPPORTED)
  160334. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160335. png_row_infop, png_bytep));
  160336. #endif
  160337. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160338. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160339. #endif
  160340. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160341. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160342. #endif
  160343. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160344. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160345. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160346. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160347. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160348. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160349. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160350. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160351. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160352. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160353. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160354. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160355. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160356. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160357. #define PNG_FLAG_MNG_FILTER_64 0x04
  160358. #define PNG_ALL_MNG_FEATURES 0x05
  160359. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160360. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160361. struct png_struct_def
  160362. {
  160363. #ifdef PNG_SETJMP_SUPPORTED
  160364. jmp_buf jmpbuf; /* used in png_error */
  160365. #endif
  160366. png_error_ptr error_fn; /* function for printing errors and aborting */
  160367. png_error_ptr warning_fn; /* function for printing warnings */
  160368. png_voidp error_ptr; /* user supplied struct for error functions */
  160369. png_rw_ptr write_data_fn; /* function for writing output data */
  160370. png_rw_ptr read_data_fn; /* function for reading input data */
  160371. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160372. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160373. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160374. #endif
  160375. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160376. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160377. #endif
  160378. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160379. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160380. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160381. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160382. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160383. png_byte user_transform_channels; /* channels in user transformed pixels */
  160384. #endif
  160385. #endif
  160386. png_uint_32 mode; /* tells us where we are in the PNG file */
  160387. png_uint_32 flags; /* flags indicating various things to libpng */
  160388. png_uint_32 transformations; /* which transformations to perform */
  160389. z_stream zstream; /* pointer to decompression structure (below) */
  160390. png_bytep zbuf; /* buffer for zlib */
  160391. png_size_t zbuf_size; /* size of zbuf */
  160392. int zlib_level; /* holds zlib compression level */
  160393. int zlib_method; /* holds zlib compression method */
  160394. int zlib_window_bits; /* holds zlib compression window bits */
  160395. int zlib_mem_level; /* holds zlib compression memory level */
  160396. int zlib_strategy; /* holds zlib compression strategy */
  160397. png_uint_32 width; /* width of image in pixels */
  160398. png_uint_32 height; /* height of image in pixels */
  160399. png_uint_32 num_rows; /* number of rows in current pass */
  160400. png_uint_32 usr_width; /* width of row at start of write */
  160401. png_uint_32 rowbytes; /* size of row in bytes */
  160402. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160403. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160404. png_uint_32 row_number; /* current row in interlace pass */
  160405. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160406. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160407. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160408. png_bytep up_row; /* buffer to save "up" row when filtering */
  160409. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160410. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160411. png_row_info row_info; /* used for transformation routines */
  160412. png_uint_32 idat_size; /* current IDAT size for read */
  160413. png_uint_32 crc; /* current chunk CRC value */
  160414. png_colorp palette; /* palette from the input file */
  160415. png_uint_16 num_palette; /* number of color entries in palette */
  160416. png_uint_16 num_trans; /* number of transparency values */
  160417. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160418. png_byte compression; /* file compression type (always 0) */
  160419. png_byte filter; /* file filter type (always 0) */
  160420. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160421. png_byte pass; /* current interlace pass (0 - 6) */
  160422. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160423. png_byte color_type; /* color type of file */
  160424. png_byte bit_depth; /* bit depth of file */
  160425. png_byte usr_bit_depth; /* bit depth of users row */
  160426. png_byte pixel_depth; /* number of bits per pixel */
  160427. png_byte channels; /* number of channels in file */
  160428. png_byte usr_channels; /* channels at start of write */
  160429. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160430. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160431. #ifdef PNG_LEGACY_SUPPORTED
  160432. png_byte filler; /* filler byte for pixel expansion */
  160433. #else
  160434. png_uint_16 filler; /* filler bytes for pixel expansion */
  160435. #endif
  160436. #endif
  160437. #if defined(PNG_bKGD_SUPPORTED)
  160438. png_byte background_gamma_type;
  160439. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160440. float background_gamma;
  160441. # endif
  160442. png_color_16 background; /* background color in screen gamma space */
  160443. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160444. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160445. #endif
  160446. #endif /* PNG_bKGD_SUPPORTED */
  160447. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160448. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160449. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160450. png_uint_32 flush_rows; /* number of rows written since last flush */
  160451. #endif
  160452. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160453. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160454. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160455. float gamma; /* file gamma value */
  160456. float screen_gamma; /* screen gamma value (display_exponent) */
  160457. #endif
  160458. #endif
  160459. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160460. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160461. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160462. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160463. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160464. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160465. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160466. #endif
  160467. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160468. png_color_8 sig_bit; /* significant bits in each available channel */
  160469. #endif
  160470. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160471. png_color_8 shift; /* shift for significant bit tranformation */
  160472. #endif
  160473. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160474. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160475. png_bytep trans; /* transparency values for paletted files */
  160476. png_color_16 trans_values; /* transparency values for non-paletted files */
  160477. #endif
  160478. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160479. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160480. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160481. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160482. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160483. png_progressive_end_ptr end_fn; /* called after image is complete */
  160484. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160485. png_bytep save_buffer; /* buffer for previously read data */
  160486. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160487. png_bytep current_buffer; /* buffer for recently used data */
  160488. png_uint_32 push_length; /* size of current input chunk */
  160489. png_uint_32 skip_length; /* bytes to skip in input data */
  160490. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160491. png_size_t save_buffer_max; /* total size of save_buffer */
  160492. png_size_t buffer_size; /* total amount of available input data */
  160493. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160494. int process_mode; /* what push library is currently doing */
  160495. int cur_palette; /* current push library palette index */
  160496. # if defined(PNG_TEXT_SUPPORTED)
  160497. png_size_t current_text_size; /* current size of text input data */
  160498. png_size_t current_text_left; /* how much text left to read in input */
  160499. png_charp current_text; /* current text chunk buffer */
  160500. png_charp current_text_ptr; /* current location in current_text */
  160501. # endif /* PNG_TEXT_SUPPORTED */
  160502. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160503. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160504. png_bytepp offset_table_ptr;
  160505. png_bytep offset_table;
  160506. png_uint_16 offset_table_number;
  160507. png_uint_16 offset_table_count;
  160508. png_uint_16 offset_table_count_free;
  160509. #endif
  160510. #if defined(PNG_READ_DITHER_SUPPORTED)
  160511. png_bytep palette_lookup; /* lookup table for dithering */
  160512. png_bytep dither_index; /* index translation for palette files */
  160513. #endif
  160514. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160515. png_uint_16p hist; /* histogram */
  160516. #endif
  160517. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160518. png_byte heuristic_method; /* heuristic for row filter selection */
  160519. png_byte num_prev_filters; /* number of weights for previous rows */
  160520. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160521. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160522. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160523. png_uint_16p filter_costs; /* relative filter calculation cost */
  160524. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160525. #endif
  160526. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160527. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160528. #endif
  160529. #ifdef PNG_FREE_ME_SUPPORTED
  160530. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160531. #endif
  160532. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160533. png_voidp user_chunk_ptr;
  160534. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160535. #endif
  160536. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160537. int num_chunk_list;
  160538. png_bytep chunk_list;
  160539. #endif
  160540. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160541. png_byte rgb_to_gray_status;
  160542. png_uint_16 rgb_to_gray_red_coeff;
  160543. png_uint_16 rgb_to_gray_green_coeff;
  160544. png_uint_16 rgb_to_gray_blue_coeff;
  160545. #endif
  160546. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160547. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160548. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160549. #ifdef PNG_1_0_X
  160550. png_byte mng_features_permitted;
  160551. #else
  160552. png_uint_32 mng_features_permitted;
  160553. #endif /* PNG_1_0_X */
  160554. #endif
  160555. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160556. png_fixed_point int_gamma;
  160557. #endif
  160558. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160559. png_byte filter_type;
  160560. #endif
  160561. #if defined(PNG_1_0_X)
  160562. png_uint_32 row_buf_size;
  160563. #endif
  160564. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160565. # if !defined(PNG_1_0_X)
  160566. # if defined(PNG_MMX_CODE_SUPPORTED)
  160567. png_byte mmx_bitdepth_threshold;
  160568. png_uint_32 mmx_rowbytes_threshold;
  160569. # endif
  160570. png_uint_32 asm_flags;
  160571. # endif
  160572. #endif
  160573. #ifdef PNG_USER_MEM_SUPPORTED
  160574. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160575. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160576. png_free_ptr free_fn; /* function for freeing memory */
  160577. #endif
  160578. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160579. #if defined(PNG_READ_DITHER_SUPPORTED)
  160580. png_bytep dither_sort; /* working sort array */
  160581. png_bytep index_to_palette; /* where the original index currently is */
  160582. png_bytep palette_to_index; /* which original index points to this */
  160583. #endif
  160584. png_byte compression_type;
  160585. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160586. png_uint_32 user_width_max;
  160587. png_uint_32 user_height_max;
  160588. #endif
  160589. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160590. png_unknown_chunk unknown_chunk;
  160591. #endif
  160592. };
  160593. typedef png_structp version_1_2_21;
  160594. typedef png_struct FAR * FAR * png_structpp;
  160595. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160596. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160597. int num_bytes));
  160598. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160599. png_size_t num_to_check));
  160600. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160601. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160602. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160603. png_error_ptr error_fn, png_error_ptr warn_fn));
  160604. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160605. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160606. png_error_ptr error_fn, png_error_ptr warn_fn));
  160607. #ifdef PNG_WRITE_SUPPORTED
  160608. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160609. PNGARG((png_structp png_ptr));
  160610. #endif
  160611. #ifdef PNG_WRITE_SUPPORTED
  160612. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160613. PNGARG((png_structp png_ptr, png_uint_32 size));
  160614. #endif
  160615. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160616. #ifdef PNG_USER_MEM_SUPPORTED
  160617. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160618. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160619. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160620. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160621. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160622. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160623. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160624. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160625. #endif
  160626. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160627. png_bytep chunk_name, png_bytep data, png_size_t length));
  160628. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160629. png_bytep chunk_name, png_uint_32 length));
  160630. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160631. png_bytep data, png_size_t length));
  160632. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160633. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160634. PNGARG((png_structp png_ptr));
  160635. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160636. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160637. #undef png_info_init
  160638. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160639. png_sizeof(png_info));
  160640. #endif
  160641. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160642. png_size_t png_info_struct_size));
  160643. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160644. png_infop info_ptr));
  160645. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160646. png_infop info_ptr));
  160647. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160648. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160649. png_infop info_ptr));
  160650. #endif
  160651. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160652. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160653. PNGARG((png_structp png_ptr, png_timep ptime));
  160654. #endif
  160655. #if !defined(_WIN32_WCE)
  160656. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160657. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160658. struct tm FAR * ttime));
  160659. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160660. time_t ttime));
  160661. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160662. #endif /* _WIN32_WCE */
  160663. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160664. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160665. #if !defined(PNG_1_0_X)
  160666. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160667. png_ptr));
  160668. #endif
  160669. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160670. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160671. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160672. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160673. #endif
  160674. #endif
  160675. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160676. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160677. #endif
  160678. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160679. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160680. #endif
  160681. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160682. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160683. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160684. int error_action, double red, double green ));
  160685. #endif
  160686. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160687. int error_action, png_fixed_point red, png_fixed_point green ));
  160688. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160689. png_ptr));
  160690. #endif
  160691. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160692. png_colorp palette));
  160693. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160694. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160695. #endif
  160696. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160697. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160698. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160699. #endif
  160700. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160701. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160702. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160703. #endif
  160704. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160705. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160706. png_uint_32 filler, int flags));
  160707. #define PNG_FILLER_BEFORE 0
  160708. #define PNG_FILLER_AFTER 1
  160709. #if !defined(PNG_1_0_X)
  160710. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160711. png_uint_32 filler, int flags));
  160712. #endif
  160713. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160714. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160715. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160716. #endif
  160717. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160718. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160719. #endif
  160720. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160721. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160722. #endif
  160723. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160724. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160725. png_color_8p true_bits));
  160726. #endif
  160727. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160728. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160729. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160730. #endif
  160731. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160732. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160733. #endif
  160734. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160735. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160736. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160737. png_color_16p background_color, int background_gamma_code,
  160738. int need_expand, double background_gamma));
  160739. #endif
  160740. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160741. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160742. #define PNG_BACKGROUND_GAMMA_FILE 2
  160743. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160744. #endif
  160745. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160746. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160747. #endif
  160748. #if defined(PNG_READ_DITHER_SUPPORTED)
  160749. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160750. png_colorp palette, int num_palette, int maximum_colors,
  160751. png_uint_16p histogram, int full_dither));
  160752. #endif
  160753. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160754. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160755. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160756. double screen_gamma, double default_file_gamma));
  160757. #endif
  160758. #endif
  160759. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160760. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160761. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160762. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160763. int empty_plte_permitted));
  160764. #endif
  160765. #endif
  160766. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160767. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160768. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160769. #endif
  160770. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160771. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160772. png_infop info_ptr));
  160773. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160774. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160775. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160776. #endif
  160777. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160778. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160779. png_bytep row,
  160780. png_bytep display_row));
  160781. #endif
  160782. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160783. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160784. png_bytepp image));
  160785. #endif
  160786. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160787. png_bytep row));
  160788. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160789. png_bytepp row, png_uint_32 num_rows));
  160790. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160791. png_bytepp image));
  160792. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160793. png_infop info_ptr));
  160794. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160795. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160796. png_infop info_ptr));
  160797. #endif
  160798. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160799. png_infopp info_ptr_ptr));
  160800. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160801. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160802. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160803. png_infop end_info_ptr));
  160804. extern PNG_EXPORT(void,png_destroy_write_struct)
  160805. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160806. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160807. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160808. int crit_action, int ancil_action));
  160809. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160810. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160811. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160812. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  160813. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  160814. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  160815. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  160816. int filters));
  160817. #define PNG_NO_FILTERS 0x00
  160818. #define PNG_FILTER_NONE 0x08
  160819. #define PNG_FILTER_SUB 0x10
  160820. #define PNG_FILTER_UP 0x20
  160821. #define PNG_FILTER_AVG 0x40
  160822. #define PNG_FILTER_PAETH 0x80
  160823. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  160824. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  160825. #define PNG_FILTER_VALUE_NONE 0
  160826. #define PNG_FILTER_VALUE_SUB 1
  160827. #define PNG_FILTER_VALUE_UP 2
  160828. #define PNG_FILTER_VALUE_AVG 3
  160829. #define PNG_FILTER_VALUE_PAETH 4
  160830. #define PNG_FILTER_VALUE_LAST 5
  160831. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  160832. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160833. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  160834. int heuristic_method, int num_weights, png_doublep filter_weights,
  160835. png_doublep filter_costs));
  160836. #endif
  160837. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  160838. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  160839. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  160840. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  160841. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  160842. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  160843. int level));
  160844. extern PNG_EXPORT(void,png_set_compression_mem_level)
  160845. PNGARG((png_structp png_ptr, int mem_level));
  160846. extern PNG_EXPORT(void,png_set_compression_strategy)
  160847. PNGARG((png_structp png_ptr, int strategy));
  160848. extern PNG_EXPORT(void,png_set_compression_window_bits)
  160849. PNGARG((png_structp png_ptr, int window_bits));
  160850. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  160851. int method));
  160852. #if !defined(PNG_NO_STDIO)
  160853. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  160854. #endif
  160855. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  160856. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  160857. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  160858. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  160859. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  160860. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  160861. png_voidp io_ptr, png_rw_ptr read_data_fn));
  160862. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  160863. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  160864. png_read_status_ptr read_row_fn));
  160865. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  160866. png_write_status_ptr write_row_fn));
  160867. #ifdef PNG_USER_MEM_SUPPORTED
  160868. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  160869. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160870. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  160871. #endif
  160872. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160873. defined(PNG_LEGACY_SUPPORTED)
  160874. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  160875. png_ptr, png_user_transform_ptr read_user_transform_fn));
  160876. #endif
  160877. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160878. defined(PNG_LEGACY_SUPPORTED)
  160879. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  160880. png_ptr, png_user_transform_ptr write_user_transform_fn));
  160881. #endif
  160882. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160883. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160884. defined(PNG_LEGACY_SUPPORTED)
  160885. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  160886. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  160887. int user_transform_channels));
  160888. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  160889. PNGARG((png_structp png_ptr));
  160890. #endif
  160891. #ifdef PNG_USER_CHUNKS_SUPPORTED
  160892. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  160893. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  160894. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  160895. png_ptr));
  160896. #endif
  160897. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160898. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  160899. png_voidp progressive_ptr,
  160900. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  160901. png_progressive_end_ptr end_fn));
  160902. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  160903. PNGARG((png_structp png_ptr));
  160904. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  160905. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  160906. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  160907. png_bytep old_row, png_bytep new_row));
  160908. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160909. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  160910. png_uint_32 size));
  160911. #if defined(PNG_1_0_X)
  160912. # define png_malloc_warn png_malloc
  160913. #else
  160914. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  160915. png_uint_32 size));
  160916. #endif
  160917. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  160918. #if defined(PNG_1_0_X)
  160919. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  160920. uInt size));
  160921. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  160922. #endif
  160923. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  160924. png_infop info_ptr, png_uint_32 free_me, int num));
  160925. #ifdef PNG_FREE_ME_SUPPORTED
  160926. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  160927. png_infop info_ptr, int freer, png_uint_32 mask));
  160928. #endif
  160929. #define PNG_DESTROY_WILL_FREE_DATA 1
  160930. #define PNG_SET_WILL_FREE_DATA 1
  160931. #define PNG_USER_WILL_FREE_DATA 2
  160932. #define PNG_FREE_HIST 0x0008
  160933. #define PNG_FREE_ICCP 0x0010
  160934. #define PNG_FREE_SPLT 0x0020
  160935. #define PNG_FREE_ROWS 0x0040
  160936. #define PNG_FREE_PCAL 0x0080
  160937. #define PNG_FREE_SCAL 0x0100
  160938. #define PNG_FREE_UNKN 0x0200
  160939. #define PNG_FREE_LIST 0x0400
  160940. #define PNG_FREE_PLTE 0x1000
  160941. #define PNG_FREE_TRNS 0x2000
  160942. #define PNG_FREE_TEXT 0x4000
  160943. #define PNG_FREE_ALL 0x7fff
  160944. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  160945. #ifdef PNG_USER_MEM_SUPPORTED
  160946. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  160947. png_uint_32 size));
  160948. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  160949. png_voidp ptr));
  160950. #endif
  160951. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  160952. png_voidp s1, png_voidp s2, png_uint_32 size));
  160953. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  160954. png_voidp s1, int value, png_uint_32 size));
  160955. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  160956. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  160957. int check));
  160958. #endif /* USE_FAR_KEYWORD */
  160959. #ifndef PNG_NO_ERROR_TEXT
  160960. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  160961. png_const_charp error_message));
  160962. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  160963. png_const_charp error_message));
  160964. #else
  160965. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  160966. #endif
  160967. #ifndef PNG_NO_WARNINGS
  160968. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  160969. png_const_charp warning_message));
  160970. #ifdef PNG_READ_SUPPORTED
  160971. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  160972. png_const_charp warning_message));
  160973. #endif /* PNG_READ_SUPPORTED */
  160974. #endif /* PNG_NO_WARNINGS */
  160975. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  160976. png_infop info_ptr, png_uint_32 flag));
  160977. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  160978. png_infop info_ptr));
  160979. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160980. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  160981. png_infop info_ptr));
  160982. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  160983. png_infop info_ptr, png_bytepp row_pointers));
  160984. #endif
  160985. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  160986. png_infop info_ptr));
  160987. #ifdef PNG_EASY_ACCESS_SUPPORTED
  160988. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  160989. png_ptr, png_infop info_ptr));
  160990. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  160991. png_ptr, png_infop info_ptr));
  160992. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  160993. png_ptr, png_infop info_ptr));
  160994. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  160995. png_ptr, png_infop info_ptr));
  160996. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  160997. png_ptr, png_infop info_ptr));
  160998. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  160999. png_ptr, png_infop info_ptr));
  161000. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161001. png_ptr, png_infop info_ptr));
  161002. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161003. png_ptr, png_infop info_ptr));
  161004. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161005. png_ptr, png_infop info_ptr));
  161006. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161007. png_ptr, png_infop info_ptr));
  161008. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161009. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161010. png_ptr, png_infop info_ptr));
  161011. #endif
  161012. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161013. png_ptr, png_infop info_ptr));
  161014. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161015. png_ptr, png_infop info_ptr));
  161016. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161017. png_ptr, png_infop info_ptr));
  161018. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161019. png_ptr, png_infop info_ptr));
  161020. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161021. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161022. png_infop info_ptr));
  161023. #if defined(PNG_bKGD_SUPPORTED)
  161024. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161025. png_infop info_ptr, png_color_16p *background));
  161026. #endif
  161027. #if defined(PNG_bKGD_SUPPORTED)
  161028. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161029. png_infop info_ptr, png_color_16p background));
  161030. #endif
  161031. #if defined(PNG_cHRM_SUPPORTED)
  161032. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161033. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161034. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161035. double *red_y, double *green_x, double *green_y, double *blue_x,
  161036. double *blue_y));
  161037. #endif
  161038. #ifdef PNG_FIXED_POINT_SUPPORTED
  161039. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161040. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161041. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161042. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161043. *int_blue_x, png_fixed_point *int_blue_y));
  161044. #endif
  161045. #endif
  161046. #if defined(PNG_cHRM_SUPPORTED)
  161047. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161048. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161049. png_infop info_ptr, double white_x, double white_y, double red_x,
  161050. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161051. #endif
  161052. #ifdef PNG_FIXED_POINT_SUPPORTED
  161053. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161054. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161055. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161056. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161057. png_fixed_point int_blue_y));
  161058. #endif
  161059. #endif
  161060. #if defined(PNG_gAMA_SUPPORTED)
  161061. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161062. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161063. png_infop info_ptr, double *file_gamma));
  161064. #endif
  161065. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161066. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161067. #endif
  161068. #if defined(PNG_gAMA_SUPPORTED)
  161069. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161070. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161071. png_infop info_ptr, double file_gamma));
  161072. #endif
  161073. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161074. png_infop info_ptr, png_fixed_point int_file_gamma));
  161075. #endif
  161076. #if defined(PNG_hIST_SUPPORTED)
  161077. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161078. png_infop info_ptr, png_uint_16p *hist));
  161079. #endif
  161080. #if defined(PNG_hIST_SUPPORTED)
  161081. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161082. png_infop info_ptr, png_uint_16p hist));
  161083. #endif
  161084. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161085. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161086. int *bit_depth, int *color_type, int *interlace_method,
  161087. int *compression_method, int *filter_method));
  161088. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161089. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161090. int color_type, int interlace_method, int compression_method,
  161091. int filter_method));
  161092. #if defined(PNG_oFFs_SUPPORTED)
  161093. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161094. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161095. int *unit_type));
  161096. #endif
  161097. #if defined(PNG_oFFs_SUPPORTED)
  161098. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161099. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161100. int unit_type));
  161101. #endif
  161102. #if defined(PNG_pCAL_SUPPORTED)
  161103. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161104. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161105. int *type, int *nparams, png_charp *units, png_charpp *params));
  161106. #endif
  161107. #if defined(PNG_pCAL_SUPPORTED)
  161108. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161109. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161110. int type, int nparams, png_charp units, png_charpp params));
  161111. #endif
  161112. #if defined(PNG_pHYs_SUPPORTED)
  161113. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161114. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161115. #endif
  161116. #if defined(PNG_pHYs_SUPPORTED)
  161117. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161118. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161119. #endif
  161120. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161121. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161122. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161123. png_infop info_ptr, png_colorp palette, int num_palette));
  161124. #if defined(PNG_sBIT_SUPPORTED)
  161125. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161126. png_infop info_ptr, png_color_8p *sig_bit));
  161127. #endif
  161128. #if defined(PNG_sBIT_SUPPORTED)
  161129. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161130. png_infop info_ptr, png_color_8p sig_bit));
  161131. #endif
  161132. #if defined(PNG_sRGB_SUPPORTED)
  161133. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161134. png_infop info_ptr, int *intent));
  161135. #endif
  161136. #if defined(PNG_sRGB_SUPPORTED)
  161137. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161138. png_infop info_ptr, int intent));
  161139. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161140. png_infop info_ptr, int intent));
  161141. #endif
  161142. #if defined(PNG_iCCP_SUPPORTED)
  161143. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161144. png_infop info_ptr, png_charpp name, int *compression_type,
  161145. png_charpp profile, png_uint_32 *proflen));
  161146. #endif
  161147. #if defined(PNG_iCCP_SUPPORTED)
  161148. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161149. png_infop info_ptr, png_charp name, int compression_type,
  161150. png_charp profile, png_uint_32 proflen));
  161151. #endif
  161152. #if defined(PNG_sPLT_SUPPORTED)
  161153. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161154. png_infop info_ptr, png_sPLT_tpp entries));
  161155. #endif
  161156. #if defined(PNG_sPLT_SUPPORTED)
  161157. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161158. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161159. #endif
  161160. #if defined(PNG_TEXT_SUPPORTED)
  161161. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161162. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161163. #endif
  161164. #if defined(PNG_TEXT_SUPPORTED)
  161165. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161166. png_infop info_ptr, png_textp text_ptr, int num_text));
  161167. #endif
  161168. #if defined(PNG_tIME_SUPPORTED)
  161169. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161170. png_infop info_ptr, png_timep *mod_time));
  161171. #endif
  161172. #if defined(PNG_tIME_SUPPORTED)
  161173. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161174. png_infop info_ptr, png_timep mod_time));
  161175. #endif
  161176. #if defined(PNG_tRNS_SUPPORTED)
  161177. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161178. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161179. png_color_16p *trans_values));
  161180. #endif
  161181. #if defined(PNG_tRNS_SUPPORTED)
  161182. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161183. png_infop info_ptr, png_bytep trans, int num_trans,
  161184. png_color_16p trans_values));
  161185. #endif
  161186. #if defined(PNG_tRNS_SUPPORTED)
  161187. #endif
  161188. #if defined(PNG_sCAL_SUPPORTED)
  161189. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161190. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161191. png_infop info_ptr, int *unit, double *width, double *height));
  161192. #else
  161193. #ifdef PNG_FIXED_POINT_SUPPORTED
  161194. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161195. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161196. #endif
  161197. #endif
  161198. #endif /* PNG_sCAL_SUPPORTED */
  161199. #if defined(PNG_sCAL_SUPPORTED)
  161200. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161201. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161202. png_infop info_ptr, int unit, double width, double height));
  161203. #else
  161204. #ifdef PNG_FIXED_POINT_SUPPORTED
  161205. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161206. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161207. #endif
  161208. #endif
  161209. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161210. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161211. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161212. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161213. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161214. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161215. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161216. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161217. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161218. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161219. #endif
  161220. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161221. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161222. chunk_name));
  161223. #endif
  161224. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161225. png_infop info_ptr, int mask));
  161226. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161227. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161228. png_infop info_ptr,
  161229. int transforms,
  161230. png_voidp params));
  161231. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161232. png_infop info_ptr,
  161233. int transforms,
  161234. png_voidp params));
  161235. #endif
  161236. #ifdef PNG_DEBUG
  161237. #if (PNG_DEBUG > 0)
  161238. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161239. #include <crtdbg.h>
  161240. #if (PNG_DEBUG > 1)
  161241. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161242. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161243. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161244. #endif
  161245. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161246. #ifndef PNG_DEBUG_FILE
  161247. #define PNG_DEBUG_FILE stderr
  161248. #endif /* PNG_DEBUG_FILE */
  161249. #if (PNG_DEBUG > 1)
  161250. #define png_debug(l,m) \
  161251. { \
  161252. int num_tabs=l; \
  161253. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161254. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161255. }
  161256. #define png_debug1(l,m,p1) \
  161257. { \
  161258. int num_tabs=l; \
  161259. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161260. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161261. }
  161262. #define png_debug2(l,m,p1,p2) \
  161263. { \
  161264. int num_tabs=l; \
  161265. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161266. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161267. }
  161268. #endif /* (PNG_DEBUG > 1) */
  161269. #endif /* _MSC_VER */
  161270. #endif /* (PNG_DEBUG > 0) */
  161271. #endif /* PNG_DEBUG */
  161272. #ifndef png_debug
  161273. #define png_debug(l, m)
  161274. #endif
  161275. #ifndef png_debug1
  161276. #define png_debug1(l, m, p1)
  161277. #endif
  161278. #ifndef png_debug2
  161279. #define png_debug2(l, m, p1, p2)
  161280. #endif
  161281. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161282. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161283. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161284. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161285. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161286. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161287. png_ptr, png_uint_32 mng_features_permitted));
  161288. #endif
  161289. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161290. #define PNG_HANDLE_CHUNK_NEVER 1
  161291. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161292. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161293. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161294. #if defined(PNG_MMX_CODE_SUPPORTED)
  161295. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161296. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161297. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161298. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161299. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161300. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161301. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161302. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161303. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161304. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161305. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161306. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161307. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161308. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161309. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161310. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161311. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161312. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161313. | PNG_MMX_READ_FLAGS \
  161314. | PNG_MMX_WRITE_FLAGS )
  161315. #define PNG_SELECT_READ 1
  161316. #define PNG_SELECT_WRITE 2
  161317. #endif /* PNG_MMX_CODE_SUPPORTED */
  161318. #if !defined(PNG_1_0_X)
  161319. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161320. PNGARG((int flag_select, int *compilerID));
  161321. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161322. PNGARG((int flag_select));
  161323. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161324. PNGARG((png_structp png_ptr));
  161325. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161326. PNGARG((png_structp png_ptr));
  161327. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161328. PNGARG((png_structp png_ptr));
  161329. extern PNG_EXPORT(void,png_set_asm_flags)
  161330. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161331. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161332. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161333. png_uint_32 mmx_rowbytes_threshold));
  161334. #endif /* PNG_1_0_X */
  161335. #if !defined(PNG_1_0_X)
  161336. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161337. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161338. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161339. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161340. png_ptr, png_uint_32 strip_mode));
  161341. #endif
  161342. #endif /* PNG_1_0_X */
  161343. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161344. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161345. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161346. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161347. png_ptr));
  161348. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161349. png_ptr));
  161350. #endif
  161351. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161352. # define png_composite(composite, fg, alpha, bg) \
  161353. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161354. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161355. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161356. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161357. # define png_composite_16(composite, fg, alpha, bg) \
  161358. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161359. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161360. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161361. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161362. #else /* standard method using integer division */
  161363. # define png_composite(composite, fg, alpha, bg) \
  161364. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161365. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161366. (png_uint_16)127) / 255)
  161367. # define png_composite_16(composite, fg, alpha, bg) \
  161368. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161369. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161370. (png_uint_32)32767) / (png_uint_32)65535L)
  161371. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161372. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161373. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161374. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161375. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161376. #else
  161377. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161378. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161379. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161380. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161381. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161382. PNGARG((png_structp png_ptr, png_bytep buf));
  161383. extern PNG_EXPORT(void,png_save_uint_32)
  161384. PNGARG((png_bytep buf, png_uint_32 i));
  161385. extern PNG_EXPORT(void,png_save_int_32)
  161386. PNGARG((png_bytep buf, png_int_32 i));
  161387. extern PNG_EXPORT(void,png_save_uint_16)
  161388. PNGARG((png_bytep buf, unsigned int i));
  161389. #define PNG_HAVE_IHDR 0x01
  161390. #define PNG_HAVE_PLTE 0x02
  161391. #define PNG_HAVE_IDAT 0x04
  161392. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161393. #define PNG_HAVE_IEND 0x10
  161394. #if defined(PNG_INTERNAL)
  161395. #define PNG_HAVE_gAMA 0x20
  161396. #define PNG_HAVE_cHRM 0x40
  161397. #define PNG_HAVE_sRGB 0x80
  161398. #define PNG_HAVE_CHUNK_HEADER 0x100
  161399. #define PNG_WROTE_tIME 0x200
  161400. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161401. #define PNG_BACKGROUND_IS_GRAY 0x800
  161402. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161403. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161404. #define PNG_BGR 0x0001
  161405. #define PNG_INTERLACE 0x0002
  161406. #define PNG_PACK 0x0004
  161407. #define PNG_SHIFT 0x0008
  161408. #define PNG_SWAP_BYTES 0x0010
  161409. #define PNG_INVERT_MONO 0x0020
  161410. #define PNG_DITHER 0x0040
  161411. #define PNG_BACKGROUND 0x0080
  161412. #define PNG_BACKGROUND_EXPAND 0x0100
  161413. #define PNG_16_TO_8 0x0400
  161414. #define PNG_RGBA 0x0800
  161415. #define PNG_EXPAND 0x1000
  161416. #define PNG_GAMMA 0x2000
  161417. #define PNG_GRAY_TO_RGB 0x4000
  161418. #define PNG_FILLER 0x8000L
  161419. #define PNG_PACKSWAP 0x10000L
  161420. #define PNG_SWAP_ALPHA 0x20000L
  161421. #define PNG_STRIP_ALPHA 0x40000L
  161422. #define PNG_INVERT_ALPHA 0x80000L
  161423. #define PNG_USER_TRANSFORM 0x100000L
  161424. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161425. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161426. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161427. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161428. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161429. #define PNG_STRUCT_PNG 0x0001
  161430. #define PNG_STRUCT_INFO 0x0002
  161431. #define PNG_WEIGHT_SHIFT 8
  161432. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161433. #define PNG_COST_SHIFT 3
  161434. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161435. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161436. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161437. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161438. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161439. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161440. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161441. #define PNG_FLAG_ROW_INIT 0x0040
  161442. #define PNG_FLAG_FILLER_AFTER 0x0080
  161443. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161444. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161445. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161446. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161447. #define PNG_FLAG_FREE_PLTE 0x1000
  161448. #define PNG_FLAG_FREE_TRNS 0x2000
  161449. #define PNG_FLAG_FREE_HIST 0x4000
  161450. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161451. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161452. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161453. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161454. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161455. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161456. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161457. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161458. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161459. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161460. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161461. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161462. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161463. PNG_FLAG_CRC_CRITICAL_MASK)
  161464. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161465. abs((int)((c1).green) - (int)((c2).green)) + \
  161466. abs((int)((c1).blue) - (int)((c2).blue)))
  161467. #define PNG_ROWBYTES(pixel_bits, width) \
  161468. ((pixel_bits) >= 8 ? \
  161469. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161470. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161471. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161472. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161473. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161474. #ifdef PNG_USE_GLOBAL_ARRAYS
  161475. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161476. #else
  161477. #endif
  161478. #endif /* PNG_NO_EXTERN */
  161479. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161480. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161481. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161482. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161483. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161484. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161485. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161486. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161487. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161488. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161489. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161490. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161491. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161492. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161493. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161494. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161495. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161496. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161497. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161498. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161499. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161500. #ifdef PNG_USE_GLOBAL_ARRAYS
  161501. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161502. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161503. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161504. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161505. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161506. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161507. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161508. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161509. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161510. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161511. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161512. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161513. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161514. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161515. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161516. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161517. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161518. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161519. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161520. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161521. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161522. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161523. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161524. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161525. #undef png_read_init
  161526. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161527. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161528. #endif
  161529. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161530. png_const_charp user_png_ver, png_size_t png_struct_size));
  161531. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161532. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161533. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161534. png_info_size));
  161535. #endif
  161536. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161537. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161538. #undef png_write_init
  161539. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161540. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161541. #endif
  161542. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161543. png_const_charp user_png_ver, png_size_t png_struct_size));
  161544. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161545. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161546. png_info_size));
  161547. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161548. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161549. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161550. malloc_fn, png_voidp mem_ptr));
  161551. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161552. png_free_ptr free_fn, png_voidp mem_ptr));
  161553. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161554. png_infop info_ptr));
  161555. #ifndef PNG_1_0_X
  161556. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161557. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161558. #ifdef PNG_SIZE_T
  161559. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161560. #endif
  161561. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161562. png_bytep data, png_size_t length));
  161563. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161564. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161565. png_bytep buffer, png_size_t length));
  161566. #endif
  161567. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161568. png_bytep data, png_size_t length));
  161569. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161570. #if !defined(PNG_NO_STDIO)
  161571. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161572. #endif
  161573. #endif
  161574. #else /* PNG_1_0_X */
  161575. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161576. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161577. png_bytep buffer, png_size_t length));
  161578. #endif
  161579. #endif /* PNG_1_0_X */
  161580. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161581. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161582. png_size_t length));
  161583. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161584. png_size_t length));
  161585. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161586. png_size_t length));
  161587. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161588. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161589. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161590. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161591. png_size_t prefix_length, png_size_t *data_length));
  161592. #endif
  161593. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161594. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161595. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161596. png_size_t length));
  161597. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161598. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161599. #endif
  161600. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161601. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161602. png_uint_32 height,
  161603. int bit_depth, int color_type, int compression_method, int filter_method,
  161604. int interlace_method));
  161605. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161606. png_uint_32 num_pal));
  161607. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161608. png_size_t length));
  161609. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161610. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161611. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161612. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161613. #endif
  161614. #ifdef PNG_FIXED_POINT_SUPPORTED
  161615. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161616. file_gamma));
  161617. #endif
  161618. #endif
  161619. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161620. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161621. int color_type));
  161622. #endif
  161623. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161624. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161625. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161626. double white_x, double white_y,
  161627. double red_x, double red_y, double green_x, double green_y,
  161628. double blue_x, double blue_y));
  161629. #endif
  161630. #ifdef PNG_FIXED_POINT_SUPPORTED
  161631. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161632. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161633. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161634. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161635. png_fixed_point int_blue_y));
  161636. #endif
  161637. #endif
  161638. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161639. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161640. int intent));
  161641. #endif
  161642. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161643. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161644. png_charp name, int compression_type,
  161645. png_charp profile, int proflen));
  161646. #endif
  161647. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161648. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161649. png_sPLT_tp palette));
  161650. #endif
  161651. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161652. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161653. png_color_16p values, int number, int color_type));
  161654. #endif
  161655. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161656. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161657. png_color_16p values, int color_type));
  161658. #endif
  161659. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161660. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161661. int num_hist));
  161662. #endif
  161663. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161664. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161665. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161666. png_charp key, png_charpp new_key));
  161667. #endif
  161668. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161669. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161670. png_charp text, png_size_t text_len));
  161671. #endif
  161672. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161673. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161674. png_charp text, png_size_t text_len, int compression));
  161675. #endif
  161676. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161677. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161678. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161679. png_charp text));
  161680. #endif
  161681. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161682. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161683. png_infop info_ptr, png_textp text_ptr, int num_text));
  161684. #endif
  161685. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161686. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161687. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161688. #endif
  161689. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161690. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161691. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161692. png_charp units, png_charpp params));
  161693. #endif
  161694. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161695. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161696. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161697. int unit_type));
  161698. #endif
  161699. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161700. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161701. png_timep mod_time));
  161702. #endif
  161703. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161704. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161705. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161706. int unit, double width, double height));
  161707. #else
  161708. #ifdef PNG_FIXED_POINT_SUPPORTED
  161709. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161710. int unit, png_charp width, png_charp height));
  161711. #endif
  161712. #endif
  161713. #endif
  161714. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161715. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161716. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161717. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161718. #endif
  161719. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161720. int mask));
  161721. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161722. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161723. #endif
  161724. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161725. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161726. png_bytep row, int pass));
  161727. #endif
  161728. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161729. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161730. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161731. png_row_infop row_info));
  161732. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161733. png_bytep filtered_row));
  161734. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161735. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161736. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161737. png_infop info_ptr));
  161738. #if defined(PNG_READ_FILLER_SUPPORTED)
  161739. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161740. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161741. #endif
  161742. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161743. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161744. png_bytep row));
  161745. #endif
  161746. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161747. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161748. png_bytep row));
  161749. #endif
  161750. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161751. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161752. png_bytep row));
  161753. #endif
  161754. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161755. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161756. png_bytep row));
  161757. #endif
  161758. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161759. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161760. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161761. png_bytep row, png_uint_32 flags));
  161762. #endif
  161763. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161764. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161765. #endif
  161766. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161767. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161768. #endif
  161769. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161770. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161771. row_info, png_bytep row));
  161772. #endif
  161773. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161774. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161775. png_bytep row));
  161776. #endif
  161777. #if defined(PNG_READ_PACK_SUPPORTED)
  161778. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161779. #endif
  161780. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161781. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161782. png_color_8p sig_bits));
  161783. #endif
  161784. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161785. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161786. #endif
  161787. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161788. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161789. #endif
  161790. #if defined(PNG_READ_DITHER_SUPPORTED)
  161791. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161792. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161793. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161794. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161795. png_colorp palette, int num_palette));
  161796. # endif
  161797. #endif
  161798. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161799. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161800. #endif
  161801. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161802. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161803. png_bytep row, png_uint_32 bit_depth));
  161804. #endif
  161805. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161806. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161807. png_color_8p bit_depth));
  161808. #endif
  161809. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161810. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161811. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161812. png_color_16p trans_values, png_color_16p background,
  161813. png_color_16p background_1,
  161814. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  161815. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  161816. png_uint_16pp gamma_16_to_1, int gamma_shift));
  161817. #else
  161818. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161819. png_color_16p trans_values, png_color_16p background));
  161820. #endif
  161821. #endif
  161822. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161823. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  161824. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  161825. int gamma_shift));
  161826. #endif
  161827. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161828. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  161829. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  161830. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  161831. png_bytep row, png_color_16p trans_value));
  161832. #endif
  161833. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  161834. png_uint_32 length));
  161835. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  161836. png_uint_32 length));
  161837. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  161838. png_uint_32 length));
  161839. #if defined(PNG_READ_bKGD_SUPPORTED)
  161840. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  161841. png_uint_32 length));
  161842. #endif
  161843. #if defined(PNG_READ_cHRM_SUPPORTED)
  161844. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  161845. png_uint_32 length));
  161846. #endif
  161847. #if defined(PNG_READ_gAMA_SUPPORTED)
  161848. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  161849. png_uint_32 length));
  161850. #endif
  161851. #if defined(PNG_READ_hIST_SUPPORTED)
  161852. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  161853. png_uint_32 length));
  161854. #endif
  161855. #if defined(PNG_READ_iCCP_SUPPORTED)
  161856. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  161857. png_uint_32 length));
  161858. #endif /* PNG_READ_iCCP_SUPPORTED */
  161859. #if defined(PNG_READ_iTXt_SUPPORTED)
  161860. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161861. png_uint_32 length));
  161862. #endif
  161863. #if defined(PNG_READ_oFFs_SUPPORTED)
  161864. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161865. png_uint_32 length));
  161866. #endif
  161867. #if defined(PNG_READ_pCAL_SUPPORTED)
  161868. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161869. png_uint_32 length));
  161870. #endif
  161871. #if defined(PNG_READ_pHYs_SUPPORTED)
  161872. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161873. png_uint_32 length));
  161874. #endif
  161875. #if defined(PNG_READ_sBIT_SUPPORTED)
  161876. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161877. png_uint_32 length));
  161878. #endif
  161879. #if defined(PNG_READ_sCAL_SUPPORTED)
  161880. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161881. png_uint_32 length));
  161882. #endif
  161883. #if defined(PNG_READ_sPLT_SUPPORTED)
  161884. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161885. png_uint_32 length));
  161886. #endif /* PNG_READ_sPLT_SUPPORTED */
  161887. #if defined(PNG_READ_sRGB_SUPPORTED)
  161888. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  161889. png_uint_32 length));
  161890. #endif
  161891. #if defined(PNG_READ_tEXt_SUPPORTED)
  161892. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161893. png_uint_32 length));
  161894. #endif
  161895. #if defined(PNG_READ_tIME_SUPPORTED)
  161896. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  161897. png_uint_32 length));
  161898. #endif
  161899. #if defined(PNG_READ_tRNS_SUPPORTED)
  161900. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  161901. png_uint_32 length));
  161902. #endif
  161903. #if defined(PNG_READ_zTXt_SUPPORTED)
  161904. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161905. png_uint_32 length));
  161906. #endif
  161907. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  161908. png_infop info_ptr, png_uint_32 length));
  161909. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  161910. png_bytep chunk_name));
  161911. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  161912. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  161913. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  161914. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161915. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  161916. png_infop info_ptr));
  161917. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  161918. png_infop info_ptr));
  161919. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  161920. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  161921. png_uint_32 length));
  161922. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  161923. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  161924. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  161925. png_bytep buffer, png_size_t buffer_length));
  161926. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  161927. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  161928. png_bytep buffer, png_size_t buffer_length));
  161929. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  161930. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  161931. png_infop info_ptr, png_uint_32 length));
  161932. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  161933. png_infop info_ptr));
  161934. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  161935. png_infop info_ptr));
  161936. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  161937. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  161938. png_infop info_ptr));
  161939. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  161940. png_infop info_ptr));
  161941. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  161942. #if defined(PNG_READ_tEXt_SUPPORTED)
  161943. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  161944. png_infop info_ptr, png_uint_32 length));
  161945. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  161946. png_infop info_ptr));
  161947. #endif
  161948. #if defined(PNG_READ_zTXt_SUPPORTED)
  161949. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  161950. png_infop info_ptr, png_uint_32 length));
  161951. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  161952. png_infop info_ptr));
  161953. #endif
  161954. #if defined(PNG_READ_iTXt_SUPPORTED)
  161955. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  161956. png_infop info_ptr, png_uint_32 length));
  161957. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  161958. png_infop info_ptr));
  161959. #endif
  161960. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161961. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161962. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  161963. png_bytep row));
  161964. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  161965. png_bytep row));
  161966. #endif
  161967. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161968. #if defined(PNG_MMX_CODE_SUPPORTED)
  161969. /* PRIVATE */
  161970. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  161971. #endif
  161972. #endif
  161973. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  161974. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  161975. png_infop info_ptr));
  161976. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  161977. png_infop info_ptr));
  161978. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  161979. png_infop info_ptr));
  161980. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  161981. png_infop info_ptr));
  161982. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  161983. png_infop info_ptr));
  161984. #if defined(PNG_pHYs_SUPPORTED)
  161985. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  161986. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161987. #endif /* PNG_pHYs_SUPPORTED */
  161988. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  161989. #endif /* PNG_INTERNAL */
  161990. #ifdef __cplusplus
  161991. }
  161992. #endif
  161993. #endif /* PNG_VERSION_INFO_ONLY */
  161994. #endif /* PNG_H */
  161995. /*** End of inlined file: png.h ***/
  161996. #define PNG_NO_EXTERN
  161997. /*** Start of inlined file: png.c ***/
  161998. #define PNG_INTERNAL
  161999. #define PNG_NO_EXTERN
  162000. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162001. #ifdef PNG_USE_GLOBAL_ARRAYS
  162002. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162003. #ifdef PNG_READ_SUPPORTED
  162004. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162005. #endif /* PNG_READ_SUPPORTED */
  162006. PNG_IHDR;
  162007. PNG_IDAT;
  162008. PNG_IEND;
  162009. PNG_PLTE;
  162010. PNG_bKGD;
  162011. PNG_cHRM;
  162012. PNG_gAMA;
  162013. PNG_hIST;
  162014. PNG_iCCP;
  162015. PNG_iTXt;
  162016. PNG_oFFs;
  162017. PNG_pCAL;
  162018. PNG_sCAL;
  162019. PNG_pHYs;
  162020. PNG_sBIT;
  162021. PNG_sPLT;
  162022. PNG_sRGB;
  162023. PNG_tEXt;
  162024. PNG_tIME;
  162025. PNG_tRNS;
  162026. PNG_zTXt;
  162027. #ifdef PNG_READ_SUPPORTED
  162028. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162029. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162030. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162031. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162032. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162033. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162034. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162035. #endif /* PNG_READ_SUPPORTED */
  162036. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162037. #ifdef PNG_READ_SUPPORTED
  162038. void PNGAPI
  162039. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162040. {
  162041. if(png_ptr == NULL) return;
  162042. png_debug(1, "in png_set_sig_bytes\n");
  162043. if (num_bytes > 8)
  162044. png_error(png_ptr, "Too many bytes for PNG signature.");
  162045. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162046. }
  162047. int PNGAPI
  162048. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162049. {
  162050. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162051. if (num_to_check > 8)
  162052. num_to_check = 8;
  162053. else if (num_to_check < 1)
  162054. return (-1);
  162055. if (start > 7)
  162056. return (-1);
  162057. if (start + num_to_check > 8)
  162058. num_to_check = 8 - start;
  162059. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162060. }
  162061. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162062. int PNGAPI
  162063. png_check_sig(png_bytep sig, int num)
  162064. {
  162065. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162066. }
  162067. #endif
  162068. #endif /* PNG_READ_SUPPORTED */
  162069. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162070. #ifdef PNG_1_0_X
  162071. voidpf PNGAPI
  162072. #else
  162073. voidpf /* private */
  162074. #endif
  162075. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162076. {
  162077. png_voidp ptr;
  162078. png_structp p=(png_structp)png_ptr;
  162079. png_uint_32 save_flags=p->flags;
  162080. png_uint_32 num_bytes;
  162081. if(png_ptr == NULL) return (NULL);
  162082. if (items > PNG_UINT_32_MAX/size)
  162083. {
  162084. png_warning (p, "Potential overflow in png_zalloc()");
  162085. return (NULL);
  162086. }
  162087. num_bytes = (png_uint_32)items * size;
  162088. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162089. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162090. p->flags=save_flags;
  162091. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162092. if (ptr == NULL)
  162093. return ((voidpf)ptr);
  162094. if (num_bytes > (png_uint_32)0x8000L)
  162095. {
  162096. png_memset(ptr, 0, (png_size_t)0x8000L);
  162097. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162098. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162099. }
  162100. else
  162101. {
  162102. png_memset(ptr, 0, (png_size_t)num_bytes);
  162103. }
  162104. #endif
  162105. return ((voidpf)ptr);
  162106. }
  162107. #ifdef PNG_1_0_X
  162108. void PNGAPI
  162109. #else
  162110. void /* private */
  162111. #endif
  162112. png_zfree(voidpf png_ptr, voidpf ptr)
  162113. {
  162114. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162115. }
  162116. void /* PRIVATE */
  162117. png_reset_crc(png_structp png_ptr)
  162118. {
  162119. png_ptr->crc = crc32(0, Z_NULL, 0);
  162120. }
  162121. void /* PRIVATE */
  162122. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162123. {
  162124. int need_crc = 1;
  162125. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162126. {
  162127. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162128. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162129. need_crc = 0;
  162130. }
  162131. else /* critical */
  162132. {
  162133. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162134. need_crc = 0;
  162135. }
  162136. if (need_crc)
  162137. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162138. }
  162139. png_infop PNGAPI
  162140. png_create_info_struct(png_structp png_ptr)
  162141. {
  162142. png_infop info_ptr;
  162143. png_debug(1, "in png_create_info_struct\n");
  162144. if(png_ptr == NULL) return (NULL);
  162145. #ifdef PNG_USER_MEM_SUPPORTED
  162146. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162147. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162148. #else
  162149. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162150. #endif
  162151. if (info_ptr != NULL)
  162152. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162153. return (info_ptr);
  162154. }
  162155. void PNGAPI
  162156. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162157. {
  162158. png_infop info_ptr = NULL;
  162159. if(png_ptr == NULL) return;
  162160. png_debug(1, "in png_destroy_info_struct\n");
  162161. if (info_ptr_ptr != NULL)
  162162. info_ptr = *info_ptr_ptr;
  162163. if (info_ptr != NULL)
  162164. {
  162165. png_info_destroy(png_ptr, info_ptr);
  162166. #ifdef PNG_USER_MEM_SUPPORTED
  162167. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162168. png_ptr->mem_ptr);
  162169. #else
  162170. png_destroy_struct((png_voidp)info_ptr);
  162171. #endif
  162172. *info_ptr_ptr = NULL;
  162173. }
  162174. }
  162175. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162176. #undef png_info_init
  162177. void PNGAPI
  162178. png_info_init(png_infop info_ptr)
  162179. {
  162180. png_info_init_3(&info_ptr, 0);
  162181. }
  162182. #endif
  162183. void PNGAPI
  162184. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162185. {
  162186. png_infop info_ptr = *ptr_ptr;
  162187. if(info_ptr == NULL) return;
  162188. png_debug(1, "in png_info_init_3\n");
  162189. if(png_sizeof(png_info) > png_info_struct_size)
  162190. {
  162191. png_destroy_struct(info_ptr);
  162192. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162193. *ptr_ptr = info_ptr;
  162194. }
  162195. png_memset(info_ptr, 0, png_sizeof (png_info));
  162196. }
  162197. #ifdef PNG_FREE_ME_SUPPORTED
  162198. void PNGAPI
  162199. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162200. int freer, png_uint_32 mask)
  162201. {
  162202. png_debug(1, "in png_data_freer\n");
  162203. if (png_ptr == NULL || info_ptr == NULL)
  162204. return;
  162205. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162206. info_ptr->free_me |= mask;
  162207. else if(freer == PNG_USER_WILL_FREE_DATA)
  162208. info_ptr->free_me &= ~mask;
  162209. else
  162210. png_warning(png_ptr,
  162211. "Unknown freer parameter in png_data_freer.");
  162212. }
  162213. #endif
  162214. void PNGAPI
  162215. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162216. int num)
  162217. {
  162218. png_debug(1, "in png_free_data\n");
  162219. if (png_ptr == NULL || info_ptr == NULL)
  162220. return;
  162221. #if defined(PNG_TEXT_SUPPORTED)
  162222. #ifdef PNG_FREE_ME_SUPPORTED
  162223. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162224. #else
  162225. if (mask & PNG_FREE_TEXT)
  162226. #endif
  162227. {
  162228. if (num != -1)
  162229. {
  162230. if (info_ptr->text && info_ptr->text[num].key)
  162231. {
  162232. png_free(png_ptr, info_ptr->text[num].key);
  162233. info_ptr->text[num].key = NULL;
  162234. }
  162235. }
  162236. else
  162237. {
  162238. int i;
  162239. for (i = 0; i < info_ptr->num_text; i++)
  162240. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162241. png_free(png_ptr, info_ptr->text);
  162242. info_ptr->text = NULL;
  162243. info_ptr->num_text=0;
  162244. }
  162245. }
  162246. #endif
  162247. #if defined(PNG_tRNS_SUPPORTED)
  162248. #ifdef PNG_FREE_ME_SUPPORTED
  162249. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162250. #else
  162251. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162252. #endif
  162253. {
  162254. png_free(png_ptr, info_ptr->trans);
  162255. info_ptr->valid &= ~PNG_INFO_tRNS;
  162256. #ifndef PNG_FREE_ME_SUPPORTED
  162257. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162258. #endif
  162259. info_ptr->trans = NULL;
  162260. }
  162261. #endif
  162262. #if defined(PNG_sCAL_SUPPORTED)
  162263. #ifdef PNG_FREE_ME_SUPPORTED
  162264. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162265. #else
  162266. if (mask & PNG_FREE_SCAL)
  162267. #endif
  162268. {
  162269. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162270. png_free(png_ptr, info_ptr->scal_s_width);
  162271. png_free(png_ptr, info_ptr->scal_s_height);
  162272. info_ptr->scal_s_width = NULL;
  162273. info_ptr->scal_s_height = NULL;
  162274. #endif
  162275. info_ptr->valid &= ~PNG_INFO_sCAL;
  162276. }
  162277. #endif
  162278. #if defined(PNG_pCAL_SUPPORTED)
  162279. #ifdef PNG_FREE_ME_SUPPORTED
  162280. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162281. #else
  162282. if (mask & PNG_FREE_PCAL)
  162283. #endif
  162284. {
  162285. png_free(png_ptr, info_ptr->pcal_purpose);
  162286. png_free(png_ptr, info_ptr->pcal_units);
  162287. info_ptr->pcal_purpose = NULL;
  162288. info_ptr->pcal_units = NULL;
  162289. if (info_ptr->pcal_params != NULL)
  162290. {
  162291. int i;
  162292. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162293. {
  162294. png_free(png_ptr, info_ptr->pcal_params[i]);
  162295. info_ptr->pcal_params[i]=NULL;
  162296. }
  162297. png_free(png_ptr, info_ptr->pcal_params);
  162298. info_ptr->pcal_params = NULL;
  162299. }
  162300. info_ptr->valid &= ~PNG_INFO_pCAL;
  162301. }
  162302. #endif
  162303. #if defined(PNG_iCCP_SUPPORTED)
  162304. #ifdef PNG_FREE_ME_SUPPORTED
  162305. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162306. #else
  162307. if (mask & PNG_FREE_ICCP)
  162308. #endif
  162309. {
  162310. png_free(png_ptr, info_ptr->iccp_name);
  162311. png_free(png_ptr, info_ptr->iccp_profile);
  162312. info_ptr->iccp_name = NULL;
  162313. info_ptr->iccp_profile = NULL;
  162314. info_ptr->valid &= ~PNG_INFO_iCCP;
  162315. }
  162316. #endif
  162317. #if defined(PNG_sPLT_SUPPORTED)
  162318. #ifdef PNG_FREE_ME_SUPPORTED
  162319. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162320. #else
  162321. if (mask & PNG_FREE_SPLT)
  162322. #endif
  162323. {
  162324. if (num != -1)
  162325. {
  162326. if(info_ptr->splt_palettes)
  162327. {
  162328. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162329. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162330. info_ptr->splt_palettes[num].name = NULL;
  162331. info_ptr->splt_palettes[num].entries = NULL;
  162332. }
  162333. }
  162334. else
  162335. {
  162336. if(info_ptr->splt_palettes_num)
  162337. {
  162338. int i;
  162339. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162340. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162341. png_free(png_ptr, info_ptr->splt_palettes);
  162342. info_ptr->splt_palettes = NULL;
  162343. info_ptr->splt_palettes_num = 0;
  162344. }
  162345. info_ptr->valid &= ~PNG_INFO_sPLT;
  162346. }
  162347. }
  162348. #endif
  162349. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162350. if(png_ptr->unknown_chunk.data)
  162351. {
  162352. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162353. png_ptr->unknown_chunk.data = NULL;
  162354. }
  162355. #ifdef PNG_FREE_ME_SUPPORTED
  162356. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162357. #else
  162358. if (mask & PNG_FREE_UNKN)
  162359. #endif
  162360. {
  162361. if (num != -1)
  162362. {
  162363. if(info_ptr->unknown_chunks)
  162364. {
  162365. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162366. info_ptr->unknown_chunks[num].data = NULL;
  162367. }
  162368. }
  162369. else
  162370. {
  162371. int i;
  162372. if(info_ptr->unknown_chunks_num)
  162373. {
  162374. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162375. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162376. png_free(png_ptr, info_ptr->unknown_chunks);
  162377. info_ptr->unknown_chunks = NULL;
  162378. info_ptr->unknown_chunks_num = 0;
  162379. }
  162380. }
  162381. }
  162382. #endif
  162383. #if defined(PNG_hIST_SUPPORTED)
  162384. #ifdef PNG_FREE_ME_SUPPORTED
  162385. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162386. #else
  162387. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162388. #endif
  162389. {
  162390. png_free(png_ptr, info_ptr->hist);
  162391. info_ptr->hist = NULL;
  162392. info_ptr->valid &= ~PNG_INFO_hIST;
  162393. #ifndef PNG_FREE_ME_SUPPORTED
  162394. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162395. #endif
  162396. }
  162397. #endif
  162398. #ifdef PNG_FREE_ME_SUPPORTED
  162399. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162400. #else
  162401. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162402. #endif
  162403. {
  162404. png_zfree(png_ptr, info_ptr->palette);
  162405. info_ptr->palette = NULL;
  162406. info_ptr->valid &= ~PNG_INFO_PLTE;
  162407. #ifndef PNG_FREE_ME_SUPPORTED
  162408. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162409. #endif
  162410. info_ptr->num_palette = 0;
  162411. }
  162412. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162413. #ifdef PNG_FREE_ME_SUPPORTED
  162414. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162415. #else
  162416. if (mask & PNG_FREE_ROWS)
  162417. #endif
  162418. {
  162419. if(info_ptr->row_pointers)
  162420. {
  162421. int row;
  162422. for (row = 0; row < (int)info_ptr->height; row++)
  162423. {
  162424. png_free(png_ptr, info_ptr->row_pointers[row]);
  162425. info_ptr->row_pointers[row]=NULL;
  162426. }
  162427. png_free(png_ptr, info_ptr->row_pointers);
  162428. info_ptr->row_pointers=NULL;
  162429. }
  162430. info_ptr->valid &= ~PNG_INFO_IDAT;
  162431. }
  162432. #endif
  162433. #ifdef PNG_FREE_ME_SUPPORTED
  162434. if(num == -1)
  162435. info_ptr->free_me &= ~mask;
  162436. else
  162437. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162438. #endif
  162439. }
  162440. void /* PRIVATE */
  162441. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162442. {
  162443. png_debug(1, "in png_info_destroy\n");
  162444. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162445. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162446. if (png_ptr->num_chunk_list)
  162447. {
  162448. png_free(png_ptr, png_ptr->chunk_list);
  162449. png_ptr->chunk_list=NULL;
  162450. png_ptr->num_chunk_list=0;
  162451. }
  162452. #endif
  162453. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162454. }
  162455. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162456. png_voidp PNGAPI
  162457. png_get_io_ptr(png_structp png_ptr)
  162458. {
  162459. if(png_ptr == NULL) return (NULL);
  162460. return (png_ptr->io_ptr);
  162461. }
  162462. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162463. #if !defined(PNG_NO_STDIO)
  162464. void PNGAPI
  162465. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162466. {
  162467. png_debug(1, "in png_init_io\n");
  162468. if(png_ptr == NULL) return;
  162469. png_ptr->io_ptr = (png_voidp)fp;
  162470. }
  162471. #endif
  162472. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162473. png_charp PNGAPI
  162474. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162475. {
  162476. static PNG_CONST char short_months[12][4] =
  162477. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162478. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162479. if(png_ptr == NULL) return (NULL);
  162480. if (png_ptr->time_buffer == NULL)
  162481. {
  162482. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162483. png_sizeof(char)));
  162484. }
  162485. #if defined(_WIN32_WCE)
  162486. {
  162487. wchar_t time_buf[29];
  162488. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162489. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162490. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162491. ptime->second % 61);
  162492. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162493. NULL, NULL);
  162494. }
  162495. #else
  162496. #ifdef USE_FAR_KEYWORD
  162497. {
  162498. char near_time_buf[29];
  162499. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162500. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162501. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162502. ptime->second % 61);
  162503. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162504. 29*png_sizeof(char));
  162505. }
  162506. #else
  162507. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162508. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162509. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162510. ptime->second % 61);
  162511. #endif
  162512. #endif /* _WIN32_WCE */
  162513. return ((png_charp)png_ptr->time_buffer);
  162514. }
  162515. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162516. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162517. png_charp PNGAPI
  162518. png_get_copyright(png_structp png_ptr)
  162519. {
  162520. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162521. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162522. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162523. Copyright (c) 1996-1997 Andreas Dilger\n\
  162524. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162525. }
  162526. png_charp PNGAPI
  162527. png_get_libpng_ver(png_structp png_ptr)
  162528. {
  162529. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162530. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162531. }
  162532. png_charp PNGAPI
  162533. png_get_header_ver(png_structp png_ptr)
  162534. {
  162535. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162536. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162537. }
  162538. png_charp PNGAPI
  162539. png_get_header_version(png_structp png_ptr)
  162540. {
  162541. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162542. return ((png_charp) PNG_HEADER_VERSION_STRING
  162543. #ifndef PNG_READ_SUPPORTED
  162544. " (NO READ SUPPORT)"
  162545. #endif
  162546. "\n");
  162547. }
  162548. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162549. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162550. int PNGAPI
  162551. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162552. {
  162553. int i;
  162554. png_bytep p;
  162555. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162556. return 0;
  162557. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162558. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162559. if (!png_memcmp(chunk_name, p, 4))
  162560. return ((int)*(p+4));
  162561. return 0;
  162562. }
  162563. #endif
  162564. int PNGAPI
  162565. png_reset_zstream(png_structp png_ptr)
  162566. {
  162567. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162568. return (inflateReset(&png_ptr->zstream));
  162569. }
  162570. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162571. png_uint_32 PNGAPI
  162572. png_access_version_number(void)
  162573. {
  162574. return((png_uint_32) PNG_LIBPNG_VER);
  162575. }
  162576. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162577. #if !defined(PNG_1_0_X)
  162578. int PNGAPI
  162579. png_mmx_support(void)
  162580. {
  162581. return -1;
  162582. }
  162583. #endif /* PNG_1_0_X */
  162584. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162585. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162586. #ifdef PNG_SIZE_T
  162587. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162588. png_size_t PNGAPI
  162589. png_convert_size(size_t size)
  162590. {
  162591. if (size > (png_size_t)-1)
  162592. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162593. return ((png_size_t)size);
  162594. }
  162595. #endif /* PNG_SIZE_T */
  162596. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162597. /*** End of inlined file: png.c ***/
  162598. /*** Start of inlined file: pngerror.c ***/
  162599. #define PNG_INTERNAL
  162600. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162601. static void /* PRIVATE */
  162602. png_default_error PNGARG((png_structp png_ptr,
  162603. png_const_charp error_message));
  162604. #ifndef PNG_NO_WARNINGS
  162605. static void /* PRIVATE */
  162606. png_default_warning PNGARG((png_structp png_ptr,
  162607. png_const_charp warning_message));
  162608. #endif /* PNG_NO_WARNINGS */
  162609. #ifndef PNG_NO_ERROR_TEXT
  162610. void PNGAPI
  162611. png_error(png_structp png_ptr, png_const_charp error_message)
  162612. {
  162613. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162614. char msg[16];
  162615. if (png_ptr != NULL)
  162616. {
  162617. if (png_ptr->flags&
  162618. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162619. {
  162620. if (*error_message == '#')
  162621. {
  162622. int offset;
  162623. for (offset=1; offset<15; offset++)
  162624. if (*(error_message+offset) == ' ')
  162625. break;
  162626. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162627. {
  162628. int i;
  162629. for (i=0; i<offset-1; i++)
  162630. msg[i]=error_message[i+1];
  162631. msg[i]='\0';
  162632. error_message=msg;
  162633. }
  162634. else
  162635. error_message+=offset;
  162636. }
  162637. else
  162638. {
  162639. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162640. {
  162641. msg[0]='0';
  162642. msg[1]='\0';
  162643. error_message=msg;
  162644. }
  162645. }
  162646. }
  162647. }
  162648. #endif
  162649. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162650. (*(png_ptr->error_fn))(png_ptr, error_message);
  162651. png_default_error(png_ptr, error_message);
  162652. }
  162653. #else
  162654. void PNGAPI
  162655. png_err(png_structp png_ptr)
  162656. {
  162657. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162658. (*(png_ptr->error_fn))(png_ptr, '\0');
  162659. png_default_error(png_ptr, '\0');
  162660. }
  162661. #endif /* PNG_NO_ERROR_TEXT */
  162662. #ifndef PNG_NO_WARNINGS
  162663. void PNGAPI
  162664. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162665. {
  162666. int offset = 0;
  162667. if (png_ptr != NULL)
  162668. {
  162669. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162670. if (png_ptr->flags&
  162671. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162672. #endif
  162673. {
  162674. if (*warning_message == '#')
  162675. {
  162676. for (offset=1; offset<15; offset++)
  162677. if (*(warning_message+offset) == ' ')
  162678. break;
  162679. }
  162680. }
  162681. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162682. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162683. }
  162684. else
  162685. png_default_warning(png_ptr, warning_message+offset);
  162686. }
  162687. #endif /* PNG_NO_WARNINGS */
  162688. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162689. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162690. static void /* PRIVATE */
  162691. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162692. error_message)
  162693. {
  162694. int iout = 0, iin = 0;
  162695. while (iin < 4)
  162696. {
  162697. int c = png_ptr->chunk_name[iin++];
  162698. if (isnonalpha(c))
  162699. {
  162700. buffer[iout++] = '[';
  162701. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162702. buffer[iout++] = png_digit[c & 0x0f];
  162703. buffer[iout++] = ']';
  162704. }
  162705. else
  162706. {
  162707. buffer[iout++] = (png_byte)c;
  162708. }
  162709. }
  162710. if (error_message == NULL)
  162711. buffer[iout] = 0;
  162712. else
  162713. {
  162714. buffer[iout++] = ':';
  162715. buffer[iout++] = ' ';
  162716. png_strncpy(buffer+iout, error_message, 63);
  162717. buffer[iout+63] = 0;
  162718. }
  162719. }
  162720. #ifdef PNG_READ_SUPPORTED
  162721. void PNGAPI
  162722. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162723. {
  162724. char msg[18+64];
  162725. if (png_ptr == NULL)
  162726. png_error(png_ptr, error_message);
  162727. else
  162728. {
  162729. png_format_buffer(png_ptr, msg, error_message);
  162730. png_error(png_ptr, msg);
  162731. }
  162732. }
  162733. #endif /* PNG_READ_SUPPORTED */
  162734. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162735. #ifndef PNG_NO_WARNINGS
  162736. void PNGAPI
  162737. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162738. {
  162739. char msg[18+64];
  162740. if (png_ptr == NULL)
  162741. png_warning(png_ptr, warning_message);
  162742. else
  162743. {
  162744. png_format_buffer(png_ptr, msg, warning_message);
  162745. png_warning(png_ptr, msg);
  162746. }
  162747. }
  162748. #endif /* PNG_NO_WARNINGS */
  162749. static void /* PRIVATE */
  162750. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162751. {
  162752. #ifndef PNG_NO_CONSOLE_IO
  162753. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162754. if (*error_message == '#')
  162755. {
  162756. int offset;
  162757. char error_number[16];
  162758. for (offset=0; offset<15; offset++)
  162759. {
  162760. error_number[offset] = *(error_message+offset+1);
  162761. if (*(error_message+offset) == ' ')
  162762. break;
  162763. }
  162764. if((offset > 1) && (offset < 15))
  162765. {
  162766. error_number[offset-1]='\0';
  162767. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162768. error_message+offset);
  162769. }
  162770. else
  162771. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162772. }
  162773. else
  162774. #endif
  162775. fprintf(stderr, "libpng error: %s\n", error_message);
  162776. #endif
  162777. #ifdef PNG_SETJMP_SUPPORTED
  162778. if (png_ptr)
  162779. {
  162780. # ifdef USE_FAR_KEYWORD
  162781. {
  162782. jmp_buf jmpbuf;
  162783. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162784. longjmp(jmpbuf, 1);
  162785. }
  162786. # else
  162787. longjmp(png_ptr->jmpbuf, 1);
  162788. # endif
  162789. }
  162790. #else
  162791. PNG_ABORT();
  162792. #endif
  162793. #ifdef PNG_NO_CONSOLE_IO
  162794. error_message = error_message; /* make compiler happy */
  162795. #endif
  162796. }
  162797. #ifndef PNG_NO_WARNINGS
  162798. static void /* PRIVATE */
  162799. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162800. {
  162801. #ifndef PNG_NO_CONSOLE_IO
  162802. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162803. if (*warning_message == '#')
  162804. {
  162805. int offset;
  162806. char warning_number[16];
  162807. for (offset=0; offset<15; offset++)
  162808. {
  162809. warning_number[offset]=*(warning_message+offset+1);
  162810. if (*(warning_message+offset) == ' ')
  162811. break;
  162812. }
  162813. if((offset > 1) && (offset < 15))
  162814. {
  162815. warning_number[offset-1]='\0';
  162816. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  162817. warning_message+offset);
  162818. }
  162819. else
  162820. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162821. }
  162822. else
  162823. # endif
  162824. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162825. #else
  162826. warning_message = warning_message; /* make compiler happy */
  162827. #endif
  162828. png_ptr = png_ptr; /* make compiler happy */
  162829. }
  162830. #endif /* PNG_NO_WARNINGS */
  162831. void PNGAPI
  162832. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  162833. png_error_ptr error_fn, png_error_ptr warning_fn)
  162834. {
  162835. if (png_ptr == NULL)
  162836. return;
  162837. png_ptr->error_ptr = error_ptr;
  162838. png_ptr->error_fn = error_fn;
  162839. png_ptr->warning_fn = warning_fn;
  162840. }
  162841. png_voidp PNGAPI
  162842. png_get_error_ptr(png_structp png_ptr)
  162843. {
  162844. if (png_ptr == NULL)
  162845. return NULL;
  162846. return ((png_voidp)png_ptr->error_ptr);
  162847. }
  162848. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162849. void PNGAPI
  162850. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  162851. {
  162852. if(png_ptr != NULL)
  162853. {
  162854. png_ptr->flags &=
  162855. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  162856. }
  162857. }
  162858. #endif
  162859. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  162860. /*** End of inlined file: pngerror.c ***/
  162861. /*** Start of inlined file: pngget.c ***/
  162862. #define PNG_INTERNAL
  162863. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162864. png_uint_32 PNGAPI
  162865. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  162866. {
  162867. if (png_ptr != NULL && info_ptr != NULL)
  162868. return(info_ptr->valid & flag);
  162869. else
  162870. return(0);
  162871. }
  162872. png_uint_32 PNGAPI
  162873. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  162874. {
  162875. if (png_ptr != NULL && info_ptr != NULL)
  162876. return(info_ptr->rowbytes);
  162877. else
  162878. return(0);
  162879. }
  162880. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162881. png_bytepp PNGAPI
  162882. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  162883. {
  162884. if (png_ptr != NULL && info_ptr != NULL)
  162885. return(info_ptr->row_pointers);
  162886. else
  162887. return(0);
  162888. }
  162889. #endif
  162890. #ifdef PNG_EASY_ACCESS_SUPPORTED
  162891. png_uint_32 PNGAPI
  162892. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  162893. {
  162894. if (png_ptr != NULL && info_ptr != NULL)
  162895. {
  162896. return info_ptr->width;
  162897. }
  162898. return (0);
  162899. }
  162900. png_uint_32 PNGAPI
  162901. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  162902. {
  162903. if (png_ptr != NULL && info_ptr != NULL)
  162904. {
  162905. return info_ptr->height;
  162906. }
  162907. return (0);
  162908. }
  162909. png_byte PNGAPI
  162910. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  162911. {
  162912. if (png_ptr != NULL && info_ptr != NULL)
  162913. {
  162914. return info_ptr->bit_depth;
  162915. }
  162916. return (0);
  162917. }
  162918. png_byte PNGAPI
  162919. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  162920. {
  162921. if (png_ptr != NULL && info_ptr != NULL)
  162922. {
  162923. return info_ptr->color_type;
  162924. }
  162925. return (0);
  162926. }
  162927. png_byte PNGAPI
  162928. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  162929. {
  162930. if (png_ptr != NULL && info_ptr != NULL)
  162931. {
  162932. return info_ptr->filter_type;
  162933. }
  162934. return (0);
  162935. }
  162936. png_byte PNGAPI
  162937. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  162938. {
  162939. if (png_ptr != NULL && info_ptr != NULL)
  162940. {
  162941. return info_ptr->interlace_type;
  162942. }
  162943. return (0);
  162944. }
  162945. png_byte PNGAPI
  162946. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  162947. {
  162948. if (png_ptr != NULL && info_ptr != NULL)
  162949. {
  162950. return info_ptr->compression_type;
  162951. }
  162952. return (0);
  162953. }
  162954. png_uint_32 PNGAPI
  162955. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  162956. {
  162957. if (png_ptr != NULL && info_ptr != NULL)
  162958. #if defined(PNG_pHYs_SUPPORTED)
  162959. if (info_ptr->valid & PNG_INFO_pHYs)
  162960. {
  162961. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  162962. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  162963. return (0);
  162964. else return (info_ptr->x_pixels_per_unit);
  162965. }
  162966. #else
  162967. return (0);
  162968. #endif
  162969. return (0);
  162970. }
  162971. png_uint_32 PNGAPI
  162972. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  162973. {
  162974. if (png_ptr != NULL && info_ptr != NULL)
  162975. #if defined(PNG_pHYs_SUPPORTED)
  162976. if (info_ptr->valid & PNG_INFO_pHYs)
  162977. {
  162978. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  162979. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  162980. return (0);
  162981. else return (info_ptr->y_pixels_per_unit);
  162982. }
  162983. #else
  162984. return (0);
  162985. #endif
  162986. return (0);
  162987. }
  162988. png_uint_32 PNGAPI
  162989. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  162990. {
  162991. if (png_ptr != NULL && info_ptr != NULL)
  162992. #if defined(PNG_pHYs_SUPPORTED)
  162993. if (info_ptr->valid & PNG_INFO_pHYs)
  162994. {
  162995. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  162996. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  162997. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  162998. return (0);
  162999. else return (info_ptr->x_pixels_per_unit);
  163000. }
  163001. #else
  163002. return (0);
  163003. #endif
  163004. return (0);
  163005. }
  163006. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163007. float PNGAPI
  163008. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163009. {
  163010. if (png_ptr != NULL && info_ptr != NULL)
  163011. #if defined(PNG_pHYs_SUPPORTED)
  163012. if (info_ptr->valid & PNG_INFO_pHYs)
  163013. {
  163014. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163015. if (info_ptr->x_pixels_per_unit == 0)
  163016. return ((float)0.0);
  163017. else
  163018. return ((float)((float)info_ptr->y_pixels_per_unit
  163019. /(float)info_ptr->x_pixels_per_unit));
  163020. }
  163021. #else
  163022. return (0.0);
  163023. #endif
  163024. return ((float)0.0);
  163025. }
  163026. #endif
  163027. png_int_32 PNGAPI
  163028. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163029. {
  163030. if (png_ptr != NULL && info_ptr != NULL)
  163031. #if defined(PNG_oFFs_SUPPORTED)
  163032. if (info_ptr->valid & PNG_INFO_oFFs)
  163033. {
  163034. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163035. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163036. return (0);
  163037. else return (info_ptr->x_offset);
  163038. }
  163039. #else
  163040. return (0);
  163041. #endif
  163042. return (0);
  163043. }
  163044. png_int_32 PNGAPI
  163045. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163046. {
  163047. if (png_ptr != NULL && info_ptr != NULL)
  163048. #if defined(PNG_oFFs_SUPPORTED)
  163049. if (info_ptr->valid & PNG_INFO_oFFs)
  163050. {
  163051. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163052. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163053. return (0);
  163054. else return (info_ptr->y_offset);
  163055. }
  163056. #else
  163057. return (0);
  163058. #endif
  163059. return (0);
  163060. }
  163061. png_int_32 PNGAPI
  163062. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163063. {
  163064. if (png_ptr != NULL && info_ptr != NULL)
  163065. #if defined(PNG_oFFs_SUPPORTED)
  163066. if (info_ptr->valid & PNG_INFO_oFFs)
  163067. {
  163068. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163069. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163070. return (0);
  163071. else return (info_ptr->x_offset);
  163072. }
  163073. #else
  163074. return (0);
  163075. #endif
  163076. return (0);
  163077. }
  163078. png_int_32 PNGAPI
  163079. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163080. {
  163081. if (png_ptr != NULL && info_ptr != NULL)
  163082. #if defined(PNG_oFFs_SUPPORTED)
  163083. if (info_ptr->valid & PNG_INFO_oFFs)
  163084. {
  163085. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163086. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163087. return (0);
  163088. else return (info_ptr->y_offset);
  163089. }
  163090. #else
  163091. return (0);
  163092. #endif
  163093. return (0);
  163094. }
  163095. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163096. png_uint_32 PNGAPI
  163097. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163098. {
  163099. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163100. *.0254 +.5));
  163101. }
  163102. png_uint_32 PNGAPI
  163103. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163104. {
  163105. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163106. *.0254 +.5));
  163107. }
  163108. png_uint_32 PNGAPI
  163109. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163110. {
  163111. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163112. *.0254 +.5));
  163113. }
  163114. float PNGAPI
  163115. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163116. {
  163117. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163118. *.00003937);
  163119. }
  163120. float PNGAPI
  163121. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163122. {
  163123. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163124. *.00003937);
  163125. }
  163126. #if defined(PNG_pHYs_SUPPORTED)
  163127. png_uint_32 PNGAPI
  163128. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163129. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163130. {
  163131. png_uint_32 retval = 0;
  163132. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163133. {
  163134. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163135. if (res_x != NULL)
  163136. {
  163137. *res_x = info_ptr->x_pixels_per_unit;
  163138. retval |= PNG_INFO_pHYs;
  163139. }
  163140. if (res_y != NULL)
  163141. {
  163142. *res_y = info_ptr->y_pixels_per_unit;
  163143. retval |= PNG_INFO_pHYs;
  163144. }
  163145. if (unit_type != NULL)
  163146. {
  163147. *unit_type = (int)info_ptr->phys_unit_type;
  163148. retval |= PNG_INFO_pHYs;
  163149. if(*unit_type == 1)
  163150. {
  163151. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163152. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163153. }
  163154. }
  163155. }
  163156. return (retval);
  163157. }
  163158. #endif /* PNG_pHYs_SUPPORTED */
  163159. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163160. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163161. png_byte PNGAPI
  163162. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163163. {
  163164. if (png_ptr != NULL && info_ptr != NULL)
  163165. return(info_ptr->channels);
  163166. else
  163167. return (0);
  163168. }
  163169. png_bytep PNGAPI
  163170. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163171. {
  163172. if (png_ptr != NULL && info_ptr != NULL)
  163173. return(info_ptr->signature);
  163174. else
  163175. return (NULL);
  163176. }
  163177. #if defined(PNG_bKGD_SUPPORTED)
  163178. png_uint_32 PNGAPI
  163179. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163180. png_color_16p *background)
  163181. {
  163182. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163183. && background != NULL)
  163184. {
  163185. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163186. *background = &(info_ptr->background);
  163187. return (PNG_INFO_bKGD);
  163188. }
  163189. return (0);
  163190. }
  163191. #endif
  163192. #if defined(PNG_cHRM_SUPPORTED)
  163193. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163194. png_uint_32 PNGAPI
  163195. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163196. double *white_x, double *white_y, double *red_x, double *red_y,
  163197. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163198. {
  163199. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163200. {
  163201. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163202. if (white_x != NULL)
  163203. *white_x = (double)info_ptr->x_white;
  163204. if (white_y != NULL)
  163205. *white_y = (double)info_ptr->y_white;
  163206. if (red_x != NULL)
  163207. *red_x = (double)info_ptr->x_red;
  163208. if (red_y != NULL)
  163209. *red_y = (double)info_ptr->y_red;
  163210. if (green_x != NULL)
  163211. *green_x = (double)info_ptr->x_green;
  163212. if (green_y != NULL)
  163213. *green_y = (double)info_ptr->y_green;
  163214. if (blue_x != NULL)
  163215. *blue_x = (double)info_ptr->x_blue;
  163216. if (blue_y != NULL)
  163217. *blue_y = (double)info_ptr->y_blue;
  163218. return (PNG_INFO_cHRM);
  163219. }
  163220. return (0);
  163221. }
  163222. #endif
  163223. #ifdef PNG_FIXED_POINT_SUPPORTED
  163224. png_uint_32 PNGAPI
  163225. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163226. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163227. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163228. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163229. {
  163230. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163231. {
  163232. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163233. if (white_x != NULL)
  163234. *white_x = info_ptr->int_x_white;
  163235. if (white_y != NULL)
  163236. *white_y = info_ptr->int_y_white;
  163237. if (red_x != NULL)
  163238. *red_x = info_ptr->int_x_red;
  163239. if (red_y != NULL)
  163240. *red_y = info_ptr->int_y_red;
  163241. if (green_x != NULL)
  163242. *green_x = info_ptr->int_x_green;
  163243. if (green_y != NULL)
  163244. *green_y = info_ptr->int_y_green;
  163245. if (blue_x != NULL)
  163246. *blue_x = info_ptr->int_x_blue;
  163247. if (blue_y != NULL)
  163248. *blue_y = info_ptr->int_y_blue;
  163249. return (PNG_INFO_cHRM);
  163250. }
  163251. return (0);
  163252. }
  163253. #endif
  163254. #endif
  163255. #if defined(PNG_gAMA_SUPPORTED)
  163256. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163257. png_uint_32 PNGAPI
  163258. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163259. {
  163260. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163261. && file_gamma != NULL)
  163262. {
  163263. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163264. *file_gamma = (double)info_ptr->gamma;
  163265. return (PNG_INFO_gAMA);
  163266. }
  163267. return (0);
  163268. }
  163269. #endif
  163270. #ifdef PNG_FIXED_POINT_SUPPORTED
  163271. png_uint_32 PNGAPI
  163272. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163273. png_fixed_point *int_file_gamma)
  163274. {
  163275. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163276. && int_file_gamma != NULL)
  163277. {
  163278. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163279. *int_file_gamma = info_ptr->int_gamma;
  163280. return (PNG_INFO_gAMA);
  163281. }
  163282. return (0);
  163283. }
  163284. #endif
  163285. #endif
  163286. #if defined(PNG_sRGB_SUPPORTED)
  163287. png_uint_32 PNGAPI
  163288. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163289. {
  163290. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163291. && file_srgb_intent != NULL)
  163292. {
  163293. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163294. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163295. return (PNG_INFO_sRGB);
  163296. }
  163297. return (0);
  163298. }
  163299. #endif
  163300. #if defined(PNG_iCCP_SUPPORTED)
  163301. png_uint_32 PNGAPI
  163302. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163303. png_charpp name, int *compression_type,
  163304. png_charpp profile, png_uint_32 *proflen)
  163305. {
  163306. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163307. && name != NULL && profile != NULL && proflen != NULL)
  163308. {
  163309. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163310. *name = info_ptr->iccp_name;
  163311. *profile = info_ptr->iccp_profile;
  163312. *proflen = (int)info_ptr->iccp_proflen;
  163313. *compression_type = (int)info_ptr->iccp_compression;
  163314. return (PNG_INFO_iCCP);
  163315. }
  163316. return (0);
  163317. }
  163318. #endif
  163319. #if defined(PNG_sPLT_SUPPORTED)
  163320. png_uint_32 PNGAPI
  163321. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163322. png_sPLT_tpp spalettes)
  163323. {
  163324. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163325. {
  163326. *spalettes = info_ptr->splt_palettes;
  163327. return ((png_uint_32)info_ptr->splt_palettes_num);
  163328. }
  163329. return (0);
  163330. }
  163331. #endif
  163332. #if defined(PNG_hIST_SUPPORTED)
  163333. png_uint_32 PNGAPI
  163334. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163335. {
  163336. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163337. && hist != NULL)
  163338. {
  163339. png_debug1(1, "in %s retrieval function\n", "hIST");
  163340. *hist = info_ptr->hist;
  163341. return (PNG_INFO_hIST);
  163342. }
  163343. return (0);
  163344. }
  163345. #endif
  163346. png_uint_32 PNGAPI
  163347. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163348. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163349. int *color_type, int *interlace_type, int *compression_type,
  163350. int *filter_type)
  163351. {
  163352. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163353. bit_depth != NULL && color_type != NULL)
  163354. {
  163355. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163356. *width = info_ptr->width;
  163357. *height = info_ptr->height;
  163358. *bit_depth = info_ptr->bit_depth;
  163359. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163360. png_error(png_ptr, "Invalid bit depth");
  163361. *color_type = info_ptr->color_type;
  163362. if (info_ptr->color_type > 6)
  163363. png_error(png_ptr, "Invalid color type");
  163364. if (compression_type != NULL)
  163365. *compression_type = info_ptr->compression_type;
  163366. if (filter_type != NULL)
  163367. *filter_type = info_ptr->filter_type;
  163368. if (interlace_type != NULL)
  163369. *interlace_type = info_ptr->interlace_type;
  163370. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163371. png_error(png_ptr, "Invalid image width");
  163372. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163373. png_error(png_ptr, "Invalid image height");
  163374. if (info_ptr->width > (PNG_UINT_32_MAX
  163375. >> 3) /* 8-byte RGBA pixels */
  163376. - 64 /* bigrowbuf hack */
  163377. - 1 /* filter byte */
  163378. - 7*8 /* rounding of width to multiple of 8 pixels */
  163379. - 8) /* extra max_pixel_depth pad */
  163380. {
  163381. png_warning(png_ptr,
  163382. "Width too large for libpng to process image data.");
  163383. }
  163384. return (1);
  163385. }
  163386. return (0);
  163387. }
  163388. #if defined(PNG_oFFs_SUPPORTED)
  163389. png_uint_32 PNGAPI
  163390. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163391. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163392. {
  163393. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163394. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163395. {
  163396. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163397. *offset_x = info_ptr->x_offset;
  163398. *offset_y = info_ptr->y_offset;
  163399. *unit_type = (int)info_ptr->offset_unit_type;
  163400. return (PNG_INFO_oFFs);
  163401. }
  163402. return (0);
  163403. }
  163404. #endif
  163405. #if defined(PNG_pCAL_SUPPORTED)
  163406. png_uint_32 PNGAPI
  163407. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163408. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163409. png_charp *units, png_charpp *params)
  163410. {
  163411. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163412. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163413. nparams != NULL && units != NULL && params != NULL)
  163414. {
  163415. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163416. *purpose = info_ptr->pcal_purpose;
  163417. *X0 = info_ptr->pcal_X0;
  163418. *X1 = info_ptr->pcal_X1;
  163419. *type = (int)info_ptr->pcal_type;
  163420. *nparams = (int)info_ptr->pcal_nparams;
  163421. *units = info_ptr->pcal_units;
  163422. *params = info_ptr->pcal_params;
  163423. return (PNG_INFO_pCAL);
  163424. }
  163425. return (0);
  163426. }
  163427. #endif
  163428. #if defined(PNG_sCAL_SUPPORTED)
  163429. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163430. png_uint_32 PNGAPI
  163431. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163432. int *unit, double *width, double *height)
  163433. {
  163434. if (png_ptr != NULL && info_ptr != NULL &&
  163435. (info_ptr->valid & PNG_INFO_sCAL))
  163436. {
  163437. *unit = info_ptr->scal_unit;
  163438. *width = info_ptr->scal_pixel_width;
  163439. *height = info_ptr->scal_pixel_height;
  163440. return (PNG_INFO_sCAL);
  163441. }
  163442. return(0);
  163443. }
  163444. #else
  163445. #ifdef PNG_FIXED_POINT_SUPPORTED
  163446. png_uint_32 PNGAPI
  163447. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163448. int *unit, png_charpp width, png_charpp height)
  163449. {
  163450. if (png_ptr != NULL && info_ptr != NULL &&
  163451. (info_ptr->valid & PNG_INFO_sCAL))
  163452. {
  163453. *unit = info_ptr->scal_unit;
  163454. *width = info_ptr->scal_s_width;
  163455. *height = info_ptr->scal_s_height;
  163456. return (PNG_INFO_sCAL);
  163457. }
  163458. return(0);
  163459. }
  163460. #endif
  163461. #endif
  163462. #endif
  163463. #if defined(PNG_pHYs_SUPPORTED)
  163464. png_uint_32 PNGAPI
  163465. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163466. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163467. {
  163468. png_uint_32 retval = 0;
  163469. if (png_ptr != NULL && info_ptr != NULL &&
  163470. (info_ptr->valid & PNG_INFO_pHYs))
  163471. {
  163472. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163473. if (res_x != NULL)
  163474. {
  163475. *res_x = info_ptr->x_pixels_per_unit;
  163476. retval |= PNG_INFO_pHYs;
  163477. }
  163478. if (res_y != NULL)
  163479. {
  163480. *res_y = info_ptr->y_pixels_per_unit;
  163481. retval |= PNG_INFO_pHYs;
  163482. }
  163483. if (unit_type != NULL)
  163484. {
  163485. *unit_type = (int)info_ptr->phys_unit_type;
  163486. retval |= PNG_INFO_pHYs;
  163487. }
  163488. }
  163489. return (retval);
  163490. }
  163491. #endif
  163492. png_uint_32 PNGAPI
  163493. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163494. int *num_palette)
  163495. {
  163496. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163497. && palette != NULL)
  163498. {
  163499. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163500. *palette = info_ptr->palette;
  163501. *num_palette = info_ptr->num_palette;
  163502. png_debug1(3, "num_palette = %d\n", *num_palette);
  163503. return (PNG_INFO_PLTE);
  163504. }
  163505. return (0);
  163506. }
  163507. #if defined(PNG_sBIT_SUPPORTED)
  163508. png_uint_32 PNGAPI
  163509. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163510. {
  163511. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163512. && sig_bit != NULL)
  163513. {
  163514. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163515. *sig_bit = &(info_ptr->sig_bit);
  163516. return (PNG_INFO_sBIT);
  163517. }
  163518. return (0);
  163519. }
  163520. #endif
  163521. #if defined(PNG_TEXT_SUPPORTED)
  163522. png_uint_32 PNGAPI
  163523. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163524. int *num_text)
  163525. {
  163526. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163527. {
  163528. png_debug1(1, "in %s retrieval function\n",
  163529. (png_ptr->chunk_name[0] == '\0' ? "text"
  163530. : (png_const_charp)png_ptr->chunk_name));
  163531. if (text_ptr != NULL)
  163532. *text_ptr = info_ptr->text;
  163533. if (num_text != NULL)
  163534. *num_text = info_ptr->num_text;
  163535. return ((png_uint_32)info_ptr->num_text);
  163536. }
  163537. if (num_text != NULL)
  163538. *num_text = 0;
  163539. return(0);
  163540. }
  163541. #endif
  163542. #if defined(PNG_tIME_SUPPORTED)
  163543. png_uint_32 PNGAPI
  163544. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163545. {
  163546. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163547. && mod_time != NULL)
  163548. {
  163549. png_debug1(1, "in %s retrieval function\n", "tIME");
  163550. *mod_time = &(info_ptr->mod_time);
  163551. return (PNG_INFO_tIME);
  163552. }
  163553. return (0);
  163554. }
  163555. #endif
  163556. #if defined(PNG_tRNS_SUPPORTED)
  163557. png_uint_32 PNGAPI
  163558. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163559. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163560. {
  163561. png_uint_32 retval = 0;
  163562. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163563. {
  163564. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163565. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163566. {
  163567. if (trans != NULL)
  163568. {
  163569. *trans = info_ptr->trans;
  163570. retval |= PNG_INFO_tRNS;
  163571. }
  163572. if (trans_values != NULL)
  163573. *trans_values = &(info_ptr->trans_values);
  163574. }
  163575. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163576. {
  163577. if (trans_values != NULL)
  163578. {
  163579. *trans_values = &(info_ptr->trans_values);
  163580. retval |= PNG_INFO_tRNS;
  163581. }
  163582. if(trans != NULL)
  163583. *trans = NULL;
  163584. }
  163585. if(num_trans != NULL)
  163586. {
  163587. *num_trans = info_ptr->num_trans;
  163588. retval |= PNG_INFO_tRNS;
  163589. }
  163590. }
  163591. return (retval);
  163592. }
  163593. #endif
  163594. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163595. png_uint_32 PNGAPI
  163596. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163597. png_unknown_chunkpp unknowns)
  163598. {
  163599. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163600. {
  163601. *unknowns = info_ptr->unknown_chunks;
  163602. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163603. }
  163604. return (0);
  163605. }
  163606. #endif
  163607. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163608. png_byte PNGAPI
  163609. png_get_rgb_to_gray_status (png_structp png_ptr)
  163610. {
  163611. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163612. }
  163613. #endif
  163614. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163615. png_voidp PNGAPI
  163616. png_get_user_chunk_ptr(png_structp png_ptr)
  163617. {
  163618. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163619. }
  163620. #endif
  163621. #ifdef PNG_WRITE_SUPPORTED
  163622. png_uint_32 PNGAPI
  163623. png_get_compression_buffer_size(png_structp png_ptr)
  163624. {
  163625. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163626. }
  163627. #endif
  163628. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163629. #ifndef PNG_1_0_X
  163630. png_uint_32 PNGAPI
  163631. png_get_asm_flags (png_structp png_ptr)
  163632. {
  163633. return (png_ptr? 0L: 0L);
  163634. }
  163635. png_uint_32 PNGAPI
  163636. png_get_asm_flagmask (int flag_select)
  163637. {
  163638. flag_select=flag_select;
  163639. return 0L;
  163640. }
  163641. png_uint_32 PNGAPI
  163642. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163643. {
  163644. flag_select=flag_select;
  163645. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163646. return 0L;
  163647. }
  163648. png_byte PNGAPI
  163649. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163650. {
  163651. return (png_ptr? 0: 0);
  163652. }
  163653. png_uint_32 PNGAPI
  163654. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163655. {
  163656. return (png_ptr? 0L: 0L);
  163657. }
  163658. #endif /* ?PNG_1_0_X */
  163659. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163660. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163661. png_uint_32 PNGAPI
  163662. png_get_user_width_max (png_structp png_ptr)
  163663. {
  163664. return (png_ptr? png_ptr->user_width_max : 0);
  163665. }
  163666. png_uint_32 PNGAPI
  163667. png_get_user_height_max (png_structp png_ptr)
  163668. {
  163669. return (png_ptr? png_ptr->user_height_max : 0);
  163670. }
  163671. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163672. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163673. /*** End of inlined file: pngget.c ***/
  163674. /*** Start of inlined file: pngmem.c ***/
  163675. #define PNG_INTERNAL
  163676. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163677. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163678. png_voidp /* PRIVATE */
  163679. png_create_struct(int type)
  163680. {
  163681. #ifdef PNG_USER_MEM_SUPPORTED
  163682. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163683. }
  163684. png_voidp /* PRIVATE */
  163685. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163686. {
  163687. #endif /* PNG_USER_MEM_SUPPORTED */
  163688. png_size_t size;
  163689. png_voidp struct_ptr;
  163690. if (type == PNG_STRUCT_INFO)
  163691. size = png_sizeof(png_info);
  163692. else if (type == PNG_STRUCT_PNG)
  163693. size = png_sizeof(png_struct);
  163694. else
  163695. return (png_get_copyright(NULL));
  163696. #ifdef PNG_USER_MEM_SUPPORTED
  163697. if(malloc_fn != NULL)
  163698. {
  163699. png_struct dummy_struct;
  163700. png_structp png_ptr = &dummy_struct;
  163701. png_ptr->mem_ptr=mem_ptr;
  163702. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163703. }
  163704. else
  163705. #endif /* PNG_USER_MEM_SUPPORTED */
  163706. struct_ptr = (png_voidp)farmalloc(size);
  163707. if (struct_ptr != NULL)
  163708. png_memset(struct_ptr, 0, size);
  163709. return (struct_ptr);
  163710. }
  163711. void /* PRIVATE */
  163712. png_destroy_struct(png_voidp struct_ptr)
  163713. {
  163714. #ifdef PNG_USER_MEM_SUPPORTED
  163715. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163716. }
  163717. void /* PRIVATE */
  163718. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163719. png_voidp mem_ptr)
  163720. {
  163721. #endif
  163722. if (struct_ptr != NULL)
  163723. {
  163724. #ifdef PNG_USER_MEM_SUPPORTED
  163725. if(free_fn != NULL)
  163726. {
  163727. png_struct dummy_struct;
  163728. png_structp png_ptr = &dummy_struct;
  163729. png_ptr->mem_ptr=mem_ptr;
  163730. (*(free_fn))(png_ptr, struct_ptr);
  163731. return;
  163732. }
  163733. #endif /* PNG_USER_MEM_SUPPORTED */
  163734. farfree (struct_ptr);
  163735. }
  163736. }
  163737. png_voidp PNGAPI
  163738. png_malloc(png_structp png_ptr, png_uint_32 size)
  163739. {
  163740. png_voidp ret;
  163741. if (png_ptr == NULL || size == 0)
  163742. return (NULL);
  163743. #ifdef PNG_USER_MEM_SUPPORTED
  163744. if(png_ptr->malloc_fn != NULL)
  163745. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163746. else
  163747. ret = (png_malloc_default(png_ptr, size));
  163748. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163749. png_error(png_ptr, "Out of memory!");
  163750. return (ret);
  163751. }
  163752. png_voidp PNGAPI
  163753. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163754. {
  163755. png_voidp ret;
  163756. #endif /* PNG_USER_MEM_SUPPORTED */
  163757. if (png_ptr == NULL || size == 0)
  163758. return (NULL);
  163759. #ifdef PNG_MAX_MALLOC_64K
  163760. if (size > (png_uint_32)65536L)
  163761. {
  163762. png_warning(png_ptr, "Cannot Allocate > 64K");
  163763. ret = NULL;
  163764. }
  163765. else
  163766. #endif
  163767. if (size != (size_t)size)
  163768. ret = NULL;
  163769. else if (size == (png_uint_32)65536L)
  163770. {
  163771. if (png_ptr->offset_table == NULL)
  163772. {
  163773. ret = farmalloc(size);
  163774. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163775. {
  163776. int num_blocks;
  163777. png_uint_32 total_size;
  163778. png_bytep table;
  163779. int i;
  163780. png_byte huge * hptr;
  163781. if (ret != NULL)
  163782. {
  163783. farfree(ret);
  163784. ret = NULL;
  163785. }
  163786. if(png_ptr->zlib_window_bits > 14)
  163787. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163788. else
  163789. num_blocks = 1;
  163790. if (png_ptr->zlib_mem_level >= 7)
  163791. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163792. else
  163793. num_blocks++;
  163794. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163795. table = farmalloc(total_size);
  163796. if (table == NULL)
  163797. {
  163798. #ifndef PNG_USER_MEM_SUPPORTED
  163799. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163800. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163801. else
  163802. png_warning(png_ptr, "Out Of Memory.");
  163803. #endif
  163804. return (NULL);
  163805. }
  163806. if ((png_size_t)table & 0xfff0)
  163807. {
  163808. #ifndef PNG_USER_MEM_SUPPORTED
  163809. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163810. png_error(png_ptr,
  163811. "Farmalloc didn't return normalized pointer");
  163812. else
  163813. png_warning(png_ptr,
  163814. "Farmalloc didn't return normalized pointer");
  163815. #endif
  163816. return (NULL);
  163817. }
  163818. png_ptr->offset_table = table;
  163819. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  163820. png_sizeof (png_bytep));
  163821. if (png_ptr->offset_table_ptr == NULL)
  163822. {
  163823. #ifndef PNG_USER_MEM_SUPPORTED
  163824. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163825. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  163826. else
  163827. png_warning(png_ptr, "Out Of memory.");
  163828. #endif
  163829. return (NULL);
  163830. }
  163831. hptr = (png_byte huge *)table;
  163832. if ((png_size_t)hptr & 0xf)
  163833. {
  163834. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  163835. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  163836. }
  163837. for (i = 0; i < num_blocks; i++)
  163838. {
  163839. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  163840. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  163841. }
  163842. png_ptr->offset_table_number = num_blocks;
  163843. png_ptr->offset_table_count = 0;
  163844. png_ptr->offset_table_count_free = 0;
  163845. }
  163846. }
  163847. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  163848. {
  163849. #ifndef PNG_USER_MEM_SUPPORTED
  163850. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163851. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  163852. else
  163853. png_warning(png_ptr, "Out of Memory.");
  163854. #endif
  163855. return (NULL);
  163856. }
  163857. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  163858. }
  163859. else
  163860. ret = farmalloc(size);
  163861. #ifndef PNG_USER_MEM_SUPPORTED
  163862. if (ret == NULL)
  163863. {
  163864. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163865. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163866. else
  163867. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163868. }
  163869. #endif
  163870. return (ret);
  163871. }
  163872. void PNGAPI
  163873. png_free(png_structp png_ptr, png_voidp ptr)
  163874. {
  163875. if (png_ptr == NULL || ptr == NULL)
  163876. return;
  163877. #ifdef PNG_USER_MEM_SUPPORTED
  163878. if (png_ptr->free_fn != NULL)
  163879. {
  163880. (*(png_ptr->free_fn))(png_ptr, ptr);
  163881. return;
  163882. }
  163883. else png_free_default(png_ptr, ptr);
  163884. }
  163885. void PNGAPI
  163886. png_free_default(png_structp png_ptr, png_voidp ptr)
  163887. {
  163888. #endif /* PNG_USER_MEM_SUPPORTED */
  163889. if(png_ptr == NULL) return;
  163890. if (png_ptr->offset_table != NULL)
  163891. {
  163892. int i;
  163893. for (i = 0; i < png_ptr->offset_table_count; i++)
  163894. {
  163895. if (ptr == png_ptr->offset_table_ptr[i])
  163896. {
  163897. ptr = NULL;
  163898. png_ptr->offset_table_count_free++;
  163899. break;
  163900. }
  163901. }
  163902. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  163903. {
  163904. farfree(png_ptr->offset_table);
  163905. farfree(png_ptr->offset_table_ptr);
  163906. png_ptr->offset_table = NULL;
  163907. png_ptr->offset_table_ptr = NULL;
  163908. }
  163909. }
  163910. if (ptr != NULL)
  163911. {
  163912. farfree(ptr);
  163913. }
  163914. }
  163915. #else /* Not the Borland DOS special memory handler */
  163916. png_voidp /* PRIVATE */
  163917. png_create_struct(int type)
  163918. {
  163919. #ifdef PNG_USER_MEM_SUPPORTED
  163920. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163921. }
  163922. png_voidp /* PRIVATE */
  163923. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163924. {
  163925. #endif /* PNG_USER_MEM_SUPPORTED */
  163926. png_size_t size;
  163927. png_voidp struct_ptr;
  163928. if (type == PNG_STRUCT_INFO)
  163929. size = png_sizeof(png_info);
  163930. else if (type == PNG_STRUCT_PNG)
  163931. size = png_sizeof(png_struct);
  163932. else
  163933. return (NULL);
  163934. #ifdef PNG_USER_MEM_SUPPORTED
  163935. if(malloc_fn != NULL)
  163936. {
  163937. png_struct dummy_struct;
  163938. png_structp png_ptr = &dummy_struct;
  163939. png_ptr->mem_ptr=mem_ptr;
  163940. struct_ptr = (*(malloc_fn))(png_ptr, size);
  163941. if (struct_ptr != NULL)
  163942. png_memset(struct_ptr, 0, size);
  163943. return (struct_ptr);
  163944. }
  163945. #endif /* PNG_USER_MEM_SUPPORTED */
  163946. #if defined(__TURBOC__) && !defined(__FLAT__)
  163947. struct_ptr = (png_voidp)farmalloc(size);
  163948. #else
  163949. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  163950. struct_ptr = (png_voidp)halloc(size,1);
  163951. # else
  163952. struct_ptr = (png_voidp)malloc(size);
  163953. # endif
  163954. #endif
  163955. if (struct_ptr != NULL)
  163956. png_memset(struct_ptr, 0, size);
  163957. return (struct_ptr);
  163958. }
  163959. void /* PRIVATE */
  163960. png_destroy_struct(png_voidp struct_ptr)
  163961. {
  163962. #ifdef PNG_USER_MEM_SUPPORTED
  163963. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163964. }
  163965. void /* PRIVATE */
  163966. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163967. png_voidp mem_ptr)
  163968. {
  163969. #endif /* PNG_USER_MEM_SUPPORTED */
  163970. if (struct_ptr != NULL)
  163971. {
  163972. #ifdef PNG_USER_MEM_SUPPORTED
  163973. if(free_fn != NULL)
  163974. {
  163975. png_struct dummy_struct;
  163976. png_structp png_ptr = &dummy_struct;
  163977. png_ptr->mem_ptr=mem_ptr;
  163978. (*(free_fn))(png_ptr, struct_ptr);
  163979. return;
  163980. }
  163981. #endif /* PNG_USER_MEM_SUPPORTED */
  163982. #if defined(__TURBOC__) && !defined(__FLAT__)
  163983. farfree(struct_ptr);
  163984. #else
  163985. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  163986. hfree(struct_ptr);
  163987. # else
  163988. free(struct_ptr);
  163989. # endif
  163990. #endif
  163991. }
  163992. }
  163993. png_voidp PNGAPI
  163994. png_malloc(png_structp png_ptr, png_uint_32 size)
  163995. {
  163996. png_voidp ret;
  163997. #ifdef PNG_USER_MEM_SUPPORTED
  163998. if (png_ptr == NULL || size == 0)
  163999. return (NULL);
  164000. if(png_ptr->malloc_fn != NULL)
  164001. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164002. else
  164003. ret = (png_malloc_default(png_ptr, size));
  164004. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164005. png_error(png_ptr, "Out of Memory!");
  164006. return (ret);
  164007. }
  164008. png_voidp PNGAPI
  164009. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164010. {
  164011. png_voidp ret;
  164012. #endif /* PNG_USER_MEM_SUPPORTED */
  164013. if (png_ptr == NULL || size == 0)
  164014. return (NULL);
  164015. #ifdef PNG_MAX_MALLOC_64K
  164016. if (size > (png_uint_32)65536L)
  164017. {
  164018. #ifndef PNG_USER_MEM_SUPPORTED
  164019. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164020. png_error(png_ptr, "Cannot Allocate > 64K");
  164021. else
  164022. #endif
  164023. return NULL;
  164024. }
  164025. #endif
  164026. #if defined(__TURBOC__) && !defined(__FLAT__)
  164027. if (size != (unsigned long)size)
  164028. ret = NULL;
  164029. else
  164030. ret = farmalloc(size);
  164031. #else
  164032. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164033. if (size != (unsigned long)size)
  164034. ret = NULL;
  164035. else
  164036. ret = halloc(size, 1);
  164037. # else
  164038. if (size != (size_t)size)
  164039. ret = NULL;
  164040. else
  164041. ret = malloc((size_t)size);
  164042. # endif
  164043. #endif
  164044. #ifndef PNG_USER_MEM_SUPPORTED
  164045. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164046. png_error(png_ptr, "Out of Memory");
  164047. #endif
  164048. return (ret);
  164049. }
  164050. void PNGAPI
  164051. png_free(png_structp png_ptr, png_voidp ptr)
  164052. {
  164053. if (png_ptr == NULL || ptr == NULL)
  164054. return;
  164055. #ifdef PNG_USER_MEM_SUPPORTED
  164056. if (png_ptr->free_fn != NULL)
  164057. {
  164058. (*(png_ptr->free_fn))(png_ptr, ptr);
  164059. return;
  164060. }
  164061. else png_free_default(png_ptr, ptr);
  164062. }
  164063. void PNGAPI
  164064. png_free_default(png_structp png_ptr, png_voidp ptr)
  164065. {
  164066. if (png_ptr == NULL || ptr == NULL)
  164067. return;
  164068. #endif /* PNG_USER_MEM_SUPPORTED */
  164069. #if defined(__TURBOC__) && !defined(__FLAT__)
  164070. farfree(ptr);
  164071. #else
  164072. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164073. hfree(ptr);
  164074. # else
  164075. free(ptr);
  164076. # endif
  164077. #endif
  164078. }
  164079. #endif /* Not Borland DOS special memory handler */
  164080. #if defined(PNG_1_0_X)
  164081. # define png_malloc_warn png_malloc
  164082. #else
  164083. png_voidp PNGAPI
  164084. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164085. {
  164086. png_voidp ptr;
  164087. png_uint_32 save_flags;
  164088. if(png_ptr == NULL) return (NULL);
  164089. save_flags=png_ptr->flags;
  164090. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164091. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164092. png_ptr->flags=save_flags;
  164093. return(ptr);
  164094. }
  164095. #endif
  164096. png_voidp PNGAPI
  164097. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164098. png_uint_32 length)
  164099. {
  164100. png_size_t size;
  164101. size = (png_size_t)length;
  164102. if ((png_uint_32)size != length)
  164103. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164104. return(png_memcpy (s1, s2, size));
  164105. }
  164106. png_voidp PNGAPI
  164107. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164108. png_uint_32 length)
  164109. {
  164110. png_size_t size;
  164111. size = (png_size_t)length;
  164112. if ((png_uint_32)size != length)
  164113. png_error(png_ptr,"Overflow in png_memset_check.");
  164114. return (png_memset (s1, value, size));
  164115. }
  164116. #ifdef PNG_USER_MEM_SUPPORTED
  164117. void PNGAPI
  164118. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164119. malloc_fn, png_free_ptr free_fn)
  164120. {
  164121. if(png_ptr != NULL) {
  164122. png_ptr->mem_ptr = mem_ptr;
  164123. png_ptr->malloc_fn = malloc_fn;
  164124. png_ptr->free_fn = free_fn;
  164125. }
  164126. }
  164127. png_voidp PNGAPI
  164128. png_get_mem_ptr(png_structp png_ptr)
  164129. {
  164130. if(png_ptr == NULL) return (NULL);
  164131. return ((png_voidp)png_ptr->mem_ptr);
  164132. }
  164133. #endif /* PNG_USER_MEM_SUPPORTED */
  164134. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164135. /*** End of inlined file: pngmem.c ***/
  164136. /*** Start of inlined file: pngread.c ***/
  164137. #define PNG_INTERNAL
  164138. #if defined(PNG_READ_SUPPORTED)
  164139. png_structp PNGAPI
  164140. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164141. png_error_ptr error_fn, png_error_ptr warn_fn)
  164142. {
  164143. #ifdef PNG_USER_MEM_SUPPORTED
  164144. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164145. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164146. }
  164147. png_structp PNGAPI
  164148. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164149. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164150. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164151. {
  164152. #endif /* PNG_USER_MEM_SUPPORTED */
  164153. png_structp png_ptr;
  164154. #ifdef PNG_SETJMP_SUPPORTED
  164155. #ifdef USE_FAR_KEYWORD
  164156. jmp_buf jmpbuf;
  164157. #endif
  164158. #endif
  164159. int i;
  164160. png_debug(1, "in png_create_read_struct\n");
  164161. #ifdef PNG_USER_MEM_SUPPORTED
  164162. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164163. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164164. #else
  164165. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164166. #endif
  164167. if (png_ptr == NULL)
  164168. return (NULL);
  164169. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164170. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164171. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164172. #endif
  164173. #ifdef PNG_SETJMP_SUPPORTED
  164174. #ifdef USE_FAR_KEYWORD
  164175. if (setjmp(jmpbuf))
  164176. #else
  164177. if (setjmp(png_ptr->jmpbuf))
  164178. #endif
  164179. {
  164180. png_free(png_ptr, png_ptr->zbuf);
  164181. png_ptr->zbuf=NULL;
  164182. #ifdef PNG_USER_MEM_SUPPORTED
  164183. png_destroy_struct_2((png_voidp)png_ptr,
  164184. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164185. #else
  164186. png_destroy_struct((png_voidp)png_ptr);
  164187. #endif
  164188. return (NULL);
  164189. }
  164190. #ifdef USE_FAR_KEYWORD
  164191. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164192. #endif
  164193. #endif
  164194. #ifdef PNG_USER_MEM_SUPPORTED
  164195. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164196. #endif
  164197. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164198. i=0;
  164199. do
  164200. {
  164201. if(user_png_ver[i] != png_libpng_ver[i])
  164202. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164203. } while (png_libpng_ver[i++]);
  164204. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164205. {
  164206. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164207. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164208. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164209. {
  164210. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164211. char msg[80];
  164212. if (user_png_ver)
  164213. {
  164214. png_snprintf(msg, 80,
  164215. "Application was compiled with png.h from libpng-%.20s",
  164216. user_png_ver);
  164217. png_warning(png_ptr, msg);
  164218. }
  164219. png_snprintf(msg, 80,
  164220. "Application is running with png.c from libpng-%.20s",
  164221. png_libpng_ver);
  164222. png_warning(png_ptr, msg);
  164223. #endif
  164224. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164225. png_ptr->flags=0;
  164226. #endif
  164227. png_error(png_ptr,
  164228. "Incompatible libpng version in application and library");
  164229. }
  164230. }
  164231. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164232. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164233. (png_uint_32)png_ptr->zbuf_size);
  164234. png_ptr->zstream.zalloc = png_zalloc;
  164235. png_ptr->zstream.zfree = png_zfree;
  164236. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164237. switch (inflateInit(&png_ptr->zstream))
  164238. {
  164239. case Z_OK: /* Do nothing */ break;
  164240. case Z_MEM_ERROR:
  164241. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164242. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164243. default: png_error(png_ptr, "Unknown zlib error");
  164244. }
  164245. png_ptr->zstream.next_out = png_ptr->zbuf;
  164246. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164247. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164248. #ifdef PNG_SETJMP_SUPPORTED
  164249. #ifdef USE_FAR_KEYWORD
  164250. if (setjmp(jmpbuf))
  164251. PNG_ABORT();
  164252. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164253. #else
  164254. if (setjmp(png_ptr->jmpbuf))
  164255. PNG_ABORT();
  164256. #endif
  164257. #endif
  164258. return (png_ptr);
  164259. }
  164260. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164261. #undef png_read_init
  164262. void PNGAPI
  164263. png_read_init(png_structp png_ptr)
  164264. {
  164265. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164266. }
  164267. void PNGAPI
  164268. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164269. png_size_t png_struct_size, png_size_t png_info_size)
  164270. {
  164271. if(png_ptr == NULL) return;
  164272. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164273. if(png_sizeof(png_struct) > png_struct_size ||
  164274. png_sizeof(png_info) > png_info_size)
  164275. {
  164276. char msg[80];
  164277. png_ptr->warning_fn=NULL;
  164278. if (user_png_ver)
  164279. {
  164280. png_snprintf(msg, 80,
  164281. "Application was compiled with png.h from libpng-%.20s",
  164282. user_png_ver);
  164283. png_warning(png_ptr, msg);
  164284. }
  164285. png_snprintf(msg, 80,
  164286. "Application is running with png.c from libpng-%.20s",
  164287. png_libpng_ver);
  164288. png_warning(png_ptr, msg);
  164289. }
  164290. #endif
  164291. if(png_sizeof(png_struct) > png_struct_size)
  164292. {
  164293. png_ptr->error_fn=NULL;
  164294. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164295. png_ptr->flags=0;
  164296. #endif
  164297. png_error(png_ptr,
  164298. "The png struct allocated by the application for reading is too small.");
  164299. }
  164300. if(png_sizeof(png_info) > png_info_size)
  164301. {
  164302. png_ptr->error_fn=NULL;
  164303. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164304. png_ptr->flags=0;
  164305. #endif
  164306. png_error(png_ptr,
  164307. "The info struct allocated by application for reading is too small.");
  164308. }
  164309. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164310. }
  164311. #endif /* PNG_1_0_X || PNG_1_2_X */
  164312. void PNGAPI
  164313. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164314. png_size_t png_struct_size)
  164315. {
  164316. #ifdef PNG_SETJMP_SUPPORTED
  164317. jmp_buf tmp_jmp; /* to save current jump buffer */
  164318. #endif
  164319. int i=0;
  164320. png_structp png_ptr=*ptr_ptr;
  164321. if(png_ptr == NULL) return;
  164322. do
  164323. {
  164324. if(user_png_ver[i] != png_libpng_ver[i])
  164325. {
  164326. #ifdef PNG_LEGACY_SUPPORTED
  164327. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164328. #else
  164329. png_ptr->warning_fn=NULL;
  164330. png_warning(png_ptr,
  164331. "Application uses deprecated png_read_init() and should be recompiled.");
  164332. break;
  164333. #endif
  164334. }
  164335. } while (png_libpng_ver[i++]);
  164336. png_debug(1, "in png_read_init_3\n");
  164337. #ifdef PNG_SETJMP_SUPPORTED
  164338. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164339. #endif
  164340. if(png_sizeof(png_struct) > png_struct_size)
  164341. {
  164342. png_destroy_struct(png_ptr);
  164343. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164344. png_ptr = *ptr_ptr;
  164345. }
  164346. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164347. #ifdef PNG_SETJMP_SUPPORTED
  164348. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164349. #endif
  164350. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164351. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164352. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164353. #endif
  164354. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164355. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164356. (png_uint_32)png_ptr->zbuf_size);
  164357. png_ptr->zstream.zalloc = png_zalloc;
  164358. png_ptr->zstream.zfree = png_zfree;
  164359. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164360. switch (inflateInit(&png_ptr->zstream))
  164361. {
  164362. case Z_OK: /* Do nothing */ break;
  164363. case Z_MEM_ERROR:
  164364. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164365. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164366. default: png_error(png_ptr, "Unknown zlib error");
  164367. }
  164368. png_ptr->zstream.next_out = png_ptr->zbuf;
  164369. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164370. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164371. }
  164372. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164373. void PNGAPI
  164374. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164375. {
  164376. if(png_ptr == NULL) return;
  164377. png_debug(1, "in png_read_info\n");
  164378. if (png_ptr->sig_bytes < 8)
  164379. {
  164380. png_size_t num_checked = png_ptr->sig_bytes,
  164381. num_to_check = 8 - num_checked;
  164382. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164383. png_ptr->sig_bytes = 8;
  164384. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164385. {
  164386. if (num_checked < 4 &&
  164387. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164388. png_error(png_ptr, "Not a PNG file");
  164389. else
  164390. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164391. }
  164392. if (num_checked < 3)
  164393. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164394. }
  164395. for(;;)
  164396. {
  164397. #ifdef PNG_USE_LOCAL_ARRAYS
  164398. PNG_CONST PNG_IHDR;
  164399. PNG_CONST PNG_IDAT;
  164400. PNG_CONST PNG_IEND;
  164401. PNG_CONST PNG_PLTE;
  164402. #if defined(PNG_READ_bKGD_SUPPORTED)
  164403. PNG_CONST PNG_bKGD;
  164404. #endif
  164405. #if defined(PNG_READ_cHRM_SUPPORTED)
  164406. PNG_CONST PNG_cHRM;
  164407. #endif
  164408. #if defined(PNG_READ_gAMA_SUPPORTED)
  164409. PNG_CONST PNG_gAMA;
  164410. #endif
  164411. #if defined(PNG_READ_hIST_SUPPORTED)
  164412. PNG_CONST PNG_hIST;
  164413. #endif
  164414. #if defined(PNG_READ_iCCP_SUPPORTED)
  164415. PNG_CONST PNG_iCCP;
  164416. #endif
  164417. #if defined(PNG_READ_iTXt_SUPPORTED)
  164418. PNG_CONST PNG_iTXt;
  164419. #endif
  164420. #if defined(PNG_READ_oFFs_SUPPORTED)
  164421. PNG_CONST PNG_oFFs;
  164422. #endif
  164423. #if defined(PNG_READ_pCAL_SUPPORTED)
  164424. PNG_CONST PNG_pCAL;
  164425. #endif
  164426. #if defined(PNG_READ_pHYs_SUPPORTED)
  164427. PNG_CONST PNG_pHYs;
  164428. #endif
  164429. #if defined(PNG_READ_sBIT_SUPPORTED)
  164430. PNG_CONST PNG_sBIT;
  164431. #endif
  164432. #if defined(PNG_READ_sCAL_SUPPORTED)
  164433. PNG_CONST PNG_sCAL;
  164434. #endif
  164435. #if defined(PNG_READ_sPLT_SUPPORTED)
  164436. PNG_CONST PNG_sPLT;
  164437. #endif
  164438. #if defined(PNG_READ_sRGB_SUPPORTED)
  164439. PNG_CONST PNG_sRGB;
  164440. #endif
  164441. #if defined(PNG_READ_tEXt_SUPPORTED)
  164442. PNG_CONST PNG_tEXt;
  164443. #endif
  164444. #if defined(PNG_READ_tIME_SUPPORTED)
  164445. PNG_CONST PNG_tIME;
  164446. #endif
  164447. #if defined(PNG_READ_tRNS_SUPPORTED)
  164448. PNG_CONST PNG_tRNS;
  164449. #endif
  164450. #if defined(PNG_READ_zTXt_SUPPORTED)
  164451. PNG_CONST PNG_zTXt;
  164452. #endif
  164453. #endif /* PNG_USE_LOCAL_ARRAYS */
  164454. png_byte chunk_length[4];
  164455. png_uint_32 length;
  164456. png_read_data(png_ptr, chunk_length, 4);
  164457. length = png_get_uint_31(png_ptr,chunk_length);
  164458. png_reset_crc(png_ptr);
  164459. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164460. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164461. length);
  164462. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164463. if(png_ptr->mode & PNG_AFTER_IDAT)
  164464. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164465. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164466. png_handle_IHDR(png_ptr, info_ptr, length);
  164467. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164468. png_handle_IEND(png_ptr, info_ptr, length);
  164469. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164470. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164471. {
  164472. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164473. png_ptr->mode |= PNG_HAVE_IDAT;
  164474. png_handle_unknown(png_ptr, info_ptr, length);
  164475. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164476. png_ptr->mode |= PNG_HAVE_PLTE;
  164477. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164478. {
  164479. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164480. png_error(png_ptr, "Missing IHDR before IDAT");
  164481. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164482. !(png_ptr->mode & PNG_HAVE_PLTE))
  164483. png_error(png_ptr, "Missing PLTE before IDAT");
  164484. break;
  164485. }
  164486. }
  164487. #endif
  164488. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164489. png_handle_PLTE(png_ptr, info_ptr, length);
  164490. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164491. {
  164492. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164493. png_error(png_ptr, "Missing IHDR before IDAT");
  164494. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164495. !(png_ptr->mode & PNG_HAVE_PLTE))
  164496. png_error(png_ptr, "Missing PLTE before IDAT");
  164497. png_ptr->idat_size = length;
  164498. png_ptr->mode |= PNG_HAVE_IDAT;
  164499. break;
  164500. }
  164501. #if defined(PNG_READ_bKGD_SUPPORTED)
  164502. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164503. png_handle_bKGD(png_ptr, info_ptr, length);
  164504. #endif
  164505. #if defined(PNG_READ_cHRM_SUPPORTED)
  164506. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164507. png_handle_cHRM(png_ptr, info_ptr, length);
  164508. #endif
  164509. #if defined(PNG_READ_gAMA_SUPPORTED)
  164510. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164511. png_handle_gAMA(png_ptr, info_ptr, length);
  164512. #endif
  164513. #if defined(PNG_READ_hIST_SUPPORTED)
  164514. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164515. png_handle_hIST(png_ptr, info_ptr, length);
  164516. #endif
  164517. #if defined(PNG_READ_oFFs_SUPPORTED)
  164518. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164519. png_handle_oFFs(png_ptr, info_ptr, length);
  164520. #endif
  164521. #if defined(PNG_READ_pCAL_SUPPORTED)
  164522. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164523. png_handle_pCAL(png_ptr, info_ptr, length);
  164524. #endif
  164525. #if defined(PNG_READ_sCAL_SUPPORTED)
  164526. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164527. png_handle_sCAL(png_ptr, info_ptr, length);
  164528. #endif
  164529. #if defined(PNG_READ_pHYs_SUPPORTED)
  164530. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164531. png_handle_pHYs(png_ptr, info_ptr, length);
  164532. #endif
  164533. #if defined(PNG_READ_sBIT_SUPPORTED)
  164534. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164535. png_handle_sBIT(png_ptr, info_ptr, length);
  164536. #endif
  164537. #if defined(PNG_READ_sRGB_SUPPORTED)
  164538. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164539. png_handle_sRGB(png_ptr, info_ptr, length);
  164540. #endif
  164541. #if defined(PNG_READ_iCCP_SUPPORTED)
  164542. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164543. png_handle_iCCP(png_ptr, info_ptr, length);
  164544. #endif
  164545. #if defined(PNG_READ_sPLT_SUPPORTED)
  164546. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164547. png_handle_sPLT(png_ptr, info_ptr, length);
  164548. #endif
  164549. #if defined(PNG_READ_tEXt_SUPPORTED)
  164550. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164551. png_handle_tEXt(png_ptr, info_ptr, length);
  164552. #endif
  164553. #if defined(PNG_READ_tIME_SUPPORTED)
  164554. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164555. png_handle_tIME(png_ptr, info_ptr, length);
  164556. #endif
  164557. #if defined(PNG_READ_tRNS_SUPPORTED)
  164558. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164559. png_handle_tRNS(png_ptr, info_ptr, length);
  164560. #endif
  164561. #if defined(PNG_READ_zTXt_SUPPORTED)
  164562. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164563. png_handle_zTXt(png_ptr, info_ptr, length);
  164564. #endif
  164565. #if defined(PNG_READ_iTXt_SUPPORTED)
  164566. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164567. png_handle_iTXt(png_ptr, info_ptr, length);
  164568. #endif
  164569. else
  164570. png_handle_unknown(png_ptr, info_ptr, length);
  164571. }
  164572. }
  164573. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164574. void PNGAPI
  164575. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164576. {
  164577. png_debug(1, "in png_read_update_info\n");
  164578. if(png_ptr == NULL) return;
  164579. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164580. png_read_start_row(png_ptr);
  164581. else
  164582. png_warning(png_ptr,
  164583. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164584. png_read_transform_info(png_ptr, info_ptr);
  164585. }
  164586. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164587. void PNGAPI
  164588. png_start_read_image(png_structp png_ptr)
  164589. {
  164590. png_debug(1, "in png_start_read_image\n");
  164591. if(png_ptr == NULL) return;
  164592. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164593. png_read_start_row(png_ptr);
  164594. }
  164595. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164596. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164597. void PNGAPI
  164598. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164599. {
  164600. #ifdef PNG_USE_LOCAL_ARRAYS
  164601. PNG_CONST PNG_IDAT;
  164602. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164603. 0xff};
  164604. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164605. #endif
  164606. int ret;
  164607. if(png_ptr == NULL) return;
  164608. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164609. png_ptr->row_number, png_ptr->pass);
  164610. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164611. png_read_start_row(png_ptr);
  164612. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164613. {
  164614. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164615. if (png_ptr->transformations & PNG_INVERT_MONO)
  164616. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164617. #endif
  164618. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164619. if (png_ptr->transformations & PNG_FILLER)
  164620. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164621. #endif
  164622. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164623. if (png_ptr->transformations & PNG_PACKSWAP)
  164624. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164625. #endif
  164626. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164627. if (png_ptr->transformations & PNG_PACK)
  164628. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164629. #endif
  164630. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164631. if (png_ptr->transformations & PNG_SHIFT)
  164632. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164633. #endif
  164634. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164635. if (png_ptr->transformations & PNG_BGR)
  164636. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164637. #endif
  164638. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164639. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164640. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164641. #endif
  164642. }
  164643. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164644. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164645. {
  164646. switch (png_ptr->pass)
  164647. {
  164648. case 0:
  164649. if (png_ptr->row_number & 0x07)
  164650. {
  164651. if (dsp_row != NULL)
  164652. png_combine_row(png_ptr, dsp_row,
  164653. png_pass_dsp_mask[png_ptr->pass]);
  164654. png_read_finish_row(png_ptr);
  164655. return;
  164656. }
  164657. break;
  164658. case 1:
  164659. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164660. {
  164661. if (dsp_row != NULL)
  164662. png_combine_row(png_ptr, dsp_row,
  164663. png_pass_dsp_mask[png_ptr->pass]);
  164664. png_read_finish_row(png_ptr);
  164665. return;
  164666. }
  164667. break;
  164668. case 2:
  164669. if ((png_ptr->row_number & 0x07) != 4)
  164670. {
  164671. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164672. png_combine_row(png_ptr, dsp_row,
  164673. png_pass_dsp_mask[png_ptr->pass]);
  164674. png_read_finish_row(png_ptr);
  164675. return;
  164676. }
  164677. break;
  164678. case 3:
  164679. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164680. {
  164681. if (dsp_row != NULL)
  164682. png_combine_row(png_ptr, dsp_row,
  164683. png_pass_dsp_mask[png_ptr->pass]);
  164684. png_read_finish_row(png_ptr);
  164685. return;
  164686. }
  164687. break;
  164688. case 4:
  164689. if ((png_ptr->row_number & 3) != 2)
  164690. {
  164691. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164692. png_combine_row(png_ptr, dsp_row,
  164693. png_pass_dsp_mask[png_ptr->pass]);
  164694. png_read_finish_row(png_ptr);
  164695. return;
  164696. }
  164697. break;
  164698. case 5:
  164699. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164700. {
  164701. if (dsp_row != NULL)
  164702. png_combine_row(png_ptr, dsp_row,
  164703. png_pass_dsp_mask[png_ptr->pass]);
  164704. png_read_finish_row(png_ptr);
  164705. return;
  164706. }
  164707. break;
  164708. case 6:
  164709. if (!(png_ptr->row_number & 1))
  164710. {
  164711. png_read_finish_row(png_ptr);
  164712. return;
  164713. }
  164714. break;
  164715. }
  164716. }
  164717. #endif
  164718. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164719. png_error(png_ptr, "Invalid attempt to read row data");
  164720. png_ptr->zstream.next_out = png_ptr->row_buf;
  164721. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164722. do
  164723. {
  164724. if (!(png_ptr->zstream.avail_in))
  164725. {
  164726. while (!png_ptr->idat_size)
  164727. {
  164728. png_byte chunk_length[4];
  164729. png_crc_finish(png_ptr, 0);
  164730. png_read_data(png_ptr, chunk_length, 4);
  164731. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164732. png_reset_crc(png_ptr);
  164733. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164734. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164735. png_error(png_ptr, "Not enough image data");
  164736. }
  164737. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164738. png_ptr->zstream.next_in = png_ptr->zbuf;
  164739. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164740. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164741. png_crc_read(png_ptr, png_ptr->zbuf,
  164742. (png_size_t)png_ptr->zstream.avail_in);
  164743. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164744. }
  164745. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164746. if (ret == Z_STREAM_END)
  164747. {
  164748. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164749. png_ptr->idat_size)
  164750. png_error(png_ptr, "Extra compressed data");
  164751. png_ptr->mode |= PNG_AFTER_IDAT;
  164752. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164753. break;
  164754. }
  164755. if (ret != Z_OK)
  164756. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164757. "Decompression error");
  164758. } while (png_ptr->zstream.avail_out);
  164759. png_ptr->row_info.color_type = png_ptr->color_type;
  164760. png_ptr->row_info.width = png_ptr->iwidth;
  164761. png_ptr->row_info.channels = png_ptr->channels;
  164762. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164763. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164764. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164765. png_ptr->row_info.width);
  164766. if(png_ptr->row_buf[0])
  164767. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164768. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164769. (int)(png_ptr->row_buf[0]));
  164770. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164771. png_ptr->rowbytes + 1);
  164772. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164773. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164774. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164775. {
  164776. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164777. }
  164778. #endif
  164779. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164780. png_do_read_transformations(png_ptr);
  164781. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164782. if (png_ptr->interlaced &&
  164783. (png_ptr->transformations & PNG_INTERLACE))
  164784. {
  164785. if (png_ptr->pass < 6)
  164786. png_do_read_interlace(png_ptr);
  164787. if (dsp_row != NULL)
  164788. png_combine_row(png_ptr, dsp_row,
  164789. png_pass_dsp_mask[png_ptr->pass]);
  164790. if (row != NULL)
  164791. png_combine_row(png_ptr, row,
  164792. png_pass_mask[png_ptr->pass]);
  164793. }
  164794. else
  164795. #endif
  164796. {
  164797. if (row != NULL)
  164798. png_combine_row(png_ptr, row, 0xff);
  164799. if (dsp_row != NULL)
  164800. png_combine_row(png_ptr, dsp_row, 0xff);
  164801. }
  164802. png_read_finish_row(png_ptr);
  164803. if (png_ptr->read_row_fn != NULL)
  164804. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164805. }
  164806. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164807. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164808. void PNGAPI
  164809. png_read_rows(png_structp png_ptr, png_bytepp row,
  164810. png_bytepp display_row, png_uint_32 num_rows)
  164811. {
  164812. png_uint_32 i;
  164813. png_bytepp rp;
  164814. png_bytepp dp;
  164815. png_debug(1, "in png_read_rows\n");
  164816. if(png_ptr == NULL) return;
  164817. rp = row;
  164818. dp = display_row;
  164819. if (rp != NULL && dp != NULL)
  164820. for (i = 0; i < num_rows; i++)
  164821. {
  164822. png_bytep rptr = *rp++;
  164823. png_bytep dptr = *dp++;
  164824. png_read_row(png_ptr, rptr, dptr);
  164825. }
  164826. else if(rp != NULL)
  164827. for (i = 0; i < num_rows; i++)
  164828. {
  164829. png_bytep rptr = *rp;
  164830. png_read_row(png_ptr, rptr, png_bytep_NULL);
  164831. rp++;
  164832. }
  164833. else if(dp != NULL)
  164834. for (i = 0; i < num_rows; i++)
  164835. {
  164836. png_bytep dptr = *dp;
  164837. png_read_row(png_ptr, png_bytep_NULL, dptr);
  164838. dp++;
  164839. }
  164840. }
  164841. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164842. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164843. void PNGAPI
  164844. png_read_image(png_structp png_ptr, png_bytepp image)
  164845. {
  164846. png_uint_32 i,image_height;
  164847. int pass, j;
  164848. png_bytepp rp;
  164849. png_debug(1, "in png_read_image\n");
  164850. if(png_ptr == NULL) return;
  164851. #ifdef PNG_READ_INTERLACING_SUPPORTED
  164852. pass = png_set_interlace_handling(png_ptr);
  164853. #else
  164854. if (png_ptr->interlaced)
  164855. png_error(png_ptr,
  164856. "Cannot read interlaced image -- interlace handler disabled.");
  164857. pass = 1;
  164858. #endif
  164859. image_height=png_ptr->height;
  164860. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  164861. for (j = 0; j < pass; j++)
  164862. {
  164863. rp = image;
  164864. for (i = 0; i < image_height; i++)
  164865. {
  164866. png_read_row(png_ptr, *rp, png_bytep_NULL);
  164867. rp++;
  164868. }
  164869. }
  164870. }
  164871. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164872. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164873. void PNGAPI
  164874. png_read_end(png_structp png_ptr, png_infop info_ptr)
  164875. {
  164876. png_byte chunk_length[4];
  164877. png_uint_32 length;
  164878. png_debug(1, "in png_read_end\n");
  164879. if(png_ptr == NULL) return;
  164880. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  164881. do
  164882. {
  164883. #ifdef PNG_USE_LOCAL_ARRAYS
  164884. PNG_CONST PNG_IHDR;
  164885. PNG_CONST PNG_IDAT;
  164886. PNG_CONST PNG_IEND;
  164887. PNG_CONST PNG_PLTE;
  164888. #if defined(PNG_READ_bKGD_SUPPORTED)
  164889. PNG_CONST PNG_bKGD;
  164890. #endif
  164891. #if defined(PNG_READ_cHRM_SUPPORTED)
  164892. PNG_CONST PNG_cHRM;
  164893. #endif
  164894. #if defined(PNG_READ_gAMA_SUPPORTED)
  164895. PNG_CONST PNG_gAMA;
  164896. #endif
  164897. #if defined(PNG_READ_hIST_SUPPORTED)
  164898. PNG_CONST PNG_hIST;
  164899. #endif
  164900. #if defined(PNG_READ_iCCP_SUPPORTED)
  164901. PNG_CONST PNG_iCCP;
  164902. #endif
  164903. #if defined(PNG_READ_iTXt_SUPPORTED)
  164904. PNG_CONST PNG_iTXt;
  164905. #endif
  164906. #if defined(PNG_READ_oFFs_SUPPORTED)
  164907. PNG_CONST PNG_oFFs;
  164908. #endif
  164909. #if defined(PNG_READ_pCAL_SUPPORTED)
  164910. PNG_CONST PNG_pCAL;
  164911. #endif
  164912. #if defined(PNG_READ_pHYs_SUPPORTED)
  164913. PNG_CONST PNG_pHYs;
  164914. #endif
  164915. #if defined(PNG_READ_sBIT_SUPPORTED)
  164916. PNG_CONST PNG_sBIT;
  164917. #endif
  164918. #if defined(PNG_READ_sCAL_SUPPORTED)
  164919. PNG_CONST PNG_sCAL;
  164920. #endif
  164921. #if defined(PNG_READ_sPLT_SUPPORTED)
  164922. PNG_CONST PNG_sPLT;
  164923. #endif
  164924. #if defined(PNG_READ_sRGB_SUPPORTED)
  164925. PNG_CONST PNG_sRGB;
  164926. #endif
  164927. #if defined(PNG_READ_tEXt_SUPPORTED)
  164928. PNG_CONST PNG_tEXt;
  164929. #endif
  164930. #if defined(PNG_READ_tIME_SUPPORTED)
  164931. PNG_CONST PNG_tIME;
  164932. #endif
  164933. #if defined(PNG_READ_tRNS_SUPPORTED)
  164934. PNG_CONST PNG_tRNS;
  164935. #endif
  164936. #if defined(PNG_READ_zTXt_SUPPORTED)
  164937. PNG_CONST PNG_zTXt;
  164938. #endif
  164939. #endif /* PNG_USE_LOCAL_ARRAYS */
  164940. png_read_data(png_ptr, chunk_length, 4);
  164941. length = png_get_uint_31(png_ptr,chunk_length);
  164942. png_reset_crc(png_ptr);
  164943. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164944. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  164945. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164946. png_handle_IHDR(png_ptr, info_ptr, length);
  164947. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164948. png_handle_IEND(png_ptr, info_ptr, length);
  164949. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164950. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164951. {
  164952. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164953. {
  164954. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  164955. png_error(png_ptr, "Too many IDAT's found");
  164956. }
  164957. png_handle_unknown(png_ptr, info_ptr, length);
  164958. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164959. png_ptr->mode |= PNG_HAVE_PLTE;
  164960. }
  164961. #endif
  164962. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164963. {
  164964. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  164965. png_error(png_ptr, "Too many IDAT's found");
  164966. png_crc_finish(png_ptr, length);
  164967. }
  164968. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164969. png_handle_PLTE(png_ptr, info_ptr, length);
  164970. #if defined(PNG_READ_bKGD_SUPPORTED)
  164971. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164972. png_handle_bKGD(png_ptr, info_ptr, length);
  164973. #endif
  164974. #if defined(PNG_READ_cHRM_SUPPORTED)
  164975. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164976. png_handle_cHRM(png_ptr, info_ptr, length);
  164977. #endif
  164978. #if defined(PNG_READ_gAMA_SUPPORTED)
  164979. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164980. png_handle_gAMA(png_ptr, info_ptr, length);
  164981. #endif
  164982. #if defined(PNG_READ_hIST_SUPPORTED)
  164983. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164984. png_handle_hIST(png_ptr, info_ptr, length);
  164985. #endif
  164986. #if defined(PNG_READ_oFFs_SUPPORTED)
  164987. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164988. png_handle_oFFs(png_ptr, info_ptr, length);
  164989. #endif
  164990. #if defined(PNG_READ_pCAL_SUPPORTED)
  164991. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164992. png_handle_pCAL(png_ptr, info_ptr, length);
  164993. #endif
  164994. #if defined(PNG_READ_sCAL_SUPPORTED)
  164995. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164996. png_handle_sCAL(png_ptr, info_ptr, length);
  164997. #endif
  164998. #if defined(PNG_READ_pHYs_SUPPORTED)
  164999. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165000. png_handle_pHYs(png_ptr, info_ptr, length);
  165001. #endif
  165002. #if defined(PNG_READ_sBIT_SUPPORTED)
  165003. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165004. png_handle_sBIT(png_ptr, info_ptr, length);
  165005. #endif
  165006. #if defined(PNG_READ_sRGB_SUPPORTED)
  165007. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165008. png_handle_sRGB(png_ptr, info_ptr, length);
  165009. #endif
  165010. #if defined(PNG_READ_iCCP_SUPPORTED)
  165011. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165012. png_handle_iCCP(png_ptr, info_ptr, length);
  165013. #endif
  165014. #if defined(PNG_READ_sPLT_SUPPORTED)
  165015. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165016. png_handle_sPLT(png_ptr, info_ptr, length);
  165017. #endif
  165018. #if defined(PNG_READ_tEXt_SUPPORTED)
  165019. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165020. png_handle_tEXt(png_ptr, info_ptr, length);
  165021. #endif
  165022. #if defined(PNG_READ_tIME_SUPPORTED)
  165023. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165024. png_handle_tIME(png_ptr, info_ptr, length);
  165025. #endif
  165026. #if defined(PNG_READ_tRNS_SUPPORTED)
  165027. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165028. png_handle_tRNS(png_ptr, info_ptr, length);
  165029. #endif
  165030. #if defined(PNG_READ_zTXt_SUPPORTED)
  165031. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165032. png_handle_zTXt(png_ptr, info_ptr, length);
  165033. #endif
  165034. #if defined(PNG_READ_iTXt_SUPPORTED)
  165035. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165036. png_handle_iTXt(png_ptr, info_ptr, length);
  165037. #endif
  165038. else
  165039. png_handle_unknown(png_ptr, info_ptr, length);
  165040. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165041. }
  165042. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165043. void PNGAPI
  165044. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165045. png_infopp end_info_ptr_ptr)
  165046. {
  165047. png_structp png_ptr = NULL;
  165048. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165049. #ifdef PNG_USER_MEM_SUPPORTED
  165050. png_free_ptr free_fn;
  165051. png_voidp mem_ptr;
  165052. #endif
  165053. png_debug(1, "in png_destroy_read_struct\n");
  165054. if (png_ptr_ptr != NULL)
  165055. png_ptr = *png_ptr_ptr;
  165056. if (info_ptr_ptr != NULL)
  165057. info_ptr = *info_ptr_ptr;
  165058. if (end_info_ptr_ptr != NULL)
  165059. end_info_ptr = *end_info_ptr_ptr;
  165060. #ifdef PNG_USER_MEM_SUPPORTED
  165061. free_fn = png_ptr->free_fn;
  165062. mem_ptr = png_ptr->mem_ptr;
  165063. #endif
  165064. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165065. if (info_ptr != NULL)
  165066. {
  165067. #if defined(PNG_TEXT_SUPPORTED)
  165068. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165069. #endif
  165070. #ifdef PNG_USER_MEM_SUPPORTED
  165071. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165072. (png_voidp)mem_ptr);
  165073. #else
  165074. png_destroy_struct((png_voidp)info_ptr);
  165075. #endif
  165076. *info_ptr_ptr = NULL;
  165077. }
  165078. if (end_info_ptr != NULL)
  165079. {
  165080. #if defined(PNG_READ_TEXT_SUPPORTED)
  165081. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165082. #endif
  165083. #ifdef PNG_USER_MEM_SUPPORTED
  165084. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165085. (png_voidp)mem_ptr);
  165086. #else
  165087. png_destroy_struct((png_voidp)end_info_ptr);
  165088. #endif
  165089. *end_info_ptr_ptr = NULL;
  165090. }
  165091. if (png_ptr != NULL)
  165092. {
  165093. #ifdef PNG_USER_MEM_SUPPORTED
  165094. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165095. (png_voidp)mem_ptr);
  165096. #else
  165097. png_destroy_struct((png_voidp)png_ptr);
  165098. #endif
  165099. *png_ptr_ptr = NULL;
  165100. }
  165101. }
  165102. void /* PRIVATE */
  165103. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165104. {
  165105. #ifdef PNG_SETJMP_SUPPORTED
  165106. jmp_buf tmp_jmp;
  165107. #endif
  165108. png_error_ptr error_fn;
  165109. png_error_ptr warning_fn;
  165110. png_voidp error_ptr;
  165111. #ifdef PNG_USER_MEM_SUPPORTED
  165112. png_free_ptr free_fn;
  165113. #endif
  165114. png_debug(1, "in png_read_destroy\n");
  165115. if (info_ptr != NULL)
  165116. png_info_destroy(png_ptr, info_ptr);
  165117. if (end_info_ptr != NULL)
  165118. png_info_destroy(png_ptr, end_info_ptr);
  165119. png_free(png_ptr, png_ptr->zbuf);
  165120. png_free(png_ptr, png_ptr->big_row_buf);
  165121. png_free(png_ptr, png_ptr->prev_row);
  165122. #if defined(PNG_READ_DITHER_SUPPORTED)
  165123. png_free(png_ptr, png_ptr->palette_lookup);
  165124. png_free(png_ptr, png_ptr->dither_index);
  165125. #endif
  165126. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165127. png_free(png_ptr, png_ptr->gamma_table);
  165128. #endif
  165129. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165130. png_free(png_ptr, png_ptr->gamma_from_1);
  165131. png_free(png_ptr, png_ptr->gamma_to_1);
  165132. #endif
  165133. #ifdef PNG_FREE_ME_SUPPORTED
  165134. if (png_ptr->free_me & PNG_FREE_PLTE)
  165135. png_zfree(png_ptr, png_ptr->palette);
  165136. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165137. #else
  165138. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165139. png_zfree(png_ptr, png_ptr->palette);
  165140. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165141. #endif
  165142. #if defined(PNG_tRNS_SUPPORTED) || \
  165143. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165144. #ifdef PNG_FREE_ME_SUPPORTED
  165145. if (png_ptr->free_me & PNG_FREE_TRNS)
  165146. png_free(png_ptr, png_ptr->trans);
  165147. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165148. #else
  165149. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165150. png_free(png_ptr, png_ptr->trans);
  165151. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165152. #endif
  165153. #endif
  165154. #if defined(PNG_READ_hIST_SUPPORTED)
  165155. #ifdef PNG_FREE_ME_SUPPORTED
  165156. if (png_ptr->free_me & PNG_FREE_HIST)
  165157. png_free(png_ptr, png_ptr->hist);
  165158. png_ptr->free_me &= ~PNG_FREE_HIST;
  165159. #else
  165160. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165161. png_free(png_ptr, png_ptr->hist);
  165162. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165163. #endif
  165164. #endif
  165165. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165166. if (png_ptr->gamma_16_table != NULL)
  165167. {
  165168. int i;
  165169. int istop = (1 << (8 - png_ptr->gamma_shift));
  165170. for (i = 0; i < istop; i++)
  165171. {
  165172. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165173. }
  165174. png_free(png_ptr, png_ptr->gamma_16_table);
  165175. }
  165176. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165177. if (png_ptr->gamma_16_from_1 != NULL)
  165178. {
  165179. int i;
  165180. int istop = (1 << (8 - png_ptr->gamma_shift));
  165181. for (i = 0; i < istop; i++)
  165182. {
  165183. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165184. }
  165185. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165186. }
  165187. if (png_ptr->gamma_16_to_1 != NULL)
  165188. {
  165189. int i;
  165190. int istop = (1 << (8 - png_ptr->gamma_shift));
  165191. for (i = 0; i < istop; i++)
  165192. {
  165193. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165194. }
  165195. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165196. }
  165197. #endif
  165198. #endif
  165199. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165200. png_free(png_ptr, png_ptr->time_buffer);
  165201. #endif
  165202. inflateEnd(&png_ptr->zstream);
  165203. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165204. png_free(png_ptr, png_ptr->save_buffer);
  165205. #endif
  165206. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165207. #ifdef PNG_TEXT_SUPPORTED
  165208. png_free(png_ptr, png_ptr->current_text);
  165209. #endif /* PNG_TEXT_SUPPORTED */
  165210. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165211. #ifdef PNG_SETJMP_SUPPORTED
  165212. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165213. #endif
  165214. error_fn = png_ptr->error_fn;
  165215. warning_fn = png_ptr->warning_fn;
  165216. error_ptr = png_ptr->error_ptr;
  165217. #ifdef PNG_USER_MEM_SUPPORTED
  165218. free_fn = png_ptr->free_fn;
  165219. #endif
  165220. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165221. png_ptr->error_fn = error_fn;
  165222. png_ptr->warning_fn = warning_fn;
  165223. png_ptr->error_ptr = error_ptr;
  165224. #ifdef PNG_USER_MEM_SUPPORTED
  165225. png_ptr->free_fn = free_fn;
  165226. #endif
  165227. #ifdef PNG_SETJMP_SUPPORTED
  165228. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165229. #endif
  165230. }
  165231. void PNGAPI
  165232. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165233. {
  165234. if(png_ptr == NULL) return;
  165235. png_ptr->read_row_fn = read_row_fn;
  165236. }
  165237. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165238. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165239. void PNGAPI
  165240. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165241. int transforms,
  165242. voidp params)
  165243. {
  165244. int row;
  165245. if(png_ptr == NULL) return;
  165246. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165247. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165248. png_set_invert_alpha(png_ptr);
  165249. #endif
  165250. png_read_info(png_ptr, info_ptr);
  165251. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165252. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165253. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165254. if (transforms & PNG_TRANSFORM_STRIP_16)
  165255. png_set_strip_16(png_ptr);
  165256. #endif
  165257. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165258. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165259. png_set_strip_alpha(png_ptr);
  165260. #endif
  165261. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165262. if (transforms & PNG_TRANSFORM_PACKING)
  165263. png_set_packing(png_ptr);
  165264. #endif
  165265. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165266. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165267. png_set_packswap(png_ptr);
  165268. #endif
  165269. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165270. if (transforms & PNG_TRANSFORM_EXPAND)
  165271. if ((png_ptr->bit_depth < 8) ||
  165272. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165273. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165274. png_set_expand(png_ptr);
  165275. #endif
  165276. #if defined(PNG_READ_INVERT_SUPPORTED)
  165277. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165278. png_set_invert_mono(png_ptr);
  165279. #endif
  165280. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165281. if ((transforms & PNG_TRANSFORM_SHIFT)
  165282. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165283. {
  165284. png_color_8p sig_bit;
  165285. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165286. png_set_shift(png_ptr, sig_bit);
  165287. }
  165288. #endif
  165289. #if defined(PNG_READ_BGR_SUPPORTED)
  165290. if (transforms & PNG_TRANSFORM_BGR)
  165291. png_set_bgr(png_ptr);
  165292. #endif
  165293. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165294. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165295. png_set_swap_alpha(png_ptr);
  165296. #endif
  165297. #if defined(PNG_READ_SWAP_SUPPORTED)
  165298. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165299. png_set_swap(png_ptr);
  165300. #endif
  165301. png_read_update_info(png_ptr, info_ptr);
  165302. #ifdef PNG_FREE_ME_SUPPORTED
  165303. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165304. #endif
  165305. if(info_ptr->row_pointers == NULL)
  165306. {
  165307. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165308. info_ptr->height * png_sizeof(png_bytep));
  165309. #ifdef PNG_FREE_ME_SUPPORTED
  165310. info_ptr->free_me |= PNG_FREE_ROWS;
  165311. #endif
  165312. for (row = 0; row < (int)info_ptr->height; row++)
  165313. {
  165314. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165315. png_get_rowbytes(png_ptr, info_ptr));
  165316. }
  165317. }
  165318. png_read_image(png_ptr, info_ptr->row_pointers);
  165319. info_ptr->valid |= PNG_INFO_IDAT;
  165320. png_read_end(png_ptr, info_ptr);
  165321. transforms = transforms; /* quiet compiler warnings */
  165322. params = params;
  165323. }
  165324. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165325. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165326. #endif /* PNG_READ_SUPPORTED */
  165327. /*** End of inlined file: pngread.c ***/
  165328. /*** Start of inlined file: pngpread.c ***/
  165329. #define PNG_INTERNAL
  165330. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165331. #define PNG_READ_SIG_MODE 0
  165332. #define PNG_READ_CHUNK_MODE 1
  165333. #define PNG_READ_IDAT_MODE 2
  165334. #define PNG_SKIP_MODE 3
  165335. #define PNG_READ_tEXt_MODE 4
  165336. #define PNG_READ_zTXt_MODE 5
  165337. #define PNG_READ_DONE_MODE 6
  165338. #define PNG_READ_iTXt_MODE 7
  165339. #define PNG_ERROR_MODE 8
  165340. void PNGAPI
  165341. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165342. png_bytep buffer, png_size_t buffer_size)
  165343. {
  165344. if(png_ptr == NULL) return;
  165345. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165346. while (png_ptr->buffer_size)
  165347. {
  165348. png_process_some_data(png_ptr, info_ptr);
  165349. }
  165350. }
  165351. void /* PRIVATE */
  165352. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165353. {
  165354. if(png_ptr == NULL) return;
  165355. switch (png_ptr->process_mode)
  165356. {
  165357. case PNG_READ_SIG_MODE:
  165358. {
  165359. png_push_read_sig(png_ptr, info_ptr);
  165360. break;
  165361. }
  165362. case PNG_READ_CHUNK_MODE:
  165363. {
  165364. png_push_read_chunk(png_ptr, info_ptr);
  165365. break;
  165366. }
  165367. case PNG_READ_IDAT_MODE:
  165368. {
  165369. png_push_read_IDAT(png_ptr);
  165370. break;
  165371. }
  165372. #if defined(PNG_READ_tEXt_SUPPORTED)
  165373. case PNG_READ_tEXt_MODE:
  165374. {
  165375. png_push_read_tEXt(png_ptr, info_ptr);
  165376. break;
  165377. }
  165378. #endif
  165379. #if defined(PNG_READ_zTXt_SUPPORTED)
  165380. case PNG_READ_zTXt_MODE:
  165381. {
  165382. png_push_read_zTXt(png_ptr, info_ptr);
  165383. break;
  165384. }
  165385. #endif
  165386. #if defined(PNG_READ_iTXt_SUPPORTED)
  165387. case PNG_READ_iTXt_MODE:
  165388. {
  165389. png_push_read_iTXt(png_ptr, info_ptr);
  165390. break;
  165391. }
  165392. #endif
  165393. case PNG_SKIP_MODE:
  165394. {
  165395. png_push_crc_finish(png_ptr);
  165396. break;
  165397. }
  165398. default:
  165399. {
  165400. png_ptr->buffer_size = 0;
  165401. break;
  165402. }
  165403. }
  165404. }
  165405. void /* PRIVATE */
  165406. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165407. {
  165408. png_size_t num_checked = png_ptr->sig_bytes,
  165409. num_to_check = 8 - num_checked;
  165410. if (png_ptr->buffer_size < num_to_check)
  165411. {
  165412. num_to_check = png_ptr->buffer_size;
  165413. }
  165414. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165415. num_to_check);
  165416. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165417. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165418. {
  165419. if (num_checked < 4 &&
  165420. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165421. png_error(png_ptr, "Not a PNG file");
  165422. else
  165423. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165424. }
  165425. else
  165426. {
  165427. if (png_ptr->sig_bytes >= 8)
  165428. {
  165429. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165430. }
  165431. }
  165432. }
  165433. void /* PRIVATE */
  165434. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165435. {
  165436. #ifdef PNG_USE_LOCAL_ARRAYS
  165437. PNG_CONST PNG_IHDR;
  165438. PNG_CONST PNG_IDAT;
  165439. PNG_CONST PNG_IEND;
  165440. PNG_CONST PNG_PLTE;
  165441. #if defined(PNG_READ_bKGD_SUPPORTED)
  165442. PNG_CONST PNG_bKGD;
  165443. #endif
  165444. #if defined(PNG_READ_cHRM_SUPPORTED)
  165445. PNG_CONST PNG_cHRM;
  165446. #endif
  165447. #if defined(PNG_READ_gAMA_SUPPORTED)
  165448. PNG_CONST PNG_gAMA;
  165449. #endif
  165450. #if defined(PNG_READ_hIST_SUPPORTED)
  165451. PNG_CONST PNG_hIST;
  165452. #endif
  165453. #if defined(PNG_READ_iCCP_SUPPORTED)
  165454. PNG_CONST PNG_iCCP;
  165455. #endif
  165456. #if defined(PNG_READ_iTXt_SUPPORTED)
  165457. PNG_CONST PNG_iTXt;
  165458. #endif
  165459. #if defined(PNG_READ_oFFs_SUPPORTED)
  165460. PNG_CONST PNG_oFFs;
  165461. #endif
  165462. #if defined(PNG_READ_pCAL_SUPPORTED)
  165463. PNG_CONST PNG_pCAL;
  165464. #endif
  165465. #if defined(PNG_READ_pHYs_SUPPORTED)
  165466. PNG_CONST PNG_pHYs;
  165467. #endif
  165468. #if defined(PNG_READ_sBIT_SUPPORTED)
  165469. PNG_CONST PNG_sBIT;
  165470. #endif
  165471. #if defined(PNG_READ_sCAL_SUPPORTED)
  165472. PNG_CONST PNG_sCAL;
  165473. #endif
  165474. #if defined(PNG_READ_sRGB_SUPPORTED)
  165475. PNG_CONST PNG_sRGB;
  165476. #endif
  165477. #if defined(PNG_READ_sPLT_SUPPORTED)
  165478. PNG_CONST PNG_sPLT;
  165479. #endif
  165480. #if defined(PNG_READ_tEXt_SUPPORTED)
  165481. PNG_CONST PNG_tEXt;
  165482. #endif
  165483. #if defined(PNG_READ_tIME_SUPPORTED)
  165484. PNG_CONST PNG_tIME;
  165485. #endif
  165486. #if defined(PNG_READ_tRNS_SUPPORTED)
  165487. PNG_CONST PNG_tRNS;
  165488. #endif
  165489. #if defined(PNG_READ_zTXt_SUPPORTED)
  165490. PNG_CONST PNG_zTXt;
  165491. #endif
  165492. #endif /* PNG_USE_LOCAL_ARRAYS */
  165493. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165494. {
  165495. png_byte chunk_length[4];
  165496. if (png_ptr->buffer_size < 8)
  165497. {
  165498. png_push_save_buffer(png_ptr);
  165499. return;
  165500. }
  165501. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165502. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165503. png_reset_crc(png_ptr);
  165504. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165505. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165506. }
  165507. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165508. if(png_ptr->mode & PNG_AFTER_IDAT)
  165509. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165510. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165511. {
  165512. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165513. {
  165514. png_push_save_buffer(png_ptr);
  165515. return;
  165516. }
  165517. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165518. }
  165519. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165520. {
  165521. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165522. {
  165523. png_push_save_buffer(png_ptr);
  165524. return;
  165525. }
  165526. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165527. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165528. png_push_have_end(png_ptr, info_ptr);
  165529. }
  165530. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165531. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165532. {
  165533. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165534. {
  165535. png_push_save_buffer(png_ptr);
  165536. return;
  165537. }
  165538. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165539. png_ptr->mode |= PNG_HAVE_IDAT;
  165540. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165541. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165542. png_ptr->mode |= PNG_HAVE_PLTE;
  165543. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165544. {
  165545. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165546. png_error(png_ptr, "Missing IHDR before IDAT");
  165547. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165548. !(png_ptr->mode & PNG_HAVE_PLTE))
  165549. png_error(png_ptr, "Missing PLTE before IDAT");
  165550. }
  165551. }
  165552. #endif
  165553. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165554. {
  165555. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165556. {
  165557. png_push_save_buffer(png_ptr);
  165558. return;
  165559. }
  165560. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165561. }
  165562. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165563. {
  165564. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165565. png_error(png_ptr, "Missing IHDR before IDAT");
  165566. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165567. !(png_ptr->mode & PNG_HAVE_PLTE))
  165568. png_error(png_ptr, "Missing PLTE before IDAT");
  165569. if (png_ptr->mode & PNG_HAVE_IDAT)
  165570. {
  165571. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165572. if (png_ptr->push_length == 0)
  165573. return;
  165574. if (png_ptr->mode & PNG_AFTER_IDAT)
  165575. png_error(png_ptr, "Too many IDAT's found");
  165576. }
  165577. png_ptr->idat_size = png_ptr->push_length;
  165578. png_ptr->mode |= PNG_HAVE_IDAT;
  165579. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165580. png_push_have_info(png_ptr, info_ptr);
  165581. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165582. png_ptr->zstream.next_out = png_ptr->row_buf;
  165583. return;
  165584. }
  165585. #if defined(PNG_READ_gAMA_SUPPORTED)
  165586. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165587. {
  165588. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165589. {
  165590. png_push_save_buffer(png_ptr);
  165591. return;
  165592. }
  165593. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165594. }
  165595. #endif
  165596. #if defined(PNG_READ_sBIT_SUPPORTED)
  165597. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165598. {
  165599. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165600. {
  165601. png_push_save_buffer(png_ptr);
  165602. return;
  165603. }
  165604. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165605. }
  165606. #endif
  165607. #if defined(PNG_READ_cHRM_SUPPORTED)
  165608. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165609. {
  165610. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165611. {
  165612. png_push_save_buffer(png_ptr);
  165613. return;
  165614. }
  165615. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165616. }
  165617. #endif
  165618. #if defined(PNG_READ_sRGB_SUPPORTED)
  165619. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165620. {
  165621. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165622. {
  165623. png_push_save_buffer(png_ptr);
  165624. return;
  165625. }
  165626. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165627. }
  165628. #endif
  165629. #if defined(PNG_READ_iCCP_SUPPORTED)
  165630. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165631. {
  165632. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165633. {
  165634. png_push_save_buffer(png_ptr);
  165635. return;
  165636. }
  165637. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165638. }
  165639. #endif
  165640. #if defined(PNG_READ_sPLT_SUPPORTED)
  165641. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165642. {
  165643. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165644. {
  165645. png_push_save_buffer(png_ptr);
  165646. return;
  165647. }
  165648. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165649. }
  165650. #endif
  165651. #if defined(PNG_READ_tRNS_SUPPORTED)
  165652. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165653. {
  165654. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165655. {
  165656. png_push_save_buffer(png_ptr);
  165657. return;
  165658. }
  165659. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165660. }
  165661. #endif
  165662. #if defined(PNG_READ_bKGD_SUPPORTED)
  165663. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165664. {
  165665. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165666. {
  165667. png_push_save_buffer(png_ptr);
  165668. return;
  165669. }
  165670. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165671. }
  165672. #endif
  165673. #if defined(PNG_READ_hIST_SUPPORTED)
  165674. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165675. {
  165676. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165677. {
  165678. png_push_save_buffer(png_ptr);
  165679. return;
  165680. }
  165681. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165682. }
  165683. #endif
  165684. #if defined(PNG_READ_pHYs_SUPPORTED)
  165685. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165686. {
  165687. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165688. {
  165689. png_push_save_buffer(png_ptr);
  165690. return;
  165691. }
  165692. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165693. }
  165694. #endif
  165695. #if defined(PNG_READ_oFFs_SUPPORTED)
  165696. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165697. {
  165698. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165699. {
  165700. png_push_save_buffer(png_ptr);
  165701. return;
  165702. }
  165703. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165704. }
  165705. #endif
  165706. #if defined(PNG_READ_pCAL_SUPPORTED)
  165707. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165708. {
  165709. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165710. {
  165711. png_push_save_buffer(png_ptr);
  165712. return;
  165713. }
  165714. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165715. }
  165716. #endif
  165717. #if defined(PNG_READ_sCAL_SUPPORTED)
  165718. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165719. {
  165720. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165721. {
  165722. png_push_save_buffer(png_ptr);
  165723. return;
  165724. }
  165725. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165726. }
  165727. #endif
  165728. #if defined(PNG_READ_tIME_SUPPORTED)
  165729. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165730. {
  165731. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165732. {
  165733. png_push_save_buffer(png_ptr);
  165734. return;
  165735. }
  165736. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165737. }
  165738. #endif
  165739. #if defined(PNG_READ_tEXt_SUPPORTED)
  165740. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165741. {
  165742. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165743. {
  165744. png_push_save_buffer(png_ptr);
  165745. return;
  165746. }
  165747. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165748. }
  165749. #endif
  165750. #if defined(PNG_READ_zTXt_SUPPORTED)
  165751. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165752. {
  165753. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165754. {
  165755. png_push_save_buffer(png_ptr);
  165756. return;
  165757. }
  165758. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165759. }
  165760. #endif
  165761. #if defined(PNG_READ_iTXt_SUPPORTED)
  165762. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165763. {
  165764. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165765. {
  165766. png_push_save_buffer(png_ptr);
  165767. return;
  165768. }
  165769. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165770. }
  165771. #endif
  165772. else
  165773. {
  165774. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165775. {
  165776. png_push_save_buffer(png_ptr);
  165777. return;
  165778. }
  165779. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165780. }
  165781. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165782. }
  165783. void /* PRIVATE */
  165784. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165785. {
  165786. png_ptr->process_mode = PNG_SKIP_MODE;
  165787. png_ptr->skip_length = skip;
  165788. }
  165789. void /* PRIVATE */
  165790. png_push_crc_finish(png_structp png_ptr)
  165791. {
  165792. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165793. {
  165794. png_size_t save_size;
  165795. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165796. save_size = (png_size_t)png_ptr->skip_length;
  165797. else
  165798. save_size = png_ptr->save_buffer_size;
  165799. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165800. png_ptr->skip_length -= save_size;
  165801. png_ptr->buffer_size -= save_size;
  165802. png_ptr->save_buffer_size -= save_size;
  165803. png_ptr->save_buffer_ptr += save_size;
  165804. }
  165805. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165806. {
  165807. png_size_t save_size;
  165808. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165809. save_size = (png_size_t)png_ptr->skip_length;
  165810. else
  165811. save_size = png_ptr->current_buffer_size;
  165812. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165813. png_ptr->skip_length -= save_size;
  165814. png_ptr->buffer_size -= save_size;
  165815. png_ptr->current_buffer_size -= save_size;
  165816. png_ptr->current_buffer_ptr += save_size;
  165817. }
  165818. if (!png_ptr->skip_length)
  165819. {
  165820. if (png_ptr->buffer_size < 4)
  165821. {
  165822. png_push_save_buffer(png_ptr);
  165823. return;
  165824. }
  165825. png_crc_finish(png_ptr, 0);
  165826. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165827. }
  165828. }
  165829. void PNGAPI
  165830. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  165831. {
  165832. png_bytep ptr;
  165833. if(png_ptr == NULL) return;
  165834. ptr = buffer;
  165835. if (png_ptr->save_buffer_size)
  165836. {
  165837. png_size_t save_size;
  165838. if (length < png_ptr->save_buffer_size)
  165839. save_size = length;
  165840. else
  165841. save_size = png_ptr->save_buffer_size;
  165842. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  165843. length -= save_size;
  165844. ptr += save_size;
  165845. png_ptr->buffer_size -= save_size;
  165846. png_ptr->save_buffer_size -= save_size;
  165847. png_ptr->save_buffer_ptr += save_size;
  165848. }
  165849. if (length && png_ptr->current_buffer_size)
  165850. {
  165851. png_size_t save_size;
  165852. if (length < png_ptr->current_buffer_size)
  165853. save_size = length;
  165854. else
  165855. save_size = png_ptr->current_buffer_size;
  165856. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  165857. png_ptr->buffer_size -= save_size;
  165858. png_ptr->current_buffer_size -= save_size;
  165859. png_ptr->current_buffer_ptr += save_size;
  165860. }
  165861. }
  165862. void /* PRIVATE */
  165863. png_push_save_buffer(png_structp png_ptr)
  165864. {
  165865. if (png_ptr->save_buffer_size)
  165866. {
  165867. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  165868. {
  165869. png_size_t i,istop;
  165870. png_bytep sp;
  165871. png_bytep dp;
  165872. istop = png_ptr->save_buffer_size;
  165873. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  165874. i < istop; i++, sp++, dp++)
  165875. {
  165876. *dp = *sp;
  165877. }
  165878. }
  165879. }
  165880. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  165881. png_ptr->save_buffer_max)
  165882. {
  165883. png_size_t new_max;
  165884. png_bytep old_buffer;
  165885. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  165886. (png_ptr->current_buffer_size + 256))
  165887. {
  165888. png_error(png_ptr, "Potential overflow of save_buffer");
  165889. }
  165890. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  165891. old_buffer = png_ptr->save_buffer;
  165892. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  165893. (png_uint_32)new_max);
  165894. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  165895. png_free(png_ptr, old_buffer);
  165896. png_ptr->save_buffer_max = new_max;
  165897. }
  165898. if (png_ptr->current_buffer_size)
  165899. {
  165900. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  165901. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  165902. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  165903. png_ptr->current_buffer_size = 0;
  165904. }
  165905. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  165906. png_ptr->buffer_size = 0;
  165907. }
  165908. void /* PRIVATE */
  165909. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  165910. png_size_t buffer_length)
  165911. {
  165912. png_ptr->current_buffer = buffer;
  165913. png_ptr->current_buffer_size = buffer_length;
  165914. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  165915. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  165916. }
  165917. void /* PRIVATE */
  165918. png_push_read_IDAT(png_structp png_ptr)
  165919. {
  165920. #ifdef PNG_USE_LOCAL_ARRAYS
  165921. PNG_CONST PNG_IDAT;
  165922. #endif
  165923. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165924. {
  165925. png_byte chunk_length[4];
  165926. if (png_ptr->buffer_size < 8)
  165927. {
  165928. png_push_save_buffer(png_ptr);
  165929. return;
  165930. }
  165931. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165932. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165933. png_reset_crc(png_ptr);
  165934. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165935. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165936. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165937. {
  165938. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165939. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165940. png_error(png_ptr, "Not enough compressed data");
  165941. return;
  165942. }
  165943. png_ptr->idat_size = png_ptr->push_length;
  165944. }
  165945. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  165946. {
  165947. png_size_t save_size;
  165948. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  165949. {
  165950. save_size = (png_size_t)png_ptr->idat_size;
  165951. if((png_uint_32)save_size != png_ptr->idat_size)
  165952. png_error(png_ptr, "save_size overflowed in pngpread");
  165953. }
  165954. else
  165955. save_size = png_ptr->save_buffer_size;
  165956. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165957. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165958. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165959. png_ptr->idat_size -= save_size;
  165960. png_ptr->buffer_size -= save_size;
  165961. png_ptr->save_buffer_size -= save_size;
  165962. png_ptr->save_buffer_ptr += save_size;
  165963. }
  165964. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  165965. {
  165966. png_size_t save_size;
  165967. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  165968. {
  165969. save_size = (png_size_t)png_ptr->idat_size;
  165970. if((png_uint_32)save_size != png_ptr->idat_size)
  165971. png_error(png_ptr, "save_size overflowed in pngpread");
  165972. }
  165973. else
  165974. save_size = png_ptr->current_buffer_size;
  165975. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165976. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165977. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165978. png_ptr->idat_size -= save_size;
  165979. png_ptr->buffer_size -= save_size;
  165980. png_ptr->current_buffer_size -= save_size;
  165981. png_ptr->current_buffer_ptr += save_size;
  165982. }
  165983. if (!png_ptr->idat_size)
  165984. {
  165985. if (png_ptr->buffer_size < 4)
  165986. {
  165987. png_push_save_buffer(png_ptr);
  165988. return;
  165989. }
  165990. png_crc_finish(png_ptr, 0);
  165991. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165992. png_ptr->mode |= PNG_AFTER_IDAT;
  165993. }
  165994. }
  165995. void /* PRIVATE */
  165996. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  165997. png_size_t buffer_length)
  165998. {
  165999. int ret;
  166000. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166001. png_error(png_ptr, "Extra compression data");
  166002. png_ptr->zstream.next_in = buffer;
  166003. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166004. for(;;)
  166005. {
  166006. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166007. if (ret != Z_OK)
  166008. {
  166009. if (ret == Z_STREAM_END)
  166010. {
  166011. if (png_ptr->zstream.avail_in)
  166012. png_error(png_ptr, "Extra compressed data");
  166013. if (!(png_ptr->zstream.avail_out))
  166014. {
  166015. png_push_process_row(png_ptr);
  166016. }
  166017. png_ptr->mode |= PNG_AFTER_IDAT;
  166018. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166019. break;
  166020. }
  166021. else if (ret == Z_BUF_ERROR)
  166022. break;
  166023. else
  166024. png_error(png_ptr, "Decompression Error");
  166025. }
  166026. if (!(png_ptr->zstream.avail_out))
  166027. {
  166028. if ((
  166029. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166030. png_ptr->interlaced && png_ptr->pass > 6) ||
  166031. (!png_ptr->interlaced &&
  166032. #endif
  166033. png_ptr->row_number == png_ptr->num_rows))
  166034. {
  166035. if (png_ptr->zstream.avail_in)
  166036. {
  166037. png_warning(png_ptr, "Too much data in IDAT chunks");
  166038. }
  166039. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166040. break;
  166041. }
  166042. png_push_process_row(png_ptr);
  166043. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166044. png_ptr->zstream.next_out = png_ptr->row_buf;
  166045. }
  166046. else
  166047. break;
  166048. }
  166049. }
  166050. void /* PRIVATE */
  166051. png_push_process_row(png_structp png_ptr)
  166052. {
  166053. png_ptr->row_info.color_type = png_ptr->color_type;
  166054. png_ptr->row_info.width = png_ptr->iwidth;
  166055. png_ptr->row_info.channels = png_ptr->channels;
  166056. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166057. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166058. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166059. png_ptr->row_info.width);
  166060. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166061. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166062. (int)(png_ptr->row_buf[0]));
  166063. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166064. png_ptr->rowbytes + 1);
  166065. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166066. png_do_read_transformations(png_ptr);
  166067. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166068. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166069. {
  166070. if (png_ptr->pass < 6)
  166071. png_do_read_interlace(png_ptr);
  166072. switch (png_ptr->pass)
  166073. {
  166074. case 0:
  166075. {
  166076. int i;
  166077. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166078. {
  166079. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166080. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166081. }
  166082. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166083. {
  166084. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166085. {
  166086. png_push_have_row(png_ptr, png_bytep_NULL);
  166087. png_read_push_finish_row(png_ptr);
  166088. }
  166089. }
  166090. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166091. {
  166092. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166093. {
  166094. png_push_have_row(png_ptr, png_bytep_NULL);
  166095. png_read_push_finish_row(png_ptr);
  166096. }
  166097. }
  166098. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166099. {
  166100. png_push_have_row(png_ptr, png_bytep_NULL);
  166101. png_read_push_finish_row(png_ptr);
  166102. }
  166103. break;
  166104. }
  166105. case 1:
  166106. {
  166107. int i;
  166108. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166109. {
  166110. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166111. png_read_push_finish_row(png_ptr);
  166112. }
  166113. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166114. {
  166115. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166116. {
  166117. png_push_have_row(png_ptr, png_bytep_NULL);
  166118. png_read_push_finish_row(png_ptr);
  166119. }
  166120. }
  166121. break;
  166122. }
  166123. case 2:
  166124. {
  166125. int i;
  166126. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166127. {
  166128. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166129. png_read_push_finish_row(png_ptr);
  166130. }
  166131. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166132. {
  166133. png_push_have_row(png_ptr, png_bytep_NULL);
  166134. png_read_push_finish_row(png_ptr);
  166135. }
  166136. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166137. {
  166138. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166139. {
  166140. png_push_have_row(png_ptr, png_bytep_NULL);
  166141. png_read_push_finish_row(png_ptr);
  166142. }
  166143. }
  166144. break;
  166145. }
  166146. case 3:
  166147. {
  166148. int i;
  166149. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166150. {
  166151. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166152. png_read_push_finish_row(png_ptr);
  166153. }
  166154. if (png_ptr->pass == 4) /* skip top two generated rows */
  166155. {
  166156. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166157. {
  166158. png_push_have_row(png_ptr, png_bytep_NULL);
  166159. png_read_push_finish_row(png_ptr);
  166160. }
  166161. }
  166162. break;
  166163. }
  166164. case 4:
  166165. {
  166166. int i;
  166167. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166168. {
  166169. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166170. png_read_push_finish_row(png_ptr);
  166171. }
  166172. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166173. {
  166174. png_push_have_row(png_ptr, png_bytep_NULL);
  166175. png_read_push_finish_row(png_ptr);
  166176. }
  166177. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166178. {
  166179. png_push_have_row(png_ptr, png_bytep_NULL);
  166180. png_read_push_finish_row(png_ptr);
  166181. }
  166182. break;
  166183. }
  166184. case 5:
  166185. {
  166186. int i;
  166187. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166188. {
  166189. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166190. png_read_push_finish_row(png_ptr);
  166191. }
  166192. if (png_ptr->pass == 6) /* skip top generated row */
  166193. {
  166194. png_push_have_row(png_ptr, png_bytep_NULL);
  166195. png_read_push_finish_row(png_ptr);
  166196. }
  166197. break;
  166198. }
  166199. case 6:
  166200. {
  166201. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166202. png_read_push_finish_row(png_ptr);
  166203. if (png_ptr->pass != 6)
  166204. break;
  166205. png_push_have_row(png_ptr, png_bytep_NULL);
  166206. png_read_push_finish_row(png_ptr);
  166207. }
  166208. }
  166209. }
  166210. else
  166211. #endif
  166212. {
  166213. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166214. png_read_push_finish_row(png_ptr);
  166215. }
  166216. }
  166217. void /* PRIVATE */
  166218. png_read_push_finish_row(png_structp png_ptr)
  166219. {
  166220. #ifdef PNG_USE_LOCAL_ARRAYS
  166221. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166222. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166223. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166224. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166225. #endif
  166226. png_ptr->row_number++;
  166227. if (png_ptr->row_number < png_ptr->num_rows)
  166228. return;
  166229. if (png_ptr->interlaced)
  166230. {
  166231. png_ptr->row_number = 0;
  166232. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166233. png_ptr->rowbytes + 1);
  166234. do
  166235. {
  166236. png_ptr->pass++;
  166237. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166238. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166239. (png_ptr->pass == 5 && png_ptr->width < 2))
  166240. png_ptr->pass++;
  166241. if (png_ptr->pass > 7)
  166242. png_ptr->pass--;
  166243. if (png_ptr->pass >= 7)
  166244. break;
  166245. png_ptr->iwidth = (png_ptr->width +
  166246. png_pass_inc[png_ptr->pass] - 1 -
  166247. png_pass_start[png_ptr->pass]) /
  166248. png_pass_inc[png_ptr->pass];
  166249. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166250. png_ptr->iwidth) + 1;
  166251. if (png_ptr->transformations & PNG_INTERLACE)
  166252. break;
  166253. png_ptr->num_rows = (png_ptr->height +
  166254. png_pass_yinc[png_ptr->pass] - 1 -
  166255. png_pass_ystart[png_ptr->pass]) /
  166256. png_pass_yinc[png_ptr->pass];
  166257. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166258. }
  166259. }
  166260. #if defined(PNG_READ_tEXt_SUPPORTED)
  166261. void /* PRIVATE */
  166262. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166263. length)
  166264. {
  166265. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166266. {
  166267. png_error(png_ptr, "Out of place tEXt");
  166268. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166269. }
  166270. #ifdef PNG_MAX_MALLOC_64K
  166271. png_ptr->skip_length = 0; /* This may not be necessary */
  166272. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166273. {
  166274. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166275. png_ptr->skip_length = length - (png_uint_32)65535L;
  166276. length = (png_uint_32)65535L;
  166277. }
  166278. #endif
  166279. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166280. (png_uint_32)(length+1));
  166281. png_ptr->current_text[length] = '\0';
  166282. png_ptr->current_text_ptr = png_ptr->current_text;
  166283. png_ptr->current_text_size = (png_size_t)length;
  166284. png_ptr->current_text_left = (png_size_t)length;
  166285. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166286. }
  166287. void /* PRIVATE */
  166288. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166289. {
  166290. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166291. {
  166292. png_size_t text_size;
  166293. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166294. text_size = png_ptr->buffer_size;
  166295. else
  166296. text_size = png_ptr->current_text_left;
  166297. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166298. png_ptr->current_text_left -= text_size;
  166299. png_ptr->current_text_ptr += text_size;
  166300. }
  166301. if (!(png_ptr->current_text_left))
  166302. {
  166303. png_textp text_ptr;
  166304. png_charp text;
  166305. png_charp key;
  166306. int ret;
  166307. if (png_ptr->buffer_size < 4)
  166308. {
  166309. png_push_save_buffer(png_ptr);
  166310. return;
  166311. }
  166312. png_push_crc_finish(png_ptr);
  166313. #if defined(PNG_MAX_MALLOC_64K)
  166314. if (png_ptr->skip_length)
  166315. return;
  166316. #endif
  166317. key = png_ptr->current_text;
  166318. for (text = key; *text; text++)
  166319. ;
  166320. if (text < key + png_ptr->current_text_size)
  166321. text++;
  166322. text_ptr = (png_textp)png_malloc(png_ptr,
  166323. (png_uint_32)png_sizeof(png_text));
  166324. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166325. text_ptr->key = key;
  166326. #ifdef PNG_iTXt_SUPPORTED
  166327. text_ptr->lang = NULL;
  166328. text_ptr->lang_key = NULL;
  166329. #endif
  166330. text_ptr->text = text;
  166331. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166332. png_free(png_ptr, key);
  166333. png_free(png_ptr, text_ptr);
  166334. png_ptr->current_text = NULL;
  166335. if (ret)
  166336. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166337. }
  166338. }
  166339. #endif
  166340. #if defined(PNG_READ_zTXt_SUPPORTED)
  166341. void /* PRIVATE */
  166342. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166343. length)
  166344. {
  166345. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166346. {
  166347. png_error(png_ptr, "Out of place zTXt");
  166348. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166349. }
  166350. #ifdef PNG_MAX_MALLOC_64K
  166351. if (length > (png_uint_32)65535L)
  166352. {
  166353. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166354. png_push_crc_skip(png_ptr, length);
  166355. return;
  166356. }
  166357. #endif
  166358. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166359. (png_uint_32)(length+1));
  166360. png_ptr->current_text[length] = '\0';
  166361. png_ptr->current_text_ptr = png_ptr->current_text;
  166362. png_ptr->current_text_size = (png_size_t)length;
  166363. png_ptr->current_text_left = (png_size_t)length;
  166364. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166365. }
  166366. void /* PRIVATE */
  166367. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166368. {
  166369. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166370. {
  166371. png_size_t text_size;
  166372. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166373. text_size = png_ptr->buffer_size;
  166374. else
  166375. text_size = png_ptr->current_text_left;
  166376. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166377. png_ptr->current_text_left -= text_size;
  166378. png_ptr->current_text_ptr += text_size;
  166379. }
  166380. if (!(png_ptr->current_text_left))
  166381. {
  166382. png_textp text_ptr;
  166383. png_charp text;
  166384. png_charp key;
  166385. int ret;
  166386. png_size_t text_size, key_size;
  166387. if (png_ptr->buffer_size < 4)
  166388. {
  166389. png_push_save_buffer(png_ptr);
  166390. return;
  166391. }
  166392. png_push_crc_finish(png_ptr);
  166393. key = png_ptr->current_text;
  166394. for (text = key; *text; text++)
  166395. ;
  166396. if (text >= key + png_ptr->current_text_size)
  166397. {
  166398. png_ptr->current_text = NULL;
  166399. png_free(png_ptr, key);
  166400. return;
  166401. }
  166402. text++;
  166403. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166404. {
  166405. png_ptr->current_text = NULL;
  166406. png_free(png_ptr, key);
  166407. return;
  166408. }
  166409. text++;
  166410. png_ptr->zstream.next_in = (png_bytep )text;
  166411. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166412. (text - key));
  166413. png_ptr->zstream.next_out = png_ptr->zbuf;
  166414. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166415. key_size = text - key;
  166416. text_size = 0;
  166417. text = NULL;
  166418. ret = Z_STREAM_END;
  166419. while (png_ptr->zstream.avail_in)
  166420. {
  166421. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166422. if (ret != Z_OK && ret != Z_STREAM_END)
  166423. {
  166424. inflateReset(&png_ptr->zstream);
  166425. png_ptr->zstream.avail_in = 0;
  166426. png_ptr->current_text = NULL;
  166427. png_free(png_ptr, key);
  166428. png_free(png_ptr, text);
  166429. return;
  166430. }
  166431. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166432. {
  166433. if (text == NULL)
  166434. {
  166435. text = (png_charp)png_malloc(png_ptr,
  166436. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166437. + key_size + 1));
  166438. png_memcpy(text + key_size, png_ptr->zbuf,
  166439. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166440. png_memcpy(text, key, key_size);
  166441. text_size = key_size + png_ptr->zbuf_size -
  166442. png_ptr->zstream.avail_out;
  166443. *(text + text_size) = '\0';
  166444. }
  166445. else
  166446. {
  166447. png_charp tmp;
  166448. tmp = text;
  166449. text = (png_charp)png_malloc(png_ptr, text_size +
  166450. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166451. + 1));
  166452. png_memcpy(text, tmp, text_size);
  166453. png_free(png_ptr, tmp);
  166454. png_memcpy(text + text_size, png_ptr->zbuf,
  166455. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166456. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166457. *(text + text_size) = '\0';
  166458. }
  166459. if (ret != Z_STREAM_END)
  166460. {
  166461. png_ptr->zstream.next_out = png_ptr->zbuf;
  166462. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166463. }
  166464. }
  166465. else
  166466. {
  166467. break;
  166468. }
  166469. if (ret == Z_STREAM_END)
  166470. break;
  166471. }
  166472. inflateReset(&png_ptr->zstream);
  166473. png_ptr->zstream.avail_in = 0;
  166474. if (ret != Z_STREAM_END)
  166475. {
  166476. png_ptr->current_text = NULL;
  166477. png_free(png_ptr, key);
  166478. png_free(png_ptr, text);
  166479. return;
  166480. }
  166481. png_ptr->current_text = NULL;
  166482. png_free(png_ptr, key);
  166483. key = text;
  166484. text += key_size;
  166485. text_ptr = (png_textp)png_malloc(png_ptr,
  166486. (png_uint_32)png_sizeof(png_text));
  166487. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166488. text_ptr->key = key;
  166489. #ifdef PNG_iTXt_SUPPORTED
  166490. text_ptr->lang = NULL;
  166491. text_ptr->lang_key = NULL;
  166492. #endif
  166493. text_ptr->text = text;
  166494. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166495. png_free(png_ptr, key);
  166496. png_free(png_ptr, text_ptr);
  166497. if (ret)
  166498. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166499. }
  166500. }
  166501. #endif
  166502. #if defined(PNG_READ_iTXt_SUPPORTED)
  166503. void /* PRIVATE */
  166504. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166505. length)
  166506. {
  166507. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166508. {
  166509. png_error(png_ptr, "Out of place iTXt");
  166510. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166511. }
  166512. #ifdef PNG_MAX_MALLOC_64K
  166513. png_ptr->skip_length = 0; /* This may not be necessary */
  166514. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166515. {
  166516. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166517. png_ptr->skip_length = length - (png_uint_32)65535L;
  166518. length = (png_uint_32)65535L;
  166519. }
  166520. #endif
  166521. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166522. (png_uint_32)(length+1));
  166523. png_ptr->current_text[length] = '\0';
  166524. png_ptr->current_text_ptr = png_ptr->current_text;
  166525. png_ptr->current_text_size = (png_size_t)length;
  166526. png_ptr->current_text_left = (png_size_t)length;
  166527. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166528. }
  166529. void /* PRIVATE */
  166530. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166531. {
  166532. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166533. {
  166534. png_size_t text_size;
  166535. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166536. text_size = png_ptr->buffer_size;
  166537. else
  166538. text_size = png_ptr->current_text_left;
  166539. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166540. png_ptr->current_text_left -= text_size;
  166541. png_ptr->current_text_ptr += text_size;
  166542. }
  166543. if (!(png_ptr->current_text_left))
  166544. {
  166545. png_textp text_ptr;
  166546. png_charp key;
  166547. int comp_flag;
  166548. png_charp lang;
  166549. png_charp lang_key;
  166550. png_charp text;
  166551. int ret;
  166552. if (png_ptr->buffer_size < 4)
  166553. {
  166554. png_push_save_buffer(png_ptr);
  166555. return;
  166556. }
  166557. png_push_crc_finish(png_ptr);
  166558. #if defined(PNG_MAX_MALLOC_64K)
  166559. if (png_ptr->skip_length)
  166560. return;
  166561. #endif
  166562. key = png_ptr->current_text;
  166563. for (lang = key; *lang; lang++)
  166564. ;
  166565. if (lang < key + png_ptr->current_text_size - 3)
  166566. lang++;
  166567. comp_flag = *lang++;
  166568. lang++; /* skip comp_type, always zero */
  166569. for (lang_key = lang; *lang_key; lang_key++)
  166570. ;
  166571. lang_key++; /* skip NUL separator */
  166572. text=lang_key;
  166573. if (lang_key < key + png_ptr->current_text_size - 1)
  166574. {
  166575. for (; *text; text++)
  166576. ;
  166577. }
  166578. if (text < key + png_ptr->current_text_size)
  166579. text++;
  166580. text_ptr = (png_textp)png_malloc(png_ptr,
  166581. (png_uint_32)png_sizeof(png_text));
  166582. text_ptr->compression = comp_flag + 2;
  166583. text_ptr->key = key;
  166584. text_ptr->lang = lang;
  166585. text_ptr->lang_key = lang_key;
  166586. text_ptr->text = text;
  166587. text_ptr->text_length = 0;
  166588. text_ptr->itxt_length = png_strlen(text);
  166589. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166590. png_ptr->current_text = NULL;
  166591. png_free(png_ptr, text_ptr);
  166592. if (ret)
  166593. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166594. }
  166595. }
  166596. #endif
  166597. void /* PRIVATE */
  166598. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166599. length)
  166600. {
  166601. png_uint_32 skip=0;
  166602. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166603. if (!(png_ptr->chunk_name[0] & 0x20))
  166604. {
  166605. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166606. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166607. PNG_HANDLE_CHUNK_ALWAYS
  166608. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166609. && png_ptr->read_user_chunk_fn == NULL
  166610. #endif
  166611. )
  166612. #endif
  166613. png_chunk_error(png_ptr, "unknown critical chunk");
  166614. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166615. }
  166616. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166617. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166618. {
  166619. #ifdef PNG_MAX_MALLOC_64K
  166620. if (length > (png_uint_32)65535L)
  166621. {
  166622. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166623. skip = length - (png_uint_32)65535L;
  166624. length = (png_uint_32)65535L;
  166625. }
  166626. #endif
  166627. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166628. (png_charp)png_ptr->chunk_name, 5);
  166629. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166630. png_ptr->unknown_chunk.size = (png_size_t)length;
  166631. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166632. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166633. if(png_ptr->read_user_chunk_fn != NULL)
  166634. {
  166635. int ret;
  166636. ret = (*(png_ptr->read_user_chunk_fn))
  166637. (png_ptr, &png_ptr->unknown_chunk);
  166638. if (ret < 0)
  166639. png_chunk_error(png_ptr, "error in user chunk");
  166640. if (ret == 0)
  166641. {
  166642. if (!(png_ptr->chunk_name[0] & 0x20))
  166643. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166644. PNG_HANDLE_CHUNK_ALWAYS)
  166645. png_chunk_error(png_ptr, "unknown critical chunk");
  166646. png_set_unknown_chunks(png_ptr, info_ptr,
  166647. &png_ptr->unknown_chunk, 1);
  166648. }
  166649. }
  166650. #else
  166651. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166652. #endif
  166653. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166654. png_ptr->unknown_chunk.data = NULL;
  166655. }
  166656. else
  166657. #endif
  166658. skip=length;
  166659. png_push_crc_skip(png_ptr, skip);
  166660. }
  166661. void /* PRIVATE */
  166662. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166663. {
  166664. if (png_ptr->info_fn != NULL)
  166665. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166666. }
  166667. void /* PRIVATE */
  166668. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166669. {
  166670. if (png_ptr->end_fn != NULL)
  166671. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166672. }
  166673. void /* PRIVATE */
  166674. png_push_have_row(png_structp png_ptr, png_bytep row)
  166675. {
  166676. if (png_ptr->row_fn != NULL)
  166677. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166678. (int)png_ptr->pass);
  166679. }
  166680. void PNGAPI
  166681. png_progressive_combine_row (png_structp png_ptr,
  166682. png_bytep old_row, png_bytep new_row)
  166683. {
  166684. #ifdef PNG_USE_LOCAL_ARRAYS
  166685. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166686. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166687. #endif
  166688. if(png_ptr == NULL) return;
  166689. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166690. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166691. }
  166692. void PNGAPI
  166693. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166694. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166695. png_progressive_end_ptr end_fn)
  166696. {
  166697. if(png_ptr == NULL) return;
  166698. png_ptr->info_fn = info_fn;
  166699. png_ptr->row_fn = row_fn;
  166700. png_ptr->end_fn = end_fn;
  166701. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166702. }
  166703. png_voidp PNGAPI
  166704. png_get_progressive_ptr(png_structp png_ptr)
  166705. {
  166706. if(png_ptr == NULL) return (NULL);
  166707. return png_ptr->io_ptr;
  166708. }
  166709. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166710. /*** End of inlined file: pngpread.c ***/
  166711. /*** Start of inlined file: pngrio.c ***/
  166712. #define PNG_INTERNAL
  166713. #if defined(PNG_READ_SUPPORTED)
  166714. void /* PRIVATE */
  166715. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166716. {
  166717. png_debug1(4,"reading %d bytes\n", (int)length);
  166718. if (png_ptr->read_data_fn != NULL)
  166719. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166720. else
  166721. png_error(png_ptr, "Call to NULL read function");
  166722. }
  166723. #if !defined(PNG_NO_STDIO)
  166724. #ifndef USE_FAR_KEYWORD
  166725. void PNGAPI
  166726. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166727. {
  166728. png_size_t check;
  166729. if(png_ptr == NULL) return;
  166730. #if defined(_WIN32_WCE)
  166731. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166732. check = 0;
  166733. #else
  166734. check = (png_size_t)fread(data, (png_size_t)1, length,
  166735. (png_FILE_p)png_ptr->io_ptr);
  166736. #endif
  166737. if (check != length)
  166738. png_error(png_ptr, "Read Error");
  166739. }
  166740. #else
  166741. #define NEAR_BUF_SIZE 1024
  166742. #define MIN(a,b) (a <= b ? a : b)
  166743. static void PNGAPI
  166744. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166745. {
  166746. int check;
  166747. png_byte *n_data;
  166748. png_FILE_p io_ptr;
  166749. if(png_ptr == NULL) return;
  166750. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166751. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166752. if ((png_bytep)n_data == data)
  166753. {
  166754. #if defined(_WIN32_WCE)
  166755. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166756. check = 0;
  166757. #else
  166758. check = fread(n_data, 1, length, io_ptr);
  166759. #endif
  166760. }
  166761. else
  166762. {
  166763. png_byte buf[NEAR_BUF_SIZE];
  166764. png_size_t read, remaining, err;
  166765. check = 0;
  166766. remaining = length;
  166767. do
  166768. {
  166769. read = MIN(NEAR_BUF_SIZE, remaining);
  166770. #if defined(_WIN32_WCE)
  166771. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166772. err = 0;
  166773. #else
  166774. err = fread(buf, (png_size_t)1, read, io_ptr);
  166775. #endif
  166776. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166777. if(err != read)
  166778. break;
  166779. else
  166780. check += err;
  166781. data += read;
  166782. remaining -= read;
  166783. }
  166784. while (remaining != 0);
  166785. }
  166786. if ((png_uint_32)check != (png_uint_32)length)
  166787. png_error(png_ptr, "read Error");
  166788. }
  166789. #endif
  166790. #endif
  166791. void PNGAPI
  166792. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166793. png_rw_ptr read_data_fn)
  166794. {
  166795. if(png_ptr == NULL) return;
  166796. png_ptr->io_ptr = io_ptr;
  166797. #if !defined(PNG_NO_STDIO)
  166798. if (read_data_fn != NULL)
  166799. png_ptr->read_data_fn = read_data_fn;
  166800. else
  166801. png_ptr->read_data_fn = png_default_read_data;
  166802. #else
  166803. png_ptr->read_data_fn = read_data_fn;
  166804. #endif
  166805. if (png_ptr->write_data_fn != NULL)
  166806. {
  166807. png_ptr->write_data_fn = NULL;
  166808. png_warning(png_ptr,
  166809. "It's an error to set both read_data_fn and write_data_fn in the ");
  166810. png_warning(png_ptr,
  166811. "same structure. Resetting write_data_fn to NULL.");
  166812. }
  166813. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  166814. png_ptr->output_flush_fn = NULL;
  166815. #endif
  166816. }
  166817. #endif /* PNG_READ_SUPPORTED */
  166818. /*** End of inlined file: pngrio.c ***/
  166819. /*** Start of inlined file: pngrtran.c ***/
  166820. #define PNG_INTERNAL
  166821. #if defined(PNG_READ_SUPPORTED)
  166822. void PNGAPI
  166823. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  166824. {
  166825. png_debug(1, "in png_set_crc_action\n");
  166826. if(png_ptr == NULL) return;
  166827. switch (crit_action)
  166828. {
  166829. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166830. break;
  166831. case PNG_CRC_WARN_USE: /* warn/use data */
  166832. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166833. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  166834. break;
  166835. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166836. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166837. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  166838. PNG_FLAG_CRC_CRITICAL_IGNORE;
  166839. break;
  166840. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  166841. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  166842. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166843. case PNG_CRC_DEFAULT:
  166844. default:
  166845. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166846. break;
  166847. }
  166848. switch (ancil_action)
  166849. {
  166850. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166851. break;
  166852. case PNG_CRC_WARN_USE: /* warn/use data */
  166853. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166854. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  166855. break;
  166856. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166857. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166858. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  166859. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166860. break;
  166861. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166862. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166863. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166864. break;
  166865. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  166866. case PNG_CRC_DEFAULT:
  166867. default:
  166868. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166869. break;
  166870. }
  166871. }
  166872. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  166873. defined(PNG_FLOATING_POINT_SUPPORTED)
  166874. void PNGAPI
  166875. png_set_background(png_structp png_ptr,
  166876. png_color_16p background_color, int background_gamma_code,
  166877. int need_expand, double background_gamma)
  166878. {
  166879. png_debug(1, "in png_set_background\n");
  166880. if(png_ptr == NULL) return;
  166881. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  166882. {
  166883. png_warning(png_ptr, "Application must supply a known background gamma");
  166884. return;
  166885. }
  166886. png_ptr->transformations |= PNG_BACKGROUND;
  166887. png_memcpy(&(png_ptr->background), background_color,
  166888. png_sizeof(png_color_16));
  166889. png_ptr->background_gamma = (float)background_gamma;
  166890. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  166891. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  166892. }
  166893. #endif
  166894. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  166895. void PNGAPI
  166896. png_set_strip_16(png_structp png_ptr)
  166897. {
  166898. png_debug(1, "in png_set_strip_16\n");
  166899. if(png_ptr == NULL) return;
  166900. png_ptr->transformations |= PNG_16_TO_8;
  166901. }
  166902. #endif
  166903. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  166904. void PNGAPI
  166905. png_set_strip_alpha(png_structp png_ptr)
  166906. {
  166907. png_debug(1, "in png_set_strip_alpha\n");
  166908. if(png_ptr == NULL) return;
  166909. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  166910. }
  166911. #endif
  166912. #if defined(PNG_READ_DITHER_SUPPORTED)
  166913. typedef struct png_dsort_struct
  166914. {
  166915. struct png_dsort_struct FAR * next;
  166916. png_byte left;
  166917. png_byte right;
  166918. } png_dsort;
  166919. typedef png_dsort FAR * png_dsortp;
  166920. typedef png_dsort FAR * FAR * png_dsortpp;
  166921. void PNGAPI
  166922. png_set_dither(png_structp png_ptr, png_colorp palette,
  166923. int num_palette, int maximum_colors, png_uint_16p histogram,
  166924. int full_dither)
  166925. {
  166926. png_debug(1, "in png_set_dither\n");
  166927. if(png_ptr == NULL) return;
  166928. png_ptr->transformations |= PNG_DITHER;
  166929. if (!full_dither)
  166930. {
  166931. int i;
  166932. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  166933. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166934. for (i = 0; i < num_palette; i++)
  166935. png_ptr->dither_index[i] = (png_byte)i;
  166936. }
  166937. if (num_palette > maximum_colors)
  166938. {
  166939. if (histogram != NULL)
  166940. {
  166941. int i;
  166942. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  166943. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166944. for (i = 0; i < num_palette; i++)
  166945. png_ptr->dither_sort[i] = (png_byte)i;
  166946. for (i = num_palette - 1; i >= maximum_colors; i--)
  166947. {
  166948. int done; /* to stop early if the list is pre-sorted */
  166949. int j;
  166950. done = 1;
  166951. for (j = 0; j < i; j++)
  166952. {
  166953. if (histogram[png_ptr->dither_sort[j]]
  166954. < histogram[png_ptr->dither_sort[j + 1]])
  166955. {
  166956. png_byte t;
  166957. t = png_ptr->dither_sort[j];
  166958. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  166959. png_ptr->dither_sort[j + 1] = t;
  166960. done = 0;
  166961. }
  166962. }
  166963. if (done)
  166964. break;
  166965. }
  166966. if (full_dither)
  166967. {
  166968. int j = num_palette;
  166969. for (i = 0; i < maximum_colors; i++)
  166970. {
  166971. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  166972. {
  166973. do
  166974. j--;
  166975. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  166976. palette[i] = palette[j];
  166977. }
  166978. }
  166979. }
  166980. else
  166981. {
  166982. int j = num_palette;
  166983. for (i = 0; i < maximum_colors; i++)
  166984. {
  166985. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  166986. {
  166987. png_color tmp_color;
  166988. do
  166989. j--;
  166990. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  166991. tmp_color = palette[j];
  166992. palette[j] = palette[i];
  166993. palette[i] = tmp_color;
  166994. png_ptr->dither_index[j] = (png_byte)i;
  166995. png_ptr->dither_index[i] = (png_byte)j;
  166996. }
  166997. }
  166998. for (i = 0; i < num_palette; i++)
  166999. {
  167000. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167001. {
  167002. int min_d, k, min_k, d_index;
  167003. d_index = png_ptr->dither_index[i];
  167004. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167005. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167006. {
  167007. int d;
  167008. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167009. if (d < min_d)
  167010. {
  167011. min_d = d;
  167012. min_k = k;
  167013. }
  167014. }
  167015. png_ptr->dither_index[i] = (png_byte)min_k;
  167016. }
  167017. }
  167018. }
  167019. png_free(png_ptr, png_ptr->dither_sort);
  167020. png_ptr->dither_sort=NULL;
  167021. }
  167022. else
  167023. {
  167024. int i;
  167025. int max_d;
  167026. int num_new_palette;
  167027. png_dsortp t;
  167028. png_dsortpp hash;
  167029. t=NULL;
  167030. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167031. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167032. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167033. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167034. for (i = 0; i < num_palette; i++)
  167035. {
  167036. png_ptr->index_to_palette[i] = (png_byte)i;
  167037. png_ptr->palette_to_index[i] = (png_byte)i;
  167038. }
  167039. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167040. png_sizeof (png_dsortp)));
  167041. for (i = 0; i < 769; i++)
  167042. hash[i] = NULL;
  167043. num_new_palette = num_palette;
  167044. max_d = 96;
  167045. while (num_new_palette > maximum_colors)
  167046. {
  167047. for (i = 0; i < num_new_palette - 1; i++)
  167048. {
  167049. int j;
  167050. for (j = i + 1; j < num_new_palette; j++)
  167051. {
  167052. int d;
  167053. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167054. if (d <= max_d)
  167055. {
  167056. t = (png_dsortp)png_malloc_warn(png_ptr,
  167057. (png_uint_32)(png_sizeof(png_dsort)));
  167058. if (t == NULL)
  167059. break;
  167060. t->next = hash[d];
  167061. t->left = (png_byte)i;
  167062. t->right = (png_byte)j;
  167063. hash[d] = t;
  167064. }
  167065. }
  167066. if (t == NULL)
  167067. break;
  167068. }
  167069. if (t != NULL)
  167070. for (i = 0; i <= max_d; i++)
  167071. {
  167072. if (hash[i] != NULL)
  167073. {
  167074. png_dsortp p;
  167075. for (p = hash[i]; p; p = p->next)
  167076. {
  167077. if ((int)png_ptr->index_to_palette[p->left]
  167078. < num_new_palette &&
  167079. (int)png_ptr->index_to_palette[p->right]
  167080. < num_new_palette)
  167081. {
  167082. int j, next_j;
  167083. if (num_new_palette & 0x01)
  167084. {
  167085. j = p->left;
  167086. next_j = p->right;
  167087. }
  167088. else
  167089. {
  167090. j = p->right;
  167091. next_j = p->left;
  167092. }
  167093. num_new_palette--;
  167094. palette[png_ptr->index_to_palette[j]]
  167095. = palette[num_new_palette];
  167096. if (!full_dither)
  167097. {
  167098. int k;
  167099. for (k = 0; k < num_palette; k++)
  167100. {
  167101. if (png_ptr->dither_index[k] ==
  167102. png_ptr->index_to_palette[j])
  167103. png_ptr->dither_index[k] =
  167104. png_ptr->index_to_palette[next_j];
  167105. if ((int)png_ptr->dither_index[k] ==
  167106. num_new_palette)
  167107. png_ptr->dither_index[k] =
  167108. png_ptr->index_to_palette[j];
  167109. }
  167110. }
  167111. png_ptr->index_to_palette[png_ptr->palette_to_index
  167112. [num_new_palette]] = png_ptr->index_to_palette[j];
  167113. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167114. = png_ptr->palette_to_index[num_new_palette];
  167115. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167116. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167117. }
  167118. if (num_new_palette <= maximum_colors)
  167119. break;
  167120. }
  167121. if (num_new_palette <= maximum_colors)
  167122. break;
  167123. }
  167124. }
  167125. for (i = 0; i < 769; i++)
  167126. {
  167127. if (hash[i] != NULL)
  167128. {
  167129. png_dsortp p = hash[i];
  167130. while (p)
  167131. {
  167132. t = p->next;
  167133. png_free(png_ptr, p);
  167134. p = t;
  167135. }
  167136. }
  167137. hash[i] = 0;
  167138. }
  167139. max_d += 96;
  167140. }
  167141. png_free(png_ptr, hash);
  167142. png_free(png_ptr, png_ptr->palette_to_index);
  167143. png_free(png_ptr, png_ptr->index_to_palette);
  167144. png_ptr->palette_to_index=NULL;
  167145. png_ptr->index_to_palette=NULL;
  167146. }
  167147. num_palette = maximum_colors;
  167148. }
  167149. if (png_ptr->palette == NULL)
  167150. {
  167151. png_ptr->palette = palette;
  167152. }
  167153. png_ptr->num_palette = (png_uint_16)num_palette;
  167154. if (full_dither)
  167155. {
  167156. int i;
  167157. png_bytep distance;
  167158. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167159. PNG_DITHER_BLUE_BITS;
  167160. int num_red = (1 << PNG_DITHER_RED_BITS);
  167161. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167162. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167163. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167164. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167165. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167166. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167167. png_sizeof (png_byte));
  167168. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167169. png_sizeof(png_byte)));
  167170. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167171. for (i = 0; i < num_palette; i++)
  167172. {
  167173. int ir, ig, ib;
  167174. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167175. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167176. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167177. for (ir = 0; ir < num_red; ir++)
  167178. {
  167179. int dr = ((ir > r) ? ir - r : r - ir);
  167180. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167181. for (ig = 0; ig < num_green; ig++)
  167182. {
  167183. int dg = ((ig > g) ? ig - g : g - ig);
  167184. int dt = dr + dg;
  167185. int dm = ((dr > dg) ? dr : dg);
  167186. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167187. for (ib = 0; ib < num_blue; ib++)
  167188. {
  167189. int d_index = index_g | ib;
  167190. int db = ((ib > b) ? ib - b : b - ib);
  167191. int dmax = ((dm > db) ? dm : db);
  167192. int d = dmax + dt + db;
  167193. if (d < (int)distance[d_index])
  167194. {
  167195. distance[d_index] = (png_byte)d;
  167196. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167197. }
  167198. }
  167199. }
  167200. }
  167201. }
  167202. png_free(png_ptr, distance);
  167203. }
  167204. }
  167205. #endif
  167206. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167207. void PNGAPI
  167208. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167209. {
  167210. png_debug(1, "in png_set_gamma\n");
  167211. if(png_ptr == NULL) return;
  167212. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167213. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167214. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167215. png_ptr->transformations |= PNG_GAMMA;
  167216. png_ptr->gamma = (float)file_gamma;
  167217. png_ptr->screen_gamma = (float)scrn_gamma;
  167218. }
  167219. #endif
  167220. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167221. void PNGAPI
  167222. png_set_expand(png_structp png_ptr)
  167223. {
  167224. png_debug(1, "in png_set_expand\n");
  167225. if(png_ptr == NULL) return;
  167226. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167227. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167228. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167229. #endif
  167230. }
  167231. void PNGAPI
  167232. png_set_palette_to_rgb(png_structp png_ptr)
  167233. {
  167234. png_debug(1, "in png_set_palette_to_rgb\n");
  167235. if(png_ptr == NULL) return;
  167236. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167237. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167238. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167239. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167240. #endif
  167241. }
  167242. #if !defined(PNG_1_0_X)
  167243. void PNGAPI
  167244. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167245. {
  167246. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167247. if(png_ptr == NULL) return;
  167248. png_ptr->transformations |= PNG_EXPAND;
  167249. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167250. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167251. #endif
  167252. }
  167253. #endif
  167254. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167255. void PNGAPI
  167256. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167257. {
  167258. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167259. if(png_ptr == NULL) return;
  167260. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167261. }
  167262. #endif
  167263. void PNGAPI
  167264. png_set_tRNS_to_alpha(png_structp png_ptr)
  167265. {
  167266. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167267. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167268. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167269. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167270. #endif
  167271. }
  167272. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167273. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167274. void PNGAPI
  167275. png_set_gray_to_rgb(png_structp png_ptr)
  167276. {
  167277. png_debug(1, "in png_set_gray_to_rgb\n");
  167278. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167279. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167280. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167281. #endif
  167282. }
  167283. #endif
  167284. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167285. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167286. void PNGAPI
  167287. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167288. double green)
  167289. {
  167290. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167291. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167292. if(png_ptr == NULL) return;
  167293. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167294. }
  167295. #endif
  167296. void PNGAPI
  167297. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167298. png_fixed_point red, png_fixed_point green)
  167299. {
  167300. png_debug(1, "in png_set_rgb_to_gray\n");
  167301. if(png_ptr == NULL) return;
  167302. switch(error_action)
  167303. {
  167304. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167305. break;
  167306. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167307. break;
  167308. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167309. }
  167310. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167311. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167312. png_ptr->transformations |= PNG_EXPAND;
  167313. #else
  167314. {
  167315. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167316. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167317. }
  167318. #endif
  167319. {
  167320. png_uint_16 red_int, green_int;
  167321. if(red < 0 || green < 0)
  167322. {
  167323. red_int = 6968; /* .212671 * 32768 + .5 */
  167324. green_int = 23434; /* .715160 * 32768 + .5 */
  167325. }
  167326. else if(red + green < 100000L)
  167327. {
  167328. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167329. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167330. }
  167331. else
  167332. {
  167333. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167334. red_int = 6968;
  167335. green_int = 23434;
  167336. }
  167337. png_ptr->rgb_to_gray_red_coeff = red_int;
  167338. png_ptr->rgb_to_gray_green_coeff = green_int;
  167339. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167340. }
  167341. }
  167342. #endif
  167343. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167344. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167345. defined(PNG_LEGACY_SUPPORTED)
  167346. void PNGAPI
  167347. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167348. read_user_transform_fn)
  167349. {
  167350. png_debug(1, "in png_set_read_user_transform_fn\n");
  167351. if(png_ptr == NULL) return;
  167352. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167353. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167354. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167355. #endif
  167356. #ifdef PNG_LEGACY_SUPPORTED
  167357. if(read_user_transform_fn)
  167358. png_warning(png_ptr,
  167359. "This version of libpng does not support user transforms");
  167360. #endif
  167361. }
  167362. #endif
  167363. void /* PRIVATE */
  167364. png_init_read_transformations(png_structp png_ptr)
  167365. {
  167366. png_debug(1, "in png_init_read_transformations\n");
  167367. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167368. if(png_ptr != NULL)
  167369. #endif
  167370. {
  167371. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167372. || defined(PNG_READ_GAMMA_SUPPORTED)
  167373. int color_type = png_ptr->color_type;
  167374. #endif
  167375. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167376. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167377. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167378. !(color_type & PNG_COLOR_MASK_COLOR))
  167379. {
  167380. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167381. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167382. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167383. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167384. png_ptr->background.red == png_ptr->background.green &&
  167385. png_ptr->background.red == png_ptr->background.blue)
  167386. {
  167387. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167388. png_ptr->background.gray = png_ptr->background.red;
  167389. }
  167390. #endif
  167391. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167392. (png_ptr->transformations & PNG_EXPAND))
  167393. {
  167394. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167395. {
  167396. switch (png_ptr->bit_depth)
  167397. {
  167398. case 1:
  167399. png_ptr->background.gray *= (png_uint_16)0xff;
  167400. png_ptr->background.red = png_ptr->background.green
  167401. = png_ptr->background.blue = png_ptr->background.gray;
  167402. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167403. {
  167404. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167405. png_ptr->trans_values.red = png_ptr->trans_values.green
  167406. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167407. }
  167408. break;
  167409. case 2:
  167410. png_ptr->background.gray *= (png_uint_16)0x55;
  167411. png_ptr->background.red = png_ptr->background.green
  167412. = png_ptr->background.blue = png_ptr->background.gray;
  167413. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167414. {
  167415. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167416. png_ptr->trans_values.red = png_ptr->trans_values.green
  167417. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167418. }
  167419. break;
  167420. case 4:
  167421. png_ptr->background.gray *= (png_uint_16)0x11;
  167422. png_ptr->background.red = png_ptr->background.green
  167423. = png_ptr->background.blue = png_ptr->background.gray;
  167424. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167425. {
  167426. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167427. png_ptr->trans_values.red = png_ptr->trans_values.green
  167428. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167429. }
  167430. break;
  167431. case 8:
  167432. case 16:
  167433. png_ptr->background.red = png_ptr->background.green
  167434. = png_ptr->background.blue = png_ptr->background.gray;
  167435. break;
  167436. }
  167437. }
  167438. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167439. {
  167440. png_ptr->background.red =
  167441. png_ptr->palette[png_ptr->background.index].red;
  167442. png_ptr->background.green =
  167443. png_ptr->palette[png_ptr->background.index].green;
  167444. png_ptr->background.blue =
  167445. png_ptr->palette[png_ptr->background.index].blue;
  167446. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167447. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167448. {
  167449. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167450. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167451. #endif
  167452. {
  167453. int i,istop;
  167454. istop=(int)png_ptr->num_trans;
  167455. for (i=0; i<istop; i++)
  167456. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167457. }
  167458. }
  167459. #endif
  167460. }
  167461. }
  167462. #endif
  167463. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167464. png_ptr->background_1 = png_ptr->background;
  167465. #endif
  167466. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167467. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167468. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167469. < PNG_GAMMA_THRESHOLD))
  167470. {
  167471. int i,k;
  167472. k=0;
  167473. for (i=0; i<png_ptr->num_trans; i++)
  167474. {
  167475. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167476. k=1; /* partial transparency is present */
  167477. }
  167478. if (k == 0)
  167479. png_ptr->transformations &= (~PNG_GAMMA);
  167480. }
  167481. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167482. png_ptr->gamma != 0.0)
  167483. {
  167484. png_build_gamma_table(png_ptr);
  167485. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167486. if (png_ptr->transformations & PNG_BACKGROUND)
  167487. {
  167488. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167489. {
  167490. png_color back, back_1;
  167491. png_colorp palette = png_ptr->palette;
  167492. int num_palette = png_ptr->num_palette;
  167493. int i;
  167494. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167495. {
  167496. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167497. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167498. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167499. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167500. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167501. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167502. }
  167503. else
  167504. {
  167505. double g, gs;
  167506. switch (png_ptr->background_gamma_type)
  167507. {
  167508. case PNG_BACKGROUND_GAMMA_SCREEN:
  167509. g = (png_ptr->screen_gamma);
  167510. gs = 1.0;
  167511. break;
  167512. case PNG_BACKGROUND_GAMMA_FILE:
  167513. g = 1.0 / (png_ptr->gamma);
  167514. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167515. break;
  167516. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167517. g = 1.0 / (png_ptr->background_gamma);
  167518. gs = 1.0 / (png_ptr->background_gamma *
  167519. png_ptr->screen_gamma);
  167520. break;
  167521. default:
  167522. g = 1.0; /* back_1 */
  167523. gs = 1.0; /* back */
  167524. }
  167525. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167526. {
  167527. back.red = (png_byte)png_ptr->background.red;
  167528. back.green = (png_byte)png_ptr->background.green;
  167529. back.blue = (png_byte)png_ptr->background.blue;
  167530. }
  167531. else
  167532. {
  167533. back.red = (png_byte)(pow(
  167534. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167535. back.green = (png_byte)(pow(
  167536. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167537. back.blue = (png_byte)(pow(
  167538. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167539. }
  167540. back_1.red = (png_byte)(pow(
  167541. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167542. back_1.green = (png_byte)(pow(
  167543. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167544. back_1.blue = (png_byte)(pow(
  167545. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167546. }
  167547. for (i = 0; i < num_palette; i++)
  167548. {
  167549. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167550. {
  167551. if (png_ptr->trans[i] == 0)
  167552. {
  167553. palette[i] = back;
  167554. }
  167555. else /* if (png_ptr->trans[i] != 0xff) */
  167556. {
  167557. png_byte v, w;
  167558. v = png_ptr->gamma_to_1[palette[i].red];
  167559. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167560. palette[i].red = png_ptr->gamma_from_1[w];
  167561. v = png_ptr->gamma_to_1[palette[i].green];
  167562. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167563. palette[i].green = png_ptr->gamma_from_1[w];
  167564. v = png_ptr->gamma_to_1[palette[i].blue];
  167565. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167566. palette[i].blue = png_ptr->gamma_from_1[w];
  167567. }
  167568. }
  167569. else
  167570. {
  167571. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167572. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167573. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167574. }
  167575. }
  167576. }
  167577. else
  167578. {
  167579. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167580. double g = 1.0;
  167581. double gs = 1.0;
  167582. switch (png_ptr->background_gamma_type)
  167583. {
  167584. case PNG_BACKGROUND_GAMMA_SCREEN:
  167585. g = (png_ptr->screen_gamma);
  167586. gs = 1.0;
  167587. break;
  167588. case PNG_BACKGROUND_GAMMA_FILE:
  167589. g = 1.0 / (png_ptr->gamma);
  167590. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167591. break;
  167592. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167593. g = 1.0 / (png_ptr->background_gamma);
  167594. gs = 1.0 / (png_ptr->background_gamma *
  167595. png_ptr->screen_gamma);
  167596. break;
  167597. }
  167598. png_ptr->background_1.gray = (png_uint_16)(pow(
  167599. (double)png_ptr->background.gray / m, g) * m + .5);
  167600. png_ptr->background.gray = (png_uint_16)(pow(
  167601. (double)png_ptr->background.gray / m, gs) * m + .5);
  167602. if ((png_ptr->background.red != png_ptr->background.green) ||
  167603. (png_ptr->background.red != png_ptr->background.blue) ||
  167604. (png_ptr->background.red != png_ptr->background.gray))
  167605. {
  167606. png_ptr->background_1.red = (png_uint_16)(pow(
  167607. (double)png_ptr->background.red / m, g) * m + .5);
  167608. png_ptr->background_1.green = (png_uint_16)(pow(
  167609. (double)png_ptr->background.green / m, g) * m + .5);
  167610. png_ptr->background_1.blue = (png_uint_16)(pow(
  167611. (double)png_ptr->background.blue / m, g) * m + .5);
  167612. png_ptr->background.red = (png_uint_16)(pow(
  167613. (double)png_ptr->background.red / m, gs) * m + .5);
  167614. png_ptr->background.green = (png_uint_16)(pow(
  167615. (double)png_ptr->background.green / m, gs) * m + .5);
  167616. png_ptr->background.blue = (png_uint_16)(pow(
  167617. (double)png_ptr->background.blue / m, gs) * m + .5);
  167618. }
  167619. else
  167620. {
  167621. png_ptr->background_1.red = png_ptr->background_1.green
  167622. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167623. png_ptr->background.red = png_ptr->background.green
  167624. = png_ptr->background.blue = png_ptr->background.gray;
  167625. }
  167626. }
  167627. }
  167628. else
  167629. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167630. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167631. {
  167632. png_colorp palette = png_ptr->palette;
  167633. int num_palette = png_ptr->num_palette;
  167634. int i;
  167635. for (i = 0; i < num_palette; i++)
  167636. {
  167637. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167638. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167639. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167640. }
  167641. }
  167642. }
  167643. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167644. else
  167645. #endif
  167646. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167647. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167648. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167649. (color_type == PNG_COLOR_TYPE_PALETTE))
  167650. {
  167651. int i;
  167652. int istop = (int)png_ptr->num_trans;
  167653. png_color back;
  167654. png_colorp palette = png_ptr->palette;
  167655. back.red = (png_byte)png_ptr->background.red;
  167656. back.green = (png_byte)png_ptr->background.green;
  167657. back.blue = (png_byte)png_ptr->background.blue;
  167658. for (i = 0; i < istop; i++)
  167659. {
  167660. if (png_ptr->trans[i] == 0)
  167661. {
  167662. palette[i] = back;
  167663. }
  167664. else if (png_ptr->trans[i] != 0xff)
  167665. {
  167666. png_composite(palette[i].red, palette[i].red,
  167667. png_ptr->trans[i], back.red);
  167668. png_composite(palette[i].green, palette[i].green,
  167669. png_ptr->trans[i], back.green);
  167670. png_composite(palette[i].blue, palette[i].blue,
  167671. png_ptr->trans[i], back.blue);
  167672. }
  167673. }
  167674. }
  167675. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167676. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167677. if ((png_ptr->transformations & PNG_SHIFT) &&
  167678. (color_type == PNG_COLOR_TYPE_PALETTE))
  167679. {
  167680. png_uint_16 i;
  167681. png_uint_16 istop = png_ptr->num_palette;
  167682. int sr = 8 - png_ptr->sig_bit.red;
  167683. int sg = 8 - png_ptr->sig_bit.green;
  167684. int sb = 8 - png_ptr->sig_bit.blue;
  167685. if (sr < 0 || sr > 8)
  167686. sr = 0;
  167687. if (sg < 0 || sg > 8)
  167688. sg = 0;
  167689. if (sb < 0 || sb > 8)
  167690. sb = 0;
  167691. for (i = 0; i < istop; i++)
  167692. {
  167693. png_ptr->palette[i].red >>= sr;
  167694. png_ptr->palette[i].green >>= sg;
  167695. png_ptr->palette[i].blue >>= sb;
  167696. }
  167697. }
  167698. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167699. }
  167700. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167701. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167702. if(png_ptr)
  167703. return;
  167704. #endif
  167705. }
  167706. void /* PRIVATE */
  167707. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167708. {
  167709. png_debug(1, "in png_read_transform_info\n");
  167710. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167711. if (png_ptr->transformations & PNG_EXPAND)
  167712. {
  167713. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167714. {
  167715. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167716. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167717. else
  167718. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167719. info_ptr->bit_depth = 8;
  167720. info_ptr->num_trans = 0;
  167721. }
  167722. else
  167723. {
  167724. if (png_ptr->num_trans)
  167725. {
  167726. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167727. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167728. else
  167729. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167730. }
  167731. if (info_ptr->bit_depth < 8)
  167732. info_ptr->bit_depth = 8;
  167733. info_ptr->num_trans = 0;
  167734. }
  167735. }
  167736. #endif
  167737. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167738. if (png_ptr->transformations & PNG_BACKGROUND)
  167739. {
  167740. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167741. info_ptr->num_trans = 0;
  167742. info_ptr->background = png_ptr->background;
  167743. }
  167744. #endif
  167745. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167746. if (png_ptr->transformations & PNG_GAMMA)
  167747. {
  167748. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167749. info_ptr->gamma = png_ptr->gamma;
  167750. #endif
  167751. #ifdef PNG_FIXED_POINT_SUPPORTED
  167752. info_ptr->int_gamma = png_ptr->int_gamma;
  167753. #endif
  167754. }
  167755. #endif
  167756. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167757. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167758. info_ptr->bit_depth = 8;
  167759. #endif
  167760. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167761. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167762. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167763. #endif
  167764. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167765. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167766. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167767. #endif
  167768. #if defined(PNG_READ_DITHER_SUPPORTED)
  167769. if (png_ptr->transformations & PNG_DITHER)
  167770. {
  167771. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167772. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167773. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167774. {
  167775. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167776. }
  167777. }
  167778. #endif
  167779. #if defined(PNG_READ_PACK_SUPPORTED)
  167780. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167781. info_ptr->bit_depth = 8;
  167782. #endif
  167783. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167784. info_ptr->channels = 1;
  167785. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167786. info_ptr->channels = 3;
  167787. else
  167788. info_ptr->channels = 1;
  167789. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167790. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167791. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167792. #endif
  167793. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167794. info_ptr->channels++;
  167795. #if defined(PNG_READ_FILLER_SUPPORTED)
  167796. if ((png_ptr->transformations & PNG_FILLER) &&
  167797. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167798. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167799. {
  167800. info_ptr->channels++;
  167801. #if !defined(PNG_1_0_X)
  167802. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167803. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167804. #endif
  167805. }
  167806. #endif
  167807. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167808. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167809. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167810. {
  167811. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167812. info_ptr->bit_depth = png_ptr->user_transform_depth;
  167813. if(info_ptr->channels < png_ptr->user_transform_channels)
  167814. info_ptr->channels = png_ptr->user_transform_channels;
  167815. }
  167816. #endif
  167817. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  167818. info_ptr->bit_depth);
  167819. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  167820. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  167821. if(png_ptr)
  167822. return;
  167823. #endif
  167824. }
  167825. void /* PRIVATE */
  167826. png_do_read_transformations(png_structp png_ptr)
  167827. {
  167828. png_debug(1, "in png_do_read_transformations\n");
  167829. if (png_ptr->row_buf == NULL)
  167830. {
  167831. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  167832. char msg[50];
  167833. png_snprintf2(msg, 50,
  167834. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  167835. png_ptr->pass);
  167836. png_error(png_ptr, msg);
  167837. #else
  167838. png_error(png_ptr, "NULL row buffer");
  167839. #endif
  167840. }
  167841. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167842. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  167843. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  167844. png_error(png_ptr, "Uninitialized row");
  167845. #else
  167846. png_warning(png_ptr, "Uninitialized row");
  167847. #endif
  167848. #endif
  167849. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167850. if (png_ptr->transformations & PNG_EXPAND)
  167851. {
  167852. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  167853. {
  167854. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167855. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  167856. }
  167857. else
  167858. {
  167859. if (png_ptr->num_trans &&
  167860. (png_ptr->transformations & PNG_EXPAND_tRNS))
  167861. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167862. &(png_ptr->trans_values));
  167863. else
  167864. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167865. NULL);
  167866. }
  167867. }
  167868. #endif
  167869. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167870. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167871. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167872. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  167873. #endif
  167874. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167875. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167876. {
  167877. int rgb_error =
  167878. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  167879. if(rgb_error)
  167880. {
  167881. png_ptr->rgb_to_gray_status=1;
  167882. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  167883. PNG_RGB_TO_GRAY_WARN)
  167884. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  167885. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  167886. PNG_RGB_TO_GRAY_ERR)
  167887. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  167888. }
  167889. }
  167890. #endif
  167891. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167892. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167893. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  167894. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167895. #endif
  167896. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167897. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167898. ((png_ptr->num_trans != 0 ) ||
  167899. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  167900. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167901. &(png_ptr->trans_values), &(png_ptr->background)
  167902. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167903. , &(png_ptr->background_1),
  167904. png_ptr->gamma_table, png_ptr->gamma_from_1,
  167905. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  167906. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  167907. png_ptr->gamma_shift
  167908. #endif
  167909. );
  167910. #endif
  167911. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167912. if ((png_ptr->transformations & PNG_GAMMA) &&
  167913. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167914. !((png_ptr->transformations & PNG_BACKGROUND) &&
  167915. ((png_ptr->num_trans != 0) ||
  167916. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  167917. #endif
  167918. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  167919. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167920. png_ptr->gamma_table, png_ptr->gamma_16_table,
  167921. png_ptr->gamma_shift);
  167922. #endif
  167923. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167924. if (png_ptr->transformations & PNG_16_TO_8)
  167925. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167926. #endif
  167927. #if defined(PNG_READ_DITHER_SUPPORTED)
  167928. if (png_ptr->transformations & PNG_DITHER)
  167929. {
  167930. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  167931. png_ptr->palette_lookup, png_ptr->dither_index);
  167932. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  167933. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  167934. }
  167935. #endif
  167936. #if defined(PNG_READ_INVERT_SUPPORTED)
  167937. if (png_ptr->transformations & PNG_INVERT_MONO)
  167938. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167939. #endif
  167940. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167941. if (png_ptr->transformations & PNG_SHIFT)
  167942. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167943. &(png_ptr->shift));
  167944. #endif
  167945. #if defined(PNG_READ_PACK_SUPPORTED)
  167946. if (png_ptr->transformations & PNG_PACK)
  167947. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167948. #endif
  167949. #if defined(PNG_READ_BGR_SUPPORTED)
  167950. if (png_ptr->transformations & PNG_BGR)
  167951. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167952. #endif
  167953. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  167954. if (png_ptr->transformations & PNG_PACKSWAP)
  167955. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167956. #endif
  167957. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167958. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167959. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  167960. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167961. #endif
  167962. #if defined(PNG_READ_FILLER_SUPPORTED)
  167963. if (png_ptr->transformations & PNG_FILLER)
  167964. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167965. (png_uint_32)png_ptr->filler, png_ptr->flags);
  167966. #endif
  167967. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167968. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167969. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167970. #endif
  167971. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  167972. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  167973. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167974. #endif
  167975. #if defined(PNG_READ_SWAP_SUPPORTED)
  167976. if (png_ptr->transformations & PNG_SWAP_BYTES)
  167977. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167978. #endif
  167979. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167980. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  167981. {
  167982. if(png_ptr->read_user_transform_fn != NULL)
  167983. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  167984. (png_ptr, /* png_ptr */
  167985. &(png_ptr->row_info), /* row_info: */
  167986. png_ptr->row_buf + 1); /* start of pixel data for row */
  167987. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  167988. if(png_ptr->user_transform_depth)
  167989. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  167990. if(png_ptr->user_transform_channels)
  167991. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  167992. #endif
  167993. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  167994. png_ptr->row_info.channels);
  167995. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  167996. png_ptr->row_info.width);
  167997. }
  167998. #endif
  167999. }
  168000. #if defined(PNG_READ_PACK_SUPPORTED)
  168001. void /* PRIVATE */
  168002. png_do_unpack(png_row_infop row_info, png_bytep row)
  168003. {
  168004. png_debug(1, "in png_do_unpack\n");
  168005. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168006. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168007. #else
  168008. if (row_info->bit_depth < 8)
  168009. #endif
  168010. {
  168011. png_uint_32 i;
  168012. png_uint_32 row_width=row_info->width;
  168013. switch (row_info->bit_depth)
  168014. {
  168015. case 1:
  168016. {
  168017. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168018. png_bytep dp = row + (png_size_t)row_width - 1;
  168019. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168020. for (i = 0; i < row_width; i++)
  168021. {
  168022. *dp = (png_byte)((*sp >> shift) & 0x01);
  168023. if (shift == 7)
  168024. {
  168025. shift = 0;
  168026. sp--;
  168027. }
  168028. else
  168029. shift++;
  168030. dp--;
  168031. }
  168032. break;
  168033. }
  168034. case 2:
  168035. {
  168036. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168037. png_bytep dp = row + (png_size_t)row_width - 1;
  168038. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168039. for (i = 0; i < row_width; i++)
  168040. {
  168041. *dp = (png_byte)((*sp >> shift) & 0x03);
  168042. if (shift == 6)
  168043. {
  168044. shift = 0;
  168045. sp--;
  168046. }
  168047. else
  168048. shift += 2;
  168049. dp--;
  168050. }
  168051. break;
  168052. }
  168053. case 4:
  168054. {
  168055. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168056. png_bytep dp = row + (png_size_t)row_width - 1;
  168057. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168058. for (i = 0; i < row_width; i++)
  168059. {
  168060. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168061. if (shift == 4)
  168062. {
  168063. shift = 0;
  168064. sp--;
  168065. }
  168066. else
  168067. shift = 4;
  168068. dp--;
  168069. }
  168070. break;
  168071. }
  168072. }
  168073. row_info->bit_depth = 8;
  168074. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168075. row_info->rowbytes = row_width * row_info->channels;
  168076. }
  168077. }
  168078. #endif
  168079. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168080. void /* PRIVATE */
  168081. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168082. {
  168083. png_debug(1, "in png_do_unshift\n");
  168084. if (
  168085. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168086. row != NULL && row_info != NULL && sig_bits != NULL &&
  168087. #endif
  168088. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168089. {
  168090. int shift[4];
  168091. int channels = 0;
  168092. int c;
  168093. png_uint_16 value = 0;
  168094. png_uint_32 row_width = row_info->width;
  168095. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168096. {
  168097. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168098. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168099. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168100. }
  168101. else
  168102. {
  168103. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168104. }
  168105. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168106. {
  168107. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168108. }
  168109. for (c = 0; c < channels; c++)
  168110. {
  168111. if (shift[c] <= 0)
  168112. shift[c] = 0;
  168113. else
  168114. value = 1;
  168115. }
  168116. if (!value)
  168117. return;
  168118. switch (row_info->bit_depth)
  168119. {
  168120. case 2:
  168121. {
  168122. png_bytep bp;
  168123. png_uint_32 i;
  168124. png_uint_32 istop = row_info->rowbytes;
  168125. for (bp = row, i = 0; i < istop; i++)
  168126. {
  168127. *bp >>= 1;
  168128. *bp++ &= 0x55;
  168129. }
  168130. break;
  168131. }
  168132. case 4:
  168133. {
  168134. png_bytep bp = row;
  168135. png_uint_32 i;
  168136. png_uint_32 istop = row_info->rowbytes;
  168137. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168138. (png_byte)((int)0xf >> shift[0]));
  168139. for (i = 0; i < istop; i++)
  168140. {
  168141. *bp >>= shift[0];
  168142. *bp++ &= mask;
  168143. }
  168144. break;
  168145. }
  168146. case 8:
  168147. {
  168148. png_bytep bp = row;
  168149. png_uint_32 i;
  168150. png_uint_32 istop = row_width * channels;
  168151. for (i = 0; i < istop; i++)
  168152. {
  168153. *bp++ >>= shift[i%channels];
  168154. }
  168155. break;
  168156. }
  168157. case 16:
  168158. {
  168159. png_bytep bp = row;
  168160. png_uint_32 i;
  168161. png_uint_32 istop = channels * row_width;
  168162. for (i = 0; i < istop; i++)
  168163. {
  168164. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168165. value >>= shift[i%channels];
  168166. *bp++ = (png_byte)(value >> 8);
  168167. *bp++ = (png_byte)(value & 0xff);
  168168. }
  168169. break;
  168170. }
  168171. }
  168172. }
  168173. }
  168174. #endif
  168175. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168176. void /* PRIVATE */
  168177. png_do_chop(png_row_infop row_info, png_bytep row)
  168178. {
  168179. png_debug(1, "in png_do_chop\n");
  168180. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168181. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168182. #else
  168183. if (row_info->bit_depth == 16)
  168184. #endif
  168185. {
  168186. png_bytep sp = row;
  168187. png_bytep dp = row;
  168188. png_uint_32 i;
  168189. png_uint_32 istop = row_info->width * row_info->channels;
  168190. for (i = 0; i<istop; i++, sp += 2, dp++)
  168191. {
  168192. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168193. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168194. #else
  168195. *dp = *sp;
  168196. #endif
  168197. }
  168198. row_info->bit_depth = 8;
  168199. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168200. row_info->rowbytes = row_info->width * row_info->channels;
  168201. }
  168202. }
  168203. #endif
  168204. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168205. void /* PRIVATE */
  168206. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168207. {
  168208. png_debug(1, "in png_do_read_swap_alpha\n");
  168209. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168210. if (row != NULL && row_info != NULL)
  168211. #endif
  168212. {
  168213. png_uint_32 row_width = row_info->width;
  168214. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168215. {
  168216. if (row_info->bit_depth == 8)
  168217. {
  168218. png_bytep sp = row + row_info->rowbytes;
  168219. png_bytep dp = sp;
  168220. png_byte save;
  168221. png_uint_32 i;
  168222. for (i = 0; i < row_width; i++)
  168223. {
  168224. save = *(--sp);
  168225. *(--dp) = *(--sp);
  168226. *(--dp) = *(--sp);
  168227. *(--dp) = *(--sp);
  168228. *(--dp) = save;
  168229. }
  168230. }
  168231. else
  168232. {
  168233. png_bytep sp = row + row_info->rowbytes;
  168234. png_bytep dp = sp;
  168235. png_byte save[2];
  168236. png_uint_32 i;
  168237. for (i = 0; i < row_width; i++)
  168238. {
  168239. save[0] = *(--sp);
  168240. save[1] = *(--sp);
  168241. *(--dp) = *(--sp);
  168242. *(--dp) = *(--sp);
  168243. *(--dp) = *(--sp);
  168244. *(--dp) = *(--sp);
  168245. *(--dp) = *(--sp);
  168246. *(--dp) = *(--sp);
  168247. *(--dp) = save[0];
  168248. *(--dp) = save[1];
  168249. }
  168250. }
  168251. }
  168252. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168253. {
  168254. if (row_info->bit_depth == 8)
  168255. {
  168256. png_bytep sp = row + row_info->rowbytes;
  168257. png_bytep dp = sp;
  168258. png_byte save;
  168259. png_uint_32 i;
  168260. for (i = 0; i < row_width; i++)
  168261. {
  168262. save = *(--sp);
  168263. *(--dp) = *(--sp);
  168264. *(--dp) = save;
  168265. }
  168266. }
  168267. else
  168268. {
  168269. png_bytep sp = row + row_info->rowbytes;
  168270. png_bytep dp = sp;
  168271. png_byte save[2];
  168272. png_uint_32 i;
  168273. for (i = 0; i < row_width; i++)
  168274. {
  168275. save[0] = *(--sp);
  168276. save[1] = *(--sp);
  168277. *(--dp) = *(--sp);
  168278. *(--dp) = *(--sp);
  168279. *(--dp) = save[0];
  168280. *(--dp) = save[1];
  168281. }
  168282. }
  168283. }
  168284. }
  168285. }
  168286. #endif
  168287. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168288. void /* PRIVATE */
  168289. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168290. {
  168291. png_debug(1, "in png_do_read_invert_alpha\n");
  168292. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168293. if (row != NULL && row_info != NULL)
  168294. #endif
  168295. {
  168296. png_uint_32 row_width = row_info->width;
  168297. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168298. {
  168299. if (row_info->bit_depth == 8)
  168300. {
  168301. png_bytep sp = row + row_info->rowbytes;
  168302. png_bytep dp = sp;
  168303. png_uint_32 i;
  168304. for (i = 0; i < row_width; i++)
  168305. {
  168306. *(--dp) = (png_byte)(255 - *(--sp));
  168307. sp-=3;
  168308. dp=sp;
  168309. }
  168310. }
  168311. else
  168312. {
  168313. png_bytep sp = row + row_info->rowbytes;
  168314. png_bytep dp = sp;
  168315. png_uint_32 i;
  168316. for (i = 0; i < row_width; i++)
  168317. {
  168318. *(--dp) = (png_byte)(255 - *(--sp));
  168319. *(--dp) = (png_byte)(255 - *(--sp));
  168320. sp-=6;
  168321. dp=sp;
  168322. }
  168323. }
  168324. }
  168325. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168326. {
  168327. if (row_info->bit_depth == 8)
  168328. {
  168329. png_bytep sp = row + row_info->rowbytes;
  168330. png_bytep dp = sp;
  168331. png_uint_32 i;
  168332. for (i = 0; i < row_width; i++)
  168333. {
  168334. *(--dp) = (png_byte)(255 - *(--sp));
  168335. *(--dp) = *(--sp);
  168336. }
  168337. }
  168338. else
  168339. {
  168340. png_bytep sp = row + row_info->rowbytes;
  168341. png_bytep dp = sp;
  168342. png_uint_32 i;
  168343. for (i = 0; i < row_width; i++)
  168344. {
  168345. *(--dp) = (png_byte)(255 - *(--sp));
  168346. *(--dp) = (png_byte)(255 - *(--sp));
  168347. sp-=2;
  168348. dp=sp;
  168349. }
  168350. }
  168351. }
  168352. }
  168353. }
  168354. #endif
  168355. #if defined(PNG_READ_FILLER_SUPPORTED)
  168356. void /* PRIVATE */
  168357. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168358. png_uint_32 filler, png_uint_32 flags)
  168359. {
  168360. png_uint_32 i;
  168361. png_uint_32 row_width = row_info->width;
  168362. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168363. png_byte lo_filler = (png_byte)(filler & 0xff);
  168364. png_debug(1, "in png_do_read_filler\n");
  168365. if (
  168366. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168367. row != NULL && row_info != NULL &&
  168368. #endif
  168369. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168370. {
  168371. if(row_info->bit_depth == 8)
  168372. {
  168373. if (flags & PNG_FLAG_FILLER_AFTER)
  168374. {
  168375. png_bytep sp = row + (png_size_t)row_width;
  168376. png_bytep dp = sp + (png_size_t)row_width;
  168377. for (i = 1; i < row_width; i++)
  168378. {
  168379. *(--dp) = lo_filler;
  168380. *(--dp) = *(--sp);
  168381. }
  168382. *(--dp) = lo_filler;
  168383. row_info->channels = 2;
  168384. row_info->pixel_depth = 16;
  168385. row_info->rowbytes = row_width * 2;
  168386. }
  168387. else
  168388. {
  168389. png_bytep sp = row + (png_size_t)row_width;
  168390. png_bytep dp = sp + (png_size_t)row_width;
  168391. for (i = 0; i < row_width; i++)
  168392. {
  168393. *(--dp) = *(--sp);
  168394. *(--dp) = lo_filler;
  168395. }
  168396. row_info->channels = 2;
  168397. row_info->pixel_depth = 16;
  168398. row_info->rowbytes = row_width * 2;
  168399. }
  168400. }
  168401. else if(row_info->bit_depth == 16)
  168402. {
  168403. if (flags & PNG_FLAG_FILLER_AFTER)
  168404. {
  168405. png_bytep sp = row + (png_size_t)row_width * 2;
  168406. png_bytep dp = sp + (png_size_t)row_width * 2;
  168407. for (i = 1; i < row_width; i++)
  168408. {
  168409. *(--dp) = hi_filler;
  168410. *(--dp) = lo_filler;
  168411. *(--dp) = *(--sp);
  168412. *(--dp) = *(--sp);
  168413. }
  168414. *(--dp) = hi_filler;
  168415. *(--dp) = lo_filler;
  168416. row_info->channels = 2;
  168417. row_info->pixel_depth = 32;
  168418. row_info->rowbytes = row_width * 4;
  168419. }
  168420. else
  168421. {
  168422. png_bytep sp = row + (png_size_t)row_width * 2;
  168423. png_bytep dp = sp + (png_size_t)row_width * 2;
  168424. for (i = 0; i < row_width; i++)
  168425. {
  168426. *(--dp) = *(--sp);
  168427. *(--dp) = *(--sp);
  168428. *(--dp) = hi_filler;
  168429. *(--dp) = lo_filler;
  168430. }
  168431. row_info->channels = 2;
  168432. row_info->pixel_depth = 32;
  168433. row_info->rowbytes = row_width * 4;
  168434. }
  168435. }
  168436. } /* COLOR_TYPE == GRAY */
  168437. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168438. {
  168439. if(row_info->bit_depth == 8)
  168440. {
  168441. if (flags & PNG_FLAG_FILLER_AFTER)
  168442. {
  168443. png_bytep sp = row + (png_size_t)row_width * 3;
  168444. png_bytep dp = sp + (png_size_t)row_width;
  168445. for (i = 1; i < row_width; i++)
  168446. {
  168447. *(--dp) = lo_filler;
  168448. *(--dp) = *(--sp);
  168449. *(--dp) = *(--sp);
  168450. *(--dp) = *(--sp);
  168451. }
  168452. *(--dp) = lo_filler;
  168453. row_info->channels = 4;
  168454. row_info->pixel_depth = 32;
  168455. row_info->rowbytes = row_width * 4;
  168456. }
  168457. else
  168458. {
  168459. png_bytep sp = row + (png_size_t)row_width * 3;
  168460. png_bytep dp = sp + (png_size_t)row_width;
  168461. for (i = 0; i < row_width; i++)
  168462. {
  168463. *(--dp) = *(--sp);
  168464. *(--dp) = *(--sp);
  168465. *(--dp) = *(--sp);
  168466. *(--dp) = lo_filler;
  168467. }
  168468. row_info->channels = 4;
  168469. row_info->pixel_depth = 32;
  168470. row_info->rowbytes = row_width * 4;
  168471. }
  168472. }
  168473. else if(row_info->bit_depth == 16)
  168474. {
  168475. if (flags & PNG_FLAG_FILLER_AFTER)
  168476. {
  168477. png_bytep sp = row + (png_size_t)row_width * 6;
  168478. png_bytep dp = sp + (png_size_t)row_width * 2;
  168479. for (i = 1; i < row_width; i++)
  168480. {
  168481. *(--dp) = hi_filler;
  168482. *(--dp) = lo_filler;
  168483. *(--dp) = *(--sp);
  168484. *(--dp) = *(--sp);
  168485. *(--dp) = *(--sp);
  168486. *(--dp) = *(--sp);
  168487. *(--dp) = *(--sp);
  168488. *(--dp) = *(--sp);
  168489. }
  168490. *(--dp) = hi_filler;
  168491. *(--dp) = lo_filler;
  168492. row_info->channels = 4;
  168493. row_info->pixel_depth = 64;
  168494. row_info->rowbytes = row_width * 8;
  168495. }
  168496. else
  168497. {
  168498. png_bytep sp = row + (png_size_t)row_width * 6;
  168499. png_bytep dp = sp + (png_size_t)row_width * 2;
  168500. for (i = 0; i < row_width; i++)
  168501. {
  168502. *(--dp) = *(--sp);
  168503. *(--dp) = *(--sp);
  168504. *(--dp) = *(--sp);
  168505. *(--dp) = *(--sp);
  168506. *(--dp) = *(--sp);
  168507. *(--dp) = *(--sp);
  168508. *(--dp) = hi_filler;
  168509. *(--dp) = lo_filler;
  168510. }
  168511. row_info->channels = 4;
  168512. row_info->pixel_depth = 64;
  168513. row_info->rowbytes = row_width * 8;
  168514. }
  168515. }
  168516. } /* COLOR_TYPE == RGB */
  168517. }
  168518. #endif
  168519. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168520. void /* PRIVATE */
  168521. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168522. {
  168523. png_uint_32 i;
  168524. png_uint_32 row_width = row_info->width;
  168525. png_debug(1, "in png_do_gray_to_rgb\n");
  168526. if (row_info->bit_depth >= 8 &&
  168527. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168528. row != NULL && row_info != NULL &&
  168529. #endif
  168530. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168531. {
  168532. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168533. {
  168534. if (row_info->bit_depth == 8)
  168535. {
  168536. png_bytep sp = row + (png_size_t)row_width - 1;
  168537. png_bytep dp = sp + (png_size_t)row_width * 2;
  168538. for (i = 0; i < row_width; i++)
  168539. {
  168540. *(dp--) = *sp;
  168541. *(dp--) = *sp;
  168542. *(dp--) = *(sp--);
  168543. }
  168544. }
  168545. else
  168546. {
  168547. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168548. png_bytep dp = sp + (png_size_t)row_width * 4;
  168549. for (i = 0; i < row_width; i++)
  168550. {
  168551. *(dp--) = *sp;
  168552. *(dp--) = *(sp - 1);
  168553. *(dp--) = *sp;
  168554. *(dp--) = *(sp - 1);
  168555. *(dp--) = *(sp--);
  168556. *(dp--) = *(sp--);
  168557. }
  168558. }
  168559. }
  168560. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168561. {
  168562. if (row_info->bit_depth == 8)
  168563. {
  168564. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168565. png_bytep dp = sp + (png_size_t)row_width * 2;
  168566. for (i = 0; i < row_width; i++)
  168567. {
  168568. *(dp--) = *(sp--);
  168569. *(dp--) = *sp;
  168570. *(dp--) = *sp;
  168571. *(dp--) = *(sp--);
  168572. }
  168573. }
  168574. else
  168575. {
  168576. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168577. png_bytep dp = sp + (png_size_t)row_width * 4;
  168578. for (i = 0; i < row_width; i++)
  168579. {
  168580. *(dp--) = *(sp--);
  168581. *(dp--) = *(sp--);
  168582. *(dp--) = *sp;
  168583. *(dp--) = *(sp - 1);
  168584. *(dp--) = *sp;
  168585. *(dp--) = *(sp - 1);
  168586. *(dp--) = *(sp--);
  168587. *(dp--) = *(sp--);
  168588. }
  168589. }
  168590. }
  168591. row_info->channels += (png_byte)2;
  168592. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168593. row_info->pixel_depth = (png_byte)(row_info->channels *
  168594. row_info->bit_depth);
  168595. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168596. }
  168597. }
  168598. #endif
  168599. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168600. int /* PRIVATE */
  168601. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168602. {
  168603. png_uint_32 i;
  168604. png_uint_32 row_width = row_info->width;
  168605. int rgb_error = 0;
  168606. png_debug(1, "in png_do_rgb_to_gray\n");
  168607. if (
  168608. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168609. row != NULL && row_info != NULL &&
  168610. #endif
  168611. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168612. {
  168613. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168614. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168615. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168616. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168617. {
  168618. if (row_info->bit_depth == 8)
  168619. {
  168620. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168621. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168622. {
  168623. png_bytep sp = row;
  168624. png_bytep dp = row;
  168625. for (i = 0; i < row_width; i++)
  168626. {
  168627. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168628. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168629. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168630. if(red != green || red != blue)
  168631. {
  168632. rgb_error |= 1;
  168633. *(dp++) = png_ptr->gamma_from_1[
  168634. (rc*red+gc*green+bc*blue)>>15];
  168635. }
  168636. else
  168637. *(dp++) = *(sp-1);
  168638. }
  168639. }
  168640. else
  168641. #endif
  168642. {
  168643. png_bytep sp = row;
  168644. png_bytep dp = row;
  168645. for (i = 0; i < row_width; i++)
  168646. {
  168647. png_byte red = *(sp++);
  168648. png_byte green = *(sp++);
  168649. png_byte blue = *(sp++);
  168650. if(red != green || red != blue)
  168651. {
  168652. rgb_error |= 1;
  168653. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168654. }
  168655. else
  168656. *(dp++) = *(sp-1);
  168657. }
  168658. }
  168659. }
  168660. else /* RGB bit_depth == 16 */
  168661. {
  168662. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168663. if (png_ptr->gamma_16_to_1 != NULL &&
  168664. png_ptr->gamma_16_from_1 != NULL)
  168665. {
  168666. png_bytep sp = row;
  168667. png_bytep dp = row;
  168668. for (i = 0; i < row_width; i++)
  168669. {
  168670. png_uint_16 red, green, blue, w;
  168671. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168672. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168673. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168674. if(red == green && red == blue)
  168675. w = red;
  168676. else
  168677. {
  168678. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168679. png_ptr->gamma_shift][red>>8];
  168680. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168681. png_ptr->gamma_shift][green>>8];
  168682. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168683. png_ptr->gamma_shift][blue>>8];
  168684. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168685. + bc*blue_1)>>15);
  168686. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168687. png_ptr->gamma_shift][gray16 >> 8];
  168688. rgb_error |= 1;
  168689. }
  168690. *(dp++) = (png_byte)((w>>8) & 0xff);
  168691. *(dp++) = (png_byte)(w & 0xff);
  168692. }
  168693. }
  168694. else
  168695. #endif
  168696. {
  168697. png_bytep sp = row;
  168698. png_bytep dp = row;
  168699. for (i = 0; i < row_width; i++)
  168700. {
  168701. png_uint_16 red, green, blue, gray16;
  168702. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168703. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168704. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168705. if(red != green || red != blue)
  168706. rgb_error |= 1;
  168707. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168708. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168709. *(dp++) = (png_byte)(gray16 & 0xff);
  168710. }
  168711. }
  168712. }
  168713. }
  168714. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168715. {
  168716. if (row_info->bit_depth == 8)
  168717. {
  168718. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168719. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168720. {
  168721. png_bytep sp = row;
  168722. png_bytep dp = row;
  168723. for (i = 0; i < row_width; i++)
  168724. {
  168725. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168726. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168727. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168728. if(red != green || red != blue)
  168729. rgb_error |= 1;
  168730. *(dp++) = png_ptr->gamma_from_1
  168731. [(rc*red + gc*green + bc*blue)>>15];
  168732. *(dp++) = *(sp++); /* alpha */
  168733. }
  168734. }
  168735. else
  168736. #endif
  168737. {
  168738. png_bytep sp = row;
  168739. png_bytep dp = row;
  168740. for (i = 0; i < row_width; i++)
  168741. {
  168742. png_byte red = *(sp++);
  168743. png_byte green = *(sp++);
  168744. png_byte blue = *(sp++);
  168745. if(red != green || red != blue)
  168746. rgb_error |= 1;
  168747. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168748. *(dp++) = *(sp++); /* alpha */
  168749. }
  168750. }
  168751. }
  168752. else /* RGBA bit_depth == 16 */
  168753. {
  168754. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168755. if (png_ptr->gamma_16_to_1 != NULL &&
  168756. png_ptr->gamma_16_from_1 != NULL)
  168757. {
  168758. png_bytep sp = row;
  168759. png_bytep dp = row;
  168760. for (i = 0; i < row_width; i++)
  168761. {
  168762. png_uint_16 red, green, blue, w;
  168763. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168764. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168765. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168766. if(red == green && red == blue)
  168767. w = red;
  168768. else
  168769. {
  168770. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168771. png_ptr->gamma_shift][red>>8];
  168772. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168773. png_ptr->gamma_shift][green>>8];
  168774. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168775. png_ptr->gamma_shift][blue>>8];
  168776. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168777. + gc * green_1 + bc * blue_1)>>15);
  168778. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168779. png_ptr->gamma_shift][gray16 >> 8];
  168780. rgb_error |= 1;
  168781. }
  168782. *(dp++) = (png_byte)((w>>8) & 0xff);
  168783. *(dp++) = (png_byte)(w & 0xff);
  168784. *(dp++) = *(sp++); /* alpha */
  168785. *(dp++) = *(sp++);
  168786. }
  168787. }
  168788. else
  168789. #endif
  168790. {
  168791. png_bytep sp = row;
  168792. png_bytep dp = row;
  168793. for (i = 0; i < row_width; i++)
  168794. {
  168795. png_uint_16 red, green, blue, gray16;
  168796. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168797. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168798. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168799. if(red != green || red != blue)
  168800. rgb_error |= 1;
  168801. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168802. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168803. *(dp++) = (png_byte)(gray16 & 0xff);
  168804. *(dp++) = *(sp++); /* alpha */
  168805. *(dp++) = *(sp++);
  168806. }
  168807. }
  168808. }
  168809. }
  168810. row_info->channels -= (png_byte)2;
  168811. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168812. row_info->pixel_depth = (png_byte)(row_info->channels *
  168813. row_info->bit_depth);
  168814. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168815. }
  168816. return rgb_error;
  168817. }
  168818. #endif
  168819. void PNGAPI
  168820. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  168821. {
  168822. int num_palette;
  168823. int color_inc;
  168824. int i;
  168825. int v;
  168826. png_debug(1, "in png_do_build_grayscale_palette\n");
  168827. if (palette == NULL)
  168828. return;
  168829. switch (bit_depth)
  168830. {
  168831. case 1:
  168832. num_palette = 2;
  168833. color_inc = 0xff;
  168834. break;
  168835. case 2:
  168836. num_palette = 4;
  168837. color_inc = 0x55;
  168838. break;
  168839. case 4:
  168840. num_palette = 16;
  168841. color_inc = 0x11;
  168842. break;
  168843. case 8:
  168844. num_palette = 256;
  168845. color_inc = 1;
  168846. break;
  168847. default:
  168848. num_palette = 0;
  168849. color_inc = 0;
  168850. break;
  168851. }
  168852. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  168853. {
  168854. palette[i].red = (png_byte)v;
  168855. palette[i].green = (png_byte)v;
  168856. palette[i].blue = (png_byte)v;
  168857. }
  168858. }
  168859. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  168860. void /* PRIVATE */
  168861. png_correct_palette(png_structp png_ptr, png_colorp palette,
  168862. int num_palette)
  168863. {
  168864. png_debug(1, "in png_correct_palette\n");
  168865. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  168866. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168867. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  168868. {
  168869. png_color back, back_1;
  168870. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168871. {
  168872. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168873. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168874. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168875. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168876. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168877. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168878. }
  168879. else
  168880. {
  168881. double g;
  168882. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  168883. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  168884. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  168885. {
  168886. back.red = png_ptr->background.red;
  168887. back.green = png_ptr->background.green;
  168888. back.blue = png_ptr->background.blue;
  168889. }
  168890. else
  168891. {
  168892. back.red =
  168893. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  168894. 255.0 + 0.5);
  168895. back.green =
  168896. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  168897. 255.0 + 0.5);
  168898. back.blue =
  168899. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  168900. 255.0 + 0.5);
  168901. }
  168902. g = 1.0 / png_ptr->background_gamma;
  168903. back_1.red =
  168904. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  168905. 255.0 + 0.5);
  168906. back_1.green =
  168907. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  168908. 255.0 + 0.5);
  168909. back_1.blue =
  168910. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  168911. 255.0 + 0.5);
  168912. }
  168913. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168914. {
  168915. png_uint_32 i;
  168916. for (i = 0; i < (png_uint_32)num_palette; i++)
  168917. {
  168918. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  168919. {
  168920. palette[i] = back;
  168921. }
  168922. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168923. {
  168924. png_byte v, w;
  168925. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  168926. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168927. palette[i].red = png_ptr->gamma_from_1[w];
  168928. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  168929. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168930. palette[i].green = png_ptr->gamma_from_1[w];
  168931. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  168932. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168933. palette[i].blue = png_ptr->gamma_from_1[w];
  168934. }
  168935. else
  168936. {
  168937. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168938. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168939. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168940. }
  168941. }
  168942. }
  168943. else
  168944. {
  168945. int i;
  168946. for (i = 0; i < num_palette; i++)
  168947. {
  168948. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  168949. {
  168950. palette[i] = back;
  168951. }
  168952. else
  168953. {
  168954. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168955. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168956. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168957. }
  168958. }
  168959. }
  168960. }
  168961. else
  168962. #endif
  168963. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168964. if (png_ptr->transformations & PNG_GAMMA)
  168965. {
  168966. int i;
  168967. for (i = 0; i < num_palette; i++)
  168968. {
  168969. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168970. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168971. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168972. }
  168973. }
  168974. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168975. else
  168976. #endif
  168977. #endif
  168978. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168979. if (png_ptr->transformations & PNG_BACKGROUND)
  168980. {
  168981. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168982. {
  168983. png_color back;
  168984. back.red = (png_byte)png_ptr->background.red;
  168985. back.green = (png_byte)png_ptr->background.green;
  168986. back.blue = (png_byte)png_ptr->background.blue;
  168987. for (i = 0; i < (int)png_ptr->num_trans; i++)
  168988. {
  168989. if (png_ptr->trans[i] == 0)
  168990. {
  168991. palette[i].red = back.red;
  168992. palette[i].green = back.green;
  168993. palette[i].blue = back.blue;
  168994. }
  168995. else if (png_ptr->trans[i] != 0xff)
  168996. {
  168997. png_composite(palette[i].red, png_ptr->palette[i].red,
  168998. png_ptr->trans[i], back.red);
  168999. png_composite(palette[i].green, png_ptr->palette[i].green,
  169000. png_ptr->trans[i], back.green);
  169001. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169002. png_ptr->trans[i], back.blue);
  169003. }
  169004. }
  169005. }
  169006. else /* assume grayscale palette (what else could it be?) */
  169007. {
  169008. int i;
  169009. for (i = 0; i < num_palette; i++)
  169010. {
  169011. if (i == (png_byte)png_ptr->trans_values.gray)
  169012. {
  169013. palette[i].red = (png_byte)png_ptr->background.red;
  169014. palette[i].green = (png_byte)png_ptr->background.green;
  169015. palette[i].blue = (png_byte)png_ptr->background.blue;
  169016. }
  169017. }
  169018. }
  169019. }
  169020. #endif
  169021. }
  169022. #endif
  169023. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169024. void /* PRIVATE */
  169025. png_do_background(png_row_infop row_info, png_bytep row,
  169026. png_color_16p trans_values, png_color_16p background
  169027. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169028. , png_color_16p background_1,
  169029. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169030. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169031. png_uint_16pp gamma_16_to_1, int gamma_shift
  169032. #endif
  169033. )
  169034. {
  169035. png_bytep sp, dp;
  169036. png_uint_32 i;
  169037. png_uint_32 row_width=row_info->width;
  169038. int shift;
  169039. png_debug(1, "in png_do_background\n");
  169040. if (background != NULL &&
  169041. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169042. row != NULL && row_info != NULL &&
  169043. #endif
  169044. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169045. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169046. {
  169047. switch (row_info->color_type)
  169048. {
  169049. case PNG_COLOR_TYPE_GRAY:
  169050. {
  169051. switch (row_info->bit_depth)
  169052. {
  169053. case 1:
  169054. {
  169055. sp = row;
  169056. shift = 7;
  169057. for (i = 0; i < row_width; i++)
  169058. {
  169059. if ((png_uint_16)((*sp >> shift) & 0x01)
  169060. == trans_values->gray)
  169061. {
  169062. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169063. *sp |= (png_byte)(background->gray << shift);
  169064. }
  169065. if (!shift)
  169066. {
  169067. shift = 7;
  169068. sp++;
  169069. }
  169070. else
  169071. shift--;
  169072. }
  169073. break;
  169074. }
  169075. case 2:
  169076. {
  169077. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169078. if (gamma_table != NULL)
  169079. {
  169080. sp = row;
  169081. shift = 6;
  169082. for (i = 0; i < row_width; i++)
  169083. {
  169084. if ((png_uint_16)((*sp >> shift) & 0x03)
  169085. == trans_values->gray)
  169086. {
  169087. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169088. *sp |= (png_byte)(background->gray << shift);
  169089. }
  169090. else
  169091. {
  169092. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169093. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169094. (p << 4) | (p << 6)] >> 6) & 0x03);
  169095. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169096. *sp |= (png_byte)(g << shift);
  169097. }
  169098. if (!shift)
  169099. {
  169100. shift = 6;
  169101. sp++;
  169102. }
  169103. else
  169104. shift -= 2;
  169105. }
  169106. }
  169107. else
  169108. #endif
  169109. {
  169110. sp = row;
  169111. shift = 6;
  169112. for (i = 0; i < row_width; i++)
  169113. {
  169114. if ((png_uint_16)((*sp >> shift) & 0x03)
  169115. == trans_values->gray)
  169116. {
  169117. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169118. *sp |= (png_byte)(background->gray << shift);
  169119. }
  169120. if (!shift)
  169121. {
  169122. shift = 6;
  169123. sp++;
  169124. }
  169125. else
  169126. shift -= 2;
  169127. }
  169128. }
  169129. break;
  169130. }
  169131. case 4:
  169132. {
  169133. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169134. if (gamma_table != NULL)
  169135. {
  169136. sp = row;
  169137. shift = 4;
  169138. for (i = 0; i < row_width; i++)
  169139. {
  169140. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169141. == trans_values->gray)
  169142. {
  169143. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169144. *sp |= (png_byte)(background->gray << shift);
  169145. }
  169146. else
  169147. {
  169148. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169149. png_byte g = (png_byte)((gamma_table[p |
  169150. (p << 4)] >> 4) & 0x0f);
  169151. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169152. *sp |= (png_byte)(g << shift);
  169153. }
  169154. if (!shift)
  169155. {
  169156. shift = 4;
  169157. sp++;
  169158. }
  169159. else
  169160. shift -= 4;
  169161. }
  169162. }
  169163. else
  169164. #endif
  169165. {
  169166. sp = row;
  169167. shift = 4;
  169168. for (i = 0; i < row_width; i++)
  169169. {
  169170. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169171. == trans_values->gray)
  169172. {
  169173. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169174. *sp |= (png_byte)(background->gray << shift);
  169175. }
  169176. if (!shift)
  169177. {
  169178. shift = 4;
  169179. sp++;
  169180. }
  169181. else
  169182. shift -= 4;
  169183. }
  169184. }
  169185. break;
  169186. }
  169187. case 8:
  169188. {
  169189. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169190. if (gamma_table != NULL)
  169191. {
  169192. sp = row;
  169193. for (i = 0; i < row_width; i++, sp++)
  169194. {
  169195. if (*sp == trans_values->gray)
  169196. {
  169197. *sp = (png_byte)background->gray;
  169198. }
  169199. else
  169200. {
  169201. *sp = gamma_table[*sp];
  169202. }
  169203. }
  169204. }
  169205. else
  169206. #endif
  169207. {
  169208. sp = row;
  169209. for (i = 0; i < row_width; i++, sp++)
  169210. {
  169211. if (*sp == trans_values->gray)
  169212. {
  169213. *sp = (png_byte)background->gray;
  169214. }
  169215. }
  169216. }
  169217. break;
  169218. }
  169219. case 16:
  169220. {
  169221. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169222. if (gamma_16 != NULL)
  169223. {
  169224. sp = row;
  169225. for (i = 0; i < row_width; i++, sp += 2)
  169226. {
  169227. png_uint_16 v;
  169228. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169229. if (v == trans_values->gray)
  169230. {
  169231. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169232. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169233. }
  169234. else
  169235. {
  169236. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169237. *sp = (png_byte)((v >> 8) & 0xff);
  169238. *(sp + 1) = (png_byte)(v & 0xff);
  169239. }
  169240. }
  169241. }
  169242. else
  169243. #endif
  169244. {
  169245. sp = row;
  169246. for (i = 0; i < row_width; i++, sp += 2)
  169247. {
  169248. png_uint_16 v;
  169249. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169250. if (v == trans_values->gray)
  169251. {
  169252. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169253. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169254. }
  169255. }
  169256. }
  169257. break;
  169258. }
  169259. }
  169260. break;
  169261. }
  169262. case PNG_COLOR_TYPE_RGB:
  169263. {
  169264. if (row_info->bit_depth == 8)
  169265. {
  169266. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169267. if (gamma_table != NULL)
  169268. {
  169269. sp = row;
  169270. for (i = 0; i < row_width; i++, sp += 3)
  169271. {
  169272. if (*sp == trans_values->red &&
  169273. *(sp + 1) == trans_values->green &&
  169274. *(sp + 2) == trans_values->blue)
  169275. {
  169276. *sp = (png_byte)background->red;
  169277. *(sp + 1) = (png_byte)background->green;
  169278. *(sp + 2) = (png_byte)background->blue;
  169279. }
  169280. else
  169281. {
  169282. *sp = gamma_table[*sp];
  169283. *(sp + 1) = gamma_table[*(sp + 1)];
  169284. *(sp + 2) = gamma_table[*(sp + 2)];
  169285. }
  169286. }
  169287. }
  169288. else
  169289. #endif
  169290. {
  169291. sp = row;
  169292. for (i = 0; i < row_width; i++, sp += 3)
  169293. {
  169294. if (*sp == trans_values->red &&
  169295. *(sp + 1) == trans_values->green &&
  169296. *(sp + 2) == trans_values->blue)
  169297. {
  169298. *sp = (png_byte)background->red;
  169299. *(sp + 1) = (png_byte)background->green;
  169300. *(sp + 2) = (png_byte)background->blue;
  169301. }
  169302. }
  169303. }
  169304. }
  169305. else /* if (row_info->bit_depth == 16) */
  169306. {
  169307. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169308. if (gamma_16 != NULL)
  169309. {
  169310. sp = row;
  169311. for (i = 0; i < row_width; i++, sp += 6)
  169312. {
  169313. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169314. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169315. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169316. if (r == trans_values->red && g == trans_values->green &&
  169317. b == trans_values->blue)
  169318. {
  169319. *sp = (png_byte)((background->red >> 8) & 0xff);
  169320. *(sp + 1) = (png_byte)(background->red & 0xff);
  169321. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169322. *(sp + 3) = (png_byte)(background->green & 0xff);
  169323. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169324. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169325. }
  169326. else
  169327. {
  169328. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169329. *sp = (png_byte)((v >> 8) & 0xff);
  169330. *(sp + 1) = (png_byte)(v & 0xff);
  169331. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169332. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169333. *(sp + 3) = (png_byte)(v & 0xff);
  169334. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169335. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169336. *(sp + 5) = (png_byte)(v & 0xff);
  169337. }
  169338. }
  169339. }
  169340. else
  169341. #endif
  169342. {
  169343. sp = row;
  169344. for (i = 0; i < row_width; i++, sp += 6)
  169345. {
  169346. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169347. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169348. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169349. if (r == trans_values->red && g == trans_values->green &&
  169350. b == trans_values->blue)
  169351. {
  169352. *sp = (png_byte)((background->red >> 8) & 0xff);
  169353. *(sp + 1) = (png_byte)(background->red & 0xff);
  169354. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169355. *(sp + 3) = (png_byte)(background->green & 0xff);
  169356. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169357. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169358. }
  169359. }
  169360. }
  169361. }
  169362. break;
  169363. }
  169364. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169365. {
  169366. if (row_info->bit_depth == 8)
  169367. {
  169368. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169369. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169370. gamma_table != NULL)
  169371. {
  169372. sp = row;
  169373. dp = row;
  169374. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169375. {
  169376. png_uint_16 a = *(sp + 1);
  169377. if (a == 0xff)
  169378. {
  169379. *dp = gamma_table[*sp];
  169380. }
  169381. else if (a == 0)
  169382. {
  169383. *dp = (png_byte)background->gray;
  169384. }
  169385. else
  169386. {
  169387. png_byte v, w;
  169388. v = gamma_to_1[*sp];
  169389. png_composite(w, v, a, background_1->gray);
  169390. *dp = gamma_from_1[w];
  169391. }
  169392. }
  169393. }
  169394. else
  169395. #endif
  169396. {
  169397. sp = row;
  169398. dp = row;
  169399. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169400. {
  169401. png_byte a = *(sp + 1);
  169402. if (a == 0xff)
  169403. {
  169404. *dp = *sp;
  169405. }
  169406. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169407. else if (a == 0)
  169408. {
  169409. *dp = (png_byte)background->gray;
  169410. }
  169411. else
  169412. {
  169413. png_composite(*dp, *sp, a, background_1->gray);
  169414. }
  169415. #else
  169416. *dp = (png_byte)background->gray;
  169417. #endif
  169418. }
  169419. }
  169420. }
  169421. else /* if (png_ptr->bit_depth == 16) */
  169422. {
  169423. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169424. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169425. gamma_16_to_1 != NULL)
  169426. {
  169427. sp = row;
  169428. dp = row;
  169429. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169430. {
  169431. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169432. if (a == (png_uint_16)0xffff)
  169433. {
  169434. png_uint_16 v;
  169435. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169436. *dp = (png_byte)((v >> 8) & 0xff);
  169437. *(dp + 1) = (png_byte)(v & 0xff);
  169438. }
  169439. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169440. else if (a == 0)
  169441. #else
  169442. else
  169443. #endif
  169444. {
  169445. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169446. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169447. }
  169448. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169449. else
  169450. {
  169451. png_uint_16 g, v, w;
  169452. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169453. png_composite_16(v, g, a, background_1->gray);
  169454. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169455. *dp = (png_byte)((w >> 8) & 0xff);
  169456. *(dp + 1) = (png_byte)(w & 0xff);
  169457. }
  169458. #endif
  169459. }
  169460. }
  169461. else
  169462. #endif
  169463. {
  169464. sp = row;
  169465. dp = row;
  169466. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169467. {
  169468. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169469. if (a == (png_uint_16)0xffff)
  169470. {
  169471. png_memcpy(dp, sp, 2);
  169472. }
  169473. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169474. else if (a == 0)
  169475. #else
  169476. else
  169477. #endif
  169478. {
  169479. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169480. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169481. }
  169482. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169483. else
  169484. {
  169485. png_uint_16 g, v;
  169486. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169487. png_composite_16(v, g, a, background_1->gray);
  169488. *dp = (png_byte)((v >> 8) & 0xff);
  169489. *(dp + 1) = (png_byte)(v & 0xff);
  169490. }
  169491. #endif
  169492. }
  169493. }
  169494. }
  169495. break;
  169496. }
  169497. case PNG_COLOR_TYPE_RGB_ALPHA:
  169498. {
  169499. if (row_info->bit_depth == 8)
  169500. {
  169501. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169502. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169503. gamma_table != NULL)
  169504. {
  169505. sp = row;
  169506. dp = row;
  169507. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169508. {
  169509. png_byte a = *(sp + 3);
  169510. if (a == 0xff)
  169511. {
  169512. *dp = gamma_table[*sp];
  169513. *(dp + 1) = gamma_table[*(sp + 1)];
  169514. *(dp + 2) = gamma_table[*(sp + 2)];
  169515. }
  169516. else if (a == 0)
  169517. {
  169518. *dp = (png_byte)background->red;
  169519. *(dp + 1) = (png_byte)background->green;
  169520. *(dp + 2) = (png_byte)background->blue;
  169521. }
  169522. else
  169523. {
  169524. png_byte v, w;
  169525. v = gamma_to_1[*sp];
  169526. png_composite(w, v, a, background_1->red);
  169527. *dp = gamma_from_1[w];
  169528. v = gamma_to_1[*(sp + 1)];
  169529. png_composite(w, v, a, background_1->green);
  169530. *(dp + 1) = gamma_from_1[w];
  169531. v = gamma_to_1[*(sp + 2)];
  169532. png_composite(w, v, a, background_1->blue);
  169533. *(dp + 2) = gamma_from_1[w];
  169534. }
  169535. }
  169536. }
  169537. else
  169538. #endif
  169539. {
  169540. sp = row;
  169541. dp = row;
  169542. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169543. {
  169544. png_byte a = *(sp + 3);
  169545. if (a == 0xff)
  169546. {
  169547. *dp = *sp;
  169548. *(dp + 1) = *(sp + 1);
  169549. *(dp + 2) = *(sp + 2);
  169550. }
  169551. else if (a == 0)
  169552. {
  169553. *dp = (png_byte)background->red;
  169554. *(dp + 1) = (png_byte)background->green;
  169555. *(dp + 2) = (png_byte)background->blue;
  169556. }
  169557. else
  169558. {
  169559. png_composite(*dp, *sp, a, background->red);
  169560. png_composite(*(dp + 1), *(sp + 1), a,
  169561. background->green);
  169562. png_composite(*(dp + 2), *(sp + 2), a,
  169563. background->blue);
  169564. }
  169565. }
  169566. }
  169567. }
  169568. else /* if (row_info->bit_depth == 16) */
  169569. {
  169570. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169571. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169572. gamma_16_to_1 != NULL)
  169573. {
  169574. sp = row;
  169575. dp = row;
  169576. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169577. {
  169578. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169579. << 8) + (png_uint_16)(*(sp + 7)));
  169580. if (a == (png_uint_16)0xffff)
  169581. {
  169582. png_uint_16 v;
  169583. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169584. *dp = (png_byte)((v >> 8) & 0xff);
  169585. *(dp + 1) = (png_byte)(v & 0xff);
  169586. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169587. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169588. *(dp + 3) = (png_byte)(v & 0xff);
  169589. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169590. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169591. *(dp + 5) = (png_byte)(v & 0xff);
  169592. }
  169593. else if (a == 0)
  169594. {
  169595. *dp = (png_byte)((background->red >> 8) & 0xff);
  169596. *(dp + 1) = (png_byte)(background->red & 0xff);
  169597. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169598. *(dp + 3) = (png_byte)(background->green & 0xff);
  169599. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169600. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169601. }
  169602. else
  169603. {
  169604. png_uint_16 v, w, x;
  169605. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169606. png_composite_16(w, v, a, background_1->red);
  169607. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169608. *dp = (png_byte)((x >> 8) & 0xff);
  169609. *(dp + 1) = (png_byte)(x & 0xff);
  169610. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169611. png_composite_16(w, v, a, background_1->green);
  169612. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169613. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169614. *(dp + 3) = (png_byte)(x & 0xff);
  169615. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169616. png_composite_16(w, v, a, background_1->blue);
  169617. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169618. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169619. *(dp + 5) = (png_byte)(x & 0xff);
  169620. }
  169621. }
  169622. }
  169623. else
  169624. #endif
  169625. {
  169626. sp = row;
  169627. dp = row;
  169628. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169629. {
  169630. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169631. << 8) + (png_uint_16)(*(sp + 7)));
  169632. if (a == (png_uint_16)0xffff)
  169633. {
  169634. png_memcpy(dp, sp, 6);
  169635. }
  169636. else if (a == 0)
  169637. {
  169638. *dp = (png_byte)((background->red >> 8) & 0xff);
  169639. *(dp + 1) = (png_byte)(background->red & 0xff);
  169640. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169641. *(dp + 3) = (png_byte)(background->green & 0xff);
  169642. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169643. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169644. }
  169645. else
  169646. {
  169647. png_uint_16 v;
  169648. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169649. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169650. + *(sp + 3));
  169651. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169652. + *(sp + 5));
  169653. png_composite_16(v, r, a, background->red);
  169654. *dp = (png_byte)((v >> 8) & 0xff);
  169655. *(dp + 1) = (png_byte)(v & 0xff);
  169656. png_composite_16(v, g, a, background->green);
  169657. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169658. *(dp + 3) = (png_byte)(v & 0xff);
  169659. png_composite_16(v, b, a, background->blue);
  169660. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169661. *(dp + 5) = (png_byte)(v & 0xff);
  169662. }
  169663. }
  169664. }
  169665. }
  169666. break;
  169667. }
  169668. }
  169669. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169670. {
  169671. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169672. row_info->channels--;
  169673. row_info->pixel_depth = (png_byte)(row_info->channels *
  169674. row_info->bit_depth);
  169675. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169676. }
  169677. }
  169678. }
  169679. #endif
  169680. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169681. void /* PRIVATE */
  169682. png_do_gamma(png_row_infop row_info, png_bytep row,
  169683. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169684. int gamma_shift)
  169685. {
  169686. png_bytep sp;
  169687. png_uint_32 i;
  169688. png_uint_32 row_width=row_info->width;
  169689. png_debug(1, "in png_do_gamma\n");
  169690. if (
  169691. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169692. row != NULL && row_info != NULL &&
  169693. #endif
  169694. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169695. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169696. {
  169697. switch (row_info->color_type)
  169698. {
  169699. case PNG_COLOR_TYPE_RGB:
  169700. {
  169701. if (row_info->bit_depth == 8)
  169702. {
  169703. sp = row;
  169704. for (i = 0; i < row_width; i++)
  169705. {
  169706. *sp = gamma_table[*sp];
  169707. sp++;
  169708. *sp = gamma_table[*sp];
  169709. sp++;
  169710. *sp = gamma_table[*sp];
  169711. sp++;
  169712. }
  169713. }
  169714. else /* if (row_info->bit_depth == 16) */
  169715. {
  169716. sp = row;
  169717. for (i = 0; i < row_width; i++)
  169718. {
  169719. png_uint_16 v;
  169720. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169721. *sp = (png_byte)((v >> 8) & 0xff);
  169722. *(sp + 1) = (png_byte)(v & 0xff);
  169723. sp += 2;
  169724. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169725. *sp = (png_byte)((v >> 8) & 0xff);
  169726. *(sp + 1) = (png_byte)(v & 0xff);
  169727. sp += 2;
  169728. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169729. *sp = (png_byte)((v >> 8) & 0xff);
  169730. *(sp + 1) = (png_byte)(v & 0xff);
  169731. sp += 2;
  169732. }
  169733. }
  169734. break;
  169735. }
  169736. case PNG_COLOR_TYPE_RGB_ALPHA:
  169737. {
  169738. if (row_info->bit_depth == 8)
  169739. {
  169740. sp = row;
  169741. for (i = 0; i < row_width; i++)
  169742. {
  169743. *sp = gamma_table[*sp];
  169744. sp++;
  169745. *sp = gamma_table[*sp];
  169746. sp++;
  169747. *sp = gamma_table[*sp];
  169748. sp++;
  169749. sp++;
  169750. }
  169751. }
  169752. else /* if (row_info->bit_depth == 16) */
  169753. {
  169754. sp = row;
  169755. for (i = 0; i < row_width; i++)
  169756. {
  169757. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169758. *sp = (png_byte)((v >> 8) & 0xff);
  169759. *(sp + 1) = (png_byte)(v & 0xff);
  169760. sp += 2;
  169761. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169762. *sp = (png_byte)((v >> 8) & 0xff);
  169763. *(sp + 1) = (png_byte)(v & 0xff);
  169764. sp += 2;
  169765. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169766. *sp = (png_byte)((v >> 8) & 0xff);
  169767. *(sp + 1) = (png_byte)(v & 0xff);
  169768. sp += 4;
  169769. }
  169770. }
  169771. break;
  169772. }
  169773. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169774. {
  169775. if (row_info->bit_depth == 8)
  169776. {
  169777. sp = row;
  169778. for (i = 0; i < row_width; i++)
  169779. {
  169780. *sp = gamma_table[*sp];
  169781. sp += 2;
  169782. }
  169783. }
  169784. else /* if (row_info->bit_depth == 16) */
  169785. {
  169786. sp = row;
  169787. for (i = 0; i < row_width; i++)
  169788. {
  169789. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169790. *sp = (png_byte)((v >> 8) & 0xff);
  169791. *(sp + 1) = (png_byte)(v & 0xff);
  169792. sp += 4;
  169793. }
  169794. }
  169795. break;
  169796. }
  169797. case PNG_COLOR_TYPE_GRAY:
  169798. {
  169799. if (row_info->bit_depth == 2)
  169800. {
  169801. sp = row;
  169802. for (i = 0; i < row_width; i += 4)
  169803. {
  169804. int a = *sp & 0xc0;
  169805. int b = *sp & 0x30;
  169806. int c = *sp & 0x0c;
  169807. int d = *sp & 0x03;
  169808. *sp = (png_byte)(
  169809. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169810. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169811. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169812. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  169813. sp++;
  169814. }
  169815. }
  169816. if (row_info->bit_depth == 4)
  169817. {
  169818. sp = row;
  169819. for (i = 0; i < row_width; i += 2)
  169820. {
  169821. int msb = *sp & 0xf0;
  169822. int lsb = *sp & 0x0f;
  169823. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  169824. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  169825. sp++;
  169826. }
  169827. }
  169828. else if (row_info->bit_depth == 8)
  169829. {
  169830. sp = row;
  169831. for (i = 0; i < row_width; i++)
  169832. {
  169833. *sp = gamma_table[*sp];
  169834. sp++;
  169835. }
  169836. }
  169837. else if (row_info->bit_depth == 16)
  169838. {
  169839. sp = row;
  169840. for (i = 0; i < row_width; i++)
  169841. {
  169842. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169843. *sp = (png_byte)((v >> 8) & 0xff);
  169844. *(sp + 1) = (png_byte)(v & 0xff);
  169845. sp += 2;
  169846. }
  169847. }
  169848. break;
  169849. }
  169850. }
  169851. }
  169852. }
  169853. #endif
  169854. #if defined(PNG_READ_EXPAND_SUPPORTED)
  169855. void /* PRIVATE */
  169856. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  169857. png_colorp palette, png_bytep trans, int num_trans)
  169858. {
  169859. int shift, value;
  169860. png_bytep sp, dp;
  169861. png_uint_32 i;
  169862. png_uint_32 row_width=row_info->width;
  169863. png_debug(1, "in png_do_expand_palette\n");
  169864. if (
  169865. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169866. row != NULL && row_info != NULL &&
  169867. #endif
  169868. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  169869. {
  169870. if (row_info->bit_depth < 8)
  169871. {
  169872. switch (row_info->bit_depth)
  169873. {
  169874. case 1:
  169875. {
  169876. sp = row + (png_size_t)((row_width - 1) >> 3);
  169877. dp = row + (png_size_t)row_width - 1;
  169878. shift = 7 - (int)((row_width + 7) & 0x07);
  169879. for (i = 0; i < row_width; i++)
  169880. {
  169881. if ((*sp >> shift) & 0x01)
  169882. *dp = 1;
  169883. else
  169884. *dp = 0;
  169885. if (shift == 7)
  169886. {
  169887. shift = 0;
  169888. sp--;
  169889. }
  169890. else
  169891. shift++;
  169892. dp--;
  169893. }
  169894. break;
  169895. }
  169896. case 2:
  169897. {
  169898. sp = row + (png_size_t)((row_width - 1) >> 2);
  169899. dp = row + (png_size_t)row_width - 1;
  169900. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  169901. for (i = 0; i < row_width; i++)
  169902. {
  169903. value = (*sp >> shift) & 0x03;
  169904. *dp = (png_byte)value;
  169905. if (shift == 6)
  169906. {
  169907. shift = 0;
  169908. sp--;
  169909. }
  169910. else
  169911. shift += 2;
  169912. dp--;
  169913. }
  169914. break;
  169915. }
  169916. case 4:
  169917. {
  169918. sp = row + (png_size_t)((row_width - 1) >> 1);
  169919. dp = row + (png_size_t)row_width - 1;
  169920. shift = (int)((row_width & 0x01) << 2);
  169921. for (i = 0; i < row_width; i++)
  169922. {
  169923. value = (*sp >> shift) & 0x0f;
  169924. *dp = (png_byte)value;
  169925. if (shift == 4)
  169926. {
  169927. shift = 0;
  169928. sp--;
  169929. }
  169930. else
  169931. shift += 4;
  169932. dp--;
  169933. }
  169934. break;
  169935. }
  169936. }
  169937. row_info->bit_depth = 8;
  169938. row_info->pixel_depth = 8;
  169939. row_info->rowbytes = row_width;
  169940. }
  169941. switch (row_info->bit_depth)
  169942. {
  169943. case 8:
  169944. {
  169945. if (trans != NULL)
  169946. {
  169947. sp = row + (png_size_t)row_width - 1;
  169948. dp = row + (png_size_t)(row_width << 2) - 1;
  169949. for (i = 0; i < row_width; i++)
  169950. {
  169951. if ((int)(*sp) >= num_trans)
  169952. *dp-- = 0xff;
  169953. else
  169954. *dp-- = trans[*sp];
  169955. *dp-- = palette[*sp].blue;
  169956. *dp-- = palette[*sp].green;
  169957. *dp-- = palette[*sp].red;
  169958. sp--;
  169959. }
  169960. row_info->bit_depth = 8;
  169961. row_info->pixel_depth = 32;
  169962. row_info->rowbytes = row_width * 4;
  169963. row_info->color_type = 6;
  169964. row_info->channels = 4;
  169965. }
  169966. else
  169967. {
  169968. sp = row + (png_size_t)row_width - 1;
  169969. dp = row + (png_size_t)(row_width * 3) - 1;
  169970. for (i = 0; i < row_width; i++)
  169971. {
  169972. *dp-- = palette[*sp].blue;
  169973. *dp-- = palette[*sp].green;
  169974. *dp-- = palette[*sp].red;
  169975. sp--;
  169976. }
  169977. row_info->bit_depth = 8;
  169978. row_info->pixel_depth = 24;
  169979. row_info->rowbytes = row_width * 3;
  169980. row_info->color_type = 2;
  169981. row_info->channels = 3;
  169982. }
  169983. break;
  169984. }
  169985. }
  169986. }
  169987. }
  169988. void /* PRIVATE */
  169989. png_do_expand(png_row_infop row_info, png_bytep row,
  169990. png_color_16p trans_value)
  169991. {
  169992. int shift, value;
  169993. png_bytep sp, dp;
  169994. png_uint_32 i;
  169995. png_uint_32 row_width=row_info->width;
  169996. png_debug(1, "in png_do_expand\n");
  169997. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169998. if (row != NULL && row_info != NULL)
  169999. #endif
  170000. {
  170001. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170002. {
  170003. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170004. if (row_info->bit_depth < 8)
  170005. {
  170006. switch (row_info->bit_depth)
  170007. {
  170008. case 1:
  170009. {
  170010. gray = (png_uint_16)((gray&0x01)*0xff);
  170011. sp = row + (png_size_t)((row_width - 1) >> 3);
  170012. dp = row + (png_size_t)row_width - 1;
  170013. shift = 7 - (int)((row_width + 7) & 0x07);
  170014. for (i = 0; i < row_width; i++)
  170015. {
  170016. if ((*sp >> shift) & 0x01)
  170017. *dp = 0xff;
  170018. else
  170019. *dp = 0;
  170020. if (shift == 7)
  170021. {
  170022. shift = 0;
  170023. sp--;
  170024. }
  170025. else
  170026. shift++;
  170027. dp--;
  170028. }
  170029. break;
  170030. }
  170031. case 2:
  170032. {
  170033. gray = (png_uint_16)((gray&0x03)*0x55);
  170034. sp = row + (png_size_t)((row_width - 1) >> 2);
  170035. dp = row + (png_size_t)row_width - 1;
  170036. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170037. for (i = 0; i < row_width; i++)
  170038. {
  170039. value = (*sp >> shift) & 0x03;
  170040. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170041. (value << 6));
  170042. if (shift == 6)
  170043. {
  170044. shift = 0;
  170045. sp--;
  170046. }
  170047. else
  170048. shift += 2;
  170049. dp--;
  170050. }
  170051. break;
  170052. }
  170053. case 4:
  170054. {
  170055. gray = (png_uint_16)((gray&0x0f)*0x11);
  170056. sp = row + (png_size_t)((row_width - 1) >> 1);
  170057. dp = row + (png_size_t)row_width - 1;
  170058. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170059. for (i = 0; i < row_width; i++)
  170060. {
  170061. value = (*sp >> shift) & 0x0f;
  170062. *dp = (png_byte)(value | (value << 4));
  170063. if (shift == 4)
  170064. {
  170065. shift = 0;
  170066. sp--;
  170067. }
  170068. else
  170069. shift = 4;
  170070. dp--;
  170071. }
  170072. break;
  170073. }
  170074. }
  170075. row_info->bit_depth = 8;
  170076. row_info->pixel_depth = 8;
  170077. row_info->rowbytes = row_width;
  170078. }
  170079. if (trans_value != NULL)
  170080. {
  170081. if (row_info->bit_depth == 8)
  170082. {
  170083. gray = gray & 0xff;
  170084. sp = row + (png_size_t)row_width - 1;
  170085. dp = row + (png_size_t)(row_width << 1) - 1;
  170086. for (i = 0; i < row_width; i++)
  170087. {
  170088. if (*sp == gray)
  170089. *dp-- = 0;
  170090. else
  170091. *dp-- = 0xff;
  170092. *dp-- = *sp--;
  170093. }
  170094. }
  170095. else if (row_info->bit_depth == 16)
  170096. {
  170097. png_byte gray_high = (gray >> 8) & 0xff;
  170098. png_byte gray_low = gray & 0xff;
  170099. sp = row + row_info->rowbytes - 1;
  170100. dp = row + (row_info->rowbytes << 1) - 1;
  170101. for (i = 0; i < row_width; i++)
  170102. {
  170103. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170104. {
  170105. *dp-- = 0;
  170106. *dp-- = 0;
  170107. }
  170108. else
  170109. {
  170110. *dp-- = 0xff;
  170111. *dp-- = 0xff;
  170112. }
  170113. *dp-- = *sp--;
  170114. *dp-- = *sp--;
  170115. }
  170116. }
  170117. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170118. row_info->channels = 2;
  170119. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170120. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170121. row_width);
  170122. }
  170123. }
  170124. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170125. {
  170126. if (row_info->bit_depth == 8)
  170127. {
  170128. png_byte red = trans_value->red & 0xff;
  170129. png_byte green = trans_value->green & 0xff;
  170130. png_byte blue = trans_value->blue & 0xff;
  170131. sp = row + (png_size_t)row_info->rowbytes - 1;
  170132. dp = row + (png_size_t)(row_width << 2) - 1;
  170133. for (i = 0; i < row_width; i++)
  170134. {
  170135. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170136. *dp-- = 0;
  170137. else
  170138. *dp-- = 0xff;
  170139. *dp-- = *sp--;
  170140. *dp-- = *sp--;
  170141. *dp-- = *sp--;
  170142. }
  170143. }
  170144. else if (row_info->bit_depth == 16)
  170145. {
  170146. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170147. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170148. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170149. png_byte red_low = trans_value->red & 0xff;
  170150. png_byte green_low = trans_value->green & 0xff;
  170151. png_byte blue_low = trans_value->blue & 0xff;
  170152. sp = row + row_info->rowbytes - 1;
  170153. dp = row + (png_size_t)(row_width << 3) - 1;
  170154. for (i = 0; i < row_width; i++)
  170155. {
  170156. if (*(sp - 5) == red_high &&
  170157. *(sp - 4) == red_low &&
  170158. *(sp - 3) == green_high &&
  170159. *(sp - 2) == green_low &&
  170160. *(sp - 1) == blue_high &&
  170161. *(sp ) == blue_low)
  170162. {
  170163. *dp-- = 0;
  170164. *dp-- = 0;
  170165. }
  170166. else
  170167. {
  170168. *dp-- = 0xff;
  170169. *dp-- = 0xff;
  170170. }
  170171. *dp-- = *sp--;
  170172. *dp-- = *sp--;
  170173. *dp-- = *sp--;
  170174. *dp-- = *sp--;
  170175. *dp-- = *sp--;
  170176. *dp-- = *sp--;
  170177. }
  170178. }
  170179. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170180. row_info->channels = 4;
  170181. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170182. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170183. }
  170184. }
  170185. }
  170186. #endif
  170187. #if defined(PNG_READ_DITHER_SUPPORTED)
  170188. void /* PRIVATE */
  170189. png_do_dither(png_row_infop row_info, png_bytep row,
  170190. png_bytep palette_lookup, png_bytep dither_lookup)
  170191. {
  170192. png_bytep sp, dp;
  170193. png_uint_32 i;
  170194. png_uint_32 row_width=row_info->width;
  170195. png_debug(1, "in png_do_dither\n");
  170196. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170197. if (row != NULL && row_info != NULL)
  170198. #endif
  170199. {
  170200. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170201. palette_lookup && row_info->bit_depth == 8)
  170202. {
  170203. int r, g, b, p;
  170204. sp = row;
  170205. dp = row;
  170206. for (i = 0; i < row_width; i++)
  170207. {
  170208. r = *sp++;
  170209. g = *sp++;
  170210. b = *sp++;
  170211. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170212. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170213. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170214. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170215. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170216. (PNG_DITHER_BLUE_BITS)) |
  170217. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170218. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170219. *dp++ = palette_lookup[p];
  170220. }
  170221. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170222. row_info->channels = 1;
  170223. row_info->pixel_depth = row_info->bit_depth;
  170224. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170225. }
  170226. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170227. palette_lookup != NULL && row_info->bit_depth == 8)
  170228. {
  170229. int r, g, b, p;
  170230. sp = row;
  170231. dp = row;
  170232. for (i = 0; i < row_width; i++)
  170233. {
  170234. r = *sp++;
  170235. g = *sp++;
  170236. b = *sp++;
  170237. sp++;
  170238. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170239. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170240. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170241. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170242. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170243. (PNG_DITHER_BLUE_BITS)) |
  170244. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170245. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170246. *dp++ = palette_lookup[p];
  170247. }
  170248. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170249. row_info->channels = 1;
  170250. row_info->pixel_depth = row_info->bit_depth;
  170251. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170252. }
  170253. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170254. dither_lookup && row_info->bit_depth == 8)
  170255. {
  170256. sp = row;
  170257. for (i = 0; i < row_width; i++, sp++)
  170258. {
  170259. *sp = dither_lookup[*sp];
  170260. }
  170261. }
  170262. }
  170263. }
  170264. #endif
  170265. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170266. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170267. static PNG_CONST int png_gamma_shift[] =
  170268. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170269. void /* PRIVATE */
  170270. png_build_gamma_table(png_structp png_ptr)
  170271. {
  170272. png_debug(1, "in png_build_gamma_table\n");
  170273. if (png_ptr->bit_depth <= 8)
  170274. {
  170275. int i;
  170276. double g;
  170277. if (png_ptr->screen_gamma > .000001)
  170278. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170279. else
  170280. g = 1.0;
  170281. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170282. (png_uint_32)256);
  170283. for (i = 0; i < 256; i++)
  170284. {
  170285. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170286. g) * 255.0 + .5);
  170287. }
  170288. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170289. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170290. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170291. {
  170292. g = 1.0 / (png_ptr->gamma);
  170293. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170294. (png_uint_32)256);
  170295. for (i = 0; i < 256; i++)
  170296. {
  170297. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170298. g) * 255.0 + .5);
  170299. }
  170300. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170301. (png_uint_32)256);
  170302. if(png_ptr->screen_gamma > 0.000001)
  170303. g = 1.0 / png_ptr->screen_gamma;
  170304. else
  170305. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170306. for (i = 0; i < 256; i++)
  170307. {
  170308. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170309. g) * 255.0 + .5);
  170310. }
  170311. }
  170312. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170313. }
  170314. else
  170315. {
  170316. double g;
  170317. int i, j, shift, num;
  170318. int sig_bit;
  170319. png_uint_32 ig;
  170320. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170321. {
  170322. sig_bit = (int)png_ptr->sig_bit.red;
  170323. if ((int)png_ptr->sig_bit.green > sig_bit)
  170324. sig_bit = png_ptr->sig_bit.green;
  170325. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170326. sig_bit = png_ptr->sig_bit.blue;
  170327. }
  170328. else
  170329. {
  170330. sig_bit = (int)png_ptr->sig_bit.gray;
  170331. }
  170332. if (sig_bit > 0)
  170333. shift = 16 - sig_bit;
  170334. else
  170335. shift = 0;
  170336. if (png_ptr->transformations & PNG_16_TO_8)
  170337. {
  170338. if (shift < (16 - PNG_MAX_GAMMA_8))
  170339. shift = (16 - PNG_MAX_GAMMA_8);
  170340. }
  170341. if (shift > 8)
  170342. shift = 8;
  170343. if (shift < 0)
  170344. shift = 0;
  170345. png_ptr->gamma_shift = (png_byte)shift;
  170346. num = (1 << (8 - shift));
  170347. if (png_ptr->screen_gamma > .000001)
  170348. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170349. else
  170350. g = 1.0;
  170351. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170352. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170353. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170354. {
  170355. double fin, fout;
  170356. png_uint_32 last, max;
  170357. for (i = 0; i < num; i++)
  170358. {
  170359. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170360. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170361. }
  170362. g = 1.0 / g;
  170363. last = 0;
  170364. for (i = 0; i < 256; i++)
  170365. {
  170366. fout = ((double)i + 0.5) / 256.0;
  170367. fin = pow(fout, g);
  170368. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170369. while (last <= max)
  170370. {
  170371. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170372. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170373. (png_uint_16)i | ((png_uint_16)i << 8));
  170374. last++;
  170375. }
  170376. }
  170377. while (last < ((png_uint_32)num << 8))
  170378. {
  170379. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170380. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170381. last++;
  170382. }
  170383. }
  170384. else
  170385. {
  170386. for (i = 0; i < num; i++)
  170387. {
  170388. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170389. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170390. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170391. for (j = 0; j < 256; j++)
  170392. {
  170393. png_ptr->gamma_16_table[i][j] =
  170394. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170395. 65535.0, g) * 65535.0 + .5);
  170396. }
  170397. }
  170398. }
  170399. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170400. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170401. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170402. {
  170403. g = 1.0 / (png_ptr->gamma);
  170404. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170405. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170406. for (i = 0; i < num; i++)
  170407. {
  170408. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170409. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170410. ig = (((png_uint_32)i *
  170411. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170412. for (j = 0; j < 256; j++)
  170413. {
  170414. png_ptr->gamma_16_to_1[i][j] =
  170415. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170416. 65535.0, g) * 65535.0 + .5);
  170417. }
  170418. }
  170419. if(png_ptr->screen_gamma > 0.000001)
  170420. g = 1.0 / png_ptr->screen_gamma;
  170421. else
  170422. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170423. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170424. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170425. for (i = 0; i < num; i++)
  170426. {
  170427. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170428. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170429. ig = (((png_uint_32)i *
  170430. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170431. for (j = 0; j < 256; j++)
  170432. {
  170433. png_ptr->gamma_16_from_1[i][j] =
  170434. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170435. 65535.0, g) * 65535.0 + .5);
  170436. }
  170437. }
  170438. }
  170439. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170440. }
  170441. }
  170442. #endif
  170443. #endif
  170444. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170445. void /* PRIVATE */
  170446. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170447. {
  170448. png_debug(1, "in png_do_read_intrapixel\n");
  170449. if (
  170450. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170451. row != NULL && row_info != NULL &&
  170452. #endif
  170453. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170454. {
  170455. int bytes_per_pixel;
  170456. png_uint_32 row_width = row_info->width;
  170457. if (row_info->bit_depth == 8)
  170458. {
  170459. png_bytep rp;
  170460. png_uint_32 i;
  170461. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170462. bytes_per_pixel = 3;
  170463. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170464. bytes_per_pixel = 4;
  170465. else
  170466. return;
  170467. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170468. {
  170469. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170470. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170471. }
  170472. }
  170473. else if (row_info->bit_depth == 16)
  170474. {
  170475. png_bytep rp;
  170476. png_uint_32 i;
  170477. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170478. bytes_per_pixel = 6;
  170479. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170480. bytes_per_pixel = 8;
  170481. else
  170482. return;
  170483. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170484. {
  170485. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170486. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170487. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170488. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170489. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170490. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170491. *(rp+1) = (png_byte)(red & 0xff);
  170492. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170493. *(rp+5) = (png_byte)(blue & 0xff);
  170494. }
  170495. }
  170496. }
  170497. }
  170498. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170499. #endif /* PNG_READ_SUPPORTED */
  170500. /*** End of inlined file: pngrtran.c ***/
  170501. /*** Start of inlined file: pngrutil.c ***/
  170502. #define PNG_INTERNAL
  170503. #if defined(PNG_READ_SUPPORTED)
  170504. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170505. # define WIN32_WCE_OLD
  170506. #endif
  170507. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170508. # if defined(WIN32_WCE_OLD)
  170509. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170510. {
  170511. double result = 0;
  170512. int len;
  170513. wchar_t *str, *end;
  170514. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170515. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170516. if ( NULL != str )
  170517. {
  170518. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170519. result = wcstod(str, &end);
  170520. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170521. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170522. png_free(png_ptr, str);
  170523. }
  170524. return result;
  170525. }
  170526. # else
  170527. # define png_strtod(p,a,b) strtod(a,b)
  170528. # endif
  170529. #endif
  170530. png_uint_32 PNGAPI
  170531. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170532. {
  170533. png_uint_32 i = png_get_uint_32(buf);
  170534. if (i > PNG_UINT_31_MAX)
  170535. png_error(png_ptr, "PNG unsigned integer out of range.");
  170536. return (i);
  170537. }
  170538. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170539. png_uint_32 PNGAPI
  170540. png_get_uint_32(png_bytep buf)
  170541. {
  170542. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170543. ((png_uint_32)(*(buf + 1)) << 16) +
  170544. ((png_uint_32)(*(buf + 2)) << 8) +
  170545. (png_uint_32)(*(buf + 3));
  170546. return (i);
  170547. }
  170548. png_int_32 PNGAPI
  170549. png_get_int_32(png_bytep buf)
  170550. {
  170551. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170552. ((png_int_32)(*(buf + 1)) << 16) +
  170553. ((png_int_32)(*(buf + 2)) << 8) +
  170554. (png_int_32)(*(buf + 3));
  170555. return (i);
  170556. }
  170557. png_uint_16 PNGAPI
  170558. png_get_uint_16(png_bytep buf)
  170559. {
  170560. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170561. (png_uint_16)(*(buf + 1)));
  170562. return (i);
  170563. }
  170564. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170565. void /* PRIVATE */
  170566. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170567. {
  170568. if(png_ptr == NULL) return;
  170569. png_read_data(png_ptr, buf, length);
  170570. png_calculate_crc(png_ptr, buf, length);
  170571. }
  170572. int /* PRIVATE */
  170573. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170574. {
  170575. png_size_t i;
  170576. png_size_t istop = png_ptr->zbuf_size;
  170577. for (i = (png_size_t)skip; i > istop; i -= istop)
  170578. {
  170579. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170580. }
  170581. if (i)
  170582. {
  170583. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170584. }
  170585. if (png_crc_error(png_ptr))
  170586. {
  170587. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170588. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170589. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170590. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170591. {
  170592. png_chunk_warning(png_ptr, "CRC error");
  170593. }
  170594. else
  170595. {
  170596. png_chunk_error(png_ptr, "CRC error");
  170597. }
  170598. return (1);
  170599. }
  170600. return (0);
  170601. }
  170602. int /* PRIVATE */
  170603. png_crc_error(png_structp png_ptr)
  170604. {
  170605. png_byte crc_bytes[4];
  170606. png_uint_32 crc;
  170607. int need_crc = 1;
  170608. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170609. {
  170610. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170611. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170612. need_crc = 0;
  170613. }
  170614. else /* critical */
  170615. {
  170616. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170617. need_crc = 0;
  170618. }
  170619. png_read_data(png_ptr, crc_bytes, 4);
  170620. if (need_crc)
  170621. {
  170622. crc = png_get_uint_32(crc_bytes);
  170623. return ((int)(crc != png_ptr->crc));
  170624. }
  170625. else
  170626. return (0);
  170627. }
  170628. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170629. defined(PNG_READ_iCCP_SUPPORTED)
  170630. png_charp /* PRIVATE */
  170631. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170632. png_charp chunkdata, png_size_t chunklength,
  170633. png_size_t prefix_size, png_size_t *newlength)
  170634. {
  170635. static PNG_CONST char msg[] = "Error decoding compressed text";
  170636. png_charp text;
  170637. png_size_t text_size;
  170638. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170639. {
  170640. int ret = Z_OK;
  170641. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170642. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170643. png_ptr->zstream.next_out = png_ptr->zbuf;
  170644. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170645. text_size = 0;
  170646. text = NULL;
  170647. while (png_ptr->zstream.avail_in)
  170648. {
  170649. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170650. if (ret != Z_OK && ret != Z_STREAM_END)
  170651. {
  170652. if (png_ptr->zstream.msg != NULL)
  170653. png_warning(png_ptr, png_ptr->zstream.msg);
  170654. else
  170655. png_warning(png_ptr, msg);
  170656. inflateReset(&png_ptr->zstream);
  170657. png_ptr->zstream.avail_in = 0;
  170658. if (text == NULL)
  170659. {
  170660. text_size = prefix_size + png_sizeof(msg) + 1;
  170661. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170662. if (text == NULL)
  170663. {
  170664. png_free(png_ptr,chunkdata);
  170665. png_error(png_ptr,"Not enough memory to decompress chunk");
  170666. }
  170667. png_memcpy(text, chunkdata, prefix_size);
  170668. }
  170669. text[text_size - 1] = 0x00;
  170670. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170671. text_size = png_sizeof(msg) > text_size ? text_size :
  170672. png_sizeof(msg);
  170673. png_memcpy(text + prefix_size, msg, text_size + 1);
  170674. break;
  170675. }
  170676. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170677. {
  170678. if (text == NULL)
  170679. {
  170680. text_size = prefix_size +
  170681. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170682. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170683. if (text == NULL)
  170684. {
  170685. png_free(png_ptr,chunkdata);
  170686. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170687. }
  170688. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170689. text_size - prefix_size);
  170690. png_memcpy(text, chunkdata, prefix_size);
  170691. *(text + text_size) = 0x00;
  170692. }
  170693. else
  170694. {
  170695. png_charp tmp;
  170696. tmp = text;
  170697. text = (png_charp)png_malloc_warn(png_ptr,
  170698. (png_uint_32)(text_size +
  170699. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170700. if (text == NULL)
  170701. {
  170702. png_free(png_ptr, tmp);
  170703. png_free(png_ptr, chunkdata);
  170704. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170705. }
  170706. png_memcpy(text, tmp, text_size);
  170707. png_free(png_ptr, tmp);
  170708. png_memcpy(text + text_size, png_ptr->zbuf,
  170709. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170710. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170711. *(text + text_size) = 0x00;
  170712. }
  170713. if (ret == Z_STREAM_END)
  170714. break;
  170715. else
  170716. {
  170717. png_ptr->zstream.next_out = png_ptr->zbuf;
  170718. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170719. }
  170720. }
  170721. }
  170722. if (ret != Z_STREAM_END)
  170723. {
  170724. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170725. char umsg[52];
  170726. if (ret == Z_BUF_ERROR)
  170727. png_snprintf(umsg, 52,
  170728. "Buffer error in compressed datastream in %s chunk",
  170729. png_ptr->chunk_name);
  170730. else if (ret == Z_DATA_ERROR)
  170731. png_snprintf(umsg, 52,
  170732. "Data error in compressed datastream in %s chunk",
  170733. png_ptr->chunk_name);
  170734. else
  170735. png_snprintf(umsg, 52,
  170736. "Incomplete compressed datastream in %s chunk",
  170737. png_ptr->chunk_name);
  170738. png_warning(png_ptr, umsg);
  170739. #else
  170740. png_warning(png_ptr,
  170741. "Incomplete compressed datastream in chunk other than IDAT");
  170742. #endif
  170743. text_size=prefix_size;
  170744. if (text == NULL)
  170745. {
  170746. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170747. if (text == NULL)
  170748. {
  170749. png_free(png_ptr, chunkdata);
  170750. png_error(png_ptr,"Not enough memory for text.");
  170751. }
  170752. png_memcpy(text, chunkdata, prefix_size);
  170753. }
  170754. *(text + text_size) = 0x00;
  170755. }
  170756. inflateReset(&png_ptr->zstream);
  170757. png_ptr->zstream.avail_in = 0;
  170758. png_free(png_ptr, chunkdata);
  170759. chunkdata = text;
  170760. *newlength=text_size;
  170761. }
  170762. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170763. {
  170764. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170765. char umsg[50];
  170766. png_snprintf(umsg, 50,
  170767. "Unknown zTXt compression type %d", comp_type);
  170768. png_warning(png_ptr, umsg);
  170769. #else
  170770. png_warning(png_ptr, "Unknown zTXt compression type");
  170771. #endif
  170772. *(chunkdata + prefix_size) = 0x00;
  170773. *newlength=prefix_size;
  170774. }
  170775. return chunkdata;
  170776. }
  170777. #endif
  170778. void /* PRIVATE */
  170779. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170780. {
  170781. png_byte buf[13];
  170782. png_uint_32 width, height;
  170783. int bit_depth, color_type, compression_type, filter_type;
  170784. int interlace_type;
  170785. png_debug(1, "in png_handle_IHDR\n");
  170786. if (png_ptr->mode & PNG_HAVE_IHDR)
  170787. png_error(png_ptr, "Out of place IHDR");
  170788. if (length != 13)
  170789. png_error(png_ptr, "Invalid IHDR chunk");
  170790. png_ptr->mode |= PNG_HAVE_IHDR;
  170791. png_crc_read(png_ptr, buf, 13);
  170792. png_crc_finish(png_ptr, 0);
  170793. width = png_get_uint_31(png_ptr, buf);
  170794. height = png_get_uint_31(png_ptr, buf + 4);
  170795. bit_depth = buf[8];
  170796. color_type = buf[9];
  170797. compression_type = buf[10];
  170798. filter_type = buf[11];
  170799. interlace_type = buf[12];
  170800. png_ptr->width = width;
  170801. png_ptr->height = height;
  170802. png_ptr->bit_depth = (png_byte)bit_depth;
  170803. png_ptr->interlaced = (png_byte)interlace_type;
  170804. png_ptr->color_type = (png_byte)color_type;
  170805. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170806. png_ptr->filter_type = (png_byte)filter_type;
  170807. #endif
  170808. png_ptr->compression_type = (png_byte)compression_type;
  170809. switch (png_ptr->color_type)
  170810. {
  170811. case PNG_COLOR_TYPE_GRAY:
  170812. case PNG_COLOR_TYPE_PALETTE:
  170813. png_ptr->channels = 1;
  170814. break;
  170815. case PNG_COLOR_TYPE_RGB:
  170816. png_ptr->channels = 3;
  170817. break;
  170818. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170819. png_ptr->channels = 2;
  170820. break;
  170821. case PNG_COLOR_TYPE_RGB_ALPHA:
  170822. png_ptr->channels = 4;
  170823. break;
  170824. }
  170825. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  170826. png_ptr->channels);
  170827. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  170828. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  170829. png_debug1(3,"channels = %d\n", png_ptr->channels);
  170830. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  170831. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  170832. color_type, interlace_type, compression_type, filter_type);
  170833. }
  170834. void /* PRIVATE */
  170835. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170836. {
  170837. png_color palette[PNG_MAX_PALETTE_LENGTH];
  170838. int num, i;
  170839. #ifndef PNG_NO_POINTER_INDEXING
  170840. png_colorp pal_ptr;
  170841. #endif
  170842. png_debug(1, "in png_handle_PLTE\n");
  170843. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170844. png_error(png_ptr, "Missing IHDR before PLTE");
  170845. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170846. {
  170847. png_warning(png_ptr, "Invalid PLTE after IDAT");
  170848. png_crc_finish(png_ptr, length);
  170849. return;
  170850. }
  170851. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170852. png_error(png_ptr, "Duplicate PLTE chunk");
  170853. png_ptr->mode |= PNG_HAVE_PLTE;
  170854. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  170855. {
  170856. png_warning(png_ptr,
  170857. "Ignoring PLTE chunk in grayscale PNG");
  170858. png_crc_finish(png_ptr, length);
  170859. return;
  170860. }
  170861. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170862. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170863. {
  170864. png_crc_finish(png_ptr, length);
  170865. return;
  170866. }
  170867. #endif
  170868. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  170869. {
  170870. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170871. {
  170872. png_warning(png_ptr, "Invalid palette chunk");
  170873. png_crc_finish(png_ptr, length);
  170874. return;
  170875. }
  170876. else
  170877. {
  170878. png_error(png_ptr, "Invalid palette chunk");
  170879. }
  170880. }
  170881. num = (int)length / 3;
  170882. #ifndef PNG_NO_POINTER_INDEXING
  170883. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  170884. {
  170885. png_byte buf[3];
  170886. png_crc_read(png_ptr, buf, 3);
  170887. pal_ptr->red = buf[0];
  170888. pal_ptr->green = buf[1];
  170889. pal_ptr->blue = buf[2];
  170890. }
  170891. #else
  170892. for (i = 0; i < num; i++)
  170893. {
  170894. png_byte buf[3];
  170895. png_crc_read(png_ptr, buf, 3);
  170896. palette[i].red = buf[0];
  170897. palette[i].green = buf[1];
  170898. palette[i].blue = buf[2];
  170899. }
  170900. #endif
  170901. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170902. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170903. #endif
  170904. {
  170905. png_crc_finish(png_ptr, 0);
  170906. }
  170907. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170908. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  170909. {
  170910. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  170911. {
  170912. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  170913. {
  170914. png_chunk_error(png_ptr, "CRC error");
  170915. }
  170916. else
  170917. {
  170918. png_chunk_warning(png_ptr, "CRC error");
  170919. return;
  170920. }
  170921. }
  170922. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170923. {
  170924. png_chunk_warning(png_ptr, "CRC error");
  170925. }
  170926. }
  170927. #endif
  170928. png_set_PLTE(png_ptr, info_ptr, palette, num);
  170929. #if defined(PNG_READ_tRNS_SUPPORTED)
  170930. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170931. {
  170932. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  170933. {
  170934. if (png_ptr->num_trans > (png_uint_16)num)
  170935. {
  170936. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  170937. png_ptr->num_trans = (png_uint_16)num;
  170938. }
  170939. if (info_ptr->num_trans > (png_uint_16)num)
  170940. {
  170941. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  170942. info_ptr->num_trans = (png_uint_16)num;
  170943. }
  170944. }
  170945. }
  170946. #endif
  170947. }
  170948. void /* PRIVATE */
  170949. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170950. {
  170951. png_debug(1, "in png_handle_IEND\n");
  170952. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  170953. {
  170954. png_error(png_ptr, "No image in file");
  170955. }
  170956. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  170957. if (length != 0)
  170958. {
  170959. png_warning(png_ptr, "Incorrect IEND chunk length");
  170960. }
  170961. png_crc_finish(png_ptr, length);
  170962. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  170963. }
  170964. #if defined(PNG_READ_gAMA_SUPPORTED)
  170965. void /* PRIVATE */
  170966. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170967. {
  170968. png_fixed_point igamma;
  170969. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170970. float file_gamma;
  170971. #endif
  170972. png_byte buf[4];
  170973. png_debug(1, "in png_handle_gAMA\n");
  170974. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170975. png_error(png_ptr, "Missing IHDR before gAMA");
  170976. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170977. {
  170978. png_warning(png_ptr, "Invalid gAMA after IDAT");
  170979. png_crc_finish(png_ptr, length);
  170980. return;
  170981. }
  170982. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170983. png_warning(png_ptr, "Out of place gAMA chunk");
  170984. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  170985. #if defined(PNG_READ_sRGB_SUPPORTED)
  170986. && !(info_ptr->valid & PNG_INFO_sRGB)
  170987. #endif
  170988. )
  170989. {
  170990. png_warning(png_ptr, "Duplicate gAMA chunk");
  170991. png_crc_finish(png_ptr, length);
  170992. return;
  170993. }
  170994. if (length != 4)
  170995. {
  170996. png_warning(png_ptr, "Incorrect gAMA chunk length");
  170997. png_crc_finish(png_ptr, length);
  170998. return;
  170999. }
  171000. png_crc_read(png_ptr, buf, 4);
  171001. if (png_crc_finish(png_ptr, 0))
  171002. return;
  171003. igamma = (png_fixed_point)png_get_uint_32(buf);
  171004. if (igamma == 0)
  171005. {
  171006. png_warning(png_ptr,
  171007. "Ignoring gAMA chunk with gamma=0");
  171008. return;
  171009. }
  171010. #if defined(PNG_READ_sRGB_SUPPORTED)
  171011. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171012. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171013. {
  171014. png_warning(png_ptr,
  171015. "Ignoring incorrect gAMA value when sRGB is also present");
  171016. #ifndef PNG_NO_CONSOLE_IO
  171017. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171018. #endif
  171019. return;
  171020. }
  171021. #endif /* PNG_READ_sRGB_SUPPORTED */
  171022. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171023. file_gamma = (float)igamma / (float)100000.0;
  171024. # ifdef PNG_READ_GAMMA_SUPPORTED
  171025. png_ptr->gamma = file_gamma;
  171026. # endif
  171027. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171028. #endif
  171029. #ifdef PNG_FIXED_POINT_SUPPORTED
  171030. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171031. #endif
  171032. }
  171033. #endif
  171034. #if defined(PNG_READ_sBIT_SUPPORTED)
  171035. void /* PRIVATE */
  171036. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171037. {
  171038. png_size_t truelen;
  171039. png_byte buf[4];
  171040. png_debug(1, "in png_handle_sBIT\n");
  171041. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171042. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171043. png_error(png_ptr, "Missing IHDR before sBIT");
  171044. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171045. {
  171046. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171047. png_crc_finish(png_ptr, length);
  171048. return;
  171049. }
  171050. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171051. {
  171052. png_warning(png_ptr, "Out of place sBIT chunk");
  171053. }
  171054. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171055. {
  171056. png_warning(png_ptr, "Duplicate sBIT chunk");
  171057. png_crc_finish(png_ptr, length);
  171058. return;
  171059. }
  171060. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171061. truelen = 3;
  171062. else
  171063. truelen = (png_size_t)png_ptr->channels;
  171064. if (length != truelen || length > 4)
  171065. {
  171066. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171067. png_crc_finish(png_ptr, length);
  171068. return;
  171069. }
  171070. png_crc_read(png_ptr, buf, truelen);
  171071. if (png_crc_finish(png_ptr, 0))
  171072. return;
  171073. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171074. {
  171075. png_ptr->sig_bit.red = buf[0];
  171076. png_ptr->sig_bit.green = buf[1];
  171077. png_ptr->sig_bit.blue = buf[2];
  171078. png_ptr->sig_bit.alpha = buf[3];
  171079. }
  171080. else
  171081. {
  171082. png_ptr->sig_bit.gray = buf[0];
  171083. png_ptr->sig_bit.red = buf[0];
  171084. png_ptr->sig_bit.green = buf[0];
  171085. png_ptr->sig_bit.blue = buf[0];
  171086. png_ptr->sig_bit.alpha = buf[1];
  171087. }
  171088. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171089. }
  171090. #endif
  171091. #if defined(PNG_READ_cHRM_SUPPORTED)
  171092. void /* PRIVATE */
  171093. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171094. {
  171095. png_byte buf[4];
  171096. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171097. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171098. #endif
  171099. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171100. int_y_green, int_x_blue, int_y_blue;
  171101. png_uint_32 uint_x, uint_y;
  171102. png_debug(1, "in png_handle_cHRM\n");
  171103. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171104. png_error(png_ptr, "Missing IHDR before cHRM");
  171105. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171106. {
  171107. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171108. png_crc_finish(png_ptr, length);
  171109. return;
  171110. }
  171111. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171112. png_warning(png_ptr, "Missing PLTE before cHRM");
  171113. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171114. #if defined(PNG_READ_sRGB_SUPPORTED)
  171115. && !(info_ptr->valid & PNG_INFO_sRGB)
  171116. #endif
  171117. )
  171118. {
  171119. png_warning(png_ptr, "Duplicate cHRM chunk");
  171120. png_crc_finish(png_ptr, length);
  171121. return;
  171122. }
  171123. if (length != 32)
  171124. {
  171125. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171126. png_crc_finish(png_ptr, length);
  171127. return;
  171128. }
  171129. png_crc_read(png_ptr, buf, 4);
  171130. uint_x = png_get_uint_32(buf);
  171131. png_crc_read(png_ptr, buf, 4);
  171132. uint_y = png_get_uint_32(buf);
  171133. if (uint_x > 80000L || uint_y > 80000L ||
  171134. uint_x + uint_y > 100000L)
  171135. {
  171136. png_warning(png_ptr, "Invalid cHRM white point");
  171137. png_crc_finish(png_ptr, 24);
  171138. return;
  171139. }
  171140. int_x_white = (png_fixed_point)uint_x;
  171141. int_y_white = (png_fixed_point)uint_y;
  171142. png_crc_read(png_ptr, buf, 4);
  171143. uint_x = png_get_uint_32(buf);
  171144. png_crc_read(png_ptr, buf, 4);
  171145. uint_y = png_get_uint_32(buf);
  171146. if (uint_x + uint_y > 100000L)
  171147. {
  171148. png_warning(png_ptr, "Invalid cHRM red point");
  171149. png_crc_finish(png_ptr, 16);
  171150. return;
  171151. }
  171152. int_x_red = (png_fixed_point)uint_x;
  171153. int_y_red = (png_fixed_point)uint_y;
  171154. png_crc_read(png_ptr, buf, 4);
  171155. uint_x = png_get_uint_32(buf);
  171156. png_crc_read(png_ptr, buf, 4);
  171157. uint_y = png_get_uint_32(buf);
  171158. if (uint_x + uint_y > 100000L)
  171159. {
  171160. png_warning(png_ptr, "Invalid cHRM green point");
  171161. png_crc_finish(png_ptr, 8);
  171162. return;
  171163. }
  171164. int_x_green = (png_fixed_point)uint_x;
  171165. int_y_green = (png_fixed_point)uint_y;
  171166. png_crc_read(png_ptr, buf, 4);
  171167. uint_x = png_get_uint_32(buf);
  171168. png_crc_read(png_ptr, buf, 4);
  171169. uint_y = png_get_uint_32(buf);
  171170. if (uint_x + uint_y > 100000L)
  171171. {
  171172. png_warning(png_ptr, "Invalid cHRM blue point");
  171173. png_crc_finish(png_ptr, 0);
  171174. return;
  171175. }
  171176. int_x_blue = (png_fixed_point)uint_x;
  171177. int_y_blue = (png_fixed_point)uint_y;
  171178. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171179. white_x = (float)int_x_white / (float)100000.0;
  171180. white_y = (float)int_y_white / (float)100000.0;
  171181. red_x = (float)int_x_red / (float)100000.0;
  171182. red_y = (float)int_y_red / (float)100000.0;
  171183. green_x = (float)int_x_green / (float)100000.0;
  171184. green_y = (float)int_y_green / (float)100000.0;
  171185. blue_x = (float)int_x_blue / (float)100000.0;
  171186. blue_y = (float)int_y_blue / (float)100000.0;
  171187. #endif
  171188. #if defined(PNG_READ_sRGB_SUPPORTED)
  171189. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171190. {
  171191. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171192. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171193. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171194. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171195. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171196. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171197. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171198. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171199. {
  171200. png_warning(png_ptr,
  171201. "Ignoring incorrect cHRM value when sRGB is also present");
  171202. #ifndef PNG_NO_CONSOLE_IO
  171203. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171204. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171205. white_x, white_y, red_x, red_y);
  171206. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171207. green_x, green_y, blue_x, blue_y);
  171208. #else
  171209. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171210. int_x_white, int_y_white, int_x_red, int_y_red);
  171211. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171212. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171213. #endif
  171214. #endif /* PNG_NO_CONSOLE_IO */
  171215. }
  171216. png_crc_finish(png_ptr, 0);
  171217. return;
  171218. }
  171219. #endif /* PNG_READ_sRGB_SUPPORTED */
  171220. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171221. png_set_cHRM(png_ptr, info_ptr,
  171222. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171223. #endif
  171224. #ifdef PNG_FIXED_POINT_SUPPORTED
  171225. png_set_cHRM_fixed(png_ptr, info_ptr,
  171226. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171227. int_y_green, int_x_blue, int_y_blue);
  171228. #endif
  171229. if (png_crc_finish(png_ptr, 0))
  171230. return;
  171231. }
  171232. #endif
  171233. #if defined(PNG_READ_sRGB_SUPPORTED)
  171234. void /* PRIVATE */
  171235. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171236. {
  171237. int intent;
  171238. png_byte buf[1];
  171239. png_debug(1, "in png_handle_sRGB\n");
  171240. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171241. png_error(png_ptr, "Missing IHDR before sRGB");
  171242. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171243. {
  171244. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171245. png_crc_finish(png_ptr, length);
  171246. return;
  171247. }
  171248. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171249. png_warning(png_ptr, "Out of place sRGB chunk");
  171250. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171251. {
  171252. png_warning(png_ptr, "Duplicate sRGB chunk");
  171253. png_crc_finish(png_ptr, length);
  171254. return;
  171255. }
  171256. if (length != 1)
  171257. {
  171258. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171259. png_crc_finish(png_ptr, length);
  171260. return;
  171261. }
  171262. png_crc_read(png_ptr, buf, 1);
  171263. if (png_crc_finish(png_ptr, 0))
  171264. return;
  171265. intent = buf[0];
  171266. if (intent >= PNG_sRGB_INTENT_LAST)
  171267. {
  171268. png_warning(png_ptr, "Unknown sRGB intent");
  171269. return;
  171270. }
  171271. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171272. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171273. {
  171274. png_fixed_point igamma;
  171275. #ifdef PNG_FIXED_POINT_SUPPORTED
  171276. igamma=info_ptr->int_gamma;
  171277. #else
  171278. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171279. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171280. # endif
  171281. #endif
  171282. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171283. {
  171284. png_warning(png_ptr,
  171285. "Ignoring incorrect gAMA value when sRGB is also present");
  171286. #ifndef PNG_NO_CONSOLE_IO
  171287. # ifdef PNG_FIXED_POINT_SUPPORTED
  171288. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171289. # else
  171290. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171291. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171292. # endif
  171293. # endif
  171294. #endif
  171295. }
  171296. }
  171297. #endif /* PNG_READ_gAMA_SUPPORTED */
  171298. #ifdef PNG_READ_cHRM_SUPPORTED
  171299. #ifdef PNG_FIXED_POINT_SUPPORTED
  171300. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171301. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171302. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171303. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171304. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171305. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171306. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171307. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171308. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171309. {
  171310. png_warning(png_ptr,
  171311. "Ignoring incorrect cHRM value when sRGB is also present");
  171312. }
  171313. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171314. #endif /* PNG_READ_cHRM_SUPPORTED */
  171315. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171316. }
  171317. #endif /* PNG_READ_sRGB_SUPPORTED */
  171318. #if defined(PNG_READ_iCCP_SUPPORTED)
  171319. void /* PRIVATE */
  171320. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171321. {
  171322. png_charp chunkdata;
  171323. png_byte compression_type;
  171324. png_bytep pC;
  171325. png_charp profile;
  171326. png_uint_32 skip = 0;
  171327. png_uint_32 profile_size, profile_length;
  171328. png_size_t slength, prefix_length, data_length;
  171329. png_debug(1, "in png_handle_iCCP\n");
  171330. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171331. png_error(png_ptr, "Missing IHDR before iCCP");
  171332. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171333. {
  171334. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171335. png_crc_finish(png_ptr, length);
  171336. return;
  171337. }
  171338. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171339. png_warning(png_ptr, "Out of place iCCP chunk");
  171340. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171341. {
  171342. png_warning(png_ptr, "Duplicate iCCP chunk");
  171343. png_crc_finish(png_ptr, length);
  171344. return;
  171345. }
  171346. #ifdef PNG_MAX_MALLOC_64K
  171347. if (length > (png_uint_32)65535L)
  171348. {
  171349. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171350. skip = length - (png_uint_32)65535L;
  171351. length = (png_uint_32)65535L;
  171352. }
  171353. #endif
  171354. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171355. slength = (png_size_t)length;
  171356. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171357. if (png_crc_finish(png_ptr, skip))
  171358. {
  171359. png_free(png_ptr, chunkdata);
  171360. return;
  171361. }
  171362. chunkdata[slength] = 0x00;
  171363. for (profile = chunkdata; *profile; profile++)
  171364. ;
  171365. ++profile;
  171366. if ( profile >= chunkdata + slength - 1)
  171367. {
  171368. png_free(png_ptr, chunkdata);
  171369. png_warning(png_ptr, "Malformed iCCP chunk");
  171370. return;
  171371. }
  171372. compression_type = *profile++;
  171373. if (compression_type)
  171374. {
  171375. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171376. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171377. wrote nonzero) */
  171378. }
  171379. prefix_length = profile - chunkdata;
  171380. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171381. slength, prefix_length, &data_length);
  171382. profile_length = data_length - prefix_length;
  171383. if ( prefix_length > data_length || profile_length < 4)
  171384. {
  171385. png_free(png_ptr, chunkdata);
  171386. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171387. return;
  171388. }
  171389. pC = (png_bytep)(chunkdata+prefix_length);
  171390. profile_size = ((*(pC ))<<24) |
  171391. ((*(pC+1))<<16) |
  171392. ((*(pC+2))<< 8) |
  171393. ((*(pC+3)) );
  171394. if(profile_size < profile_length)
  171395. profile_length = profile_size;
  171396. if(profile_size > profile_length)
  171397. {
  171398. png_free(png_ptr, chunkdata);
  171399. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171400. return;
  171401. }
  171402. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171403. chunkdata + prefix_length, profile_length);
  171404. png_free(png_ptr, chunkdata);
  171405. }
  171406. #endif /* PNG_READ_iCCP_SUPPORTED */
  171407. #if defined(PNG_READ_sPLT_SUPPORTED)
  171408. void /* PRIVATE */
  171409. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171410. {
  171411. png_bytep chunkdata;
  171412. png_bytep entry_start;
  171413. png_sPLT_t new_palette;
  171414. #ifdef PNG_NO_POINTER_INDEXING
  171415. png_sPLT_entryp pp;
  171416. #endif
  171417. int data_length, entry_size, i;
  171418. png_uint_32 skip = 0;
  171419. png_size_t slength;
  171420. png_debug(1, "in png_handle_sPLT\n");
  171421. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171422. png_error(png_ptr, "Missing IHDR before sPLT");
  171423. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171424. {
  171425. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171426. png_crc_finish(png_ptr, length);
  171427. return;
  171428. }
  171429. #ifdef PNG_MAX_MALLOC_64K
  171430. if (length > (png_uint_32)65535L)
  171431. {
  171432. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171433. skip = length - (png_uint_32)65535L;
  171434. length = (png_uint_32)65535L;
  171435. }
  171436. #endif
  171437. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171438. slength = (png_size_t)length;
  171439. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171440. if (png_crc_finish(png_ptr, skip))
  171441. {
  171442. png_free(png_ptr, chunkdata);
  171443. return;
  171444. }
  171445. chunkdata[slength] = 0x00;
  171446. for (entry_start = chunkdata; *entry_start; entry_start++)
  171447. ;
  171448. ++entry_start;
  171449. if (entry_start > chunkdata + slength - 2)
  171450. {
  171451. png_free(png_ptr, chunkdata);
  171452. png_warning(png_ptr, "malformed sPLT chunk");
  171453. return;
  171454. }
  171455. new_palette.depth = *entry_start++;
  171456. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171457. data_length = (slength - (entry_start - chunkdata));
  171458. if (data_length % entry_size)
  171459. {
  171460. png_free(png_ptr, chunkdata);
  171461. png_warning(png_ptr, "sPLT chunk has bad length");
  171462. return;
  171463. }
  171464. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171465. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171466. png_sizeof(png_sPLT_entry)))
  171467. {
  171468. png_warning(png_ptr, "sPLT chunk too long");
  171469. return;
  171470. }
  171471. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171472. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171473. if (new_palette.entries == NULL)
  171474. {
  171475. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171476. return;
  171477. }
  171478. #ifndef PNG_NO_POINTER_INDEXING
  171479. for (i = 0; i < new_palette.nentries; i++)
  171480. {
  171481. png_sPLT_entryp pp = new_palette.entries + i;
  171482. if (new_palette.depth == 8)
  171483. {
  171484. pp->red = *entry_start++;
  171485. pp->green = *entry_start++;
  171486. pp->blue = *entry_start++;
  171487. pp->alpha = *entry_start++;
  171488. }
  171489. else
  171490. {
  171491. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171492. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171493. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171494. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171495. }
  171496. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171497. }
  171498. #else
  171499. pp = new_palette.entries;
  171500. for (i = 0; i < new_palette.nentries; i++)
  171501. {
  171502. if (new_palette.depth == 8)
  171503. {
  171504. pp[i].red = *entry_start++;
  171505. pp[i].green = *entry_start++;
  171506. pp[i].blue = *entry_start++;
  171507. pp[i].alpha = *entry_start++;
  171508. }
  171509. else
  171510. {
  171511. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171512. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171513. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171514. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171515. }
  171516. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171517. }
  171518. #endif
  171519. new_palette.name = (png_charp)chunkdata;
  171520. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171521. png_free(png_ptr, chunkdata);
  171522. png_free(png_ptr, new_palette.entries);
  171523. }
  171524. #endif /* PNG_READ_sPLT_SUPPORTED */
  171525. #if defined(PNG_READ_tRNS_SUPPORTED)
  171526. void /* PRIVATE */
  171527. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171528. {
  171529. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171530. int bit_mask;
  171531. png_debug(1, "in png_handle_tRNS\n");
  171532. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171533. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171534. png_error(png_ptr, "Missing IHDR before tRNS");
  171535. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171536. {
  171537. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171538. png_crc_finish(png_ptr, length);
  171539. return;
  171540. }
  171541. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171542. {
  171543. png_warning(png_ptr, "Duplicate tRNS chunk");
  171544. png_crc_finish(png_ptr, length);
  171545. return;
  171546. }
  171547. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171548. {
  171549. png_byte buf[2];
  171550. if (length != 2)
  171551. {
  171552. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171553. png_crc_finish(png_ptr, length);
  171554. return;
  171555. }
  171556. png_crc_read(png_ptr, buf, 2);
  171557. png_ptr->num_trans = 1;
  171558. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171559. }
  171560. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171561. {
  171562. png_byte buf[6];
  171563. if (length != 6)
  171564. {
  171565. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171566. png_crc_finish(png_ptr, length);
  171567. return;
  171568. }
  171569. png_crc_read(png_ptr, buf, (png_size_t)length);
  171570. png_ptr->num_trans = 1;
  171571. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171572. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171573. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171574. }
  171575. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171576. {
  171577. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171578. {
  171579. png_warning(png_ptr, "Missing PLTE before tRNS");
  171580. }
  171581. if (length > (png_uint_32)png_ptr->num_palette ||
  171582. length > PNG_MAX_PALETTE_LENGTH)
  171583. {
  171584. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171585. png_crc_finish(png_ptr, length);
  171586. return;
  171587. }
  171588. if (length == 0)
  171589. {
  171590. png_warning(png_ptr, "Zero length tRNS chunk");
  171591. png_crc_finish(png_ptr, length);
  171592. return;
  171593. }
  171594. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171595. png_ptr->num_trans = (png_uint_16)length;
  171596. }
  171597. else
  171598. {
  171599. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171600. png_crc_finish(png_ptr, length);
  171601. return;
  171602. }
  171603. if (png_crc_finish(png_ptr, 0))
  171604. {
  171605. png_ptr->num_trans = 0;
  171606. return;
  171607. }
  171608. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171609. &(png_ptr->trans_values));
  171610. }
  171611. #endif
  171612. #if defined(PNG_READ_bKGD_SUPPORTED)
  171613. void /* PRIVATE */
  171614. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171615. {
  171616. png_size_t truelen;
  171617. png_byte buf[6];
  171618. png_debug(1, "in png_handle_bKGD\n");
  171619. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171620. png_error(png_ptr, "Missing IHDR before bKGD");
  171621. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171622. {
  171623. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171624. png_crc_finish(png_ptr, length);
  171625. return;
  171626. }
  171627. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171628. !(png_ptr->mode & PNG_HAVE_PLTE))
  171629. {
  171630. png_warning(png_ptr, "Missing PLTE before bKGD");
  171631. png_crc_finish(png_ptr, length);
  171632. return;
  171633. }
  171634. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171635. {
  171636. png_warning(png_ptr, "Duplicate bKGD chunk");
  171637. png_crc_finish(png_ptr, length);
  171638. return;
  171639. }
  171640. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171641. truelen = 1;
  171642. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171643. truelen = 6;
  171644. else
  171645. truelen = 2;
  171646. if (length != truelen)
  171647. {
  171648. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171649. png_crc_finish(png_ptr, length);
  171650. return;
  171651. }
  171652. png_crc_read(png_ptr, buf, truelen);
  171653. if (png_crc_finish(png_ptr, 0))
  171654. return;
  171655. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171656. {
  171657. png_ptr->background.index = buf[0];
  171658. if(info_ptr->num_palette)
  171659. {
  171660. if(buf[0] > info_ptr->num_palette)
  171661. {
  171662. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171663. return;
  171664. }
  171665. png_ptr->background.red =
  171666. (png_uint_16)png_ptr->palette[buf[0]].red;
  171667. png_ptr->background.green =
  171668. (png_uint_16)png_ptr->palette[buf[0]].green;
  171669. png_ptr->background.blue =
  171670. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171671. }
  171672. }
  171673. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171674. {
  171675. png_ptr->background.red =
  171676. png_ptr->background.green =
  171677. png_ptr->background.blue =
  171678. png_ptr->background.gray = png_get_uint_16(buf);
  171679. }
  171680. else
  171681. {
  171682. png_ptr->background.red = png_get_uint_16(buf);
  171683. png_ptr->background.green = png_get_uint_16(buf + 2);
  171684. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171685. }
  171686. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171687. }
  171688. #endif
  171689. #if defined(PNG_READ_hIST_SUPPORTED)
  171690. void /* PRIVATE */
  171691. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171692. {
  171693. unsigned int num, i;
  171694. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171695. png_debug(1, "in png_handle_hIST\n");
  171696. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171697. png_error(png_ptr, "Missing IHDR before hIST");
  171698. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171699. {
  171700. png_warning(png_ptr, "Invalid hIST after IDAT");
  171701. png_crc_finish(png_ptr, length);
  171702. return;
  171703. }
  171704. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171705. {
  171706. png_warning(png_ptr, "Missing PLTE before hIST");
  171707. png_crc_finish(png_ptr, length);
  171708. return;
  171709. }
  171710. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171711. {
  171712. png_warning(png_ptr, "Duplicate hIST chunk");
  171713. png_crc_finish(png_ptr, length);
  171714. return;
  171715. }
  171716. num = length / 2 ;
  171717. if (num != (unsigned int) png_ptr->num_palette || num >
  171718. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171719. {
  171720. png_warning(png_ptr, "Incorrect hIST chunk length");
  171721. png_crc_finish(png_ptr, length);
  171722. return;
  171723. }
  171724. for (i = 0; i < num; i++)
  171725. {
  171726. png_byte buf[2];
  171727. png_crc_read(png_ptr, buf, 2);
  171728. readbuf[i] = png_get_uint_16(buf);
  171729. }
  171730. if (png_crc_finish(png_ptr, 0))
  171731. return;
  171732. png_set_hIST(png_ptr, info_ptr, readbuf);
  171733. }
  171734. #endif
  171735. #if defined(PNG_READ_pHYs_SUPPORTED)
  171736. void /* PRIVATE */
  171737. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171738. {
  171739. png_byte buf[9];
  171740. png_uint_32 res_x, res_y;
  171741. int unit_type;
  171742. png_debug(1, "in png_handle_pHYs\n");
  171743. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171744. png_error(png_ptr, "Missing IHDR before pHYs");
  171745. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171746. {
  171747. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171748. png_crc_finish(png_ptr, length);
  171749. return;
  171750. }
  171751. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171752. {
  171753. png_warning(png_ptr, "Duplicate pHYs chunk");
  171754. png_crc_finish(png_ptr, length);
  171755. return;
  171756. }
  171757. if (length != 9)
  171758. {
  171759. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171760. png_crc_finish(png_ptr, length);
  171761. return;
  171762. }
  171763. png_crc_read(png_ptr, buf, 9);
  171764. if (png_crc_finish(png_ptr, 0))
  171765. return;
  171766. res_x = png_get_uint_32(buf);
  171767. res_y = png_get_uint_32(buf + 4);
  171768. unit_type = buf[8];
  171769. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171770. }
  171771. #endif
  171772. #if defined(PNG_READ_oFFs_SUPPORTED)
  171773. void /* PRIVATE */
  171774. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171775. {
  171776. png_byte buf[9];
  171777. png_int_32 offset_x, offset_y;
  171778. int unit_type;
  171779. png_debug(1, "in png_handle_oFFs\n");
  171780. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171781. png_error(png_ptr, "Missing IHDR before oFFs");
  171782. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171783. {
  171784. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171785. png_crc_finish(png_ptr, length);
  171786. return;
  171787. }
  171788. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171789. {
  171790. png_warning(png_ptr, "Duplicate oFFs chunk");
  171791. png_crc_finish(png_ptr, length);
  171792. return;
  171793. }
  171794. if (length != 9)
  171795. {
  171796. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171797. png_crc_finish(png_ptr, length);
  171798. return;
  171799. }
  171800. png_crc_read(png_ptr, buf, 9);
  171801. if (png_crc_finish(png_ptr, 0))
  171802. return;
  171803. offset_x = png_get_int_32(buf);
  171804. offset_y = png_get_int_32(buf + 4);
  171805. unit_type = buf[8];
  171806. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171807. }
  171808. #endif
  171809. #if defined(PNG_READ_pCAL_SUPPORTED)
  171810. void /* PRIVATE */
  171811. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171812. {
  171813. png_charp purpose;
  171814. png_int_32 X0, X1;
  171815. png_byte type, nparams;
  171816. png_charp buf, units, endptr;
  171817. png_charpp params;
  171818. png_size_t slength;
  171819. int i;
  171820. png_debug(1, "in png_handle_pCAL\n");
  171821. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171822. png_error(png_ptr, "Missing IHDR before pCAL");
  171823. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171824. {
  171825. png_warning(png_ptr, "Invalid pCAL after IDAT");
  171826. png_crc_finish(png_ptr, length);
  171827. return;
  171828. }
  171829. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  171830. {
  171831. png_warning(png_ptr, "Duplicate pCAL chunk");
  171832. png_crc_finish(png_ptr, length);
  171833. return;
  171834. }
  171835. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  171836. length + 1);
  171837. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171838. if (purpose == NULL)
  171839. {
  171840. png_warning(png_ptr, "No memory for pCAL purpose.");
  171841. return;
  171842. }
  171843. slength = (png_size_t)length;
  171844. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  171845. if (png_crc_finish(png_ptr, 0))
  171846. {
  171847. png_free(png_ptr, purpose);
  171848. return;
  171849. }
  171850. purpose[slength] = 0x00; /* null terminate the last string */
  171851. png_debug(3, "Finding end of pCAL purpose string\n");
  171852. for (buf = purpose; *buf; buf++)
  171853. ;
  171854. endptr = purpose + slength;
  171855. if (endptr <= buf + 12)
  171856. {
  171857. png_warning(png_ptr, "Invalid pCAL data");
  171858. png_free(png_ptr, purpose);
  171859. return;
  171860. }
  171861. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  171862. X0 = png_get_int_32((png_bytep)buf+1);
  171863. X1 = png_get_int_32((png_bytep)buf+5);
  171864. type = buf[9];
  171865. nparams = buf[10];
  171866. units = buf + 11;
  171867. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  171868. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  171869. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  171870. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  171871. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  171872. {
  171873. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  171874. png_free(png_ptr, purpose);
  171875. return;
  171876. }
  171877. else if (type >= PNG_EQUATION_LAST)
  171878. {
  171879. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  171880. }
  171881. for (buf = units; *buf; buf++)
  171882. ;
  171883. png_debug(3, "Allocating pCAL parameters array\n");
  171884. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  171885. *png_sizeof(png_charp))) ;
  171886. if (params == NULL)
  171887. {
  171888. png_free(png_ptr, purpose);
  171889. png_warning(png_ptr, "No memory for pCAL params.");
  171890. return;
  171891. }
  171892. for (i = 0; i < (int)nparams; i++)
  171893. {
  171894. buf++; /* Skip the null string terminator from previous parameter. */
  171895. png_debug1(3, "Reading pCAL parameter %d\n", i);
  171896. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  171897. ;
  171898. if (buf > endptr)
  171899. {
  171900. png_warning(png_ptr, "Invalid pCAL data");
  171901. png_free(png_ptr, purpose);
  171902. png_free(png_ptr, params);
  171903. return;
  171904. }
  171905. }
  171906. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  171907. units, params);
  171908. png_free(png_ptr, purpose);
  171909. png_free(png_ptr, params);
  171910. }
  171911. #endif
  171912. #if defined(PNG_READ_sCAL_SUPPORTED)
  171913. void /* PRIVATE */
  171914. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171915. {
  171916. png_charp buffer, ep;
  171917. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171918. double width, height;
  171919. png_charp vp;
  171920. #else
  171921. #ifdef PNG_FIXED_POINT_SUPPORTED
  171922. png_charp swidth, sheight;
  171923. #endif
  171924. #endif
  171925. png_size_t slength;
  171926. png_debug(1, "in png_handle_sCAL\n");
  171927. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171928. png_error(png_ptr, "Missing IHDR before sCAL");
  171929. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171930. {
  171931. png_warning(png_ptr, "Invalid sCAL after IDAT");
  171932. png_crc_finish(png_ptr, length);
  171933. return;
  171934. }
  171935. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  171936. {
  171937. png_warning(png_ptr, "Duplicate sCAL chunk");
  171938. png_crc_finish(png_ptr, length);
  171939. return;
  171940. }
  171941. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  171942. length + 1);
  171943. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171944. if (buffer == NULL)
  171945. {
  171946. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  171947. return;
  171948. }
  171949. slength = (png_size_t)length;
  171950. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  171951. if (png_crc_finish(png_ptr, 0))
  171952. {
  171953. png_free(png_ptr, buffer);
  171954. return;
  171955. }
  171956. buffer[slength] = 0x00; /* null terminate the last string */
  171957. ep = buffer + 1; /* skip unit byte */
  171958. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171959. width = png_strtod(png_ptr, ep, &vp);
  171960. if (*vp)
  171961. {
  171962. png_warning(png_ptr, "malformed width string in sCAL chunk");
  171963. return;
  171964. }
  171965. #else
  171966. #ifdef PNG_FIXED_POINT_SUPPORTED
  171967. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  171968. if (swidth == NULL)
  171969. {
  171970. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  171971. return;
  171972. }
  171973. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  171974. #endif
  171975. #endif
  171976. for (ep = buffer; *ep; ep++)
  171977. ;
  171978. ep++;
  171979. if (buffer + slength < ep)
  171980. {
  171981. png_warning(png_ptr, "Truncated sCAL chunk");
  171982. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  171983. !defined(PNG_FLOATING_POINT_SUPPORTED)
  171984. png_free(png_ptr, swidth);
  171985. #endif
  171986. png_free(png_ptr, buffer);
  171987. return;
  171988. }
  171989. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171990. height = png_strtod(png_ptr, ep, &vp);
  171991. if (*vp)
  171992. {
  171993. png_warning(png_ptr, "malformed height string in sCAL chunk");
  171994. return;
  171995. }
  171996. #else
  171997. #ifdef PNG_FIXED_POINT_SUPPORTED
  171998. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  171999. if (swidth == NULL)
  172000. {
  172001. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172002. return;
  172003. }
  172004. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172005. #endif
  172006. #endif
  172007. if (buffer + slength < ep
  172008. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172009. || width <= 0. || height <= 0.
  172010. #endif
  172011. )
  172012. {
  172013. png_warning(png_ptr, "Invalid sCAL data");
  172014. png_free(png_ptr, buffer);
  172015. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172016. png_free(png_ptr, swidth);
  172017. png_free(png_ptr, sheight);
  172018. #endif
  172019. return;
  172020. }
  172021. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172022. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172023. #else
  172024. #ifdef PNG_FIXED_POINT_SUPPORTED
  172025. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172026. #endif
  172027. #endif
  172028. png_free(png_ptr, buffer);
  172029. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172030. png_free(png_ptr, swidth);
  172031. png_free(png_ptr, sheight);
  172032. #endif
  172033. }
  172034. #endif
  172035. #if defined(PNG_READ_tIME_SUPPORTED)
  172036. void /* PRIVATE */
  172037. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172038. {
  172039. png_byte buf[7];
  172040. png_time mod_time;
  172041. png_debug(1, "in png_handle_tIME\n");
  172042. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172043. png_error(png_ptr, "Out of place tIME chunk");
  172044. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172045. {
  172046. png_warning(png_ptr, "Duplicate tIME chunk");
  172047. png_crc_finish(png_ptr, length);
  172048. return;
  172049. }
  172050. if (png_ptr->mode & PNG_HAVE_IDAT)
  172051. png_ptr->mode |= PNG_AFTER_IDAT;
  172052. if (length != 7)
  172053. {
  172054. png_warning(png_ptr, "Incorrect tIME chunk length");
  172055. png_crc_finish(png_ptr, length);
  172056. return;
  172057. }
  172058. png_crc_read(png_ptr, buf, 7);
  172059. if (png_crc_finish(png_ptr, 0))
  172060. return;
  172061. mod_time.second = buf[6];
  172062. mod_time.minute = buf[5];
  172063. mod_time.hour = buf[4];
  172064. mod_time.day = buf[3];
  172065. mod_time.month = buf[2];
  172066. mod_time.year = png_get_uint_16(buf);
  172067. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172068. }
  172069. #endif
  172070. #if defined(PNG_READ_tEXt_SUPPORTED)
  172071. void /* PRIVATE */
  172072. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172073. {
  172074. png_textp text_ptr;
  172075. png_charp key;
  172076. png_charp text;
  172077. png_uint_32 skip = 0;
  172078. png_size_t slength;
  172079. int ret;
  172080. png_debug(1, "in png_handle_tEXt\n");
  172081. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172082. png_error(png_ptr, "Missing IHDR before tEXt");
  172083. if (png_ptr->mode & PNG_HAVE_IDAT)
  172084. png_ptr->mode |= PNG_AFTER_IDAT;
  172085. #ifdef PNG_MAX_MALLOC_64K
  172086. if (length > (png_uint_32)65535L)
  172087. {
  172088. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172089. skip = length - (png_uint_32)65535L;
  172090. length = (png_uint_32)65535L;
  172091. }
  172092. #endif
  172093. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172094. if (key == NULL)
  172095. {
  172096. png_warning(png_ptr, "No memory to process text chunk.");
  172097. return;
  172098. }
  172099. slength = (png_size_t)length;
  172100. png_crc_read(png_ptr, (png_bytep)key, slength);
  172101. if (png_crc_finish(png_ptr, skip))
  172102. {
  172103. png_free(png_ptr, key);
  172104. return;
  172105. }
  172106. key[slength] = 0x00;
  172107. for (text = key; *text; text++)
  172108. ;
  172109. if (text != key + slength)
  172110. text++;
  172111. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172112. (png_uint_32)png_sizeof(png_text));
  172113. if (text_ptr == NULL)
  172114. {
  172115. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172116. png_free(png_ptr, key);
  172117. return;
  172118. }
  172119. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172120. text_ptr->key = key;
  172121. #ifdef PNG_iTXt_SUPPORTED
  172122. text_ptr->lang = NULL;
  172123. text_ptr->lang_key = NULL;
  172124. text_ptr->itxt_length = 0;
  172125. #endif
  172126. text_ptr->text = text;
  172127. text_ptr->text_length = png_strlen(text);
  172128. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172129. png_free(png_ptr, key);
  172130. png_free(png_ptr, text_ptr);
  172131. if (ret)
  172132. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172133. }
  172134. #endif
  172135. #if defined(PNG_READ_zTXt_SUPPORTED)
  172136. void /* PRIVATE */
  172137. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172138. {
  172139. png_textp text_ptr;
  172140. png_charp chunkdata;
  172141. png_charp text;
  172142. int comp_type;
  172143. int ret;
  172144. png_size_t slength, prefix_len, data_len;
  172145. png_debug(1, "in png_handle_zTXt\n");
  172146. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172147. png_error(png_ptr, "Missing IHDR before zTXt");
  172148. if (png_ptr->mode & PNG_HAVE_IDAT)
  172149. png_ptr->mode |= PNG_AFTER_IDAT;
  172150. #ifdef PNG_MAX_MALLOC_64K
  172151. if (length > (png_uint_32)65535L)
  172152. {
  172153. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172154. png_crc_finish(png_ptr, length);
  172155. return;
  172156. }
  172157. #endif
  172158. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172159. if (chunkdata == NULL)
  172160. {
  172161. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172162. return;
  172163. }
  172164. slength = (png_size_t)length;
  172165. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172166. if (png_crc_finish(png_ptr, 0))
  172167. {
  172168. png_free(png_ptr, chunkdata);
  172169. return;
  172170. }
  172171. chunkdata[slength] = 0x00;
  172172. for (text = chunkdata; *text; text++)
  172173. ;
  172174. if (text >= chunkdata + slength - 2)
  172175. {
  172176. png_warning(png_ptr, "Truncated zTXt chunk");
  172177. png_free(png_ptr, chunkdata);
  172178. return;
  172179. }
  172180. else
  172181. {
  172182. comp_type = *(++text);
  172183. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172184. {
  172185. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172186. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172187. }
  172188. text++; /* skip the compression_method byte */
  172189. }
  172190. prefix_len = text - chunkdata;
  172191. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172192. (png_size_t)length, prefix_len, &data_len);
  172193. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172194. (png_uint_32)png_sizeof(png_text));
  172195. if (text_ptr == NULL)
  172196. {
  172197. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172198. png_free(png_ptr, chunkdata);
  172199. return;
  172200. }
  172201. text_ptr->compression = comp_type;
  172202. text_ptr->key = chunkdata;
  172203. #ifdef PNG_iTXt_SUPPORTED
  172204. text_ptr->lang = NULL;
  172205. text_ptr->lang_key = NULL;
  172206. text_ptr->itxt_length = 0;
  172207. #endif
  172208. text_ptr->text = chunkdata + prefix_len;
  172209. text_ptr->text_length = data_len;
  172210. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172211. png_free(png_ptr, text_ptr);
  172212. png_free(png_ptr, chunkdata);
  172213. if (ret)
  172214. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172215. }
  172216. #endif
  172217. #if defined(PNG_READ_iTXt_SUPPORTED)
  172218. void /* PRIVATE */
  172219. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172220. {
  172221. png_textp text_ptr;
  172222. png_charp chunkdata;
  172223. png_charp key, lang, text, lang_key;
  172224. int comp_flag;
  172225. int comp_type = 0;
  172226. int ret;
  172227. png_size_t slength, prefix_len, data_len;
  172228. png_debug(1, "in png_handle_iTXt\n");
  172229. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172230. png_error(png_ptr, "Missing IHDR before iTXt");
  172231. if (png_ptr->mode & PNG_HAVE_IDAT)
  172232. png_ptr->mode |= PNG_AFTER_IDAT;
  172233. #ifdef PNG_MAX_MALLOC_64K
  172234. if (length > (png_uint_32)65535L)
  172235. {
  172236. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172237. png_crc_finish(png_ptr, length);
  172238. return;
  172239. }
  172240. #endif
  172241. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172242. if (chunkdata == NULL)
  172243. {
  172244. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172245. return;
  172246. }
  172247. slength = (png_size_t)length;
  172248. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172249. if (png_crc_finish(png_ptr, 0))
  172250. {
  172251. png_free(png_ptr, chunkdata);
  172252. return;
  172253. }
  172254. chunkdata[slength] = 0x00;
  172255. for (lang = chunkdata; *lang; lang++)
  172256. ;
  172257. lang++; /* skip NUL separator */
  172258. if (lang >= chunkdata + slength - 3)
  172259. {
  172260. png_warning(png_ptr, "Truncated iTXt chunk");
  172261. png_free(png_ptr, chunkdata);
  172262. return;
  172263. }
  172264. else
  172265. {
  172266. comp_flag = *lang++;
  172267. comp_type = *lang++;
  172268. }
  172269. for (lang_key = lang; *lang_key; lang_key++)
  172270. ;
  172271. lang_key++; /* skip NUL separator */
  172272. if (lang_key >= chunkdata + slength)
  172273. {
  172274. png_warning(png_ptr, "Truncated iTXt chunk");
  172275. png_free(png_ptr, chunkdata);
  172276. return;
  172277. }
  172278. for (text = lang_key; *text; text++)
  172279. ;
  172280. text++; /* skip NUL separator */
  172281. if (text >= chunkdata + slength)
  172282. {
  172283. png_warning(png_ptr, "Malformed iTXt chunk");
  172284. png_free(png_ptr, chunkdata);
  172285. return;
  172286. }
  172287. prefix_len = text - chunkdata;
  172288. key=chunkdata;
  172289. if (comp_flag)
  172290. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172291. (size_t)length, prefix_len, &data_len);
  172292. else
  172293. data_len=png_strlen(chunkdata + prefix_len);
  172294. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172295. (png_uint_32)png_sizeof(png_text));
  172296. if (text_ptr == NULL)
  172297. {
  172298. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172299. png_free(png_ptr, chunkdata);
  172300. return;
  172301. }
  172302. text_ptr->compression = (int)comp_flag + 1;
  172303. text_ptr->lang_key = chunkdata+(lang_key-key);
  172304. text_ptr->lang = chunkdata+(lang-key);
  172305. text_ptr->itxt_length = data_len;
  172306. text_ptr->text_length = 0;
  172307. text_ptr->key = chunkdata;
  172308. text_ptr->text = chunkdata + prefix_len;
  172309. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172310. png_free(png_ptr, text_ptr);
  172311. png_free(png_ptr, chunkdata);
  172312. if (ret)
  172313. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172314. }
  172315. #endif
  172316. void /* PRIVATE */
  172317. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172318. {
  172319. png_uint_32 skip = 0;
  172320. png_debug(1, "in png_handle_unknown\n");
  172321. if (png_ptr->mode & PNG_HAVE_IDAT)
  172322. {
  172323. #ifdef PNG_USE_LOCAL_ARRAYS
  172324. PNG_CONST PNG_IDAT;
  172325. #endif
  172326. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172327. png_ptr->mode |= PNG_AFTER_IDAT;
  172328. }
  172329. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172330. if (!(png_ptr->chunk_name[0] & 0x20))
  172331. {
  172332. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172333. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172334. PNG_HANDLE_CHUNK_ALWAYS
  172335. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172336. && png_ptr->read_user_chunk_fn == NULL
  172337. #endif
  172338. )
  172339. #endif
  172340. png_chunk_error(png_ptr, "unknown critical chunk");
  172341. }
  172342. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172343. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172344. (png_ptr->read_user_chunk_fn != NULL))
  172345. {
  172346. #ifdef PNG_MAX_MALLOC_64K
  172347. if (length > (png_uint_32)65535L)
  172348. {
  172349. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172350. skip = length - (png_uint_32)65535L;
  172351. length = (png_uint_32)65535L;
  172352. }
  172353. #endif
  172354. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172355. (png_charp)png_ptr->chunk_name, 5);
  172356. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172357. png_ptr->unknown_chunk.size = (png_size_t)length;
  172358. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172359. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172360. if(png_ptr->read_user_chunk_fn != NULL)
  172361. {
  172362. int ret;
  172363. ret = (*(png_ptr->read_user_chunk_fn))
  172364. (png_ptr, &png_ptr->unknown_chunk);
  172365. if (ret < 0)
  172366. png_chunk_error(png_ptr, "error in user chunk");
  172367. if (ret == 0)
  172368. {
  172369. if (!(png_ptr->chunk_name[0] & 0x20))
  172370. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172371. PNG_HANDLE_CHUNK_ALWAYS)
  172372. png_chunk_error(png_ptr, "unknown critical chunk");
  172373. png_set_unknown_chunks(png_ptr, info_ptr,
  172374. &png_ptr->unknown_chunk, 1);
  172375. }
  172376. }
  172377. #else
  172378. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172379. #endif
  172380. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172381. png_ptr->unknown_chunk.data = NULL;
  172382. }
  172383. else
  172384. #endif
  172385. skip = length;
  172386. png_crc_finish(png_ptr, skip);
  172387. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172388. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172389. #endif
  172390. }
  172391. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172392. void /* PRIVATE */
  172393. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172394. {
  172395. png_debug(1, "in png_check_chunk_name\n");
  172396. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172397. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172398. {
  172399. png_chunk_error(png_ptr, "invalid chunk type");
  172400. }
  172401. }
  172402. void /* PRIVATE */
  172403. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172404. {
  172405. png_debug(1,"in png_combine_row\n");
  172406. if (mask == 0xff)
  172407. {
  172408. png_memcpy(row, png_ptr->row_buf + 1,
  172409. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172410. }
  172411. else
  172412. {
  172413. switch (png_ptr->row_info.pixel_depth)
  172414. {
  172415. case 1:
  172416. {
  172417. png_bytep sp = png_ptr->row_buf + 1;
  172418. png_bytep dp = row;
  172419. int s_inc, s_start, s_end;
  172420. int m = 0x80;
  172421. int shift;
  172422. png_uint_32 i;
  172423. png_uint_32 row_width = png_ptr->width;
  172424. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172425. if (png_ptr->transformations & PNG_PACKSWAP)
  172426. {
  172427. s_start = 0;
  172428. s_end = 7;
  172429. s_inc = 1;
  172430. }
  172431. else
  172432. #endif
  172433. {
  172434. s_start = 7;
  172435. s_end = 0;
  172436. s_inc = -1;
  172437. }
  172438. shift = s_start;
  172439. for (i = 0; i < row_width; i++)
  172440. {
  172441. if (m & mask)
  172442. {
  172443. int value;
  172444. value = (*sp >> shift) & 0x01;
  172445. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172446. *dp |= (png_byte)(value << shift);
  172447. }
  172448. if (shift == s_end)
  172449. {
  172450. shift = s_start;
  172451. sp++;
  172452. dp++;
  172453. }
  172454. else
  172455. shift += s_inc;
  172456. if (m == 1)
  172457. m = 0x80;
  172458. else
  172459. m >>= 1;
  172460. }
  172461. break;
  172462. }
  172463. case 2:
  172464. {
  172465. png_bytep sp = png_ptr->row_buf + 1;
  172466. png_bytep dp = row;
  172467. int s_start, s_end, s_inc;
  172468. int m = 0x80;
  172469. int shift;
  172470. png_uint_32 i;
  172471. png_uint_32 row_width = png_ptr->width;
  172472. int value;
  172473. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172474. if (png_ptr->transformations & PNG_PACKSWAP)
  172475. {
  172476. s_start = 0;
  172477. s_end = 6;
  172478. s_inc = 2;
  172479. }
  172480. else
  172481. #endif
  172482. {
  172483. s_start = 6;
  172484. s_end = 0;
  172485. s_inc = -2;
  172486. }
  172487. shift = s_start;
  172488. for (i = 0; i < row_width; i++)
  172489. {
  172490. if (m & mask)
  172491. {
  172492. value = (*sp >> shift) & 0x03;
  172493. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172494. *dp |= (png_byte)(value << shift);
  172495. }
  172496. if (shift == s_end)
  172497. {
  172498. shift = s_start;
  172499. sp++;
  172500. dp++;
  172501. }
  172502. else
  172503. shift += s_inc;
  172504. if (m == 1)
  172505. m = 0x80;
  172506. else
  172507. m >>= 1;
  172508. }
  172509. break;
  172510. }
  172511. case 4:
  172512. {
  172513. png_bytep sp = png_ptr->row_buf + 1;
  172514. png_bytep dp = row;
  172515. int s_start, s_end, s_inc;
  172516. int m = 0x80;
  172517. int shift;
  172518. png_uint_32 i;
  172519. png_uint_32 row_width = png_ptr->width;
  172520. int value;
  172521. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172522. if (png_ptr->transformations & PNG_PACKSWAP)
  172523. {
  172524. s_start = 0;
  172525. s_end = 4;
  172526. s_inc = 4;
  172527. }
  172528. else
  172529. #endif
  172530. {
  172531. s_start = 4;
  172532. s_end = 0;
  172533. s_inc = -4;
  172534. }
  172535. shift = s_start;
  172536. for (i = 0; i < row_width; i++)
  172537. {
  172538. if (m & mask)
  172539. {
  172540. value = (*sp >> shift) & 0xf;
  172541. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172542. *dp |= (png_byte)(value << shift);
  172543. }
  172544. if (shift == s_end)
  172545. {
  172546. shift = s_start;
  172547. sp++;
  172548. dp++;
  172549. }
  172550. else
  172551. shift += s_inc;
  172552. if (m == 1)
  172553. m = 0x80;
  172554. else
  172555. m >>= 1;
  172556. }
  172557. break;
  172558. }
  172559. default:
  172560. {
  172561. png_bytep sp = png_ptr->row_buf + 1;
  172562. png_bytep dp = row;
  172563. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172564. png_uint_32 i;
  172565. png_uint_32 row_width = png_ptr->width;
  172566. png_byte m = 0x80;
  172567. for (i = 0; i < row_width; i++)
  172568. {
  172569. if (m & mask)
  172570. {
  172571. png_memcpy(dp, sp, pixel_bytes);
  172572. }
  172573. sp += pixel_bytes;
  172574. dp += pixel_bytes;
  172575. if (m == 1)
  172576. m = 0x80;
  172577. else
  172578. m >>= 1;
  172579. }
  172580. break;
  172581. }
  172582. }
  172583. }
  172584. }
  172585. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172586. void /* PRIVATE */
  172587. png_do_read_interlace(png_structp png_ptr)
  172588. {
  172589. png_row_infop row_info = &(png_ptr->row_info);
  172590. png_bytep row = png_ptr->row_buf + 1;
  172591. int pass = png_ptr->pass;
  172592. png_uint_32 transformations = png_ptr->transformations;
  172593. #ifdef PNG_USE_LOCAL_ARRAYS
  172594. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172595. #endif
  172596. png_debug(1,"in png_do_read_interlace\n");
  172597. if (row != NULL && row_info != NULL)
  172598. {
  172599. png_uint_32 final_width;
  172600. final_width = row_info->width * png_pass_inc[pass];
  172601. switch (row_info->pixel_depth)
  172602. {
  172603. case 1:
  172604. {
  172605. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172606. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172607. int sshift, dshift;
  172608. int s_start, s_end, s_inc;
  172609. int jstop = png_pass_inc[pass];
  172610. png_byte v;
  172611. png_uint_32 i;
  172612. int j;
  172613. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172614. if (transformations & PNG_PACKSWAP)
  172615. {
  172616. sshift = (int)((row_info->width + 7) & 0x07);
  172617. dshift = (int)((final_width + 7) & 0x07);
  172618. s_start = 7;
  172619. s_end = 0;
  172620. s_inc = -1;
  172621. }
  172622. else
  172623. #endif
  172624. {
  172625. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172626. dshift = 7 - (int)((final_width + 7) & 0x07);
  172627. s_start = 0;
  172628. s_end = 7;
  172629. s_inc = 1;
  172630. }
  172631. for (i = 0; i < row_info->width; i++)
  172632. {
  172633. v = (png_byte)((*sp >> sshift) & 0x01);
  172634. for (j = 0; j < jstop; j++)
  172635. {
  172636. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172637. *dp |= (png_byte)(v << dshift);
  172638. if (dshift == s_end)
  172639. {
  172640. dshift = s_start;
  172641. dp--;
  172642. }
  172643. else
  172644. dshift += s_inc;
  172645. }
  172646. if (sshift == s_end)
  172647. {
  172648. sshift = s_start;
  172649. sp--;
  172650. }
  172651. else
  172652. sshift += s_inc;
  172653. }
  172654. break;
  172655. }
  172656. case 2:
  172657. {
  172658. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172659. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172660. int sshift, dshift;
  172661. int s_start, s_end, s_inc;
  172662. int jstop = png_pass_inc[pass];
  172663. png_uint_32 i;
  172664. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172665. if (transformations & PNG_PACKSWAP)
  172666. {
  172667. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172668. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172669. s_start = 6;
  172670. s_end = 0;
  172671. s_inc = -2;
  172672. }
  172673. else
  172674. #endif
  172675. {
  172676. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172677. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172678. s_start = 0;
  172679. s_end = 6;
  172680. s_inc = 2;
  172681. }
  172682. for (i = 0; i < row_info->width; i++)
  172683. {
  172684. png_byte v;
  172685. int j;
  172686. v = (png_byte)((*sp >> sshift) & 0x03);
  172687. for (j = 0; j < jstop; j++)
  172688. {
  172689. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172690. *dp |= (png_byte)(v << dshift);
  172691. if (dshift == s_end)
  172692. {
  172693. dshift = s_start;
  172694. dp--;
  172695. }
  172696. else
  172697. dshift += s_inc;
  172698. }
  172699. if (sshift == s_end)
  172700. {
  172701. sshift = s_start;
  172702. sp--;
  172703. }
  172704. else
  172705. sshift += s_inc;
  172706. }
  172707. break;
  172708. }
  172709. case 4:
  172710. {
  172711. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172712. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172713. int sshift, dshift;
  172714. int s_start, s_end, s_inc;
  172715. png_uint_32 i;
  172716. int jstop = png_pass_inc[pass];
  172717. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172718. if (transformations & PNG_PACKSWAP)
  172719. {
  172720. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172721. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172722. s_start = 4;
  172723. s_end = 0;
  172724. s_inc = -4;
  172725. }
  172726. else
  172727. #endif
  172728. {
  172729. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172730. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172731. s_start = 0;
  172732. s_end = 4;
  172733. s_inc = 4;
  172734. }
  172735. for (i = 0; i < row_info->width; i++)
  172736. {
  172737. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172738. int j;
  172739. for (j = 0; j < jstop; j++)
  172740. {
  172741. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172742. *dp |= (png_byte)(v << dshift);
  172743. if (dshift == s_end)
  172744. {
  172745. dshift = s_start;
  172746. dp--;
  172747. }
  172748. else
  172749. dshift += s_inc;
  172750. }
  172751. if (sshift == s_end)
  172752. {
  172753. sshift = s_start;
  172754. sp--;
  172755. }
  172756. else
  172757. sshift += s_inc;
  172758. }
  172759. break;
  172760. }
  172761. default:
  172762. {
  172763. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172764. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172765. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172766. int jstop = png_pass_inc[pass];
  172767. png_uint_32 i;
  172768. for (i = 0; i < row_info->width; i++)
  172769. {
  172770. png_byte v[8];
  172771. int j;
  172772. png_memcpy(v, sp, pixel_bytes);
  172773. for (j = 0; j < jstop; j++)
  172774. {
  172775. png_memcpy(dp, v, pixel_bytes);
  172776. dp -= pixel_bytes;
  172777. }
  172778. sp -= pixel_bytes;
  172779. }
  172780. break;
  172781. }
  172782. }
  172783. row_info->width = final_width;
  172784. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172785. }
  172786. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172787. transformations = transformations; /* silence compiler warning */
  172788. #endif
  172789. }
  172790. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172791. void /* PRIVATE */
  172792. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172793. png_bytep prev_row, int filter)
  172794. {
  172795. png_debug(1, "in png_read_filter_row\n");
  172796. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172797. switch (filter)
  172798. {
  172799. case PNG_FILTER_VALUE_NONE:
  172800. break;
  172801. case PNG_FILTER_VALUE_SUB:
  172802. {
  172803. png_uint_32 i;
  172804. png_uint_32 istop = row_info->rowbytes;
  172805. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172806. png_bytep rp = row + bpp;
  172807. png_bytep lp = row;
  172808. for (i = bpp; i < istop; i++)
  172809. {
  172810. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172811. rp++;
  172812. }
  172813. break;
  172814. }
  172815. case PNG_FILTER_VALUE_UP:
  172816. {
  172817. png_uint_32 i;
  172818. png_uint_32 istop = row_info->rowbytes;
  172819. png_bytep rp = row;
  172820. png_bytep pp = prev_row;
  172821. for (i = 0; i < istop; i++)
  172822. {
  172823. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172824. rp++;
  172825. }
  172826. break;
  172827. }
  172828. case PNG_FILTER_VALUE_AVG:
  172829. {
  172830. png_uint_32 i;
  172831. png_bytep rp = row;
  172832. png_bytep pp = prev_row;
  172833. png_bytep lp = row;
  172834. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172835. png_uint_32 istop = row_info->rowbytes - bpp;
  172836. for (i = 0; i < bpp; i++)
  172837. {
  172838. *rp = (png_byte)(((int)(*rp) +
  172839. ((int)(*pp++) / 2 )) & 0xff);
  172840. rp++;
  172841. }
  172842. for (i = 0; i < istop; i++)
  172843. {
  172844. *rp = (png_byte)(((int)(*rp) +
  172845. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  172846. rp++;
  172847. }
  172848. break;
  172849. }
  172850. case PNG_FILTER_VALUE_PAETH:
  172851. {
  172852. png_uint_32 i;
  172853. png_bytep rp = row;
  172854. png_bytep pp = prev_row;
  172855. png_bytep lp = row;
  172856. png_bytep cp = prev_row;
  172857. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172858. png_uint_32 istop=row_info->rowbytes - bpp;
  172859. for (i = 0; i < bpp; i++)
  172860. {
  172861. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172862. rp++;
  172863. }
  172864. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  172865. {
  172866. int a, b, c, pa, pb, pc, p;
  172867. a = *lp++;
  172868. b = *pp++;
  172869. c = *cp++;
  172870. p = b - c;
  172871. pc = a - c;
  172872. #ifdef PNG_USE_ABS
  172873. pa = abs(p);
  172874. pb = abs(pc);
  172875. pc = abs(p + pc);
  172876. #else
  172877. pa = p < 0 ? -p : p;
  172878. pb = pc < 0 ? -pc : pc;
  172879. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  172880. #endif
  172881. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  172882. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  172883. rp++;
  172884. }
  172885. break;
  172886. }
  172887. default:
  172888. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  172889. *row=0;
  172890. break;
  172891. }
  172892. }
  172893. void /* PRIVATE */
  172894. png_read_finish_row(png_structp png_ptr)
  172895. {
  172896. #ifdef PNG_USE_LOCAL_ARRAYS
  172897. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  172898. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172899. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  172900. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  172901. #endif
  172902. png_debug(1, "in png_read_finish_row\n");
  172903. png_ptr->row_number++;
  172904. if (png_ptr->row_number < png_ptr->num_rows)
  172905. return;
  172906. if (png_ptr->interlaced)
  172907. {
  172908. png_ptr->row_number = 0;
  172909. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  172910. png_ptr->rowbytes + 1);
  172911. do
  172912. {
  172913. png_ptr->pass++;
  172914. if (png_ptr->pass >= 7)
  172915. break;
  172916. png_ptr->iwidth = (png_ptr->width +
  172917. png_pass_inc[png_ptr->pass] - 1 -
  172918. png_pass_start[png_ptr->pass]) /
  172919. png_pass_inc[png_ptr->pass];
  172920. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  172921. png_ptr->iwidth) + 1;
  172922. if (!(png_ptr->transformations & PNG_INTERLACE))
  172923. {
  172924. png_ptr->num_rows = (png_ptr->height +
  172925. png_pass_yinc[png_ptr->pass] - 1 -
  172926. png_pass_ystart[png_ptr->pass]) /
  172927. png_pass_yinc[png_ptr->pass];
  172928. if (!(png_ptr->num_rows))
  172929. continue;
  172930. }
  172931. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  172932. break;
  172933. } while (png_ptr->iwidth == 0);
  172934. if (png_ptr->pass < 7)
  172935. return;
  172936. }
  172937. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  172938. {
  172939. #ifdef PNG_USE_LOCAL_ARRAYS
  172940. PNG_CONST PNG_IDAT;
  172941. #endif
  172942. char extra;
  172943. int ret;
  172944. png_ptr->zstream.next_out = (Bytef *)&extra;
  172945. png_ptr->zstream.avail_out = (uInt)1;
  172946. for(;;)
  172947. {
  172948. if (!(png_ptr->zstream.avail_in))
  172949. {
  172950. while (!png_ptr->idat_size)
  172951. {
  172952. png_byte chunk_length[4];
  172953. png_crc_finish(png_ptr, 0);
  172954. png_read_data(png_ptr, chunk_length, 4);
  172955. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  172956. png_reset_crc(png_ptr);
  172957. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  172958. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  172959. png_error(png_ptr, "Not enough image data");
  172960. }
  172961. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  172962. png_ptr->zstream.next_in = png_ptr->zbuf;
  172963. if (png_ptr->zbuf_size > png_ptr->idat_size)
  172964. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  172965. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  172966. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  172967. }
  172968. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  172969. if (ret == Z_STREAM_END)
  172970. {
  172971. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  172972. png_ptr->idat_size)
  172973. png_warning(png_ptr, "Extra compressed data");
  172974. png_ptr->mode |= PNG_AFTER_IDAT;
  172975. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  172976. break;
  172977. }
  172978. if (ret != Z_OK)
  172979. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  172980. "Decompression Error");
  172981. if (!(png_ptr->zstream.avail_out))
  172982. {
  172983. png_warning(png_ptr, "Extra compressed data.");
  172984. png_ptr->mode |= PNG_AFTER_IDAT;
  172985. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  172986. break;
  172987. }
  172988. }
  172989. png_ptr->zstream.avail_out = 0;
  172990. }
  172991. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  172992. png_warning(png_ptr, "Extra compression data");
  172993. inflateReset(&png_ptr->zstream);
  172994. png_ptr->mode |= PNG_AFTER_IDAT;
  172995. }
  172996. void /* PRIVATE */
  172997. png_read_start_row(png_structp png_ptr)
  172998. {
  172999. #ifdef PNG_USE_LOCAL_ARRAYS
  173000. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173001. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173002. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173003. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173004. #endif
  173005. int max_pixel_depth;
  173006. png_uint_32 row_bytes;
  173007. png_debug(1, "in png_read_start_row\n");
  173008. png_ptr->zstream.avail_in = 0;
  173009. png_init_read_transformations(png_ptr);
  173010. if (png_ptr->interlaced)
  173011. {
  173012. if (!(png_ptr->transformations & PNG_INTERLACE))
  173013. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173014. png_pass_ystart[0]) / png_pass_yinc[0];
  173015. else
  173016. png_ptr->num_rows = png_ptr->height;
  173017. png_ptr->iwidth = (png_ptr->width +
  173018. png_pass_inc[png_ptr->pass] - 1 -
  173019. png_pass_start[png_ptr->pass]) /
  173020. png_pass_inc[png_ptr->pass];
  173021. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173022. png_ptr->irowbytes = (png_size_t)row_bytes;
  173023. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173024. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173025. }
  173026. else
  173027. {
  173028. png_ptr->num_rows = png_ptr->height;
  173029. png_ptr->iwidth = png_ptr->width;
  173030. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173031. }
  173032. max_pixel_depth = png_ptr->pixel_depth;
  173033. #if defined(PNG_READ_PACK_SUPPORTED)
  173034. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173035. max_pixel_depth = 8;
  173036. #endif
  173037. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173038. if (png_ptr->transformations & PNG_EXPAND)
  173039. {
  173040. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173041. {
  173042. if (png_ptr->num_trans)
  173043. max_pixel_depth = 32;
  173044. else
  173045. max_pixel_depth = 24;
  173046. }
  173047. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173048. {
  173049. if (max_pixel_depth < 8)
  173050. max_pixel_depth = 8;
  173051. if (png_ptr->num_trans)
  173052. max_pixel_depth *= 2;
  173053. }
  173054. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173055. {
  173056. if (png_ptr->num_trans)
  173057. {
  173058. max_pixel_depth *= 4;
  173059. max_pixel_depth /= 3;
  173060. }
  173061. }
  173062. }
  173063. #endif
  173064. #if defined(PNG_READ_FILLER_SUPPORTED)
  173065. if (png_ptr->transformations & (PNG_FILLER))
  173066. {
  173067. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173068. max_pixel_depth = 32;
  173069. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173070. {
  173071. if (max_pixel_depth <= 8)
  173072. max_pixel_depth = 16;
  173073. else
  173074. max_pixel_depth = 32;
  173075. }
  173076. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173077. {
  173078. if (max_pixel_depth <= 32)
  173079. max_pixel_depth = 32;
  173080. else
  173081. max_pixel_depth = 64;
  173082. }
  173083. }
  173084. #endif
  173085. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173086. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173087. {
  173088. if (
  173089. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173090. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173091. #endif
  173092. #if defined(PNG_READ_FILLER_SUPPORTED)
  173093. (png_ptr->transformations & (PNG_FILLER)) ||
  173094. #endif
  173095. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173096. {
  173097. if (max_pixel_depth <= 16)
  173098. max_pixel_depth = 32;
  173099. else
  173100. max_pixel_depth = 64;
  173101. }
  173102. else
  173103. {
  173104. if (max_pixel_depth <= 8)
  173105. {
  173106. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173107. max_pixel_depth = 32;
  173108. else
  173109. max_pixel_depth = 24;
  173110. }
  173111. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173112. max_pixel_depth = 64;
  173113. else
  173114. max_pixel_depth = 48;
  173115. }
  173116. }
  173117. #endif
  173118. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173119. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173120. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173121. {
  173122. int user_pixel_depth=png_ptr->user_transform_depth*
  173123. png_ptr->user_transform_channels;
  173124. if(user_pixel_depth > max_pixel_depth)
  173125. max_pixel_depth=user_pixel_depth;
  173126. }
  173127. #endif
  173128. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173129. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173130. 1 + ((max_pixel_depth + 7) >> 3);
  173131. #ifdef PNG_MAX_MALLOC_64K
  173132. if (row_bytes > (png_uint_32)65536L)
  173133. png_error(png_ptr, "This image requires a row greater than 64KB");
  173134. #endif
  173135. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173136. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173137. #ifdef PNG_MAX_MALLOC_64K
  173138. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173139. png_error(png_ptr, "This image requires a row greater than 64KB");
  173140. #endif
  173141. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173142. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173143. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173144. png_ptr->rowbytes + 1));
  173145. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173146. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173147. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173148. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173149. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173150. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173151. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173152. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173153. }
  173154. #endif /* PNG_READ_SUPPORTED */
  173155. /*** End of inlined file: pngrutil.c ***/
  173156. /*** Start of inlined file: pngset.c ***/
  173157. #define PNG_INTERNAL
  173158. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173159. #if defined(PNG_bKGD_SUPPORTED)
  173160. void PNGAPI
  173161. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173162. {
  173163. png_debug1(1, "in %s storage function\n", "bKGD");
  173164. if (png_ptr == NULL || info_ptr == NULL)
  173165. return;
  173166. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173167. info_ptr->valid |= PNG_INFO_bKGD;
  173168. }
  173169. #endif
  173170. #if defined(PNG_cHRM_SUPPORTED)
  173171. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173172. void PNGAPI
  173173. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173174. double white_x, double white_y, double red_x, double red_y,
  173175. double green_x, double green_y, double blue_x, double blue_y)
  173176. {
  173177. png_debug1(1, "in %s storage function\n", "cHRM");
  173178. if (png_ptr == NULL || info_ptr == NULL)
  173179. return;
  173180. if (white_x < 0.0 || white_y < 0.0 ||
  173181. red_x < 0.0 || red_y < 0.0 ||
  173182. green_x < 0.0 || green_y < 0.0 ||
  173183. blue_x < 0.0 || blue_y < 0.0)
  173184. {
  173185. png_warning(png_ptr,
  173186. "Ignoring attempt to set negative chromaticity value");
  173187. return;
  173188. }
  173189. if (white_x > 21474.83 || white_y > 21474.83 ||
  173190. red_x > 21474.83 || red_y > 21474.83 ||
  173191. green_x > 21474.83 || green_y > 21474.83 ||
  173192. blue_x > 21474.83 || blue_y > 21474.83)
  173193. {
  173194. png_warning(png_ptr,
  173195. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173196. return;
  173197. }
  173198. info_ptr->x_white = (float)white_x;
  173199. info_ptr->y_white = (float)white_y;
  173200. info_ptr->x_red = (float)red_x;
  173201. info_ptr->y_red = (float)red_y;
  173202. info_ptr->x_green = (float)green_x;
  173203. info_ptr->y_green = (float)green_y;
  173204. info_ptr->x_blue = (float)blue_x;
  173205. info_ptr->y_blue = (float)blue_y;
  173206. #ifdef PNG_FIXED_POINT_SUPPORTED
  173207. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173208. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173209. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173210. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173211. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173212. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173213. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173214. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173215. #endif
  173216. info_ptr->valid |= PNG_INFO_cHRM;
  173217. }
  173218. #endif
  173219. #ifdef PNG_FIXED_POINT_SUPPORTED
  173220. void PNGAPI
  173221. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173222. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173223. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173224. png_fixed_point blue_x, png_fixed_point blue_y)
  173225. {
  173226. png_debug1(1, "in %s storage function\n", "cHRM");
  173227. if (png_ptr == NULL || info_ptr == NULL)
  173228. return;
  173229. if (white_x < 0 || white_y < 0 ||
  173230. red_x < 0 || red_y < 0 ||
  173231. green_x < 0 || green_y < 0 ||
  173232. blue_x < 0 || blue_y < 0)
  173233. {
  173234. png_warning(png_ptr,
  173235. "Ignoring attempt to set negative chromaticity value");
  173236. return;
  173237. }
  173238. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173239. if (white_x > (double) PNG_UINT_31_MAX ||
  173240. white_y > (double) PNG_UINT_31_MAX ||
  173241. red_x > (double) PNG_UINT_31_MAX ||
  173242. red_y > (double) PNG_UINT_31_MAX ||
  173243. green_x > (double) PNG_UINT_31_MAX ||
  173244. green_y > (double) PNG_UINT_31_MAX ||
  173245. blue_x > (double) PNG_UINT_31_MAX ||
  173246. blue_y > (double) PNG_UINT_31_MAX)
  173247. #else
  173248. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173249. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173250. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173251. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173252. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173253. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173254. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173255. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173256. #endif
  173257. {
  173258. png_warning(png_ptr,
  173259. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173260. return;
  173261. }
  173262. info_ptr->int_x_white = white_x;
  173263. info_ptr->int_y_white = white_y;
  173264. info_ptr->int_x_red = red_x;
  173265. info_ptr->int_y_red = red_y;
  173266. info_ptr->int_x_green = green_x;
  173267. info_ptr->int_y_green = green_y;
  173268. info_ptr->int_x_blue = blue_x;
  173269. info_ptr->int_y_blue = blue_y;
  173270. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173271. info_ptr->x_white = (float)(white_x/100000.);
  173272. info_ptr->y_white = (float)(white_y/100000.);
  173273. info_ptr->x_red = (float)( red_x/100000.);
  173274. info_ptr->y_red = (float)( red_y/100000.);
  173275. info_ptr->x_green = (float)(green_x/100000.);
  173276. info_ptr->y_green = (float)(green_y/100000.);
  173277. info_ptr->x_blue = (float)( blue_x/100000.);
  173278. info_ptr->y_blue = (float)( blue_y/100000.);
  173279. #endif
  173280. info_ptr->valid |= PNG_INFO_cHRM;
  173281. }
  173282. #endif
  173283. #endif
  173284. #if defined(PNG_gAMA_SUPPORTED)
  173285. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173286. void PNGAPI
  173287. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173288. {
  173289. double gamma;
  173290. png_debug1(1, "in %s storage function\n", "gAMA");
  173291. if (png_ptr == NULL || info_ptr == NULL)
  173292. return;
  173293. if (file_gamma > 21474.83)
  173294. {
  173295. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173296. gamma=21474.83;
  173297. }
  173298. else
  173299. gamma=file_gamma;
  173300. info_ptr->gamma = (float)gamma;
  173301. #ifdef PNG_FIXED_POINT_SUPPORTED
  173302. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173303. #endif
  173304. info_ptr->valid |= PNG_INFO_gAMA;
  173305. if(gamma == 0.0)
  173306. png_warning(png_ptr, "Setting gamma=0");
  173307. }
  173308. #endif
  173309. void PNGAPI
  173310. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173311. int_gamma)
  173312. {
  173313. png_fixed_point gamma;
  173314. png_debug1(1, "in %s storage function\n", "gAMA");
  173315. if (png_ptr == NULL || info_ptr == NULL)
  173316. return;
  173317. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173318. {
  173319. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173320. gamma=PNG_UINT_31_MAX;
  173321. }
  173322. else
  173323. {
  173324. if (int_gamma < 0)
  173325. {
  173326. png_warning(png_ptr, "Setting negative gamma to zero");
  173327. gamma=0;
  173328. }
  173329. else
  173330. gamma=int_gamma;
  173331. }
  173332. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173333. info_ptr->gamma = (float)(gamma/100000.);
  173334. #endif
  173335. #ifdef PNG_FIXED_POINT_SUPPORTED
  173336. info_ptr->int_gamma = gamma;
  173337. #endif
  173338. info_ptr->valid |= PNG_INFO_gAMA;
  173339. if(gamma == 0)
  173340. png_warning(png_ptr, "Setting gamma=0");
  173341. }
  173342. #endif
  173343. #if defined(PNG_hIST_SUPPORTED)
  173344. void PNGAPI
  173345. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173346. {
  173347. int i;
  173348. png_debug1(1, "in %s storage function\n", "hIST");
  173349. if (png_ptr == NULL || info_ptr == NULL)
  173350. return;
  173351. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173352. > PNG_MAX_PALETTE_LENGTH)
  173353. {
  173354. png_warning(png_ptr,
  173355. "Invalid palette size, hIST allocation skipped.");
  173356. return;
  173357. }
  173358. #ifdef PNG_FREE_ME_SUPPORTED
  173359. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173360. #endif
  173361. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173362. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173363. if (png_ptr->hist == NULL)
  173364. {
  173365. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173366. return;
  173367. }
  173368. for (i = 0; i < info_ptr->num_palette; i++)
  173369. png_ptr->hist[i] = hist[i];
  173370. info_ptr->hist = png_ptr->hist;
  173371. info_ptr->valid |= PNG_INFO_hIST;
  173372. #ifdef PNG_FREE_ME_SUPPORTED
  173373. info_ptr->free_me |= PNG_FREE_HIST;
  173374. #else
  173375. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173376. #endif
  173377. }
  173378. #endif
  173379. void PNGAPI
  173380. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173381. png_uint_32 width, png_uint_32 height, int bit_depth,
  173382. int color_type, int interlace_type, int compression_type,
  173383. int filter_type)
  173384. {
  173385. png_debug1(1, "in %s storage function\n", "IHDR");
  173386. if (png_ptr == NULL || info_ptr == NULL)
  173387. return;
  173388. if (width == 0 || height == 0)
  173389. png_error(png_ptr, "Image width or height is zero in IHDR");
  173390. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173391. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173392. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173393. #else
  173394. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173395. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173396. #endif
  173397. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173398. png_error(png_ptr, "Invalid image size in IHDR");
  173399. if ( width > (PNG_UINT_32_MAX
  173400. >> 3) /* 8-byte RGBA pixels */
  173401. - 64 /* bigrowbuf hack */
  173402. - 1 /* filter byte */
  173403. - 7*8 /* rounding of width to multiple of 8 pixels */
  173404. - 8) /* extra max_pixel_depth pad */
  173405. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173406. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173407. bit_depth != 8 && bit_depth != 16)
  173408. png_error(png_ptr, "Invalid bit depth in IHDR");
  173409. if (color_type < 0 || color_type == 1 ||
  173410. color_type == 5 || color_type > 6)
  173411. png_error(png_ptr, "Invalid color type in IHDR");
  173412. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173413. ((color_type == PNG_COLOR_TYPE_RGB ||
  173414. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173415. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173416. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173417. if (interlace_type >= PNG_INTERLACE_LAST)
  173418. png_error(png_ptr, "Unknown interlace method in IHDR");
  173419. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173420. png_error(png_ptr, "Unknown compression method in IHDR");
  173421. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173422. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173423. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173424. if(filter_type != PNG_FILTER_TYPE_BASE)
  173425. {
  173426. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173427. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173428. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173429. (color_type == PNG_COLOR_TYPE_RGB ||
  173430. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173431. png_error(png_ptr, "Unknown filter method in IHDR");
  173432. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173433. png_warning(png_ptr, "Invalid filter method in IHDR");
  173434. }
  173435. #else
  173436. if(filter_type != PNG_FILTER_TYPE_BASE)
  173437. png_error(png_ptr, "Unknown filter method in IHDR");
  173438. #endif
  173439. info_ptr->width = width;
  173440. info_ptr->height = height;
  173441. info_ptr->bit_depth = (png_byte)bit_depth;
  173442. info_ptr->color_type =(png_byte) color_type;
  173443. info_ptr->compression_type = (png_byte)compression_type;
  173444. info_ptr->filter_type = (png_byte)filter_type;
  173445. info_ptr->interlace_type = (png_byte)interlace_type;
  173446. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173447. info_ptr->channels = 1;
  173448. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173449. info_ptr->channels = 3;
  173450. else
  173451. info_ptr->channels = 1;
  173452. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173453. info_ptr->channels++;
  173454. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173455. if (width > (PNG_UINT_32_MAX
  173456. >> 3) /* 8-byte RGBA pixels */
  173457. - 64 /* bigrowbuf hack */
  173458. - 1 /* filter byte */
  173459. - 7*8 /* rounding of width to multiple of 8 pixels */
  173460. - 8) /* extra max_pixel_depth pad */
  173461. info_ptr->rowbytes = (png_size_t)0;
  173462. else
  173463. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173464. }
  173465. #if defined(PNG_oFFs_SUPPORTED)
  173466. void PNGAPI
  173467. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173468. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173469. {
  173470. png_debug1(1, "in %s storage function\n", "oFFs");
  173471. if (png_ptr == NULL || info_ptr == NULL)
  173472. return;
  173473. info_ptr->x_offset = offset_x;
  173474. info_ptr->y_offset = offset_y;
  173475. info_ptr->offset_unit_type = (png_byte)unit_type;
  173476. info_ptr->valid |= PNG_INFO_oFFs;
  173477. }
  173478. #endif
  173479. #if defined(PNG_pCAL_SUPPORTED)
  173480. void PNGAPI
  173481. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173482. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173483. png_charp units, png_charpp params)
  173484. {
  173485. png_uint_32 length;
  173486. int i;
  173487. png_debug1(1, "in %s storage function\n", "pCAL");
  173488. if (png_ptr == NULL || info_ptr == NULL)
  173489. return;
  173490. length = png_strlen(purpose) + 1;
  173491. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173492. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173493. if (info_ptr->pcal_purpose == NULL)
  173494. {
  173495. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173496. return;
  173497. }
  173498. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173499. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173500. info_ptr->pcal_X0 = X0;
  173501. info_ptr->pcal_X1 = X1;
  173502. info_ptr->pcal_type = (png_byte)type;
  173503. info_ptr->pcal_nparams = (png_byte)nparams;
  173504. length = png_strlen(units) + 1;
  173505. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173506. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173507. if (info_ptr->pcal_units == NULL)
  173508. {
  173509. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173510. return;
  173511. }
  173512. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173513. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173514. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173515. if (info_ptr->pcal_params == NULL)
  173516. {
  173517. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173518. return;
  173519. }
  173520. info_ptr->pcal_params[nparams] = NULL;
  173521. for (i = 0; i < nparams; i++)
  173522. {
  173523. length = png_strlen(params[i]) + 1;
  173524. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173525. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173526. if (info_ptr->pcal_params[i] == NULL)
  173527. {
  173528. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173529. return;
  173530. }
  173531. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173532. }
  173533. info_ptr->valid |= PNG_INFO_pCAL;
  173534. #ifdef PNG_FREE_ME_SUPPORTED
  173535. info_ptr->free_me |= PNG_FREE_PCAL;
  173536. #endif
  173537. }
  173538. #endif
  173539. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173540. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173541. void PNGAPI
  173542. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173543. int unit, double width, double height)
  173544. {
  173545. png_debug1(1, "in %s storage function\n", "sCAL");
  173546. if (png_ptr == NULL || info_ptr == NULL)
  173547. return;
  173548. info_ptr->scal_unit = (png_byte)unit;
  173549. info_ptr->scal_pixel_width = width;
  173550. info_ptr->scal_pixel_height = height;
  173551. info_ptr->valid |= PNG_INFO_sCAL;
  173552. }
  173553. #else
  173554. #ifdef PNG_FIXED_POINT_SUPPORTED
  173555. void PNGAPI
  173556. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173557. int unit, png_charp swidth, png_charp sheight)
  173558. {
  173559. png_uint_32 length;
  173560. png_debug1(1, "in %s storage function\n", "sCAL");
  173561. if (png_ptr == NULL || info_ptr == NULL)
  173562. return;
  173563. info_ptr->scal_unit = (png_byte)unit;
  173564. length = png_strlen(swidth) + 1;
  173565. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173566. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173567. if (info_ptr->scal_s_width == NULL)
  173568. {
  173569. png_warning(png_ptr,
  173570. "Memory allocation failed while processing sCAL.");
  173571. }
  173572. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173573. length = png_strlen(sheight) + 1;
  173574. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173575. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173576. if (info_ptr->scal_s_height == NULL)
  173577. {
  173578. png_free (png_ptr, info_ptr->scal_s_width);
  173579. png_warning(png_ptr,
  173580. "Memory allocation failed while processing sCAL.");
  173581. }
  173582. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173583. info_ptr->valid |= PNG_INFO_sCAL;
  173584. #ifdef PNG_FREE_ME_SUPPORTED
  173585. info_ptr->free_me |= PNG_FREE_SCAL;
  173586. #endif
  173587. }
  173588. #endif
  173589. #endif
  173590. #endif
  173591. #if defined(PNG_pHYs_SUPPORTED)
  173592. void PNGAPI
  173593. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173594. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173595. {
  173596. png_debug1(1, "in %s storage function\n", "pHYs");
  173597. if (png_ptr == NULL || info_ptr == NULL)
  173598. return;
  173599. info_ptr->x_pixels_per_unit = res_x;
  173600. info_ptr->y_pixels_per_unit = res_y;
  173601. info_ptr->phys_unit_type = (png_byte)unit_type;
  173602. info_ptr->valid |= PNG_INFO_pHYs;
  173603. }
  173604. #endif
  173605. void PNGAPI
  173606. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173607. png_colorp palette, int num_palette)
  173608. {
  173609. png_debug1(1, "in %s storage function\n", "PLTE");
  173610. if (png_ptr == NULL || info_ptr == NULL)
  173611. return;
  173612. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173613. {
  173614. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173615. png_error(png_ptr, "Invalid palette length");
  173616. else
  173617. {
  173618. png_warning(png_ptr, "Invalid palette length");
  173619. return;
  173620. }
  173621. }
  173622. #ifdef PNG_FREE_ME_SUPPORTED
  173623. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173624. #endif
  173625. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173626. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173627. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173628. png_sizeof(png_color));
  173629. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173630. info_ptr->palette = png_ptr->palette;
  173631. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173632. #ifdef PNG_FREE_ME_SUPPORTED
  173633. info_ptr->free_me |= PNG_FREE_PLTE;
  173634. #else
  173635. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173636. #endif
  173637. info_ptr->valid |= PNG_INFO_PLTE;
  173638. }
  173639. #if defined(PNG_sBIT_SUPPORTED)
  173640. void PNGAPI
  173641. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173642. png_color_8p sig_bit)
  173643. {
  173644. png_debug1(1, "in %s storage function\n", "sBIT");
  173645. if (png_ptr == NULL || info_ptr == NULL)
  173646. return;
  173647. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173648. info_ptr->valid |= PNG_INFO_sBIT;
  173649. }
  173650. #endif
  173651. #if defined(PNG_sRGB_SUPPORTED)
  173652. void PNGAPI
  173653. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173654. {
  173655. png_debug1(1, "in %s storage function\n", "sRGB");
  173656. if (png_ptr == NULL || info_ptr == NULL)
  173657. return;
  173658. info_ptr->srgb_intent = (png_byte)intent;
  173659. info_ptr->valid |= PNG_INFO_sRGB;
  173660. }
  173661. void PNGAPI
  173662. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173663. int intent)
  173664. {
  173665. #if defined(PNG_gAMA_SUPPORTED)
  173666. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173667. float file_gamma;
  173668. #endif
  173669. #ifdef PNG_FIXED_POINT_SUPPORTED
  173670. png_fixed_point int_file_gamma;
  173671. #endif
  173672. #endif
  173673. #if defined(PNG_cHRM_SUPPORTED)
  173674. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173675. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173676. #endif
  173677. #ifdef PNG_FIXED_POINT_SUPPORTED
  173678. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173679. int_green_y, int_blue_x, int_blue_y;
  173680. #endif
  173681. #endif
  173682. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173683. if (png_ptr == NULL || info_ptr == NULL)
  173684. return;
  173685. png_set_sRGB(png_ptr, info_ptr, intent);
  173686. #if defined(PNG_gAMA_SUPPORTED)
  173687. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173688. file_gamma = (float).45455;
  173689. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173690. #endif
  173691. #ifdef PNG_FIXED_POINT_SUPPORTED
  173692. int_file_gamma = 45455L;
  173693. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173694. #endif
  173695. #endif
  173696. #if defined(PNG_cHRM_SUPPORTED)
  173697. #ifdef PNG_FIXED_POINT_SUPPORTED
  173698. int_white_x = 31270L;
  173699. int_white_y = 32900L;
  173700. int_red_x = 64000L;
  173701. int_red_y = 33000L;
  173702. int_green_x = 30000L;
  173703. int_green_y = 60000L;
  173704. int_blue_x = 15000L;
  173705. int_blue_y = 6000L;
  173706. png_set_cHRM_fixed(png_ptr, info_ptr,
  173707. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173708. int_blue_x, int_blue_y);
  173709. #endif
  173710. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173711. white_x = (float).3127;
  173712. white_y = (float).3290;
  173713. red_x = (float).64;
  173714. red_y = (float).33;
  173715. green_x = (float).30;
  173716. green_y = (float).60;
  173717. blue_x = (float).15;
  173718. blue_y = (float).06;
  173719. png_set_cHRM(png_ptr, info_ptr,
  173720. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173721. #endif
  173722. #endif
  173723. }
  173724. #endif
  173725. #if defined(PNG_iCCP_SUPPORTED)
  173726. void PNGAPI
  173727. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173728. png_charp name, int compression_type,
  173729. png_charp profile, png_uint_32 proflen)
  173730. {
  173731. png_charp new_iccp_name;
  173732. png_charp new_iccp_profile;
  173733. png_debug1(1, "in %s storage function\n", "iCCP");
  173734. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173735. return;
  173736. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173737. if (new_iccp_name == NULL)
  173738. {
  173739. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173740. return;
  173741. }
  173742. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173743. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173744. if (new_iccp_profile == NULL)
  173745. {
  173746. png_free (png_ptr, new_iccp_name);
  173747. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173748. return;
  173749. }
  173750. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173751. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173752. info_ptr->iccp_proflen = proflen;
  173753. info_ptr->iccp_name = new_iccp_name;
  173754. info_ptr->iccp_profile = new_iccp_profile;
  173755. info_ptr->iccp_compression = (png_byte)compression_type;
  173756. #ifdef PNG_FREE_ME_SUPPORTED
  173757. info_ptr->free_me |= PNG_FREE_ICCP;
  173758. #endif
  173759. info_ptr->valid |= PNG_INFO_iCCP;
  173760. }
  173761. #endif
  173762. #if defined(PNG_TEXT_SUPPORTED)
  173763. void PNGAPI
  173764. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173765. int num_text)
  173766. {
  173767. int ret;
  173768. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173769. if (ret)
  173770. png_error(png_ptr, "Insufficient memory to store text");
  173771. }
  173772. int /* PRIVATE */
  173773. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173774. int num_text)
  173775. {
  173776. int i;
  173777. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173778. "text" : (png_const_charp)png_ptr->chunk_name));
  173779. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173780. return(0);
  173781. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173782. {
  173783. if (info_ptr->text != NULL)
  173784. {
  173785. png_textp old_text;
  173786. int old_max;
  173787. old_max = info_ptr->max_text;
  173788. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173789. old_text = info_ptr->text;
  173790. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173791. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173792. if (info_ptr->text == NULL)
  173793. {
  173794. png_free(png_ptr, old_text);
  173795. return(1);
  173796. }
  173797. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173798. png_sizeof(png_text)));
  173799. png_free(png_ptr, old_text);
  173800. }
  173801. else
  173802. {
  173803. info_ptr->max_text = num_text + 8;
  173804. info_ptr->num_text = 0;
  173805. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173806. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173807. if (info_ptr->text == NULL)
  173808. return(1);
  173809. #ifdef PNG_FREE_ME_SUPPORTED
  173810. info_ptr->free_me |= PNG_FREE_TEXT;
  173811. #endif
  173812. }
  173813. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  173814. info_ptr->max_text);
  173815. }
  173816. for (i = 0; i < num_text; i++)
  173817. {
  173818. png_size_t text_length,key_len;
  173819. png_size_t lang_len,lang_key_len;
  173820. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  173821. if (text_ptr[i].key == NULL)
  173822. continue;
  173823. key_len = png_strlen(text_ptr[i].key);
  173824. if(text_ptr[i].compression <= 0)
  173825. {
  173826. lang_len = 0;
  173827. lang_key_len = 0;
  173828. }
  173829. else
  173830. #ifdef PNG_iTXt_SUPPORTED
  173831. {
  173832. if (text_ptr[i].lang != NULL)
  173833. lang_len = png_strlen(text_ptr[i].lang);
  173834. else
  173835. lang_len = 0;
  173836. if (text_ptr[i].lang_key != NULL)
  173837. lang_key_len = png_strlen(text_ptr[i].lang_key);
  173838. else
  173839. lang_key_len = 0;
  173840. }
  173841. #else
  173842. {
  173843. png_warning(png_ptr, "iTXt chunk not supported.");
  173844. continue;
  173845. }
  173846. #endif
  173847. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  173848. {
  173849. text_length = 0;
  173850. #ifdef PNG_iTXt_SUPPORTED
  173851. if(text_ptr[i].compression > 0)
  173852. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  173853. else
  173854. #endif
  173855. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  173856. }
  173857. else
  173858. {
  173859. text_length = png_strlen(text_ptr[i].text);
  173860. textp->compression = text_ptr[i].compression;
  173861. }
  173862. textp->key = (png_charp)png_malloc_warn(png_ptr,
  173863. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  173864. if (textp->key == NULL)
  173865. return(1);
  173866. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  173867. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  173868. (int)textp->key);
  173869. png_memcpy(textp->key, text_ptr[i].key,
  173870. (png_size_t)(key_len));
  173871. *(textp->key+key_len) = '\0';
  173872. #ifdef PNG_iTXt_SUPPORTED
  173873. if (text_ptr[i].compression > 0)
  173874. {
  173875. textp->lang=textp->key + key_len + 1;
  173876. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  173877. *(textp->lang+lang_len) = '\0';
  173878. textp->lang_key=textp->lang + lang_len + 1;
  173879. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  173880. *(textp->lang_key+lang_key_len) = '\0';
  173881. textp->text=textp->lang_key + lang_key_len + 1;
  173882. }
  173883. else
  173884. #endif
  173885. {
  173886. #ifdef PNG_iTXt_SUPPORTED
  173887. textp->lang=NULL;
  173888. textp->lang_key=NULL;
  173889. #endif
  173890. textp->text=textp->key + key_len + 1;
  173891. }
  173892. if(text_length)
  173893. png_memcpy(textp->text, text_ptr[i].text,
  173894. (png_size_t)(text_length));
  173895. *(textp->text+text_length) = '\0';
  173896. #ifdef PNG_iTXt_SUPPORTED
  173897. if(textp->compression > 0)
  173898. {
  173899. textp->text_length = 0;
  173900. textp->itxt_length = text_length;
  173901. }
  173902. else
  173903. #endif
  173904. {
  173905. textp->text_length = text_length;
  173906. #ifdef PNG_iTXt_SUPPORTED
  173907. textp->itxt_length = 0;
  173908. #endif
  173909. }
  173910. info_ptr->num_text++;
  173911. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  173912. }
  173913. return(0);
  173914. }
  173915. #endif
  173916. #if defined(PNG_tIME_SUPPORTED)
  173917. void PNGAPI
  173918. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  173919. {
  173920. png_debug1(1, "in %s storage function\n", "tIME");
  173921. if (png_ptr == NULL || info_ptr == NULL ||
  173922. (png_ptr->mode & PNG_WROTE_tIME))
  173923. return;
  173924. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  173925. info_ptr->valid |= PNG_INFO_tIME;
  173926. }
  173927. #endif
  173928. #if defined(PNG_tRNS_SUPPORTED)
  173929. void PNGAPI
  173930. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  173931. png_bytep trans, int num_trans, png_color_16p trans_values)
  173932. {
  173933. png_debug1(1, "in %s storage function\n", "tRNS");
  173934. if (png_ptr == NULL || info_ptr == NULL)
  173935. return;
  173936. if (trans != NULL)
  173937. {
  173938. #ifdef PNG_FREE_ME_SUPPORTED
  173939. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  173940. #endif
  173941. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  173942. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  173943. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  173944. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  173945. #ifdef PNG_FREE_ME_SUPPORTED
  173946. info_ptr->free_me |= PNG_FREE_TRNS;
  173947. #else
  173948. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  173949. #endif
  173950. }
  173951. if (trans_values != NULL)
  173952. {
  173953. png_memcpy(&(info_ptr->trans_values), trans_values,
  173954. png_sizeof(png_color_16));
  173955. if (num_trans == 0)
  173956. num_trans = 1;
  173957. }
  173958. info_ptr->num_trans = (png_uint_16)num_trans;
  173959. info_ptr->valid |= PNG_INFO_tRNS;
  173960. }
  173961. #endif
  173962. #if defined(PNG_sPLT_SUPPORTED)
  173963. void PNGAPI
  173964. png_set_sPLT(png_structp png_ptr,
  173965. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  173966. {
  173967. png_sPLT_tp np;
  173968. int i;
  173969. if (png_ptr == NULL || info_ptr == NULL)
  173970. return;
  173971. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  173972. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  173973. if (np == NULL)
  173974. {
  173975. png_warning(png_ptr, "No memory for sPLT palettes.");
  173976. return;
  173977. }
  173978. png_memcpy(np, info_ptr->splt_palettes,
  173979. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  173980. png_free(png_ptr, info_ptr->splt_palettes);
  173981. info_ptr->splt_palettes=NULL;
  173982. for (i = 0; i < nentries; i++)
  173983. {
  173984. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  173985. png_sPLT_tp from = entries + i;
  173986. to->name = (png_charp)png_malloc_warn(png_ptr,
  173987. png_strlen(from->name) + 1);
  173988. if (to->name == NULL)
  173989. {
  173990. png_warning(png_ptr,
  173991. "Out of memory while processing sPLT chunk");
  173992. }
  173993. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  173994. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  173995. from->nentries * png_sizeof(png_sPLT_entry));
  173996. png_memcpy(to->entries, from->entries,
  173997. from->nentries * png_sizeof(png_sPLT_entry));
  173998. if (to->entries == NULL)
  173999. {
  174000. png_warning(png_ptr,
  174001. "Out of memory while processing sPLT chunk");
  174002. png_free(png_ptr,to->name);
  174003. to->name = NULL;
  174004. }
  174005. to->nentries = from->nentries;
  174006. to->depth = from->depth;
  174007. }
  174008. info_ptr->splt_palettes = np;
  174009. info_ptr->splt_palettes_num += nentries;
  174010. info_ptr->valid |= PNG_INFO_sPLT;
  174011. #ifdef PNG_FREE_ME_SUPPORTED
  174012. info_ptr->free_me |= PNG_FREE_SPLT;
  174013. #endif
  174014. }
  174015. #endif /* PNG_sPLT_SUPPORTED */
  174016. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174017. void PNGAPI
  174018. png_set_unknown_chunks(png_structp png_ptr,
  174019. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174020. {
  174021. png_unknown_chunkp np;
  174022. int i;
  174023. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174024. return;
  174025. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174026. (info_ptr->unknown_chunks_num + num_unknowns) *
  174027. png_sizeof(png_unknown_chunk));
  174028. if (np == NULL)
  174029. {
  174030. png_warning(png_ptr,
  174031. "Out of memory while processing unknown chunk.");
  174032. return;
  174033. }
  174034. png_memcpy(np, info_ptr->unknown_chunks,
  174035. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174036. png_free(png_ptr, info_ptr->unknown_chunks);
  174037. info_ptr->unknown_chunks=NULL;
  174038. for (i = 0; i < num_unknowns; i++)
  174039. {
  174040. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174041. png_unknown_chunkp from = unknowns + i;
  174042. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174043. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174044. if (to->data == NULL)
  174045. {
  174046. png_warning(png_ptr,
  174047. "Out of memory while processing unknown chunk.");
  174048. }
  174049. else
  174050. {
  174051. png_memcpy(to->data, from->data, from->size);
  174052. to->size = from->size;
  174053. to->location = (png_byte)(png_ptr->mode & 0xff);
  174054. }
  174055. }
  174056. info_ptr->unknown_chunks = np;
  174057. info_ptr->unknown_chunks_num += num_unknowns;
  174058. #ifdef PNG_FREE_ME_SUPPORTED
  174059. info_ptr->free_me |= PNG_FREE_UNKN;
  174060. #endif
  174061. }
  174062. void PNGAPI
  174063. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174064. int chunk, int location)
  174065. {
  174066. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174067. (int)info_ptr->unknown_chunks_num)
  174068. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174069. }
  174070. #endif
  174071. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174072. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174073. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174074. void PNGAPI
  174075. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174076. {
  174077. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174078. if (png_ptr == NULL)
  174079. return;
  174080. png_ptr->mng_features_permitted = (png_byte)
  174081. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174082. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174083. }
  174084. #endif
  174085. #endif
  174086. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174087. png_uint_32 PNGAPI
  174088. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174089. {
  174090. png_debug(1, "in png_permit_mng_features\n");
  174091. if (png_ptr == NULL)
  174092. return (png_uint_32)0;
  174093. png_ptr->mng_features_permitted =
  174094. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174095. return (png_uint_32)png_ptr->mng_features_permitted;
  174096. }
  174097. #endif
  174098. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174099. void PNGAPI
  174100. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174101. chunk_list, int num_chunks)
  174102. {
  174103. png_bytep new_list, p;
  174104. int i, old_num_chunks;
  174105. if (png_ptr == NULL)
  174106. return;
  174107. if (num_chunks == 0)
  174108. {
  174109. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174110. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174111. else
  174112. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174113. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174114. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174115. else
  174116. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174117. return;
  174118. }
  174119. if (chunk_list == NULL)
  174120. return;
  174121. old_num_chunks=png_ptr->num_chunk_list;
  174122. new_list=(png_bytep)png_malloc(png_ptr,
  174123. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174124. if(png_ptr->chunk_list != NULL)
  174125. {
  174126. png_memcpy(new_list, png_ptr->chunk_list,
  174127. (png_size_t)(5*old_num_chunks));
  174128. png_free(png_ptr, png_ptr->chunk_list);
  174129. png_ptr->chunk_list=NULL;
  174130. }
  174131. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174132. (png_size_t)(5*num_chunks));
  174133. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174134. *p=(png_byte)keep;
  174135. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174136. png_ptr->chunk_list=new_list;
  174137. #ifdef PNG_FREE_ME_SUPPORTED
  174138. png_ptr->free_me |= PNG_FREE_LIST;
  174139. #endif
  174140. }
  174141. #endif
  174142. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174143. void PNGAPI
  174144. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174145. png_user_chunk_ptr read_user_chunk_fn)
  174146. {
  174147. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174148. if (png_ptr == NULL)
  174149. return;
  174150. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174151. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174152. }
  174153. #endif
  174154. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174155. void PNGAPI
  174156. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174157. {
  174158. png_debug1(1, "in %s storage function\n", "rows");
  174159. if (png_ptr == NULL || info_ptr == NULL)
  174160. return;
  174161. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174162. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174163. info_ptr->row_pointers = row_pointers;
  174164. if(row_pointers)
  174165. info_ptr->valid |= PNG_INFO_IDAT;
  174166. }
  174167. #endif
  174168. #ifdef PNG_WRITE_SUPPORTED
  174169. void PNGAPI
  174170. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174171. {
  174172. if (png_ptr == NULL)
  174173. return;
  174174. if(png_ptr->zbuf)
  174175. png_free(png_ptr, png_ptr->zbuf);
  174176. png_ptr->zbuf_size = (png_size_t)size;
  174177. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174178. png_ptr->zstream.next_out = png_ptr->zbuf;
  174179. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174180. }
  174181. #endif
  174182. void PNGAPI
  174183. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174184. {
  174185. if (png_ptr && info_ptr)
  174186. info_ptr->valid &= ~(mask);
  174187. }
  174188. #ifndef PNG_1_0_X
  174189. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174190. void PNGAPI
  174191. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174192. {
  174193. if (png_ptr != NULL)
  174194. png_ptr->asm_flags = 0;
  174195. }
  174196. void PNGAPI
  174197. png_set_mmx_thresholds (png_structp png_ptr,
  174198. png_byte mmx_bitdepth_threshold,
  174199. png_uint_32 mmx_rowbytes_threshold)
  174200. {
  174201. if (png_ptr == NULL)
  174202. return;
  174203. }
  174204. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174205. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174206. void PNGAPI
  174207. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174208. png_uint_32 user_height_max)
  174209. {
  174210. if(png_ptr == NULL) return;
  174211. png_ptr->user_width_max = user_width_max;
  174212. png_ptr->user_height_max = user_height_max;
  174213. }
  174214. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174215. #endif /* ?PNG_1_0_X */
  174216. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174217. /*** End of inlined file: pngset.c ***/
  174218. /*** Start of inlined file: pngtrans.c ***/
  174219. #define PNG_INTERNAL
  174220. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174221. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174222. void PNGAPI
  174223. png_set_bgr(png_structp png_ptr)
  174224. {
  174225. png_debug(1, "in png_set_bgr\n");
  174226. if(png_ptr == NULL) return;
  174227. png_ptr->transformations |= PNG_BGR;
  174228. }
  174229. #endif
  174230. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174231. void PNGAPI
  174232. png_set_swap(png_structp png_ptr)
  174233. {
  174234. png_debug(1, "in png_set_swap\n");
  174235. if(png_ptr == NULL) return;
  174236. if (png_ptr->bit_depth == 16)
  174237. png_ptr->transformations |= PNG_SWAP_BYTES;
  174238. }
  174239. #endif
  174240. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174241. void PNGAPI
  174242. png_set_packing(png_structp png_ptr)
  174243. {
  174244. png_debug(1, "in png_set_packing\n");
  174245. if(png_ptr == NULL) return;
  174246. if (png_ptr->bit_depth < 8)
  174247. {
  174248. png_ptr->transformations |= PNG_PACK;
  174249. png_ptr->usr_bit_depth = 8;
  174250. }
  174251. }
  174252. #endif
  174253. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174254. void PNGAPI
  174255. png_set_packswap(png_structp png_ptr)
  174256. {
  174257. png_debug(1, "in png_set_packswap\n");
  174258. if(png_ptr == NULL) return;
  174259. if (png_ptr->bit_depth < 8)
  174260. png_ptr->transformations |= PNG_PACKSWAP;
  174261. }
  174262. #endif
  174263. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174264. void PNGAPI
  174265. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174266. {
  174267. png_debug(1, "in png_set_shift\n");
  174268. if(png_ptr == NULL) return;
  174269. png_ptr->transformations |= PNG_SHIFT;
  174270. png_ptr->shift = *true_bits;
  174271. }
  174272. #endif
  174273. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174274. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174275. int PNGAPI
  174276. png_set_interlace_handling(png_structp png_ptr)
  174277. {
  174278. png_debug(1, "in png_set_interlace handling\n");
  174279. if (png_ptr && png_ptr->interlaced)
  174280. {
  174281. png_ptr->transformations |= PNG_INTERLACE;
  174282. return (7);
  174283. }
  174284. return (1);
  174285. }
  174286. #endif
  174287. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174288. void PNGAPI
  174289. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174290. {
  174291. png_debug(1, "in png_set_filler\n");
  174292. if(png_ptr == NULL) return;
  174293. png_ptr->transformations |= PNG_FILLER;
  174294. png_ptr->filler = (png_byte)filler;
  174295. if (filler_loc == PNG_FILLER_AFTER)
  174296. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174297. else
  174298. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174299. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174300. {
  174301. png_ptr->usr_channels = 4;
  174302. }
  174303. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174304. {
  174305. png_ptr->usr_channels = 2;
  174306. }
  174307. }
  174308. #if !defined(PNG_1_0_X)
  174309. void PNGAPI
  174310. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174311. {
  174312. png_debug(1, "in png_set_add_alpha\n");
  174313. if(png_ptr == NULL) return;
  174314. png_set_filler(png_ptr, filler, filler_loc);
  174315. png_ptr->transformations |= PNG_ADD_ALPHA;
  174316. }
  174317. #endif
  174318. #endif
  174319. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174320. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174321. void PNGAPI
  174322. png_set_swap_alpha(png_structp png_ptr)
  174323. {
  174324. png_debug(1, "in png_set_swap_alpha\n");
  174325. if(png_ptr == NULL) return;
  174326. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174327. }
  174328. #endif
  174329. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174330. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174331. void PNGAPI
  174332. png_set_invert_alpha(png_structp png_ptr)
  174333. {
  174334. png_debug(1, "in png_set_invert_alpha\n");
  174335. if(png_ptr == NULL) return;
  174336. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174337. }
  174338. #endif
  174339. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174340. void PNGAPI
  174341. png_set_invert_mono(png_structp png_ptr)
  174342. {
  174343. png_debug(1, "in png_set_invert_mono\n");
  174344. if(png_ptr == NULL) return;
  174345. png_ptr->transformations |= PNG_INVERT_MONO;
  174346. }
  174347. void /* PRIVATE */
  174348. png_do_invert(png_row_infop row_info, png_bytep row)
  174349. {
  174350. png_debug(1, "in png_do_invert\n");
  174351. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174352. if (row == NULL || row_info == NULL)
  174353. return;
  174354. #endif
  174355. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174356. {
  174357. png_bytep rp = row;
  174358. png_uint_32 i;
  174359. png_uint_32 istop = row_info->rowbytes;
  174360. for (i = 0; i < istop; i++)
  174361. {
  174362. *rp = (png_byte)(~(*rp));
  174363. rp++;
  174364. }
  174365. }
  174366. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174367. row_info->bit_depth == 8)
  174368. {
  174369. png_bytep rp = row;
  174370. png_uint_32 i;
  174371. png_uint_32 istop = row_info->rowbytes;
  174372. for (i = 0; i < istop; i+=2)
  174373. {
  174374. *rp = (png_byte)(~(*rp));
  174375. rp+=2;
  174376. }
  174377. }
  174378. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174379. row_info->bit_depth == 16)
  174380. {
  174381. png_bytep rp = row;
  174382. png_uint_32 i;
  174383. png_uint_32 istop = row_info->rowbytes;
  174384. for (i = 0; i < istop; i+=4)
  174385. {
  174386. *rp = (png_byte)(~(*rp));
  174387. *(rp+1) = (png_byte)(~(*(rp+1)));
  174388. rp+=4;
  174389. }
  174390. }
  174391. }
  174392. #endif
  174393. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174394. void /* PRIVATE */
  174395. png_do_swap(png_row_infop row_info, png_bytep row)
  174396. {
  174397. png_debug(1, "in png_do_swap\n");
  174398. if (
  174399. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174400. row != NULL && row_info != NULL &&
  174401. #endif
  174402. row_info->bit_depth == 16)
  174403. {
  174404. png_bytep rp = row;
  174405. png_uint_32 i;
  174406. png_uint_32 istop= row_info->width * row_info->channels;
  174407. for (i = 0; i < istop; i++, rp += 2)
  174408. {
  174409. png_byte t = *rp;
  174410. *rp = *(rp + 1);
  174411. *(rp + 1) = t;
  174412. }
  174413. }
  174414. }
  174415. #endif
  174416. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174417. static PNG_CONST png_byte onebppswaptable[256] = {
  174418. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174419. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174420. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174421. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174422. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174423. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174424. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174425. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174426. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174427. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174428. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174429. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174430. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174431. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174432. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174433. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174434. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174435. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174436. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174437. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174438. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174439. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174440. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174441. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174442. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174443. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174444. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174445. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174446. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174447. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174448. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174449. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174450. };
  174451. static PNG_CONST png_byte twobppswaptable[256] = {
  174452. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174453. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174454. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174455. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174456. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174457. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174458. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174459. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174460. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174461. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174462. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174463. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174464. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174465. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174466. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174467. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174468. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174469. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174470. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174471. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174472. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174473. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174474. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174475. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174476. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174477. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174478. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174479. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174480. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174481. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174482. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174483. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174484. };
  174485. static PNG_CONST png_byte fourbppswaptable[256] = {
  174486. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174487. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174488. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174489. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174490. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174491. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174492. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174493. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174494. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174495. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174496. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174497. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174498. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174499. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174500. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174501. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174502. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174503. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174504. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174505. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174506. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174507. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174508. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174509. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174510. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174511. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174512. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174513. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174514. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174515. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174516. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174517. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174518. };
  174519. void /* PRIVATE */
  174520. png_do_packswap(png_row_infop row_info, png_bytep row)
  174521. {
  174522. png_debug(1, "in png_do_packswap\n");
  174523. if (
  174524. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174525. row != NULL && row_info != NULL &&
  174526. #endif
  174527. row_info->bit_depth < 8)
  174528. {
  174529. png_bytep rp, end, table;
  174530. end = row + row_info->rowbytes;
  174531. if (row_info->bit_depth == 1)
  174532. table = (png_bytep)onebppswaptable;
  174533. else if (row_info->bit_depth == 2)
  174534. table = (png_bytep)twobppswaptable;
  174535. else if (row_info->bit_depth == 4)
  174536. table = (png_bytep)fourbppswaptable;
  174537. else
  174538. return;
  174539. for (rp = row; rp < end; rp++)
  174540. *rp = table[*rp];
  174541. }
  174542. }
  174543. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174544. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174545. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174546. void /* PRIVATE */
  174547. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174548. {
  174549. png_debug(1, "in png_do_strip_filler\n");
  174550. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174551. if (row != NULL && row_info != NULL)
  174552. #endif
  174553. {
  174554. png_bytep sp=row;
  174555. png_bytep dp=row;
  174556. png_uint_32 row_width=row_info->width;
  174557. png_uint_32 i;
  174558. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174559. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174560. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174561. row_info->channels == 4)
  174562. {
  174563. if (row_info->bit_depth == 8)
  174564. {
  174565. if (flags & PNG_FLAG_FILLER_AFTER)
  174566. {
  174567. dp+=3; sp+=4;
  174568. for (i = 1; i < row_width; i++)
  174569. {
  174570. *dp++ = *sp++;
  174571. *dp++ = *sp++;
  174572. *dp++ = *sp++;
  174573. sp++;
  174574. }
  174575. }
  174576. else
  174577. {
  174578. for (i = 0; i < row_width; i++)
  174579. {
  174580. sp++;
  174581. *dp++ = *sp++;
  174582. *dp++ = *sp++;
  174583. *dp++ = *sp++;
  174584. }
  174585. }
  174586. row_info->pixel_depth = 24;
  174587. row_info->rowbytes = row_width * 3;
  174588. }
  174589. else /* if (row_info->bit_depth == 16) */
  174590. {
  174591. if (flags & PNG_FLAG_FILLER_AFTER)
  174592. {
  174593. sp += 8; dp += 6;
  174594. for (i = 1; i < row_width; i++)
  174595. {
  174596. *dp++ = *sp++;
  174597. *dp++ = *sp++;
  174598. *dp++ = *sp++;
  174599. *dp++ = *sp++;
  174600. *dp++ = *sp++;
  174601. *dp++ = *sp++;
  174602. sp += 2;
  174603. }
  174604. }
  174605. else
  174606. {
  174607. for (i = 0; i < row_width; i++)
  174608. {
  174609. sp+=2;
  174610. *dp++ = *sp++;
  174611. *dp++ = *sp++;
  174612. *dp++ = *sp++;
  174613. *dp++ = *sp++;
  174614. *dp++ = *sp++;
  174615. *dp++ = *sp++;
  174616. }
  174617. }
  174618. row_info->pixel_depth = 48;
  174619. row_info->rowbytes = row_width * 6;
  174620. }
  174621. row_info->channels = 3;
  174622. }
  174623. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174624. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174625. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174626. row_info->channels == 2)
  174627. {
  174628. if (row_info->bit_depth == 8)
  174629. {
  174630. if (flags & PNG_FLAG_FILLER_AFTER)
  174631. {
  174632. for (i = 0; i < row_width; i++)
  174633. {
  174634. *dp++ = *sp++;
  174635. sp++;
  174636. }
  174637. }
  174638. else
  174639. {
  174640. for (i = 0; i < row_width; i++)
  174641. {
  174642. sp++;
  174643. *dp++ = *sp++;
  174644. }
  174645. }
  174646. row_info->pixel_depth = 8;
  174647. row_info->rowbytes = row_width;
  174648. }
  174649. else /* if (row_info->bit_depth == 16) */
  174650. {
  174651. if (flags & PNG_FLAG_FILLER_AFTER)
  174652. {
  174653. sp += 4; dp += 2;
  174654. for (i = 1; i < row_width; i++)
  174655. {
  174656. *dp++ = *sp++;
  174657. *dp++ = *sp++;
  174658. sp += 2;
  174659. }
  174660. }
  174661. else
  174662. {
  174663. for (i = 0; i < row_width; i++)
  174664. {
  174665. sp += 2;
  174666. *dp++ = *sp++;
  174667. *dp++ = *sp++;
  174668. }
  174669. }
  174670. row_info->pixel_depth = 16;
  174671. row_info->rowbytes = row_width * 2;
  174672. }
  174673. row_info->channels = 1;
  174674. }
  174675. if (flags & PNG_FLAG_STRIP_ALPHA)
  174676. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174677. }
  174678. }
  174679. #endif
  174680. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174681. void /* PRIVATE */
  174682. png_do_bgr(png_row_infop row_info, png_bytep row)
  174683. {
  174684. png_debug(1, "in png_do_bgr\n");
  174685. if (
  174686. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174687. row != NULL && row_info != NULL &&
  174688. #endif
  174689. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174690. {
  174691. png_uint_32 row_width = row_info->width;
  174692. if (row_info->bit_depth == 8)
  174693. {
  174694. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174695. {
  174696. png_bytep rp;
  174697. png_uint_32 i;
  174698. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174699. {
  174700. png_byte save = *rp;
  174701. *rp = *(rp + 2);
  174702. *(rp + 2) = save;
  174703. }
  174704. }
  174705. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174706. {
  174707. png_bytep rp;
  174708. png_uint_32 i;
  174709. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174710. {
  174711. png_byte save = *rp;
  174712. *rp = *(rp + 2);
  174713. *(rp + 2) = save;
  174714. }
  174715. }
  174716. }
  174717. else if (row_info->bit_depth == 16)
  174718. {
  174719. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174720. {
  174721. png_bytep rp;
  174722. png_uint_32 i;
  174723. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174724. {
  174725. png_byte save = *rp;
  174726. *rp = *(rp + 4);
  174727. *(rp + 4) = save;
  174728. save = *(rp + 1);
  174729. *(rp + 1) = *(rp + 5);
  174730. *(rp + 5) = save;
  174731. }
  174732. }
  174733. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174734. {
  174735. png_bytep rp;
  174736. png_uint_32 i;
  174737. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174738. {
  174739. png_byte save = *rp;
  174740. *rp = *(rp + 4);
  174741. *(rp + 4) = save;
  174742. save = *(rp + 1);
  174743. *(rp + 1) = *(rp + 5);
  174744. *(rp + 5) = save;
  174745. }
  174746. }
  174747. }
  174748. }
  174749. }
  174750. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174751. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174752. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174753. defined(PNG_LEGACY_SUPPORTED)
  174754. void PNGAPI
  174755. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174756. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174757. {
  174758. png_debug(1, "in png_set_user_transform_info\n");
  174759. if(png_ptr == NULL) return;
  174760. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174761. png_ptr->user_transform_ptr = user_transform_ptr;
  174762. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174763. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174764. #else
  174765. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174766. png_warning(png_ptr,
  174767. "This version of libpng does not support user transform info");
  174768. #endif
  174769. }
  174770. #endif
  174771. png_voidp PNGAPI
  174772. png_get_user_transform_ptr(png_structp png_ptr)
  174773. {
  174774. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174775. if (png_ptr == NULL) return (NULL);
  174776. return ((png_voidp)png_ptr->user_transform_ptr);
  174777. #else
  174778. return (NULL);
  174779. #endif
  174780. }
  174781. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174782. /*** End of inlined file: pngtrans.c ***/
  174783. /*** Start of inlined file: pngwio.c ***/
  174784. #define PNG_INTERNAL
  174785. #ifdef PNG_WRITE_SUPPORTED
  174786. void /* PRIVATE */
  174787. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174788. {
  174789. if (png_ptr->write_data_fn != NULL )
  174790. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174791. else
  174792. png_error(png_ptr, "Call to NULL write function");
  174793. }
  174794. #if !defined(PNG_NO_STDIO)
  174795. #ifndef USE_FAR_KEYWORD
  174796. void PNGAPI
  174797. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174798. {
  174799. png_uint_32 check;
  174800. if(png_ptr == NULL) return;
  174801. #if defined(_WIN32_WCE)
  174802. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174803. check = 0;
  174804. #else
  174805. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174806. #endif
  174807. if (check != length)
  174808. png_error(png_ptr, "Write Error");
  174809. }
  174810. #else
  174811. #define NEAR_BUF_SIZE 1024
  174812. #define MIN(a,b) (a <= b ? a : b)
  174813. void PNGAPI
  174814. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174815. {
  174816. png_uint_32 check;
  174817. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  174818. png_FILE_p io_ptr;
  174819. if(png_ptr == NULL) return;
  174820. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  174821. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  174822. if ((png_bytep)near_data == data)
  174823. {
  174824. #if defined(_WIN32_WCE)
  174825. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  174826. check = 0;
  174827. #else
  174828. check = fwrite(near_data, 1, length, io_ptr);
  174829. #endif
  174830. }
  174831. else
  174832. {
  174833. png_byte buf[NEAR_BUF_SIZE];
  174834. png_size_t written, remaining, err;
  174835. check = 0;
  174836. remaining = length;
  174837. do
  174838. {
  174839. written = MIN(NEAR_BUF_SIZE, remaining);
  174840. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  174841. #if defined(_WIN32_WCE)
  174842. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  174843. err = 0;
  174844. #else
  174845. err = fwrite(buf, 1, written, io_ptr);
  174846. #endif
  174847. if (err != written)
  174848. break;
  174849. else
  174850. check += err;
  174851. data += written;
  174852. remaining -= written;
  174853. }
  174854. while (remaining != 0);
  174855. }
  174856. if (check != length)
  174857. png_error(png_ptr, "Write Error");
  174858. }
  174859. #endif
  174860. #endif
  174861. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174862. void /* PRIVATE */
  174863. png_flush(png_structp png_ptr)
  174864. {
  174865. if (png_ptr->output_flush_fn != NULL)
  174866. (*(png_ptr->output_flush_fn))(png_ptr);
  174867. }
  174868. #if !defined(PNG_NO_STDIO)
  174869. void PNGAPI
  174870. png_default_flush(png_structp png_ptr)
  174871. {
  174872. #if !defined(_WIN32_WCE)
  174873. png_FILE_p io_ptr;
  174874. #endif
  174875. if(png_ptr == NULL) return;
  174876. #if !defined(_WIN32_WCE)
  174877. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  174878. if (io_ptr != NULL)
  174879. fflush(io_ptr);
  174880. #endif
  174881. }
  174882. #endif
  174883. #endif
  174884. void PNGAPI
  174885. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  174886. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  174887. {
  174888. if(png_ptr == NULL) return;
  174889. png_ptr->io_ptr = io_ptr;
  174890. #if !defined(PNG_NO_STDIO)
  174891. if (write_data_fn != NULL)
  174892. png_ptr->write_data_fn = write_data_fn;
  174893. else
  174894. png_ptr->write_data_fn = png_default_write_data;
  174895. #else
  174896. png_ptr->write_data_fn = write_data_fn;
  174897. #endif
  174898. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174899. #if !defined(PNG_NO_STDIO)
  174900. if (output_flush_fn != NULL)
  174901. png_ptr->output_flush_fn = output_flush_fn;
  174902. else
  174903. png_ptr->output_flush_fn = png_default_flush;
  174904. #else
  174905. png_ptr->output_flush_fn = output_flush_fn;
  174906. #endif
  174907. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  174908. if (png_ptr->read_data_fn != NULL)
  174909. {
  174910. png_ptr->read_data_fn = NULL;
  174911. png_warning(png_ptr,
  174912. "Attempted to set both read_data_fn and write_data_fn in");
  174913. png_warning(png_ptr,
  174914. "the same structure. Resetting read_data_fn to NULL.");
  174915. }
  174916. }
  174917. #if defined(USE_FAR_KEYWORD)
  174918. #if defined(_MSC_VER)
  174919. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  174920. {
  174921. void *near_ptr;
  174922. void FAR *far_ptr;
  174923. FP_OFF(near_ptr) = FP_OFF(ptr);
  174924. far_ptr = (void FAR *)near_ptr;
  174925. if(check != 0)
  174926. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  174927. png_error(png_ptr,"segment lost in conversion");
  174928. return(near_ptr);
  174929. }
  174930. # else
  174931. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  174932. {
  174933. void *near_ptr;
  174934. void FAR *far_ptr;
  174935. near_ptr = (void FAR *)ptr;
  174936. far_ptr = (void FAR *)near_ptr;
  174937. if(check != 0)
  174938. if(far_ptr != ptr)
  174939. png_error(png_ptr,"segment lost in conversion");
  174940. return(near_ptr);
  174941. }
  174942. # endif
  174943. # endif
  174944. #endif /* PNG_WRITE_SUPPORTED */
  174945. /*** End of inlined file: pngwio.c ***/
  174946. /*** Start of inlined file: pngwrite.c ***/
  174947. #define PNG_INTERNAL
  174948. #ifdef PNG_WRITE_SUPPORTED
  174949. void PNGAPI
  174950. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  174951. {
  174952. png_debug(1, "in png_write_info_before_PLTE\n");
  174953. if (png_ptr == NULL || info_ptr == NULL)
  174954. return;
  174955. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  174956. {
  174957. png_write_sig(png_ptr); /* write PNG signature */
  174958. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174959. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  174960. {
  174961. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174962. png_ptr->mng_features_permitted=0;
  174963. }
  174964. #endif
  174965. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  174966. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  174967. info_ptr->filter_type,
  174968. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174969. info_ptr->interlace_type);
  174970. #else
  174971. 0);
  174972. #endif
  174973. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  174974. if (info_ptr->valid & PNG_INFO_gAMA)
  174975. {
  174976. # ifdef PNG_FLOATING_POINT_SUPPORTED
  174977. png_write_gAMA(png_ptr, info_ptr->gamma);
  174978. #else
  174979. #ifdef PNG_FIXED_POINT_SUPPORTED
  174980. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  174981. # endif
  174982. #endif
  174983. }
  174984. #endif
  174985. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  174986. if (info_ptr->valid & PNG_INFO_sRGB)
  174987. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  174988. #endif
  174989. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  174990. if (info_ptr->valid & PNG_INFO_iCCP)
  174991. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  174992. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  174993. #endif
  174994. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  174995. if (info_ptr->valid & PNG_INFO_sBIT)
  174996. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  174997. #endif
  174998. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  174999. if (info_ptr->valid & PNG_INFO_cHRM)
  175000. {
  175001. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175002. png_write_cHRM(png_ptr,
  175003. info_ptr->x_white, info_ptr->y_white,
  175004. info_ptr->x_red, info_ptr->y_red,
  175005. info_ptr->x_green, info_ptr->y_green,
  175006. info_ptr->x_blue, info_ptr->y_blue);
  175007. #else
  175008. # ifdef PNG_FIXED_POINT_SUPPORTED
  175009. png_write_cHRM_fixed(png_ptr,
  175010. info_ptr->int_x_white, info_ptr->int_y_white,
  175011. info_ptr->int_x_red, info_ptr->int_y_red,
  175012. info_ptr->int_x_green, info_ptr->int_y_green,
  175013. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175014. # endif
  175015. #endif
  175016. }
  175017. #endif
  175018. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175019. if (info_ptr->unknown_chunks_num)
  175020. {
  175021. png_unknown_chunk *up;
  175022. png_debug(5, "writing extra chunks\n");
  175023. for (up = info_ptr->unknown_chunks;
  175024. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175025. up++)
  175026. {
  175027. int keep=png_handle_as_unknown(png_ptr, up->name);
  175028. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175029. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175030. !(up->location & PNG_HAVE_IDAT) &&
  175031. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175032. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175033. {
  175034. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175035. }
  175036. }
  175037. }
  175038. #endif
  175039. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175040. }
  175041. }
  175042. void PNGAPI
  175043. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175044. {
  175045. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175046. int i;
  175047. #endif
  175048. png_debug(1, "in png_write_info\n");
  175049. if (png_ptr == NULL || info_ptr == NULL)
  175050. return;
  175051. png_write_info_before_PLTE(png_ptr, info_ptr);
  175052. if (info_ptr->valid & PNG_INFO_PLTE)
  175053. png_write_PLTE(png_ptr, info_ptr->palette,
  175054. (png_uint_32)info_ptr->num_palette);
  175055. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175056. png_error(png_ptr, "Valid palette required for paletted images");
  175057. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175058. if (info_ptr->valid & PNG_INFO_tRNS)
  175059. {
  175060. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175061. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175062. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175063. {
  175064. int j;
  175065. for (j=0; j<(int)info_ptr->num_trans; j++)
  175066. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175067. }
  175068. #endif
  175069. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175070. info_ptr->num_trans, info_ptr->color_type);
  175071. }
  175072. #endif
  175073. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175074. if (info_ptr->valid & PNG_INFO_bKGD)
  175075. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175076. #endif
  175077. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175078. if (info_ptr->valid & PNG_INFO_hIST)
  175079. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175080. #endif
  175081. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175082. if (info_ptr->valid & PNG_INFO_oFFs)
  175083. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175084. info_ptr->offset_unit_type);
  175085. #endif
  175086. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175087. if (info_ptr->valid & PNG_INFO_pCAL)
  175088. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175089. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175090. info_ptr->pcal_units, info_ptr->pcal_params);
  175091. #endif
  175092. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175093. if (info_ptr->valid & PNG_INFO_sCAL)
  175094. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175095. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175096. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175097. #else
  175098. #ifdef PNG_FIXED_POINT_SUPPORTED
  175099. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175100. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175101. #else
  175102. png_warning(png_ptr,
  175103. "png_write_sCAL not supported; sCAL chunk not written.");
  175104. #endif
  175105. #endif
  175106. #endif
  175107. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175108. if (info_ptr->valid & PNG_INFO_pHYs)
  175109. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175110. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175111. #endif
  175112. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175113. if (info_ptr->valid & PNG_INFO_tIME)
  175114. {
  175115. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175116. png_ptr->mode |= PNG_WROTE_tIME;
  175117. }
  175118. #endif
  175119. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175120. if (info_ptr->valid & PNG_INFO_sPLT)
  175121. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175122. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175123. #endif
  175124. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175125. for (i = 0; i < info_ptr->num_text; i++)
  175126. {
  175127. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175128. info_ptr->text[i].compression);
  175129. if (info_ptr->text[i].compression > 0)
  175130. {
  175131. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175132. png_write_iTXt(png_ptr,
  175133. info_ptr->text[i].compression,
  175134. info_ptr->text[i].key,
  175135. info_ptr->text[i].lang,
  175136. info_ptr->text[i].lang_key,
  175137. info_ptr->text[i].text);
  175138. #else
  175139. png_warning(png_ptr, "Unable to write international text");
  175140. #endif
  175141. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175142. }
  175143. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175144. {
  175145. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175146. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175147. info_ptr->text[i].text, 0,
  175148. info_ptr->text[i].compression);
  175149. #else
  175150. png_warning(png_ptr, "Unable to write compressed text");
  175151. #endif
  175152. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175153. }
  175154. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175155. {
  175156. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175157. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175158. info_ptr->text[i].text,
  175159. 0);
  175160. #else
  175161. png_warning(png_ptr, "Unable to write uncompressed text");
  175162. #endif
  175163. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175164. }
  175165. }
  175166. #endif
  175167. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175168. if (info_ptr->unknown_chunks_num)
  175169. {
  175170. png_unknown_chunk *up;
  175171. png_debug(5, "writing extra chunks\n");
  175172. for (up = info_ptr->unknown_chunks;
  175173. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175174. up++)
  175175. {
  175176. int keep=png_handle_as_unknown(png_ptr, up->name);
  175177. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175178. up->location && (up->location & PNG_HAVE_PLTE) &&
  175179. !(up->location & PNG_HAVE_IDAT) &&
  175180. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175181. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175182. {
  175183. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175184. }
  175185. }
  175186. }
  175187. #endif
  175188. }
  175189. void PNGAPI
  175190. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175191. {
  175192. png_debug(1, "in png_write_end\n");
  175193. if (png_ptr == NULL)
  175194. return;
  175195. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175196. png_error(png_ptr, "No IDATs written into file");
  175197. if (info_ptr != NULL)
  175198. {
  175199. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175200. int i; /* local index variable */
  175201. #endif
  175202. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175203. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175204. !(png_ptr->mode & PNG_WROTE_tIME))
  175205. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175206. #endif
  175207. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175208. for (i = 0; i < info_ptr->num_text; i++)
  175209. {
  175210. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175211. info_ptr->text[i].compression);
  175212. if (info_ptr->text[i].compression > 0)
  175213. {
  175214. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175215. png_write_iTXt(png_ptr,
  175216. info_ptr->text[i].compression,
  175217. info_ptr->text[i].key,
  175218. info_ptr->text[i].lang,
  175219. info_ptr->text[i].lang_key,
  175220. info_ptr->text[i].text);
  175221. #else
  175222. png_warning(png_ptr, "Unable to write international text");
  175223. #endif
  175224. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175225. }
  175226. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175227. {
  175228. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175229. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175230. info_ptr->text[i].text, 0,
  175231. info_ptr->text[i].compression);
  175232. #else
  175233. png_warning(png_ptr, "Unable to write compressed text");
  175234. #endif
  175235. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175236. }
  175237. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175238. {
  175239. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175240. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175241. info_ptr->text[i].text, 0);
  175242. #else
  175243. png_warning(png_ptr, "Unable to write uncompressed text");
  175244. #endif
  175245. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175246. }
  175247. }
  175248. #endif
  175249. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175250. if (info_ptr->unknown_chunks_num)
  175251. {
  175252. png_unknown_chunk *up;
  175253. png_debug(5, "writing extra chunks\n");
  175254. for (up = info_ptr->unknown_chunks;
  175255. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175256. up++)
  175257. {
  175258. int keep=png_handle_as_unknown(png_ptr, up->name);
  175259. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175260. up->location && (up->location & PNG_AFTER_IDAT) &&
  175261. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175262. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175263. {
  175264. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175265. }
  175266. }
  175267. }
  175268. #endif
  175269. }
  175270. png_ptr->mode |= PNG_AFTER_IDAT;
  175271. png_write_IEND(png_ptr);
  175272. }
  175273. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175274. #if !defined(_WIN32_WCE)
  175275. void PNGAPI
  175276. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175277. {
  175278. png_debug(1, "in png_convert_from_struct_tm\n");
  175279. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175280. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175281. ptime->day = (png_byte)ttime->tm_mday;
  175282. ptime->hour = (png_byte)ttime->tm_hour;
  175283. ptime->minute = (png_byte)ttime->tm_min;
  175284. ptime->second = (png_byte)ttime->tm_sec;
  175285. }
  175286. void PNGAPI
  175287. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175288. {
  175289. struct tm *tbuf;
  175290. png_debug(1, "in png_convert_from_time_t\n");
  175291. tbuf = gmtime(&ttime);
  175292. png_convert_from_struct_tm(ptime, tbuf);
  175293. }
  175294. #endif
  175295. #endif
  175296. png_structp PNGAPI
  175297. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175298. png_error_ptr error_fn, png_error_ptr warn_fn)
  175299. {
  175300. #ifdef PNG_USER_MEM_SUPPORTED
  175301. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175302. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175303. }
  175304. png_structp PNGAPI
  175305. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175306. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175307. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175308. {
  175309. #endif /* PNG_USER_MEM_SUPPORTED */
  175310. png_structp png_ptr;
  175311. #ifdef PNG_SETJMP_SUPPORTED
  175312. #ifdef USE_FAR_KEYWORD
  175313. jmp_buf jmpbuf;
  175314. #endif
  175315. #endif
  175316. int i;
  175317. png_debug(1, "in png_create_write_struct\n");
  175318. #ifdef PNG_USER_MEM_SUPPORTED
  175319. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175320. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175321. #else
  175322. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175323. #endif /* PNG_USER_MEM_SUPPORTED */
  175324. if (png_ptr == NULL)
  175325. return (NULL);
  175326. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175327. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175328. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175329. #endif
  175330. #ifdef PNG_SETJMP_SUPPORTED
  175331. #ifdef USE_FAR_KEYWORD
  175332. if (setjmp(jmpbuf))
  175333. #else
  175334. if (setjmp(png_ptr->jmpbuf))
  175335. #endif
  175336. {
  175337. png_free(png_ptr, png_ptr->zbuf);
  175338. png_ptr->zbuf=NULL;
  175339. png_destroy_struct(png_ptr);
  175340. return (NULL);
  175341. }
  175342. #ifdef USE_FAR_KEYWORD
  175343. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175344. #endif
  175345. #endif
  175346. #ifdef PNG_USER_MEM_SUPPORTED
  175347. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175348. #endif /* PNG_USER_MEM_SUPPORTED */
  175349. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175350. i=0;
  175351. do
  175352. {
  175353. if(user_png_ver[i] != png_libpng_ver[i])
  175354. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175355. } while (png_libpng_ver[i++]);
  175356. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175357. {
  175358. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175359. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175360. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175361. {
  175362. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175363. char msg[80];
  175364. if (user_png_ver)
  175365. {
  175366. png_snprintf(msg, 80,
  175367. "Application was compiled with png.h from libpng-%.20s",
  175368. user_png_ver);
  175369. png_warning(png_ptr, msg);
  175370. }
  175371. png_snprintf(msg, 80,
  175372. "Application is running with png.c from libpng-%.20s",
  175373. png_libpng_ver);
  175374. png_warning(png_ptr, msg);
  175375. #endif
  175376. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175377. png_ptr->flags=0;
  175378. #endif
  175379. png_error(png_ptr,
  175380. "Incompatible libpng version in application and library");
  175381. }
  175382. }
  175383. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175384. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175385. (png_uint_32)png_ptr->zbuf_size);
  175386. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175387. png_flush_ptr_NULL);
  175388. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175389. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175390. 1, png_doublep_NULL, png_doublep_NULL);
  175391. #endif
  175392. #ifdef PNG_SETJMP_SUPPORTED
  175393. #ifdef USE_FAR_KEYWORD
  175394. if (setjmp(jmpbuf))
  175395. PNG_ABORT();
  175396. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175397. #else
  175398. if (setjmp(png_ptr->jmpbuf))
  175399. PNG_ABORT();
  175400. #endif
  175401. #endif
  175402. return (png_ptr);
  175403. }
  175404. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175405. #undef png_write_init
  175406. void PNGAPI
  175407. png_write_init(png_structp png_ptr)
  175408. {
  175409. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175410. }
  175411. void PNGAPI
  175412. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175413. png_size_t png_struct_size, png_size_t png_info_size)
  175414. {
  175415. if(png_ptr == NULL) return;
  175416. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175417. if(png_sizeof(png_struct) > png_struct_size ||
  175418. png_sizeof(png_info) > png_info_size)
  175419. {
  175420. char msg[80];
  175421. png_ptr->warning_fn=NULL;
  175422. if (user_png_ver)
  175423. {
  175424. png_snprintf(msg, 80,
  175425. "Application was compiled with png.h from libpng-%.20s",
  175426. user_png_ver);
  175427. png_warning(png_ptr, msg);
  175428. }
  175429. png_snprintf(msg, 80,
  175430. "Application is running with png.c from libpng-%.20s",
  175431. png_libpng_ver);
  175432. png_warning(png_ptr, msg);
  175433. }
  175434. #endif
  175435. if(png_sizeof(png_struct) > png_struct_size)
  175436. {
  175437. png_ptr->error_fn=NULL;
  175438. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175439. png_ptr->flags=0;
  175440. #endif
  175441. png_error(png_ptr,
  175442. "The png struct allocated by the application for writing is too small.");
  175443. }
  175444. if(png_sizeof(png_info) > png_info_size)
  175445. {
  175446. png_ptr->error_fn=NULL;
  175447. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175448. png_ptr->flags=0;
  175449. #endif
  175450. png_error(png_ptr,
  175451. "The info struct allocated by the application for writing is too small.");
  175452. }
  175453. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175454. }
  175455. #endif /* PNG_1_0_X || PNG_1_2_X */
  175456. void PNGAPI
  175457. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175458. png_size_t png_struct_size)
  175459. {
  175460. png_structp png_ptr=*ptr_ptr;
  175461. #ifdef PNG_SETJMP_SUPPORTED
  175462. jmp_buf tmp_jmp; /* to save current jump buffer */
  175463. #endif
  175464. int i = 0;
  175465. if (png_ptr == NULL)
  175466. return;
  175467. do
  175468. {
  175469. if (user_png_ver[i] != png_libpng_ver[i])
  175470. {
  175471. #ifdef PNG_LEGACY_SUPPORTED
  175472. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175473. #else
  175474. png_ptr->warning_fn=NULL;
  175475. png_warning(png_ptr,
  175476. "Application uses deprecated png_write_init() and should be recompiled.");
  175477. break;
  175478. #endif
  175479. }
  175480. } while (png_libpng_ver[i++]);
  175481. png_debug(1, "in png_write_init_3\n");
  175482. #ifdef PNG_SETJMP_SUPPORTED
  175483. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175484. #endif
  175485. if (png_sizeof(png_struct) > png_struct_size)
  175486. {
  175487. png_destroy_struct(png_ptr);
  175488. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175489. *ptr_ptr = png_ptr;
  175490. }
  175491. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175492. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175493. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175494. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175495. #endif
  175496. #ifdef PNG_SETJMP_SUPPORTED
  175497. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175498. #endif
  175499. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175500. png_flush_ptr_NULL);
  175501. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175502. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175503. (png_uint_32)png_ptr->zbuf_size);
  175504. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175505. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175506. 1, png_doublep_NULL, png_doublep_NULL);
  175507. #endif
  175508. }
  175509. void PNGAPI
  175510. png_write_rows(png_structp png_ptr, png_bytepp row,
  175511. png_uint_32 num_rows)
  175512. {
  175513. png_uint_32 i; /* row counter */
  175514. png_bytepp rp; /* row pointer */
  175515. png_debug(1, "in png_write_rows\n");
  175516. if (png_ptr == NULL)
  175517. return;
  175518. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175519. {
  175520. png_write_row(png_ptr, *rp);
  175521. }
  175522. }
  175523. void PNGAPI
  175524. png_write_image(png_structp png_ptr, png_bytepp image)
  175525. {
  175526. png_uint_32 i; /* row index */
  175527. int pass, num_pass; /* pass variables */
  175528. png_bytepp rp; /* points to current row */
  175529. if (png_ptr == NULL)
  175530. return;
  175531. png_debug(1, "in png_write_image\n");
  175532. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175533. num_pass = png_set_interlace_handling(png_ptr);
  175534. #else
  175535. num_pass = 1;
  175536. #endif
  175537. for (pass = 0; pass < num_pass; pass++)
  175538. {
  175539. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175540. {
  175541. png_write_row(png_ptr, *rp);
  175542. }
  175543. }
  175544. }
  175545. void PNGAPI
  175546. png_write_row(png_structp png_ptr, png_bytep row)
  175547. {
  175548. if (png_ptr == NULL)
  175549. return;
  175550. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175551. png_ptr->row_number, png_ptr->pass);
  175552. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175553. {
  175554. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175555. png_error(png_ptr,
  175556. "png_write_info was never called before png_write_row.");
  175557. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175558. if (png_ptr->transformations & PNG_INVERT_MONO)
  175559. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175560. #endif
  175561. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175562. if (png_ptr->transformations & PNG_FILLER)
  175563. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175564. #endif
  175565. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175566. if (png_ptr->transformations & PNG_PACKSWAP)
  175567. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175568. #endif
  175569. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175570. if (png_ptr->transformations & PNG_PACK)
  175571. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175572. #endif
  175573. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175574. if (png_ptr->transformations & PNG_SHIFT)
  175575. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175576. #endif
  175577. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175578. if (png_ptr->transformations & PNG_BGR)
  175579. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175580. #endif
  175581. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175582. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175583. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175584. #endif
  175585. png_write_start_row(png_ptr);
  175586. }
  175587. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175588. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175589. {
  175590. switch (png_ptr->pass)
  175591. {
  175592. case 0:
  175593. if (png_ptr->row_number & 0x07)
  175594. {
  175595. png_write_finish_row(png_ptr);
  175596. return;
  175597. }
  175598. break;
  175599. case 1:
  175600. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175601. {
  175602. png_write_finish_row(png_ptr);
  175603. return;
  175604. }
  175605. break;
  175606. case 2:
  175607. if ((png_ptr->row_number & 0x07) != 4)
  175608. {
  175609. png_write_finish_row(png_ptr);
  175610. return;
  175611. }
  175612. break;
  175613. case 3:
  175614. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175615. {
  175616. png_write_finish_row(png_ptr);
  175617. return;
  175618. }
  175619. break;
  175620. case 4:
  175621. if ((png_ptr->row_number & 0x03) != 2)
  175622. {
  175623. png_write_finish_row(png_ptr);
  175624. return;
  175625. }
  175626. break;
  175627. case 5:
  175628. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175629. {
  175630. png_write_finish_row(png_ptr);
  175631. return;
  175632. }
  175633. break;
  175634. case 6:
  175635. if (!(png_ptr->row_number & 0x01))
  175636. {
  175637. png_write_finish_row(png_ptr);
  175638. return;
  175639. }
  175640. break;
  175641. }
  175642. }
  175643. #endif
  175644. png_ptr->row_info.color_type = png_ptr->color_type;
  175645. png_ptr->row_info.width = png_ptr->usr_width;
  175646. png_ptr->row_info.channels = png_ptr->usr_channels;
  175647. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175648. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175649. png_ptr->row_info.channels);
  175650. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175651. png_ptr->row_info.width);
  175652. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175653. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175654. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175655. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175656. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175657. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175658. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175659. png_ptr->row_info.rowbytes);
  175660. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175661. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175662. (png_ptr->transformations & PNG_INTERLACE))
  175663. {
  175664. png_do_write_interlace(&(png_ptr->row_info),
  175665. png_ptr->row_buf + 1, png_ptr->pass);
  175666. if (!(png_ptr->row_info.width))
  175667. {
  175668. png_write_finish_row(png_ptr);
  175669. return;
  175670. }
  175671. }
  175672. #endif
  175673. if (png_ptr->transformations)
  175674. png_do_write_transformations(png_ptr);
  175675. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175676. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175677. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175678. {
  175679. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175680. }
  175681. #endif
  175682. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175683. if (png_ptr->write_row_fn != NULL)
  175684. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175685. }
  175686. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175687. void PNGAPI
  175688. png_set_flush(png_structp png_ptr, int nrows)
  175689. {
  175690. png_debug(1, "in png_set_flush\n");
  175691. if (png_ptr == NULL)
  175692. return;
  175693. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175694. }
  175695. void PNGAPI
  175696. png_write_flush(png_structp png_ptr)
  175697. {
  175698. int wrote_IDAT;
  175699. png_debug(1, "in png_write_flush\n");
  175700. if (png_ptr == NULL)
  175701. return;
  175702. if (png_ptr->row_number >= png_ptr->num_rows)
  175703. return;
  175704. do
  175705. {
  175706. int ret;
  175707. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175708. wrote_IDAT = 0;
  175709. if (ret != Z_OK)
  175710. {
  175711. if (png_ptr->zstream.msg != NULL)
  175712. png_error(png_ptr, png_ptr->zstream.msg);
  175713. else
  175714. png_error(png_ptr, "zlib error");
  175715. }
  175716. if (!(png_ptr->zstream.avail_out))
  175717. {
  175718. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175719. png_ptr->zbuf_size);
  175720. png_ptr->zstream.next_out = png_ptr->zbuf;
  175721. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175722. wrote_IDAT = 1;
  175723. }
  175724. } while(wrote_IDAT == 1);
  175725. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175726. {
  175727. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175728. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175729. png_ptr->zstream.next_out = png_ptr->zbuf;
  175730. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175731. }
  175732. png_ptr->flush_rows = 0;
  175733. png_flush(png_ptr);
  175734. }
  175735. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175736. void PNGAPI
  175737. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175738. {
  175739. png_structp png_ptr = NULL;
  175740. png_infop info_ptr = NULL;
  175741. #ifdef PNG_USER_MEM_SUPPORTED
  175742. png_free_ptr free_fn = NULL;
  175743. png_voidp mem_ptr = NULL;
  175744. #endif
  175745. png_debug(1, "in png_destroy_write_struct\n");
  175746. if (png_ptr_ptr != NULL)
  175747. {
  175748. png_ptr = *png_ptr_ptr;
  175749. #ifdef PNG_USER_MEM_SUPPORTED
  175750. free_fn = png_ptr->free_fn;
  175751. mem_ptr = png_ptr->mem_ptr;
  175752. #endif
  175753. }
  175754. if (info_ptr_ptr != NULL)
  175755. info_ptr = *info_ptr_ptr;
  175756. if (info_ptr != NULL)
  175757. {
  175758. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175759. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175760. if (png_ptr->num_chunk_list)
  175761. {
  175762. png_free(png_ptr, png_ptr->chunk_list);
  175763. png_ptr->chunk_list=NULL;
  175764. png_ptr->num_chunk_list=0;
  175765. }
  175766. #endif
  175767. #ifdef PNG_USER_MEM_SUPPORTED
  175768. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175769. (png_voidp)mem_ptr);
  175770. #else
  175771. png_destroy_struct((png_voidp)info_ptr);
  175772. #endif
  175773. *info_ptr_ptr = NULL;
  175774. }
  175775. if (png_ptr != NULL)
  175776. {
  175777. png_write_destroy(png_ptr);
  175778. #ifdef PNG_USER_MEM_SUPPORTED
  175779. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175780. (png_voidp)mem_ptr);
  175781. #else
  175782. png_destroy_struct((png_voidp)png_ptr);
  175783. #endif
  175784. *png_ptr_ptr = NULL;
  175785. }
  175786. }
  175787. void /* PRIVATE */
  175788. png_write_destroy(png_structp png_ptr)
  175789. {
  175790. #ifdef PNG_SETJMP_SUPPORTED
  175791. jmp_buf tmp_jmp; /* save jump buffer */
  175792. #endif
  175793. png_error_ptr error_fn;
  175794. png_error_ptr warning_fn;
  175795. png_voidp error_ptr;
  175796. #ifdef PNG_USER_MEM_SUPPORTED
  175797. png_free_ptr free_fn;
  175798. #endif
  175799. png_debug(1, "in png_write_destroy\n");
  175800. deflateEnd(&png_ptr->zstream);
  175801. png_free(png_ptr, png_ptr->zbuf);
  175802. png_free(png_ptr, png_ptr->row_buf);
  175803. png_free(png_ptr, png_ptr->prev_row);
  175804. png_free(png_ptr, png_ptr->sub_row);
  175805. png_free(png_ptr, png_ptr->up_row);
  175806. png_free(png_ptr, png_ptr->avg_row);
  175807. png_free(png_ptr, png_ptr->paeth_row);
  175808. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175809. png_free(png_ptr, png_ptr->time_buffer);
  175810. #endif
  175811. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175812. png_free(png_ptr, png_ptr->prev_filters);
  175813. png_free(png_ptr, png_ptr->filter_weights);
  175814. png_free(png_ptr, png_ptr->inv_filter_weights);
  175815. png_free(png_ptr, png_ptr->filter_costs);
  175816. png_free(png_ptr, png_ptr->inv_filter_costs);
  175817. #endif
  175818. #ifdef PNG_SETJMP_SUPPORTED
  175819. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175820. #endif
  175821. error_fn = png_ptr->error_fn;
  175822. warning_fn = png_ptr->warning_fn;
  175823. error_ptr = png_ptr->error_ptr;
  175824. #ifdef PNG_USER_MEM_SUPPORTED
  175825. free_fn = png_ptr->free_fn;
  175826. #endif
  175827. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175828. png_ptr->error_fn = error_fn;
  175829. png_ptr->warning_fn = warning_fn;
  175830. png_ptr->error_ptr = error_ptr;
  175831. #ifdef PNG_USER_MEM_SUPPORTED
  175832. png_ptr->free_fn = free_fn;
  175833. #endif
  175834. #ifdef PNG_SETJMP_SUPPORTED
  175835. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175836. #endif
  175837. }
  175838. void PNGAPI
  175839. png_set_filter(png_structp png_ptr, int method, int filters)
  175840. {
  175841. png_debug(1, "in png_set_filter\n");
  175842. if (png_ptr == NULL)
  175843. return;
  175844. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175845. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175846. (method == PNG_INTRAPIXEL_DIFFERENCING))
  175847. method = PNG_FILTER_TYPE_BASE;
  175848. #endif
  175849. if (method == PNG_FILTER_TYPE_BASE)
  175850. {
  175851. switch (filters & (PNG_ALL_FILTERS | 0x07))
  175852. {
  175853. #ifndef PNG_NO_WRITE_FILTER
  175854. case 5:
  175855. case 6:
  175856. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  175857. #endif /* PNG_NO_WRITE_FILTER */
  175858. case PNG_FILTER_VALUE_NONE:
  175859. png_ptr->do_filter=PNG_FILTER_NONE; break;
  175860. #ifndef PNG_NO_WRITE_FILTER
  175861. case PNG_FILTER_VALUE_SUB:
  175862. png_ptr->do_filter=PNG_FILTER_SUB; break;
  175863. case PNG_FILTER_VALUE_UP:
  175864. png_ptr->do_filter=PNG_FILTER_UP; break;
  175865. case PNG_FILTER_VALUE_AVG:
  175866. png_ptr->do_filter=PNG_FILTER_AVG; break;
  175867. case PNG_FILTER_VALUE_PAETH:
  175868. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  175869. default: png_ptr->do_filter = (png_byte)filters; break;
  175870. #else
  175871. default: png_warning(png_ptr, "Unknown row filter for method 0");
  175872. #endif /* PNG_NO_WRITE_FILTER */
  175873. }
  175874. if (png_ptr->row_buf != NULL)
  175875. {
  175876. #ifndef PNG_NO_WRITE_FILTER
  175877. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  175878. {
  175879. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  175880. (png_ptr->rowbytes + 1));
  175881. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  175882. }
  175883. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  175884. {
  175885. if (png_ptr->prev_row == NULL)
  175886. {
  175887. png_warning(png_ptr, "Can't add Up filter after starting");
  175888. png_ptr->do_filter &= ~PNG_FILTER_UP;
  175889. }
  175890. else
  175891. {
  175892. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  175893. (png_ptr->rowbytes + 1));
  175894. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  175895. }
  175896. }
  175897. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  175898. {
  175899. if (png_ptr->prev_row == NULL)
  175900. {
  175901. png_warning(png_ptr, "Can't add Average filter after starting");
  175902. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  175903. }
  175904. else
  175905. {
  175906. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  175907. (png_ptr->rowbytes + 1));
  175908. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  175909. }
  175910. }
  175911. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  175912. png_ptr->paeth_row == NULL)
  175913. {
  175914. if (png_ptr->prev_row == NULL)
  175915. {
  175916. png_warning(png_ptr, "Can't add Paeth filter after starting");
  175917. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  175918. }
  175919. else
  175920. {
  175921. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  175922. (png_ptr->rowbytes + 1));
  175923. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  175924. }
  175925. }
  175926. if (png_ptr->do_filter == PNG_NO_FILTERS)
  175927. #endif /* PNG_NO_WRITE_FILTER */
  175928. png_ptr->do_filter = PNG_FILTER_NONE;
  175929. }
  175930. }
  175931. else
  175932. png_error(png_ptr, "Unknown custom filter method");
  175933. }
  175934. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  175935. void PNGAPI
  175936. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  175937. int num_weights, png_doublep filter_weights,
  175938. png_doublep filter_costs)
  175939. {
  175940. int i;
  175941. png_debug(1, "in png_set_filter_heuristics\n");
  175942. if (png_ptr == NULL)
  175943. return;
  175944. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  175945. {
  175946. png_warning(png_ptr, "Unknown filter heuristic method");
  175947. return;
  175948. }
  175949. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  175950. {
  175951. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  175952. }
  175953. if (num_weights < 0 || filter_weights == NULL ||
  175954. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  175955. {
  175956. num_weights = 0;
  175957. }
  175958. png_ptr->num_prev_filters = (png_byte)num_weights;
  175959. png_ptr->heuristic_method = (png_byte)heuristic_method;
  175960. if (num_weights > 0)
  175961. {
  175962. if (png_ptr->prev_filters == NULL)
  175963. {
  175964. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  175965. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  175966. for (i = 0; i < num_weights; i++)
  175967. {
  175968. png_ptr->prev_filters[i] = 255;
  175969. }
  175970. }
  175971. if (png_ptr->filter_weights == NULL)
  175972. {
  175973. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  175974. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  175975. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  175976. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  175977. for (i = 0; i < num_weights; i++)
  175978. {
  175979. png_ptr->inv_filter_weights[i] =
  175980. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  175981. }
  175982. }
  175983. for (i = 0; i < num_weights; i++)
  175984. {
  175985. if (filter_weights[i] < 0.0)
  175986. {
  175987. png_ptr->inv_filter_weights[i] =
  175988. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  175989. }
  175990. else
  175991. {
  175992. png_ptr->inv_filter_weights[i] =
  175993. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  175994. png_ptr->filter_weights[i] =
  175995. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  175996. }
  175997. }
  175998. }
  175999. if (png_ptr->filter_costs == NULL)
  176000. {
  176001. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176002. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176003. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176004. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176005. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176006. {
  176007. png_ptr->inv_filter_costs[i] =
  176008. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176009. }
  176010. }
  176011. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176012. {
  176013. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176014. {
  176015. png_ptr->inv_filter_costs[i] =
  176016. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176017. }
  176018. else if (filter_costs[i] >= 1.0)
  176019. {
  176020. png_ptr->inv_filter_costs[i] =
  176021. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176022. png_ptr->filter_costs[i] =
  176023. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176024. }
  176025. }
  176026. }
  176027. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176028. void PNGAPI
  176029. png_set_compression_level(png_structp png_ptr, int level)
  176030. {
  176031. png_debug(1, "in png_set_compression_level\n");
  176032. if (png_ptr == NULL)
  176033. return;
  176034. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176035. png_ptr->zlib_level = level;
  176036. }
  176037. void PNGAPI
  176038. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176039. {
  176040. png_debug(1, "in png_set_compression_mem_level\n");
  176041. if (png_ptr == NULL)
  176042. return;
  176043. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176044. png_ptr->zlib_mem_level = mem_level;
  176045. }
  176046. void PNGAPI
  176047. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176048. {
  176049. png_debug(1, "in png_set_compression_strategy\n");
  176050. if (png_ptr == NULL)
  176051. return;
  176052. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176053. png_ptr->zlib_strategy = strategy;
  176054. }
  176055. void PNGAPI
  176056. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176057. {
  176058. if (png_ptr == NULL)
  176059. return;
  176060. if (window_bits > 15)
  176061. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176062. else if (window_bits < 8)
  176063. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176064. #ifndef WBITS_8_OK
  176065. if (window_bits == 8)
  176066. {
  176067. png_warning(png_ptr, "Compression window is being reset to 512");
  176068. window_bits=9;
  176069. }
  176070. #endif
  176071. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176072. png_ptr->zlib_window_bits = window_bits;
  176073. }
  176074. void PNGAPI
  176075. png_set_compression_method(png_structp png_ptr, int method)
  176076. {
  176077. png_debug(1, "in png_set_compression_method\n");
  176078. if (png_ptr == NULL)
  176079. return;
  176080. if (method != 8)
  176081. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176082. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176083. png_ptr->zlib_method = method;
  176084. }
  176085. void PNGAPI
  176086. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176087. {
  176088. if (png_ptr == NULL)
  176089. return;
  176090. png_ptr->write_row_fn = write_row_fn;
  176091. }
  176092. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176093. void PNGAPI
  176094. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176095. write_user_transform_fn)
  176096. {
  176097. png_debug(1, "in png_set_write_user_transform_fn\n");
  176098. if (png_ptr == NULL)
  176099. return;
  176100. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176101. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176102. }
  176103. #endif
  176104. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176105. void PNGAPI
  176106. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176107. int transforms, voidp params)
  176108. {
  176109. if (png_ptr == NULL || info_ptr == NULL)
  176110. return;
  176111. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176112. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176113. png_set_invert_alpha(png_ptr);
  176114. #endif
  176115. png_write_info(png_ptr, info_ptr);
  176116. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176117. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176118. png_set_invert_mono(png_ptr);
  176119. #endif
  176120. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176121. if ((transforms & PNG_TRANSFORM_SHIFT)
  176122. && (info_ptr->valid & PNG_INFO_sBIT))
  176123. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176124. #endif
  176125. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176126. if (transforms & PNG_TRANSFORM_PACKING)
  176127. png_set_packing(png_ptr);
  176128. #endif
  176129. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176130. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176131. png_set_swap_alpha(png_ptr);
  176132. #endif
  176133. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176134. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176135. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176136. #endif
  176137. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176138. if (transforms & PNG_TRANSFORM_BGR)
  176139. png_set_bgr(png_ptr);
  176140. #endif
  176141. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176142. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176143. png_set_swap(png_ptr);
  176144. #endif
  176145. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176146. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176147. png_set_packswap(png_ptr);
  176148. #endif
  176149. if (info_ptr->valid & PNG_INFO_IDAT)
  176150. png_write_image(png_ptr, info_ptr->row_pointers);
  176151. png_write_end(png_ptr, info_ptr);
  176152. transforms = transforms; /* quiet compiler warnings */
  176153. params = params;
  176154. }
  176155. #endif
  176156. #endif /* PNG_WRITE_SUPPORTED */
  176157. /*** End of inlined file: pngwrite.c ***/
  176158. /*** Start of inlined file: pngwtran.c ***/
  176159. #define PNG_INTERNAL
  176160. #ifdef PNG_WRITE_SUPPORTED
  176161. void /* PRIVATE */
  176162. png_do_write_transformations(png_structp png_ptr)
  176163. {
  176164. png_debug(1, "in png_do_write_transformations\n");
  176165. if (png_ptr == NULL)
  176166. return;
  176167. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176168. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176169. if(png_ptr->write_user_transform_fn != NULL)
  176170. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176171. (png_ptr, /* png_ptr */
  176172. &(png_ptr->row_info), /* row_info: */
  176173. png_ptr->row_buf + 1); /* start of pixel data for row */
  176174. #endif
  176175. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176176. if (png_ptr->transformations & PNG_FILLER)
  176177. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176178. png_ptr->flags);
  176179. #endif
  176180. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176181. if (png_ptr->transformations & PNG_PACKSWAP)
  176182. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176183. #endif
  176184. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176185. if (png_ptr->transformations & PNG_PACK)
  176186. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176187. (png_uint_32)png_ptr->bit_depth);
  176188. #endif
  176189. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176190. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176191. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176192. #endif
  176193. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176194. if (png_ptr->transformations & PNG_SHIFT)
  176195. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176196. &(png_ptr->shift));
  176197. #endif
  176198. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176199. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176200. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176201. #endif
  176202. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176203. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176204. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176205. #endif
  176206. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176207. if (png_ptr->transformations & PNG_BGR)
  176208. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176209. #endif
  176210. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176211. if (png_ptr->transformations & PNG_INVERT_MONO)
  176212. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176213. #endif
  176214. }
  176215. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176216. void /* PRIVATE */
  176217. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176218. {
  176219. png_debug(1, "in png_do_pack\n");
  176220. if (row_info->bit_depth == 8 &&
  176221. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176222. row != NULL && row_info != NULL &&
  176223. #endif
  176224. row_info->channels == 1)
  176225. {
  176226. switch ((int)bit_depth)
  176227. {
  176228. case 1:
  176229. {
  176230. png_bytep sp, dp;
  176231. int mask, v;
  176232. png_uint_32 i;
  176233. png_uint_32 row_width = row_info->width;
  176234. sp = row;
  176235. dp = row;
  176236. mask = 0x80;
  176237. v = 0;
  176238. for (i = 0; i < row_width; i++)
  176239. {
  176240. if (*sp != 0)
  176241. v |= mask;
  176242. sp++;
  176243. if (mask > 1)
  176244. mask >>= 1;
  176245. else
  176246. {
  176247. mask = 0x80;
  176248. *dp = (png_byte)v;
  176249. dp++;
  176250. v = 0;
  176251. }
  176252. }
  176253. if (mask != 0x80)
  176254. *dp = (png_byte)v;
  176255. break;
  176256. }
  176257. case 2:
  176258. {
  176259. png_bytep sp, dp;
  176260. int shift, v;
  176261. png_uint_32 i;
  176262. png_uint_32 row_width = row_info->width;
  176263. sp = row;
  176264. dp = row;
  176265. shift = 6;
  176266. v = 0;
  176267. for (i = 0; i < row_width; i++)
  176268. {
  176269. png_byte value;
  176270. value = (png_byte)(*sp & 0x03);
  176271. v |= (value << shift);
  176272. if (shift == 0)
  176273. {
  176274. shift = 6;
  176275. *dp = (png_byte)v;
  176276. dp++;
  176277. v = 0;
  176278. }
  176279. else
  176280. shift -= 2;
  176281. sp++;
  176282. }
  176283. if (shift != 6)
  176284. *dp = (png_byte)v;
  176285. break;
  176286. }
  176287. case 4:
  176288. {
  176289. png_bytep sp, dp;
  176290. int shift, v;
  176291. png_uint_32 i;
  176292. png_uint_32 row_width = row_info->width;
  176293. sp = row;
  176294. dp = row;
  176295. shift = 4;
  176296. v = 0;
  176297. for (i = 0; i < row_width; i++)
  176298. {
  176299. png_byte value;
  176300. value = (png_byte)(*sp & 0x0f);
  176301. v |= (value << shift);
  176302. if (shift == 0)
  176303. {
  176304. shift = 4;
  176305. *dp = (png_byte)v;
  176306. dp++;
  176307. v = 0;
  176308. }
  176309. else
  176310. shift -= 4;
  176311. sp++;
  176312. }
  176313. if (shift != 4)
  176314. *dp = (png_byte)v;
  176315. break;
  176316. }
  176317. }
  176318. row_info->bit_depth = (png_byte)bit_depth;
  176319. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176320. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176321. row_info->width);
  176322. }
  176323. }
  176324. #endif
  176325. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176326. void /* PRIVATE */
  176327. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176328. {
  176329. png_debug(1, "in png_do_shift\n");
  176330. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176331. if (row != NULL && row_info != NULL &&
  176332. #else
  176333. if (
  176334. #endif
  176335. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176336. {
  176337. int shift_start[4], shift_dec[4];
  176338. int channels = 0;
  176339. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176340. {
  176341. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176342. shift_dec[channels] = bit_depth->red;
  176343. channels++;
  176344. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176345. shift_dec[channels] = bit_depth->green;
  176346. channels++;
  176347. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176348. shift_dec[channels] = bit_depth->blue;
  176349. channels++;
  176350. }
  176351. else
  176352. {
  176353. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176354. shift_dec[channels] = bit_depth->gray;
  176355. channels++;
  176356. }
  176357. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176358. {
  176359. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176360. shift_dec[channels] = bit_depth->alpha;
  176361. channels++;
  176362. }
  176363. if (row_info->bit_depth < 8)
  176364. {
  176365. png_bytep bp = row;
  176366. png_uint_32 i;
  176367. png_byte mask;
  176368. png_uint_32 row_bytes = row_info->rowbytes;
  176369. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176370. mask = 0x55;
  176371. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176372. mask = 0x11;
  176373. else
  176374. mask = 0xff;
  176375. for (i = 0; i < row_bytes; i++, bp++)
  176376. {
  176377. png_uint_16 v;
  176378. int j;
  176379. v = *bp;
  176380. *bp = 0;
  176381. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176382. {
  176383. if (j > 0)
  176384. *bp |= (png_byte)((v << j) & 0xff);
  176385. else
  176386. *bp |= (png_byte)((v >> (-j)) & mask);
  176387. }
  176388. }
  176389. }
  176390. else if (row_info->bit_depth == 8)
  176391. {
  176392. png_bytep bp = row;
  176393. png_uint_32 i;
  176394. png_uint_32 istop = channels * row_info->width;
  176395. for (i = 0; i < istop; i++, bp++)
  176396. {
  176397. png_uint_16 v;
  176398. int j;
  176399. int c = (int)(i%channels);
  176400. v = *bp;
  176401. *bp = 0;
  176402. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176403. {
  176404. if (j > 0)
  176405. *bp |= (png_byte)((v << j) & 0xff);
  176406. else
  176407. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176408. }
  176409. }
  176410. }
  176411. else
  176412. {
  176413. png_bytep bp;
  176414. png_uint_32 i;
  176415. png_uint_32 istop = channels * row_info->width;
  176416. for (bp = row, i = 0; i < istop; i++)
  176417. {
  176418. int c = (int)(i%channels);
  176419. png_uint_16 value, v;
  176420. int j;
  176421. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176422. value = 0;
  176423. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176424. {
  176425. if (j > 0)
  176426. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176427. else
  176428. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176429. }
  176430. *bp++ = (png_byte)(value >> 8);
  176431. *bp++ = (png_byte)(value & 0xff);
  176432. }
  176433. }
  176434. }
  176435. }
  176436. #endif
  176437. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176438. void /* PRIVATE */
  176439. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176440. {
  176441. png_debug(1, "in png_do_write_swap_alpha\n");
  176442. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176443. if (row != NULL && row_info != NULL)
  176444. #endif
  176445. {
  176446. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176447. {
  176448. if (row_info->bit_depth == 8)
  176449. {
  176450. png_bytep sp, dp;
  176451. png_uint_32 i;
  176452. png_uint_32 row_width = row_info->width;
  176453. for (i = 0, sp = dp = row; i < row_width; i++)
  176454. {
  176455. png_byte save = *(sp++);
  176456. *(dp++) = *(sp++);
  176457. *(dp++) = *(sp++);
  176458. *(dp++) = *(sp++);
  176459. *(dp++) = save;
  176460. }
  176461. }
  176462. else
  176463. {
  176464. png_bytep sp, dp;
  176465. png_uint_32 i;
  176466. png_uint_32 row_width = row_info->width;
  176467. for (i = 0, sp = dp = row; i < row_width; i++)
  176468. {
  176469. png_byte save[2];
  176470. save[0] = *(sp++);
  176471. save[1] = *(sp++);
  176472. *(dp++) = *(sp++);
  176473. *(dp++) = *(sp++);
  176474. *(dp++) = *(sp++);
  176475. *(dp++) = *(sp++);
  176476. *(dp++) = *(sp++);
  176477. *(dp++) = *(sp++);
  176478. *(dp++) = save[0];
  176479. *(dp++) = save[1];
  176480. }
  176481. }
  176482. }
  176483. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176484. {
  176485. if (row_info->bit_depth == 8)
  176486. {
  176487. png_bytep sp, dp;
  176488. png_uint_32 i;
  176489. png_uint_32 row_width = row_info->width;
  176490. for (i = 0, sp = dp = row; i < row_width; i++)
  176491. {
  176492. png_byte save = *(sp++);
  176493. *(dp++) = *(sp++);
  176494. *(dp++) = save;
  176495. }
  176496. }
  176497. else
  176498. {
  176499. png_bytep sp, dp;
  176500. png_uint_32 i;
  176501. png_uint_32 row_width = row_info->width;
  176502. for (i = 0, sp = dp = row; i < row_width; i++)
  176503. {
  176504. png_byte save[2];
  176505. save[0] = *(sp++);
  176506. save[1] = *(sp++);
  176507. *(dp++) = *(sp++);
  176508. *(dp++) = *(sp++);
  176509. *(dp++) = save[0];
  176510. *(dp++) = save[1];
  176511. }
  176512. }
  176513. }
  176514. }
  176515. }
  176516. #endif
  176517. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176518. void /* PRIVATE */
  176519. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176520. {
  176521. png_debug(1, "in png_do_write_invert_alpha\n");
  176522. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176523. if (row != NULL && row_info != NULL)
  176524. #endif
  176525. {
  176526. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176527. {
  176528. if (row_info->bit_depth == 8)
  176529. {
  176530. png_bytep sp, dp;
  176531. png_uint_32 i;
  176532. png_uint_32 row_width = row_info->width;
  176533. for (i = 0, sp = dp = row; i < row_width; i++)
  176534. {
  176535. sp+=3; dp = sp;
  176536. *(dp++) = (png_byte)(255 - *(sp++));
  176537. }
  176538. }
  176539. else
  176540. {
  176541. png_bytep sp, dp;
  176542. png_uint_32 i;
  176543. png_uint_32 row_width = row_info->width;
  176544. for (i = 0, sp = dp = row; i < row_width; i++)
  176545. {
  176546. sp+=6; dp = sp;
  176547. *(dp++) = (png_byte)(255 - *(sp++));
  176548. *(dp++) = (png_byte)(255 - *(sp++));
  176549. }
  176550. }
  176551. }
  176552. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176553. {
  176554. if (row_info->bit_depth == 8)
  176555. {
  176556. png_bytep sp, dp;
  176557. png_uint_32 i;
  176558. png_uint_32 row_width = row_info->width;
  176559. for (i = 0, sp = dp = row; i < row_width; i++)
  176560. {
  176561. *(dp++) = *(sp++);
  176562. *(dp++) = (png_byte)(255 - *(sp++));
  176563. }
  176564. }
  176565. else
  176566. {
  176567. png_bytep sp, dp;
  176568. png_uint_32 i;
  176569. png_uint_32 row_width = row_info->width;
  176570. for (i = 0, sp = dp = row; i < row_width; i++)
  176571. {
  176572. sp+=2; dp = sp;
  176573. *(dp++) = (png_byte)(255 - *(sp++));
  176574. *(dp++) = (png_byte)(255 - *(sp++));
  176575. }
  176576. }
  176577. }
  176578. }
  176579. }
  176580. #endif
  176581. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176582. void /* PRIVATE */
  176583. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176584. {
  176585. png_debug(1, "in png_do_write_intrapixel\n");
  176586. if (
  176587. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176588. row != NULL && row_info != NULL &&
  176589. #endif
  176590. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176591. {
  176592. int bytes_per_pixel;
  176593. png_uint_32 row_width = row_info->width;
  176594. if (row_info->bit_depth == 8)
  176595. {
  176596. png_bytep rp;
  176597. png_uint_32 i;
  176598. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176599. bytes_per_pixel = 3;
  176600. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176601. bytes_per_pixel = 4;
  176602. else
  176603. return;
  176604. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176605. {
  176606. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176607. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176608. }
  176609. }
  176610. else if (row_info->bit_depth == 16)
  176611. {
  176612. png_bytep rp;
  176613. png_uint_32 i;
  176614. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176615. bytes_per_pixel = 6;
  176616. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176617. bytes_per_pixel = 8;
  176618. else
  176619. return;
  176620. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176621. {
  176622. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176623. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176624. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176625. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176626. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176627. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176628. *(rp+1) = (png_byte)(red & 0xff);
  176629. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176630. *(rp+5) = (png_byte)(blue & 0xff);
  176631. }
  176632. }
  176633. }
  176634. }
  176635. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176636. #endif /* PNG_WRITE_SUPPORTED */
  176637. /*** End of inlined file: pngwtran.c ***/
  176638. /*** Start of inlined file: pngwutil.c ***/
  176639. #define PNG_INTERNAL
  176640. #ifdef PNG_WRITE_SUPPORTED
  176641. void PNGAPI
  176642. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176643. {
  176644. buf[0] = (png_byte)((i >> 24) & 0xff);
  176645. buf[1] = (png_byte)((i >> 16) & 0xff);
  176646. buf[2] = (png_byte)((i >> 8) & 0xff);
  176647. buf[3] = (png_byte)(i & 0xff);
  176648. }
  176649. void PNGAPI
  176650. png_save_int_32(png_bytep buf, png_int_32 i)
  176651. {
  176652. buf[0] = (png_byte)((i >> 24) & 0xff);
  176653. buf[1] = (png_byte)((i >> 16) & 0xff);
  176654. buf[2] = (png_byte)((i >> 8) & 0xff);
  176655. buf[3] = (png_byte)(i & 0xff);
  176656. }
  176657. void PNGAPI
  176658. png_save_uint_16(png_bytep buf, unsigned int i)
  176659. {
  176660. buf[0] = (png_byte)((i >> 8) & 0xff);
  176661. buf[1] = (png_byte)(i & 0xff);
  176662. }
  176663. void PNGAPI
  176664. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176665. png_bytep data, png_size_t length)
  176666. {
  176667. if(png_ptr == NULL) return;
  176668. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176669. png_write_chunk_data(png_ptr, data, length);
  176670. png_write_chunk_end(png_ptr);
  176671. }
  176672. void PNGAPI
  176673. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176674. png_uint_32 length)
  176675. {
  176676. png_byte buf[4];
  176677. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176678. if(png_ptr == NULL) return;
  176679. png_save_uint_32(buf, length);
  176680. png_write_data(png_ptr, buf, (png_size_t)4);
  176681. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176682. png_reset_crc(png_ptr);
  176683. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176684. }
  176685. void PNGAPI
  176686. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176687. {
  176688. if(png_ptr == NULL) return;
  176689. if (data != NULL && length > 0)
  176690. {
  176691. png_calculate_crc(png_ptr, data, length);
  176692. png_write_data(png_ptr, data, length);
  176693. }
  176694. }
  176695. void PNGAPI
  176696. png_write_chunk_end(png_structp png_ptr)
  176697. {
  176698. png_byte buf[4];
  176699. if(png_ptr == NULL) return;
  176700. png_save_uint_32(buf, png_ptr->crc);
  176701. png_write_data(png_ptr, buf, (png_size_t)4);
  176702. }
  176703. void /* PRIVATE */
  176704. png_write_sig(png_structp png_ptr)
  176705. {
  176706. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176707. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176708. (png_size_t)8 - png_ptr->sig_bytes);
  176709. if(png_ptr->sig_bytes < 3)
  176710. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176711. }
  176712. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176713. typedef struct
  176714. {
  176715. char *input; /* the uncompressed input data */
  176716. int input_len; /* its length */
  176717. int num_output_ptr; /* number of output pointers used */
  176718. int max_output_ptr; /* size of output_ptr */
  176719. png_charpp output_ptr; /* array of pointers to output */
  176720. } compression_state;
  176721. static int /* PRIVATE */
  176722. png_text_compress(png_structp png_ptr,
  176723. png_charp text, png_size_t text_len, int compression,
  176724. compression_state *comp)
  176725. {
  176726. int ret;
  176727. comp->num_output_ptr = 0;
  176728. comp->max_output_ptr = 0;
  176729. comp->output_ptr = NULL;
  176730. comp->input = NULL;
  176731. comp->input_len = 0;
  176732. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176733. {
  176734. comp->input = text;
  176735. comp->input_len = text_len;
  176736. return((int)text_len);
  176737. }
  176738. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176739. {
  176740. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176741. char msg[50];
  176742. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176743. png_warning(png_ptr, msg);
  176744. #else
  176745. png_warning(png_ptr, "Unknown compression type");
  176746. #endif
  176747. }
  176748. png_ptr->zstream.avail_in = (uInt)text_len;
  176749. png_ptr->zstream.next_in = (Bytef *)text;
  176750. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176751. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176752. do
  176753. {
  176754. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176755. if (ret != Z_OK)
  176756. {
  176757. if (png_ptr->zstream.msg != NULL)
  176758. png_error(png_ptr, png_ptr->zstream.msg);
  176759. else
  176760. png_error(png_ptr, "zlib error");
  176761. }
  176762. if (!(png_ptr->zstream.avail_out))
  176763. {
  176764. if (comp->num_output_ptr >= comp->max_output_ptr)
  176765. {
  176766. int old_max;
  176767. old_max = comp->max_output_ptr;
  176768. comp->max_output_ptr = comp->num_output_ptr + 4;
  176769. if (comp->output_ptr != NULL)
  176770. {
  176771. png_charpp old_ptr;
  176772. old_ptr = comp->output_ptr;
  176773. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176774. (png_uint_32)(comp->max_output_ptr *
  176775. png_sizeof (png_charpp)));
  176776. png_memcpy(comp->output_ptr, old_ptr, old_max
  176777. * png_sizeof (png_charp));
  176778. png_free(png_ptr, old_ptr);
  176779. }
  176780. else
  176781. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176782. (png_uint_32)(comp->max_output_ptr *
  176783. png_sizeof (png_charp)));
  176784. }
  176785. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176786. (png_uint_32)png_ptr->zbuf_size);
  176787. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176788. png_ptr->zbuf_size);
  176789. comp->num_output_ptr++;
  176790. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176791. png_ptr->zstream.next_out = png_ptr->zbuf;
  176792. }
  176793. } while (png_ptr->zstream.avail_in);
  176794. do
  176795. {
  176796. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176797. if (ret == Z_OK)
  176798. {
  176799. if (!(png_ptr->zstream.avail_out))
  176800. {
  176801. if (comp->num_output_ptr >= comp->max_output_ptr)
  176802. {
  176803. int old_max;
  176804. old_max = comp->max_output_ptr;
  176805. comp->max_output_ptr = comp->num_output_ptr + 4;
  176806. if (comp->output_ptr != NULL)
  176807. {
  176808. png_charpp old_ptr;
  176809. old_ptr = comp->output_ptr;
  176810. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176811. (png_uint_32)(comp->max_output_ptr *
  176812. png_sizeof (png_charpp)));
  176813. png_memcpy(comp->output_ptr, old_ptr,
  176814. old_max * png_sizeof (png_charp));
  176815. png_free(png_ptr, old_ptr);
  176816. }
  176817. else
  176818. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176819. (png_uint_32)(comp->max_output_ptr *
  176820. png_sizeof (png_charp)));
  176821. }
  176822. comp->output_ptr[comp->num_output_ptr] =
  176823. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  176824. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176825. png_ptr->zbuf_size);
  176826. comp->num_output_ptr++;
  176827. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176828. png_ptr->zstream.next_out = png_ptr->zbuf;
  176829. }
  176830. }
  176831. else if (ret != Z_STREAM_END)
  176832. {
  176833. if (png_ptr->zstream.msg != NULL)
  176834. png_error(png_ptr, png_ptr->zstream.msg);
  176835. else
  176836. png_error(png_ptr, "zlib error");
  176837. }
  176838. } while (ret != Z_STREAM_END);
  176839. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  176840. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  176841. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  176842. return((int)text_len);
  176843. }
  176844. static void /* PRIVATE */
  176845. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  176846. {
  176847. int i;
  176848. if (comp->input)
  176849. {
  176850. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  176851. (png_size_t)comp->input_len);
  176852. return;
  176853. }
  176854. for (i = 0; i < comp->num_output_ptr; i++)
  176855. {
  176856. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  176857. png_ptr->zbuf_size);
  176858. png_free(png_ptr, comp->output_ptr[i]);
  176859. comp->output_ptr[i]=NULL;
  176860. }
  176861. if (comp->max_output_ptr != 0)
  176862. png_free(png_ptr, comp->output_ptr);
  176863. comp->output_ptr=NULL;
  176864. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  176865. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  176866. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176867. deflateReset(&png_ptr->zstream);
  176868. png_ptr->zstream.data_type = Z_BINARY;
  176869. }
  176870. #endif
  176871. void /* PRIVATE */
  176872. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  176873. int bit_depth, int color_type, int compression_type, int filter_type,
  176874. int interlace_type)
  176875. {
  176876. #ifdef PNG_USE_LOCAL_ARRAYS
  176877. PNG_IHDR;
  176878. #endif
  176879. png_byte buf[13]; /* buffer to store the IHDR info */
  176880. png_debug(1, "in png_write_IHDR\n");
  176881. switch (color_type)
  176882. {
  176883. case PNG_COLOR_TYPE_GRAY:
  176884. switch (bit_depth)
  176885. {
  176886. case 1:
  176887. case 2:
  176888. case 4:
  176889. case 8:
  176890. case 16: png_ptr->channels = 1; break;
  176891. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  176892. }
  176893. break;
  176894. case PNG_COLOR_TYPE_RGB:
  176895. if (bit_depth != 8 && bit_depth != 16)
  176896. png_error(png_ptr, "Invalid bit depth for RGB image");
  176897. png_ptr->channels = 3;
  176898. break;
  176899. case PNG_COLOR_TYPE_PALETTE:
  176900. switch (bit_depth)
  176901. {
  176902. case 1:
  176903. case 2:
  176904. case 4:
  176905. case 8: png_ptr->channels = 1; break;
  176906. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  176907. }
  176908. break;
  176909. case PNG_COLOR_TYPE_GRAY_ALPHA:
  176910. if (bit_depth != 8 && bit_depth != 16)
  176911. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  176912. png_ptr->channels = 2;
  176913. break;
  176914. case PNG_COLOR_TYPE_RGB_ALPHA:
  176915. if (bit_depth != 8 && bit_depth != 16)
  176916. png_error(png_ptr, "Invalid bit depth for RGBA image");
  176917. png_ptr->channels = 4;
  176918. break;
  176919. default:
  176920. png_error(png_ptr, "Invalid image color type specified");
  176921. }
  176922. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  176923. {
  176924. png_warning(png_ptr, "Invalid compression type specified");
  176925. compression_type = PNG_COMPRESSION_TYPE_BASE;
  176926. }
  176927. if (
  176928. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176929. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176930. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  176931. (color_type == PNG_COLOR_TYPE_RGB ||
  176932. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  176933. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  176934. #endif
  176935. filter_type != PNG_FILTER_TYPE_BASE)
  176936. {
  176937. png_warning(png_ptr, "Invalid filter type specified");
  176938. filter_type = PNG_FILTER_TYPE_BASE;
  176939. }
  176940. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  176941. if (interlace_type != PNG_INTERLACE_NONE &&
  176942. interlace_type != PNG_INTERLACE_ADAM7)
  176943. {
  176944. png_warning(png_ptr, "Invalid interlace type specified");
  176945. interlace_type = PNG_INTERLACE_ADAM7;
  176946. }
  176947. #else
  176948. interlace_type=PNG_INTERLACE_NONE;
  176949. #endif
  176950. png_ptr->bit_depth = (png_byte)bit_depth;
  176951. png_ptr->color_type = (png_byte)color_type;
  176952. png_ptr->interlaced = (png_byte)interlace_type;
  176953. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176954. png_ptr->filter_type = (png_byte)filter_type;
  176955. #endif
  176956. png_ptr->compression_type = (png_byte)compression_type;
  176957. png_ptr->width = width;
  176958. png_ptr->height = height;
  176959. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  176960. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  176961. png_ptr->usr_width = png_ptr->width;
  176962. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  176963. png_ptr->usr_channels = png_ptr->channels;
  176964. png_save_uint_32(buf, width);
  176965. png_save_uint_32(buf + 4, height);
  176966. buf[8] = (png_byte)bit_depth;
  176967. buf[9] = (png_byte)color_type;
  176968. buf[10] = (png_byte)compression_type;
  176969. buf[11] = (png_byte)filter_type;
  176970. buf[12] = (png_byte)interlace_type;
  176971. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  176972. png_ptr->zstream.zalloc = png_zalloc;
  176973. png_ptr->zstream.zfree = png_zfree;
  176974. png_ptr->zstream.opaque = (voidpf)png_ptr;
  176975. if (!(png_ptr->do_filter))
  176976. {
  176977. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  176978. png_ptr->bit_depth < 8)
  176979. png_ptr->do_filter = PNG_FILTER_NONE;
  176980. else
  176981. png_ptr->do_filter = PNG_ALL_FILTERS;
  176982. }
  176983. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  176984. {
  176985. if (png_ptr->do_filter != PNG_FILTER_NONE)
  176986. png_ptr->zlib_strategy = Z_FILTERED;
  176987. else
  176988. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  176989. }
  176990. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  176991. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  176992. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  176993. png_ptr->zlib_mem_level = 8;
  176994. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  176995. png_ptr->zlib_window_bits = 15;
  176996. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  176997. png_ptr->zlib_method = 8;
  176998. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  176999. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177000. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177001. png_error(png_ptr, "zlib failed to initialize compressor");
  177002. png_ptr->zstream.next_out = png_ptr->zbuf;
  177003. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177004. png_ptr->zstream.data_type = Z_BINARY;
  177005. png_ptr->mode = PNG_HAVE_IHDR;
  177006. }
  177007. void /* PRIVATE */
  177008. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177009. {
  177010. #ifdef PNG_USE_LOCAL_ARRAYS
  177011. PNG_PLTE;
  177012. #endif
  177013. png_uint_32 i;
  177014. png_colorp pal_ptr;
  177015. png_byte buf[3];
  177016. png_debug(1, "in png_write_PLTE\n");
  177017. if ((
  177018. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177019. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177020. #endif
  177021. num_pal == 0) || num_pal > 256)
  177022. {
  177023. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177024. {
  177025. png_error(png_ptr, "Invalid number of colors in palette");
  177026. }
  177027. else
  177028. {
  177029. png_warning(png_ptr, "Invalid number of colors in palette");
  177030. return;
  177031. }
  177032. }
  177033. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177034. {
  177035. png_warning(png_ptr,
  177036. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177037. return;
  177038. }
  177039. png_ptr->num_palette = (png_uint_16)num_pal;
  177040. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177041. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177042. #ifndef PNG_NO_POINTER_INDEXING
  177043. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177044. {
  177045. buf[0] = pal_ptr->red;
  177046. buf[1] = pal_ptr->green;
  177047. buf[2] = pal_ptr->blue;
  177048. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177049. }
  177050. #else
  177051. pal_ptr=palette;
  177052. for (i = 0; i < num_pal; i++)
  177053. {
  177054. buf[0] = pal_ptr[i].red;
  177055. buf[1] = pal_ptr[i].green;
  177056. buf[2] = pal_ptr[i].blue;
  177057. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177058. }
  177059. #endif
  177060. png_write_chunk_end(png_ptr);
  177061. png_ptr->mode |= PNG_HAVE_PLTE;
  177062. }
  177063. void /* PRIVATE */
  177064. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177065. {
  177066. #ifdef PNG_USE_LOCAL_ARRAYS
  177067. PNG_IDAT;
  177068. #endif
  177069. png_debug(1, "in png_write_IDAT\n");
  177070. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177071. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177072. {
  177073. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177074. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177075. {
  177076. if (length >= 2 &&
  177077. png_ptr->height < 16384 && png_ptr->width < 16384)
  177078. {
  177079. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177080. ((png_ptr->width *
  177081. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177082. unsigned int z_cinfo = z_cmf >> 4;
  177083. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177084. while (uncompressed_idat_size <= half_z_window_size &&
  177085. half_z_window_size >= 256)
  177086. {
  177087. z_cinfo--;
  177088. half_z_window_size >>= 1;
  177089. }
  177090. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177091. if (data[0] != (png_byte)z_cmf)
  177092. {
  177093. data[0] = (png_byte)z_cmf;
  177094. data[1] &= 0xe0;
  177095. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177096. }
  177097. }
  177098. }
  177099. else
  177100. png_error(png_ptr,
  177101. "Invalid zlib compression method or flags in IDAT");
  177102. }
  177103. png_write_chunk(png_ptr, png_IDAT, data, length);
  177104. png_ptr->mode |= PNG_HAVE_IDAT;
  177105. }
  177106. void /* PRIVATE */
  177107. png_write_IEND(png_structp png_ptr)
  177108. {
  177109. #ifdef PNG_USE_LOCAL_ARRAYS
  177110. PNG_IEND;
  177111. #endif
  177112. png_debug(1, "in png_write_IEND\n");
  177113. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177114. (png_size_t)0);
  177115. png_ptr->mode |= PNG_HAVE_IEND;
  177116. }
  177117. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177118. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177119. void /* PRIVATE */
  177120. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177121. {
  177122. #ifdef PNG_USE_LOCAL_ARRAYS
  177123. PNG_gAMA;
  177124. #endif
  177125. png_uint_32 igamma;
  177126. png_byte buf[4];
  177127. png_debug(1, "in png_write_gAMA\n");
  177128. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177129. png_save_uint_32(buf, igamma);
  177130. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177131. }
  177132. #endif
  177133. #ifdef PNG_FIXED_POINT_SUPPORTED
  177134. void /* PRIVATE */
  177135. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177136. {
  177137. #ifdef PNG_USE_LOCAL_ARRAYS
  177138. PNG_gAMA;
  177139. #endif
  177140. png_byte buf[4];
  177141. png_debug(1, "in png_write_gAMA\n");
  177142. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177143. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177144. }
  177145. #endif
  177146. #endif
  177147. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177148. void /* PRIVATE */
  177149. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177150. {
  177151. #ifdef PNG_USE_LOCAL_ARRAYS
  177152. PNG_sRGB;
  177153. #endif
  177154. png_byte buf[1];
  177155. png_debug(1, "in png_write_sRGB\n");
  177156. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177157. png_warning(png_ptr,
  177158. "Invalid sRGB rendering intent specified");
  177159. buf[0]=(png_byte)srgb_intent;
  177160. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177161. }
  177162. #endif
  177163. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177164. void /* PRIVATE */
  177165. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177166. png_charp profile, int profile_len)
  177167. {
  177168. #ifdef PNG_USE_LOCAL_ARRAYS
  177169. PNG_iCCP;
  177170. #endif
  177171. png_size_t name_len;
  177172. png_charp new_name;
  177173. compression_state comp;
  177174. int embedded_profile_len = 0;
  177175. png_debug(1, "in png_write_iCCP\n");
  177176. comp.num_output_ptr = 0;
  177177. comp.max_output_ptr = 0;
  177178. comp.output_ptr = NULL;
  177179. comp.input = NULL;
  177180. comp.input_len = 0;
  177181. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177182. &new_name)) == 0)
  177183. {
  177184. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177185. return;
  177186. }
  177187. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177188. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177189. if (profile == NULL)
  177190. profile_len = 0;
  177191. if (profile_len > 3)
  177192. embedded_profile_len =
  177193. ((*( (png_bytep)profile ))<<24) |
  177194. ((*( (png_bytep)profile+1))<<16) |
  177195. ((*( (png_bytep)profile+2))<< 8) |
  177196. ((*( (png_bytep)profile+3)) );
  177197. if (profile_len < embedded_profile_len)
  177198. {
  177199. png_warning(png_ptr,
  177200. "Embedded profile length too large in iCCP chunk");
  177201. return;
  177202. }
  177203. if (profile_len > embedded_profile_len)
  177204. {
  177205. png_warning(png_ptr,
  177206. "Truncating profile to actual length in iCCP chunk");
  177207. profile_len = embedded_profile_len;
  177208. }
  177209. if (profile_len)
  177210. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177211. PNG_COMPRESSION_TYPE_BASE, &comp);
  177212. png_write_chunk_start(png_ptr, png_iCCP,
  177213. (png_uint_32)name_len+profile_len+2);
  177214. new_name[name_len+1]=0x00;
  177215. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177216. if (profile_len)
  177217. png_write_compressed_data_out(png_ptr, &comp);
  177218. png_write_chunk_end(png_ptr);
  177219. png_free(png_ptr, new_name);
  177220. }
  177221. #endif
  177222. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177223. void /* PRIVATE */
  177224. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177225. {
  177226. #ifdef PNG_USE_LOCAL_ARRAYS
  177227. PNG_sPLT;
  177228. #endif
  177229. png_size_t name_len;
  177230. png_charp new_name;
  177231. png_byte entrybuf[10];
  177232. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177233. int palette_size = entry_size * spalette->nentries;
  177234. png_sPLT_entryp ep;
  177235. #ifdef PNG_NO_POINTER_INDEXING
  177236. int i;
  177237. #endif
  177238. png_debug(1, "in png_write_sPLT\n");
  177239. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177240. spalette->name, &new_name))==0)
  177241. {
  177242. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177243. return;
  177244. }
  177245. png_write_chunk_start(png_ptr, png_sPLT,
  177246. (png_uint_32)(name_len + 2 + palette_size));
  177247. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177248. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177249. #ifndef PNG_NO_POINTER_INDEXING
  177250. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177251. {
  177252. if (spalette->depth == 8)
  177253. {
  177254. entrybuf[0] = (png_byte)ep->red;
  177255. entrybuf[1] = (png_byte)ep->green;
  177256. entrybuf[2] = (png_byte)ep->blue;
  177257. entrybuf[3] = (png_byte)ep->alpha;
  177258. png_save_uint_16(entrybuf + 4, ep->frequency);
  177259. }
  177260. else
  177261. {
  177262. png_save_uint_16(entrybuf + 0, ep->red);
  177263. png_save_uint_16(entrybuf + 2, ep->green);
  177264. png_save_uint_16(entrybuf + 4, ep->blue);
  177265. png_save_uint_16(entrybuf + 6, ep->alpha);
  177266. png_save_uint_16(entrybuf + 8, ep->frequency);
  177267. }
  177268. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177269. }
  177270. #else
  177271. ep=spalette->entries;
  177272. for (i=0; i>spalette->nentries; i++)
  177273. {
  177274. if (spalette->depth == 8)
  177275. {
  177276. entrybuf[0] = (png_byte)ep[i].red;
  177277. entrybuf[1] = (png_byte)ep[i].green;
  177278. entrybuf[2] = (png_byte)ep[i].blue;
  177279. entrybuf[3] = (png_byte)ep[i].alpha;
  177280. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177281. }
  177282. else
  177283. {
  177284. png_save_uint_16(entrybuf + 0, ep[i].red);
  177285. png_save_uint_16(entrybuf + 2, ep[i].green);
  177286. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177287. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177288. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177289. }
  177290. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177291. }
  177292. #endif
  177293. png_write_chunk_end(png_ptr);
  177294. png_free(png_ptr, new_name);
  177295. }
  177296. #endif
  177297. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177298. void /* PRIVATE */
  177299. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177300. {
  177301. #ifdef PNG_USE_LOCAL_ARRAYS
  177302. PNG_sBIT;
  177303. #endif
  177304. png_byte buf[4];
  177305. png_size_t size;
  177306. png_debug(1, "in png_write_sBIT\n");
  177307. if (color_type & PNG_COLOR_MASK_COLOR)
  177308. {
  177309. png_byte maxbits;
  177310. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177311. png_ptr->usr_bit_depth);
  177312. if (sbit->red == 0 || sbit->red > maxbits ||
  177313. sbit->green == 0 || sbit->green > maxbits ||
  177314. sbit->blue == 0 || sbit->blue > maxbits)
  177315. {
  177316. png_warning(png_ptr, "Invalid sBIT depth specified");
  177317. return;
  177318. }
  177319. buf[0] = sbit->red;
  177320. buf[1] = sbit->green;
  177321. buf[2] = sbit->blue;
  177322. size = 3;
  177323. }
  177324. else
  177325. {
  177326. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177327. {
  177328. png_warning(png_ptr, "Invalid sBIT depth specified");
  177329. return;
  177330. }
  177331. buf[0] = sbit->gray;
  177332. size = 1;
  177333. }
  177334. if (color_type & PNG_COLOR_MASK_ALPHA)
  177335. {
  177336. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177337. {
  177338. png_warning(png_ptr, "Invalid sBIT depth specified");
  177339. return;
  177340. }
  177341. buf[size++] = sbit->alpha;
  177342. }
  177343. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177344. }
  177345. #endif
  177346. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177347. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177348. void /* PRIVATE */
  177349. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177350. double red_x, double red_y, double green_x, double green_y,
  177351. double blue_x, double blue_y)
  177352. {
  177353. #ifdef PNG_USE_LOCAL_ARRAYS
  177354. PNG_cHRM;
  177355. #endif
  177356. png_byte buf[32];
  177357. png_uint_32 itemp;
  177358. png_debug(1, "in png_write_cHRM\n");
  177359. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177360. white_x + white_y > 1.0)
  177361. {
  177362. png_warning(png_ptr, "Invalid cHRM white point specified");
  177363. #if !defined(PNG_NO_CONSOLE_IO)
  177364. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177365. #endif
  177366. return;
  177367. }
  177368. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177369. png_save_uint_32(buf, itemp);
  177370. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177371. png_save_uint_32(buf + 4, itemp);
  177372. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177373. {
  177374. png_warning(png_ptr, "Invalid cHRM red point specified");
  177375. return;
  177376. }
  177377. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177378. png_save_uint_32(buf + 8, itemp);
  177379. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177380. png_save_uint_32(buf + 12, itemp);
  177381. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177382. {
  177383. png_warning(png_ptr, "Invalid cHRM green point specified");
  177384. return;
  177385. }
  177386. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177387. png_save_uint_32(buf + 16, itemp);
  177388. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177389. png_save_uint_32(buf + 20, itemp);
  177390. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177391. {
  177392. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177393. return;
  177394. }
  177395. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177396. png_save_uint_32(buf + 24, itemp);
  177397. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177398. png_save_uint_32(buf + 28, itemp);
  177399. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177400. }
  177401. #endif
  177402. #ifdef PNG_FIXED_POINT_SUPPORTED
  177403. void /* PRIVATE */
  177404. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177405. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177406. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177407. png_fixed_point blue_y)
  177408. {
  177409. #ifdef PNG_USE_LOCAL_ARRAYS
  177410. PNG_cHRM;
  177411. #endif
  177412. png_byte buf[32];
  177413. png_debug(1, "in png_write_cHRM\n");
  177414. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177415. {
  177416. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177417. #if !defined(PNG_NO_CONSOLE_IO)
  177418. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177419. #endif
  177420. return;
  177421. }
  177422. png_save_uint_32(buf, (png_uint_32)white_x);
  177423. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177424. if (red_x + red_y > 100000L)
  177425. {
  177426. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177427. return;
  177428. }
  177429. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177430. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177431. if (green_x + green_y > 100000L)
  177432. {
  177433. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177434. return;
  177435. }
  177436. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177437. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177438. if (blue_x + blue_y > 100000L)
  177439. {
  177440. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177441. return;
  177442. }
  177443. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177444. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177445. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177446. }
  177447. #endif
  177448. #endif
  177449. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177450. void /* PRIVATE */
  177451. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177452. int num_trans, int color_type)
  177453. {
  177454. #ifdef PNG_USE_LOCAL_ARRAYS
  177455. PNG_tRNS;
  177456. #endif
  177457. png_byte buf[6];
  177458. png_debug(1, "in png_write_tRNS\n");
  177459. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177460. {
  177461. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177462. {
  177463. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177464. return;
  177465. }
  177466. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177467. }
  177468. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177469. {
  177470. if(tran->gray >= (1 << png_ptr->bit_depth))
  177471. {
  177472. png_warning(png_ptr,
  177473. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177474. return;
  177475. }
  177476. png_save_uint_16(buf, tran->gray);
  177477. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177478. }
  177479. else if (color_type == PNG_COLOR_TYPE_RGB)
  177480. {
  177481. png_save_uint_16(buf, tran->red);
  177482. png_save_uint_16(buf + 2, tran->green);
  177483. png_save_uint_16(buf + 4, tran->blue);
  177484. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177485. {
  177486. png_warning(png_ptr,
  177487. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177488. return;
  177489. }
  177490. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177491. }
  177492. else
  177493. {
  177494. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177495. }
  177496. }
  177497. #endif
  177498. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177499. void /* PRIVATE */
  177500. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177501. {
  177502. #ifdef PNG_USE_LOCAL_ARRAYS
  177503. PNG_bKGD;
  177504. #endif
  177505. png_byte buf[6];
  177506. png_debug(1, "in png_write_bKGD\n");
  177507. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177508. {
  177509. if (
  177510. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177511. (png_ptr->num_palette ||
  177512. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177513. #endif
  177514. back->index > png_ptr->num_palette)
  177515. {
  177516. png_warning(png_ptr, "Invalid background palette index");
  177517. return;
  177518. }
  177519. buf[0] = back->index;
  177520. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177521. }
  177522. else if (color_type & PNG_COLOR_MASK_COLOR)
  177523. {
  177524. png_save_uint_16(buf, back->red);
  177525. png_save_uint_16(buf + 2, back->green);
  177526. png_save_uint_16(buf + 4, back->blue);
  177527. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177528. {
  177529. png_warning(png_ptr,
  177530. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177531. return;
  177532. }
  177533. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177534. }
  177535. else
  177536. {
  177537. if(back->gray >= (1 << png_ptr->bit_depth))
  177538. {
  177539. png_warning(png_ptr,
  177540. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177541. return;
  177542. }
  177543. png_save_uint_16(buf, back->gray);
  177544. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177545. }
  177546. }
  177547. #endif
  177548. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177549. void /* PRIVATE */
  177550. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177551. {
  177552. #ifdef PNG_USE_LOCAL_ARRAYS
  177553. PNG_hIST;
  177554. #endif
  177555. int i;
  177556. png_byte buf[3];
  177557. png_debug(1, "in png_write_hIST\n");
  177558. if (num_hist > (int)png_ptr->num_palette)
  177559. {
  177560. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177561. png_ptr->num_palette);
  177562. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177563. return;
  177564. }
  177565. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177566. for (i = 0; i < num_hist; i++)
  177567. {
  177568. png_save_uint_16(buf, hist[i]);
  177569. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177570. }
  177571. png_write_chunk_end(png_ptr);
  177572. }
  177573. #endif
  177574. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177575. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177576. png_size_t /* PRIVATE */
  177577. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177578. {
  177579. png_size_t key_len;
  177580. png_charp kp, dp;
  177581. int kflag;
  177582. int kwarn=0;
  177583. png_debug(1, "in png_check_keyword\n");
  177584. *new_key = NULL;
  177585. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177586. {
  177587. png_warning(png_ptr, "zero length keyword");
  177588. return ((png_size_t)0);
  177589. }
  177590. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177591. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177592. if (*new_key == NULL)
  177593. {
  177594. png_warning(png_ptr, "Out of memory while procesing keyword");
  177595. return ((png_size_t)0);
  177596. }
  177597. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177598. {
  177599. if ((png_byte)*kp < 0x20 ||
  177600. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177601. {
  177602. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177603. char msg[40];
  177604. png_snprintf(msg, 40,
  177605. "invalid keyword character 0x%02X", (png_byte)*kp);
  177606. png_warning(png_ptr, msg);
  177607. #else
  177608. png_warning(png_ptr, "invalid character in keyword");
  177609. #endif
  177610. *dp = ' ';
  177611. }
  177612. else
  177613. {
  177614. *dp = *kp;
  177615. }
  177616. }
  177617. *dp = '\0';
  177618. kp = *new_key + key_len - 1;
  177619. if (*kp == ' ')
  177620. {
  177621. png_warning(png_ptr, "trailing spaces removed from keyword");
  177622. while (*kp == ' ')
  177623. {
  177624. *(kp--) = '\0';
  177625. key_len--;
  177626. }
  177627. }
  177628. kp = *new_key;
  177629. if (*kp == ' ')
  177630. {
  177631. png_warning(png_ptr, "leading spaces removed from keyword");
  177632. while (*kp == ' ')
  177633. {
  177634. kp++;
  177635. key_len--;
  177636. }
  177637. }
  177638. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177639. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177640. {
  177641. if (*kp == ' ' && kflag == 0)
  177642. {
  177643. *(dp++) = *kp;
  177644. kflag = 1;
  177645. }
  177646. else if (*kp == ' ')
  177647. {
  177648. key_len--;
  177649. kwarn=1;
  177650. }
  177651. else
  177652. {
  177653. *(dp++) = *kp;
  177654. kflag = 0;
  177655. }
  177656. }
  177657. *dp = '\0';
  177658. if(kwarn)
  177659. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177660. if (key_len == 0)
  177661. {
  177662. png_free(png_ptr, *new_key);
  177663. *new_key=NULL;
  177664. png_warning(png_ptr, "Zero length keyword");
  177665. }
  177666. if (key_len > 79)
  177667. {
  177668. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177669. new_key[79] = '\0';
  177670. key_len = 79;
  177671. }
  177672. return (key_len);
  177673. }
  177674. #endif
  177675. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177676. void /* PRIVATE */
  177677. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177678. png_size_t text_len)
  177679. {
  177680. #ifdef PNG_USE_LOCAL_ARRAYS
  177681. PNG_tEXt;
  177682. #endif
  177683. png_size_t key_len;
  177684. png_charp new_key;
  177685. png_debug(1, "in png_write_tEXt\n");
  177686. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177687. {
  177688. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177689. return;
  177690. }
  177691. if (text == NULL || *text == '\0')
  177692. text_len = 0;
  177693. else
  177694. text_len = png_strlen(text);
  177695. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177696. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177697. if (text_len)
  177698. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177699. png_write_chunk_end(png_ptr);
  177700. png_free(png_ptr, new_key);
  177701. }
  177702. #endif
  177703. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177704. void /* PRIVATE */
  177705. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177706. png_size_t text_len, int compression)
  177707. {
  177708. #ifdef PNG_USE_LOCAL_ARRAYS
  177709. PNG_zTXt;
  177710. #endif
  177711. png_size_t key_len;
  177712. char buf[1];
  177713. png_charp new_key;
  177714. compression_state comp;
  177715. png_debug(1, "in png_write_zTXt\n");
  177716. comp.num_output_ptr = 0;
  177717. comp.max_output_ptr = 0;
  177718. comp.output_ptr = NULL;
  177719. comp.input = NULL;
  177720. comp.input_len = 0;
  177721. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177722. {
  177723. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177724. return;
  177725. }
  177726. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177727. {
  177728. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177729. png_free(png_ptr, new_key);
  177730. return;
  177731. }
  177732. text_len = png_strlen(text);
  177733. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177734. &comp);
  177735. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177736. (key_len+text_len+2));
  177737. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177738. png_free(png_ptr, new_key);
  177739. buf[0] = (png_byte)compression;
  177740. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177741. png_write_compressed_data_out(png_ptr, &comp);
  177742. png_write_chunk_end(png_ptr);
  177743. }
  177744. #endif
  177745. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177746. void /* PRIVATE */
  177747. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177748. png_charp lang, png_charp lang_key, png_charp text)
  177749. {
  177750. #ifdef PNG_USE_LOCAL_ARRAYS
  177751. PNG_iTXt;
  177752. #endif
  177753. png_size_t lang_len, key_len, lang_key_len, text_len;
  177754. png_charp new_lang, new_key;
  177755. png_byte cbuf[2];
  177756. compression_state comp;
  177757. png_debug(1, "in png_write_iTXt\n");
  177758. comp.num_output_ptr = 0;
  177759. comp.max_output_ptr = 0;
  177760. comp.output_ptr = NULL;
  177761. comp.input = NULL;
  177762. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177763. {
  177764. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177765. return;
  177766. }
  177767. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177768. {
  177769. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177770. new_lang = NULL;
  177771. lang_len = 0;
  177772. }
  177773. if (lang_key == NULL)
  177774. lang_key_len = 0;
  177775. else
  177776. lang_key_len = png_strlen(lang_key);
  177777. if (text == NULL)
  177778. text_len = 0;
  177779. else
  177780. text_len = png_strlen(text);
  177781. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177782. &comp);
  177783. png_write_chunk_start(png_ptr, png_iTXt,
  177784. (png_uint_32)(
  177785. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177786. + key_len
  177787. + lang_len
  177788. + lang_key_len
  177789. + text_len));
  177790. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177791. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177792. compression == PNG_TEXT_COMPRESSION_NONE)
  177793. cbuf[0] = 0;
  177794. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177795. cbuf[0] = 1;
  177796. cbuf[1] = 0;
  177797. png_write_chunk_data(png_ptr, cbuf, 2);
  177798. cbuf[0] = 0;
  177799. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177800. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177801. png_write_compressed_data_out(png_ptr, &comp);
  177802. png_write_chunk_end(png_ptr);
  177803. png_free(png_ptr, new_key);
  177804. if (new_lang)
  177805. png_free(png_ptr, new_lang);
  177806. }
  177807. #endif
  177808. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177809. void /* PRIVATE */
  177810. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177811. int unit_type)
  177812. {
  177813. #ifdef PNG_USE_LOCAL_ARRAYS
  177814. PNG_oFFs;
  177815. #endif
  177816. png_byte buf[9];
  177817. png_debug(1, "in png_write_oFFs\n");
  177818. if (unit_type >= PNG_OFFSET_LAST)
  177819. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  177820. png_save_int_32(buf, x_offset);
  177821. png_save_int_32(buf + 4, y_offset);
  177822. buf[8] = (png_byte)unit_type;
  177823. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  177824. }
  177825. #endif
  177826. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  177827. void /* PRIVATE */
  177828. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  177829. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  177830. {
  177831. #ifdef PNG_USE_LOCAL_ARRAYS
  177832. PNG_pCAL;
  177833. #endif
  177834. png_size_t purpose_len, units_len, total_len;
  177835. png_uint_32p params_len;
  177836. png_byte buf[10];
  177837. png_charp new_purpose;
  177838. int i;
  177839. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  177840. if (type >= PNG_EQUATION_LAST)
  177841. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  177842. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  177843. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  177844. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  177845. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  177846. total_len = purpose_len + units_len + 10;
  177847. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  177848. *png_sizeof(png_uint_32)));
  177849. for (i = 0; i < nparams; i++)
  177850. {
  177851. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  177852. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  177853. total_len += (png_size_t)params_len[i];
  177854. }
  177855. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  177856. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  177857. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  177858. png_save_int_32(buf, X0);
  177859. png_save_int_32(buf + 4, X1);
  177860. buf[8] = (png_byte)type;
  177861. buf[9] = (png_byte)nparams;
  177862. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  177863. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  177864. png_free(png_ptr, new_purpose);
  177865. for (i = 0; i < nparams; i++)
  177866. {
  177867. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  177868. (png_size_t)params_len[i]);
  177869. }
  177870. png_free(png_ptr, params_len);
  177871. png_write_chunk_end(png_ptr);
  177872. }
  177873. #endif
  177874. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  177875. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  177876. void /* PRIVATE */
  177877. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  177878. {
  177879. #ifdef PNG_USE_LOCAL_ARRAYS
  177880. PNG_sCAL;
  177881. #endif
  177882. char buf[64];
  177883. png_size_t total_len;
  177884. png_debug(1, "in png_write_sCAL\n");
  177885. buf[0] = (char)unit;
  177886. #if defined(_WIN32_WCE)
  177887. {
  177888. wchar_t wc_buf[32];
  177889. size_t wc_len;
  177890. swprintf(wc_buf, TEXT("%12.12e"), width);
  177891. wc_len = wcslen(wc_buf);
  177892. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  177893. total_len = wc_len + 2;
  177894. swprintf(wc_buf, TEXT("%12.12e"), height);
  177895. wc_len = wcslen(wc_buf);
  177896. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  177897. NULL, NULL);
  177898. total_len += wc_len;
  177899. }
  177900. #else
  177901. png_snprintf(buf + 1, 63, "%12.12e", width);
  177902. total_len = 1 + png_strlen(buf + 1) + 1;
  177903. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  177904. total_len += png_strlen(buf + total_len);
  177905. #endif
  177906. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  177907. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  177908. }
  177909. #else
  177910. #ifdef PNG_FIXED_POINT_SUPPORTED
  177911. void /* PRIVATE */
  177912. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  177913. png_charp height)
  177914. {
  177915. #ifdef PNG_USE_LOCAL_ARRAYS
  177916. PNG_sCAL;
  177917. #endif
  177918. png_byte buf[64];
  177919. png_size_t wlen, hlen, total_len;
  177920. png_debug(1, "in png_write_sCAL_s\n");
  177921. wlen = png_strlen(width);
  177922. hlen = png_strlen(height);
  177923. total_len = wlen + hlen + 2;
  177924. if (total_len > 64)
  177925. {
  177926. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  177927. return;
  177928. }
  177929. buf[0] = (png_byte)unit;
  177930. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  177931. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  177932. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  177933. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  177934. }
  177935. #endif
  177936. #endif
  177937. #endif
  177938. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  177939. void /* PRIVATE */
  177940. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  177941. png_uint_32 y_pixels_per_unit,
  177942. int unit_type)
  177943. {
  177944. #ifdef PNG_USE_LOCAL_ARRAYS
  177945. PNG_pHYs;
  177946. #endif
  177947. png_byte buf[9];
  177948. png_debug(1, "in png_write_pHYs\n");
  177949. if (unit_type >= PNG_RESOLUTION_LAST)
  177950. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  177951. png_save_uint_32(buf, x_pixels_per_unit);
  177952. png_save_uint_32(buf + 4, y_pixels_per_unit);
  177953. buf[8] = (png_byte)unit_type;
  177954. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  177955. }
  177956. #endif
  177957. #if defined(PNG_WRITE_tIME_SUPPORTED)
  177958. void /* PRIVATE */
  177959. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  177960. {
  177961. #ifdef PNG_USE_LOCAL_ARRAYS
  177962. PNG_tIME;
  177963. #endif
  177964. png_byte buf[7];
  177965. png_debug(1, "in png_write_tIME\n");
  177966. if (mod_time->month > 12 || mod_time->month < 1 ||
  177967. mod_time->day > 31 || mod_time->day < 1 ||
  177968. mod_time->hour > 23 || mod_time->second > 60)
  177969. {
  177970. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  177971. return;
  177972. }
  177973. png_save_uint_16(buf, mod_time->year);
  177974. buf[2] = mod_time->month;
  177975. buf[3] = mod_time->day;
  177976. buf[4] = mod_time->hour;
  177977. buf[5] = mod_time->minute;
  177978. buf[6] = mod_time->second;
  177979. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  177980. }
  177981. #endif
  177982. void /* PRIVATE */
  177983. png_write_start_row(png_structp png_ptr)
  177984. {
  177985. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177986. #ifdef PNG_USE_LOCAL_ARRAYS
  177987. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  177988. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  177989. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  177990. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  177991. #endif
  177992. #endif
  177993. png_size_t buf_size;
  177994. png_debug(1, "in png_write_start_row\n");
  177995. buf_size = (png_size_t)(PNG_ROWBYTES(
  177996. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  177997. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  177998. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  177999. #ifndef PNG_NO_WRITE_FILTERING
  178000. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178001. {
  178002. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178003. (png_ptr->rowbytes + 1));
  178004. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178005. }
  178006. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178007. {
  178008. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178009. png_memset(png_ptr->prev_row, 0, buf_size);
  178010. if (png_ptr->do_filter & PNG_FILTER_UP)
  178011. {
  178012. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178013. (png_ptr->rowbytes + 1));
  178014. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178015. }
  178016. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178017. {
  178018. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178019. (png_ptr->rowbytes + 1));
  178020. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178021. }
  178022. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178023. {
  178024. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178025. (png_ptr->rowbytes + 1));
  178026. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178027. }
  178028. #endif /* PNG_NO_WRITE_FILTERING */
  178029. }
  178030. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178031. if (png_ptr->interlaced)
  178032. {
  178033. if (!(png_ptr->transformations & PNG_INTERLACE))
  178034. {
  178035. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178036. png_pass_ystart[0]) / png_pass_yinc[0];
  178037. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178038. png_pass_start[0]) / png_pass_inc[0];
  178039. }
  178040. else
  178041. {
  178042. png_ptr->num_rows = png_ptr->height;
  178043. png_ptr->usr_width = png_ptr->width;
  178044. }
  178045. }
  178046. else
  178047. #endif
  178048. {
  178049. png_ptr->num_rows = png_ptr->height;
  178050. png_ptr->usr_width = png_ptr->width;
  178051. }
  178052. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178053. png_ptr->zstream.next_out = png_ptr->zbuf;
  178054. }
  178055. void /* PRIVATE */
  178056. png_write_finish_row(png_structp png_ptr)
  178057. {
  178058. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178059. #ifdef PNG_USE_LOCAL_ARRAYS
  178060. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178061. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178062. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178063. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178064. #endif
  178065. #endif
  178066. int ret;
  178067. png_debug(1, "in png_write_finish_row\n");
  178068. png_ptr->row_number++;
  178069. if (png_ptr->row_number < png_ptr->num_rows)
  178070. return;
  178071. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178072. if (png_ptr->interlaced)
  178073. {
  178074. png_ptr->row_number = 0;
  178075. if (png_ptr->transformations & PNG_INTERLACE)
  178076. {
  178077. png_ptr->pass++;
  178078. }
  178079. else
  178080. {
  178081. do
  178082. {
  178083. png_ptr->pass++;
  178084. if (png_ptr->pass >= 7)
  178085. break;
  178086. png_ptr->usr_width = (png_ptr->width +
  178087. png_pass_inc[png_ptr->pass] - 1 -
  178088. png_pass_start[png_ptr->pass]) /
  178089. png_pass_inc[png_ptr->pass];
  178090. png_ptr->num_rows = (png_ptr->height +
  178091. png_pass_yinc[png_ptr->pass] - 1 -
  178092. png_pass_ystart[png_ptr->pass]) /
  178093. png_pass_yinc[png_ptr->pass];
  178094. if (png_ptr->transformations & PNG_INTERLACE)
  178095. break;
  178096. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178097. }
  178098. if (png_ptr->pass < 7)
  178099. {
  178100. if (png_ptr->prev_row != NULL)
  178101. png_memset(png_ptr->prev_row, 0,
  178102. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178103. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178104. return;
  178105. }
  178106. }
  178107. #endif
  178108. do
  178109. {
  178110. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178111. if (ret == Z_OK)
  178112. {
  178113. if (!(png_ptr->zstream.avail_out))
  178114. {
  178115. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178116. png_ptr->zstream.next_out = png_ptr->zbuf;
  178117. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178118. }
  178119. }
  178120. else if (ret != Z_STREAM_END)
  178121. {
  178122. if (png_ptr->zstream.msg != NULL)
  178123. png_error(png_ptr, png_ptr->zstream.msg);
  178124. else
  178125. png_error(png_ptr, "zlib error");
  178126. }
  178127. } while (ret != Z_STREAM_END);
  178128. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178129. {
  178130. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178131. png_ptr->zstream.avail_out);
  178132. }
  178133. deflateReset(&png_ptr->zstream);
  178134. png_ptr->zstream.data_type = Z_BINARY;
  178135. }
  178136. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178137. void /* PRIVATE */
  178138. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178139. {
  178140. #ifdef PNG_USE_LOCAL_ARRAYS
  178141. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178142. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178143. #endif
  178144. png_debug(1, "in png_do_write_interlace\n");
  178145. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178146. if (row != NULL && row_info != NULL && pass < 6)
  178147. #else
  178148. if (pass < 6)
  178149. #endif
  178150. {
  178151. switch (row_info->pixel_depth)
  178152. {
  178153. case 1:
  178154. {
  178155. png_bytep sp;
  178156. png_bytep dp;
  178157. int shift;
  178158. int d;
  178159. int value;
  178160. png_uint_32 i;
  178161. png_uint_32 row_width = row_info->width;
  178162. dp = row;
  178163. d = 0;
  178164. shift = 7;
  178165. for (i = png_pass_start[pass]; i < row_width;
  178166. i += png_pass_inc[pass])
  178167. {
  178168. sp = row + (png_size_t)(i >> 3);
  178169. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178170. d |= (value << shift);
  178171. if (shift == 0)
  178172. {
  178173. shift = 7;
  178174. *dp++ = (png_byte)d;
  178175. d = 0;
  178176. }
  178177. else
  178178. shift--;
  178179. }
  178180. if (shift != 7)
  178181. *dp = (png_byte)d;
  178182. break;
  178183. }
  178184. case 2:
  178185. {
  178186. png_bytep sp;
  178187. png_bytep dp;
  178188. int shift;
  178189. int d;
  178190. int value;
  178191. png_uint_32 i;
  178192. png_uint_32 row_width = row_info->width;
  178193. dp = row;
  178194. shift = 6;
  178195. d = 0;
  178196. for (i = png_pass_start[pass]; i < row_width;
  178197. i += png_pass_inc[pass])
  178198. {
  178199. sp = row + (png_size_t)(i >> 2);
  178200. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178201. d |= (value << shift);
  178202. if (shift == 0)
  178203. {
  178204. shift = 6;
  178205. *dp++ = (png_byte)d;
  178206. d = 0;
  178207. }
  178208. else
  178209. shift -= 2;
  178210. }
  178211. if (shift != 6)
  178212. *dp = (png_byte)d;
  178213. break;
  178214. }
  178215. case 4:
  178216. {
  178217. png_bytep sp;
  178218. png_bytep dp;
  178219. int shift;
  178220. int d;
  178221. int value;
  178222. png_uint_32 i;
  178223. png_uint_32 row_width = row_info->width;
  178224. dp = row;
  178225. shift = 4;
  178226. d = 0;
  178227. for (i = png_pass_start[pass]; i < row_width;
  178228. i += png_pass_inc[pass])
  178229. {
  178230. sp = row + (png_size_t)(i >> 1);
  178231. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178232. d |= (value << shift);
  178233. if (shift == 0)
  178234. {
  178235. shift = 4;
  178236. *dp++ = (png_byte)d;
  178237. d = 0;
  178238. }
  178239. else
  178240. shift -= 4;
  178241. }
  178242. if (shift != 4)
  178243. *dp = (png_byte)d;
  178244. break;
  178245. }
  178246. default:
  178247. {
  178248. png_bytep sp;
  178249. png_bytep dp;
  178250. png_uint_32 i;
  178251. png_uint_32 row_width = row_info->width;
  178252. png_size_t pixel_bytes;
  178253. dp = row;
  178254. pixel_bytes = (row_info->pixel_depth >> 3);
  178255. for (i = png_pass_start[pass]; i < row_width;
  178256. i += png_pass_inc[pass])
  178257. {
  178258. sp = row + (png_size_t)i * pixel_bytes;
  178259. if (dp != sp)
  178260. png_memcpy(dp, sp, pixel_bytes);
  178261. dp += pixel_bytes;
  178262. }
  178263. break;
  178264. }
  178265. }
  178266. row_info->width = (row_info->width +
  178267. png_pass_inc[pass] - 1 -
  178268. png_pass_start[pass]) /
  178269. png_pass_inc[pass];
  178270. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178271. row_info->width);
  178272. }
  178273. }
  178274. #endif
  178275. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178276. #define PNG_HISHIFT 10
  178277. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178278. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178279. void /* PRIVATE */
  178280. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178281. {
  178282. png_bytep best_row;
  178283. #ifndef PNG_NO_WRITE_FILTER
  178284. png_bytep prev_row, row_buf;
  178285. png_uint_32 mins, bpp;
  178286. png_byte filter_to_do = png_ptr->do_filter;
  178287. png_uint_32 row_bytes = row_info->rowbytes;
  178288. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178289. int num_p_filters = (int)png_ptr->num_prev_filters;
  178290. #endif
  178291. png_debug(1, "in png_write_find_filter\n");
  178292. bpp = (row_info->pixel_depth + 7) >> 3;
  178293. prev_row = png_ptr->prev_row;
  178294. #endif
  178295. best_row = png_ptr->row_buf;
  178296. #ifndef PNG_NO_WRITE_FILTER
  178297. row_buf = best_row;
  178298. mins = PNG_MAXSUM;
  178299. if ((filter_to_do & PNG_FILTER_NONE) &&
  178300. filter_to_do != PNG_FILTER_NONE)
  178301. {
  178302. png_bytep rp;
  178303. png_uint_32 sum = 0;
  178304. png_uint_32 i;
  178305. int v;
  178306. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178307. {
  178308. v = *rp;
  178309. sum += (v < 128) ? v : 256 - v;
  178310. }
  178311. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178312. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178313. {
  178314. png_uint_32 sumhi, sumlo;
  178315. int j;
  178316. sumlo = sum & PNG_LOMASK;
  178317. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178318. for (j = 0; j < num_p_filters; j++)
  178319. {
  178320. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178321. {
  178322. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178323. PNG_WEIGHT_SHIFT;
  178324. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178325. PNG_WEIGHT_SHIFT;
  178326. }
  178327. }
  178328. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178329. PNG_COST_SHIFT;
  178330. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178331. PNG_COST_SHIFT;
  178332. if (sumhi > PNG_HIMASK)
  178333. sum = PNG_MAXSUM;
  178334. else
  178335. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178336. }
  178337. #endif
  178338. mins = sum;
  178339. }
  178340. if (filter_to_do == PNG_FILTER_SUB)
  178341. {
  178342. png_bytep rp, lp, dp;
  178343. png_uint_32 i;
  178344. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178345. i++, rp++, dp++)
  178346. {
  178347. *dp = *rp;
  178348. }
  178349. for (lp = row_buf + 1; i < row_bytes;
  178350. i++, rp++, lp++, dp++)
  178351. {
  178352. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178353. }
  178354. best_row = png_ptr->sub_row;
  178355. }
  178356. else if (filter_to_do & PNG_FILTER_SUB)
  178357. {
  178358. png_bytep rp, dp, lp;
  178359. png_uint_32 sum = 0, lmins = mins;
  178360. png_uint_32 i;
  178361. int v;
  178362. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178363. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178364. {
  178365. int j;
  178366. png_uint_32 lmhi, lmlo;
  178367. lmlo = lmins & PNG_LOMASK;
  178368. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178369. for (j = 0; j < num_p_filters; j++)
  178370. {
  178371. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178372. {
  178373. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178374. PNG_WEIGHT_SHIFT;
  178375. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178376. PNG_WEIGHT_SHIFT;
  178377. }
  178378. }
  178379. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178380. PNG_COST_SHIFT;
  178381. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178382. PNG_COST_SHIFT;
  178383. if (lmhi > PNG_HIMASK)
  178384. lmins = PNG_MAXSUM;
  178385. else
  178386. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178387. }
  178388. #endif
  178389. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178390. i++, rp++, dp++)
  178391. {
  178392. v = *dp = *rp;
  178393. sum += (v < 128) ? v : 256 - v;
  178394. }
  178395. for (lp = row_buf + 1; i < row_bytes;
  178396. i++, rp++, lp++, dp++)
  178397. {
  178398. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178399. sum += (v < 128) ? v : 256 - v;
  178400. if (sum > lmins) /* We are already worse, don't continue. */
  178401. break;
  178402. }
  178403. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178404. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178405. {
  178406. int j;
  178407. png_uint_32 sumhi, sumlo;
  178408. sumlo = sum & PNG_LOMASK;
  178409. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178410. for (j = 0; j < num_p_filters; j++)
  178411. {
  178412. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178413. {
  178414. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178415. PNG_WEIGHT_SHIFT;
  178416. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178417. PNG_WEIGHT_SHIFT;
  178418. }
  178419. }
  178420. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178421. PNG_COST_SHIFT;
  178422. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178423. PNG_COST_SHIFT;
  178424. if (sumhi > PNG_HIMASK)
  178425. sum = PNG_MAXSUM;
  178426. else
  178427. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178428. }
  178429. #endif
  178430. if (sum < mins)
  178431. {
  178432. mins = sum;
  178433. best_row = png_ptr->sub_row;
  178434. }
  178435. }
  178436. if (filter_to_do == PNG_FILTER_UP)
  178437. {
  178438. png_bytep rp, dp, pp;
  178439. png_uint_32 i;
  178440. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178441. pp = prev_row + 1; i < row_bytes;
  178442. i++, rp++, pp++, dp++)
  178443. {
  178444. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178445. }
  178446. best_row = png_ptr->up_row;
  178447. }
  178448. else if (filter_to_do & PNG_FILTER_UP)
  178449. {
  178450. png_bytep rp, dp, pp;
  178451. png_uint_32 sum = 0, lmins = mins;
  178452. png_uint_32 i;
  178453. int v;
  178454. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178455. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178456. {
  178457. int j;
  178458. png_uint_32 lmhi, lmlo;
  178459. lmlo = lmins & PNG_LOMASK;
  178460. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178461. for (j = 0; j < num_p_filters; j++)
  178462. {
  178463. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178464. {
  178465. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178466. PNG_WEIGHT_SHIFT;
  178467. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178468. PNG_WEIGHT_SHIFT;
  178469. }
  178470. }
  178471. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178472. PNG_COST_SHIFT;
  178473. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178474. PNG_COST_SHIFT;
  178475. if (lmhi > PNG_HIMASK)
  178476. lmins = PNG_MAXSUM;
  178477. else
  178478. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178479. }
  178480. #endif
  178481. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178482. pp = prev_row + 1; i < row_bytes; i++)
  178483. {
  178484. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178485. sum += (v < 128) ? v : 256 - v;
  178486. if (sum > lmins) /* We are already worse, don't continue. */
  178487. break;
  178488. }
  178489. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178490. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178491. {
  178492. int j;
  178493. png_uint_32 sumhi, sumlo;
  178494. sumlo = sum & PNG_LOMASK;
  178495. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178496. for (j = 0; j < num_p_filters; j++)
  178497. {
  178498. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178499. {
  178500. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178501. PNG_WEIGHT_SHIFT;
  178502. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178503. PNG_WEIGHT_SHIFT;
  178504. }
  178505. }
  178506. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178507. PNG_COST_SHIFT;
  178508. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178509. PNG_COST_SHIFT;
  178510. if (sumhi > PNG_HIMASK)
  178511. sum = PNG_MAXSUM;
  178512. else
  178513. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178514. }
  178515. #endif
  178516. if (sum < mins)
  178517. {
  178518. mins = sum;
  178519. best_row = png_ptr->up_row;
  178520. }
  178521. }
  178522. if (filter_to_do == PNG_FILTER_AVG)
  178523. {
  178524. png_bytep rp, dp, pp, lp;
  178525. png_uint_32 i;
  178526. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178527. pp = prev_row + 1; i < bpp; i++)
  178528. {
  178529. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178530. }
  178531. for (lp = row_buf + 1; i < row_bytes; i++)
  178532. {
  178533. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178534. & 0xff);
  178535. }
  178536. best_row = png_ptr->avg_row;
  178537. }
  178538. else if (filter_to_do & PNG_FILTER_AVG)
  178539. {
  178540. png_bytep rp, dp, pp, lp;
  178541. png_uint_32 sum = 0, lmins = mins;
  178542. png_uint_32 i;
  178543. int v;
  178544. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178545. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178546. {
  178547. int j;
  178548. png_uint_32 lmhi, lmlo;
  178549. lmlo = lmins & PNG_LOMASK;
  178550. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178551. for (j = 0; j < num_p_filters; j++)
  178552. {
  178553. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178554. {
  178555. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178556. PNG_WEIGHT_SHIFT;
  178557. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178558. PNG_WEIGHT_SHIFT;
  178559. }
  178560. }
  178561. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178562. PNG_COST_SHIFT;
  178563. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178564. PNG_COST_SHIFT;
  178565. if (lmhi > PNG_HIMASK)
  178566. lmins = PNG_MAXSUM;
  178567. else
  178568. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178569. }
  178570. #endif
  178571. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178572. pp = prev_row + 1; i < bpp; i++)
  178573. {
  178574. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178575. sum += (v < 128) ? v : 256 - v;
  178576. }
  178577. for (lp = row_buf + 1; i < row_bytes; i++)
  178578. {
  178579. v = *dp++ =
  178580. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178581. sum += (v < 128) ? v : 256 - v;
  178582. if (sum > lmins) /* We are already worse, don't continue. */
  178583. break;
  178584. }
  178585. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178586. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178587. {
  178588. int j;
  178589. png_uint_32 sumhi, sumlo;
  178590. sumlo = sum & PNG_LOMASK;
  178591. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178592. for (j = 0; j < num_p_filters; j++)
  178593. {
  178594. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178595. {
  178596. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178597. PNG_WEIGHT_SHIFT;
  178598. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178599. PNG_WEIGHT_SHIFT;
  178600. }
  178601. }
  178602. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178603. PNG_COST_SHIFT;
  178604. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178605. PNG_COST_SHIFT;
  178606. if (sumhi > PNG_HIMASK)
  178607. sum = PNG_MAXSUM;
  178608. else
  178609. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178610. }
  178611. #endif
  178612. if (sum < mins)
  178613. {
  178614. mins = sum;
  178615. best_row = png_ptr->avg_row;
  178616. }
  178617. }
  178618. if (filter_to_do == PNG_FILTER_PAETH)
  178619. {
  178620. png_bytep rp, dp, pp, cp, lp;
  178621. png_uint_32 i;
  178622. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178623. pp = prev_row + 1; i < bpp; i++)
  178624. {
  178625. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178626. }
  178627. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178628. {
  178629. int a, b, c, pa, pb, pc, p;
  178630. b = *pp++;
  178631. c = *cp++;
  178632. a = *lp++;
  178633. p = b - c;
  178634. pc = a - c;
  178635. #ifdef PNG_USE_ABS
  178636. pa = abs(p);
  178637. pb = abs(pc);
  178638. pc = abs(p + pc);
  178639. #else
  178640. pa = p < 0 ? -p : p;
  178641. pb = pc < 0 ? -pc : pc;
  178642. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178643. #endif
  178644. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178645. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178646. }
  178647. best_row = png_ptr->paeth_row;
  178648. }
  178649. else if (filter_to_do & PNG_FILTER_PAETH)
  178650. {
  178651. png_bytep rp, dp, pp, cp, lp;
  178652. png_uint_32 sum = 0, lmins = mins;
  178653. png_uint_32 i;
  178654. int v;
  178655. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178656. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178657. {
  178658. int j;
  178659. png_uint_32 lmhi, lmlo;
  178660. lmlo = lmins & PNG_LOMASK;
  178661. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178662. for (j = 0; j < num_p_filters; j++)
  178663. {
  178664. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178665. {
  178666. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178667. PNG_WEIGHT_SHIFT;
  178668. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178669. PNG_WEIGHT_SHIFT;
  178670. }
  178671. }
  178672. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178673. PNG_COST_SHIFT;
  178674. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178675. PNG_COST_SHIFT;
  178676. if (lmhi > PNG_HIMASK)
  178677. lmins = PNG_MAXSUM;
  178678. else
  178679. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178680. }
  178681. #endif
  178682. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178683. pp = prev_row + 1; i < bpp; i++)
  178684. {
  178685. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178686. sum += (v < 128) ? v : 256 - v;
  178687. }
  178688. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178689. {
  178690. int a, b, c, pa, pb, pc, p;
  178691. b = *pp++;
  178692. c = *cp++;
  178693. a = *lp++;
  178694. #ifndef PNG_SLOW_PAETH
  178695. p = b - c;
  178696. pc = a - c;
  178697. #ifdef PNG_USE_ABS
  178698. pa = abs(p);
  178699. pb = abs(pc);
  178700. pc = abs(p + pc);
  178701. #else
  178702. pa = p < 0 ? -p : p;
  178703. pb = pc < 0 ? -pc : pc;
  178704. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178705. #endif
  178706. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178707. #else /* PNG_SLOW_PAETH */
  178708. p = a + b - c;
  178709. pa = abs(p - a);
  178710. pb = abs(p - b);
  178711. pc = abs(p - c);
  178712. if (pa <= pb && pa <= pc)
  178713. p = a;
  178714. else if (pb <= pc)
  178715. p = b;
  178716. else
  178717. p = c;
  178718. #endif /* PNG_SLOW_PAETH */
  178719. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178720. sum += (v < 128) ? v : 256 - v;
  178721. if (sum > lmins) /* We are already worse, don't continue. */
  178722. break;
  178723. }
  178724. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178725. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178726. {
  178727. int j;
  178728. png_uint_32 sumhi, sumlo;
  178729. sumlo = sum & PNG_LOMASK;
  178730. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178731. for (j = 0; j < num_p_filters; j++)
  178732. {
  178733. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178734. {
  178735. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178736. PNG_WEIGHT_SHIFT;
  178737. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178738. PNG_WEIGHT_SHIFT;
  178739. }
  178740. }
  178741. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178742. PNG_COST_SHIFT;
  178743. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178744. PNG_COST_SHIFT;
  178745. if (sumhi > PNG_HIMASK)
  178746. sum = PNG_MAXSUM;
  178747. else
  178748. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178749. }
  178750. #endif
  178751. if (sum < mins)
  178752. {
  178753. best_row = png_ptr->paeth_row;
  178754. }
  178755. }
  178756. #endif /* PNG_NO_WRITE_FILTER */
  178757. png_write_filtered_row(png_ptr, best_row);
  178758. #ifndef PNG_NO_WRITE_FILTER
  178759. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178760. if (png_ptr->num_prev_filters > 0)
  178761. {
  178762. int j;
  178763. for (j = 1; j < num_p_filters; j++)
  178764. {
  178765. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178766. }
  178767. png_ptr->prev_filters[j] = best_row[0];
  178768. }
  178769. #endif
  178770. #endif /* PNG_NO_WRITE_FILTER */
  178771. }
  178772. void /* PRIVATE */
  178773. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178774. {
  178775. png_debug(1, "in png_write_filtered_row\n");
  178776. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178777. png_ptr->zstream.next_in = filtered_row;
  178778. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178779. do
  178780. {
  178781. int ret; /* return of zlib */
  178782. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178783. if (ret != Z_OK)
  178784. {
  178785. if (png_ptr->zstream.msg != NULL)
  178786. png_error(png_ptr, png_ptr->zstream.msg);
  178787. else
  178788. png_error(png_ptr, "zlib error");
  178789. }
  178790. if (!(png_ptr->zstream.avail_out))
  178791. {
  178792. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178793. png_ptr->zstream.next_out = png_ptr->zbuf;
  178794. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178795. }
  178796. } while (png_ptr->zstream.avail_in);
  178797. if (png_ptr->prev_row != NULL)
  178798. {
  178799. png_bytep tptr;
  178800. tptr = png_ptr->prev_row;
  178801. png_ptr->prev_row = png_ptr->row_buf;
  178802. png_ptr->row_buf = tptr;
  178803. }
  178804. png_write_finish_row(png_ptr);
  178805. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178806. png_ptr->flush_rows++;
  178807. if (png_ptr->flush_dist > 0 &&
  178808. png_ptr->flush_rows >= png_ptr->flush_dist)
  178809. {
  178810. png_write_flush(png_ptr);
  178811. }
  178812. #endif
  178813. }
  178814. #endif /* PNG_WRITE_SUPPORTED */
  178815. /*** End of inlined file: pngwutil.c ***/
  178816. }
  178817. #else
  178818. #define PNG_INTERNAL
  178819. #define PNG_SETJMP_NOT_SUPPORTED
  178820. #include <png.h>
  178821. #include <pngconf.h>
  178822. #endif
  178823. }
  178824. #undef max
  178825. #undef min
  178826. #ifdef _MSC_VER
  178827. #pragma warning (pop)
  178828. #endif
  178829. BEGIN_JUCE_NAMESPACE
  178830. using ::calloc;
  178831. using ::malloc;
  178832. using ::free;
  178833. namespace PNGHelpers
  178834. {
  178835. using namespace pnglibNamespace;
  178836. static void readCallback (png_structp png, png_bytep data, png_size_t length)
  178837. {
  178838. static_cast<InputStream*> (png_get_io_ptr (png))->read (data, (int) length);
  178839. }
  178840. static void writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  178841. {
  178842. static_cast<OutputStream*> (png_get_io_ptr (png))->write (data, (int) length);
  178843. }
  178844. struct PNGErrorStruct {};
  178845. static void errorCallback (png_structp, png_const_charp)
  178846. {
  178847. throw PNGErrorStruct();
  178848. }
  178849. }
  178850. Image* juce_loadPNGImageFromStream (InputStream& in)
  178851. {
  178852. using namespace pnglibNamespace;
  178853. Image* image = 0;
  178854. png_structp pngReadStruct;
  178855. png_infop pngInfoStruct;
  178856. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178857. if (pngReadStruct != 0)
  178858. {
  178859. pngInfoStruct = png_create_info_struct (pngReadStruct);
  178860. if (pngInfoStruct == 0)
  178861. {
  178862. png_destroy_read_struct (&pngReadStruct, 0, 0);
  178863. return 0;
  178864. }
  178865. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  178866. // read the header..
  178867. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  178868. png_uint_32 width, height;
  178869. int bitDepth, colorType, interlaceType;
  178870. png_read_info (pngReadStruct, pngInfoStruct);
  178871. png_get_IHDR (pngReadStruct, pngInfoStruct,
  178872. &width, &height,
  178873. &bitDepth, &colorType,
  178874. &interlaceType, 0, 0);
  178875. if (bitDepth == 16)
  178876. png_set_strip_16 (pngReadStruct);
  178877. if (colorType == PNG_COLOR_TYPE_PALETTE)
  178878. png_set_expand (pngReadStruct);
  178879. if (bitDepth < 8)
  178880. png_set_expand (pngReadStruct);
  178881. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  178882. png_set_expand (pngReadStruct);
  178883. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  178884. png_set_gray_to_rgb (pngReadStruct);
  178885. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  178886. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  178887. || pngInfoStruct->num_trans > 0;
  178888. // Load the image into a temp buffer in the pnglib format..
  178889. HeapBlock <uint8> tempBuffer (height * (width << 2));
  178890. {
  178891. HeapBlock <png_bytep> rows (height);
  178892. for (int y = (int) height; --y >= 0;)
  178893. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  178894. png_read_image (pngReadStruct, rows);
  178895. png_read_end (pngReadStruct, pngInfoStruct);
  178896. }
  178897. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  178898. // now convert the data to a juce image format..
  178899. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  178900. (int) width, (int) height, hasAlphaChan);
  178901. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  178902. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  178903. uint8* srcRow = tempBuffer;
  178904. uint8* destRow = destData.data;
  178905. for (int y = 0; y < (int) height; ++y)
  178906. {
  178907. const uint8* src = srcRow;
  178908. srcRow += (width << 2);
  178909. uint8* dest = destRow;
  178910. destRow += destData.lineStride;
  178911. if (hasAlphaChan)
  178912. {
  178913. for (int i = (int) width; --i >= 0;)
  178914. {
  178915. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  178916. ((PixelARGB*) dest)->premultiply();
  178917. dest += destData.pixelStride;
  178918. src += 4;
  178919. }
  178920. }
  178921. else
  178922. {
  178923. for (int i = (int) width; --i >= 0;)
  178924. {
  178925. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  178926. dest += destData.pixelStride;
  178927. src += 4;
  178928. }
  178929. }
  178930. }
  178931. }
  178932. return image;
  178933. }
  178934. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  178935. {
  178936. using namespace pnglibNamespace;
  178937. const int width = image.getWidth();
  178938. const int height = image.getHeight();
  178939. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178940. if (pngWriteStruct == 0)
  178941. return false;
  178942. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  178943. if (pngInfoStruct == 0)
  178944. {
  178945. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  178946. return false;
  178947. }
  178948. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  178949. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  178950. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  178951. : PNG_COLOR_TYPE_RGB,
  178952. PNG_INTERLACE_NONE,
  178953. PNG_COMPRESSION_TYPE_BASE,
  178954. PNG_FILTER_TYPE_BASE);
  178955. HeapBlock <png_byte> rowData (width * 4);
  178956. png_color_8 sig_bit;
  178957. sig_bit.red = 8;
  178958. sig_bit.green = 8;
  178959. sig_bit.blue = 8;
  178960. sig_bit.alpha = 8;
  178961. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  178962. png_write_info (pngWriteStruct, pngInfoStruct);
  178963. png_set_shift (pngWriteStruct, &sig_bit);
  178964. png_set_packing (pngWriteStruct);
  178965. const Image::BitmapData srcData (image, 0, 0, width, height);
  178966. for (int y = 0; y < height; ++y)
  178967. {
  178968. uint8* dst = (uint8*) rowData;
  178969. const uint8* src = srcData.getLinePointer (y);
  178970. if (image.hasAlphaChannel())
  178971. {
  178972. for (int i = width; --i >= 0;)
  178973. {
  178974. PixelARGB p (*(const PixelARGB*) src);
  178975. p.unpremultiply();
  178976. *dst++ = p.getRed();
  178977. *dst++ = p.getGreen();
  178978. *dst++ = p.getBlue();
  178979. *dst++ = p.getAlpha();
  178980. src += srcData.pixelStride;
  178981. }
  178982. }
  178983. else
  178984. {
  178985. for (int i = width; --i >= 0;)
  178986. {
  178987. *dst++ = ((const PixelRGB*) src)->getRed();
  178988. *dst++ = ((const PixelRGB*) src)->getGreen();
  178989. *dst++ = ((const PixelRGB*) src)->getBlue();
  178990. src += srcData.pixelStride;
  178991. }
  178992. }
  178993. png_write_rows (pngWriteStruct, &rowData, 1);
  178994. }
  178995. png_write_end (pngWriteStruct, pngInfoStruct);
  178996. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  178997. out.flush();
  178998. return true;
  178999. }
  179000. END_JUCE_NAMESPACE
  179001. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179002. #endif
  179003. //==============================================================================
  179004. #if JUCE_BUILD_NATIVE
  179005. #if JUCE_WINDOWS
  179006. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179007. #if JUCE_WINDOWS
  179008. BEGIN_JUCE_NAMESPACE
  179009. #define JUCE_INCLUDED_FILE 1
  179010. // Now include the actual code files..
  179011. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179012. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179013. // compiled on its own).
  179014. #if JUCE_INCLUDED_FILE
  179015. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179016. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179017. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179018. #ifndef DOXYGEN
  179019. // use with DynamicLibraryLoader to simplify importing functions
  179020. //
  179021. // functionName: function to import
  179022. // localFunctionName: name you want to use to actually call it (must be different)
  179023. // returnType: the return type
  179024. // object: the DynamicLibraryLoader to use
  179025. // params: list of params (bracketed)
  179026. //
  179027. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179028. typedef returnType (WINAPI *type##localFunctionName) params; \
  179029. type##localFunctionName localFunctionName \
  179030. = (type##localFunctionName)object.findProcAddress (#functionName);
  179031. // loads and unloads a DLL automatically
  179032. class JUCE_API DynamicLibraryLoader
  179033. {
  179034. public:
  179035. DynamicLibraryLoader (const String& name);
  179036. ~DynamicLibraryLoader();
  179037. void* findProcAddress (const String& functionName);
  179038. private:
  179039. void* libHandle;
  179040. };
  179041. #endif
  179042. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179043. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179044. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179045. {
  179046. libHandle = LoadLibrary (name);
  179047. }
  179048. DynamicLibraryLoader::~DynamicLibraryLoader()
  179049. {
  179050. FreeLibrary ((HMODULE) libHandle);
  179051. }
  179052. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179053. {
  179054. return GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179055. }
  179056. #endif
  179057. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179058. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179059. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179060. // compiled on its own).
  179061. #if JUCE_INCLUDED_FILE
  179062. extern void juce_initialiseThreadEvents();
  179063. void Logger::outputDebugString (const String& text) throw()
  179064. {
  179065. OutputDebugString (text + "\n");
  179066. }
  179067. static int64 hiResTicksPerSecond;
  179068. static double hiResTicksScaleFactor;
  179069. #if JUCE_USE_INTRINSICS
  179070. // CPU info functions using intrinsics...
  179071. #pragma intrinsic (__cpuid)
  179072. #pragma intrinsic (__rdtsc)
  179073. const String SystemStats::getCpuVendor() throw()
  179074. {
  179075. int info [4];
  179076. __cpuid (info, 0);
  179077. char v [12];
  179078. memcpy (v, info + 1, 4);
  179079. memcpy (v + 4, info + 3, 4);
  179080. memcpy (v + 8, info + 2, 4);
  179081. return String (v, 12);
  179082. }
  179083. #else
  179084. // CPU info functions using old fashioned inline asm...
  179085. static void juce_getCpuVendor (char* const v)
  179086. {
  179087. int vendor[4];
  179088. zeromem (vendor, 16);
  179089. #ifdef JUCE_64BIT
  179090. #else
  179091. #ifndef __MINGW32__
  179092. __try
  179093. #endif
  179094. {
  179095. #if JUCE_GCC
  179096. unsigned int dummy = 0;
  179097. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179098. #else
  179099. __asm
  179100. {
  179101. mov eax, 0
  179102. cpuid
  179103. mov [vendor], ebx
  179104. mov [vendor + 4], edx
  179105. mov [vendor + 8], ecx
  179106. }
  179107. #endif
  179108. }
  179109. #ifndef __MINGW32__
  179110. __except (EXCEPTION_EXECUTE_HANDLER)
  179111. {
  179112. *v = 0;
  179113. }
  179114. #endif
  179115. #endif
  179116. memcpy (v, vendor, 16);
  179117. }
  179118. const String SystemStats::getCpuVendor() throw()
  179119. {
  179120. char v [16];
  179121. juce_getCpuVendor (v);
  179122. return String (v, 16);
  179123. }
  179124. #endif
  179125. struct CPUFlags
  179126. {
  179127. bool hasMMX : 1;
  179128. bool hasSSE : 1;
  179129. bool hasSSE2 : 1;
  179130. bool has3DNow : 1;
  179131. };
  179132. static CPUFlags cpuFlags;
  179133. bool SystemStats::hasMMX() throw()
  179134. {
  179135. return cpuFlags.hasMMX;
  179136. }
  179137. bool SystemStats::hasSSE() throw()
  179138. {
  179139. return cpuFlags.hasSSE;
  179140. }
  179141. bool SystemStats::hasSSE2() throw()
  179142. {
  179143. return cpuFlags.hasSSE2;
  179144. }
  179145. bool SystemStats::has3DNow() throw()
  179146. {
  179147. return cpuFlags.has3DNow;
  179148. }
  179149. void SystemStats::initialiseStats() throw()
  179150. {
  179151. juce_initialiseThreadEvents();
  179152. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179153. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179154. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179155. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179156. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179157. #else
  179158. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179159. #endif
  179160. LARGE_INTEGER f;
  179161. QueryPerformanceFrequency (&f);
  179162. hiResTicksPerSecond = f.QuadPart;
  179163. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179164. String s (SystemStats::getJUCEVersion());
  179165. #ifdef JUCE_DEBUG
  179166. const MMRESULT res = timeBeginPeriod (1);
  179167. jassert (res == TIMERR_NOERROR);
  179168. #else
  179169. timeBeginPeriod (1);
  179170. #endif
  179171. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179172. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179173. #endif
  179174. }
  179175. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179176. {
  179177. OSVERSIONINFO info;
  179178. info.dwOSVersionInfoSize = sizeof (info);
  179179. GetVersionEx (&info);
  179180. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179181. {
  179182. switch (info.dwMajorVersion)
  179183. {
  179184. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179185. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179186. default: jassertfalse; break; // !! not a supported OS!
  179187. }
  179188. }
  179189. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179190. {
  179191. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179192. return Win98;
  179193. }
  179194. return UnknownOS;
  179195. }
  179196. const String SystemStats::getOperatingSystemName() throw()
  179197. {
  179198. const char* name = "Unknown OS";
  179199. switch (getOperatingSystemType())
  179200. {
  179201. case Windows7: name = "Windows 7"; break;
  179202. case WinVista: name = "Windows Vista"; break;
  179203. case WinXP: name = "Windows XP"; break;
  179204. case Win2000: name = "Windows 2000"; break;
  179205. case Win98: name = "Windows 98"; break;
  179206. default: jassertfalse; break; // !! new type of OS?
  179207. }
  179208. return name;
  179209. }
  179210. bool SystemStats::isOperatingSystem64Bit() throw()
  179211. {
  179212. #ifdef _WIN64
  179213. return true;
  179214. #else
  179215. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179216. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179217. BOOL isWow64 = FALSE;
  179218. return (fnIsWow64Process != 0)
  179219. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179220. && (isWow64 != FALSE);
  179221. #endif
  179222. }
  179223. int SystemStats::getMemorySizeInMegabytes() throw()
  179224. {
  179225. MEMORYSTATUSEX mem;
  179226. mem.dwLength = sizeof (mem);
  179227. GlobalMemoryStatusEx (&mem);
  179228. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179229. }
  179230. int SystemStats::getNumCpus() throw()
  179231. {
  179232. SYSTEM_INFO systemInfo;
  179233. GetSystemInfo (&systemInfo);
  179234. return systemInfo.dwNumberOfProcessors;
  179235. }
  179236. uint32 juce_millisecondsSinceStartup() throw()
  179237. {
  179238. return (uint32) GetTickCount();
  179239. }
  179240. int64 Time::getHighResolutionTicks() throw()
  179241. {
  179242. LARGE_INTEGER ticks;
  179243. QueryPerformanceCounter (&ticks);
  179244. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179245. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179246. // fix for a very obscure PCI hardware bug that can make the counter
  179247. // sometimes jump forwards by a few seconds..
  179248. static int64 hiResTicksOffset = 0;
  179249. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179250. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179251. hiResTicksOffset = newOffset;
  179252. return ticks.QuadPart + hiResTicksOffset;
  179253. }
  179254. double Time::getMillisecondCounterHiRes() throw()
  179255. {
  179256. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179257. }
  179258. int64 Time::getHighResolutionTicksPerSecond() throw()
  179259. {
  179260. return hiResTicksPerSecond;
  179261. }
  179262. int64 SystemStats::getClockCycleCounter() throw()
  179263. {
  179264. #if JUCE_USE_INTRINSICS
  179265. // MS intrinsics version...
  179266. return __rdtsc();
  179267. #elif JUCE_GCC
  179268. // GNU inline asm version...
  179269. unsigned int hi = 0, lo = 0;
  179270. __asm__ __volatile__ (
  179271. "xor %%eax, %%eax \n\
  179272. xor %%edx, %%edx \n\
  179273. rdtsc \n\
  179274. movl %%eax, %[lo] \n\
  179275. movl %%edx, %[hi]"
  179276. :
  179277. : [hi] "m" (hi),
  179278. [lo] "m" (lo)
  179279. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179280. return (int64) ((((uint64) hi) << 32) | lo);
  179281. #else
  179282. // MSVC inline asm version...
  179283. unsigned int hi = 0, lo = 0;
  179284. __asm
  179285. {
  179286. xor eax, eax
  179287. xor edx, edx
  179288. rdtsc
  179289. mov lo, eax
  179290. mov hi, edx
  179291. }
  179292. return (int64) ((((uint64) hi) << 32) | lo);
  179293. #endif
  179294. }
  179295. int SystemStats::getCpuSpeedInMegaherz() throw()
  179296. {
  179297. const int64 cycles = SystemStats::getClockCycleCounter();
  179298. const uint32 millis = Time::getMillisecondCounter();
  179299. int lastResult = 0;
  179300. for (;;)
  179301. {
  179302. int n = 1000000;
  179303. while (--n > 0) {}
  179304. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179305. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179306. if (millisElapsed > 80)
  179307. {
  179308. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179309. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179310. return newResult;
  179311. lastResult = newResult;
  179312. }
  179313. }
  179314. }
  179315. bool Time::setSystemTimeToThisTime() const throw()
  179316. {
  179317. SYSTEMTIME st;
  179318. st.wDayOfWeek = 0;
  179319. st.wYear = (WORD) getYear();
  179320. st.wMonth = (WORD) (getMonth() + 1);
  179321. st.wDay = (WORD) getDayOfMonth();
  179322. st.wHour = (WORD) getHours();
  179323. st.wMinute = (WORD) getMinutes();
  179324. st.wSecond = (WORD) getSeconds();
  179325. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179326. // do this twice because of daylight saving conversion problems - the
  179327. // first one sets it up, the second one kicks it in.
  179328. return SetLocalTime (&st) != 0
  179329. && SetLocalTime (&st) != 0;
  179330. }
  179331. int SystemStats::getPageSize() throw()
  179332. {
  179333. SYSTEM_INFO systemInfo;
  179334. GetSystemInfo (&systemInfo);
  179335. return systemInfo.dwPageSize;
  179336. }
  179337. const String SystemStats::getLogonName()
  179338. {
  179339. TCHAR text [256];
  179340. DWORD len = numElementsInArray (text) - 2;
  179341. zerostruct (text);
  179342. GetUserName (text, &len);
  179343. return String (text, len);
  179344. }
  179345. const String SystemStats::getFullUserName()
  179346. {
  179347. return getLogonName();
  179348. }
  179349. #endif
  179350. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179351. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179352. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179353. // compiled on its own).
  179354. #if JUCE_INCLUDED_FILE
  179355. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179356. extern HWND juce_messageWindowHandle;
  179357. #endif
  179358. #if ! JUCE_USE_INTRINSICS
  179359. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179360. // older ones we have to actually call the ops as win32 functions..
  179361. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179362. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179363. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179364. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179365. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179366. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179367. #endif
  179368. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179369. CriticalSection::CriticalSection() throw()
  179370. {
  179371. // (just to check the MS haven't changed this structure and broken things...)
  179372. #if _MSC_VER >= 1400
  179373. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179374. #else
  179375. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179376. #endif
  179377. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179378. }
  179379. CriticalSection::~CriticalSection() throw()
  179380. {
  179381. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179382. }
  179383. void CriticalSection::enter() const throw()
  179384. {
  179385. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179386. }
  179387. bool CriticalSection::tryEnter() const throw()
  179388. {
  179389. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179390. }
  179391. void CriticalSection::exit() const throw()
  179392. {
  179393. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179394. }
  179395. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  179396. : internal (CreateEvent (0, manualReset ? TRUE : FALSE, FALSE, 0))
  179397. {
  179398. }
  179399. WaitableEvent::~WaitableEvent() throw()
  179400. {
  179401. CloseHandle (internal);
  179402. }
  179403. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179404. {
  179405. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179406. }
  179407. void WaitableEvent::signal() const throw()
  179408. {
  179409. SetEvent (internal);
  179410. }
  179411. void WaitableEvent::reset() const throw()
  179412. {
  179413. ResetEvent (internal);
  179414. }
  179415. void JUCE_API juce_threadEntryPoint (void*);
  179416. static unsigned int __stdcall threadEntryProc (void* userData)
  179417. {
  179418. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179419. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179420. GetCurrentThreadId(), TRUE);
  179421. #endif
  179422. juce_threadEntryPoint (userData);
  179423. _endthreadex (0);
  179424. return 0;
  179425. }
  179426. void juce_CloseThreadHandle (void* handle)
  179427. {
  179428. CloseHandle ((HANDLE) handle);
  179429. }
  179430. void* juce_createThread (void* userData)
  179431. {
  179432. unsigned int threadId;
  179433. return (void*) _beginthreadex (0, 0,
  179434. &threadEntryProc,
  179435. userData,
  179436. 0, &threadId);
  179437. }
  179438. void juce_killThread (void* handle)
  179439. {
  179440. if (handle != 0)
  179441. {
  179442. #ifdef JUCE_DEBUG
  179443. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179444. #endif
  179445. TerminateThread (handle, 0);
  179446. }
  179447. }
  179448. void juce_setCurrentThreadName (const String& name)
  179449. {
  179450. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179451. struct
  179452. {
  179453. DWORD dwType;
  179454. LPCSTR szName;
  179455. DWORD dwThreadID;
  179456. DWORD dwFlags;
  179457. } info;
  179458. info.dwType = 0x1000;
  179459. info.szName = name.toCString();
  179460. info.dwThreadID = GetCurrentThreadId();
  179461. info.dwFlags = 0;
  179462. __try
  179463. {
  179464. RaiseException (0x406d1388 /*MS_VC_EXCEPTION*/, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179465. }
  179466. __except (EXCEPTION_CONTINUE_EXECUTION)
  179467. {}
  179468. #else
  179469. (void) name;
  179470. #endif
  179471. }
  179472. Thread::ThreadID Thread::getCurrentThreadId()
  179473. {
  179474. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179475. }
  179476. // priority 1 to 10 where 5=normal, 1=low
  179477. bool juce_setThreadPriority (void* threadHandle, int priority)
  179478. {
  179479. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179480. if (priority < 1)
  179481. pri = THREAD_PRIORITY_IDLE;
  179482. else if (priority < 2)
  179483. pri = THREAD_PRIORITY_LOWEST;
  179484. else if (priority < 5)
  179485. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179486. else if (priority < 7)
  179487. pri = THREAD_PRIORITY_NORMAL;
  179488. else if (priority < 9)
  179489. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179490. else if (priority < 10)
  179491. pri = THREAD_PRIORITY_HIGHEST;
  179492. if (threadHandle == 0)
  179493. threadHandle = GetCurrentThread();
  179494. return SetThreadPriority (threadHandle, pri) != FALSE;
  179495. }
  179496. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179497. {
  179498. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179499. }
  179500. static HANDLE sleepEvent = 0;
  179501. void juce_initialiseThreadEvents()
  179502. {
  179503. if (sleepEvent == 0)
  179504. #ifdef JUCE_DEBUG
  179505. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179506. #else
  179507. sleepEvent = CreateEvent (0, 0, 0, 0);
  179508. #endif
  179509. }
  179510. void Thread::yield()
  179511. {
  179512. Sleep (0);
  179513. }
  179514. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179515. {
  179516. if (millisecs >= 10)
  179517. {
  179518. Sleep (millisecs);
  179519. }
  179520. else
  179521. {
  179522. jassert (sleepEvent != 0);
  179523. // unlike Sleep() this is guaranteed to return to the current thread after
  179524. // the time expires, so we'll use this for short waits, which are more likely
  179525. // to need to be accurate
  179526. WaitForSingleObject (sleepEvent, millisecs);
  179527. }
  179528. }
  179529. static int lastProcessPriority = -1;
  179530. // called by WindowDriver because Windows does wierd things to process priority
  179531. // when you swap apps, and this forces an update when the app is brought to the front.
  179532. void juce_repeatLastProcessPriority()
  179533. {
  179534. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179535. {
  179536. DWORD p;
  179537. switch (lastProcessPriority)
  179538. {
  179539. case Process::LowPriority: p = IDLE_PRIORITY_CLASS; break;
  179540. case Process::NormalPriority: p = NORMAL_PRIORITY_CLASS; break;
  179541. case Process::HighPriority: p = HIGH_PRIORITY_CLASS; break;
  179542. case Process::RealtimePriority: p = REALTIME_PRIORITY_CLASS; break;
  179543. default: jassertfalse; return; // bad priority value
  179544. }
  179545. SetPriorityClass (GetCurrentProcess(), p);
  179546. }
  179547. }
  179548. void Process::setPriority (ProcessPriority prior)
  179549. {
  179550. if (lastProcessPriority != (int) prior)
  179551. {
  179552. lastProcessPriority = (int) prior;
  179553. juce_repeatLastProcessPriority();
  179554. }
  179555. }
  179556. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179557. {
  179558. return IsDebuggerPresent() != FALSE;
  179559. }
  179560. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179561. {
  179562. return juce_isRunningUnderDebugger();
  179563. }
  179564. void Process::raisePrivilege()
  179565. {
  179566. jassertfalse // xxx not implemented
  179567. }
  179568. void Process::lowerPrivilege()
  179569. {
  179570. jassertfalse // xxx not implemented
  179571. }
  179572. void Process::terminate()
  179573. {
  179574. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179575. _CrtDumpMemoryLeaks();
  179576. #endif
  179577. // bullet in the head in case there's a problem shutting down..
  179578. ExitProcess (0);
  179579. }
  179580. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179581. {
  179582. void* result = 0;
  179583. JUCE_TRY
  179584. {
  179585. result = (void*) LoadLibrary (name);
  179586. }
  179587. JUCE_CATCH_ALL
  179588. return result;
  179589. }
  179590. void PlatformUtilities::freeDynamicLibrary (void* h)
  179591. {
  179592. JUCE_TRY
  179593. {
  179594. if (h != 0)
  179595. FreeLibrary ((HMODULE) h);
  179596. }
  179597. JUCE_CATCH_ALL
  179598. }
  179599. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179600. {
  179601. return (h != 0) ? GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179602. }
  179603. class InterProcessLock::Pimpl
  179604. {
  179605. public:
  179606. Pimpl (const String& name, const int timeOutMillisecs)
  179607. : handle (0), refCount (1)
  179608. {
  179609. handle = CreateMutex (0, TRUE, "Global\\" + name.replaceCharacter ('\\','/'));
  179610. if (handle != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179611. {
  179612. if (timeOutMillisecs == 0)
  179613. {
  179614. close();
  179615. return;
  179616. }
  179617. switch (WaitForSingleObject (handle, timeOutMillisecs < 0 ? INFINITE : timeOutMillisecs))
  179618. {
  179619. case WAIT_OBJECT_0:
  179620. case WAIT_ABANDONED:
  179621. break;
  179622. case WAIT_TIMEOUT:
  179623. default:
  179624. close();
  179625. break;
  179626. }
  179627. }
  179628. }
  179629. ~Pimpl()
  179630. {
  179631. close();
  179632. }
  179633. void close()
  179634. {
  179635. if (handle != 0)
  179636. {
  179637. ReleaseMutex (handle);
  179638. CloseHandle (handle);
  179639. handle = 0;
  179640. }
  179641. }
  179642. HANDLE handle;
  179643. int refCount;
  179644. };
  179645. InterProcessLock::InterProcessLock (const String& name_)
  179646. : name (name_)
  179647. {
  179648. }
  179649. InterProcessLock::~InterProcessLock()
  179650. {
  179651. }
  179652. bool InterProcessLock::enter (const int timeOutMillisecs)
  179653. {
  179654. const ScopedLock sl (lock);
  179655. if (pimpl == 0)
  179656. {
  179657. pimpl = new Pimpl (name, timeOutMillisecs);
  179658. if (pimpl->handle == 0)
  179659. pimpl = 0;
  179660. }
  179661. else
  179662. {
  179663. pimpl->refCount++;
  179664. }
  179665. return pimpl != 0;
  179666. }
  179667. void InterProcessLock::exit()
  179668. {
  179669. const ScopedLock sl (lock);
  179670. // Trying to release the lock too many times!
  179671. jassert (pimpl != 0);
  179672. if (pimpl != 0 && --(pimpl->refCount) == 0)
  179673. pimpl = 0;
  179674. }
  179675. #endif
  179676. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179677. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179678. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179679. // compiled on its own).
  179680. #if JUCE_INCLUDED_FILE
  179681. #ifndef CSIDL_MYMUSIC
  179682. #define CSIDL_MYMUSIC 0x000d
  179683. #endif
  179684. #ifndef CSIDL_MYVIDEO
  179685. #define CSIDL_MYVIDEO 0x000e
  179686. #endif
  179687. #ifndef INVALID_FILE_ATTRIBUTES
  179688. #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
  179689. #endif
  179690. const juce_wchar File::separator = '\\';
  179691. const juce_wchar* File::separatorString = T("\\");
  179692. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179693. {
  179694. if (fileName.isEmpty())
  179695. return false;
  179696. const DWORD attr = GetFileAttributes (fileName);
  179697. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179698. : (attr != INVALID_FILE_ATTRIBUTES);
  179699. }
  179700. bool juce_isDirectory (const String& fileName)
  179701. {
  179702. const DWORD attr = GetFileAttributes (fileName);
  179703. return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
  179704. }
  179705. bool juce_canWriteToFile (const String& fileName)
  179706. {
  179707. const DWORD attr = GetFileAttributes (fileName);
  179708. return (attr & FILE_ATTRIBUTE_READONLY) == 0;
  179709. }
  179710. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179711. {
  179712. DWORD attr = GetFileAttributes (fileName);
  179713. if (attr == INVALID_FILE_ATTRIBUTES)
  179714. return false;
  179715. if (isReadOnly != juce_canWriteToFile (fileName))
  179716. return true;
  179717. if (isReadOnly)
  179718. attr |= FILE_ATTRIBUTE_READONLY;
  179719. else
  179720. attr &= ~FILE_ATTRIBUTE_READONLY;
  179721. return SetFileAttributes (fileName, attr) != FALSE;
  179722. }
  179723. bool File::isHidden() const
  179724. {
  179725. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179726. }
  179727. bool juce_deleteFile (const String& fileName)
  179728. {
  179729. if (juce_isDirectory (fileName))
  179730. return RemoveDirectory (fileName) != 0;
  179731. return DeleteFile (fileName) != 0;
  179732. }
  179733. bool File::moveToTrash() const
  179734. {
  179735. if (! exists())
  179736. return true;
  179737. SHFILEOPSTRUCT fos;
  179738. zerostruct (fos);
  179739. // The string we pass in must be double null terminated..
  179740. String doubleNullTermPath (getFullPathName() + " ");
  179741. TCHAR* const p = const_cast <TCHAR*> (static_cast <const TCHAR*> (doubleNullTermPath));
  179742. p [getFullPathName().length()] = 0;
  179743. fos.wFunc = FO_DELETE;
  179744. fos.pFrom = p;
  179745. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179746. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179747. return SHFileOperation (&fos) == 0;
  179748. }
  179749. bool juce_moveFile (const String& source, const String& dest)
  179750. {
  179751. return MoveFile (source, dest) != 0;
  179752. }
  179753. bool juce_copyFile (const String& source, const String& dest)
  179754. {
  179755. return CopyFile (source, dest, false) != 0;
  179756. }
  179757. void juce_createDirectory (const String& fileName)
  179758. {
  179759. if (! juce_fileExists (fileName, true))
  179760. CreateDirectory (fileName, 0);
  179761. }
  179762. // return 0 if not possible
  179763. void* juce_fileOpen (const String& fileName, bool forWriting)
  179764. {
  179765. HANDLE h;
  179766. if (forWriting)
  179767. {
  179768. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179769. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179770. if (h != INVALID_HANDLE_VALUE)
  179771. SetFilePointer (h, 0, 0, FILE_END);
  179772. else
  179773. h = 0;
  179774. }
  179775. else
  179776. {
  179777. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179778. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179779. if (h == INVALID_HANDLE_VALUE)
  179780. h = 0;
  179781. }
  179782. return h;
  179783. }
  179784. void juce_fileClose (void* handle)
  179785. {
  179786. CloseHandle (handle);
  179787. }
  179788. int juce_fileRead (void* handle, void* buffer, int size)
  179789. {
  179790. DWORD num = 0;
  179791. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179792. return (int) num;
  179793. }
  179794. int juce_fileWrite (void* handle, const void* buffer, int size)
  179795. {
  179796. DWORD num;
  179797. WriteFile ((HANDLE) handle, buffer, size, &num, 0);
  179798. return (int) num;
  179799. }
  179800. int64 juce_fileSetPosition (void* handle, int64 pos)
  179801. {
  179802. LARGE_INTEGER li;
  179803. li.QuadPart = pos;
  179804. li.LowPart = SetFilePointer ((HANDLE) handle, li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
  179805. return li.QuadPart;
  179806. }
  179807. int64 juce_fileGetPosition (void* handle)
  179808. {
  179809. LARGE_INTEGER li;
  179810. li.QuadPart = 0;
  179811. li.LowPart = SetFilePointer ((HANDLE) handle, 0, &li.HighPart, FILE_CURRENT); // (returns -1 if it fails)
  179812. return jmax ((int64) 0, li.QuadPart);
  179813. }
  179814. void juce_fileFlush (void* handle)
  179815. {
  179816. FlushFileBuffers ((HANDLE) handle);
  179817. }
  179818. int64 juce_getFileSize (const String& fileName)
  179819. {
  179820. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179821. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179822. return (((int64) attributes.nFileSizeHigh) << 32) | attributes.nFileSizeLow;
  179823. return 0;
  179824. }
  179825. static int64 fileTimeToTime (const FILETIME* const ft)
  179826. {
  179827. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME)); // tell me if this fails!
  179828. return (reinterpret_cast<const ULARGE_INTEGER*> (ft)->QuadPart - literal64bit (116444736000000000)) / 10000;
  179829. }
  179830. static void timeToFileTime (const int64 time, FILETIME* const ft)
  179831. {
  179832. reinterpret_cast<ULARGE_INTEGER*> (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000);
  179833. }
  179834. void juce_getFileTimes (const String& fileName,
  179835. int64& modificationTime,
  179836. int64& accessTime,
  179837. int64& creationTime)
  179838. {
  179839. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179840. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179841. {
  179842. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  179843. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  179844. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  179845. }
  179846. else
  179847. {
  179848. creationTime = accessTime = modificationTime = 0;
  179849. }
  179850. }
  179851. bool juce_setFileTimes (const String& fileName,
  179852. int64 modificationTime,
  179853. int64 accessTime,
  179854. int64 creationTime)
  179855. {
  179856. void* const h = juce_fileOpen (fileName, true);
  179857. bool ok = false;
  179858. if (h != 0)
  179859. {
  179860. FILETIME m, a, c;
  179861. timeToFileTime (modificationTime, &m);
  179862. timeToFileTime (accessTime, &a);
  179863. timeToFileTime (creationTime, &c);
  179864. ok = SetFileTime ((HANDLE) h,
  179865. creationTime > 0 ? &c : 0,
  179866. accessTime > 0 ? &a : 0,
  179867. modificationTime > 0 ? &m : 0) != 0;
  179868. juce_fileClose (h);
  179869. }
  179870. return ok;
  179871. }
  179872. // return '\0' separated list of strings
  179873. const StringArray juce_getFileSystemRoots()
  179874. {
  179875. TCHAR buffer [2048];
  179876. buffer[0] = 0;
  179877. buffer[1] = 0;
  179878. GetLogicalDriveStrings (2048, buffer);
  179879. const TCHAR* n = buffer;
  179880. StringArray roots;
  179881. while (*n != 0)
  179882. {
  179883. roots.add (String (n));
  179884. while (*n++ != 0)
  179885. {}
  179886. }
  179887. roots.sort (true);
  179888. return roots;
  179889. }
  179890. static const String getDriveFromPath (const String& path)
  179891. {
  179892. if (path.isNotEmpty() && path[1] == ':')
  179893. return path.substring (0, 2) + '\\';
  179894. return path;
  179895. }
  179896. const String juce_getVolumeLabel (const String& filenameOnVolume,
  179897. int& volumeSerialNumber)
  179898. {
  179899. TCHAR dest[64];
  179900. DWORD serialNum;
  179901. if (! GetVolumeInformation (getDriveFromPath (filenameOnVolume), dest,
  179902. numElementsInArray (dest), &serialNum, 0, 0, 0, 0))
  179903. {
  179904. dest[0] = 0;
  179905. serialNum = 0;
  179906. }
  179907. volumeSerialNumber = serialNum;
  179908. return dest;
  179909. }
  179910. static int64 getDiskSpaceInfo (const String& path, const bool total)
  179911. {
  179912. ULARGE_INTEGER spc, tot, totFree;
  179913. if (GetDiskFreeSpaceEx (getDriveFromPath (path), &spc, &tot, &totFree))
  179914. return total ? (int64) tot.QuadPart
  179915. : (int64) spc.QuadPart;
  179916. return 0;
  179917. }
  179918. int64 File::getBytesFreeOnVolume() const
  179919. {
  179920. return getDiskSpaceInfo (getFullPathName(), false);
  179921. }
  179922. int64 File::getVolumeTotalSize() const
  179923. {
  179924. return getDiskSpaceInfo (getFullPathName(), true);
  179925. }
  179926. static unsigned int getWindowsDriveType (const String& path)
  179927. {
  179928. return GetDriveType (getDriveFromPath (path));
  179929. }
  179930. bool File::isOnCDRomDrive() const
  179931. {
  179932. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  179933. }
  179934. bool File::isOnHardDisk() const
  179935. {
  179936. if (fullPath.isEmpty())
  179937. return false;
  179938. const unsigned int n = getWindowsDriveType (getFullPathName());
  179939. if (fullPath.toLowerCase()[0] <= 'b' && fullPath[1] == ':')
  179940. return n != DRIVE_REMOVABLE;
  179941. else
  179942. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  179943. }
  179944. bool File::isOnRemovableDrive() const
  179945. {
  179946. if (fullPath.isEmpty())
  179947. return false;
  179948. const unsigned int n = getWindowsDriveType (getFullPathName());
  179949. return n == DRIVE_CDROM
  179950. || n == DRIVE_REMOTE
  179951. || n == DRIVE_REMOVABLE
  179952. || n == DRIVE_RAMDISK;
  179953. }
  179954. static const File juce_getSpecialFolderPath (int type)
  179955. {
  179956. WCHAR path [MAX_PATH + 256];
  179957. if (SHGetSpecialFolderPath (0, path, type, FALSE))
  179958. return File (String (path));
  179959. return File::nonexistent;
  179960. }
  179961. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  179962. {
  179963. int csidlType = 0;
  179964. switch (type)
  179965. {
  179966. case userHomeDirectory: csidlType = CSIDL_PROFILE; break;
  179967. case userDocumentsDirectory: csidlType = CSIDL_PERSONAL; break;
  179968. case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break;
  179969. case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break;
  179970. case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break;
  179971. case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break;
  179972. case userMusicDirectory: csidlType = CSIDL_MYMUSIC; break;
  179973. case userMoviesDirectory: csidlType = CSIDL_MYVIDEO; break;
  179974. case tempDirectory:
  179975. {
  179976. WCHAR dest [2048];
  179977. dest[0] = 0;
  179978. GetTempPath (numElementsInArray (dest), dest);
  179979. return File (String (dest));
  179980. }
  179981. case invokedExecutableFile:
  179982. case currentExecutableFile:
  179983. case currentApplicationFile:
  179984. {
  179985. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  179986. WCHAR dest [MAX_PATH + 256];
  179987. dest[0] = 0;
  179988. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  179989. return File (String (dest));
  179990. }
  179991. break;
  179992. default:
  179993. jassertfalse // unknown type?
  179994. return File::nonexistent;
  179995. }
  179996. return juce_getSpecialFolderPath (csidlType);
  179997. }
  179998. const File File::getCurrentWorkingDirectory()
  179999. {
  180000. WCHAR dest [MAX_PATH + 256];
  180001. dest[0] = 0;
  180002. GetCurrentDirectory (numElementsInArray (dest), dest);
  180003. return File (String (dest));
  180004. }
  180005. bool File::setAsCurrentWorkingDirectory() const
  180006. {
  180007. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180008. }
  180009. const String File::getVersion() const
  180010. {
  180011. String result;
  180012. DWORD handle = 0;
  180013. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180014. HeapBlock<char> buffer;
  180015. buffer.calloc (bufferSize);
  180016. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180017. {
  180018. VS_FIXEDFILEINFO* vffi;
  180019. UINT len = 0;
  180020. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180021. {
  180022. result << (int) HIWORD (vffi->dwFileVersionMS) << '.'
  180023. << (int) LOWORD (vffi->dwFileVersionMS) << '.'
  180024. << (int) HIWORD (vffi->dwFileVersionLS) << '.'
  180025. << (int) LOWORD (vffi->dwFileVersionLS);
  180026. }
  180027. }
  180028. return result;
  180029. }
  180030. const File File::getLinkedTarget() const
  180031. {
  180032. File result (*this);
  180033. String p (getFullPathName());
  180034. if (! exists())
  180035. p += ".lnk";
  180036. else if (getFileExtension() != ".lnk")
  180037. return result;
  180038. ComSmartPtr <IShellLink> shellLink;
  180039. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180040. {
  180041. ComSmartPtr <IPersistFile> persistFile;
  180042. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180043. {
  180044. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180045. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180046. {
  180047. WIN32_FIND_DATA winFindData;
  180048. WCHAR resolvedPath [MAX_PATH];
  180049. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180050. result = File (resolvedPath);
  180051. }
  180052. }
  180053. }
  180054. return result;
  180055. }
  180056. template <class FindDataType>
  180057. static void getFindFileInfo (FindDataType& findData,
  180058. String& filename, bool* const isDir, bool* const isHidden,
  180059. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180060. bool* const isReadOnly)
  180061. {
  180062. filename = findData.cFileName;
  180063. if (isDir != 0)
  180064. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180065. if (isHidden != 0)
  180066. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180067. if (fileSize != 0)
  180068. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180069. if (modTime != 0)
  180070. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180071. if (creationTime != 0)
  180072. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180073. if (isReadOnly != 0)
  180074. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180075. }
  180076. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180077. bool* isDir, bool* isHidden, int64* fileSize,
  180078. Time* modTime, Time* creationTime, bool* isReadOnly)
  180079. {
  180080. String wc (directory);
  180081. if (! wc.endsWithChar (File::separator))
  180082. wc += File::separator;
  180083. wc += wildCard;
  180084. WIN32_FIND_DATA findData;
  180085. HANDLE h = FindFirstFile (wc, &findData);
  180086. if (h != INVALID_HANDLE_VALUE)
  180087. {
  180088. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180089. modTime, creationTime, isReadOnly);
  180090. return h;
  180091. }
  180092. firstResult = String::empty;
  180093. return 0;
  180094. }
  180095. bool juce_findFileNext (void* handle, String& resultFile,
  180096. bool* isDir, bool* isHidden, int64* fileSize,
  180097. Time* modTime, Time* creationTime, bool* isReadOnly)
  180098. {
  180099. WIN32_FIND_DATA findData;
  180100. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180101. {
  180102. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180103. modTime, creationTime, isReadOnly);
  180104. return true;
  180105. }
  180106. resultFile = String::empty;
  180107. return false;
  180108. }
  180109. void juce_findFileClose (void* handle)
  180110. {
  180111. FindClose (handle);
  180112. }
  180113. bool juce_launchFile (const String& fileName, const String& parameters)
  180114. {
  180115. HINSTANCE hInstance = 0;
  180116. JUCE_TRY
  180117. {
  180118. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180119. }
  180120. JUCE_CATCH_ALL
  180121. return hInstance > (HINSTANCE) 32;
  180122. }
  180123. void File::revealToUser() const
  180124. {
  180125. if (isDirectory())
  180126. startAsProcess();
  180127. else if (getParentDirectory().exists())
  180128. getParentDirectory().startAsProcess();
  180129. }
  180130. class NamedPipeInternal
  180131. {
  180132. public:
  180133. NamedPipeInternal (const String& file, const bool isPipe_)
  180134. : pipeH (0),
  180135. cancelEvent (0),
  180136. connected (false),
  180137. isPipe (isPipe_)
  180138. {
  180139. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180140. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180141. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180142. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180143. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180144. }
  180145. ~NamedPipeInternal()
  180146. {
  180147. disconnectPipe();
  180148. if (pipeH != 0)
  180149. CloseHandle (pipeH);
  180150. CloseHandle (cancelEvent);
  180151. }
  180152. bool connect (const int timeOutMs)
  180153. {
  180154. if (! isPipe)
  180155. return true;
  180156. if (! connected)
  180157. {
  180158. OVERLAPPED over;
  180159. zerostruct (over);
  180160. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180161. if (ConnectNamedPipe (pipeH, &over))
  180162. {
  180163. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180164. }
  180165. else
  180166. {
  180167. const int err = GetLastError();
  180168. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180169. {
  180170. HANDLE handles[] = { over.hEvent, cancelEvent };
  180171. if (WaitForMultipleObjects (2, handles, FALSE,
  180172. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180173. connected = true;
  180174. }
  180175. else if (err == ERROR_PIPE_CONNECTED)
  180176. {
  180177. connected = true;
  180178. }
  180179. }
  180180. CloseHandle (over.hEvent);
  180181. }
  180182. return connected;
  180183. }
  180184. void disconnectPipe()
  180185. {
  180186. if (connected)
  180187. {
  180188. DisconnectNamedPipe (pipeH);
  180189. connected = false;
  180190. }
  180191. }
  180192. HANDLE pipeH;
  180193. HANDLE cancelEvent;
  180194. bool connected, isPipe;
  180195. };
  180196. void NamedPipe::close()
  180197. {
  180198. cancelPendingReads();
  180199. const ScopedLock sl (lock);
  180200. delete static_cast<NamedPipeInternal*> (internal);
  180201. internal = 0;
  180202. }
  180203. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180204. {
  180205. close();
  180206. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180207. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180208. {
  180209. internal = intern.release();
  180210. return true;
  180211. }
  180212. return false;
  180213. }
  180214. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180215. {
  180216. const ScopedLock sl (lock);
  180217. int bytesRead = -1;
  180218. bool waitAgain = true;
  180219. while (waitAgain && internal != 0)
  180220. {
  180221. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180222. waitAgain = false;
  180223. if (! intern->connect (timeOutMilliseconds))
  180224. break;
  180225. if (maxBytesToRead <= 0)
  180226. return 0;
  180227. OVERLAPPED over;
  180228. zerostruct (over);
  180229. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180230. unsigned long numRead;
  180231. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180232. {
  180233. bytesRead = (int) numRead;
  180234. }
  180235. else if (GetLastError() == ERROR_IO_PENDING)
  180236. {
  180237. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180238. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180239. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180240. : INFINITE);
  180241. if (waitResult != WAIT_OBJECT_0)
  180242. {
  180243. // if the operation timed out, let's cancel it...
  180244. CancelIo (intern->pipeH);
  180245. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180246. }
  180247. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180248. {
  180249. bytesRead = (int) numRead;
  180250. }
  180251. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180252. {
  180253. intern->disconnectPipe();
  180254. waitAgain = true;
  180255. }
  180256. }
  180257. else
  180258. {
  180259. waitAgain = internal != 0;
  180260. Sleep (5);
  180261. }
  180262. CloseHandle (over.hEvent);
  180263. }
  180264. return bytesRead;
  180265. }
  180266. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180267. {
  180268. int bytesWritten = -1;
  180269. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180270. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180271. {
  180272. if (numBytesToWrite <= 0)
  180273. return 0;
  180274. OVERLAPPED over;
  180275. zerostruct (over);
  180276. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180277. unsigned long numWritten;
  180278. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180279. {
  180280. bytesWritten = (int) numWritten;
  180281. }
  180282. else if (GetLastError() == ERROR_IO_PENDING)
  180283. {
  180284. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180285. DWORD waitResult;
  180286. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180287. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180288. : INFINITE);
  180289. if (waitResult != WAIT_OBJECT_0)
  180290. {
  180291. CancelIo (intern->pipeH);
  180292. WaitForSingleObject (over.hEvent, INFINITE);
  180293. }
  180294. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180295. {
  180296. bytesWritten = (int) numWritten;
  180297. }
  180298. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180299. {
  180300. intern->disconnectPipe();
  180301. }
  180302. }
  180303. CloseHandle (over.hEvent);
  180304. }
  180305. return bytesWritten;
  180306. }
  180307. void NamedPipe::cancelPendingReads()
  180308. {
  180309. if (internal != 0)
  180310. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180311. }
  180312. #endif
  180313. /*** End of inlined file: juce_win32_Files.cpp ***/
  180314. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180315. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180316. // compiled on its own).
  180317. #if JUCE_INCLUDED_FILE
  180318. #ifndef INTERNET_FLAG_NEED_FILE
  180319. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180320. #endif
  180321. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180322. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180323. #endif
  180324. bool juce_isOnLine()
  180325. {
  180326. DWORD connectionType;
  180327. return InternetGetConnectedState (&connectionType, 0) != 0
  180328. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180329. }
  180330. struct ConnectionAndRequestStruct
  180331. {
  180332. HINTERNET connection, request;
  180333. };
  180334. static HINTERNET sessionHandle = 0;
  180335. #ifndef WORKAROUND_TIMEOUT_BUG
  180336. //#define WORKAROUND_TIMEOUT_BUG 1
  180337. #endif
  180338. #if WORKAROUND_TIMEOUT_BUG
  180339. // Required because of a Microsoft bug in setting a timeout
  180340. class InternetConnectThread : public Thread
  180341. {
  180342. public:
  180343. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180344. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180345. {
  180346. startThread();
  180347. }
  180348. ~InternetConnectThread()
  180349. {
  180350. stopThread (60000);
  180351. }
  180352. void run()
  180353. {
  180354. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180355. uc.nPort, _T(""), _T(""),
  180356. isFtp ? INTERNET_SERVICE_FTP
  180357. : INTERNET_SERVICE_HTTP,
  180358. 0, 0);
  180359. notify();
  180360. }
  180361. juce_UseDebuggingNewOperator
  180362. private:
  180363. URL_COMPONENTS& uc;
  180364. HINTERNET& connection;
  180365. const bool isFtp;
  180366. InternetConnectThread (const InternetConnectThread&);
  180367. InternetConnectThread& operator= (const InternetConnectThread&);
  180368. };
  180369. #endif
  180370. void* juce_openInternetFile (const String& url,
  180371. const String& headers,
  180372. const MemoryBlock& postData,
  180373. const bool isPost,
  180374. URL::OpenStreamProgressCallback* callback,
  180375. void* callbackContext,
  180376. int timeOutMs)
  180377. {
  180378. if (sessionHandle == 0)
  180379. sessionHandle = InternetOpen (_T("juce"),
  180380. INTERNET_OPEN_TYPE_PRECONFIG,
  180381. 0, 0, 0);
  180382. if (sessionHandle != 0)
  180383. {
  180384. // break up the url..
  180385. TCHAR file[1024], server[1024];
  180386. URL_COMPONENTS uc;
  180387. zerostruct (uc);
  180388. uc.dwStructSize = sizeof (uc);
  180389. uc.dwUrlPathLength = sizeof (file);
  180390. uc.dwHostNameLength = sizeof (server);
  180391. uc.lpszUrlPath = file;
  180392. uc.lpszHostName = server;
  180393. if (InternetCrackUrl (url, 0, 0, &uc))
  180394. {
  180395. int disable = 1;
  180396. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180397. if (timeOutMs == 0)
  180398. timeOutMs = 30000;
  180399. else if (timeOutMs < 0)
  180400. timeOutMs = -1;
  180401. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180402. const bool isFtp = url.startsWithIgnoreCase ("ftp:");
  180403. #if WORKAROUND_TIMEOUT_BUG
  180404. HINTERNET connection = 0;
  180405. {
  180406. InternetConnectThread connectThread (uc, connection, isFtp);
  180407. connectThread.wait (timeOutMs);
  180408. if (connection == 0)
  180409. {
  180410. InternetCloseHandle (sessionHandle);
  180411. sessionHandle = 0;
  180412. }
  180413. }
  180414. #else
  180415. HINTERNET connection = InternetConnect (sessionHandle,
  180416. uc.lpszHostName,
  180417. uc.nPort,
  180418. _T(""), _T(""),
  180419. isFtp ? INTERNET_SERVICE_FTP
  180420. : INTERNET_SERVICE_HTTP,
  180421. 0, 0);
  180422. #endif
  180423. if (connection != 0)
  180424. {
  180425. if (isFtp)
  180426. {
  180427. HINTERNET request = FtpOpenFile (connection,
  180428. uc.lpszUrlPath,
  180429. GENERIC_READ,
  180430. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180431. 0);
  180432. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180433. result->connection = connection;
  180434. result->request = request;
  180435. return result;
  180436. }
  180437. else
  180438. {
  180439. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180440. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180441. if (url.startsWithIgnoreCase ("https:"))
  180442. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180443. // IE7 seems to automatically work out when it's https)
  180444. HINTERNET request = HttpOpenRequest (connection,
  180445. isPost ? _T("POST")
  180446. : _T("GET"),
  180447. uc.lpszUrlPath,
  180448. 0, 0, mimeTypes, flags, 0);
  180449. if (request != 0)
  180450. {
  180451. INTERNET_BUFFERS buffers;
  180452. zerostruct (buffers);
  180453. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180454. buffers.lpcszHeader = (LPCTSTR) headers;
  180455. buffers.dwHeadersLength = headers.length();
  180456. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180457. ConnectionAndRequestStruct* result = 0;
  180458. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180459. {
  180460. int bytesSent = 0;
  180461. for (;;)
  180462. {
  180463. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180464. DWORD bytesDone = 0;
  180465. if (bytesToDo > 0
  180466. && ! InternetWriteFile (request,
  180467. ((const char*) postData.getData()) + bytesSent,
  180468. bytesToDo, &bytesDone))
  180469. {
  180470. break;
  180471. }
  180472. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180473. {
  180474. result = new ConnectionAndRequestStruct();
  180475. result->connection = connection;
  180476. result->request = request;
  180477. HttpEndRequest (request, 0, 0, 0);
  180478. return result;
  180479. }
  180480. bytesSent += bytesDone;
  180481. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180482. break;
  180483. }
  180484. }
  180485. InternetCloseHandle (request);
  180486. }
  180487. InternetCloseHandle (connection);
  180488. }
  180489. }
  180490. }
  180491. }
  180492. return 0;
  180493. }
  180494. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180495. {
  180496. DWORD bytesRead = 0;
  180497. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180498. if (crs != 0)
  180499. InternetReadFile (crs->request,
  180500. buffer, bytesToRead,
  180501. &bytesRead);
  180502. return bytesRead;
  180503. }
  180504. int juce_seekInInternetFile (void* handle, int newPosition)
  180505. {
  180506. if (handle != 0)
  180507. {
  180508. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180509. return InternetSetFilePointer (crs->request,
  180510. newPosition, 0,
  180511. FILE_BEGIN, 0);
  180512. }
  180513. else
  180514. {
  180515. return -1;
  180516. }
  180517. }
  180518. int64 juce_getInternetFileContentLength (void* handle)
  180519. {
  180520. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180521. if (crs != 0)
  180522. {
  180523. DWORD index = 0;
  180524. DWORD result = 0;
  180525. DWORD size = sizeof (result);
  180526. if (HttpQueryInfo (crs->request,
  180527. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180528. &result,
  180529. &size,
  180530. &index))
  180531. {
  180532. return (int64) result;
  180533. }
  180534. }
  180535. return -1;
  180536. }
  180537. void juce_closeInternetFile (void* handle)
  180538. {
  180539. if (handle != 0)
  180540. {
  180541. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  180542. InternetCloseHandle (crs->request);
  180543. InternetCloseHandle (crs->connection);
  180544. delete crs;
  180545. }
  180546. }
  180547. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180548. {
  180549. int numFound = 0;
  180550. DynamicLibraryLoader dll ("iphlpapi.dll");
  180551. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180552. if (getAdaptersInfo != 0)
  180553. {
  180554. ULONG len = sizeof (IP_ADAPTER_INFO);
  180555. MemoryBlock mb;
  180556. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180557. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180558. {
  180559. mb.setSize (len);
  180560. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180561. }
  180562. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180563. {
  180564. PIP_ADAPTER_INFO adapter = adapterInfo;
  180565. while (adapter != 0)
  180566. {
  180567. int64 mac = 0;
  180568. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180569. mac = (mac << 8) | adapter->Address[i];
  180570. if (littleEndian)
  180571. mac = (int64) ByteOrder::swap ((uint64) mac);
  180572. if (numFound < maxNum && mac != 0)
  180573. addresses [numFound++] = mac;
  180574. adapter = adapter->Next;
  180575. }
  180576. }
  180577. }
  180578. return numFound;
  180579. }
  180580. struct ASTAT
  180581. {
  180582. ADAPTER_STATUS adapt;
  180583. NAME_BUFFER NameBuff [30];
  180584. };
  180585. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180586. {
  180587. int numFound = 0;
  180588. DynamicLibraryLoader dll ("netapi32.dll");
  180589. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180590. if (NetbiosCall != 0)
  180591. {
  180592. NCB ncb;
  180593. zerostruct (ncb);
  180594. ASTAT astat;
  180595. zerostruct (astat);
  180596. LANA_ENUM enums;
  180597. zerostruct (enums);
  180598. ncb.ncb_command = NCBENUM;
  180599. ncb.ncb_buffer = (unsigned char*) &enums;
  180600. ncb.ncb_length = sizeof (LANA_ENUM);
  180601. NetbiosCall (&ncb);
  180602. for (int i = 0; i < enums.length; ++i)
  180603. {
  180604. zerostruct (ncb);
  180605. ncb.ncb_command = NCBRESET;
  180606. ncb.ncb_lana_num = enums.lana[i];
  180607. if (NetbiosCall (&ncb) == 0)
  180608. {
  180609. zerostruct (ncb);
  180610. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180611. ncb.ncb_command = NCBASTAT;
  180612. ncb.ncb_lana_num = enums.lana[i];
  180613. ncb.ncb_buffer = (unsigned char*) &astat;
  180614. ncb.ncb_length = sizeof (ASTAT);
  180615. if (NetbiosCall (&ncb) == 0)
  180616. {
  180617. if (astat.adapt.adapter_type == 0xfe)
  180618. {
  180619. uint64 mac = 0;
  180620. for (int i = 6; --i >= 0;)
  180621. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180622. if (numFound < maxNum && mac != 0)
  180623. addresses [numFound++] = mac;
  180624. }
  180625. }
  180626. }
  180627. }
  180628. }
  180629. return numFound;
  180630. }
  180631. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180632. {
  180633. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180634. if (numFound == 0)
  180635. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180636. return numFound;
  180637. }
  180638. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180639. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180640. const String& emailSubject,
  180641. const String& bodyText,
  180642. const StringArray& filesToAttach)
  180643. {
  180644. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180645. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180646. bool ok = false;
  180647. if (mapiSendMail != 0)
  180648. {
  180649. MapiMessage message;
  180650. zerostruct (message);
  180651. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180652. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180653. MapiRecipDesc recip;
  180654. zerostruct (recip);
  180655. recip.ulRecipClass = MAPI_TO;
  180656. String targetEmailAddress_ (targetEmailAddress);
  180657. if (targetEmailAddress_.isEmpty())
  180658. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180659. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180660. message.nRecipCount = 1;
  180661. message.lpRecips = &recip;
  180662. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  180663. mb.fillWith (0);
  180664. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  180665. message.nFileCount = filesToAttach.size();
  180666. message.lpFiles = files;
  180667. for (int i = 0; i < filesToAttach.size(); ++i)
  180668. {
  180669. files[i].nPosition = (ULONG) -1;
  180670. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180671. }
  180672. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180673. }
  180674. FreeLibrary (h);
  180675. return ok;
  180676. }
  180677. #endif
  180678. /*** End of inlined file: juce_win32_Network.cpp ***/
  180679. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180680. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180681. // compiled on its own).
  180682. #if JUCE_INCLUDED_FILE
  180683. static HKEY findKeyForPath (String name,
  180684. const bool createForWriting,
  180685. String& valueName)
  180686. {
  180687. HKEY rootKey = 0;
  180688. if (name.startsWithIgnoreCase ("HKEY_CURRENT_USER\\"))
  180689. rootKey = HKEY_CURRENT_USER;
  180690. else if (name.startsWithIgnoreCase ("HKEY_LOCAL_MACHINE\\"))
  180691. rootKey = HKEY_LOCAL_MACHINE;
  180692. else if (name.startsWithIgnoreCase ("HKEY_CLASSES_ROOT\\"))
  180693. rootKey = HKEY_CLASSES_ROOT;
  180694. if (rootKey != 0)
  180695. {
  180696. name = name.substring (name.indexOfChar ('\\') + 1);
  180697. const int lastSlash = name.lastIndexOfChar ('\\');
  180698. valueName = name.substring (lastSlash + 1);
  180699. name = name.substring (0, lastSlash);
  180700. HKEY key;
  180701. DWORD result;
  180702. if (createForWriting)
  180703. {
  180704. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180705. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180706. return key;
  180707. }
  180708. else
  180709. {
  180710. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180711. return key;
  180712. }
  180713. }
  180714. return 0;
  180715. }
  180716. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180717. const String& defaultValue)
  180718. {
  180719. String valueName, result (defaultValue);
  180720. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180721. if (k != 0)
  180722. {
  180723. WCHAR buffer [2048];
  180724. unsigned long bufferSize = sizeof (buffer);
  180725. DWORD type = REG_SZ;
  180726. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180727. {
  180728. if (type == REG_SZ)
  180729. result = buffer;
  180730. else if (type == REG_DWORD)
  180731. result = String ((int) *(DWORD*) buffer);
  180732. }
  180733. RegCloseKey (k);
  180734. }
  180735. return result;
  180736. }
  180737. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180738. const String& value)
  180739. {
  180740. String valueName;
  180741. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180742. if (k != 0)
  180743. {
  180744. RegSetValueEx (k, valueName, 0, REG_SZ,
  180745. (const BYTE*) (const WCHAR*) value,
  180746. sizeof (WCHAR) * (value.length() + 1));
  180747. RegCloseKey (k);
  180748. }
  180749. }
  180750. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180751. {
  180752. bool exists = false;
  180753. String valueName;
  180754. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180755. if (k != 0)
  180756. {
  180757. unsigned char buffer [2048];
  180758. unsigned long bufferSize = sizeof (buffer);
  180759. DWORD type = 0;
  180760. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180761. exists = true;
  180762. RegCloseKey (k);
  180763. }
  180764. return exists;
  180765. }
  180766. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180767. {
  180768. String valueName;
  180769. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180770. if (k != 0)
  180771. {
  180772. RegDeleteValue (k, valueName);
  180773. RegCloseKey (k);
  180774. }
  180775. }
  180776. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180777. {
  180778. String valueName;
  180779. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180780. if (k != 0)
  180781. {
  180782. RegDeleteKey (k, valueName);
  180783. RegCloseKey (k);
  180784. }
  180785. }
  180786. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  180787. const String& symbolicDescription,
  180788. const String& fullDescription,
  180789. const File& targetExecutable,
  180790. int iconResourceNumber)
  180791. {
  180792. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  180793. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  180794. if (iconResourceNumber != 0)
  180795. setRegistryValue (key + "\\DefaultIcon\\",
  180796. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  180797. setRegistryValue (key + "\\", fullDescription);
  180798. setRegistryValue (key + "\\shell\\open\\command\\",
  180799. targetExecutable.getFullPathName() + " %1");
  180800. }
  180801. bool juce_IsRunningInWine()
  180802. {
  180803. HKEY key;
  180804. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  180805. {
  180806. RegCloseKey (key);
  180807. return true;
  180808. }
  180809. return false;
  180810. }
  180811. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  180812. {
  180813. String s (::GetCommandLineW());
  180814. StringArray tokens;
  180815. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  180816. return tokens.joinIntoString (" ", 1);
  180817. }
  180818. static void* currentModuleHandle = 0;
  180819. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  180820. {
  180821. if (currentModuleHandle == 0)
  180822. currentModuleHandle = GetModuleHandle (0);
  180823. return currentModuleHandle;
  180824. }
  180825. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  180826. {
  180827. currentModuleHandle = newHandle;
  180828. }
  180829. void PlatformUtilities::fpuReset()
  180830. {
  180831. #if JUCE_MSVC
  180832. _clearfp();
  180833. #endif
  180834. }
  180835. void PlatformUtilities::beep()
  180836. {
  180837. MessageBeep (MB_OK);
  180838. }
  180839. #endif
  180840. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  180841. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180842. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  180843. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180844. // compiled on its own).
  180845. #if JUCE_INCLUDED_FILE
  180846. static const unsigned int specialId = WM_APP + 0x4400;
  180847. static const unsigned int broadcastId = WM_APP + 0x4403;
  180848. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  180849. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  180850. HWND juce_messageWindowHandle = 0;
  180851. extern long improbableWindowNumber; // defined in windowing.cpp
  180852. #ifndef WM_APPCOMMAND
  180853. #define WM_APPCOMMAND 0x0319
  180854. #endif
  180855. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  180856. const UINT message,
  180857. const WPARAM wParam,
  180858. const LPARAM lParam) throw()
  180859. {
  180860. JUCE_TRY
  180861. {
  180862. if (h == juce_messageWindowHandle)
  180863. {
  180864. if (message == specialCallbackId)
  180865. {
  180866. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  180867. return (LRESULT) (*func) ((void*) lParam);
  180868. }
  180869. else if (message == specialId)
  180870. {
  180871. // these are trapped early in the dispatch call, but must also be checked
  180872. // here in case there are windows modal dialog boxes doing their own
  180873. // dispatch loop and not calling our version
  180874. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  180875. return 0;
  180876. }
  180877. else if (message == broadcastId)
  180878. {
  180879. const ScopedPointer <String> messageString ((String*) lParam);
  180880. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  180881. return 0;
  180882. }
  180883. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  180884. {
  180885. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  180886. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  180887. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  180888. return 0;
  180889. }
  180890. }
  180891. }
  180892. JUCE_CATCH_EXCEPTION
  180893. return DefWindowProc (h, message, wParam, lParam);
  180894. }
  180895. static bool isEventBlockedByModalComps (MSG& m)
  180896. {
  180897. if (Component::getNumCurrentlyModalComponents() == 0
  180898. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  180899. return false;
  180900. switch (m.message)
  180901. {
  180902. case WM_MOUSEMOVE:
  180903. case WM_NCMOUSEMOVE:
  180904. case 0x020A: /* WM_MOUSEWHEEL */
  180905. case 0x020E: /* WM_MOUSEHWHEEL */
  180906. case WM_KEYUP:
  180907. case WM_SYSKEYUP:
  180908. case WM_CHAR:
  180909. case WM_APPCOMMAND:
  180910. case WM_LBUTTONUP:
  180911. case WM_MBUTTONUP:
  180912. case WM_RBUTTONUP:
  180913. case WM_MOUSEACTIVATE:
  180914. case WM_NCMOUSEHOVER:
  180915. case WM_MOUSEHOVER:
  180916. return true;
  180917. case WM_NCLBUTTONDOWN:
  180918. case WM_NCLBUTTONDBLCLK:
  180919. case WM_NCRBUTTONDOWN:
  180920. case WM_NCRBUTTONDBLCLK:
  180921. case WM_NCMBUTTONDOWN:
  180922. case WM_NCMBUTTONDBLCLK:
  180923. case WM_LBUTTONDOWN:
  180924. case WM_LBUTTONDBLCLK:
  180925. case WM_MBUTTONDOWN:
  180926. case WM_MBUTTONDBLCLK:
  180927. case WM_RBUTTONDOWN:
  180928. case WM_RBUTTONDBLCLK:
  180929. case WM_KEYDOWN:
  180930. case WM_SYSKEYDOWN:
  180931. {
  180932. Component* const modal = Component::getCurrentlyModalComponent (0);
  180933. if (modal != 0)
  180934. modal->inputAttemptWhenModal();
  180935. return true;
  180936. }
  180937. default:
  180938. break;
  180939. }
  180940. return false;
  180941. }
  180942. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  180943. {
  180944. MSG m;
  180945. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  180946. return false;
  180947. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  180948. {
  180949. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  180950. {
  180951. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  180952. }
  180953. else if (m.message == WM_QUIT)
  180954. {
  180955. if (JUCEApplication::getInstance())
  180956. JUCEApplication::getInstance()->systemRequestedQuit();
  180957. }
  180958. else if (! isEventBlockedByModalComps (m))
  180959. {
  180960. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  180961. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  180962. {
  180963. // if it's someone else's window being clicked on, and the focus is
  180964. // currently on a juce window, pass the kb focus over..
  180965. HWND currentFocus = GetFocus();
  180966. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  180967. SetFocus (m.hwnd);
  180968. }
  180969. TranslateMessage (&m);
  180970. DispatchMessage (&m);
  180971. }
  180972. }
  180973. return true;
  180974. }
  180975. bool juce_postMessageToSystemQueue (void* message)
  180976. {
  180977. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  180978. }
  180979. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  180980. void* userData)
  180981. {
  180982. if (MessageManager::getInstance()->isThisTheMessageThread())
  180983. {
  180984. return (*callback) (userData);
  180985. }
  180986. else
  180987. {
  180988. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  180989. // deadlock because the message manager is blocked from running, and can't
  180990. // call your function..
  180991. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  180992. return (void*) SendMessage (juce_messageWindowHandle,
  180993. specialCallbackId,
  180994. (WPARAM) callback,
  180995. (LPARAM) userData);
  180996. }
  180997. }
  180998. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  180999. {
  181000. if (hwnd != juce_messageWindowHandle)
  181001. reinterpret_cast <VoidArray*> (lParam)->add ((void*) hwnd);
  181002. return TRUE;
  181003. }
  181004. void MessageManager::broadcastMessage (const String& value) throw()
  181005. {
  181006. VoidArray windows;
  181007. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181008. const String localCopy (value);
  181009. COPYDATASTRUCT data;
  181010. data.dwData = broadcastId;
  181011. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181012. data.lpData = (void*) static_cast <const juce_wchar*> (localCopy);
  181013. for (int i = windows.size(); --i >= 0;)
  181014. {
  181015. HWND hwnd = (HWND) windows.getUnchecked(i);
  181016. TCHAR windowName [64]; // no need to read longer strings than this
  181017. GetWindowText (hwnd, windowName, 64);
  181018. windowName [63] = 0;
  181019. if (String (windowName) == String (messageWindowName))
  181020. {
  181021. DWORD_PTR result;
  181022. SendMessageTimeout (hwnd, WM_COPYDATA,
  181023. (WPARAM) juce_messageWindowHandle,
  181024. (LPARAM) &data,
  181025. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181026. 8000,
  181027. &result);
  181028. }
  181029. }
  181030. }
  181031. static const String getMessageWindowClassName()
  181032. {
  181033. // this name has to be different for each app/dll instance because otherwise
  181034. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181035. // window class).
  181036. static int number = 0;
  181037. if (number == 0)
  181038. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181039. return "JUCEcs_" + String (number);
  181040. }
  181041. void MessageManager::doPlatformSpecificInitialisation()
  181042. {
  181043. OleInitialize (0);
  181044. const String className (getMessageWindowClassName());
  181045. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181046. WNDCLASSEX wc;
  181047. zerostruct (wc);
  181048. wc.cbSize = sizeof (wc);
  181049. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181050. wc.cbWndExtra = 4;
  181051. wc.hInstance = hmod;
  181052. wc.lpszClassName = className;
  181053. RegisterClassEx (&wc);
  181054. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181055. messageWindowName,
  181056. 0, 0, 0, 0, 0, 0, 0,
  181057. hmod, 0);
  181058. }
  181059. void MessageManager::doPlatformSpecificShutdown()
  181060. {
  181061. DestroyWindow (juce_messageWindowHandle);
  181062. UnregisterClass (getMessageWindowClassName(), 0);
  181063. OleUninitialize();
  181064. }
  181065. #endif
  181066. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181067. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181068. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181069. // compiled on its own).
  181070. #if JUCE_INCLUDED_FILE
  181071. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181072. // these are in the windows SDK, but need to be repeated here for GCC..
  181073. #ifndef GET_APPCOMMAND_LPARAM
  181074. #define FAPPCOMMAND_MASK 0xF000
  181075. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181076. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181077. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181078. #define APPCOMMAND_MEDIA_STOP 13
  181079. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181080. #define WM_APPCOMMAND 0x0319
  181081. #endif
  181082. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181083. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181084. extern bool juce_IsRunningInWine();
  181085. #ifndef ULW_ALPHA
  181086. #define ULW_ALPHA 0x00000002
  181087. #endif
  181088. #ifndef AC_SRC_ALPHA
  181089. #define AC_SRC_ALPHA 0x01
  181090. #endif
  181091. static HPALETTE palette = 0;
  181092. static bool createPaletteIfNeeded = true;
  181093. static bool shouldDeactivateTitleBar = true;
  181094. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181095. #define WM_TRAYNOTIFY WM_USER + 100
  181096. using ::abs;
  181097. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181098. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181099. bool Desktop::canUseSemiTransparentWindows() throw()
  181100. {
  181101. if (updateLayeredWindow == 0)
  181102. {
  181103. if (! juce_IsRunningInWine())
  181104. {
  181105. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181106. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181107. }
  181108. }
  181109. return updateLayeredWindow != 0;
  181110. }
  181111. const int extendedKeyModifier = 0x10000;
  181112. const int KeyPress::spaceKey = VK_SPACE;
  181113. const int KeyPress::returnKey = VK_RETURN;
  181114. const int KeyPress::escapeKey = VK_ESCAPE;
  181115. const int KeyPress::backspaceKey = VK_BACK;
  181116. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181117. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181118. const int KeyPress::tabKey = VK_TAB;
  181119. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181120. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181121. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181122. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181123. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181124. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181125. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181126. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181127. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181128. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181129. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181130. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181131. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181132. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181133. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181134. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181135. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181136. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181137. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181138. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181139. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181140. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181141. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181142. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181143. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181144. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181145. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181146. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181147. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181148. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181149. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181150. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181151. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181152. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181153. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181154. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181155. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181156. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181157. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181158. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181159. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181160. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181161. const int KeyPress::playKey = 0x30000;
  181162. const int KeyPress::stopKey = 0x30001;
  181163. const int KeyPress::fastForwardKey = 0x30002;
  181164. const int KeyPress::rewindKey = 0x30003;
  181165. class WindowsBitmapImage : public Image
  181166. {
  181167. public:
  181168. HBITMAP hBitmap;
  181169. BITMAPV4HEADER bitmapInfo;
  181170. HDC hdc;
  181171. unsigned char* bitmapData;
  181172. WindowsBitmapImage (const PixelFormat format_,
  181173. const int w, const int h, const bool clearImage)
  181174. : Image (format_, w, h)
  181175. {
  181176. jassert (format_ == RGB || format_ == ARGB);
  181177. pixelStride = (format_ == RGB) ? 3 : 4;
  181178. zerostruct (bitmapInfo);
  181179. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181180. bitmapInfo.bV4Width = w;
  181181. bitmapInfo.bV4Height = h;
  181182. bitmapInfo.bV4Planes = 1;
  181183. bitmapInfo.bV4CSType = 1;
  181184. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181185. if (format_ == ARGB)
  181186. {
  181187. bitmapInfo.bV4AlphaMask = 0xff000000;
  181188. bitmapInfo.bV4RedMask = 0xff0000;
  181189. bitmapInfo.bV4GreenMask = 0xff00;
  181190. bitmapInfo.bV4BlueMask = 0xff;
  181191. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181192. }
  181193. else
  181194. {
  181195. bitmapInfo.bV4V4Compression = BI_RGB;
  181196. }
  181197. lineStride = -((w * pixelStride + 3) & ~3);
  181198. HDC dc = GetDC (0);
  181199. hdc = CreateCompatibleDC (dc);
  181200. ReleaseDC (0, dc);
  181201. SetMapMode (hdc, MM_TEXT);
  181202. hBitmap = CreateDIBSection (hdc,
  181203. (BITMAPINFO*) &(bitmapInfo),
  181204. DIB_RGB_COLORS,
  181205. (void**) &bitmapData,
  181206. 0, 0);
  181207. SelectObject (hdc, hBitmap);
  181208. if (format_ == ARGB && clearImage)
  181209. zeromem (bitmapData, abs (h * lineStride));
  181210. imageData = bitmapData - (lineStride * (h - 1));
  181211. }
  181212. ~WindowsBitmapImage()
  181213. {
  181214. DeleteDC (hdc);
  181215. DeleteObject (hBitmap);
  181216. }
  181217. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181218. const int x, const int y,
  181219. const RectangleList& maskedRegion) throw()
  181220. {
  181221. static HDRAWDIB hdd = 0;
  181222. static bool needToCreateDrawDib = true;
  181223. if (needToCreateDrawDib)
  181224. {
  181225. needToCreateDrawDib = false;
  181226. HDC dc = GetDC (0);
  181227. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181228. ReleaseDC (0, dc);
  181229. // only open if we're not palettised
  181230. if (n > 8)
  181231. hdd = DrawDibOpen();
  181232. }
  181233. if (createPaletteIfNeeded)
  181234. {
  181235. HDC dc = GetDC (0);
  181236. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181237. ReleaseDC (0, dc);
  181238. if (n <= 8)
  181239. palette = CreateHalftonePalette (dc);
  181240. createPaletteIfNeeded = false;
  181241. }
  181242. if (palette != 0)
  181243. {
  181244. SelectPalette (dc, palette, FALSE);
  181245. RealizePalette (dc);
  181246. SetStretchBltMode (dc, HALFTONE);
  181247. }
  181248. SetMapMode (dc, MM_TEXT);
  181249. if (transparent)
  181250. {
  181251. POINT p, pos;
  181252. SIZE size;
  181253. RECT windowBounds;
  181254. GetWindowRect (hwnd, &windowBounds);
  181255. p.x = -x;
  181256. p.y = -y;
  181257. pos.x = windowBounds.left;
  181258. pos.y = windowBounds.top;
  181259. size.cx = windowBounds.right - windowBounds.left;
  181260. size.cy = windowBounds.bottom - windowBounds.top;
  181261. BLENDFUNCTION bf;
  181262. bf.AlphaFormat = AC_SRC_ALPHA;
  181263. bf.BlendFlags = 0;
  181264. bf.BlendOp = AC_SRC_OVER;
  181265. bf.SourceConstantAlpha = 0xff;
  181266. if (! maskedRegion.isEmpty())
  181267. {
  181268. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181269. {
  181270. const Rectangle<int>& r = *i.getRectangle();
  181271. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181272. }
  181273. }
  181274. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181275. }
  181276. else
  181277. {
  181278. int savedDC = 0;
  181279. if (! maskedRegion.isEmpty())
  181280. {
  181281. savedDC = SaveDC (dc);
  181282. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181283. {
  181284. const Rectangle<int>& r = *i.getRectangle();
  181285. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181286. }
  181287. }
  181288. const int w = getWidth();
  181289. const int h = getHeight();
  181290. if (hdd == 0)
  181291. {
  181292. StretchDIBits (dc,
  181293. x, y, w, h,
  181294. 0, 0, w, h,
  181295. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181296. DIB_RGB_COLORS, SRCCOPY);
  181297. }
  181298. else
  181299. {
  181300. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181301. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181302. 0, 0, w, h, 0);
  181303. }
  181304. if (! maskedRegion.isEmpty())
  181305. RestoreDC (dc, savedDC);
  181306. }
  181307. }
  181308. juce_UseDebuggingNewOperator
  181309. private:
  181310. WindowsBitmapImage (const WindowsBitmapImage&);
  181311. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181312. };
  181313. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181314. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  181315. {
  181316. SHORT k = (SHORT) keyCode;
  181317. if ((keyCode & extendedKeyModifier) == 0
  181318. && (k >= (SHORT) 'a' && k <= (SHORT) 'z'))
  181319. k += (SHORT) 'A' - (SHORT) 'a';
  181320. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181321. (SHORT) '+', VK_OEM_PLUS,
  181322. (SHORT) '-', VK_OEM_MINUS,
  181323. (SHORT) '.', VK_OEM_PERIOD,
  181324. (SHORT) ';', VK_OEM_1,
  181325. (SHORT) ':', VK_OEM_1,
  181326. (SHORT) '/', VK_OEM_2,
  181327. (SHORT) '?', VK_OEM_2,
  181328. (SHORT) '[', VK_OEM_4,
  181329. (SHORT) ']', VK_OEM_6 };
  181330. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181331. if (k == translatedValues [i])
  181332. k = translatedValues [i + 1];
  181333. return (GetKeyState (k) & 0x8000) != 0;
  181334. }
  181335. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181336. {
  181337. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181338. return callback (userData);
  181339. else
  181340. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181341. }
  181342. class Win32ComponentPeer : public ComponentPeer
  181343. {
  181344. public:
  181345. Win32ComponentPeer (Component* const component,
  181346. const int windowStyleFlags)
  181347. : ComponentPeer (component, windowStyleFlags),
  181348. dontRepaint (false),
  181349. fullScreen (false),
  181350. isDragging (false),
  181351. isMouseOver (false),
  181352. hasCreatedCaret (false),
  181353. currentWindowIcon (0),
  181354. taskBarIcon (0),
  181355. dropTarget (0)
  181356. {
  181357. callFunctionIfNotLocked (&createWindowCallback, this);
  181358. setTitle (component->getName());
  181359. if ((windowStyleFlags & windowHasDropShadow) != 0
  181360. && Desktop::canUseSemiTransparentWindows())
  181361. {
  181362. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181363. if (shadower != 0)
  181364. shadower->setOwner (component);
  181365. }
  181366. else
  181367. {
  181368. shadower = 0;
  181369. }
  181370. }
  181371. ~Win32ComponentPeer()
  181372. {
  181373. setTaskBarIcon (0);
  181374. deleteAndZero (shadower);
  181375. // do this before the next bit to avoid messages arriving for this window
  181376. // before it's destroyed
  181377. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181378. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181379. if (currentWindowIcon != 0)
  181380. DestroyIcon (currentWindowIcon);
  181381. if (dropTarget != 0)
  181382. {
  181383. dropTarget->Release();
  181384. dropTarget = 0;
  181385. }
  181386. }
  181387. void* getNativeHandle() const
  181388. {
  181389. return hwnd;
  181390. }
  181391. void setVisible (bool shouldBeVisible)
  181392. {
  181393. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181394. if (shouldBeVisible)
  181395. InvalidateRect (hwnd, 0, 0);
  181396. else
  181397. lastPaintTime = 0;
  181398. }
  181399. void setTitle (const String& title)
  181400. {
  181401. SetWindowText (hwnd, title);
  181402. }
  181403. void setPosition (int x, int y)
  181404. {
  181405. offsetWithinParent (x, y);
  181406. SetWindowPos (hwnd, 0,
  181407. x - windowBorder.getLeft(),
  181408. y - windowBorder.getTop(),
  181409. 0, 0,
  181410. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181411. }
  181412. void repaintNowIfTransparent()
  181413. {
  181414. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181415. handlePaintMessage();
  181416. }
  181417. void updateBorderSize()
  181418. {
  181419. WINDOWINFO info;
  181420. info.cbSize = sizeof (info);
  181421. if (GetWindowInfo (hwnd, &info))
  181422. {
  181423. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181424. info.rcClient.left - info.rcWindow.left,
  181425. info.rcWindow.bottom - info.rcClient.bottom,
  181426. info.rcWindow.right - info.rcClient.right);
  181427. }
  181428. }
  181429. void setSize (int w, int h)
  181430. {
  181431. SetWindowPos (hwnd, 0, 0, 0,
  181432. w + windowBorder.getLeftAndRight(),
  181433. h + windowBorder.getTopAndBottom(),
  181434. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181435. updateBorderSize();
  181436. repaintNowIfTransparent();
  181437. }
  181438. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  181439. {
  181440. fullScreen = isNowFullScreen;
  181441. offsetWithinParent (x, y);
  181442. SetWindowPos (hwnd, 0,
  181443. x - windowBorder.getLeft(),
  181444. y - windowBorder.getTop(),
  181445. w + windowBorder.getLeftAndRight(),
  181446. h + windowBorder.getTopAndBottom(),
  181447. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181448. updateBorderSize();
  181449. repaintNowIfTransparent();
  181450. }
  181451. const Rectangle<int> getBounds() const
  181452. {
  181453. RECT r;
  181454. GetWindowRect (hwnd, &r);
  181455. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181456. HWND parentH = GetParent (hwnd);
  181457. if (parentH != 0)
  181458. {
  181459. GetWindowRect (parentH, &r);
  181460. bounds.translate (-r.left, -r.top);
  181461. }
  181462. return windowBorder.subtractedFrom (bounds);
  181463. }
  181464. const Point<int> getScreenPosition() const
  181465. {
  181466. RECT r;
  181467. GetWindowRect (hwnd, &r);
  181468. return Point<int> (r.left + windowBorder.getLeft(),
  181469. r.top + windowBorder.getTop());
  181470. }
  181471. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181472. {
  181473. return relativePosition + getScreenPosition();
  181474. }
  181475. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181476. {
  181477. return screenPosition - getScreenPosition();
  181478. }
  181479. void setMinimised (bool shouldBeMinimised)
  181480. {
  181481. if (shouldBeMinimised != isMinimised())
  181482. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181483. }
  181484. bool isMinimised() const
  181485. {
  181486. WINDOWPLACEMENT wp;
  181487. wp.length = sizeof (WINDOWPLACEMENT);
  181488. GetWindowPlacement (hwnd, &wp);
  181489. return wp.showCmd == SW_SHOWMINIMIZED;
  181490. }
  181491. void setFullScreen (bool shouldBeFullScreen)
  181492. {
  181493. setMinimised (false);
  181494. if (fullScreen != shouldBeFullScreen)
  181495. {
  181496. fullScreen = shouldBeFullScreen;
  181497. const Component::SafePointer<Component> deletionChecker (component);
  181498. if (! fullScreen)
  181499. {
  181500. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181501. if (hasTitleBar())
  181502. ShowWindow (hwnd, SW_SHOWNORMAL);
  181503. if (! boundsCopy.isEmpty())
  181504. {
  181505. setBounds (boundsCopy.getX(),
  181506. boundsCopy.getY(),
  181507. boundsCopy.getWidth(),
  181508. boundsCopy.getHeight(),
  181509. false);
  181510. }
  181511. }
  181512. else
  181513. {
  181514. if (hasTitleBar())
  181515. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181516. else
  181517. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181518. }
  181519. if (deletionChecker != 0)
  181520. handleMovedOrResized();
  181521. }
  181522. }
  181523. bool isFullScreen() const
  181524. {
  181525. if (! hasTitleBar())
  181526. return fullScreen;
  181527. WINDOWPLACEMENT wp;
  181528. wp.length = sizeof (wp);
  181529. GetWindowPlacement (hwnd, &wp);
  181530. return wp.showCmd == SW_SHOWMAXIMIZED;
  181531. }
  181532. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181533. {
  181534. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181535. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181536. return false;
  181537. RECT r;
  181538. GetWindowRect (hwnd, &r);
  181539. POINT p;
  181540. p.x = position.getX() + r.left + windowBorder.getLeft();
  181541. p.y = position.getY() + r.top + windowBorder.getTop();
  181542. HWND w = WindowFromPoint (p);
  181543. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181544. }
  181545. const BorderSize getFrameSize() const
  181546. {
  181547. return windowBorder;
  181548. }
  181549. bool setAlwaysOnTop (bool alwaysOnTop)
  181550. {
  181551. const bool oldDeactivate = shouldDeactivateTitleBar;
  181552. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181553. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181554. 0, 0, 0, 0,
  181555. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181556. shouldDeactivateTitleBar = oldDeactivate;
  181557. if (shadower != 0)
  181558. shadower->componentBroughtToFront (*component);
  181559. return true;
  181560. }
  181561. void toFront (bool makeActive)
  181562. {
  181563. setMinimised (false);
  181564. const bool oldDeactivate = shouldDeactivateTitleBar;
  181565. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181566. callFunctionIfNotLocked (makeActive ? &toFrontCallback1 : &toFrontCallback2, hwnd);
  181567. shouldDeactivateTitleBar = oldDeactivate;
  181568. if (! makeActive)
  181569. {
  181570. // in this case a broughttofront call won't have occured, so do it now..
  181571. handleBroughtToFront();
  181572. }
  181573. }
  181574. void toBehind (ComponentPeer* other)
  181575. {
  181576. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181577. jassert (otherPeer != 0); // wrong type of window?
  181578. if (otherPeer != 0)
  181579. {
  181580. setMinimised (false);
  181581. // must be careful not to try to put a topmost window behind a normal one, or win32
  181582. // promotes the normal one to be topmost!
  181583. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181584. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181585. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181586. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181587. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181588. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181589. }
  181590. }
  181591. bool isFocused() const
  181592. {
  181593. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181594. }
  181595. void grabFocus()
  181596. {
  181597. const bool oldDeactivate = shouldDeactivateTitleBar;
  181598. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181599. callFunctionIfNotLocked (&setFocusCallback, hwnd);
  181600. shouldDeactivateTitleBar = oldDeactivate;
  181601. }
  181602. void textInputRequired (const Point<int>&)
  181603. {
  181604. if (! hasCreatedCaret)
  181605. {
  181606. hasCreatedCaret = true;
  181607. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181608. }
  181609. ShowCaret (hwnd);
  181610. SetCaretPos (0, 0);
  181611. }
  181612. void repaint (int x, int y, int w, int h)
  181613. {
  181614. const RECT r = { x, y, x + w, y + h };
  181615. InvalidateRect (hwnd, &r, FALSE);
  181616. }
  181617. void performAnyPendingRepaintsNow()
  181618. {
  181619. MSG m;
  181620. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181621. DispatchMessage (&m);
  181622. }
  181623. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181624. {
  181625. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181626. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181627. return 0;
  181628. }
  181629. void setTaskBarIcon (const Image* const image)
  181630. {
  181631. if (image != 0)
  181632. {
  181633. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181634. if (taskBarIcon == 0)
  181635. {
  181636. taskBarIcon = new NOTIFYICONDATA();
  181637. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181638. taskBarIcon->hWnd = (HWND) hwnd;
  181639. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181640. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181641. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181642. taskBarIcon->hIcon = hicon;
  181643. taskBarIcon->szTip[0] = 0;
  181644. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181645. }
  181646. else
  181647. {
  181648. HICON oldIcon = taskBarIcon->hIcon;
  181649. taskBarIcon->hIcon = hicon;
  181650. taskBarIcon->uFlags = NIF_ICON;
  181651. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181652. DestroyIcon (oldIcon);
  181653. }
  181654. DestroyIcon (hicon);
  181655. }
  181656. else if (taskBarIcon != 0)
  181657. {
  181658. taskBarIcon->uFlags = 0;
  181659. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181660. DestroyIcon (taskBarIcon->hIcon);
  181661. deleteAndZero (taskBarIcon);
  181662. }
  181663. }
  181664. void setTaskBarIconToolTip (const String& toolTip) const
  181665. {
  181666. if (taskBarIcon != 0)
  181667. {
  181668. taskBarIcon->uFlags = NIF_TIP;
  181669. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181670. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181671. }
  181672. }
  181673. bool isInside (HWND h) const
  181674. {
  181675. return GetAncestor (hwnd, GA_ROOT) == h;
  181676. }
  181677. static void updateKeyModifiers() throw()
  181678. {
  181679. int keyMods = 0;
  181680. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181681. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181682. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181683. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181684. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181685. }
  181686. static void updateModifiersFromWParam (const WPARAM wParam)
  181687. {
  181688. int mouseMods = 0;
  181689. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181690. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181691. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181692. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181693. updateKeyModifiers();
  181694. }
  181695. static int64 getMouseEventTime()
  181696. {
  181697. static int64 eventTimeOffset = 0;
  181698. static DWORD lastMessageTime = 0;
  181699. const DWORD thisMessageTime = GetMessageTime();
  181700. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181701. {
  181702. lastMessageTime = thisMessageTime;
  181703. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181704. }
  181705. return eventTimeOffset + thisMessageTime;
  181706. }
  181707. juce_UseDebuggingNewOperator
  181708. bool dontRepaint;
  181709. static ModifierKeys currentModifiers;
  181710. static ModifierKeys modifiersAtLastCallback;
  181711. private:
  181712. HWND hwnd;
  181713. DropShadower* shadower;
  181714. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181715. BorderSize windowBorder;
  181716. HICON currentWindowIcon;
  181717. NOTIFYICONDATA* taskBarIcon;
  181718. IDropTarget* dropTarget;
  181719. class TemporaryImage : public Timer
  181720. {
  181721. public:
  181722. TemporaryImage()
  181723. : image (0)
  181724. {
  181725. }
  181726. ~TemporaryImage()
  181727. {
  181728. delete image;
  181729. }
  181730. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181731. {
  181732. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181733. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181734. {
  181735. delete image;
  181736. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181737. }
  181738. startTimer (3000);
  181739. return image;
  181740. }
  181741. void timerCallback()
  181742. {
  181743. stopTimer();
  181744. deleteAndZero (image);
  181745. }
  181746. private:
  181747. WindowsBitmapImage* image;
  181748. TemporaryImage (const TemporaryImage&);
  181749. TemporaryImage& operator= (const TemporaryImage&);
  181750. };
  181751. TemporaryImage offscreenImageGenerator;
  181752. class WindowClassHolder : public DeletedAtShutdown
  181753. {
  181754. public:
  181755. WindowClassHolder()
  181756. : windowClassName ("JUCE_")
  181757. {
  181758. // this name has to be different for each app/dll instance because otherwise
  181759. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181760. // window class).
  181761. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181762. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181763. TCHAR moduleFile [1024];
  181764. moduleFile[0] = 0;
  181765. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181766. WORD iconNum = 0;
  181767. WNDCLASSEX wcex;
  181768. wcex.cbSize = sizeof (wcex);
  181769. wcex.style = CS_OWNDC;
  181770. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181771. wcex.lpszClassName = windowClassName;
  181772. wcex.cbClsExtra = 0;
  181773. wcex.cbWndExtra = 32;
  181774. wcex.hInstance = moduleHandle;
  181775. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181776. iconNum = 1;
  181777. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181778. wcex.hCursor = 0;
  181779. wcex.hbrBackground = 0;
  181780. wcex.lpszMenuName = 0;
  181781. RegisterClassEx (&wcex);
  181782. }
  181783. ~WindowClassHolder()
  181784. {
  181785. if (ComponentPeer::getNumPeers() == 0)
  181786. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  181787. clearSingletonInstance();
  181788. }
  181789. String windowClassName;
  181790. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  181791. };
  181792. static void* createWindowCallback (void* userData)
  181793. {
  181794. static_cast <Win32ComponentPeer*> (userData)->createWindow();
  181795. return 0;
  181796. }
  181797. void createWindow()
  181798. {
  181799. DWORD exstyle = WS_EX_ACCEPTFILES;
  181800. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  181801. if (hasTitleBar())
  181802. {
  181803. type |= WS_OVERLAPPED;
  181804. exstyle |= WS_EX_APPWINDOW;
  181805. if ((styleFlags & windowHasCloseButton) != 0)
  181806. {
  181807. type |= WS_SYSMENU;
  181808. }
  181809. else
  181810. {
  181811. // annoyingly, windows won't let you have a min/max button without a close button
  181812. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  181813. }
  181814. if ((styleFlags & windowIsResizable) != 0)
  181815. type |= WS_THICKFRAME;
  181816. }
  181817. else
  181818. {
  181819. type |= WS_POPUP | WS_SYSMENU;
  181820. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  181821. exstyle |= WS_EX_TOOLWINDOW;
  181822. else
  181823. exstyle |= WS_EX_APPWINDOW;
  181824. }
  181825. if ((styleFlags & windowHasMinimiseButton) != 0)
  181826. type |= WS_MINIMIZEBOX;
  181827. if ((styleFlags & windowHasMaximiseButton) != 0)
  181828. type |= WS_MAXIMIZEBOX;
  181829. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  181830. exstyle |= WS_EX_TRANSPARENT;
  181831. if ((styleFlags & windowIsSemiTransparent) != 0
  181832. && Desktop::canUseSemiTransparentWindows())
  181833. exstyle |= WS_EX_LAYERED;
  181834. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  181835. if (hwnd != 0)
  181836. {
  181837. SetWindowLongPtr (hwnd, 0, 0);
  181838. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  181839. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  181840. if (dropTarget == 0)
  181841. dropTarget = new JuceDropTarget (this);
  181842. RegisterDragDrop (hwnd, dropTarget);
  181843. updateBorderSize();
  181844. // Calling this function here is (for some reason) necessary to make Windows
  181845. // correctly enable the menu items that we specify in the wm_initmenu message.
  181846. GetSystemMenu (hwnd, false);
  181847. }
  181848. else
  181849. {
  181850. jassertfalse
  181851. }
  181852. }
  181853. static void* destroyWindowCallback (void* handle)
  181854. {
  181855. RevokeDragDrop ((HWND) handle);
  181856. DestroyWindow ((HWND) handle);
  181857. return 0;
  181858. }
  181859. static void* toFrontCallback1 (void* h)
  181860. {
  181861. SetForegroundWindow ((HWND) h);
  181862. return 0;
  181863. }
  181864. static void* toFrontCallback2 (void* h)
  181865. {
  181866. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181867. return 0;
  181868. }
  181869. static void* setFocusCallback (void* h)
  181870. {
  181871. SetFocus ((HWND) h);
  181872. return 0;
  181873. }
  181874. static void* getFocusCallback (void*)
  181875. {
  181876. return GetFocus();
  181877. }
  181878. void offsetWithinParent (int& x, int& y) const
  181879. {
  181880. if (isTransparent())
  181881. {
  181882. HWND parentHwnd = GetParent (hwnd);
  181883. if (parentHwnd != 0)
  181884. {
  181885. RECT parentRect;
  181886. GetWindowRect (parentHwnd, &parentRect);
  181887. x += parentRect.left;
  181888. y += parentRect.top;
  181889. }
  181890. }
  181891. }
  181892. bool isTransparent() const
  181893. {
  181894. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  181895. }
  181896. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  181897. void setIcon (const Image& newIcon)
  181898. {
  181899. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  181900. if (hicon != 0)
  181901. {
  181902. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  181903. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  181904. if (currentWindowIcon != 0)
  181905. DestroyIcon (currentWindowIcon);
  181906. currentWindowIcon = hicon;
  181907. }
  181908. }
  181909. void handlePaintMessage()
  181910. {
  181911. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  181912. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  181913. PAINTSTRUCT paintStruct;
  181914. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  181915. // message and become re-entrant, but that's OK
  181916. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  181917. // corrupt the image it's using to paint into, so do a check here.
  181918. static bool reentrant = false;
  181919. if (reentrant)
  181920. {
  181921. DeleteObject (rgn);
  181922. EndPaint (hwnd, &paintStruct);
  181923. return;
  181924. }
  181925. reentrant = true;
  181926. // this is the rectangle to update..
  181927. int x = paintStruct.rcPaint.left;
  181928. int y = paintStruct.rcPaint.top;
  181929. int w = paintStruct.rcPaint.right - x;
  181930. int h = paintStruct.rcPaint.bottom - y;
  181931. const bool transparent = isTransparent();
  181932. if (transparent)
  181933. {
  181934. // it's not possible to have a transparent window with a title bar at the moment!
  181935. jassert (! hasTitleBar());
  181936. RECT r;
  181937. GetWindowRect (hwnd, &r);
  181938. x = y = 0;
  181939. w = r.right - r.left;
  181940. h = r.bottom - r.top;
  181941. }
  181942. if (w > 0 && h > 0)
  181943. {
  181944. clearMaskedRegion();
  181945. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  181946. RectangleList contextClip;
  181947. bool needToPaintAll = true;
  181948. if (regionType == COMPLEXREGION && ! transparent)
  181949. {
  181950. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  181951. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  181952. DeleteObject (clipRgn);
  181953. char rgnData [8192];
  181954. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  181955. if (res > 0 && res <= sizeof (rgnData))
  181956. {
  181957. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  181958. if (hdr->iType == RDH_RECTANGLES
  181959. && hdr->rcBound.right - hdr->rcBound.left >= w
  181960. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  181961. {
  181962. needToPaintAll = false;
  181963. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  181964. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  181965. while (--num >= 0)
  181966. {
  181967. // (need to move this one pixel to the left because of a win32 bug)
  181968. const int cx = jmax (x, (int) rects->left - 1);
  181969. const int cy = rects->top;
  181970. const int cw = rects->right - cx;
  181971. const int ch = rects->bottom - rects->top;
  181972. if (cx + cw - x <= w && cy + ch - y <= h)
  181973. {
  181974. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  181975. }
  181976. else
  181977. {
  181978. needToPaintAll = true;
  181979. break;
  181980. }
  181981. ++rects;
  181982. }
  181983. }
  181984. }
  181985. }
  181986. if (needToPaintAll)
  181987. {
  181988. contextClip.clear();
  181989. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  181990. }
  181991. if (transparent)
  181992. {
  181993. RectangleList::Iterator i (contextClip);
  181994. while (i.next())
  181995. {
  181996. const Rectangle<int>& r = *i.getRectangle();
  181997. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  181998. }
  181999. }
  182000. // if the component's not opaque, this won't draw properly unless the platform can support this
  182001. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182002. updateCurrentModifiers();
  182003. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182004. context.clipToRectangleList (contextClip);
  182005. context.setOrigin (-x, -y);
  182006. handlePaint (context);
  182007. if (! dontRepaint)
  182008. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182009. }
  182010. DeleteObject (rgn);
  182011. EndPaint (hwnd, &paintStruct);
  182012. reentrant = false;
  182013. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182014. _fpreset(); // because some graphics cards can unmask FP exceptions
  182015. #endif
  182016. lastPaintTime = Time::getMillisecondCounter();
  182017. }
  182018. void doMouseEvent (const Point<int>& position)
  182019. {
  182020. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182021. }
  182022. void doMouseMove (const Point<int>& position)
  182023. {
  182024. if (! isMouseOver)
  182025. {
  182026. isMouseOver = true;
  182027. updateKeyModifiers();
  182028. TRACKMOUSEEVENT tme;
  182029. tme.cbSize = sizeof (tme);
  182030. tme.dwFlags = TME_LEAVE;
  182031. tme.hwndTrack = hwnd;
  182032. tme.dwHoverTime = 0;
  182033. if (! TrackMouseEvent (&tme))
  182034. jassertfalse;
  182035. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182036. }
  182037. else if (! isDragging)
  182038. {
  182039. if (! contains (position, false))
  182040. return;
  182041. }
  182042. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182043. static uint32 lastMouseTime = 0;
  182044. const uint32 now = Time::getMillisecondCounter();
  182045. const int maxMouseMovesPerSecond = 60;
  182046. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182047. {
  182048. lastMouseTime = now;
  182049. doMouseEvent (position);
  182050. }
  182051. }
  182052. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182053. {
  182054. if (GetCapture() != hwnd)
  182055. SetCapture (hwnd);
  182056. doMouseMove (position);
  182057. updateModifiersFromWParam (wParam);
  182058. isDragging = true;
  182059. doMouseEvent (position);
  182060. }
  182061. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182062. {
  182063. updateModifiersFromWParam (wParam);
  182064. isDragging = false;
  182065. // release the mouse capture if the user has released all buttons
  182066. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182067. ReleaseCapture();
  182068. doMouseEvent (position);
  182069. }
  182070. void doCaptureChanged()
  182071. {
  182072. if (isDragging)
  182073. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182074. }
  182075. void doMouseExit()
  182076. {
  182077. isMouseOver = false;
  182078. doMouseEvent (getCurrentMousePos());
  182079. }
  182080. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182081. {
  182082. updateKeyModifiers();
  182083. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182084. handleMouseWheel (0, position, getMouseEventTime(),
  182085. isVertical ? 0.0f : amount,
  182086. isVertical ? amount : 0.0f);
  182087. }
  182088. void sendModifierKeyChangeIfNeeded()
  182089. {
  182090. if (modifiersAtLastCallback != currentModifiers)
  182091. {
  182092. modifiersAtLastCallback = currentModifiers;
  182093. handleModifierKeysChange();
  182094. }
  182095. }
  182096. bool doKeyUp (const WPARAM key)
  182097. {
  182098. updateKeyModifiers();
  182099. switch (key)
  182100. {
  182101. case VK_SHIFT:
  182102. case VK_CONTROL:
  182103. case VK_MENU:
  182104. case VK_CAPITAL:
  182105. case VK_LWIN:
  182106. case VK_RWIN:
  182107. case VK_APPS:
  182108. case VK_NUMLOCK:
  182109. case VK_SCROLL:
  182110. case VK_LSHIFT:
  182111. case VK_RSHIFT:
  182112. case VK_LCONTROL:
  182113. case VK_LMENU:
  182114. case VK_RCONTROL:
  182115. case VK_RMENU:
  182116. sendModifierKeyChangeIfNeeded();
  182117. }
  182118. return handleKeyUpOrDown (false)
  182119. || Component::getCurrentlyModalComponent() != 0;
  182120. }
  182121. bool doKeyDown (const WPARAM key)
  182122. {
  182123. updateKeyModifiers();
  182124. bool used = false;
  182125. switch (key)
  182126. {
  182127. case VK_SHIFT:
  182128. case VK_LSHIFT:
  182129. case VK_RSHIFT:
  182130. case VK_CONTROL:
  182131. case VK_LCONTROL:
  182132. case VK_RCONTROL:
  182133. case VK_MENU:
  182134. case VK_LMENU:
  182135. case VK_RMENU:
  182136. case VK_LWIN:
  182137. case VK_RWIN:
  182138. case VK_CAPITAL:
  182139. case VK_NUMLOCK:
  182140. case VK_SCROLL:
  182141. case VK_APPS:
  182142. sendModifierKeyChangeIfNeeded();
  182143. break;
  182144. case VK_LEFT:
  182145. case VK_RIGHT:
  182146. case VK_UP:
  182147. case VK_DOWN:
  182148. case VK_PRIOR:
  182149. case VK_NEXT:
  182150. case VK_HOME:
  182151. case VK_END:
  182152. case VK_DELETE:
  182153. case VK_INSERT:
  182154. case VK_F1:
  182155. case VK_F2:
  182156. case VK_F3:
  182157. case VK_F4:
  182158. case VK_F5:
  182159. case VK_F6:
  182160. case VK_F7:
  182161. case VK_F8:
  182162. case VK_F9:
  182163. case VK_F10:
  182164. case VK_F11:
  182165. case VK_F12:
  182166. case VK_F13:
  182167. case VK_F14:
  182168. case VK_F15:
  182169. case VK_F16:
  182170. used = handleKeyUpOrDown (true);
  182171. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182172. break;
  182173. case VK_ADD:
  182174. case VK_SUBTRACT:
  182175. case VK_MULTIPLY:
  182176. case VK_DIVIDE:
  182177. case VK_SEPARATOR:
  182178. case VK_DECIMAL:
  182179. used = handleKeyUpOrDown (true);
  182180. break;
  182181. default:
  182182. used = handleKeyUpOrDown (true);
  182183. {
  182184. MSG msg;
  182185. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182186. {
  182187. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182188. // manually generate the key-press event that matches this key-down.
  182189. const UINT keyChar = MapVirtualKey (key, 2);
  182190. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182191. }
  182192. }
  182193. break;
  182194. }
  182195. if (Component::getCurrentlyModalComponent() != 0)
  182196. used = true;
  182197. return used;
  182198. }
  182199. bool doKeyChar (int key, const LPARAM flags)
  182200. {
  182201. updateKeyModifiers();
  182202. juce_wchar textChar = (juce_wchar) key;
  182203. const int virtualScanCode = (flags >> 16) & 0xff;
  182204. if (key >= '0' && key <= '9')
  182205. {
  182206. switch (virtualScanCode) // check for a numeric keypad scan-code
  182207. {
  182208. case 0x52:
  182209. case 0x4f:
  182210. case 0x50:
  182211. case 0x51:
  182212. case 0x4b:
  182213. case 0x4c:
  182214. case 0x4d:
  182215. case 0x47:
  182216. case 0x48:
  182217. case 0x49:
  182218. key = (key - '0') + KeyPress::numberPad0;
  182219. break;
  182220. default:
  182221. break;
  182222. }
  182223. }
  182224. else
  182225. {
  182226. // convert the scan code to an unmodified character code..
  182227. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182228. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182229. keyChar = LOWORD (keyChar);
  182230. if (keyChar != 0)
  182231. key = (int) keyChar;
  182232. // avoid sending junk text characters for some control-key combinations
  182233. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182234. textChar = 0;
  182235. }
  182236. return handleKeyPress (key, textChar);
  182237. }
  182238. bool doAppCommand (const LPARAM lParam)
  182239. {
  182240. int key = 0;
  182241. switch (GET_APPCOMMAND_LPARAM (lParam))
  182242. {
  182243. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182244. key = KeyPress::playKey;
  182245. break;
  182246. case APPCOMMAND_MEDIA_STOP:
  182247. key = KeyPress::stopKey;
  182248. break;
  182249. case APPCOMMAND_MEDIA_NEXTTRACK:
  182250. key = KeyPress::fastForwardKey;
  182251. break;
  182252. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182253. key = KeyPress::rewindKey;
  182254. break;
  182255. }
  182256. if (key != 0)
  182257. {
  182258. updateKeyModifiers();
  182259. if (hwnd == GetActiveWindow())
  182260. {
  182261. handleKeyPress (key, 0);
  182262. return true;
  182263. }
  182264. }
  182265. return false;
  182266. }
  182267. class JuceDropTarget : public IDropTarget
  182268. {
  182269. public:
  182270. JuceDropTarget (Win32ComponentPeer* const owner_)
  182271. : owner (owner_),
  182272. refCount (1)
  182273. {
  182274. }
  182275. virtual ~JuceDropTarget()
  182276. {
  182277. jassert (refCount == 0);
  182278. }
  182279. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182280. {
  182281. if (id == IID_IUnknown || id == IID_IDropTarget)
  182282. {
  182283. AddRef();
  182284. *result = this;
  182285. return S_OK;
  182286. }
  182287. *result = 0;
  182288. return E_NOINTERFACE;
  182289. }
  182290. ULONG __stdcall AddRef() { return ++refCount; }
  182291. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182292. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182293. {
  182294. updateFileList (pDataObject);
  182295. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182296. *pdwEffect = DROPEFFECT_COPY;
  182297. return S_OK;
  182298. }
  182299. HRESULT __stdcall DragLeave()
  182300. {
  182301. owner->handleFileDragExit (files);
  182302. return S_OK;
  182303. }
  182304. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182305. {
  182306. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182307. *pdwEffect = DROPEFFECT_COPY;
  182308. return S_OK;
  182309. }
  182310. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182311. {
  182312. updateFileList (pDataObject);
  182313. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182314. *pdwEffect = DROPEFFECT_COPY;
  182315. return S_OK;
  182316. }
  182317. private:
  182318. Win32ComponentPeer* const owner;
  182319. int refCount;
  182320. StringArray files;
  182321. void updateFileList (IDataObject* const pDataObject)
  182322. {
  182323. files.clear();
  182324. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182325. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182326. if (pDataObject->GetData (&format, &medium) == S_OK)
  182327. {
  182328. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182329. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182330. unsigned int i = 0;
  182331. if (pDropFiles->fWide)
  182332. {
  182333. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182334. for (;;)
  182335. {
  182336. unsigned int len = 0;
  182337. while (i + len < totalLen && fname [i + len] != 0)
  182338. ++len;
  182339. if (len == 0)
  182340. break;
  182341. files.add (String (fname + i, len));
  182342. i += len + 1;
  182343. }
  182344. }
  182345. else
  182346. {
  182347. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182348. for (;;)
  182349. {
  182350. unsigned int len = 0;
  182351. while (i + len < totalLen && fname [i + len] != 0)
  182352. ++len;
  182353. if (len == 0)
  182354. break;
  182355. files.add (String (fname + i, len));
  182356. i += len + 1;
  182357. }
  182358. }
  182359. GlobalUnlock (medium.hGlobal);
  182360. }
  182361. }
  182362. JuceDropTarget (const JuceDropTarget&);
  182363. JuceDropTarget& operator= (const JuceDropTarget&);
  182364. };
  182365. void doSettingChange()
  182366. {
  182367. Desktop::getInstance().refreshMonitorSizes();
  182368. if (fullScreen && ! isMinimised())
  182369. {
  182370. const Rectangle<int> r (component->getParentMonitorArea());
  182371. SetWindowPos (hwnd, 0,
  182372. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182373. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182374. }
  182375. }
  182376. public:
  182377. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182378. {
  182379. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182380. if (peer != 0)
  182381. return peer->peerWindowProc (h, message, wParam, lParam);
  182382. return DefWindowProcW (h, message, wParam, lParam);
  182383. }
  182384. private:
  182385. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182386. {
  182387. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182388. }
  182389. const Point<int> getCurrentMousePos() throw()
  182390. {
  182391. RECT wr;
  182392. GetWindowRect (hwnd, &wr);
  182393. const DWORD mp = GetMessagePos();
  182394. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182395. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182396. }
  182397. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182398. {
  182399. if (isValidPeer (this))
  182400. {
  182401. switch (message)
  182402. {
  182403. case WM_NCHITTEST:
  182404. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182405. return HTTRANSPARENT;
  182406. if (hasTitleBar())
  182407. break;
  182408. return HTCLIENT;
  182409. case WM_PAINT:
  182410. handlePaintMessage();
  182411. return 0;
  182412. case WM_NCPAINT:
  182413. if (wParam != 1)
  182414. handlePaintMessage();
  182415. if (hasTitleBar())
  182416. break;
  182417. return 0;
  182418. case WM_ERASEBKGND:
  182419. case WM_NCCALCSIZE:
  182420. if (hasTitleBar())
  182421. break;
  182422. return 1;
  182423. case WM_MOUSEMOVE:
  182424. doMouseMove (getPointFromLParam (lParam));
  182425. return 0;
  182426. case WM_MOUSELEAVE:
  182427. doMouseExit();
  182428. return 0;
  182429. case WM_LBUTTONDOWN:
  182430. case WM_MBUTTONDOWN:
  182431. case WM_RBUTTONDOWN:
  182432. doMouseDown (getPointFromLParam (lParam), wParam);
  182433. return 0;
  182434. case WM_LBUTTONUP:
  182435. case WM_MBUTTONUP:
  182436. case WM_RBUTTONUP:
  182437. doMouseUp (getPointFromLParam (lParam), wParam);
  182438. return 0;
  182439. case WM_CAPTURECHANGED:
  182440. doCaptureChanged();
  182441. return 0;
  182442. case WM_NCMOUSEMOVE:
  182443. if (hasTitleBar())
  182444. break;
  182445. return 0;
  182446. case 0x020A: /* WM_MOUSEWHEEL */
  182447. doMouseWheel (getCurrentMousePos(), wParam, true);
  182448. return 0;
  182449. case 0x020E: /* WM_MOUSEHWHEEL */
  182450. doMouseWheel (getCurrentMousePos(), wParam, false);
  182451. return 0;
  182452. case WM_WINDOWPOSCHANGING:
  182453. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182454. {
  182455. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182456. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182457. {
  182458. if (constrainer != 0)
  182459. {
  182460. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182461. component->getY() - windowBorder.getTop(),
  182462. component->getWidth() + windowBorder.getLeftAndRight(),
  182463. component->getHeight() + windowBorder.getTopAndBottom());
  182464. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182465. constrainer->checkBounds (pos, current,
  182466. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182467. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182468. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182469. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182470. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182471. wp->x = pos.getX();
  182472. wp->y = pos.getY();
  182473. wp->cx = pos.getWidth();
  182474. wp->cy = pos.getHeight();
  182475. }
  182476. }
  182477. }
  182478. return 0;
  182479. case WM_WINDOWPOSCHANGED:
  182480. handleMovedOrResized();
  182481. if (dontRepaint)
  182482. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182483. return 0;
  182484. case WM_KEYDOWN:
  182485. case WM_SYSKEYDOWN:
  182486. if (doKeyDown (wParam))
  182487. return 0;
  182488. break;
  182489. case WM_KEYUP:
  182490. case WM_SYSKEYUP:
  182491. if (doKeyUp (wParam))
  182492. return 0;
  182493. break;
  182494. case WM_CHAR:
  182495. if (doKeyChar ((int) wParam, lParam))
  182496. return 0;
  182497. break;
  182498. case WM_APPCOMMAND:
  182499. if (doAppCommand (lParam))
  182500. return TRUE;
  182501. break;
  182502. case WM_SETFOCUS:
  182503. updateKeyModifiers();
  182504. handleFocusGain();
  182505. break;
  182506. case WM_KILLFOCUS:
  182507. if (hasCreatedCaret)
  182508. {
  182509. hasCreatedCaret = false;
  182510. DestroyCaret();
  182511. }
  182512. handleFocusLoss();
  182513. break;
  182514. case WM_ACTIVATEAPP:
  182515. // Windows does weird things to process priority when you swap apps,
  182516. // so this forces an update when the app is brought to the front
  182517. if (wParam != FALSE)
  182518. juce_repeatLastProcessPriority();
  182519. else
  182520. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182521. juce_CheckCurrentlyFocusedTopLevelWindow();
  182522. modifiersAtLastCallback = -1;
  182523. return 0;
  182524. case WM_ACTIVATE:
  182525. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182526. {
  182527. modifiersAtLastCallback = -1;
  182528. updateKeyModifiers();
  182529. if (isMinimised())
  182530. {
  182531. component->repaint();
  182532. handleMovedOrResized();
  182533. if (! ComponentPeer::isValidPeer (this))
  182534. return 0;
  182535. }
  182536. if (LOWORD (wParam) == WA_CLICKACTIVE
  182537. && component->isCurrentlyBlockedByAnotherModalComponent())
  182538. {
  182539. const Point<int> mousePos (component->getMouseXYRelative());
  182540. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182541. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182542. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182543. return 0;
  182544. }
  182545. handleBroughtToFront();
  182546. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182547. Component::getCurrentlyModalComponent()->toFront (true);
  182548. return 0;
  182549. }
  182550. break;
  182551. case WM_NCACTIVATE:
  182552. // while a temporary window is being shown, prevent Windows from deactivating the
  182553. // title bars of our main windows.
  182554. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182555. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182556. break;
  182557. case WM_MOUSEACTIVATE:
  182558. if (! component->getMouseClickGrabsKeyboardFocus())
  182559. return MA_NOACTIVATE;
  182560. break;
  182561. case WM_SHOWWINDOW:
  182562. if (wParam != 0)
  182563. handleBroughtToFront();
  182564. break;
  182565. case WM_CLOSE:
  182566. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182567. handleUserClosingWindow();
  182568. return 0;
  182569. case WM_QUERYENDSESSION:
  182570. if (JUCEApplication::getInstance() != 0)
  182571. {
  182572. JUCEApplication::getInstance()->systemRequestedQuit();
  182573. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182574. }
  182575. return TRUE;
  182576. case WM_TRAYNOTIFY:
  182577. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182578. {
  182579. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182580. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182581. {
  182582. Component* const current = Component::getCurrentlyModalComponent();
  182583. if (current != 0)
  182584. current->inputAttemptWhenModal();
  182585. }
  182586. }
  182587. else
  182588. {
  182589. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182590. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182591. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182592. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182593. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182594. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182595. eventMods = eventMods.withoutMouseButtons();
  182596. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182597. Point<int>(), eventMods, component, getMouseEventTime(),
  182598. Point<int>(), getMouseEventTime(), 1, false);
  182599. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182600. {
  182601. SetFocus (hwnd);
  182602. SetForegroundWindow (hwnd);
  182603. component->mouseDown (e);
  182604. }
  182605. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182606. {
  182607. component->mouseUp (e);
  182608. }
  182609. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182610. {
  182611. component->mouseDoubleClick (e);
  182612. }
  182613. else if (lParam == WM_MOUSEMOVE)
  182614. {
  182615. component->mouseMove (e);
  182616. }
  182617. }
  182618. break;
  182619. case WM_SYNCPAINT:
  182620. return 0;
  182621. case WM_PALETTECHANGED:
  182622. InvalidateRect (h, 0, 0);
  182623. break;
  182624. case WM_DISPLAYCHANGE:
  182625. InvalidateRect (h, 0, 0);
  182626. createPaletteIfNeeded = true;
  182627. // intentional fall-through...
  182628. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182629. doSettingChange();
  182630. break;
  182631. case WM_INITMENU:
  182632. if (! hasTitleBar())
  182633. {
  182634. if (isFullScreen())
  182635. {
  182636. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182637. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182638. }
  182639. else if (! isMinimised())
  182640. {
  182641. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182642. }
  182643. }
  182644. break;
  182645. case WM_SYSCOMMAND:
  182646. switch (wParam & 0xfff0)
  182647. {
  182648. case SC_CLOSE:
  182649. if (sendInputAttemptWhenModalMessage())
  182650. return 0;
  182651. if (hasTitleBar())
  182652. {
  182653. PostMessage (h, WM_CLOSE, 0, 0);
  182654. return 0;
  182655. }
  182656. break;
  182657. case SC_KEYMENU:
  182658. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182659. // obscure situations that can arise if a modal loop is started from an alt-key
  182660. // keypress).
  182661. if (hasTitleBar() && h == GetCapture())
  182662. ReleaseCapture();
  182663. break;
  182664. case SC_MAXIMIZE:
  182665. if (sendInputAttemptWhenModalMessage())
  182666. return 0;
  182667. setFullScreen (true);
  182668. return 0;
  182669. case SC_MINIMIZE:
  182670. if (sendInputAttemptWhenModalMessage())
  182671. return 0;
  182672. if (! hasTitleBar())
  182673. {
  182674. setMinimised (true);
  182675. return 0;
  182676. }
  182677. break;
  182678. case SC_RESTORE:
  182679. if (sendInputAttemptWhenModalMessage())
  182680. return 0;
  182681. if (hasTitleBar())
  182682. {
  182683. if (isFullScreen())
  182684. {
  182685. setFullScreen (false);
  182686. return 0;
  182687. }
  182688. }
  182689. else
  182690. {
  182691. if (isMinimised())
  182692. setMinimised (false);
  182693. else if (isFullScreen())
  182694. setFullScreen (false);
  182695. return 0;
  182696. }
  182697. break;
  182698. }
  182699. break;
  182700. case WM_NCLBUTTONDOWN:
  182701. case WM_NCRBUTTONDOWN:
  182702. case WM_NCMBUTTONDOWN:
  182703. sendInputAttemptWhenModalMessage();
  182704. break;
  182705. //case WM_IME_STARTCOMPOSITION;
  182706. // return 0;
  182707. case WM_GETDLGCODE:
  182708. return DLGC_WANTALLKEYS;
  182709. default:
  182710. break;
  182711. }
  182712. }
  182713. return DefWindowProcW (h, message, wParam, lParam);
  182714. }
  182715. bool sendInputAttemptWhenModalMessage()
  182716. {
  182717. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182718. {
  182719. Component* const current = Component::getCurrentlyModalComponent();
  182720. if (current != 0)
  182721. current->inputAttemptWhenModal();
  182722. return true;
  182723. }
  182724. return false;
  182725. }
  182726. Win32ComponentPeer (const Win32ComponentPeer&);
  182727. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182728. };
  182729. ModifierKeys Win32ComponentPeer::currentModifiers;
  182730. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182731. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182732. {
  182733. return new Win32ComponentPeer (this, styleFlags);
  182734. }
  182735. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182736. void ModifierKeys::updateCurrentModifiers() throw()
  182737. {
  182738. currentModifiers = Win32ComponentPeer::currentModifiers;
  182739. }
  182740. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182741. {
  182742. Win32ComponentPeer::updateKeyModifiers();
  182743. int keyMods = 0;
  182744. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182745. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182746. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182747. Win32ComponentPeer::currentModifiers
  182748. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182749. return Win32ComponentPeer::currentModifiers;
  182750. }
  182751. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182752. {
  182753. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182754. if (wp != 0)
  182755. wp->setTaskBarIcon (&newImage);
  182756. }
  182757. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182758. {
  182759. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182760. if (wp != 0)
  182761. wp->setTaskBarIconToolTip (tooltip);
  182762. }
  182763. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182764. {
  182765. DWORD val = GetWindowLong (h, styleType);
  182766. if (bitIsSet)
  182767. val |= feature;
  182768. else
  182769. val &= ~feature;
  182770. SetWindowLongPtr (h, styleType, val);
  182771. SetWindowPos (h, 0, 0, 0, 0, 0,
  182772. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182773. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182774. }
  182775. bool Process::isForegroundProcess()
  182776. {
  182777. HWND fg = GetForegroundWindow();
  182778. if (fg == 0)
  182779. return true;
  182780. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  182781. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  182782. // have to see if any of our windows are children of the foreground window
  182783. fg = GetAncestor (fg, GA_ROOT);
  182784. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  182785. {
  182786. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  182787. if (wp != 0 && wp->isInside (fg))
  182788. return true;
  182789. }
  182790. return false;
  182791. }
  182792. bool AlertWindow::showNativeDialogBox (const String& title,
  182793. const String& bodyText,
  182794. bool isOkCancel)
  182795. {
  182796. return MessageBox (0, bodyText, title,
  182797. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  182798. : MB_OK)) == IDOK;
  182799. }
  182800. void Desktop::createMouseInputSources()
  182801. {
  182802. mouseSources.add (new MouseInputSource (0, true));
  182803. }
  182804. const Point<int> Desktop::getMousePosition()
  182805. {
  182806. POINT mousePos;
  182807. GetCursorPos (&mousePos);
  182808. return Point<int> (mousePos.x, mousePos.y);
  182809. }
  182810. void Desktop::setMousePosition (const Point<int>& newPosition)
  182811. {
  182812. SetCursorPos (newPosition.getX(), newPosition.getY());
  182813. }
  182814. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  182815. {
  182816. return new Image (format, imageWidth, imageHeight, clearImage);
  182817. }
  182818. class ScreenSaverDefeater : public Timer,
  182819. public DeletedAtShutdown
  182820. {
  182821. public:
  182822. ScreenSaverDefeater() throw()
  182823. {
  182824. startTimer (10000);
  182825. timerCallback();
  182826. }
  182827. ~ScreenSaverDefeater() {}
  182828. void timerCallback()
  182829. {
  182830. if (Process::isForegroundProcess())
  182831. {
  182832. // simulate a shift key getting pressed..
  182833. INPUT input[2];
  182834. input[0].type = INPUT_KEYBOARD;
  182835. input[0].ki.wVk = VK_SHIFT;
  182836. input[0].ki.dwFlags = 0;
  182837. input[0].ki.dwExtraInfo = 0;
  182838. input[1].type = INPUT_KEYBOARD;
  182839. input[1].ki.wVk = VK_SHIFT;
  182840. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  182841. input[1].ki.dwExtraInfo = 0;
  182842. SendInput (2, input, sizeof (INPUT));
  182843. }
  182844. }
  182845. };
  182846. static ScreenSaverDefeater* screenSaverDefeater = 0;
  182847. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  182848. {
  182849. if (isEnabled)
  182850. {
  182851. deleteAndZero (screenSaverDefeater);
  182852. }
  182853. else if (screenSaverDefeater == 0)
  182854. {
  182855. screenSaverDefeater = new ScreenSaverDefeater();
  182856. }
  182857. }
  182858. bool Desktop::isScreenSaverEnabled() throw()
  182859. {
  182860. return screenSaverDefeater == 0;
  182861. }
  182862. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  182863. {
  182864. if (enableOrDisable)
  182865. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  182866. }
  182867. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  182868. {
  182869. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  182870. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  182871. return TRUE;
  182872. }
  182873. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  182874. {
  182875. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  182876. // make sure the first in the list is the main monitor
  182877. for (int i = 1; i < monitorCoords.size(); ++i)
  182878. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  182879. monitorCoords.swap (i, 0);
  182880. if (monitorCoords.size() == 0)
  182881. {
  182882. RECT r;
  182883. GetWindowRect (GetDesktopWindow(), &r);
  182884. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  182885. }
  182886. if (clipToWorkArea)
  182887. {
  182888. // clip the main monitor to the active non-taskbar area
  182889. RECT r;
  182890. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  182891. Rectangle<int>& screen = monitorCoords.getReference (0);
  182892. screen.setPosition (jmax (screen.getX(), (int) r.left),
  182893. jmax (screen.getY(), (int) r.top));
  182894. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  182895. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  182896. }
  182897. }
  182898. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  182899. {
  182900. Image* im = 0;
  182901. if (bitmap != 0)
  182902. {
  182903. BITMAP bm;
  182904. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  182905. && bm.bmWidth > 0 && bm.bmHeight > 0)
  182906. {
  182907. HDC tempDC = GetDC (0);
  182908. HDC dc = CreateCompatibleDC (tempDC);
  182909. ReleaseDC (0, tempDC);
  182910. SelectObject (dc, bitmap);
  182911. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  182912. for (int y = bm.bmHeight; --y >= 0;)
  182913. {
  182914. for (int x = bm.bmWidth; --x >= 0;)
  182915. {
  182916. COLORREF col = GetPixel (dc, x, y);
  182917. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  182918. (uint8) GetGValue (col),
  182919. (uint8) GetBValue (col)));
  182920. }
  182921. }
  182922. DeleteDC (dc);
  182923. }
  182924. }
  182925. return im;
  182926. }
  182927. static Image* createImageFromHICON (HICON icon) throw()
  182928. {
  182929. ICONINFO info;
  182930. if (GetIconInfo (icon, &info))
  182931. {
  182932. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  182933. if (mask == 0)
  182934. return 0;
  182935. Image* const image = createImageFromHBITMAP (info.hbmColor);
  182936. if (image == 0)
  182937. return mask;
  182938. for (int y = image->getHeight(); --y >= 0;)
  182939. {
  182940. for (int x = image->getWidth(); --x >= 0;)
  182941. {
  182942. const float brightness = mask->getPixelAt (x, y).getBrightness();
  182943. if (brightness > 0.0f)
  182944. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  182945. }
  182946. }
  182947. delete mask;
  182948. return image;
  182949. }
  182950. return 0;
  182951. }
  182952. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  182953. {
  182954. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  182955. ICONINFO info;
  182956. info.fIcon = isIcon;
  182957. info.xHotspot = hotspotX;
  182958. info.yHotspot = hotspotY;
  182959. info.hbmMask = mask;
  182960. HICON hi = 0;
  182961. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  182962. {
  182963. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  182964. Graphics g (bitmap);
  182965. g.drawImageAt (&image, 0, 0);
  182966. info.hbmColor = bitmap.hBitmap;
  182967. hi = CreateIconIndirect (&info);
  182968. }
  182969. else
  182970. {
  182971. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  182972. HDC colDC = CreateCompatibleDC (GetDC (0));
  182973. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  182974. SelectObject (colDC, colour);
  182975. SelectObject (alphaDC, mask);
  182976. for (int y = image.getHeight(); --y >= 0;)
  182977. {
  182978. for (int x = image.getWidth(); --x >= 0;)
  182979. {
  182980. const Colour c (image.getPixelAt (x, y));
  182981. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  182982. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  182983. }
  182984. }
  182985. DeleteDC (colDC);
  182986. DeleteDC (alphaDC);
  182987. info.hbmColor = colour;
  182988. hi = CreateIconIndirect (&info);
  182989. DeleteObject (colour);
  182990. }
  182991. DeleteObject (mask);
  182992. return hi;
  182993. }
  182994. Image* juce_createIconForFile (const File& file)
  182995. {
  182996. Image* image = 0;
  182997. WCHAR filename [1024];
  182998. file.getFullPathName().copyToUnicode (filename, 1023);
  182999. WORD iconNum = 0;
  183000. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183001. filename, &iconNum);
  183002. if (icon != 0)
  183003. {
  183004. image = createImageFromHICON (icon);
  183005. DestroyIcon (icon);
  183006. }
  183007. return image;
  183008. }
  183009. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183010. {
  183011. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183012. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183013. const Image* im = &image;
  183014. Image* newIm = 0;
  183015. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183016. {
  183017. im = newIm = image.createCopy (maxW, maxH);
  183018. hotspotX = (hotspotX * maxW) / image.getWidth();
  183019. hotspotY = (hotspotY * maxH) / image.getHeight();
  183020. }
  183021. void* cursorH = 0;
  183022. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183023. if (os == SystemStats::WinXP)
  183024. {
  183025. cursorH = createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183026. }
  183027. else
  183028. {
  183029. const int stride = (maxW + 7) >> 3;
  183030. HeapBlock <uint8> andPlane, xorPlane;
  183031. andPlane.calloc (stride * maxH);
  183032. xorPlane.calloc (stride * maxH);
  183033. int index = 0;
  183034. for (int y = 0; y < maxH; ++y)
  183035. {
  183036. for (int x = 0; x < maxW; ++x)
  183037. {
  183038. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183039. const Colour pixelColour (im->getPixelAt (x, y));
  183040. if (pixelColour.getAlpha() < 127)
  183041. andPlane [index + (x >> 3)] |= bit;
  183042. else if (pixelColour.getBrightness() >= 0.5f)
  183043. xorPlane [index + (x >> 3)] |= bit;
  183044. }
  183045. index += stride;
  183046. }
  183047. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183048. }
  183049. delete newIm;
  183050. return cursorH;
  183051. }
  183052. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183053. {
  183054. if (cursorHandle != 0 && ! isStandard)
  183055. DestroyCursor ((HCURSOR) cursorHandle);
  183056. }
  183057. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183058. {
  183059. LPCTSTR cursorName = IDC_ARROW;
  183060. switch (type)
  183061. {
  183062. case MouseCursor::NormalCursor:
  183063. cursorName = IDC_ARROW;
  183064. break;
  183065. case MouseCursor::NoCursor:
  183066. return 0;
  183067. case MouseCursor::DraggingHandCursor:
  183068. {
  183069. static void* dragHandCursor = 0;
  183070. if (dragHandCursor == 0)
  183071. {
  183072. static const unsigned char dragHandData[] =
  183073. { 71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  183074. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39, 132,117,151,116,132,146,248,60,209,138,
  183075. 98,22,203,114,34,236,37,52,77,217,247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  183076. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183077. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183078. }
  183079. return dragHandCursor;
  183080. }
  183081. case MouseCursor::WaitCursor:
  183082. cursorName = IDC_WAIT;
  183083. break;
  183084. case MouseCursor::IBeamCursor:
  183085. cursorName = IDC_IBEAM;
  183086. break;
  183087. case MouseCursor::PointingHandCursor:
  183088. cursorName = MAKEINTRESOURCE(32649);
  183089. break;
  183090. case MouseCursor::LeftRightResizeCursor:
  183091. case MouseCursor::LeftEdgeResizeCursor:
  183092. case MouseCursor::RightEdgeResizeCursor:
  183093. cursorName = IDC_SIZEWE;
  183094. break;
  183095. case MouseCursor::UpDownResizeCursor:
  183096. case MouseCursor::TopEdgeResizeCursor:
  183097. case MouseCursor::BottomEdgeResizeCursor:
  183098. cursorName = IDC_SIZENS;
  183099. break;
  183100. case MouseCursor::TopLeftCornerResizeCursor:
  183101. case MouseCursor::BottomRightCornerResizeCursor:
  183102. cursorName = IDC_SIZENWSE;
  183103. break;
  183104. case MouseCursor::TopRightCornerResizeCursor:
  183105. case MouseCursor::BottomLeftCornerResizeCursor:
  183106. cursorName = IDC_SIZENESW;
  183107. break;
  183108. case MouseCursor::UpDownLeftRightResizeCursor:
  183109. cursorName = IDC_SIZEALL;
  183110. break;
  183111. case MouseCursor::CrosshairCursor:
  183112. cursorName = IDC_CROSS;
  183113. break;
  183114. case MouseCursor::CopyingCursor:
  183115. // can't seem to find one of these in the win32 list..
  183116. break;
  183117. }
  183118. HCURSOR cursorH = LoadCursor (0, cursorName);
  183119. if (cursorH == 0)
  183120. cursorH = LoadCursor (0, IDC_ARROW);
  183121. return cursorH;
  183122. }
  183123. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183124. {
  183125. SetCursor ((HCURSOR) getHandle());
  183126. }
  183127. void MouseCursor::showInAllWindows() const throw()
  183128. {
  183129. showInWindow (0);
  183130. }
  183131. class JuceDropSource : public IDropSource
  183132. {
  183133. int refCount;
  183134. public:
  183135. JuceDropSource()
  183136. : refCount (1)
  183137. {
  183138. }
  183139. virtual ~JuceDropSource()
  183140. {
  183141. jassert (refCount == 0);
  183142. }
  183143. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183144. {
  183145. if (id == IID_IUnknown || id == IID_IDropSource)
  183146. {
  183147. AddRef();
  183148. *result = this;
  183149. return S_OK;
  183150. }
  183151. *result = 0;
  183152. return E_NOINTERFACE;
  183153. }
  183154. ULONG __stdcall AddRef() { return ++refCount; }
  183155. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183156. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183157. {
  183158. if (escapePressed)
  183159. return DRAGDROP_S_CANCEL;
  183160. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183161. return DRAGDROP_S_DROP;
  183162. return S_OK;
  183163. }
  183164. HRESULT __stdcall GiveFeedback (DWORD)
  183165. {
  183166. return DRAGDROP_S_USEDEFAULTCURSORS;
  183167. }
  183168. };
  183169. class JuceEnumFormatEtc : public IEnumFORMATETC
  183170. {
  183171. public:
  183172. JuceEnumFormatEtc (const FORMATETC* const format_)
  183173. : refCount (1),
  183174. format (format_),
  183175. index (0)
  183176. {
  183177. }
  183178. virtual ~JuceEnumFormatEtc()
  183179. {
  183180. jassert (refCount == 0);
  183181. }
  183182. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183183. {
  183184. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183185. {
  183186. AddRef();
  183187. *result = this;
  183188. return S_OK;
  183189. }
  183190. *result = 0;
  183191. return E_NOINTERFACE;
  183192. }
  183193. ULONG __stdcall AddRef() { return ++refCount; }
  183194. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183195. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183196. {
  183197. if (result == 0)
  183198. return E_POINTER;
  183199. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183200. newOne->index = index;
  183201. *result = newOne;
  183202. return S_OK;
  183203. }
  183204. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183205. {
  183206. if (pceltFetched != 0)
  183207. *pceltFetched = 0;
  183208. else if (celt != 1)
  183209. return S_FALSE;
  183210. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183211. {
  183212. copyFormatEtc (lpFormatEtc [0], *format);
  183213. ++index;
  183214. if (pceltFetched != 0)
  183215. *pceltFetched = 1;
  183216. return S_OK;
  183217. }
  183218. return S_FALSE;
  183219. }
  183220. HRESULT __stdcall Skip (ULONG celt)
  183221. {
  183222. if (index + (int) celt >= 1)
  183223. return S_FALSE;
  183224. index += celt;
  183225. return S_OK;
  183226. }
  183227. HRESULT __stdcall Reset()
  183228. {
  183229. index = 0;
  183230. return S_OK;
  183231. }
  183232. private:
  183233. int refCount;
  183234. const FORMATETC* const format;
  183235. int index;
  183236. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183237. {
  183238. dest = source;
  183239. if (source.ptd != 0)
  183240. {
  183241. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183242. *(dest.ptd) = *(source.ptd);
  183243. }
  183244. }
  183245. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183246. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183247. };
  183248. class JuceDataObject : public IDataObject
  183249. {
  183250. JuceDropSource* const dropSource;
  183251. const FORMATETC* const format;
  183252. const STGMEDIUM* const medium;
  183253. int refCount;
  183254. JuceDataObject (const JuceDataObject&);
  183255. JuceDataObject& operator= (const JuceDataObject&);
  183256. public:
  183257. JuceDataObject (JuceDropSource* const dropSource_,
  183258. const FORMATETC* const format_,
  183259. const STGMEDIUM* const medium_)
  183260. : dropSource (dropSource_),
  183261. format (format_),
  183262. medium (medium_),
  183263. refCount (1)
  183264. {
  183265. }
  183266. virtual ~JuceDataObject()
  183267. {
  183268. jassert (refCount == 0);
  183269. }
  183270. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183271. {
  183272. if (id == IID_IUnknown || id == IID_IDataObject)
  183273. {
  183274. AddRef();
  183275. *result = this;
  183276. return S_OK;
  183277. }
  183278. *result = 0;
  183279. return E_NOINTERFACE;
  183280. }
  183281. ULONG __stdcall AddRef() { return ++refCount; }
  183282. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183283. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183284. {
  183285. if ((pFormatEtc->tymed & format->tymed) != 0
  183286. && pFormatEtc->cfFormat == format->cfFormat
  183287. && pFormatEtc->dwAspect == format->dwAspect)
  183288. {
  183289. pMedium->tymed = format->tymed;
  183290. pMedium->pUnkForRelease = 0;
  183291. if (format->tymed == TYMED_HGLOBAL)
  183292. {
  183293. const SIZE_T len = GlobalSize (medium->hGlobal);
  183294. void* const src = GlobalLock (medium->hGlobal);
  183295. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183296. memcpy (dst, src, len);
  183297. GlobalUnlock (medium->hGlobal);
  183298. pMedium->hGlobal = dst;
  183299. return S_OK;
  183300. }
  183301. }
  183302. return DV_E_FORMATETC;
  183303. }
  183304. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183305. {
  183306. if (f == 0)
  183307. return E_INVALIDARG;
  183308. if (f->tymed == format->tymed
  183309. && f->cfFormat == format->cfFormat
  183310. && f->dwAspect == format->dwAspect)
  183311. return S_OK;
  183312. return DV_E_FORMATETC;
  183313. }
  183314. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183315. {
  183316. pFormatEtcOut->ptd = 0;
  183317. return E_NOTIMPL;
  183318. }
  183319. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183320. {
  183321. if (result == 0)
  183322. return E_POINTER;
  183323. if (direction == DATADIR_GET)
  183324. {
  183325. *result = new JuceEnumFormatEtc (format);
  183326. return S_OK;
  183327. }
  183328. *result = 0;
  183329. return E_NOTIMPL;
  183330. }
  183331. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183332. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183333. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183334. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183335. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183336. };
  183337. static HDROP createHDrop (const StringArray& fileNames) throw()
  183338. {
  183339. int totalChars = 0;
  183340. for (int i = fileNames.size(); --i >= 0;)
  183341. totalChars += fileNames[i].length() + 1;
  183342. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183343. sizeof (DROPFILES)
  183344. + sizeof (WCHAR) * (totalChars + 2));
  183345. if (hDrop != 0)
  183346. {
  183347. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183348. pDropFiles->pFiles = sizeof (DROPFILES);
  183349. pDropFiles->fWide = true;
  183350. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183351. for (int i = 0; i < fileNames.size(); ++i)
  183352. {
  183353. fileNames[i].copyToUnicode (fname, 2048);
  183354. fname += fileNames[i].length() + 1;
  183355. }
  183356. *fname = 0;
  183357. GlobalUnlock (hDrop);
  183358. }
  183359. return hDrop;
  183360. }
  183361. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183362. {
  183363. JuceDropSource* const source = new JuceDropSource();
  183364. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183365. DWORD effect;
  183366. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183367. data->Release();
  183368. source->Release();
  183369. return res == DRAGDROP_S_DROP;
  183370. }
  183371. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183372. {
  183373. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183374. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183375. medium.hGlobal = createHDrop (files);
  183376. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183377. : DROPEFFECT_COPY);
  183378. }
  183379. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183380. {
  183381. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183382. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183383. const int numChars = text.length();
  183384. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183385. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (medium.hGlobal));
  183386. text.copyToUnicode (data, numChars + 1);
  183387. format.cfFormat = CF_UNICODETEXT;
  183388. GlobalUnlock (medium.hGlobal);
  183389. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183390. }
  183391. #endif
  183392. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183393. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183394. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183395. // compiled on its own).
  183396. #if JUCE_INCLUDED_FILE
  183397. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183398. NEWTEXTMETRICEXW*,
  183399. int type,
  183400. LPARAM lParam)
  183401. {
  183402. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183403. {
  183404. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183405. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters ("@"));
  183406. }
  183407. return 1;
  183408. }
  183409. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183410. NEWTEXTMETRICEXW*,
  183411. int type,
  183412. LPARAM lParam)
  183413. {
  183414. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183415. {
  183416. LOGFONTW lf;
  183417. zerostruct (lf);
  183418. lf.lfWeight = FW_DONTCARE;
  183419. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183420. lf.lfQuality = DEFAULT_QUALITY;
  183421. lf.lfCharSet = DEFAULT_CHARSET;
  183422. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183423. lf.lfPitchAndFamily = FF_DONTCARE;
  183424. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183425. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183426. HDC dc = CreateCompatibleDC (0);
  183427. EnumFontFamiliesEx (dc, &lf,
  183428. (FONTENUMPROCW) &wfontEnum2,
  183429. lParam, 0);
  183430. DeleteDC (dc);
  183431. }
  183432. return 1;
  183433. }
  183434. const StringArray Font::findAllTypefaceNames()
  183435. {
  183436. StringArray results;
  183437. HDC dc = CreateCompatibleDC (0);
  183438. {
  183439. LOGFONTW lf;
  183440. zerostruct (lf);
  183441. lf.lfWeight = FW_DONTCARE;
  183442. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183443. lf.lfQuality = DEFAULT_QUALITY;
  183444. lf.lfCharSet = DEFAULT_CHARSET;
  183445. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183446. lf.lfPitchAndFamily = FF_DONTCARE;
  183447. lf.lfFaceName[0] = 0;
  183448. EnumFontFamiliesEx (dc, &lf,
  183449. (FONTENUMPROCW) &wfontEnum1,
  183450. (LPARAM) &results, 0);
  183451. }
  183452. DeleteDC (dc);
  183453. results.sort (true);
  183454. return results;
  183455. }
  183456. extern bool juce_IsRunningInWine();
  183457. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  183458. {
  183459. if (juce_IsRunningInWine())
  183460. {
  183461. // If we're running in Wine, then use fonts that might be available on Linux..
  183462. defaultSans = "Bitstream Vera Sans";
  183463. defaultSerif = "Bitstream Vera Serif";
  183464. defaultFixed = "Bitstream Vera Sans Mono";
  183465. }
  183466. else
  183467. {
  183468. defaultSans = "Verdana";
  183469. defaultSerif = "Times";
  183470. defaultFixed = "Lucida Console";
  183471. }
  183472. }
  183473. class FontDCHolder : private DeletedAtShutdown
  183474. {
  183475. public:
  183476. FontDCHolder() throw()
  183477. : dc (0), numKPs (0), size (0),
  183478. bold (false), italic (false)
  183479. {
  183480. }
  183481. ~FontDCHolder() throw()
  183482. {
  183483. if (dc != 0)
  183484. {
  183485. DeleteDC (dc);
  183486. DeleteObject (fontH);
  183487. }
  183488. clearSingletonInstance();
  183489. }
  183490. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183491. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183492. {
  183493. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183494. {
  183495. fontName = fontName_;
  183496. bold = bold_;
  183497. italic = italic_;
  183498. size = size_;
  183499. if (dc != 0)
  183500. {
  183501. DeleteDC (dc);
  183502. DeleteObject (fontH);
  183503. kps.free();
  183504. }
  183505. fontH = 0;
  183506. dc = CreateCompatibleDC (0);
  183507. SetMapperFlags (dc, 0);
  183508. SetMapMode (dc, MM_TEXT);
  183509. LOGFONTW lfw;
  183510. zerostruct (lfw);
  183511. lfw.lfCharSet = DEFAULT_CHARSET;
  183512. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183513. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183514. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183515. lfw.lfQuality = PROOF_QUALITY;
  183516. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183517. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183518. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183519. lfw.lfHeight = size > 0 ? size : -256;
  183520. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183521. if (standardSizedFont != 0)
  183522. {
  183523. if (SelectObject (dc, standardSizedFont) != 0)
  183524. {
  183525. fontH = standardSizedFont;
  183526. if (size == 0)
  183527. {
  183528. OUTLINETEXTMETRIC otm;
  183529. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183530. {
  183531. lfw.lfHeight = -(int) otm.otmEMSquare;
  183532. fontH = CreateFontIndirect (&lfw);
  183533. SelectObject (dc, fontH);
  183534. DeleteObject (standardSizedFont);
  183535. }
  183536. }
  183537. }
  183538. else
  183539. {
  183540. jassertfalse
  183541. }
  183542. }
  183543. else
  183544. {
  183545. jassertfalse
  183546. }
  183547. }
  183548. return dc;
  183549. }
  183550. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183551. {
  183552. if (kps == 0)
  183553. {
  183554. numKPs = GetKerningPairs (dc, 0, 0);
  183555. kps.calloc (numKPs);
  183556. GetKerningPairs (dc, numKPs, kps);
  183557. }
  183558. numKPs_ = numKPs;
  183559. return kps;
  183560. }
  183561. private:
  183562. HFONT fontH;
  183563. HDC dc;
  183564. String fontName;
  183565. HeapBlock <KERNINGPAIR> kps;
  183566. int numKPs, size;
  183567. bool bold, italic;
  183568. FontDCHolder (const FontDCHolder&);
  183569. FontDCHolder& operator= (const FontDCHolder&);
  183570. };
  183571. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183572. class WindowsTypeface : public CustomTypeface
  183573. {
  183574. public:
  183575. WindowsTypeface (const Font& font)
  183576. {
  183577. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183578. font.isBold(), font.isItalic(), 0);
  183579. TEXTMETRIC tm;
  183580. tm.tmAscent = tm.tmHeight = 1;
  183581. tm.tmDefaultChar = 0;
  183582. GetTextMetrics (dc, &tm);
  183583. setCharacteristics (font.getTypefaceName(),
  183584. tm.tmAscent / (float) tm.tmHeight,
  183585. font.isBold(), font.isItalic(),
  183586. tm.tmDefaultChar);
  183587. }
  183588. bool loadGlyphIfPossible (juce_wchar character)
  183589. {
  183590. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183591. GLYPHMETRICS gm;
  183592. {
  183593. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183594. WORD index = 0;
  183595. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183596. && index == 0xffff)
  183597. {
  183598. return false;
  183599. }
  183600. }
  183601. Path glyphPath;
  183602. TEXTMETRIC tm;
  183603. if (! GetTextMetrics (dc, &tm))
  183604. {
  183605. addGlyph (character, glyphPath, 0);
  183606. return true;
  183607. }
  183608. const float height = (float) tm.tmHeight;
  183609. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183610. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183611. &gm, 0, 0, &identityMatrix);
  183612. if (bufSize > 0)
  183613. {
  183614. HeapBlock<char> data (bufSize);
  183615. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183616. bufSize, data, &identityMatrix);
  183617. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183618. const float scaleX = 1.0f / height;
  183619. const float scaleY = -1.0f / height;
  183620. while ((char*) pheader < data + bufSize)
  183621. {
  183622. float x = scaleX * pheader->pfxStart.x.value;
  183623. float y = scaleY * pheader->pfxStart.y.value;
  183624. glyphPath.startNewSubPath (x, y);
  183625. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183626. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183627. while ((const char*) curve < curveEnd)
  183628. {
  183629. if (curve->wType == TT_PRIM_LINE)
  183630. {
  183631. for (int i = 0; i < curve->cpfx; ++i)
  183632. {
  183633. x = scaleX * curve->apfx[i].x.value;
  183634. y = scaleY * curve->apfx[i].y.value;
  183635. glyphPath.lineTo (x, y);
  183636. }
  183637. }
  183638. else if (curve->wType == TT_PRIM_QSPLINE)
  183639. {
  183640. for (int i = 0; i < curve->cpfx - 1; ++i)
  183641. {
  183642. const float x2 = scaleX * curve->apfx[i].x.value;
  183643. const float y2 = scaleY * curve->apfx[i].y.value;
  183644. float x3, y3;
  183645. if (i < curve->cpfx - 2)
  183646. {
  183647. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183648. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183649. }
  183650. else
  183651. {
  183652. x3 = scaleX * curve->apfx[i + 1].x.value;
  183653. y3 = scaleY * curve->apfx[i + 1].y.value;
  183654. }
  183655. glyphPath.quadraticTo (x2, y2, x3, y3);
  183656. x = x3;
  183657. y = y3;
  183658. }
  183659. }
  183660. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183661. }
  183662. pheader = (const TTPOLYGONHEADER*) curve;
  183663. glyphPath.closeSubPath();
  183664. }
  183665. }
  183666. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183667. int numKPs;
  183668. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183669. for (int i = 0; i < numKPs; ++i)
  183670. {
  183671. if (kps[i].wFirst == character)
  183672. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183673. kps[i].iKernAmount / height);
  183674. }
  183675. return true;
  183676. }
  183677. };
  183678. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183679. {
  183680. return new WindowsTypeface (font);
  183681. }
  183682. #endif
  183683. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183684. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183685. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183686. // compiled on its own).
  183687. #if JUCE_INCLUDED_FILE
  183688. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183689. namespace FileChooserHelpers
  183690. {
  183691. static const void* defaultDirPath = 0;
  183692. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183693. static Component* currentExtraFileWin = 0;
  183694. static bool areThereAnyAlwaysOnTopWindows()
  183695. {
  183696. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183697. {
  183698. Component* c = Desktop::getInstance().getComponent (i);
  183699. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183700. return true;
  183701. }
  183702. return false;
  183703. }
  183704. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183705. {
  183706. if (msg == BFFM_INITIALIZED)
  183707. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183708. else if (msg == BFFM_VALIDATEFAILEDW)
  183709. returnedString = (LPCWSTR) lParam;
  183710. else if (msg == BFFM_VALIDATEFAILEDA)
  183711. returnedString = (const char*) lParam;
  183712. return 0;
  183713. }
  183714. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183715. {
  183716. if (currentExtraFileWin != 0)
  183717. {
  183718. if (uiMsg == WM_INITDIALOG)
  183719. {
  183720. HWND dialogH = GetParent (hdlg);
  183721. jassert (dialogH != 0);
  183722. if (dialogH == 0)
  183723. dialogH = hdlg;
  183724. RECT r, cr;
  183725. GetWindowRect (dialogH, &r);
  183726. GetClientRect (dialogH, &cr);
  183727. SetWindowPos (dialogH, 0,
  183728. r.left, r.top,
  183729. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183730. jmax (150, (int) (r.bottom - r.top)),
  183731. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183732. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183733. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183734. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183735. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183736. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183737. }
  183738. else if (uiMsg == WM_NOTIFY)
  183739. {
  183740. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183741. if (ofn->hdr.code == CDN_SELCHANGE)
  183742. {
  183743. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183744. if (comp != 0)
  183745. {
  183746. TCHAR path [MAX_PATH * 2];
  183747. path[0] = 0;
  183748. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183749. const String fn ((const WCHAR*) path);
  183750. comp->selectedFileChanged (File (fn));
  183751. }
  183752. }
  183753. }
  183754. }
  183755. return 0;
  183756. }
  183757. class FPComponentHolder : public Component
  183758. {
  183759. public:
  183760. FPComponentHolder()
  183761. {
  183762. setVisible (true);
  183763. setOpaque (true);
  183764. }
  183765. ~FPComponentHolder()
  183766. {
  183767. }
  183768. void paint (Graphics& g)
  183769. {
  183770. g.fillAll (Colours::lightgrey);
  183771. }
  183772. private:
  183773. FPComponentHolder (const FPComponentHolder&);
  183774. FPComponentHolder& operator= (const FPComponentHolder&);
  183775. };
  183776. }
  183777. void FileChooser::showPlatformDialog (Array<File>& results,
  183778. const String& title,
  183779. const File& currentFileOrDirectory,
  183780. const String& filter,
  183781. bool selectsDirectory,
  183782. bool /*selectsFiles*/,
  183783. bool isSaveDialogue,
  183784. bool warnAboutOverwritingExistingFiles,
  183785. bool selectMultipleFiles,
  183786. FilePreviewComponent* extraInfoComponent)
  183787. {
  183788. using namespace FileChooserHelpers;
  183789. const int numCharsAvailable = 32768;
  183790. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  183791. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  183792. int fnameIdx = 0;
  183793. JUCE_TRY
  183794. {
  183795. // use a modal window as the parent for this dialog box
  183796. // to block input from other app windows
  183797. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  183798. Component w (String::empty);
  183799. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  183800. mainMon.getY() + mainMon.getHeight() / 4,
  183801. 0, 0);
  183802. w.setOpaque (true);
  183803. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  183804. w.addToDesktop (0);
  183805. if (extraInfoComponent == 0)
  183806. w.enterModalState();
  183807. String initialDir;
  183808. if (currentFileOrDirectory.isDirectory())
  183809. {
  183810. initialDir = currentFileOrDirectory.getFullPathName();
  183811. }
  183812. else
  183813. {
  183814. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  183815. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  183816. }
  183817. if (currentExtraFileWin->isValidComponent())
  183818. {
  183819. jassertfalse
  183820. return;
  183821. }
  183822. if (selectsDirectory)
  183823. {
  183824. LPITEMIDLIST list = 0;
  183825. filenameSpace.fillWith (0);
  183826. {
  183827. BROWSEINFO bi;
  183828. zerostruct (bi);
  183829. bi.hwndOwner = (HWND) w.getWindowHandle();
  183830. bi.pszDisplayName = fname;
  183831. bi.lpszTitle = title;
  183832. bi.lpfn = browseCallbackProc;
  183833. #ifdef BIF_USENEWUI
  183834. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  183835. #else
  183836. bi.ulFlags = 0x50;
  183837. #endif
  183838. defaultDirPath = (const WCHAR*) initialDir;
  183839. list = SHBrowseForFolder (&bi);
  183840. if (! SHGetPathFromIDListW (list, fname))
  183841. {
  183842. fname[0] = 0;
  183843. returnedString = String::empty;
  183844. }
  183845. }
  183846. LPMALLOC al;
  183847. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  183848. al->Free (list);
  183849. defaultDirPath = 0;
  183850. if (returnedString.isNotEmpty())
  183851. {
  183852. const String stringFName (fname);
  183853. results.add (File (stringFName).getSiblingFile (returnedString));
  183854. returnedString = String::empty;
  183855. return;
  183856. }
  183857. }
  183858. else
  183859. {
  183860. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  183861. if (warnAboutOverwritingExistingFiles)
  183862. flags |= OFN_OVERWRITEPROMPT;
  183863. if (selectMultipleFiles)
  183864. flags |= OFN_ALLOWMULTISELECT;
  183865. if (extraInfoComponent != 0)
  183866. {
  183867. flags |= OFN_ENABLEHOOK;
  183868. currentExtraFileWin = new FPComponentHolder();
  183869. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  183870. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  183871. extraInfoComponent->getHeight());
  183872. currentExtraFileWin->addToDesktop (0);
  183873. currentExtraFileWin->enterModalState();
  183874. }
  183875. {
  183876. WCHAR filters [1024];
  183877. zeromem (filters, sizeof (filters));
  183878. filter.copyToUnicode (filters, 1024);
  183879. filter.copyToUnicode (filters + filter.length() + 1,
  183880. 1022 - filter.length());
  183881. OPENFILENAMEW of;
  183882. zerostruct (of);
  183883. #ifdef OPENFILENAME_SIZE_VERSION_400W
  183884. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  183885. #else
  183886. of.lStructSize = sizeof (of);
  183887. #endif
  183888. of.hwndOwner = (HWND) w.getWindowHandle();
  183889. of.lpstrFilter = filters;
  183890. of.nFilterIndex = 1;
  183891. of.lpstrFile = fname;
  183892. of.nMaxFile = numCharsAvailable;
  183893. of.lpstrInitialDir = initialDir;
  183894. of.lpstrTitle = title;
  183895. of.Flags = flags;
  183896. if (extraInfoComponent != 0)
  183897. of.lpfnHook = &openCallback;
  183898. if (isSaveDialogue)
  183899. {
  183900. if (! GetSaveFileName (&of))
  183901. fname[0] = 0;
  183902. else
  183903. fnameIdx = of.nFileOffset;
  183904. }
  183905. else
  183906. {
  183907. if (! GetOpenFileName (&of))
  183908. fname[0] = 0;
  183909. else
  183910. fnameIdx = of.nFileOffset;
  183911. }
  183912. }
  183913. }
  183914. }
  183915. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  183916. catch (...)
  183917. {
  183918. fname[0] = 0;
  183919. }
  183920. #endif
  183921. deleteAndZero (currentExtraFileWin);
  183922. const WCHAR* const files = fname;
  183923. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  183924. {
  183925. const WCHAR* filename = files + fnameIdx;
  183926. while (*filename != 0)
  183927. {
  183928. const String filepath (String (files) + "\\" + String (filename));
  183929. results.add (File (filepath));
  183930. filename += CharacterFunctions::length (filename) + 1;
  183931. }
  183932. }
  183933. else if (files[0] != 0)
  183934. {
  183935. results.add (File (files));
  183936. }
  183937. }
  183938. #endif
  183939. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  183940. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  183941. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183942. // compiled on its own).
  183943. #if JUCE_INCLUDED_FILE
  183944. void SystemClipboard::copyTextToClipboard (const String& text)
  183945. {
  183946. if (OpenClipboard (0) != 0)
  183947. {
  183948. if (EmptyClipboard() != 0)
  183949. {
  183950. const int len = text.length();
  183951. if (len > 0)
  183952. {
  183953. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  183954. (len + 1) * sizeof (wchar_t));
  183955. if (bufH != 0)
  183956. {
  183957. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH));
  183958. text.copyToUnicode (data, len);
  183959. GlobalUnlock (bufH);
  183960. SetClipboardData (CF_UNICODETEXT, bufH);
  183961. }
  183962. }
  183963. }
  183964. CloseClipboard();
  183965. }
  183966. }
  183967. const String SystemClipboard::getTextFromClipboard()
  183968. {
  183969. String result;
  183970. if (OpenClipboard (0) != 0)
  183971. {
  183972. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  183973. if (bufH != 0)
  183974. {
  183975. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  183976. if (data != 0)
  183977. {
  183978. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  183979. GlobalUnlock (bufH);
  183980. }
  183981. }
  183982. CloseClipboard();
  183983. }
  183984. return result;
  183985. }
  183986. #endif
  183987. /*** End of inlined file: juce_win32_Misc.cpp ***/
  183988. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  183989. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183990. // compiled on its own).
  183991. #if JUCE_INCLUDED_FILE
  183992. namespace ActiveXHelpers
  183993. {
  183994. class JuceIStorage : public IStorage
  183995. {
  183996. int refCount;
  183997. public:
  183998. JuceIStorage() : refCount (1) {}
  183999. virtual ~JuceIStorage()
  184000. {
  184001. jassert (refCount == 0);
  184002. }
  184003. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184004. {
  184005. if (id == IID_IUnknown || id == IID_IStorage)
  184006. {
  184007. AddRef();
  184008. *result = this;
  184009. return S_OK;
  184010. }
  184011. *result = 0;
  184012. return E_NOINTERFACE;
  184013. }
  184014. ULONG __stdcall AddRef() { return ++refCount; }
  184015. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184016. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184017. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184018. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184019. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184020. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184021. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184022. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184023. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184024. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184025. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184026. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184027. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184028. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184029. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184030. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184031. juce_UseDebuggingNewOperator
  184032. };
  184033. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184034. {
  184035. int refCount;
  184036. HWND window;
  184037. public:
  184038. JuceOleInPlaceFrame (HWND window_)
  184039. : refCount (1),
  184040. window (window_)
  184041. {
  184042. }
  184043. virtual ~JuceOleInPlaceFrame()
  184044. {
  184045. jassert (refCount == 0);
  184046. }
  184047. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184048. {
  184049. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184050. {
  184051. AddRef();
  184052. *result = this;
  184053. return S_OK;
  184054. }
  184055. *result = 0;
  184056. return E_NOINTERFACE;
  184057. }
  184058. ULONG __stdcall AddRef() { return ++refCount; }
  184059. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184060. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184061. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184062. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184063. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184064. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184065. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184066. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184067. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184068. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184069. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184070. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184071. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184072. juce_UseDebuggingNewOperator
  184073. };
  184074. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184075. {
  184076. int refCount;
  184077. HWND window;
  184078. JuceOleInPlaceFrame* frame;
  184079. public:
  184080. JuceIOleInPlaceSite (HWND window_)
  184081. : refCount (1),
  184082. window (window_)
  184083. {
  184084. frame = new JuceOleInPlaceFrame (window);
  184085. }
  184086. virtual ~JuceIOleInPlaceSite()
  184087. {
  184088. jassert (refCount == 0);
  184089. frame->Release();
  184090. }
  184091. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184092. {
  184093. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184094. {
  184095. AddRef();
  184096. *result = this;
  184097. return S_OK;
  184098. }
  184099. *result = 0;
  184100. return E_NOINTERFACE;
  184101. }
  184102. ULONG __stdcall AddRef() { return ++refCount; }
  184103. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184104. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184105. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184106. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184107. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184108. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184109. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184110. {
  184111. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184112. *lplpFrame = frame;
  184113. *lplpDoc = 0;
  184114. lpFrameInfo->fMDIApp = FALSE;
  184115. lpFrameInfo->hwndFrame = window;
  184116. lpFrameInfo->haccel = 0;
  184117. lpFrameInfo->cAccelEntries = 0;
  184118. return S_OK;
  184119. }
  184120. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184121. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184122. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184123. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184124. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184125. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184126. juce_UseDebuggingNewOperator
  184127. };
  184128. class JuceIOleClientSite : public IOleClientSite
  184129. {
  184130. int refCount;
  184131. JuceIOleInPlaceSite* inplaceSite;
  184132. public:
  184133. JuceIOleClientSite (HWND window)
  184134. : refCount (1)
  184135. {
  184136. inplaceSite = new JuceIOleInPlaceSite (window);
  184137. }
  184138. virtual ~JuceIOleClientSite()
  184139. {
  184140. jassert (refCount == 0);
  184141. inplaceSite->Release();
  184142. }
  184143. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184144. {
  184145. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184146. {
  184147. AddRef();
  184148. *result = this;
  184149. return S_OK;
  184150. }
  184151. else if (id == IID_IOleInPlaceSite)
  184152. {
  184153. inplaceSite->AddRef();
  184154. *result = inplaceSite;
  184155. return S_OK;
  184156. }
  184157. *result = 0;
  184158. return E_NOINTERFACE;
  184159. }
  184160. ULONG __stdcall AddRef() { return ++refCount; }
  184161. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184162. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184163. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184164. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184165. HRESULT __stdcall ShowObject() { return S_OK; }
  184166. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184167. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184168. juce_UseDebuggingNewOperator
  184169. };
  184170. static VoidArray activeXComps;
  184171. static HWND getHWND (const ActiveXControlComponent* const component)
  184172. {
  184173. HWND hwnd = 0;
  184174. const IID iid = IID_IOleWindow;
  184175. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184176. if (window != 0)
  184177. {
  184178. window->GetWindow (&hwnd);
  184179. window->Release();
  184180. }
  184181. return hwnd;
  184182. }
  184183. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184184. {
  184185. RECT activeXRect, peerRect;
  184186. GetWindowRect (hwnd, &activeXRect);
  184187. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184188. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184189. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184190. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184191. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184192. switch (message)
  184193. {
  184194. case WM_MOUSEMOVE:
  184195. case WM_LBUTTONDOWN:
  184196. case WM_MBUTTONDOWN:
  184197. case WM_RBUTTONDOWN:
  184198. case WM_LBUTTONUP:
  184199. case WM_MBUTTONUP:
  184200. case WM_RBUTTONUP:
  184201. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184202. break;
  184203. default:
  184204. break;
  184205. }
  184206. }
  184207. }
  184208. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184209. {
  184210. ActiveXControlComponent* const owner;
  184211. bool wasShowing;
  184212. public:
  184213. HWND controlHWND;
  184214. IStorage* storage;
  184215. IOleClientSite* clientSite;
  184216. IOleObject* control;
  184217. ActiveXControlData (HWND hwnd,
  184218. ActiveXControlComponent* const owner_)
  184219. : ComponentMovementWatcher (owner_),
  184220. owner (owner_),
  184221. wasShowing (owner_ != 0 && owner_->isShowing()),
  184222. controlHWND (0),
  184223. storage (new ActiveXHelpers::JuceIStorage()),
  184224. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184225. control (0)
  184226. {
  184227. }
  184228. ~ActiveXControlData()
  184229. {
  184230. if (control != 0)
  184231. {
  184232. control->Close (OLECLOSE_NOSAVE);
  184233. control->Release();
  184234. }
  184235. clientSite->Release();
  184236. storage->Release();
  184237. }
  184238. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184239. {
  184240. Component* const topComp = owner->getTopLevelComponent();
  184241. if (topComp->getPeer() != 0)
  184242. {
  184243. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184244. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184245. }
  184246. }
  184247. void componentPeerChanged()
  184248. {
  184249. const bool isShowingNow = owner->isShowing();
  184250. if (wasShowing != isShowingNow)
  184251. {
  184252. wasShowing = isShowingNow;
  184253. owner->setControlVisible (isShowingNow);
  184254. }
  184255. componentMovedOrResized (true, true);
  184256. }
  184257. void componentVisibilityChanged (Component&)
  184258. {
  184259. componentPeerChanged();
  184260. }
  184261. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184262. {
  184263. return ((ActiveXControlData*) ax->control) != 0
  184264. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184265. }
  184266. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184267. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184268. {
  184269. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184270. {
  184271. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184272. if (doesWindowMatch (ax, hwnd))
  184273. {
  184274. switch (message)
  184275. {
  184276. case WM_MOUSEMOVE:
  184277. case WM_LBUTTONDOWN:
  184278. case WM_MBUTTONDOWN:
  184279. case WM_RBUTTONDOWN:
  184280. case WM_LBUTTONUP:
  184281. case WM_MBUTTONUP:
  184282. case WM_RBUTTONUP:
  184283. case WM_LBUTTONDBLCLK:
  184284. case WM_MBUTTONDBLCLK:
  184285. case WM_RBUTTONDBLCLK:
  184286. if (ax->isShowing())
  184287. {
  184288. ComponentPeer* const peer = ax->getPeer();
  184289. if (peer != 0)
  184290. {
  184291. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184292. if (! ax->areMouseEventsAllowed())
  184293. return 0;
  184294. }
  184295. }
  184296. break;
  184297. default:
  184298. break;
  184299. }
  184300. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184301. }
  184302. }
  184303. return DefWindowProc (hwnd, message, wParam, lParam);
  184304. }
  184305. };
  184306. ActiveXControlComponent::ActiveXControlComponent()
  184307. : originalWndProc (0),
  184308. control (0),
  184309. mouseEventsAllowed (true)
  184310. {
  184311. ActiveXHelpers::activeXComps.add (this);
  184312. }
  184313. ActiveXControlComponent::~ActiveXControlComponent()
  184314. {
  184315. deleteControl();
  184316. ActiveXHelpers::activeXComps.removeValue (this);
  184317. }
  184318. void ActiveXControlComponent::paint (Graphics& g)
  184319. {
  184320. if (control == 0)
  184321. g.fillAll (Colours::lightgrey);
  184322. }
  184323. bool ActiveXControlComponent::createControl (const void* controlIID)
  184324. {
  184325. deleteControl();
  184326. ComponentPeer* const peer = getPeer();
  184327. // the component must have already been added to a real window when you call this!
  184328. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184329. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184330. {
  184331. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184332. HWND hwnd = (HWND) peer->getNativeHandle();
  184333. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184334. HRESULT hr;
  184335. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184336. info->clientSite, info->storage,
  184337. (void**) &(info->control))) == S_OK)
  184338. {
  184339. info->control->SetHostNames (L"Juce", 0);
  184340. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184341. {
  184342. RECT rect;
  184343. rect.left = pos.getX();
  184344. rect.top = pos.getY();
  184345. rect.right = pos.getX() + getWidth();
  184346. rect.bottom = pos.getY() + getHeight();
  184347. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184348. {
  184349. control = info.release();
  184350. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184351. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184352. if (((ActiveXControlData*) control)->controlHWND != 0)
  184353. {
  184354. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184355. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184356. }
  184357. return true;
  184358. }
  184359. }
  184360. }
  184361. }
  184362. return false;
  184363. }
  184364. void ActiveXControlComponent::deleteControl()
  184365. {
  184366. ActiveXControlData* const info = (ActiveXControlData*) control;
  184367. if (info != 0)
  184368. {
  184369. delete info;
  184370. control = 0;
  184371. originalWndProc = 0;
  184372. }
  184373. }
  184374. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184375. {
  184376. ActiveXControlData* const info = (ActiveXControlData*) control;
  184377. void* result = 0;
  184378. if (info != 0 && info->control != 0
  184379. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184380. return result;
  184381. return 0;
  184382. }
  184383. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184384. {
  184385. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184386. if (hwnd != 0)
  184387. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184388. }
  184389. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184390. {
  184391. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184392. if (hwnd != 0)
  184393. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184394. }
  184395. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184396. {
  184397. mouseEventsAllowed = eventsCanReachControl;
  184398. }
  184399. #endif
  184400. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184401. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184402. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184403. // compiled on its own).
  184404. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184405. using namespace QTOLibrary;
  184406. using namespace QTOControlLib;
  184407. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184408. static bool isQTAvailable = false;
  184409. class QuickTimeMovieComponent::Pimpl
  184410. {
  184411. public:
  184412. Pimpl() : dataHandle (0)
  184413. {
  184414. }
  184415. ~Pimpl()
  184416. {
  184417. clearHandle();
  184418. }
  184419. void clearHandle()
  184420. {
  184421. if (dataHandle != 0)
  184422. {
  184423. DisposeHandle (dataHandle);
  184424. dataHandle = 0;
  184425. }
  184426. }
  184427. IQTControlPtr qtControl;
  184428. IQTMoviePtr qtMovie;
  184429. Handle dataHandle;
  184430. };
  184431. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184432. : movieLoaded (false),
  184433. controllerVisible (true)
  184434. {
  184435. pimpl = new Pimpl();
  184436. setMouseEventsAllowed (false);
  184437. }
  184438. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184439. {
  184440. closeMovie();
  184441. pimpl->qtControl = 0;
  184442. deleteControl();
  184443. pimpl = 0;
  184444. }
  184445. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184446. {
  184447. if (! isQTAvailable)
  184448. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184449. return isQTAvailable;
  184450. }
  184451. void QuickTimeMovieComponent::createControlIfNeeded()
  184452. {
  184453. if (isShowing() && ! isControlCreated())
  184454. {
  184455. const IID qtIID = __uuidof (QTControl);
  184456. if (createControl (&qtIID))
  184457. {
  184458. const IID qtInterfaceIID = __uuidof (IQTControl);
  184459. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184460. if (pimpl->qtControl != 0)
  184461. {
  184462. pimpl->qtControl->Release(); // it has one ref too many at this point
  184463. pimpl->qtControl->QuickTimeInitialize();
  184464. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184465. if (movieFile != File::nonexistent)
  184466. loadMovie (movieFile, controllerVisible);
  184467. }
  184468. }
  184469. }
  184470. }
  184471. bool QuickTimeMovieComponent::isControlCreated() const
  184472. {
  184473. return isControlOpen();
  184474. }
  184475. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184476. const bool isControllerVisible)
  184477. {
  184478. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184479. movieFile = File::nonexistent;
  184480. movieLoaded = false;
  184481. pimpl->qtMovie = 0;
  184482. controllerVisible = isControllerVisible;
  184483. createControlIfNeeded();
  184484. if (isControlCreated())
  184485. {
  184486. if (pimpl->qtControl != 0)
  184487. {
  184488. pimpl->qtControl->Put_MovieHandle (0);
  184489. pimpl->clearHandle();
  184490. Movie movie;
  184491. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184492. {
  184493. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184494. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184495. if (pimpl->qtMovie != 0)
  184496. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184497. : qtMovieControllerTypeNone);
  184498. }
  184499. if (movie == 0)
  184500. pimpl->clearHandle();
  184501. }
  184502. movieLoaded = (pimpl->qtMovie != 0);
  184503. }
  184504. else
  184505. {
  184506. // You're trying to open a movie when the control hasn't yet been created, probably because
  184507. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184508. jassertfalse
  184509. }
  184510. return movieLoaded;
  184511. }
  184512. void QuickTimeMovieComponent::closeMovie()
  184513. {
  184514. stop();
  184515. movieFile = File::nonexistent;
  184516. movieLoaded = false;
  184517. pimpl->qtMovie = 0;
  184518. if (pimpl->qtControl != 0)
  184519. pimpl->qtControl->Put_MovieHandle (0);
  184520. pimpl->clearHandle();
  184521. }
  184522. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184523. {
  184524. return movieFile;
  184525. }
  184526. bool QuickTimeMovieComponent::isMovieOpen() const
  184527. {
  184528. return movieLoaded;
  184529. }
  184530. double QuickTimeMovieComponent::getMovieDuration() const
  184531. {
  184532. if (pimpl->qtMovie != 0)
  184533. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184534. return 0.0;
  184535. }
  184536. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184537. {
  184538. if (pimpl->qtMovie != 0)
  184539. {
  184540. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184541. width = r.right - r.left;
  184542. height = r.bottom - r.top;
  184543. }
  184544. else
  184545. {
  184546. width = height = 0;
  184547. }
  184548. }
  184549. void QuickTimeMovieComponent::play()
  184550. {
  184551. if (pimpl->qtMovie != 0)
  184552. pimpl->qtMovie->Play();
  184553. }
  184554. void QuickTimeMovieComponent::stop()
  184555. {
  184556. if (pimpl->qtMovie != 0)
  184557. pimpl->qtMovie->Stop();
  184558. }
  184559. bool QuickTimeMovieComponent::isPlaying() const
  184560. {
  184561. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184562. }
  184563. void QuickTimeMovieComponent::setPosition (const double seconds)
  184564. {
  184565. if (pimpl->qtMovie != 0)
  184566. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184567. }
  184568. double QuickTimeMovieComponent::getPosition() const
  184569. {
  184570. if (pimpl->qtMovie != 0)
  184571. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184572. return 0.0;
  184573. }
  184574. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184575. {
  184576. if (pimpl->qtMovie != 0)
  184577. pimpl->qtMovie->PutRate (newSpeed);
  184578. }
  184579. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184580. {
  184581. if (pimpl->qtMovie != 0)
  184582. {
  184583. pimpl->qtMovie->PutAudioVolume (newVolume);
  184584. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184585. }
  184586. }
  184587. float QuickTimeMovieComponent::getMovieVolume() const
  184588. {
  184589. if (pimpl->qtMovie != 0)
  184590. return pimpl->qtMovie->GetAudioVolume();
  184591. return 0.0f;
  184592. }
  184593. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184594. {
  184595. if (pimpl->qtMovie != 0)
  184596. pimpl->qtMovie->PutLoop (shouldLoop);
  184597. }
  184598. bool QuickTimeMovieComponent::isLooping() const
  184599. {
  184600. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184601. }
  184602. bool QuickTimeMovieComponent::isControllerVisible() const
  184603. {
  184604. return controllerVisible;
  184605. }
  184606. void QuickTimeMovieComponent::parentHierarchyChanged()
  184607. {
  184608. createControlIfNeeded();
  184609. QTCompBaseClass::parentHierarchyChanged();
  184610. }
  184611. void QuickTimeMovieComponent::visibilityChanged()
  184612. {
  184613. createControlIfNeeded();
  184614. QTCompBaseClass::visibilityChanged();
  184615. }
  184616. void QuickTimeMovieComponent::paint (Graphics& g)
  184617. {
  184618. if (! isControlCreated())
  184619. g.fillAll (Colours::black);
  184620. }
  184621. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184622. {
  184623. Handle dataRef = 0;
  184624. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184625. if (err == noErr)
  184626. {
  184627. Str255 suffix;
  184628. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184629. StringPtr name = suffix;
  184630. err = PtrAndHand (name, dataRef, name[0] + 1);
  184631. if (err == noErr)
  184632. {
  184633. long atoms[3];
  184634. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184635. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184636. atoms[2] = EndianU32_NtoB (MovieFileType);
  184637. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184638. if (err == noErr)
  184639. return dataRef;
  184640. }
  184641. DisposeHandle (dataRef);
  184642. }
  184643. return 0;
  184644. }
  184645. static CFStringRef juceStringToCFString (const String& s)
  184646. {
  184647. const int len = s.length();
  184648. const juce_wchar* const t = s;
  184649. HeapBlock <UniChar> temp (len + 2);
  184650. for (int i = 0; i <= len; ++i)
  184651. temp[i] = t[i];
  184652. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184653. }
  184654. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184655. {
  184656. Boolean trueBool = true;
  184657. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184658. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184659. props[prop].propValueSize = sizeof (trueBool);
  184660. props[prop].propValueAddress = &trueBool;
  184661. ++prop;
  184662. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184663. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184664. props[prop].propValueSize = sizeof (trueBool);
  184665. props[prop].propValueAddress = &trueBool;
  184666. ++prop;
  184667. Boolean isActive = true;
  184668. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184669. props[prop].propID = kQTNewMoviePropertyID_Active;
  184670. props[prop].propValueSize = sizeof (isActive);
  184671. props[prop].propValueAddress = &isActive;
  184672. ++prop;
  184673. MacSetPort (0);
  184674. jassert (prop <= 5);
  184675. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184676. return err == noErr;
  184677. }
  184678. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184679. {
  184680. if (input == 0)
  184681. return false;
  184682. dataHandle = 0;
  184683. bool ok = false;
  184684. QTNewMoviePropertyElement props[5];
  184685. zeromem (props, sizeof (props));
  184686. int prop = 0;
  184687. DataReferenceRecord dr;
  184688. props[prop].propClass = kQTPropertyClass_DataLocation;
  184689. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184690. props[prop].propValueSize = sizeof (dr);
  184691. props[prop].propValueAddress = &dr;
  184692. ++prop;
  184693. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184694. if (fin != 0)
  184695. {
  184696. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184697. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184698. &dr.dataRef, &dr.dataRefType);
  184699. ok = openMovie (props, prop, movie);
  184700. DisposeHandle (dr.dataRef);
  184701. CFRelease (filePath);
  184702. }
  184703. else
  184704. {
  184705. // sanity-check because this currently needs to load the whole stream into memory..
  184706. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184707. dataHandle = NewHandle ((Size) input->getTotalLength());
  184708. HLock (dataHandle);
  184709. // read the entire stream into memory - this is a pain, but can't get it to work
  184710. // properly using a custom callback to supply the data.
  184711. input->read (*dataHandle, (int) input->getTotalLength());
  184712. HUnlock (dataHandle);
  184713. // different types to get QT to try. (We should really be a bit smarter here by
  184714. // working out in advance which one the stream contains, rather than just trying
  184715. // each one)
  184716. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184717. "\04.avi", "\04.m4a" };
  184718. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184719. {
  184720. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184721. dr.dataRefType = HandleDataHandlerSubType;
  184722. ok = openMovie (props, prop, movie);
  184723. DisposeHandle (dr.dataRef);
  184724. }
  184725. }
  184726. return ok;
  184727. }
  184728. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184729. const bool isControllerVisible)
  184730. {
  184731. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184732. movieFile = movieFile_;
  184733. return ok;
  184734. }
  184735. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184736. const bool isControllerVisible)
  184737. {
  184738. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184739. }
  184740. void QuickTimeMovieComponent::goToStart()
  184741. {
  184742. setPosition (0.0);
  184743. }
  184744. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184745. const RectanglePlacement& placement)
  184746. {
  184747. int normalWidth, normalHeight;
  184748. getMovieNormalSize (normalWidth, normalHeight);
  184749. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184750. {
  184751. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184752. placement.applyTo (x, y, w, h,
  184753. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184754. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184755. if (w > 0 && h > 0)
  184756. {
  184757. setBounds (roundToInt (x), roundToInt (y),
  184758. roundToInt (w), roundToInt (h));
  184759. }
  184760. }
  184761. else
  184762. {
  184763. setBounds (spaceToFitWithin);
  184764. }
  184765. }
  184766. #endif
  184767. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184768. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184769. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184770. // compiled on its own).
  184771. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184772. class WebBrowserComponentInternal : public ActiveXControlComponent
  184773. {
  184774. public:
  184775. WebBrowserComponentInternal()
  184776. : browser (0),
  184777. connectionPoint (0),
  184778. adviseCookie (0)
  184779. {
  184780. }
  184781. ~WebBrowserComponentInternal()
  184782. {
  184783. if (connectionPoint != 0)
  184784. connectionPoint->Unadvise (adviseCookie);
  184785. if (browser != 0)
  184786. browser->Release();
  184787. }
  184788. void createBrowser()
  184789. {
  184790. createControl (&CLSID_WebBrowser);
  184791. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  184792. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  184793. if (connectionPointContainer != 0)
  184794. {
  184795. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  184796. &connectionPoint);
  184797. if (connectionPoint != 0)
  184798. {
  184799. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  184800. jassert (owner != 0);
  184801. EventHandler* handler = new EventHandler (owner);
  184802. connectionPoint->Advise (handler, &adviseCookie);
  184803. }
  184804. }
  184805. }
  184806. void goToURL (const String& url,
  184807. const StringArray* headers,
  184808. const MemoryBlock* postData)
  184809. {
  184810. if (browser != 0)
  184811. {
  184812. LPSAFEARRAY sa = 0;
  184813. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  184814. VariantInit (&flags);
  184815. VariantInit (&frame);
  184816. VariantInit (&postDataVar);
  184817. VariantInit (&headersVar);
  184818. if (headers != 0)
  184819. {
  184820. V_VT (&headersVar) = VT_BSTR;
  184821. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  184822. }
  184823. if (postData != 0 && postData->getSize() > 0)
  184824. {
  184825. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  184826. if (sa != 0)
  184827. {
  184828. void* data = 0;
  184829. SafeArrayAccessData (sa, &data);
  184830. jassert (data != 0);
  184831. if (data != 0)
  184832. {
  184833. postData->copyTo (data, 0, postData->getSize());
  184834. SafeArrayUnaccessData (sa);
  184835. VARIANT postDataVar2;
  184836. VariantInit (&postDataVar2);
  184837. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  184838. V_ARRAY (&postDataVar2) = sa;
  184839. postDataVar = postDataVar2;
  184840. }
  184841. }
  184842. }
  184843. browser->Navigate ((BSTR) (const OLECHAR*) url,
  184844. &flags, &frame,
  184845. &postDataVar, &headersVar);
  184846. if (sa != 0)
  184847. SafeArrayDestroy (sa);
  184848. VariantClear (&flags);
  184849. VariantClear (&frame);
  184850. VariantClear (&postDataVar);
  184851. VariantClear (&headersVar);
  184852. }
  184853. }
  184854. IWebBrowser2* browser;
  184855. juce_UseDebuggingNewOperator
  184856. private:
  184857. IConnectionPoint* connectionPoint;
  184858. DWORD adviseCookie;
  184859. class EventHandler : public IDispatch,
  184860. public ComponentMovementWatcher
  184861. {
  184862. public:
  184863. EventHandler (WebBrowserComponent* owner_)
  184864. : ComponentMovementWatcher (owner_),
  184865. owner (owner_),
  184866. refCount (0)
  184867. {
  184868. }
  184869. ~EventHandler()
  184870. {
  184871. }
  184872. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184873. {
  184874. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  184875. {
  184876. AddRef();
  184877. *result = this;
  184878. return S_OK;
  184879. }
  184880. *result = 0;
  184881. return E_NOINTERFACE;
  184882. }
  184883. ULONG __stdcall AddRef() { return ++refCount; }
  184884. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184885. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  184886. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  184887. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  184888. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  184889. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  184890. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  184891. UINT __RPC_FAR* /*puArgErr*/)
  184892. {
  184893. switch (dispIdMember)
  184894. {
  184895. case DISPID_BEFORENAVIGATE2:
  184896. {
  184897. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  184898. String url;
  184899. if ((vurl->vt & VT_BYREF) != 0)
  184900. url = *vurl->pbstrVal;
  184901. else
  184902. url = vurl->bstrVal;
  184903. *pDispParams->rgvarg->pboolVal
  184904. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  184905. : VARIANT_TRUE;
  184906. return S_OK;
  184907. }
  184908. default:
  184909. break;
  184910. }
  184911. return E_NOTIMPL;
  184912. }
  184913. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  184914. void componentPeerChanged() {}
  184915. void componentVisibilityChanged (Component&)
  184916. {
  184917. owner->visibilityChanged();
  184918. }
  184919. juce_UseDebuggingNewOperator
  184920. private:
  184921. WebBrowserComponent* const owner;
  184922. int refCount;
  184923. EventHandler (const EventHandler&);
  184924. EventHandler& operator= (const EventHandler&);
  184925. };
  184926. };
  184927. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  184928. : browser (0),
  184929. blankPageShown (false),
  184930. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  184931. {
  184932. setOpaque (true);
  184933. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  184934. }
  184935. WebBrowserComponent::~WebBrowserComponent()
  184936. {
  184937. delete browser;
  184938. }
  184939. void WebBrowserComponent::goToURL (const String& url,
  184940. const StringArray* headers,
  184941. const MemoryBlock* postData)
  184942. {
  184943. lastURL = url;
  184944. lastHeaders.clear();
  184945. if (headers != 0)
  184946. lastHeaders = *headers;
  184947. lastPostData.setSize (0);
  184948. if (postData != 0)
  184949. lastPostData = *postData;
  184950. blankPageShown = false;
  184951. browser->goToURL (url, headers, postData);
  184952. }
  184953. void WebBrowserComponent::stop()
  184954. {
  184955. if (browser->browser != 0)
  184956. browser->browser->Stop();
  184957. }
  184958. void WebBrowserComponent::goBack()
  184959. {
  184960. lastURL = String::empty;
  184961. blankPageShown = false;
  184962. if (browser->browser != 0)
  184963. browser->browser->GoBack();
  184964. }
  184965. void WebBrowserComponent::goForward()
  184966. {
  184967. lastURL = String::empty;
  184968. if (browser->browser != 0)
  184969. browser->browser->GoForward();
  184970. }
  184971. void WebBrowserComponent::refresh()
  184972. {
  184973. if (browser->browser != 0)
  184974. browser->browser->Refresh();
  184975. }
  184976. void WebBrowserComponent::paint (Graphics& g)
  184977. {
  184978. if (browser->browser == 0)
  184979. g.fillAll (Colours::white);
  184980. }
  184981. void WebBrowserComponent::checkWindowAssociation()
  184982. {
  184983. if (isShowing())
  184984. {
  184985. if (browser->browser == 0 && getPeer() != 0)
  184986. {
  184987. browser->createBrowser();
  184988. reloadLastURL();
  184989. }
  184990. else
  184991. {
  184992. if (blankPageShown)
  184993. goBack();
  184994. }
  184995. }
  184996. else
  184997. {
  184998. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  184999. {
  185000. // when the component becomes invisible, some stuff like flash
  185001. // carries on playing audio, so we need to force it onto a blank
  185002. // page to avoid this..
  185003. blankPageShown = true;
  185004. browser->goToURL ("about:blank", 0, 0);
  185005. }
  185006. }
  185007. }
  185008. void WebBrowserComponent::reloadLastURL()
  185009. {
  185010. if (lastURL.isNotEmpty())
  185011. {
  185012. goToURL (lastURL, &lastHeaders, &lastPostData);
  185013. lastURL = String::empty;
  185014. }
  185015. }
  185016. void WebBrowserComponent::parentHierarchyChanged()
  185017. {
  185018. checkWindowAssociation();
  185019. }
  185020. void WebBrowserComponent::resized()
  185021. {
  185022. browser->setSize (getWidth(), getHeight());
  185023. }
  185024. void WebBrowserComponent::visibilityChanged()
  185025. {
  185026. checkWindowAssociation();
  185027. }
  185028. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185029. {
  185030. return true;
  185031. }
  185032. #endif
  185033. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185034. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185035. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185036. // compiled on its own).
  185037. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185038. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185039. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185040. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185041. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185042. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185043. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185044. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185045. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185046. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185047. #define WGL_ACCELERATION_ARB 0x2003
  185048. #define WGL_SWAP_METHOD_ARB 0x2007
  185049. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185050. #define WGL_PIXEL_TYPE_ARB 0x2013
  185051. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185052. #define WGL_COLOR_BITS_ARB 0x2014
  185053. #define WGL_RED_BITS_ARB 0x2015
  185054. #define WGL_GREEN_BITS_ARB 0x2017
  185055. #define WGL_BLUE_BITS_ARB 0x2019
  185056. #define WGL_ALPHA_BITS_ARB 0x201B
  185057. #define WGL_DEPTH_BITS_ARB 0x2022
  185058. #define WGL_STENCIL_BITS_ARB 0x2023
  185059. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185060. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185061. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185062. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185063. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185064. #define WGL_STEREO_ARB 0x2012
  185065. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185066. #define WGL_SAMPLES_ARB 0x2042
  185067. #define WGL_TYPE_RGBA_ARB 0x202B
  185068. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185069. {
  185070. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185071. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185072. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185073. else
  185074. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185075. }
  185076. class WindowedGLContext : public OpenGLContext
  185077. {
  185078. public:
  185079. WindowedGLContext (Component* const component_,
  185080. HGLRC contextToShareWith,
  185081. const OpenGLPixelFormat& pixelFormat)
  185082. : renderContext (0),
  185083. nativeWindow (0),
  185084. dc (0),
  185085. component (component_)
  185086. {
  185087. jassert (component != 0);
  185088. createNativeWindow();
  185089. // Use a default pixel format that should be supported everywhere
  185090. PIXELFORMATDESCRIPTOR pfd;
  185091. zerostruct (pfd);
  185092. pfd.nSize = sizeof (pfd);
  185093. pfd.nVersion = 1;
  185094. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185095. pfd.iPixelType = PFD_TYPE_RGBA;
  185096. pfd.cColorBits = 24;
  185097. pfd.cDepthBits = 16;
  185098. const int format = ChoosePixelFormat (dc, &pfd);
  185099. if (format != 0)
  185100. SetPixelFormat (dc, format, &pfd);
  185101. renderContext = wglCreateContext (dc);
  185102. makeActive();
  185103. setPixelFormat (pixelFormat);
  185104. if (contextToShareWith != 0 && renderContext != 0)
  185105. wglShareLists (contextToShareWith, renderContext);
  185106. }
  185107. ~WindowedGLContext()
  185108. {
  185109. makeInactive();
  185110. wglDeleteContext (renderContext);
  185111. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185112. delete nativeWindow;
  185113. }
  185114. bool makeActive() const throw()
  185115. {
  185116. jassert (renderContext != 0);
  185117. return wglMakeCurrent (dc, renderContext) != 0;
  185118. }
  185119. bool makeInactive() const throw()
  185120. {
  185121. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185122. }
  185123. bool isActive() const throw()
  185124. {
  185125. return wglGetCurrentContext() == renderContext;
  185126. }
  185127. const OpenGLPixelFormat getPixelFormat() const
  185128. {
  185129. OpenGLPixelFormat pf;
  185130. makeActive();
  185131. StringArray availableExtensions;
  185132. getWglExtensions (dc, availableExtensions);
  185133. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185134. return pf;
  185135. }
  185136. void* getRawContext() const throw()
  185137. {
  185138. return renderContext;
  185139. }
  185140. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185141. {
  185142. makeActive();
  185143. PIXELFORMATDESCRIPTOR pfd;
  185144. zerostruct (pfd);
  185145. pfd.nSize = sizeof (pfd);
  185146. pfd.nVersion = 1;
  185147. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185148. pfd.iPixelType = PFD_TYPE_RGBA;
  185149. pfd.iLayerType = PFD_MAIN_PLANE;
  185150. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185151. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185152. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185153. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185154. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185155. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185156. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185157. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185158. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185159. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185160. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185161. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185162. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185163. int format = 0;
  185164. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185165. StringArray availableExtensions;
  185166. getWglExtensions (dc, availableExtensions);
  185167. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185168. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185169. {
  185170. int attributes[64];
  185171. int n = 0;
  185172. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185173. attributes[n++] = GL_TRUE;
  185174. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185175. attributes[n++] = GL_TRUE;
  185176. attributes[n++] = WGL_ACCELERATION_ARB;
  185177. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185178. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185179. attributes[n++] = GL_TRUE;
  185180. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185181. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185182. attributes[n++] = WGL_COLOR_BITS_ARB;
  185183. attributes[n++] = pfd.cColorBits;
  185184. attributes[n++] = WGL_RED_BITS_ARB;
  185185. attributes[n++] = pixelFormat.redBits;
  185186. attributes[n++] = WGL_GREEN_BITS_ARB;
  185187. attributes[n++] = pixelFormat.greenBits;
  185188. attributes[n++] = WGL_BLUE_BITS_ARB;
  185189. attributes[n++] = pixelFormat.blueBits;
  185190. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185191. attributes[n++] = pixelFormat.alphaBits;
  185192. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185193. attributes[n++] = pixelFormat.depthBufferBits;
  185194. if (pixelFormat.stencilBufferBits > 0)
  185195. {
  185196. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185197. attributes[n++] = pixelFormat.stencilBufferBits;
  185198. }
  185199. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185200. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185201. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185202. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185203. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185204. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185205. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185206. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185207. if (availableExtensions.contains ("WGL_ARB_multisample")
  185208. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185209. {
  185210. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185211. attributes[n++] = 1;
  185212. attributes[n++] = WGL_SAMPLES_ARB;
  185213. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185214. }
  185215. attributes[n++] = 0;
  185216. UINT formatsCount;
  185217. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185218. (void) ok;
  185219. jassert (ok);
  185220. }
  185221. else
  185222. {
  185223. format = ChoosePixelFormat (dc, &pfd);
  185224. }
  185225. if (format != 0)
  185226. {
  185227. makeInactive();
  185228. // win32 can't change the pixel format of a window, so need to delete the
  185229. // old one and create a new one..
  185230. jassert (nativeWindow != 0);
  185231. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185232. delete nativeWindow;
  185233. createNativeWindow();
  185234. if (SetPixelFormat (dc, format, &pfd))
  185235. {
  185236. wglDeleteContext (renderContext);
  185237. renderContext = wglCreateContext (dc);
  185238. jassert (renderContext != 0);
  185239. return renderContext != 0;
  185240. }
  185241. }
  185242. return false;
  185243. }
  185244. void updateWindowPosition (int x, int y, int w, int h, int)
  185245. {
  185246. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185247. x, y, w, h,
  185248. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185249. }
  185250. void repaint()
  185251. {
  185252. const Rectangle<int> bounds (nativeWindow->getBounds());
  185253. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185254. }
  185255. void swapBuffers()
  185256. {
  185257. SwapBuffers (dc);
  185258. }
  185259. bool setSwapInterval (int numFramesPerSwap)
  185260. {
  185261. makeActive();
  185262. StringArray availableExtensions;
  185263. getWglExtensions (dc, availableExtensions);
  185264. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185265. return availableExtensions.contains ("WGL_EXT_swap_control")
  185266. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185267. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185268. }
  185269. int getSwapInterval() const
  185270. {
  185271. makeActive();
  185272. StringArray availableExtensions;
  185273. getWglExtensions (dc, availableExtensions);
  185274. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185275. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185276. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185277. return wglGetSwapIntervalEXT();
  185278. return 0;
  185279. }
  185280. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185281. {
  185282. jassert (isActive());
  185283. StringArray availableExtensions;
  185284. getWglExtensions (dc, availableExtensions);
  185285. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185286. int numTypes = 0;
  185287. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185288. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185289. {
  185290. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185291. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185292. jassertfalse
  185293. }
  185294. else
  185295. {
  185296. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185297. }
  185298. OpenGLPixelFormat pf;
  185299. for (int i = 0; i < numTypes; ++i)
  185300. {
  185301. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185302. {
  185303. bool alreadyListed = false;
  185304. for (int j = results.size(); --j >= 0;)
  185305. if (pf == *results.getUnchecked(j))
  185306. alreadyListed = true;
  185307. if (! alreadyListed)
  185308. results.add (new OpenGLPixelFormat (pf));
  185309. }
  185310. }
  185311. }
  185312. void* getNativeWindowHandle() const
  185313. {
  185314. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185315. }
  185316. juce_UseDebuggingNewOperator
  185317. HGLRC renderContext;
  185318. private:
  185319. Win32ComponentPeer* nativeWindow;
  185320. Component* const component;
  185321. HDC dc;
  185322. void createNativeWindow()
  185323. {
  185324. nativeWindow = new Win32ComponentPeer (component, 0);
  185325. nativeWindow->dontRepaint = true;
  185326. nativeWindow->setVisible (true);
  185327. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185328. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185329. if (peer != 0)
  185330. {
  185331. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185332. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185333. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185334. }
  185335. dc = GetDC (hwnd);
  185336. }
  185337. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185338. OpenGLPixelFormat& result,
  185339. const StringArray& availableExtensions) const throw()
  185340. {
  185341. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185342. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185343. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185344. {
  185345. int attributes[32];
  185346. int numAttributes = 0;
  185347. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185348. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185349. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185350. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185351. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185352. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185353. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185354. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185355. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185356. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185357. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185358. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185359. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185360. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185361. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185362. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185363. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185364. int values[32];
  185365. zeromem (values, sizeof (values));
  185366. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185367. {
  185368. int n = 0;
  185369. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185370. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185371. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185372. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185373. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185374. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185375. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185376. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185377. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185378. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185379. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185380. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185381. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185382. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185383. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185384. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185385. return isValidFormat;
  185386. }
  185387. else
  185388. {
  185389. jassertfalse
  185390. }
  185391. }
  185392. else
  185393. {
  185394. PIXELFORMATDESCRIPTOR pfd;
  185395. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185396. {
  185397. result.redBits = pfd.cRedBits;
  185398. result.greenBits = pfd.cGreenBits;
  185399. result.blueBits = pfd.cBlueBits;
  185400. result.alphaBits = pfd.cAlphaBits;
  185401. result.depthBufferBits = pfd.cDepthBits;
  185402. result.stencilBufferBits = pfd.cStencilBits;
  185403. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185404. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185405. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185406. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185407. result.fullSceneAntiAliasingNumSamples = 0;
  185408. return true;
  185409. }
  185410. else
  185411. {
  185412. jassertfalse
  185413. }
  185414. }
  185415. return false;
  185416. }
  185417. WindowedGLContext (const WindowedGLContext&);
  185418. WindowedGLContext& operator= (const WindowedGLContext&);
  185419. };
  185420. OpenGLContext* OpenGLComponent::createContext()
  185421. {
  185422. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185423. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185424. preferredPixelFormat));
  185425. return (c->renderContext != 0) ? c.release() : 0;
  185426. }
  185427. void* OpenGLComponent::getNativeWindowHandle() const
  185428. {
  185429. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle() : 0;
  185430. }
  185431. void juce_glViewport (const int w, const int h)
  185432. {
  185433. glViewport (0, 0, w, h);
  185434. }
  185435. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185436. OwnedArray <OpenGLPixelFormat>& results)
  185437. {
  185438. Component tempComp;
  185439. {
  185440. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185441. wc.makeActive();
  185442. wc.findAlternativeOpenGLPixelFormats (results);
  185443. }
  185444. }
  185445. #endif
  185446. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185447. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185448. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185449. // compiled on its own).
  185450. #if JUCE_INCLUDED_FILE
  185451. #if JUCE_USE_CDREADER
  185452. namespace CDReaderHelpers
  185453. {
  185454. //***************************************************************************
  185455. // %%% TARGET STATUS VALUES %%%
  185456. //***************************************************************************
  185457. #define STATUS_GOOD 0x00 // Status Good
  185458. #define STATUS_CHKCOND 0x02 // Check Condition
  185459. #define STATUS_CONDMET 0x04 // Condition Met
  185460. #define STATUS_BUSY 0x08 // Busy
  185461. #define STATUS_INTERM 0x10 // Intermediate
  185462. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185463. #define STATUS_RESCONF 0x18 // Reservation conflict
  185464. #define STATUS_COMTERM 0x22 // Command Terminated
  185465. #define STATUS_QFULL 0x28 // Queue full
  185466. //***************************************************************************
  185467. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185468. //***************************************************************************
  185469. #define MAXLUN 7 // Maximum Logical Unit Id
  185470. #define MAXTARG 7 // Maximum Target Id
  185471. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185472. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185473. //***************************************************************************
  185474. // %%% Commands for all Device Types %%%
  185475. //***************************************************************************
  185476. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185477. #define SCSI_COMPARE 0x39 // Compare (O)
  185478. #define SCSI_COPY 0x18 // Copy (O)
  185479. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185480. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185481. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185482. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185483. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185484. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185485. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185486. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185487. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185488. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185489. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185490. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185491. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185492. //***************************************************************************
  185493. // %%% Commands Unique to Direct Access Devices %%%
  185494. //***************************************************************************
  185495. #define SCSI_COMPARE 0x39 // Compare (O)
  185496. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185497. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185498. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185499. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185500. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185501. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185502. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185503. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185504. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185505. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185506. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185507. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185508. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185509. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185510. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185511. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185512. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185513. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185514. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185515. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185516. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185517. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185518. #define SCSI_VERIFY 0x2F // Verify (O)
  185519. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185520. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185521. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185522. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185523. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185524. //***************************************************************************
  185525. // %%% Commands Unique to Sequential Access Devices %%%
  185526. //***************************************************************************
  185527. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185528. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185529. #define SCSI_LOCATE 0x2B // Locate (O)
  185530. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185531. #define SCSI_READ_POS 0x34 // Read Position (O)
  185532. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185533. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185534. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185535. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185536. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185537. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185538. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185539. //***************************************************************************
  185540. // %%% Commands Unique to Printer Devices %%%
  185541. //***************************************************************************
  185542. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185543. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185544. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185545. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185546. //***************************************************************************
  185547. // %%% Commands Unique to Processor Devices %%%
  185548. //***************************************************************************
  185549. #define SCSI_RECEIVE 0x08 // Receive (O)
  185550. #define SCSI_SEND 0x0A // Send (O)
  185551. //***************************************************************************
  185552. // %%% Commands Unique to Write-Once Devices %%%
  185553. //***************************************************************************
  185554. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185555. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185556. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185557. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185558. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185559. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185560. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185561. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185562. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185563. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185564. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185565. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185566. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185567. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185568. //***************************************************************************
  185569. // %%% Commands Unique to CD-ROM Devices %%%
  185570. //***************************************************************************
  185571. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185572. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185573. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185574. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185575. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185576. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185577. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185578. #define SCSI_READHEADER 0x44 // Read Header (O)
  185579. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185580. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185581. //***************************************************************************
  185582. // %%% Commands Unique to Scanner Devices %%%
  185583. //***************************************************************************
  185584. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185585. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185586. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185587. #define SCSI_SCAN 0x1B // Scan (O)
  185588. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185589. //***************************************************************************
  185590. // %%% Commands Unique to Optical Memory Devices %%%
  185591. //***************************************************************************
  185592. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185593. //***************************************************************************
  185594. // %%% Commands Unique to Medium Changer Devices %%%
  185595. //***************************************************************************
  185596. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185597. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185598. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185599. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185600. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185601. //***************************************************************************
  185602. // %%% Commands Unique to Communication Devices %%%
  185603. //***************************************************************************
  185604. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185605. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185606. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185607. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185608. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185609. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185610. //***************************************************************************
  185611. // %%% Request Sense Data Format %%%
  185612. //***************************************************************************
  185613. typedef struct {
  185614. BYTE ErrorCode; // Error Code (70H or 71H)
  185615. BYTE SegmentNum; // Number of current segment descriptor
  185616. BYTE SenseKey; // Sense Key(See bit definitions too)
  185617. BYTE InfoByte0; // Information MSB
  185618. BYTE InfoByte1; // Information MID
  185619. BYTE InfoByte2; // Information MID
  185620. BYTE InfoByte3; // Information LSB
  185621. BYTE AddSenLen; // Additional Sense Length
  185622. BYTE ComSpecInf0; // Command Specific Information MSB
  185623. BYTE ComSpecInf1; // Command Specific Information MID
  185624. BYTE ComSpecInf2; // Command Specific Information MID
  185625. BYTE ComSpecInf3; // Command Specific Information LSB
  185626. BYTE AddSenseCode; // Additional Sense Code
  185627. BYTE AddSenQual; // Additional Sense Code Qualifier
  185628. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185629. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185630. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185631. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185632. BYTE AddSenseBytes; // Additional Sense Bytes
  185633. } SENSE_DATA_FMT;
  185634. //***************************************************************************
  185635. // %%% REQUEST SENSE ERROR CODE %%%
  185636. //***************************************************************************
  185637. #define SERROR_CURRENT 0x70 // Current Errors
  185638. #define SERROR_DEFERED 0x71 // Deferred Errors
  185639. //***************************************************************************
  185640. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185641. //***************************************************************************
  185642. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185643. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185644. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185645. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185646. //***************************************************************************
  185647. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185648. //***************************************************************************
  185649. #define KEY_NOSENSE 0x00 // No Sense
  185650. #define KEY_RECERROR 0x01 // Recovered Error
  185651. #define KEY_NOTREADY 0x02 // Not Ready
  185652. #define KEY_MEDIUMERR 0x03 // Medium Error
  185653. #define KEY_HARDERROR 0x04 // Hardware Error
  185654. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185655. #define KEY_UNITATT 0x06 // Unit Attention
  185656. #define KEY_DATAPROT 0x07 // Data Protect
  185657. #define KEY_BLANKCHK 0x08 // Blank Check
  185658. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185659. #define KEY_COPYABORT 0x0A // Copy Abort
  185660. #define KEY_EQUAL 0x0C // Equal (Search)
  185661. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185662. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185663. #define KEY_RESERVED 0x0F // Reserved
  185664. //***************************************************************************
  185665. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185666. //***************************************************************************
  185667. #define DTYPE_DASD 0x00 // Disk Device
  185668. #define DTYPE_SEQD 0x01 // Tape Device
  185669. #define DTYPE_PRNT 0x02 // Printer
  185670. #define DTYPE_PROC 0x03 // Processor
  185671. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185672. #define DTYPE_CROM 0x05 // CD-ROM device
  185673. #define DTYPE_SCAN 0x06 // Scanner device
  185674. #define DTYPE_OPTI 0x07 // Optical memory device
  185675. #define DTYPE_JUKE 0x08 // Medium Changer device
  185676. #define DTYPE_COMM 0x09 // Communications device
  185677. #define DTYPE_RESL 0x0A // Reserved (low)
  185678. #define DTYPE_RESH 0x1E // Reserved (high)
  185679. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185680. //***************************************************************************
  185681. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185682. //***************************************************************************
  185683. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185684. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185685. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185686. #define ANSI_RESLO 0x3 // Reserved (low)
  185687. #define ANSI_RESHI 0x7 // Reserved (high)
  185688. typedef struct
  185689. {
  185690. USHORT Length;
  185691. UCHAR ScsiStatus;
  185692. UCHAR PathId;
  185693. UCHAR TargetId;
  185694. UCHAR Lun;
  185695. UCHAR CdbLength;
  185696. UCHAR SenseInfoLength;
  185697. UCHAR DataIn;
  185698. ULONG DataTransferLength;
  185699. ULONG TimeOutValue;
  185700. ULONG DataBufferOffset;
  185701. ULONG SenseInfoOffset;
  185702. UCHAR Cdb[16];
  185703. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185704. typedef struct
  185705. {
  185706. USHORT Length;
  185707. UCHAR ScsiStatus;
  185708. UCHAR PathId;
  185709. UCHAR TargetId;
  185710. UCHAR Lun;
  185711. UCHAR CdbLength;
  185712. UCHAR SenseInfoLength;
  185713. UCHAR DataIn;
  185714. ULONG DataTransferLength;
  185715. ULONG TimeOutValue;
  185716. PVOID DataBuffer;
  185717. ULONG SenseInfoOffset;
  185718. UCHAR Cdb[16];
  185719. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185720. typedef struct
  185721. {
  185722. SCSI_PASS_THROUGH_DIRECT spt;
  185723. ULONG Filler;
  185724. UCHAR ucSenseBuf[32];
  185725. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185726. typedef struct
  185727. {
  185728. ULONG Length;
  185729. UCHAR PortNumber;
  185730. UCHAR PathId;
  185731. UCHAR TargetId;
  185732. UCHAR Lun;
  185733. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185734. #define METHOD_BUFFERED 0
  185735. #define METHOD_IN_DIRECT 1
  185736. #define METHOD_OUT_DIRECT 2
  185737. #define METHOD_NEITHER 3
  185738. #define FILE_ANY_ACCESS 0
  185739. #ifndef FILE_READ_ACCESS
  185740. #define FILE_READ_ACCESS (0x0001)
  185741. #endif
  185742. #ifndef FILE_WRITE_ACCESS
  185743. #define FILE_WRITE_ACCESS (0x0002)
  185744. #endif
  185745. #define IOCTL_SCSI_BASE 0x00000004
  185746. #define SCSI_IOCTL_DATA_OUT 0
  185747. #define SCSI_IOCTL_DATA_IN 1
  185748. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185749. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185750. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185751. )
  185752. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185753. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185754. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185755. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185756. #define SENSE_LEN 14
  185757. #define SRB_DIR_SCSI 0x00
  185758. #define SRB_POSTING 0x01
  185759. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185760. #define SRB_DIR_IN 0x08
  185761. #define SRB_DIR_OUT 0x10
  185762. #define SRB_EVENT_NOTIFY 0x40
  185763. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185764. #define MAX_SRB_TIMEOUT 1080001u
  185765. #define DEFAULT_SRB_TIMEOUT 1080001u
  185766. #define SC_HA_INQUIRY 0x00
  185767. #define SC_GET_DEV_TYPE 0x01
  185768. #define SC_EXEC_SCSI_CMD 0x02
  185769. #define SC_ABORT_SRB 0x03
  185770. #define SC_RESET_DEV 0x04
  185771. #define SC_SET_HA_PARMS 0x05
  185772. #define SC_GET_DISK_INFO 0x06
  185773. #define SC_RESCAN_SCSI_BUS 0x07
  185774. #define SC_GETSET_TIMEOUTS 0x08
  185775. #define SS_PENDING 0x00
  185776. #define SS_COMP 0x01
  185777. #define SS_ABORTED 0x02
  185778. #define SS_ABORT_FAIL 0x03
  185779. #define SS_ERR 0x04
  185780. #define SS_INVALID_CMD 0x80
  185781. #define SS_INVALID_HA 0x81
  185782. #define SS_NO_DEVICE 0x82
  185783. #define SS_INVALID_SRB 0xE0
  185784. #define SS_OLD_MANAGER 0xE1
  185785. #define SS_BUFFER_ALIGN 0xE1
  185786. #define SS_ILLEGAL_MODE 0xE2
  185787. #define SS_NO_ASPI 0xE3
  185788. #define SS_FAILED_INIT 0xE4
  185789. #define SS_ASPI_IS_BUSY 0xE5
  185790. #define SS_BUFFER_TO_BIG 0xE6
  185791. #define SS_BUFFER_TOO_BIG 0xE6
  185792. #define SS_MISMATCHED_COMPONENTS 0xE7
  185793. #define SS_NO_ADAPTERS 0xE8
  185794. #define SS_INSUFFICIENT_RESOURCES 0xE9
  185795. #define SS_ASPI_IS_SHUTDOWN 0xEA
  185796. #define SS_BAD_INSTALL 0xEB
  185797. #define HASTAT_OK 0x00
  185798. #define HASTAT_SEL_TO 0x11
  185799. #define HASTAT_DO_DU 0x12
  185800. #define HASTAT_BUS_FREE 0x13
  185801. #define HASTAT_PHASE_ERR 0x14
  185802. #define HASTAT_TIMEOUT 0x09
  185803. #define HASTAT_COMMAND_TIMEOUT 0x0B
  185804. #define HASTAT_MESSAGE_REJECT 0x0D
  185805. #define HASTAT_BUS_RESET 0x0E
  185806. #define HASTAT_PARITY_ERROR 0x0F
  185807. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  185808. #define PACKED
  185809. #pragma pack(1)
  185810. typedef struct
  185811. {
  185812. BYTE SRB_Cmd;
  185813. BYTE SRB_Status;
  185814. BYTE SRB_HaID;
  185815. BYTE SRB_Flags;
  185816. DWORD SRB_Hdr_Rsvd;
  185817. BYTE HA_Count;
  185818. BYTE HA_SCSI_ID;
  185819. BYTE HA_ManagerId[16];
  185820. BYTE HA_Identifier[16];
  185821. BYTE HA_Unique[16];
  185822. WORD HA_Rsvd1;
  185823. BYTE pad[20];
  185824. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  185825. typedef struct
  185826. {
  185827. BYTE SRB_Cmd;
  185828. BYTE SRB_Status;
  185829. BYTE SRB_HaID;
  185830. BYTE SRB_Flags;
  185831. DWORD SRB_Hdr_Rsvd;
  185832. BYTE SRB_Target;
  185833. BYTE SRB_Lun;
  185834. BYTE SRB_DeviceType;
  185835. BYTE SRB_Rsvd1;
  185836. BYTE pad[68];
  185837. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  185838. typedef struct
  185839. {
  185840. BYTE SRB_Cmd;
  185841. BYTE SRB_Status;
  185842. BYTE SRB_HaID;
  185843. BYTE SRB_Flags;
  185844. DWORD SRB_Hdr_Rsvd;
  185845. BYTE SRB_Target;
  185846. BYTE SRB_Lun;
  185847. WORD SRB_Rsvd1;
  185848. DWORD SRB_BufLen;
  185849. BYTE FAR *SRB_BufPointer;
  185850. BYTE SRB_SenseLen;
  185851. BYTE SRB_CDBLen;
  185852. BYTE SRB_HaStat;
  185853. BYTE SRB_TargStat;
  185854. VOID FAR *SRB_PostProc;
  185855. BYTE SRB_Rsvd2[20];
  185856. BYTE CDBByte[16];
  185857. BYTE SenseArea[SENSE_LEN+2];
  185858. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  185859. typedef struct
  185860. {
  185861. BYTE SRB_Cmd;
  185862. BYTE SRB_Status;
  185863. BYTE SRB_HaId;
  185864. BYTE SRB_Flags;
  185865. DWORD SRB_Hdr_Rsvd;
  185866. } PACKED SRB, *PSRB, FAR *LPSRB;
  185867. #pragma pack()
  185868. struct CDDeviceInfo
  185869. {
  185870. char vendor[9];
  185871. char productId[17];
  185872. char rev[5];
  185873. char vendorSpec[21];
  185874. BYTE ha;
  185875. BYTE tgt;
  185876. BYTE lun;
  185877. char scsiDriveLetter; // will be 0 if not using scsi
  185878. };
  185879. class CDReadBuffer
  185880. {
  185881. public:
  185882. int startFrame;
  185883. int numFrames;
  185884. int dataStartOffset;
  185885. int dataLength;
  185886. BYTE* buffer;
  185887. int bufferSize;
  185888. int index;
  185889. bool wantsIndex;
  185890. CDReadBuffer (const int numberOfFrames)
  185891. : startFrame (0),
  185892. numFrames (0),
  185893. dataStartOffset (0),
  185894. dataLength (0),
  185895. index (0),
  185896. wantsIndex (false)
  185897. {
  185898. bufferSize = 2352 * numberOfFrames;
  185899. buffer = (BYTE*) juce_malloc (bufferSize);
  185900. }
  185901. ~CDReadBuffer()
  185902. {
  185903. juce_free (buffer);
  185904. }
  185905. bool isZero() const
  185906. {
  185907. BYTE* p = buffer + dataStartOffset;
  185908. for (int i = dataLength; --i >= 0;)
  185909. if (*p++ != 0)
  185910. return false;
  185911. return true;
  185912. }
  185913. };
  185914. class CDDeviceHandle;
  185915. class CDController
  185916. {
  185917. public:
  185918. CDController();
  185919. virtual ~CDController();
  185920. virtual bool read (CDReadBuffer* t) = 0;
  185921. virtual void shutDown();
  185922. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  185923. int getLastIndex();
  185924. public:
  185925. bool initialised;
  185926. CDDeviceHandle* deviceInfo;
  185927. int framesToCheck, framesOverlap;
  185928. void prepare (SRB_ExecSCSICmd& s);
  185929. void perform (SRB_ExecSCSICmd& s);
  185930. void setPaused (bool paused);
  185931. };
  185932. #pragma pack(1)
  185933. struct TOCTRACK
  185934. {
  185935. BYTE rsvd;
  185936. BYTE ADR;
  185937. BYTE trackNumber;
  185938. BYTE rsvd2;
  185939. BYTE addr[4];
  185940. };
  185941. struct TOC
  185942. {
  185943. WORD tocLen;
  185944. BYTE firstTrack;
  185945. BYTE lastTrack;
  185946. TOCTRACK tracks[100];
  185947. };
  185948. #pragma pack()
  185949. enum
  185950. {
  185951. READTYPE_ANY = 0,
  185952. READTYPE_ATAPI1 = 1,
  185953. READTYPE_ATAPI2 = 2,
  185954. READTYPE_READ6 = 3,
  185955. READTYPE_READ10 = 4,
  185956. READTYPE_READ_D8 = 5,
  185957. READTYPE_READ_D4 = 6,
  185958. READTYPE_READ_D4_1 = 7,
  185959. READTYPE_READ10_2 = 8
  185960. };
  185961. class CDDeviceHandle
  185962. {
  185963. public:
  185964. CDDeviceHandle (const CDDeviceInfo* const device)
  185965. : scsiHandle (0),
  185966. readType (READTYPE_ANY),
  185967. controller (0)
  185968. {
  185969. memcpy (&info, device, sizeof (info));
  185970. }
  185971. ~CDDeviceHandle()
  185972. {
  185973. if (controller != 0)
  185974. {
  185975. controller->shutDown();
  185976. controller = 0;
  185977. }
  185978. if (scsiHandle != 0)
  185979. CloseHandle (scsiHandle);
  185980. }
  185981. bool readTOC (TOC* lpToc, bool useMSF);
  185982. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  185983. void openDrawer (bool shouldBeOpen);
  185984. CDDeviceInfo info;
  185985. HANDLE scsiHandle;
  185986. BYTE readType;
  185987. private:
  185988. ScopedPointer<CDController> controller;
  185989. bool testController (const int readType,
  185990. CDController* const newController,
  185991. CDReadBuffer* const bufferToUse);
  185992. };
  185993. DWORD (*fGetASPI32SupportInfo)(void);
  185994. DWORD (*fSendASPI32Command)(LPSRB);
  185995. static HINSTANCE winAspiLib = 0;
  185996. static bool usingScsi = false;
  185997. static bool initialised = false;
  185998. static bool InitialiseCDRipper()
  185999. {
  186000. if (! initialised)
  186001. {
  186002. initialised = true;
  186003. OSVERSIONINFO info;
  186004. info.dwOSVersionInfoSize = sizeof (info);
  186005. GetVersionEx (&info);
  186006. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186007. if (! usingScsi)
  186008. {
  186009. fGetASPI32SupportInfo = 0;
  186010. fSendASPI32Command = 0;
  186011. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186012. if (winAspiLib != 0)
  186013. {
  186014. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186015. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186016. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186017. return false;
  186018. }
  186019. else
  186020. {
  186021. usingScsi = true;
  186022. }
  186023. }
  186024. }
  186025. return true;
  186026. }
  186027. static void DeinitialiseCDRipper()
  186028. {
  186029. if (winAspiLib != 0)
  186030. {
  186031. fGetASPI32SupportInfo = 0;
  186032. fSendASPI32Command = 0;
  186033. FreeLibrary (winAspiLib);
  186034. winAspiLib = 0;
  186035. }
  186036. initialised = false;
  186037. }
  186038. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186039. {
  186040. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186041. OSVERSIONINFO info;
  186042. info.dwOSVersionInfoSize = sizeof (info);
  186043. GetVersionEx (&info);
  186044. DWORD flags = GENERIC_READ;
  186045. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186046. flags = GENERIC_READ | GENERIC_WRITE;
  186047. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186048. if (h == INVALID_HANDLE_VALUE)
  186049. {
  186050. flags ^= GENERIC_WRITE;
  186051. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186052. }
  186053. return h;
  186054. }
  186055. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186056. const char driveLetter,
  186057. HANDLE& deviceHandle,
  186058. const bool retryOnFailure = true)
  186059. {
  186060. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186061. zerostruct (s);
  186062. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186063. s.spt.CdbLength = srb->SRB_CDBLen;
  186064. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186065. ? SCSI_IOCTL_DATA_IN
  186066. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186067. ? SCSI_IOCTL_DATA_OUT
  186068. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186069. s.spt.DataTransferLength = srb->SRB_BufLen;
  186070. s.spt.TimeOutValue = 5;
  186071. s.spt.DataBuffer = srb->SRB_BufPointer;
  186072. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186073. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186074. srb->SRB_Status = SS_ERR;
  186075. srb->SRB_TargStat = 0x0004;
  186076. DWORD bytesReturned = 0;
  186077. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186078. &s, sizeof (s),
  186079. &s, sizeof (s),
  186080. &bytesReturned, 0) != 0)
  186081. {
  186082. srb->SRB_Status = SS_COMP;
  186083. }
  186084. else if (retryOnFailure)
  186085. {
  186086. const DWORD error = GetLastError();
  186087. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186088. {
  186089. if (error != ERROR_INVALID_HANDLE)
  186090. CloseHandle (deviceHandle);
  186091. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186092. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186093. }
  186094. }
  186095. return srb->SRB_Status;
  186096. }
  186097. // Controller types..
  186098. class ControllerType1 : public CDController
  186099. {
  186100. public:
  186101. ControllerType1() {}
  186102. ~ControllerType1() {}
  186103. bool read (CDReadBuffer* rb)
  186104. {
  186105. if (rb->numFrames * 2352 > rb->bufferSize)
  186106. return false;
  186107. SRB_ExecSCSICmd s;
  186108. prepare (s);
  186109. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186110. s.SRB_BufLen = rb->bufferSize;
  186111. s.SRB_BufPointer = rb->buffer;
  186112. s.SRB_CDBLen = 12;
  186113. s.CDBByte[0] = 0xBE;
  186114. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186115. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186116. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186117. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186118. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186119. perform (s);
  186120. if (s.SRB_Status != SS_COMP)
  186121. return false;
  186122. rb->dataLength = rb->numFrames * 2352;
  186123. rb->dataStartOffset = 0;
  186124. return true;
  186125. }
  186126. };
  186127. class ControllerType2 : public CDController
  186128. {
  186129. public:
  186130. ControllerType2() {}
  186131. ~ControllerType2() {}
  186132. void shutDown()
  186133. {
  186134. if (initialised)
  186135. {
  186136. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186137. SRB_ExecSCSICmd s;
  186138. prepare (s);
  186139. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186140. s.SRB_BufLen = 0x0C;
  186141. s.SRB_BufPointer = bufPointer;
  186142. s.SRB_CDBLen = 6;
  186143. s.CDBByte[0] = 0x15;
  186144. s.CDBByte[4] = 0x0C;
  186145. perform (s);
  186146. }
  186147. }
  186148. bool init()
  186149. {
  186150. SRB_ExecSCSICmd s;
  186151. s.SRB_Status = SS_ERR;
  186152. if (deviceInfo->readType == READTYPE_READ10_2)
  186153. {
  186154. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186155. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186156. for (int i = 0; i < 2; ++i)
  186157. {
  186158. prepare (s);
  186159. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186160. s.SRB_BufLen = 0x14;
  186161. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186162. s.SRB_CDBLen = 6;
  186163. s.CDBByte[0] = 0x15;
  186164. s.CDBByte[1] = 0x10;
  186165. s.CDBByte[4] = 0x14;
  186166. perform (s);
  186167. if (s.SRB_Status != SS_COMP)
  186168. return false;
  186169. }
  186170. }
  186171. else
  186172. {
  186173. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186174. prepare (s);
  186175. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186176. s.SRB_BufLen = 0x0C;
  186177. s.SRB_BufPointer = bufPointer;
  186178. s.SRB_CDBLen = 6;
  186179. s.CDBByte[0] = 0x15;
  186180. s.CDBByte[4] = 0x0C;
  186181. perform (s);
  186182. }
  186183. return s.SRB_Status == SS_COMP;
  186184. }
  186185. bool read (CDReadBuffer* rb)
  186186. {
  186187. if (rb->numFrames * 2352 > rb->bufferSize)
  186188. return false;
  186189. if (!initialised)
  186190. {
  186191. initialised = init();
  186192. if (!initialised)
  186193. return false;
  186194. }
  186195. SRB_ExecSCSICmd s;
  186196. prepare (s);
  186197. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186198. s.SRB_BufLen = rb->bufferSize;
  186199. s.SRB_BufPointer = rb->buffer;
  186200. s.SRB_CDBLen = 10;
  186201. s.CDBByte[0] = 0x28;
  186202. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186203. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186204. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186205. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186206. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186207. perform (s);
  186208. if (s.SRB_Status != SS_COMP)
  186209. return false;
  186210. rb->dataLength = rb->numFrames * 2352;
  186211. rb->dataStartOffset = 0;
  186212. return true;
  186213. }
  186214. };
  186215. class ControllerType3 : public CDController
  186216. {
  186217. public:
  186218. ControllerType3() {}
  186219. ~ControllerType3() {}
  186220. bool read (CDReadBuffer* rb)
  186221. {
  186222. if (rb->numFrames * 2352 > rb->bufferSize)
  186223. return false;
  186224. if (!initialised)
  186225. {
  186226. setPaused (false);
  186227. initialised = true;
  186228. }
  186229. SRB_ExecSCSICmd s;
  186230. prepare (s);
  186231. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186232. s.SRB_BufLen = rb->numFrames * 2352;
  186233. s.SRB_BufPointer = rb->buffer;
  186234. s.SRB_CDBLen = 12;
  186235. s.CDBByte[0] = 0xD8;
  186236. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186237. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186238. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186239. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186240. perform (s);
  186241. if (s.SRB_Status != SS_COMP)
  186242. return false;
  186243. rb->dataLength = rb->numFrames * 2352;
  186244. rb->dataStartOffset = 0;
  186245. return true;
  186246. }
  186247. };
  186248. class ControllerType4 : public CDController
  186249. {
  186250. public:
  186251. ControllerType4() {}
  186252. ~ControllerType4() {}
  186253. bool selectD4Mode()
  186254. {
  186255. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186256. SRB_ExecSCSICmd s;
  186257. prepare (s);
  186258. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186259. s.SRB_CDBLen = 6;
  186260. s.SRB_BufLen = 12;
  186261. s.SRB_BufPointer = bufPointer;
  186262. s.CDBByte[0] = 0x15;
  186263. s.CDBByte[1] = 0x10;
  186264. s.CDBByte[4] = 0x08;
  186265. perform (s);
  186266. return s.SRB_Status == SS_COMP;
  186267. }
  186268. bool read (CDReadBuffer* rb)
  186269. {
  186270. if (rb->numFrames * 2352 > rb->bufferSize)
  186271. return false;
  186272. if (!initialised)
  186273. {
  186274. setPaused (true);
  186275. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186276. selectD4Mode();
  186277. initialised = true;
  186278. }
  186279. SRB_ExecSCSICmd s;
  186280. prepare (s);
  186281. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186282. s.SRB_BufLen = rb->bufferSize;
  186283. s.SRB_BufPointer = rb->buffer;
  186284. s.SRB_CDBLen = 10;
  186285. s.CDBByte[0] = 0xD4;
  186286. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186287. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186288. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186289. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186290. perform (s);
  186291. if (s.SRB_Status != SS_COMP)
  186292. return false;
  186293. rb->dataLength = rb->numFrames * 2352;
  186294. rb->dataStartOffset = 0;
  186295. return true;
  186296. }
  186297. };
  186298. CDController::CDController() : initialised (false)
  186299. {
  186300. }
  186301. CDController::~CDController()
  186302. {
  186303. }
  186304. void CDController::prepare (SRB_ExecSCSICmd& s)
  186305. {
  186306. zerostruct (s);
  186307. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186308. s.SRB_HaID = deviceInfo->info.ha;
  186309. s.SRB_Target = deviceInfo->info.tgt;
  186310. s.SRB_Lun = deviceInfo->info.lun;
  186311. s.SRB_SenseLen = SENSE_LEN;
  186312. }
  186313. void CDController::perform (SRB_ExecSCSICmd& s)
  186314. {
  186315. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186316. s.SRB_PostProc = event;
  186317. ResetEvent (event);
  186318. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186319. deviceInfo->info.scsiDriveLetter,
  186320. deviceInfo->scsiHandle)
  186321. : fSendASPI32Command ((LPSRB)&s);
  186322. if (status == SS_PENDING)
  186323. WaitForSingleObject (event, 4000);
  186324. CloseHandle (event);
  186325. }
  186326. void CDController::setPaused (bool paused)
  186327. {
  186328. SRB_ExecSCSICmd s;
  186329. prepare (s);
  186330. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186331. s.SRB_CDBLen = 10;
  186332. s.CDBByte[0] = 0x4B;
  186333. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186334. perform (s);
  186335. }
  186336. void CDController::shutDown()
  186337. {
  186338. }
  186339. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186340. {
  186341. if (overlapBuffer != 0)
  186342. {
  186343. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186344. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186345. if (doJitter
  186346. && overlapBuffer->startFrame > 0
  186347. && overlapBuffer->numFrames > 0
  186348. && overlapBuffer->dataLength > 0)
  186349. {
  186350. const int numFrames = rb->numFrames;
  186351. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186352. {
  186353. rb->startFrame -= framesOverlap;
  186354. if (framesToCheck < framesOverlap
  186355. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186356. rb->numFrames += framesOverlap;
  186357. }
  186358. else
  186359. {
  186360. overlapBuffer->dataLength = 0;
  186361. overlapBuffer->startFrame = 0;
  186362. overlapBuffer->numFrames = 0;
  186363. }
  186364. }
  186365. if (! read (rb))
  186366. return false;
  186367. if (doJitter)
  186368. {
  186369. const int checkLen = framesToCheck * 2352;
  186370. const int maxToCheck = rb->dataLength - checkLen;
  186371. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186372. return true;
  186373. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186374. bool found = false;
  186375. for (int i = 0; i < maxToCheck; ++i)
  186376. {
  186377. if (memcmp (p, rb->buffer + i, checkLen) == 0)
  186378. {
  186379. i += checkLen;
  186380. rb->dataStartOffset = i;
  186381. rb->dataLength -= i;
  186382. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186383. found = true;
  186384. break;
  186385. }
  186386. }
  186387. rb->numFrames = rb->dataLength / 2352;
  186388. rb->dataLength = 2352 * rb->numFrames;
  186389. if (!found)
  186390. return false;
  186391. }
  186392. if (canDoJitter)
  186393. {
  186394. memcpy (overlapBuffer->buffer,
  186395. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186396. 2352 * framesToCheck);
  186397. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186398. overlapBuffer->numFrames = framesToCheck;
  186399. overlapBuffer->dataLength = 2352 * framesToCheck;
  186400. overlapBuffer->dataStartOffset = 0;
  186401. }
  186402. else
  186403. {
  186404. overlapBuffer->startFrame = 0;
  186405. overlapBuffer->numFrames = 0;
  186406. overlapBuffer->dataLength = 0;
  186407. }
  186408. return true;
  186409. }
  186410. else
  186411. {
  186412. return read (rb);
  186413. }
  186414. }
  186415. int CDController::getLastIndex()
  186416. {
  186417. char qdata[100];
  186418. SRB_ExecSCSICmd s;
  186419. prepare (s);
  186420. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186421. s.SRB_BufLen = sizeof (qdata);
  186422. s.SRB_BufPointer = (BYTE*)qdata;
  186423. s.SRB_CDBLen = 12;
  186424. s.CDBByte[0] = 0x42;
  186425. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186426. s.CDBByte[2] = 64;
  186427. s.CDBByte[3] = 1; // get current position
  186428. s.CDBByte[7] = 0;
  186429. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186430. perform (s);
  186431. if (s.SRB_Status == SS_COMP)
  186432. return qdata[7];
  186433. return 0;
  186434. }
  186435. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186436. {
  186437. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186438. SRB_ExecSCSICmd s;
  186439. zerostruct (s);
  186440. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186441. s.SRB_HaID = info.ha;
  186442. s.SRB_Target = info.tgt;
  186443. s.SRB_Lun = info.lun;
  186444. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186445. s.SRB_BufLen = 0x324;
  186446. s.SRB_BufPointer = (BYTE*)lpToc;
  186447. s.SRB_SenseLen = 0x0E;
  186448. s.SRB_CDBLen = 0x0A;
  186449. s.SRB_PostProc = event;
  186450. s.CDBByte[0] = 0x43;
  186451. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186452. s.CDBByte[7] = 0x03;
  186453. s.CDBByte[8] = 0x24;
  186454. ResetEvent (event);
  186455. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186456. : fSendASPI32Command ((LPSRB)&s);
  186457. if (status == SS_PENDING)
  186458. WaitForSingleObject (event, 4000);
  186459. CloseHandle (event);
  186460. return (s.SRB_Status == SS_COMP);
  186461. }
  186462. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186463. CDReadBuffer* const overlapBuffer)
  186464. {
  186465. if (controller == 0)
  186466. {
  186467. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186468. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186469. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186470. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186471. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186472. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186473. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186474. }
  186475. buffer->index = 0;
  186476. if ((controller != 0)
  186477. && controller->readAudio (buffer, overlapBuffer))
  186478. {
  186479. if (buffer->wantsIndex)
  186480. buffer->index = controller->getLastIndex();
  186481. return true;
  186482. }
  186483. return false;
  186484. }
  186485. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186486. {
  186487. if (shouldBeOpen)
  186488. {
  186489. if (controller != 0)
  186490. {
  186491. controller->shutDown();
  186492. controller = 0;
  186493. }
  186494. if (scsiHandle != 0)
  186495. {
  186496. CloseHandle (scsiHandle);
  186497. scsiHandle = 0;
  186498. }
  186499. }
  186500. SRB_ExecSCSICmd s;
  186501. zerostruct (s);
  186502. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186503. s.SRB_HaID = info.ha;
  186504. s.SRB_Target = info.tgt;
  186505. s.SRB_Lun = info.lun;
  186506. s.SRB_SenseLen = SENSE_LEN;
  186507. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186508. s.SRB_BufLen = 0;
  186509. s.SRB_BufPointer = 0;
  186510. s.SRB_CDBLen = 12;
  186511. s.CDBByte[0] = 0x1b;
  186512. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186513. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186514. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186515. s.SRB_PostProc = event;
  186516. ResetEvent (event);
  186517. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186518. : fSendASPI32Command ((LPSRB)&s);
  186519. if (status == SS_PENDING)
  186520. WaitForSingleObject (event, 4000);
  186521. CloseHandle (event);
  186522. }
  186523. bool CDDeviceHandle::testController (const int type,
  186524. CDController* const newController,
  186525. CDReadBuffer* const rb)
  186526. {
  186527. controller = newController;
  186528. readType = (BYTE)type;
  186529. controller->deviceInfo = this;
  186530. controller->framesToCheck = 1;
  186531. controller->framesOverlap = 3;
  186532. bool passed = false;
  186533. memset (rb->buffer, 0xcd, rb->bufferSize);
  186534. if (controller->read (rb))
  186535. {
  186536. passed = true;
  186537. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186538. int wrong = 0;
  186539. for (int i = rb->dataLength / 4; --i >= 0;)
  186540. {
  186541. if (*p++ == (int) 0xcdcdcdcd)
  186542. {
  186543. if (++wrong == 4)
  186544. {
  186545. passed = false;
  186546. break;
  186547. }
  186548. }
  186549. else
  186550. {
  186551. wrong = 0;
  186552. }
  186553. }
  186554. }
  186555. if (! passed)
  186556. {
  186557. controller->shutDown();
  186558. controller = 0;
  186559. }
  186560. return passed;
  186561. }
  186562. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186563. {
  186564. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186565. const int bufSize = 128;
  186566. BYTE buffer[bufSize];
  186567. zeromem (buffer, bufSize);
  186568. SRB_ExecSCSICmd s;
  186569. zerostruct (s);
  186570. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186571. s.SRB_HaID = ha;
  186572. s.SRB_Target = tgt;
  186573. s.SRB_Lun = lun;
  186574. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186575. s.SRB_BufLen = bufSize;
  186576. s.SRB_BufPointer = buffer;
  186577. s.SRB_SenseLen = SENSE_LEN;
  186578. s.SRB_CDBLen = 6;
  186579. s.SRB_PostProc = event;
  186580. s.CDBByte[0] = SCSI_INQUIRY;
  186581. s.CDBByte[4] = 100;
  186582. ResetEvent (event);
  186583. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186584. WaitForSingleObject (event, 4000);
  186585. CloseHandle (event);
  186586. if (s.SRB_Status == SS_COMP)
  186587. {
  186588. memcpy (dev->vendor, &buffer[8], 8);
  186589. memcpy (dev->productId, &buffer[16], 16);
  186590. memcpy (dev->rev, &buffer[32], 4);
  186591. memcpy (dev->vendorSpec, &buffer[36], 20);
  186592. }
  186593. }
  186594. static int FindCDDevices (CDDeviceInfo* const list,
  186595. int maxItems)
  186596. {
  186597. int count = 0;
  186598. if (usingScsi)
  186599. {
  186600. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186601. {
  186602. TCHAR drivePath[8];
  186603. drivePath[0] = driveLetter;
  186604. drivePath[1] = ':';
  186605. drivePath[2] = '\\';
  186606. drivePath[3] = 0;
  186607. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186608. {
  186609. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186610. if (h != INVALID_HANDLE_VALUE)
  186611. {
  186612. BYTE buffer[100], passThroughStruct[1024];
  186613. zeromem (buffer, sizeof (buffer));
  186614. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186615. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186616. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186617. p->spt.CdbLength = 6;
  186618. p->spt.SenseInfoLength = 24;
  186619. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186620. p->spt.DataTransferLength = 100;
  186621. p->spt.TimeOutValue = 2;
  186622. p->spt.DataBuffer = buffer;
  186623. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186624. p->spt.Cdb[0] = 0x12;
  186625. p->spt.Cdb[4] = 100;
  186626. DWORD bytesReturned = 0;
  186627. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186628. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186629. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186630. &bytesReturned, 0) != 0)
  186631. {
  186632. zeromem (&list[count], sizeof (CDDeviceInfo));
  186633. list[count].scsiDriveLetter = driveLetter;
  186634. memcpy (list[count].vendor, &buffer[8], 8);
  186635. memcpy (list[count].productId, &buffer[16], 16);
  186636. memcpy (list[count].rev, &buffer[32], 4);
  186637. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186638. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186639. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186640. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186641. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186642. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186643. &bytesReturned, 0) != 0)
  186644. {
  186645. list[count].ha = scsiAddr->PortNumber;
  186646. list[count].tgt = scsiAddr->TargetId;
  186647. list[count].lun = scsiAddr->Lun;
  186648. ++count;
  186649. }
  186650. }
  186651. CloseHandle (h);
  186652. }
  186653. }
  186654. }
  186655. }
  186656. else
  186657. {
  186658. const DWORD d = fGetASPI32SupportInfo();
  186659. BYTE status = HIBYTE (LOWORD (d));
  186660. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186661. return 0;
  186662. const int numAdapters = LOBYTE (LOWORD (d));
  186663. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186664. {
  186665. SRB_HAInquiry s;
  186666. zerostruct (s);
  186667. s.SRB_Cmd = SC_HA_INQUIRY;
  186668. s.SRB_HaID = ha;
  186669. fSendASPI32Command ((LPSRB)&s);
  186670. if (s.SRB_Status == SS_COMP)
  186671. {
  186672. maxItems = (int)s.HA_Unique[3];
  186673. if (maxItems == 0)
  186674. maxItems = 8;
  186675. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186676. {
  186677. for (BYTE lun = 0; lun < 8; ++lun)
  186678. {
  186679. SRB_GDEVBlock sb;
  186680. zerostruct (sb);
  186681. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186682. sb.SRB_HaID = ha;
  186683. sb.SRB_Target = tgt;
  186684. sb.SRB_Lun = lun;
  186685. fSendASPI32Command ((LPSRB) &sb);
  186686. if (sb.SRB_Status == SS_COMP
  186687. && sb.SRB_DeviceType == DTYPE_CROM)
  186688. {
  186689. zeromem (&list[count], sizeof (CDDeviceInfo));
  186690. list[count].ha = ha;
  186691. list[count].tgt = tgt;
  186692. list[count].lun = lun;
  186693. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186694. ++count;
  186695. }
  186696. }
  186697. }
  186698. }
  186699. }
  186700. }
  186701. return count;
  186702. }
  186703. static int ripperUsers = 0;
  186704. static bool initialisedOk = false;
  186705. class DeinitialiseTimer : private Timer,
  186706. private DeletedAtShutdown
  186707. {
  186708. DeinitialiseTimer (const DeinitialiseTimer&);
  186709. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186710. public:
  186711. DeinitialiseTimer()
  186712. {
  186713. startTimer (4000);
  186714. }
  186715. ~DeinitialiseTimer()
  186716. {
  186717. if (--ripperUsers == 0)
  186718. DeinitialiseCDRipper();
  186719. }
  186720. void timerCallback()
  186721. {
  186722. delete this;
  186723. }
  186724. juce_UseDebuggingNewOperator
  186725. };
  186726. static void incUserCount()
  186727. {
  186728. if (ripperUsers++ == 0)
  186729. initialisedOk = InitialiseCDRipper();
  186730. }
  186731. static void decUserCount()
  186732. {
  186733. new DeinitialiseTimer();
  186734. }
  186735. struct CDDeviceWrapper
  186736. {
  186737. ScopedPointer<CDDeviceHandle> cdH;
  186738. ScopedPointer<CDReadBuffer> overlapBuffer;
  186739. bool jitter;
  186740. };
  186741. static int getAddressOf (const TOCTRACK* const t)
  186742. {
  186743. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186744. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186745. }
  186746. static int getMSFAddressOf (const TOCTRACK* const t)
  186747. {
  186748. return 60 * t->addr[1] + t->addr[2];
  186749. }
  186750. static const int samplesPerFrame = 44100 / 75;
  186751. static const int bytesPerFrame = samplesPerFrame * 4;
  186752. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186753. {
  186754. SRB_GDEVBlock s;
  186755. zerostruct (s);
  186756. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186757. s.SRB_HaID = device->ha;
  186758. s.SRB_Target = device->tgt;
  186759. s.SRB_Lun = device->lun;
  186760. if (usingScsi)
  186761. {
  186762. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186763. if (h != INVALID_HANDLE_VALUE)
  186764. {
  186765. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186766. cdh->scsiHandle = h;
  186767. return cdh;
  186768. }
  186769. }
  186770. else
  186771. {
  186772. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186773. && s.SRB_DeviceType == DTYPE_CROM)
  186774. {
  186775. return new CDDeviceHandle (device);
  186776. }
  186777. }
  186778. return 0;
  186779. }
  186780. }
  186781. const StringArray AudioCDReader::getAvailableCDNames()
  186782. {
  186783. using namespace CDReaderHelpers;
  186784. StringArray results;
  186785. incUserCount();
  186786. if (initialisedOk)
  186787. {
  186788. CDDeviceInfo list[8];
  186789. const int num = FindCDDevices (list, 8);
  186790. decUserCount();
  186791. for (int i = 0; i < num; ++i)
  186792. {
  186793. String s;
  186794. if (list[i].scsiDriveLetter > 0)
  186795. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << ": ";
  186796. s << String (list[i].vendor).trim()
  186797. << ' ' << String (list[i].productId).trim()
  186798. << ' ' << String (list[i].rev).trim();
  186799. results.add (s);
  186800. }
  186801. }
  186802. return results;
  186803. }
  186804. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  186805. {
  186806. using namespace CDReaderHelpers;
  186807. incUserCount();
  186808. if (initialisedOk)
  186809. {
  186810. CDDeviceInfo list[8];
  186811. const int num = FindCDDevices (list, 8);
  186812. if (((unsigned int) deviceIndex) < (unsigned int) num)
  186813. {
  186814. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  186815. if (handle != 0)
  186816. {
  186817. CDDeviceWrapper* const d = new CDDeviceWrapper();
  186818. d->cdH = handle;
  186819. d->overlapBuffer = new CDReadBuffer(3);
  186820. return new AudioCDReader (d);
  186821. }
  186822. }
  186823. }
  186824. decUserCount();
  186825. return 0;
  186826. }
  186827. AudioCDReader::AudioCDReader (void* handle_)
  186828. : AudioFormatReader (0, "CD Audio"),
  186829. handle (handle_),
  186830. indexingEnabled (false),
  186831. lastIndex (0),
  186832. firstFrameInBuffer (0),
  186833. samplesInBuffer (0)
  186834. {
  186835. using namespace CDReaderHelpers;
  186836. jassert (handle_ != 0);
  186837. refreshTrackLengths();
  186838. sampleRate = 44100.0;
  186839. bitsPerSample = 16;
  186840. lengthInSamples = getPositionOfTrackStart (numTracks);
  186841. numChannels = 2;
  186842. usesFloatingPointData = false;
  186843. buffer.setSize (4 * bytesPerFrame, true);
  186844. }
  186845. AudioCDReader::~AudioCDReader()
  186846. {
  186847. using namespace CDReaderHelpers;
  186848. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186849. delete device;
  186850. decUserCount();
  186851. }
  186852. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  186853. int64 startSampleInFile, int numSamples)
  186854. {
  186855. using namespace CDReaderHelpers;
  186856. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186857. bool ok = true;
  186858. while (numSamples > 0)
  186859. {
  186860. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  186861. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  186862. if (startSampleInFile >= bufferStartSample
  186863. && startSampleInFile < bufferEndSample)
  186864. {
  186865. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  186866. int* const l = destSamples[0] + startOffsetInDestBuffer;
  186867. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186868. const short* src = (const short*) buffer.getData();
  186869. src += 2 * (startSampleInFile - bufferStartSample);
  186870. for (int i = 0; i < toDo; ++i)
  186871. {
  186872. l[i] = src [i << 1] << 16;
  186873. if (r != 0)
  186874. r[i] = src [(i << 1) + 1] << 16;
  186875. }
  186876. startOffsetInDestBuffer += toDo;
  186877. startSampleInFile += toDo;
  186878. numSamples -= toDo;
  186879. }
  186880. else
  186881. {
  186882. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  186883. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  186884. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  186885. {
  186886. device->overlapBuffer->dataLength = 0;
  186887. device->overlapBuffer->startFrame = 0;
  186888. device->overlapBuffer->numFrames = 0;
  186889. device->jitter = false;
  186890. }
  186891. firstFrameInBuffer = frameNeeded;
  186892. lastIndex = 0;
  186893. CDReadBuffer readBuffer (framesInBuffer + 4);
  186894. readBuffer.wantsIndex = indexingEnabled;
  186895. int i;
  186896. for (i = 5; --i >= 0;)
  186897. {
  186898. readBuffer.startFrame = frameNeeded;
  186899. readBuffer.numFrames = framesInBuffer;
  186900. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  186901. break;
  186902. else
  186903. device->overlapBuffer->dataLength = 0;
  186904. }
  186905. if (i >= 0)
  186906. {
  186907. memcpy ((char*) buffer.getData(),
  186908. readBuffer.buffer + readBuffer.dataStartOffset,
  186909. readBuffer.dataLength);
  186910. samplesInBuffer = readBuffer.dataLength >> 2;
  186911. lastIndex = readBuffer.index;
  186912. }
  186913. else
  186914. {
  186915. int* l = destSamples[0] + startOffsetInDestBuffer;
  186916. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186917. while (--numSamples >= 0)
  186918. {
  186919. *l++ = 0;
  186920. if (r != 0)
  186921. *r++ = 0;
  186922. }
  186923. // sometimes the read fails for just the very last couple of blocks, so
  186924. // we'll ignore and errors in the last half-second of the disk..
  186925. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  186926. break;
  186927. }
  186928. }
  186929. }
  186930. return ok;
  186931. }
  186932. bool AudioCDReader::isCDStillPresent() const
  186933. {
  186934. using namespace CDReaderHelpers;
  186935. TOC toc;
  186936. zerostruct (toc);
  186937. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  186938. }
  186939. int AudioCDReader::getNumTracks() const
  186940. {
  186941. return numTracks;
  186942. }
  186943. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  186944. {
  186945. using namespace CDReaderHelpers;
  186946. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  186947. : 0;
  186948. }
  186949. void AudioCDReader::refreshTrackLengths()
  186950. {
  186951. using namespace CDReaderHelpers;
  186952. zeromem (trackStarts, sizeof (trackStarts));
  186953. zeromem (audioTracks, sizeof (audioTracks));
  186954. TOC toc;
  186955. zerostruct (toc);
  186956. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  186957. {
  186958. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  186959. for (int i = 0; i <= numTracks; ++i)
  186960. {
  186961. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  186962. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  186963. }
  186964. }
  186965. else
  186966. {
  186967. numTracks = 0;
  186968. }
  186969. }
  186970. bool AudioCDReader::isTrackAudio (int trackNum) const
  186971. {
  186972. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  186973. : false;
  186974. }
  186975. void AudioCDReader::enableIndexScanning (bool b)
  186976. {
  186977. indexingEnabled = b;
  186978. }
  186979. int AudioCDReader::getLastIndex() const
  186980. {
  186981. return lastIndex;
  186982. }
  186983. const int framesPerIndexRead = 4;
  186984. int AudioCDReader::getIndexAt (int samplePos)
  186985. {
  186986. using namespace CDReaderHelpers;
  186987. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186988. const int frameNeeded = samplePos / samplesPerFrame;
  186989. device->overlapBuffer->dataLength = 0;
  186990. device->overlapBuffer->startFrame = 0;
  186991. device->overlapBuffer->numFrames = 0;
  186992. device->jitter = false;
  186993. firstFrameInBuffer = 0;
  186994. lastIndex = 0;
  186995. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  186996. readBuffer.wantsIndex = true;
  186997. int i;
  186998. for (i = 5; --i >= 0;)
  186999. {
  187000. readBuffer.startFrame = frameNeeded;
  187001. readBuffer.numFrames = framesPerIndexRead;
  187002. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187003. break;
  187004. }
  187005. if (i >= 0)
  187006. return readBuffer.index;
  187007. return -1;
  187008. }
  187009. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187010. {
  187011. using namespace CDReaderHelpers;
  187012. Array <int> indexes;
  187013. const int trackStart = getPositionOfTrackStart (trackNumber);
  187014. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187015. bool needToScan = true;
  187016. if (trackEnd - trackStart > 20 * 44100)
  187017. {
  187018. // check the end of the track for indexes before scanning the whole thing
  187019. needToScan = false;
  187020. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187021. bool seenAnIndex = false;
  187022. while (pos <= trackEnd - samplesPerFrame)
  187023. {
  187024. const int index = getIndexAt (pos);
  187025. if (index == 0)
  187026. {
  187027. // lead-out, so skip back a bit if we've not found any indexes yet..
  187028. if (seenAnIndex)
  187029. break;
  187030. pos -= 44100 * 5;
  187031. if (pos < trackStart)
  187032. break;
  187033. }
  187034. else
  187035. {
  187036. if (index > 0)
  187037. seenAnIndex = true;
  187038. if (index > 1)
  187039. {
  187040. needToScan = true;
  187041. break;
  187042. }
  187043. pos += samplesPerFrame * framesPerIndexRead;
  187044. }
  187045. }
  187046. }
  187047. if (needToScan)
  187048. {
  187049. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187050. int pos = trackStart;
  187051. int last = -1;
  187052. while (pos < trackEnd - samplesPerFrame * 10)
  187053. {
  187054. const int frameNeeded = pos / samplesPerFrame;
  187055. device->overlapBuffer->dataLength = 0;
  187056. device->overlapBuffer->startFrame = 0;
  187057. device->overlapBuffer->numFrames = 0;
  187058. device->jitter = false;
  187059. firstFrameInBuffer = 0;
  187060. CDReadBuffer readBuffer (4);
  187061. readBuffer.wantsIndex = true;
  187062. int i;
  187063. for (i = 5; --i >= 0;)
  187064. {
  187065. readBuffer.startFrame = frameNeeded;
  187066. readBuffer.numFrames = framesPerIndexRead;
  187067. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187068. break;
  187069. }
  187070. if (i < 0)
  187071. break;
  187072. if (readBuffer.index > last && readBuffer.index > 1)
  187073. {
  187074. last = readBuffer.index;
  187075. indexes.add (pos);
  187076. }
  187077. pos += samplesPerFrame * framesPerIndexRead;
  187078. }
  187079. indexes.removeValue (trackStart);
  187080. }
  187081. return indexes;
  187082. }
  187083. int AudioCDReader::getCDDBId()
  187084. {
  187085. using namespace CDReaderHelpers;
  187086. refreshTrackLengths();
  187087. if (numTracks > 0)
  187088. {
  187089. TOC toc;
  187090. zerostruct (toc);
  187091. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187092. {
  187093. int n = 0;
  187094. for (int i = numTracks; --i >= 0;)
  187095. {
  187096. int j = getMSFAddressOf (&toc.tracks[i]);
  187097. while (j > 0)
  187098. {
  187099. n += (j % 10);
  187100. j /= 10;
  187101. }
  187102. }
  187103. if (n != 0)
  187104. {
  187105. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187106. - getMSFAddressOf (&toc.tracks[0]);
  187107. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187108. }
  187109. }
  187110. }
  187111. return 0;
  187112. }
  187113. void AudioCDReader::ejectDisk()
  187114. {
  187115. using namespace CDReaderHelpers;
  187116. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187117. }
  187118. #endif
  187119. #if JUCE_USE_CDBURNER
  187120. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187121. {
  187122. CoInitialize (0);
  187123. IDiscMaster* dm;
  187124. IDiscRecorder* result = 0;
  187125. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187126. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187127. IID_IDiscMaster,
  187128. (void**) &dm)))
  187129. {
  187130. if (SUCCEEDED (dm->Open()))
  187131. {
  187132. IEnumDiscRecorders* drEnum = 0;
  187133. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187134. {
  187135. IDiscRecorder* dr = 0;
  187136. DWORD dummy;
  187137. int index = 0;
  187138. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187139. {
  187140. if (indexToOpen == index)
  187141. {
  187142. result = dr;
  187143. break;
  187144. }
  187145. else if (list != 0)
  187146. {
  187147. BSTR path;
  187148. if (SUCCEEDED (dr->GetPath (&path)))
  187149. list->add ((const WCHAR*) path);
  187150. }
  187151. ++index;
  187152. dr->Release();
  187153. }
  187154. drEnum->Release();
  187155. }
  187156. if (master == 0)
  187157. dm->Close();
  187158. }
  187159. if (master != 0)
  187160. *master = dm;
  187161. else
  187162. dm->Release();
  187163. }
  187164. return result;
  187165. }
  187166. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187167. public Timer
  187168. {
  187169. public:
  187170. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187171. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187172. listener (0), progress (0), shouldCancel (false), refCount (1)
  187173. {
  187174. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187175. jassert (SUCCEEDED (hr));
  187176. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187177. //jassert (SUCCEEDED (hr));
  187178. lastState = getDiskState();
  187179. startTimer (2000);
  187180. }
  187181. ~Pimpl() {}
  187182. void releaseObjects()
  187183. {
  187184. discRecorder->Close();
  187185. if (redbook != 0)
  187186. redbook->Release();
  187187. discRecorder->Release();
  187188. discMaster->Release();
  187189. Release();
  187190. }
  187191. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187192. {
  187193. if (result == 0)
  187194. return E_POINTER;
  187195. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187196. {
  187197. AddRef();
  187198. *result = this;
  187199. return S_OK;
  187200. }
  187201. *result = 0;
  187202. return E_NOINTERFACE;
  187203. }
  187204. ULONG __stdcall AddRef() { return ++refCount; }
  187205. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187206. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187207. {
  187208. if (listener != 0 && ! shouldCancel)
  187209. shouldCancel = listener->audioCDBurnProgress (progress);
  187210. *pbCancel = shouldCancel;
  187211. return S_OK;
  187212. }
  187213. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187214. {
  187215. progress = nCompleted / (float) nTotal;
  187216. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187217. return E_NOTIMPL;
  187218. }
  187219. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187220. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187221. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187222. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187223. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187224. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187225. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187226. class ScopedDiscOpener
  187227. {
  187228. public:
  187229. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187230. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187231. private:
  187232. Pimpl& pimpl;
  187233. ScopedDiscOpener (const ScopedDiscOpener&);
  187234. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187235. };
  187236. DiskState getDiskState()
  187237. {
  187238. const ScopedDiscOpener opener (*this);
  187239. long type, flags;
  187240. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187241. if (FAILED (hr))
  187242. return unknown;
  187243. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187244. return writableDiskPresent;
  187245. if (type == 0)
  187246. return noDisc;
  187247. else
  187248. return readOnlyDiskPresent;
  187249. }
  187250. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187251. {
  187252. ComSmartPtr<IPropertyStorage> prop;
  187253. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187254. return defaultReturn;
  187255. PROPSPEC iPropSpec;
  187256. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187257. iPropSpec.lpwstr = name;
  187258. PROPVARIANT iPropVariant;
  187259. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187260. ? defaultReturn : (int) iPropVariant.lVal;
  187261. }
  187262. bool setIntProperty (const LPOLESTR name, const int value) const
  187263. {
  187264. ComSmartPtr<IPropertyStorage> prop;
  187265. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187266. return false;
  187267. PROPSPEC iPropSpec;
  187268. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187269. iPropSpec.lpwstr = name;
  187270. PROPVARIANT iPropVariant;
  187271. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187272. return false;
  187273. iPropVariant.lVal = (long) value;
  187274. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187275. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187276. }
  187277. void timerCallback()
  187278. {
  187279. const DiskState state = getDiskState();
  187280. if (state != lastState)
  187281. {
  187282. lastState = state;
  187283. owner.sendChangeMessage (&owner);
  187284. }
  187285. }
  187286. AudioCDBurner& owner;
  187287. DiskState lastState;
  187288. IDiscMaster* discMaster;
  187289. IDiscRecorder* discRecorder;
  187290. IRedbookDiscMaster* redbook;
  187291. AudioCDBurner::BurnProgressListener* listener;
  187292. float progress;
  187293. bool shouldCancel;
  187294. private:
  187295. int refCount;
  187296. };
  187297. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187298. {
  187299. IDiscMaster* discMaster = 0;
  187300. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187301. if (discRecorder != 0)
  187302. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187303. }
  187304. AudioCDBurner::~AudioCDBurner()
  187305. {
  187306. if (pimpl != 0)
  187307. pimpl.release()->releaseObjects();
  187308. }
  187309. const StringArray AudioCDBurner::findAvailableDevices()
  187310. {
  187311. StringArray devs;
  187312. enumCDBurners (&devs, -1, 0);
  187313. return devs;
  187314. }
  187315. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187316. {
  187317. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187318. if (b->pimpl == 0)
  187319. b = 0;
  187320. return b.release();
  187321. }
  187322. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187323. {
  187324. return pimpl->getDiskState();
  187325. }
  187326. bool AudioCDBurner::isDiskPresent() const
  187327. {
  187328. return getDiskState() == writableDiskPresent;
  187329. }
  187330. bool AudioCDBurner::openTray()
  187331. {
  187332. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187333. return SUCCEEDED (pimpl->discRecorder->Eject());
  187334. }
  187335. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187336. {
  187337. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187338. DiskState oldState = getDiskState();
  187339. DiskState newState = oldState;
  187340. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187341. {
  187342. newState = getDiskState();
  187343. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187344. }
  187345. return newState;
  187346. }
  187347. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187348. {
  187349. Array<int> results;
  187350. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187351. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187352. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187353. if (speeds[i] <= maxSpeed)
  187354. results.add (speeds[i]);
  187355. results.addIfNotAlreadyThere (maxSpeed);
  187356. return results;
  187357. }
  187358. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187359. {
  187360. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187361. return false;
  187362. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187363. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187364. }
  187365. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187366. {
  187367. long blocksFree = 0;
  187368. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187369. return blocksFree;
  187370. }
  187371. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187372. bool performFakeBurnForTesting, int writeSpeed)
  187373. {
  187374. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187375. pimpl->listener = listener;
  187376. pimpl->progress = 0;
  187377. pimpl->shouldCancel = false;
  187378. UINT_PTR cookie;
  187379. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187380. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187381. ejectDiscAfterwards);
  187382. String error;
  187383. if (hr != S_OK)
  187384. {
  187385. const char* e = "Couldn't open or write to the CD device";
  187386. if (hr == IMAPI_E_USERABORT)
  187387. e = "User cancelled the write operation";
  187388. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187389. e = "No Disk present";
  187390. error = e;
  187391. }
  187392. pimpl->discMaster->ProgressUnadvise (cookie);
  187393. pimpl->listener = 0;
  187394. return error;
  187395. }
  187396. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187397. {
  187398. if (audioSource == 0)
  187399. return false;
  187400. ScopedPointer<AudioSource> source (audioSource);
  187401. long bytesPerBlock;
  187402. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187403. const int samplesPerBlock = bytesPerBlock / 4;
  187404. bool ok = true;
  187405. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187406. HeapBlock <byte> buffer (bytesPerBlock);
  187407. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187408. int samplesDone = 0;
  187409. source->prepareToPlay (samplesPerBlock, 44100.0);
  187410. while (ok)
  187411. {
  187412. {
  187413. AudioSourceChannelInfo info;
  187414. info.buffer = &sourceBuffer;
  187415. info.numSamples = samplesPerBlock;
  187416. info.startSample = 0;
  187417. sourceBuffer.clear();
  187418. source->getNextAudioBlock (info);
  187419. }
  187420. zeromem (buffer, bytesPerBlock);
  187421. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187422. buffer, samplesPerBlock, 4);
  187423. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187424. buffer + 2, samplesPerBlock, 4);
  187425. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187426. if (FAILED (hr))
  187427. ok = false;
  187428. samplesDone += samplesPerBlock;
  187429. if (samplesDone >= numSamples)
  187430. break;
  187431. }
  187432. hr = pimpl->redbook->CloseAudioTrack();
  187433. return ok && hr == S_OK;
  187434. }
  187435. #endif
  187436. #endif
  187437. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187438. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187439. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187440. // compiled on its own).
  187441. #if JUCE_INCLUDED_FILE
  187442. using ::free;
  187443. namespace MidiConstants
  187444. {
  187445. static const int midiBufferSize = 1024 * 10;
  187446. static const int numInHeaders = 32;
  187447. static const int inBufferSize = 256;
  187448. }
  187449. class MidiInThread : public Thread
  187450. {
  187451. public:
  187452. MidiInThread (MidiInput* const input_,
  187453. MidiInputCallback* const callback_)
  187454. : Thread ("Juce Midi"),
  187455. hIn (0),
  187456. input (input_),
  187457. callback (callback_),
  187458. isStarted (false),
  187459. startTime (0),
  187460. pendingLength(0)
  187461. {
  187462. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187463. {
  187464. zeromem (&hdr[i], sizeof (MIDIHDR));
  187465. hdr[i].lpData = inData[i];
  187466. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187467. }
  187468. };
  187469. ~MidiInThread()
  187470. {
  187471. stop();
  187472. if (hIn != 0)
  187473. {
  187474. int count = 5;
  187475. while (--count >= 0)
  187476. {
  187477. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187478. break;
  187479. Sleep (20);
  187480. }
  187481. }
  187482. }
  187483. void handle (const uint32 message, const uint32 timeStamp) throw()
  187484. {
  187485. const int byte = message & 0xff;
  187486. if (byte < 0x80)
  187487. return;
  187488. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187489. const double time = timeStampToTime (timeStamp);
  187490. {
  187491. const ScopedLock sl (lock);
  187492. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187493. {
  187494. char* const p = pending + pendingLength;
  187495. *(double*) p = time;
  187496. *(uint32*) (p + 8) = numBytes;
  187497. *(uint32*) (p + 12) = message;
  187498. pendingLength += 12 + numBytes;
  187499. }
  187500. else
  187501. {
  187502. jassertfalse // midi buffer overflow! You might need to increase the size..
  187503. }
  187504. }
  187505. notify();
  187506. }
  187507. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187508. {
  187509. const int num = hdr->dwBytesRecorded;
  187510. if (num > 0)
  187511. {
  187512. const double time = timeStampToTime (timeStamp);
  187513. {
  187514. const ScopedLock sl (lock);
  187515. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187516. {
  187517. char* const p = pending + pendingLength;
  187518. *(double*) p = time;
  187519. *(uint32*) (p + 8) = num;
  187520. memcpy (p + 12, hdr->lpData, num);
  187521. pendingLength += 12 + num;
  187522. }
  187523. else
  187524. {
  187525. jassertfalse // midi buffer overflow! You might need to increase the size..
  187526. }
  187527. }
  187528. notify();
  187529. }
  187530. }
  187531. void writeBlock (const int i) throw()
  187532. {
  187533. hdr[i].dwBytesRecorded = 0;
  187534. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187535. jassert (res == MMSYSERR_NOERROR);
  187536. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187537. jassert (res == MMSYSERR_NOERROR);
  187538. }
  187539. void run()
  187540. {
  187541. MemoryBlock pendingCopy (64);
  187542. while (! threadShouldExit())
  187543. {
  187544. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187545. {
  187546. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187547. {
  187548. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187549. (void) res;
  187550. jassert (res == MMSYSERR_NOERROR);
  187551. writeBlock (i);
  187552. }
  187553. }
  187554. int len;
  187555. {
  187556. const ScopedLock sl (lock);
  187557. len = pendingLength;
  187558. if (len > 0)
  187559. {
  187560. pendingCopy.ensureSize (len);
  187561. pendingCopy.copyFrom (pending, 0, len);
  187562. pendingLength = 0;
  187563. }
  187564. }
  187565. //xxx needs to figure out if blocks are broken up or not
  187566. if (len == 0)
  187567. {
  187568. wait (500);
  187569. }
  187570. else
  187571. {
  187572. const char* p = (const char*) pendingCopy.getData();
  187573. while (len > 0)
  187574. {
  187575. const double time = *(const double*) p;
  187576. const int messageLen = *(const int*) (p + 8);
  187577. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187578. callback->handleIncomingMidiMessage (input, message);
  187579. p += 12 + messageLen;
  187580. len -= 12 + messageLen;
  187581. }
  187582. }
  187583. }
  187584. }
  187585. void start() throw()
  187586. {
  187587. jassert (hIn != 0);
  187588. if (hIn != 0 && ! isStarted)
  187589. {
  187590. stop();
  187591. activeMidiThreads.addIfNotAlreadyThere (this);
  187592. int i;
  187593. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187594. writeBlock (i);
  187595. startTime = Time::getMillisecondCounter();
  187596. MMRESULT res = midiInStart (hIn);
  187597. jassert (res == MMSYSERR_NOERROR);
  187598. if (res == MMSYSERR_NOERROR)
  187599. {
  187600. isStarted = true;
  187601. pendingLength = 0;
  187602. startThread (6);
  187603. }
  187604. }
  187605. }
  187606. void stop() throw()
  187607. {
  187608. if (isStarted)
  187609. {
  187610. stopThread (5000);
  187611. midiInReset (hIn);
  187612. midiInStop (hIn);
  187613. activeMidiThreads.removeValue (this);
  187614. { const ScopedLock sl (lock); }
  187615. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187616. {
  187617. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187618. {
  187619. int c = 10;
  187620. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187621. Sleep (20);
  187622. jassert (c >= 0);
  187623. }
  187624. }
  187625. isStarted = false;
  187626. pendingLength = 0;
  187627. }
  187628. }
  187629. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187630. {
  187631. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187632. if (thread != 0 && activeMidiThreads.contains (thread))
  187633. {
  187634. if (uMsg == MIM_DATA)
  187635. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187636. else if (uMsg == MIM_LONGDATA)
  187637. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187638. }
  187639. }
  187640. juce_UseDebuggingNewOperator
  187641. HMIDIIN hIn;
  187642. private:
  187643. static Array <void*, CriticalSection> activeMidiThreads;
  187644. MidiInput* input;
  187645. MidiInputCallback* callback;
  187646. bool isStarted;
  187647. uint32 startTime;
  187648. CriticalSection lock;
  187649. MIDIHDR hdr [MidiConstants::numInHeaders];
  187650. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187651. int pendingLength;
  187652. char pending [MidiConstants::midiBufferSize];
  187653. double timeStampToTime (uint32 timeStamp) throw()
  187654. {
  187655. timeStamp += startTime;
  187656. const uint32 now = Time::getMillisecondCounter();
  187657. if (timeStamp > now)
  187658. {
  187659. if (timeStamp > now + 2)
  187660. --startTime;
  187661. timeStamp = now;
  187662. }
  187663. return 0.001 * timeStamp;
  187664. }
  187665. MidiInThread (const MidiInThread&);
  187666. MidiInThread& operator= (const MidiInThread&);
  187667. };
  187668. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187669. const StringArray MidiInput::getDevices()
  187670. {
  187671. StringArray s;
  187672. const int num = midiInGetNumDevs();
  187673. for (int i = 0; i < num; ++i)
  187674. {
  187675. MIDIINCAPS mc;
  187676. zerostruct (mc);
  187677. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187678. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187679. }
  187680. return s;
  187681. }
  187682. int MidiInput::getDefaultDeviceIndex()
  187683. {
  187684. return 0;
  187685. }
  187686. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187687. {
  187688. if (callback == 0)
  187689. return 0;
  187690. UINT deviceId = MIDI_MAPPER;
  187691. int n = 0;
  187692. String name;
  187693. const int num = midiInGetNumDevs();
  187694. for (int i = 0; i < num; ++i)
  187695. {
  187696. MIDIINCAPS mc;
  187697. zerostruct (mc);
  187698. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187699. {
  187700. if (index == n)
  187701. {
  187702. deviceId = i;
  187703. name = String (mc.szPname, sizeof (mc.szPname));
  187704. break;
  187705. }
  187706. ++n;
  187707. }
  187708. }
  187709. ScopedPointer <MidiInput> in (new MidiInput (name));
  187710. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187711. HMIDIIN h;
  187712. HRESULT err = midiInOpen (&h, deviceId,
  187713. (DWORD_PTR) &MidiInThread::midiInCallback,
  187714. (DWORD_PTR) (MidiInThread*) thread,
  187715. CALLBACK_FUNCTION);
  187716. if (err == MMSYSERR_NOERROR)
  187717. {
  187718. thread->hIn = h;
  187719. in->internal = thread.release();
  187720. return in.release();
  187721. }
  187722. return 0;
  187723. }
  187724. MidiInput::MidiInput (const String& name_)
  187725. : name (name_),
  187726. internal (0)
  187727. {
  187728. }
  187729. MidiInput::~MidiInput()
  187730. {
  187731. delete static_cast <MidiInThread*> (internal);
  187732. }
  187733. void MidiInput::start()
  187734. {
  187735. static_cast <MidiInThread*> (internal)->start();
  187736. }
  187737. void MidiInput::stop()
  187738. {
  187739. static_cast <MidiInThread*> (internal)->stop();
  187740. }
  187741. struct MidiOutHandle
  187742. {
  187743. int refCount;
  187744. UINT deviceId;
  187745. HMIDIOUT handle;
  187746. static Array<MidiOutHandle*> activeHandles;
  187747. juce_UseDebuggingNewOperator
  187748. };
  187749. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187750. const StringArray MidiOutput::getDevices()
  187751. {
  187752. StringArray s;
  187753. const int num = midiOutGetNumDevs();
  187754. for (int i = 0; i < num; ++i)
  187755. {
  187756. MIDIOUTCAPS mc;
  187757. zerostruct (mc);
  187758. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187759. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187760. }
  187761. return s;
  187762. }
  187763. int MidiOutput::getDefaultDeviceIndex()
  187764. {
  187765. const int num = midiOutGetNumDevs();
  187766. int n = 0;
  187767. for (int i = 0; i < num; ++i)
  187768. {
  187769. MIDIOUTCAPS mc;
  187770. zerostruct (mc);
  187771. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187772. {
  187773. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187774. return n;
  187775. ++n;
  187776. }
  187777. }
  187778. return 0;
  187779. }
  187780. MidiOutput* MidiOutput::openDevice (int index)
  187781. {
  187782. UINT deviceId = MIDI_MAPPER;
  187783. const int num = midiOutGetNumDevs();
  187784. int i, n = 0;
  187785. for (i = 0; i < num; ++i)
  187786. {
  187787. MIDIOUTCAPS mc;
  187788. zerostruct (mc);
  187789. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187790. {
  187791. // use the microsoft sw synth as a default - best not to allow deviceId
  187792. // to be MIDI_MAPPER, or else device sharing breaks
  187793. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase ("microsoft"))
  187794. deviceId = i;
  187795. if (index == n)
  187796. {
  187797. deviceId = i;
  187798. break;
  187799. }
  187800. ++n;
  187801. }
  187802. }
  187803. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  187804. {
  187805. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  187806. if (han != 0 && han->deviceId == deviceId)
  187807. {
  187808. han->refCount++;
  187809. MidiOutput* const out = new MidiOutput();
  187810. out->internal = han;
  187811. return out;
  187812. }
  187813. }
  187814. for (i = 4; --i >= 0;)
  187815. {
  187816. HMIDIOUT h = 0;
  187817. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  187818. if (res == MMSYSERR_NOERROR)
  187819. {
  187820. MidiOutHandle* const han = new MidiOutHandle();
  187821. han->deviceId = deviceId;
  187822. han->refCount = 1;
  187823. han->handle = h;
  187824. MidiOutHandle::activeHandles.add (han);
  187825. MidiOutput* const out = new MidiOutput();
  187826. out->internal = han;
  187827. return out;
  187828. }
  187829. else if (res == MMSYSERR_ALLOCATED)
  187830. {
  187831. Sleep (100);
  187832. }
  187833. else
  187834. {
  187835. break;
  187836. }
  187837. }
  187838. return 0;
  187839. }
  187840. MidiOutput::~MidiOutput()
  187841. {
  187842. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  187843. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  187844. {
  187845. midiOutClose (h->handle);
  187846. MidiOutHandle::activeHandles.removeValue (h);
  187847. delete h;
  187848. }
  187849. }
  187850. void MidiOutput::reset()
  187851. {
  187852. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  187853. midiOutReset (h->handle);
  187854. }
  187855. bool MidiOutput::getVolume (float& leftVol,
  187856. float& rightVol)
  187857. {
  187858. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187859. DWORD n;
  187860. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  187861. {
  187862. const unsigned short* const nn = (const unsigned short*) &n;
  187863. rightVol = nn[0] / (float) 0xffff;
  187864. leftVol = nn[1] / (float) 0xffff;
  187865. return true;
  187866. }
  187867. else
  187868. {
  187869. rightVol = leftVol = 1.0f;
  187870. return false;
  187871. }
  187872. }
  187873. void MidiOutput::setVolume (float leftVol,
  187874. float rightVol)
  187875. {
  187876. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  187877. DWORD n;
  187878. unsigned short* const nn = (unsigned short*) &n;
  187879. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  187880. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  187881. midiOutSetVolume (handle->handle, n);
  187882. }
  187883. void MidiOutput::sendMessageNow (const MidiMessage& message)
  187884. {
  187885. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187886. if (message.getRawDataSize() > 3
  187887. || message.isSysEx())
  187888. {
  187889. MIDIHDR h;
  187890. zerostruct (h);
  187891. h.lpData = (char*) message.getRawData();
  187892. h.dwBufferLength = message.getRawDataSize();
  187893. h.dwBytesRecorded = message.getRawDataSize();
  187894. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  187895. {
  187896. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  187897. if (res == MMSYSERR_NOERROR)
  187898. {
  187899. while ((h.dwFlags & MHDR_DONE) == 0)
  187900. Sleep (1);
  187901. int count = 500; // 1 sec timeout
  187902. while (--count >= 0)
  187903. {
  187904. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  187905. if (res == MIDIERR_STILLPLAYING)
  187906. Sleep (2);
  187907. else
  187908. break;
  187909. }
  187910. }
  187911. }
  187912. }
  187913. else
  187914. {
  187915. midiOutShortMsg (handle->handle,
  187916. *(unsigned int*) message.getRawData());
  187917. }
  187918. }
  187919. #endif
  187920. /*** End of inlined file: juce_win32_Midi.cpp ***/
  187921. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  187922. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187923. // compiled on its own).
  187924. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  187925. #undef WINDOWS
  187926. // #define ASIO_DEBUGGING
  187927. #ifdef ASIO_DEBUGGING
  187928. #define log(a) { Logger::writeToLog (a); DBG (a) }
  187929. #else
  187930. #define log(a) {}
  187931. #endif
  187932. #ifdef ASIO_DEBUGGING
  187933. static void logError (const String& context, long error)
  187934. {
  187935. String err ("unknown error");
  187936. if (error == ASE_NotPresent)
  187937. err = "Not Present";
  187938. else if (error == ASE_HWMalfunction)
  187939. err = "Hardware Malfunction";
  187940. else if (error == ASE_InvalidParameter)
  187941. err = "Invalid Parameter";
  187942. else if (error == ASE_InvalidMode)
  187943. err = "Invalid Mode";
  187944. else if (error == ASE_SPNotAdvancing)
  187945. err = "Sample position not advancing";
  187946. else if (error == ASE_NoClock)
  187947. err = "No Clock";
  187948. else if (error == ASE_NoMemory)
  187949. err = "Out of memory";
  187950. log ("!!error: " + context + " - " + err);
  187951. }
  187952. #else
  187953. #define logError(a, b) {}
  187954. #endif
  187955. class ASIOAudioIODevice;
  187956. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  187957. static const int maxASIOChannels = 160;
  187958. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  187959. private Timer
  187960. {
  187961. public:
  187962. Component ourWindow;
  187963. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  187964. const String& optionalDllForDirectLoading_)
  187965. : AudioIODevice (name_, "ASIO"),
  187966. asioObject (0),
  187967. classId (classId_),
  187968. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  187969. currentBitDepth (16),
  187970. currentSampleRate (0),
  187971. isOpen_ (false),
  187972. isStarted (false),
  187973. postOutput (true),
  187974. insideControlPanelModalLoop (false),
  187975. shouldUsePreferredSize (false)
  187976. {
  187977. name = name_;
  187978. ourWindow.addToDesktop (0);
  187979. windowHandle = ourWindow.getWindowHandle();
  187980. jassert (currentASIODev [slotNumber] == 0);
  187981. currentASIODev [slotNumber] = this;
  187982. openDevice();
  187983. }
  187984. ~ASIOAudioIODevice()
  187985. {
  187986. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  187987. if (currentASIODev[i] == this)
  187988. currentASIODev[i] = 0;
  187989. close();
  187990. log ("ASIO - exiting");
  187991. removeCurrentDriver();
  187992. }
  187993. void updateSampleRates()
  187994. {
  187995. // find a list of sample rates..
  187996. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  187997. sampleRates.clear();
  187998. if (asioObject != 0)
  187999. {
  188000. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188001. {
  188002. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188003. if (err == 0)
  188004. {
  188005. sampleRates.add ((int) possibleSampleRates[index]);
  188006. log ("rate: " + String ((int) possibleSampleRates[index]));
  188007. }
  188008. else if (err != ASE_NoClock)
  188009. {
  188010. logError ("CanSampleRate", err);
  188011. }
  188012. }
  188013. if (sampleRates.size() == 0)
  188014. {
  188015. double cr = 0;
  188016. const long err = asioObject->getSampleRate (&cr);
  188017. log ("No sample rates supported - current rate: " + String ((int) cr));
  188018. if (err == 0)
  188019. sampleRates.add ((int) cr);
  188020. }
  188021. }
  188022. }
  188023. const StringArray getOutputChannelNames()
  188024. {
  188025. return outputChannelNames;
  188026. }
  188027. const StringArray getInputChannelNames()
  188028. {
  188029. return inputChannelNames;
  188030. }
  188031. int getNumSampleRates()
  188032. {
  188033. return sampleRates.size();
  188034. }
  188035. double getSampleRate (int index)
  188036. {
  188037. return sampleRates [index];
  188038. }
  188039. int getNumBufferSizesAvailable()
  188040. {
  188041. return bufferSizes.size();
  188042. }
  188043. int getBufferSizeSamples (int index)
  188044. {
  188045. return bufferSizes [index];
  188046. }
  188047. int getDefaultBufferSize()
  188048. {
  188049. return preferredSize;
  188050. }
  188051. const String open (const BigInteger& inputChannels,
  188052. const BigInteger& outputChannels,
  188053. double sr,
  188054. int bufferSizeSamples)
  188055. {
  188056. close();
  188057. currentCallback = 0;
  188058. if (bufferSizeSamples <= 0)
  188059. shouldUsePreferredSize = true;
  188060. if (asioObject == 0 || ! isASIOOpen)
  188061. {
  188062. log ("Warning: device not open");
  188063. const String err (openDevice());
  188064. if (asioObject == 0 || ! isASIOOpen)
  188065. return err;
  188066. }
  188067. isStarted = false;
  188068. bufferIndex = -1;
  188069. long err = 0;
  188070. long newPreferredSize = 0;
  188071. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188072. minSize = 0;
  188073. maxSize = 0;
  188074. newPreferredSize = 0;
  188075. granularity = 0;
  188076. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188077. {
  188078. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188079. shouldUsePreferredSize = true;
  188080. preferredSize = newPreferredSize;
  188081. }
  188082. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188083. // dynamic changes to the buffer size...
  188084. shouldUsePreferredSize = shouldUsePreferredSize
  188085. || getName().containsIgnoreCase ("Digidesign");
  188086. if (shouldUsePreferredSize)
  188087. {
  188088. log ("Using preferred size for buffer..");
  188089. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188090. {
  188091. bufferSizeSamples = preferredSize;
  188092. }
  188093. else
  188094. {
  188095. bufferSizeSamples = 1024;
  188096. logError ("GetBufferSize1", err);
  188097. }
  188098. shouldUsePreferredSize = false;
  188099. }
  188100. int sampleRate = roundDoubleToInt (sr);
  188101. currentSampleRate = sampleRate;
  188102. currentBlockSizeSamples = bufferSizeSamples;
  188103. currentChansOut.clear();
  188104. currentChansIn.clear();
  188105. zeromem (inBuffers, sizeof (inBuffers));
  188106. zeromem (outBuffers, sizeof (outBuffers));
  188107. updateSampleRates();
  188108. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188109. sampleRate = sampleRates[0];
  188110. jassert (sampleRate != 0);
  188111. if (sampleRate == 0)
  188112. sampleRate = 44100;
  188113. long numSources = 32;
  188114. ASIOClockSource clocks[32];
  188115. zeromem (clocks, sizeof (clocks));
  188116. asioObject->getClockSources (clocks, &numSources);
  188117. bool isSourceSet = false;
  188118. // careful not to remove this loop because it does more than just logging!
  188119. int i;
  188120. for (i = 0; i < numSources; ++i)
  188121. {
  188122. String s ("clock: ");
  188123. s += clocks[i].name;
  188124. if (clocks[i].isCurrentSource)
  188125. {
  188126. isSourceSet = true;
  188127. s << " (cur)";
  188128. }
  188129. log (s);
  188130. }
  188131. if (numSources > 1 && ! isSourceSet)
  188132. {
  188133. log ("setting clock source");
  188134. asioObject->setClockSource (clocks[0].index);
  188135. Thread::sleep (20);
  188136. }
  188137. else
  188138. {
  188139. if (numSources == 0)
  188140. {
  188141. log ("ASIO - no clock sources!");
  188142. }
  188143. }
  188144. double cr = 0;
  188145. err = asioObject->getSampleRate (&cr);
  188146. if (err == 0)
  188147. {
  188148. currentSampleRate = cr;
  188149. }
  188150. else
  188151. {
  188152. logError ("GetSampleRate", err);
  188153. currentSampleRate = 0;
  188154. }
  188155. error = String::empty;
  188156. needToReset = false;
  188157. isReSync = false;
  188158. err = 0;
  188159. bool buffersCreated = false;
  188160. if (currentSampleRate != sampleRate)
  188161. {
  188162. log ("ASIO samplerate: " + String (currentSampleRate) + " to " + String (sampleRate));
  188163. err = asioObject->setSampleRate (sampleRate);
  188164. if (err == ASE_NoClock && numSources > 0)
  188165. {
  188166. log ("trying to set a clock source..");
  188167. Thread::sleep (10);
  188168. err = asioObject->setClockSource (clocks[0].index);
  188169. if (err != 0)
  188170. {
  188171. logError ("SetClock", err);
  188172. }
  188173. Thread::sleep (10);
  188174. err = asioObject->setSampleRate (sampleRate);
  188175. }
  188176. }
  188177. if (err == 0)
  188178. {
  188179. currentSampleRate = sampleRate;
  188180. if (needToReset)
  188181. {
  188182. if (isReSync)
  188183. {
  188184. log ("Resync request");
  188185. }
  188186. log ("! Resetting ASIO after sample rate change");
  188187. removeCurrentDriver();
  188188. loadDriver();
  188189. const String error (initDriver());
  188190. if (error.isNotEmpty())
  188191. {
  188192. log ("ASIOInit: " + error);
  188193. }
  188194. needToReset = false;
  188195. isReSync = false;
  188196. }
  188197. numActiveInputChans = 0;
  188198. numActiveOutputChans = 0;
  188199. ASIOBufferInfo* info = bufferInfos;
  188200. int i;
  188201. for (i = 0; i < totalNumInputChans; ++i)
  188202. {
  188203. if (inputChannels[i])
  188204. {
  188205. currentChansIn.setBit (i);
  188206. info->isInput = 1;
  188207. info->channelNum = i;
  188208. info->buffers[0] = info->buffers[1] = 0;
  188209. ++info;
  188210. ++numActiveInputChans;
  188211. }
  188212. }
  188213. for (i = 0; i < totalNumOutputChans; ++i)
  188214. {
  188215. if (outputChannels[i])
  188216. {
  188217. currentChansOut.setBit (i);
  188218. info->isInput = 0;
  188219. info->channelNum = i;
  188220. info->buffers[0] = info->buffers[1] = 0;
  188221. ++info;
  188222. ++numActiveOutputChans;
  188223. }
  188224. }
  188225. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188226. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188227. if (currentASIODev[0] == this)
  188228. {
  188229. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188230. callbacks.asioMessage = &asioMessagesCallback0;
  188231. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188232. }
  188233. else if (currentASIODev[1] == this)
  188234. {
  188235. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188236. callbacks.asioMessage = &asioMessagesCallback1;
  188237. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188238. }
  188239. else if (currentASIODev[2] == this)
  188240. {
  188241. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188242. callbacks.asioMessage = &asioMessagesCallback2;
  188243. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188244. }
  188245. else
  188246. {
  188247. jassertfalse
  188248. }
  188249. log ("disposing buffers");
  188250. err = asioObject->disposeBuffers();
  188251. log ("creating buffers: " + String (totalBuffers) + ", " + String (currentBlockSizeSamples));
  188252. err = asioObject->createBuffers (bufferInfos,
  188253. totalBuffers,
  188254. currentBlockSizeSamples,
  188255. &callbacks);
  188256. if (err != 0)
  188257. {
  188258. currentBlockSizeSamples = preferredSize;
  188259. logError ("create buffers 2", err);
  188260. asioObject->disposeBuffers();
  188261. err = asioObject->createBuffers (bufferInfos,
  188262. totalBuffers,
  188263. currentBlockSizeSamples,
  188264. &callbacks);
  188265. }
  188266. if (err == 0)
  188267. {
  188268. buffersCreated = true;
  188269. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188270. int n = 0;
  188271. Array <int> types;
  188272. currentBitDepth = 16;
  188273. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188274. {
  188275. if (inputChannels[i])
  188276. {
  188277. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188278. ASIOChannelInfo channelInfo;
  188279. zerostruct (channelInfo);
  188280. channelInfo.channel = i;
  188281. channelInfo.isInput = 1;
  188282. asioObject->getChannelInfo (&channelInfo);
  188283. types.addIfNotAlreadyThere (channelInfo.type);
  188284. typeToFormatParameters (channelInfo.type,
  188285. inputChannelBitDepths[n],
  188286. inputChannelBytesPerSample[n],
  188287. inputChannelIsFloat[n],
  188288. inputChannelLittleEndian[n]);
  188289. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188290. ++n;
  188291. }
  188292. }
  188293. jassert (numActiveInputChans == n);
  188294. n = 0;
  188295. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188296. {
  188297. if (outputChannels[i])
  188298. {
  188299. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188300. ASIOChannelInfo channelInfo;
  188301. zerostruct (channelInfo);
  188302. channelInfo.channel = i;
  188303. channelInfo.isInput = 0;
  188304. asioObject->getChannelInfo (&channelInfo);
  188305. types.addIfNotAlreadyThere (channelInfo.type);
  188306. typeToFormatParameters (channelInfo.type,
  188307. outputChannelBitDepths[n],
  188308. outputChannelBytesPerSample[n],
  188309. outputChannelIsFloat[n],
  188310. outputChannelLittleEndian[n]);
  188311. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188312. ++n;
  188313. }
  188314. }
  188315. jassert (numActiveOutputChans == n);
  188316. for (i = types.size(); --i >= 0;)
  188317. {
  188318. log ("channel format: " + String (types[i]));
  188319. }
  188320. jassert (n <= totalBuffers);
  188321. for (i = 0; i < numActiveOutputChans; ++i)
  188322. {
  188323. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188324. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188325. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188326. {
  188327. log ("!! Null buffers");
  188328. }
  188329. else
  188330. {
  188331. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188332. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188333. }
  188334. }
  188335. inputLatency = outputLatency = 0;
  188336. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188337. {
  188338. log ("ASIO - no latencies");
  188339. }
  188340. else
  188341. {
  188342. log ("ASIO latencies: " + String ((int) outputLatency) + ", " + String ((int) inputLatency));
  188343. }
  188344. isOpen_ = true;
  188345. log ("starting ASIO");
  188346. calledback = false;
  188347. err = asioObject->start();
  188348. if (err != 0)
  188349. {
  188350. isOpen_ = false;
  188351. log ("ASIO - stop on failure");
  188352. Thread::sleep (10);
  188353. asioObject->stop();
  188354. error = "Can't start device";
  188355. Thread::sleep (10);
  188356. }
  188357. else
  188358. {
  188359. int count = 300;
  188360. while (--count > 0 && ! calledback)
  188361. Thread::sleep (10);
  188362. isStarted = true;
  188363. if (! calledback)
  188364. {
  188365. error = "Device didn't start correctly";
  188366. log ("ASIO didn't callback - stopping..");
  188367. asioObject->stop();
  188368. }
  188369. }
  188370. }
  188371. else
  188372. {
  188373. error = "Can't create i/o buffers";
  188374. }
  188375. }
  188376. else
  188377. {
  188378. error = "Can't set sample rate: ";
  188379. error << sampleRate;
  188380. }
  188381. if (error.isNotEmpty())
  188382. {
  188383. logError (error, err);
  188384. if (asioObject != 0 && buffersCreated)
  188385. asioObject->disposeBuffers();
  188386. Thread::sleep (20);
  188387. isStarted = false;
  188388. isOpen_ = false;
  188389. close();
  188390. }
  188391. needToReset = false;
  188392. isReSync = false;
  188393. return error;
  188394. }
  188395. void close()
  188396. {
  188397. error = String::empty;
  188398. stopTimer();
  188399. stop();
  188400. if (isASIOOpen && isOpen_)
  188401. {
  188402. const ScopedLock sl (callbackLock);
  188403. isOpen_ = false;
  188404. isStarted = false;
  188405. needToReset = false;
  188406. isReSync = false;
  188407. log ("ASIO - stopping");
  188408. if (asioObject != 0)
  188409. {
  188410. Thread::sleep (20);
  188411. asioObject->stop();
  188412. Thread::sleep (10);
  188413. asioObject->disposeBuffers();
  188414. }
  188415. Thread::sleep (10);
  188416. }
  188417. }
  188418. bool isOpen()
  188419. {
  188420. return isOpen_ || insideControlPanelModalLoop;
  188421. }
  188422. int getCurrentBufferSizeSamples()
  188423. {
  188424. return currentBlockSizeSamples;
  188425. }
  188426. double getCurrentSampleRate()
  188427. {
  188428. return currentSampleRate;
  188429. }
  188430. const BigInteger getActiveOutputChannels() const
  188431. {
  188432. return currentChansOut;
  188433. }
  188434. const BigInteger getActiveInputChannels() const
  188435. {
  188436. return currentChansIn;
  188437. }
  188438. int getCurrentBitDepth()
  188439. {
  188440. return currentBitDepth;
  188441. }
  188442. int getOutputLatencyInSamples()
  188443. {
  188444. return outputLatency + currentBlockSizeSamples / 4;
  188445. }
  188446. int getInputLatencyInSamples()
  188447. {
  188448. return inputLatency + currentBlockSizeSamples / 4;
  188449. }
  188450. void start (AudioIODeviceCallback* callback)
  188451. {
  188452. if (callback != 0)
  188453. {
  188454. callback->audioDeviceAboutToStart (this);
  188455. const ScopedLock sl (callbackLock);
  188456. currentCallback = callback;
  188457. }
  188458. }
  188459. void stop()
  188460. {
  188461. AudioIODeviceCallback* const lastCallback = currentCallback;
  188462. {
  188463. const ScopedLock sl (callbackLock);
  188464. currentCallback = 0;
  188465. }
  188466. if (lastCallback != 0)
  188467. lastCallback->audioDeviceStopped();
  188468. }
  188469. bool isPlaying()
  188470. {
  188471. return isASIOOpen && (currentCallback != 0);
  188472. }
  188473. const String getLastError()
  188474. {
  188475. return error;
  188476. }
  188477. bool hasControlPanel() const
  188478. {
  188479. return true;
  188480. }
  188481. bool showControlPanel()
  188482. {
  188483. log ("ASIO - showing control panel");
  188484. Component modalWindow (String::empty);
  188485. modalWindow.setOpaque (true);
  188486. modalWindow.addToDesktop (0);
  188487. modalWindow.enterModalState();
  188488. bool done = false;
  188489. JUCE_TRY
  188490. {
  188491. // are there are devices that need to be closed before showing their control panel?
  188492. // close();
  188493. insideControlPanelModalLoop = true;
  188494. const uint32 started = Time::getMillisecondCounter();
  188495. if (asioObject != 0)
  188496. {
  188497. asioObject->controlPanel();
  188498. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188499. log ("spent: " + String (spent));
  188500. if (spent > 300)
  188501. {
  188502. shouldUsePreferredSize = true;
  188503. done = true;
  188504. }
  188505. }
  188506. }
  188507. JUCE_CATCH_ALL
  188508. insideControlPanelModalLoop = false;
  188509. return done;
  188510. }
  188511. void resetRequest() throw()
  188512. {
  188513. needToReset = true;
  188514. }
  188515. void resyncRequest() throw()
  188516. {
  188517. needToReset = true;
  188518. isReSync = true;
  188519. }
  188520. void timerCallback()
  188521. {
  188522. if (! insideControlPanelModalLoop)
  188523. {
  188524. stopTimer();
  188525. // used to cause a reset
  188526. log ("! ASIO restart request!");
  188527. if (isOpen_)
  188528. {
  188529. AudioIODeviceCallback* const oldCallback = currentCallback;
  188530. close();
  188531. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188532. currentSampleRate, currentBlockSizeSamples);
  188533. if (oldCallback != 0)
  188534. start (oldCallback);
  188535. }
  188536. }
  188537. else
  188538. {
  188539. startTimer (100);
  188540. }
  188541. }
  188542. juce_UseDebuggingNewOperator
  188543. private:
  188544. IASIO* volatile asioObject;
  188545. ASIOCallbacks callbacks;
  188546. void* windowHandle;
  188547. CLSID classId;
  188548. const String optionalDllForDirectLoading;
  188549. String error;
  188550. long totalNumInputChans, totalNumOutputChans;
  188551. StringArray inputChannelNames, outputChannelNames;
  188552. Array<int> sampleRates, bufferSizes;
  188553. long inputLatency, outputLatency;
  188554. long minSize, maxSize, preferredSize, granularity;
  188555. int volatile currentBlockSizeSamples;
  188556. int volatile currentBitDepth;
  188557. double volatile currentSampleRate;
  188558. BigInteger currentChansOut, currentChansIn;
  188559. AudioIODeviceCallback* volatile currentCallback;
  188560. CriticalSection callbackLock;
  188561. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188562. float* inBuffers [maxASIOChannels];
  188563. float* outBuffers [maxASIOChannels];
  188564. int inputChannelBitDepths [maxASIOChannels];
  188565. int outputChannelBitDepths [maxASIOChannels];
  188566. int inputChannelBytesPerSample [maxASIOChannels];
  188567. int outputChannelBytesPerSample [maxASIOChannels];
  188568. bool inputChannelIsFloat [maxASIOChannels];
  188569. bool outputChannelIsFloat [maxASIOChannels];
  188570. bool inputChannelLittleEndian [maxASIOChannels];
  188571. bool outputChannelLittleEndian [maxASIOChannels];
  188572. WaitableEvent event1;
  188573. HeapBlock <float> tempBuffer;
  188574. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188575. bool isOpen_, isStarted;
  188576. bool volatile isASIOOpen;
  188577. bool volatile calledback;
  188578. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188579. bool volatile insideControlPanelModalLoop;
  188580. bool volatile shouldUsePreferredSize;
  188581. void removeCurrentDriver()
  188582. {
  188583. if (asioObject != 0)
  188584. {
  188585. asioObject->Release();
  188586. asioObject = 0;
  188587. }
  188588. }
  188589. bool loadDriver()
  188590. {
  188591. removeCurrentDriver();
  188592. JUCE_TRY
  188593. {
  188594. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188595. classId, (void**) &asioObject) == S_OK)
  188596. {
  188597. return true;
  188598. }
  188599. // If a class isn't registered but we have a path for it, we can fallback to
  188600. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188601. if (optionalDllForDirectLoading.isNotEmpty())
  188602. {
  188603. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188604. if (h != 0)
  188605. {
  188606. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188607. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188608. if (dllGetClassObject != 0)
  188609. {
  188610. IClassFactory* classFactory = 0;
  188611. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188612. if (classFactory != 0)
  188613. {
  188614. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188615. classFactory->Release();
  188616. }
  188617. return asioObject != 0;
  188618. }
  188619. }
  188620. }
  188621. }
  188622. JUCE_CATCH_ALL
  188623. asioObject = 0;
  188624. return false;
  188625. }
  188626. const String initDriver()
  188627. {
  188628. if (asioObject != 0)
  188629. {
  188630. char buffer [256];
  188631. zeromem (buffer, sizeof (buffer));
  188632. if (! asioObject->init (windowHandle))
  188633. {
  188634. asioObject->getErrorMessage (buffer);
  188635. return String (buffer, sizeof (buffer) - 1);
  188636. }
  188637. // just in case any daft drivers expect this to be called..
  188638. asioObject->getDriverName (buffer);
  188639. return String::empty;
  188640. }
  188641. return "No Driver";
  188642. }
  188643. const String openDevice()
  188644. {
  188645. // use this in case the driver starts opening dialog boxes..
  188646. Component modalWindow (String::empty);
  188647. modalWindow.setOpaque (true);
  188648. modalWindow.addToDesktop (0);
  188649. modalWindow.enterModalState();
  188650. // open the device and get its info..
  188651. log ("opening ASIO device: " + getName());
  188652. needToReset = false;
  188653. isReSync = false;
  188654. outputChannelNames.clear();
  188655. inputChannelNames.clear();
  188656. bufferSizes.clear();
  188657. sampleRates.clear();
  188658. isASIOOpen = false;
  188659. isOpen_ = false;
  188660. totalNumInputChans = 0;
  188661. totalNumOutputChans = 0;
  188662. numActiveInputChans = 0;
  188663. numActiveOutputChans = 0;
  188664. currentCallback = 0;
  188665. error = String::empty;
  188666. if (getName().isEmpty())
  188667. return error;
  188668. long err = 0;
  188669. if (loadDriver())
  188670. {
  188671. if ((error = initDriver()).isEmpty())
  188672. {
  188673. numActiveInputChans = 0;
  188674. numActiveOutputChans = 0;
  188675. totalNumInputChans = 0;
  188676. totalNumOutputChans = 0;
  188677. if (asioObject != 0
  188678. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188679. {
  188680. log (String ((int) totalNumInputChans) + " in, " + String ((int) totalNumOutputChans) + " out");
  188681. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188682. {
  188683. // find a list of buffer sizes..
  188684. log (String ((int) minSize) + " " + String ((int) maxSize) + " " + String ((int) preferredSize) + " " + String ((int) granularity));
  188685. if (granularity >= 0)
  188686. {
  188687. granularity = jmax (1, (int) granularity);
  188688. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188689. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188690. }
  188691. else if (granularity < 0)
  188692. {
  188693. for (int i = 0; i < 18; ++i)
  188694. {
  188695. const int s = (1 << i);
  188696. if (s >= minSize && s <= maxSize)
  188697. bufferSizes.add (s);
  188698. }
  188699. }
  188700. if (! bufferSizes.contains (preferredSize))
  188701. bufferSizes.insert (0, preferredSize);
  188702. double currentRate = 0;
  188703. asioObject->getSampleRate (&currentRate);
  188704. if (currentRate <= 0.0 || currentRate > 192001.0)
  188705. {
  188706. log ("setting sample rate");
  188707. err = asioObject->setSampleRate (44100.0);
  188708. if (err != 0)
  188709. {
  188710. logError ("setting sample rate", err);
  188711. }
  188712. asioObject->getSampleRate (&currentRate);
  188713. }
  188714. currentSampleRate = currentRate;
  188715. postOutput = (asioObject->outputReady() == 0);
  188716. if (postOutput)
  188717. {
  188718. log ("ASIO outputReady = ok");
  188719. }
  188720. updateSampleRates();
  188721. // ..because cubase does it at this point
  188722. inputLatency = outputLatency = 0;
  188723. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188724. {
  188725. log ("ASIO - no latencies");
  188726. }
  188727. log ("latencies: " + String ((int) inputLatency) + ", " + String ((int) outputLatency));
  188728. // create some dummy buffers now.. because cubase does..
  188729. numActiveInputChans = 0;
  188730. numActiveOutputChans = 0;
  188731. ASIOBufferInfo* info = bufferInfos;
  188732. int i, numChans = 0;
  188733. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188734. {
  188735. info->isInput = 1;
  188736. info->channelNum = i;
  188737. info->buffers[0] = info->buffers[1] = 0;
  188738. ++info;
  188739. ++numChans;
  188740. }
  188741. const int outputBufferIndex = numChans;
  188742. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188743. {
  188744. info->isInput = 0;
  188745. info->channelNum = i;
  188746. info->buffers[0] = info->buffers[1] = 0;
  188747. ++info;
  188748. ++numChans;
  188749. }
  188750. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188751. if (currentASIODev[0] == this)
  188752. {
  188753. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188754. callbacks.asioMessage = &asioMessagesCallback0;
  188755. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188756. }
  188757. else if (currentASIODev[1] == this)
  188758. {
  188759. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188760. callbacks.asioMessage = &asioMessagesCallback1;
  188761. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188762. }
  188763. else if (currentASIODev[2] == this)
  188764. {
  188765. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188766. callbacks.asioMessage = &asioMessagesCallback2;
  188767. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188768. }
  188769. else
  188770. {
  188771. jassertfalse
  188772. }
  188773. log ("creating buffers (dummy): " + String (numChans) + ", " + String ((int) preferredSize));
  188774. if (preferredSize > 0)
  188775. {
  188776. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  188777. if (err != 0)
  188778. {
  188779. logError ("dummy buffers", err);
  188780. }
  188781. }
  188782. long newInps = 0, newOuts = 0;
  188783. asioObject->getChannels (&newInps, &newOuts);
  188784. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  188785. {
  188786. totalNumInputChans = newInps;
  188787. totalNumOutputChans = newOuts;
  188788. log (String ((int) totalNumInputChans) + " in; " + String ((int) totalNumOutputChans) + " out");
  188789. }
  188790. updateSampleRates();
  188791. ASIOChannelInfo channelInfo;
  188792. channelInfo.type = 0;
  188793. for (i = 0; i < totalNumInputChans; ++i)
  188794. {
  188795. zerostruct (channelInfo);
  188796. channelInfo.channel = i;
  188797. channelInfo.isInput = 1;
  188798. asioObject->getChannelInfo (&channelInfo);
  188799. inputChannelNames.add (String (channelInfo.name));
  188800. }
  188801. for (i = 0; i < totalNumOutputChans; ++i)
  188802. {
  188803. zerostruct (channelInfo);
  188804. channelInfo.channel = i;
  188805. channelInfo.isInput = 0;
  188806. asioObject->getChannelInfo (&channelInfo);
  188807. outputChannelNames.add (String (channelInfo.name));
  188808. typeToFormatParameters (channelInfo.type,
  188809. outputChannelBitDepths[i],
  188810. outputChannelBytesPerSample[i],
  188811. outputChannelIsFloat[i],
  188812. outputChannelLittleEndian[i]);
  188813. if (i < 2)
  188814. {
  188815. // clear the channels that are used with the dummy stuff
  188816. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  188817. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  188818. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  188819. }
  188820. }
  188821. outputChannelNames.trim();
  188822. inputChannelNames.trim();
  188823. outputChannelNames.appendNumbersToDuplicates (false, true);
  188824. inputChannelNames.appendNumbersToDuplicates (false, true);
  188825. // start and stop because cubase does it..
  188826. asioObject->getLatencies (&inputLatency, &outputLatency);
  188827. if ((err = asioObject->start()) != 0)
  188828. {
  188829. // ignore an error here, as it might start later after setting other stuff up
  188830. logError ("ASIO start", err);
  188831. }
  188832. Thread::sleep (100);
  188833. asioObject->stop();
  188834. }
  188835. else
  188836. {
  188837. error = "Can't detect buffer sizes";
  188838. }
  188839. }
  188840. else
  188841. {
  188842. error = "Can't detect asio channels";
  188843. }
  188844. }
  188845. }
  188846. else
  188847. {
  188848. error = "No such device";
  188849. }
  188850. if (error.isNotEmpty())
  188851. {
  188852. logError (error, err);
  188853. if (asioObject != 0)
  188854. asioObject->disposeBuffers();
  188855. removeCurrentDriver();
  188856. isASIOOpen = false;
  188857. }
  188858. else
  188859. {
  188860. isASIOOpen = true;
  188861. log ("ASIO device open");
  188862. }
  188863. isOpen_ = false;
  188864. needToReset = false;
  188865. isReSync = false;
  188866. return error;
  188867. }
  188868. void callback (const long index) throw()
  188869. {
  188870. if (isStarted)
  188871. {
  188872. bufferIndex = index;
  188873. processBuffer();
  188874. }
  188875. else
  188876. {
  188877. if (postOutput && (asioObject != 0))
  188878. asioObject->outputReady();
  188879. }
  188880. calledback = true;
  188881. }
  188882. void processBuffer() throw()
  188883. {
  188884. const ASIOBufferInfo* const infos = bufferInfos;
  188885. const int bi = bufferIndex;
  188886. const ScopedLock sl (callbackLock);
  188887. if (needToReset)
  188888. {
  188889. needToReset = false;
  188890. if (isReSync)
  188891. {
  188892. log ("! ASIO resync");
  188893. isReSync = false;
  188894. }
  188895. else
  188896. {
  188897. startTimer (20);
  188898. }
  188899. }
  188900. if (bi >= 0)
  188901. {
  188902. const int samps = currentBlockSizeSamples;
  188903. if (currentCallback != 0)
  188904. {
  188905. int i;
  188906. for (i = 0; i < numActiveInputChans; ++i)
  188907. {
  188908. float* const dst = inBuffers[i];
  188909. jassert (dst != 0);
  188910. const char* const src = (const char*) (infos[i].buffers[bi]);
  188911. if (inputChannelIsFloat[i])
  188912. {
  188913. memcpy (dst, src, samps * sizeof (float));
  188914. }
  188915. else
  188916. {
  188917. jassert (dst == tempBuffer + (samps * i));
  188918. switch (inputChannelBitDepths[i])
  188919. {
  188920. case 16:
  188921. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  188922. samps, inputChannelLittleEndian[i]);
  188923. break;
  188924. case 24:
  188925. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  188926. samps, inputChannelLittleEndian[i]);
  188927. break;
  188928. case 32:
  188929. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  188930. samps, inputChannelLittleEndian[i]);
  188931. break;
  188932. case 64:
  188933. jassertfalse
  188934. break;
  188935. }
  188936. }
  188937. }
  188938. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  188939. numActiveInputChans,
  188940. outBuffers,
  188941. numActiveOutputChans,
  188942. samps);
  188943. for (i = 0; i < numActiveOutputChans; ++i)
  188944. {
  188945. float* const src = outBuffers[i];
  188946. jassert (src != 0);
  188947. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  188948. if (outputChannelIsFloat[i])
  188949. {
  188950. memcpy (dst, src, samps * sizeof (float));
  188951. }
  188952. else
  188953. {
  188954. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  188955. switch (outputChannelBitDepths[i])
  188956. {
  188957. case 16:
  188958. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  188959. samps, outputChannelLittleEndian[i]);
  188960. break;
  188961. case 24:
  188962. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  188963. samps, outputChannelLittleEndian[i]);
  188964. break;
  188965. case 32:
  188966. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  188967. samps, outputChannelLittleEndian[i]);
  188968. break;
  188969. case 64:
  188970. jassertfalse
  188971. break;
  188972. }
  188973. }
  188974. }
  188975. }
  188976. else
  188977. {
  188978. for (int i = 0; i < numActiveOutputChans; ++i)
  188979. {
  188980. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  188981. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  188982. }
  188983. }
  188984. }
  188985. if (postOutput)
  188986. asioObject->outputReady();
  188987. }
  188988. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  188989. {
  188990. if (currentASIODev[0] != 0)
  188991. currentASIODev[0]->callback (index);
  188992. return 0;
  188993. }
  188994. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  188995. {
  188996. if (currentASIODev[1] != 0)
  188997. currentASIODev[1]->callback (index);
  188998. return 0;
  188999. }
  189000. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189001. {
  189002. if (currentASIODev[2] != 0)
  189003. currentASIODev[2]->callback (index);
  189004. return 0;
  189005. }
  189006. static void bufferSwitchCallback0 (long index, long) throw()
  189007. {
  189008. if (currentASIODev[0] != 0)
  189009. currentASIODev[0]->callback (index);
  189010. }
  189011. static void bufferSwitchCallback1 (long index, long) throw()
  189012. {
  189013. if (currentASIODev[1] != 0)
  189014. currentASIODev[1]->callback (index);
  189015. }
  189016. static void bufferSwitchCallback2 (long index, long) throw()
  189017. {
  189018. if (currentASIODev[2] != 0)
  189019. currentASIODev[2]->callback (index);
  189020. }
  189021. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189022. {
  189023. return asioMessagesCallback (selector, value, 0);
  189024. }
  189025. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189026. {
  189027. return asioMessagesCallback (selector, value, 1);
  189028. }
  189029. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189030. {
  189031. return asioMessagesCallback (selector, value, 2);
  189032. }
  189033. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189034. {
  189035. switch (selector)
  189036. {
  189037. case kAsioSelectorSupported:
  189038. if (value == kAsioResetRequest
  189039. || value == kAsioEngineVersion
  189040. || value == kAsioResyncRequest
  189041. || value == kAsioLatenciesChanged
  189042. || value == kAsioSupportsInputMonitor)
  189043. return 1;
  189044. break;
  189045. case kAsioBufferSizeChange:
  189046. break;
  189047. case kAsioResetRequest:
  189048. if (currentASIODev[deviceIndex] != 0)
  189049. currentASIODev[deviceIndex]->resetRequest();
  189050. return 1;
  189051. case kAsioResyncRequest:
  189052. if (currentASIODev[deviceIndex] != 0)
  189053. currentASIODev[deviceIndex]->resyncRequest();
  189054. return 1;
  189055. case kAsioLatenciesChanged:
  189056. return 1;
  189057. case kAsioEngineVersion:
  189058. return 2;
  189059. case kAsioSupportsTimeInfo:
  189060. case kAsioSupportsTimeCode:
  189061. return 0;
  189062. }
  189063. return 0;
  189064. }
  189065. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189066. {
  189067. }
  189068. static void convertInt16ToFloat (const char* src,
  189069. float* dest,
  189070. const int srcStrideBytes,
  189071. int numSamples,
  189072. const bool littleEndian) throw()
  189073. {
  189074. const double g = 1.0 / 32768.0;
  189075. if (littleEndian)
  189076. {
  189077. while (--numSamples >= 0)
  189078. {
  189079. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189080. src += srcStrideBytes;
  189081. }
  189082. }
  189083. else
  189084. {
  189085. while (--numSamples >= 0)
  189086. {
  189087. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189088. src += srcStrideBytes;
  189089. }
  189090. }
  189091. }
  189092. static void convertFloatToInt16 (const float* src,
  189093. char* dest,
  189094. const int dstStrideBytes,
  189095. int numSamples,
  189096. const bool littleEndian) throw()
  189097. {
  189098. const double maxVal = (double) 0x7fff;
  189099. if (littleEndian)
  189100. {
  189101. while (--numSamples >= 0)
  189102. {
  189103. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189104. dest += dstStrideBytes;
  189105. }
  189106. }
  189107. else
  189108. {
  189109. while (--numSamples >= 0)
  189110. {
  189111. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189112. dest += dstStrideBytes;
  189113. }
  189114. }
  189115. }
  189116. static void convertInt24ToFloat (const char* src,
  189117. float* dest,
  189118. const int srcStrideBytes,
  189119. int numSamples,
  189120. const bool littleEndian) throw()
  189121. {
  189122. const double g = 1.0 / 0x7fffff;
  189123. if (littleEndian)
  189124. {
  189125. while (--numSamples >= 0)
  189126. {
  189127. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189128. src += srcStrideBytes;
  189129. }
  189130. }
  189131. else
  189132. {
  189133. while (--numSamples >= 0)
  189134. {
  189135. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189136. src += srcStrideBytes;
  189137. }
  189138. }
  189139. }
  189140. static void convertFloatToInt24 (const float* src,
  189141. char* dest,
  189142. const int dstStrideBytes,
  189143. int numSamples,
  189144. const bool littleEndian) throw()
  189145. {
  189146. const double maxVal = (double) 0x7fffff;
  189147. if (littleEndian)
  189148. {
  189149. while (--numSamples >= 0)
  189150. {
  189151. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189152. dest += dstStrideBytes;
  189153. }
  189154. }
  189155. else
  189156. {
  189157. while (--numSamples >= 0)
  189158. {
  189159. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189160. dest += dstStrideBytes;
  189161. }
  189162. }
  189163. }
  189164. static void convertInt32ToFloat (const char* src,
  189165. float* dest,
  189166. const int srcStrideBytes,
  189167. int numSamples,
  189168. const bool littleEndian) throw()
  189169. {
  189170. const double g = 1.0 / 0x7fffffff;
  189171. if (littleEndian)
  189172. {
  189173. while (--numSamples >= 0)
  189174. {
  189175. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189176. src += srcStrideBytes;
  189177. }
  189178. }
  189179. else
  189180. {
  189181. while (--numSamples >= 0)
  189182. {
  189183. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189184. src += srcStrideBytes;
  189185. }
  189186. }
  189187. }
  189188. static void convertFloatToInt32 (const float* src,
  189189. char* dest,
  189190. const int dstStrideBytes,
  189191. int numSamples,
  189192. const bool littleEndian) throw()
  189193. {
  189194. const double maxVal = (double) 0x7fffffff;
  189195. if (littleEndian)
  189196. {
  189197. while (--numSamples >= 0)
  189198. {
  189199. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189200. dest += dstStrideBytes;
  189201. }
  189202. }
  189203. else
  189204. {
  189205. while (--numSamples >= 0)
  189206. {
  189207. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189208. dest += dstStrideBytes;
  189209. }
  189210. }
  189211. }
  189212. static void typeToFormatParameters (const long type,
  189213. int& bitDepth,
  189214. int& byteStride,
  189215. bool& formatIsFloat,
  189216. bool& littleEndian) throw()
  189217. {
  189218. bitDepth = 0;
  189219. littleEndian = false;
  189220. formatIsFloat = false;
  189221. switch (type)
  189222. {
  189223. case ASIOSTInt16MSB:
  189224. case ASIOSTInt16LSB:
  189225. case ASIOSTInt32MSB16:
  189226. case ASIOSTInt32LSB16:
  189227. bitDepth = 16; break;
  189228. case ASIOSTFloat32MSB:
  189229. case ASIOSTFloat32LSB:
  189230. formatIsFloat = true;
  189231. bitDepth = 32; break;
  189232. case ASIOSTInt32MSB:
  189233. case ASIOSTInt32LSB:
  189234. bitDepth = 32; break;
  189235. case ASIOSTInt24MSB:
  189236. case ASIOSTInt24LSB:
  189237. case ASIOSTInt32MSB24:
  189238. case ASIOSTInt32LSB24:
  189239. case ASIOSTInt32MSB18:
  189240. case ASIOSTInt32MSB20:
  189241. case ASIOSTInt32LSB18:
  189242. case ASIOSTInt32LSB20:
  189243. bitDepth = 24; break;
  189244. case ASIOSTFloat64MSB:
  189245. case ASIOSTFloat64LSB:
  189246. default:
  189247. bitDepth = 64;
  189248. break;
  189249. }
  189250. switch (type)
  189251. {
  189252. case ASIOSTInt16MSB:
  189253. case ASIOSTInt32MSB16:
  189254. case ASIOSTFloat32MSB:
  189255. case ASIOSTFloat64MSB:
  189256. case ASIOSTInt32MSB:
  189257. case ASIOSTInt32MSB18:
  189258. case ASIOSTInt32MSB20:
  189259. case ASIOSTInt32MSB24:
  189260. case ASIOSTInt24MSB:
  189261. littleEndian = false; break;
  189262. case ASIOSTInt16LSB:
  189263. case ASIOSTInt32LSB16:
  189264. case ASIOSTFloat32LSB:
  189265. case ASIOSTFloat64LSB:
  189266. case ASIOSTInt32LSB:
  189267. case ASIOSTInt32LSB18:
  189268. case ASIOSTInt32LSB20:
  189269. case ASIOSTInt32LSB24:
  189270. case ASIOSTInt24LSB:
  189271. littleEndian = true; break;
  189272. default:
  189273. break;
  189274. }
  189275. switch (type)
  189276. {
  189277. case ASIOSTInt16LSB:
  189278. case ASIOSTInt16MSB:
  189279. byteStride = 2; break;
  189280. case ASIOSTInt24LSB:
  189281. case ASIOSTInt24MSB:
  189282. byteStride = 3; break;
  189283. case ASIOSTInt32MSB16:
  189284. case ASIOSTInt32LSB16:
  189285. case ASIOSTInt32MSB:
  189286. case ASIOSTInt32MSB18:
  189287. case ASIOSTInt32MSB20:
  189288. case ASIOSTInt32MSB24:
  189289. case ASIOSTInt32LSB:
  189290. case ASIOSTInt32LSB18:
  189291. case ASIOSTInt32LSB20:
  189292. case ASIOSTInt32LSB24:
  189293. case ASIOSTFloat32LSB:
  189294. case ASIOSTFloat32MSB:
  189295. byteStride = 4; break;
  189296. case ASIOSTFloat64MSB:
  189297. case ASIOSTFloat64LSB:
  189298. byteStride = 8; break;
  189299. default:
  189300. break;
  189301. }
  189302. }
  189303. };
  189304. class ASIOAudioIODeviceType : public AudioIODeviceType
  189305. {
  189306. public:
  189307. ASIOAudioIODeviceType()
  189308. : AudioIODeviceType ("ASIO"),
  189309. hasScanned (false)
  189310. {
  189311. CoInitialize (0);
  189312. }
  189313. ~ASIOAudioIODeviceType()
  189314. {
  189315. }
  189316. void scanForDevices()
  189317. {
  189318. hasScanned = true;
  189319. deviceNames.clear();
  189320. classIds.clear();
  189321. HKEY hk = 0;
  189322. int index = 0;
  189323. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189324. {
  189325. for (;;)
  189326. {
  189327. char name [256];
  189328. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189329. {
  189330. addDriverInfo (name, hk);
  189331. }
  189332. else
  189333. {
  189334. break;
  189335. }
  189336. }
  189337. RegCloseKey (hk);
  189338. }
  189339. }
  189340. const StringArray getDeviceNames (bool /*wantInputNames*/) const
  189341. {
  189342. jassert (hasScanned); // need to call scanForDevices() before doing this
  189343. return deviceNames;
  189344. }
  189345. int getDefaultDeviceIndex (bool) const
  189346. {
  189347. jassert (hasScanned); // need to call scanForDevices() before doing this
  189348. for (int i = deviceNames.size(); --i >= 0;)
  189349. if (deviceNames[i].containsIgnoreCase ("asio4all"))
  189350. return i; // asio4all is a safe choice for a default..
  189351. #if JUCE_DEBUG
  189352. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase ("digidesign"))
  189353. return 1; // (the digi m-box driver crashes the app when you run
  189354. // it in the debugger, which can be a bit annoying)
  189355. #endif
  189356. return 0;
  189357. }
  189358. static int findFreeSlot()
  189359. {
  189360. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189361. if (currentASIODev[i] == 0)
  189362. return i;
  189363. jassertfalse; // unfortunately you can only have a finite number
  189364. // of ASIO devices open at the same time..
  189365. return -1;
  189366. }
  189367. int getIndexOfDevice (AudioIODevice* d, bool /*asInput*/) const
  189368. {
  189369. jassert (hasScanned); // need to call scanForDevices() before doing this
  189370. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189371. }
  189372. bool hasSeparateInputsAndOutputs() const { return false; }
  189373. AudioIODevice* createDevice (const String& outputDeviceName,
  189374. const String& inputDeviceName)
  189375. {
  189376. // ASIO can't open two different devices for input and output - they must be the same one.
  189377. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189378. jassert (hasScanned); // need to call scanForDevices() before doing this
  189379. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189380. : inputDeviceName);
  189381. if (index >= 0)
  189382. {
  189383. const int freeSlot = findFreeSlot();
  189384. if (freeSlot >= 0)
  189385. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189386. }
  189387. return 0;
  189388. }
  189389. juce_UseDebuggingNewOperator
  189390. private:
  189391. StringArray deviceNames;
  189392. OwnedArray <CLSID> classIds;
  189393. bool hasScanned;
  189394. static bool checkClassIsOk (const String& classId)
  189395. {
  189396. HKEY hk = 0;
  189397. bool ok = false;
  189398. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189399. {
  189400. int index = 0;
  189401. for (;;)
  189402. {
  189403. WCHAR buf [512];
  189404. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189405. {
  189406. if (classId.equalsIgnoreCase (buf))
  189407. {
  189408. HKEY subKey, pathKey;
  189409. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189410. {
  189411. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189412. {
  189413. WCHAR pathName [1024];
  189414. DWORD dtype = REG_SZ;
  189415. DWORD dsize = sizeof (pathName);
  189416. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189417. ok = File (pathName).exists();
  189418. RegCloseKey (pathKey);
  189419. }
  189420. RegCloseKey (subKey);
  189421. }
  189422. break;
  189423. }
  189424. }
  189425. else
  189426. {
  189427. break;
  189428. }
  189429. }
  189430. RegCloseKey (hk);
  189431. }
  189432. return ok;
  189433. }
  189434. void addDriverInfo (const String& keyName, HKEY hk)
  189435. {
  189436. HKEY subKey;
  189437. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189438. {
  189439. WCHAR buf [256];
  189440. zerostruct (buf);
  189441. DWORD dtype = REG_SZ;
  189442. DWORD dsize = sizeof (buf);
  189443. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189444. {
  189445. if (dsize > 0 && checkClassIsOk (buf))
  189446. {
  189447. CLSID classId;
  189448. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189449. {
  189450. dtype = REG_SZ;
  189451. dsize = sizeof (buf);
  189452. String deviceName;
  189453. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189454. deviceName = buf;
  189455. else
  189456. deviceName = keyName;
  189457. log ("found " + deviceName);
  189458. deviceNames.add (deviceName);
  189459. classIds.add (new CLSID (classId));
  189460. }
  189461. }
  189462. RegCloseKey (subKey);
  189463. }
  189464. }
  189465. }
  189466. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189467. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189468. };
  189469. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189470. {
  189471. return new ASIOAudioIODeviceType();
  189472. }
  189473. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189474. void* guid,
  189475. const String& optionalDllForDirectLoading)
  189476. {
  189477. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189478. if (freeSlot < 0)
  189479. return 0;
  189480. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189481. }
  189482. #undef log
  189483. #endif
  189484. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189485. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189486. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189487. // compiled on its own).
  189488. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189489. END_JUCE_NAMESPACE
  189490. extern "C"
  189491. {
  189492. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189493. typedef struct typeDSBUFFERDESC
  189494. {
  189495. DWORD dwSize;
  189496. DWORD dwFlags;
  189497. DWORD dwBufferBytes;
  189498. DWORD dwReserved;
  189499. LPWAVEFORMATEX lpwfxFormat;
  189500. GUID guid3DAlgorithm;
  189501. } DSBUFFERDESC;
  189502. struct IDirectSoundBuffer;
  189503. #undef INTERFACE
  189504. #define INTERFACE IDirectSound
  189505. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189506. {
  189507. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189508. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189509. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189510. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189511. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189512. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189513. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189514. STDMETHOD(Compact) (THIS) PURE;
  189515. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189516. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189517. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189518. };
  189519. #undef INTERFACE
  189520. #define INTERFACE IDirectSoundBuffer
  189521. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189522. {
  189523. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189524. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189525. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189526. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189527. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189528. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189529. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189530. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189531. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189532. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189533. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189534. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189535. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189536. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189537. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189538. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189539. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189540. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189541. STDMETHOD(Stop) (THIS) PURE;
  189542. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189543. STDMETHOD(Restore) (THIS) PURE;
  189544. };
  189545. typedef struct typeDSCBUFFERDESC
  189546. {
  189547. DWORD dwSize;
  189548. DWORD dwFlags;
  189549. DWORD dwBufferBytes;
  189550. DWORD dwReserved;
  189551. LPWAVEFORMATEX lpwfxFormat;
  189552. } DSCBUFFERDESC;
  189553. struct IDirectSoundCaptureBuffer;
  189554. #undef INTERFACE
  189555. #define INTERFACE IDirectSoundCapture
  189556. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189557. {
  189558. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189559. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189560. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189561. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189562. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189563. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189564. };
  189565. #undef INTERFACE
  189566. #define INTERFACE IDirectSoundCaptureBuffer
  189567. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189568. {
  189569. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189570. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189571. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189572. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189573. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189574. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189575. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189576. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189577. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189578. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189579. STDMETHOD(Stop) (THIS) PURE;
  189580. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189581. };
  189582. };
  189583. BEGIN_JUCE_NAMESPACE
  189584. static const String getDSErrorMessage (HRESULT hr)
  189585. {
  189586. const char* result = 0;
  189587. switch (hr)
  189588. {
  189589. case MAKE_HRESULT(1, 0x878, 10):
  189590. result = "Device already allocated";
  189591. break;
  189592. case MAKE_HRESULT(1, 0x878, 30):
  189593. result = "Control unavailable";
  189594. break;
  189595. case E_INVALIDARG:
  189596. result = "Invalid parameter";
  189597. break;
  189598. case MAKE_HRESULT(1, 0x878, 50):
  189599. result = "Invalid call";
  189600. break;
  189601. case E_FAIL:
  189602. result = "Generic error";
  189603. break;
  189604. case MAKE_HRESULT(1, 0x878, 70):
  189605. result = "Priority level error";
  189606. break;
  189607. case E_OUTOFMEMORY:
  189608. result = "Out of memory";
  189609. break;
  189610. case MAKE_HRESULT(1, 0x878, 100):
  189611. result = "Bad format";
  189612. break;
  189613. case E_NOTIMPL:
  189614. result = "Unsupported function";
  189615. break;
  189616. case MAKE_HRESULT(1, 0x878, 120):
  189617. result = "No driver";
  189618. break;
  189619. case MAKE_HRESULT(1, 0x878, 130):
  189620. result = "Already initialised";
  189621. break;
  189622. case CLASS_E_NOAGGREGATION:
  189623. result = "No aggregation";
  189624. break;
  189625. case MAKE_HRESULT(1, 0x878, 150):
  189626. result = "Buffer lost";
  189627. break;
  189628. case MAKE_HRESULT(1, 0x878, 160):
  189629. result = "Another app has priority";
  189630. break;
  189631. case MAKE_HRESULT(1, 0x878, 170):
  189632. result = "Uninitialised";
  189633. break;
  189634. case E_NOINTERFACE:
  189635. result = "No interface";
  189636. break;
  189637. case S_OK:
  189638. result = "No error";
  189639. break;
  189640. default:
  189641. return "Unknown error: " + String ((int) hr);
  189642. }
  189643. return result;
  189644. }
  189645. #define DS_DEBUGGING 1
  189646. #ifdef DS_DEBUGGING
  189647. #define CATCH JUCE_CATCH_EXCEPTION
  189648. #undef log
  189649. #define log(a) Logger::writeToLog(a);
  189650. #undef logError
  189651. #define logError(a) logDSError(a, __LINE__);
  189652. static void logDSError (HRESULT hr, int lineNum)
  189653. {
  189654. if (hr != S_OK)
  189655. {
  189656. String error ("DS error at line ");
  189657. error << lineNum << " - " << getDSErrorMessage (hr);
  189658. log (error);
  189659. }
  189660. }
  189661. #else
  189662. #define CATCH JUCE_CATCH_ALL
  189663. #define log(a)
  189664. #define logError(a)
  189665. #endif
  189666. #define DSOUND_FUNCTION(functionName, params) \
  189667. typedef HRESULT (WINAPI *type##functionName) params; \
  189668. static type##functionName ds##functionName = 0;
  189669. #define DSOUND_FUNCTION_LOAD(functionName) \
  189670. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189671. jassert (ds##functionName != 0);
  189672. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189673. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189674. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189675. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189676. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189677. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189678. static void initialiseDSoundFunctions()
  189679. {
  189680. if (dsDirectSoundCreate == 0)
  189681. {
  189682. HMODULE h = LoadLibraryA ("dsound.dll");
  189683. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189684. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189685. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189686. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189687. }
  189688. }
  189689. class DSoundInternalOutChannel
  189690. {
  189691. String name;
  189692. LPGUID guid;
  189693. int sampleRate, bufferSizeSamples;
  189694. float* leftBuffer;
  189695. float* rightBuffer;
  189696. IDirectSound* pDirectSound;
  189697. IDirectSoundBuffer* pOutputBuffer;
  189698. DWORD writeOffset;
  189699. int totalBytesPerBuffer;
  189700. int bytesPerBuffer;
  189701. unsigned int lastPlayCursor;
  189702. public:
  189703. int bitDepth;
  189704. bool doneFlag;
  189705. DSoundInternalOutChannel (const String& name_,
  189706. LPGUID guid_,
  189707. int rate,
  189708. int bufferSize,
  189709. float* left,
  189710. float* right)
  189711. : name (name_),
  189712. guid (guid_),
  189713. sampleRate (rate),
  189714. bufferSizeSamples (bufferSize),
  189715. leftBuffer (left),
  189716. rightBuffer (right),
  189717. pDirectSound (0),
  189718. pOutputBuffer (0),
  189719. bitDepth (16)
  189720. {
  189721. }
  189722. ~DSoundInternalOutChannel()
  189723. {
  189724. close();
  189725. }
  189726. void close()
  189727. {
  189728. HRESULT hr;
  189729. if (pOutputBuffer != 0)
  189730. {
  189731. JUCE_TRY
  189732. {
  189733. log ("closing dsound out: " + name);
  189734. hr = pOutputBuffer->Stop();
  189735. logError (hr);
  189736. }
  189737. CATCH
  189738. JUCE_TRY
  189739. {
  189740. hr = pOutputBuffer->Release();
  189741. logError (hr);
  189742. }
  189743. CATCH
  189744. pOutputBuffer = 0;
  189745. }
  189746. if (pDirectSound != 0)
  189747. {
  189748. JUCE_TRY
  189749. {
  189750. hr = pDirectSound->Release();
  189751. logError (hr);
  189752. }
  189753. CATCH
  189754. pDirectSound = 0;
  189755. }
  189756. }
  189757. const String open()
  189758. {
  189759. log ("opening dsound out device: " + name + " rate=" + String (sampleRate)
  189760. + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  189761. pDirectSound = 0;
  189762. pOutputBuffer = 0;
  189763. writeOffset = 0;
  189764. String error;
  189765. HRESULT hr = E_NOINTERFACE;
  189766. if (dsDirectSoundCreate != 0)
  189767. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  189768. if (hr == S_OK)
  189769. {
  189770. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189771. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189772. const int numChannels = 2;
  189773. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  189774. logError (hr);
  189775. if (hr == S_OK)
  189776. {
  189777. IDirectSoundBuffer* pPrimaryBuffer;
  189778. DSBUFFERDESC primaryDesc;
  189779. zerostruct (primaryDesc);
  189780. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189781. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  189782. primaryDesc.dwBufferBytes = 0;
  189783. primaryDesc.lpwfxFormat = 0;
  189784. log ("opening dsound out step 2");
  189785. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  189786. logError (hr);
  189787. if (hr == S_OK)
  189788. {
  189789. WAVEFORMATEX wfFormat;
  189790. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189791. wfFormat.nChannels = (unsigned short) numChannels;
  189792. wfFormat.nSamplesPerSec = sampleRate;
  189793. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  189794. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  189795. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189796. wfFormat.cbSize = 0;
  189797. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  189798. logError (hr);
  189799. if (hr == S_OK)
  189800. {
  189801. DSBUFFERDESC secondaryDesc;
  189802. zerostruct (secondaryDesc);
  189803. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189804. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  189805. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  189806. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  189807. secondaryDesc.lpwfxFormat = &wfFormat;
  189808. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  189809. logError (hr);
  189810. if (hr == S_OK)
  189811. {
  189812. log ("opening dsound out step 3");
  189813. DWORD dwDataLen;
  189814. unsigned char* pDSBuffData;
  189815. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  189816. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  189817. logError (hr);
  189818. if (hr == S_OK)
  189819. {
  189820. zeromem (pDSBuffData, dwDataLen);
  189821. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  189822. if (hr == S_OK)
  189823. {
  189824. hr = pOutputBuffer->SetCurrentPosition (0);
  189825. if (hr == S_OK)
  189826. {
  189827. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  189828. if (hr == S_OK)
  189829. return String::empty;
  189830. }
  189831. }
  189832. }
  189833. }
  189834. }
  189835. }
  189836. }
  189837. }
  189838. error = getDSErrorMessage (hr);
  189839. close();
  189840. return error;
  189841. }
  189842. void synchronisePosition()
  189843. {
  189844. if (pOutputBuffer != 0)
  189845. {
  189846. DWORD playCursor;
  189847. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  189848. }
  189849. }
  189850. bool service()
  189851. {
  189852. if (pOutputBuffer == 0)
  189853. return true;
  189854. DWORD playCursor, writeCursor;
  189855. for (;;)
  189856. {
  189857. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  189858. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189859. {
  189860. pOutputBuffer->Restore();
  189861. continue;
  189862. }
  189863. if (hr == S_OK)
  189864. break;
  189865. logError (hr);
  189866. jassertfalse
  189867. return true;
  189868. }
  189869. int playWriteGap = writeCursor - playCursor;
  189870. if (playWriteGap < 0)
  189871. playWriteGap += totalBytesPerBuffer;
  189872. int bytesEmpty = playCursor - writeOffset;
  189873. if (bytesEmpty < 0)
  189874. bytesEmpty += totalBytesPerBuffer;
  189875. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  189876. {
  189877. writeOffset = writeCursor;
  189878. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  189879. }
  189880. if (bytesEmpty >= bytesPerBuffer)
  189881. {
  189882. LPBYTE lpbuf1 = 0;
  189883. LPBYTE lpbuf2 = 0;
  189884. DWORD dwSize1 = 0;
  189885. DWORD dwSize2 = 0;
  189886. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  189887. bytesPerBuffer,
  189888. (void**) &lpbuf1, &dwSize1,
  189889. (void**) &lpbuf2, &dwSize2, 0);
  189890. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189891. {
  189892. pOutputBuffer->Restore();
  189893. hr = pOutputBuffer->Lock (writeOffset,
  189894. bytesPerBuffer,
  189895. (void**) &lpbuf1, &dwSize1,
  189896. (void**) &lpbuf2, &dwSize2, 0);
  189897. }
  189898. if (hr == S_OK)
  189899. {
  189900. if (bitDepth == 16)
  189901. {
  189902. const float gainL = 32767.0f;
  189903. const float gainR = 32767.0f;
  189904. int* dest = (int*)lpbuf1;
  189905. const float* left = leftBuffer;
  189906. const float* right = rightBuffer;
  189907. int samples1 = dwSize1 >> 2;
  189908. int samples2 = dwSize2 >> 2;
  189909. if (left == 0)
  189910. {
  189911. while (--samples1 >= 0)
  189912. {
  189913. int r = roundToInt (gainR * *right++);
  189914. if (r < -32768)
  189915. r = -32768;
  189916. else if (r > 32767)
  189917. r = 32767;
  189918. *dest++ = (r << 16);
  189919. }
  189920. dest = (int*)lpbuf2;
  189921. while (--samples2 >= 0)
  189922. {
  189923. int r = roundToInt (gainR * *right++);
  189924. if (r < -32768)
  189925. r = -32768;
  189926. else if (r > 32767)
  189927. r = 32767;
  189928. *dest++ = (r << 16);
  189929. }
  189930. }
  189931. else if (right == 0)
  189932. {
  189933. while (--samples1 >= 0)
  189934. {
  189935. int l = roundToInt (gainL * *left++);
  189936. if (l < -32768)
  189937. l = -32768;
  189938. else if (l > 32767)
  189939. l = 32767;
  189940. l &= 0xffff;
  189941. *dest++ = l;
  189942. }
  189943. dest = (int*)lpbuf2;
  189944. while (--samples2 >= 0)
  189945. {
  189946. int l = roundToInt (gainL * *left++);
  189947. if (l < -32768)
  189948. l = -32768;
  189949. else if (l > 32767)
  189950. l = 32767;
  189951. l &= 0xffff;
  189952. *dest++ = l;
  189953. }
  189954. }
  189955. else
  189956. {
  189957. while (--samples1 >= 0)
  189958. {
  189959. int l = roundToInt (gainL * *left++);
  189960. if (l < -32768)
  189961. l = -32768;
  189962. else if (l > 32767)
  189963. l = 32767;
  189964. l &= 0xffff;
  189965. int r = roundToInt (gainR * *right++);
  189966. if (r < -32768)
  189967. r = -32768;
  189968. else if (r > 32767)
  189969. r = 32767;
  189970. *dest++ = (r << 16) | l;
  189971. }
  189972. dest = (int*)lpbuf2;
  189973. while (--samples2 >= 0)
  189974. {
  189975. int l = roundToInt (gainL * *left++);
  189976. if (l < -32768)
  189977. l = -32768;
  189978. else if (l > 32767)
  189979. l = 32767;
  189980. l &= 0xffff;
  189981. int r = roundToInt (gainR * *right++);
  189982. if (r < -32768)
  189983. r = -32768;
  189984. else if (r > 32767)
  189985. r = 32767;
  189986. *dest++ = (r << 16) | l;
  189987. }
  189988. }
  189989. }
  189990. else
  189991. {
  189992. jassertfalse
  189993. }
  189994. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  189995. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  189996. }
  189997. else
  189998. {
  189999. jassertfalse
  190000. logError (hr);
  190001. }
  190002. bytesEmpty -= bytesPerBuffer;
  190003. return true;
  190004. }
  190005. else
  190006. {
  190007. return false;
  190008. }
  190009. }
  190010. };
  190011. struct DSoundInternalInChannel
  190012. {
  190013. String name;
  190014. LPGUID guid;
  190015. int sampleRate, bufferSizeSamples;
  190016. float* leftBuffer;
  190017. float* rightBuffer;
  190018. IDirectSound* pDirectSound;
  190019. IDirectSoundCapture* pDirectSoundCapture;
  190020. IDirectSoundCaptureBuffer* pInputBuffer;
  190021. public:
  190022. unsigned int readOffset;
  190023. int bytesPerBuffer, totalBytesPerBuffer;
  190024. int bitDepth;
  190025. bool doneFlag;
  190026. DSoundInternalInChannel (const String& name_,
  190027. LPGUID guid_,
  190028. int rate,
  190029. int bufferSize,
  190030. float* left,
  190031. float* right)
  190032. : name (name_),
  190033. guid (guid_),
  190034. sampleRate (rate),
  190035. bufferSizeSamples (bufferSize),
  190036. leftBuffer (left),
  190037. rightBuffer (right),
  190038. pDirectSound (0),
  190039. pDirectSoundCapture (0),
  190040. pInputBuffer (0),
  190041. bitDepth (16)
  190042. {
  190043. }
  190044. ~DSoundInternalInChannel()
  190045. {
  190046. close();
  190047. }
  190048. void close()
  190049. {
  190050. HRESULT hr;
  190051. if (pInputBuffer != 0)
  190052. {
  190053. JUCE_TRY
  190054. {
  190055. log ("closing dsound in: " + name);
  190056. hr = pInputBuffer->Stop();
  190057. logError (hr);
  190058. }
  190059. CATCH
  190060. JUCE_TRY
  190061. {
  190062. hr = pInputBuffer->Release();
  190063. logError (hr);
  190064. }
  190065. CATCH
  190066. pInputBuffer = 0;
  190067. }
  190068. if (pDirectSoundCapture != 0)
  190069. {
  190070. JUCE_TRY
  190071. {
  190072. hr = pDirectSoundCapture->Release();
  190073. logError (hr);
  190074. }
  190075. CATCH
  190076. pDirectSoundCapture = 0;
  190077. }
  190078. if (pDirectSound != 0)
  190079. {
  190080. JUCE_TRY
  190081. {
  190082. hr = pDirectSound->Release();
  190083. logError (hr);
  190084. }
  190085. CATCH
  190086. pDirectSound = 0;
  190087. }
  190088. }
  190089. const String open()
  190090. {
  190091. log ("opening dsound in device: " + name
  190092. + " rate=" + String (sampleRate) + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  190093. pDirectSound = 0;
  190094. pDirectSoundCapture = 0;
  190095. pInputBuffer = 0;
  190096. readOffset = 0;
  190097. totalBytesPerBuffer = 0;
  190098. String error;
  190099. HRESULT hr = E_NOINTERFACE;
  190100. if (dsDirectSoundCaptureCreate != 0)
  190101. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190102. logError (hr);
  190103. if (hr == S_OK)
  190104. {
  190105. const int numChannels = 2;
  190106. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190107. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190108. WAVEFORMATEX wfFormat;
  190109. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190110. wfFormat.nChannels = (unsigned short)numChannels;
  190111. wfFormat.nSamplesPerSec = sampleRate;
  190112. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190113. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190114. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190115. wfFormat.cbSize = 0;
  190116. DSCBUFFERDESC captureDesc;
  190117. zerostruct (captureDesc);
  190118. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190119. captureDesc.dwFlags = 0;
  190120. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190121. captureDesc.lpwfxFormat = &wfFormat;
  190122. log ("opening dsound in step 2");
  190123. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190124. logError (hr);
  190125. if (hr == S_OK)
  190126. {
  190127. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190128. logError (hr);
  190129. if (hr == S_OK)
  190130. return String::empty;
  190131. }
  190132. }
  190133. error = getDSErrorMessage (hr);
  190134. close();
  190135. return error;
  190136. }
  190137. void synchronisePosition()
  190138. {
  190139. if (pInputBuffer != 0)
  190140. {
  190141. DWORD capturePos;
  190142. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190143. }
  190144. }
  190145. bool service()
  190146. {
  190147. if (pInputBuffer == 0)
  190148. return true;
  190149. DWORD capturePos, readPos;
  190150. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190151. logError (hr);
  190152. if (hr != S_OK)
  190153. return true;
  190154. int bytesFilled = readPos - readOffset;
  190155. if (bytesFilled < 0)
  190156. bytesFilled += totalBytesPerBuffer;
  190157. if (bytesFilled >= bytesPerBuffer)
  190158. {
  190159. LPBYTE lpbuf1 = 0;
  190160. LPBYTE lpbuf2 = 0;
  190161. DWORD dwsize1 = 0;
  190162. DWORD dwsize2 = 0;
  190163. HRESULT hr = pInputBuffer->Lock (readOffset,
  190164. bytesPerBuffer,
  190165. (void**) &lpbuf1, &dwsize1,
  190166. (void**) &lpbuf2, &dwsize2, 0);
  190167. if (hr == S_OK)
  190168. {
  190169. if (bitDepth == 16)
  190170. {
  190171. const float g = 1.0f / 32768.0f;
  190172. float* destL = leftBuffer;
  190173. float* destR = rightBuffer;
  190174. int samples1 = dwsize1 >> 2;
  190175. int samples2 = dwsize2 >> 2;
  190176. const short* src = (const short*)lpbuf1;
  190177. if (destL == 0)
  190178. {
  190179. while (--samples1 >= 0)
  190180. {
  190181. ++src;
  190182. *destR++ = *src++ * g;
  190183. }
  190184. src = (const short*)lpbuf2;
  190185. while (--samples2 >= 0)
  190186. {
  190187. ++src;
  190188. *destR++ = *src++ * g;
  190189. }
  190190. }
  190191. else if (destR == 0)
  190192. {
  190193. while (--samples1 >= 0)
  190194. {
  190195. *destL++ = *src++ * g;
  190196. ++src;
  190197. }
  190198. src = (const short*)lpbuf2;
  190199. while (--samples2 >= 0)
  190200. {
  190201. *destL++ = *src++ * g;
  190202. ++src;
  190203. }
  190204. }
  190205. else
  190206. {
  190207. while (--samples1 >= 0)
  190208. {
  190209. *destL++ = *src++ * g;
  190210. *destR++ = *src++ * g;
  190211. }
  190212. src = (const short*)lpbuf2;
  190213. while (--samples2 >= 0)
  190214. {
  190215. *destL++ = *src++ * g;
  190216. *destR++ = *src++ * g;
  190217. }
  190218. }
  190219. }
  190220. else
  190221. {
  190222. jassertfalse
  190223. }
  190224. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190225. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190226. }
  190227. else
  190228. {
  190229. logError (hr);
  190230. jassertfalse
  190231. }
  190232. bytesFilled -= bytesPerBuffer;
  190233. return true;
  190234. }
  190235. else
  190236. {
  190237. return false;
  190238. }
  190239. }
  190240. };
  190241. class DSoundAudioIODevice : public AudioIODevice,
  190242. public Thread
  190243. {
  190244. public:
  190245. DSoundAudioIODevice (const String& deviceName,
  190246. const int outputDeviceIndex_,
  190247. const int inputDeviceIndex_)
  190248. : AudioIODevice (deviceName, "DirectSound"),
  190249. Thread ("Juce DSound"),
  190250. isOpen_ (false),
  190251. isStarted (false),
  190252. outputDeviceIndex (outputDeviceIndex_),
  190253. inputDeviceIndex (inputDeviceIndex_),
  190254. numInputBuffers (0),
  190255. numOutputBuffers (0),
  190256. totalSamplesOut (0),
  190257. sampleRate (0.0),
  190258. inputBuffers (0),
  190259. outputBuffers (0),
  190260. callback (0),
  190261. bufferSizeSamples (0)
  190262. {
  190263. if (outputDeviceIndex_ >= 0)
  190264. {
  190265. outChannels.add (TRANS("Left"));
  190266. outChannels.add (TRANS("Right"));
  190267. }
  190268. if (inputDeviceIndex_ >= 0)
  190269. {
  190270. inChannels.add (TRANS("Left"));
  190271. inChannels.add (TRANS("Right"));
  190272. }
  190273. }
  190274. ~DSoundAudioIODevice()
  190275. {
  190276. close();
  190277. }
  190278. const StringArray getOutputChannelNames()
  190279. {
  190280. return outChannels;
  190281. }
  190282. const StringArray getInputChannelNames()
  190283. {
  190284. return inChannels;
  190285. }
  190286. int getNumSampleRates()
  190287. {
  190288. return 4;
  190289. }
  190290. double getSampleRate (int index)
  190291. {
  190292. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190293. return samps [jlimit (0, 3, index)];
  190294. }
  190295. int getNumBufferSizesAvailable()
  190296. {
  190297. return 50;
  190298. }
  190299. int getBufferSizeSamples (int index)
  190300. {
  190301. int n = 64;
  190302. for (int i = 0; i < index; ++i)
  190303. n += (n < 512) ? 32
  190304. : ((n < 1024) ? 64
  190305. : ((n < 2048) ? 128 : 256));
  190306. return n;
  190307. }
  190308. int getDefaultBufferSize()
  190309. {
  190310. return 2560;
  190311. }
  190312. const String open (const BigInteger& inputChannels,
  190313. const BigInteger& outputChannels,
  190314. double sampleRate,
  190315. int bufferSizeSamples)
  190316. {
  190317. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190318. isOpen_ = lastError.isEmpty();
  190319. return lastError;
  190320. }
  190321. void close()
  190322. {
  190323. stop();
  190324. if (isOpen_)
  190325. {
  190326. closeDevice();
  190327. isOpen_ = false;
  190328. }
  190329. }
  190330. bool isOpen()
  190331. {
  190332. return isOpen_ && isThreadRunning();
  190333. }
  190334. int getCurrentBufferSizeSamples()
  190335. {
  190336. return bufferSizeSamples;
  190337. }
  190338. double getCurrentSampleRate()
  190339. {
  190340. return sampleRate;
  190341. }
  190342. int getCurrentBitDepth()
  190343. {
  190344. int i, bits = 256;
  190345. for (i = inChans.size(); --i >= 0;)
  190346. bits = jmin (bits, inChans[i]->bitDepth);
  190347. for (i = outChans.size(); --i >= 0;)
  190348. bits = jmin (bits, outChans[i]->bitDepth);
  190349. if (bits > 32)
  190350. bits = 16;
  190351. return bits;
  190352. }
  190353. const BigInteger getActiveOutputChannels() const
  190354. {
  190355. return enabledOutputs;
  190356. }
  190357. const BigInteger getActiveInputChannels() const
  190358. {
  190359. return enabledInputs;
  190360. }
  190361. int getOutputLatencyInSamples()
  190362. {
  190363. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190364. }
  190365. int getInputLatencyInSamples()
  190366. {
  190367. return getOutputLatencyInSamples();
  190368. }
  190369. void start (AudioIODeviceCallback* call)
  190370. {
  190371. if (isOpen_ && call != 0 && ! isStarted)
  190372. {
  190373. if (! isThreadRunning())
  190374. {
  190375. // something gone wrong and the thread's stopped..
  190376. isOpen_ = false;
  190377. return;
  190378. }
  190379. call->audioDeviceAboutToStart (this);
  190380. const ScopedLock sl (startStopLock);
  190381. callback = call;
  190382. isStarted = true;
  190383. }
  190384. }
  190385. void stop()
  190386. {
  190387. if (isStarted)
  190388. {
  190389. AudioIODeviceCallback* const callbackLocal = callback;
  190390. {
  190391. const ScopedLock sl (startStopLock);
  190392. isStarted = false;
  190393. }
  190394. if (callbackLocal != 0)
  190395. callbackLocal->audioDeviceStopped();
  190396. }
  190397. }
  190398. bool isPlaying()
  190399. {
  190400. return isStarted && isOpen_ && isThreadRunning();
  190401. }
  190402. const String getLastError()
  190403. {
  190404. return lastError;
  190405. }
  190406. juce_UseDebuggingNewOperator
  190407. StringArray inChannels, outChannels;
  190408. int outputDeviceIndex, inputDeviceIndex;
  190409. private:
  190410. bool isOpen_;
  190411. bool isStarted;
  190412. String lastError;
  190413. OwnedArray <DSoundInternalInChannel> inChans;
  190414. OwnedArray <DSoundInternalOutChannel> outChans;
  190415. WaitableEvent startEvent;
  190416. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190417. int volatile totalSamplesOut;
  190418. int64 volatile lastBlockTime;
  190419. double sampleRate;
  190420. BigInteger enabledInputs, enabledOutputs;
  190421. HeapBlock <float*> inputBuffers, outputBuffers;
  190422. AudioIODeviceCallback* callback;
  190423. CriticalSection startStopLock;
  190424. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190425. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190426. const String openDevice (const BigInteger& inputChannels,
  190427. const BigInteger& outputChannels,
  190428. double sampleRate_,
  190429. int bufferSizeSamples_);
  190430. void closeDevice()
  190431. {
  190432. isStarted = false;
  190433. stopThread (5000);
  190434. inChans.clear();
  190435. outChans.clear();
  190436. int i;
  190437. for (i = 0; i < numInputBuffers; ++i)
  190438. juce_free (inputBuffers[i]);
  190439. inputBuffers.free();
  190440. numInputBuffers = 0;
  190441. for (i = 0; i < numOutputBuffers; ++i)
  190442. juce_free (outputBuffers[i]);
  190443. outputBuffers.free();
  190444. numOutputBuffers = 0;
  190445. }
  190446. void resync()
  190447. {
  190448. if (! threadShouldExit())
  190449. {
  190450. sleep (5);
  190451. int i;
  190452. for (i = 0; i < outChans.size(); ++i)
  190453. outChans.getUnchecked(i)->synchronisePosition();
  190454. for (i = 0; i < inChans.size(); ++i)
  190455. inChans.getUnchecked(i)->synchronisePosition();
  190456. }
  190457. }
  190458. public:
  190459. void run()
  190460. {
  190461. while (! threadShouldExit())
  190462. {
  190463. if (wait (100))
  190464. break;
  190465. }
  190466. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190467. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190468. while (! threadShouldExit())
  190469. {
  190470. int numToDo = 0;
  190471. uint32 startTime = Time::getMillisecondCounter();
  190472. int i;
  190473. for (i = inChans.size(); --i >= 0;)
  190474. {
  190475. inChans.getUnchecked(i)->doneFlag = false;
  190476. ++numToDo;
  190477. }
  190478. for (i = outChans.size(); --i >= 0;)
  190479. {
  190480. outChans.getUnchecked(i)->doneFlag = false;
  190481. ++numToDo;
  190482. }
  190483. if (numToDo > 0)
  190484. {
  190485. const int maxCount = 3;
  190486. int count = maxCount;
  190487. for (;;)
  190488. {
  190489. for (i = inChans.size(); --i >= 0;)
  190490. {
  190491. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190492. if ((! in->doneFlag) && in->service())
  190493. {
  190494. in->doneFlag = true;
  190495. --numToDo;
  190496. }
  190497. }
  190498. for (i = outChans.size(); --i >= 0;)
  190499. {
  190500. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190501. if ((! out->doneFlag) && out->service())
  190502. {
  190503. out->doneFlag = true;
  190504. --numToDo;
  190505. }
  190506. }
  190507. if (numToDo <= 0)
  190508. break;
  190509. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190510. {
  190511. resync();
  190512. break;
  190513. }
  190514. if (--count <= 0)
  190515. {
  190516. Sleep (1);
  190517. count = maxCount;
  190518. }
  190519. if (threadShouldExit())
  190520. return;
  190521. }
  190522. }
  190523. else
  190524. {
  190525. sleep (1);
  190526. }
  190527. const ScopedLock sl (startStopLock);
  190528. if (isStarted)
  190529. {
  190530. JUCE_TRY
  190531. {
  190532. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190533. numInputBuffers,
  190534. outputBuffers,
  190535. numOutputBuffers,
  190536. bufferSizeSamples);
  190537. }
  190538. JUCE_CATCH_EXCEPTION
  190539. totalSamplesOut += bufferSizeSamples;
  190540. }
  190541. else
  190542. {
  190543. for (i = 0; i < numOutputBuffers; ++i)
  190544. if (outputBuffers[i] != 0)
  190545. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190546. totalSamplesOut = 0;
  190547. sleep (1);
  190548. }
  190549. }
  190550. }
  190551. };
  190552. class DSoundAudioIODeviceType : public AudioIODeviceType
  190553. {
  190554. public:
  190555. DSoundAudioIODeviceType()
  190556. : AudioIODeviceType ("DirectSound"),
  190557. hasScanned (false)
  190558. {
  190559. initialiseDSoundFunctions();
  190560. }
  190561. ~DSoundAudioIODeviceType()
  190562. {
  190563. }
  190564. void scanForDevices()
  190565. {
  190566. hasScanned = true;
  190567. outputDeviceNames.clear();
  190568. outputGuids.clear();
  190569. inputDeviceNames.clear();
  190570. inputGuids.clear();
  190571. if (dsDirectSoundEnumerateW != 0)
  190572. {
  190573. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190574. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190575. }
  190576. }
  190577. const StringArray getDeviceNames (bool wantInputNames) const
  190578. {
  190579. jassert (hasScanned); // need to call scanForDevices() before doing this
  190580. return wantInputNames ? inputDeviceNames
  190581. : outputDeviceNames;
  190582. }
  190583. int getDefaultDeviceIndex (bool /*forInput*/) const
  190584. {
  190585. jassert (hasScanned); // need to call scanForDevices() before doing this
  190586. return 0;
  190587. }
  190588. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  190589. {
  190590. jassert (hasScanned); // need to call scanForDevices() before doing this
  190591. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190592. if (d == 0)
  190593. return -1;
  190594. return asInput ? d->inputDeviceIndex
  190595. : d->outputDeviceIndex;
  190596. }
  190597. bool hasSeparateInputsAndOutputs() const { return true; }
  190598. AudioIODevice* createDevice (const String& outputDeviceName,
  190599. const String& inputDeviceName)
  190600. {
  190601. jassert (hasScanned); // need to call scanForDevices() before doing this
  190602. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190603. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190604. if (outputIndex >= 0 || inputIndex >= 0)
  190605. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190606. : inputDeviceName,
  190607. outputIndex, inputIndex);
  190608. return 0;
  190609. }
  190610. juce_UseDebuggingNewOperator
  190611. StringArray outputDeviceNames;
  190612. OwnedArray <GUID> outputGuids;
  190613. StringArray inputDeviceNames;
  190614. OwnedArray <GUID> inputGuids;
  190615. private:
  190616. bool hasScanned;
  190617. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190618. {
  190619. desc = desc.trim();
  190620. if (desc.isNotEmpty())
  190621. {
  190622. const String origDesc (desc);
  190623. int n = 2;
  190624. while (outputDeviceNames.contains (desc))
  190625. desc = origDesc + " (" + String (n++) + ")";
  190626. outputDeviceNames.add (desc);
  190627. if (lpGUID != 0)
  190628. outputGuids.add (new GUID (*lpGUID));
  190629. else
  190630. outputGuids.add (0);
  190631. }
  190632. return TRUE;
  190633. }
  190634. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190635. {
  190636. return ((DSoundAudioIODeviceType*) object)
  190637. ->outputEnumProc (lpGUID, String (description));
  190638. }
  190639. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190640. {
  190641. return ((DSoundAudioIODeviceType*) object)
  190642. ->outputEnumProc (lpGUID, String (description));
  190643. }
  190644. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190645. {
  190646. desc = desc.trim();
  190647. if (desc.isNotEmpty())
  190648. {
  190649. const String origDesc (desc);
  190650. int n = 2;
  190651. while (inputDeviceNames.contains (desc))
  190652. desc = origDesc + " (" + String (n++) + ")";
  190653. inputDeviceNames.add (desc);
  190654. if (lpGUID != 0)
  190655. inputGuids.add (new GUID (*lpGUID));
  190656. else
  190657. inputGuids.add (0);
  190658. }
  190659. return TRUE;
  190660. }
  190661. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190662. {
  190663. return ((DSoundAudioIODeviceType*) object)
  190664. ->inputEnumProc (lpGUID, String (description));
  190665. }
  190666. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190667. {
  190668. return ((DSoundAudioIODeviceType*) object)
  190669. ->inputEnumProc (lpGUID, String (description));
  190670. }
  190671. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190672. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190673. };
  190674. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190675. const BigInteger& outputChannels,
  190676. double sampleRate_,
  190677. int bufferSizeSamples_)
  190678. {
  190679. closeDevice();
  190680. totalSamplesOut = 0;
  190681. sampleRate = sampleRate_;
  190682. if (bufferSizeSamples_ <= 0)
  190683. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190684. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190685. DSoundAudioIODeviceType dlh;
  190686. dlh.scanForDevices();
  190687. enabledInputs = inputChannels;
  190688. enabledInputs.setRange (inChannels.size(),
  190689. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190690. false);
  190691. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190692. inputBuffers.calloc (numInputBuffers + 2);
  190693. int i, numIns = 0;
  190694. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190695. {
  190696. float* left = 0;
  190697. float* right = 0;
  190698. if (enabledInputs[i])
  190699. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190700. if (enabledInputs[i + 1])
  190701. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190702. if (left != 0 || right != 0)
  190703. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190704. dlh.inputGuids [inputDeviceIndex],
  190705. (int) sampleRate, bufferSizeSamples,
  190706. left, right));
  190707. }
  190708. enabledOutputs = outputChannels;
  190709. enabledOutputs.setRange (outChannels.size(),
  190710. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190711. false);
  190712. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190713. outputBuffers.calloc (numOutputBuffers + 2);
  190714. int numOuts = 0;
  190715. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190716. {
  190717. float* left = 0;
  190718. float* right = 0;
  190719. if (enabledOutputs[i])
  190720. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190721. if (enabledOutputs[i + 1])
  190722. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190723. if (left != 0 || right != 0)
  190724. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190725. dlh.outputGuids [outputDeviceIndex],
  190726. (int) sampleRate, bufferSizeSamples,
  190727. left, right));
  190728. }
  190729. String error;
  190730. // boost our priority while opening the devices to try to get better sync between them
  190731. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190732. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190733. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190734. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190735. for (i = 0; i < outChans.size(); ++i)
  190736. {
  190737. error = outChans[i]->open();
  190738. if (error.isNotEmpty())
  190739. {
  190740. error = "Error opening " + dlh.outputDeviceNames[i] + ": \"" + error + "\"";
  190741. break;
  190742. }
  190743. }
  190744. if (error.isEmpty())
  190745. {
  190746. for (i = 0; i < inChans.size(); ++i)
  190747. {
  190748. error = inChans[i]->open();
  190749. if (error.isNotEmpty())
  190750. {
  190751. error = "Error opening " + dlh.inputDeviceNames[i] + ": \"" + error + "\"";
  190752. break;
  190753. }
  190754. }
  190755. }
  190756. if (error.isEmpty())
  190757. {
  190758. totalSamplesOut = 0;
  190759. for (i = 0; i < outChans.size(); ++i)
  190760. outChans.getUnchecked(i)->synchronisePosition();
  190761. for (i = 0; i < inChans.size(); ++i)
  190762. inChans.getUnchecked(i)->synchronisePosition();
  190763. startThread (9);
  190764. sleep (10);
  190765. notify();
  190766. }
  190767. else
  190768. {
  190769. log (error);
  190770. }
  190771. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  190772. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  190773. return error;
  190774. }
  190775. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  190776. {
  190777. return new DSoundAudioIODeviceType();
  190778. }
  190779. #undef log
  190780. #endif
  190781. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  190782. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  190783. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190784. // compiled on its own).
  190785. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  190786. #if 1
  190787. const String getAudioErrorDesc (HRESULT hr)
  190788. {
  190789. const char* e = 0;
  190790. switch (hr)
  190791. {
  190792. case E_POINTER: e = "E_POINTER"; break;
  190793. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  190794. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  190795. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  190796. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  190797. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  190798. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  190799. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  190800. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  190801. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  190802. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  190803. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  190804. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  190805. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  190806. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  190807. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  190808. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  190809. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  190810. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  190811. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  190812. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  190813. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  190814. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  190815. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  190816. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  190817. default: return String::toHexString ((int) hr);
  190818. }
  190819. return e;
  190820. }
  190821. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  190822. #define OK(a) wasapi_checkResult(a)
  190823. static bool wasapi_checkResult (HRESULT hr)
  190824. {
  190825. logFailure (hr);
  190826. return SUCCEEDED (hr);
  190827. }
  190828. #else
  190829. #define logFailure(hr) {}
  190830. #define OK(a) SUCCEEDED(a)
  190831. #endif
  190832. static const String wasapi_getDeviceID (IMMDevice* const device)
  190833. {
  190834. String s;
  190835. WCHAR* deviceId = 0;
  190836. if (OK (device->GetId (&deviceId)))
  190837. {
  190838. s = String (deviceId);
  190839. CoTaskMemFree (deviceId);
  190840. }
  190841. return s;
  190842. }
  190843. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  190844. {
  190845. EDataFlow flow = eRender;
  190846. ComSmartPtr <IMMEndpoint> endPoint;
  190847. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  190848. (void) OK (endPoint->GetDataFlow (&flow));
  190849. return flow;
  190850. }
  190851. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  190852. {
  190853. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  190854. }
  190855. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  190856. {
  190857. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  190858. : sizeof (WAVEFORMATEX));
  190859. }
  190860. class WASAPIDeviceBase
  190861. {
  190862. public:
  190863. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190864. : device (device_),
  190865. sampleRate (0),
  190866. numChannels (0),
  190867. actualNumChannels (0),
  190868. defaultSampleRate (0),
  190869. minBufferSize (0),
  190870. defaultBufferSize (0),
  190871. latencySamples (0),
  190872. useExclusiveMode (useExclusiveMode_)
  190873. {
  190874. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  190875. ComSmartPtr <IAudioClient> tempClient (createClient());
  190876. if (tempClient == 0)
  190877. return;
  190878. REFERENCE_TIME defaultPeriod, minPeriod;
  190879. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  190880. return;
  190881. WAVEFORMATEX* mixFormat = 0;
  190882. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  190883. return;
  190884. WAVEFORMATEXTENSIBLE format;
  190885. wasapi_copyWavFormat (format, mixFormat);
  190886. CoTaskMemFree (mixFormat);
  190887. actualNumChannels = numChannels = format.Format.nChannels;
  190888. defaultSampleRate = format.Format.nSamplesPerSec;
  190889. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  190890. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  190891. FloatElementComparator<double> comparator;
  190892. rates.addSorted (comparator, defaultSampleRate);
  190893. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190894. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  190895. {
  190896. if (ratesToTest[i] == defaultSampleRate)
  190897. continue;
  190898. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  190899. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  190900. (WAVEFORMATEX*) &format, 0)))
  190901. if (! rates.contains (ratesToTest[i]))
  190902. rates.addSorted (comparator, ratesToTest[i]);
  190903. }
  190904. }
  190905. ~WASAPIDeviceBase()
  190906. {
  190907. device = 0;
  190908. CloseHandle (clientEvent);
  190909. }
  190910. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  190911. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  190912. {
  190913. sampleRate = newSampleRate;
  190914. channels = newChannels;
  190915. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  190916. numChannels = channels.getHighestBit() + 1;
  190917. if (numChannels == 0)
  190918. return true;
  190919. client = createClient();
  190920. if (client != 0
  190921. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  190922. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  190923. {
  190924. channelMaps.clear();
  190925. for (int i = 0; i <= channels.getHighestBit(); ++i)
  190926. if (channels[i])
  190927. channelMaps.add (i);
  190928. REFERENCE_TIME latency;
  190929. if (OK (client->GetStreamLatency (&latency)))
  190930. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  190931. (void) OK (client->GetBufferSize (&actualBufferSize));
  190932. return OK (client->SetEventHandle (clientEvent));
  190933. }
  190934. return false;
  190935. }
  190936. void closeClient()
  190937. {
  190938. if (client != 0)
  190939. client->Stop();
  190940. client = 0;
  190941. ResetEvent (clientEvent);
  190942. }
  190943. ComSmartPtr <IMMDevice> device;
  190944. ComSmartPtr <IAudioClient> client;
  190945. double sampleRate, defaultSampleRate;
  190946. int numChannels, actualNumChannels;
  190947. int minBufferSize, defaultBufferSize, latencySamples;
  190948. const bool useExclusiveMode;
  190949. Array <double> rates;
  190950. HANDLE clientEvent;
  190951. BigInteger channels;
  190952. AudioDataConverters::DataFormat dataFormat;
  190953. Array <int> channelMaps;
  190954. UINT32 actualBufferSize;
  190955. int bytesPerSample;
  190956. private:
  190957. const ComSmartPtr <IAudioClient> createClient()
  190958. {
  190959. ComSmartPtr <IAudioClient> client;
  190960. if (device != 0)
  190961. {
  190962. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  190963. logFailure (hr);
  190964. }
  190965. return client;
  190966. }
  190967. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  190968. {
  190969. WAVEFORMATEXTENSIBLE format;
  190970. zerostruct (format);
  190971. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  190972. {
  190973. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  190974. }
  190975. else
  190976. {
  190977. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  190978. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  190979. }
  190980. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  190981. format.Format.nChannels = (WORD) numChannels;
  190982. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  190983. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  190984. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  190985. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  190986. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  190987. switch (numChannels)
  190988. {
  190989. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  190990. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  190991. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  190992. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  190993. case 8: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER; break;
  190994. default: break;
  190995. }
  190996. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  190997. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  190998. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  190999. logFailure (hr);
  191000. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191001. {
  191002. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191003. hr = S_OK;
  191004. }
  191005. CoTaskMemFree (nearestFormat);
  191006. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191007. if (useExclusiveMode)
  191008. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191009. GUID session;
  191010. if (hr == S_OK
  191011. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191012. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191013. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191014. {
  191015. actualNumChannels = format.Format.nChannels;
  191016. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191017. bytesPerSample = format.Format.wBitsPerSample / 8;
  191018. dataFormat = isFloat ? AudioDataConverters::float32LE
  191019. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191020. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191021. : AudioDataConverters::int16LE)));
  191022. return true;
  191023. }
  191024. return false;
  191025. }
  191026. };
  191027. class WASAPIInputDevice : public WASAPIDeviceBase
  191028. {
  191029. public:
  191030. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191031. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191032. reservoir (1, 1)
  191033. {
  191034. }
  191035. ~WASAPIInputDevice()
  191036. {
  191037. close();
  191038. }
  191039. bool open (const double newSampleRate, const BigInteger& newChannels)
  191040. {
  191041. reservoirSize = 0;
  191042. reservoirCapacity = 16384;
  191043. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191044. return openClient (newSampleRate, newChannels)
  191045. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191046. }
  191047. void close()
  191048. {
  191049. closeClient();
  191050. captureClient = 0;
  191051. reservoir.setSize (0);
  191052. }
  191053. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191054. {
  191055. if (numChannels <= 0)
  191056. return;
  191057. int offset = 0;
  191058. while (bufferSize > 0)
  191059. {
  191060. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191061. {
  191062. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191063. for (int i = 0; i < numDestBuffers; ++i)
  191064. {
  191065. float* const dest = destBuffers[i] + offset;
  191066. const int srcChan = channelMaps.getUnchecked(i);
  191067. switch (dataFormat)
  191068. {
  191069. case AudioDataConverters::float32LE:
  191070. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191071. break;
  191072. case AudioDataConverters::int32LE:
  191073. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191074. break;
  191075. case AudioDataConverters::int24LE:
  191076. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191077. break;
  191078. case AudioDataConverters::int16LE:
  191079. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191080. break;
  191081. default: jassertfalse; break;
  191082. }
  191083. }
  191084. bufferSize -= samplesToDo;
  191085. offset += samplesToDo;
  191086. reservoirSize -= samplesToDo;
  191087. }
  191088. else
  191089. {
  191090. UINT32 packetLength = 0;
  191091. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191092. break;
  191093. if (packetLength == 0)
  191094. {
  191095. if (thread.threadShouldExit())
  191096. break;
  191097. Thread::sleep (1);
  191098. continue;
  191099. }
  191100. uint8* inputData = 0;
  191101. UINT32 numSamplesAvailable;
  191102. DWORD flags;
  191103. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191104. {
  191105. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191106. for (int i = 0; i < numDestBuffers; ++i)
  191107. {
  191108. float* const dest = destBuffers[i] + offset;
  191109. const int srcChan = channelMaps.getUnchecked(i);
  191110. switch (dataFormat)
  191111. {
  191112. case AudioDataConverters::float32LE:
  191113. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191114. break;
  191115. case AudioDataConverters::int32LE:
  191116. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191117. break;
  191118. case AudioDataConverters::int24LE:
  191119. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191120. break;
  191121. case AudioDataConverters::int16LE:
  191122. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191123. break;
  191124. default: jassertfalse; break;
  191125. }
  191126. }
  191127. bufferSize -= samplesToDo;
  191128. offset += samplesToDo;
  191129. if (samplesToDo < (int) numSamplesAvailable)
  191130. {
  191131. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191132. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191133. bytesPerSample * actualNumChannels * reservoirSize);
  191134. }
  191135. captureClient->ReleaseBuffer (numSamplesAvailable);
  191136. }
  191137. }
  191138. }
  191139. }
  191140. ComSmartPtr <IAudioCaptureClient> captureClient;
  191141. MemoryBlock reservoir;
  191142. int reservoirSize, reservoirCapacity;
  191143. };
  191144. class WASAPIOutputDevice : public WASAPIDeviceBase
  191145. {
  191146. public:
  191147. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191148. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191149. {
  191150. }
  191151. ~WASAPIOutputDevice()
  191152. {
  191153. close();
  191154. }
  191155. bool open (const double newSampleRate, const BigInteger& newChannels)
  191156. {
  191157. return openClient (newSampleRate, newChannels)
  191158. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191159. }
  191160. void close()
  191161. {
  191162. closeClient();
  191163. renderClient = 0;
  191164. }
  191165. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191166. {
  191167. if (numChannels <= 0)
  191168. return;
  191169. int offset = 0;
  191170. while (bufferSize > 0)
  191171. {
  191172. UINT32 padding = 0;
  191173. if (! OK (client->GetCurrentPadding (&padding)))
  191174. return;
  191175. int samplesToDo = useExclusiveMode ? bufferSize
  191176. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191177. if (samplesToDo <= 0)
  191178. {
  191179. if (thread.threadShouldExit())
  191180. break;
  191181. Thread::sleep (0);
  191182. continue;
  191183. }
  191184. uint8* outputData = 0;
  191185. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191186. {
  191187. for (int i = 0; i < numSrcBuffers; ++i)
  191188. {
  191189. const float* const source = srcBuffers[i] + offset;
  191190. const int destChan = channelMaps.getUnchecked(i);
  191191. switch (dataFormat)
  191192. {
  191193. case AudioDataConverters::float32LE:
  191194. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191195. break;
  191196. case AudioDataConverters::int32LE:
  191197. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191198. break;
  191199. case AudioDataConverters::int24LE:
  191200. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191201. break;
  191202. case AudioDataConverters::int16LE:
  191203. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191204. break;
  191205. default: jassertfalse; break;
  191206. }
  191207. }
  191208. renderClient->ReleaseBuffer (samplesToDo, 0);
  191209. offset += samplesToDo;
  191210. bufferSize -= samplesToDo;
  191211. }
  191212. }
  191213. }
  191214. ComSmartPtr <IAudioRenderClient> renderClient;
  191215. };
  191216. class WASAPIAudioIODevice : public AudioIODevice,
  191217. public Thread
  191218. {
  191219. public:
  191220. WASAPIAudioIODevice (const String& deviceName,
  191221. const String& outputDeviceId_,
  191222. const String& inputDeviceId_,
  191223. const bool useExclusiveMode_)
  191224. : AudioIODevice (deviceName, "Windows Audio"),
  191225. Thread ("Juce WASAPI"),
  191226. isOpen_ (false),
  191227. isStarted (false),
  191228. outputDevice (0),
  191229. outputDeviceId (outputDeviceId_),
  191230. inputDevice (0),
  191231. inputDeviceId (inputDeviceId_),
  191232. useExclusiveMode (useExclusiveMode_),
  191233. currentBufferSizeSamples (0),
  191234. currentSampleRate (0),
  191235. callback (0)
  191236. {
  191237. }
  191238. ~WASAPIAudioIODevice()
  191239. {
  191240. close();
  191241. deleteAndZero (inputDevice);
  191242. deleteAndZero (outputDevice);
  191243. }
  191244. bool initialise()
  191245. {
  191246. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191247. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191248. latencyIn = latencyOut = 0;
  191249. Array <double> ratesIn, ratesOut;
  191250. if (createDevices())
  191251. {
  191252. jassert (inputDevice != 0 || outputDevice != 0);
  191253. if (inputDevice != 0 && outputDevice != 0)
  191254. {
  191255. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191256. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191257. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191258. sampleRates = inputDevice->rates;
  191259. sampleRates.removeValuesNotIn (outputDevice->rates);
  191260. }
  191261. else
  191262. {
  191263. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191264. defaultSampleRate = d->defaultSampleRate;
  191265. minBufferSize = d->minBufferSize;
  191266. defaultBufferSize = d->defaultBufferSize;
  191267. sampleRates = d->rates;
  191268. }
  191269. IntegerElementComparator<int> comparator;
  191270. bufferSizes.addSorted (comparator, defaultBufferSize);
  191271. if (minBufferSize != defaultBufferSize)
  191272. bufferSizes.addSorted (comparator, minBufferSize);
  191273. int n = 64;
  191274. for (int i = 0; i < 40; ++i)
  191275. {
  191276. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191277. bufferSizes.addSorted (comparator, n);
  191278. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191279. }
  191280. return true;
  191281. }
  191282. return false;
  191283. }
  191284. const StringArray getOutputChannelNames()
  191285. {
  191286. StringArray outChannels;
  191287. if (outputDevice != 0)
  191288. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191289. outChannels.add ("Output channel " + String (i));
  191290. return outChannels;
  191291. }
  191292. const StringArray getInputChannelNames()
  191293. {
  191294. StringArray inChannels;
  191295. if (inputDevice != 0)
  191296. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191297. inChannels.add ("Input channel " + String (i));
  191298. return inChannels;
  191299. }
  191300. int getNumSampleRates() { return sampleRates.size(); }
  191301. double getSampleRate (int index) { return sampleRates [index]; }
  191302. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191303. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191304. int getDefaultBufferSize() { return defaultBufferSize; }
  191305. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191306. double getCurrentSampleRate() { return currentSampleRate; }
  191307. int getCurrentBitDepth() { return 32; }
  191308. int getOutputLatencyInSamples() { return latencyOut; }
  191309. int getInputLatencyInSamples() { return latencyIn; }
  191310. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191311. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191312. const String getLastError() { return lastError; }
  191313. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191314. double sampleRate, int bufferSizeSamples)
  191315. {
  191316. close();
  191317. lastError = String::empty;
  191318. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191319. {
  191320. lastError = "The input and output devices don't share a common sample rate!";
  191321. return lastError;
  191322. }
  191323. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191324. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191325. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191326. {
  191327. lastError = "Couldn't open the input device!";
  191328. return lastError;
  191329. }
  191330. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191331. {
  191332. close();
  191333. lastError = "Couldn't open the output device!";
  191334. return lastError;
  191335. }
  191336. if (inputDevice != 0)
  191337. ResetEvent (inputDevice->clientEvent);
  191338. if (outputDevice != 0)
  191339. ResetEvent (outputDevice->clientEvent);
  191340. startThread (8);
  191341. Thread::sleep (5);
  191342. if (inputDevice != 0 && inputDevice->client != 0)
  191343. {
  191344. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191345. HRESULT hr = inputDevice->client->Start();
  191346. logFailure (hr); //xxx handle this
  191347. }
  191348. if (outputDevice != 0 && outputDevice->client != 0)
  191349. {
  191350. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191351. HRESULT hr = outputDevice->client->Start();
  191352. logFailure (hr); //xxx handle this
  191353. }
  191354. isOpen_ = true;
  191355. return lastError;
  191356. }
  191357. void close()
  191358. {
  191359. stop();
  191360. if (inputDevice != 0)
  191361. SetEvent (inputDevice->clientEvent);
  191362. if (outputDevice != 0)
  191363. SetEvent (outputDevice->clientEvent);
  191364. stopThread (5000);
  191365. if (inputDevice != 0)
  191366. inputDevice->close();
  191367. if (outputDevice != 0)
  191368. outputDevice->close();
  191369. isOpen_ = false;
  191370. }
  191371. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191372. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191373. void start (AudioIODeviceCallback* call)
  191374. {
  191375. if (isOpen_ && call != 0 && ! isStarted)
  191376. {
  191377. if (! isThreadRunning())
  191378. {
  191379. // something's gone wrong and the thread's stopped..
  191380. isOpen_ = false;
  191381. return;
  191382. }
  191383. call->audioDeviceAboutToStart (this);
  191384. const ScopedLock sl (startStopLock);
  191385. callback = call;
  191386. isStarted = true;
  191387. }
  191388. }
  191389. void stop()
  191390. {
  191391. if (isStarted)
  191392. {
  191393. AudioIODeviceCallback* const callbackLocal = callback;
  191394. {
  191395. const ScopedLock sl (startStopLock);
  191396. isStarted = false;
  191397. }
  191398. if (callbackLocal != 0)
  191399. callbackLocal->audioDeviceStopped();
  191400. }
  191401. }
  191402. void setMMThreadPriority()
  191403. {
  191404. DynamicLibraryLoader dll ("avrt.dll");
  191405. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191406. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191407. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191408. {
  191409. DWORD dummy = 0;
  191410. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191411. if (h != 0)
  191412. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191413. }
  191414. }
  191415. void run()
  191416. {
  191417. setMMThreadPriority();
  191418. const int bufferSize = currentBufferSizeSamples;
  191419. HANDLE events[2];
  191420. int numEvents = 0;
  191421. if (inputDevice != 0)
  191422. events [numEvents++] = inputDevice->clientEvent;
  191423. if (outputDevice != 0)
  191424. events [numEvents++] = outputDevice->clientEvent;
  191425. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191426. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191427. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191428. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191429. float** const inputBuffers = ins.getArrayOfChannels();
  191430. float** const outputBuffers = outs.getArrayOfChannels();
  191431. ins.clear();
  191432. while (! threadShouldExit())
  191433. {
  191434. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191435. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191436. if (result == WAIT_TIMEOUT)
  191437. continue;
  191438. if (threadShouldExit())
  191439. break;
  191440. if (inputDevice != 0)
  191441. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191442. // Make the callback..
  191443. {
  191444. const ScopedLock sl (startStopLock);
  191445. if (isStarted)
  191446. {
  191447. JUCE_TRY
  191448. {
  191449. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191450. numInputBuffers,
  191451. outputBuffers,
  191452. numOutputBuffers,
  191453. bufferSize);
  191454. }
  191455. JUCE_CATCH_EXCEPTION
  191456. }
  191457. else
  191458. {
  191459. outs.clear();
  191460. }
  191461. }
  191462. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191463. continue;
  191464. if (outputDevice != 0)
  191465. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191466. }
  191467. }
  191468. juce_UseDebuggingNewOperator
  191469. String outputDeviceId, inputDeviceId;
  191470. String lastError;
  191471. private:
  191472. // Device stats...
  191473. WASAPIInputDevice* inputDevice;
  191474. WASAPIOutputDevice* outputDevice;
  191475. const bool useExclusiveMode;
  191476. double defaultSampleRate;
  191477. int minBufferSize, defaultBufferSize;
  191478. int latencyIn, latencyOut;
  191479. Array <double> sampleRates;
  191480. Array <int> bufferSizes;
  191481. // Active state...
  191482. bool isOpen_, isStarted;
  191483. int currentBufferSizeSamples;
  191484. double currentSampleRate;
  191485. AudioIODeviceCallback* callback;
  191486. CriticalSection startStopLock;
  191487. bool createDevices()
  191488. {
  191489. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191490. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191491. return false;
  191492. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191493. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191494. return false;
  191495. UINT32 numDevices = 0;
  191496. if (! OK (deviceCollection->GetCount (&numDevices)))
  191497. return false;
  191498. for (UINT32 i = 0; i < numDevices; ++i)
  191499. {
  191500. ComSmartPtr <IMMDevice> device;
  191501. if (! OK (deviceCollection->Item (i, &device)))
  191502. continue;
  191503. const String deviceId (wasapi_getDeviceID (device));
  191504. if (deviceId.isEmpty())
  191505. continue;
  191506. const EDataFlow flow = wasapi_getDataFlow (device);
  191507. if (deviceId == inputDeviceId && flow == eCapture)
  191508. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191509. else if (deviceId == outputDeviceId && flow == eRender)
  191510. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191511. }
  191512. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191513. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191514. }
  191515. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191516. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191517. };
  191518. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191519. {
  191520. public:
  191521. WASAPIAudioIODeviceType()
  191522. : AudioIODeviceType ("Windows Audio"),
  191523. hasScanned (false)
  191524. {
  191525. }
  191526. ~WASAPIAudioIODeviceType()
  191527. {
  191528. }
  191529. void scanForDevices()
  191530. {
  191531. hasScanned = true;
  191532. outputDeviceNames.clear();
  191533. inputDeviceNames.clear();
  191534. outputDeviceIds.clear();
  191535. inputDeviceIds.clear();
  191536. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191537. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191538. return;
  191539. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191540. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191541. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191542. UINT32 numDevices = 0;
  191543. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191544. && OK (deviceCollection->GetCount (&numDevices))))
  191545. return;
  191546. for (UINT32 i = 0; i < numDevices; ++i)
  191547. {
  191548. ComSmartPtr <IMMDevice> device;
  191549. if (! OK (deviceCollection->Item (i, &device)))
  191550. continue;
  191551. const String deviceId (wasapi_getDeviceID (device));
  191552. DWORD state = 0;
  191553. if (! OK (device->GetState (&state)))
  191554. continue;
  191555. if (state != DEVICE_STATE_ACTIVE)
  191556. continue;
  191557. String name;
  191558. {
  191559. ComSmartPtr <IPropertyStore> properties;
  191560. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191561. continue;
  191562. PROPVARIANT value;
  191563. PropVariantInit (&value);
  191564. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191565. name = value.pwszVal;
  191566. PropVariantClear (&value);
  191567. }
  191568. const EDataFlow flow = wasapi_getDataFlow (device);
  191569. if (flow == eRender)
  191570. {
  191571. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191572. outputDeviceIds.insert (index, deviceId);
  191573. outputDeviceNames.insert (index, name);
  191574. }
  191575. else if (flow == eCapture)
  191576. {
  191577. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191578. inputDeviceIds.insert (index, deviceId);
  191579. inputDeviceNames.insert (index, name);
  191580. }
  191581. }
  191582. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191583. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191584. }
  191585. const StringArray getDeviceNames (bool wantInputNames) const
  191586. {
  191587. jassert (hasScanned); // need to call scanForDevices() before doing this
  191588. return wantInputNames ? inputDeviceNames
  191589. : outputDeviceNames;
  191590. }
  191591. int getDefaultDeviceIndex (bool /*forInput*/) const
  191592. {
  191593. jassert (hasScanned); // need to call scanForDevices() before doing this
  191594. return 0;
  191595. }
  191596. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  191597. {
  191598. jassert (hasScanned); // need to call scanForDevices() before doing this
  191599. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191600. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191601. : outputDeviceIds.indexOf (d->outputDeviceId));
  191602. }
  191603. bool hasSeparateInputsAndOutputs() const { return true; }
  191604. AudioIODevice* createDevice (const String& outputDeviceName,
  191605. const String& inputDeviceName)
  191606. {
  191607. jassert (hasScanned); // need to call scanForDevices() before doing this
  191608. const bool useExclusiveMode = false;
  191609. ScopedPointer<WASAPIAudioIODevice> device;
  191610. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191611. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191612. if (outputIndex >= 0 || inputIndex >= 0)
  191613. {
  191614. device = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191615. : inputDeviceName,
  191616. outputDeviceIds [outputIndex],
  191617. inputDeviceIds [inputIndex],
  191618. useExclusiveMode);
  191619. if (! device->initialise())
  191620. device = 0;
  191621. }
  191622. return device.release();
  191623. }
  191624. juce_UseDebuggingNewOperator
  191625. StringArray outputDeviceNames, outputDeviceIds;
  191626. StringArray inputDeviceNames, inputDeviceIds;
  191627. private:
  191628. bool hasScanned;
  191629. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191630. {
  191631. String s;
  191632. IMMDevice* dev = 0;
  191633. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191634. eMultimedia, &dev)))
  191635. {
  191636. WCHAR* deviceId = 0;
  191637. if (OK (dev->GetId (&deviceId)))
  191638. {
  191639. s = String (deviceId);
  191640. CoTaskMemFree (deviceId);
  191641. }
  191642. dev->Release();
  191643. }
  191644. return s;
  191645. }
  191646. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191647. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191648. };
  191649. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191650. {
  191651. return new WASAPIAudioIODeviceType();
  191652. }
  191653. #undef logFailure
  191654. #undef OK
  191655. #endif
  191656. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191657. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191658. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191659. // compiled on its own).
  191660. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191661. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191662. {
  191663. public:
  191664. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191665. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191666. const ComSmartPtr <IBaseFilter>& filter_,
  191667. int minWidth, int minHeight,
  191668. int maxWidth, int maxHeight)
  191669. : owner (owner_),
  191670. captureGraphBuilder (captureGraphBuilder_),
  191671. filter (filter_),
  191672. ok (false),
  191673. imageNeedsFlipping (false),
  191674. width (0),
  191675. height (0),
  191676. activeUsers (0),
  191677. recordNextFrameTime (false),
  191678. activeImage (0),
  191679. loadingImage (0)
  191680. {
  191681. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191682. if (FAILED (hr))
  191683. return;
  191684. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191685. if (FAILED (hr))
  191686. return;
  191687. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191688. if (FAILED (hr))
  191689. return;
  191690. {
  191691. ComSmartPtr <IAMStreamConfig> streamConfig;
  191692. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191693. IID_IAMStreamConfig, (void**) &streamConfig);
  191694. if (streamConfig != 0)
  191695. {
  191696. getVideoSizes (streamConfig);
  191697. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191698. return;
  191699. }
  191700. }
  191701. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191702. if (FAILED (hr))
  191703. return;
  191704. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191705. if (FAILED (hr))
  191706. return;
  191707. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191708. if (FAILED (hr))
  191709. return;
  191710. if (! connectFilters (filter, smartTee))
  191711. return;
  191712. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191713. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191714. if (FAILED (hr))
  191715. return;
  191716. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191717. if (FAILED (hr))
  191718. return;
  191719. AM_MEDIA_TYPE mt;
  191720. zerostruct (mt);
  191721. mt.majortype = MEDIATYPE_Video;
  191722. mt.subtype = MEDIASUBTYPE_RGB24;
  191723. mt.formattype = FORMAT_VideoInfo;
  191724. sampleGrabber->SetMediaType (&mt);
  191725. callback = new GrabberCallback (*this);
  191726. sampleGrabber->SetCallback (callback, 1);
  191727. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191728. if (FAILED (hr))
  191729. return;
  191730. ComSmartPtr <IPin> grabberInputPin;
  191731. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191732. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191733. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191734. return;
  191735. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191736. if (FAILED (hr))
  191737. return;
  191738. zerostruct (mt);
  191739. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191740. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191741. width = pVih->bmiHeader.biWidth;
  191742. height = pVih->bmiHeader.biHeight;
  191743. ComSmartPtr <IBaseFilter> nullFilter;
  191744. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  191745. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191746. if (connectFilters (sampleGrabberBase, nullFilter)
  191747. && addGraphToRot())
  191748. {
  191749. activeImage = new Image (Image::RGB, width, height, true);
  191750. loadingImage = new Image (Image::RGB, width, height, true);
  191751. ok = true;
  191752. }
  191753. }
  191754. ~DShowCameraDeviceInteral()
  191755. {
  191756. if (mediaControl != 0)
  191757. mediaControl->Stop();
  191758. removeGraphFromRot();
  191759. for (int i = viewerComps.size(); --i >= 0;)
  191760. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191761. callback = 0;
  191762. graphBuilder = 0;
  191763. sampleGrabber = 0;
  191764. mediaControl = 0;
  191765. filter = 0;
  191766. captureGraphBuilder = 0;
  191767. smartTee = 0;
  191768. smartTeePreviewOutputPin = 0;
  191769. smartTeeCaptureOutputPin = 0;
  191770. asfWriter = 0;
  191771. delete activeImage;
  191772. delete loadingImage;
  191773. }
  191774. void addUser()
  191775. {
  191776. if (ok && activeUsers++ == 0)
  191777. mediaControl->Run();
  191778. }
  191779. void removeUser()
  191780. {
  191781. if (ok && --activeUsers == 0)
  191782. mediaControl->Stop();
  191783. }
  191784. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  191785. {
  191786. if (recordNextFrameTime)
  191787. {
  191788. const double defaultCameraLatency = 0.1;
  191789. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  191790. recordNextFrameTime = false;
  191791. ComSmartPtr <IPin> pin;
  191792. if (getPin (filter, PINDIR_OUTPUT, &pin))
  191793. {
  191794. ComSmartPtr <IAMPushSource> pushSource;
  191795. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  191796. if (pushSource != 0)
  191797. {
  191798. REFERENCE_TIME latency = 0;
  191799. hr = pushSource->GetLatency (&latency);
  191800. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  191801. }
  191802. }
  191803. }
  191804. {
  191805. const int lineStride = width * 3;
  191806. const ScopedLock sl (imageSwapLock);
  191807. {
  191808. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  191809. for (int i = 0; i < height; ++i)
  191810. memcpy (destData.getLinePointer ((height - 1) - i),
  191811. buffer + lineStride * i,
  191812. lineStride);
  191813. }
  191814. imageNeedsFlipping = true;
  191815. }
  191816. if (listeners.size() > 0)
  191817. callListeners (*loadingImage);
  191818. sendChangeMessage (this);
  191819. }
  191820. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  191821. {
  191822. if (imageNeedsFlipping)
  191823. {
  191824. const ScopedLock sl (imageSwapLock);
  191825. swapVariables (loadingImage, activeImage);
  191826. imageNeedsFlipping = false;
  191827. }
  191828. RectanglePlacement rp (RectanglePlacement::centred);
  191829. double dx = 0, dy = 0, dw = width, dh = height;
  191830. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  191831. const int rx = roundToInt (dx), ry = roundToInt (dy);
  191832. const int rw = roundToInt (dw), rh = roundToInt (dh);
  191833. g.saveState();
  191834. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  191835. g.fillAll (Colours::black);
  191836. g.restoreState();
  191837. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  191838. }
  191839. bool createFileCaptureFilter (const File& file)
  191840. {
  191841. removeFileCaptureFilter();
  191842. file.deleteFile();
  191843. mediaControl->Stop();
  191844. firstRecordedTime = Time();
  191845. recordNextFrameTime = true;
  191846. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  191847. if (SUCCEEDED (hr))
  191848. {
  191849. ComSmartPtr <IFileSinkFilter> fileSink;
  191850. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  191851. if (SUCCEEDED (hr))
  191852. {
  191853. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  191854. if (SUCCEEDED (hr))
  191855. {
  191856. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  191857. if (SUCCEEDED (hr))
  191858. {
  191859. ComSmartPtr <IConfigAsfWriter> asfConfig;
  191860. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  191861. asfConfig->SetIndexMode (true);
  191862. ComSmartPtr <IWMProfileManager> profileManager;
  191863. hr = WMCreateProfileManager (&profileManager);
  191864. // This gibberish is the DirectShow profile for a video-only wmv file.
  191865. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  191866. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  191867. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  191868. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  191869. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  191870. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  191871. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  191872. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  191873. prof = prof.replace ("$WIDTH", String (width))
  191874. .replace ("$HEIGHT", String (height));
  191875. ComSmartPtr <IWMProfile> currentProfile;
  191876. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  191877. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  191878. if (SUCCEEDED (hr))
  191879. {
  191880. ComSmartPtr <IPin> asfWriterInputPin;
  191881. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  191882. {
  191883. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  191884. if (SUCCEEDED (hr)
  191885. && ok && activeUsers > 0
  191886. && SUCCEEDED (mediaControl->Run()))
  191887. {
  191888. return true;
  191889. }
  191890. }
  191891. }
  191892. }
  191893. }
  191894. }
  191895. }
  191896. removeFileCaptureFilter();
  191897. if (ok && activeUsers > 0)
  191898. mediaControl->Run();
  191899. return false;
  191900. }
  191901. void removeFileCaptureFilter()
  191902. {
  191903. mediaControl->Stop();
  191904. if (asfWriter != 0)
  191905. {
  191906. graphBuilder->RemoveFilter (asfWriter);
  191907. asfWriter = 0;
  191908. }
  191909. if (ok && activeUsers > 0)
  191910. mediaControl->Run();
  191911. }
  191912. void addListener (CameraImageListener* listenerToAdd)
  191913. {
  191914. const ScopedLock sl (listenerLock);
  191915. if (listeners.size() == 0)
  191916. addUser();
  191917. listeners.addIfNotAlreadyThere (listenerToAdd);
  191918. }
  191919. void removeListener (CameraImageListener* listenerToRemove)
  191920. {
  191921. const ScopedLock sl (listenerLock);
  191922. listeners.removeValue (listenerToRemove);
  191923. if (listeners.size() == 0)
  191924. removeUser();
  191925. }
  191926. void callListeners (Image& image)
  191927. {
  191928. const ScopedLock sl (listenerLock);
  191929. for (int i = listeners.size(); --i >= 0;)
  191930. {
  191931. CameraImageListener* l = (CameraImageListener*) listeners[i];
  191932. if (l != 0)
  191933. l->imageReceived (image);
  191934. }
  191935. }
  191936. class DShowCaptureViewerComp : public Component,
  191937. public ChangeListener
  191938. {
  191939. public:
  191940. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  191941. : owner (owner_)
  191942. {
  191943. setOpaque (true);
  191944. owner->addChangeListener (this);
  191945. owner->addUser();
  191946. owner->viewerComps.add (this);
  191947. setSize (owner_->width, owner_->height);
  191948. }
  191949. ~DShowCaptureViewerComp()
  191950. {
  191951. if (owner != 0)
  191952. {
  191953. owner->viewerComps.removeValue (this);
  191954. owner->removeUser();
  191955. owner->removeChangeListener (this);
  191956. }
  191957. }
  191958. void ownerDeleted()
  191959. {
  191960. owner = 0;
  191961. }
  191962. void paint (Graphics& g)
  191963. {
  191964. g.setColour (Colours::black);
  191965. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  191966. if (owner != 0)
  191967. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  191968. else
  191969. g.fillAll (Colours::black);
  191970. }
  191971. void changeListenerCallback (void*)
  191972. {
  191973. repaint();
  191974. }
  191975. private:
  191976. DShowCameraDeviceInteral* owner;
  191977. };
  191978. bool ok;
  191979. int width, height;
  191980. Time firstRecordedTime;
  191981. VoidArray viewerComps;
  191982. private:
  191983. CameraDevice* const owner;
  191984. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  191985. ComSmartPtr <IBaseFilter> filter;
  191986. ComSmartPtr <IBaseFilter> smartTee;
  191987. ComSmartPtr <IGraphBuilder> graphBuilder;
  191988. ComSmartPtr <ISampleGrabber> sampleGrabber;
  191989. ComSmartPtr <IMediaControl> mediaControl;
  191990. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  191991. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  191992. ComSmartPtr <IBaseFilter> asfWriter;
  191993. int activeUsers;
  191994. Array <int> widths, heights;
  191995. DWORD graphRegistrationID;
  191996. CriticalSection imageSwapLock;
  191997. bool imageNeedsFlipping;
  191998. Image* loadingImage;
  191999. Image* activeImage;
  192000. bool recordNextFrameTime;
  192001. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192002. {
  192003. widths.clear();
  192004. heights.clear();
  192005. int count = 0, size = 0;
  192006. streamConfig->GetNumberOfCapabilities (&count, &size);
  192007. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192008. {
  192009. for (int i = 0; i < count; ++i)
  192010. {
  192011. VIDEO_STREAM_CONFIG_CAPS scc;
  192012. AM_MEDIA_TYPE* config;
  192013. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192014. if (SUCCEEDED (hr))
  192015. {
  192016. const int w = scc.InputSize.cx;
  192017. const int h = scc.InputSize.cy;
  192018. bool duplicate = false;
  192019. for (int j = widths.size(); --j >= 0;)
  192020. {
  192021. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192022. {
  192023. duplicate = true;
  192024. break;
  192025. }
  192026. }
  192027. if (! duplicate)
  192028. {
  192029. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192030. widths.add (w);
  192031. heights.add (h);
  192032. }
  192033. deleteMediaType (config);
  192034. }
  192035. }
  192036. }
  192037. }
  192038. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192039. const int minWidth, const int minHeight,
  192040. const int maxWidth, const int maxHeight)
  192041. {
  192042. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192043. streamConfig->GetNumberOfCapabilities (&count, &size);
  192044. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192045. {
  192046. AM_MEDIA_TYPE* config;
  192047. VIDEO_STREAM_CONFIG_CAPS scc;
  192048. for (int i = 0; i < count; ++i)
  192049. {
  192050. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192051. if (SUCCEEDED (hr))
  192052. {
  192053. if (scc.InputSize.cx >= minWidth
  192054. && scc.InputSize.cy >= minHeight
  192055. && scc.InputSize.cx <= maxWidth
  192056. && scc.InputSize.cy <= maxHeight)
  192057. {
  192058. int area = scc.InputSize.cx * scc.InputSize.cy;
  192059. if (area > bestArea)
  192060. {
  192061. bestIndex = i;
  192062. bestArea = area;
  192063. }
  192064. }
  192065. deleteMediaType (config);
  192066. }
  192067. }
  192068. if (bestIndex >= 0)
  192069. {
  192070. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192071. hr = streamConfig->SetFormat (config);
  192072. deleteMediaType (config);
  192073. return SUCCEEDED (hr);
  192074. }
  192075. }
  192076. return false;
  192077. }
  192078. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192079. {
  192080. ComSmartPtr <IEnumPins> enumerator;
  192081. ComSmartPtr <IPin> pin;
  192082. filter->EnumPins (&enumerator);
  192083. while (enumerator->Next (1, &pin, 0) == S_OK)
  192084. {
  192085. PIN_DIRECTION dir;
  192086. pin->QueryDirection (&dir);
  192087. if (wantedDirection == dir)
  192088. {
  192089. PIN_INFO info;
  192090. zerostruct (info);
  192091. pin->QueryPinInfo (&info);
  192092. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192093. {
  192094. pin.p->AddRef();
  192095. *result = pin;
  192096. return true;
  192097. }
  192098. }
  192099. }
  192100. return false;
  192101. }
  192102. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192103. {
  192104. ComSmartPtr <IPin> in, out;
  192105. return getPin (first, PINDIR_OUTPUT, &out)
  192106. && getPin (second, PINDIR_INPUT, &in)
  192107. && SUCCEEDED (graphBuilder->Connect (out, in));
  192108. }
  192109. bool addGraphToRot()
  192110. {
  192111. ComSmartPtr <IRunningObjectTable> rot;
  192112. if (FAILED (GetRunningObjectTable (0, &rot)))
  192113. return false;
  192114. ComSmartPtr <IMoniker> moniker;
  192115. WCHAR buffer[128];
  192116. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192117. if (FAILED (hr))
  192118. return false;
  192119. graphRegistrationID = 0;
  192120. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192121. }
  192122. void removeGraphFromRot()
  192123. {
  192124. ComSmartPtr <IRunningObjectTable> rot;
  192125. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192126. rot->Revoke (graphRegistrationID);
  192127. }
  192128. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192129. {
  192130. if (pmt->cbFormat != 0)
  192131. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192132. if (pmt->pUnk != 0)
  192133. pmt->pUnk->Release();
  192134. CoTaskMemFree (pmt);
  192135. }
  192136. class GrabberCallback : public ISampleGrabberCB
  192137. {
  192138. public:
  192139. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192140. : owner (owner_)
  192141. {
  192142. }
  192143. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192144. {
  192145. if (id == IID_IUnknown)
  192146. *result = dynamic_cast <IUnknown*> (this);
  192147. else if (id == IID_ISampleGrabberCB)
  192148. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192149. else
  192150. {
  192151. *result = 0;
  192152. return E_NOINTERFACE;
  192153. }
  192154. AddRef();
  192155. return S_OK;
  192156. }
  192157. ULONG __stdcall AddRef() { return ++refCount; }
  192158. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192159. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192160. {
  192161. return E_FAIL;
  192162. }
  192163. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192164. {
  192165. owner.handleFrame (time, buffer, bufferSize);
  192166. return S_OK;
  192167. }
  192168. private:
  192169. int refCount;
  192170. DShowCameraDeviceInteral& owner;
  192171. GrabberCallback (const GrabberCallback&);
  192172. GrabberCallback& operator= (const GrabberCallback&);
  192173. };
  192174. ComSmartPtr <GrabberCallback> callback;
  192175. VoidArray listeners;
  192176. CriticalSection listenerLock;
  192177. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192178. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192179. };
  192180. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192181. : name (name_)
  192182. {
  192183. isRecording = false;
  192184. }
  192185. CameraDevice::~CameraDevice()
  192186. {
  192187. stopRecording();
  192188. delete (DShowCameraDeviceInteral*) internal;
  192189. internal = 0;
  192190. }
  192191. Component* CameraDevice::createViewerComponent()
  192192. {
  192193. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192194. }
  192195. const String CameraDevice::getFileExtension()
  192196. {
  192197. return ".wmv";
  192198. }
  192199. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192200. {
  192201. stopRecording();
  192202. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192203. d->addUser();
  192204. isRecording = d->createFileCaptureFilter (file);
  192205. }
  192206. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192207. {
  192208. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192209. return d->firstRecordedTime;
  192210. }
  192211. void CameraDevice::stopRecording()
  192212. {
  192213. if (isRecording)
  192214. {
  192215. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192216. d->removeFileCaptureFilter();
  192217. d->removeUser();
  192218. isRecording = false;
  192219. }
  192220. }
  192221. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192222. {
  192223. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192224. if (listenerToAdd != 0)
  192225. d->addListener (listenerToAdd);
  192226. }
  192227. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192228. {
  192229. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192230. if (listenerToRemove != 0)
  192231. d->removeListener (listenerToRemove);
  192232. }
  192233. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192234. const int deviceIndexToOpen,
  192235. String& name)
  192236. {
  192237. int index = 0;
  192238. ComSmartPtr <IBaseFilter> result;
  192239. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192240. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192241. if (SUCCEEDED (hr))
  192242. {
  192243. ComSmartPtr <IEnumMoniker> enumerator;
  192244. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192245. if (SUCCEEDED (hr) && enumerator != 0)
  192246. {
  192247. ComSmartPtr <IBaseFilter> captureFilter;
  192248. ComSmartPtr <IMoniker> moniker;
  192249. ULONG fetched;
  192250. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192251. {
  192252. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192253. if (SUCCEEDED (hr))
  192254. {
  192255. ComSmartPtr <IPropertyBag> propertyBag;
  192256. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192257. if (SUCCEEDED (hr))
  192258. {
  192259. VARIANT var;
  192260. var.vt = VT_BSTR;
  192261. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192262. propertyBag = 0;
  192263. if (SUCCEEDED (hr))
  192264. {
  192265. if (names != 0)
  192266. names->add (var.bstrVal);
  192267. if (index == deviceIndexToOpen)
  192268. {
  192269. name = var.bstrVal;
  192270. result = captureFilter;
  192271. captureFilter = 0;
  192272. break;
  192273. }
  192274. ++index;
  192275. }
  192276. moniker = 0;
  192277. }
  192278. captureFilter = 0;
  192279. }
  192280. }
  192281. }
  192282. }
  192283. return result;
  192284. }
  192285. const StringArray CameraDevice::getAvailableDevices()
  192286. {
  192287. StringArray devs;
  192288. String dummy;
  192289. enumerateCameras (&devs, -1, dummy);
  192290. return devs;
  192291. }
  192292. CameraDevice* CameraDevice::openDevice (int index,
  192293. int minWidth, int minHeight,
  192294. int maxWidth, int maxHeight)
  192295. {
  192296. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192297. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192298. if (SUCCEEDED (hr))
  192299. {
  192300. String name;
  192301. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192302. if (filter != 0)
  192303. {
  192304. CameraDevice* const cam = new CameraDevice (name, index);
  192305. DShowCameraDeviceInteral* const intern
  192306. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192307. minWidth, minHeight, maxWidth, maxHeight);
  192308. cam->internal = intern;
  192309. if (intern->ok)
  192310. return cam;
  192311. else
  192312. delete cam;
  192313. }
  192314. }
  192315. return 0;
  192316. }
  192317. #endif
  192318. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192319. #endif
  192320. // Auto-link the other win32 libs that are needed by library calls..
  192321. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192322. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192323. // Auto-links to various win32 libs that are needed by library calls..
  192324. #pragma comment(lib, "kernel32.lib")
  192325. #pragma comment(lib, "user32.lib")
  192326. #pragma comment(lib, "shell32.lib")
  192327. #pragma comment(lib, "gdi32.lib")
  192328. #pragma comment(lib, "vfw32.lib")
  192329. #pragma comment(lib, "comdlg32.lib")
  192330. #pragma comment(lib, "winmm.lib")
  192331. #pragma comment(lib, "wininet.lib")
  192332. #pragma comment(lib, "ole32.lib")
  192333. #pragma comment(lib, "oleaut32.lib")
  192334. #pragma comment(lib, "advapi32.lib")
  192335. #pragma comment(lib, "ws2_32.lib")
  192336. #pragma comment(lib, "comsupp.lib")
  192337. #pragma comment(lib, "version.lib")
  192338. #if JUCE_OPENGL
  192339. #pragma comment(lib, "OpenGL32.Lib")
  192340. #pragma comment(lib, "GlU32.Lib")
  192341. #endif
  192342. #if JUCE_QUICKTIME
  192343. #pragma comment (lib, "QTMLClient.lib")
  192344. #endif
  192345. #if JUCE_USE_CAMERA
  192346. #pragma comment (lib, "Strmiids.lib")
  192347. #pragma comment (lib, "wmvcore.lib")
  192348. #endif
  192349. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192350. #endif
  192351. END_JUCE_NAMESPACE
  192352. #endif
  192353. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192354. #endif
  192355. #if JUCE_LINUX
  192356. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192357. #if JUCE_LINUX
  192358. BEGIN_JUCE_NAMESPACE
  192359. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192360. #define SUPPORT_AFFINITIES 1
  192361. #endif
  192362. #define JUCE_INCLUDED_FILE 1
  192363. // Now include the actual code files..
  192364. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192365. CriticalSection::CriticalSection() throw()
  192366. {
  192367. pthread_mutexattr_t atts;
  192368. pthread_mutexattr_init (&atts);
  192369. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192370. pthread_mutex_init (&internal, &atts);
  192371. }
  192372. CriticalSection::~CriticalSection() throw()
  192373. {
  192374. pthread_mutex_destroy (&internal);
  192375. }
  192376. void CriticalSection::enter() const throw()
  192377. {
  192378. pthread_mutex_lock (&internal);
  192379. }
  192380. bool CriticalSection::tryEnter() const throw()
  192381. {
  192382. return pthread_mutex_trylock (&internal) == 0;
  192383. }
  192384. void CriticalSection::exit() const throw()
  192385. {
  192386. pthread_mutex_unlock (&internal);
  192387. }
  192388. class WaitableEventImpl
  192389. {
  192390. public:
  192391. WaitableEventImpl (const bool manualReset_)
  192392. : triggered (false),
  192393. manualReset (manualReset_)
  192394. {
  192395. pthread_cond_init (&condition, 0);
  192396. pthread_mutex_init (&mutex, 0);
  192397. }
  192398. ~WaitableEventImpl()
  192399. {
  192400. pthread_cond_destroy (&condition);
  192401. pthread_mutex_destroy (&mutex);
  192402. }
  192403. bool wait (const int timeOutMillisecs) throw()
  192404. {
  192405. pthread_mutex_lock (&mutex);
  192406. if (! triggered)
  192407. {
  192408. if (timeOutMillisecs < 0)
  192409. {
  192410. do
  192411. {
  192412. pthread_cond_wait (&condition, &mutex);
  192413. }
  192414. while (! triggered);
  192415. }
  192416. else
  192417. {
  192418. struct timeval now;
  192419. gettimeofday (&now, 0);
  192420. struct timespec time;
  192421. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192422. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192423. if (time.tv_nsec >= 1000000000)
  192424. {
  192425. time.tv_nsec -= 1000000000;
  192426. time.tv_sec++;
  192427. }
  192428. do
  192429. {
  192430. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192431. {
  192432. pthread_mutex_unlock (&mutex);
  192433. return false;
  192434. }
  192435. }
  192436. while (! triggered);
  192437. }
  192438. }
  192439. if (! manualReset)
  192440. triggered = false;
  192441. pthread_mutex_unlock (&mutex);
  192442. return true;
  192443. }
  192444. void signal() throw()
  192445. {
  192446. pthread_mutex_lock (&mutex);
  192447. triggered = true;
  192448. pthread_cond_broadcast (&condition);
  192449. pthread_mutex_unlock (&mutex);
  192450. }
  192451. void reset() throw()
  192452. {
  192453. pthread_mutex_lock (&mutex);
  192454. triggered = false;
  192455. pthread_mutex_unlock (&mutex);
  192456. }
  192457. private:
  192458. pthread_cond_t condition;
  192459. pthread_mutex_t mutex;
  192460. bool triggered;
  192461. const bool manualReset;
  192462. WaitableEventImpl (const WaitableEventImpl&);
  192463. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192464. };
  192465. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  192466. : internal (new WaitableEventImpl (manualReset))
  192467. {
  192468. }
  192469. WaitableEvent::~WaitableEvent() throw()
  192470. {
  192471. delete static_cast <WaitableEventImpl*> (internal);
  192472. }
  192473. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192474. {
  192475. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192476. }
  192477. void WaitableEvent::signal() const throw()
  192478. {
  192479. static_cast <WaitableEventImpl*> (internal)->signal();
  192480. }
  192481. void WaitableEvent::reset() const throw()
  192482. {
  192483. static_cast <WaitableEventImpl*> (internal)->reset();
  192484. }
  192485. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192486. {
  192487. struct timespec time;
  192488. time.tv_sec = millisecs / 1000;
  192489. time.tv_nsec = (millisecs % 1000) * 1000000;
  192490. nanosleep (&time, 0);
  192491. }
  192492. const juce_wchar File::separator = '/';
  192493. const juce_wchar* File::separatorString = L"/";
  192494. const File File::getCurrentWorkingDirectory()
  192495. {
  192496. HeapBlock<char> heapBuffer;
  192497. char localBuffer [1024];
  192498. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192499. int bufferSize = 4096;
  192500. while (cwd == 0 && errno == ERANGE)
  192501. {
  192502. heapBuffer.malloc (bufferSize);
  192503. cwd = getcwd (heapBuffer, bufferSize - 1);
  192504. bufferSize += 1024;
  192505. }
  192506. return File (String::fromUTF8 (cwd));
  192507. }
  192508. bool File::setAsCurrentWorkingDirectory() const
  192509. {
  192510. return chdir (getFullPathName().toUTF8()) == 0;
  192511. }
  192512. bool juce_copyFile (const String& s, const String& d);
  192513. static bool juce_stat (const String& fileName, struct stat& info)
  192514. {
  192515. return fileName.isNotEmpty()
  192516. && (stat (fileName.toUTF8(), &info) == 0);
  192517. }
  192518. bool juce_isDirectory (const String& fileName)
  192519. {
  192520. struct stat info;
  192521. return fileName.isEmpty()
  192522. || (juce_stat (fileName, info)
  192523. && ((info.st_mode & S_IFDIR) != 0));
  192524. }
  192525. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192526. {
  192527. if (fileName.isEmpty())
  192528. return false;
  192529. const char* const fileNameUTF8 = fileName.toUTF8();
  192530. bool exists = access (fileNameUTF8, F_OK) == 0;
  192531. if (exists && dontCountDirectories)
  192532. {
  192533. struct stat info;
  192534. const int res = stat (fileNameUTF8, &info);
  192535. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192536. exists = false;
  192537. }
  192538. return exists;
  192539. }
  192540. int64 juce_getFileSize (const String& fileName)
  192541. {
  192542. struct stat info;
  192543. return juce_stat (fileName, info) ? info.st_size : 0;
  192544. }
  192545. bool juce_canWriteToFile (const String& fileName)
  192546. {
  192547. return access (fileName.toUTF8(), W_OK) == 0;
  192548. }
  192549. bool juce_deleteFile (const String& fileName)
  192550. {
  192551. if (juce_isDirectory (fileName))
  192552. return rmdir (fileName.toUTF8()) == 0;
  192553. else
  192554. return remove (fileName.toUTF8()) == 0;
  192555. }
  192556. bool juce_moveFile (const String& source, const String& dest)
  192557. {
  192558. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192559. return true;
  192560. if (juce_canWriteToFile (source)
  192561. && juce_copyFile (source, dest))
  192562. {
  192563. if (juce_deleteFile (source))
  192564. return true;
  192565. juce_deleteFile (dest);
  192566. }
  192567. return false;
  192568. }
  192569. void juce_createDirectory (const String& fileName)
  192570. {
  192571. mkdir (fileName.toUTF8(), 0777);
  192572. }
  192573. void* juce_fileOpen (const String& fileName, bool forWriting)
  192574. {
  192575. int flags = O_RDONLY;
  192576. if (forWriting)
  192577. {
  192578. if (juce_fileExists (fileName, false))
  192579. {
  192580. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  192581. if (f != -1)
  192582. lseek (f, 0, SEEK_END);
  192583. return (void*) f;
  192584. }
  192585. else
  192586. {
  192587. flags = O_RDWR + O_CREAT;
  192588. }
  192589. }
  192590. return (void*) open (fileName.toUTF8(), flags, 00644);
  192591. }
  192592. void juce_fileClose (void* handle)
  192593. {
  192594. if (handle != 0)
  192595. close ((int) (pointer_sized_int) handle);
  192596. }
  192597. int juce_fileRead (void* handle, void* buffer, int size)
  192598. {
  192599. if (handle != 0)
  192600. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  192601. return 0;
  192602. }
  192603. int juce_fileWrite (void* handle, const void* buffer, int size)
  192604. {
  192605. if (handle != 0)
  192606. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192607. return 0;
  192608. }
  192609. int64 juce_fileSetPosition (void* handle, int64 pos)
  192610. {
  192611. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192612. return pos;
  192613. return -1;
  192614. }
  192615. int64 juce_fileGetPosition (void* handle)
  192616. {
  192617. if (handle != 0)
  192618. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192619. return -1;
  192620. }
  192621. void juce_fileFlush (void* handle)
  192622. {
  192623. if (handle != 0)
  192624. fsync ((int) (pointer_sized_int) handle);
  192625. }
  192626. const File juce_getExecutableFile()
  192627. {
  192628. Dl_info exeInfo;
  192629. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192630. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  192631. }
  192632. // if this file doesn't exist, find a parent of it that does..
  192633. static bool doStatFS (const File* file, struct statfs& result)
  192634. {
  192635. File f (*file);
  192636. for (int i = 5; --i >= 0;)
  192637. {
  192638. if (f.exists())
  192639. break;
  192640. f = f.getParentDirectory();
  192641. }
  192642. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192643. }
  192644. int64 File::getBytesFreeOnVolume() const
  192645. {
  192646. struct statfs buf;
  192647. if (doStatFS (this, buf))
  192648. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192649. return 0;
  192650. }
  192651. int64 File::getVolumeTotalSize() const
  192652. {
  192653. struct statfs buf;
  192654. if (doStatFS (this, buf))
  192655. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192656. return 0;
  192657. }
  192658. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192659. int& volumeSerialNumber)
  192660. {
  192661. volumeSerialNumber = 0;
  192662. #if JUCE_MAC
  192663. struct VolAttrBuf
  192664. {
  192665. u_int32_t length;
  192666. attrreference_t mountPointRef;
  192667. char mountPointSpace [MAXPATHLEN];
  192668. } attrBuf;
  192669. struct attrlist attrList;
  192670. zerostruct (attrList);
  192671. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192672. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192673. File f (filenameOnVolume);
  192674. for (;;)
  192675. {
  192676. if (getattrlist (f.getFullPathName().toUTF8(),
  192677. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192678. {
  192679. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192680. (int) attrBuf.mountPointRef.attr_length);
  192681. }
  192682. const File parent (f.getParentDirectory());
  192683. if (f == parent)
  192684. break;
  192685. f = parent;
  192686. }
  192687. #endif
  192688. return String::empty;
  192689. }
  192690. void juce_runSystemCommand (const String& command)
  192691. {
  192692. int result = system (command.toUTF8());
  192693. (void) result;
  192694. }
  192695. const String juce_getOutputFromCommand (const String& command)
  192696. {
  192697. // slight bodge here, as we just pipe the output into a temp file and read it...
  192698. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192699. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192700. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192701. String result (tempFile.loadFileAsString());
  192702. tempFile.deleteFile();
  192703. return result;
  192704. }
  192705. class InterProcessLock::Pimpl
  192706. {
  192707. public:
  192708. Pimpl (const String& name, const int timeOutMillisecs)
  192709. : handle (0), refCount (1)
  192710. {
  192711. #if JUCE_MAC
  192712. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192713. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  192714. #else
  192715. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192716. #endif
  192717. temp.create();
  192718. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192719. if (handle != 0)
  192720. {
  192721. struct flock fl;
  192722. zerostruct (fl);
  192723. fl.l_whence = SEEK_SET;
  192724. fl.l_type = F_WRLCK;
  192725. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192726. for (;;)
  192727. {
  192728. const int result = fcntl (handle, F_SETLK, &fl);
  192729. if (result >= 0)
  192730. return;
  192731. if (errno != EINTR)
  192732. {
  192733. if (timeOutMillisecs == 0
  192734. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192735. break;
  192736. Thread::sleep (10);
  192737. }
  192738. }
  192739. }
  192740. closeFile();
  192741. }
  192742. ~Pimpl()
  192743. {
  192744. closeFile();
  192745. }
  192746. void closeFile()
  192747. {
  192748. if (handle != 0)
  192749. {
  192750. struct flock fl;
  192751. zerostruct (fl);
  192752. fl.l_whence = SEEK_SET;
  192753. fl.l_type = F_UNLCK;
  192754. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  192755. {}
  192756. close (handle);
  192757. handle = 0;
  192758. }
  192759. }
  192760. int handle, refCount;
  192761. };
  192762. InterProcessLock::InterProcessLock (const String& name_)
  192763. : name (name_)
  192764. {
  192765. }
  192766. InterProcessLock::~InterProcessLock()
  192767. {
  192768. }
  192769. bool InterProcessLock::enter (const int timeOutMillisecs)
  192770. {
  192771. const ScopedLock sl (lock);
  192772. if (pimpl == 0)
  192773. {
  192774. pimpl = new Pimpl (name, timeOutMillisecs);
  192775. if (pimpl->handle == 0)
  192776. pimpl = 0;
  192777. }
  192778. else
  192779. {
  192780. pimpl->refCount++;
  192781. }
  192782. return pimpl != 0;
  192783. }
  192784. void InterProcessLock::exit()
  192785. {
  192786. const ScopedLock sl (lock);
  192787. // Trying to release the lock too many times!
  192788. jassert (pimpl != 0);
  192789. if (pimpl != 0 && --(pimpl->refCount) == 0)
  192790. pimpl = 0;
  192791. }
  192792. /*** End of inlined file: juce_posix_SharedCode.h ***/
  192793. /*** Start of inlined file: juce_linux_Files.cpp ***/
  192794. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192795. // compiled on its own).
  192796. #if JUCE_INCLUDED_FILE
  192797. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  192798. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  192799. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  192800. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  192801. void juce_getFileTimes (const String& fileName,
  192802. int64& modificationTime,
  192803. int64& accessTime,
  192804. int64& creationTime)
  192805. {
  192806. modificationTime = 0;
  192807. accessTime = 0;
  192808. creationTime = 0;
  192809. struct stat info;
  192810. const int res = stat (fileName.toUTF8(), &info);
  192811. if (res == 0)
  192812. {
  192813. modificationTime = (int64) info.st_mtime * 1000;
  192814. accessTime = (int64) info.st_atime * 1000;
  192815. creationTime = (int64) info.st_ctime * 1000;
  192816. }
  192817. }
  192818. bool juce_setFileTimes (const String& fileName,
  192819. int64 modificationTime,
  192820. int64 accessTime,
  192821. int64 creationTime)
  192822. {
  192823. struct utimbuf times;
  192824. times.actime = (time_t) (accessTime / 1000);
  192825. times.modtime = (time_t) (modificationTime / 1000);
  192826. return utime (fileName.toUTF8(), &times) == 0;
  192827. }
  192828. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  192829. {
  192830. struct stat info;
  192831. const int res = stat (fileName.toUTF8(), &info);
  192832. if (res != 0)
  192833. return false;
  192834. info.st_mode &= 0777; // Just permissions
  192835. if( isReadOnly )
  192836. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  192837. else
  192838. // Give everybody write permission?
  192839. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  192840. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  192841. }
  192842. bool juce_copyFile (const String& s, const String& d)
  192843. {
  192844. const File source (s), dest (d);
  192845. FileInputStream* in = source.createInputStream();
  192846. bool ok = false;
  192847. if (in != 0)
  192848. {
  192849. if (dest.deleteFile())
  192850. {
  192851. FileOutputStream* const out = dest.createOutputStream();
  192852. if (out != 0)
  192853. {
  192854. const int bytesCopied = out->writeFromInputStream (*in, -1);
  192855. delete out;
  192856. ok = (bytesCopied == source.getSize());
  192857. if (! ok)
  192858. dest.deleteFile();
  192859. }
  192860. }
  192861. delete in;
  192862. }
  192863. return ok;
  192864. }
  192865. const StringArray juce_getFileSystemRoots()
  192866. {
  192867. StringArray s;
  192868. s.add ("/");
  192869. return s;
  192870. }
  192871. bool File::isOnCDRomDrive() const
  192872. {
  192873. struct statfs buf;
  192874. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192875. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  192876. // Assume not if this fails for some reason
  192877. return false;
  192878. }
  192879. bool File::isOnHardDisk() const
  192880. {
  192881. struct statfs buf;
  192882. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192883. {
  192884. switch (buf.f_type)
  192885. {
  192886. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  192887. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  192888. case U_NFS_SUPER_MAGIC: // Network NFS
  192889. case U_SMB_SUPER_MAGIC: // Network Samba
  192890. return false;
  192891. default:
  192892. // Assume anything else is a hard-disk (but note it could
  192893. // be a RAM disk. There isn't a good way of determining
  192894. // this for sure)
  192895. return true;
  192896. }
  192897. }
  192898. // Assume so if this fails for some reason
  192899. return true;
  192900. }
  192901. bool File::isOnRemovableDrive() const
  192902. {
  192903. jassertfalse // xxx not implemented for linux!
  192904. return false;
  192905. }
  192906. bool File::isHidden() const
  192907. {
  192908. return getFileName().startsWithChar ('.');
  192909. }
  192910. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  192911. const File File::getSpecialLocation (const SpecialLocationType type)
  192912. {
  192913. switch (type)
  192914. {
  192915. case userHomeDirectory:
  192916. {
  192917. const char* homeDir = getenv ("HOME");
  192918. if (homeDir == 0)
  192919. {
  192920. struct passwd* const pw = getpwuid (getuid());
  192921. if (pw != 0)
  192922. homeDir = pw->pw_dir;
  192923. }
  192924. return File (String::fromUTF8 (homeDir));
  192925. }
  192926. case userDocumentsDirectory:
  192927. case userMusicDirectory:
  192928. case userMoviesDirectory:
  192929. case userApplicationDataDirectory:
  192930. return File ("~");
  192931. case userDesktopDirectory:
  192932. return File ("~/Desktop");
  192933. case commonApplicationDataDirectory:
  192934. return File ("/var");
  192935. case globalApplicationsDirectory:
  192936. return File ("/usr");
  192937. case tempDirectory:
  192938. {
  192939. File tmp ("/var/tmp");
  192940. if (! tmp.isDirectory())
  192941. {
  192942. tmp = "/tmp";
  192943. if (! tmp.isDirectory())
  192944. tmp = File::getCurrentWorkingDirectory();
  192945. }
  192946. return tmp;
  192947. }
  192948. case invokedExecutableFile:
  192949. if (juce_Argv0 != 0)
  192950. return File (String::fromUTF8 (juce_Argv0));
  192951. // deliberate fall-through...
  192952. case currentExecutableFile:
  192953. case currentApplicationFile:
  192954. return juce_getExecutableFile();
  192955. default:
  192956. jassertfalse // unknown type?
  192957. break;
  192958. }
  192959. return File::nonexistent;
  192960. }
  192961. const String File::getVersion() const
  192962. {
  192963. return String::empty; // xxx not yet implemented
  192964. }
  192965. const File File::getLinkedTarget() const
  192966. {
  192967. char buffer [4096];
  192968. size_t numChars = readlink (getFullPathName().toUTF8(),
  192969. buffer, sizeof (buffer));
  192970. if (numChars > 0 && numChars <= sizeof (buffer))
  192971. return File (String::fromUTF8 (buffer, (int) numChars));
  192972. return *this;
  192973. }
  192974. bool File::moveToTrash() const
  192975. {
  192976. if (! exists())
  192977. return true;
  192978. File trashCan ("~/.Trash");
  192979. if (! trashCan.isDirectory())
  192980. trashCan = "~/.local/share/Trash/files";
  192981. if (! trashCan.isDirectory())
  192982. return false;
  192983. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  192984. getFileExtension()));
  192985. }
  192986. struct FindFileStruct
  192987. {
  192988. String parentDir, wildCard;
  192989. DIR* dir;
  192990. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  192991. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  192992. {
  192993. const char* const wildcardUTF8 = wildCard.toUTF8();
  192994. for (;;)
  192995. {
  192996. struct dirent* const de = readdir (dir);
  192997. if (de == 0)
  192998. break;
  192999. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193000. {
  193001. result = String::fromUTF8 (de->d_name);
  193002. const String path (parentDir + result);
  193003. if (isDir != 0 || fileSize != 0)
  193004. {
  193005. struct stat info;
  193006. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193007. if (isDir != 0)
  193008. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193009. if (isHidden != 0)
  193010. *isHidden = (de->d_name[0] == '.');
  193011. if (fileSize != 0)
  193012. *fileSize = statOk ? info.st_size : 0;
  193013. }
  193014. if (modTime != 0 || creationTime != 0)
  193015. {
  193016. int64 m, a, c;
  193017. juce_getFileTimes (path, m, a, c);
  193018. if (modTime != 0)
  193019. *modTime = m;
  193020. if (creationTime != 0)
  193021. *creationTime = c;
  193022. }
  193023. if (isReadOnly != 0)
  193024. *isReadOnly = ! juce_canWriteToFile (path);
  193025. return true;
  193026. }
  193027. }
  193028. return false;
  193029. }
  193030. };
  193031. // returns 0 on failure
  193032. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193033. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193034. Time* creationTime, bool* isReadOnly)
  193035. {
  193036. DIR* d = opendir (directory.toUTF8());
  193037. if (d != 0)
  193038. {
  193039. FindFileStruct* ff = new FindFileStruct();
  193040. ff->parentDir = directory;
  193041. if (!ff->parentDir.endsWithChar (File::separator))
  193042. ff->parentDir += File::separator;
  193043. ff->wildCard = wildCard;
  193044. if (wildCard == "*.*")
  193045. ff->wildCard = "*";
  193046. ff->dir = d;
  193047. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193048. {
  193049. return ff;
  193050. }
  193051. else
  193052. {
  193053. firstResultFile = String::empty;
  193054. isDir = false;
  193055. isHidden = false;
  193056. closedir (d);
  193057. delete ff;
  193058. }
  193059. }
  193060. return 0;
  193061. }
  193062. bool juce_findFileNext (void* handle, String& resultFile,
  193063. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193064. {
  193065. FindFileStruct* const ff = (FindFileStruct*) handle;
  193066. if (ff != 0)
  193067. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193068. return false;
  193069. }
  193070. void juce_findFileClose (void* handle)
  193071. {
  193072. FindFileStruct* const ff = (FindFileStruct*) handle;
  193073. if (ff != 0)
  193074. {
  193075. closedir (ff->dir);
  193076. delete ff;
  193077. }
  193078. }
  193079. bool juce_launchFile (const String& fileName,
  193080. const String& parameters)
  193081. {
  193082. String cmdString (fileName.replace (" ", "\\ ",false));
  193083. cmdString << " " << parameters;
  193084. if (URL::isProbablyAWebsiteURL (fileName)
  193085. || cmdString.startsWithIgnoreCase ("file:")
  193086. || URL::isProbablyAnEmailAddress (fileName))
  193087. {
  193088. // create a command that tries to launch a bunch of likely browsers
  193089. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193090. StringArray cmdLines;
  193091. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193092. cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
  193093. cmdString = cmdLines.joinIntoString (" || ");
  193094. }
  193095. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  193096. const int cpid = fork();
  193097. if (cpid == 0)
  193098. {
  193099. setsid();
  193100. // Child process
  193101. execve (argv[0], (char**) argv, environ);
  193102. exit (0);
  193103. }
  193104. return cpid >= 0;
  193105. }
  193106. void File::revealToUser() const
  193107. {
  193108. if (isDirectory())
  193109. startAsProcess();
  193110. else if (getParentDirectory().exists())
  193111. getParentDirectory().startAsProcess();
  193112. }
  193113. #endif
  193114. /*** End of inlined file: juce_linux_Files.cpp ***/
  193115. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193116. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193117. // compiled on its own).
  193118. #if JUCE_INCLUDED_FILE
  193119. struct NamedPipeInternal
  193120. {
  193121. String pipeInName, pipeOutName;
  193122. int pipeIn, pipeOut;
  193123. bool volatile createdPipe, blocked, stopReadOperation;
  193124. static void signalHandler (int) {}
  193125. };
  193126. void NamedPipe::cancelPendingReads()
  193127. {
  193128. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193129. {
  193130. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193131. intern->stopReadOperation = true;
  193132. char buffer [1] = { 0 };
  193133. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193134. (void) bytesWritten;
  193135. int timeout = 2000;
  193136. while (intern->blocked && --timeout >= 0)
  193137. Thread::sleep (2);
  193138. intern->stopReadOperation = false;
  193139. }
  193140. }
  193141. void NamedPipe::close()
  193142. {
  193143. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193144. if (intern != 0)
  193145. {
  193146. internal = 0;
  193147. if (intern->pipeIn != -1)
  193148. ::close (intern->pipeIn);
  193149. if (intern->pipeOut != -1)
  193150. ::close (intern->pipeOut);
  193151. if (intern->createdPipe)
  193152. {
  193153. unlink (intern->pipeInName.toUTF8());
  193154. unlink (intern->pipeOutName.toUTF8());
  193155. }
  193156. delete intern;
  193157. }
  193158. }
  193159. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193160. {
  193161. close();
  193162. NamedPipeInternal* const intern = new NamedPipeInternal();
  193163. internal = intern;
  193164. intern->createdPipe = createPipe;
  193165. intern->blocked = false;
  193166. intern->stopReadOperation = false;
  193167. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193168. siginterrupt (SIGPIPE, 1);
  193169. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  193170. intern->pipeInName = pipePath + "_in";
  193171. intern->pipeOutName = pipePath + "_out";
  193172. intern->pipeIn = -1;
  193173. intern->pipeOut = -1;
  193174. if (createPipe)
  193175. {
  193176. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193177. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193178. {
  193179. delete intern;
  193180. internal = 0;
  193181. return false;
  193182. }
  193183. }
  193184. return true;
  193185. }
  193186. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193187. {
  193188. int bytesRead = -1;
  193189. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193190. if (intern != 0)
  193191. {
  193192. intern->blocked = true;
  193193. if (intern->pipeIn == -1)
  193194. {
  193195. if (intern->createdPipe)
  193196. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193197. else
  193198. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193199. if (intern->pipeIn == -1)
  193200. {
  193201. intern->blocked = false;
  193202. return -1;
  193203. }
  193204. }
  193205. bytesRead = 0;
  193206. char* p = (char*) destBuffer;
  193207. while (bytesRead < maxBytesToRead)
  193208. {
  193209. const int bytesThisTime = maxBytesToRead - bytesRead;
  193210. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193211. if (numRead <= 0 || intern->stopReadOperation)
  193212. {
  193213. bytesRead = -1;
  193214. break;
  193215. }
  193216. bytesRead += numRead;
  193217. p += bytesRead;
  193218. }
  193219. intern->blocked = false;
  193220. }
  193221. return bytesRead;
  193222. }
  193223. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193224. {
  193225. int bytesWritten = -1;
  193226. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193227. if (intern != 0)
  193228. {
  193229. if (intern->pipeOut == -1)
  193230. {
  193231. if (intern->createdPipe)
  193232. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193233. else
  193234. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193235. if (intern->pipeOut == -1)
  193236. {
  193237. return -1;
  193238. }
  193239. }
  193240. const char* p = (const char*) sourceBuffer;
  193241. bytesWritten = 0;
  193242. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193243. while (bytesWritten < numBytesToWrite
  193244. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193245. {
  193246. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193247. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193248. if (numWritten <= 0)
  193249. {
  193250. bytesWritten = -1;
  193251. break;
  193252. }
  193253. bytesWritten += numWritten;
  193254. p += bytesWritten;
  193255. }
  193256. }
  193257. return bytesWritten;
  193258. }
  193259. #endif
  193260. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193261. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193262. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193263. // compiled on its own).
  193264. #if JUCE_INCLUDED_FILE
  193265. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193266. {
  193267. int numResults = 0;
  193268. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193269. if (s != -1)
  193270. {
  193271. char buf [1024];
  193272. struct ifconf ifc;
  193273. ifc.ifc_len = sizeof (buf);
  193274. ifc.ifc_buf = buf;
  193275. ioctl (s, SIOCGIFCONF, &ifc);
  193276. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193277. {
  193278. struct ifreq ifr;
  193279. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193280. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193281. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193282. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193283. && numResults < maxNum)
  193284. {
  193285. int64 a = 0;
  193286. for (int j = 6; --j >= 0;)
  193287. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193288. *addresses++ = a;
  193289. ++numResults;
  193290. }
  193291. }
  193292. close (s);
  193293. }
  193294. return numResults;
  193295. }
  193296. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193297. const String& emailSubject,
  193298. const String& bodyText,
  193299. const StringArray& filesToAttach)
  193300. {
  193301. jassertfalse // xxx todo
  193302. return false;
  193303. }
  193304. class JUCE_HTTPSocketStream
  193305. {
  193306. public:
  193307. JUCE_HTTPSocketStream()
  193308. : readPosition (0),
  193309. socketHandle (-1),
  193310. levelsOfRedirection (0),
  193311. timeoutSeconds (15)
  193312. {
  193313. }
  193314. ~JUCE_HTTPSocketStream()
  193315. {
  193316. closeSocket();
  193317. }
  193318. bool open (const String& url,
  193319. const String& headers,
  193320. const MemoryBlock& postData,
  193321. const bool isPost,
  193322. URL::OpenStreamProgressCallback* callback,
  193323. void* callbackContext,
  193324. int timeOutMs)
  193325. {
  193326. closeSocket();
  193327. uint32 timeOutTime = Time::getMillisecondCounter();
  193328. if (timeOutMs == 0)
  193329. timeOutTime += 60000;
  193330. else if (timeOutMs < 0)
  193331. timeOutTime = 0xffffffff;
  193332. else
  193333. timeOutTime += timeOutMs;
  193334. String hostName, hostPath;
  193335. int hostPort;
  193336. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193337. return false;
  193338. const struct hostent* host = 0;
  193339. int port = 0;
  193340. String proxyName, proxyPath;
  193341. int proxyPort = 0;
  193342. String proxyURL (getenv ("http_proxy"));
  193343. if (proxyURL.startsWithIgnoreCase ("http://"))
  193344. {
  193345. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193346. return false;
  193347. host = gethostbyname (proxyName.toUTF8());
  193348. port = proxyPort;
  193349. }
  193350. else
  193351. {
  193352. host = gethostbyname (hostName.toUTF8());
  193353. port = hostPort;
  193354. }
  193355. if (host == 0)
  193356. return false;
  193357. struct sockaddr_in address;
  193358. zerostruct (address);
  193359. memcpy (&address.sin_addr, host->h_addr, host->h_length);
  193360. address.sin_family = host->h_addrtype;
  193361. address.sin_port = htons (port);
  193362. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193363. if (socketHandle == -1)
  193364. return false;
  193365. int receiveBufferSize = 16384;
  193366. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193367. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193368. #if JUCE_MAC
  193369. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193370. #endif
  193371. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193372. {
  193373. closeSocket();
  193374. return false;
  193375. }
  193376. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193377. proxyName, proxyPort,
  193378. hostPath, url,
  193379. headers, postData,
  193380. isPost));
  193381. size_t totalHeaderSent = 0;
  193382. while (totalHeaderSent < requestHeader.getSize())
  193383. {
  193384. if (Time::getMillisecondCounter() > timeOutTime)
  193385. {
  193386. closeSocket();
  193387. return false;
  193388. }
  193389. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193390. if (send (socketHandle,
  193391. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193392. numToSend, 0)
  193393. != numToSend)
  193394. {
  193395. closeSocket();
  193396. return false;
  193397. }
  193398. totalHeaderSent += numToSend;
  193399. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193400. {
  193401. closeSocket();
  193402. return false;
  193403. }
  193404. }
  193405. const String responseHeader (readResponse (timeOutTime));
  193406. if (responseHeader.isNotEmpty())
  193407. {
  193408. //DBG (responseHeader);
  193409. StringArray lines;
  193410. lines.addLines (responseHeader);
  193411. const int statusCode = responseHeader.fromFirstOccurrenceOf (" ", false, false)
  193412. .substring (0, 3).getIntValue();
  193413. //int contentLength = findHeaderItem (lines, "Content-Length:").getIntValue();
  193414. //bool isChunked = findHeaderItem (lines, "Transfer-Encoding:").equalsIgnoreCase ("chunked");
  193415. String location (findHeaderItem (lines, "Location:"));
  193416. if (statusCode >= 300 && statusCode < 400
  193417. && location.isNotEmpty())
  193418. {
  193419. if (! location.startsWithIgnoreCase ("http://"))
  193420. location = "http://" + location;
  193421. if (levelsOfRedirection++ < 3)
  193422. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193423. }
  193424. else
  193425. {
  193426. levelsOfRedirection = 0;
  193427. return true;
  193428. }
  193429. }
  193430. closeSocket();
  193431. return false;
  193432. }
  193433. int read (void* buffer, int bytesToRead)
  193434. {
  193435. fd_set readbits;
  193436. FD_ZERO (&readbits);
  193437. FD_SET (socketHandle, &readbits);
  193438. struct timeval tv;
  193439. tv.tv_sec = timeoutSeconds;
  193440. tv.tv_usec = 0;
  193441. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193442. return 0; // (timeout)
  193443. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193444. readPosition += bytesRead;
  193445. return bytesRead;
  193446. }
  193447. int readPosition;
  193448. juce_UseDebuggingNewOperator
  193449. private:
  193450. int socketHandle, levelsOfRedirection;
  193451. const int timeoutSeconds;
  193452. void closeSocket()
  193453. {
  193454. if (socketHandle >= 0)
  193455. close (socketHandle);
  193456. socketHandle = -1;
  193457. }
  193458. const MemoryBlock createRequestHeader (const String& hostName,
  193459. const int hostPort,
  193460. const String& proxyName,
  193461. const int proxyPort,
  193462. const String& hostPath,
  193463. const String& originalURL,
  193464. const String& headers,
  193465. const MemoryBlock& postData,
  193466. const bool isPost)
  193467. {
  193468. String header (isPost ? "POST " : "GET ");
  193469. if (proxyName.isEmpty())
  193470. {
  193471. header << hostPath << " HTTP/1.0\r\nHost: "
  193472. << hostName << ':' << hostPort;
  193473. }
  193474. else
  193475. {
  193476. header << originalURL << " HTTP/1.0\r\nHost: "
  193477. << proxyName << ':' << proxyPort;
  193478. }
  193479. header << "\r\nUser-Agent: JUCE/"
  193480. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193481. << "\r\nConnection: Close\r\nContent-Length: "
  193482. << postData.getSize() << "\r\n"
  193483. << headers << "\r\n";
  193484. MemoryBlock mb;
  193485. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193486. mb.append (postData.getData(), postData.getSize());
  193487. return mb;
  193488. }
  193489. const String readResponse (const uint32 timeOutTime)
  193490. {
  193491. int bytesRead = 0, numConsecutiveLFs = 0;
  193492. MemoryBlock buffer (1024, true);
  193493. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193494. && Time::getMillisecondCounter() <= timeOutTime)
  193495. {
  193496. fd_set readbits;
  193497. FD_ZERO (&readbits);
  193498. FD_SET (socketHandle, &readbits);
  193499. struct timeval tv;
  193500. tv.tv_sec = timeoutSeconds;
  193501. tv.tv_usec = 0;
  193502. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193503. return String::empty; // (timeout)
  193504. buffer.ensureSize (bytesRead + 8, true);
  193505. char* const dest = (char*) buffer.getData() + bytesRead;
  193506. if (recv (socketHandle, dest, 1, 0) == -1)
  193507. return String::empty;
  193508. const char lastByte = *dest;
  193509. ++bytesRead;
  193510. if (lastByte == '\n')
  193511. ++numConsecutiveLFs;
  193512. else if (lastByte != '\r')
  193513. numConsecutiveLFs = 0;
  193514. }
  193515. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193516. if (header.startsWithIgnoreCase ("HTTP/"))
  193517. return header.trimEnd();
  193518. return String::empty;
  193519. }
  193520. static bool decomposeURL (const String& url,
  193521. String& host, String& path, int& port)
  193522. {
  193523. if (! url.startsWithIgnoreCase ("http://"))
  193524. return false;
  193525. const int nextSlash = url.indexOfChar (7, '/');
  193526. int nextColon = url.indexOfChar (7, ':');
  193527. if (nextColon > nextSlash && nextSlash > 0)
  193528. nextColon = -1;
  193529. if (nextColon >= 0)
  193530. {
  193531. host = url.substring (7, nextColon);
  193532. if (nextSlash >= 0)
  193533. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193534. else
  193535. port = url.substring (nextColon + 1).getIntValue();
  193536. }
  193537. else
  193538. {
  193539. port = 80;
  193540. if (nextSlash >= 0)
  193541. host = url.substring (7, nextSlash);
  193542. else
  193543. host = url.substring (7);
  193544. }
  193545. if (nextSlash >= 0)
  193546. path = url.substring (nextSlash);
  193547. else
  193548. path = "/";
  193549. return true;
  193550. }
  193551. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193552. {
  193553. for (int i = 0; i < lines.size(); ++i)
  193554. if (lines[i].startsWithIgnoreCase (itemName))
  193555. return lines[i].substring (itemName.length()).trim();
  193556. return String::empty;
  193557. }
  193558. };
  193559. bool juce_isOnLine()
  193560. {
  193561. return true;
  193562. }
  193563. void* juce_openInternetFile (const String& url,
  193564. const String& headers,
  193565. const MemoryBlock& postData,
  193566. const bool isPost,
  193567. URL::OpenStreamProgressCallback* callback,
  193568. void* callbackContext,
  193569. int timeOutMs)
  193570. {
  193571. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193572. if (s->open (url, headers, postData, isPost,
  193573. callback, callbackContext, timeOutMs))
  193574. return s;
  193575. delete s;
  193576. return 0;
  193577. }
  193578. void juce_closeInternetFile (void* handle)
  193579. {
  193580. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193581. if (s != 0)
  193582. delete s;
  193583. }
  193584. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193585. {
  193586. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193587. if (s != 0)
  193588. return s->read (buffer, bytesToRead);
  193589. return 0;
  193590. }
  193591. int64 juce_getInternetFileContentLength (void* handle)
  193592. {
  193593. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193594. if (s != 0)
  193595. {
  193596. //xxx todo
  193597. jassertfalse
  193598. }
  193599. return -1;
  193600. }
  193601. int juce_seekInInternetFile (void* handle, int newPosition)
  193602. {
  193603. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193604. if (s != 0)
  193605. return s->readPosition;
  193606. return 0;
  193607. }
  193608. #endif
  193609. /*** End of inlined file: juce_linux_Network.cpp ***/
  193610. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193611. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193612. // compiled on its own).
  193613. #if JUCE_INCLUDED_FILE
  193614. void Logger::outputDebugString (const String& text) throw()
  193615. {
  193616. std::cerr << text << std::endl;
  193617. }
  193618. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193619. {
  193620. return Linux;
  193621. }
  193622. const String SystemStats::getOperatingSystemName() throw()
  193623. {
  193624. return "Linux";
  193625. }
  193626. bool SystemStats::isOperatingSystem64Bit() throw()
  193627. {
  193628. #if JUCE_64BIT
  193629. return true;
  193630. #else
  193631. //xxx not sure how to find this out?..
  193632. return false;
  193633. #endif
  193634. }
  193635. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193636. {
  193637. String info;
  193638. char buf [256];
  193639. FILE* f = fopen ("/proc/cpuinfo", "r");
  193640. while (f != 0 && fgets (buf, sizeof(buf), f))
  193641. {
  193642. if (strncmp (buf, key, strlen (key)) == 0)
  193643. {
  193644. char* p = buf;
  193645. while (*p && *p != '\n')
  193646. ++p;
  193647. if (*p != 0)
  193648. *p = 0;
  193649. p = buf;
  193650. while (*p != 0 && *p != ':')
  193651. ++p;
  193652. if (*p != 0 && *(p + 1) != 0)
  193653. info = p + 2;
  193654. if (! lastOne)
  193655. break;
  193656. }
  193657. }
  193658. fclose (f);
  193659. return info;
  193660. }
  193661. bool SystemStats::hasMMX() throw()
  193662. {
  193663. return getCpuInfo ("flags").contains ("mmx");
  193664. }
  193665. bool SystemStats::hasSSE() throw()
  193666. {
  193667. return getCpuInfo ("flags").contains ("sse");
  193668. }
  193669. bool SystemStats::hasSSE2() throw()
  193670. {
  193671. return getCpuInfo ("flags").contains ("sse2");
  193672. }
  193673. bool SystemStats::has3DNow() throw()
  193674. {
  193675. return getCpuInfo ("flags").contains ("3dnow");
  193676. }
  193677. const String SystemStats::getCpuVendor() throw()
  193678. {
  193679. return getCpuInfo ("vendor_id");
  193680. }
  193681. int SystemStats::getCpuSpeedInMegaherz() throw()
  193682. {
  193683. const String speed (getCpuInfo ("cpu MHz"));
  193684. return (int) (speed.getFloatValue() + 0.5f);
  193685. }
  193686. int SystemStats::getMemorySizeInMegabytes() throw()
  193687. {
  193688. struct sysinfo sysi;
  193689. if (sysinfo (&sysi) == 0)
  193690. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193691. return 0;
  193692. }
  193693. uint32 juce_millisecondsSinceStartup() throw()
  193694. {
  193695. static unsigned int calibrate = 0;
  193696. static bool calibrated = false;
  193697. timeval t;
  193698. unsigned int ret = 0;
  193699. if (! gettimeofday (&t, 0))
  193700. {
  193701. if (! calibrated)
  193702. {
  193703. struct sysinfo sysi;
  193704. if (sysinfo (&sysi) == 0)
  193705. // Safe to assume system was not brought up earlier than 1970!
  193706. calibrate = t.tv_sec - sysi.uptime;
  193707. calibrated = true;
  193708. }
  193709. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193710. }
  193711. return ret;
  193712. }
  193713. double Time::getMillisecondCounterHiRes() throw()
  193714. {
  193715. return getHighResolutionTicks() * 0.001;
  193716. }
  193717. int64 Time::getHighResolutionTicks() throw()
  193718. {
  193719. timeval t;
  193720. if (gettimeofday (&t, 0))
  193721. return 0;
  193722. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193723. }
  193724. int64 Time::getHighResolutionTicksPerSecond() throw()
  193725. {
  193726. // Microseconds
  193727. return 1000000;
  193728. }
  193729. bool Time::setSystemTimeToThisTime() const throw()
  193730. {
  193731. timeval t;
  193732. t.tv_sec = millisSinceEpoch % 1000000;
  193733. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193734. return settimeofday (&t, NULL) ? false : true;
  193735. }
  193736. int SystemStats::getPageSize() throw()
  193737. {
  193738. static int systemPageSize = 0;
  193739. if (systemPageSize == 0)
  193740. systemPageSize = sysconf (_SC_PAGESIZE);
  193741. return systemPageSize;
  193742. }
  193743. int SystemStats::getNumCpus() throw()
  193744. {
  193745. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193746. return lastCpu + 1;
  193747. }
  193748. const String SystemStats::getLogonName()
  193749. {
  193750. const char* user = getenv ("USER");
  193751. if (user == 0)
  193752. {
  193753. struct passwd* const pw = getpwuid (getuid());
  193754. if (pw != 0)
  193755. user = pw->pw_name;
  193756. }
  193757. return String::fromUTF8 (user);
  193758. }
  193759. const String SystemStats::getFullUserName()
  193760. {
  193761. return getLogonName();
  193762. }
  193763. void SystemStats::initialiseStats() throw()
  193764. {
  193765. // Process starts off as root when running suid
  193766. Process::lowerPrivilege();
  193767. String s (SystemStats::getJUCEVersion());
  193768. }
  193769. void PlatformUtilities::fpuReset()
  193770. {
  193771. }
  193772. #endif
  193773. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193774. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193775. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193776. // compiled on its own).
  193777. #if JUCE_INCLUDED_FILE
  193778. void JUCE_API juce_threadEntryPoint (void*);
  193779. void* threadEntryProc (void* value)
  193780. {
  193781. // New threads start off as root when running suid
  193782. Process::lowerPrivilege();
  193783. juce_threadEntryPoint (value);
  193784. return 0;
  193785. }
  193786. void* juce_createThread (void* userData)
  193787. {
  193788. pthread_t handle = 0;
  193789. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  193790. {
  193791. pthread_detach (handle);
  193792. return (void*) handle;
  193793. }
  193794. return 0;
  193795. }
  193796. void juce_killThread (void* handle)
  193797. {
  193798. if (handle != 0)
  193799. pthread_cancel ((pthread_t)handle);
  193800. }
  193801. void juce_setCurrentThreadName (const String& /*name*/)
  193802. {
  193803. }
  193804. Thread::ThreadID Thread::getCurrentThreadId()
  193805. {
  193806. return (ThreadID) pthread_self();
  193807. }
  193808. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  193809. // priority of the current thread
  193810. bool juce_setThreadPriority (void* handle, int priority)
  193811. {
  193812. struct sched_param param;
  193813. int policy, maxp, minp, pri;
  193814. if (handle == 0)
  193815. handle = (void*) pthread_self();
  193816. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  193817. && policy != SCHED_OTHER)
  193818. {
  193819. minp = sched_get_priority_min(policy);
  193820. maxp = sched_get_priority_max(policy);
  193821. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  193822. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  193823. // Realtime process priority
  193824. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  193825. else
  193826. // High process priority
  193827. param.__sched_priority = minp + pri;
  193828. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  193829. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  193830. }
  193831. return false;
  193832. }
  193833. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  193834. {
  193835. #if SUPPORT_AFFINITIES
  193836. cpu_set_t affinity;
  193837. CPU_ZERO (&affinity);
  193838. for (int i = 0; i < 32; ++i)
  193839. if ((affinityMask & (1 << i)) != 0)
  193840. CPU_SET (i, &affinity);
  193841. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  193842. sched_yield();
  193843. #else
  193844. /* affinities aren't supported because either the appropriate header files weren't found,
  193845. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  193846. */
  193847. jassertfalse
  193848. #endif
  193849. }
  193850. void Thread::yield()
  193851. {
  193852. sched_yield();
  193853. }
  193854. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  193855. void Process::setPriority (ProcessPriority prior)
  193856. {
  193857. struct sched_param param;
  193858. int policy, maxp, minp;
  193859. const int p = (int) prior;
  193860. if (p <= 1)
  193861. policy = SCHED_OTHER;
  193862. else
  193863. policy = SCHED_RR;
  193864. minp = sched_get_priority_min (policy);
  193865. maxp = sched_get_priority_max (policy);
  193866. if (p < 2)
  193867. param.__sched_priority = 0;
  193868. else if (p == 2 )
  193869. // Set to middle of lower realtime priority range
  193870. param.__sched_priority = minp + (maxp - minp) / 4;
  193871. else
  193872. // Set to middle of higher realtime priority range
  193873. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  193874. pthread_setschedparam (pthread_self(), policy, &param);
  193875. }
  193876. void Process::terminate()
  193877. {
  193878. exit (0);
  193879. }
  193880. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  193881. {
  193882. static char testResult = 0;
  193883. if (testResult == 0)
  193884. {
  193885. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  193886. if (testResult >= 0)
  193887. {
  193888. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  193889. testResult = 1;
  193890. }
  193891. }
  193892. return testResult < 0;
  193893. }
  193894. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  193895. {
  193896. return juce_isRunningUnderDebugger();
  193897. }
  193898. void Process::raisePrivilege()
  193899. {
  193900. // If running suid root, change effective user
  193901. // to root
  193902. if (geteuid() != 0 && getuid() == 0)
  193903. {
  193904. setreuid (geteuid(), getuid());
  193905. setregid (getegid(), getgid());
  193906. }
  193907. }
  193908. void Process::lowerPrivilege()
  193909. {
  193910. // If runing suid root, change effective user
  193911. // back to real user
  193912. if (geteuid() == 0 && getuid() != 0)
  193913. {
  193914. setreuid (geteuid(), getuid());
  193915. setregid (getegid(), getgid());
  193916. }
  193917. }
  193918. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193919. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  193920. {
  193921. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  193922. }
  193923. void PlatformUtilities::freeDynamicLibrary (void* handle)
  193924. {
  193925. dlclose(handle);
  193926. }
  193927. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  193928. {
  193929. return dlsym (libraryHandle, procedureName.toCString());
  193930. }
  193931. #endif
  193932. #endif
  193933. /*** End of inlined file: juce_linux_Threads.cpp ***/
  193934. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193935. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  193936. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193937. // compiled on its own).
  193938. #if JUCE_INCLUDED_FILE
  193939. #ifdef JUCE_DEBUG
  193940. #define JUCE_DEBUG_XERRORS 1
  193941. #endif
  193942. extern Display* display;
  193943. extern Window juce_messageWindowHandle;
  193944. static String localClipboardContent;
  193945. static Atom atom_UTF8_STRING;
  193946. static Atom atom_CLIPBOARD;
  193947. static Atom atom_TARGETS;
  193948. static void initSelectionAtoms()
  193949. {
  193950. static bool isInitialised = false;
  193951. if (! isInitialised)
  193952. {
  193953. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  193954. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  193955. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  193956. }
  193957. }
  193958. // Read the content of a window property as either a locale-dependent string or an utf8 string
  193959. // works only for strings shorter than 1000000 bytes
  193960. static String juce_readWindowProperty (Window window, Atom prop,
  193961. Atom fmt, // XA_STRING or UTF8_STRING
  193962. bool deleteAfterReading)
  193963. {
  193964. String returnData;
  193965. char* clipData;
  193966. Atom actualType;
  193967. int actualFormat;
  193968. unsigned long numItems, bytesLeft;
  193969. if (XGetWindowProperty (display, window, prop,
  193970. 0L /* offset */, 1000000 /* length (max) */, False,
  193971. AnyPropertyType /* format */,
  193972. &actualType, &actualFormat, &numItems, &bytesLeft,
  193973. (unsigned char**) &clipData) == Success)
  193974. {
  193975. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  193976. {
  193977. returnData = String::fromUTF8 (clipData, numItems);
  193978. }
  193979. else if (actualType == XA_STRING && actualFormat == 8)
  193980. {
  193981. returnData = String (clipData, numItems);
  193982. }
  193983. if (clipData != 0)
  193984. XFree (clipData);
  193985. jassert (bytesLeft == 0 || numItems == 1000000);
  193986. }
  193987. if (deleteAfterReading)
  193988. XDeleteProperty (display, window, prop);
  193989. return returnData;
  193990. }
  193991. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  193992. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  193993. {
  193994. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  193995. // The selection owner will be asked to set the JUCE_SEL property on the
  193996. // juce_messageWindowHandle with the selection content
  193997. XConvertSelection (display, selection, requested_format, property_name,
  193998. juce_messageWindowHandle, CurrentTime);
  193999. int timeoutMs = 200; // will wait at most for 200 ms
  194000. do
  194001. {
  194002. XEvent event;
  194003. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194004. {
  194005. if (event.xselection.property == property_name)
  194006. {
  194007. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194008. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194009. event.xselection.property,
  194010. requested_format, true);
  194011. return true;
  194012. }
  194013. else
  194014. {
  194015. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194016. }
  194017. }
  194018. // not very elegant.. we could do a select() or something like that...
  194019. // however clipboard content requesting is inherently slow on x11, it
  194020. // often takes 50ms or more so...
  194021. Thread::sleep (4);
  194022. timeoutMs -= 4;
  194023. }
  194024. while (timeoutMs > 0);
  194025. DBG("timeout for juce_requestSelectionContent");
  194026. return false;
  194027. }
  194028. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194029. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194030. {
  194031. initSelectionAtoms();
  194032. // the selection content is sent to the target window as a window property
  194033. XSelectionEvent reply;
  194034. reply.type = SelectionNotify;
  194035. reply.display = evt.display;
  194036. reply.requestor = evt.requestor;
  194037. reply.selection = evt.selection;
  194038. reply.target = evt.target;
  194039. reply.property = None; // == "fail"
  194040. reply.time = evt.time;
  194041. HeapBlock <char> data;
  194042. int propertyFormat = 0, numDataItems = 0;
  194043. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194044. {
  194045. if (evt.target == XA_STRING)
  194046. {
  194047. // format data according to system locale
  194048. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194049. data.calloc (numDataItems + 1);
  194050. localClipboardContent.copyToCString (data, numDataItems);
  194051. propertyFormat = 8; // bits/item
  194052. }
  194053. else if (evt.target == atom_UTF8_STRING)
  194054. {
  194055. // translate to utf8
  194056. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194057. data.calloc (numDataItems + 1);
  194058. localClipboardContent.copyToUTF8 (data, numDataItems);
  194059. propertyFormat = 8; // bits/item
  194060. }
  194061. else if (evt.target == atom_TARGETS)
  194062. {
  194063. // another application wants to know what we are able to send
  194064. numDataItems = 2;
  194065. propertyFormat = 32; // atoms are 32-bit
  194066. data.calloc (numDataItems * 4);
  194067. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194068. atoms[0] = atom_UTF8_STRING;
  194069. atoms[1] = XA_STRING;
  194070. }
  194071. }
  194072. else
  194073. {
  194074. DBG ("requested unsupported clipboard");
  194075. }
  194076. if (data != 0)
  194077. {
  194078. const int maxReasonableSelectionSize = 1000000;
  194079. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194080. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194081. {
  194082. XChangeProperty (evt.display, evt.requestor,
  194083. evt.property, evt.target,
  194084. propertyFormat /* 8 or 32 */, PropModeReplace,
  194085. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194086. reply.property = evt.property; // " == success"
  194087. }
  194088. }
  194089. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194090. }
  194091. void SystemClipboard::copyTextToClipboard (const String& clipText)
  194092. {
  194093. initSelectionAtoms();
  194094. localClipboardContent = clipText;
  194095. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194096. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194097. }
  194098. const String SystemClipboard::getTextFromClipboard()
  194099. {
  194100. initSelectionAtoms();
  194101. String content;
  194102. Atom selection = XA_PRIMARY;
  194103. Window selectionOwner = None;
  194104. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194105. {
  194106. selection = atom_CLIPBOARD;
  194107. selectionOwner = XGetSelectionOwner (display, selection);
  194108. }
  194109. if (selectionOwner != None)
  194110. {
  194111. if (selectionOwner == juce_messageWindowHandle)
  194112. {
  194113. content = localClipboardContent;
  194114. }
  194115. else
  194116. {
  194117. // first try: we want an utf8 string
  194118. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194119. if (! ok)
  194120. {
  194121. // second chance, ask for a good old locale-dependent string ..
  194122. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194123. }
  194124. }
  194125. }
  194126. return content;
  194127. }
  194128. #endif
  194129. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194130. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194131. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194132. // compiled on its own).
  194133. #if JUCE_INCLUDED_FILE
  194134. #ifdef JUCE_DEBUG
  194135. #define JUCE_DEBUG_XERRORS 1
  194136. #endif
  194137. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194138. Window juce_messageWindowHandle = None;
  194139. XContext improbableNumber; // This is referenced from Windowing.cpp
  194140. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194141. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194142. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194143. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194144. class InternalMessageQueue
  194145. {
  194146. public:
  194147. InternalMessageQueue()
  194148. : bytesInSocket (0)
  194149. {
  194150. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194151. (void) ret; jassert (ret == 0);
  194152. //setNonBlocking (fd[0]);
  194153. //setNonBlocking (fd[1]);
  194154. }
  194155. ~InternalMessageQueue()
  194156. {
  194157. close (fd[0]);
  194158. close (fd[1]);
  194159. }
  194160. void postMessage (Message* msg)
  194161. {
  194162. const int maxBytesInSocketQueue = 128;
  194163. ScopedLock sl (lock);
  194164. queue.add (msg);
  194165. if (bytesInSocket < maxBytesInSocketQueue)
  194166. {
  194167. ++bytesInSocket;
  194168. ScopedUnlock ul (lock);
  194169. const unsigned char x = 0xff;
  194170. size_t bytesWritten = write (fd[0], &x, 1);
  194171. (void) bytesWritten;
  194172. }
  194173. }
  194174. bool isEmpty() const
  194175. {
  194176. ScopedLock sl (lock);
  194177. return queue.size() == 0;
  194178. }
  194179. Message* popNextMessage()
  194180. {
  194181. ScopedLock sl (lock);
  194182. if (bytesInSocket > 0)
  194183. {
  194184. --bytesInSocket;
  194185. ScopedUnlock ul (lock);
  194186. unsigned char x;
  194187. size_t numBytes = read (fd[1], &x, 1);
  194188. (void) numBytes;
  194189. }
  194190. Message* m = queue[0];
  194191. queue.remove (0, false /* deleteObject */);
  194192. return m;
  194193. }
  194194. int getWaitHandle() const { return fd[1]; }
  194195. private:
  194196. CriticalSection lock;
  194197. OwnedArray <Message> queue;
  194198. int fd[2];
  194199. int bytesInSocket;
  194200. static bool setNonBlocking (int handle)
  194201. {
  194202. int socketFlags = fcntl (handle, F_GETFL, 0);
  194203. if (socketFlags == -1)
  194204. return false;
  194205. socketFlags |= O_NONBLOCK;
  194206. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194207. }
  194208. };
  194209. struct MessageThreadFuncCall
  194210. {
  194211. enum { uniqueID = 0x73774623 };
  194212. MessageCallbackFunction* func;
  194213. void* parameter;
  194214. void* result;
  194215. CriticalSection lock;
  194216. WaitableEvent event;
  194217. };
  194218. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194219. // error handling in X11
  194220. static bool errorOccurred = false;
  194221. static bool keyboardBreakOccurred = false;
  194222. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194223. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194224. // Usually happens when client-server connection is broken
  194225. static int ioErrorHandler (Display* display)
  194226. {
  194227. DBG ("ERROR: connection to X server broken.. terminating.");
  194228. errorOccurred = true;
  194229. if (JUCEApplication::getInstance() != 0)
  194230. Process::terminate();
  194231. return 0;
  194232. }
  194233. // A protocol error has occurred
  194234. static int errorHandler (Display* display, XErrorEvent* event)
  194235. {
  194236. #ifdef JUCE_DEBUG_XERRORS
  194237. char errorStr[64] = { 0 };
  194238. char requestStr[64] = { 0 };
  194239. XGetErrorText (display, event->error_code, errorStr, 64);
  194240. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194241. "Unknown", requestStr, 64);
  194242. DBG ("ERROR: X returned " + String (errorStr) + " for operation " + String (requestStr));
  194243. #endif
  194244. return 0;
  194245. }
  194246. // Breakin from keyboard
  194247. static void signalHandler (int sig)
  194248. {
  194249. if (sig == SIGINT)
  194250. {
  194251. keyboardBreakOccurred = true;
  194252. return;
  194253. }
  194254. static bool reentrant = false;
  194255. if (! reentrant)
  194256. {
  194257. reentrant = true;
  194258. // Illegal instruction
  194259. fflush (stdout);
  194260. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194261. errorOccurred = true;
  194262. if (JUCEApplication::getInstance() != 0)
  194263. Process::terminate();
  194264. }
  194265. else
  194266. {
  194267. if (JUCEApplication::getInstance() != 0)
  194268. exit(0);
  194269. }
  194270. }
  194271. void MessageManager::doPlatformSpecificInitialisation()
  194272. {
  194273. // Initialise xlib for multiple thread support
  194274. static bool initThreadCalled = false;
  194275. if (! initThreadCalled)
  194276. {
  194277. if (! XInitThreads())
  194278. {
  194279. // This is fatal! Print error and closedown
  194280. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194281. if (JUCEApplication::getInstance() != 0)
  194282. Process::terminate();
  194283. return;
  194284. }
  194285. initThreadCalled = true;
  194286. }
  194287. // This is called if the client/server connection is broken
  194288. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194289. // This is called if a protocol error occurs
  194290. oldErrorHandler = XSetErrorHandler (errorHandler);
  194291. // Install signal handler for break-in
  194292. struct sigaction saction;
  194293. sigset_t maskSet;
  194294. sigemptyset (&maskSet);
  194295. saction.sa_handler = signalHandler;
  194296. saction.sa_mask = maskSet;
  194297. saction.sa_flags = 0;
  194298. sigaction (SIGINT, &saction, NULL);
  194299. #ifndef _DEBUG
  194300. // Setup signal handlers for various fatal errors
  194301. sigaction (SIGILL, &saction, NULL);
  194302. sigaction (SIGBUS, &saction, NULL);
  194303. sigaction (SIGFPE, &saction, NULL);
  194304. sigaction (SIGSEGV, &saction, NULL);
  194305. sigaction (SIGSYS, &saction, NULL);
  194306. #endif
  194307. // Create the internal message queue
  194308. juce_internalMessageQueue = new InternalMessageQueue();
  194309. // Try to connect to a display
  194310. String displayName (getenv ("DISPLAY"));
  194311. if (displayName.isEmpty())
  194312. displayName = ":0.0";
  194313. display = XOpenDisplay (displayName.toCString());
  194314. if (display == 0)
  194315. {
  194316. // This is not fatal! we can run headless.
  194317. return;
  194318. }
  194319. // Get defaults for various properties
  194320. int screen = DefaultScreen (display);
  194321. Window root = RootWindow (display, screen);
  194322. Visual* visual = DefaultVisual (display, screen);
  194323. // Create a context to store user data associated with Windows we
  194324. // create in WindowDriver
  194325. improbableNumber = XUniqueContext();
  194326. // We're only interested in client messages for this window
  194327. // which are always sent
  194328. XSetWindowAttributes swa;
  194329. swa.event_mask = NoEventMask;
  194330. // Create our message window (this will never be mapped)
  194331. juce_messageWindowHandle = XCreateWindow (display, root,
  194332. 0, 0, 1, 1, 0, 0, InputOnly,
  194333. visual, CWEventMask, &swa);
  194334. }
  194335. void MessageManager::doPlatformSpecificShutdown()
  194336. {
  194337. deleteAndZero (juce_internalMessageQueue);
  194338. if (display != 0 && ! errorOccurred)
  194339. {
  194340. XDestroyWindow (display, juce_messageWindowHandle);
  194341. XCloseDisplay (display);
  194342. // reset pointers
  194343. juce_messageWindowHandle = 0;
  194344. display = 0;
  194345. // Restore original error handlers
  194346. XSetIOErrorHandler (oldIOErrorHandler);
  194347. oldIOErrorHandler = 0;
  194348. XSetErrorHandler (oldErrorHandler);
  194349. oldErrorHandler = 0;
  194350. }
  194351. }
  194352. bool juce_postMessageToSystemQueue (void* message)
  194353. {
  194354. if (errorOccurred)
  194355. return false;
  194356. juce_internalMessageQueue->postMessage ((Message*) message);
  194357. return true;
  194358. }
  194359. void MessageManager::broadcastMessage (const String& value) throw()
  194360. {
  194361. }
  194362. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194363. void* parameter)
  194364. {
  194365. if (errorOccurred)
  194366. return 0;
  194367. if (! isThisTheMessageThread())
  194368. {
  194369. MessageThreadFuncCall messageCallContext;
  194370. messageCallContext.func = func;
  194371. messageCallContext.parameter = parameter;
  194372. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194373. 0, 0, &messageCallContext));
  194374. // Wait for it to complete before continuing
  194375. messageCallContext.event.wait();
  194376. return messageCallContext.result;
  194377. }
  194378. else
  194379. {
  194380. // Just call the function directly
  194381. return func (parameter);
  194382. }
  194383. }
  194384. // Wait for an event (either XEvent, or an internal Message)
  194385. static bool juce_sleepUntilEvent (const int timeoutMs)
  194386. {
  194387. if (! juce_internalMessageQueue->isEmpty())
  194388. return true;
  194389. if (display != 0)
  194390. {
  194391. ScopedXLock xlock;
  194392. if (XPending (display))
  194393. return true;
  194394. }
  194395. struct timeval tv;
  194396. tv.tv_sec = 0;
  194397. tv.tv_usec = timeoutMs * 1000;
  194398. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194399. int fdmax = fd0;
  194400. fd_set readset;
  194401. FD_ZERO (&readset);
  194402. FD_SET (fd0, &readset);
  194403. if (display != 0)
  194404. {
  194405. ScopedXLock xlock;
  194406. int fd1 = XConnectionNumber (display);
  194407. FD_SET (fd1, &readset);
  194408. fdmax = jmax (fd0, fd1);
  194409. }
  194410. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194411. return (ret > 0); // ret <= 0 if error or timeout
  194412. }
  194413. // Handle next XEvent (if any)
  194414. static bool juce_dispatchNextXEvent()
  194415. {
  194416. if (display == 0)
  194417. return false;
  194418. XEvent evt;
  194419. {
  194420. ScopedXLock xlock;
  194421. if (! XPending (display))
  194422. return false;
  194423. XNextEvent (display, &evt);
  194424. }
  194425. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194426. {
  194427. juce_handleSelectionRequest (evt.xselectionrequest);
  194428. }
  194429. else if (evt.xany.window != juce_messageWindowHandle)
  194430. {
  194431. juce_windowMessageReceive (&evt);
  194432. }
  194433. return true;
  194434. }
  194435. // Handle next internal Message (if any)
  194436. static bool juce_dispatchNextInternalMessage()
  194437. {
  194438. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194439. if (msg == 0)
  194440. return false;
  194441. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194442. {
  194443. // Handle callback message
  194444. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194445. call->result = (*(call->func)) (call->parameter);
  194446. call->event.signal();
  194447. }
  194448. else
  194449. {
  194450. // Handle "normal" messages
  194451. MessageManager::getInstance()->deliverMessage (msg.release());
  194452. }
  194453. return true;
  194454. }
  194455. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194456. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194457. {
  194458. for (;;)
  194459. {
  194460. if (errorOccurred)
  194461. break;
  194462. if (keyboardBreakOccurred)
  194463. {
  194464. errorOccurred = true;
  194465. if (JUCEApplication::getInstance() != 0)
  194466. Process::terminate();
  194467. break;
  194468. }
  194469. static int totalEventCount = 0;
  194470. ++totalEventCount;
  194471. // The purpose here is to give either priority to XEvents or
  194472. // to internal messages This is necessary to keep a "good"
  194473. // behaviour when the cpu is overloaded
  194474. if (totalEventCount & 1)
  194475. {
  194476. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194477. return true;
  194478. }
  194479. else
  194480. {
  194481. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194482. return true;
  194483. }
  194484. if (returnIfNoPendingMessages) // early exit
  194485. break;
  194486. // the timeout is to be on the safe side, but it does not seem to be useful
  194487. juce_sleepUntilEvent (2000);
  194488. }
  194489. return false;
  194490. }
  194491. #endif
  194492. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194493. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194494. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194495. // compiled on its own).
  194496. #if JUCE_INCLUDED_FILE
  194497. class FreeTypeFontFace
  194498. {
  194499. public:
  194500. enum FontStyle
  194501. {
  194502. Plain = 0,
  194503. Bold = 1,
  194504. Italic = 2
  194505. };
  194506. struct FontNameIndex
  194507. {
  194508. String fileName;
  194509. int faceIndex;
  194510. };
  194511. FreeTypeFontFace (const String& familyName)
  194512. : hasSerif (false),
  194513. monospaced (false)
  194514. {
  194515. family = familyName;
  194516. }
  194517. void setFileName (const String& name, const int faceIndex, FontStyle style)
  194518. {
  194519. if (names [(int) style].fileName.isEmpty())
  194520. {
  194521. names [(int) style].fileName = name;
  194522. names [(int) style].faceIndex = faceIndex;
  194523. }
  194524. }
  194525. const String& getFamilyName() const throw() { return family; }
  194526. const String& getFileName (const int style, int& faceIndex) const throw()
  194527. {
  194528. faceIndex = names[style].faceIndex;
  194529. return names[style].fileName;
  194530. }
  194531. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194532. bool getMonospaced() const throw() { return monospaced; }
  194533. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194534. bool getSerif() const throw() { return hasSerif; }
  194535. private:
  194536. String family;
  194537. FontNameIndex names[4];
  194538. bool hasSerif, monospaced;
  194539. };
  194540. class FreeTypeInterface : public DeletedAtShutdown
  194541. {
  194542. public:
  194543. FreeTypeInterface()
  194544. : lastFace (0),
  194545. lastBold (false),
  194546. lastItalic (false)
  194547. {
  194548. if (FT_Init_FreeType (&ftLib) != 0)
  194549. {
  194550. ftLib = 0;
  194551. DBG ("Failed to initialize FreeType");
  194552. }
  194553. StringArray fontDirs;
  194554. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194555. fontDirs.removeEmptyStrings (true);
  194556. if (fontDirs.size() == 0)
  194557. {
  194558. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194559. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194560. if (fontsInfo != 0)
  194561. {
  194562. forEachXmlChildElementWithTagName (*fontsInfo, e, "dir")
  194563. {
  194564. fontDirs.add (e->getAllSubText().trim());
  194565. }
  194566. delete fontsInfo;
  194567. }
  194568. }
  194569. if (fontDirs.size() == 0)
  194570. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194571. for (int i = 0; i < fontDirs.size(); ++i)
  194572. enumerateFaces (fontDirs[i]);
  194573. }
  194574. ~FreeTypeInterface()
  194575. {
  194576. if (lastFace != 0)
  194577. FT_Done_Face (lastFace);
  194578. if (ftLib != 0)
  194579. FT_Done_FreeType (ftLib);
  194580. clearSingletonInstance();
  194581. }
  194582. FreeTypeFontFace* findOrCreate (const String& familyName, const bool create = false)
  194583. {
  194584. for (int i = 0; i < faces.size(); i++)
  194585. if (faces[i]->getFamilyName() == familyName)
  194586. return faces[i];
  194587. if (! create)
  194588. return NULL;
  194589. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194590. faces.add (newFace);
  194591. return newFace;
  194592. }
  194593. // Enumerate all font faces available in a given directory
  194594. void enumerateFaces (const String& path)
  194595. {
  194596. File dirPath (path);
  194597. if (path.isEmpty() || ! dirPath.isDirectory())
  194598. return;
  194599. DirectoryIterator di (dirPath, true);
  194600. while (di.next())
  194601. {
  194602. File possible (di.getFile());
  194603. if (possible.hasFileExtension ("ttf")
  194604. || possible.hasFileExtension ("pfb")
  194605. || possible.hasFileExtension ("pcf"))
  194606. {
  194607. FT_Face face;
  194608. int faceIndex = 0;
  194609. int numFaces = 0;
  194610. do
  194611. {
  194612. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194613. faceIndex, &face) == 0)
  194614. {
  194615. if (faceIndex == 0)
  194616. numFaces = face->num_faces;
  194617. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194618. {
  194619. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194620. int style = (int) FreeTypeFontFace::Plain;
  194621. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194622. style |= (int) FreeTypeFontFace::Bold;
  194623. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194624. style |= (int) FreeTypeFontFace::Italic;
  194625. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194626. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194627. // Surely there must be a better way to do this?
  194628. const String name (face->family_name);
  194629. newFace->setSerif (! (name.containsIgnoreCase ("Sans")
  194630. || name.containsIgnoreCase ("Verdana")
  194631. || name.containsIgnoreCase ("Arial")));
  194632. }
  194633. FT_Done_Face (face);
  194634. }
  194635. ++faceIndex;
  194636. }
  194637. while (faceIndex < numFaces);
  194638. }
  194639. }
  194640. }
  194641. // Create a FreeType face object for a given font
  194642. FT_Face createFT_Face (const String& fontName, const bool bold, const bool italic)
  194643. {
  194644. FT_Face face = 0;
  194645. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194646. {
  194647. face = lastFace;
  194648. }
  194649. else
  194650. {
  194651. if (lastFace != 0)
  194652. {
  194653. FT_Done_Face (lastFace);
  194654. lastFace = 0;
  194655. }
  194656. lastFontName = fontName;
  194657. lastBold = bold;
  194658. lastItalic = italic;
  194659. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194660. if (ftFace != 0)
  194661. {
  194662. int style = (int) FreeTypeFontFace::Plain;
  194663. if (bold)
  194664. style |= (int) FreeTypeFontFace::Bold;
  194665. if (italic)
  194666. style |= (int) FreeTypeFontFace::Italic;
  194667. int faceIndex;
  194668. String fileName (ftFace->getFileName (style, faceIndex));
  194669. if (fileName.isEmpty())
  194670. {
  194671. style ^= (int) FreeTypeFontFace::Bold;
  194672. fileName = ftFace->getFileName (style, faceIndex);
  194673. if (fileName.isEmpty())
  194674. {
  194675. style ^= (int) FreeTypeFontFace::Bold;
  194676. style ^= (int) FreeTypeFontFace::Italic;
  194677. fileName = ftFace->getFileName (style, faceIndex);
  194678. if (! fileName.length())
  194679. {
  194680. style ^= (int) FreeTypeFontFace::Bold;
  194681. fileName = ftFace->getFileName (style, faceIndex);
  194682. }
  194683. }
  194684. }
  194685. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194686. {
  194687. face = lastFace;
  194688. // If there isn't a unicode charmap then select the first one.
  194689. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194690. FT_Set_Charmap (face, face->charmaps[0]);
  194691. }
  194692. }
  194693. }
  194694. return face;
  194695. }
  194696. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character)
  194697. {
  194698. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194699. const float height = (float) (face->ascender - face->descender);
  194700. const float scaleX = 1.0f / height;
  194701. const float scaleY = -1.0f / height;
  194702. Path destShape;
  194703. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194704. || face->glyph->format != ft_glyph_format_outline)
  194705. {
  194706. return false;
  194707. }
  194708. const FT_Outline* const outline = &face->glyph->outline;
  194709. const short* const contours = outline->contours;
  194710. const char* const tags = outline->tags;
  194711. FT_Vector* const points = outline->points;
  194712. for (int c = 0; c < outline->n_contours; c++)
  194713. {
  194714. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194715. const int endPoint = contours[c];
  194716. for (int p = startPoint; p <= endPoint; p++)
  194717. {
  194718. const float x = scaleX * points[p].x;
  194719. const float y = scaleY * points[p].y;
  194720. if (p == startPoint)
  194721. {
  194722. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194723. {
  194724. float x2 = scaleX * points [endPoint].x;
  194725. float y2 = scaleY * points [endPoint].y;
  194726. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194727. {
  194728. x2 = (x + x2) * 0.5f;
  194729. y2 = (y + y2) * 0.5f;
  194730. }
  194731. destShape.startNewSubPath (x2, y2);
  194732. }
  194733. else
  194734. {
  194735. destShape.startNewSubPath (x, y);
  194736. }
  194737. }
  194738. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194739. {
  194740. if (p != startPoint)
  194741. destShape.lineTo (x, y);
  194742. }
  194743. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194744. {
  194745. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194746. float x2 = scaleX * points [nextIndex].x;
  194747. float y2 = scaleY * points [nextIndex].y;
  194748. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194749. {
  194750. x2 = (x + x2) * 0.5f;
  194751. y2 = (y + y2) * 0.5f;
  194752. }
  194753. else
  194754. {
  194755. ++p;
  194756. }
  194757. destShape.quadraticTo (x, y, x2, y2);
  194758. }
  194759. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194760. {
  194761. if (p >= endPoint)
  194762. return false;
  194763. const int next1 = p + 1;
  194764. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194765. const float x2 = scaleX * points [next1].x;
  194766. const float y2 = scaleY * points [next1].y;
  194767. const float x3 = scaleX * points [next2].x;
  194768. const float y3 = scaleY * points [next2].y;
  194769. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194770. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194771. return false;
  194772. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194773. p += 2;
  194774. }
  194775. }
  194776. destShape.closeSubPath();
  194777. }
  194778. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194779. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194780. addKerning (face, dest, character, glyphIndex);
  194781. return true;
  194782. }
  194783. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex)
  194784. {
  194785. const float height = (float) (face->ascender - face->descender);
  194786. uint32 rightGlyphIndex;
  194787. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  194788. while (rightGlyphIndex != 0)
  194789. {
  194790. FT_Vector kerning;
  194791. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  194792. {
  194793. if (kerning.x != 0)
  194794. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  194795. }
  194796. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  194797. }
  194798. }
  194799. // Add a glyph to a font
  194800. bool addGlyphToFont (const uint32 character,
  194801. const tchar* fontName, bool bold, bool italic,
  194802. CustomTypeface& dest)
  194803. {
  194804. FT_Face face = createFT_Face (fontName, bold, italic);
  194805. if (face != 0)
  194806. return addGlyph (face, dest, character);
  194807. return false;
  194808. }
  194809. void getFamilyNames (StringArray& familyNames) const
  194810. {
  194811. for (int i = 0; i < faces.size(); i++)
  194812. familyNames.add (faces[i]->getFamilyName());
  194813. }
  194814. void getMonospacedNames (StringArray& monoSpaced) const
  194815. {
  194816. for (int i = 0; i < faces.size(); i++)
  194817. if (faces[i]->getMonospaced())
  194818. monoSpaced.add (faces[i]->getFamilyName());
  194819. }
  194820. void getSerifNames (StringArray& serif) const
  194821. {
  194822. for (int i = 0; i < faces.size(); i++)
  194823. if (faces[i]->getSerif())
  194824. serif.add (faces[i]->getFamilyName());
  194825. }
  194826. void getSansSerifNames (StringArray& sansSerif) const
  194827. {
  194828. for (int i = 0; i < faces.size(); i++)
  194829. if (! faces[i]->getSerif())
  194830. sansSerif.add (faces[i]->getFamilyName());
  194831. }
  194832. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  194833. private:
  194834. FT_Library ftLib;
  194835. FT_Face lastFace;
  194836. String lastFontName;
  194837. bool lastBold, lastItalic;
  194838. OwnedArray<FreeTypeFontFace> faces;
  194839. };
  194840. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  194841. class FreetypeTypeface : public CustomTypeface
  194842. {
  194843. public:
  194844. FreetypeTypeface (const Font& font)
  194845. {
  194846. FT_Face face = FreeTypeInterface::getInstance()
  194847. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  194848. if (face == 0)
  194849. {
  194850. #ifdef JUCE_DEBUG
  194851. String msg ("Failed to create typeface: ");
  194852. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  194853. DBG (msg);
  194854. #endif
  194855. }
  194856. else
  194857. {
  194858. setCharacteristics (font.getTypefaceName(),
  194859. face->ascender / (float) (face->ascender - face->descender),
  194860. font.isBold(), font.isItalic(),
  194861. L' ');
  194862. }
  194863. }
  194864. bool loadGlyphIfPossible (juce_wchar character)
  194865. {
  194866. return FreeTypeInterface::getInstance()
  194867. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  194868. }
  194869. };
  194870. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  194871. {
  194872. return new FreetypeTypeface (font);
  194873. }
  194874. const StringArray Font::findAllTypefaceNames()
  194875. {
  194876. StringArray s;
  194877. FreeTypeInterface::getInstance()->getFamilyNames (s);
  194878. s.sort (true);
  194879. return s;
  194880. }
  194881. static const String pickBestFont (const StringArray& names,
  194882. const char* const choicesString)
  194883. {
  194884. StringArray choices;
  194885. choices.addTokens (String (choicesString), ",", String::empty);
  194886. choices.trim();
  194887. choices.removeEmptyStrings();
  194888. int i, j;
  194889. for (j = 0; j < choices.size(); ++j)
  194890. if (names.contains (choices[j], true))
  194891. return choices[j];
  194892. for (j = 0; j < choices.size(); ++j)
  194893. for (i = 0; i < names.size(); i++)
  194894. if (names[i].startsWithIgnoreCase (choices[j]))
  194895. return names[i];
  194896. for (j = 0; j < choices.size(); ++j)
  194897. for (i = 0; i < names.size(); i++)
  194898. if (names[i].containsIgnoreCase (choices[j]))
  194899. return names[i];
  194900. return names[0];
  194901. }
  194902. static const String linux_getDefaultSansSerifFontName()
  194903. {
  194904. StringArray allFonts;
  194905. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  194906. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  194907. }
  194908. static const String linux_getDefaultSerifFontName()
  194909. {
  194910. StringArray allFonts;
  194911. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  194912. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  194913. }
  194914. static const String linux_getDefaultMonospacedFontName()
  194915. {
  194916. StringArray allFonts;
  194917. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  194918. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  194919. }
  194920. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  194921. {
  194922. defaultSans = linux_getDefaultSansSerifFontName();
  194923. defaultSerif = linux_getDefaultSerifFontName();
  194924. defaultFixed = linux_getDefaultMonospacedFontName();
  194925. }
  194926. #endif
  194927. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  194928. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  194929. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194930. // compiled on its own).
  194931. #if JUCE_INCLUDED_FILE
  194932. // These are defined in juce_linux_Messaging.cpp
  194933. extern Display* display;
  194934. extern XContext improbableNumber;
  194935. namespace Atoms
  194936. {
  194937. enum ProtocolItems
  194938. {
  194939. TAKE_FOCUS = 0,
  194940. DELETE_WINDOW = 1,
  194941. PING = 2
  194942. };
  194943. static Atom Protocols, ProtocolList[3], ChangeState, State,
  194944. ActiveWin, Pid, WindowType, WindowState,
  194945. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  194946. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  194947. XdndActionDescription, XdndActionCopy,
  194948. allowedActions[5],
  194949. allowedMimeTypes[2];
  194950. const unsigned long DndVersion = 3;
  194951. static void initialiseAtoms()
  194952. {
  194953. static bool atomsInitialised = false;
  194954. if (! atomsInitialised)
  194955. {
  194956. atomsInitialised = true;
  194957. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  194958. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  194959. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  194960. ProtocolList [PING] = XInternAtom (display, "_NET_WM_PING", True);
  194961. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  194962. State = XInternAtom (display, "WM_STATE", True);
  194963. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  194964. Pid = XInternAtom (display, "_NET_WM_PID", False);
  194965. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  194966. WindowState = XInternAtom (display, "_NET_WM_STATE", True);
  194967. XdndAware = XInternAtom (display, "XdndAware", False);
  194968. XdndEnter = XInternAtom (display, "XdndEnter", False);
  194969. XdndLeave = XInternAtom (display, "XdndLeave", False);
  194970. XdndPosition = XInternAtom (display, "XdndPosition", False);
  194971. XdndStatus = XInternAtom (display, "XdndStatus", False);
  194972. XdndDrop = XInternAtom (display, "XdndDrop", False);
  194973. XdndFinished = XInternAtom (display, "XdndFinished", False);
  194974. XdndSelection = XInternAtom (display, "XdndSelection", False);
  194975. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  194976. XdndActionList = XInternAtom (display, "XdndActionList", False);
  194977. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  194978. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  194979. allowedMimeTypes[0] = XInternAtom (display, "text/plain", False);
  194980. allowedMimeTypes[1] = XInternAtom (display, "text/uri-list", False);
  194981. allowedActions[0] = XInternAtom (display, "XdndActionMove", False);
  194982. allowedActions[1] = XdndActionCopy;
  194983. allowedActions[2] = XInternAtom (display, "XdndActionLink", False);
  194984. allowedActions[3] = XInternAtom (display, "XdndActionAsk", False);
  194985. allowedActions[4] = XInternAtom (display, "XdndActionPrivate", False);
  194986. }
  194987. }
  194988. }
  194989. namespace Keys
  194990. {
  194991. enum MouseButtons
  194992. {
  194993. NoButton = 0,
  194994. LeftButton = 1,
  194995. MiddleButton = 2,
  194996. RightButton = 3,
  194997. WheelUp = 4,
  194998. WheelDown = 5
  194999. };
  195000. static int AltMask = 0;
  195001. static int NumLockMask = 0;
  195002. static bool numLock = false;
  195003. static bool capsLock = false;
  195004. static char keyStates [32];
  195005. static const int extendedKeyModifier = 0x10000000;
  195006. }
  195007. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  195008. {
  195009. int keysym;
  195010. if (keyCode & Keys::extendedKeyModifier)
  195011. {
  195012. keysym = 0xff00 | (keyCode & 0xff);
  195013. }
  195014. else
  195015. {
  195016. keysym = keyCode;
  195017. if (keysym == (XK_Tab & 0xff)
  195018. || keysym == (XK_Return & 0xff)
  195019. || keysym == (XK_Escape & 0xff)
  195020. || keysym == (XK_BackSpace & 0xff))
  195021. {
  195022. keysym |= 0xff00;
  195023. }
  195024. }
  195025. ScopedXLock xlock;
  195026. const int keycode = XKeysymToKeycode (display, keysym);
  195027. const int keybyte = keycode >> 3;
  195028. const int keybit = (1 << (keycode & 7));
  195029. return (Keys::keyStates [keybyte] & keybit) != 0;
  195030. }
  195031. #if JUCE_USE_XSHM
  195032. namespace XSHMHelpers
  195033. {
  195034. static int trappedErrorCode = 0;
  195035. extern "C" int errorTrapHandler (Display*, XErrorEvent* err)
  195036. {
  195037. trappedErrorCode = err->error_code;
  195038. return 0;
  195039. }
  195040. static bool isShmAvailable() throw()
  195041. {
  195042. static bool isChecked = false;
  195043. static bool isAvailable = false;
  195044. if (! isChecked)
  195045. {
  195046. isChecked = true;
  195047. int major, minor;
  195048. Bool pixmaps;
  195049. ScopedXLock xlock;
  195050. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195051. {
  195052. trappedErrorCode = 0;
  195053. XErrorHandler oldHandler = XSetErrorHandler (errorTrapHandler);
  195054. XShmSegmentInfo segmentInfo;
  195055. zerostruct (segmentInfo);
  195056. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195057. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195058. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195059. xImage->bytes_per_line * xImage->height,
  195060. IPC_CREAT | 0777)) >= 0)
  195061. {
  195062. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195063. if (segmentInfo.shmaddr != (void*) -1)
  195064. {
  195065. segmentInfo.readOnly = False;
  195066. xImage->data = segmentInfo.shmaddr;
  195067. XSync (display, False);
  195068. if (XShmAttach (display, &segmentInfo) != 0)
  195069. {
  195070. XSync (display, False);
  195071. XShmDetach (display, &segmentInfo);
  195072. isAvailable = true;
  195073. }
  195074. }
  195075. XFlush (display);
  195076. XDestroyImage (xImage);
  195077. shmdt (segmentInfo.shmaddr);
  195078. }
  195079. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195080. XSetErrorHandler (oldHandler);
  195081. if (trappedErrorCode != 0)
  195082. isAvailable = false;
  195083. }
  195084. }
  195085. return isAvailable;
  195086. }
  195087. }
  195088. #endif
  195089. #if JUCE_USE_XRENDER
  195090. namespace XRender
  195091. {
  195092. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195093. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195094. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195095. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195096. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195097. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195098. static tXRenderFindFormat xRenderFindFormat = 0;
  195099. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195100. static bool isAvailable()
  195101. {
  195102. static bool hasLoaded = false;
  195103. if (! hasLoaded)
  195104. {
  195105. ScopedXLock xlock;
  195106. hasLoaded = true;
  195107. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195108. if (h != 0)
  195109. {
  195110. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195111. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195112. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195113. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195114. }
  195115. if (xRenderQueryVersion != 0
  195116. && xRenderFindStandardFormat != 0
  195117. && xRenderFindFormat != 0
  195118. && xRenderFindVisualFormat != 0)
  195119. {
  195120. int major, minor;
  195121. if (xRenderQueryVersion (display, &major, &minor))
  195122. return true;
  195123. }
  195124. xRenderQueryVersion = 0;
  195125. }
  195126. return xRenderQueryVersion != 0;
  195127. }
  195128. static XRenderPictFormat* findPictureFormat()
  195129. {
  195130. ScopedXLock xlock;
  195131. XRenderPictFormat* pictFormat = 0;
  195132. if (isAvailable())
  195133. {
  195134. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195135. if (pictFormat == 0)
  195136. {
  195137. XRenderPictFormat desiredFormat;
  195138. desiredFormat.type = PictTypeDirect;
  195139. desiredFormat.depth = 32;
  195140. desiredFormat.direct.alphaMask = 0xff;
  195141. desiredFormat.direct.redMask = 0xff;
  195142. desiredFormat.direct.greenMask = 0xff;
  195143. desiredFormat.direct.blueMask = 0xff;
  195144. desiredFormat.direct.alpha = 24;
  195145. desiredFormat.direct.red = 16;
  195146. desiredFormat.direct.green = 8;
  195147. desiredFormat.direct.blue = 0;
  195148. pictFormat = xRenderFindFormat (display,
  195149. PictFormatType | PictFormatDepth
  195150. | PictFormatRedMask | PictFormatRed
  195151. | PictFormatGreenMask | PictFormatGreen
  195152. | PictFormatBlueMask | PictFormatBlue
  195153. | PictFormatAlphaMask | PictFormatAlpha,
  195154. &desiredFormat,
  195155. 0);
  195156. }
  195157. }
  195158. return pictFormat;
  195159. }
  195160. }
  195161. #endif
  195162. namespace Visuals
  195163. {
  195164. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195165. {
  195166. ScopedXLock xlock;
  195167. Visual* visual = 0;
  195168. int numVisuals = 0;
  195169. long desiredMask = VisualNoMask;
  195170. XVisualInfo desiredVisual;
  195171. desiredVisual.screen = DefaultScreen (display);
  195172. desiredVisual.depth = desiredDepth;
  195173. desiredMask = VisualScreenMask | VisualDepthMask;
  195174. if (desiredDepth == 32)
  195175. {
  195176. desiredVisual.c_class = TrueColor;
  195177. desiredVisual.red_mask = 0x00FF0000;
  195178. desiredVisual.green_mask = 0x0000FF00;
  195179. desiredVisual.blue_mask = 0x000000FF;
  195180. desiredVisual.bits_per_rgb = 8;
  195181. desiredMask |= VisualClassMask;
  195182. desiredMask |= VisualRedMaskMask;
  195183. desiredMask |= VisualGreenMaskMask;
  195184. desiredMask |= VisualBlueMaskMask;
  195185. desiredMask |= VisualBitsPerRGBMask;
  195186. }
  195187. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195188. desiredMask,
  195189. &desiredVisual,
  195190. &numVisuals);
  195191. if (xvinfos != 0)
  195192. {
  195193. for (int i = 0; i < numVisuals; i++)
  195194. {
  195195. if (xvinfos[i].depth == desiredDepth)
  195196. {
  195197. visual = xvinfos[i].visual;
  195198. break;
  195199. }
  195200. }
  195201. XFree (xvinfos);
  195202. }
  195203. return visual;
  195204. }
  195205. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195206. {
  195207. Visual* visual = 0;
  195208. if (desiredDepth == 32)
  195209. {
  195210. #if JUCE_USE_XSHM
  195211. if (XSHMHelpers::isShmAvailable())
  195212. {
  195213. #if JUCE_USE_XRENDER
  195214. if (XRender::isAvailable())
  195215. {
  195216. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195217. if (pictFormat != 0)
  195218. {
  195219. int numVisuals = 0;
  195220. XVisualInfo desiredVisual;
  195221. desiredVisual.screen = DefaultScreen (display);
  195222. desiredVisual.depth = 32;
  195223. desiredVisual.bits_per_rgb = 8;
  195224. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195225. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195226. &desiredVisual, &numVisuals);
  195227. if (xvinfos != 0)
  195228. {
  195229. for (int i = 0; i < numVisuals; ++i)
  195230. {
  195231. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195232. if (pictVisualFormat != 0
  195233. && pictVisualFormat->type == PictTypeDirect
  195234. && pictVisualFormat->direct.alphaMask)
  195235. {
  195236. visual = xvinfos[i].visual;
  195237. matchedDepth = 32;
  195238. break;
  195239. }
  195240. }
  195241. XFree (xvinfos);
  195242. }
  195243. }
  195244. }
  195245. #endif
  195246. if (visual == 0)
  195247. {
  195248. visual = findVisualWithDepth (32);
  195249. if (visual != 0)
  195250. matchedDepth = 32;
  195251. }
  195252. }
  195253. #endif
  195254. }
  195255. if (visual == 0 && desiredDepth >= 24)
  195256. {
  195257. visual = findVisualWithDepth (24);
  195258. if (visual != 0)
  195259. matchedDepth = 24;
  195260. }
  195261. if (visual == 0 && desiredDepth >= 16)
  195262. {
  195263. visual = findVisualWithDepth (16);
  195264. if (visual != 0)
  195265. matchedDepth = 16;
  195266. }
  195267. return visual;
  195268. }
  195269. }
  195270. class XBitmapImage : public Image
  195271. {
  195272. public:
  195273. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195274. const bool clearImage, const int imageDepth_, Visual* visual)
  195275. : Image (format_, w, h),
  195276. imageDepth (imageDepth_),
  195277. gc (None)
  195278. {
  195279. jassert (format_ == RGB || format_ == ARGB);
  195280. pixelStride = (format_ == RGB) ? 3 : 4;
  195281. lineStride = ((w * pixelStride + 3) & ~3);
  195282. ScopedXLock xlock;
  195283. #if JUCE_USE_XSHM
  195284. usingXShm = false;
  195285. if ((imageDepth > 16) && XSHMHelpers::isShmAvailable())
  195286. {
  195287. zerostruct (segmentInfo);
  195288. segmentInfo.shmid = -1;
  195289. segmentInfo.shmaddr = (char *) -1;
  195290. segmentInfo.readOnly = False;
  195291. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195292. if (xImage != 0)
  195293. {
  195294. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195295. xImage->bytes_per_line * xImage->height,
  195296. IPC_CREAT | 0777)) >= 0)
  195297. {
  195298. if (segmentInfo.shmid != -1)
  195299. {
  195300. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195301. if (segmentInfo.shmaddr != (void*) -1)
  195302. {
  195303. segmentInfo.readOnly = False;
  195304. xImage->data = segmentInfo.shmaddr;
  195305. imageData = (uint8*) segmentInfo.shmaddr;
  195306. if (XShmAttach (display, &segmentInfo) != 0)
  195307. {
  195308. usingXShm = true;
  195309. }
  195310. else
  195311. {
  195312. jassertfalse
  195313. }
  195314. }
  195315. else
  195316. {
  195317. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195318. }
  195319. }
  195320. }
  195321. }
  195322. }
  195323. if (! usingXShm)
  195324. #endif
  195325. {
  195326. imageDataAllocated.malloc (lineStride * h);
  195327. imageData = imageDataAllocated;
  195328. if (format_ == ARGB && clearImage)
  195329. zeromem (imageData, h * lineStride);
  195330. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195331. xImage->width = w;
  195332. xImage->height = h;
  195333. xImage->xoffset = 0;
  195334. xImage->format = ZPixmap;
  195335. xImage->data = (char*) imageData;
  195336. xImage->byte_order = ImageByteOrder (display);
  195337. xImage->bitmap_unit = BitmapUnit (display);
  195338. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195339. xImage->bitmap_pad = 32;
  195340. xImage->depth = pixelStride * 8;
  195341. xImage->bytes_per_line = lineStride;
  195342. xImage->bits_per_pixel = pixelStride * 8;
  195343. xImage->red_mask = 0x00FF0000;
  195344. xImage->green_mask = 0x0000FF00;
  195345. xImage->blue_mask = 0x000000FF;
  195346. if (imageDepth == 16)
  195347. {
  195348. const int pixelStride = 2;
  195349. const int lineStride = ((w * pixelStride + 3) & ~3);
  195350. imageData16Bit.malloc (lineStride * h);
  195351. xImage->data = imageData16Bit;
  195352. xImage->bitmap_pad = 16;
  195353. xImage->depth = pixelStride * 8;
  195354. xImage->bytes_per_line = lineStride;
  195355. xImage->bits_per_pixel = pixelStride * 8;
  195356. xImage->red_mask = visual->red_mask;
  195357. xImage->green_mask = visual->green_mask;
  195358. xImage->blue_mask = visual->blue_mask;
  195359. }
  195360. if (! XInitImage (xImage))
  195361. {
  195362. jassertfalse
  195363. }
  195364. }
  195365. }
  195366. ~XBitmapImage()
  195367. {
  195368. ScopedXLock xlock;
  195369. #if JUCE_USE_XSHM
  195370. if (usingXShm)
  195371. {
  195372. XShmDetach (display, &segmentInfo);
  195373. XFlush (display);
  195374. XDestroyImage (xImage);
  195375. shmdt (segmentInfo.shmaddr);
  195376. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195377. }
  195378. else
  195379. #endif
  195380. {
  195381. xImage->data = 0;
  195382. XDestroyImage (xImage);
  195383. }
  195384. }
  195385. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195386. {
  195387. ScopedXLock xlock;
  195388. if (gc == 0)
  195389. {
  195390. XGCValues gcvalues;
  195391. gcvalues.foreground = None;
  195392. gcvalues.background = None;
  195393. gcvalues.function = GXcopy;
  195394. gcvalues.plane_mask = AllPlanes;
  195395. gcvalues.clip_mask = None;
  195396. gcvalues.graphics_exposures = False;
  195397. gc = XCreateGC (display, window,
  195398. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195399. &gcvalues);
  195400. }
  195401. if (imageDepth == 16)
  195402. {
  195403. const uint32 rMask = xImage->red_mask;
  195404. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195405. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195406. const uint32 gMask = xImage->green_mask;
  195407. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195408. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195409. const uint32 bMask = xImage->blue_mask;
  195410. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195411. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195412. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195413. for (int y = sy; y < sy + dh; ++y)
  195414. {
  195415. const uint8* p = srcData.getPixelPointer (sx, y);
  195416. for (int x = sx; x < sx + dw; ++x)
  195417. {
  195418. const PixelRGB* const pixel = (const PixelRGB*) p;
  195419. p += srcData.pixelStride;
  195420. XPutPixel (xImage, x, y,
  195421. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195422. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195423. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195424. }
  195425. }
  195426. }
  195427. // blit results to screen.
  195428. #if JUCE_USE_XSHM
  195429. if (usingXShm)
  195430. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195431. else
  195432. #endif
  195433. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195434. }
  195435. juce_UseDebuggingNewOperator
  195436. private:
  195437. XImage* xImage;
  195438. const int imageDepth;
  195439. HeapBlock <char> imageData16Bit;
  195440. GC gc;
  195441. #if JUCE_USE_XSHM
  195442. XShmSegmentInfo segmentInfo;
  195443. bool usingXShm;
  195444. #endif
  195445. static int getShiftNeeded (const uint32 mask) throw()
  195446. {
  195447. for (int i = 32; --i >= 0;)
  195448. if (((mask >> i) & 1) != 0)
  195449. return i - 7;
  195450. jassertfalse
  195451. return 0;
  195452. }
  195453. };
  195454. class LinuxComponentPeer : public ComponentPeer
  195455. {
  195456. public:
  195457. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195458. : ComponentPeer (component, windowStyleFlags),
  195459. windowH (0),
  195460. parentWindow (0),
  195461. wx (0),
  195462. wy (0),
  195463. ww (0),
  195464. wh (0),
  195465. fullScreen (false),
  195466. mapped (false),
  195467. visual (0),
  195468. depth (0)
  195469. {
  195470. // it's dangerous to create a window on a thread other than the message thread..
  195471. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195472. repainter = new LinuxRepaintManager (this);
  195473. createWindow();
  195474. setTitle (component->getName());
  195475. }
  195476. ~LinuxComponentPeer()
  195477. {
  195478. // it's dangerous to delete a window on a thread other than the message thread..
  195479. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195480. deleteIconPixmaps();
  195481. destroyWindow();
  195482. windowH = 0;
  195483. }
  195484. void* getNativeHandle() const
  195485. {
  195486. return (void*) windowH;
  195487. }
  195488. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195489. {
  195490. XPointer peer = 0;
  195491. ScopedXLock xlock;
  195492. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195493. {
  195494. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195495. peer = 0;
  195496. }
  195497. return (LinuxComponentPeer*) peer;
  195498. }
  195499. void setVisible (bool shouldBeVisible)
  195500. {
  195501. ScopedXLock xlock;
  195502. if (shouldBeVisible)
  195503. XMapWindow (display, windowH);
  195504. else
  195505. XUnmapWindow (display, windowH);
  195506. }
  195507. void setTitle (const String& title)
  195508. {
  195509. setWindowTitle (windowH, title);
  195510. }
  195511. void setPosition (int x, int y)
  195512. {
  195513. setBounds (x, y, ww, wh, false);
  195514. }
  195515. void setSize (int w, int h)
  195516. {
  195517. setBounds (wx, wy, w, h, false);
  195518. }
  195519. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  195520. {
  195521. fullScreen = isNowFullScreen;
  195522. if (windowH != 0)
  195523. {
  195524. Component::SafePointer<Component> deletionChecker (component);
  195525. wx = x;
  195526. wy = y;
  195527. ww = jmax (1, w);
  195528. wh = jmax (1, h);
  195529. ScopedXLock xlock;
  195530. // Make sure the Window manager does what we want
  195531. XSizeHints* hints = XAllocSizeHints();
  195532. hints->flags = USSize | USPosition;
  195533. hints->width = ww;
  195534. hints->height = wh;
  195535. hints->x = wx;
  195536. hints->y = wy;
  195537. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195538. {
  195539. hints->min_width = hints->max_width = hints->width;
  195540. hints->min_height = hints->max_height = hints->height;
  195541. hints->flags |= PMinSize | PMaxSize;
  195542. }
  195543. XSetWMNormalHints (display, windowH, hints);
  195544. XFree (hints);
  195545. XMoveResizeWindow (display, windowH,
  195546. wx - windowBorder.getLeft(),
  195547. wy - windowBorder.getTop(), ww, wh);
  195548. if (deletionChecker != 0)
  195549. {
  195550. updateBorderSize();
  195551. handleMovedOrResized();
  195552. }
  195553. }
  195554. }
  195555. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195556. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195557. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195558. {
  195559. return relativePosition + getScreenPosition();
  195560. }
  195561. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195562. {
  195563. return screenPosition - getScreenPosition();
  195564. }
  195565. void setMinimised (bool shouldBeMinimised)
  195566. {
  195567. if (shouldBeMinimised)
  195568. {
  195569. Window root = RootWindow (display, DefaultScreen (display));
  195570. XClientMessageEvent clientMsg;
  195571. clientMsg.display = display;
  195572. clientMsg.window = windowH;
  195573. clientMsg.type = ClientMessage;
  195574. clientMsg.format = 32;
  195575. clientMsg.message_type = Atoms::ChangeState;
  195576. clientMsg.data.l[0] = IconicState;
  195577. ScopedXLock xlock;
  195578. XSendEvent (display, root, false,
  195579. SubstructureRedirectMask | SubstructureNotifyMask,
  195580. (XEvent*) &clientMsg);
  195581. }
  195582. else
  195583. {
  195584. setVisible (true);
  195585. }
  195586. }
  195587. bool isMinimised() const
  195588. {
  195589. bool minimised = false;
  195590. unsigned char* stateProp;
  195591. unsigned long nitems, bytesLeft;
  195592. Atom actualType;
  195593. int actualFormat;
  195594. ScopedXLock xlock;
  195595. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195596. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195597. &stateProp) == Success
  195598. && actualType == Atoms::State
  195599. && actualFormat == 32
  195600. && nitems > 0)
  195601. {
  195602. if (((unsigned long*) stateProp)[0] == IconicState)
  195603. minimised = true;
  195604. XFree (stateProp);
  195605. }
  195606. return minimised;
  195607. }
  195608. void setFullScreen (const bool shouldBeFullScreen)
  195609. {
  195610. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195611. setMinimised (false);
  195612. if (fullScreen != shouldBeFullScreen)
  195613. {
  195614. if (shouldBeFullScreen)
  195615. r = Desktop::getInstance().getMainMonitorArea();
  195616. if (! r.isEmpty())
  195617. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195618. getComponent()->repaint();
  195619. }
  195620. }
  195621. bool isFullScreen() const
  195622. {
  195623. return fullScreen;
  195624. }
  195625. bool isChildWindowOf (Window possibleParent) const
  195626. {
  195627. Window* windowList = 0;
  195628. uint32 windowListSize = 0;
  195629. Window parent, root;
  195630. ScopedXLock xlock;
  195631. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195632. {
  195633. if (windowList != 0)
  195634. XFree (windowList);
  195635. return parent == possibleParent;
  195636. }
  195637. return false;
  195638. }
  195639. bool isFrontWindow() const
  195640. {
  195641. Window* windowList = 0;
  195642. uint32 windowListSize = 0;
  195643. bool result = false;
  195644. ScopedXLock xlock;
  195645. Window parent, root = RootWindow (display, DefaultScreen (display));
  195646. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195647. {
  195648. for (int i = windowListSize; --i >= 0;)
  195649. {
  195650. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195651. if (peer != 0)
  195652. {
  195653. result = (peer == this);
  195654. break;
  195655. }
  195656. }
  195657. }
  195658. if (windowList != 0)
  195659. XFree (windowList);
  195660. return result;
  195661. }
  195662. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195663. {
  195664. int x = position.getX();
  195665. int y = position.getY();
  195666. if (((unsigned int) x) >= (unsigned int) ww
  195667. || ((unsigned int) y) >= (unsigned int) wh)
  195668. return false;
  195669. bool inFront = false;
  195670. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195671. {
  195672. Component* const c = Desktop::getInstance().getComponent (i);
  195673. if (inFront)
  195674. {
  195675. if (c->contains (x + wx - c->getScreenX(),
  195676. y + wy - c->getScreenY()))
  195677. {
  195678. return false;
  195679. }
  195680. }
  195681. else if (c == getComponent())
  195682. {
  195683. inFront = true;
  195684. }
  195685. }
  195686. if (trueIfInAChildWindow)
  195687. return true;
  195688. ::Window root, child;
  195689. unsigned int bw, depth;
  195690. int wx, wy, w, h;
  195691. ScopedXLock xlock;
  195692. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195693. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195694. &bw, &depth))
  195695. {
  195696. return false;
  195697. }
  195698. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195699. return false;
  195700. return child == None;
  195701. }
  195702. const BorderSize getFrameSize() const
  195703. {
  195704. return BorderSize();
  195705. }
  195706. bool setAlwaysOnTop (bool alwaysOnTop)
  195707. {
  195708. if (windowH != 0)
  195709. {
  195710. const bool wasVisible = component->isVisible();
  195711. if (wasVisible)
  195712. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195713. {
  195714. ScopedXLock xlock;
  195715. XSetWindowAttributes swa;
  195716. swa.override_redirect = alwaysOnTop ? True : False;
  195717. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195718. }
  195719. if (wasVisible)
  195720. setVisible (true);
  195721. }
  195722. return true;
  195723. }
  195724. void toFront (bool makeActive)
  195725. {
  195726. if (makeActive)
  195727. {
  195728. setVisible (true);
  195729. grabFocus();
  195730. }
  195731. XEvent ev;
  195732. ev.xclient.type = ClientMessage;
  195733. ev.xclient.serial = 0;
  195734. ev.xclient.send_event = True;
  195735. ev.xclient.message_type = Atoms::ActiveWin;
  195736. ev.xclient.window = windowH;
  195737. ev.xclient.format = 32;
  195738. ev.xclient.data.l[0] = 2;
  195739. ev.xclient.data.l[1] = CurrentTime;
  195740. ev.xclient.data.l[2] = 0;
  195741. ev.xclient.data.l[3] = 0;
  195742. ev.xclient.data.l[4] = 0;
  195743. {
  195744. ScopedXLock xlock;
  195745. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195746. False,
  195747. SubstructureRedirectMask | SubstructureNotifyMask,
  195748. &ev);
  195749. XWindowAttributes attr;
  195750. XGetWindowAttributes (display, windowH, &attr);
  195751. if (attr.override_redirect)
  195752. XRaiseWindow (display, windowH);
  195753. XSync (display, False);
  195754. }
  195755. handleBroughtToFront();
  195756. }
  195757. void toBehind (ComponentPeer* other)
  195758. {
  195759. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195760. jassert (otherPeer != 0); // wrong type of window?
  195761. if (otherPeer != 0)
  195762. {
  195763. setMinimised (false);
  195764. Window newStack[] = { otherPeer->windowH, windowH };
  195765. ScopedXLock xlock;
  195766. XRestackWindows (display, newStack, 2);
  195767. }
  195768. }
  195769. bool isFocused() const
  195770. {
  195771. int revert;
  195772. Window focusedWindow = 0;
  195773. ScopedXLock xlock;
  195774. XGetInputFocus (display, &focusedWindow, &revert);
  195775. return focusedWindow == windowH;
  195776. }
  195777. void grabFocus()
  195778. {
  195779. XWindowAttributes atts;
  195780. ScopedXLock xlock;
  195781. if (windowH != 0
  195782. && XGetWindowAttributes (display, windowH, &atts)
  195783. && atts.map_state == IsViewable
  195784. && ! isFocused())
  195785. {
  195786. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  195787. isActiveApplication = true;
  195788. }
  195789. }
  195790. void textInputRequired (const Point<int>&)
  195791. {
  195792. }
  195793. void repaint (int x, int y, int w, int h)
  195794. {
  195795. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  195796. 0, 0,
  195797. getComponent()->getWidth(),
  195798. getComponent()->getHeight()))
  195799. {
  195800. repainter->repaint (x, y, w, h);
  195801. }
  195802. }
  195803. void performAnyPendingRepaintsNow()
  195804. {
  195805. repainter->performAnyPendingRepaintsNow();
  195806. }
  195807. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195808. {
  195809. ScopedXLock xlock;
  195810. const int width = image.getWidth();
  195811. const int height = image.getHeight();
  195812. HeapBlock <char> colour (width * height);
  195813. int index = 0;
  195814. for (int y = 0; y < height; ++y)
  195815. for (int x = 0; x < width; ++x)
  195816. colour[index++] = static_cast<char> (image.getPixelAt (x, y).getARGB());
  195817. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195818. 0, colour.getData(),
  195819. width, height, 32, 0);
  195820. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195821. width, height, 24);
  195822. GC gc = XCreateGC (display, pixmap, 0, 0);
  195823. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195824. XFreeGC (display, gc);
  195825. return pixmap;
  195826. }
  195827. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195828. {
  195829. ScopedXLock xlock;
  195830. const int width = image.getWidth();
  195831. const int height = image.getHeight();
  195832. const int stride = (width + 7) >> 3;
  195833. HeapBlock <char> mask;
  195834. mask.calloc (stride * height);
  195835. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195836. for (int y = 0; y < height; ++y)
  195837. {
  195838. for (int x = 0; x < width; ++x)
  195839. {
  195840. const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195841. const int offset = y * stride + (x >> 3);
  195842. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195843. mask[offset] |= bit;
  195844. }
  195845. }
  195846. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195847. mask.getData(), width, height, 1, 0, 1);
  195848. }
  195849. void setIcon (const Image& newIcon)
  195850. {
  195851. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  195852. HeapBlock <unsigned long> data (dataSize);
  195853. int index = 0;
  195854. data[index++] = newIcon.getWidth();
  195855. data[index++] = newIcon.getHeight();
  195856. for (int y = 0; y < newIcon.getHeight(); ++y)
  195857. for (int x = 0; x < newIcon.getWidth(); ++x)
  195858. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  195859. ScopedXLock xlock;
  195860. XChangeProperty (display, windowH,
  195861. XInternAtom (display, "_NET_WM_ICON", False),
  195862. XA_CARDINAL, 32, PropModeReplace,
  195863. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  195864. deleteIconPixmaps();
  195865. XWMHints* wmHints = XGetWMHints (display, windowH);
  195866. if (wmHints == 0)
  195867. wmHints = XAllocWMHints();
  195868. wmHints->flags |= IconPixmapHint | IconMaskHint;
  195869. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  195870. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  195871. XSetWMHints (display, windowH, wmHints);
  195872. XFree (wmHints);
  195873. XSync (display, False);
  195874. }
  195875. void deleteIconPixmaps()
  195876. {
  195877. ScopedXLock xlock;
  195878. XWMHints* wmHints = XGetWMHints (display, windowH);
  195879. if (wmHints != 0)
  195880. {
  195881. if ((wmHints->flags & IconPixmapHint) != 0)
  195882. {
  195883. wmHints->flags &= ~IconPixmapHint;
  195884. XFreePixmap (display, wmHints->icon_pixmap);
  195885. }
  195886. if ((wmHints->flags & IconMaskHint) != 0)
  195887. {
  195888. wmHints->flags &= ~IconMaskHint;
  195889. XFreePixmap (display, wmHints->icon_mask);
  195890. }
  195891. XSetWMHints (display, windowH, wmHints);
  195892. XFree (wmHints);
  195893. }
  195894. }
  195895. void handleWindowMessage (XEvent* event)
  195896. {
  195897. switch (event->xany.type)
  195898. {
  195899. case 2: // 'KeyPress'
  195900. {
  195901. ScopedXLock xlock;
  195902. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  195903. updateKeyStates (keyEvent->keycode, true);
  195904. char utf8 [64];
  195905. zeromem (utf8, sizeof (utf8));
  195906. KeySym sym;
  195907. {
  195908. const char* oldLocale = ::setlocale (LC_ALL, 0);
  195909. ::setlocale (LC_ALL, "");
  195910. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  195911. ::setlocale (LC_ALL, oldLocale);
  195912. }
  195913. const juce_wchar unicodeChar = String::fromUTF8 (utf8, sizeof (utf8) - 1) [0];
  195914. int keyCode = (int) unicodeChar;
  195915. if (keyCode < 0x20)
  195916. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  195917. const ModifierKeys oldMods (currentModifiers);
  195918. bool keyPressed = false;
  195919. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  195920. if ((sym & 0xff00) == 0xff00)
  195921. {
  195922. // Translate keypad
  195923. if (sym == XK_KP_Divide)
  195924. keyCode = XK_slash;
  195925. else if (sym == XK_KP_Multiply)
  195926. keyCode = XK_asterisk;
  195927. else if (sym == XK_KP_Subtract)
  195928. keyCode = XK_hyphen;
  195929. else if (sym == XK_KP_Add)
  195930. keyCode = XK_plus;
  195931. else if (sym == XK_KP_Enter)
  195932. keyCode = XK_Return;
  195933. else if (sym == XK_KP_Decimal)
  195934. keyCode = Keys::numLock ? XK_period : XK_Delete;
  195935. else if (sym == XK_KP_0)
  195936. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  195937. else if (sym == XK_KP_1)
  195938. keyCode = Keys::numLock ? XK_1 : XK_End;
  195939. else if (sym == XK_KP_2)
  195940. keyCode = Keys::numLock ? XK_2 : XK_Down;
  195941. else if (sym == XK_KP_3)
  195942. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  195943. else if (sym == XK_KP_4)
  195944. keyCode = Keys::numLock ? XK_4 : XK_Left;
  195945. else if (sym == XK_KP_5)
  195946. keyCode = XK_5;
  195947. else if (sym == XK_KP_6)
  195948. keyCode = Keys::numLock ? XK_6 : XK_Right;
  195949. else if (sym == XK_KP_7)
  195950. keyCode = Keys::numLock ? XK_7 : XK_Home;
  195951. else if (sym == XK_KP_8)
  195952. keyCode = Keys::numLock ? XK_8 : XK_Up;
  195953. else if (sym == XK_KP_9)
  195954. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  195955. switch (sym)
  195956. {
  195957. case XK_Left:
  195958. case XK_Right:
  195959. case XK_Up:
  195960. case XK_Down:
  195961. case XK_Page_Up:
  195962. case XK_Page_Down:
  195963. case XK_End:
  195964. case XK_Home:
  195965. case XK_Delete:
  195966. case XK_Insert:
  195967. keyPressed = true;
  195968. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  195969. break;
  195970. case XK_Tab:
  195971. case XK_Return:
  195972. case XK_Escape:
  195973. case XK_BackSpace:
  195974. keyPressed = true;
  195975. keyCode &= 0xff;
  195976. break;
  195977. default:
  195978. {
  195979. if (sym >= XK_F1 && sym <= XK_F16)
  195980. {
  195981. keyPressed = true;
  195982. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  195983. }
  195984. break;
  195985. }
  195986. }
  195987. }
  195988. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  195989. keyPressed = true;
  195990. if (oldMods != currentModifiers)
  195991. handleModifierKeysChange();
  195992. if (keyDownChange)
  195993. handleKeyUpOrDown (true);
  195994. if (keyPressed)
  195995. handleKeyPress (keyCode, unicodeChar);
  195996. break;
  195997. }
  195998. case KeyRelease:
  195999. {
  196000. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196001. updateKeyStates (keyEvent->keycode, false);
  196002. ScopedXLock xlock;
  196003. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196004. const ModifierKeys oldMods (currentModifiers);
  196005. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196006. if (oldMods != currentModifiers)
  196007. handleModifierKeysChange();
  196008. if (keyDownChange)
  196009. handleKeyUpOrDown (false);
  196010. break;
  196011. }
  196012. case ButtonPress:
  196013. {
  196014. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196015. updateKeyModifiers (buttonPressEvent->state);
  196016. bool buttonMsg = false;
  196017. const int map = pointerMap [buttonPressEvent->button - Button1];
  196018. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196019. {
  196020. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196021. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196022. }
  196023. if (map == Keys::LeftButton)
  196024. {
  196025. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196026. buttonMsg = true;
  196027. }
  196028. else if (map == Keys::RightButton)
  196029. {
  196030. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196031. buttonMsg = true;
  196032. }
  196033. else if (map == Keys::MiddleButton)
  196034. {
  196035. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196036. buttonMsg = true;
  196037. }
  196038. if (buttonMsg)
  196039. {
  196040. toFront (true);
  196041. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196042. getEventTime (buttonPressEvent->time));
  196043. }
  196044. clearLastMousePos();
  196045. break;
  196046. }
  196047. case ButtonRelease:
  196048. {
  196049. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196050. updateKeyModifiers (buttonRelEvent->state);
  196051. const int map = pointerMap [buttonRelEvent->button - Button1];
  196052. if (map == Keys::LeftButton)
  196053. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196054. else if (map == Keys::RightButton)
  196055. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196056. else if (map == Keys::MiddleButton)
  196057. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196058. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196059. getEventTime (buttonRelEvent->time));
  196060. clearLastMousePos();
  196061. break;
  196062. }
  196063. case MotionNotify:
  196064. {
  196065. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196066. updateKeyModifiers (movedEvent->state);
  196067. const Point<int> mousePos (Desktop::getMousePosition());
  196068. if (lastMousePos != mousePos)
  196069. {
  196070. lastMousePos = mousePos;
  196071. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196072. {
  196073. Window wRoot = 0, wParent = 0;
  196074. {
  196075. ScopedXLock xlock;
  196076. unsigned int numChildren;
  196077. Window* wChild = 0;
  196078. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196079. }
  196080. if (wParent != 0
  196081. && wParent != windowH
  196082. && wParent != wRoot)
  196083. {
  196084. parentWindow = wParent;
  196085. updateBounds();
  196086. }
  196087. else
  196088. {
  196089. parentWindow = 0;
  196090. }
  196091. }
  196092. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196093. }
  196094. break;
  196095. }
  196096. case EnterNotify:
  196097. {
  196098. clearLastMousePos();
  196099. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196100. if (! currentModifiers.isAnyMouseButtonDown())
  196101. {
  196102. updateKeyModifiers (enterEvent->state);
  196103. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196104. }
  196105. break;
  196106. }
  196107. case LeaveNotify:
  196108. {
  196109. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196110. // Suppress the normal leave if we've got a pointer grab, or if
  196111. // it's a bogus one caused by clicking a mouse button when running
  196112. // in a Window manager
  196113. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196114. || leaveEvent->mode == NotifyUngrab)
  196115. {
  196116. updateKeyModifiers (leaveEvent->state);
  196117. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196118. }
  196119. break;
  196120. }
  196121. case FocusIn:
  196122. {
  196123. isActiveApplication = true;
  196124. if (isFocused())
  196125. handleFocusGain();
  196126. break;
  196127. }
  196128. case FocusOut:
  196129. {
  196130. isActiveApplication = false;
  196131. if (! isFocused())
  196132. handleFocusLoss();
  196133. break;
  196134. }
  196135. case Expose:
  196136. {
  196137. // Batch together all pending expose events
  196138. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196139. XEvent nextEvent;
  196140. ScopedXLock xlock;
  196141. if (exposeEvent->window != windowH)
  196142. {
  196143. Window child;
  196144. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196145. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196146. &child);
  196147. }
  196148. repaint (exposeEvent->x, exposeEvent->y,
  196149. exposeEvent->width, exposeEvent->height);
  196150. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196151. {
  196152. XPeekEvent (display, (XEvent*) &nextEvent);
  196153. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196154. break;
  196155. XNextEvent (display, (XEvent*) &nextEvent);
  196156. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196157. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196158. nextExposeEvent->width, nextExposeEvent->height);
  196159. }
  196160. break;
  196161. }
  196162. case CirculateNotify:
  196163. case CreateNotify:
  196164. case DestroyNotify:
  196165. // Think we can ignore these
  196166. break;
  196167. case ConfigureNotify:
  196168. {
  196169. updateBounds();
  196170. updateBorderSize();
  196171. handleMovedOrResized();
  196172. // if the native title bar is dragged, need to tell any active menus, etc.
  196173. if ((styleFlags & windowHasTitleBar) != 0
  196174. && component->isCurrentlyBlockedByAnotherModalComponent())
  196175. {
  196176. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196177. if (currentModalComp != 0)
  196178. currentModalComp->inputAttemptWhenModal();
  196179. }
  196180. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196181. if (confEvent->window == windowH
  196182. && confEvent->above != 0
  196183. && isFrontWindow())
  196184. {
  196185. handleBroughtToFront();
  196186. }
  196187. break;
  196188. }
  196189. case ReparentNotify:
  196190. {
  196191. parentWindow = 0;
  196192. Window wRoot = 0;
  196193. Window* wChild = 0;
  196194. unsigned int numChildren;
  196195. {
  196196. ScopedXLock xlock;
  196197. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196198. }
  196199. if (parentWindow == windowH || parentWindow == wRoot)
  196200. parentWindow = 0;
  196201. updateBounds();
  196202. updateBorderSize();
  196203. handleMovedOrResized();
  196204. break;
  196205. }
  196206. case GravityNotify:
  196207. {
  196208. updateBounds();
  196209. updateBorderSize();
  196210. handleMovedOrResized();
  196211. break;
  196212. }
  196213. case MapNotify:
  196214. mapped = true;
  196215. handleBroughtToFront();
  196216. break;
  196217. case UnmapNotify:
  196218. mapped = false;
  196219. break;
  196220. case MappingNotify:
  196221. {
  196222. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196223. if (mappingEvent->request != MappingPointer)
  196224. {
  196225. // Deal with modifier/keyboard mapping
  196226. ScopedXLock xlock;
  196227. XRefreshKeyboardMapping (mappingEvent);
  196228. updateModifierMappings();
  196229. }
  196230. break;
  196231. }
  196232. case ClientMessage:
  196233. {
  196234. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196235. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196236. {
  196237. const Atom atom = (Atom) clientMsg->data.l[0];
  196238. if (atom == Atoms::ProtocolList [Atoms::PING])
  196239. {
  196240. Window root = RootWindow (display, DefaultScreen (display));
  196241. event->xclient.window = root;
  196242. XSendEvent (display, root, False, NoEventMask, event);
  196243. XFlush (display);
  196244. }
  196245. else if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196246. {
  196247. XWindowAttributes atts;
  196248. ScopedXLock xlock;
  196249. if (clientMsg->window != 0
  196250. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196251. {
  196252. if (atts.map_state == IsViewable)
  196253. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196254. }
  196255. }
  196256. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196257. {
  196258. handleUserClosingWindow();
  196259. }
  196260. }
  196261. else if (clientMsg->message_type == Atoms::XdndEnter)
  196262. {
  196263. handleDragAndDropEnter (clientMsg);
  196264. }
  196265. else if (clientMsg->message_type == Atoms::XdndLeave)
  196266. {
  196267. resetDragAndDrop();
  196268. }
  196269. else if (clientMsg->message_type == Atoms::XdndPosition)
  196270. {
  196271. handleDragAndDropPosition (clientMsg);
  196272. }
  196273. else if (clientMsg->message_type == Atoms::XdndDrop)
  196274. {
  196275. handleDragAndDropDrop (clientMsg);
  196276. }
  196277. else if (clientMsg->message_type == Atoms::XdndStatus)
  196278. {
  196279. handleDragAndDropStatus (clientMsg);
  196280. }
  196281. else if (clientMsg->message_type == Atoms::XdndFinished)
  196282. {
  196283. resetDragAndDrop();
  196284. }
  196285. break;
  196286. }
  196287. case SelectionNotify:
  196288. handleDragAndDropSelection (event);
  196289. break;
  196290. case SelectionClear:
  196291. case SelectionRequest:
  196292. break;
  196293. default:
  196294. #if JUCE_USE_XSHM
  196295. {
  196296. ScopedXLock xlock;
  196297. if (event->xany.type == XShmGetEventBase (display))
  196298. repainter->notifyPaintCompleted();
  196299. }
  196300. #endif
  196301. break;
  196302. }
  196303. }
  196304. void showMouseCursor (Cursor cursor) throw()
  196305. {
  196306. ScopedXLock xlock;
  196307. XDefineCursor (display, windowH, cursor);
  196308. }
  196309. void setTaskBarIcon (const Image& image)
  196310. {
  196311. ScopedXLock xlock;
  196312. taskbarImage = image.createCopy();
  196313. Screen* const screen = XDefaultScreenOfDisplay (display);
  196314. const int screenNumber = XScreenNumberOfScreen (screen);
  196315. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196316. screenAtom << screenNumber;
  196317. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196318. XGrabServer (display);
  196319. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196320. if (managerWin != None)
  196321. XSelectInput (display, managerWin, StructureNotifyMask);
  196322. XUngrabServer (display);
  196323. XFlush (display);
  196324. if (managerWin != None)
  196325. {
  196326. XEvent ev;
  196327. zerostruct (ev);
  196328. ev.xclient.type = ClientMessage;
  196329. ev.xclient.window = managerWin;
  196330. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196331. ev.xclient.format = 32;
  196332. ev.xclient.data.l[0] = CurrentTime;
  196333. ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
  196334. ev.xclient.data.l[2] = windowH;
  196335. ev.xclient.data.l[3] = 0;
  196336. ev.xclient.data.l[4] = 0;
  196337. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196338. XSync (display, False);
  196339. }
  196340. // For older KDE's ...
  196341. long atomData = 1;
  196342. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196343. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196344. // For more recent KDE's...
  196345. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196346. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196347. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196348. XSizeHints* hints = XAllocSizeHints();
  196349. hints->flags = PMinSize;
  196350. hints->min_width = 22;
  196351. hints->min_height = 22;
  196352. XSetWMNormalHints (display, windowH, hints);
  196353. XFree (hints);
  196354. }
  196355. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196356. juce_UseDebuggingNewOperator
  196357. bool dontRepaint;
  196358. static ModifierKeys currentModifiers;
  196359. static bool isActiveApplication;
  196360. private:
  196361. class LinuxRepaintManager : public Timer
  196362. {
  196363. public:
  196364. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196365. : peer (peer_),
  196366. lastTimeImageUsed (0)
  196367. {
  196368. #if JUCE_USE_XSHM
  196369. shmCompletedDrawing = true;
  196370. useARGBImagesForRendering = XSHMHelpers::isShmAvailable();
  196371. if (useARGBImagesForRendering)
  196372. {
  196373. ScopedXLock xlock;
  196374. XShmSegmentInfo segmentinfo;
  196375. XImage* const testImage
  196376. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196377. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196378. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196379. XDestroyImage (testImage);
  196380. }
  196381. #endif
  196382. }
  196383. ~LinuxRepaintManager()
  196384. {
  196385. }
  196386. void timerCallback()
  196387. {
  196388. #if JUCE_USE_XSHM
  196389. if (! shmCompletedDrawing)
  196390. return;
  196391. #endif
  196392. if (! regionsNeedingRepaint.isEmpty())
  196393. {
  196394. stopTimer();
  196395. performAnyPendingRepaintsNow();
  196396. }
  196397. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196398. {
  196399. stopTimer();
  196400. image = 0;
  196401. }
  196402. }
  196403. void repaint (int x, int y, int w, int h)
  196404. {
  196405. if (! isTimerRunning())
  196406. startTimer (repaintTimerPeriod);
  196407. regionsNeedingRepaint.add (x, y, w, h);
  196408. }
  196409. void performAnyPendingRepaintsNow()
  196410. {
  196411. #if JUCE_USE_XSHM
  196412. if (! shmCompletedDrawing)
  196413. {
  196414. startTimer (repaintTimerPeriod);
  196415. return;
  196416. }
  196417. #endif
  196418. peer->clearMaskedRegion();
  196419. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196420. regionsNeedingRepaint.clear();
  196421. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196422. if (! totalArea.isEmpty())
  196423. {
  196424. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196425. || image->getHeight() < totalArea.getHeight())
  196426. {
  196427. #if JUCE_USE_XSHM
  196428. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196429. : Image::RGB,
  196430. #else
  196431. image = new XBitmapImage (Image::RGB,
  196432. #endif
  196433. (totalArea.getWidth() + 31) & ~31,
  196434. (totalArea.getHeight() + 31) & ~31,
  196435. false,
  196436. peer->depth,
  196437. peer->visual);
  196438. }
  196439. startTimer (repaintTimerPeriod);
  196440. LowLevelGraphicsSoftwareRenderer context (*image);
  196441. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196442. if (context.clipToRectangleList (originalRepaintRegion))
  196443. {
  196444. if (peer->depth == 32)
  196445. {
  196446. RectangleList::Iterator i (originalRepaintRegion);
  196447. while (i.next())
  196448. {
  196449. const Rectangle<int>& r = *i.getRectangle();
  196450. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196451. }
  196452. }
  196453. peer->handlePaint (context);
  196454. }
  196455. if (! peer->maskedRegion.isEmpty())
  196456. originalRepaintRegion.subtract (peer->maskedRegion);
  196457. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196458. {
  196459. #if JUCE_USE_XSHM
  196460. shmCompletedDrawing = false;
  196461. #endif
  196462. const Rectangle<int>& r = *i.getRectangle();
  196463. image->blitToWindow (peer->windowH,
  196464. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196465. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196466. }
  196467. }
  196468. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196469. startTimer (repaintTimerPeriod);
  196470. }
  196471. #if JUCE_USE_XSHM
  196472. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196473. #endif
  196474. private:
  196475. enum { repaintTimerPeriod = 1000 / 100 };
  196476. LinuxComponentPeer* const peer;
  196477. ScopedPointer <XBitmapImage> image;
  196478. uint32 lastTimeImageUsed;
  196479. RectangleList regionsNeedingRepaint;
  196480. #if JUCE_USE_XSHM
  196481. bool useARGBImagesForRendering, shmCompletedDrawing;
  196482. #endif
  196483. LinuxRepaintManager (const LinuxRepaintManager&);
  196484. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196485. };
  196486. ScopedPointer <LinuxRepaintManager> repainter;
  196487. friend class LinuxRepaintManager;
  196488. Window windowH, parentWindow;
  196489. int wx, wy, ww, wh;
  196490. ScopedPointer<Image> taskbarImage;
  196491. bool fullScreen, mapped;
  196492. Visual* visual;
  196493. int depth;
  196494. BorderSize windowBorder;
  196495. struct MotifWmHints
  196496. {
  196497. unsigned long flags;
  196498. unsigned long functions;
  196499. unsigned long decorations;
  196500. long input_mode;
  196501. unsigned long status;
  196502. };
  196503. static void updateKeyStates (const int keycode, const bool press) throw()
  196504. {
  196505. const int keybyte = keycode >> 3;
  196506. const int keybit = (1 << (keycode & 7));
  196507. if (press)
  196508. Keys::keyStates [keybyte] |= keybit;
  196509. else
  196510. Keys::keyStates [keybyte] &= ~keybit;
  196511. }
  196512. static void updateKeyModifiers (const int status) throw()
  196513. {
  196514. int keyMods = 0;
  196515. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196516. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196517. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196518. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196519. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196520. Keys::capsLock = ((status & LockMask) != 0);
  196521. }
  196522. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196523. {
  196524. int modifier = 0;
  196525. bool isModifier = true;
  196526. switch (sym)
  196527. {
  196528. case XK_Shift_L:
  196529. case XK_Shift_R:
  196530. modifier = ModifierKeys::shiftModifier;
  196531. break;
  196532. case XK_Control_L:
  196533. case XK_Control_R:
  196534. modifier = ModifierKeys::ctrlModifier;
  196535. break;
  196536. case XK_Alt_L:
  196537. case XK_Alt_R:
  196538. modifier = ModifierKeys::altModifier;
  196539. break;
  196540. case XK_Num_Lock:
  196541. if (press)
  196542. Keys::numLock = ! Keys::numLock;
  196543. break;
  196544. case XK_Caps_Lock:
  196545. if (press)
  196546. Keys::capsLock = ! Keys::capsLock;
  196547. break;
  196548. case XK_Scroll_Lock:
  196549. break;
  196550. default:
  196551. isModifier = false;
  196552. break;
  196553. }
  196554. if (modifier != 0)
  196555. {
  196556. if (press)
  196557. currentModifiers = currentModifiers.withFlags (modifier);
  196558. else
  196559. currentModifiers = currentModifiers.withoutFlags (modifier);
  196560. }
  196561. return isModifier;
  196562. }
  196563. // Alt and Num lock are not defined by standard X
  196564. // modifier constants: check what they're mapped to
  196565. static void updateModifierMappings() throw()
  196566. {
  196567. ScopedXLock xlock;
  196568. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196569. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196570. Keys::AltMask = 0;
  196571. Keys::NumLockMask = 0;
  196572. XModifierKeymap* mapping = XGetModifierMapping (display);
  196573. if (mapping)
  196574. {
  196575. for (int i = 0; i < 8; i++)
  196576. {
  196577. if (mapping->modifiermap [i << 1] == altLeftCode)
  196578. Keys::AltMask = 1 << i;
  196579. else if (mapping->modifiermap [i << 1] == numLockCode)
  196580. Keys::NumLockMask = 1 << i;
  196581. }
  196582. XFreeModifiermap (mapping);
  196583. }
  196584. }
  196585. void removeWindowDecorations (Window wndH)
  196586. {
  196587. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196588. if (hints != None)
  196589. {
  196590. MotifWmHints motifHints;
  196591. zerostruct (motifHints);
  196592. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196593. motifHints.decorations = 0;
  196594. ScopedXLock xlock;
  196595. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196596. (unsigned char*) &motifHints, 4);
  196597. }
  196598. hints = XInternAtom (display, "_WIN_HINTS", True);
  196599. if (hints != None)
  196600. {
  196601. long gnomeHints = 0;
  196602. ScopedXLock xlock;
  196603. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196604. (unsigned char*) &gnomeHints, 1);
  196605. }
  196606. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196607. if (hints != None)
  196608. {
  196609. long kwmHints = 2; /*KDE_tinyDecoration*/
  196610. ScopedXLock xlock;
  196611. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196612. (unsigned char*) &kwmHints, 1);
  196613. }
  196614. }
  196615. void addWindowButtons (Window wndH)
  196616. {
  196617. ScopedXLock xlock;
  196618. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196619. if (hints != None)
  196620. {
  196621. MotifWmHints motifHints;
  196622. zerostruct (motifHints);
  196623. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196624. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196625. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196626. if ((styleFlags & windowHasCloseButton) != 0)
  196627. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196628. if ((styleFlags & windowHasMinimiseButton) != 0)
  196629. {
  196630. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196631. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196632. }
  196633. if ((styleFlags & windowHasMaximiseButton) != 0)
  196634. {
  196635. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196636. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196637. }
  196638. if ((styleFlags & windowIsResizable) != 0)
  196639. {
  196640. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196641. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196642. }
  196643. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196644. }
  196645. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196646. if (hints != None)
  196647. {
  196648. int netHints [6];
  196649. int num = 0;
  196650. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196651. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196652. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196653. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196654. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196655. (unsigned char*) &netHints, num);
  196656. }
  196657. }
  196658. void setWindowType (Window wndH)
  196659. {
  196660. int netHints [2];
  196661. int numHints = 0;
  196662. if ((styleFlags & windowIsTemporary) != 0
  196663. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196664. {
  196665. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196666. }
  196667. else
  196668. {
  196669. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196670. }
  196671. if (netHints [numHints] != 0)
  196672. ++numHints;
  196673. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196674. if (netHints [numHints] != 0)
  196675. ++numHints;
  196676. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196677. (unsigned char*) &netHints, numHints);
  196678. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196679. {
  196680. Atom skipTaskbar = XInternAtom (display, "_NET_WM_STATE_SKIP_TASKBAR", False);
  196681. XChangeProperty (display, wndH, Atoms::WindowState, XA_ATOM, 32, PropModeReplace,
  196682. (unsigned char*) &skipTaskbar, 1);
  196683. }
  196684. }
  196685. void createWindow()
  196686. {
  196687. ScopedXLock xlock;
  196688. Atoms::initialiseAtoms();
  196689. resetDragAndDrop();
  196690. // Get defaults for various properties
  196691. const int screen = DefaultScreen (display);
  196692. Window root = RootWindow (display, screen);
  196693. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196694. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196695. if (visual == 0)
  196696. {
  196697. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196698. Process::terminate();
  196699. }
  196700. // Create and install a colormap suitable fr our visual
  196701. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196702. XInstallColormap (display, colormap);
  196703. // Set up the window attributes
  196704. XSetWindowAttributes swa;
  196705. swa.border_pixel = 0;
  196706. swa.background_pixmap = None;
  196707. swa.colormap = colormap;
  196708. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196709. swa.event_mask = getAllEventsMask();
  196710. Window wndH = XCreateWindow (display, root,
  196711. 0, 0, 1, 1,
  196712. 0, depth, InputOutput, visual,
  196713. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196714. &swa);
  196715. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196716. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196717. GrabModeAsync, GrabModeAsync, None, None);
  196718. // Set the window context to identify the window handle object
  196719. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196720. {
  196721. // Failed
  196722. jassertfalse
  196723. Logger::outputDebugString ("Failed to create context information for window.\n");
  196724. XDestroyWindow (display, wndH);
  196725. wndH = 0;
  196726. }
  196727. // Set window manager hints
  196728. XWMHints* wmHints = XAllocWMHints();
  196729. wmHints->flags = InputHint | StateHint;
  196730. wmHints->input = True; // Locally active input model
  196731. wmHints->initial_state = NormalState;
  196732. XSetWMHints (display, wndH, wmHints);
  196733. XFree (wmHints);
  196734. // Set the window type
  196735. setWindowType (wndH);
  196736. // Define decoration
  196737. if ((styleFlags & windowHasTitleBar) == 0)
  196738. removeWindowDecorations (wndH);
  196739. else
  196740. addWindowButtons (wndH);
  196741. // Set window name
  196742. setWindowTitle (wndH, getComponent()->getName());
  196743. // Associate the PID, allowing to be shut down when something goes wrong
  196744. unsigned long pid = getpid();
  196745. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196746. (unsigned char*) &pid, 1);
  196747. // Set window manager protocols
  196748. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196749. (unsigned char*) Atoms::ProtocolList, 2);
  196750. // Set drag and drop flags
  196751. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196752. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196753. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196754. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196755. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196756. (const unsigned char*) "", 0);
  196757. unsigned long dndVersion = Atoms::DndVersion;
  196758. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196759. (const unsigned char*) &dndVersion, 1);
  196760. // Initialise the pointer and keyboard mapping
  196761. // This is not the same as the logical pointer mapping the X server uses:
  196762. // we don't mess with this.
  196763. static bool mappingInitialised = false;
  196764. if (! mappingInitialised)
  196765. {
  196766. mappingInitialised = true;
  196767. const int numButtons = XGetPointerMapping (display, 0, 0);
  196768. if (numButtons == 2)
  196769. {
  196770. pointerMap[0] = Keys::LeftButton;
  196771. pointerMap[1] = Keys::RightButton;
  196772. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196773. }
  196774. else if (numButtons >= 3)
  196775. {
  196776. pointerMap[0] = Keys::LeftButton;
  196777. pointerMap[1] = Keys::MiddleButton;
  196778. pointerMap[2] = Keys::RightButton;
  196779. if (numButtons >= 5)
  196780. {
  196781. pointerMap[3] = Keys::WheelUp;
  196782. pointerMap[4] = Keys::WheelDown;
  196783. }
  196784. }
  196785. updateModifierMappings();
  196786. }
  196787. windowH = wndH;
  196788. }
  196789. void destroyWindow()
  196790. {
  196791. ScopedXLock xlock;
  196792. XPointer handlePointer;
  196793. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  196794. XDeleteContext (display, (XID) windowH, improbableNumber);
  196795. XDestroyWindow (display, windowH);
  196796. // Wait for it to complete and then remove any events for this
  196797. // window from the event queue.
  196798. XSync (display, false);
  196799. XEvent event;
  196800. while (XCheckWindowEvent (display, windowH, getAllEventsMask(), &event) == True)
  196801. {}
  196802. }
  196803. static int getAllEventsMask() throw()
  196804. {
  196805. return NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  196806. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  196807. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  196808. }
  196809. static int64 getEventTime (::Time t)
  196810. {
  196811. static int64 eventTimeOffset = 0x12345678;
  196812. const int64 thisMessageTime = t;
  196813. if (eventTimeOffset == 0x12345678)
  196814. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  196815. return eventTimeOffset + thisMessageTime;
  196816. }
  196817. static void setWindowTitle (Window xwin, const String& title)
  196818. {
  196819. XTextProperty nameProperty;
  196820. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  196821. ScopedXLock xlock;
  196822. if (XStringListToTextProperty (strings, 1, &nameProperty))
  196823. {
  196824. XSetWMName (display, xwin, &nameProperty);
  196825. XSetWMIconName (display, xwin, &nameProperty);
  196826. XFree (nameProperty.value);
  196827. }
  196828. }
  196829. void updateBorderSize()
  196830. {
  196831. if ((styleFlags & windowHasTitleBar) == 0)
  196832. {
  196833. windowBorder = BorderSize (0);
  196834. }
  196835. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  196836. {
  196837. ScopedXLock xlock;
  196838. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  196839. if (hints != None)
  196840. {
  196841. unsigned char* data = 0;
  196842. unsigned long nitems, bytesLeft;
  196843. Atom actualType;
  196844. int actualFormat;
  196845. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  196846. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  196847. &data) == Success)
  196848. {
  196849. const unsigned long* const sizes = (const unsigned long*) data;
  196850. if (actualFormat == 32)
  196851. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  196852. (int) sizes[3], (int) sizes[1]);
  196853. XFree (data);
  196854. }
  196855. }
  196856. }
  196857. }
  196858. void updateBounds()
  196859. {
  196860. jassert (windowH != 0);
  196861. if (windowH != 0)
  196862. {
  196863. Window root, child;
  196864. unsigned int bw, depth;
  196865. ScopedXLock xlock;
  196866. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196867. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  196868. &bw, &depth))
  196869. {
  196870. wx = wy = ww = wh = 0;
  196871. }
  196872. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  196873. {
  196874. wx = wy = 0;
  196875. }
  196876. }
  196877. }
  196878. void resetDragAndDrop()
  196879. {
  196880. dragAndDropFiles.clear();
  196881. lastDropPos = Point<int> (-1, -1);
  196882. dragAndDropCurrentMimeType = 0;
  196883. dragAndDropSourceWindow = 0;
  196884. srcMimeTypeAtomList.clear();
  196885. }
  196886. void sendDragAndDropMessage (XClientMessageEvent& msg)
  196887. {
  196888. msg.type = ClientMessage;
  196889. msg.display = display;
  196890. msg.window = dragAndDropSourceWindow;
  196891. msg.format = 32;
  196892. msg.data.l[0] = windowH;
  196893. ScopedXLock xlock;
  196894. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  196895. }
  196896. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  196897. {
  196898. XClientMessageEvent msg;
  196899. zerostruct (msg);
  196900. msg.message_type = Atoms::XdndStatus;
  196901. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  196902. msg.data.l[4] = dropAction;
  196903. sendDragAndDropMessage (msg);
  196904. }
  196905. void sendDragAndDropLeave()
  196906. {
  196907. XClientMessageEvent msg;
  196908. zerostruct (msg);
  196909. msg.message_type = Atoms::XdndLeave;
  196910. sendDragAndDropMessage (msg);
  196911. }
  196912. void sendDragAndDropFinish()
  196913. {
  196914. XClientMessageEvent msg;
  196915. zerostruct (msg);
  196916. msg.message_type = Atoms::XdndFinished;
  196917. sendDragAndDropMessage (msg);
  196918. }
  196919. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  196920. {
  196921. if ((clientMsg->data.l[1] & 1) == 0)
  196922. {
  196923. sendDragAndDropLeave();
  196924. if (dragAndDropFiles.size() > 0)
  196925. handleFileDragExit (dragAndDropFiles);
  196926. dragAndDropFiles.clear();
  196927. }
  196928. }
  196929. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  196930. {
  196931. if (dragAndDropSourceWindow == 0)
  196932. return;
  196933. dragAndDropSourceWindow = clientMsg->data.l[0];
  196934. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  196935. (int) clientMsg->data.l[2] & 0xffff);
  196936. dropPos -= getScreenPosition();
  196937. if (lastDropPos != dropPos)
  196938. {
  196939. lastDropPos = dropPos;
  196940. dragAndDropTimestamp = clientMsg->data.l[3];
  196941. Atom targetAction = Atoms::XdndActionCopy;
  196942. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  196943. {
  196944. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  196945. {
  196946. targetAction = Atoms::allowedActions[i];
  196947. break;
  196948. }
  196949. }
  196950. sendDragAndDropStatus (true, targetAction);
  196951. if (dragAndDropFiles.size() == 0)
  196952. updateDraggedFileList (clientMsg);
  196953. if (dragAndDropFiles.size() > 0)
  196954. handleFileDragMove (dragAndDropFiles, dropPos);
  196955. }
  196956. }
  196957. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  196958. {
  196959. if (dragAndDropFiles.size() == 0)
  196960. updateDraggedFileList (clientMsg);
  196961. const StringArray files (dragAndDropFiles);
  196962. const Point<int> lastPos (lastDropPos);
  196963. sendDragAndDropFinish();
  196964. resetDragAndDrop();
  196965. if (files.size() > 0)
  196966. handleFileDragDrop (files, lastPos);
  196967. }
  196968. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  196969. {
  196970. dragAndDropFiles.clear();
  196971. srcMimeTypeAtomList.clear();
  196972. dragAndDropCurrentMimeType = 0;
  196973. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  196974. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  196975. {
  196976. dragAndDropSourceWindow = 0;
  196977. return;
  196978. }
  196979. dragAndDropSourceWindow = clientMsg->data.l[0];
  196980. if ((clientMsg->data.l[1] & 1) != 0)
  196981. {
  196982. Atom actual;
  196983. int format;
  196984. unsigned long count = 0, remaining = 0;
  196985. unsigned char* data = 0;
  196986. ScopedXLock xlock;
  196987. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  196988. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  196989. &count, &remaining, &data);
  196990. if (data != 0)
  196991. {
  196992. if (actual == XA_ATOM && format == 32 && count != 0)
  196993. {
  196994. const unsigned long* const types = (const unsigned long*) data;
  196995. for (unsigned int i = 0; i < count; ++i)
  196996. if (types[i] != None)
  196997. srcMimeTypeAtomList.add (types[i]);
  196998. }
  196999. XFree (data);
  197000. }
  197001. }
  197002. if (srcMimeTypeAtomList.size() == 0)
  197003. {
  197004. for (int i = 2; i < 5; ++i)
  197005. if (clientMsg->data.l[i] != None)
  197006. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197007. if (srcMimeTypeAtomList.size() == 0)
  197008. {
  197009. dragAndDropSourceWindow = 0;
  197010. return;
  197011. }
  197012. }
  197013. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197014. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197015. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197016. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197017. handleDragAndDropPosition (clientMsg);
  197018. }
  197019. void handleDragAndDropSelection (const XEvent* const evt)
  197020. {
  197021. dragAndDropFiles.clear();
  197022. if (evt->xselection.property != 0)
  197023. {
  197024. StringArray lines;
  197025. {
  197026. MemoryBlock dropData;
  197027. for (;;)
  197028. {
  197029. Atom actual;
  197030. uint8* data = 0;
  197031. unsigned long count = 0, remaining = 0;
  197032. int format = 0;
  197033. ScopedXLock xlock;
  197034. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197035. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197036. &format, &count, &remaining, &data) == Success)
  197037. {
  197038. dropData.append (data, count * format / 8);
  197039. XFree (data);
  197040. if (remaining == 0)
  197041. break;
  197042. }
  197043. else
  197044. {
  197045. XFree (data);
  197046. break;
  197047. }
  197048. }
  197049. lines.addLines (dropData.toString());
  197050. }
  197051. for (int i = 0; i < lines.size(); ++i)
  197052. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf ("file://", false, true)));
  197053. dragAndDropFiles.trim();
  197054. dragAndDropFiles.removeEmptyStrings();
  197055. }
  197056. }
  197057. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197058. {
  197059. dragAndDropFiles.clear();
  197060. if (dragAndDropSourceWindow != None
  197061. && dragAndDropCurrentMimeType != 0)
  197062. {
  197063. dragAndDropTimestamp = clientMsg->data.l[2];
  197064. ScopedXLock xlock;
  197065. XConvertSelection (display,
  197066. Atoms::XdndSelection,
  197067. dragAndDropCurrentMimeType,
  197068. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197069. windowH,
  197070. dragAndDropTimestamp);
  197071. }
  197072. }
  197073. StringArray dragAndDropFiles;
  197074. int dragAndDropTimestamp;
  197075. Point<int> lastDropPos;
  197076. Atom dragAndDropCurrentMimeType;
  197077. Window dragAndDropSourceWindow;
  197078. Array <Atom> srcMimeTypeAtomList;
  197079. static int pointerMap[5];
  197080. static Point<int> lastMousePos;
  197081. static void clearLastMousePos() throw()
  197082. {
  197083. lastMousePos = Point<int> (0x100000, 0x100000);
  197084. }
  197085. };
  197086. ModifierKeys LinuxComponentPeer::currentModifiers;
  197087. bool LinuxComponentPeer::isActiveApplication = false;
  197088. int LinuxComponentPeer::pointerMap[5];
  197089. Point<int> LinuxComponentPeer::lastMousePos;
  197090. bool Process::isForegroundProcess()
  197091. {
  197092. return LinuxComponentPeer::isActiveApplication;
  197093. }
  197094. void ModifierKeys::updateCurrentModifiers() throw()
  197095. {
  197096. currentModifiers = LinuxComponentPeer::currentModifiers;
  197097. }
  197098. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197099. {
  197100. Window root, child;
  197101. int x, y, winx, winy;
  197102. unsigned int mask;
  197103. int mouseMods = 0;
  197104. ScopedXLock xlock;
  197105. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197106. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197107. {
  197108. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197109. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197110. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197111. }
  197112. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197113. return LinuxComponentPeer::currentModifiers;
  197114. }
  197115. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197116. {
  197117. if (enableOrDisable)
  197118. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197119. }
  197120. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197121. {
  197122. return new LinuxComponentPeer (this, styleFlags);
  197123. }
  197124. // (this callback is hooked up in the messaging code)
  197125. void juce_windowMessageReceive (XEvent* event)
  197126. {
  197127. if (event->xany.window != None)
  197128. {
  197129. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197130. if (ComponentPeer::isValidPeer (peer))
  197131. peer->handleWindowMessage (event);
  197132. }
  197133. else
  197134. {
  197135. switch (event->xany.type)
  197136. {
  197137. case KeymapNotify:
  197138. {
  197139. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197140. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197141. break;
  197142. }
  197143. default:
  197144. break;
  197145. }
  197146. }
  197147. }
  197148. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197149. {
  197150. if (display == 0)
  197151. return;
  197152. #if JUCE_USE_XINERAMA
  197153. int major_opcode, first_event, first_error;
  197154. ScopedXLock xlock;
  197155. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197156. {
  197157. typedef Bool (*tXineramaIsActive) (Display*);
  197158. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197159. static tXineramaIsActive xXineramaIsActive = 0;
  197160. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197161. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197162. {
  197163. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197164. if (h != 0)
  197165. {
  197166. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197167. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197168. }
  197169. }
  197170. if (xXineramaIsActive != 0
  197171. && xXineramaQueryScreens != 0
  197172. && xXineramaIsActive (display))
  197173. {
  197174. int numMonitors = 0;
  197175. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197176. if (screens != 0)
  197177. {
  197178. for (int i = numMonitors; --i >= 0;)
  197179. {
  197180. int index = screens[i].screen_number;
  197181. if (index >= 0)
  197182. {
  197183. while (monitorCoords.size() < index)
  197184. monitorCoords.add (Rectangle<int>());
  197185. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197186. screens[i].y_org,
  197187. screens[i].width,
  197188. screens[i].height));
  197189. }
  197190. }
  197191. XFree (screens);
  197192. }
  197193. }
  197194. }
  197195. if (monitorCoords.size() == 0)
  197196. #endif
  197197. {
  197198. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197199. if (hints != None)
  197200. {
  197201. const int numMonitors = ScreenCount (display);
  197202. for (int i = 0; i < numMonitors; ++i)
  197203. {
  197204. Window root = RootWindow (display, i);
  197205. unsigned long nitems, bytesLeft;
  197206. Atom actualType;
  197207. int actualFormat;
  197208. unsigned char* data = 0;
  197209. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197210. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197211. &data) == Success)
  197212. {
  197213. const long* const position = (const long*) data;
  197214. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197215. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197216. position[2], position[3]));
  197217. XFree (data);
  197218. }
  197219. }
  197220. }
  197221. if (monitorCoords.size() == 0)
  197222. {
  197223. monitorCoords.add (Rectangle<int> (0, 0,
  197224. DisplayWidth (display, DefaultScreen (display)),
  197225. DisplayHeight (display, DefaultScreen (display))));
  197226. }
  197227. }
  197228. }
  197229. void Desktop::createMouseInputSources()
  197230. {
  197231. mouseSources.add (new MouseInputSource (0, true));
  197232. }
  197233. bool Desktop::canUseSemiTransparentWindows() throw()
  197234. {
  197235. int matchedDepth = 0;
  197236. const int desiredDepth = 32;
  197237. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197238. && (matchedDepth == desiredDepth);
  197239. }
  197240. const Point<int> Desktop::getMousePosition()
  197241. {
  197242. Window root, child;
  197243. int x, y, winx, winy;
  197244. unsigned int mask;
  197245. ScopedXLock xlock;
  197246. if (XQueryPointer (display,
  197247. RootWindow (display, DefaultScreen (display)),
  197248. &root, &child,
  197249. &x, &y, &winx, &winy, &mask) == False)
  197250. {
  197251. // Pointer not on the default screen
  197252. x = y = -1;
  197253. }
  197254. return Point<int> (x, y);
  197255. }
  197256. void Desktop::setMousePosition (const Point<int>& newPosition)
  197257. {
  197258. ScopedXLock xlock;
  197259. Window root = RootWindow (display, DefaultScreen (display));
  197260. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197261. }
  197262. static bool screenSaverAllowed = true;
  197263. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197264. {
  197265. if (screenSaverAllowed != isEnabled)
  197266. {
  197267. screenSaverAllowed = isEnabled;
  197268. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197269. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197270. if (xScreenSaverSuspend == 0)
  197271. {
  197272. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197273. if (h != 0)
  197274. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197275. }
  197276. ScopedXLock xlock;
  197277. if (xScreenSaverSuspend != 0)
  197278. xScreenSaverSuspend (display, ! isEnabled);
  197279. }
  197280. }
  197281. bool Desktop::isScreenSaverEnabled() throw()
  197282. {
  197283. return screenSaverAllowed;
  197284. }
  197285. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197286. {
  197287. ScopedXLock xlock;
  197288. const unsigned int imageW = image.getWidth();
  197289. const unsigned int imageH = image.getHeight();
  197290. #if JUCE_USE_XCURSOR
  197291. {
  197292. typedef XcursorBool (*tXcursorSupportsARGB) (Display*);
  197293. typedef XcursorImage* (*tXcursorImageCreate) (int, int);
  197294. typedef void (*tXcursorImageDestroy) (XcursorImage*);
  197295. typedef Cursor (*tXcursorImageLoadCursor) (Display*, const XcursorImage*);
  197296. static tXcursorSupportsARGB xXcursorSupportsARGB = 0;
  197297. static tXcursorImageCreate xXcursorImageCreate = 0;
  197298. static tXcursorImageDestroy xXcursorImageDestroy = 0;
  197299. static tXcursorImageLoadCursor xXcursorImageLoadCursor = 0;
  197300. static bool hasBeenLoaded = false;
  197301. if (! hasBeenLoaded)
  197302. {
  197303. hasBeenLoaded = true;
  197304. void* h = dlopen ("libXcursor.so", RTLD_GLOBAL | RTLD_NOW);
  197305. if (h != 0)
  197306. {
  197307. xXcursorSupportsARGB = (tXcursorSupportsARGB) dlsym (h, "XcursorSupportsARGB");
  197308. xXcursorImageCreate = (tXcursorImageCreate) dlsym (h, "XcursorImageCreate");
  197309. xXcursorImageLoadCursor = (tXcursorImageLoadCursor) dlsym (h, "XcursorImageLoadCursor");
  197310. xXcursorImageDestroy = (tXcursorImageDestroy) dlsym (h, "XcursorImageDestroy");
  197311. if (xXcursorSupportsARGB == 0 || xXcursorImageCreate == 0
  197312. || xXcursorImageLoadCursor == 0 || xXcursorImageDestroy == 0
  197313. || ! xXcursorSupportsARGB (display))
  197314. xXcursorSupportsARGB = 0;
  197315. }
  197316. }
  197317. if (xXcursorSupportsARGB != 0)
  197318. {
  197319. XcursorImage* xcImage = xXcursorImageCreate (imageW, imageH);
  197320. if (xcImage != 0)
  197321. {
  197322. xcImage->xhot = hotspotX;
  197323. xcImage->yhot = hotspotY;
  197324. XcursorPixel* dest = xcImage->pixels;
  197325. for (int y = 0; y < (int) imageH; ++y)
  197326. for (int x = 0; x < (int) imageW; ++x)
  197327. *dest++ = image.getPixelAt (x, y).getARGB();
  197328. void* result = (void*) xXcursorImageLoadCursor (display, xcImage);
  197329. xXcursorImageDestroy (xcImage);
  197330. if (result != 0)
  197331. return result;
  197332. }
  197333. }
  197334. }
  197335. #endif
  197336. Window root = RootWindow (display, DefaultScreen (display));
  197337. unsigned int cursorW, cursorH;
  197338. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197339. return 0;
  197340. Image im (Image::ARGB, cursorW, cursorH, true);
  197341. {
  197342. Graphics g (im);
  197343. if (imageW > cursorW || imageH > cursorH)
  197344. {
  197345. hotspotX = (hotspotX * cursorW) / imageW;
  197346. hotspotY = (hotspotY * cursorH) / imageH;
  197347. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197348. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197349. false);
  197350. }
  197351. else
  197352. {
  197353. g.drawImageAt (&image, 0, 0);
  197354. }
  197355. }
  197356. const int stride = (cursorW + 7) >> 3;
  197357. HeapBlock <char> maskPlane, sourcePlane;
  197358. maskPlane.calloc (stride * cursorH);
  197359. sourcePlane.calloc (stride * cursorH);
  197360. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197361. for (int y = cursorH; --y >= 0;)
  197362. {
  197363. for (int x = cursorW; --x >= 0;)
  197364. {
  197365. const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197366. const int offset = y * stride + (x >> 3);
  197367. const Colour c (im.getPixelAt (x, y));
  197368. if (c.getAlpha() >= 128)
  197369. maskPlane[offset] |= mask;
  197370. if (c.getBrightness() >= 0.5f)
  197371. sourcePlane[offset] |= mask;
  197372. }
  197373. }
  197374. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, sourcePlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197375. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, maskPlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197376. XColor white, black;
  197377. black.red = black.green = black.blue = 0;
  197378. white.red = white.green = white.blue = 0xffff;
  197379. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197380. XFreePixmap (display, sourcePixmap);
  197381. XFreePixmap (display, maskPixmap);
  197382. return result;
  197383. }
  197384. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197385. {
  197386. ScopedXLock xlock;
  197387. if (cursorHandle != None)
  197388. XFreeCursor (display, (Cursor) cursorHandle);
  197389. }
  197390. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197391. {
  197392. unsigned int shape;
  197393. switch (type)
  197394. {
  197395. case MouseCursor::NoCursor:
  197396. {
  197397. const Image im (Image::ARGB, 16, 16, true);
  197398. return juce_createMouseCursorFromImage (im, 0, 0);
  197399. }
  197400. case MouseCursor::NormalCursor:
  197401. return (void*) None; // Use parent cursor
  197402. case MouseCursor::DraggingHandCursor:
  197403. {
  197404. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197405. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197406. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197407. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197408. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197409. const int dragHandDataSize = 99;
  197410. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (dragHandData, dragHandDataSize));
  197411. return juce_createMouseCursorFromImage (*im, 8, 7);
  197412. }
  197413. case MouseCursor::CopyingCursor:
  197414. {
  197415. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197416. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197417. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197418. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197419. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197420. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197421. const int copyCursorSize = 119;
  197422. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (copyCursorData, copyCursorSize));
  197423. return juce_createMouseCursorFromImage (*im, 1, 3);
  197424. }
  197425. case MouseCursor::WaitCursor:
  197426. shape = XC_watch;
  197427. break;
  197428. case MouseCursor::IBeamCursor:
  197429. shape = XC_xterm;
  197430. break;
  197431. case MouseCursor::PointingHandCursor:
  197432. shape = XC_hand2;
  197433. break;
  197434. case MouseCursor::LeftRightResizeCursor:
  197435. shape = XC_sb_h_double_arrow;
  197436. break;
  197437. case MouseCursor::UpDownResizeCursor:
  197438. shape = XC_sb_v_double_arrow;
  197439. break;
  197440. case MouseCursor::UpDownLeftRightResizeCursor:
  197441. shape = XC_fleur;
  197442. break;
  197443. case MouseCursor::TopEdgeResizeCursor:
  197444. shape = XC_top_side;
  197445. break;
  197446. case MouseCursor::BottomEdgeResizeCursor:
  197447. shape = XC_bottom_side;
  197448. break;
  197449. case MouseCursor::LeftEdgeResizeCursor:
  197450. shape = XC_left_side;
  197451. break;
  197452. case MouseCursor::RightEdgeResizeCursor:
  197453. shape = XC_right_side;
  197454. break;
  197455. case MouseCursor::TopLeftCornerResizeCursor:
  197456. shape = XC_top_left_corner;
  197457. break;
  197458. case MouseCursor::TopRightCornerResizeCursor:
  197459. shape = XC_top_right_corner;
  197460. break;
  197461. case MouseCursor::BottomLeftCornerResizeCursor:
  197462. shape = XC_bottom_left_corner;
  197463. break;
  197464. case MouseCursor::BottomRightCornerResizeCursor:
  197465. shape = XC_bottom_right_corner;
  197466. break;
  197467. case MouseCursor::CrosshairCursor:
  197468. shape = XC_crosshair;
  197469. break;
  197470. default:
  197471. return (void*) None; // Use parent cursor
  197472. }
  197473. ScopedXLock xlock;
  197474. return (void*) XCreateFontCursor (display, shape);
  197475. }
  197476. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197477. {
  197478. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197479. if (lp != 0)
  197480. lp->showMouseCursor ((Cursor) getHandle());
  197481. }
  197482. void MouseCursor::showInAllWindows() const throw()
  197483. {
  197484. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197485. showInWindow (ComponentPeer::getPeer (i));
  197486. }
  197487. Image* juce_createIconForFile (const File& file)
  197488. {
  197489. return 0;
  197490. }
  197491. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197492. {
  197493. return new Image (format, imageWidth, imageHeight, clearImage);
  197494. }
  197495. #if JUCE_OPENGL
  197496. class WindowedGLContext : public OpenGLContext
  197497. {
  197498. public:
  197499. WindowedGLContext (Component* const component,
  197500. const OpenGLPixelFormat& pixelFormat_,
  197501. GLXContext sharedContext)
  197502. : renderContext (0),
  197503. embeddedWindow (0),
  197504. pixelFormat (pixelFormat_)
  197505. {
  197506. jassert (component != 0);
  197507. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197508. if (peer == 0)
  197509. return;
  197510. ScopedXLock xlock;
  197511. XSync (display, False);
  197512. GLint attribs [64];
  197513. int n = 0;
  197514. attribs[n++] = GLX_RGBA;
  197515. attribs[n++] = GLX_DOUBLEBUFFER;
  197516. attribs[n++] = GLX_RED_SIZE;
  197517. attribs[n++] = pixelFormat.redBits;
  197518. attribs[n++] = GLX_GREEN_SIZE;
  197519. attribs[n++] = pixelFormat.greenBits;
  197520. attribs[n++] = GLX_BLUE_SIZE;
  197521. attribs[n++] = pixelFormat.blueBits;
  197522. attribs[n++] = GLX_ALPHA_SIZE;
  197523. attribs[n++] = pixelFormat.alphaBits;
  197524. attribs[n++] = GLX_DEPTH_SIZE;
  197525. attribs[n++] = pixelFormat.depthBufferBits;
  197526. attribs[n++] = GLX_STENCIL_SIZE;
  197527. attribs[n++] = pixelFormat.stencilBufferBits;
  197528. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197529. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197530. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197531. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197532. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197533. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197534. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197535. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197536. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197537. attribs[n++] = None;
  197538. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197539. if (bestVisual == 0)
  197540. return;
  197541. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197542. Window windowH = (Window) peer->getNativeHandle();
  197543. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197544. XSetWindowAttributes swa;
  197545. swa.colormap = colourMap;
  197546. swa.border_pixel = 0;
  197547. swa.event_mask = ExposureMask | StructureNotifyMask;
  197548. embeddedWindow = XCreateWindow (display, windowH,
  197549. 0, 0, 1, 1, 0,
  197550. bestVisual->depth,
  197551. InputOutput,
  197552. bestVisual->visual,
  197553. CWBorderPixel | CWColormap | CWEventMask,
  197554. &swa);
  197555. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197556. XMapWindow (display, embeddedWindow);
  197557. XFreeColormap (display, colourMap);
  197558. XFree (bestVisual);
  197559. XSync (display, False);
  197560. }
  197561. ~WindowedGLContext()
  197562. {
  197563. makeInactive();
  197564. ScopedXLock xlock;
  197565. glXDestroyContext (display, renderContext);
  197566. XUnmapWindow (display, embeddedWindow);
  197567. XDestroyWindow (display, embeddedWindow);
  197568. }
  197569. bool makeActive() const throw()
  197570. {
  197571. jassert (renderContext != 0);
  197572. ScopedXLock xlock;
  197573. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197574. && XSync (display, False);
  197575. }
  197576. bool makeInactive() const throw()
  197577. {
  197578. ScopedXLock xlock;
  197579. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197580. }
  197581. bool isActive() const throw()
  197582. {
  197583. ScopedXLock xlock;
  197584. return glXGetCurrentContext() == renderContext;
  197585. }
  197586. const OpenGLPixelFormat getPixelFormat() const
  197587. {
  197588. return pixelFormat;
  197589. }
  197590. void* getRawContext() const throw()
  197591. {
  197592. return renderContext;
  197593. }
  197594. void updateWindowPosition (int x, int y, int w, int h, int)
  197595. {
  197596. ScopedXLock xlock;
  197597. XMoveResizeWindow (display, embeddedWindow,
  197598. x, y, jmax (1, w), jmax (1, h));
  197599. }
  197600. void swapBuffers()
  197601. {
  197602. ScopedXLock xlock;
  197603. glXSwapBuffers (display, embeddedWindow);
  197604. }
  197605. bool setSwapInterval (const int numFramesPerSwap)
  197606. {
  197607. // xxx needs doing..
  197608. return false;
  197609. }
  197610. int getSwapInterval() const
  197611. {
  197612. // xxx needs doing..
  197613. return 0;
  197614. }
  197615. void repaint()
  197616. {
  197617. }
  197618. juce_UseDebuggingNewOperator
  197619. GLXContext renderContext;
  197620. private:
  197621. Window embeddedWindow;
  197622. OpenGLPixelFormat pixelFormat;
  197623. WindowedGLContext (const WindowedGLContext&);
  197624. WindowedGLContext& operator= (const WindowedGLContext&);
  197625. };
  197626. OpenGLContext* OpenGLComponent::createContext()
  197627. {
  197628. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197629. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197630. return (c->renderContext != 0) ? c.release() : 0;
  197631. }
  197632. void juce_glViewport (const int w, const int h)
  197633. {
  197634. glViewport (0, 0, w, h);
  197635. }
  197636. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197637. OwnedArray <OpenGLPixelFormat>& results)
  197638. {
  197639. results.add (new OpenGLPixelFormat()); // xxx
  197640. }
  197641. #endif
  197642. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197643. {
  197644. jassertfalse // not implemented!
  197645. return false;
  197646. }
  197647. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197648. {
  197649. jassertfalse // not implemented!
  197650. return false;
  197651. }
  197652. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197653. {
  197654. if (! isOnDesktop ())
  197655. addToDesktop (0);
  197656. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197657. if (wp != 0)
  197658. {
  197659. wp->setTaskBarIcon (newImage);
  197660. setVisible (true);
  197661. toFront (false);
  197662. repaint();
  197663. }
  197664. }
  197665. void SystemTrayIconComponent::paint (Graphics& g)
  197666. {
  197667. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197668. if (wp != 0)
  197669. {
  197670. const Image* const image = wp->getTaskbarIcon();
  197671. if (image != 0)
  197672. {
  197673. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197674. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197675. false);
  197676. }
  197677. }
  197678. }
  197679. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197680. {
  197681. // xxx not yet implemented!
  197682. }
  197683. void PlatformUtilities::beep()
  197684. {
  197685. std::cout << "\a" << std::flush;
  197686. }
  197687. bool AlertWindow::showNativeDialogBox (const String& title,
  197688. const String& bodyText,
  197689. bool isOkCancel)
  197690. {
  197691. // use a non-native one for the time being..
  197692. if (isOkCancel)
  197693. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197694. else
  197695. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197696. return true;
  197697. }
  197698. const int KeyPress::spaceKey = XK_space & 0xff;
  197699. const int KeyPress::returnKey = XK_Return & 0xff;
  197700. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197701. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197702. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197703. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197704. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197705. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197706. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197707. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197708. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197709. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197710. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197711. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197712. const int KeyPress::tabKey = XK_Tab & 0xff;
  197713. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197714. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197715. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197716. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197717. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197718. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197719. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197720. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197721. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197722. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197723. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197724. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197725. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197726. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197727. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197728. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197729. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197730. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197731. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197732. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197733. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197734. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197735. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197736. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197737. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197738. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197739. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197740. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197741. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197742. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197743. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197744. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197745. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197746. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197747. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197748. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197749. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197750. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197751. #endif
  197752. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197753. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197754. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197755. // compiled on its own).
  197756. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197757. static const int maxNumChans = 64;
  197758. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197759. {
  197760. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197761. snd_pcm_hw_params_t* hwParams;
  197762. snd_pcm_hw_params_alloca (&hwParams);
  197763. for (int i = 0; ratesToTry[i] != 0; ++i)
  197764. {
  197765. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197766. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197767. {
  197768. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197769. }
  197770. }
  197771. }
  197772. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197773. {
  197774. snd_pcm_hw_params_t *params;
  197775. snd_pcm_hw_params_alloca (&params);
  197776. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197777. {
  197778. snd_pcm_hw_params_get_channels_min (params, minChans);
  197779. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197780. }
  197781. }
  197782. static void getDeviceProperties (const String& deviceID,
  197783. unsigned int& minChansOut,
  197784. unsigned int& maxChansOut,
  197785. unsigned int& minChansIn,
  197786. unsigned int& maxChansIn,
  197787. Array <int>& rates)
  197788. {
  197789. if (deviceID.isEmpty())
  197790. return;
  197791. snd_ctl_t* handle;
  197792. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (",", false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197793. {
  197794. snd_pcm_info_t* info;
  197795. snd_pcm_info_alloca (&info);
  197796. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197797. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (",", false, false).getIntValue());
  197798. snd_pcm_info_set_subdevice (info, 0);
  197799. if (snd_ctl_pcm_info (handle, info) >= 0)
  197800. {
  197801. snd_pcm_t* pcmHandle;
  197802. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197803. {
  197804. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197805. getDeviceSampleRates (pcmHandle, rates);
  197806. snd_pcm_close (pcmHandle);
  197807. }
  197808. }
  197809. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197810. if (snd_ctl_pcm_info (handle, info) >= 0)
  197811. {
  197812. snd_pcm_t* pcmHandle;
  197813. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197814. {
  197815. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197816. if (rates.size() == 0)
  197817. getDeviceSampleRates (pcmHandle, rates);
  197818. snd_pcm_close (pcmHandle);
  197819. }
  197820. }
  197821. snd_ctl_close (handle);
  197822. }
  197823. }
  197824. class ALSADevice
  197825. {
  197826. public:
  197827. ALSADevice (const String& deviceID,
  197828. const bool forInput)
  197829. : handle (0),
  197830. bitDepth (16),
  197831. numChannelsRunning (0),
  197832. isInput (forInput),
  197833. sampleFormat (AudioDataConverters::int16LE)
  197834. {
  197835. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  197836. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  197837. SND_PCM_ASYNC));
  197838. }
  197839. ~ALSADevice()
  197840. {
  197841. if (handle != 0)
  197842. snd_pcm_close (handle);
  197843. }
  197844. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  197845. {
  197846. if (handle == 0)
  197847. return false;
  197848. snd_pcm_hw_params_t* hwParams;
  197849. snd_pcm_hw_params_alloca (&hwParams);
  197850. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  197851. return false;
  197852. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  197853. isInterleaved = false;
  197854. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  197855. isInterleaved = true;
  197856. else
  197857. {
  197858. jassertfalse
  197859. return false;
  197860. }
  197861. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  197862. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  197863. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  197864. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  197865. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  197866. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  197867. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  197868. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  197869. bitDepth = 0;
  197870. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  197871. {
  197872. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  197873. {
  197874. bitDepth = formatsToTry [i + 1];
  197875. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  197876. break;
  197877. }
  197878. }
  197879. if (bitDepth == 0)
  197880. {
  197881. error = "device doesn't support a compatible PCM format";
  197882. DBG ("ALSA error: " + error + "\n");
  197883. return false;
  197884. }
  197885. int dir = 0;
  197886. unsigned int periods = 4;
  197887. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  197888. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  197889. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  197890. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  197891. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  197892. || failed (snd_pcm_hw_params (handle, hwParams)))
  197893. {
  197894. return false;
  197895. }
  197896. snd_pcm_sw_params_t* swParams;
  197897. snd_pcm_sw_params_alloca (&swParams);
  197898. snd_pcm_uframes_t boundary;
  197899. if (failed (snd_pcm_sw_params_current (handle, swParams))
  197900. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  197901. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  197902. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  197903. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  197904. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  197905. || failed (snd_pcm_sw_params (handle, swParams)))
  197906. {
  197907. return false;
  197908. }
  197909. numChannelsRunning = numChannels;
  197910. return true;
  197911. }
  197912. bool write (float** const data, const int numSamples)
  197913. {
  197914. if (isInterleaved)
  197915. {
  197916. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197917. float* interleaved = static_cast <float*> (scratch.getData());
  197918. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  197919. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197920. snd_pcm_sframes_t num = snd_pcm_writei (handle, interleaved, numSamples);
  197921. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197922. return false;
  197923. }
  197924. else
  197925. {
  197926. for (int i = 0; i < numChannelsRunning; ++i)
  197927. if (data[i] != 0)
  197928. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  197929. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  197930. if (failed (num))
  197931. {
  197932. if (num == -EPIPE)
  197933. {
  197934. if (failed (snd_pcm_prepare (handle)))
  197935. return false;
  197936. }
  197937. else if (num != -ESTRPIPE)
  197938. return false;
  197939. }
  197940. }
  197941. return true;
  197942. }
  197943. bool read (float** const data, const int numSamples)
  197944. {
  197945. if (isInterleaved)
  197946. {
  197947. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197948. float* interleaved = static_cast <float*> (scratch.getData());
  197949. snd_pcm_sframes_t num = snd_pcm_readi (handle, interleaved, numSamples);
  197950. if (failed (num))
  197951. {
  197952. if (num == -EPIPE)
  197953. {
  197954. if (failed (snd_pcm_prepare (handle)))
  197955. return false;
  197956. }
  197957. else if (num != -ESTRPIPE)
  197958. return false;
  197959. }
  197960. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197961. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  197962. }
  197963. else
  197964. {
  197965. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  197966. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197967. return false;
  197968. for (int i = 0; i < numChannelsRunning; ++i)
  197969. if (data[i] != 0)
  197970. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  197971. }
  197972. return true;
  197973. }
  197974. juce_UseDebuggingNewOperator
  197975. snd_pcm_t* handle;
  197976. String error;
  197977. int bitDepth, numChannelsRunning;
  197978. private:
  197979. const bool isInput;
  197980. bool isInterleaved;
  197981. MemoryBlock scratch;
  197982. AudioDataConverters::DataFormat sampleFormat;
  197983. bool failed (const int errorNum)
  197984. {
  197985. if (errorNum >= 0)
  197986. return false;
  197987. error = snd_strerror (errorNum);
  197988. DBG ("ALSA error: " + error + "\n");
  197989. return true;
  197990. }
  197991. };
  197992. class ALSAThread : public Thread
  197993. {
  197994. public:
  197995. ALSAThread (const String& inputId_,
  197996. const String& outputId_)
  197997. : Thread ("Juce ALSA"),
  197998. sampleRate (0),
  197999. bufferSize (0),
  198000. callback (0),
  198001. inputId (inputId_),
  198002. outputId (outputId_),
  198003. outputDevice (0),
  198004. inputDevice (0),
  198005. numCallbacks (0),
  198006. totalNumInputChannels (0),
  198007. totalNumOutputChannels (0)
  198008. {
  198009. zeromem (outputChannelData, sizeof (outputChannelData));
  198010. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198011. zeromem (inputChannelData, sizeof (inputChannelData));
  198012. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198013. initialiseRatesAndChannels();
  198014. }
  198015. ~ALSAThread()
  198016. {
  198017. close();
  198018. }
  198019. void open (BigInteger inputChannels,
  198020. BigInteger outputChannels,
  198021. const double sampleRate_,
  198022. const int bufferSize_)
  198023. {
  198024. close();
  198025. error = String::empty;
  198026. sampleRate = sampleRate_;
  198027. bufferSize = bufferSize_;
  198028. currentInputChans.clear();
  198029. currentOutputChans.clear();
  198030. if (inputChannels.getHighestBit() >= 0)
  198031. {
  198032. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198033. {
  198034. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198035. if (inputChannels[i])
  198036. {
  198037. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198038. currentInputChans.setBit (i);
  198039. }
  198040. }
  198041. }
  198042. if (outputChannels.getHighestBit() >= 0)
  198043. {
  198044. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198045. {
  198046. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198047. if (outputChannels[i])
  198048. {
  198049. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198050. currentOutputChans.setBit (i);
  198051. }
  198052. }
  198053. }
  198054. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198055. {
  198056. outputDevice = new ALSADevice (outputId, false);
  198057. if (outputDevice->error.isNotEmpty())
  198058. {
  198059. error = outputDevice->error;
  198060. deleteAndZero (outputDevice);
  198061. return;
  198062. }
  198063. currentOutputChans.setRange (0, minChansOut, true);
  198064. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198065. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198066. bufferSize))
  198067. {
  198068. error = outputDevice->error;
  198069. deleteAndZero (outputDevice);
  198070. return;
  198071. }
  198072. }
  198073. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198074. {
  198075. inputDevice = new ALSADevice (inputId, true);
  198076. if (inputDevice->error.isNotEmpty())
  198077. {
  198078. error = inputDevice->error;
  198079. deleteAndZero (inputDevice);
  198080. return;
  198081. }
  198082. currentInputChans.setRange (0, minChansIn, true);
  198083. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198084. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198085. bufferSize))
  198086. {
  198087. error = inputDevice->error;
  198088. deleteAndZero (inputDevice);
  198089. return;
  198090. }
  198091. }
  198092. if (outputDevice == 0 && inputDevice == 0)
  198093. {
  198094. error = "no channels";
  198095. return;
  198096. }
  198097. if (outputDevice != 0 && inputDevice != 0)
  198098. {
  198099. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198100. }
  198101. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198102. return;
  198103. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198104. return;
  198105. startThread (9);
  198106. int count = 1000;
  198107. while (numCallbacks == 0)
  198108. {
  198109. sleep (5);
  198110. if (--count < 0 || ! isThreadRunning())
  198111. {
  198112. error = "device didn't start";
  198113. break;
  198114. }
  198115. }
  198116. }
  198117. void close()
  198118. {
  198119. stopThread (6000);
  198120. deleteAndZero (inputDevice);
  198121. deleteAndZero (outputDevice);
  198122. for (int i = 0; i < maxNumChans; ++i)
  198123. {
  198124. juce_free (inputChannelData [i]);
  198125. juce_free (outputChannelData [i]);
  198126. }
  198127. zeromem (outputChannelData, sizeof (outputChannelData));
  198128. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198129. zeromem (inputChannelData, sizeof (inputChannelData));
  198130. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198131. totalNumOutputChannels = 0;
  198132. totalNumInputChannels = 0;
  198133. numCallbacks = 0;
  198134. }
  198135. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198136. {
  198137. const ScopedLock sl (callbackLock);
  198138. callback = newCallback;
  198139. }
  198140. void run()
  198141. {
  198142. while (! threadShouldExit())
  198143. {
  198144. if (inputDevice != 0)
  198145. {
  198146. if (! inputDevice->read (inputChannelData, bufferSize))
  198147. {
  198148. DBG ("ALSA: read failure");
  198149. break;
  198150. }
  198151. }
  198152. if (threadShouldExit())
  198153. break;
  198154. {
  198155. const ScopedLock sl (callbackLock);
  198156. ++numCallbacks;
  198157. if (callback != 0)
  198158. {
  198159. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198160. totalNumInputChannels,
  198161. outputChannelDataForCallback,
  198162. totalNumOutputChannels,
  198163. bufferSize);
  198164. }
  198165. else
  198166. {
  198167. for (int i = 0; i < totalNumOutputChannels; ++i)
  198168. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198169. }
  198170. }
  198171. if (outputDevice != 0)
  198172. {
  198173. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198174. if (threadShouldExit())
  198175. break;
  198176. failed (snd_pcm_avail_update (outputDevice->handle));
  198177. if (! outputDevice->write (outputChannelData, bufferSize))
  198178. {
  198179. DBG ("ALSA: write failure");
  198180. break;
  198181. }
  198182. }
  198183. }
  198184. }
  198185. int getBitDepth() const throw()
  198186. {
  198187. if (outputDevice != 0)
  198188. return outputDevice->bitDepth;
  198189. if (inputDevice != 0)
  198190. return inputDevice->bitDepth;
  198191. return 16;
  198192. }
  198193. juce_UseDebuggingNewOperator
  198194. String error;
  198195. double sampleRate;
  198196. int bufferSize;
  198197. BigInteger currentInputChans, currentOutputChans;
  198198. Array <int> sampleRates;
  198199. StringArray channelNamesOut, channelNamesIn;
  198200. AudioIODeviceCallback* callback;
  198201. private:
  198202. const String inputId, outputId;
  198203. ALSADevice* outputDevice;
  198204. ALSADevice* inputDevice;
  198205. int numCallbacks;
  198206. CriticalSection callbackLock;
  198207. float* outputChannelData [maxNumChans];
  198208. float* outputChannelDataForCallback [maxNumChans];
  198209. int totalNumInputChannels;
  198210. float* inputChannelData [maxNumChans];
  198211. float* inputChannelDataForCallback [maxNumChans];
  198212. int totalNumOutputChannels;
  198213. unsigned int minChansOut, maxChansOut;
  198214. unsigned int minChansIn, maxChansIn;
  198215. bool failed (const int errorNum) throw()
  198216. {
  198217. if (errorNum >= 0)
  198218. return false;
  198219. error = snd_strerror (errorNum);
  198220. DBG ("ALSA error: " + error + "\n");
  198221. return true;
  198222. }
  198223. void initialiseRatesAndChannels() throw()
  198224. {
  198225. sampleRates.clear();
  198226. channelNamesOut.clear();
  198227. channelNamesIn.clear();
  198228. minChansOut = 0;
  198229. maxChansOut = 0;
  198230. minChansIn = 0;
  198231. maxChansIn = 0;
  198232. unsigned int dummy = 0;
  198233. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198234. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198235. unsigned int i;
  198236. for (i = 0; i < maxChansOut; ++i)
  198237. channelNamesOut.add ("channel " + String ((int) i + 1));
  198238. for (i = 0; i < maxChansIn; ++i)
  198239. channelNamesIn.add ("channel " + String ((int) i + 1));
  198240. }
  198241. };
  198242. class ALSAAudioIODevice : public AudioIODevice
  198243. {
  198244. public:
  198245. ALSAAudioIODevice (const String& deviceName,
  198246. const String& inputId_,
  198247. const String& outputId_)
  198248. : AudioIODevice (deviceName, "ALSA"),
  198249. inputId (inputId_),
  198250. outputId (outputId_),
  198251. isOpen_ (false),
  198252. isStarted (false),
  198253. internal (0)
  198254. {
  198255. internal = new ALSAThread (inputId, outputId);
  198256. }
  198257. ~ALSAAudioIODevice()
  198258. {
  198259. delete internal;
  198260. }
  198261. const StringArray getOutputChannelNames()
  198262. {
  198263. return internal->channelNamesOut;
  198264. }
  198265. const StringArray getInputChannelNames()
  198266. {
  198267. return internal->channelNamesIn;
  198268. }
  198269. int getNumSampleRates()
  198270. {
  198271. return internal->sampleRates.size();
  198272. }
  198273. double getSampleRate (int index)
  198274. {
  198275. return internal->sampleRates [index];
  198276. }
  198277. int getNumBufferSizesAvailable()
  198278. {
  198279. return 50;
  198280. }
  198281. int getBufferSizeSamples (int index)
  198282. {
  198283. int n = 16;
  198284. for (int i = 0; i < index; ++i)
  198285. n += n < 64 ? 16
  198286. : (n < 512 ? 32
  198287. : (n < 1024 ? 64
  198288. : (n < 2048 ? 128 : 256)));
  198289. return n;
  198290. }
  198291. int getDefaultBufferSize()
  198292. {
  198293. return 512;
  198294. }
  198295. const String open (const BigInteger& inputChannels,
  198296. const BigInteger& outputChannels,
  198297. double sampleRate,
  198298. int bufferSizeSamples)
  198299. {
  198300. close();
  198301. if (bufferSizeSamples <= 0)
  198302. bufferSizeSamples = getDefaultBufferSize();
  198303. if (sampleRate <= 0)
  198304. {
  198305. for (int i = 0; i < getNumSampleRates(); ++i)
  198306. {
  198307. if (getSampleRate (i) >= 44100)
  198308. {
  198309. sampleRate = getSampleRate (i);
  198310. break;
  198311. }
  198312. }
  198313. }
  198314. internal->open (inputChannels, outputChannels,
  198315. sampleRate, bufferSizeSamples);
  198316. isOpen_ = internal->error.isEmpty();
  198317. return internal->error;
  198318. }
  198319. void close()
  198320. {
  198321. stop();
  198322. internal->close();
  198323. isOpen_ = false;
  198324. }
  198325. bool isOpen()
  198326. {
  198327. return isOpen_;
  198328. }
  198329. int getCurrentBufferSizeSamples()
  198330. {
  198331. return internal->bufferSize;
  198332. }
  198333. double getCurrentSampleRate()
  198334. {
  198335. return internal->sampleRate;
  198336. }
  198337. int getCurrentBitDepth()
  198338. {
  198339. return internal->getBitDepth();
  198340. }
  198341. const BigInteger getActiveOutputChannels() const
  198342. {
  198343. return internal->currentOutputChans;
  198344. }
  198345. const BigInteger getActiveInputChannels() const
  198346. {
  198347. return internal->currentInputChans;
  198348. }
  198349. int getOutputLatencyInSamples()
  198350. {
  198351. return 0;
  198352. }
  198353. int getInputLatencyInSamples()
  198354. {
  198355. return 0;
  198356. }
  198357. void start (AudioIODeviceCallback* callback)
  198358. {
  198359. if (! isOpen_)
  198360. callback = 0;
  198361. internal->setCallback (callback);
  198362. if (callback != 0)
  198363. callback->audioDeviceAboutToStart (this);
  198364. isStarted = (callback != 0);
  198365. }
  198366. void stop()
  198367. {
  198368. AudioIODeviceCallback* const oldCallback = internal->callback;
  198369. start (0);
  198370. if (oldCallback != 0)
  198371. oldCallback->audioDeviceStopped();
  198372. }
  198373. bool isPlaying()
  198374. {
  198375. return isStarted && internal->error.isEmpty();
  198376. }
  198377. const String getLastError()
  198378. {
  198379. return internal->error;
  198380. }
  198381. String inputId, outputId;
  198382. private:
  198383. bool isOpen_, isStarted;
  198384. ALSAThread* internal;
  198385. };
  198386. class ALSAAudioIODeviceType : public AudioIODeviceType
  198387. {
  198388. public:
  198389. ALSAAudioIODeviceType()
  198390. : AudioIODeviceType ("ALSA"),
  198391. hasScanned (false)
  198392. {
  198393. }
  198394. ~ALSAAudioIODeviceType()
  198395. {
  198396. }
  198397. void scanForDevices()
  198398. {
  198399. if (hasScanned)
  198400. return;
  198401. hasScanned = true;
  198402. inputNames.clear();
  198403. inputIds.clear();
  198404. outputNames.clear();
  198405. outputIds.clear();
  198406. snd_ctl_t* handle;
  198407. snd_ctl_card_info_t* info;
  198408. snd_ctl_card_info_alloca (&info);
  198409. int cardNum = -1;
  198410. while (outputIds.size() + inputIds.size() <= 32)
  198411. {
  198412. snd_card_next (&cardNum);
  198413. if (cardNum < 0)
  198414. break;
  198415. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198416. {
  198417. if (snd_ctl_card_info (handle, info) >= 0)
  198418. {
  198419. String cardId (snd_ctl_card_info_get_id (info));
  198420. if (cardId.removeCharacters ("0123456789").isEmpty())
  198421. cardId = String (cardNum);
  198422. int device = -1;
  198423. for (;;)
  198424. {
  198425. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198426. break;
  198427. String id, name;
  198428. id << "hw:" << cardId << ',' << device;
  198429. bool isInput, isOutput;
  198430. if (testDevice (id, isInput, isOutput))
  198431. {
  198432. name << snd_ctl_card_info_get_name (info);
  198433. if (name.isEmpty())
  198434. name = id;
  198435. if (isInput)
  198436. {
  198437. inputNames.add (name);
  198438. inputIds.add (id);
  198439. }
  198440. if (isOutput)
  198441. {
  198442. outputNames.add (name);
  198443. outputIds.add (id);
  198444. }
  198445. }
  198446. }
  198447. }
  198448. snd_ctl_close (handle);
  198449. }
  198450. }
  198451. inputNames.appendNumbersToDuplicates (false, true);
  198452. outputNames.appendNumbersToDuplicates (false, true);
  198453. }
  198454. const StringArray getDeviceNames (bool wantInputNames) const
  198455. {
  198456. jassert (hasScanned); // need to call scanForDevices() before doing this
  198457. return wantInputNames ? inputNames : outputNames;
  198458. }
  198459. int getDefaultDeviceIndex (bool forInput) const
  198460. {
  198461. jassert (hasScanned); // need to call scanForDevices() before doing this
  198462. return 0;
  198463. }
  198464. bool hasSeparateInputsAndOutputs() const { return true; }
  198465. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198466. {
  198467. jassert (hasScanned); // need to call scanForDevices() before doing this
  198468. ALSAAudioIODevice* d = dynamic_cast <ALSAAudioIODevice*> (device);
  198469. if (d == 0)
  198470. return -1;
  198471. return asInput ? inputIds.indexOf (d->inputId)
  198472. : outputIds.indexOf (d->outputId);
  198473. }
  198474. AudioIODevice* createDevice (const String& outputDeviceName,
  198475. const String& inputDeviceName)
  198476. {
  198477. jassert (hasScanned); // need to call scanForDevices() before doing this
  198478. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198479. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198480. String deviceName (outputIndex >= 0 ? outputDeviceName
  198481. : inputDeviceName);
  198482. if (inputIndex >= 0 || outputIndex >= 0)
  198483. return new ALSAAudioIODevice (deviceName,
  198484. inputIds [inputIndex],
  198485. outputIds [outputIndex]);
  198486. return 0;
  198487. }
  198488. juce_UseDebuggingNewOperator
  198489. private:
  198490. StringArray inputNames, outputNames, inputIds, outputIds;
  198491. bool hasScanned;
  198492. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198493. {
  198494. unsigned int minChansOut = 0, maxChansOut = 0;
  198495. unsigned int minChansIn = 0, maxChansIn = 0;
  198496. Array <int> rates;
  198497. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198498. DBG ("ALSA device: " + id
  198499. + " outs=" + String ((int) minChansOut) + "-" + String ((int) maxChansOut)
  198500. + " ins=" + String ((int) minChansIn) + "-" + String ((int) maxChansIn)
  198501. + " rates=" + String (rates.size()));
  198502. isInput = maxChansIn > 0;
  198503. isOutput = maxChansOut > 0;
  198504. return (isInput || isOutput) && rates.size() > 0;
  198505. }
  198506. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198507. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198508. };
  198509. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198510. {
  198511. return new ALSAAudioIODeviceType();
  198512. }
  198513. #endif
  198514. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198515. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198516. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198517. // compiled on its own).
  198518. #ifdef JUCE_INCLUDED_FILE
  198519. #if JUCE_JACK
  198520. static void* juce_libjack_handle = 0;
  198521. void* juce_load_jack_function (const char* const name)
  198522. {
  198523. if (juce_libjack_handle == 0)
  198524. return 0;
  198525. return dlsym (juce_libjack_handle, name);
  198526. }
  198527. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198528. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198529. return_type fn_name argument_types { \
  198530. static fn_name##_ptr_t fn = 0; \
  198531. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198532. if (fn) return (*fn)arguments; \
  198533. else return 0; \
  198534. }
  198535. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198536. typedef void (*fn_name##_ptr_t)argument_types; \
  198537. void fn_name argument_types { \
  198538. static fn_name##_ptr_t fn = 0; \
  198539. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198540. if (fn) (*fn)arguments; \
  198541. }
  198542. JUCE_DECL_JACK_FUNCTION (jack_client_t*, jack_client_open, (const char* client_name, jack_options_t options, jack_status_t* status), (client_name, options, status));
  198543. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198544. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198545. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198546. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198547. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198548. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198549. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198550. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198551. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_register, (jack_client_t* client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size), (client, port_name, port_type, flags, buffer_size));
  198552. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198553. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198554. JUCE_DECL_JACK_FUNCTION (const char**, jack_get_ports, (jack_client_t* client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags), (client, port_name_pattern, type_name_pattern, flags));
  198555. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198556. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198557. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198558. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198559. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198560. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198561. #if JUCE_DEBUG
  198562. #define JACK_LOGGING_ENABLED 1
  198563. #endif
  198564. #if JACK_LOGGING_ENABLED
  198565. static void jack_Log (const String& s)
  198566. {
  198567. std::cerr << s << std::endl;
  198568. }
  198569. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198570. {
  198571. if (status & JackServerFailed || status & JackServerError)
  198572. jack_Log ("Unable to connect to JACK server");
  198573. if (status & JackVersionError)
  198574. jack_Log ("Client's protocol version does not match");
  198575. if (status & JackInvalidOption)
  198576. jack_Log ("The operation contained an invalid or unsupported option");
  198577. if (status & JackNameNotUnique)
  198578. jack_Log ("The desired client name was not unique");
  198579. if (status & JackNoSuchClient)
  198580. jack_Log ("Requested client does not exist");
  198581. if (status & JackInitFailure)
  198582. jack_Log ("Unable to initialize client");
  198583. }
  198584. #else
  198585. #define dumpJackErrorMessage(a) {}
  198586. #define jack_Log(...) {}
  198587. #endif
  198588. #ifndef JUCE_JACK_CLIENT_NAME
  198589. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198590. #endif
  198591. class JackAudioIODevice : public AudioIODevice
  198592. {
  198593. public:
  198594. JackAudioIODevice (const String& deviceName,
  198595. const String& inputId_,
  198596. const String& outputId_)
  198597. : AudioIODevice (deviceName, "JACK"),
  198598. inputId (inputId_),
  198599. outputId (outputId_),
  198600. isOpen_ (false),
  198601. callback (0),
  198602. totalNumberOfInputChannels (0),
  198603. totalNumberOfOutputChannels (0)
  198604. {
  198605. jassert (deviceName.isNotEmpty());
  198606. jack_status_t status;
  198607. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198608. if (client == 0)
  198609. {
  198610. dumpJackErrorMessage (status);
  198611. }
  198612. else
  198613. {
  198614. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198615. // open input ports
  198616. const StringArray inputChannels (getInputChannelNames());
  198617. for (int i = 0; i < inputChannels.size(); i++)
  198618. {
  198619. String inputName;
  198620. inputName << "in_" << ++totalNumberOfInputChannels;
  198621. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198622. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198623. }
  198624. // open output ports
  198625. const StringArray outputChannels (getOutputChannelNames());
  198626. for (int i = 0; i < outputChannels.size (); i++)
  198627. {
  198628. String outputName;
  198629. outputName << "out_" << ++totalNumberOfOutputChannels;
  198630. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198631. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198632. }
  198633. inChans.calloc (totalNumberOfInputChannels + 2);
  198634. outChans.calloc (totalNumberOfOutputChannels + 2);
  198635. }
  198636. }
  198637. ~JackAudioIODevice()
  198638. {
  198639. close();
  198640. if (client != 0)
  198641. {
  198642. JUCE_NAMESPACE::jack_client_close (client);
  198643. client = 0;
  198644. }
  198645. }
  198646. const StringArray getChannelNames (bool forInput) const
  198647. {
  198648. StringArray names;
  198649. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198650. forInput ? JackPortIsInput : JackPortIsOutput);
  198651. if (ports != 0)
  198652. {
  198653. int j = 0;
  198654. while (ports[j] != 0)
  198655. {
  198656. const String portName (ports [j++]);
  198657. if (portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198658. names.add (portName.fromFirstOccurrenceOf (":", false, false));
  198659. }
  198660. free (ports);
  198661. }
  198662. return names;
  198663. }
  198664. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198665. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198666. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198667. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198668. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198669. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198670. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198671. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198672. double sampleRate, int bufferSizeSamples)
  198673. {
  198674. if (client == 0)
  198675. {
  198676. lastError = "No JACK client running";
  198677. return lastError;
  198678. }
  198679. lastError = String::empty;
  198680. close();
  198681. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198682. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198683. JUCE_NAMESPACE::jack_activate (client);
  198684. isOpen_ = true;
  198685. if (! inputChannels.isZero())
  198686. {
  198687. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198688. if (ports != 0)
  198689. {
  198690. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198691. for (int i = 0; i < numInputChannels; ++i)
  198692. {
  198693. const String portName (ports[i]);
  198694. if (inputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198695. {
  198696. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198697. if (error != 0)
  198698. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198699. }
  198700. }
  198701. free (ports);
  198702. }
  198703. }
  198704. if (! outputChannels.isZero())
  198705. {
  198706. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198707. if (ports != 0)
  198708. {
  198709. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198710. for (int i = 0; i < numOutputChannels; ++i)
  198711. {
  198712. const String portName (ports[i]);
  198713. if (outputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198714. {
  198715. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198716. if (error != 0)
  198717. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198718. }
  198719. }
  198720. free (ports);
  198721. }
  198722. }
  198723. return lastError;
  198724. }
  198725. void close()
  198726. {
  198727. stop();
  198728. if (client != 0)
  198729. {
  198730. JUCE_NAMESPACE::jack_deactivate (client);
  198731. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198732. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198733. }
  198734. isOpen_ = false;
  198735. }
  198736. void start (AudioIODeviceCallback* newCallback)
  198737. {
  198738. if (isOpen_ && newCallback != callback)
  198739. {
  198740. if (newCallback != 0)
  198741. newCallback->audioDeviceAboutToStart (this);
  198742. AudioIODeviceCallback* const oldCallback = callback;
  198743. {
  198744. const ScopedLock sl (callbackLock);
  198745. callback = newCallback;
  198746. }
  198747. if (oldCallback != 0)
  198748. oldCallback->audioDeviceStopped();
  198749. }
  198750. }
  198751. void stop()
  198752. {
  198753. start (0);
  198754. }
  198755. bool isOpen() { return isOpen_; }
  198756. bool isPlaying() { return callback != 0; }
  198757. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198758. double getCurrentSampleRate() { return getSampleRate (0); }
  198759. int getCurrentBitDepth() { return 32; }
  198760. const String getLastError() { return lastError; }
  198761. const BigInteger getActiveOutputChannels() const
  198762. {
  198763. BigInteger outputBits;
  198764. for (int i = 0; i < outputPorts.size(); i++)
  198765. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198766. outputBits.setBit (i);
  198767. return outputBits;
  198768. }
  198769. const BigInteger getActiveInputChannels() const
  198770. {
  198771. BigInteger inputBits;
  198772. for (int i = 0; i < inputPorts.size(); i++)
  198773. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198774. inputBits.setBit (i);
  198775. return inputBits;
  198776. }
  198777. int getOutputLatencyInSamples()
  198778. {
  198779. int latency = 0;
  198780. for (int i = 0; i < outputPorts.size(); i++)
  198781. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198782. return latency;
  198783. }
  198784. int getInputLatencyInSamples()
  198785. {
  198786. int latency = 0;
  198787. for (int i = 0; i < inputPorts.size(); i++)
  198788. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198789. return latency;
  198790. }
  198791. String inputId, outputId;
  198792. private:
  198793. void process (const int numSamples)
  198794. {
  198795. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198796. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198797. {
  198798. jack_default_audio_sample_t* in
  198799. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198800. if (in != 0)
  198801. inChans [numActiveInChans++] = (float*) in;
  198802. }
  198803. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198804. {
  198805. jack_default_audio_sample_t* out
  198806. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198807. if (out != 0)
  198808. outChans [numActiveOutChans++] = (float*) out;
  198809. }
  198810. const ScopedLock sl (callbackLock);
  198811. if (callback != 0)
  198812. {
  198813. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198814. outChans, numActiveOutChans, numSamples);
  198815. }
  198816. else
  198817. {
  198818. for (i = 0; i < numActiveOutChans; ++i)
  198819. zeromem (outChans[i], sizeof (float) * numSamples);
  198820. }
  198821. }
  198822. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198823. {
  198824. if (callbackArgument != 0)
  198825. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198826. return 0;
  198827. }
  198828. static void threadInitCallback (void* callbackArgument)
  198829. {
  198830. jack_Log ("JackAudioIODevice::initialise");
  198831. }
  198832. static void shutdownCallback (void* callbackArgument)
  198833. {
  198834. jack_Log ("JackAudioIODevice::shutdown");
  198835. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  198836. if (device != 0)
  198837. {
  198838. device->client = 0;
  198839. device->close();
  198840. }
  198841. }
  198842. static void errorCallback (const char* msg)
  198843. {
  198844. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  198845. }
  198846. bool isOpen_;
  198847. jack_client_t* client;
  198848. String lastError;
  198849. AudioIODeviceCallback* callback;
  198850. CriticalSection callbackLock;
  198851. HeapBlock <float*> inChans, outChans;
  198852. int totalNumberOfInputChannels;
  198853. int totalNumberOfOutputChannels;
  198854. VoidArray inputPorts, outputPorts;
  198855. };
  198856. class JackAudioIODeviceType : public AudioIODeviceType
  198857. {
  198858. public:
  198859. JackAudioIODeviceType()
  198860. : AudioIODeviceType ("JACK"),
  198861. hasScanned (false)
  198862. {
  198863. }
  198864. ~JackAudioIODeviceType()
  198865. {
  198866. }
  198867. void scanForDevices()
  198868. {
  198869. hasScanned = true;
  198870. inputNames.clear();
  198871. inputIds.clear();
  198872. outputNames.clear();
  198873. outputIds.clear();
  198874. if (juce_libjack_handle == 0)
  198875. {
  198876. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  198877. if (juce_libjack_handle == 0)
  198878. return;
  198879. }
  198880. // open a dummy client
  198881. jack_status_t status;
  198882. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  198883. if (client == 0)
  198884. {
  198885. dumpJackErrorMessage (status);
  198886. }
  198887. else
  198888. {
  198889. // scan for output devices
  198890. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198891. if (ports != 0)
  198892. {
  198893. int j = 0;
  198894. while (ports[j] != 0)
  198895. {
  198896. String clientName (ports[j]);
  198897. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198898. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198899. && ! inputNames.contains (clientName))
  198900. {
  198901. inputNames.add (clientName);
  198902. inputIds.add (ports [j]);
  198903. }
  198904. ++j;
  198905. }
  198906. free (ports);
  198907. }
  198908. // scan for input devices
  198909. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198910. if (ports != 0)
  198911. {
  198912. int j = 0;
  198913. while (ports[j] != 0)
  198914. {
  198915. String clientName (ports[j]);
  198916. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198917. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198918. && ! outputNames.contains (clientName))
  198919. {
  198920. outputNames.add (clientName);
  198921. outputIds.add (ports [j]);
  198922. }
  198923. ++j;
  198924. }
  198925. free (ports);
  198926. }
  198927. JUCE_NAMESPACE::jack_client_close (client);
  198928. }
  198929. }
  198930. const StringArray getDeviceNames (bool wantInputNames) const
  198931. {
  198932. jassert (hasScanned); // need to call scanForDevices() before doing this
  198933. return wantInputNames ? inputNames : outputNames;
  198934. }
  198935. int getDefaultDeviceIndex (bool forInput) const
  198936. {
  198937. jassert (hasScanned); // need to call scanForDevices() before doing this
  198938. return 0;
  198939. }
  198940. bool hasSeparateInputsAndOutputs() const { return true; }
  198941. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198942. {
  198943. jassert (hasScanned); // need to call scanForDevices() before doing this
  198944. JackAudioIODevice* d = dynamic_cast <JackAudioIODevice*> (device);
  198945. if (d == 0)
  198946. return -1;
  198947. return asInput ? inputIds.indexOf (d->inputId)
  198948. : outputIds.indexOf (d->outputId);
  198949. }
  198950. AudioIODevice* createDevice (const String& outputDeviceName,
  198951. const String& inputDeviceName)
  198952. {
  198953. jassert (hasScanned); // need to call scanForDevices() before doing this
  198954. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198955. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198956. if (inputIndex >= 0 || outputIndex >= 0)
  198957. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  198958. : inputDeviceName,
  198959. inputIds [inputIndex],
  198960. outputIds [outputIndex]);
  198961. return 0;
  198962. }
  198963. juce_UseDebuggingNewOperator
  198964. private:
  198965. StringArray inputNames, outputNames, inputIds, outputIds;
  198966. bool hasScanned;
  198967. JackAudioIODeviceType (const JackAudioIODeviceType&);
  198968. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  198969. };
  198970. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  198971. {
  198972. return new JackAudioIODeviceType();
  198973. }
  198974. #else // if JACK is turned off..
  198975. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  198976. #endif
  198977. #endif
  198978. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  198979. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  198980. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198981. // compiled on its own).
  198982. #if JUCE_INCLUDED_FILE
  198983. #if JUCE_ALSA
  198984. static snd_seq_t* iterateDevices (const bool forInput,
  198985. StringArray& deviceNamesFound,
  198986. const int deviceIndexToOpen)
  198987. {
  198988. snd_seq_t* returnedHandle = 0;
  198989. snd_seq_t* seqHandle;
  198990. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  198991. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  198992. {
  198993. snd_seq_system_info_t* systemInfo;
  198994. snd_seq_client_info_t* clientInfo;
  198995. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  198996. {
  198997. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  198998. && snd_seq_client_info_malloc (&clientInfo) == 0)
  198999. {
  199000. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199001. while (--numClients >= 0 && returnedHandle == 0)
  199002. {
  199003. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199004. {
  199005. snd_seq_port_info_t* portInfo;
  199006. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199007. {
  199008. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199009. const int client = snd_seq_client_info_get_client (clientInfo);
  199010. snd_seq_port_info_set_client (portInfo, client);
  199011. snd_seq_port_info_set_port (portInfo, -1);
  199012. while (--numPorts >= 0)
  199013. {
  199014. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199015. && (snd_seq_port_info_get_capability (portInfo)
  199016. & (forInput ? SND_SEQ_PORT_CAP_READ
  199017. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199018. {
  199019. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199020. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199021. {
  199022. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199023. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199024. if (sourcePort != -1)
  199025. {
  199026. snd_seq_set_client_name (seqHandle,
  199027. forInput ? "Juce Midi Input"
  199028. : "Juce Midi Output");
  199029. const int portId
  199030. = snd_seq_create_simple_port (seqHandle,
  199031. forInput ? "Juce Midi In Port"
  199032. : "Juce Midi Out Port",
  199033. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199034. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199035. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199036. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199037. returnedHandle = seqHandle;
  199038. }
  199039. }
  199040. }
  199041. }
  199042. snd_seq_port_info_free (portInfo);
  199043. }
  199044. }
  199045. }
  199046. snd_seq_client_info_free (clientInfo);
  199047. }
  199048. snd_seq_system_info_free (systemInfo);
  199049. }
  199050. if (returnedHandle == 0)
  199051. snd_seq_close (seqHandle);
  199052. }
  199053. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199054. return returnedHandle;
  199055. }
  199056. static snd_seq_t* createDevice (const bool forInput,
  199057. const String& deviceNameToOpen)
  199058. {
  199059. snd_seq_t* seqHandle = 0;
  199060. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199061. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199062. {
  199063. snd_seq_set_client_name (seqHandle,
  199064. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199065. const int portId
  199066. = snd_seq_create_simple_port (seqHandle,
  199067. forInput ? "in"
  199068. : "out",
  199069. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199070. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199071. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199072. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199073. if (portId < 0)
  199074. {
  199075. snd_seq_close (seqHandle);
  199076. seqHandle = 0;
  199077. }
  199078. }
  199079. return seqHandle;
  199080. }
  199081. class MidiOutputDevice
  199082. {
  199083. public:
  199084. MidiOutputDevice (MidiOutput* const midiOutput_,
  199085. snd_seq_t* const seqHandle_)
  199086. :
  199087. midiOutput (midiOutput_),
  199088. seqHandle (seqHandle_),
  199089. maxEventSize (16 * 1024)
  199090. {
  199091. jassert (seqHandle != 0 && midiOutput != 0);
  199092. snd_midi_event_new (maxEventSize, &midiParser);
  199093. }
  199094. ~MidiOutputDevice()
  199095. {
  199096. snd_midi_event_free (midiParser);
  199097. snd_seq_close (seqHandle);
  199098. }
  199099. void sendMessageNow (const MidiMessage& message)
  199100. {
  199101. if (message.getRawDataSize() > maxEventSize)
  199102. {
  199103. maxEventSize = message.getRawDataSize();
  199104. snd_midi_event_free (midiParser);
  199105. snd_midi_event_new (maxEventSize, &midiParser);
  199106. }
  199107. snd_seq_event_t event;
  199108. snd_seq_ev_clear (&event);
  199109. snd_midi_event_encode (midiParser,
  199110. message.getRawData(),
  199111. message.getRawDataSize(),
  199112. &event);
  199113. snd_midi_event_reset_encode (midiParser);
  199114. snd_seq_ev_set_source (&event, 0);
  199115. snd_seq_ev_set_subs (&event);
  199116. snd_seq_ev_set_direct (&event);
  199117. snd_seq_event_output (seqHandle, &event);
  199118. snd_seq_drain_output (seqHandle);
  199119. }
  199120. juce_UseDebuggingNewOperator
  199121. private:
  199122. MidiOutput* const midiOutput;
  199123. snd_seq_t* const seqHandle;
  199124. snd_midi_event_t* midiParser;
  199125. int maxEventSize;
  199126. };
  199127. const StringArray MidiOutput::getDevices()
  199128. {
  199129. StringArray devices;
  199130. iterateDevices (false, devices, -1);
  199131. return devices;
  199132. }
  199133. int MidiOutput::getDefaultDeviceIndex()
  199134. {
  199135. return 0;
  199136. }
  199137. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199138. {
  199139. MidiOutput* newDevice = 0;
  199140. StringArray devices;
  199141. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199142. if (handle != 0)
  199143. {
  199144. newDevice = new MidiOutput();
  199145. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199146. }
  199147. return newDevice;
  199148. }
  199149. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199150. {
  199151. MidiOutput* newDevice = 0;
  199152. snd_seq_t* const handle = createDevice (false, deviceName);
  199153. if (handle != 0)
  199154. {
  199155. newDevice = new MidiOutput();
  199156. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199157. }
  199158. return newDevice;
  199159. }
  199160. MidiOutput::~MidiOutput()
  199161. {
  199162. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199163. delete device;
  199164. }
  199165. void MidiOutput::reset()
  199166. {
  199167. }
  199168. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199169. {
  199170. return false;
  199171. }
  199172. void MidiOutput::setVolume (float leftVol, float rightVol)
  199173. {
  199174. }
  199175. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199176. {
  199177. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199178. }
  199179. class MidiInputThread : public Thread
  199180. {
  199181. public:
  199182. MidiInputThread (MidiInput* const midiInput_,
  199183. snd_seq_t* const seqHandle_,
  199184. MidiInputCallback* const callback_)
  199185. : Thread ("Juce MIDI Input"),
  199186. midiInput (midiInput_),
  199187. seqHandle (seqHandle_),
  199188. callback (callback_)
  199189. {
  199190. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199191. }
  199192. ~MidiInputThread()
  199193. {
  199194. snd_seq_close (seqHandle);
  199195. }
  199196. void run()
  199197. {
  199198. const int maxEventSize = 16 * 1024;
  199199. snd_midi_event_t* midiParser;
  199200. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199201. {
  199202. HeapBlock <uint8> buffer (maxEventSize);
  199203. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199204. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199205. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199206. while (! threadShouldExit())
  199207. {
  199208. if (poll (pfd, numPfds, 500) > 0)
  199209. {
  199210. snd_seq_event_t* inputEvent = 0;
  199211. snd_seq_nonblock (seqHandle, 1);
  199212. do
  199213. {
  199214. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199215. {
  199216. // xxx what about SYSEXes that are too big for the buffer?
  199217. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199218. snd_midi_event_reset_decode (midiParser);
  199219. if (numBytes > 0)
  199220. {
  199221. const MidiMessage message ((const uint8*) buffer,
  199222. numBytes,
  199223. Time::getMillisecondCounter() * 0.001);
  199224. callback->handleIncomingMidiMessage (midiInput, message);
  199225. }
  199226. snd_seq_free_event (inputEvent);
  199227. }
  199228. }
  199229. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199230. snd_seq_free_event (inputEvent);
  199231. }
  199232. }
  199233. snd_midi_event_free (midiParser);
  199234. }
  199235. };
  199236. juce_UseDebuggingNewOperator
  199237. private:
  199238. MidiInput* const midiInput;
  199239. snd_seq_t* const seqHandle;
  199240. MidiInputCallback* const callback;
  199241. };
  199242. MidiInput::MidiInput (const String& name_)
  199243. : name (name_),
  199244. internal (0)
  199245. {
  199246. }
  199247. MidiInput::~MidiInput()
  199248. {
  199249. stop();
  199250. MidiInputThread* const thread = (MidiInputThread*) internal;
  199251. delete thread;
  199252. }
  199253. void MidiInput::start()
  199254. {
  199255. ((MidiInputThread*) internal)->startThread();
  199256. }
  199257. void MidiInput::stop()
  199258. {
  199259. ((MidiInputThread*) internal)->stopThread (3000);
  199260. }
  199261. int MidiInput::getDefaultDeviceIndex()
  199262. {
  199263. return 0;
  199264. }
  199265. const StringArray MidiInput::getDevices()
  199266. {
  199267. StringArray devices;
  199268. iterateDevices (true, devices, -1);
  199269. return devices;
  199270. }
  199271. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199272. {
  199273. MidiInput* newDevice = 0;
  199274. StringArray devices;
  199275. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199276. if (handle != 0)
  199277. {
  199278. newDevice = new MidiInput (devices [deviceIndex]);
  199279. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199280. }
  199281. return newDevice;
  199282. }
  199283. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199284. {
  199285. MidiInput* newDevice = 0;
  199286. snd_seq_t* const handle = createDevice (true, deviceName);
  199287. if (handle != 0)
  199288. {
  199289. newDevice = new MidiInput (deviceName);
  199290. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199291. }
  199292. return newDevice;
  199293. }
  199294. #else
  199295. // (These are just stub functions if ALSA is unavailable...)
  199296. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199297. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199298. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199299. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199300. MidiOutput::~MidiOutput() {}
  199301. void MidiOutput::reset() {}
  199302. bool MidiOutput::getVolume (float&, float&) { return false; }
  199303. void MidiOutput::setVolume (float, float) {}
  199304. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199305. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199306. MidiInput::~MidiInput() {}
  199307. void MidiInput::start() {}
  199308. void MidiInput::stop() {}
  199309. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199310. const StringArray MidiInput::getDevices() { return StringArray(); }
  199311. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199312. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199313. #endif
  199314. #endif
  199315. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199316. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199317. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199318. // compiled on its own).
  199319. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199320. AudioCDReader::AudioCDReader()
  199321. : AudioFormatReader (0, "CD Audio")
  199322. {
  199323. }
  199324. const StringArray AudioCDReader::getAvailableCDNames()
  199325. {
  199326. StringArray names;
  199327. return names;
  199328. }
  199329. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199330. {
  199331. return 0;
  199332. }
  199333. AudioCDReader::~AudioCDReader()
  199334. {
  199335. }
  199336. void AudioCDReader::refreshTrackLengths()
  199337. {
  199338. }
  199339. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199340. int64 startSampleInFile, int numSamples)
  199341. {
  199342. return false;
  199343. }
  199344. bool AudioCDReader::isCDStillPresent() const
  199345. {
  199346. return false;
  199347. }
  199348. int AudioCDReader::getNumTracks() const
  199349. {
  199350. return 0;
  199351. }
  199352. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199353. {
  199354. return 0;
  199355. }
  199356. bool AudioCDReader::isTrackAudio (int trackNum) const
  199357. {
  199358. return false;
  199359. }
  199360. void AudioCDReader::enableIndexScanning (bool b)
  199361. {
  199362. }
  199363. int AudioCDReader::getLastIndex() const
  199364. {
  199365. return 0;
  199366. }
  199367. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199368. {
  199369. return Array<int>();
  199370. }
  199371. int AudioCDReader::getCDDBId()
  199372. {
  199373. return 0;
  199374. }
  199375. #endif
  199376. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199377. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199378. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199379. // compiled on its own).
  199380. #if JUCE_INCLUDED_FILE
  199381. void FileChooser::showPlatformDialog (Array<File>& results,
  199382. const String& title,
  199383. const File& file,
  199384. const String& filters,
  199385. bool isDirectory,
  199386. bool selectsFiles,
  199387. bool isSave,
  199388. bool warnAboutOverwritingExistingFiles,
  199389. bool selectMultipleFiles,
  199390. FilePreviewComponent* previewComponent)
  199391. {
  199392. const String separator (":");
  199393. String command ("zenity --file-selection");
  199394. if (title.isNotEmpty())
  199395. command << " --title=\"" << title << "\"";
  199396. if (file != File::nonexistent)
  199397. command << " --filename=\"" << file.getFullPathName () << "\"";
  199398. if (isDirectory)
  199399. command << " --directory";
  199400. if (isSave)
  199401. command << " --save";
  199402. if (selectMultipleFiles)
  199403. command << " --multiple --separator=\"" << separator << "\"";
  199404. command << " 2>&1";
  199405. MemoryOutputStream result;
  199406. int status = -1;
  199407. FILE* stream = popen (command.toUTF8(), "r");
  199408. if (stream != 0)
  199409. {
  199410. for (;;)
  199411. {
  199412. char buffer [1024];
  199413. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199414. if (bytesRead <= 0)
  199415. break;
  199416. result.write (buffer, bytesRead);
  199417. }
  199418. status = pclose (stream);
  199419. }
  199420. if (status == 0)
  199421. {
  199422. StringArray tokens;
  199423. if (selectMultipleFiles)
  199424. tokens.addTokens (result.toUTF8(), separator, String::empty);
  199425. else
  199426. tokens.add (result.toUTF8());
  199427. for (int i = 0; i < tokens.size(); i++)
  199428. results.add (File (tokens[i]));
  199429. return;
  199430. }
  199431. //xxx ain't got one!
  199432. jassertfalse
  199433. }
  199434. #endif
  199435. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199436. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199437. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199438. // compiled on its own).
  199439. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199440. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199441. : browser (0),
  199442. blankPageShown (false),
  199443. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199444. {
  199445. setOpaque (true);
  199446. }
  199447. WebBrowserComponent::~WebBrowserComponent()
  199448. {
  199449. }
  199450. void WebBrowserComponent::goToURL (const String& url,
  199451. const StringArray* headers,
  199452. const MemoryBlock* postData)
  199453. {
  199454. lastURL = url;
  199455. lastHeaders.clear();
  199456. if (headers != 0)
  199457. lastHeaders = *headers;
  199458. lastPostData.setSize (0);
  199459. if (postData != 0)
  199460. lastPostData = *postData;
  199461. blankPageShown = false;
  199462. }
  199463. void WebBrowserComponent::stop()
  199464. {
  199465. }
  199466. void WebBrowserComponent::goBack()
  199467. {
  199468. lastURL = String::empty;
  199469. blankPageShown = false;
  199470. }
  199471. void WebBrowserComponent::goForward()
  199472. {
  199473. lastURL = String::empty;
  199474. }
  199475. void WebBrowserComponent::refresh()
  199476. {
  199477. }
  199478. void WebBrowserComponent::paint (Graphics& g)
  199479. {
  199480. g.fillAll (Colours::white);
  199481. }
  199482. void WebBrowserComponent::checkWindowAssociation()
  199483. {
  199484. }
  199485. void WebBrowserComponent::reloadLastURL()
  199486. {
  199487. if (lastURL.isNotEmpty())
  199488. {
  199489. goToURL (lastURL, &lastHeaders, &lastPostData);
  199490. lastURL = String::empty;
  199491. }
  199492. }
  199493. void WebBrowserComponent::parentHierarchyChanged()
  199494. {
  199495. checkWindowAssociation();
  199496. }
  199497. void WebBrowserComponent::resized()
  199498. {
  199499. }
  199500. void WebBrowserComponent::visibilityChanged()
  199501. {
  199502. checkWindowAssociation();
  199503. }
  199504. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199505. {
  199506. return true;
  199507. }
  199508. #endif
  199509. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199510. #endif
  199511. END_JUCE_NAMESPACE
  199512. #endif
  199513. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199514. #endif
  199515. #if JUCE_MAC || JUCE_IPHONE
  199516. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199517. #if JUCE_MAC || JUCE_IPHONE
  199518. BEGIN_JUCE_NAMESPACE
  199519. #undef Point
  199520. #define JUCE_INCLUDED_FILE 1
  199521. // Now include the actual code files..
  199522. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199523. #ifndef JUCE_ObjCExtraSuffix
  199524. #define JUCE_ObjCExtraSuffix 3
  199525. #endif
  199526. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199527. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199528. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199529. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199530. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199531. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199532. // compiled on its own).
  199533. #if JUCE_INCLUDED_FILE
  199534. static const String nsStringToJuce (NSString* s)
  199535. {
  199536. return String::fromUTF8 ([s UTF8String]);
  199537. }
  199538. static NSString* juceStringToNS (const String& s)
  199539. {
  199540. return [NSString stringWithUTF8String: s.toUTF8()];
  199541. }
  199542. static const String convertUTF16ToString (const UniChar* utf16)
  199543. {
  199544. String s;
  199545. while (*utf16 != 0)
  199546. s += (juce_wchar) *utf16++;
  199547. return s;
  199548. }
  199549. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199550. {
  199551. String result;
  199552. if (cfString != 0)
  199553. {
  199554. CFRange range = { 0, CFStringGetLength (cfString) };
  199555. HeapBlock <UniChar> u (range.length + 1);
  199556. CFStringGetCharacters (cfString, range, u);
  199557. u[range.length] = 0;
  199558. result = convertUTF16ToString (u);
  199559. }
  199560. return result;
  199561. }
  199562. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199563. {
  199564. const int len = s.length();
  199565. HeapBlock <UniChar> temp (len + 2);
  199566. for (int i = 0; i <= len; ++i)
  199567. temp[i] = s[i];
  199568. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199569. }
  199570. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199571. {
  199572. #if JUCE_IPHONE
  199573. const ScopedAutoReleasePool pool;
  199574. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199575. #else
  199576. UnicodeMapping map;
  199577. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199578. kUnicodeNoSubset,
  199579. kTextEncodingDefaultFormat);
  199580. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199581. kUnicodeCanonicalCompVariant,
  199582. kTextEncodingDefaultFormat);
  199583. map.mappingVersion = kUnicodeUseLatestMapping;
  199584. UnicodeToTextInfo conversionInfo = 0;
  199585. String result;
  199586. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199587. {
  199588. const int len = s.length();
  199589. HeapBlock <UniChar> tempIn, tempOut;
  199590. tempIn.calloc (len + 2);
  199591. tempOut.calloc (len + 2);
  199592. for (int i = 0; i <= len; ++i)
  199593. tempIn[i] = s[i];
  199594. ByteCount bytesRead = 0;
  199595. ByteCount outputBufferSize = 0;
  199596. if (ConvertFromUnicodeToText (conversionInfo,
  199597. len * sizeof (UniChar), tempIn,
  199598. kUnicodeDefaultDirectionMask,
  199599. 0, 0, 0, 0,
  199600. len * sizeof (UniChar), &bytesRead,
  199601. &outputBufferSize, tempOut) == noErr)
  199602. {
  199603. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199604. tchar* t = result;
  199605. unsigned int i;
  199606. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199607. t[i] = (tchar) tempOut[i];
  199608. t[i] = 0;
  199609. }
  199610. DisposeUnicodeToTextInfo (&conversionInfo);
  199611. }
  199612. return result;
  199613. #endif
  199614. }
  199615. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199616. void SystemClipboard::copyTextToClipboard (const String& text)
  199617. {
  199618. #if JUCE_IPHONE
  199619. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199620. forPasteboardType: @"public.text"];
  199621. #else
  199622. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199623. owner: nil];
  199624. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199625. forType: NSStringPboardType];
  199626. #endif
  199627. }
  199628. const String SystemClipboard::getTextFromClipboard()
  199629. {
  199630. #if JUCE_IPHONE
  199631. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199632. #else
  199633. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199634. #endif
  199635. return text == 0 ? String::empty
  199636. : nsStringToJuce (text);
  199637. }
  199638. #endif
  199639. #endif
  199640. /*** End of inlined file: juce_mac_Strings.mm ***/
  199641. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199642. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199643. // compiled on its own).
  199644. #if JUCE_INCLUDED_FILE
  199645. namespace SystemStatsHelpers
  199646. {
  199647. static int64 highResTimerFrequency = 0;
  199648. static double highResTimerToMillisecRatio = 0;
  199649. #if JUCE_INTEL
  199650. static void juce_getCpuVendor (char* const v) throw()
  199651. {
  199652. int vendor[4];
  199653. zerostruct (vendor);
  199654. int dummy = 0;
  199655. asm ("mov %%ebx, %%esi \n\t"
  199656. "cpuid \n\t"
  199657. "xchg %%esi, %%ebx"
  199658. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199659. memcpy (v, vendor, 16);
  199660. }
  199661. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199662. {
  199663. unsigned int cpu = 0;
  199664. unsigned int ext = 0;
  199665. unsigned int family = 0;
  199666. unsigned int dummy = 0;
  199667. asm ("mov %%ebx, %%esi \n\t"
  199668. "cpuid \n\t"
  199669. "xchg %%esi, %%ebx"
  199670. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199671. familyModel = family;
  199672. extFeatures = ext;
  199673. return cpu;
  199674. }
  199675. struct CPUFlags
  199676. {
  199677. bool hasMMX : 1;
  199678. bool hasSSE : 1;
  199679. bool hasSSE2 : 1;
  199680. bool has3DNow : 1;
  199681. };
  199682. static CPUFlags cpuFlags;
  199683. #endif
  199684. }
  199685. void SystemStats::initialiseStats() throw()
  199686. {
  199687. using namespace SystemStatsHelpers;
  199688. static bool initialised = false;
  199689. if (! initialised)
  199690. {
  199691. initialised = true;
  199692. #if JUCE_MAC
  199693. // extremely annoying: adding this line stops the apple menu items from working. Of
  199694. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199695. // any events.
  199696. //NSApplicationLoad();
  199697. [NSApplication sharedApplication];
  199698. #endif
  199699. #if JUCE_INTEL
  199700. {
  199701. unsigned int familyModel, extFeatures;
  199702. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199703. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199704. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199705. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199706. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199707. }
  199708. #endif
  199709. mach_timebase_info_data_t timebase;
  199710. (void) mach_timebase_info (&timebase);
  199711. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199712. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199713. String s (SystemStats::getJUCEVersion());
  199714. rlimit lim;
  199715. getrlimit (RLIMIT_NOFILE, &lim);
  199716. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199717. setrlimit (RLIMIT_NOFILE, &lim);
  199718. }
  199719. }
  199720. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199721. {
  199722. return MacOSX;
  199723. }
  199724. const String SystemStats::getOperatingSystemName() throw()
  199725. {
  199726. return "Mac OS X";
  199727. }
  199728. bool SystemStats::isOperatingSystem64Bit() throw()
  199729. {
  199730. #if JUCE_64BIT
  199731. return true;
  199732. #else
  199733. //xxx not sure how to find this out?..
  199734. return false;
  199735. #endif
  199736. }
  199737. int SystemStats::getMemorySizeInMegabytes() throw()
  199738. {
  199739. uint64 mem = 0;
  199740. size_t memSize = sizeof (mem);
  199741. int mib[] = { CTL_HW, HW_MEMSIZE };
  199742. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199743. return (int) (mem / (1024 * 1024));
  199744. }
  199745. bool SystemStats::hasMMX() throw()
  199746. {
  199747. #if JUCE_INTEL
  199748. return SystemStatsHelpers::cpuFlags.hasMMX;
  199749. #else
  199750. return false;
  199751. #endif
  199752. }
  199753. bool SystemStats::hasSSE() throw()
  199754. {
  199755. #if JUCE_INTEL
  199756. return SystemStatsHelpers::cpuFlags.hasSSE;
  199757. #else
  199758. return false;
  199759. #endif
  199760. }
  199761. bool SystemStats::hasSSE2() throw()
  199762. {
  199763. #if JUCE_INTEL
  199764. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199765. #else
  199766. return false;
  199767. #endif
  199768. }
  199769. bool SystemStats::has3DNow() throw()
  199770. {
  199771. #if JUCE_INTEL
  199772. return SystemStatsHelpers::cpuFlags.has3DNow;
  199773. #else
  199774. return false;
  199775. #endif
  199776. }
  199777. const String SystemStats::getCpuVendor() throw()
  199778. {
  199779. #if JUCE_INTEL
  199780. char v [16];
  199781. SystemStatsHelpers::juce_getCpuVendor (v);
  199782. return String (v, 16);
  199783. #else
  199784. return String::empty;
  199785. #endif
  199786. }
  199787. int SystemStats::getCpuSpeedInMegaherz() throw()
  199788. {
  199789. uint64 speedHz = 0;
  199790. size_t speedSize = sizeof (speedHz);
  199791. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199792. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199793. #if JUCE_BIG_ENDIAN
  199794. if (speedSize == 4)
  199795. speedHz >>= 32;
  199796. #endif
  199797. return (int) (speedHz / 1000000);
  199798. }
  199799. int SystemStats::getNumCpus() throw()
  199800. {
  199801. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199802. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199803. #else
  199804. return MPProcessors();
  199805. #endif
  199806. }
  199807. const String SystemStats::getLogonName()
  199808. {
  199809. return nsStringToJuce (NSUserName());
  199810. }
  199811. const String SystemStats::getFullUserName()
  199812. {
  199813. return nsStringToJuce (NSFullUserName());
  199814. }
  199815. uint32 juce_millisecondsSinceStartup() throw()
  199816. {
  199817. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199818. }
  199819. double Time::getMillisecondCounterHiRes() throw()
  199820. {
  199821. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199822. }
  199823. int64 Time::getHighResolutionTicks() throw()
  199824. {
  199825. return (int64) mach_absolute_time();
  199826. }
  199827. int64 Time::getHighResolutionTicksPerSecond() throw()
  199828. {
  199829. return SystemStatsHelpers::highResTimerFrequency;
  199830. }
  199831. int64 SystemStats::getClockCycleCounter() throw()
  199832. {
  199833. return (int64) mach_absolute_time();
  199834. }
  199835. bool Time::setSystemTimeToThisTime() const throw()
  199836. {
  199837. jassertfalse
  199838. return false;
  199839. }
  199840. int SystemStats::getPageSize() throw()
  199841. {
  199842. return (int) NSPageSize();
  199843. }
  199844. void PlatformUtilities::fpuReset()
  199845. {
  199846. }
  199847. #endif
  199848. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  199849. /*** Start of inlined file: juce_mac_Network.mm ***/
  199850. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199851. // compiled on its own).
  199852. #if JUCE_INCLUDED_FILE
  199853. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  199854. {
  199855. #ifndef IFT_ETHER
  199856. #define IFT_ETHER 6
  199857. #endif
  199858. ifaddrs* addrs = 0;
  199859. int numResults = 0;
  199860. if (getifaddrs (&addrs) == 0)
  199861. {
  199862. const ifaddrs* cursor = addrs;
  199863. while (cursor != 0 && numResults < maxNum)
  199864. {
  199865. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  199866. if (sto->ss_family == AF_LINK)
  199867. {
  199868. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  199869. if (sadd->sdl_type == IFT_ETHER)
  199870. {
  199871. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  199872. uint64 a = 0;
  199873. for (int i = 6; --i >= 0;)
  199874. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  199875. *addresses++ = (int64) a;
  199876. ++numResults;
  199877. }
  199878. }
  199879. cursor = cursor->ifa_next;
  199880. }
  199881. freeifaddrs (addrs);
  199882. }
  199883. return numResults;
  199884. }
  199885. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  199886. const String& emailSubject,
  199887. const String& bodyText,
  199888. const StringArray& filesToAttach)
  199889. {
  199890. #if JUCE_IPHONE
  199891. //xxx probably need to use MFMailComposeViewController
  199892. jassertfalse
  199893. return false;
  199894. #else
  199895. const ScopedAutoReleasePool pool;
  199896. String script;
  199897. script << "tell application \"Mail\"\r\n"
  199898. "set newMessage to make new outgoing message with properties {subject:\""
  199899. << emailSubject.replace ("\"", "\\\"")
  199900. << "\", content:\""
  199901. << bodyText.replace ("\"", "\\\"")
  199902. << "\" & return & return}\r\n"
  199903. "tell newMessage\r\n"
  199904. "set visible to true\r\n"
  199905. "set sender to \"sdfsdfsdfewf\"\r\n"
  199906. "make new to recipient at end of to recipients with properties {address:\""
  199907. << targetEmailAddress
  199908. << "\"}\r\n";
  199909. for (int i = 0; i < filesToAttach.size(); ++i)
  199910. {
  199911. script << "tell content\r\n"
  199912. "make new attachment with properties {file name:\""
  199913. << filesToAttach[i].replace ("\"", "\\\"")
  199914. << "\"} at after the last paragraph\r\n"
  199915. "end tell\r\n";
  199916. }
  199917. script << "end tell\r\n"
  199918. "end tell\r\n";
  199919. NSAppleScript* s = [[NSAppleScript alloc]
  199920. initWithSource: juceStringToNS (script)];
  199921. NSDictionary* error = 0;
  199922. const bool ok = [s executeAndReturnError: &error] != nil;
  199923. [s release];
  199924. return ok;
  199925. #endif
  199926. }
  199927. END_JUCE_NAMESPACE
  199928. using namespace JUCE_NAMESPACE;
  199929. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  199930. @interface JuceURLConnection : NSObject
  199931. {
  199932. @public
  199933. NSURLRequest* request;
  199934. NSURLConnection* connection;
  199935. NSMutableData* data;
  199936. Thread* runLoopThread;
  199937. bool initialised, hasFailed, hasFinished;
  199938. int position;
  199939. int64 contentLength;
  199940. NSLock* dataLock;
  199941. }
  199942. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  199943. - (void) dealloc;
  199944. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  199945. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  199946. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  199947. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  199948. - (BOOL) isOpen;
  199949. - (int) read: (char*) dest numBytes: (int) num;
  199950. - (int) readPosition;
  199951. - (void) stop;
  199952. - (void) createConnection;
  199953. @end
  199954. class JuceURLConnectionMessageThread : public Thread
  199955. {
  199956. JuceURLConnection* owner;
  199957. public:
  199958. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  199959. : Thread ("http connection"),
  199960. owner (owner_)
  199961. {
  199962. }
  199963. ~JuceURLConnectionMessageThread()
  199964. {
  199965. stopThread (10000);
  199966. }
  199967. void run()
  199968. {
  199969. [owner createConnection];
  199970. while (! threadShouldExit())
  199971. {
  199972. const ScopedAutoReleasePool pool;
  199973. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  199974. }
  199975. }
  199976. };
  199977. @implementation JuceURLConnection
  199978. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  199979. withCallback: (URL::OpenStreamProgressCallback*) callback
  199980. withContext: (void*) context;
  199981. {
  199982. [super init];
  199983. request = req;
  199984. [request retain];
  199985. data = [[NSMutableData data] retain];
  199986. dataLock = [[NSLock alloc] init];
  199987. connection = 0;
  199988. initialised = false;
  199989. hasFailed = false;
  199990. hasFinished = false;
  199991. contentLength = -1;
  199992. runLoopThread = new JuceURLConnectionMessageThread (self);
  199993. runLoopThread->startThread();
  199994. while (runLoopThread->isThreadRunning() && ! initialised)
  199995. {
  199996. if (callback != 0)
  199997. callback (context, -1, (int) [[request HTTPBody] length]);
  199998. Thread::sleep (1);
  199999. }
  200000. return self;
  200001. }
  200002. - (void) dealloc
  200003. {
  200004. [self stop];
  200005. delete runLoopThread;
  200006. [connection release];
  200007. [data release];
  200008. [dataLock release];
  200009. [request release];
  200010. [super dealloc];
  200011. }
  200012. - (void) createConnection
  200013. {
  200014. connection = [[NSURLConnection alloc] initWithRequest: request
  200015. delegate: [self retain]];
  200016. if (connection == nil)
  200017. runLoopThread->signalThreadShouldExit();
  200018. }
  200019. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200020. {
  200021. [dataLock lock];
  200022. [data setLength: 0];
  200023. [dataLock unlock];
  200024. initialised = true;
  200025. contentLength = [response expectedContentLength];
  200026. }
  200027. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200028. {
  200029. DBG (nsStringToJuce ([error description]));
  200030. hasFailed = true;
  200031. initialised = true;
  200032. runLoopThread->signalThreadShouldExit();
  200033. }
  200034. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200035. {
  200036. [dataLock lock];
  200037. [data appendData: newData];
  200038. [dataLock unlock];
  200039. initialised = true;
  200040. }
  200041. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200042. {
  200043. hasFinished = true;
  200044. initialised = true;
  200045. runLoopThread->signalThreadShouldExit();
  200046. }
  200047. - (BOOL) isOpen
  200048. {
  200049. return connection != 0 && ! hasFailed;
  200050. }
  200051. - (int) readPosition
  200052. {
  200053. return position;
  200054. }
  200055. - (int) read: (char*) dest numBytes: (int) numNeeded
  200056. {
  200057. int numDone = 0;
  200058. while (numNeeded > 0)
  200059. {
  200060. int available = jmin (numNeeded, (int) [data length]);
  200061. if (available > 0)
  200062. {
  200063. [dataLock lock];
  200064. [data getBytes: dest length: available];
  200065. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200066. [dataLock unlock];
  200067. numDone += available;
  200068. numNeeded -= available;
  200069. dest += available;
  200070. }
  200071. else
  200072. {
  200073. if (hasFailed || hasFinished)
  200074. break;
  200075. Thread::sleep (1);
  200076. }
  200077. }
  200078. position += numDone;
  200079. return numDone;
  200080. }
  200081. - (void) stop
  200082. {
  200083. [connection cancel];
  200084. runLoopThread->stopThread (10000);
  200085. }
  200086. @end
  200087. BEGIN_JUCE_NAMESPACE
  200088. bool juce_isOnLine()
  200089. {
  200090. return true;
  200091. }
  200092. void* juce_openInternetFile (const String& url,
  200093. const String& headers,
  200094. const MemoryBlock& postData,
  200095. const bool isPost,
  200096. URL::OpenStreamProgressCallback* callback,
  200097. void* callbackContext,
  200098. int timeOutMs)
  200099. {
  200100. const ScopedAutoReleasePool pool;
  200101. NSMutableURLRequest* req = [NSMutableURLRequest
  200102. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200103. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200104. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200105. if (req == nil)
  200106. return 0;
  200107. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200108. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200109. StringArray headerLines;
  200110. headerLines.addLines (headers);
  200111. headerLines.removeEmptyStrings (true);
  200112. for (int i = 0; i < headerLines.size(); ++i)
  200113. {
  200114. const String key (headerLines[i].upToFirstOccurrenceOf (":", false, false).trim());
  200115. const String value (headerLines[i].fromFirstOccurrenceOf (":", false, false).trim());
  200116. if (key.isNotEmpty() && value.isNotEmpty())
  200117. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200118. }
  200119. if (isPost && postData.getSize() > 0)
  200120. {
  200121. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200122. length: postData.getSize()]];
  200123. }
  200124. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200125. withCallback: callback
  200126. withContext: callbackContext];
  200127. if ([s isOpen])
  200128. return s;
  200129. [s release];
  200130. return 0;
  200131. }
  200132. void juce_closeInternetFile (void* handle)
  200133. {
  200134. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200135. if (s != 0)
  200136. {
  200137. const ScopedAutoReleasePool pool;
  200138. [s stop];
  200139. [s release];
  200140. }
  200141. }
  200142. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200143. {
  200144. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200145. if (s != 0)
  200146. {
  200147. const ScopedAutoReleasePool pool;
  200148. return [s read: (char*) buffer numBytes: bytesToRead];
  200149. }
  200150. return 0;
  200151. }
  200152. int64 juce_getInternetFileContentLength (void* handle)
  200153. {
  200154. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200155. if (s != 0)
  200156. return s->contentLength;
  200157. return -1;
  200158. }
  200159. int juce_seekInInternetFile (void* handle, int newPosition)
  200160. {
  200161. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200162. if (s != 0)
  200163. return [s readPosition];
  200164. return 0;
  200165. }
  200166. #endif
  200167. /*** End of inlined file: juce_mac_Network.mm ***/
  200168. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200169. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200170. // compiled on its own).
  200171. #if JUCE_INCLUDED_FILE
  200172. struct NamedPipeInternal
  200173. {
  200174. String pipeInName, pipeOutName;
  200175. int pipeIn, pipeOut;
  200176. bool volatile createdPipe, blocked, stopReadOperation;
  200177. static void signalHandler (int) {}
  200178. };
  200179. void NamedPipe::cancelPendingReads()
  200180. {
  200181. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200182. {
  200183. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200184. intern->stopReadOperation = true;
  200185. char buffer [1] = { 0 };
  200186. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200187. (void) bytesWritten;
  200188. int timeout = 2000;
  200189. while (intern->blocked && --timeout >= 0)
  200190. Thread::sleep (2);
  200191. intern->stopReadOperation = false;
  200192. }
  200193. }
  200194. void NamedPipe::close()
  200195. {
  200196. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200197. if (intern != 0)
  200198. {
  200199. internal = 0;
  200200. if (intern->pipeIn != -1)
  200201. ::close (intern->pipeIn);
  200202. if (intern->pipeOut != -1)
  200203. ::close (intern->pipeOut);
  200204. if (intern->createdPipe)
  200205. {
  200206. unlink (intern->pipeInName.toUTF8());
  200207. unlink (intern->pipeOutName.toUTF8());
  200208. }
  200209. delete intern;
  200210. }
  200211. }
  200212. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200213. {
  200214. close();
  200215. NamedPipeInternal* const intern = new NamedPipeInternal();
  200216. internal = intern;
  200217. intern->createdPipe = createPipe;
  200218. intern->blocked = false;
  200219. intern->stopReadOperation = false;
  200220. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200221. siginterrupt (SIGPIPE, 1);
  200222. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  200223. intern->pipeInName = pipePath + "_in";
  200224. intern->pipeOutName = pipePath + "_out";
  200225. intern->pipeIn = -1;
  200226. intern->pipeOut = -1;
  200227. if (createPipe)
  200228. {
  200229. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200230. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200231. {
  200232. delete intern;
  200233. internal = 0;
  200234. return false;
  200235. }
  200236. }
  200237. return true;
  200238. }
  200239. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200240. {
  200241. int bytesRead = -1;
  200242. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200243. if (intern != 0)
  200244. {
  200245. intern->blocked = true;
  200246. if (intern->pipeIn == -1)
  200247. {
  200248. if (intern->createdPipe)
  200249. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200250. else
  200251. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200252. if (intern->pipeIn == -1)
  200253. {
  200254. intern->blocked = false;
  200255. return -1;
  200256. }
  200257. }
  200258. bytesRead = 0;
  200259. char* p = (char*) destBuffer;
  200260. while (bytesRead < maxBytesToRead)
  200261. {
  200262. const int bytesThisTime = maxBytesToRead - bytesRead;
  200263. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200264. if (numRead <= 0 || intern->stopReadOperation)
  200265. {
  200266. bytesRead = -1;
  200267. break;
  200268. }
  200269. bytesRead += numRead;
  200270. p += bytesRead;
  200271. }
  200272. intern->blocked = false;
  200273. }
  200274. return bytesRead;
  200275. }
  200276. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200277. {
  200278. int bytesWritten = -1;
  200279. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200280. if (intern != 0)
  200281. {
  200282. if (intern->pipeOut == -1)
  200283. {
  200284. if (intern->createdPipe)
  200285. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200286. else
  200287. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200288. if (intern->pipeOut == -1)
  200289. {
  200290. return -1;
  200291. }
  200292. }
  200293. const char* p = (const char*) sourceBuffer;
  200294. bytesWritten = 0;
  200295. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200296. while (bytesWritten < numBytesToWrite
  200297. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200298. {
  200299. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200300. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200301. if (numWritten <= 0)
  200302. {
  200303. bytesWritten = -1;
  200304. break;
  200305. }
  200306. bytesWritten += numWritten;
  200307. p += bytesWritten;
  200308. }
  200309. }
  200310. return bytesWritten;
  200311. }
  200312. #endif
  200313. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200314. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200315. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200316. // compiled on its own).
  200317. #if JUCE_INCLUDED_FILE
  200318. void JUCE_API juce_threadEntryPoint (void*);
  200319. void* threadEntryProc (void* userData)
  200320. {
  200321. const ScopedAutoReleasePool pool;
  200322. juce_threadEntryPoint (userData);
  200323. return 0;
  200324. }
  200325. void* juce_createThread (void* userData)
  200326. {
  200327. pthread_t handle = 0;
  200328. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200329. {
  200330. pthread_detach (handle);
  200331. return (void*) handle;
  200332. }
  200333. return 0;
  200334. }
  200335. void juce_killThread (void* handle)
  200336. {
  200337. if (handle != 0)
  200338. pthread_cancel ((pthread_t) handle);
  200339. }
  200340. void juce_setCurrentThreadName (const String& /*name*/)
  200341. {
  200342. }
  200343. bool juce_setThreadPriority (void* handle, int priority)
  200344. {
  200345. if (handle == 0)
  200346. handle = (void*) pthread_self();
  200347. struct sched_param param;
  200348. int policy;
  200349. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200350. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200351. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200352. }
  200353. Thread::ThreadID Thread::getCurrentThreadId()
  200354. {
  200355. return static_cast <ThreadID> (pthread_self());
  200356. }
  200357. void Thread::yield()
  200358. {
  200359. sched_yield();
  200360. }
  200361. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200362. {
  200363. // xxx
  200364. jassertfalse
  200365. }
  200366. bool Process::isForegroundProcess()
  200367. {
  200368. #if JUCE_MAC
  200369. return [NSApp isActive];
  200370. #else
  200371. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200372. #endif
  200373. }
  200374. void Process::raisePrivilege()
  200375. {
  200376. jassertfalse
  200377. }
  200378. void Process::lowerPrivilege()
  200379. {
  200380. jassertfalse
  200381. }
  200382. void Process::terminate()
  200383. {
  200384. exit (0);
  200385. }
  200386. void Process::setPriority (ProcessPriority p)
  200387. {
  200388. // xxx
  200389. }
  200390. #endif
  200391. /*** End of inlined file: juce_mac_Threads.mm ***/
  200392. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200393. CriticalSection::CriticalSection() throw()
  200394. {
  200395. pthread_mutexattr_t atts;
  200396. pthread_mutexattr_init (&atts);
  200397. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200398. pthread_mutex_init (&internal, &atts);
  200399. }
  200400. CriticalSection::~CriticalSection() throw()
  200401. {
  200402. pthread_mutex_destroy (&internal);
  200403. }
  200404. void CriticalSection::enter() const throw()
  200405. {
  200406. pthread_mutex_lock (&internal);
  200407. }
  200408. bool CriticalSection::tryEnter() const throw()
  200409. {
  200410. return pthread_mutex_trylock (&internal) == 0;
  200411. }
  200412. void CriticalSection::exit() const throw()
  200413. {
  200414. pthread_mutex_unlock (&internal);
  200415. }
  200416. class WaitableEventImpl
  200417. {
  200418. public:
  200419. WaitableEventImpl (const bool manualReset_)
  200420. : triggered (false),
  200421. manualReset (manualReset_)
  200422. {
  200423. pthread_cond_init (&condition, 0);
  200424. pthread_mutex_init (&mutex, 0);
  200425. }
  200426. ~WaitableEventImpl()
  200427. {
  200428. pthread_cond_destroy (&condition);
  200429. pthread_mutex_destroy (&mutex);
  200430. }
  200431. bool wait (const int timeOutMillisecs) throw()
  200432. {
  200433. pthread_mutex_lock (&mutex);
  200434. if (! triggered)
  200435. {
  200436. if (timeOutMillisecs < 0)
  200437. {
  200438. do
  200439. {
  200440. pthread_cond_wait (&condition, &mutex);
  200441. }
  200442. while (! triggered);
  200443. }
  200444. else
  200445. {
  200446. struct timeval now;
  200447. gettimeofday (&now, 0);
  200448. struct timespec time;
  200449. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200450. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200451. if (time.tv_nsec >= 1000000000)
  200452. {
  200453. time.tv_nsec -= 1000000000;
  200454. time.tv_sec++;
  200455. }
  200456. do
  200457. {
  200458. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200459. {
  200460. pthread_mutex_unlock (&mutex);
  200461. return false;
  200462. }
  200463. }
  200464. while (! triggered);
  200465. }
  200466. }
  200467. if (! manualReset)
  200468. triggered = false;
  200469. pthread_mutex_unlock (&mutex);
  200470. return true;
  200471. }
  200472. void signal() throw()
  200473. {
  200474. pthread_mutex_lock (&mutex);
  200475. triggered = true;
  200476. pthread_cond_broadcast (&condition);
  200477. pthread_mutex_unlock (&mutex);
  200478. }
  200479. void reset() throw()
  200480. {
  200481. pthread_mutex_lock (&mutex);
  200482. triggered = false;
  200483. pthread_mutex_unlock (&mutex);
  200484. }
  200485. private:
  200486. pthread_cond_t condition;
  200487. pthread_mutex_t mutex;
  200488. bool triggered;
  200489. const bool manualReset;
  200490. WaitableEventImpl (const WaitableEventImpl&);
  200491. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200492. };
  200493. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  200494. : internal (new WaitableEventImpl (manualReset))
  200495. {
  200496. }
  200497. WaitableEvent::~WaitableEvent() throw()
  200498. {
  200499. delete static_cast <WaitableEventImpl*> (internal);
  200500. }
  200501. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200502. {
  200503. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200504. }
  200505. void WaitableEvent::signal() const throw()
  200506. {
  200507. static_cast <WaitableEventImpl*> (internal)->signal();
  200508. }
  200509. void WaitableEvent::reset() const throw()
  200510. {
  200511. static_cast <WaitableEventImpl*> (internal)->reset();
  200512. }
  200513. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200514. {
  200515. struct timespec time;
  200516. time.tv_sec = millisecs / 1000;
  200517. time.tv_nsec = (millisecs % 1000) * 1000000;
  200518. nanosleep (&time, 0);
  200519. }
  200520. const juce_wchar File::separator = '/';
  200521. const juce_wchar* File::separatorString = L"/";
  200522. const File File::getCurrentWorkingDirectory()
  200523. {
  200524. HeapBlock<char> heapBuffer;
  200525. char localBuffer [1024];
  200526. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200527. int bufferSize = 4096;
  200528. while (cwd == 0 && errno == ERANGE)
  200529. {
  200530. heapBuffer.malloc (bufferSize);
  200531. cwd = getcwd (heapBuffer, bufferSize - 1);
  200532. bufferSize += 1024;
  200533. }
  200534. return File (String::fromUTF8 (cwd));
  200535. }
  200536. bool File::setAsCurrentWorkingDirectory() const
  200537. {
  200538. return chdir (getFullPathName().toUTF8()) == 0;
  200539. }
  200540. bool juce_copyFile (const String& s, const String& d);
  200541. static bool juce_stat (const String& fileName, struct stat& info)
  200542. {
  200543. return fileName.isNotEmpty()
  200544. && (stat (fileName.toUTF8(), &info) == 0);
  200545. }
  200546. bool juce_isDirectory (const String& fileName)
  200547. {
  200548. struct stat info;
  200549. return fileName.isEmpty()
  200550. || (juce_stat (fileName, info)
  200551. && ((info.st_mode & S_IFDIR) != 0));
  200552. }
  200553. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200554. {
  200555. if (fileName.isEmpty())
  200556. return false;
  200557. const char* const fileNameUTF8 = fileName.toUTF8();
  200558. bool exists = access (fileNameUTF8, F_OK) == 0;
  200559. if (exists && dontCountDirectories)
  200560. {
  200561. struct stat info;
  200562. const int res = stat (fileNameUTF8, &info);
  200563. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200564. exists = false;
  200565. }
  200566. return exists;
  200567. }
  200568. int64 juce_getFileSize (const String& fileName)
  200569. {
  200570. struct stat info;
  200571. return juce_stat (fileName, info) ? info.st_size : 0;
  200572. }
  200573. bool juce_canWriteToFile (const String& fileName)
  200574. {
  200575. return access (fileName.toUTF8(), W_OK) == 0;
  200576. }
  200577. bool juce_deleteFile (const String& fileName)
  200578. {
  200579. if (juce_isDirectory (fileName))
  200580. return rmdir (fileName.toUTF8()) == 0;
  200581. else
  200582. return remove (fileName.toUTF8()) == 0;
  200583. }
  200584. bool juce_moveFile (const String& source, const String& dest)
  200585. {
  200586. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200587. return true;
  200588. if (juce_canWriteToFile (source)
  200589. && juce_copyFile (source, dest))
  200590. {
  200591. if (juce_deleteFile (source))
  200592. return true;
  200593. juce_deleteFile (dest);
  200594. }
  200595. return false;
  200596. }
  200597. void juce_createDirectory (const String& fileName)
  200598. {
  200599. mkdir (fileName.toUTF8(), 0777);
  200600. }
  200601. void* juce_fileOpen (const String& fileName, bool forWriting)
  200602. {
  200603. int flags = O_RDONLY;
  200604. if (forWriting)
  200605. {
  200606. if (juce_fileExists (fileName, false))
  200607. {
  200608. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  200609. if (f != -1)
  200610. lseek (f, 0, SEEK_END);
  200611. return (void*) f;
  200612. }
  200613. else
  200614. {
  200615. flags = O_RDWR + O_CREAT;
  200616. }
  200617. }
  200618. return (void*) open (fileName.toUTF8(), flags, 00644);
  200619. }
  200620. void juce_fileClose (void* handle)
  200621. {
  200622. if (handle != 0)
  200623. close ((int) (pointer_sized_int) handle);
  200624. }
  200625. int juce_fileRead (void* handle, void* buffer, int size)
  200626. {
  200627. if (handle != 0)
  200628. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  200629. return 0;
  200630. }
  200631. int juce_fileWrite (void* handle, const void* buffer, int size)
  200632. {
  200633. if (handle != 0)
  200634. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200635. return 0;
  200636. }
  200637. int64 juce_fileSetPosition (void* handle, int64 pos)
  200638. {
  200639. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200640. return pos;
  200641. return -1;
  200642. }
  200643. int64 juce_fileGetPosition (void* handle)
  200644. {
  200645. if (handle != 0)
  200646. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200647. return -1;
  200648. }
  200649. void juce_fileFlush (void* handle)
  200650. {
  200651. if (handle != 0)
  200652. fsync ((int) (pointer_sized_int) handle);
  200653. }
  200654. const File juce_getExecutableFile()
  200655. {
  200656. Dl_info exeInfo;
  200657. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200658. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  200659. }
  200660. // if this file doesn't exist, find a parent of it that does..
  200661. static bool doStatFS (const File* file, struct statfs& result)
  200662. {
  200663. File f (*file);
  200664. for (int i = 5; --i >= 0;)
  200665. {
  200666. if (f.exists())
  200667. break;
  200668. f = f.getParentDirectory();
  200669. }
  200670. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200671. }
  200672. int64 File::getBytesFreeOnVolume() const
  200673. {
  200674. struct statfs buf;
  200675. if (doStatFS (this, buf))
  200676. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200677. return 0;
  200678. }
  200679. int64 File::getVolumeTotalSize() const
  200680. {
  200681. struct statfs buf;
  200682. if (doStatFS (this, buf))
  200683. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200684. return 0;
  200685. }
  200686. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200687. int& volumeSerialNumber)
  200688. {
  200689. volumeSerialNumber = 0;
  200690. #if JUCE_MAC
  200691. struct VolAttrBuf
  200692. {
  200693. u_int32_t length;
  200694. attrreference_t mountPointRef;
  200695. char mountPointSpace [MAXPATHLEN];
  200696. } attrBuf;
  200697. struct attrlist attrList;
  200698. zerostruct (attrList);
  200699. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200700. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200701. File f (filenameOnVolume);
  200702. for (;;)
  200703. {
  200704. if (getattrlist (f.getFullPathName().toUTF8(),
  200705. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200706. {
  200707. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200708. (int) attrBuf.mountPointRef.attr_length);
  200709. }
  200710. const File parent (f.getParentDirectory());
  200711. if (f == parent)
  200712. break;
  200713. f = parent;
  200714. }
  200715. #endif
  200716. return String::empty;
  200717. }
  200718. void juce_runSystemCommand (const String& command)
  200719. {
  200720. int result = system (command.toUTF8());
  200721. (void) result;
  200722. }
  200723. const String juce_getOutputFromCommand (const String& command)
  200724. {
  200725. // slight bodge here, as we just pipe the output into a temp file and read it...
  200726. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200727. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200728. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200729. String result (tempFile.loadFileAsString());
  200730. tempFile.deleteFile();
  200731. return result;
  200732. }
  200733. class InterProcessLock::Pimpl
  200734. {
  200735. public:
  200736. Pimpl (const String& name, const int timeOutMillisecs)
  200737. : handle (0), refCount (1)
  200738. {
  200739. #if JUCE_MAC
  200740. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200741. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  200742. #else
  200743. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200744. #endif
  200745. temp.create();
  200746. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200747. if (handle != 0)
  200748. {
  200749. struct flock fl;
  200750. zerostruct (fl);
  200751. fl.l_whence = SEEK_SET;
  200752. fl.l_type = F_WRLCK;
  200753. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200754. for (;;)
  200755. {
  200756. const int result = fcntl (handle, F_SETLK, &fl);
  200757. if (result >= 0)
  200758. return;
  200759. if (errno != EINTR)
  200760. {
  200761. if (timeOutMillisecs == 0
  200762. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200763. break;
  200764. Thread::sleep (10);
  200765. }
  200766. }
  200767. }
  200768. closeFile();
  200769. }
  200770. ~Pimpl()
  200771. {
  200772. closeFile();
  200773. }
  200774. void closeFile()
  200775. {
  200776. if (handle != 0)
  200777. {
  200778. struct flock fl;
  200779. zerostruct (fl);
  200780. fl.l_whence = SEEK_SET;
  200781. fl.l_type = F_UNLCK;
  200782. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  200783. {}
  200784. close (handle);
  200785. handle = 0;
  200786. }
  200787. }
  200788. int handle, refCount;
  200789. };
  200790. InterProcessLock::InterProcessLock (const String& name_)
  200791. : name (name_)
  200792. {
  200793. }
  200794. InterProcessLock::~InterProcessLock()
  200795. {
  200796. }
  200797. bool InterProcessLock::enter (const int timeOutMillisecs)
  200798. {
  200799. const ScopedLock sl (lock);
  200800. if (pimpl == 0)
  200801. {
  200802. pimpl = new Pimpl (name, timeOutMillisecs);
  200803. if (pimpl->handle == 0)
  200804. pimpl = 0;
  200805. }
  200806. else
  200807. {
  200808. pimpl->refCount++;
  200809. }
  200810. return pimpl != 0;
  200811. }
  200812. void InterProcessLock::exit()
  200813. {
  200814. const ScopedLock sl (lock);
  200815. // Trying to release the lock too many times!
  200816. jassert (pimpl != 0);
  200817. if (pimpl != 0 && --(pimpl->refCount) == 0)
  200818. pimpl = 0;
  200819. }
  200820. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200821. /*** Start of inlined file: juce_mac_Files.mm ***/
  200822. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200823. // compiled on its own).
  200824. #if JUCE_INCLUDED_FILE
  200825. void juce_getFileTimes (const String& fileName,
  200826. int64& modificationTime,
  200827. int64& accessTime,
  200828. int64& creationTime)
  200829. {
  200830. modificationTime = 0;
  200831. accessTime = 0;
  200832. creationTime = 0;
  200833. struct stat info;
  200834. const int res = stat (fileName.toUTF8(), &info);
  200835. if (res == 0)
  200836. {
  200837. modificationTime = (int64) info.st_mtime * 1000;
  200838. accessTime = (int64) info.st_atime * 1000;
  200839. creationTime = (int64) info.st_ctime * 1000;
  200840. }
  200841. }
  200842. bool juce_setFileTimes (const String& fileName,
  200843. int64 modificationTime,
  200844. int64 accessTime,
  200845. int64 creationTime)
  200846. {
  200847. struct utimbuf times;
  200848. times.actime = (time_t) (accessTime / 1000);
  200849. times.modtime = (time_t) (modificationTime / 1000);
  200850. return utime (fileName.toUTF8(), &times) == 0;
  200851. }
  200852. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200853. {
  200854. struct stat info;
  200855. const int res = stat (fileName.toUTF8(), &info);
  200856. if (res != 0)
  200857. return false;
  200858. info.st_mode &= 0777; // Just permissions
  200859. if (isReadOnly)
  200860. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200861. else
  200862. // Give everybody write permission?
  200863. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200864. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  200865. }
  200866. bool juce_copyFile (const String& src, const String& dst)
  200867. {
  200868. const ScopedAutoReleasePool pool;
  200869. NSFileManager* fm = [NSFileManager defaultManager];
  200870. return [fm fileExistsAtPath: juceStringToNS (src)]
  200871. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  200872. && [fm copyItemAtPath: juceStringToNS (src)
  200873. toPath: juceStringToNS (dst)
  200874. error: nil];
  200875. #else
  200876. && [fm copyPath: juceStringToNS (src)
  200877. toPath: juceStringToNS (dst)
  200878. handler: nil];
  200879. #endif
  200880. }
  200881. const StringArray juce_getFileSystemRoots()
  200882. {
  200883. StringArray s;
  200884. s.add ("/");
  200885. return s;
  200886. }
  200887. static bool isFileOnDriveType (const File* const f, const char** types)
  200888. {
  200889. struct statfs buf;
  200890. if (doStatFS (f, buf))
  200891. {
  200892. const String type (buf.f_fstypename);
  200893. while (*types != 0)
  200894. if (type.equalsIgnoreCase (*types++))
  200895. return true;
  200896. }
  200897. return false;
  200898. }
  200899. bool File::isOnCDRomDrive() const
  200900. {
  200901. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  200902. return isFileOnDriveType (this, (const char**) cdTypes);
  200903. }
  200904. bool File::isOnHardDisk() const
  200905. {
  200906. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  200907. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  200908. }
  200909. bool File::isOnRemovableDrive() const
  200910. {
  200911. #if JUCE_IPHONE
  200912. return false; // xxx is this possible?
  200913. #else
  200914. const ScopedAutoReleasePool pool;
  200915. BOOL removable = false;
  200916. [[NSWorkspace sharedWorkspace]
  200917. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  200918. isRemovable: &removable
  200919. isWritable: nil
  200920. isUnmountable: nil
  200921. description: nil
  200922. type: nil];
  200923. return removable;
  200924. #endif
  200925. }
  200926. static bool juce_isHiddenFile (const String& path)
  200927. {
  200928. #if JUCE_IPHONE
  200929. return File (path).getFileName().startsWithChar ('.');
  200930. #else
  200931. FSRef ref;
  200932. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  200933. return false;
  200934. FSCatalogInfo info;
  200935. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  200936. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  200937. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200938. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200939. #endif
  200940. }
  200941. bool File::isHidden() const
  200942. {
  200943. return juce_isHiddenFile (getFullPathName());
  200944. }
  200945. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  200946. const File File::getSpecialLocation (const SpecialLocationType type)
  200947. {
  200948. const ScopedAutoReleasePool pool;
  200949. String resultPath;
  200950. switch (type)
  200951. {
  200952. case userHomeDirectory:
  200953. resultPath = nsStringToJuce (NSHomeDirectory());
  200954. break;
  200955. case userDocumentsDirectory:
  200956. resultPath = "~/Documents";
  200957. break;
  200958. case userDesktopDirectory:
  200959. resultPath = "~/Desktop";
  200960. break;
  200961. case userApplicationDataDirectory:
  200962. resultPath = "~/Library";
  200963. break;
  200964. case commonApplicationDataDirectory:
  200965. resultPath = "/Library";
  200966. break;
  200967. case globalApplicationsDirectory:
  200968. resultPath = "/Applications";
  200969. break;
  200970. case userMusicDirectory:
  200971. resultPath = "~/Music";
  200972. break;
  200973. case userMoviesDirectory:
  200974. resultPath = "~/Movies";
  200975. break;
  200976. case tempDirectory:
  200977. {
  200978. File tmp ("~/Library/Caches/" + juce_getExecutableFile().getFileNameWithoutExtension());
  200979. tmp.createDirectory();
  200980. return tmp.getFullPathName();
  200981. }
  200982. case invokedExecutableFile:
  200983. if (juce_Argv0 != 0)
  200984. return File (String::fromUTF8 (juce_Argv0));
  200985. // deliberate fall-through...
  200986. case currentExecutableFile:
  200987. return juce_getExecutableFile();
  200988. case currentApplicationFile:
  200989. {
  200990. const File exe (juce_getExecutableFile());
  200991. const File parent (exe.getParentDirectory());
  200992. return parent.getFullPathName().endsWithIgnoreCase ("Contents/MacOS")
  200993. ? parent.getParentDirectory().getParentDirectory()
  200994. : exe;
  200995. }
  200996. default:
  200997. jassertfalse // unknown type?
  200998. break;
  200999. }
  201000. if (resultPath.isNotEmpty())
  201001. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201002. return File::nonexistent;
  201003. }
  201004. const String File::getVersion() const
  201005. {
  201006. const ScopedAutoReleasePool pool;
  201007. String result;
  201008. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201009. if (bundle != 0)
  201010. {
  201011. NSDictionary* info = [bundle infoDictionary];
  201012. if (info != 0)
  201013. {
  201014. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201015. if (name != nil)
  201016. result = nsStringToJuce (name);
  201017. }
  201018. }
  201019. return result;
  201020. }
  201021. const File File::getLinkedTarget() const
  201022. {
  201023. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201024. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201025. #else
  201026. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201027. #endif
  201028. if (dest != nil)
  201029. return File (nsStringToJuce (dest));
  201030. return *this;
  201031. }
  201032. bool File::moveToTrash() const
  201033. {
  201034. if (! exists())
  201035. return true;
  201036. #if JUCE_IPHONE
  201037. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201038. #else
  201039. const ScopedAutoReleasePool pool;
  201040. NSString* p = juceStringToNS (getFullPathName());
  201041. return [[NSWorkspace sharedWorkspace]
  201042. performFileOperation: NSWorkspaceRecycleOperation
  201043. source: [p stringByDeletingLastPathComponent]
  201044. destination: @""
  201045. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201046. tag: nil ];
  201047. #endif
  201048. }
  201049. struct FindFileStruct
  201050. {
  201051. NSDirectoryEnumerator* enumerator;
  201052. String parentDir, wildCard;
  201053. };
  201054. bool juce_findFileNext (void* handle, String& resultFile,
  201055. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201056. {
  201057. ScopedAutoReleasePool pool;
  201058. FindFileStruct* ff = (FindFileStruct*) handle;
  201059. NSString* file;
  201060. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201061. for (;;)
  201062. {
  201063. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201064. return false;
  201065. [ff->enumerator skipDescendents];
  201066. resultFile = nsStringToJuce (file);
  201067. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201068. continue;
  201069. const String path (ff->parentDir + resultFile);
  201070. if (isDir != 0 || fileSize != 0)
  201071. {
  201072. struct stat info;
  201073. const bool statOk = juce_stat (path, info);
  201074. if (isDir != 0)
  201075. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201076. if (isHidden != 0)
  201077. *isHidden = juce_isHiddenFile (path);
  201078. if (fileSize != 0)
  201079. *fileSize = statOk ? info.st_size : 0;
  201080. }
  201081. if (modTime != 0 || creationTime != 0)
  201082. {
  201083. int64 m, a, c;
  201084. juce_getFileTimes (path, m, a, c);
  201085. if (modTime != 0)
  201086. *modTime = m;
  201087. if (creationTime != 0)
  201088. *creationTime = c;
  201089. }
  201090. if (isReadOnly != 0)
  201091. *isReadOnly = ! juce_canWriteToFile (path);
  201092. return true;
  201093. }
  201094. }
  201095. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201096. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201097. Time* creationTime, bool* isReadOnly)
  201098. {
  201099. ScopedAutoReleasePool pool;
  201100. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201101. if (e != 0)
  201102. {
  201103. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201104. ff->enumerator = [e retain];
  201105. ff->parentDir = directory;
  201106. ff->wildCard = wildCard;
  201107. if (! ff->parentDir.endsWithChar (File::separator))
  201108. ff->parentDir += File::separator;
  201109. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201110. return ff.release();
  201111. [e release];
  201112. }
  201113. return 0;
  201114. }
  201115. void juce_findFileClose (void* handle)
  201116. {
  201117. ScopedAutoReleasePool pool;
  201118. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201119. [ff->enumerator release];
  201120. }
  201121. bool juce_launchExecutable (const String& pathAndArguments)
  201122. {
  201123. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201124. const int cpid = fork();
  201125. if (cpid == 0)
  201126. {
  201127. // Child process
  201128. if (execve (argv[0], (char**) argv, 0) < 0)
  201129. exit (0);
  201130. }
  201131. else
  201132. {
  201133. if (cpid < 0)
  201134. return false;
  201135. }
  201136. return true;
  201137. }
  201138. bool juce_launchFile (const String& fileName, const String& parameters)
  201139. {
  201140. #if JUCE_IPHONE
  201141. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201142. #else
  201143. const ScopedAutoReleasePool pool;
  201144. if (parameters.isEmpty())
  201145. {
  201146. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201147. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201148. }
  201149. bool ok = false;
  201150. FSRef ref;
  201151. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201152. {
  201153. if (PlatformUtilities::isBundle (fileName))
  201154. {
  201155. NSMutableArray* urls = [NSMutableArray array];
  201156. StringArray docs;
  201157. docs.addTokens (parameters, true);
  201158. for (int i = 0; i < docs.size(); ++i)
  201159. [urls addObject: juceStringToNS (docs[i])];
  201160. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201161. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201162. options: 0
  201163. additionalEventParamDescriptor: nil
  201164. launchIdentifiers: nil];
  201165. }
  201166. else
  201167. {
  201168. ok = juce_launchExecutable ("\"" + fileName + "\" " + parameters);
  201169. }
  201170. }
  201171. return ok;
  201172. #endif
  201173. }
  201174. void File::revealToUser() const
  201175. {
  201176. #if ! JUCE_IPHONE
  201177. if (exists())
  201178. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201179. else if (getParentDirectory().exists())
  201180. getParentDirectory().revealToUser();
  201181. #endif
  201182. }
  201183. #if ! JUCE_IPHONE
  201184. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201185. {
  201186. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201187. }
  201188. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201189. {
  201190. char path [2048];
  201191. zerostruct (path);
  201192. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201193. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201194. return String::empty;
  201195. }
  201196. #endif
  201197. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201198. {
  201199. const ScopedAutoReleasePool pool;
  201200. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201201. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201202. #else
  201203. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201204. #endif
  201205. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201206. return [fileDict fileHFSTypeCode];
  201207. }
  201208. bool PlatformUtilities::isBundle (const String& filename)
  201209. {
  201210. #if JUCE_IPHONE
  201211. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201212. #else
  201213. const ScopedAutoReleasePool pool;
  201214. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201215. #endif
  201216. }
  201217. #endif
  201218. /*** End of inlined file: juce_mac_Files.mm ***/
  201219. #if JUCE_IPHONE
  201220. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201221. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201222. // compiled on its own).
  201223. #if JUCE_INCLUDED_FILE
  201224. static JUCEApplication* juce_intialisingApp;
  201225. END_JUCE_NAMESPACE
  201226. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201227. {
  201228. }
  201229. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201230. - (void) applicationWillResignActive: (UIApplication*) application;
  201231. @end
  201232. @implementation JuceAppStartupDelegate
  201233. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201234. {
  201235. String dummy;
  201236. if (! juce_intialisingApp->initialiseApp (dummy))
  201237. exit (0);
  201238. }
  201239. - (void) applicationWillResignActive: (UIApplication*) application
  201240. {
  201241. JUCEApplication::shutdownAppAndClearUp();
  201242. }
  201243. @end
  201244. BEGIN_JUCE_NAMESPACE
  201245. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201246. {
  201247. juce_intialisingApp = app;
  201248. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201249. }
  201250. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201251. {
  201252. pool = [[NSAutoreleasePool alloc] init];
  201253. }
  201254. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201255. {
  201256. [((NSAutoreleasePool*) pool) release];
  201257. }
  201258. void PlatformUtilities::beep()
  201259. {
  201260. //xxx
  201261. //AudioServicesPlaySystemSound ();
  201262. }
  201263. void PlatformUtilities::addItemToDock (const File& file)
  201264. {
  201265. }
  201266. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201267. END_JUCE_NAMESPACE
  201268. @interface JuceAlertBoxDelegate : NSObject
  201269. {
  201270. @public
  201271. bool clickedOk;
  201272. }
  201273. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201274. @end
  201275. @implementation JuceAlertBoxDelegate
  201276. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201277. {
  201278. clickedOk = (buttonIndex == 0);
  201279. alertView.hidden = true;
  201280. }
  201281. @end
  201282. BEGIN_JUCE_NAMESPACE
  201283. // (This function is used directly by other bits of code)
  201284. bool juce_iPhoneShowModalAlert (const String& title,
  201285. const String& bodyText,
  201286. NSString* okButtonText,
  201287. NSString* cancelButtonText)
  201288. {
  201289. const ScopedAutoReleasePool pool;
  201290. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201291. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201292. message: juceStringToNS (bodyText)
  201293. delegate: callback
  201294. cancelButtonTitle: okButtonText
  201295. otherButtonTitles: cancelButtonText, nil];
  201296. [alert retain];
  201297. [alert show];
  201298. while (! alert.hidden && alert.superview != nil)
  201299. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201300. const bool result = callback->clickedOk;
  201301. [alert release];
  201302. [callback release];
  201303. return result;
  201304. }
  201305. bool AlertWindow::showNativeDialogBox (const String& title,
  201306. const String& bodyText,
  201307. bool isOkCancel)
  201308. {
  201309. return juce_iPhoneShowModalAlert (title, bodyText,
  201310. @"OK",
  201311. isOkCancel ? @"Cancel" : nil);
  201312. }
  201313. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201314. {
  201315. jassertfalse // no such thing on the iphone!
  201316. return false;
  201317. }
  201318. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201319. {
  201320. jassertfalse // no such thing on the iphone!
  201321. return false;
  201322. }
  201323. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201324. {
  201325. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201326. }
  201327. bool Desktop::isScreenSaverEnabled() throw()
  201328. {
  201329. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201330. }
  201331. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201332. {
  201333. const ScopedAutoReleasePool pool;
  201334. monitorCoords.clear();
  201335. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201336. : [[UIScreen mainScreen] bounds];
  201337. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201338. (int) r.origin.y,
  201339. (int) r.size.width,
  201340. (int) r.size.height));
  201341. }
  201342. #endif
  201343. #endif
  201344. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201345. #else
  201346. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201347. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201348. // compiled on its own).
  201349. #if JUCE_INCLUDED_FILE
  201350. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201351. {
  201352. pool = [[NSAutoreleasePool alloc] init];
  201353. }
  201354. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201355. {
  201356. [((NSAutoreleasePool*) pool) release];
  201357. }
  201358. void PlatformUtilities::beep()
  201359. {
  201360. NSBeep();
  201361. }
  201362. void PlatformUtilities::addItemToDock (const File& file)
  201363. {
  201364. // check that it's not already there...
  201365. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201366. .containsIgnoreCase (file.getFullPathName()))
  201367. {
  201368. juce_runSystemCommand ("defaults write com.apple.dock persistent-apps -array-add \"<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>"
  201369. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201370. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201371. }
  201372. }
  201373. int PlatformUtilities::getOSXMinorVersionNumber()
  201374. {
  201375. SInt32 versionMinor = 0;
  201376. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201377. (void) err;
  201378. jassert (err == noErr);
  201379. return (int) versionMinor;
  201380. }
  201381. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201382. bool AlertWindow::showNativeDialogBox (const String& title,
  201383. const String& bodyText,
  201384. bool isOkCancel)
  201385. {
  201386. const ScopedAutoReleasePool pool;
  201387. return NSRunAlertPanel (juceStringToNS (title),
  201388. juceStringToNS (bodyText),
  201389. @"Ok",
  201390. isOkCancel ? @"Cancel" : nil,
  201391. nil) == NSAlertDefaultReturn;
  201392. }
  201393. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201394. {
  201395. if (files.size() == 0)
  201396. return false;
  201397. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201398. if (draggingSource == 0)
  201399. {
  201400. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201401. return false;
  201402. }
  201403. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201404. if (sourceComp == 0)
  201405. {
  201406. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201407. return false;
  201408. }
  201409. const ScopedAutoReleasePool pool;
  201410. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201411. if (view == 0)
  201412. return false;
  201413. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201414. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201415. owner: nil];
  201416. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201417. for (int i = 0; i < files.size(); ++i)
  201418. [filesArray addObject: juceStringToNS (files[i])];
  201419. [pboard setPropertyList: filesArray
  201420. forType: NSFilenamesPboardType];
  201421. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201422. fromView: nil];
  201423. dragPosition.x -= 16;
  201424. dragPosition.y -= 16;
  201425. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201426. at: dragPosition
  201427. offset: NSMakeSize (0, 0)
  201428. event: [[view window] currentEvent]
  201429. pasteboard: pboard
  201430. source: view
  201431. slideBack: YES];
  201432. return true;
  201433. }
  201434. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201435. {
  201436. jassertfalse // not implemented!
  201437. return false;
  201438. }
  201439. bool Desktop::canUseSemiTransparentWindows() throw()
  201440. {
  201441. return true;
  201442. }
  201443. const Point<int> Desktop::getMousePosition()
  201444. {
  201445. const ScopedAutoReleasePool pool;
  201446. const NSPoint p ([NSEvent mouseLocation]);
  201447. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201448. }
  201449. void Desktop::setMousePosition (const Point<int>& newPosition)
  201450. {
  201451. // this rubbish needs to be done around the warp call, to avoid causing a
  201452. // bizarre glitch..
  201453. CGAssociateMouseAndMouseCursorPosition (false);
  201454. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201455. CGAssociateMouseAndMouseCursorPosition (true);
  201456. }
  201457. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201458. class ScreenSaverDefeater : public Timer,
  201459. public DeletedAtShutdown
  201460. {
  201461. public:
  201462. ScreenSaverDefeater() throw()
  201463. {
  201464. startTimer (10000);
  201465. timerCallback();
  201466. }
  201467. ~ScreenSaverDefeater() {}
  201468. void timerCallback()
  201469. {
  201470. if (Process::isForegroundProcess())
  201471. UpdateSystemActivity (UsrActivity);
  201472. }
  201473. };
  201474. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201475. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201476. {
  201477. if (isEnabled)
  201478. {
  201479. deleteAndZero (screenSaverDefeater);
  201480. }
  201481. else if (screenSaverDefeater == 0)
  201482. {
  201483. screenSaverDefeater = new ScreenSaverDefeater();
  201484. }
  201485. }
  201486. bool Desktop::isScreenSaverEnabled() throw()
  201487. {
  201488. return screenSaverDefeater == 0;
  201489. }
  201490. #else
  201491. static IOPMAssertionID screenSaverDisablerID = 0;
  201492. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201493. {
  201494. if (isEnabled)
  201495. {
  201496. if (screenSaverDisablerID != 0)
  201497. {
  201498. IOPMAssertionRelease (screenSaverDisablerID);
  201499. screenSaverDisablerID = 0;
  201500. }
  201501. }
  201502. else
  201503. {
  201504. if (screenSaverDisablerID == 0)
  201505. {
  201506. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201507. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201508. CFSTR ("Juce"), &screenSaverDisablerID);
  201509. #else
  201510. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201511. &screenSaverDisablerID);
  201512. #endif
  201513. }
  201514. }
  201515. }
  201516. bool Desktop::isScreenSaverEnabled() throw()
  201517. {
  201518. return screenSaverDisablerID == 0;
  201519. }
  201520. #endif
  201521. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201522. {
  201523. const ScopedAutoReleasePool pool;
  201524. monitorCoords.clear();
  201525. NSArray* screens = [NSScreen screens];
  201526. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201527. for (unsigned int i = 0; i < [screens count]; ++i)
  201528. {
  201529. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201530. NSRect r = clipToWorkArea ? [s visibleFrame]
  201531. : [s frame];
  201532. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201533. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201534. (int) r.size.width,
  201535. (int) r.size.height));
  201536. }
  201537. jassert (monitorCoords.size() > 0);
  201538. }
  201539. #endif
  201540. #endif
  201541. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201542. #endif
  201543. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201544. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201545. // compiled on its own).
  201546. #if JUCE_INCLUDED_FILE
  201547. void Logger::outputDebugString (const String& text) throw()
  201548. {
  201549. std::cerr << text << std::endl;
  201550. }
  201551. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201552. {
  201553. static char testResult = 0;
  201554. if (testResult == 0)
  201555. {
  201556. struct kinfo_proc info;
  201557. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201558. size_t sz = sizeof (info);
  201559. sysctl (m, 4, &info, &sz, 0, 0);
  201560. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201561. }
  201562. return testResult > 0;
  201563. }
  201564. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201565. {
  201566. return juce_isRunningUnderDebugger();
  201567. }
  201568. #endif
  201569. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201570. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201571. #if JUCE_IPHONE
  201572. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201573. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201574. // compiled on its own).
  201575. #if JUCE_INCLUDED_FILE
  201576. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201577. #define SUPPORT_10_4_FONTS 1
  201578. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201579. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201580. #define SUPPORT_ONLY_10_4_FONTS 1
  201581. #endif
  201582. END_JUCE_NAMESPACE
  201583. @interface NSFont (PrivateHack)
  201584. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201585. @end
  201586. BEGIN_JUCE_NAMESPACE
  201587. #endif
  201588. class MacTypeface : public Typeface
  201589. {
  201590. public:
  201591. MacTypeface (const Font& font)
  201592. : Typeface (font.getTypefaceName())
  201593. {
  201594. const ScopedAutoReleasePool pool;
  201595. renderingTransform = CGAffineTransformIdentity;
  201596. bool needsItalicTransform = false;
  201597. #if JUCE_IPHONE
  201598. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201599. if (font.isItalic() || font.isBold())
  201600. {
  201601. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201602. for (NSString* i in familyFonts)
  201603. {
  201604. const String fn (nsStringToJuce (i));
  201605. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  201606. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  201607. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  201608. || afterDash.containsIgnoreCase ("italic")
  201609. || fn.endsWithIgnoreCase ("oblique")
  201610. || fn.endsWithIgnoreCase ("italic");
  201611. if (probablyBold == font.isBold()
  201612. && probablyItalic == font.isItalic())
  201613. {
  201614. fontName = i;
  201615. needsItalicTransform = false;
  201616. break;
  201617. }
  201618. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201619. {
  201620. fontName = i;
  201621. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201622. }
  201623. }
  201624. if (needsItalicTransform)
  201625. renderingTransform.c = 0.15f;
  201626. }
  201627. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201628. const int ascender = abs (CGFontGetAscent (fontRef));
  201629. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201630. ascent = ascender / totalHeight;
  201631. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201632. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201633. #else
  201634. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201635. if (font.isItalic())
  201636. {
  201637. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201638. toHaveTrait: NSItalicFontMask];
  201639. if (newFont == nsFont)
  201640. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201641. nsFont = newFont;
  201642. }
  201643. if (font.isBold())
  201644. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201645. [nsFont retain];
  201646. ascent = fabsf ((float) [nsFont ascender]);
  201647. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201648. ascent /= totalSize;
  201649. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201650. if (needsItalicTransform)
  201651. {
  201652. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201653. renderingTransform.c = 0.15f;
  201654. }
  201655. #if SUPPORT_ONLY_10_4_FONTS
  201656. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201657. if (atsFont == 0)
  201658. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201659. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201660. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201661. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201662. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201663. #else
  201664. #if SUPPORT_10_4_FONTS
  201665. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201666. {
  201667. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201668. if (atsFont == 0)
  201669. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201670. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201671. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201672. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201673. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201674. }
  201675. else
  201676. #endif
  201677. {
  201678. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201679. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201680. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201681. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201682. }
  201683. #endif
  201684. #endif
  201685. }
  201686. ~MacTypeface()
  201687. {
  201688. #if ! JUCE_IPHONE
  201689. [nsFont release];
  201690. #endif
  201691. if (fontRef != 0)
  201692. CGFontRelease (fontRef);
  201693. }
  201694. float getAscent() const
  201695. {
  201696. return ascent;
  201697. }
  201698. float getDescent() const
  201699. {
  201700. return 1.0f - ascent;
  201701. }
  201702. float getStringWidth (const String& text)
  201703. {
  201704. if (fontRef == 0 || text.isEmpty())
  201705. return 0;
  201706. const int length = text.length();
  201707. HeapBlock <CGGlyph> glyphs;
  201708. createGlyphsForString (text, length, glyphs);
  201709. float x = 0;
  201710. #if SUPPORT_ONLY_10_4_FONTS
  201711. HeapBlock <NSSize> advances (length);
  201712. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201713. for (int i = 0; i < length; ++i)
  201714. x += advances[i].width;
  201715. #else
  201716. #if SUPPORT_10_4_FONTS
  201717. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201718. {
  201719. HeapBlock <NSSize> advances (length);
  201720. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201721. for (int i = 0; i < length; ++i)
  201722. x += advances[i].width;
  201723. }
  201724. else
  201725. #endif
  201726. {
  201727. HeapBlock <int> advances (length);
  201728. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201729. for (int i = 0; i < length; ++i)
  201730. x += advances[i];
  201731. }
  201732. #endif
  201733. return x * unitsToHeightScaleFactor;
  201734. }
  201735. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201736. {
  201737. xOffsets.add (0);
  201738. if (fontRef == 0 || text.isEmpty())
  201739. return;
  201740. const int length = text.length();
  201741. HeapBlock <CGGlyph> glyphs;
  201742. createGlyphsForString (text, length, glyphs);
  201743. #if SUPPORT_ONLY_10_4_FONTS
  201744. HeapBlock <NSSize> advances (length);
  201745. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201746. int x = 0;
  201747. for (int i = 0; i < length; ++i)
  201748. {
  201749. x += advances[i].width;
  201750. xOffsets.add (x * unitsToHeightScaleFactor);
  201751. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201752. }
  201753. #else
  201754. #if SUPPORT_10_4_FONTS
  201755. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201756. {
  201757. HeapBlock <NSSize> advances (length);
  201758. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201759. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201760. float x = 0;
  201761. for (int i = 0; i < length; ++i)
  201762. {
  201763. x += advances[i].width;
  201764. xOffsets.add (x * unitsToHeightScaleFactor);
  201765. resultGlyphs.add (nsGlyphs[i]);
  201766. }
  201767. }
  201768. else
  201769. #endif
  201770. {
  201771. HeapBlock <int> advances (length);
  201772. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201773. {
  201774. int x = 0;
  201775. for (int i = 0; i < length; ++i)
  201776. {
  201777. x += advances [i];
  201778. xOffsets.add (x * unitsToHeightScaleFactor);
  201779. resultGlyphs.add (glyphs[i]);
  201780. }
  201781. }
  201782. }
  201783. #endif
  201784. }
  201785. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201786. {
  201787. #if JUCE_IPHONE
  201788. return false;
  201789. #else
  201790. if (nsFont == 0)
  201791. return false;
  201792. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201793. jassert (path.isEmpty());
  201794. const ScopedAutoReleasePool pool;
  201795. NSBezierPath* bez = [NSBezierPath bezierPath];
  201796. [bez moveToPoint: NSMakePoint (0, 0)];
  201797. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201798. inFont: nsFont];
  201799. for (int i = 0; i < [bez elementCount]; ++i)
  201800. {
  201801. NSPoint p[3];
  201802. switch ([bez elementAtIndex: i associatedPoints: p])
  201803. {
  201804. case NSMoveToBezierPathElement:
  201805. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201806. break;
  201807. case NSLineToBezierPathElement:
  201808. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201809. break;
  201810. case NSCurveToBezierPathElement:
  201811. path.cubicTo ((float) p[0].x, (float) -p[0].y, (float) p[1].x, (float) -p[1].y, (float) p[2].x, (float) -p[2].y);
  201812. break;
  201813. case NSClosePathBezierPathElement:
  201814. path.closeSubPath();
  201815. break;
  201816. default:
  201817. jassertfalse
  201818. break;
  201819. }
  201820. }
  201821. path.applyTransform (pathTransform);
  201822. return true;
  201823. #endif
  201824. }
  201825. juce_UseDebuggingNewOperator
  201826. CGFontRef fontRef;
  201827. float fontHeightToCGSizeFactor;
  201828. CGAffineTransform renderingTransform;
  201829. private:
  201830. float ascent, unitsToHeightScaleFactor;
  201831. #if JUCE_IPHONE
  201832. #else
  201833. NSFont* nsFont;
  201834. AffineTransform pathTransform;
  201835. #endif
  201836. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201837. {
  201838. #if SUPPORT_10_4_FONTS
  201839. #if ! SUPPORT_ONLY_10_4_FONTS
  201840. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201841. #endif
  201842. {
  201843. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201844. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201845. for (int i = 0; i < length; ++i)
  201846. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201847. return;
  201848. }
  201849. #endif
  201850. #if ! SUPPORT_ONLY_10_4_FONTS
  201851. if (charToGlyphMapper == 0)
  201852. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201853. glyphs.malloc (length);
  201854. for (int i = 0; i < length; ++i)
  201855. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201856. #endif
  201857. }
  201858. #if ! SUPPORT_ONLY_10_4_FONTS
  201859. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201860. class CharToGlyphMapper
  201861. {
  201862. public:
  201863. CharToGlyphMapper (CGFontRef fontRef)
  201864. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201865. idRangeOffset (0), glyphIndexes (0)
  201866. {
  201867. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  201868. if (cmapTable != 0)
  201869. {
  201870. const int numSubtables = getValue16 (cmapTable, 2);
  201871. for (int i = 0; i < numSubtables; ++i)
  201872. {
  201873. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  201874. {
  201875. const int offset = getValue32 (cmapTable, i * 8 + 8);
  201876. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  201877. {
  201878. const int length = getValue16 (cmapTable, offset + 2);
  201879. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  201880. segCount = segCountX2 / 2;
  201881. const int endCodeOffset = offset + 14;
  201882. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  201883. const int idDeltaOffset = startCodeOffset + segCountX2;
  201884. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  201885. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  201886. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  201887. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  201888. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  201889. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  201890. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  201891. }
  201892. break;
  201893. }
  201894. }
  201895. CFRelease (cmapTable);
  201896. }
  201897. }
  201898. ~CharToGlyphMapper()
  201899. {
  201900. if (endCode != 0)
  201901. {
  201902. CFRelease (endCode);
  201903. CFRelease (startCode);
  201904. CFRelease (idDelta);
  201905. CFRelease (idRangeOffset);
  201906. CFRelease (glyphIndexes);
  201907. }
  201908. }
  201909. int getGlyphForCharacter (const juce_wchar c) const
  201910. {
  201911. for (int i = 0; i < segCount; ++i)
  201912. {
  201913. if (getValue16 (endCode, i * 2) >= c)
  201914. {
  201915. const int start = getValue16 (startCode, i * 2);
  201916. if (start > c)
  201917. break;
  201918. const int delta = getValue16 (idDelta, i * 2);
  201919. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  201920. if (rangeOffset == 0)
  201921. return delta + c;
  201922. else
  201923. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  201924. }
  201925. }
  201926. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  201927. return jmax (-1, c - 29);
  201928. }
  201929. private:
  201930. int segCount;
  201931. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  201932. static uint16 getValue16 (CFDataRef data, const int index)
  201933. {
  201934. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  201935. }
  201936. static uint32 getValue32 (CFDataRef data, const int index)
  201937. {
  201938. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  201939. }
  201940. };
  201941. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  201942. #endif
  201943. MacTypeface (const MacTypeface&);
  201944. MacTypeface& operator= (const MacTypeface&);
  201945. };
  201946. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  201947. {
  201948. return new MacTypeface (font);
  201949. }
  201950. const StringArray Font::findAllTypefaceNames()
  201951. {
  201952. StringArray names;
  201953. const ScopedAutoReleasePool pool;
  201954. #if JUCE_IPHONE
  201955. NSArray* fonts = [UIFont familyNames];
  201956. #else
  201957. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  201958. #endif
  201959. for (unsigned int i = 0; i < [fonts count]; ++i)
  201960. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  201961. names.sort (true);
  201962. return names;
  201963. }
  201964. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  201965. {
  201966. #if JUCE_IPHONE
  201967. defaultSans = "Helvetica";
  201968. defaultSerif = "Times New Roman";
  201969. defaultFixed = "Courier New";
  201970. #else
  201971. defaultSans = "Lucida Grande";
  201972. defaultSerif = "Times New Roman";
  201973. defaultFixed = "Monaco";
  201974. #endif
  201975. }
  201976. #endif
  201977. /*** End of inlined file: juce_mac_Fonts.mm ***/
  201978. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  201979. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201980. // compiled on its own).
  201981. #if JUCE_INCLUDED_FILE
  201982. class CoreGraphicsImage : public Image
  201983. {
  201984. public:
  201985. CoreGraphicsImage (const PixelFormat format_,
  201986. const int imageWidth_,
  201987. const int imageHeight_,
  201988. const bool clearImage)
  201989. : Image (format_, imageWidth_, imageHeight_, clearImage)
  201990. {
  201991. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  201992. : CGColorSpaceCreateDeviceRGB();
  201993. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  201994. colourSpace, getCGImageFlags (*this));
  201995. CGColorSpaceRelease (colourSpace);
  201996. }
  201997. ~CoreGraphicsImage()
  201998. {
  201999. CGContextRelease (context);
  202000. }
  202001. LowLevelGraphicsContext* createLowLevelContext();
  202002. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202003. {
  202004. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202005. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202006. {
  202007. return CGBitmapContextCreateImage (nativeImage->context);
  202008. }
  202009. else
  202010. {
  202011. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202012. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202013. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202014. 8, srcData.pixelStride * 8, srcData.lineStride,
  202015. colourSpace, getCGImageFlags (juceImage), provider,
  202016. 0, true, kCGRenderingIntentDefault);
  202017. CGDataProviderRelease (provider);
  202018. return imageRef;
  202019. }
  202020. }
  202021. #if JUCE_MAC
  202022. static NSImage* createNSImage (const Image& image)
  202023. {
  202024. const ScopedAutoReleasePool pool;
  202025. NSImage* im = [[NSImage alloc] init];
  202026. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202027. [im lockFocus];
  202028. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202029. CGImageRef imageRef = createImage (image, false, colourSpace);
  202030. CGColorSpaceRelease (colourSpace);
  202031. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202032. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202033. CGImageRelease (imageRef);
  202034. [im unlockFocus];
  202035. return im;
  202036. }
  202037. #endif
  202038. CGContextRef context;
  202039. private:
  202040. static CGBitmapInfo getCGImageFlags (const Image& image)
  202041. {
  202042. #if JUCE_BIG_ENDIAN
  202043. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202044. #else
  202045. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202046. #endif
  202047. }
  202048. };
  202049. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202050. {
  202051. #if USE_COREGRAPHICS_RENDERING
  202052. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202053. #else
  202054. return new Image (format, imageWidth, imageHeight, clearImage);
  202055. #endif
  202056. }
  202057. class CoreGraphicsContext : public LowLevelGraphicsContext
  202058. {
  202059. public:
  202060. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202061. : context (context_),
  202062. flipHeight (flipHeight_),
  202063. state (new SavedState()),
  202064. numGradientLookupEntries (0)
  202065. {
  202066. CGContextRetain (context);
  202067. CGContextSaveGState(context);
  202068. CGContextSetShouldSmoothFonts (context, true);
  202069. CGContextSetShouldAntialias (context, true);
  202070. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202071. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202072. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202073. gradientCallbacks.version = 0;
  202074. gradientCallbacks.evaluate = gradientCallback;
  202075. gradientCallbacks.releaseInfo = 0;
  202076. setFont (Font());
  202077. }
  202078. ~CoreGraphicsContext()
  202079. {
  202080. CGContextRestoreGState (context);
  202081. CGContextRelease (context);
  202082. CGColorSpaceRelease (rgbColourSpace);
  202083. CGColorSpaceRelease (greyColourSpace);
  202084. }
  202085. bool isVectorDevice() const { return false; }
  202086. void setOrigin (int x, int y)
  202087. {
  202088. CGContextTranslateCTM (context, x, -y);
  202089. }
  202090. bool clipToRectangle (const Rectangle<int>& r)
  202091. {
  202092. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202093. return ! isClipEmpty();
  202094. }
  202095. bool clipToRectangleList (const RectangleList& clipRegion)
  202096. {
  202097. if (clipRegion.isEmpty())
  202098. {
  202099. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202100. return false;
  202101. }
  202102. else
  202103. {
  202104. const int numRects = clipRegion.getNumRectangles();
  202105. HeapBlock <CGRect> rects (numRects);
  202106. for (int i = 0; i < numRects; ++i)
  202107. {
  202108. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202109. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202110. }
  202111. CGContextClipToRects (context, rects, numRects);
  202112. return ! isClipEmpty();
  202113. }
  202114. }
  202115. void excludeClipRectangle (const Rectangle<int>& r)
  202116. {
  202117. RectangleList remaining (getClipBounds());
  202118. remaining.subtract (r);
  202119. clipToRectangleList (remaining);
  202120. }
  202121. void clipToPath (const Path& path, const AffineTransform& transform)
  202122. {
  202123. createPath (path, transform);
  202124. CGContextClip (context);
  202125. }
  202126. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202127. {
  202128. if (! transform.isSingularity())
  202129. {
  202130. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202131. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202132. flip();
  202133. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202134. applyTransform (t);
  202135. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202136. CGContextClipToMask (context, r, image);
  202137. applyTransform (t.inverted());
  202138. flip();
  202139. CGImageRelease (image);
  202140. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202141. }
  202142. }
  202143. bool clipRegionIntersects (const Rectangle<int>& r)
  202144. {
  202145. return getClipBounds().intersects (r);
  202146. }
  202147. const Rectangle<int> getClipBounds() const
  202148. {
  202149. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202150. return Rectangle<int> (roundToInt (bounds.origin.x),
  202151. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202152. roundToInt (bounds.size.width),
  202153. roundToInt (bounds.size.height));
  202154. }
  202155. bool isClipEmpty() const
  202156. {
  202157. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202158. }
  202159. void saveState()
  202160. {
  202161. CGContextSaveGState (context);
  202162. stateStack.add (new SavedState (*state));
  202163. }
  202164. void restoreState()
  202165. {
  202166. CGContextRestoreGState (context);
  202167. SavedState* const top = stateStack.getLast();
  202168. if (top != 0)
  202169. {
  202170. state = top;
  202171. stateStack.removeLast (1, false);
  202172. }
  202173. else
  202174. {
  202175. jassertfalse // trying to pop with an empty stack!
  202176. }
  202177. }
  202178. void setFill (const FillType& fillType)
  202179. {
  202180. state->fillType = fillType;
  202181. if (fillType.isColour())
  202182. {
  202183. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202184. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202185. CGContextSetAlpha (context, 1.0f);
  202186. }
  202187. }
  202188. void setOpacity (float newOpacity)
  202189. {
  202190. state->fillType.setOpacity (newOpacity);
  202191. setFill (state->fillType);
  202192. }
  202193. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202194. {
  202195. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202196. ? kCGInterpolationLow
  202197. : kCGInterpolationHigh);
  202198. }
  202199. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202200. {
  202201. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202202. if (replaceExistingContents)
  202203. {
  202204. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202205. CGContextClearRect (context, cgRect);
  202206. #else
  202207. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202208. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202209. CGContextClearRect (context, cgRect);
  202210. else
  202211. #endif
  202212. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202213. #endif
  202214. fillRect (r, false);
  202215. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202216. }
  202217. else
  202218. {
  202219. if (state->fillType.isColour())
  202220. {
  202221. CGContextFillRect (context, cgRect);
  202222. }
  202223. else if (state->fillType.isGradient())
  202224. {
  202225. CGContextSaveGState (context);
  202226. CGContextClipToRect (context, cgRect);
  202227. drawGradient();
  202228. CGContextRestoreGState (context);
  202229. }
  202230. else
  202231. {
  202232. CGContextSaveGState (context);
  202233. CGContextClipToRect (context, cgRect);
  202234. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202235. CGContextRestoreGState (context);
  202236. }
  202237. }
  202238. }
  202239. void fillPath (const Path& path, const AffineTransform& transform)
  202240. {
  202241. CGContextSaveGState (context);
  202242. if (state->fillType.isColour())
  202243. {
  202244. flip();
  202245. applyTransform (transform);
  202246. createPath (path);
  202247. if (path.isUsingNonZeroWinding())
  202248. CGContextFillPath (context);
  202249. else
  202250. CGContextEOFillPath (context);
  202251. }
  202252. else
  202253. {
  202254. createPath (path, transform);
  202255. if (path.isUsingNonZeroWinding())
  202256. CGContextClip (context);
  202257. else
  202258. CGContextEOClip (context);
  202259. if (state->fillType.isGradient())
  202260. drawGradient();
  202261. else
  202262. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202263. }
  202264. CGContextRestoreGState (context);
  202265. }
  202266. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202267. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202268. {
  202269. jassert (sourceImage.getBounds().contains (srcClip));
  202270. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202271. CGImageRef image = fullImage;
  202272. if (srcClip != sourceImage.getBounds())
  202273. {
  202274. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202275. srcClip.getWidth(), srcClip.getHeight()));
  202276. CGImageRelease (fullImage);
  202277. }
  202278. CGContextSaveGState (context);
  202279. CGContextSetAlpha (context, state->fillType.getOpacity());
  202280. flip();
  202281. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202282. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202283. if (fillEntireClipAsTiles)
  202284. {
  202285. #if JUCE_IPHONE
  202286. CGContextDrawTiledImage (context, imageRect, image);
  202287. #else
  202288. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202289. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202290. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202291. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202292. CGContextDrawTiledImage (context, imageRect, image);
  202293. else
  202294. #endif
  202295. {
  202296. // Fallback to manually doing a tiled fill on 10.4
  202297. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202298. const int iw = srcClip.getWidth();
  202299. const int ih = srcClip.getHeight();
  202300. int x = 0, y = 0;
  202301. while (x > clip.origin.x) x -= iw;
  202302. while (y > clip.origin.y) y -= ih;
  202303. const int right = (int) (clip.origin.x + clip.size.width);
  202304. const int bottom = (int) (clip.origin.y + clip.size.height);
  202305. while (y < bottom)
  202306. {
  202307. for (int x2 = x; x2 < right; x2 += iw)
  202308. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202309. y += ih;
  202310. }
  202311. }
  202312. #endif
  202313. }
  202314. else
  202315. {
  202316. CGContextDrawImage (context, imageRect, image);
  202317. }
  202318. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202319. CGContextRestoreGState (context);
  202320. }
  202321. void drawLine (double x1, double y1, double x2, double y2)
  202322. {
  202323. CGContextSetLineCap (context, kCGLineCapSquare);
  202324. CGContextSetLineWidth (context, 1.0f);
  202325. CGContextSetRGBStrokeColor (context,
  202326. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202327. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202328. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202329. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202330. CGContextStrokeLineSegments (context, line, 1);
  202331. }
  202332. void drawVerticalLine (const int x, double top, double bottom)
  202333. {
  202334. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202335. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202336. #else
  202337. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202338. // the x co-ord slightly to trick it..
  202339. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202340. #endif
  202341. }
  202342. void drawHorizontalLine (const int y, double left, double right)
  202343. {
  202344. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202345. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202346. #else
  202347. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202348. // the x co-ord slightly to trick it..
  202349. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202350. #endif
  202351. }
  202352. void setFont (const Font& newFont)
  202353. {
  202354. if (state->font != newFont)
  202355. {
  202356. state->fontRef = 0;
  202357. state->font = newFont;
  202358. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202359. if (mf != 0)
  202360. {
  202361. state->fontRef = mf->fontRef;
  202362. CGContextSetFont (context, state->fontRef);
  202363. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202364. state->fontTransform = mf->renderingTransform;
  202365. state->fontTransform.a *= state->font.getHorizontalScale();
  202366. CGContextSetTextMatrix (context, state->fontTransform);
  202367. }
  202368. }
  202369. }
  202370. const Font getFont()
  202371. {
  202372. return state->font;
  202373. }
  202374. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202375. {
  202376. if (state->fontRef != 0 && state->fillType.isColour())
  202377. {
  202378. if (transform.isOnlyTranslation())
  202379. {
  202380. CGGlyph g = glyphNumber;
  202381. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202382. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202383. }
  202384. else
  202385. {
  202386. CGContextSaveGState (context);
  202387. flip();
  202388. applyTransform (transform);
  202389. CGAffineTransform t = state->fontTransform;
  202390. t.d = -t.d;
  202391. CGContextSetTextMatrix (context, t);
  202392. CGGlyph g = glyphNumber;
  202393. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202394. CGContextSetTextMatrix (context, state->fontTransform);
  202395. CGContextRestoreGState (context);
  202396. }
  202397. }
  202398. else
  202399. {
  202400. Path p;
  202401. Font& f = state->font;
  202402. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202403. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202404. .followedBy (transform));
  202405. }
  202406. }
  202407. private:
  202408. CGContextRef context;
  202409. const CGFloat flipHeight;
  202410. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202411. CGFunctionCallbacks gradientCallbacks;
  202412. struct SavedState
  202413. {
  202414. SavedState()
  202415. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202416. {
  202417. }
  202418. SavedState (const SavedState& other)
  202419. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202420. fontTransform (other.fontTransform)
  202421. {
  202422. }
  202423. ~SavedState()
  202424. {
  202425. }
  202426. FillType fillType;
  202427. Font font;
  202428. CGFontRef fontRef;
  202429. CGAffineTransform fontTransform;
  202430. };
  202431. ScopedPointer <SavedState> state;
  202432. OwnedArray <SavedState> stateStack;
  202433. HeapBlock <PixelARGB> gradientLookupTable;
  202434. int numGradientLookupEntries;
  202435. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202436. {
  202437. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202438. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202439. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202440. colour.unpremultiply();
  202441. outData[0] = colour.getRed() / 255.0f;
  202442. outData[1] = colour.getGreen() / 255.0f;
  202443. outData[2] = colour.getBlue() / 255.0f;
  202444. outData[3] = colour.getAlpha() / 255.0f;
  202445. }
  202446. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202447. {
  202448. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202449. --numGradientLookupEntries;
  202450. CGShadingRef result = 0;
  202451. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  202452. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202453. if (gradient.isRadial)
  202454. {
  202455. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202456. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202457. function, true, true);
  202458. }
  202459. else
  202460. {
  202461. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202462. CGPointMake (gradient.x2, gradient.y2),
  202463. function, true, true);
  202464. }
  202465. CGFunctionRelease (function);
  202466. return result;
  202467. }
  202468. void drawGradient()
  202469. {
  202470. flip();
  202471. applyTransform (state->fillType.transform);
  202472. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202473. // you draw a gradient with high quality interp enabled).
  202474. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202475. CGContextSetAlpha (context, state->fillType.getOpacity());
  202476. CGContextDrawShading (context, shading);
  202477. CGShadingRelease (shading);
  202478. }
  202479. void createPath (const Path& path) const
  202480. {
  202481. CGContextBeginPath (context);
  202482. Path::Iterator i (path);
  202483. while (i.next())
  202484. {
  202485. switch (i.elementType)
  202486. {
  202487. case Path::Iterator::startNewSubPath:
  202488. CGContextMoveToPoint (context, i.x1, i.y1);
  202489. break;
  202490. case Path::Iterator::lineTo:
  202491. CGContextAddLineToPoint (context, i.x1, i.y1);
  202492. break;
  202493. case Path::Iterator::quadraticTo:
  202494. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202495. break;
  202496. case Path::Iterator::cubicTo:
  202497. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202498. break;
  202499. case Path::Iterator::closePath:
  202500. CGContextClosePath (context); break;
  202501. default:
  202502. jassertfalse
  202503. break;
  202504. }
  202505. }
  202506. }
  202507. void createPath (const Path& path, const AffineTransform& transform) const
  202508. {
  202509. CGContextBeginPath (context);
  202510. Path::Iterator i (path);
  202511. while (i.next())
  202512. {
  202513. switch (i.elementType)
  202514. {
  202515. case Path::Iterator::startNewSubPath:
  202516. transform.transformPoint (i.x1, i.y1);
  202517. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202518. break;
  202519. case Path::Iterator::lineTo:
  202520. transform.transformPoint (i.x1, i.y1);
  202521. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202522. break;
  202523. case Path::Iterator::quadraticTo:
  202524. transform.transformPoint (i.x1, i.y1);
  202525. transform.transformPoint (i.x2, i.y2);
  202526. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202527. break;
  202528. case Path::Iterator::cubicTo:
  202529. transform.transformPoint (i.x1, i.y1);
  202530. transform.transformPoint (i.x2, i.y2);
  202531. transform.transformPoint (i.x3, i.y3);
  202532. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202533. break;
  202534. case Path::Iterator::closePath:
  202535. CGContextClosePath (context); break;
  202536. default:
  202537. jassertfalse
  202538. break;
  202539. }
  202540. }
  202541. }
  202542. static Image* createAlphaChannelImage (const Image& im)
  202543. {
  202544. if (im.getFormat() == Image::SingleChannel)
  202545. return const_cast <Image*> (&im);
  202546. return im.createCopyOfAlphaChannel();
  202547. }
  202548. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202549. {
  202550. if (im.getFormat() != Image::SingleChannel)
  202551. delete alphaIm;
  202552. }
  202553. void flip() const
  202554. {
  202555. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202556. }
  202557. void applyTransform (const AffineTransform& transform) const
  202558. {
  202559. CGAffineTransform t;
  202560. t.a = transform.mat00;
  202561. t.b = transform.mat10;
  202562. t.c = transform.mat01;
  202563. t.d = transform.mat11;
  202564. t.tx = transform.mat02;
  202565. t.ty = transform.mat12;
  202566. CGContextConcatCTM (context, t);
  202567. }
  202568. CoreGraphicsContext (const CoreGraphicsContext&);
  202569. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202570. };
  202571. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202572. {
  202573. return new CoreGraphicsContext (context, imageHeight);
  202574. }
  202575. #endif
  202576. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202577. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202578. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202579. // compiled on its own).
  202580. #if JUCE_INCLUDED_FILE
  202581. class UIViewComponentPeer;
  202582. END_JUCE_NAMESPACE
  202583. #define JuceUIView MakeObjCClassName(JuceUIView)
  202584. @interface JuceUIView : UIView <UITextFieldDelegate>
  202585. {
  202586. @public
  202587. UIViewComponentPeer* owner;
  202588. UITextField *hiddenTextField;
  202589. }
  202590. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202591. - (void) dealloc;
  202592. - (void) drawRect: (CGRect) r;
  202593. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202594. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202595. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202596. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202597. - (BOOL) becomeFirstResponder;
  202598. - (BOOL) resignFirstResponder;
  202599. - (BOOL) canBecomeFirstResponder;
  202600. - (void) asyncRepaint: (id) rect;
  202601. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string;
  202602. - (BOOL) textFieldShouldClear: (UITextField*) textField;
  202603. - (BOOL) textFieldShouldReturn: (UITextField*) textField;
  202604. @end
  202605. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202606. @interface JuceUIWindow : UIWindow
  202607. {
  202608. @private
  202609. UIViewComponentPeer* owner;
  202610. bool isZooming;
  202611. }
  202612. - (void) setOwner: (UIViewComponentPeer*) owner;
  202613. - (void) becomeKeyWindow;
  202614. @end
  202615. BEGIN_JUCE_NAMESPACE
  202616. class UIViewComponentPeer : public ComponentPeer,
  202617. public FocusChangeListener
  202618. {
  202619. public:
  202620. UIViewComponentPeer (Component* const component,
  202621. const int windowStyleFlags,
  202622. UIView* viewToAttachTo);
  202623. ~UIViewComponentPeer();
  202624. void* getNativeHandle() const;
  202625. void setVisible (bool shouldBeVisible);
  202626. void setTitle (const String& title);
  202627. void setPosition (int x, int y);
  202628. void setSize (int w, int h);
  202629. void setBounds (int x, int y, int w, int h, bool isNowFullScreen);
  202630. const Rectangle<int> getBounds() const;
  202631. const Rectangle<int> getBounds (const bool global) const;
  202632. const Point<int> getScreenPosition() const;
  202633. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202634. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202635. void setMinimised (bool shouldBeMinimised);
  202636. bool isMinimised() const;
  202637. void setFullScreen (bool shouldBeFullScreen);
  202638. bool isFullScreen() const;
  202639. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202640. const BorderSize getFrameSize() const;
  202641. bool setAlwaysOnTop (bool alwaysOnTop);
  202642. void toFront (bool makeActiveWindow);
  202643. void toBehind (ComponentPeer* other);
  202644. void setIcon (const Image& newIcon);
  202645. virtual void drawRect (CGRect r);
  202646. virtual bool canBecomeKeyWindow();
  202647. virtual bool windowShouldClose();
  202648. virtual void redirectMovedOrResized();
  202649. virtual CGRect constrainRect (CGRect r);
  202650. virtual void viewFocusGain();
  202651. virtual void viewFocusLoss();
  202652. bool isFocused() const;
  202653. void grabFocus();
  202654. void textInputRequired (const Point<int>& position);
  202655. virtual BOOL textFieldReplaceCharacters (const Range<int>& range, const String& text);
  202656. virtual BOOL textFieldShouldClear();
  202657. virtual BOOL textFieldShouldReturn();
  202658. void updateHiddenTextContent (TextInputTarget* target);
  202659. void globalFocusChanged (Component*);
  202660. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202661. void repaint (int x, int y, int w, int h);
  202662. void performAnyPendingRepaintsNow();
  202663. juce_UseDebuggingNewOperator
  202664. UIWindow* window;
  202665. JuceUIView* view;
  202666. bool isSharedWindow, fullScreen, insideDrawRect;
  202667. static ModifierKeys currentModifiers;
  202668. static int64 getMouseTime (UIEvent* e)
  202669. {
  202670. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202671. + (int64) ([e timestamp] * 1000.0);
  202672. }
  202673. Array <UITouch*> currentTouches;
  202674. };
  202675. END_JUCE_NAMESPACE
  202676. @implementation JuceUIView
  202677. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202678. withFrame: (CGRect) frame
  202679. {
  202680. [super initWithFrame: frame];
  202681. owner = owner_;
  202682. hiddenTextField = [[UITextField alloc] initWithFrame: CGRectMake (0, 0, 0, 0)];
  202683. [self addSubview: hiddenTextField];
  202684. hiddenTextField.delegate = self;
  202685. return self;
  202686. }
  202687. - (void) dealloc
  202688. {
  202689. [hiddenTextField removeFromSuperview];
  202690. [hiddenTextField release];
  202691. [super dealloc];
  202692. }
  202693. - (void) drawRect: (CGRect) r
  202694. {
  202695. if (owner != 0)
  202696. owner->drawRect (r);
  202697. }
  202698. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  202699. {
  202700. return false;
  202701. }
  202702. ModifierKeys UIViewComponentPeer::currentModifiers;
  202703. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202704. {
  202705. return UIViewComponentPeer::currentModifiers;
  202706. }
  202707. void ModifierKeys::updateCurrentModifiers() throw()
  202708. {
  202709. currentModifiers = UIViewComponentPeer::currentModifiers;
  202710. }
  202711. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202712. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202713. {
  202714. if (owner != 0)
  202715. owner->handleTouches (event, true, false, false);
  202716. }
  202717. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202718. {
  202719. if (owner != 0)
  202720. owner->handleTouches (event, false, false, false);
  202721. }
  202722. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202723. {
  202724. if (owner != 0)
  202725. owner->handleTouches (event, false, true, false);
  202726. }
  202727. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202728. {
  202729. if (owner != 0)
  202730. owner->handleTouches (event, false, true, true);
  202731. [self touchesEnded: touches withEvent: event];
  202732. }
  202733. - (BOOL) becomeFirstResponder
  202734. {
  202735. if (owner != 0)
  202736. owner->viewFocusGain();
  202737. return true;
  202738. }
  202739. - (BOOL) resignFirstResponder
  202740. {
  202741. if (owner != 0)
  202742. owner->viewFocusLoss();
  202743. return true;
  202744. }
  202745. - (BOOL) canBecomeFirstResponder
  202746. {
  202747. return owner != 0 && owner->canBecomeKeyWindow();
  202748. }
  202749. - (void) asyncRepaint: (id) rect
  202750. {
  202751. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202752. [self setNeedsDisplayInRect: *r];
  202753. }
  202754. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) text
  202755. {
  202756. return owner->textFieldReplaceCharacters (Range<int> (range.location, range.location + range.length),
  202757. nsStringToJuce (text));
  202758. }
  202759. - (BOOL) textFieldShouldClear: (UITextField*) textField
  202760. {
  202761. return owner->textFieldShouldClear();
  202762. }
  202763. - (BOOL) textFieldShouldReturn: (UITextField*) textField
  202764. {
  202765. return owner->textFieldShouldReturn();
  202766. }
  202767. @end
  202768. @implementation JuceUIWindow
  202769. - (void) setOwner: (UIViewComponentPeer*) owner_
  202770. {
  202771. owner = owner_;
  202772. isZooming = false;
  202773. }
  202774. - (void) becomeKeyWindow
  202775. {
  202776. [super becomeKeyWindow];
  202777. if (owner != 0)
  202778. owner->grabFocus();
  202779. }
  202780. @end
  202781. BEGIN_JUCE_NAMESPACE
  202782. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202783. const int windowStyleFlags,
  202784. UIView* viewToAttachTo)
  202785. : ComponentPeer (component, windowStyleFlags),
  202786. window (0),
  202787. view (0),
  202788. isSharedWindow (viewToAttachTo != 0),
  202789. fullScreen (false),
  202790. insideDrawRect (false)
  202791. {
  202792. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202793. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202794. if (isSharedWindow)
  202795. {
  202796. window = [viewToAttachTo window];
  202797. [viewToAttachTo addSubview: view];
  202798. setVisible (component->isVisible());
  202799. }
  202800. else
  202801. {
  202802. r.origin.x = (float) component->getX();
  202803. r.origin.y = (float) component->getY();
  202804. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202805. window = [[JuceUIWindow alloc] init];
  202806. window.frame = r;
  202807. window.opaque = component->isOpaque();
  202808. view.opaque = component->isOpaque();
  202809. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202810. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202811. [((JuceUIWindow*) window) setOwner: this];
  202812. if (component->isAlwaysOnTop())
  202813. window.windowLevel = UIWindowLevelAlert;
  202814. [window addSubview: view];
  202815. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202816. view.hidden = ! component->isVisible();
  202817. window.hidden = ! component->isVisible();
  202818. view.multipleTouchEnabled = YES;
  202819. }
  202820. setTitle (component->getName());
  202821. Desktop::getInstance().addFocusChangeListener (this);
  202822. }
  202823. UIViewComponentPeer::~UIViewComponentPeer()
  202824. {
  202825. Desktop::getInstance().removeFocusChangeListener (this);
  202826. view->owner = 0;
  202827. [view removeFromSuperview];
  202828. [view release];
  202829. if (! isSharedWindow)
  202830. {
  202831. [((JuceUIWindow*) window) setOwner: 0];
  202832. [window release];
  202833. }
  202834. }
  202835. void* UIViewComponentPeer::getNativeHandle() const
  202836. {
  202837. return view;
  202838. }
  202839. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202840. {
  202841. view.hidden = ! shouldBeVisible;
  202842. if (! isSharedWindow)
  202843. window.hidden = ! shouldBeVisible;
  202844. }
  202845. void UIViewComponentPeer::setTitle (const String& title)
  202846. {
  202847. // xxx is this possible?
  202848. }
  202849. void UIViewComponentPeer::setPosition (int x, int y)
  202850. {
  202851. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202852. }
  202853. void UIViewComponentPeer::setSize (int w, int h)
  202854. {
  202855. setBounds (component->getX(), component->getY(), w, h, false);
  202856. }
  202857. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202858. {
  202859. fullScreen = isNowFullScreen;
  202860. w = jmax (0, w);
  202861. h = jmax (0, h);
  202862. CGRect r;
  202863. r.origin.x = (float) x;
  202864. r.origin.y = (float) y;
  202865. r.size.width = (float) w;
  202866. r.size.height = (float) h;
  202867. if (isSharedWindow)
  202868. {
  202869. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202870. if ([view frame].size.width != r.size.width
  202871. || [view frame].size.height != r.size.height)
  202872. [view setNeedsDisplay];
  202873. view.frame = r;
  202874. }
  202875. else
  202876. {
  202877. window.frame = r;
  202878. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202879. }
  202880. }
  202881. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202882. {
  202883. CGRect r = [view frame];
  202884. if (global && [view window] != 0)
  202885. {
  202886. r = [view convertRect: r toView: nil];
  202887. CGRect wr = [[view window] frame];
  202888. r.origin.x += wr.origin.x;
  202889. r.origin.y += wr.origin.y;
  202890. }
  202891. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  202892. (int) r.size.width, (int) r.size.height);
  202893. }
  202894. const Rectangle<int> UIViewComponentPeer::getBounds() const
  202895. {
  202896. return getBounds (! isSharedWindow);
  202897. }
  202898. const Point<int> UIViewComponentPeer::getScreenPosition() const
  202899. {
  202900. return getBounds (true).getPosition();
  202901. }
  202902. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  202903. {
  202904. return relativePosition + getScreenPosition();
  202905. }
  202906. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  202907. {
  202908. return screenPosition - getScreenPosition();
  202909. }
  202910. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  202911. {
  202912. if (constrainer != 0)
  202913. {
  202914. CGRect current = [window frame];
  202915. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  202916. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  202917. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  202918. (int) r.size.width, (int) r.size.height);
  202919. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  202920. (int) current.size.width, (int) current.size.height);
  202921. constrainer->checkBounds (pos, original,
  202922. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  202923. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  202924. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  202925. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  202926. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  202927. r.origin.x = pos.getX();
  202928. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  202929. r.size.width = pos.getWidth();
  202930. r.size.height = pos.getHeight();
  202931. }
  202932. return r;
  202933. }
  202934. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  202935. {
  202936. // xxx
  202937. }
  202938. bool UIViewComponentPeer::isMinimised() const
  202939. {
  202940. return false;
  202941. }
  202942. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  202943. {
  202944. if (! isSharedWindow)
  202945. {
  202946. Rectangle<int> r (lastNonFullscreenBounds);
  202947. setMinimised (false);
  202948. if (fullScreen != shouldBeFullScreen)
  202949. {
  202950. if (shouldBeFullScreen)
  202951. r = Desktop::getInstance().getMainMonitorArea();
  202952. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  202953. if (r != getComponent()->getBounds() && ! r.isEmpty())
  202954. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  202955. }
  202956. }
  202957. }
  202958. bool UIViewComponentPeer::isFullScreen() const
  202959. {
  202960. return fullScreen;
  202961. }
  202962. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  202963. {
  202964. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  202965. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  202966. return false;
  202967. CGPoint p;
  202968. p.x = (float) position.getX();
  202969. p.y = (float) position.getY();
  202970. UIView* v = [view hitTest: p withEvent: nil];
  202971. if (trueIfInAChildWindow)
  202972. return v != nil;
  202973. return v == view;
  202974. }
  202975. const BorderSize UIViewComponentPeer::getFrameSize() const
  202976. {
  202977. BorderSize b;
  202978. if (! isSharedWindow)
  202979. {
  202980. CGRect v = [view convertRect: [view frame] toView: nil];
  202981. CGRect w = [window frame];
  202982. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  202983. b.setBottom ((int) v.origin.y);
  202984. b.setLeft ((int) v.origin.x);
  202985. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  202986. }
  202987. return b;
  202988. }
  202989. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  202990. {
  202991. if (! isSharedWindow)
  202992. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  202993. return true;
  202994. }
  202995. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  202996. {
  202997. if (isSharedWindow)
  202998. [[view superview] bringSubviewToFront: view];
  202999. if (window != 0 && component->isVisible())
  203000. [window makeKeyAndVisible];
  203001. }
  203002. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203003. {
  203004. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203005. if (isSharedWindow)
  203006. {
  203007. [[view superview] insertSubview: view belowSubview: o->view];
  203008. }
  203009. else
  203010. {
  203011. jassertfalse // don't know how to do this
  203012. }
  203013. }
  203014. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203015. {
  203016. // to do..
  203017. }
  203018. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203019. {
  203020. NSArray* touches = [[event touchesForView: view] allObjects];
  203021. for (unsigned int i = 0; i < [touches count]; ++i)
  203022. {
  203023. UITouch* touch = [touches objectAtIndex: i];
  203024. CGPoint p = [touch locationInView: view];
  203025. const Point<int> pos ((int) p.x, (int) p.y);
  203026. juce_lastMousePos = pos + getScreenPosition();
  203027. const int64 time = getMouseTime (event);
  203028. int touchIndex = currentTouches.indexOf (touch);
  203029. if (touchIndex < 0)
  203030. {
  203031. touchIndex = currentTouches.size();
  203032. currentTouches.add (touch);
  203033. }
  203034. if (isDown)
  203035. {
  203036. currentModifiers = currentModifiers.withoutMouseButtons();
  203037. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203038. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203039. }
  203040. else if (isUp)
  203041. {
  203042. currentModifiers = currentModifiers.withoutMouseButtons();
  203043. currentTouches.remove (touchIndex);
  203044. }
  203045. if (isCancel)
  203046. currentTouches.clear();
  203047. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203048. }
  203049. }
  203050. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203051. void UIViewComponentPeer::viewFocusGain()
  203052. {
  203053. if (currentlyFocusedPeer != this)
  203054. {
  203055. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203056. currentlyFocusedPeer->handleFocusLoss();
  203057. currentlyFocusedPeer = this;
  203058. handleFocusGain();
  203059. }
  203060. }
  203061. void UIViewComponentPeer::viewFocusLoss()
  203062. {
  203063. if (currentlyFocusedPeer == this)
  203064. {
  203065. currentlyFocusedPeer = 0;
  203066. handleFocusLoss();
  203067. }
  203068. }
  203069. void juce_HandleProcessFocusChange()
  203070. {
  203071. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203072. {
  203073. if (Process::isForegroundProcess())
  203074. {
  203075. currentlyFocusedPeer->handleFocusGain();
  203076. ComponentPeer::bringModalComponentToFront();
  203077. }
  203078. else
  203079. {
  203080. currentlyFocusedPeer->handleFocusLoss();
  203081. // turn kiosk mode off if we lose focus..
  203082. Desktop::getInstance().setKioskModeComponent (0);
  203083. }
  203084. }
  203085. }
  203086. bool UIViewComponentPeer::isFocused() const
  203087. {
  203088. return isSharedWindow ? this == currentlyFocusedPeer
  203089. : (window != 0 && [window isKeyWindow]);
  203090. }
  203091. void UIViewComponentPeer::grabFocus()
  203092. {
  203093. if (window != 0)
  203094. {
  203095. [window makeKeyWindow];
  203096. viewFocusGain();
  203097. }
  203098. }
  203099. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203100. {
  203101. }
  203102. void UIViewComponentPeer::updateHiddenTextContent (TextInputTarget* target)
  203103. {
  203104. view->hiddenTextField.text = juceStringToNS (target->getTextInRange (Range<int> (0, target->getHighlightedRegion().getStart())));
  203105. }
  203106. BOOL UIViewComponentPeer::textFieldReplaceCharacters (const Range<int>& range, const String& text)
  203107. {
  203108. TextInputTarget* const target = findCurrentTextInputTarget();
  203109. if (target != 0)
  203110. {
  203111. const Range<int> currentSelection (target->getHighlightedRegion());
  203112. if (range.getLength() == 1 && text.isEmpty()) // (detect backspace)
  203113. if (currentSelection.isEmpty())
  203114. target->setHighlightedRegion (currentSelection.withStart (currentSelection.getStart() - 1));
  203115. target->insertTextAtCaret (text);
  203116. updateHiddenTextContent (target);
  203117. }
  203118. return NO;
  203119. }
  203120. BOOL UIViewComponentPeer::textFieldShouldClear()
  203121. {
  203122. TextInputTarget* const target = findCurrentTextInputTarget();
  203123. if (target != 0)
  203124. {
  203125. target->setHighlightedRegion (Range<int> (0, std::numeric_limits<int>::max()));
  203126. target->insertTextAtCaret (String::empty);
  203127. updateHiddenTextContent (target);
  203128. }
  203129. return YES;
  203130. }
  203131. BOOL UIViewComponentPeer::textFieldShouldReturn()
  203132. {
  203133. TextInputTarget* const target = findCurrentTextInputTarget();
  203134. if (target != 0)
  203135. {
  203136. target->insertTextAtCaret ("\n");
  203137. updateHiddenTextContent (target);
  203138. }
  203139. return YES;
  203140. }
  203141. void UIViewComponentPeer::globalFocusChanged (Component*)
  203142. {
  203143. TextInputTarget* const target = findCurrentTextInputTarget();
  203144. if (target != 0)
  203145. {
  203146. Component* comp = dynamic_cast<Component*> (target);
  203147. Point<int> pos (comp->relativePositionToOtherComponent (component, Point<int>()));
  203148. view->hiddenTextField.frame = CGRectMake (pos.getX(), pos.getY(), 0, 0);
  203149. updateHiddenTextContent (target);
  203150. [view->hiddenTextField becomeFirstResponder];
  203151. }
  203152. else
  203153. {
  203154. [view->hiddenTextField resignFirstResponder];
  203155. }
  203156. }
  203157. void UIViewComponentPeer::drawRect (CGRect r)
  203158. {
  203159. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203160. return;
  203161. CGContextRef cg = UIGraphicsGetCurrentContext();
  203162. if (! component->isOpaque())
  203163. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203164. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203165. CoreGraphicsContext g (cg, view.bounds.size.height);
  203166. insideDrawRect = true;
  203167. handlePaint (g);
  203168. insideDrawRect = false;
  203169. }
  203170. bool UIViewComponentPeer::canBecomeKeyWindow()
  203171. {
  203172. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203173. }
  203174. bool UIViewComponentPeer::windowShouldClose()
  203175. {
  203176. if (! isValidPeer (this))
  203177. return YES;
  203178. handleUserClosingWindow();
  203179. return NO;
  203180. }
  203181. void UIViewComponentPeer::redirectMovedOrResized()
  203182. {
  203183. handleMovedOrResized();
  203184. }
  203185. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203186. {
  203187. }
  203188. class AsyncRepaintMessage : public CallbackMessage
  203189. {
  203190. public:
  203191. UIViewComponentPeer* const peer;
  203192. const Rectangle<int> rect;
  203193. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203194. : peer (peer_), rect (rect_)
  203195. {
  203196. }
  203197. void messageCallback()
  203198. {
  203199. if (ComponentPeer::isValidPeer (peer))
  203200. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203201. }
  203202. };
  203203. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203204. {
  203205. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203206. {
  203207. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203208. }
  203209. else
  203210. {
  203211. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203212. }
  203213. }
  203214. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203215. {
  203216. }
  203217. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203218. {
  203219. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203220. }
  203221. Image* juce_createIconForFile (const File& file)
  203222. {
  203223. return 0;
  203224. }
  203225. void Desktop::createMouseInputSources()
  203226. {
  203227. for (int i = 0; i < 10; ++i)
  203228. mouseSources.add (new MouseInputSource (i, false));
  203229. }
  203230. bool Desktop::canUseSemiTransparentWindows() throw()
  203231. {
  203232. return true;
  203233. }
  203234. const Point<int> Desktop::getMousePosition()
  203235. {
  203236. return juce_lastMousePos;
  203237. }
  203238. void Desktop::setMousePosition (const Point<int>&)
  203239. {
  203240. }
  203241. const int KeyPress::spaceKey = ' ';
  203242. const int KeyPress::returnKey = 0x0d;
  203243. const int KeyPress::escapeKey = 0x1b;
  203244. const int KeyPress::backspaceKey = 0x7f;
  203245. const int KeyPress::leftKey = 0x1000;
  203246. const int KeyPress::rightKey = 0x1001;
  203247. const int KeyPress::upKey = 0x1002;
  203248. const int KeyPress::downKey = 0x1003;
  203249. const int KeyPress::pageUpKey = 0x1004;
  203250. const int KeyPress::pageDownKey = 0x1005;
  203251. const int KeyPress::endKey = 0x1006;
  203252. const int KeyPress::homeKey = 0x1007;
  203253. const int KeyPress::deleteKey = 0x1008;
  203254. const int KeyPress::insertKey = -1;
  203255. const int KeyPress::tabKey = 9;
  203256. const int KeyPress::F1Key = 0x2001;
  203257. const int KeyPress::F2Key = 0x2002;
  203258. const int KeyPress::F3Key = 0x2003;
  203259. const int KeyPress::F4Key = 0x2004;
  203260. const int KeyPress::F5Key = 0x2005;
  203261. const int KeyPress::F6Key = 0x2006;
  203262. const int KeyPress::F7Key = 0x2007;
  203263. const int KeyPress::F8Key = 0x2008;
  203264. const int KeyPress::F9Key = 0x2009;
  203265. const int KeyPress::F10Key = 0x200a;
  203266. const int KeyPress::F11Key = 0x200b;
  203267. const int KeyPress::F12Key = 0x200c;
  203268. const int KeyPress::F13Key = 0x200d;
  203269. const int KeyPress::F14Key = 0x200e;
  203270. const int KeyPress::F15Key = 0x200f;
  203271. const int KeyPress::F16Key = 0x2010;
  203272. const int KeyPress::numberPad0 = 0x30020;
  203273. const int KeyPress::numberPad1 = 0x30021;
  203274. const int KeyPress::numberPad2 = 0x30022;
  203275. const int KeyPress::numberPad3 = 0x30023;
  203276. const int KeyPress::numberPad4 = 0x30024;
  203277. const int KeyPress::numberPad5 = 0x30025;
  203278. const int KeyPress::numberPad6 = 0x30026;
  203279. const int KeyPress::numberPad7 = 0x30027;
  203280. const int KeyPress::numberPad8 = 0x30028;
  203281. const int KeyPress::numberPad9 = 0x30029;
  203282. const int KeyPress::numberPadAdd = 0x3002a;
  203283. const int KeyPress::numberPadSubtract = 0x3002b;
  203284. const int KeyPress::numberPadMultiply = 0x3002c;
  203285. const int KeyPress::numberPadDivide = 0x3002d;
  203286. const int KeyPress::numberPadSeparator = 0x3002e;
  203287. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203288. const int KeyPress::numberPadEquals = 0x30030;
  203289. const int KeyPress::numberPadDelete = 0x30031;
  203290. const int KeyPress::playKey = 0x30000;
  203291. const int KeyPress::stopKey = 0x30001;
  203292. const int KeyPress::fastForwardKey = 0x30002;
  203293. const int KeyPress::rewindKey = 0x30003;
  203294. #endif
  203295. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203296. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203297. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203298. // compiled on its own).
  203299. #if JUCE_INCLUDED_FILE
  203300. struct CallbackMessagePayload
  203301. {
  203302. MessageCallbackFunction* function;
  203303. void* parameter;
  203304. void* volatile result;
  203305. bool volatile hasBeenExecuted;
  203306. };
  203307. END_JUCE_NAMESPACE
  203308. using namespace JUCE_NAMESPACE;
  203309. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203310. {
  203311. }
  203312. - (JuceAppDelegate*) init;
  203313. - (void) dealloc;
  203314. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203315. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203316. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203317. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203318. - (void) customEvent: (id) data;
  203319. - (void) performCallback: (id) info;
  203320. @end
  203321. @implementation JuceAppDelegate
  203322. - (JuceAppDelegate*) init
  203323. {
  203324. [super init];
  203325. [[UIApplication sharedApplication] setDelegate: self];
  203326. return self;
  203327. }
  203328. - (void) dealloc
  203329. {
  203330. [[UIApplication sharedApplication] setDelegate: nil];
  203331. [super dealloc];
  203332. }
  203333. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203334. {
  203335. if (JUCEApplication::getInstance() != 0)
  203336. {
  203337. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203338. return YES;
  203339. }
  203340. return NO;
  203341. }
  203342. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203343. {
  203344. juce_HandleProcessFocusChange();
  203345. }
  203346. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203347. {
  203348. juce_HandleProcessFocusChange();
  203349. }
  203350. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203351. {
  203352. juce_HandleProcessFocusChange();
  203353. }
  203354. - (void) customEvent: (id) n
  203355. {
  203356. NSData* data = (NSData*) n;
  203357. void* message = 0;
  203358. [data getBytes: &message length: sizeof (message)];
  203359. [data release];
  203360. if (message != 0)
  203361. MessageManager::getInstance()->deliverMessage (message);
  203362. }
  203363. - (void) performCallback: (id) info
  203364. {
  203365. if ([info isKindOfClass: [NSData class]])
  203366. {
  203367. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203368. if (pl != 0)
  203369. {
  203370. pl->result = (*pl->function) (pl->parameter);
  203371. pl->hasBeenExecuted = true;
  203372. }
  203373. }
  203374. else
  203375. {
  203376. jassertfalse // should never get here!
  203377. }
  203378. }
  203379. @end
  203380. BEGIN_JUCE_NAMESPACE
  203381. static JuceAppDelegate* juceAppDelegate = 0;
  203382. void MessageManager::runDispatchLoop()
  203383. {
  203384. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203385. runDispatchLoopUntil (-1);
  203386. }
  203387. void MessageManager::stopDispatchLoop()
  203388. {
  203389. exit (0); // iPhone apps get no mercy..
  203390. }
  203391. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203392. {
  203393. const ScopedAutoReleasePool pool;
  203394. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203395. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203396. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203397. while (! quitMessagePosted)
  203398. {
  203399. const ScopedAutoReleasePool pool;
  203400. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203401. beforeDate: endDate];
  203402. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203403. break;
  203404. }
  203405. return ! quitMessagePosted;
  203406. }
  203407. static CFRunLoopRef runLoop = 0;
  203408. static CFRunLoopSourceRef runLoopSource = 0;
  203409. static Array <void*, CriticalSection>* pendingMessages = 0;
  203410. static void runLoopSourceCallback (void*)
  203411. {
  203412. if (pendingMessages != 0)
  203413. {
  203414. int numDispatched = 0;
  203415. do
  203416. {
  203417. void* const nextMessage = pendingMessages->remove (0);
  203418. if (nextMessage == 0)
  203419. return;
  203420. const ScopedAutoReleasePool pool;
  203421. MessageManager::getInstance()->deliverMessage (nextMessage);
  203422. } while (++numDispatched <= 4);
  203423. CFRunLoopSourceSignal (runLoopSource);
  203424. CFRunLoopWakeUp (runLoop);
  203425. }
  203426. }
  203427. void MessageManager::doPlatformSpecificInitialisation()
  203428. {
  203429. pendingMessages = new Array <void*, CriticalSection>();
  203430. runLoop = CFRunLoopGetCurrent();
  203431. CFRunLoopSourceContext sourceContext;
  203432. zerostruct (sourceContext);
  203433. sourceContext.perform = runLoopSourceCallback;
  203434. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203435. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203436. if (juceAppDelegate == 0)
  203437. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203438. }
  203439. void MessageManager::doPlatformSpecificShutdown()
  203440. {
  203441. CFRunLoopSourceInvalidate (runLoopSource);
  203442. CFRelease (runLoopSource);
  203443. runLoopSource = 0;
  203444. if (pendingMessages != 0)
  203445. {
  203446. while (pendingMessages->size() > 0)
  203447. delete ((Message*) pendingMessages->remove(0));
  203448. deleteAndZero (pendingMessages);
  203449. }
  203450. if (juceAppDelegate != 0)
  203451. {
  203452. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203453. [juceAppDelegate release];
  203454. juceAppDelegate = 0;
  203455. }
  203456. }
  203457. bool juce_postMessageToSystemQueue (void* message)
  203458. {
  203459. if (pendingMessages != 0)
  203460. {
  203461. pendingMessages->add (message);
  203462. CFRunLoopSourceSignal (runLoopSource);
  203463. CFRunLoopWakeUp (runLoop);
  203464. }
  203465. return true;
  203466. }
  203467. void MessageManager::broadcastMessage (const String& value) throw()
  203468. {
  203469. }
  203470. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203471. void* data)
  203472. {
  203473. if (isThisTheMessageThread())
  203474. {
  203475. return (*callback) (data);
  203476. }
  203477. else
  203478. {
  203479. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203480. // deadlock because the message manager is blocked from running, so can never
  203481. // call your function..
  203482. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203483. const ScopedAutoReleasePool pool;
  203484. CallbackMessagePayload cmp;
  203485. cmp.function = callback;
  203486. cmp.parameter = data;
  203487. cmp.result = 0;
  203488. cmp.hasBeenExecuted = false;
  203489. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203490. withObject: [NSData dataWithBytesNoCopy: &cmp
  203491. length: sizeof (cmp)
  203492. freeWhenDone: NO]
  203493. waitUntilDone: YES];
  203494. return cmp.result;
  203495. }
  203496. }
  203497. #endif
  203498. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203499. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203500. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203501. // compiled on its own).
  203502. #if JUCE_INCLUDED_FILE
  203503. #if JUCE_MAC
  203504. END_JUCE_NAMESPACE
  203505. using namespace JUCE_NAMESPACE;
  203506. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203507. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203508. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203509. #else
  203510. @interface JuceFileChooserDelegate : NSObject
  203511. #endif
  203512. {
  203513. StringArray* filters;
  203514. }
  203515. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203516. - (void) dealloc;
  203517. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203518. @end
  203519. @implementation JuceFileChooserDelegate
  203520. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203521. {
  203522. [super init];
  203523. filters = filters_;
  203524. return self;
  203525. }
  203526. - (void) dealloc
  203527. {
  203528. delete filters;
  203529. [super dealloc];
  203530. }
  203531. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203532. {
  203533. const File f (nsStringToJuce (filename));
  203534. for (int i = filters->size(); --i >= 0;)
  203535. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203536. return true;
  203537. return f.isDirectory();
  203538. }
  203539. @end
  203540. BEGIN_JUCE_NAMESPACE
  203541. void FileChooser::showPlatformDialog (Array<File>& results,
  203542. const String& title,
  203543. const File& currentFileOrDirectory,
  203544. const String& filter,
  203545. bool selectsDirectory,
  203546. bool selectsFiles,
  203547. bool isSaveDialogue,
  203548. bool warnAboutOverwritingExistingFiles,
  203549. bool selectMultipleFiles,
  203550. FilePreviewComponent* extraInfoComponent)
  203551. {
  203552. const ScopedAutoReleasePool pool;
  203553. StringArray* filters = new StringArray();
  203554. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  203555. filters->trim();
  203556. filters->removeEmptyStrings();
  203557. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203558. [delegate autorelease];
  203559. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203560. : [NSOpenPanel openPanel];
  203561. [panel setTitle: juceStringToNS (title)];
  203562. if (! isSaveDialogue)
  203563. {
  203564. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203565. [openPanel setCanChooseDirectories: selectsDirectory];
  203566. [openPanel setCanChooseFiles: selectsFiles];
  203567. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203568. }
  203569. [panel setDelegate: delegate];
  203570. if (isSaveDialogue || selectsDirectory)
  203571. [panel setCanCreateDirectories: YES];
  203572. String directory, filename;
  203573. if (currentFileOrDirectory.isDirectory())
  203574. {
  203575. directory = currentFileOrDirectory.getFullPathName();
  203576. }
  203577. else
  203578. {
  203579. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203580. filename = currentFileOrDirectory.getFileName();
  203581. }
  203582. if ([panel runModalForDirectory: juceStringToNS (directory)
  203583. file: juceStringToNS (filename)]
  203584. == NSOKButton)
  203585. {
  203586. if (isSaveDialogue)
  203587. {
  203588. results.add (File (nsStringToJuce ([panel filename])));
  203589. }
  203590. else
  203591. {
  203592. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203593. NSArray* urls = [openPanel filenames];
  203594. for (unsigned int i = 0; i < [urls count]; ++i)
  203595. {
  203596. NSString* f = [urls objectAtIndex: i];
  203597. results.add (File (nsStringToJuce (f)));
  203598. }
  203599. }
  203600. }
  203601. [panel setDelegate: nil];
  203602. }
  203603. #else
  203604. void FileChooser::showPlatformDialog (Array<File>& results,
  203605. const String& title,
  203606. const File& currentFileOrDirectory,
  203607. const String& filter,
  203608. bool selectsDirectory,
  203609. bool selectsFiles,
  203610. bool isSaveDialogue,
  203611. bool warnAboutOverwritingExistingFiles,
  203612. bool selectMultipleFiles,
  203613. FilePreviewComponent* extraInfoComponent)
  203614. {
  203615. const ScopedAutoReleasePool pool;
  203616. jassertfalse //xxx to do
  203617. }
  203618. #endif
  203619. #endif
  203620. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203621. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203622. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203623. // compiled on its own).
  203624. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203625. #if JUCE_MAC
  203626. END_JUCE_NAMESPACE
  203627. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203628. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203629. {
  203630. CriticalSection* contextLock;
  203631. bool needsUpdate;
  203632. }
  203633. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203634. - (bool) makeActive;
  203635. - (void) makeInactive;
  203636. - (void) reshape;
  203637. @end
  203638. @implementation ThreadSafeNSOpenGLView
  203639. - (id) initWithFrame: (NSRect) frameRect
  203640. pixelFormat: (NSOpenGLPixelFormat*) format
  203641. {
  203642. contextLock = new CriticalSection();
  203643. self = [super initWithFrame: frameRect pixelFormat: format];
  203644. if (self != nil)
  203645. [[NSNotificationCenter defaultCenter] addObserver: self
  203646. selector: @selector (_surfaceNeedsUpdate:)
  203647. name: NSViewGlobalFrameDidChangeNotification
  203648. object: self];
  203649. return self;
  203650. }
  203651. - (void) dealloc
  203652. {
  203653. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203654. delete contextLock;
  203655. [super dealloc];
  203656. }
  203657. - (bool) makeActive
  203658. {
  203659. const ScopedLock sl (*contextLock);
  203660. if ([self openGLContext] == 0)
  203661. return false;
  203662. [[self openGLContext] makeCurrentContext];
  203663. if (needsUpdate)
  203664. {
  203665. [super update];
  203666. needsUpdate = false;
  203667. }
  203668. return true;
  203669. }
  203670. - (void) makeInactive
  203671. {
  203672. const ScopedLock sl (*contextLock);
  203673. [NSOpenGLContext clearCurrentContext];
  203674. }
  203675. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203676. {
  203677. const ScopedLock sl (*contextLock);
  203678. needsUpdate = true;
  203679. }
  203680. - (void) update
  203681. {
  203682. const ScopedLock sl (*contextLock);
  203683. needsUpdate = true;
  203684. }
  203685. - (void) reshape
  203686. {
  203687. const ScopedLock sl (*contextLock);
  203688. needsUpdate = true;
  203689. }
  203690. @end
  203691. BEGIN_JUCE_NAMESPACE
  203692. class WindowedGLContext : public OpenGLContext
  203693. {
  203694. public:
  203695. WindowedGLContext (Component* const component,
  203696. const OpenGLPixelFormat& pixelFormat_,
  203697. NSOpenGLContext* sharedContext)
  203698. : renderContext (0),
  203699. pixelFormat (pixelFormat_)
  203700. {
  203701. jassert (component != 0);
  203702. NSOpenGLPixelFormatAttribute attribs [64];
  203703. int n = 0;
  203704. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203705. attribs[n++] = NSOpenGLPFAAccelerated;
  203706. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203707. attribs[n++] = NSOpenGLPFAColorSize;
  203708. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203709. pixelFormat.greenBits,
  203710. pixelFormat.blueBits);
  203711. attribs[n++] = NSOpenGLPFAAlphaSize;
  203712. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203713. attribs[n++] = NSOpenGLPFADepthSize;
  203714. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203715. attribs[n++] = NSOpenGLPFAStencilSize;
  203716. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203717. attribs[n++] = NSOpenGLPFAAccumSize;
  203718. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203719. pixelFormat.accumulationBufferGreenBits,
  203720. pixelFormat.accumulationBufferBlueBits,
  203721. pixelFormat.accumulationBufferAlphaBits);
  203722. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203723. attribs[n++] = NSOpenGLPFASampleBuffers;
  203724. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203725. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203726. attribs[n++] = NSOpenGLPFANoRecovery;
  203727. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203728. NSOpenGLPixelFormat* format
  203729. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203730. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203731. pixelFormat: format];
  203732. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203733. shareContext: sharedContext] autorelease];
  203734. const GLint swapInterval = 1;
  203735. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203736. [view setOpenGLContext: renderContext];
  203737. [renderContext setView: view];
  203738. [format release];
  203739. viewHolder = new NSViewComponentInternal (view, component);
  203740. }
  203741. ~WindowedGLContext()
  203742. {
  203743. makeInactive();
  203744. [renderContext clearDrawable];
  203745. viewHolder = 0;
  203746. }
  203747. bool makeActive() const throw()
  203748. {
  203749. jassert (renderContext != 0);
  203750. [view makeActive];
  203751. return isActive();
  203752. }
  203753. bool makeInactive() const throw()
  203754. {
  203755. [view makeInactive];
  203756. return true;
  203757. }
  203758. bool isActive() const throw()
  203759. {
  203760. return [NSOpenGLContext currentContext] == renderContext;
  203761. }
  203762. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203763. void* getRawContext() const throw() { return renderContext; }
  203764. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203765. {
  203766. }
  203767. void swapBuffers()
  203768. {
  203769. [renderContext flushBuffer];
  203770. }
  203771. bool setSwapInterval (const int numFramesPerSwap)
  203772. {
  203773. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203774. forParameter: NSOpenGLCPSwapInterval];
  203775. return true;
  203776. }
  203777. int getSwapInterval() const
  203778. {
  203779. GLint numFrames = 0;
  203780. [renderContext getValues: &numFrames
  203781. forParameter: NSOpenGLCPSwapInterval];
  203782. return numFrames;
  203783. }
  203784. void repaint()
  203785. {
  203786. // we need to invalidate the juce view that holds this gl view, to make it
  203787. // cause a repaint callback
  203788. NSView* v = (NSView*) viewHolder->view;
  203789. NSRect r = [v frame];
  203790. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203791. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203792. // repaint message, thus never causing our paint() callback, and never repainting
  203793. // the comp. So invalidating just a little bit around the edge helps..
  203794. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203795. }
  203796. void* getNativeWindowHandle() const { return viewHolder->view; }
  203797. juce_UseDebuggingNewOperator
  203798. NSOpenGLContext* renderContext;
  203799. ThreadSafeNSOpenGLView* view;
  203800. private:
  203801. OpenGLPixelFormat pixelFormat;
  203802. ScopedPointer <NSViewComponentInternal> viewHolder;
  203803. WindowedGLContext (const WindowedGLContext&);
  203804. WindowedGLContext& operator= (const WindowedGLContext&);
  203805. };
  203806. OpenGLContext* OpenGLComponent::createContext()
  203807. {
  203808. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203809. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203810. return (c->renderContext != 0) ? c.release() : 0;
  203811. }
  203812. void* OpenGLComponent::getNativeWindowHandle() const
  203813. {
  203814. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  203815. : 0;
  203816. }
  203817. void juce_glViewport (const int w, const int h)
  203818. {
  203819. glViewport (0, 0, w, h);
  203820. }
  203821. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203822. OwnedArray <OpenGLPixelFormat>& results)
  203823. {
  203824. /* GLint attribs [64];
  203825. int n = 0;
  203826. attribs[n++] = AGL_RGBA;
  203827. attribs[n++] = AGL_DOUBLEBUFFER;
  203828. attribs[n++] = AGL_ACCELERATED;
  203829. attribs[n++] = AGL_NO_RECOVERY;
  203830. attribs[n++] = AGL_NONE;
  203831. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203832. while (p != 0)
  203833. {
  203834. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203835. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203836. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203837. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203838. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203839. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203840. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203841. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203842. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203843. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203844. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203845. results.add (pf);
  203846. p = aglNextPixelFormat (p);
  203847. }*/
  203848. //jassertfalse //xxx can't see how you do this in cocoa!
  203849. }
  203850. #else
  203851. END_JUCE_NAMESPACE
  203852. @interface JuceGLView : UIView
  203853. {
  203854. }
  203855. + (Class) layerClass;
  203856. @end
  203857. @implementation JuceGLView
  203858. + (Class) layerClass
  203859. {
  203860. return [CAEAGLLayer class];
  203861. }
  203862. @end
  203863. BEGIN_JUCE_NAMESPACE
  203864. class GLESContext : public OpenGLContext
  203865. {
  203866. public:
  203867. GLESContext (UIViewComponentPeer* peer,
  203868. Component* const component_,
  203869. const OpenGLPixelFormat& pixelFormat_,
  203870. const GLESContext* const sharedContext,
  203871. NSUInteger apiType)
  203872. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203873. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203874. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203875. {
  203876. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203877. view.opaque = YES;
  203878. view.hidden = NO;
  203879. view.backgroundColor = [UIColor blackColor];
  203880. view.userInteractionEnabled = NO;
  203881. glLayer = (CAEAGLLayer*) [view layer];
  203882. [peer->view addSubview: view];
  203883. if (sharedContext != 0)
  203884. context = [[EAGLContext alloc] initWithAPI: apiType
  203885. sharegroup: [sharedContext->context sharegroup]];
  203886. else
  203887. context = [[EAGLContext alloc] initWithAPI: apiType];
  203888. createGLBuffers();
  203889. }
  203890. ~GLESContext()
  203891. {
  203892. makeInactive();
  203893. [context release];
  203894. [view removeFromSuperview];
  203895. [view release];
  203896. freeGLBuffers();
  203897. }
  203898. bool makeActive() const throw()
  203899. {
  203900. jassert (context != 0);
  203901. [EAGLContext setCurrentContext: context];
  203902. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203903. return true;
  203904. }
  203905. void swapBuffers()
  203906. {
  203907. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203908. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  203909. }
  203910. bool makeInactive() const throw()
  203911. {
  203912. return [EAGLContext setCurrentContext: nil];
  203913. }
  203914. bool isActive() const throw()
  203915. {
  203916. return [EAGLContext currentContext] == context;
  203917. }
  203918. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203919. void* getRawContext() const throw() { return glLayer; }
  203920. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203921. {
  203922. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  203923. if (lastWidth != w || lastHeight != h)
  203924. {
  203925. lastWidth = w;
  203926. lastHeight = h;
  203927. freeGLBuffers();
  203928. createGLBuffers();
  203929. }
  203930. }
  203931. bool setSwapInterval (const int numFramesPerSwap)
  203932. {
  203933. numFrames = numFramesPerSwap;
  203934. return true;
  203935. }
  203936. int getSwapInterval() const
  203937. {
  203938. return numFrames;
  203939. }
  203940. void repaint()
  203941. {
  203942. }
  203943. void createGLBuffers()
  203944. {
  203945. makeActive();
  203946. glGenFramebuffersOES (1, &frameBufferHandle);
  203947. glGenRenderbuffersOES (1, &colorBufferHandle);
  203948. glGenRenderbuffersOES (1, &depthBufferHandle);
  203949. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203950. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  203951. GLint width, height;
  203952. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  203953. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  203954. if (useDepthBuffer)
  203955. {
  203956. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  203957. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  203958. }
  203959. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203960. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203961. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  203962. if (useDepthBuffer)
  203963. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  203964. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  203965. }
  203966. void freeGLBuffers()
  203967. {
  203968. if (frameBufferHandle != 0)
  203969. {
  203970. glDeleteFramebuffersOES (1, &frameBufferHandle);
  203971. frameBufferHandle = 0;
  203972. }
  203973. if (colorBufferHandle != 0)
  203974. {
  203975. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  203976. colorBufferHandle = 0;
  203977. }
  203978. if (depthBufferHandle != 0)
  203979. {
  203980. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  203981. depthBufferHandle = 0;
  203982. }
  203983. }
  203984. juce_UseDebuggingNewOperator
  203985. private:
  203986. Component::SafePointer<Component> component;
  203987. OpenGLPixelFormat pixelFormat;
  203988. JuceGLView* view;
  203989. CAEAGLLayer* glLayer;
  203990. EAGLContext* context;
  203991. bool useDepthBuffer;
  203992. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  203993. int numFrames;
  203994. int lastWidth, lastHeight;
  203995. GLESContext (const GLESContext&);
  203996. GLESContext& operator= (const GLESContext&);
  203997. };
  203998. OpenGLContext* OpenGLComponent::createContext()
  203999. {
  204000. ScopedAutoReleasePool pool;
  204001. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  204002. if (peer != 0)
  204003. return new GLESContext (peer, this, preferredPixelFormat,
  204004. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  204005. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  204006. return 0;
  204007. }
  204008. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204009. OwnedArray <OpenGLPixelFormat>& /*results*/)
  204010. {
  204011. }
  204012. void juce_glViewport (const int w, const int h)
  204013. {
  204014. glViewport (0, 0, w, h);
  204015. }
  204016. #endif
  204017. #endif
  204018. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204019. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204020. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204021. // compiled on its own).
  204022. #if JUCE_INCLUDED_FILE
  204023. #if JUCE_MAC
  204024. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  204025. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204026. {
  204027. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204028. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204029. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204030. [im release];
  204031. return c;
  204032. }
  204033. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204034. {
  204035. MemoryInputStream stream (data, size, false);
  204036. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  204037. jassert (im != 0);
  204038. if (im == 0)
  204039. return 0;
  204040. return juce_createMouseCursorFromImage (*im,
  204041. (int) (hx * im->getWidth()),
  204042. (int) (hy * im->getHeight()));
  204043. }
  204044. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204045. {
  204046. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204047. MemoryBlock mb;
  204048. if (f.getChildFile (filename).loadFileAsData (mb))
  204049. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204050. return 0;
  204051. }
  204052. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204053. {
  204054. const ScopedAutoReleasePool pool;
  204055. NSCursor* c = 0;
  204056. switch (type)
  204057. {
  204058. case MouseCursor::NormalCursor:
  204059. c = [NSCursor arrowCursor];
  204060. break;
  204061. case MouseCursor::NoCursor:
  204062. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204063. case MouseCursor::DraggingHandCursor:
  204064. c = [NSCursor openHandCursor];
  204065. break;
  204066. case MouseCursor::CopyingCursor:
  204067. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204068. case MouseCursor::WaitCursor:
  204069. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204070. break;
  204071. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204072. case MouseCursor::IBeamCursor:
  204073. c = [NSCursor IBeamCursor];
  204074. break;
  204075. case MouseCursor::PointingHandCursor:
  204076. c = [NSCursor pointingHandCursor];
  204077. break;
  204078. case MouseCursor::LeftRightResizeCursor:
  204079. c = [NSCursor resizeLeftRightCursor];
  204080. break;
  204081. case MouseCursor::LeftEdgeResizeCursor:
  204082. c = [NSCursor resizeLeftCursor];
  204083. break;
  204084. case MouseCursor::RightEdgeResizeCursor:
  204085. c = [NSCursor resizeRightCursor];
  204086. break;
  204087. case MouseCursor::UpDownResizeCursor:
  204088. case MouseCursor::TopEdgeResizeCursor:
  204089. case MouseCursor::BottomEdgeResizeCursor:
  204090. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204091. case MouseCursor::TopLeftCornerResizeCursor:
  204092. case MouseCursor::BottomRightCornerResizeCursor:
  204093. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204094. case MouseCursor::TopRightCornerResizeCursor:
  204095. case MouseCursor::BottomLeftCornerResizeCursor:
  204096. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204097. case MouseCursor::UpDownLeftRightResizeCursor:
  204098. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204099. case MouseCursor::CrosshairCursor:
  204100. c = [NSCursor crosshairCursor];
  204101. break;
  204102. }
  204103. [c retain];
  204104. return c;
  204105. }
  204106. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204107. {
  204108. NSCursor* c = (NSCursor*) cursorHandle;
  204109. [c release];
  204110. }
  204111. void MouseCursor::showInAllWindows() const throw()
  204112. {
  204113. showInWindow (0);
  204114. }
  204115. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204116. {
  204117. NSCursor* const c = (NSCursor*) getHandle();
  204118. [c set];
  204119. }
  204120. #else
  204121. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204122. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204123. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204124. void MouseCursor::showInAllWindows() const throw() {}
  204125. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204126. #endif
  204127. #endif
  204128. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204129. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204130. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204131. // compiled on its own).
  204132. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204133. #if JUCE_MAC
  204134. END_JUCE_NAMESPACE
  204135. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204136. @interface DownloadClickDetector : NSObject
  204137. {
  204138. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204139. }
  204140. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204141. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204142. request: (NSURLRequest*) request
  204143. frame: (WebFrame*) frame
  204144. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204145. @end
  204146. @implementation DownloadClickDetector
  204147. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204148. {
  204149. [super init];
  204150. ownerComponent = ownerComponent_;
  204151. return self;
  204152. }
  204153. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204154. request: (NSURLRequest*) request
  204155. frame: (WebFrame*) frame
  204156. decisionListener: (id <WebPolicyDecisionListener>) listener
  204157. {
  204158. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204159. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204160. [listener use];
  204161. else
  204162. [listener ignore];
  204163. }
  204164. @end
  204165. BEGIN_JUCE_NAMESPACE
  204166. class WebBrowserComponentInternal : public NSViewComponent
  204167. {
  204168. public:
  204169. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204170. {
  204171. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204172. frameName: @""
  204173. groupName: @""];
  204174. setView (webView);
  204175. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204176. [webView setPolicyDelegate: clickListener];
  204177. }
  204178. ~WebBrowserComponentInternal()
  204179. {
  204180. [webView setPolicyDelegate: nil];
  204181. [clickListener release];
  204182. setView (0);
  204183. }
  204184. void goToURL (const String& url,
  204185. const StringArray* headers,
  204186. const MemoryBlock* postData)
  204187. {
  204188. NSMutableURLRequest* r
  204189. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204190. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204191. timeoutInterval: 30.0];
  204192. if (postData != 0 && postData->getSize() > 0)
  204193. {
  204194. [r setHTTPMethod: @"POST"];
  204195. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204196. length: postData->getSize()]];
  204197. }
  204198. if (headers != 0)
  204199. {
  204200. for (int i = 0; i < headers->size(); ++i)
  204201. {
  204202. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  204203. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  204204. [r setValue: juceStringToNS (headerValue)
  204205. forHTTPHeaderField: juceStringToNS (headerName)];
  204206. }
  204207. }
  204208. stop();
  204209. [[webView mainFrame] loadRequest: r];
  204210. }
  204211. void goBack()
  204212. {
  204213. [webView goBack];
  204214. }
  204215. void goForward()
  204216. {
  204217. [webView goForward];
  204218. }
  204219. void stop()
  204220. {
  204221. [webView stopLoading: nil];
  204222. }
  204223. void refresh()
  204224. {
  204225. [webView reload: nil];
  204226. }
  204227. private:
  204228. WebView* webView;
  204229. DownloadClickDetector* clickListener;
  204230. };
  204231. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204232. : browser (0),
  204233. blankPageShown (false),
  204234. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204235. {
  204236. setOpaque (true);
  204237. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204238. }
  204239. WebBrowserComponent::~WebBrowserComponent()
  204240. {
  204241. deleteAndZero (browser);
  204242. }
  204243. void WebBrowserComponent::goToURL (const String& url,
  204244. const StringArray* headers,
  204245. const MemoryBlock* postData)
  204246. {
  204247. lastURL = url;
  204248. lastHeaders.clear();
  204249. if (headers != 0)
  204250. lastHeaders = *headers;
  204251. lastPostData.setSize (0);
  204252. if (postData != 0)
  204253. lastPostData = *postData;
  204254. blankPageShown = false;
  204255. browser->goToURL (url, headers, postData);
  204256. }
  204257. void WebBrowserComponent::stop()
  204258. {
  204259. browser->stop();
  204260. }
  204261. void WebBrowserComponent::goBack()
  204262. {
  204263. lastURL = String::empty;
  204264. blankPageShown = false;
  204265. browser->goBack();
  204266. }
  204267. void WebBrowserComponent::goForward()
  204268. {
  204269. lastURL = String::empty;
  204270. browser->goForward();
  204271. }
  204272. void WebBrowserComponent::refresh()
  204273. {
  204274. browser->refresh();
  204275. }
  204276. void WebBrowserComponent::paint (Graphics& g)
  204277. {
  204278. }
  204279. void WebBrowserComponent::checkWindowAssociation()
  204280. {
  204281. if (isShowing())
  204282. {
  204283. if (blankPageShown)
  204284. goBack();
  204285. }
  204286. else
  204287. {
  204288. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204289. {
  204290. // when the component becomes invisible, some stuff like flash
  204291. // carries on playing audio, so we need to force it onto a blank
  204292. // page to avoid this, (and send it back when it's made visible again).
  204293. blankPageShown = true;
  204294. browser->goToURL ("about:blank", 0, 0);
  204295. }
  204296. }
  204297. }
  204298. void WebBrowserComponent::reloadLastURL()
  204299. {
  204300. if (lastURL.isNotEmpty())
  204301. {
  204302. goToURL (lastURL, &lastHeaders, &lastPostData);
  204303. lastURL = String::empty;
  204304. }
  204305. }
  204306. void WebBrowserComponent::parentHierarchyChanged()
  204307. {
  204308. checkWindowAssociation();
  204309. }
  204310. void WebBrowserComponent::resized()
  204311. {
  204312. browser->setSize (getWidth(), getHeight());
  204313. }
  204314. void WebBrowserComponent::visibilityChanged()
  204315. {
  204316. checkWindowAssociation();
  204317. }
  204318. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204319. {
  204320. return true;
  204321. }
  204322. #else
  204323. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204324. {
  204325. }
  204326. WebBrowserComponent::~WebBrowserComponent()
  204327. {
  204328. }
  204329. void WebBrowserComponent::goToURL (const String& url,
  204330. const StringArray* headers,
  204331. const MemoryBlock* postData)
  204332. {
  204333. }
  204334. void WebBrowserComponent::stop()
  204335. {
  204336. }
  204337. void WebBrowserComponent::goBack()
  204338. {
  204339. }
  204340. void WebBrowserComponent::goForward()
  204341. {
  204342. }
  204343. void WebBrowserComponent::refresh()
  204344. {
  204345. }
  204346. void WebBrowserComponent::paint (Graphics& g)
  204347. {
  204348. }
  204349. void WebBrowserComponent::checkWindowAssociation()
  204350. {
  204351. }
  204352. void WebBrowserComponent::reloadLastURL()
  204353. {
  204354. }
  204355. void WebBrowserComponent::parentHierarchyChanged()
  204356. {
  204357. }
  204358. void WebBrowserComponent::resized()
  204359. {
  204360. }
  204361. void WebBrowserComponent::visibilityChanged()
  204362. {
  204363. }
  204364. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204365. {
  204366. return true;
  204367. }
  204368. #endif
  204369. #endif
  204370. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204371. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204372. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204373. // compiled on its own).
  204374. #if JUCE_INCLUDED_FILE
  204375. class IPhoneAudioIODevice : public AudioIODevice
  204376. {
  204377. public:
  204378. IPhoneAudioIODevice (const String& deviceName)
  204379. : AudioIODevice (deviceName, "Audio"),
  204380. audioUnit (0),
  204381. isRunning (false),
  204382. callback (0),
  204383. actualBufferSize (0),
  204384. floatData (1, 2)
  204385. {
  204386. numInputChannels = 2;
  204387. numOutputChannels = 2;
  204388. preferredBufferSize = 0;
  204389. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204390. updateDeviceInfo();
  204391. }
  204392. ~IPhoneAudioIODevice()
  204393. {
  204394. close();
  204395. }
  204396. const StringArray getOutputChannelNames()
  204397. {
  204398. StringArray s;
  204399. s.add ("Left");
  204400. s.add ("Right");
  204401. return s;
  204402. }
  204403. const StringArray getInputChannelNames()
  204404. {
  204405. StringArray s;
  204406. if (audioInputIsAvailable)
  204407. {
  204408. s.add ("Left");
  204409. s.add ("Right");
  204410. }
  204411. return s;
  204412. }
  204413. int getNumSampleRates()
  204414. {
  204415. return 1;
  204416. }
  204417. double getSampleRate (int index)
  204418. {
  204419. return sampleRate;
  204420. }
  204421. int getNumBufferSizesAvailable()
  204422. {
  204423. return 1;
  204424. }
  204425. int getBufferSizeSamples (int index)
  204426. {
  204427. return getDefaultBufferSize();
  204428. }
  204429. int getDefaultBufferSize()
  204430. {
  204431. return 1024;
  204432. }
  204433. const String open (const BigInteger& inputChannels,
  204434. const BigInteger& outputChannels,
  204435. double sampleRate,
  204436. int bufferSize)
  204437. {
  204438. close();
  204439. lastError = String::empty;
  204440. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204441. // xxx set up channel mapping
  204442. activeOutputChans = outputChannels;
  204443. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204444. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204445. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204446. activeInputChans = inputChannels;
  204447. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204448. numInputChannels = activeInputChans.countNumberOfSetBits();
  204449. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204450. AudioSessionSetActive (true);
  204451. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204452. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204453. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204454. fixAudioRouteIfSetToReceiver();
  204455. updateDeviceInfo();
  204456. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204457. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204458. actualBufferSize = preferredBufferSize;
  204459. prepareFloatBuffers();
  204460. isRunning = true;
  204461. propertyChanged (0, 0, 0); // creates and starts the AU
  204462. lastError = audioUnit != 0 ? "" : "Couldn't open the device";
  204463. return lastError;
  204464. }
  204465. void close()
  204466. {
  204467. if (isRunning)
  204468. {
  204469. isRunning = false;
  204470. AudioSessionSetActive (false);
  204471. if (audioUnit != 0)
  204472. {
  204473. AudioComponentInstanceDispose (audioUnit);
  204474. audioUnit = 0;
  204475. }
  204476. }
  204477. }
  204478. bool isOpen()
  204479. {
  204480. return isRunning;
  204481. }
  204482. int getCurrentBufferSizeSamples()
  204483. {
  204484. return actualBufferSize;
  204485. }
  204486. double getCurrentSampleRate()
  204487. {
  204488. return sampleRate;
  204489. }
  204490. int getCurrentBitDepth()
  204491. {
  204492. return 16;
  204493. }
  204494. const BigInteger getActiveOutputChannels() const
  204495. {
  204496. return activeOutputChans;
  204497. }
  204498. const BigInteger getActiveInputChannels() const
  204499. {
  204500. return activeInputChans;
  204501. }
  204502. int getOutputLatencyInSamples()
  204503. {
  204504. return 0; //xxx
  204505. }
  204506. int getInputLatencyInSamples()
  204507. {
  204508. return 0; //xxx
  204509. }
  204510. void start (AudioIODeviceCallback* callback_)
  204511. {
  204512. if (isRunning && callback != callback_)
  204513. {
  204514. if (callback_ != 0)
  204515. callback_->audioDeviceAboutToStart (this);
  204516. const ScopedLock sl (callbackLock);
  204517. callback = callback_;
  204518. }
  204519. }
  204520. void stop()
  204521. {
  204522. if (isRunning)
  204523. {
  204524. AudioIODeviceCallback* lastCallback;
  204525. {
  204526. const ScopedLock sl (callbackLock);
  204527. lastCallback = callback;
  204528. callback = 0;
  204529. }
  204530. if (lastCallback != 0)
  204531. lastCallback->audioDeviceStopped();
  204532. }
  204533. }
  204534. bool isPlaying()
  204535. {
  204536. return isRunning && callback != 0;
  204537. }
  204538. const String getLastError()
  204539. {
  204540. return lastError;
  204541. }
  204542. private:
  204543. CriticalSection callbackLock;
  204544. Float64 sampleRate;
  204545. int numInputChannels, numOutputChannels;
  204546. int preferredBufferSize;
  204547. int actualBufferSize;
  204548. bool isRunning;
  204549. String lastError;
  204550. AudioStreamBasicDescription format;
  204551. AudioUnit audioUnit;
  204552. UInt32 audioInputIsAvailable;
  204553. AudioIODeviceCallback* callback;
  204554. BigInteger activeOutputChans, activeInputChans;
  204555. AudioSampleBuffer floatData;
  204556. float* inputChannels[3];
  204557. float* outputChannels[3];
  204558. bool monoInputChannelNumber, monoOutputChannelNumber;
  204559. void prepareFloatBuffers()
  204560. {
  204561. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204562. zerostruct (inputChannels);
  204563. zerostruct (outputChannels);
  204564. for (int i = 0; i < numInputChannels; ++i)
  204565. inputChannels[i] = floatData.getSampleData (i);
  204566. for (int i = 0; i < numOutputChannels; ++i)
  204567. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204568. }
  204569. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204570. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204571. {
  204572. OSStatus err = noErr;
  204573. if (audioInputIsAvailable)
  204574. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204575. const ScopedLock sl (callbackLock);
  204576. if (callback != 0)
  204577. {
  204578. if (audioInputIsAvailable && numInputChannels > 0)
  204579. {
  204580. short* shortData = (short*) ioData->mBuffers[0].mData;
  204581. if (numInputChannels >= 2)
  204582. {
  204583. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204584. {
  204585. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204586. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204587. }
  204588. }
  204589. else
  204590. {
  204591. if (monoInputChannelNumber > 0)
  204592. ++shortData;
  204593. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204594. {
  204595. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204596. ++shortData;
  204597. }
  204598. }
  204599. }
  204600. else
  204601. {
  204602. for (int i = numInputChannels; --i >= 0;)
  204603. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204604. }
  204605. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204606. outputChannels, numOutputChannels,
  204607. (int) inNumberFrames);
  204608. short* shortData = (short*) ioData->mBuffers[0].mData;
  204609. int n = 0;
  204610. if (numOutputChannels >= 2)
  204611. {
  204612. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204613. {
  204614. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204615. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204616. }
  204617. }
  204618. else if (numOutputChannels == 1)
  204619. {
  204620. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204621. {
  204622. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204623. shortData [n++] = s;
  204624. shortData [n++] = s;
  204625. }
  204626. }
  204627. else
  204628. {
  204629. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204630. }
  204631. }
  204632. else
  204633. {
  204634. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204635. }
  204636. return err;
  204637. }
  204638. void updateDeviceInfo()
  204639. {
  204640. UInt32 size = sizeof (sampleRate);
  204641. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204642. size = sizeof (audioInputIsAvailable);
  204643. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204644. }
  204645. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204646. {
  204647. if (! isRunning)
  204648. return;
  204649. if (inPropertyValue != 0)
  204650. {
  204651. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204652. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204653. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204654. SInt32 routeChangeReason;
  204655. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204656. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204657. fixAudioRouteIfSetToReceiver();
  204658. }
  204659. updateDeviceInfo();
  204660. createAudioUnit();
  204661. AudioSessionSetActive (true);
  204662. if (audioUnit != 0)
  204663. {
  204664. UInt32 formatSize = sizeof (format);
  204665. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204666. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204667. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204668. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204669. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204670. AudioOutputUnitStart (audioUnit);
  204671. }
  204672. }
  204673. void interruptionListener (UInt32 inInterruption)
  204674. {
  204675. if (inInterruption == kAudioSessionEndInterruption)
  204676. {
  204677. isRunning = true;
  204678. AudioSessionSetActive (true);
  204679. AudioOutputUnitStart (audioUnit);
  204680. }
  204681. }
  204682. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204683. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204684. {
  204685. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204686. }
  204687. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204688. {
  204689. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204690. }
  204691. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204692. {
  204693. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204694. }
  204695. void resetFormat (const int numChannels)
  204696. {
  204697. memset (&format, 0, sizeof (format));
  204698. format.mFormatID = kAudioFormatLinearPCM;
  204699. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204700. format.mBitsPerChannel = 8 * sizeof (short);
  204701. format.mChannelsPerFrame = 2;
  204702. format.mFramesPerPacket = 1;
  204703. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204704. }
  204705. bool createAudioUnit()
  204706. {
  204707. if (audioUnit != 0)
  204708. {
  204709. AudioComponentInstanceDispose (audioUnit);
  204710. audioUnit = 0;
  204711. }
  204712. resetFormat (2);
  204713. AudioComponentDescription desc;
  204714. desc.componentType = kAudioUnitType_Output;
  204715. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204716. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204717. desc.componentFlags = 0;
  204718. desc.componentFlagsMask = 0;
  204719. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204720. AudioComponentInstanceNew (comp, &audioUnit);
  204721. if (audioUnit == 0)
  204722. return false;
  204723. const UInt32 one = 1;
  204724. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204725. AudioChannelLayout layout;
  204726. layout.mChannelBitmap = 0;
  204727. layout.mNumberChannelDescriptions = 0;
  204728. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204729. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204730. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204731. AURenderCallbackStruct inputProc;
  204732. inputProc.inputProc = processStatic;
  204733. inputProc.inputProcRefCon = this;
  204734. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204735. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204736. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204737. AudioUnitInitialize (audioUnit);
  204738. return true;
  204739. }
  204740. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204741. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204742. static void fixAudioRouteIfSetToReceiver()
  204743. {
  204744. CFStringRef audioRoute = 0;
  204745. UInt32 propertySize = sizeof (audioRoute);
  204746. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204747. {
  204748. NSString* route = (NSString*) audioRoute;
  204749. //DBG ("audio route: " + nsStringToJuce (route));
  204750. if ([route hasPrefix: @"Receiver"])
  204751. {
  204752. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204753. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204754. }
  204755. CFRelease (audioRoute);
  204756. }
  204757. }
  204758. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204759. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204760. };
  204761. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204762. {
  204763. public:
  204764. IPhoneAudioIODeviceType()
  204765. : AudioIODeviceType ("iPhone Audio")
  204766. {
  204767. }
  204768. ~IPhoneAudioIODeviceType()
  204769. {
  204770. }
  204771. void scanForDevices()
  204772. {
  204773. }
  204774. const StringArray getDeviceNames (bool wantInputNames) const
  204775. {
  204776. StringArray s;
  204777. s.add ("iPhone Audio");
  204778. return s;
  204779. }
  204780. int getDefaultDeviceIndex (bool forInput) const
  204781. {
  204782. return 0;
  204783. }
  204784. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  204785. {
  204786. return device != 0 ? 0 : -1;
  204787. }
  204788. bool hasSeparateInputsAndOutputs() const { return false; }
  204789. AudioIODevice* createDevice (const String& outputDeviceName,
  204790. const String& inputDeviceName)
  204791. {
  204792. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204793. {
  204794. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204795. : inputDeviceName);
  204796. }
  204797. return 0;
  204798. }
  204799. juce_UseDebuggingNewOperator
  204800. private:
  204801. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204802. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204803. };
  204804. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204805. {
  204806. return new IPhoneAudioIODeviceType();
  204807. }
  204808. #endif
  204809. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204810. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204811. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204812. // compiled on its own).
  204813. #if JUCE_INCLUDED_FILE
  204814. #if JUCE_MAC
  204815. #undef log
  204816. #define log(a) Logger::writeToLog(a)
  204817. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204818. {
  204819. if (err == noErr)
  204820. return true;
  204821. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  204822. jassertfalse
  204823. return false;
  204824. }
  204825. #undef OK
  204826. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204827. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204828. {
  204829. String result;
  204830. CFStringRef str = 0;
  204831. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204832. if (str != 0)
  204833. {
  204834. result = PlatformUtilities::cfStringToJuceString (str);
  204835. CFRelease (str);
  204836. str = 0;
  204837. }
  204838. MIDIEntityRef entity = 0;
  204839. MIDIEndpointGetEntity (endpoint, &entity);
  204840. if (entity == 0)
  204841. return result; // probably virtual
  204842. if (result.isEmpty())
  204843. {
  204844. // endpoint name has zero length - try the entity
  204845. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204846. if (str != 0)
  204847. {
  204848. result += PlatformUtilities::cfStringToJuceString (str);
  204849. CFRelease (str);
  204850. str = 0;
  204851. }
  204852. }
  204853. // now consider the device's name
  204854. MIDIDeviceRef device = 0;
  204855. MIDIEntityGetDevice (entity, &device);
  204856. if (device == 0)
  204857. return result;
  204858. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204859. if (str != 0)
  204860. {
  204861. const String s (PlatformUtilities::cfStringToJuceString (str));
  204862. CFRelease (str);
  204863. // if an external device has only one entity, throw away
  204864. // the endpoint name and just use the device name
  204865. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204866. {
  204867. result = s;
  204868. }
  204869. else if (! result.startsWithIgnoreCase (s))
  204870. {
  204871. // prepend the device name to the entity name
  204872. result = (s + " " + result).trimEnd();
  204873. }
  204874. }
  204875. return result;
  204876. }
  204877. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204878. {
  204879. String result;
  204880. // Does the endpoint have connections?
  204881. CFDataRef connections = 0;
  204882. int numConnections = 0;
  204883. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204884. if (connections != 0)
  204885. {
  204886. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204887. if (numConnections > 0)
  204888. {
  204889. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204890. for (int i = 0; i < numConnections; ++i, ++pid)
  204891. {
  204892. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204893. MIDIObjectRef connObject;
  204894. MIDIObjectType connObjectType;
  204895. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204896. if (err == noErr)
  204897. {
  204898. String s;
  204899. if (connObjectType == kMIDIObjectType_ExternalSource
  204900. || connObjectType == kMIDIObjectType_ExternalDestination)
  204901. {
  204902. // Connected to an external device's endpoint (10.3 and later).
  204903. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204904. }
  204905. else
  204906. {
  204907. // Connected to an external device (10.2) (or something else, catch-all)
  204908. CFStringRef str = 0;
  204909. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204910. if (str != 0)
  204911. {
  204912. s = PlatformUtilities::cfStringToJuceString (str);
  204913. CFRelease (str);
  204914. }
  204915. }
  204916. if (s.isNotEmpty())
  204917. {
  204918. if (result.isNotEmpty())
  204919. result += ", ";
  204920. result += s;
  204921. }
  204922. }
  204923. }
  204924. }
  204925. CFRelease (connections);
  204926. }
  204927. if (result.isNotEmpty())
  204928. return result;
  204929. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204930. return getEndpointName (endpoint, false);
  204931. }
  204932. const StringArray MidiOutput::getDevices()
  204933. {
  204934. StringArray s;
  204935. const ItemCount num = MIDIGetNumberOfDestinations();
  204936. for (ItemCount i = 0; i < num; ++i)
  204937. {
  204938. MIDIEndpointRef dest = MIDIGetDestination (i);
  204939. if (dest != 0)
  204940. {
  204941. String name (getConnectedEndpointName (dest));
  204942. if (name.isEmpty())
  204943. name = "<error>";
  204944. s.add (name);
  204945. }
  204946. else
  204947. {
  204948. s.add ("<error>");
  204949. }
  204950. }
  204951. return s;
  204952. }
  204953. int MidiOutput::getDefaultDeviceIndex()
  204954. {
  204955. return 0;
  204956. }
  204957. static MIDIClientRef globalMidiClient;
  204958. static bool hasGlobalClientBeenCreated = false;
  204959. static bool makeSureClientExists()
  204960. {
  204961. if (! hasGlobalClientBeenCreated)
  204962. {
  204963. String name ("JUCE");
  204964. if (JUCEApplication::getInstance() != 0)
  204965. name = JUCEApplication::getInstance()->getApplicationName();
  204966. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  204967. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  204968. CFRelease (appName);
  204969. }
  204970. return hasGlobalClientBeenCreated;
  204971. }
  204972. class MidiPortAndEndpoint
  204973. {
  204974. public:
  204975. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  204976. : port (port_), endPoint (endPoint_)
  204977. {
  204978. }
  204979. ~MidiPortAndEndpoint()
  204980. {
  204981. if (port != 0)
  204982. MIDIPortDispose (port);
  204983. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  204984. MIDIEndpointDispose (endPoint);
  204985. }
  204986. MIDIPortRef port;
  204987. MIDIEndpointRef endPoint;
  204988. };
  204989. MidiOutput* MidiOutput::openDevice (int index)
  204990. {
  204991. MidiOutput* mo = 0;
  204992. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  204993. {
  204994. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  204995. CFStringRef pname;
  204996. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  204997. {
  204998. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  204999. if (makeSureClientExists())
  205000. {
  205001. MIDIPortRef port;
  205002. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205003. {
  205004. mo = new MidiOutput();
  205005. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  205006. }
  205007. }
  205008. CFRelease (pname);
  205009. }
  205010. }
  205011. return mo;
  205012. }
  205013. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205014. {
  205015. MidiOutput* mo = 0;
  205016. if (makeSureClientExists())
  205017. {
  205018. MIDIEndpointRef endPoint;
  205019. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205020. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205021. {
  205022. mo = new MidiOutput();
  205023. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  205024. }
  205025. CFRelease (name);
  205026. }
  205027. return mo;
  205028. }
  205029. MidiOutput::~MidiOutput()
  205030. {
  205031. delete (MidiPortAndEndpoint*) internal;
  205032. }
  205033. void MidiOutput::reset()
  205034. {
  205035. }
  205036. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205037. {
  205038. return false;
  205039. }
  205040. void MidiOutput::setVolume (float leftVol, float rightVol)
  205041. {
  205042. }
  205043. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205044. {
  205045. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205046. if (message.isSysEx())
  205047. {
  205048. const int maxPacketSize = 256;
  205049. int pos = 0, bytesLeft = message.getRawDataSize();
  205050. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205051. HeapBlock <MIDIPacketList> packets;
  205052. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205053. packets->numPackets = numPackets;
  205054. MIDIPacket* p = packets->packet;
  205055. for (int i = 0; i < numPackets; ++i)
  205056. {
  205057. p->timeStamp = 0;
  205058. p->length = jmin (maxPacketSize, bytesLeft);
  205059. memcpy (p->data, message.getRawData() + pos, p->length);
  205060. pos += p->length;
  205061. bytesLeft -= p->length;
  205062. p = MIDIPacketNext (p);
  205063. }
  205064. if (mpe->port != 0)
  205065. MIDISend (mpe->port, mpe->endPoint, packets);
  205066. else
  205067. MIDIReceived (mpe->endPoint, packets);
  205068. }
  205069. else
  205070. {
  205071. MIDIPacketList packets;
  205072. packets.numPackets = 1;
  205073. packets.packet[0].timeStamp = 0;
  205074. packets.packet[0].length = message.getRawDataSize();
  205075. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205076. if (mpe->port != 0)
  205077. MIDISend (mpe->port, mpe->endPoint, &packets);
  205078. else
  205079. MIDIReceived (mpe->endPoint, &packets);
  205080. }
  205081. }
  205082. const StringArray MidiInput::getDevices()
  205083. {
  205084. StringArray s;
  205085. const ItemCount num = MIDIGetNumberOfSources();
  205086. for (ItemCount i = 0; i < num; ++i)
  205087. {
  205088. MIDIEndpointRef source = MIDIGetSource (i);
  205089. if (source != 0)
  205090. {
  205091. String name (getConnectedEndpointName (source));
  205092. if (name.isEmpty())
  205093. name = "<error>";
  205094. s.add (name);
  205095. }
  205096. else
  205097. {
  205098. s.add ("<error>");
  205099. }
  205100. }
  205101. return s;
  205102. }
  205103. int MidiInput::getDefaultDeviceIndex()
  205104. {
  205105. return 0;
  205106. }
  205107. struct MidiPortAndCallback
  205108. {
  205109. MidiInput* input;
  205110. MidiPortAndEndpoint* portAndEndpoint;
  205111. MidiInputCallback* callback;
  205112. MemoryBlock pendingData;
  205113. int pendingBytes;
  205114. double pendingDataTime;
  205115. bool active;
  205116. void processSysex (const uint8*& d, int& size, const double time)
  205117. {
  205118. if (*d == 0xf0)
  205119. {
  205120. pendingBytes = 0;
  205121. pendingDataTime = time;
  205122. }
  205123. pendingData.ensureSize (pendingBytes + size, false);
  205124. uint8* totalMessage = (uint8*) pendingData.getData();
  205125. uint8* dest = totalMessage + pendingBytes;
  205126. while (size > 0)
  205127. {
  205128. if (pendingBytes > 0 && *d >= 0x80)
  205129. {
  205130. if (*d >= 0xfa || *d == 0xf8)
  205131. {
  205132. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205133. ++d;
  205134. --size;
  205135. }
  205136. else
  205137. {
  205138. if (*d == 0xf7)
  205139. {
  205140. *dest++ = *d++;
  205141. pendingBytes++;
  205142. --size;
  205143. }
  205144. break;
  205145. }
  205146. }
  205147. else
  205148. {
  205149. *dest++ = *d++;
  205150. pendingBytes++;
  205151. --size;
  205152. }
  205153. }
  205154. if (totalMessage [pendingBytes - 1] == 0xf7)
  205155. {
  205156. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205157. pendingBytes = 0;
  205158. }
  205159. else
  205160. {
  205161. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205162. }
  205163. }
  205164. };
  205165. namespace CoreMidiCallbacks
  205166. {
  205167. static CriticalSection callbackLock;
  205168. static VoidArray activeCallbacks;
  205169. }
  205170. static void midiInputProc (const MIDIPacketList* pktlist,
  205171. void* readProcRefCon,
  205172. void* srcConnRefCon)
  205173. {
  205174. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205175. const double originalTime = time;
  205176. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205177. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205178. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205179. {
  205180. const MIDIPacket* packet = &pktlist->packet[0];
  205181. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205182. {
  205183. const uint8* d = (const uint8*) (packet->data);
  205184. int size = packet->length;
  205185. while (size > 0)
  205186. {
  205187. time = originalTime;
  205188. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205189. {
  205190. mpc->processSysex (d, size, time);
  205191. }
  205192. else
  205193. {
  205194. int used = 0;
  205195. const MidiMessage m (d, size, used, 0, time);
  205196. if (used <= 0)
  205197. {
  205198. jassertfalse // malformed midi message
  205199. break;
  205200. }
  205201. else
  205202. {
  205203. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205204. }
  205205. size -= used;
  205206. d += used;
  205207. }
  205208. }
  205209. packet = MIDIPacketNext (packet);
  205210. }
  205211. }
  205212. }
  205213. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205214. {
  205215. MidiInput* mi = 0;
  205216. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205217. {
  205218. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205219. if (endPoint != 0)
  205220. {
  205221. CFStringRef pname;
  205222. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205223. {
  205224. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  205225. if (makeSureClientExists())
  205226. {
  205227. MIDIPortRef port;
  205228. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205229. mpc->active = false;
  205230. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205231. {
  205232. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205233. {
  205234. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205235. mpc->callback = callback;
  205236. mpc->pendingBytes = 0;
  205237. mpc->pendingData.ensureSize (128);
  205238. mi = new MidiInput (getDevices() [index]);
  205239. mpc->input = mi;
  205240. mi->internal = mpc;
  205241. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205242. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205243. }
  205244. else
  205245. {
  205246. OK (MIDIPortDispose (port));
  205247. }
  205248. }
  205249. }
  205250. }
  205251. CFRelease (pname);
  205252. }
  205253. }
  205254. return mi;
  205255. }
  205256. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205257. {
  205258. MidiInput* mi = 0;
  205259. if (makeSureClientExists())
  205260. {
  205261. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205262. mpc->active = false;
  205263. MIDIEndpointRef endPoint;
  205264. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205265. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205266. {
  205267. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205268. mpc->callback = callback;
  205269. mpc->pendingBytes = 0;
  205270. mpc->pendingData.ensureSize (128);
  205271. mi = new MidiInput (deviceName);
  205272. mpc->input = mi;
  205273. mi->internal = mpc;
  205274. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205275. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205276. }
  205277. CFRelease (name);
  205278. }
  205279. return mi;
  205280. }
  205281. MidiInput::MidiInput (const String& name_)
  205282. : name (name_)
  205283. {
  205284. }
  205285. MidiInput::~MidiInput()
  205286. {
  205287. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205288. mpc->active = false;
  205289. {
  205290. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205291. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205292. }
  205293. if (mpc->portAndEndpoint->port != 0)
  205294. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205295. delete mpc->portAndEndpoint;
  205296. delete mpc;
  205297. }
  205298. void MidiInput::start()
  205299. {
  205300. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205301. ((MidiPortAndCallback*) internal)->active = true;
  205302. }
  205303. void MidiInput::stop()
  205304. {
  205305. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205306. ((MidiPortAndCallback*) internal)->active = false;
  205307. }
  205308. #undef log
  205309. #else
  205310. MidiOutput::~MidiOutput()
  205311. {
  205312. }
  205313. void MidiOutput::reset()
  205314. {
  205315. }
  205316. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205317. {
  205318. return false;
  205319. }
  205320. void MidiOutput::setVolume (float leftVol, float rightVol)
  205321. {
  205322. }
  205323. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205324. {
  205325. }
  205326. const StringArray MidiOutput::getDevices()
  205327. {
  205328. return StringArray();
  205329. }
  205330. MidiOutput* MidiOutput::openDevice (int index)
  205331. {
  205332. return 0;
  205333. }
  205334. const StringArray MidiInput::getDevices()
  205335. {
  205336. return StringArray();
  205337. }
  205338. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205339. {
  205340. return 0;
  205341. }
  205342. #endif
  205343. #endif
  205344. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205345. #else
  205346. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205347. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205348. // compiled on its own).
  205349. #if JUCE_INCLUDED_FILE
  205350. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205351. #define SUPPORT_10_4_FONTS 1
  205352. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205353. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205354. #define SUPPORT_ONLY_10_4_FONTS 1
  205355. #endif
  205356. END_JUCE_NAMESPACE
  205357. @interface NSFont (PrivateHack)
  205358. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205359. @end
  205360. BEGIN_JUCE_NAMESPACE
  205361. #endif
  205362. class MacTypeface : public Typeface
  205363. {
  205364. public:
  205365. MacTypeface (const Font& font)
  205366. : Typeface (font.getTypefaceName())
  205367. {
  205368. const ScopedAutoReleasePool pool;
  205369. renderingTransform = CGAffineTransformIdentity;
  205370. bool needsItalicTransform = false;
  205371. #if JUCE_IPHONE
  205372. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205373. if (font.isItalic() || font.isBold())
  205374. {
  205375. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205376. for (NSString* i in familyFonts)
  205377. {
  205378. const String fn (nsStringToJuce (i));
  205379. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  205380. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  205381. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  205382. || afterDash.containsIgnoreCase ("italic")
  205383. || fn.endsWithIgnoreCase ("oblique")
  205384. || fn.endsWithIgnoreCase ("italic");
  205385. if (probablyBold == font.isBold()
  205386. && probablyItalic == font.isItalic())
  205387. {
  205388. fontName = i;
  205389. needsItalicTransform = false;
  205390. break;
  205391. }
  205392. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205393. {
  205394. fontName = i;
  205395. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205396. }
  205397. }
  205398. if (needsItalicTransform)
  205399. renderingTransform.c = 0.15f;
  205400. }
  205401. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205402. const int ascender = abs (CGFontGetAscent (fontRef));
  205403. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205404. ascent = ascender / totalHeight;
  205405. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205406. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205407. #else
  205408. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205409. if (font.isItalic())
  205410. {
  205411. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205412. toHaveTrait: NSItalicFontMask];
  205413. if (newFont == nsFont)
  205414. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205415. nsFont = newFont;
  205416. }
  205417. if (font.isBold())
  205418. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205419. [nsFont retain];
  205420. ascent = fabsf ((float) [nsFont ascender]);
  205421. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205422. ascent /= totalSize;
  205423. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205424. if (needsItalicTransform)
  205425. {
  205426. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205427. renderingTransform.c = 0.15f;
  205428. }
  205429. #if SUPPORT_ONLY_10_4_FONTS
  205430. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205431. if (atsFont == 0)
  205432. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205433. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205434. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205435. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205436. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205437. #else
  205438. #if SUPPORT_10_4_FONTS
  205439. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205440. {
  205441. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205442. if (atsFont == 0)
  205443. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205444. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205445. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205446. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205447. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205448. }
  205449. else
  205450. #endif
  205451. {
  205452. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205453. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205454. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205455. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205456. }
  205457. #endif
  205458. #endif
  205459. }
  205460. ~MacTypeface()
  205461. {
  205462. #if ! JUCE_IPHONE
  205463. [nsFont release];
  205464. #endif
  205465. if (fontRef != 0)
  205466. CGFontRelease (fontRef);
  205467. }
  205468. float getAscent() const
  205469. {
  205470. return ascent;
  205471. }
  205472. float getDescent() const
  205473. {
  205474. return 1.0f - ascent;
  205475. }
  205476. float getStringWidth (const String& text)
  205477. {
  205478. if (fontRef == 0 || text.isEmpty())
  205479. return 0;
  205480. const int length = text.length();
  205481. HeapBlock <CGGlyph> glyphs;
  205482. createGlyphsForString (text, length, glyphs);
  205483. float x = 0;
  205484. #if SUPPORT_ONLY_10_4_FONTS
  205485. HeapBlock <NSSize> advances (length);
  205486. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205487. for (int i = 0; i < length; ++i)
  205488. x += advances[i].width;
  205489. #else
  205490. #if SUPPORT_10_4_FONTS
  205491. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205492. {
  205493. HeapBlock <NSSize> advances (length);
  205494. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205495. for (int i = 0; i < length; ++i)
  205496. x += advances[i].width;
  205497. }
  205498. else
  205499. #endif
  205500. {
  205501. HeapBlock <int> advances (length);
  205502. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205503. for (int i = 0; i < length; ++i)
  205504. x += advances[i];
  205505. }
  205506. #endif
  205507. return x * unitsToHeightScaleFactor;
  205508. }
  205509. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205510. {
  205511. xOffsets.add (0);
  205512. if (fontRef == 0 || text.isEmpty())
  205513. return;
  205514. const int length = text.length();
  205515. HeapBlock <CGGlyph> glyphs;
  205516. createGlyphsForString (text, length, glyphs);
  205517. #if SUPPORT_ONLY_10_4_FONTS
  205518. HeapBlock <NSSize> advances (length);
  205519. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205520. int x = 0;
  205521. for (int i = 0; i < length; ++i)
  205522. {
  205523. x += advances[i].width;
  205524. xOffsets.add (x * unitsToHeightScaleFactor);
  205525. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205526. }
  205527. #else
  205528. #if SUPPORT_10_4_FONTS
  205529. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205530. {
  205531. HeapBlock <NSSize> advances (length);
  205532. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205533. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205534. float x = 0;
  205535. for (int i = 0; i < length; ++i)
  205536. {
  205537. x += advances[i].width;
  205538. xOffsets.add (x * unitsToHeightScaleFactor);
  205539. resultGlyphs.add (nsGlyphs[i]);
  205540. }
  205541. }
  205542. else
  205543. #endif
  205544. {
  205545. HeapBlock <int> advances (length);
  205546. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205547. {
  205548. int x = 0;
  205549. for (int i = 0; i < length; ++i)
  205550. {
  205551. x += advances [i];
  205552. xOffsets.add (x * unitsToHeightScaleFactor);
  205553. resultGlyphs.add (glyphs[i]);
  205554. }
  205555. }
  205556. }
  205557. #endif
  205558. }
  205559. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205560. {
  205561. #if JUCE_IPHONE
  205562. return false;
  205563. #else
  205564. if (nsFont == 0)
  205565. return false;
  205566. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205567. jassert (path.isEmpty());
  205568. const ScopedAutoReleasePool pool;
  205569. NSBezierPath* bez = [NSBezierPath bezierPath];
  205570. [bez moveToPoint: NSMakePoint (0, 0)];
  205571. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205572. inFont: nsFont];
  205573. for (int i = 0; i < [bez elementCount]; ++i)
  205574. {
  205575. NSPoint p[3];
  205576. switch ([bez elementAtIndex: i associatedPoints: p])
  205577. {
  205578. case NSMoveToBezierPathElement:
  205579. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205580. break;
  205581. case NSLineToBezierPathElement:
  205582. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205583. break;
  205584. case NSCurveToBezierPathElement:
  205585. path.cubicTo ((float) p[0].x, (float) -p[0].y, (float) p[1].x, (float) -p[1].y, (float) p[2].x, (float) -p[2].y);
  205586. break;
  205587. case NSClosePathBezierPathElement:
  205588. path.closeSubPath();
  205589. break;
  205590. default:
  205591. jassertfalse
  205592. break;
  205593. }
  205594. }
  205595. path.applyTransform (pathTransform);
  205596. return true;
  205597. #endif
  205598. }
  205599. juce_UseDebuggingNewOperator
  205600. CGFontRef fontRef;
  205601. float fontHeightToCGSizeFactor;
  205602. CGAffineTransform renderingTransform;
  205603. private:
  205604. float ascent, unitsToHeightScaleFactor;
  205605. #if JUCE_IPHONE
  205606. #else
  205607. NSFont* nsFont;
  205608. AffineTransform pathTransform;
  205609. #endif
  205610. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205611. {
  205612. #if SUPPORT_10_4_FONTS
  205613. #if ! SUPPORT_ONLY_10_4_FONTS
  205614. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205615. #endif
  205616. {
  205617. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205618. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205619. for (int i = 0; i < length; ++i)
  205620. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205621. return;
  205622. }
  205623. #endif
  205624. #if ! SUPPORT_ONLY_10_4_FONTS
  205625. if (charToGlyphMapper == 0)
  205626. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205627. glyphs.malloc (length);
  205628. for (int i = 0; i < length; ++i)
  205629. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205630. #endif
  205631. }
  205632. #if ! SUPPORT_ONLY_10_4_FONTS
  205633. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205634. class CharToGlyphMapper
  205635. {
  205636. public:
  205637. CharToGlyphMapper (CGFontRef fontRef)
  205638. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205639. idRangeOffset (0), glyphIndexes (0)
  205640. {
  205641. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205642. if (cmapTable != 0)
  205643. {
  205644. const int numSubtables = getValue16 (cmapTable, 2);
  205645. for (int i = 0; i < numSubtables; ++i)
  205646. {
  205647. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205648. {
  205649. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205650. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205651. {
  205652. const int length = getValue16 (cmapTable, offset + 2);
  205653. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205654. segCount = segCountX2 / 2;
  205655. const int endCodeOffset = offset + 14;
  205656. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205657. const int idDeltaOffset = startCodeOffset + segCountX2;
  205658. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205659. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205660. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205661. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205662. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205663. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205664. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205665. }
  205666. break;
  205667. }
  205668. }
  205669. CFRelease (cmapTable);
  205670. }
  205671. }
  205672. ~CharToGlyphMapper()
  205673. {
  205674. if (endCode != 0)
  205675. {
  205676. CFRelease (endCode);
  205677. CFRelease (startCode);
  205678. CFRelease (idDelta);
  205679. CFRelease (idRangeOffset);
  205680. CFRelease (glyphIndexes);
  205681. }
  205682. }
  205683. int getGlyphForCharacter (const juce_wchar c) const
  205684. {
  205685. for (int i = 0; i < segCount; ++i)
  205686. {
  205687. if (getValue16 (endCode, i * 2) >= c)
  205688. {
  205689. const int start = getValue16 (startCode, i * 2);
  205690. if (start > c)
  205691. break;
  205692. const int delta = getValue16 (idDelta, i * 2);
  205693. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205694. if (rangeOffset == 0)
  205695. return delta + c;
  205696. else
  205697. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205698. }
  205699. }
  205700. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205701. return jmax (-1, c - 29);
  205702. }
  205703. private:
  205704. int segCount;
  205705. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205706. static uint16 getValue16 (CFDataRef data, const int index)
  205707. {
  205708. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205709. }
  205710. static uint32 getValue32 (CFDataRef data, const int index)
  205711. {
  205712. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205713. }
  205714. };
  205715. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205716. #endif
  205717. MacTypeface (const MacTypeface&);
  205718. MacTypeface& operator= (const MacTypeface&);
  205719. };
  205720. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205721. {
  205722. return new MacTypeface (font);
  205723. }
  205724. const StringArray Font::findAllTypefaceNames()
  205725. {
  205726. StringArray names;
  205727. const ScopedAutoReleasePool pool;
  205728. #if JUCE_IPHONE
  205729. NSArray* fonts = [UIFont familyNames];
  205730. #else
  205731. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205732. #endif
  205733. for (unsigned int i = 0; i < [fonts count]; ++i)
  205734. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205735. names.sort (true);
  205736. return names;
  205737. }
  205738. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  205739. {
  205740. #if JUCE_IPHONE
  205741. defaultSans = "Helvetica";
  205742. defaultSerif = "Times New Roman";
  205743. defaultFixed = "Courier New";
  205744. #else
  205745. defaultSans = "Lucida Grande";
  205746. defaultSerif = "Times New Roman";
  205747. defaultFixed = "Monaco";
  205748. #endif
  205749. }
  205750. #endif
  205751. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205752. // (must go before juce_mac_CoreGraphicsContext.mm)
  205753. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205754. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205755. // compiled on its own).
  205756. #if JUCE_INCLUDED_FILE
  205757. class CoreGraphicsImage : public Image
  205758. {
  205759. public:
  205760. CoreGraphicsImage (const PixelFormat format_,
  205761. const int imageWidth_,
  205762. const int imageHeight_,
  205763. const bool clearImage)
  205764. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205765. {
  205766. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205767. : CGColorSpaceCreateDeviceRGB();
  205768. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205769. colourSpace, getCGImageFlags (*this));
  205770. CGColorSpaceRelease (colourSpace);
  205771. }
  205772. ~CoreGraphicsImage()
  205773. {
  205774. CGContextRelease (context);
  205775. }
  205776. LowLevelGraphicsContext* createLowLevelContext();
  205777. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205778. {
  205779. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205780. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205781. {
  205782. return CGBitmapContextCreateImage (nativeImage->context);
  205783. }
  205784. else
  205785. {
  205786. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205787. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205788. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205789. 8, srcData.pixelStride * 8, srcData.lineStride,
  205790. colourSpace, getCGImageFlags (juceImage), provider,
  205791. 0, true, kCGRenderingIntentDefault);
  205792. CGDataProviderRelease (provider);
  205793. return imageRef;
  205794. }
  205795. }
  205796. #if JUCE_MAC
  205797. static NSImage* createNSImage (const Image& image)
  205798. {
  205799. const ScopedAutoReleasePool pool;
  205800. NSImage* im = [[NSImage alloc] init];
  205801. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205802. [im lockFocus];
  205803. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205804. CGImageRef imageRef = createImage (image, false, colourSpace);
  205805. CGColorSpaceRelease (colourSpace);
  205806. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205807. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205808. CGImageRelease (imageRef);
  205809. [im unlockFocus];
  205810. return im;
  205811. }
  205812. #endif
  205813. CGContextRef context;
  205814. private:
  205815. static CGBitmapInfo getCGImageFlags (const Image& image)
  205816. {
  205817. #if JUCE_BIG_ENDIAN
  205818. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205819. #else
  205820. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205821. #endif
  205822. }
  205823. };
  205824. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205825. {
  205826. #if USE_COREGRAPHICS_RENDERING
  205827. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205828. #else
  205829. return new Image (format, imageWidth, imageHeight, clearImage);
  205830. #endif
  205831. }
  205832. class CoreGraphicsContext : public LowLevelGraphicsContext
  205833. {
  205834. public:
  205835. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205836. : context (context_),
  205837. flipHeight (flipHeight_),
  205838. state (new SavedState()),
  205839. numGradientLookupEntries (0)
  205840. {
  205841. CGContextRetain (context);
  205842. CGContextSaveGState(context);
  205843. CGContextSetShouldSmoothFonts (context, true);
  205844. CGContextSetShouldAntialias (context, true);
  205845. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205846. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205847. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205848. gradientCallbacks.version = 0;
  205849. gradientCallbacks.evaluate = gradientCallback;
  205850. gradientCallbacks.releaseInfo = 0;
  205851. setFont (Font());
  205852. }
  205853. ~CoreGraphicsContext()
  205854. {
  205855. CGContextRestoreGState (context);
  205856. CGContextRelease (context);
  205857. CGColorSpaceRelease (rgbColourSpace);
  205858. CGColorSpaceRelease (greyColourSpace);
  205859. }
  205860. bool isVectorDevice() const { return false; }
  205861. void setOrigin (int x, int y)
  205862. {
  205863. CGContextTranslateCTM (context, x, -y);
  205864. }
  205865. bool clipToRectangle (const Rectangle<int>& r)
  205866. {
  205867. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205868. return ! isClipEmpty();
  205869. }
  205870. bool clipToRectangleList (const RectangleList& clipRegion)
  205871. {
  205872. if (clipRegion.isEmpty())
  205873. {
  205874. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205875. return false;
  205876. }
  205877. else
  205878. {
  205879. const int numRects = clipRegion.getNumRectangles();
  205880. HeapBlock <CGRect> rects (numRects);
  205881. for (int i = 0; i < numRects; ++i)
  205882. {
  205883. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205884. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205885. }
  205886. CGContextClipToRects (context, rects, numRects);
  205887. return ! isClipEmpty();
  205888. }
  205889. }
  205890. void excludeClipRectangle (const Rectangle<int>& r)
  205891. {
  205892. RectangleList remaining (getClipBounds());
  205893. remaining.subtract (r);
  205894. clipToRectangleList (remaining);
  205895. }
  205896. void clipToPath (const Path& path, const AffineTransform& transform)
  205897. {
  205898. createPath (path, transform);
  205899. CGContextClip (context);
  205900. }
  205901. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205902. {
  205903. if (! transform.isSingularity())
  205904. {
  205905. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205906. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205907. flip();
  205908. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205909. applyTransform (t);
  205910. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205911. CGContextClipToMask (context, r, image);
  205912. applyTransform (t.inverted());
  205913. flip();
  205914. CGImageRelease (image);
  205915. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205916. }
  205917. }
  205918. bool clipRegionIntersects (const Rectangle<int>& r)
  205919. {
  205920. return getClipBounds().intersects (r);
  205921. }
  205922. const Rectangle<int> getClipBounds() const
  205923. {
  205924. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205925. return Rectangle<int> (roundToInt (bounds.origin.x),
  205926. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205927. roundToInt (bounds.size.width),
  205928. roundToInt (bounds.size.height));
  205929. }
  205930. bool isClipEmpty() const
  205931. {
  205932. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205933. }
  205934. void saveState()
  205935. {
  205936. CGContextSaveGState (context);
  205937. stateStack.add (new SavedState (*state));
  205938. }
  205939. void restoreState()
  205940. {
  205941. CGContextRestoreGState (context);
  205942. SavedState* const top = stateStack.getLast();
  205943. if (top != 0)
  205944. {
  205945. state = top;
  205946. stateStack.removeLast (1, false);
  205947. }
  205948. else
  205949. {
  205950. jassertfalse // trying to pop with an empty stack!
  205951. }
  205952. }
  205953. void setFill (const FillType& fillType)
  205954. {
  205955. state->fillType = fillType;
  205956. if (fillType.isColour())
  205957. {
  205958. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  205959. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  205960. CGContextSetAlpha (context, 1.0f);
  205961. }
  205962. }
  205963. void setOpacity (float newOpacity)
  205964. {
  205965. state->fillType.setOpacity (newOpacity);
  205966. setFill (state->fillType);
  205967. }
  205968. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  205969. {
  205970. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  205971. ? kCGInterpolationLow
  205972. : kCGInterpolationHigh);
  205973. }
  205974. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  205975. {
  205976. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205977. if (replaceExistingContents)
  205978. {
  205979. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205980. CGContextClearRect (context, cgRect);
  205981. #else
  205982. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205983. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  205984. CGContextClearRect (context, cgRect);
  205985. else
  205986. #endif
  205987. CGContextSetBlendMode (context, kCGBlendModeCopy);
  205988. #endif
  205989. fillRect (r, false);
  205990. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205991. }
  205992. else
  205993. {
  205994. if (state->fillType.isColour())
  205995. {
  205996. CGContextFillRect (context, cgRect);
  205997. }
  205998. else if (state->fillType.isGradient())
  205999. {
  206000. CGContextSaveGState (context);
  206001. CGContextClipToRect (context, cgRect);
  206002. drawGradient();
  206003. CGContextRestoreGState (context);
  206004. }
  206005. else
  206006. {
  206007. CGContextSaveGState (context);
  206008. CGContextClipToRect (context, cgRect);
  206009. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206010. CGContextRestoreGState (context);
  206011. }
  206012. }
  206013. }
  206014. void fillPath (const Path& path, const AffineTransform& transform)
  206015. {
  206016. CGContextSaveGState (context);
  206017. if (state->fillType.isColour())
  206018. {
  206019. flip();
  206020. applyTransform (transform);
  206021. createPath (path);
  206022. if (path.isUsingNonZeroWinding())
  206023. CGContextFillPath (context);
  206024. else
  206025. CGContextEOFillPath (context);
  206026. }
  206027. else
  206028. {
  206029. createPath (path, transform);
  206030. if (path.isUsingNonZeroWinding())
  206031. CGContextClip (context);
  206032. else
  206033. CGContextEOClip (context);
  206034. if (state->fillType.isGradient())
  206035. drawGradient();
  206036. else
  206037. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206038. }
  206039. CGContextRestoreGState (context);
  206040. }
  206041. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206042. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206043. {
  206044. jassert (sourceImage.getBounds().contains (srcClip));
  206045. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206046. CGImageRef image = fullImage;
  206047. if (srcClip != sourceImage.getBounds())
  206048. {
  206049. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206050. srcClip.getWidth(), srcClip.getHeight()));
  206051. CGImageRelease (fullImage);
  206052. }
  206053. CGContextSaveGState (context);
  206054. CGContextSetAlpha (context, state->fillType.getOpacity());
  206055. flip();
  206056. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206057. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206058. if (fillEntireClipAsTiles)
  206059. {
  206060. #if JUCE_IPHONE
  206061. CGContextDrawTiledImage (context, imageRect, image);
  206062. #else
  206063. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206064. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206065. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206066. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206067. CGContextDrawTiledImage (context, imageRect, image);
  206068. else
  206069. #endif
  206070. {
  206071. // Fallback to manually doing a tiled fill on 10.4
  206072. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206073. const int iw = srcClip.getWidth();
  206074. const int ih = srcClip.getHeight();
  206075. int x = 0, y = 0;
  206076. while (x > clip.origin.x) x -= iw;
  206077. while (y > clip.origin.y) y -= ih;
  206078. const int right = (int) (clip.origin.x + clip.size.width);
  206079. const int bottom = (int) (clip.origin.y + clip.size.height);
  206080. while (y < bottom)
  206081. {
  206082. for (int x2 = x; x2 < right; x2 += iw)
  206083. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206084. y += ih;
  206085. }
  206086. }
  206087. #endif
  206088. }
  206089. else
  206090. {
  206091. CGContextDrawImage (context, imageRect, image);
  206092. }
  206093. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206094. CGContextRestoreGState (context);
  206095. }
  206096. void drawLine (double x1, double y1, double x2, double y2)
  206097. {
  206098. CGContextSetLineCap (context, kCGLineCapSquare);
  206099. CGContextSetLineWidth (context, 1.0f);
  206100. CGContextSetRGBStrokeColor (context,
  206101. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206102. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206103. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206104. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206105. CGContextStrokeLineSegments (context, line, 1);
  206106. }
  206107. void drawVerticalLine (const int x, double top, double bottom)
  206108. {
  206109. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206110. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206111. #else
  206112. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206113. // the x co-ord slightly to trick it..
  206114. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206115. #endif
  206116. }
  206117. void drawHorizontalLine (const int y, double left, double right)
  206118. {
  206119. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206120. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206121. #else
  206122. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206123. // the x co-ord slightly to trick it..
  206124. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206125. #endif
  206126. }
  206127. void setFont (const Font& newFont)
  206128. {
  206129. if (state->font != newFont)
  206130. {
  206131. state->fontRef = 0;
  206132. state->font = newFont;
  206133. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206134. if (mf != 0)
  206135. {
  206136. state->fontRef = mf->fontRef;
  206137. CGContextSetFont (context, state->fontRef);
  206138. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206139. state->fontTransform = mf->renderingTransform;
  206140. state->fontTransform.a *= state->font.getHorizontalScale();
  206141. CGContextSetTextMatrix (context, state->fontTransform);
  206142. }
  206143. }
  206144. }
  206145. const Font getFont()
  206146. {
  206147. return state->font;
  206148. }
  206149. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206150. {
  206151. if (state->fontRef != 0 && state->fillType.isColour())
  206152. {
  206153. if (transform.isOnlyTranslation())
  206154. {
  206155. CGGlyph g = glyphNumber;
  206156. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206157. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206158. }
  206159. else
  206160. {
  206161. CGContextSaveGState (context);
  206162. flip();
  206163. applyTransform (transform);
  206164. CGAffineTransform t = state->fontTransform;
  206165. t.d = -t.d;
  206166. CGContextSetTextMatrix (context, t);
  206167. CGGlyph g = glyphNumber;
  206168. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206169. CGContextSetTextMatrix (context, state->fontTransform);
  206170. CGContextRestoreGState (context);
  206171. }
  206172. }
  206173. else
  206174. {
  206175. Path p;
  206176. Font& f = state->font;
  206177. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206178. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206179. .followedBy (transform));
  206180. }
  206181. }
  206182. private:
  206183. CGContextRef context;
  206184. const CGFloat flipHeight;
  206185. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206186. CGFunctionCallbacks gradientCallbacks;
  206187. struct SavedState
  206188. {
  206189. SavedState()
  206190. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206191. {
  206192. }
  206193. SavedState (const SavedState& other)
  206194. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206195. fontTransform (other.fontTransform)
  206196. {
  206197. }
  206198. ~SavedState()
  206199. {
  206200. }
  206201. FillType fillType;
  206202. Font font;
  206203. CGFontRef fontRef;
  206204. CGAffineTransform fontTransform;
  206205. };
  206206. ScopedPointer <SavedState> state;
  206207. OwnedArray <SavedState> stateStack;
  206208. HeapBlock <PixelARGB> gradientLookupTable;
  206209. int numGradientLookupEntries;
  206210. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206211. {
  206212. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206213. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206214. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206215. colour.unpremultiply();
  206216. outData[0] = colour.getRed() / 255.0f;
  206217. outData[1] = colour.getGreen() / 255.0f;
  206218. outData[2] = colour.getBlue() / 255.0f;
  206219. outData[3] = colour.getAlpha() / 255.0f;
  206220. }
  206221. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206222. {
  206223. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206224. --numGradientLookupEntries;
  206225. CGShadingRef result = 0;
  206226. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  206227. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206228. if (gradient.isRadial)
  206229. {
  206230. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206231. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206232. function, true, true);
  206233. }
  206234. else
  206235. {
  206236. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206237. CGPointMake (gradient.x2, gradient.y2),
  206238. function, true, true);
  206239. }
  206240. CGFunctionRelease (function);
  206241. return result;
  206242. }
  206243. void drawGradient()
  206244. {
  206245. flip();
  206246. applyTransform (state->fillType.transform);
  206247. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206248. // you draw a gradient with high quality interp enabled).
  206249. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206250. CGContextSetAlpha (context, state->fillType.getOpacity());
  206251. CGContextDrawShading (context, shading);
  206252. CGShadingRelease (shading);
  206253. }
  206254. void createPath (const Path& path) const
  206255. {
  206256. CGContextBeginPath (context);
  206257. Path::Iterator i (path);
  206258. while (i.next())
  206259. {
  206260. switch (i.elementType)
  206261. {
  206262. case Path::Iterator::startNewSubPath:
  206263. CGContextMoveToPoint (context, i.x1, i.y1);
  206264. break;
  206265. case Path::Iterator::lineTo:
  206266. CGContextAddLineToPoint (context, i.x1, i.y1);
  206267. break;
  206268. case Path::Iterator::quadraticTo:
  206269. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206270. break;
  206271. case Path::Iterator::cubicTo:
  206272. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206273. break;
  206274. case Path::Iterator::closePath:
  206275. CGContextClosePath (context); break;
  206276. default:
  206277. jassertfalse
  206278. break;
  206279. }
  206280. }
  206281. }
  206282. void createPath (const Path& path, const AffineTransform& transform) const
  206283. {
  206284. CGContextBeginPath (context);
  206285. Path::Iterator i (path);
  206286. while (i.next())
  206287. {
  206288. switch (i.elementType)
  206289. {
  206290. case Path::Iterator::startNewSubPath:
  206291. transform.transformPoint (i.x1, i.y1);
  206292. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206293. break;
  206294. case Path::Iterator::lineTo:
  206295. transform.transformPoint (i.x1, i.y1);
  206296. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206297. break;
  206298. case Path::Iterator::quadraticTo:
  206299. transform.transformPoint (i.x1, i.y1);
  206300. transform.transformPoint (i.x2, i.y2);
  206301. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206302. break;
  206303. case Path::Iterator::cubicTo:
  206304. transform.transformPoint (i.x1, i.y1);
  206305. transform.transformPoint (i.x2, i.y2);
  206306. transform.transformPoint (i.x3, i.y3);
  206307. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206308. break;
  206309. case Path::Iterator::closePath:
  206310. CGContextClosePath (context); break;
  206311. default:
  206312. jassertfalse
  206313. break;
  206314. }
  206315. }
  206316. }
  206317. static Image* createAlphaChannelImage (const Image& im)
  206318. {
  206319. if (im.getFormat() == Image::SingleChannel)
  206320. return const_cast <Image*> (&im);
  206321. return im.createCopyOfAlphaChannel();
  206322. }
  206323. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206324. {
  206325. if (im.getFormat() != Image::SingleChannel)
  206326. delete alphaIm;
  206327. }
  206328. void flip() const
  206329. {
  206330. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206331. }
  206332. void applyTransform (const AffineTransform& transform) const
  206333. {
  206334. CGAffineTransform t;
  206335. t.a = transform.mat00;
  206336. t.b = transform.mat10;
  206337. t.c = transform.mat01;
  206338. t.d = transform.mat11;
  206339. t.tx = transform.mat02;
  206340. t.ty = transform.mat12;
  206341. CGContextConcatCTM (context, t);
  206342. }
  206343. CoreGraphicsContext (const CoreGraphicsContext&);
  206344. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206345. };
  206346. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206347. {
  206348. return new CoreGraphicsContext (context, imageHeight);
  206349. }
  206350. #endif
  206351. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206352. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206353. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206354. // compiled on its own).
  206355. #if JUCE_INCLUDED_FILE
  206356. class NSViewComponentPeer;
  206357. END_JUCE_NAMESPACE
  206358. #define JuceNSView MakeObjCClassName(JuceNSView)
  206359. @interface JuceNSView : NSView<NSTextInput>
  206360. {
  206361. @public
  206362. NSViewComponentPeer* owner;
  206363. NSNotificationCenter* notificationCenter;
  206364. String* stringBeingComposed;
  206365. bool textWasInserted;
  206366. }
  206367. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206368. - (void) dealloc;
  206369. - (BOOL) isOpaque;
  206370. - (void) drawRect: (NSRect) r;
  206371. - (void) mouseDown: (NSEvent*) ev;
  206372. - (void) asyncMouseDown: (NSEvent*) ev;
  206373. - (void) mouseUp: (NSEvent*) ev;
  206374. - (void) asyncMouseUp: (NSEvent*) ev;
  206375. - (void) mouseDragged: (NSEvent*) ev;
  206376. - (void) mouseMoved: (NSEvent*) ev;
  206377. - (void) mouseEntered: (NSEvent*) ev;
  206378. - (void) mouseExited: (NSEvent*) ev;
  206379. - (void) rightMouseDown: (NSEvent*) ev;
  206380. - (void) rightMouseDragged: (NSEvent*) ev;
  206381. - (void) rightMouseUp: (NSEvent*) ev;
  206382. - (void) otherMouseDown: (NSEvent*) ev;
  206383. - (void) otherMouseDragged: (NSEvent*) ev;
  206384. - (void) otherMouseUp: (NSEvent*) ev;
  206385. - (void) scrollWheel: (NSEvent*) ev;
  206386. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206387. - (void) frameChanged: (NSNotification*) n;
  206388. - (void) viewDidMoveToWindow;
  206389. - (void) keyDown: (NSEvent*) ev;
  206390. - (void) keyUp: (NSEvent*) ev;
  206391. // NSTextInput Methods
  206392. - (void) insertText: (id) aString;
  206393. - (void) doCommandBySelector: (SEL) aSelector;
  206394. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206395. - (void) unmarkText;
  206396. - (BOOL) hasMarkedText;
  206397. - (long) conversationIdentifier;
  206398. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206399. - (NSRange) markedRange;
  206400. - (NSRange) selectedRange;
  206401. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206402. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206403. - (NSArray*) validAttributesForMarkedText;
  206404. - (void) flagsChanged: (NSEvent*) ev;
  206405. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206406. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206407. #endif
  206408. - (BOOL) becomeFirstResponder;
  206409. - (BOOL) resignFirstResponder;
  206410. - (BOOL) acceptsFirstResponder;
  206411. - (void) asyncRepaint: (id) rect;
  206412. - (NSArray*) getSupportedDragTypes;
  206413. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206414. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206415. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206416. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206417. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206418. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206419. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206420. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206421. @end
  206422. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206423. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206424. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206425. #else
  206426. @interface JuceNSWindow : NSWindow
  206427. #endif
  206428. {
  206429. @private
  206430. NSViewComponentPeer* owner;
  206431. bool isZooming;
  206432. }
  206433. - (void) setOwner: (NSViewComponentPeer*) owner;
  206434. - (BOOL) canBecomeKeyWindow;
  206435. - (void) becomeKeyWindow;
  206436. - (BOOL) windowShouldClose: (id) window;
  206437. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206438. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206439. - (void) zoom: (id) sender;
  206440. @end
  206441. BEGIN_JUCE_NAMESPACE
  206442. class NSViewComponentPeer : public ComponentPeer
  206443. {
  206444. public:
  206445. NSViewComponentPeer (Component* const component,
  206446. const int windowStyleFlags,
  206447. NSView* viewToAttachTo);
  206448. ~NSViewComponentPeer();
  206449. void* getNativeHandle() const;
  206450. void setVisible (bool shouldBeVisible);
  206451. void setTitle (const String& title);
  206452. void setPosition (int x, int y);
  206453. void setSize (int w, int h);
  206454. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206455. const Rectangle<int> getBounds (const bool global) const;
  206456. const Rectangle<int> getBounds() const;
  206457. const Point<int> getScreenPosition() const;
  206458. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206459. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206460. void setMinimised (bool shouldBeMinimised);
  206461. bool isMinimised() const;
  206462. void setFullScreen (bool shouldBeFullScreen);
  206463. bool isFullScreen() const;
  206464. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206465. const BorderSize getFrameSize() const;
  206466. bool setAlwaysOnTop (bool alwaysOnTop);
  206467. void toFront (bool makeActiveWindow);
  206468. void toBehind (ComponentPeer* other);
  206469. void setIcon (const Image& newIcon);
  206470. const StringArray getAvailableRenderingEngines() throw();
  206471. int getCurrentRenderingEngine() throw();
  206472. void setCurrentRenderingEngine (int index) throw();
  206473. virtual void redirectMouseDown (NSEvent* ev);
  206474. virtual void redirectMouseUp (NSEvent* ev);
  206475. virtual void redirectMouseDrag (NSEvent* ev);
  206476. virtual void redirectMouseMove (NSEvent* ev);
  206477. virtual void redirectMouseEnter (NSEvent* ev);
  206478. virtual void redirectMouseExit (NSEvent* ev);
  206479. virtual void redirectMouseWheel (NSEvent* ev);
  206480. void sendMouseEvent (NSEvent* ev);
  206481. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206482. virtual bool redirectKeyDown (NSEvent* ev);
  206483. virtual bool redirectKeyUp (NSEvent* ev);
  206484. virtual void redirectModKeyChange (NSEvent* ev);
  206485. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206486. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206487. #endif
  206488. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206489. virtual bool isOpaque();
  206490. virtual void drawRect (NSRect r);
  206491. virtual bool canBecomeKeyWindow();
  206492. virtual bool windowShouldClose();
  206493. virtual void redirectMovedOrResized();
  206494. virtual void viewMovedToWindow();
  206495. virtual NSRect constrainRect (NSRect r);
  206496. static void showArrowCursorIfNeeded();
  206497. static void updateModifiers (NSEvent* e);
  206498. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206499. static int getKeyCodeFromEvent (NSEvent* ev)
  206500. {
  206501. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206502. int keyCode = unmodified[0];
  206503. if (keyCode == 0x19) // (backwards-tab)
  206504. keyCode = '\t';
  206505. else if (keyCode == 0x03) // (enter)
  206506. keyCode = '\r';
  206507. return keyCode;
  206508. }
  206509. static int64 getMouseTime (NSEvent* e)
  206510. {
  206511. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206512. + (int64) ([e timestamp] * 1000.0);
  206513. }
  206514. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206515. {
  206516. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206517. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206518. }
  206519. static int getModifierForButtonNumber (const NSInteger num)
  206520. {
  206521. return num == 0 ? ModifierKeys::leftButtonModifier
  206522. : (num == 1 ? ModifierKeys::rightButtonModifier
  206523. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206524. }
  206525. virtual void viewFocusGain();
  206526. virtual void viewFocusLoss();
  206527. bool isFocused() const;
  206528. void grabFocus();
  206529. void textInputRequired (const Point<int>& position);
  206530. void repaint (int x, int y, int w, int h);
  206531. void performAnyPendingRepaintsNow();
  206532. juce_UseDebuggingNewOperator
  206533. NSWindow* window;
  206534. JuceNSView* view;
  206535. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206536. static ModifierKeys currentModifiers;
  206537. static ComponentPeer* currentlyFocusedPeer;
  206538. static Array<int> keysCurrentlyDown;
  206539. };
  206540. END_JUCE_NAMESPACE
  206541. @implementation JuceNSView
  206542. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206543. withFrame: (NSRect) frame
  206544. {
  206545. [super initWithFrame: frame];
  206546. owner = owner_;
  206547. stringBeingComposed = 0;
  206548. textWasInserted = false;
  206549. notificationCenter = [NSNotificationCenter defaultCenter];
  206550. [notificationCenter addObserver: self
  206551. selector: @selector (frameChanged:)
  206552. name: NSViewFrameDidChangeNotification
  206553. object: self];
  206554. if (! owner_->isSharedWindow)
  206555. {
  206556. [notificationCenter addObserver: self
  206557. selector: @selector (frameChanged:)
  206558. name: NSWindowDidMoveNotification
  206559. object: owner_->window];
  206560. }
  206561. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206562. return self;
  206563. }
  206564. - (void) dealloc
  206565. {
  206566. [notificationCenter removeObserver: self];
  206567. delete stringBeingComposed;
  206568. [super dealloc];
  206569. }
  206570. - (void) drawRect: (NSRect) r
  206571. {
  206572. if (owner != 0)
  206573. owner->drawRect (r);
  206574. }
  206575. - (BOOL) isOpaque
  206576. {
  206577. return owner == 0 || owner->isOpaque();
  206578. }
  206579. - (void) mouseDown: (NSEvent*) ev
  206580. {
  206581. // In some host situations, the host will stop modal loops from working
  206582. // correctly if they're called from a mouse event, so we'll trigger
  206583. // the event asynchronously..
  206584. if (JUCEApplication::getInstance() == 0)
  206585. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206586. withObject: ev
  206587. waitUntilDone: NO];
  206588. else
  206589. [self asyncMouseDown: ev];
  206590. }
  206591. - (void) asyncMouseDown: (NSEvent*) ev
  206592. {
  206593. if (owner != 0)
  206594. owner->redirectMouseDown (ev);
  206595. }
  206596. - (void) mouseUp: (NSEvent*) ev
  206597. {
  206598. // In some host situations, the host will stop modal loops from working
  206599. // correctly if they're called from a mouse event, so we'll trigger
  206600. // the event asynchronously..
  206601. if (JUCEApplication::getInstance() == 0)
  206602. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206603. withObject: ev
  206604. waitUntilDone: NO];
  206605. else
  206606. [self asyncMouseUp: ev];
  206607. }
  206608. - (void) asyncMouseUp: (NSEvent*) ev
  206609. {
  206610. if (owner != 0)
  206611. owner->redirectMouseUp (ev);
  206612. }
  206613. - (void) mouseDragged: (NSEvent*) ev
  206614. {
  206615. if (owner != 0)
  206616. owner->redirectMouseDrag (ev);
  206617. }
  206618. - (void) mouseMoved: (NSEvent*) ev
  206619. {
  206620. if (owner != 0)
  206621. owner->redirectMouseMove (ev);
  206622. }
  206623. - (void) mouseEntered: (NSEvent*) ev
  206624. {
  206625. if (owner != 0)
  206626. owner->redirectMouseEnter (ev);
  206627. }
  206628. - (void) mouseExited: (NSEvent*) ev
  206629. {
  206630. if (owner != 0)
  206631. owner->redirectMouseExit (ev);
  206632. }
  206633. - (void) rightMouseDown: (NSEvent*) ev
  206634. {
  206635. [self mouseDown: ev];
  206636. }
  206637. - (void) rightMouseDragged: (NSEvent*) ev
  206638. {
  206639. [self mouseDragged: ev];
  206640. }
  206641. - (void) rightMouseUp: (NSEvent*) ev
  206642. {
  206643. [self mouseUp: ev];
  206644. }
  206645. - (void) otherMouseDown: (NSEvent*) ev
  206646. {
  206647. [self mouseDown: ev];
  206648. }
  206649. - (void) otherMouseDragged: (NSEvent*) ev
  206650. {
  206651. [self mouseDragged: ev];
  206652. }
  206653. - (void) otherMouseUp: (NSEvent*) ev
  206654. {
  206655. [self mouseUp: ev];
  206656. }
  206657. - (void) scrollWheel: (NSEvent*) ev
  206658. {
  206659. if (owner != 0)
  206660. owner->redirectMouseWheel (ev);
  206661. }
  206662. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206663. {
  206664. return YES;
  206665. }
  206666. - (void) frameChanged: (NSNotification*) n
  206667. {
  206668. if (owner != 0)
  206669. owner->redirectMovedOrResized();
  206670. }
  206671. - (void) viewDidMoveToWindow
  206672. {
  206673. if (owner != 0)
  206674. owner->viewMovedToWindow();
  206675. }
  206676. - (void) asyncRepaint: (id) rect
  206677. {
  206678. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206679. [self setNeedsDisplayInRect: *r];
  206680. }
  206681. - (void) keyDown: (NSEvent*) ev
  206682. {
  206683. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206684. textWasInserted = false;
  206685. if (target != 0)
  206686. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206687. else
  206688. deleteAndZero (stringBeingComposed);
  206689. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206690. [super keyDown: ev];
  206691. }
  206692. - (void) keyUp: (NSEvent*) ev
  206693. {
  206694. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206695. [super keyUp: ev];
  206696. }
  206697. - (void) insertText: (id) aString
  206698. {
  206699. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206700. if ([aString length] > 0)
  206701. {
  206702. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206703. if (target != 0)
  206704. {
  206705. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206706. textWasInserted = true;
  206707. }
  206708. }
  206709. deleteAndZero (stringBeingComposed);
  206710. }
  206711. - (void) doCommandBySelector: (SEL) aSelector
  206712. {
  206713. }
  206714. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206715. {
  206716. if (stringBeingComposed == 0)
  206717. stringBeingComposed = new String();
  206718. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206719. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206720. if (target != 0)
  206721. {
  206722. const Range<int> currentHighlight (target->getHighlightedRegion());
  206723. target->insertTextAtCaret (*stringBeingComposed);
  206724. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206725. textWasInserted = true;
  206726. }
  206727. }
  206728. - (void) unmarkText
  206729. {
  206730. if (stringBeingComposed != 0)
  206731. {
  206732. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206733. if (target != 0)
  206734. {
  206735. target->insertTextAtCaret (*stringBeingComposed);
  206736. textWasInserted = true;
  206737. }
  206738. }
  206739. deleteAndZero (stringBeingComposed);
  206740. }
  206741. - (BOOL) hasMarkedText
  206742. {
  206743. return stringBeingComposed != 0;
  206744. }
  206745. - (long) conversationIdentifier
  206746. {
  206747. return (long) (pointer_sized_int) self;
  206748. }
  206749. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206750. {
  206751. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206752. if (target != 0)
  206753. {
  206754. const Range<int> r ((int) theRange.location,
  206755. (int) (theRange.location + theRange.length));
  206756. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206757. }
  206758. return nil;
  206759. }
  206760. - (NSRange) markedRange
  206761. {
  206762. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206763. : NSMakeRange (NSNotFound, 0);
  206764. }
  206765. - (NSRange) selectedRange
  206766. {
  206767. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206768. if (target != 0)
  206769. {
  206770. const Range<int> highlight (target->getHighlightedRegion());
  206771. if (! highlight.isEmpty())
  206772. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206773. }
  206774. return NSMakeRange (NSNotFound, 0);
  206775. }
  206776. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206777. {
  206778. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206779. if (comp == 0)
  206780. return NSMakeRect (0, 0, 0, 0);
  206781. const Rectangle<int> bounds (comp->getScreenBounds());
  206782. return NSMakeRect (bounds.getX(),
  206783. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206784. bounds.getWidth(),
  206785. bounds.getHeight());
  206786. }
  206787. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206788. {
  206789. return NSNotFound;
  206790. }
  206791. - (NSArray*) validAttributesForMarkedText
  206792. {
  206793. return [NSArray array];
  206794. }
  206795. - (void) flagsChanged: (NSEvent*) ev
  206796. {
  206797. if (owner != 0)
  206798. owner->redirectModKeyChange (ev);
  206799. }
  206800. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206801. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206802. {
  206803. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206804. return true;
  206805. return [super performKeyEquivalent: ev];
  206806. }
  206807. #endif
  206808. - (BOOL) becomeFirstResponder
  206809. {
  206810. if (owner != 0)
  206811. owner->viewFocusGain();
  206812. return true;
  206813. }
  206814. - (BOOL) resignFirstResponder
  206815. {
  206816. if (owner != 0)
  206817. owner->viewFocusLoss();
  206818. return true;
  206819. }
  206820. - (BOOL) acceptsFirstResponder
  206821. {
  206822. return owner != 0 && owner->canBecomeKeyWindow();
  206823. }
  206824. - (NSArray*) getSupportedDragTypes
  206825. {
  206826. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206827. }
  206828. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206829. {
  206830. return owner != 0 && owner->sendDragCallback (type, sender);
  206831. }
  206832. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206833. {
  206834. if ([self sendDragCallback: 0 sender: sender])
  206835. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206836. else
  206837. return NSDragOperationNone;
  206838. }
  206839. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206840. {
  206841. if ([self sendDragCallback: 0 sender: sender])
  206842. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206843. else
  206844. return NSDragOperationNone;
  206845. }
  206846. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206847. {
  206848. [self sendDragCallback: 1 sender: sender];
  206849. }
  206850. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206851. {
  206852. [self sendDragCallback: 1 sender: sender];
  206853. }
  206854. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206855. {
  206856. return YES;
  206857. }
  206858. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206859. {
  206860. return [self sendDragCallback: 2 sender: sender];
  206861. }
  206862. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206863. {
  206864. }
  206865. @end
  206866. @implementation JuceNSWindow
  206867. - (void) setOwner: (NSViewComponentPeer*) owner_
  206868. {
  206869. owner = owner_;
  206870. isZooming = false;
  206871. }
  206872. - (BOOL) canBecomeKeyWindow
  206873. {
  206874. return owner != 0 && owner->canBecomeKeyWindow();
  206875. }
  206876. - (void) becomeKeyWindow
  206877. {
  206878. [super becomeKeyWindow];
  206879. if (owner != 0)
  206880. owner->grabFocus();
  206881. }
  206882. - (BOOL) windowShouldClose: (id) window
  206883. {
  206884. return owner == 0 || owner->windowShouldClose();
  206885. }
  206886. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206887. {
  206888. if (owner != 0)
  206889. frameRect = owner->constrainRect (frameRect);
  206890. return frameRect;
  206891. }
  206892. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206893. {
  206894. if (isZooming)
  206895. return proposedFrameSize;
  206896. NSRect frameRect = [self frame];
  206897. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206898. frameRect.size = proposedFrameSize;
  206899. if (owner != 0)
  206900. frameRect = owner->constrainRect (frameRect);
  206901. return frameRect.size;
  206902. }
  206903. - (void) zoom: (id) sender
  206904. {
  206905. isZooming = true;
  206906. [super zoom: sender];
  206907. isZooming = false;
  206908. }
  206909. - (void) windowWillMove: (NSNotification*) notification
  206910. {
  206911. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206912. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206913. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206914. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206915. }
  206916. @end
  206917. BEGIN_JUCE_NAMESPACE
  206918. ModifierKeys NSViewComponentPeer::currentModifiers;
  206919. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206920. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  206921. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  206922. {
  206923. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  206924. return true;
  206925. if (keyCode >= 'A' && keyCode <= 'Z'
  206926. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206927. return true;
  206928. if (keyCode >= 'a' && keyCode <= 'z'
  206929. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206930. return true;
  206931. return false;
  206932. }
  206933. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206934. {
  206935. int m = 0;
  206936. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206937. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206938. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206939. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206940. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206941. }
  206942. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206943. {
  206944. updateModifiers (ev);
  206945. int keyCode = getKeyCodeFromEvent (ev);
  206946. if (keyCode != 0)
  206947. {
  206948. if (isKeyDown)
  206949. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  206950. else
  206951. keysCurrentlyDown.removeValue (keyCode);
  206952. }
  206953. }
  206954. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206955. {
  206956. return NSViewComponentPeer::currentModifiers;
  206957. }
  206958. void ModifierKeys::updateCurrentModifiers() throw()
  206959. {
  206960. currentModifiers = NSViewComponentPeer::currentModifiers;
  206961. }
  206962. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  206963. const int windowStyleFlags,
  206964. NSView* viewToAttachTo)
  206965. : ComponentPeer (component_, windowStyleFlags),
  206966. window (0),
  206967. view (0),
  206968. isSharedWindow (viewToAttachTo != 0),
  206969. fullScreen (false),
  206970. insideDrawRect (false),
  206971. #if USE_COREGRAPHICS_RENDERING
  206972. usingCoreGraphics (true),
  206973. #else
  206974. usingCoreGraphics (false),
  206975. #endif
  206976. recursiveToFrontCall (false)
  206977. {
  206978. NSRect r;
  206979. r.origin.x = 0;
  206980. r.origin.y = 0;
  206981. r.size.width = (float) component->getWidth();
  206982. r.size.height = (float) component->getHeight();
  206983. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  206984. [view setPostsFrameChangedNotifications: YES];
  206985. if (isSharedWindow)
  206986. {
  206987. window = [viewToAttachTo window];
  206988. [viewToAttachTo addSubview: view];
  206989. setVisible (component->isVisible());
  206990. }
  206991. else
  206992. {
  206993. r.origin.x = (float) component->getX();
  206994. r.origin.y = (float) component->getY();
  206995. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  206996. unsigned int style = 0;
  206997. if ((windowStyleFlags & windowHasTitleBar) == 0)
  206998. style = NSBorderlessWindowMask;
  206999. else
  207000. style = NSTitledWindowMask;
  207001. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207002. style |= NSMiniaturizableWindowMask;
  207003. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207004. style |= NSClosableWindowMask;
  207005. if ((windowStyleFlags & windowIsResizable) != 0)
  207006. style |= NSResizableWindowMask;
  207007. window = [[JuceNSWindow alloc] initWithContentRect: r
  207008. styleMask: style
  207009. backing: NSBackingStoreBuffered
  207010. defer: YES];
  207011. [((JuceNSWindow*) window) setOwner: this];
  207012. [window orderOut: nil];
  207013. [window setDelegate: (JuceNSWindow*) window];
  207014. [window setOpaque: component->isOpaque()];
  207015. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207016. if (component->isAlwaysOnTop())
  207017. [window setLevel: NSFloatingWindowLevel];
  207018. [window setContentView: view];
  207019. [window setAutodisplay: YES];
  207020. [window setAcceptsMouseMovedEvents: YES];
  207021. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207022. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207023. [window setReleasedWhenClosed: YES];
  207024. [window retain];
  207025. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207026. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207027. }
  207028. setTitle (component->getName());
  207029. }
  207030. NSViewComponentPeer::~NSViewComponentPeer()
  207031. {
  207032. view->owner = 0;
  207033. [view removeFromSuperview];
  207034. [view release];
  207035. if (! isSharedWindow)
  207036. {
  207037. [((JuceNSWindow*) window) setOwner: 0];
  207038. [window close];
  207039. [window release];
  207040. }
  207041. }
  207042. void* NSViewComponentPeer::getNativeHandle() const
  207043. {
  207044. return view;
  207045. }
  207046. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207047. {
  207048. if (isSharedWindow)
  207049. {
  207050. [view setHidden: ! shouldBeVisible];
  207051. }
  207052. else
  207053. {
  207054. if (shouldBeVisible)
  207055. {
  207056. [window orderFront: nil];
  207057. handleBroughtToFront();
  207058. }
  207059. else
  207060. {
  207061. [window orderOut: nil];
  207062. }
  207063. }
  207064. }
  207065. void NSViewComponentPeer::setTitle (const String& title)
  207066. {
  207067. const ScopedAutoReleasePool pool;
  207068. if (! isSharedWindow)
  207069. [window setTitle: juceStringToNS (title)];
  207070. }
  207071. void NSViewComponentPeer::setPosition (int x, int y)
  207072. {
  207073. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207074. }
  207075. void NSViewComponentPeer::setSize (int w, int h)
  207076. {
  207077. setBounds (component->getX(), component->getY(), w, h, false);
  207078. }
  207079. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  207080. {
  207081. fullScreen = isNowFullScreen;
  207082. w = jmax (0, w);
  207083. h = jmax (0, h);
  207084. NSRect r;
  207085. r.origin.x = (float) x;
  207086. r.origin.y = (float) y;
  207087. r.size.width = (float) w;
  207088. r.size.height = (float) h;
  207089. if (isSharedWindow)
  207090. {
  207091. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207092. if ([view frame].size.width != r.size.width
  207093. || [view frame].size.height != r.size.height)
  207094. [view setNeedsDisplay: true];
  207095. [view setFrame: r];
  207096. }
  207097. else
  207098. {
  207099. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207100. [window setFrame: [window frameRectForContentRect: r]
  207101. display: true];
  207102. }
  207103. }
  207104. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207105. {
  207106. NSRect r = [view frame];
  207107. if (global && [view window] != 0)
  207108. {
  207109. r = [view convertRect: r toView: nil];
  207110. NSRect wr = [[view window] frame];
  207111. r.origin.x += wr.origin.x;
  207112. r.origin.y += wr.origin.y;
  207113. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207114. }
  207115. else
  207116. {
  207117. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207118. }
  207119. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207120. }
  207121. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207122. {
  207123. return getBounds (! isSharedWindow);
  207124. }
  207125. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207126. {
  207127. return getBounds (true).getPosition();
  207128. }
  207129. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207130. {
  207131. return relativePosition + getScreenPosition();
  207132. }
  207133. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207134. {
  207135. return screenPosition - getScreenPosition();
  207136. }
  207137. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207138. {
  207139. if (constrainer != 0)
  207140. {
  207141. NSRect current = [window frame];
  207142. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207143. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207144. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207145. (int) r.size.width, (int) r.size.height);
  207146. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207147. (int) current.size.width, (int) current.size.height);
  207148. constrainer->checkBounds (pos, original,
  207149. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207150. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207151. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207152. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207153. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207154. r.origin.x = pos.getX();
  207155. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207156. r.size.width = pos.getWidth();
  207157. r.size.height = pos.getHeight();
  207158. }
  207159. return r;
  207160. }
  207161. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207162. {
  207163. if (! isSharedWindow)
  207164. {
  207165. if (shouldBeMinimised)
  207166. [window miniaturize: nil];
  207167. else
  207168. [window deminiaturize: nil];
  207169. }
  207170. }
  207171. bool NSViewComponentPeer::isMinimised() const
  207172. {
  207173. return window != 0 && [window isMiniaturized];
  207174. }
  207175. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207176. {
  207177. if (! isSharedWindow)
  207178. {
  207179. Rectangle<int> r (lastNonFullscreenBounds);
  207180. setMinimised (false);
  207181. if (fullScreen != shouldBeFullScreen)
  207182. {
  207183. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207184. {
  207185. fullScreen = true;
  207186. [window performZoom: nil];
  207187. }
  207188. else
  207189. {
  207190. if (shouldBeFullScreen)
  207191. r = Desktop::getInstance().getMainMonitorArea();
  207192. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207193. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207194. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207195. }
  207196. }
  207197. }
  207198. }
  207199. bool NSViewComponentPeer::isFullScreen() const
  207200. {
  207201. return fullScreen;
  207202. }
  207203. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207204. {
  207205. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207206. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207207. return false;
  207208. NSPoint p;
  207209. p.x = (float) position.getX();
  207210. p.y = (float) position.getY();
  207211. NSView* v = [view hitTest: p];
  207212. if (trueIfInAChildWindow)
  207213. return v != nil;
  207214. return v == view;
  207215. }
  207216. const BorderSize NSViewComponentPeer::getFrameSize() const
  207217. {
  207218. BorderSize b;
  207219. if (! isSharedWindow)
  207220. {
  207221. NSRect v = [view convertRect: [view frame] toView: nil];
  207222. NSRect w = [window frame];
  207223. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207224. b.setBottom ((int) v.origin.y);
  207225. b.setLeft ((int) v.origin.x);
  207226. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207227. }
  207228. return b;
  207229. }
  207230. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207231. {
  207232. if (! isSharedWindow)
  207233. {
  207234. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207235. : NSNormalWindowLevel];
  207236. }
  207237. return true;
  207238. }
  207239. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207240. {
  207241. if (isSharedWindow)
  207242. {
  207243. [[view superview] addSubview: view
  207244. positioned: NSWindowAbove
  207245. relativeTo: nil];
  207246. }
  207247. if (window != 0 && component->isVisible())
  207248. {
  207249. if (makeActiveWindow)
  207250. [window makeKeyAndOrderFront: nil];
  207251. else
  207252. [window orderFront: nil];
  207253. if (! recursiveToFrontCall)
  207254. {
  207255. recursiveToFrontCall = true;
  207256. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207257. handleBroughtToFront();
  207258. recursiveToFrontCall = false;
  207259. }
  207260. }
  207261. }
  207262. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207263. {
  207264. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207265. if (isSharedWindow)
  207266. {
  207267. [[view superview] addSubview: view
  207268. positioned: NSWindowBelow
  207269. relativeTo: o->view];
  207270. }
  207271. else
  207272. {
  207273. [window orderWindow: NSWindowBelow
  207274. relativeTo: o->window != 0 ? [o->window windowNumber]
  207275. : nil ];
  207276. }
  207277. }
  207278. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207279. {
  207280. // to do..
  207281. }
  207282. void NSViewComponentPeer::viewFocusGain()
  207283. {
  207284. if (currentlyFocusedPeer != this)
  207285. {
  207286. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207287. currentlyFocusedPeer->handleFocusLoss();
  207288. currentlyFocusedPeer = this;
  207289. handleFocusGain();
  207290. }
  207291. }
  207292. void NSViewComponentPeer::viewFocusLoss()
  207293. {
  207294. if (currentlyFocusedPeer == this)
  207295. {
  207296. currentlyFocusedPeer = 0;
  207297. handleFocusLoss();
  207298. }
  207299. }
  207300. void juce_HandleProcessFocusChange()
  207301. {
  207302. NSViewComponentPeer::keysCurrentlyDown.clear();
  207303. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207304. {
  207305. if (Process::isForegroundProcess())
  207306. {
  207307. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207308. ComponentPeer::bringModalComponentToFront();
  207309. }
  207310. else
  207311. {
  207312. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207313. // turn kiosk mode off if we lose focus..
  207314. Desktop::getInstance().setKioskModeComponent (0);
  207315. }
  207316. }
  207317. }
  207318. bool NSViewComponentPeer::isFocused() const
  207319. {
  207320. return isSharedWindow ? this == currentlyFocusedPeer
  207321. : (window != 0 && [window isKeyWindow]);
  207322. }
  207323. void NSViewComponentPeer::grabFocus()
  207324. {
  207325. if (window != 0)
  207326. {
  207327. [window makeKeyWindow];
  207328. [window makeFirstResponder: view];
  207329. viewFocusGain();
  207330. }
  207331. }
  207332. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207333. {
  207334. }
  207335. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207336. {
  207337. String unicode (nsStringToJuce ([ev characters]));
  207338. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207339. int keyCode = getKeyCodeFromEvent (ev);
  207340. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207341. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207342. if (unicode.isNotEmpty() || keyCode != 0)
  207343. {
  207344. if (isKeyDown)
  207345. {
  207346. bool used = false;
  207347. while (unicode.length() > 0)
  207348. {
  207349. juce_wchar textCharacter = unicode[0];
  207350. unicode = unicode.substring (1);
  207351. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207352. textCharacter = 0;
  207353. used = handleKeyUpOrDown (true) || used;
  207354. used = handleKeyPress (keyCode, textCharacter) || used;
  207355. }
  207356. return used;
  207357. }
  207358. else
  207359. {
  207360. if (handleKeyUpOrDown (false))
  207361. return true;
  207362. }
  207363. }
  207364. return false;
  207365. }
  207366. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207367. {
  207368. updateKeysDown (ev, true);
  207369. bool used = handleKeyEvent (ev, true);
  207370. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207371. {
  207372. // for command keys, the key-up event is thrown away, so simulate one..
  207373. updateKeysDown (ev, false);
  207374. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207375. }
  207376. // (If we're running modally, don't allow unused keystrokes to be passed
  207377. // along to other blocked views..)
  207378. if (Component::getCurrentlyModalComponent() != 0)
  207379. used = true;
  207380. return used;
  207381. }
  207382. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207383. {
  207384. updateKeysDown (ev, false);
  207385. return handleKeyEvent (ev, false)
  207386. || Component::getCurrentlyModalComponent() != 0;
  207387. }
  207388. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207389. {
  207390. keysCurrentlyDown.clear();
  207391. handleKeyUpOrDown (true);
  207392. updateModifiers (ev);
  207393. handleModifierKeysChange();
  207394. }
  207395. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207396. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207397. {
  207398. if ([ev type] == NSKeyDown)
  207399. return redirectKeyDown (ev);
  207400. else if ([ev type] == NSKeyUp)
  207401. return redirectKeyUp (ev);
  207402. return false;
  207403. }
  207404. #endif
  207405. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207406. {
  207407. updateModifiers (ev);
  207408. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207409. }
  207410. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207411. {
  207412. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207413. sendMouseEvent (ev);
  207414. }
  207415. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207416. {
  207417. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207418. sendMouseEvent (ev);
  207419. showArrowCursorIfNeeded();
  207420. }
  207421. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207422. {
  207423. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207424. sendMouseEvent (ev);
  207425. }
  207426. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207427. {
  207428. currentModifiers = currentModifiers.withoutMouseButtons();
  207429. sendMouseEvent (ev);
  207430. showArrowCursorIfNeeded();
  207431. }
  207432. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207433. {
  207434. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207435. currentModifiers = currentModifiers.withoutMouseButtons();
  207436. sendMouseEvent (ev);
  207437. }
  207438. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207439. {
  207440. currentModifiers = currentModifiers.withoutMouseButtons();
  207441. sendMouseEvent (ev);
  207442. }
  207443. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207444. {
  207445. updateModifiers (ev);
  207446. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207447. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207448. }
  207449. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207450. {
  207451. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207452. if (mouse.getComponentUnderMouse() == 0
  207453. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207454. {
  207455. [[NSCursor arrowCursor] set];
  207456. }
  207457. }
  207458. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207459. {
  207460. NSString* bestType
  207461. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207462. if (bestType == nil)
  207463. return false;
  207464. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207465. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207466. StringArray files;
  207467. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207468. if (list == nil)
  207469. return false;
  207470. if ([list isKindOfClass: [NSArray class]])
  207471. {
  207472. NSArray* items = (NSArray*) list;
  207473. for (unsigned int i = 0; i < [items count]; ++i)
  207474. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207475. }
  207476. if (files.size() == 0)
  207477. return false;
  207478. if (type == 0)
  207479. handleFileDragMove (files, pos);
  207480. else if (type == 1)
  207481. handleFileDragExit (files);
  207482. else if (type == 2)
  207483. handleFileDragDrop (files, pos);
  207484. return true;
  207485. }
  207486. bool NSViewComponentPeer::isOpaque()
  207487. {
  207488. return component == 0 || component->isOpaque();
  207489. }
  207490. void NSViewComponentPeer::drawRect (NSRect r)
  207491. {
  207492. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207493. return;
  207494. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207495. if (! component->isOpaque())
  207496. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207497. #if USE_COREGRAPHICS_RENDERING
  207498. if (usingCoreGraphics)
  207499. {
  207500. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207501. insideDrawRect = true;
  207502. handlePaint (context);
  207503. insideDrawRect = false;
  207504. }
  207505. else
  207506. #endif
  207507. {
  207508. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207509. (int) (r.size.width + 0.5f),
  207510. (int) (r.size.height + 0.5f),
  207511. ! getComponent()->isOpaque());
  207512. LowLevelGraphicsSoftwareRenderer context (temp);
  207513. context.setOrigin (-roundToInt (r.origin.x),
  207514. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207515. const NSRect* rects = 0;
  207516. NSInteger numRects = 0;
  207517. [view getRectsBeingDrawn: &rects count: &numRects];
  207518. RectangleList clip;
  207519. for (int i = 0; i < numRects; ++i)
  207520. {
  207521. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207522. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207523. roundToInt (rects[i].size.width),
  207524. roundToInt (rects[i].size.height)));
  207525. }
  207526. if (context.clipToRectangleList (clip))
  207527. {
  207528. insideDrawRect = true;
  207529. handlePaint (context);
  207530. insideDrawRect = false;
  207531. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207532. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207533. CGColorSpaceRelease (colourSpace);
  207534. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207535. CGImageRelease (image);
  207536. }
  207537. }
  207538. }
  207539. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207540. {
  207541. StringArray s;
  207542. s.add ("Software Renderer");
  207543. #if USE_COREGRAPHICS_RENDERING
  207544. s.add ("CoreGraphics Renderer");
  207545. #endif
  207546. return s;
  207547. }
  207548. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207549. {
  207550. return usingCoreGraphics ? 1 : 0;
  207551. }
  207552. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207553. {
  207554. #if USE_COREGRAPHICS_RENDERING
  207555. if (usingCoreGraphics != (index > 0))
  207556. {
  207557. usingCoreGraphics = index > 0;
  207558. [view setNeedsDisplay: true];
  207559. }
  207560. #endif
  207561. }
  207562. bool NSViewComponentPeer::canBecomeKeyWindow()
  207563. {
  207564. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207565. }
  207566. bool NSViewComponentPeer::windowShouldClose()
  207567. {
  207568. if (! isValidPeer (this))
  207569. return YES;
  207570. handleUserClosingWindow();
  207571. return NO;
  207572. }
  207573. void NSViewComponentPeer::redirectMovedOrResized()
  207574. {
  207575. handleMovedOrResized();
  207576. }
  207577. void NSViewComponentPeer::viewMovedToWindow()
  207578. {
  207579. if (isSharedWindow)
  207580. window = [view window];
  207581. }
  207582. void Desktop::createMouseInputSources()
  207583. {
  207584. mouseSources.add (new MouseInputSource (0, true));
  207585. }
  207586. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207587. {
  207588. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207589. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207590. // is apparently still available in 64-bit apps..
  207591. if (enableOrDisable)
  207592. {
  207593. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207594. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207595. }
  207596. else
  207597. {
  207598. SetSystemUIMode (kUIModeNormal, 0);
  207599. }
  207600. }
  207601. class AsyncRepaintMessage : public CallbackMessage
  207602. {
  207603. public:
  207604. NSViewComponentPeer* const peer;
  207605. const Rectangle<int> rect;
  207606. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207607. : peer (peer_), rect (rect_)
  207608. {
  207609. }
  207610. void messageCallback()
  207611. {
  207612. if (ComponentPeer::isValidPeer (peer))
  207613. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207614. }
  207615. };
  207616. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207617. {
  207618. if (insideDrawRect)
  207619. {
  207620. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207621. }
  207622. else
  207623. {
  207624. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207625. (float) w, (float) h)];
  207626. }
  207627. }
  207628. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207629. {
  207630. [view displayIfNeeded];
  207631. }
  207632. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207633. {
  207634. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207635. }
  207636. Image* juce_createIconForFile (const File& file)
  207637. {
  207638. const ScopedAutoReleasePool pool;
  207639. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207640. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207641. [NSGraphicsContext saveGraphicsState];
  207642. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207643. [image drawAtPoint: NSMakePoint (0, 0)
  207644. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207645. operation: NSCompositeSourceOver fraction: 1.0f];
  207646. [[NSGraphicsContext currentContext] flushGraphics];
  207647. [NSGraphicsContext restoreGraphicsState];
  207648. return result;
  207649. }
  207650. const int KeyPress::spaceKey = ' ';
  207651. const int KeyPress::returnKey = 0x0d;
  207652. const int KeyPress::escapeKey = 0x1b;
  207653. const int KeyPress::backspaceKey = 0x7f;
  207654. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207655. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207656. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207657. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207658. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207659. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207660. const int KeyPress::endKey = NSEndFunctionKey;
  207661. const int KeyPress::homeKey = NSHomeFunctionKey;
  207662. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207663. const int KeyPress::insertKey = -1;
  207664. const int KeyPress::tabKey = 9;
  207665. const int KeyPress::F1Key = NSF1FunctionKey;
  207666. const int KeyPress::F2Key = NSF2FunctionKey;
  207667. const int KeyPress::F3Key = NSF3FunctionKey;
  207668. const int KeyPress::F4Key = NSF4FunctionKey;
  207669. const int KeyPress::F5Key = NSF5FunctionKey;
  207670. const int KeyPress::F6Key = NSF6FunctionKey;
  207671. const int KeyPress::F7Key = NSF7FunctionKey;
  207672. const int KeyPress::F8Key = NSF8FunctionKey;
  207673. const int KeyPress::F9Key = NSF9FunctionKey;
  207674. const int KeyPress::F10Key = NSF10FunctionKey;
  207675. const int KeyPress::F11Key = NSF1FunctionKey;
  207676. const int KeyPress::F12Key = NSF12FunctionKey;
  207677. const int KeyPress::F13Key = NSF13FunctionKey;
  207678. const int KeyPress::F14Key = NSF14FunctionKey;
  207679. const int KeyPress::F15Key = NSF15FunctionKey;
  207680. const int KeyPress::F16Key = NSF16FunctionKey;
  207681. const int KeyPress::numberPad0 = 0x30020;
  207682. const int KeyPress::numberPad1 = 0x30021;
  207683. const int KeyPress::numberPad2 = 0x30022;
  207684. const int KeyPress::numberPad3 = 0x30023;
  207685. const int KeyPress::numberPad4 = 0x30024;
  207686. const int KeyPress::numberPad5 = 0x30025;
  207687. const int KeyPress::numberPad6 = 0x30026;
  207688. const int KeyPress::numberPad7 = 0x30027;
  207689. const int KeyPress::numberPad8 = 0x30028;
  207690. const int KeyPress::numberPad9 = 0x30029;
  207691. const int KeyPress::numberPadAdd = 0x3002a;
  207692. const int KeyPress::numberPadSubtract = 0x3002b;
  207693. const int KeyPress::numberPadMultiply = 0x3002c;
  207694. const int KeyPress::numberPadDivide = 0x3002d;
  207695. const int KeyPress::numberPadSeparator = 0x3002e;
  207696. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207697. const int KeyPress::numberPadEquals = 0x30030;
  207698. const int KeyPress::numberPadDelete = 0x30031;
  207699. const int KeyPress::playKey = 0x30000;
  207700. const int KeyPress::stopKey = 0x30001;
  207701. const int KeyPress::fastForwardKey = 0x30002;
  207702. const int KeyPress::rewindKey = 0x30003;
  207703. #endif
  207704. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207705. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207706. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207707. // compiled on its own).
  207708. #if JUCE_INCLUDED_FILE
  207709. #if JUCE_MAC
  207710. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207711. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207712. {
  207713. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207714. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207715. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207716. [im release];
  207717. return c;
  207718. }
  207719. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207720. {
  207721. MemoryInputStream stream (data, size, false);
  207722. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207723. jassert (im != 0);
  207724. if (im == 0)
  207725. return 0;
  207726. return juce_createMouseCursorFromImage (*im,
  207727. (int) (hx * im->getWidth()),
  207728. (int) (hy * im->getHeight()));
  207729. }
  207730. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207731. {
  207732. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207733. MemoryBlock mb;
  207734. if (f.getChildFile (filename).loadFileAsData (mb))
  207735. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207736. return 0;
  207737. }
  207738. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207739. {
  207740. const ScopedAutoReleasePool pool;
  207741. NSCursor* c = 0;
  207742. switch (type)
  207743. {
  207744. case MouseCursor::NormalCursor:
  207745. c = [NSCursor arrowCursor];
  207746. break;
  207747. case MouseCursor::NoCursor:
  207748. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207749. case MouseCursor::DraggingHandCursor:
  207750. c = [NSCursor openHandCursor];
  207751. break;
  207752. case MouseCursor::CopyingCursor:
  207753. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207754. case MouseCursor::WaitCursor:
  207755. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207756. break;
  207757. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207758. case MouseCursor::IBeamCursor:
  207759. c = [NSCursor IBeamCursor];
  207760. break;
  207761. case MouseCursor::PointingHandCursor:
  207762. c = [NSCursor pointingHandCursor];
  207763. break;
  207764. case MouseCursor::LeftRightResizeCursor:
  207765. c = [NSCursor resizeLeftRightCursor];
  207766. break;
  207767. case MouseCursor::LeftEdgeResizeCursor:
  207768. c = [NSCursor resizeLeftCursor];
  207769. break;
  207770. case MouseCursor::RightEdgeResizeCursor:
  207771. c = [NSCursor resizeRightCursor];
  207772. break;
  207773. case MouseCursor::UpDownResizeCursor:
  207774. case MouseCursor::TopEdgeResizeCursor:
  207775. case MouseCursor::BottomEdgeResizeCursor:
  207776. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207777. case MouseCursor::TopLeftCornerResizeCursor:
  207778. case MouseCursor::BottomRightCornerResizeCursor:
  207779. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207780. case MouseCursor::TopRightCornerResizeCursor:
  207781. case MouseCursor::BottomLeftCornerResizeCursor:
  207782. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207783. case MouseCursor::UpDownLeftRightResizeCursor:
  207784. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207785. case MouseCursor::CrosshairCursor:
  207786. c = [NSCursor crosshairCursor];
  207787. break;
  207788. }
  207789. [c retain];
  207790. return c;
  207791. }
  207792. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207793. {
  207794. NSCursor* c = (NSCursor*) cursorHandle;
  207795. [c release];
  207796. }
  207797. void MouseCursor::showInAllWindows() const throw()
  207798. {
  207799. showInWindow (0);
  207800. }
  207801. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207802. {
  207803. NSCursor* const c = (NSCursor*) getHandle();
  207804. [c set];
  207805. }
  207806. #else
  207807. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207808. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207809. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207810. void MouseCursor::showInAllWindows() const throw() {}
  207811. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207812. #endif
  207813. #endif
  207814. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207815. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207816. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207817. // compiled on its own).
  207818. #if JUCE_INCLUDED_FILE
  207819. class NSViewComponentInternal : public ComponentMovementWatcher
  207820. {
  207821. Component* const owner;
  207822. NSViewComponentPeer* currentPeer;
  207823. bool wasShowing;
  207824. public:
  207825. NSView* const view;
  207826. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207827. : ComponentMovementWatcher (owner_),
  207828. owner (owner_),
  207829. currentPeer (0),
  207830. wasShowing (false),
  207831. view (view_)
  207832. {
  207833. [view_ retain];
  207834. if (owner_->isShowing())
  207835. componentPeerChanged();
  207836. }
  207837. ~NSViewComponentInternal()
  207838. {
  207839. [view removeFromSuperview];
  207840. [view release];
  207841. }
  207842. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207843. {
  207844. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207845. // The ComponentMovementWatcher version of this method avoids calling
  207846. // us when the top-level comp is resized, but for an NSView we need to know this
  207847. // because with inverted co-ords, we need to update the position even if the
  207848. // top-left pos hasn't changed
  207849. if (comp.isOnDesktop() && wasResized)
  207850. componentMovedOrResized (wasMoved, wasResized);
  207851. }
  207852. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207853. {
  207854. Component* const topComp = owner->getTopLevelComponent();
  207855. if (topComp->getPeer() != 0)
  207856. {
  207857. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207858. NSRect r;
  207859. r.origin.x = (float) pos.getX();
  207860. r.origin.y = (float) pos.getY();
  207861. r.size.width = (float) owner->getWidth();
  207862. r.size.height = (float) owner->getHeight();
  207863. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207864. [view setFrame: r];
  207865. }
  207866. }
  207867. void componentPeerChanged()
  207868. {
  207869. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207870. if (currentPeer != peer)
  207871. {
  207872. [view removeFromSuperview];
  207873. currentPeer = peer;
  207874. if (peer != 0)
  207875. {
  207876. [peer->view addSubview: view];
  207877. componentMovedOrResized (false, false);
  207878. }
  207879. }
  207880. [view setHidden: ! owner->isShowing()];
  207881. }
  207882. void componentVisibilityChanged (Component&)
  207883. {
  207884. componentPeerChanged();
  207885. }
  207886. juce_UseDebuggingNewOperator
  207887. private:
  207888. NSViewComponentInternal (const NSViewComponentInternal&);
  207889. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207890. };
  207891. NSViewComponent::NSViewComponent()
  207892. {
  207893. }
  207894. NSViewComponent::~NSViewComponent()
  207895. {
  207896. }
  207897. void NSViewComponent::setView (void* view)
  207898. {
  207899. if (view != getView())
  207900. {
  207901. if (view != 0)
  207902. info = new NSViewComponentInternal ((NSView*) view, this);
  207903. else
  207904. info = 0;
  207905. }
  207906. }
  207907. void* NSViewComponent::getView() const
  207908. {
  207909. return info == 0 ? 0 : info->view;
  207910. }
  207911. void NSViewComponent::paint (Graphics& g)
  207912. {
  207913. }
  207914. #endif
  207915. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207916. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207917. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207918. // compiled on its own).
  207919. #if JUCE_INCLUDED_FILE
  207920. AppleRemoteDevice::AppleRemoteDevice()
  207921. : device (0),
  207922. queue (0),
  207923. remoteId (0)
  207924. {
  207925. }
  207926. AppleRemoteDevice::~AppleRemoteDevice()
  207927. {
  207928. stop();
  207929. }
  207930. static io_object_t getAppleRemoteDevice()
  207931. {
  207932. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207933. io_iterator_t iter = 0;
  207934. io_object_t iod = 0;
  207935. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207936. && iter != 0)
  207937. {
  207938. iod = IOIteratorNext (iter);
  207939. }
  207940. IOObjectRelease (iter);
  207941. return iod;
  207942. }
  207943. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207944. {
  207945. jassert (*device == 0);
  207946. io_name_t classname;
  207947. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207948. {
  207949. IOCFPlugInInterface** cfPlugInInterface = 0;
  207950. SInt32 score = 0;
  207951. if (IOCreatePlugInInterfaceForService (iod,
  207952. kIOHIDDeviceUserClientTypeID,
  207953. kIOCFPlugInInterfaceID,
  207954. &cfPlugInInterface,
  207955. &score) == kIOReturnSuccess)
  207956. {
  207957. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  207958. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  207959. device);
  207960. (void) hr;
  207961. (*cfPlugInInterface)->Release (cfPlugInInterface);
  207962. }
  207963. }
  207964. return *device != 0;
  207965. }
  207966. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  207967. {
  207968. if (queue != 0)
  207969. return true;
  207970. stop();
  207971. bool result = false;
  207972. io_object_t iod = getAppleRemoteDevice();
  207973. if (iod != 0)
  207974. {
  207975. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  207976. result = true;
  207977. else
  207978. stop();
  207979. IOObjectRelease (iod);
  207980. }
  207981. return result;
  207982. }
  207983. void AppleRemoteDevice::stop()
  207984. {
  207985. if (queue != 0)
  207986. {
  207987. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  207988. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  207989. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  207990. queue = 0;
  207991. }
  207992. if (device != 0)
  207993. {
  207994. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  207995. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  207996. device = 0;
  207997. }
  207998. }
  207999. bool AppleRemoteDevice::isActive() const
  208000. {
  208001. return queue != 0;
  208002. }
  208003. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208004. {
  208005. if (result == kIOReturnSuccess)
  208006. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208007. }
  208008. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208009. {
  208010. Array <int> cookies;
  208011. CFArrayRef elements;
  208012. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208013. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208014. return false;
  208015. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208016. {
  208017. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208018. // get the cookie
  208019. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208020. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208021. continue;
  208022. long number;
  208023. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208024. continue;
  208025. cookies.add ((int) number);
  208026. }
  208027. CFRelease (elements);
  208028. if ((*(IOHIDDeviceInterface**) device)
  208029. ->open ((IOHIDDeviceInterface**) device,
  208030. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208031. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208032. {
  208033. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208034. if (queue != 0)
  208035. {
  208036. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208037. for (int i = 0; i < cookies.size(); ++i)
  208038. {
  208039. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208040. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208041. }
  208042. CFRunLoopSourceRef eventSource;
  208043. if ((*(IOHIDQueueInterface**) queue)
  208044. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208045. {
  208046. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208047. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208048. {
  208049. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208050. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208051. return true;
  208052. }
  208053. }
  208054. }
  208055. }
  208056. return false;
  208057. }
  208058. void AppleRemoteDevice::handleCallbackInternal()
  208059. {
  208060. int totalValues = 0;
  208061. AbsoluteTime nullTime = { 0, 0 };
  208062. char cookies [12];
  208063. int numCookies = 0;
  208064. while (numCookies < numElementsInArray (cookies))
  208065. {
  208066. IOHIDEventStruct e;
  208067. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208068. break;
  208069. if ((int) e.elementCookie == 19)
  208070. {
  208071. remoteId = e.value;
  208072. buttonPressed (switched, false);
  208073. }
  208074. else
  208075. {
  208076. totalValues += e.value;
  208077. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208078. }
  208079. }
  208080. cookies [numCookies++] = 0;
  208081. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208082. static const char buttonPatterns[] =
  208083. {
  208084. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208085. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208086. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208087. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208088. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208089. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208090. 0x1f, 0x12, 0x04, 0x02, 0,
  208091. 0x1f, 0x12, 0x03, 0x02, 0,
  208092. 0x1f, 0x12, 0x1f, 0x12, 0,
  208093. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208094. 19, 0
  208095. };
  208096. int buttonNum = (int) menuButton;
  208097. int i = 0;
  208098. while (i < numElementsInArray (buttonPatterns))
  208099. {
  208100. if (strcmp (cookies, buttonPatterns + i) == 0)
  208101. {
  208102. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208103. break;
  208104. }
  208105. i += (int) strlen (buttonPatterns + i) + 1;
  208106. ++buttonNum;
  208107. }
  208108. }
  208109. #endif
  208110. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208111. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208112. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208113. // compiled on its own).
  208114. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208115. #if JUCE_MAC
  208116. END_JUCE_NAMESPACE
  208117. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208118. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208119. {
  208120. CriticalSection* contextLock;
  208121. bool needsUpdate;
  208122. }
  208123. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208124. - (bool) makeActive;
  208125. - (void) makeInactive;
  208126. - (void) reshape;
  208127. @end
  208128. @implementation ThreadSafeNSOpenGLView
  208129. - (id) initWithFrame: (NSRect) frameRect
  208130. pixelFormat: (NSOpenGLPixelFormat*) format
  208131. {
  208132. contextLock = new CriticalSection();
  208133. self = [super initWithFrame: frameRect pixelFormat: format];
  208134. if (self != nil)
  208135. [[NSNotificationCenter defaultCenter] addObserver: self
  208136. selector: @selector (_surfaceNeedsUpdate:)
  208137. name: NSViewGlobalFrameDidChangeNotification
  208138. object: self];
  208139. return self;
  208140. }
  208141. - (void) dealloc
  208142. {
  208143. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208144. delete contextLock;
  208145. [super dealloc];
  208146. }
  208147. - (bool) makeActive
  208148. {
  208149. const ScopedLock sl (*contextLock);
  208150. if ([self openGLContext] == 0)
  208151. return false;
  208152. [[self openGLContext] makeCurrentContext];
  208153. if (needsUpdate)
  208154. {
  208155. [super update];
  208156. needsUpdate = false;
  208157. }
  208158. return true;
  208159. }
  208160. - (void) makeInactive
  208161. {
  208162. const ScopedLock sl (*contextLock);
  208163. [NSOpenGLContext clearCurrentContext];
  208164. }
  208165. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208166. {
  208167. const ScopedLock sl (*contextLock);
  208168. needsUpdate = true;
  208169. }
  208170. - (void) update
  208171. {
  208172. const ScopedLock sl (*contextLock);
  208173. needsUpdate = true;
  208174. }
  208175. - (void) reshape
  208176. {
  208177. const ScopedLock sl (*contextLock);
  208178. needsUpdate = true;
  208179. }
  208180. @end
  208181. BEGIN_JUCE_NAMESPACE
  208182. class WindowedGLContext : public OpenGLContext
  208183. {
  208184. public:
  208185. WindowedGLContext (Component* const component,
  208186. const OpenGLPixelFormat& pixelFormat_,
  208187. NSOpenGLContext* sharedContext)
  208188. : renderContext (0),
  208189. pixelFormat (pixelFormat_)
  208190. {
  208191. jassert (component != 0);
  208192. NSOpenGLPixelFormatAttribute attribs [64];
  208193. int n = 0;
  208194. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208195. attribs[n++] = NSOpenGLPFAAccelerated;
  208196. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208197. attribs[n++] = NSOpenGLPFAColorSize;
  208198. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208199. pixelFormat.greenBits,
  208200. pixelFormat.blueBits);
  208201. attribs[n++] = NSOpenGLPFAAlphaSize;
  208202. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208203. attribs[n++] = NSOpenGLPFADepthSize;
  208204. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208205. attribs[n++] = NSOpenGLPFAStencilSize;
  208206. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208207. attribs[n++] = NSOpenGLPFAAccumSize;
  208208. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208209. pixelFormat.accumulationBufferGreenBits,
  208210. pixelFormat.accumulationBufferBlueBits,
  208211. pixelFormat.accumulationBufferAlphaBits);
  208212. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208213. attribs[n++] = NSOpenGLPFASampleBuffers;
  208214. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208215. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208216. attribs[n++] = NSOpenGLPFANoRecovery;
  208217. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208218. NSOpenGLPixelFormat* format
  208219. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208220. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208221. pixelFormat: format];
  208222. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208223. shareContext: sharedContext] autorelease];
  208224. const GLint swapInterval = 1;
  208225. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208226. [view setOpenGLContext: renderContext];
  208227. [renderContext setView: view];
  208228. [format release];
  208229. viewHolder = new NSViewComponentInternal (view, component);
  208230. }
  208231. ~WindowedGLContext()
  208232. {
  208233. makeInactive();
  208234. [renderContext clearDrawable];
  208235. viewHolder = 0;
  208236. }
  208237. bool makeActive() const throw()
  208238. {
  208239. jassert (renderContext != 0);
  208240. [view makeActive];
  208241. return isActive();
  208242. }
  208243. bool makeInactive() const throw()
  208244. {
  208245. [view makeInactive];
  208246. return true;
  208247. }
  208248. bool isActive() const throw()
  208249. {
  208250. return [NSOpenGLContext currentContext] == renderContext;
  208251. }
  208252. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208253. void* getRawContext() const throw() { return renderContext; }
  208254. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208255. {
  208256. }
  208257. void swapBuffers()
  208258. {
  208259. [renderContext flushBuffer];
  208260. }
  208261. bool setSwapInterval (const int numFramesPerSwap)
  208262. {
  208263. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208264. forParameter: NSOpenGLCPSwapInterval];
  208265. return true;
  208266. }
  208267. int getSwapInterval() const
  208268. {
  208269. GLint numFrames = 0;
  208270. [renderContext getValues: &numFrames
  208271. forParameter: NSOpenGLCPSwapInterval];
  208272. return numFrames;
  208273. }
  208274. void repaint()
  208275. {
  208276. // we need to invalidate the juce view that holds this gl view, to make it
  208277. // cause a repaint callback
  208278. NSView* v = (NSView*) viewHolder->view;
  208279. NSRect r = [v frame];
  208280. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208281. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208282. // repaint message, thus never causing our paint() callback, and never repainting
  208283. // the comp. So invalidating just a little bit around the edge helps..
  208284. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208285. }
  208286. void* getNativeWindowHandle() const { return viewHolder->view; }
  208287. juce_UseDebuggingNewOperator
  208288. NSOpenGLContext* renderContext;
  208289. ThreadSafeNSOpenGLView* view;
  208290. private:
  208291. OpenGLPixelFormat pixelFormat;
  208292. ScopedPointer <NSViewComponentInternal> viewHolder;
  208293. WindowedGLContext (const WindowedGLContext&);
  208294. WindowedGLContext& operator= (const WindowedGLContext&);
  208295. };
  208296. OpenGLContext* OpenGLComponent::createContext()
  208297. {
  208298. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  208299. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  208300. return (c->renderContext != 0) ? c.release() : 0;
  208301. }
  208302. void* OpenGLComponent::getNativeWindowHandle() const
  208303. {
  208304. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  208305. : 0;
  208306. }
  208307. void juce_glViewport (const int w, const int h)
  208308. {
  208309. glViewport (0, 0, w, h);
  208310. }
  208311. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208312. OwnedArray <OpenGLPixelFormat>& results)
  208313. {
  208314. /* GLint attribs [64];
  208315. int n = 0;
  208316. attribs[n++] = AGL_RGBA;
  208317. attribs[n++] = AGL_DOUBLEBUFFER;
  208318. attribs[n++] = AGL_ACCELERATED;
  208319. attribs[n++] = AGL_NO_RECOVERY;
  208320. attribs[n++] = AGL_NONE;
  208321. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208322. while (p != 0)
  208323. {
  208324. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208325. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208326. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208327. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208328. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208329. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208330. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208331. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208332. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208333. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208334. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208335. results.add (pf);
  208336. p = aglNextPixelFormat (p);
  208337. }*/
  208338. //jassertfalse //xxx can't see how you do this in cocoa!
  208339. }
  208340. #else
  208341. END_JUCE_NAMESPACE
  208342. @interface JuceGLView : UIView
  208343. {
  208344. }
  208345. + (Class) layerClass;
  208346. @end
  208347. @implementation JuceGLView
  208348. + (Class) layerClass
  208349. {
  208350. return [CAEAGLLayer class];
  208351. }
  208352. @end
  208353. BEGIN_JUCE_NAMESPACE
  208354. class GLESContext : public OpenGLContext
  208355. {
  208356. public:
  208357. GLESContext (UIViewComponentPeer* peer,
  208358. Component* const component_,
  208359. const OpenGLPixelFormat& pixelFormat_,
  208360. const GLESContext* const sharedContext,
  208361. NSUInteger apiType)
  208362. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  208363. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  208364. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  208365. {
  208366. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  208367. view.opaque = YES;
  208368. view.hidden = NO;
  208369. view.backgroundColor = [UIColor blackColor];
  208370. view.userInteractionEnabled = NO;
  208371. glLayer = (CAEAGLLayer*) [view layer];
  208372. [peer->view addSubview: view];
  208373. if (sharedContext != 0)
  208374. context = [[EAGLContext alloc] initWithAPI: apiType
  208375. sharegroup: [sharedContext->context sharegroup]];
  208376. else
  208377. context = [[EAGLContext alloc] initWithAPI: apiType];
  208378. createGLBuffers();
  208379. }
  208380. ~GLESContext()
  208381. {
  208382. makeInactive();
  208383. [context release];
  208384. [view removeFromSuperview];
  208385. [view release];
  208386. freeGLBuffers();
  208387. }
  208388. bool makeActive() const throw()
  208389. {
  208390. jassert (context != 0);
  208391. [EAGLContext setCurrentContext: context];
  208392. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208393. return true;
  208394. }
  208395. void swapBuffers()
  208396. {
  208397. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208398. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208399. }
  208400. bool makeInactive() const throw()
  208401. {
  208402. return [EAGLContext setCurrentContext: nil];
  208403. }
  208404. bool isActive() const throw()
  208405. {
  208406. return [EAGLContext currentContext] == context;
  208407. }
  208408. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208409. void* getRawContext() const throw() { return glLayer; }
  208410. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208411. {
  208412. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208413. if (lastWidth != w || lastHeight != h)
  208414. {
  208415. lastWidth = w;
  208416. lastHeight = h;
  208417. freeGLBuffers();
  208418. createGLBuffers();
  208419. }
  208420. }
  208421. bool setSwapInterval (const int numFramesPerSwap)
  208422. {
  208423. numFrames = numFramesPerSwap;
  208424. return true;
  208425. }
  208426. int getSwapInterval() const
  208427. {
  208428. return numFrames;
  208429. }
  208430. void repaint()
  208431. {
  208432. }
  208433. void createGLBuffers()
  208434. {
  208435. makeActive();
  208436. glGenFramebuffersOES (1, &frameBufferHandle);
  208437. glGenRenderbuffersOES (1, &colorBufferHandle);
  208438. glGenRenderbuffersOES (1, &depthBufferHandle);
  208439. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208440. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208441. GLint width, height;
  208442. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208443. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208444. if (useDepthBuffer)
  208445. {
  208446. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208447. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208448. }
  208449. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208450. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208451. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208452. if (useDepthBuffer)
  208453. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208454. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208455. }
  208456. void freeGLBuffers()
  208457. {
  208458. if (frameBufferHandle != 0)
  208459. {
  208460. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208461. frameBufferHandle = 0;
  208462. }
  208463. if (colorBufferHandle != 0)
  208464. {
  208465. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208466. colorBufferHandle = 0;
  208467. }
  208468. if (depthBufferHandle != 0)
  208469. {
  208470. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208471. depthBufferHandle = 0;
  208472. }
  208473. }
  208474. juce_UseDebuggingNewOperator
  208475. private:
  208476. Component::SafePointer<Component> component;
  208477. OpenGLPixelFormat pixelFormat;
  208478. JuceGLView* view;
  208479. CAEAGLLayer* glLayer;
  208480. EAGLContext* context;
  208481. bool useDepthBuffer;
  208482. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208483. int numFrames;
  208484. int lastWidth, lastHeight;
  208485. GLESContext (const GLESContext&);
  208486. GLESContext& operator= (const GLESContext&);
  208487. };
  208488. OpenGLContext* OpenGLComponent::createContext()
  208489. {
  208490. ScopedAutoReleasePool pool;
  208491. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208492. if (peer != 0)
  208493. return new GLESContext (peer, this, preferredPixelFormat,
  208494. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208495. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208496. return 0;
  208497. }
  208498. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208499. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208500. {
  208501. }
  208502. void juce_glViewport (const int w, const int h)
  208503. {
  208504. glViewport (0, 0, w, h);
  208505. }
  208506. #endif
  208507. #endif
  208508. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208509. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208510. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208511. // compiled on its own).
  208512. #if JUCE_INCLUDED_FILE
  208513. class JuceMainMenuHandler;
  208514. END_JUCE_NAMESPACE
  208515. using namespace JUCE_NAMESPACE;
  208516. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208517. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208518. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208519. #else
  208520. @interface JuceMenuCallback : NSObject
  208521. #endif
  208522. {
  208523. JuceMainMenuHandler* owner;
  208524. }
  208525. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208526. - (void) dealloc;
  208527. - (void) menuItemInvoked: (id) menu;
  208528. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208529. @end
  208530. BEGIN_JUCE_NAMESPACE
  208531. class JuceMainMenuHandler : private MenuBarModelListener,
  208532. private DeletedAtShutdown
  208533. {
  208534. public:
  208535. static JuceMainMenuHandler* instance;
  208536. JuceMainMenuHandler()
  208537. : currentModel (0),
  208538. lastUpdateTime (0)
  208539. {
  208540. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208541. }
  208542. ~JuceMainMenuHandler()
  208543. {
  208544. setMenu (0);
  208545. jassert (instance == this);
  208546. instance = 0;
  208547. [callback release];
  208548. }
  208549. void setMenu (MenuBarModel* const newMenuBarModel)
  208550. {
  208551. if (currentModel != newMenuBarModel)
  208552. {
  208553. if (currentModel != 0)
  208554. currentModel->removeListener (this);
  208555. currentModel = newMenuBarModel;
  208556. if (currentModel != 0)
  208557. currentModel->addListener (this);
  208558. menuBarItemsChanged (0);
  208559. }
  208560. }
  208561. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208562. const String& name, const int menuId, const int tag)
  208563. {
  208564. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208565. action: nil
  208566. keyEquivalent: @""];
  208567. [item setTag: tag];
  208568. NSMenu* sub = createMenu (child, name, menuId, tag);
  208569. [parent setSubmenu: sub forItem: item];
  208570. [sub setAutoenablesItems: false];
  208571. [sub release];
  208572. }
  208573. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208574. const String& name, const int menuId, const int tag)
  208575. {
  208576. [parentItem setTag: tag];
  208577. NSMenu* menu = [parentItem submenu];
  208578. [menu setTitle: juceStringToNS (name)];
  208579. while ([menu numberOfItems] > 0)
  208580. [menu removeItemAtIndex: 0];
  208581. PopupMenu::MenuItemIterator iter (menuToCopy);
  208582. while (iter.next())
  208583. addMenuItem (iter, menu, menuId, tag);
  208584. [menu setAutoenablesItems: false];
  208585. [menu update];
  208586. }
  208587. void menuBarItemsChanged (MenuBarModel*)
  208588. {
  208589. lastUpdateTime = Time::getMillisecondCounter();
  208590. StringArray menuNames;
  208591. if (currentModel != 0)
  208592. menuNames = currentModel->getMenuBarNames();
  208593. NSMenu* menuBar = [NSApp mainMenu];
  208594. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208595. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208596. int menuId = 1;
  208597. for (int i = 0; i < menuNames.size(); ++i)
  208598. {
  208599. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208600. if (i >= [menuBar numberOfItems] - 1)
  208601. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208602. else
  208603. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208604. }
  208605. }
  208606. static void flashMenuBar (NSMenu* menu)
  208607. {
  208608. if ([[menu title] isEqualToString: @"Apple"])
  208609. return;
  208610. [menu retain];
  208611. const unichar f35Key = NSF35FunctionKey;
  208612. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208613. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208614. action: nil
  208615. keyEquivalent: f35String];
  208616. [item setTarget: nil];
  208617. [menu insertItem: item atIndex: [menu numberOfItems]];
  208618. [item release];
  208619. if ([menu indexOfItem: item] >= 0)
  208620. {
  208621. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208622. location: NSZeroPoint
  208623. modifierFlags: NSCommandKeyMask
  208624. timestamp: 0
  208625. windowNumber: 0
  208626. context: [NSGraphicsContext currentContext]
  208627. characters: f35String
  208628. charactersIgnoringModifiers: f35String
  208629. isARepeat: NO
  208630. keyCode: 0];
  208631. [menu performKeyEquivalent: f35Event];
  208632. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208633. }
  208634. [menu release];
  208635. }
  208636. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208637. {
  208638. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208639. {
  208640. NSMenuItem* m = [menu itemAtIndex: i];
  208641. if ([m tag] == info.commandID)
  208642. return m;
  208643. if ([m submenu] != 0)
  208644. {
  208645. NSMenuItem* found = findMenuItem ([m submenu], info);
  208646. if (found != 0)
  208647. return found;
  208648. }
  208649. }
  208650. return 0;
  208651. }
  208652. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208653. {
  208654. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208655. if (item != 0)
  208656. flashMenuBar ([item menu]);
  208657. }
  208658. void updateMenus()
  208659. {
  208660. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208661. menuBarItemsChanged (0);
  208662. }
  208663. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208664. {
  208665. if (currentModel != 0)
  208666. {
  208667. if (commandManager != 0)
  208668. {
  208669. ApplicationCommandTarget::InvocationInfo info (commandId);
  208670. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208671. commandManager->invoke (info, true);
  208672. }
  208673. currentModel->menuItemSelected (commandId, topLevelIndex);
  208674. }
  208675. }
  208676. MenuBarModel* currentModel;
  208677. uint32 lastUpdateTime;
  208678. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208679. const int topLevelMenuId, const int topLevelIndex)
  208680. {
  208681. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf ("<end>", false, true));
  208682. if (text == 0)
  208683. text = @"";
  208684. if (iter.isSeparator)
  208685. {
  208686. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208687. }
  208688. else if (iter.isSectionHeader)
  208689. {
  208690. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208691. action: nil
  208692. keyEquivalent: @""];
  208693. [item setEnabled: false];
  208694. }
  208695. else if (iter.subMenu != 0)
  208696. {
  208697. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208698. action: nil
  208699. keyEquivalent: @""];
  208700. [item setTag: iter.itemId];
  208701. [item setEnabled: iter.isEnabled];
  208702. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208703. [sub setDelegate: nil];
  208704. [menuToAddTo setSubmenu: sub forItem: item];
  208705. [sub release];
  208706. }
  208707. else
  208708. {
  208709. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208710. action: @selector (menuItemInvoked:)
  208711. keyEquivalent: @""];
  208712. [item setTag: iter.itemId];
  208713. [item setEnabled: iter.isEnabled];
  208714. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208715. [item setTarget: (id) callback];
  208716. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208717. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208718. [item setRepresentedObject: info];
  208719. if (iter.commandManager != 0)
  208720. {
  208721. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208722. ->getKeyPressesAssignedToCommand (iter.itemId));
  208723. if (keyPresses.size() > 0)
  208724. {
  208725. const KeyPress& kp = keyPresses.getReference(0);
  208726. juce_wchar key = kp.getTextCharacter();
  208727. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208728. key = NSBackspaceCharacter;
  208729. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208730. key = NSDeleteCharacter;
  208731. else if (key == 0)
  208732. key = (juce_wchar) kp.getKeyCode();
  208733. unsigned int mods = 0;
  208734. if (kp.getModifiers().isShiftDown())
  208735. mods |= NSShiftKeyMask;
  208736. if (kp.getModifiers().isCtrlDown())
  208737. mods |= NSControlKeyMask;
  208738. if (kp.getModifiers().isAltDown())
  208739. mods |= NSAlternateKeyMask;
  208740. if (kp.getModifiers().isCommandDown())
  208741. mods |= NSCommandKeyMask;
  208742. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208743. [item setKeyEquivalentModifierMask: mods];
  208744. }
  208745. }
  208746. }
  208747. }
  208748. JuceMenuCallback* callback;
  208749. private:
  208750. NSMenu* createMenu (const PopupMenu menu,
  208751. const String& menuName,
  208752. const int topLevelMenuId,
  208753. const int topLevelIndex)
  208754. {
  208755. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208756. [m setAutoenablesItems: false];
  208757. [m setDelegate: callback];
  208758. PopupMenu::MenuItemIterator iter (menu);
  208759. while (iter.next())
  208760. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208761. [m update];
  208762. return m;
  208763. }
  208764. };
  208765. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208766. END_JUCE_NAMESPACE
  208767. @implementation JuceMenuCallback
  208768. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208769. {
  208770. [super init];
  208771. owner = owner_;
  208772. return self;
  208773. }
  208774. - (void) dealloc
  208775. {
  208776. [super dealloc];
  208777. }
  208778. - (void) menuItemInvoked: (id) menu
  208779. {
  208780. NSMenuItem* item = (NSMenuItem*) menu;
  208781. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208782. {
  208783. // If the menu is being triggered by a keypress, the OS will have picked it up before we had a chance to offer it to
  208784. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208785. // into the focused component and let it trigger the menu item indirectly.
  208786. NSEvent* e = [NSApp currentEvent];
  208787. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208788. {
  208789. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208790. {
  208791. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208792. if (peer != 0)
  208793. {
  208794. if ([e type] == NSKeyDown)
  208795. peer->redirectKeyDown (e);
  208796. else
  208797. peer->redirectKeyUp (e);
  208798. return;
  208799. }
  208800. }
  208801. }
  208802. NSArray* info = (NSArray*) [item representedObject];
  208803. owner->invoke ((int) [item tag],
  208804. (ApplicationCommandManager*) (pointer_sized_int)
  208805. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208806. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208807. }
  208808. }
  208809. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208810. {
  208811. if (JuceMainMenuHandler::instance != 0)
  208812. JuceMainMenuHandler::instance->updateMenus();
  208813. }
  208814. @end
  208815. BEGIN_JUCE_NAMESPACE
  208816. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208817. const PopupMenu* extraItems)
  208818. {
  208819. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208820. {
  208821. PopupMenu::MenuItemIterator iter (*extraItems);
  208822. while (iter.next())
  208823. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208824. [menu addItem: [NSMenuItem separatorItem]];
  208825. }
  208826. NSMenuItem* item;
  208827. // Services...
  208828. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208829. action: nil keyEquivalent: @""];
  208830. [menu addItem: item];
  208831. [item release];
  208832. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208833. [menu setSubmenu: servicesMenu forItem: item];
  208834. [NSApp setServicesMenu: servicesMenu];
  208835. [servicesMenu release];
  208836. [menu addItem: [NSMenuItem separatorItem]];
  208837. // Hide + Show stuff...
  208838. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208839. action: @selector (hide:) keyEquivalent: @"h"];
  208840. [item setTarget: NSApp];
  208841. [menu addItem: item];
  208842. [item release];
  208843. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208844. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208845. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208846. [item setTarget: NSApp];
  208847. [menu addItem: item];
  208848. [item release];
  208849. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208850. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208851. [item setTarget: NSApp];
  208852. [menu addItem: item];
  208853. [item release];
  208854. [menu addItem: [NSMenuItem separatorItem]];
  208855. // Quit item....
  208856. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208857. action: @selector (terminate:) keyEquivalent: @"q"];
  208858. [item setTarget: NSApp];
  208859. [menu addItem: item];
  208860. [item release];
  208861. return menu;
  208862. }
  208863. // Since our app has no NIB, this initialises a standard app menu...
  208864. static void rebuildMainMenu (const PopupMenu* extraItems)
  208865. {
  208866. // this can't be used in a plugin!
  208867. jassert (JUCEApplication::getInstance() != 0);
  208868. if (JUCEApplication::getInstance() != 0)
  208869. {
  208870. const ScopedAutoReleasePool pool;
  208871. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208872. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208873. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208874. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208875. [mainMenu setSubmenu: appMenu forItem: item];
  208876. [NSApp setMainMenu: mainMenu];
  208877. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208878. [appMenu release];
  208879. [mainMenu release];
  208880. }
  208881. }
  208882. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208883. const PopupMenu* extraAppleMenuItems)
  208884. {
  208885. if (getMacMainMenu() != newMenuBarModel)
  208886. {
  208887. const ScopedAutoReleasePool pool;
  208888. if (newMenuBarModel == 0)
  208889. {
  208890. delete JuceMainMenuHandler::instance;
  208891. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208892. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208893. extraAppleMenuItems = 0;
  208894. }
  208895. else
  208896. {
  208897. if (JuceMainMenuHandler::instance == 0)
  208898. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208899. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208900. }
  208901. }
  208902. rebuildMainMenu (extraAppleMenuItems);
  208903. if (newMenuBarModel != 0)
  208904. newMenuBarModel->menuItemsChanged();
  208905. }
  208906. MenuBarModel* MenuBarModel::getMacMainMenu()
  208907. {
  208908. return JuceMainMenuHandler::instance != 0
  208909. ? JuceMainMenuHandler::instance->currentModel : 0;
  208910. }
  208911. void initialiseMainMenu()
  208912. {
  208913. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208914. rebuildMainMenu (0);
  208915. }
  208916. #endif
  208917. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208918. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208919. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208920. // compiled on its own).
  208921. #if JUCE_INCLUDED_FILE
  208922. #if JUCE_MAC
  208923. END_JUCE_NAMESPACE
  208924. using namespace JUCE_NAMESPACE;
  208925. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208926. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208927. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208928. #else
  208929. @interface JuceFileChooserDelegate : NSObject
  208930. #endif
  208931. {
  208932. StringArray* filters;
  208933. }
  208934. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208935. - (void) dealloc;
  208936. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208937. @end
  208938. @implementation JuceFileChooserDelegate
  208939. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208940. {
  208941. [super init];
  208942. filters = filters_;
  208943. return self;
  208944. }
  208945. - (void) dealloc
  208946. {
  208947. delete filters;
  208948. [super dealloc];
  208949. }
  208950. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208951. {
  208952. const File f (nsStringToJuce (filename));
  208953. for (int i = filters->size(); --i >= 0;)
  208954. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208955. return true;
  208956. return f.isDirectory();
  208957. }
  208958. @end
  208959. BEGIN_JUCE_NAMESPACE
  208960. void FileChooser::showPlatformDialog (Array<File>& results,
  208961. const String& title,
  208962. const File& currentFileOrDirectory,
  208963. const String& filter,
  208964. bool selectsDirectory,
  208965. bool selectsFiles,
  208966. bool isSaveDialogue,
  208967. bool warnAboutOverwritingExistingFiles,
  208968. bool selectMultipleFiles,
  208969. FilePreviewComponent* extraInfoComponent)
  208970. {
  208971. const ScopedAutoReleasePool pool;
  208972. StringArray* filters = new StringArray();
  208973. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  208974. filters->trim();
  208975. filters->removeEmptyStrings();
  208976. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208977. [delegate autorelease];
  208978. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208979. : [NSOpenPanel openPanel];
  208980. [panel setTitle: juceStringToNS (title)];
  208981. if (! isSaveDialogue)
  208982. {
  208983. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208984. [openPanel setCanChooseDirectories: selectsDirectory];
  208985. [openPanel setCanChooseFiles: selectsFiles];
  208986. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208987. }
  208988. [panel setDelegate: delegate];
  208989. if (isSaveDialogue || selectsDirectory)
  208990. [panel setCanCreateDirectories: YES];
  208991. String directory, filename;
  208992. if (currentFileOrDirectory.isDirectory())
  208993. {
  208994. directory = currentFileOrDirectory.getFullPathName();
  208995. }
  208996. else
  208997. {
  208998. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208999. filename = currentFileOrDirectory.getFileName();
  209000. }
  209001. if ([panel runModalForDirectory: juceStringToNS (directory)
  209002. file: juceStringToNS (filename)]
  209003. == NSOKButton)
  209004. {
  209005. if (isSaveDialogue)
  209006. {
  209007. results.add (File (nsStringToJuce ([panel filename])));
  209008. }
  209009. else
  209010. {
  209011. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209012. NSArray* urls = [openPanel filenames];
  209013. for (unsigned int i = 0; i < [urls count]; ++i)
  209014. {
  209015. NSString* f = [urls objectAtIndex: i];
  209016. results.add (File (nsStringToJuce (f)));
  209017. }
  209018. }
  209019. }
  209020. [panel setDelegate: nil];
  209021. }
  209022. #else
  209023. void FileChooser::showPlatformDialog (Array<File>& results,
  209024. const String& title,
  209025. const File& currentFileOrDirectory,
  209026. const String& filter,
  209027. bool selectsDirectory,
  209028. bool selectsFiles,
  209029. bool isSaveDialogue,
  209030. bool warnAboutOverwritingExistingFiles,
  209031. bool selectMultipleFiles,
  209032. FilePreviewComponent* extraInfoComponent)
  209033. {
  209034. const ScopedAutoReleasePool pool;
  209035. jassertfalse //xxx to do
  209036. }
  209037. #endif
  209038. #endif
  209039. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209040. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209041. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209042. // compiled on its own).
  209043. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209044. END_JUCE_NAMESPACE
  209045. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  209046. @interface NonInterceptingQTMovieView : QTMovieView
  209047. {
  209048. }
  209049. - (id) initWithFrame: (NSRect) frame;
  209050. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  209051. - (NSView*) hitTest: (NSPoint) p;
  209052. @end
  209053. @implementation NonInterceptingQTMovieView
  209054. - (id) initWithFrame: (NSRect) frame
  209055. {
  209056. self = [super initWithFrame: frame];
  209057. [self setNextResponder: [self superview]];
  209058. return self;
  209059. }
  209060. - (void) dealloc
  209061. {
  209062. [super dealloc];
  209063. }
  209064. - (NSView*) hitTest: (NSPoint) point
  209065. {
  209066. return [self isControllerVisible] ? [super hitTest: point] : nil;
  209067. }
  209068. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  209069. {
  209070. return YES;
  209071. }
  209072. @end
  209073. BEGIN_JUCE_NAMESPACE
  209074. #define theMovie (static_cast <QTMovie*> (movie))
  209075. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209076. : movie (0)
  209077. {
  209078. setOpaque (true);
  209079. setVisible (true);
  209080. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209081. setView (view);
  209082. [view release];
  209083. }
  209084. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209085. {
  209086. closeMovie();
  209087. setView (0);
  209088. }
  209089. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209090. {
  209091. return true;
  209092. }
  209093. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209094. {
  209095. // unfortunately, QTMovie objects can only be created on the main thread..
  209096. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209097. QTMovie* movie = 0;
  209098. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209099. if (fin != 0)
  209100. {
  209101. movieFile = fin->getFile();
  209102. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209103. error: nil];
  209104. }
  209105. else
  209106. {
  209107. MemoryBlock temp;
  209108. movieStream->readIntoMemoryBlock (temp);
  209109. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209110. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209111. {
  209112. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209113. length: temp.getSize()]
  209114. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209115. MIMEType: @""]
  209116. error: nil];
  209117. if (movie != 0)
  209118. break;
  209119. }
  209120. }
  209121. return movie;
  209122. }
  209123. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209124. const bool isControllerVisible_)
  209125. {
  209126. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209127. }
  209128. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209129. const bool controllerVisible_)
  209130. {
  209131. closeMovie();
  209132. if (getPeer() == 0)
  209133. {
  209134. // To open a movie, this component must be visible inside a functioning window, so that
  209135. // the QT control can be assigned to the window.
  209136. jassertfalse
  209137. return false;
  209138. }
  209139. movie = openMovieFromStream (movieStream, movieFile);
  209140. [theMovie retain];
  209141. QTMovieView* view = (QTMovieView*) getView();
  209142. [view setMovie: theMovie];
  209143. [view setControllerVisible: controllerVisible_];
  209144. setLooping (looping);
  209145. return movie != nil;
  209146. }
  209147. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209148. const bool isControllerVisible_)
  209149. {
  209150. // unfortunately, QTMovie objects can only be created on the main thread..
  209151. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209152. closeMovie();
  209153. if (getPeer() == 0)
  209154. {
  209155. // To open a movie, this component must be visible inside a functioning window, so that
  209156. // the QT control can be assigned to the window.
  209157. jassertfalse
  209158. return false;
  209159. }
  209160. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209161. NSError* err;
  209162. if ([QTMovie canInitWithURL: url])
  209163. movie = [QTMovie movieWithURL: url error: &err];
  209164. [theMovie retain];
  209165. QTMovieView* view = (QTMovieView*) getView();
  209166. [view setMovie: theMovie];
  209167. [view setControllerVisible: controllerVisible];
  209168. setLooping (looping);
  209169. return movie != nil;
  209170. }
  209171. void QuickTimeMovieComponent::closeMovie()
  209172. {
  209173. stop();
  209174. QTMovieView* view = (QTMovieView*) getView();
  209175. [view setMovie: nil];
  209176. [theMovie release];
  209177. movie = 0;
  209178. movieFile = File::nonexistent;
  209179. }
  209180. bool QuickTimeMovieComponent::isMovieOpen() const
  209181. {
  209182. return movie != nil;
  209183. }
  209184. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209185. {
  209186. return movieFile;
  209187. }
  209188. void QuickTimeMovieComponent::play()
  209189. {
  209190. [theMovie play];
  209191. }
  209192. void QuickTimeMovieComponent::stop()
  209193. {
  209194. [theMovie stop];
  209195. }
  209196. bool QuickTimeMovieComponent::isPlaying() const
  209197. {
  209198. return movie != 0 && [theMovie rate] != 0;
  209199. }
  209200. void QuickTimeMovieComponent::setPosition (const double seconds)
  209201. {
  209202. if (movie != 0)
  209203. {
  209204. QTTime t;
  209205. t.timeValue = (uint64) (100000.0 * seconds);
  209206. t.timeScale = 100000;
  209207. t.flags = 0;
  209208. [theMovie setCurrentTime: t];
  209209. }
  209210. }
  209211. double QuickTimeMovieComponent::getPosition() const
  209212. {
  209213. if (movie == 0)
  209214. return 0.0;
  209215. QTTime t = [theMovie currentTime];
  209216. return t.timeValue / (double) t.timeScale;
  209217. }
  209218. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209219. {
  209220. [theMovie setRate: newSpeed];
  209221. }
  209222. double QuickTimeMovieComponent::getMovieDuration() const
  209223. {
  209224. if (movie == 0)
  209225. return 0.0;
  209226. QTTime t = [theMovie duration];
  209227. return t.timeValue / (double) t.timeScale;
  209228. }
  209229. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209230. {
  209231. looping = shouldLoop;
  209232. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209233. forKey: QTMovieLoopsAttribute];
  209234. }
  209235. bool QuickTimeMovieComponent::isLooping() const
  209236. {
  209237. return looping;
  209238. }
  209239. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209240. {
  209241. [theMovie setVolume: newVolume];
  209242. }
  209243. float QuickTimeMovieComponent::getMovieVolume() const
  209244. {
  209245. return movie != 0 ? [theMovie volume] : 0.0f;
  209246. }
  209247. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209248. {
  209249. width = 0;
  209250. height = 0;
  209251. if (movie != 0)
  209252. {
  209253. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209254. width = (int) s.width;
  209255. height = (int) s.height;
  209256. }
  209257. }
  209258. void QuickTimeMovieComponent::paint (Graphics& g)
  209259. {
  209260. if (movie == 0)
  209261. g.fillAll (Colours::black);
  209262. }
  209263. bool QuickTimeMovieComponent::isControllerVisible() const
  209264. {
  209265. return controllerVisible;
  209266. }
  209267. void QuickTimeMovieComponent::goToStart()
  209268. {
  209269. setPosition (0.0);
  209270. }
  209271. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209272. const RectanglePlacement& placement)
  209273. {
  209274. int normalWidth, normalHeight;
  209275. getMovieNormalSize (normalWidth, normalHeight);
  209276. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209277. {
  209278. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209279. placement.applyTo (x, y, w, h,
  209280. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209281. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209282. if (w > 0 && h > 0)
  209283. {
  209284. setBounds (roundToInt (x), roundToInt (y),
  209285. roundToInt (w), roundToInt (h));
  209286. }
  209287. }
  209288. else
  209289. {
  209290. setBounds (spaceToFitWithin);
  209291. }
  209292. }
  209293. #if ! (JUCE_MAC && JUCE_64BIT)
  209294. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209295. {
  209296. if (movieStream == 0)
  209297. return false;
  209298. File file;
  209299. QTMovie* movie = openMovieFromStream (movieStream, file);
  209300. if (movie != nil)
  209301. result = [movie quickTimeMovie];
  209302. return movie != nil;
  209303. }
  209304. #endif
  209305. #endif
  209306. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209307. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209308. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209309. // compiled on its own).
  209310. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209311. const int kilobytesPerSecond1x = 176;
  209312. END_JUCE_NAMESPACE
  209313. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209314. @interface OpenDiskDevice : NSObject
  209315. {
  209316. @public
  209317. DRDevice* device;
  209318. NSMutableArray* tracks;
  209319. bool underrunProtection;
  209320. }
  209321. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209322. - (void) dealloc;
  209323. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209324. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209325. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209326. @end
  209327. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209328. @interface AudioTrackProducer : NSObject
  209329. {
  209330. JUCE_NAMESPACE::AudioSource* source;
  209331. int readPosition, lengthInFrames;
  209332. }
  209333. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209334. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209335. - (void) dealloc;
  209336. - (void) setupTrackProperties: (DRTrack*) track;
  209337. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209338. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209339. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209340. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209341. toMedia:(NSDictionary*)mediaInfo;
  209342. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209343. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209344. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209345. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209346. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209347. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209348. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209349. ioFlags:(uint32_t*)flags;
  209350. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209351. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209352. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209353. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209354. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209355. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209356. ioFlags:(uint32_t*)flags;
  209357. @end
  209358. @implementation OpenDiskDevice
  209359. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209360. {
  209361. [super init];
  209362. device = device_;
  209363. tracks = [[NSMutableArray alloc] init];
  209364. underrunProtection = true;
  209365. return self;
  209366. }
  209367. - (void) dealloc
  209368. {
  209369. [tracks release];
  209370. [super dealloc];
  209371. }
  209372. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209373. {
  209374. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209375. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209376. [p setupTrackProperties: t];
  209377. [tracks addObject: t];
  209378. [t release];
  209379. [p release];
  209380. }
  209381. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209382. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209383. {
  209384. DRBurn* burn = [DRBurn burnForDevice: device];
  209385. if (! [device acquireExclusiveAccess])
  209386. {
  209387. *error = "Couldn't open or write to the CD device";
  209388. return;
  209389. }
  209390. [device acquireMediaReservation];
  209391. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209392. [d autorelease];
  209393. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209394. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209395. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209396. if (burnSpeed > 0)
  209397. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209398. if (! underrunProtection)
  209399. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209400. [burn setProperties: d];
  209401. [burn writeLayout: tracks];
  209402. for (;;)
  209403. {
  209404. JUCE_NAMESPACE::Thread::sleep (300);
  209405. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209406. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209407. {
  209408. [burn abort];
  209409. *error = "User cancelled the write operation";
  209410. break;
  209411. }
  209412. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209413. {
  209414. *error = "Write operation failed";
  209415. break;
  209416. }
  209417. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209418. {
  209419. break;
  209420. }
  209421. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209422. objectForKey: DRErrorStatusErrorStringKey];
  209423. if ([err length] > 0)
  209424. {
  209425. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209426. break;
  209427. }
  209428. }
  209429. [device releaseMediaReservation];
  209430. [device releaseExclusiveAccess];
  209431. }
  209432. @end
  209433. @implementation AudioTrackProducer
  209434. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209435. {
  209436. lengthInFrames = lengthInFrames_;
  209437. readPosition = 0;
  209438. return self;
  209439. }
  209440. - (void) setupTrackProperties: (DRTrack*) track
  209441. {
  209442. NSMutableDictionary* p = [[track properties] mutableCopy];
  209443. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209444. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209445. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209446. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209447. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209448. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209449. [track setProperties: p];
  209450. [p release];
  209451. }
  209452. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209453. {
  209454. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209455. if (s != nil)
  209456. s->source = source_;
  209457. return s;
  209458. }
  209459. - (void) dealloc
  209460. {
  209461. if (source != 0)
  209462. {
  209463. source->releaseResources();
  209464. delete source;
  209465. }
  209466. [super dealloc];
  209467. }
  209468. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209469. {
  209470. }
  209471. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209472. {
  209473. return true;
  209474. }
  209475. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209476. {
  209477. return lengthInFrames;
  209478. }
  209479. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209480. toMedia: (NSDictionary*) mediaInfo
  209481. {
  209482. if (source != 0)
  209483. source->prepareToPlay (44100 / 75, 44100);
  209484. readPosition = 0;
  209485. return true;
  209486. }
  209487. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209488. {
  209489. if (source != 0)
  209490. source->prepareToPlay (44100 / 75, 44100);
  209491. return true;
  209492. }
  209493. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209494. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209495. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209496. {
  209497. if (source != 0)
  209498. {
  209499. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209500. if (numSamples > 0)
  209501. {
  209502. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209503. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209504. info.buffer = &tempBuffer;
  209505. info.startSample = 0;
  209506. info.numSamples = numSamples;
  209507. source->getNextAudioBlock (info);
  209508. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209509. buffer, numSamples, 4);
  209510. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209511. buffer + 2, numSamples, 4);
  209512. readPosition += numSamples;
  209513. }
  209514. return numSamples * 4;
  209515. }
  209516. return 0;
  209517. }
  209518. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209519. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209520. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209521. ioFlags: (uint32_t*) flags
  209522. {
  209523. zeromem (buffer, bufferLength);
  209524. return bufferLength;
  209525. }
  209526. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209527. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209528. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209529. {
  209530. return true;
  209531. }
  209532. @end
  209533. BEGIN_JUCE_NAMESPACE
  209534. class AudioCDBurner::Pimpl : public Timer
  209535. {
  209536. public:
  209537. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209538. : device (0), owner (owner_)
  209539. {
  209540. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209541. if (dev != 0)
  209542. {
  209543. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209544. lastState = getDiskState();
  209545. startTimer (1000);
  209546. }
  209547. }
  209548. ~Pimpl()
  209549. {
  209550. stopTimer();
  209551. [device release];
  209552. }
  209553. void timerCallback()
  209554. {
  209555. const DiskState state = getDiskState();
  209556. if (state != lastState)
  209557. {
  209558. lastState = state;
  209559. owner.sendChangeMessage (&owner);
  209560. }
  209561. }
  209562. DiskState getDiskState() const
  209563. {
  209564. if ([device->device isValid])
  209565. {
  209566. NSDictionary* status = [device->device status];
  209567. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209568. if ([state isEqualTo: DRDeviceMediaStateNone])
  209569. {
  209570. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209571. return trayOpen;
  209572. return noDisc;
  209573. }
  209574. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209575. {
  209576. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209577. return writableDiskPresent;
  209578. else
  209579. return readOnlyDiskPresent;
  209580. }
  209581. }
  209582. return unknown;
  209583. }
  209584. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209585. const Array<int> getAvailableWriteSpeeds() const
  209586. {
  209587. Array<int> results;
  209588. if ([device->device isValid])
  209589. {
  209590. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209591. for (unsigned int i = 0; i < [speeds count]; ++i)
  209592. {
  209593. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209594. results.add (kbPerSec / kilobytesPerSecond1x);
  209595. }
  209596. }
  209597. return results;
  209598. }
  209599. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209600. {
  209601. if ([device->device isValid])
  209602. {
  209603. device->underrunProtection = shouldBeEnabled;
  209604. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209605. }
  209606. return false;
  209607. }
  209608. int getNumAvailableAudioBlocks() const
  209609. {
  209610. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209611. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209612. }
  209613. OpenDiskDevice* device;
  209614. private:
  209615. DiskState lastState;
  209616. AudioCDBurner& owner;
  209617. };
  209618. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209619. {
  209620. pimpl = new Pimpl (*this, deviceIndex);
  209621. }
  209622. AudioCDBurner::~AudioCDBurner()
  209623. {
  209624. }
  209625. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209626. {
  209627. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209628. if (b->pimpl->device == 0)
  209629. b = 0;
  209630. return b.release();
  209631. }
  209632. static NSArray* findDiskBurnerDevices()
  209633. {
  209634. NSMutableArray* results = [NSMutableArray array];
  209635. NSArray* devs = [DRDevice devices];
  209636. if (devs != 0)
  209637. {
  209638. int num = [devs count];
  209639. int i;
  209640. for (i = 0; i < num; ++i)
  209641. {
  209642. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209643. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209644. if (name != nil)
  209645. [results addObject: name];
  209646. }
  209647. }
  209648. return results;
  209649. }
  209650. const StringArray AudioCDBurner::findAvailableDevices()
  209651. {
  209652. NSArray* names = findDiskBurnerDevices();
  209653. StringArray s;
  209654. for (unsigned int i = 0; i < [names count]; ++i)
  209655. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209656. return s;
  209657. }
  209658. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209659. {
  209660. return pimpl->getDiskState();
  209661. }
  209662. bool AudioCDBurner::isDiskPresent() const
  209663. {
  209664. return getDiskState() == writableDiskPresent;
  209665. }
  209666. bool AudioCDBurner::openTray()
  209667. {
  209668. return pimpl->openTray();
  209669. }
  209670. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209671. {
  209672. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209673. DiskState oldState = getDiskState();
  209674. DiskState newState = oldState;
  209675. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209676. {
  209677. newState = getDiskState();
  209678. Thread::sleep (100);
  209679. }
  209680. return newState;
  209681. }
  209682. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209683. {
  209684. return pimpl->getAvailableWriteSpeeds();
  209685. }
  209686. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209687. {
  209688. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209689. }
  209690. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209691. {
  209692. return pimpl->getNumAvailableAudioBlocks();
  209693. }
  209694. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209695. {
  209696. if ([pimpl->device->device isValid])
  209697. {
  209698. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209699. return true;
  209700. }
  209701. return false;
  209702. }
  209703. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209704. bool ejectDiscAfterwards,
  209705. bool performFakeBurnForTesting,
  209706. int writeSpeed)
  209707. {
  209708. String error ("Couldn't open or write to the CD device");
  209709. if ([pimpl->device->device isValid])
  209710. {
  209711. error = String::empty;
  209712. [pimpl->device burn: listener
  209713. errorString: &error
  209714. ejectAfterwards: ejectDiscAfterwards
  209715. isFake: performFakeBurnForTesting
  209716. speed: writeSpeed];
  209717. }
  209718. return error;
  209719. }
  209720. #endif
  209721. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209722. void AudioCDReader::ejectDisk()
  209723. {
  209724. const ScopedAutoReleasePool p;
  209725. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209726. }
  209727. #endif
  209728. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209729. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209730. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209731. // compiled on its own).
  209732. #if JUCE_INCLUDED_FILE
  209733. class AppDelegateRedirector
  209734. {
  209735. public:
  209736. AppDelegateRedirector()
  209737. {
  209738. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209739. runLoop = CFRunLoopGetMain();
  209740. #else
  209741. runLoop = CFRunLoopGetCurrent();
  209742. #endif
  209743. CFRunLoopSourceContext sourceContext;
  209744. zerostruct (sourceContext);
  209745. sourceContext.info = this;
  209746. sourceContext.perform = runLoopSourceCallback;
  209747. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209748. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209749. }
  209750. virtual ~AppDelegateRedirector()
  209751. {
  209752. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209753. CFRunLoopSourceInvalidate (runLoopSource);
  209754. CFRelease (runLoopSource);
  209755. while (messages.size() > 0)
  209756. delete ((Message*) messages.remove(0));
  209757. }
  209758. virtual NSApplicationTerminateReply shouldTerminate()
  209759. {
  209760. if (JUCEApplication::getInstance() != 0)
  209761. {
  209762. JUCEApplication::getInstance()->systemRequestedQuit();
  209763. return NSTerminateCancel;
  209764. }
  209765. return NSTerminateNow;
  209766. }
  209767. virtual BOOL openFile (const NSString* filename)
  209768. {
  209769. if (JUCEApplication::getInstance() != 0)
  209770. {
  209771. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209772. return YES;
  209773. }
  209774. return NO;
  209775. }
  209776. virtual void openFiles (NSArray* filenames)
  209777. {
  209778. StringArray files;
  209779. for (unsigned int i = 0; i < [filenames count]; ++i)
  209780. {
  209781. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209782. if (filename.containsChar (' '))
  209783. filename = filename.quoted('"');
  209784. files.add (filename);
  209785. }
  209786. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209787. {
  209788. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (" "));
  209789. }
  209790. }
  209791. virtual void focusChanged()
  209792. {
  209793. juce_HandleProcessFocusChange();
  209794. }
  209795. struct CallbackMessagePayload
  209796. {
  209797. MessageCallbackFunction* function;
  209798. void* parameter;
  209799. void* volatile result;
  209800. bool volatile hasBeenExecuted;
  209801. };
  209802. virtual void performCallback (CallbackMessagePayload* pl)
  209803. {
  209804. pl->result = (*pl->function) (pl->parameter);
  209805. pl->hasBeenExecuted = true;
  209806. }
  209807. virtual void deleteSelf()
  209808. {
  209809. delete this;
  209810. }
  209811. void postMessage (void* m)
  209812. {
  209813. messages.add (m);
  209814. CFRunLoopSourceSignal (runLoopSource);
  209815. CFRunLoopWakeUp (runLoop);
  209816. }
  209817. private:
  209818. CFRunLoopRef runLoop;
  209819. CFRunLoopSourceRef runLoopSource;
  209820. Array <void*, CriticalSection> messages;
  209821. void runLoopCallback()
  209822. {
  209823. int numDispatched = 0;
  209824. do
  209825. {
  209826. void* const nextMessage = messages.remove (0);
  209827. if (nextMessage == 0)
  209828. return;
  209829. const ScopedAutoReleasePool pool;
  209830. MessageManager::getInstance()->deliverMessage (nextMessage);
  209831. } while (++numDispatched <= 4);
  209832. CFRunLoopSourceSignal (runLoopSource);
  209833. CFRunLoopWakeUp (runLoop);
  209834. }
  209835. static void runLoopSourceCallback (void* info)
  209836. {
  209837. ((AppDelegateRedirector*) info)->runLoopCallback();
  209838. }
  209839. };
  209840. END_JUCE_NAMESPACE
  209841. using namespace JUCE_NAMESPACE;
  209842. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209843. @interface JuceAppDelegate : NSObject
  209844. {
  209845. @private
  209846. id oldDelegate;
  209847. @public
  209848. AppDelegateRedirector* redirector;
  209849. }
  209850. - (JuceAppDelegate*) init;
  209851. - (void) dealloc;
  209852. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209853. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209854. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209855. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209856. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209857. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209858. - (void) performCallback: (id) info;
  209859. - (void) dummyMethod;
  209860. @end
  209861. @implementation JuceAppDelegate
  209862. - (JuceAppDelegate*) init
  209863. {
  209864. [super init];
  209865. redirector = new AppDelegateRedirector();
  209866. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209867. if (JUCEApplication::getInstance() != 0)
  209868. {
  209869. oldDelegate = [NSApp delegate];
  209870. [NSApp setDelegate: self];
  209871. }
  209872. else
  209873. {
  209874. oldDelegate = 0;
  209875. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209876. name: NSApplicationDidResignActiveNotification object: NSApp];
  209877. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209878. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209879. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209880. name: NSApplicationWillUnhideNotification object: NSApp];
  209881. }
  209882. return self;
  209883. }
  209884. - (void) dealloc
  209885. {
  209886. if (oldDelegate != 0)
  209887. [NSApp setDelegate: oldDelegate];
  209888. redirector->deleteSelf();
  209889. [super dealloc];
  209890. }
  209891. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209892. {
  209893. return redirector->shouldTerminate();
  209894. }
  209895. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209896. {
  209897. return redirector->openFile (filename);
  209898. }
  209899. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209900. {
  209901. return redirector->openFiles (filenames);
  209902. }
  209903. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209904. {
  209905. redirector->focusChanged();
  209906. }
  209907. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209908. {
  209909. redirector->focusChanged();
  209910. }
  209911. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209912. {
  209913. redirector->focusChanged();
  209914. }
  209915. - (void) performCallback: (id) info
  209916. {
  209917. if ([info isKindOfClass: [NSData class]])
  209918. {
  209919. AppDelegateRedirector::CallbackMessagePayload* pl
  209920. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  209921. if (pl != 0)
  209922. redirector->performCallback (pl);
  209923. }
  209924. else
  209925. {
  209926. jassertfalse // should never get here!
  209927. }
  209928. }
  209929. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209930. @end
  209931. BEGIN_JUCE_NAMESPACE
  209932. static JuceAppDelegate* juceAppDelegate = 0;
  209933. void MessageManager::runDispatchLoop()
  209934. {
  209935. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209936. {
  209937. const ScopedAutoReleasePool pool;
  209938. // must only be called by the message thread!
  209939. jassert (isThisTheMessageThread());
  209940. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209941. @try
  209942. {
  209943. [NSApp run];
  209944. }
  209945. @catch (NSException* e)
  209946. {
  209947. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209948. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209949. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209950. }
  209951. @finally
  209952. {
  209953. }
  209954. #else
  209955. [NSApp run];
  209956. #endif
  209957. }
  209958. }
  209959. void MessageManager::stopDispatchLoop()
  209960. {
  209961. quitMessagePosted = true;
  209962. [NSApp stop: nil];
  209963. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209964. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209965. }
  209966. static bool isEventBlockedByModalComps (NSEvent* e)
  209967. {
  209968. if (Component::getNumCurrentlyModalComponents() == 0)
  209969. return false;
  209970. NSWindow* const w = [e window];
  209971. if (w == 0 || [w worksWhenModal])
  209972. return false;
  209973. bool isKey = false, isInputAttempt = false;
  209974. switch ([e type])
  209975. {
  209976. case NSKeyDown:
  209977. case NSKeyUp:
  209978. isKey = isInputAttempt = true;
  209979. break;
  209980. case NSLeftMouseDown:
  209981. case NSRightMouseDown:
  209982. case NSOtherMouseDown:
  209983. isInputAttempt = true;
  209984. break;
  209985. case NSLeftMouseDragged:
  209986. case NSRightMouseDragged:
  209987. case NSLeftMouseUp:
  209988. case NSRightMouseUp:
  209989. case NSOtherMouseUp:
  209990. case NSOtherMouseDragged:
  209991. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  209992. return false;
  209993. break;
  209994. case NSMouseMoved:
  209995. case NSMouseEntered:
  209996. case NSMouseExited:
  209997. case NSCursorUpdate:
  209998. case NSScrollWheel:
  209999. case NSTabletPoint:
  210000. case NSTabletProximity:
  210001. break;
  210002. default:
  210003. return false;
  210004. }
  210005. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210006. {
  210007. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210008. NSView* const compView = (NSView*) peer->getNativeHandle();
  210009. if ([compView window] == w)
  210010. {
  210011. if (isKey)
  210012. {
  210013. if (compView == [w firstResponder])
  210014. return false;
  210015. }
  210016. else
  210017. {
  210018. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210019. [compView bounds]))
  210020. return false;
  210021. }
  210022. }
  210023. }
  210024. if (isInputAttempt)
  210025. {
  210026. if (! [NSApp isActive])
  210027. [NSApp activateIgnoringOtherApps: YES];
  210028. Component* const modal = Component::getCurrentlyModalComponent (0);
  210029. if (modal != 0)
  210030. modal->inputAttemptWhenModal();
  210031. }
  210032. return true;
  210033. }
  210034. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210035. {
  210036. const ScopedAutoReleasePool pool;
  210037. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210038. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210039. while (! quitMessagePosted)
  210040. {
  210041. const ScopedAutoReleasePool pool2;
  210042. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210043. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210044. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210045. inMode: NSDefaultRunLoopMode
  210046. dequeue: YES];
  210047. if (e != 0 && ! isEventBlockedByModalComps (e))
  210048. [NSApp sendEvent: e];
  210049. if (Time::getMillisecondCounter() >= endTime)
  210050. break;
  210051. }
  210052. return ! quitMessagePosted;
  210053. }
  210054. void MessageManager::doPlatformSpecificInitialisation()
  210055. {
  210056. if (juceAppDelegate == 0)
  210057. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210058. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210059. // correctly (needed prior to 10.5)
  210060. if (! [NSThread isMultiThreaded])
  210061. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210062. toTarget: juceAppDelegate
  210063. withObject: nil];
  210064. initialiseMainMenu();
  210065. }
  210066. void MessageManager::doPlatformSpecificShutdown()
  210067. {
  210068. if (juceAppDelegate != 0)
  210069. {
  210070. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210071. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210072. [juceAppDelegate release];
  210073. juceAppDelegate = 0;
  210074. }
  210075. }
  210076. bool juce_postMessageToSystemQueue (void* message)
  210077. {
  210078. juceAppDelegate->redirector->postMessage (message);
  210079. return true;
  210080. }
  210081. void MessageManager::broadcastMessage (const String& value) throw()
  210082. {
  210083. }
  210084. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210085. void* data)
  210086. {
  210087. if (isThisTheMessageThread())
  210088. {
  210089. return (*callback) (data);
  210090. }
  210091. else
  210092. {
  210093. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210094. // deadlock because the message manager is blocked from running, so can never
  210095. // call your function..
  210096. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210097. const ScopedAutoReleasePool pool;
  210098. AppDelegateRedirector::CallbackMessagePayload cmp;
  210099. cmp.function = callback;
  210100. cmp.parameter = data;
  210101. cmp.result = 0;
  210102. cmp.hasBeenExecuted = false;
  210103. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210104. withObject: [NSData dataWithBytesNoCopy: &cmp
  210105. length: sizeof (cmp)
  210106. freeWhenDone: NO]
  210107. waitUntilDone: YES];
  210108. return cmp.result;
  210109. }
  210110. }
  210111. #endif
  210112. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210113. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210114. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210115. // compiled on its own).
  210116. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210117. #if JUCE_MAC
  210118. END_JUCE_NAMESPACE
  210119. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210120. @interface DownloadClickDetector : NSObject
  210121. {
  210122. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210123. }
  210124. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210125. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210126. request: (NSURLRequest*) request
  210127. frame: (WebFrame*) frame
  210128. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210129. @end
  210130. @implementation DownloadClickDetector
  210131. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210132. {
  210133. [super init];
  210134. ownerComponent = ownerComponent_;
  210135. return self;
  210136. }
  210137. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210138. request: (NSURLRequest*) request
  210139. frame: (WebFrame*) frame
  210140. decisionListener: (id <WebPolicyDecisionListener>) listener
  210141. {
  210142. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210143. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210144. [listener use];
  210145. else
  210146. [listener ignore];
  210147. }
  210148. @end
  210149. BEGIN_JUCE_NAMESPACE
  210150. class WebBrowserComponentInternal : public NSViewComponent
  210151. {
  210152. public:
  210153. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210154. {
  210155. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210156. frameName: @""
  210157. groupName: @""];
  210158. setView (webView);
  210159. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210160. [webView setPolicyDelegate: clickListener];
  210161. }
  210162. ~WebBrowserComponentInternal()
  210163. {
  210164. [webView setPolicyDelegate: nil];
  210165. [clickListener release];
  210166. setView (0);
  210167. }
  210168. void goToURL (const String& url,
  210169. const StringArray* headers,
  210170. const MemoryBlock* postData)
  210171. {
  210172. NSMutableURLRequest* r
  210173. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210174. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210175. timeoutInterval: 30.0];
  210176. if (postData != 0 && postData->getSize() > 0)
  210177. {
  210178. [r setHTTPMethod: @"POST"];
  210179. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210180. length: postData->getSize()]];
  210181. }
  210182. if (headers != 0)
  210183. {
  210184. for (int i = 0; i < headers->size(); ++i)
  210185. {
  210186. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  210187. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  210188. [r setValue: juceStringToNS (headerValue)
  210189. forHTTPHeaderField: juceStringToNS (headerName)];
  210190. }
  210191. }
  210192. stop();
  210193. [[webView mainFrame] loadRequest: r];
  210194. }
  210195. void goBack()
  210196. {
  210197. [webView goBack];
  210198. }
  210199. void goForward()
  210200. {
  210201. [webView goForward];
  210202. }
  210203. void stop()
  210204. {
  210205. [webView stopLoading: nil];
  210206. }
  210207. void refresh()
  210208. {
  210209. [webView reload: nil];
  210210. }
  210211. private:
  210212. WebView* webView;
  210213. DownloadClickDetector* clickListener;
  210214. };
  210215. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210216. : browser (0),
  210217. blankPageShown (false),
  210218. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210219. {
  210220. setOpaque (true);
  210221. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210222. }
  210223. WebBrowserComponent::~WebBrowserComponent()
  210224. {
  210225. deleteAndZero (browser);
  210226. }
  210227. void WebBrowserComponent::goToURL (const String& url,
  210228. const StringArray* headers,
  210229. const MemoryBlock* postData)
  210230. {
  210231. lastURL = url;
  210232. lastHeaders.clear();
  210233. if (headers != 0)
  210234. lastHeaders = *headers;
  210235. lastPostData.setSize (0);
  210236. if (postData != 0)
  210237. lastPostData = *postData;
  210238. blankPageShown = false;
  210239. browser->goToURL (url, headers, postData);
  210240. }
  210241. void WebBrowserComponent::stop()
  210242. {
  210243. browser->stop();
  210244. }
  210245. void WebBrowserComponent::goBack()
  210246. {
  210247. lastURL = String::empty;
  210248. blankPageShown = false;
  210249. browser->goBack();
  210250. }
  210251. void WebBrowserComponent::goForward()
  210252. {
  210253. lastURL = String::empty;
  210254. browser->goForward();
  210255. }
  210256. void WebBrowserComponent::refresh()
  210257. {
  210258. browser->refresh();
  210259. }
  210260. void WebBrowserComponent::paint (Graphics& g)
  210261. {
  210262. }
  210263. void WebBrowserComponent::checkWindowAssociation()
  210264. {
  210265. if (isShowing())
  210266. {
  210267. if (blankPageShown)
  210268. goBack();
  210269. }
  210270. else
  210271. {
  210272. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210273. {
  210274. // when the component becomes invisible, some stuff like flash
  210275. // carries on playing audio, so we need to force it onto a blank
  210276. // page to avoid this, (and send it back when it's made visible again).
  210277. blankPageShown = true;
  210278. browser->goToURL ("about:blank", 0, 0);
  210279. }
  210280. }
  210281. }
  210282. void WebBrowserComponent::reloadLastURL()
  210283. {
  210284. if (lastURL.isNotEmpty())
  210285. {
  210286. goToURL (lastURL, &lastHeaders, &lastPostData);
  210287. lastURL = String::empty;
  210288. }
  210289. }
  210290. void WebBrowserComponent::parentHierarchyChanged()
  210291. {
  210292. checkWindowAssociation();
  210293. }
  210294. void WebBrowserComponent::resized()
  210295. {
  210296. browser->setSize (getWidth(), getHeight());
  210297. }
  210298. void WebBrowserComponent::visibilityChanged()
  210299. {
  210300. checkWindowAssociation();
  210301. }
  210302. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210303. {
  210304. return true;
  210305. }
  210306. #else
  210307. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210308. {
  210309. }
  210310. WebBrowserComponent::~WebBrowserComponent()
  210311. {
  210312. }
  210313. void WebBrowserComponent::goToURL (const String& url,
  210314. const StringArray* headers,
  210315. const MemoryBlock* postData)
  210316. {
  210317. }
  210318. void WebBrowserComponent::stop()
  210319. {
  210320. }
  210321. void WebBrowserComponent::goBack()
  210322. {
  210323. }
  210324. void WebBrowserComponent::goForward()
  210325. {
  210326. }
  210327. void WebBrowserComponent::refresh()
  210328. {
  210329. }
  210330. void WebBrowserComponent::paint (Graphics& g)
  210331. {
  210332. }
  210333. void WebBrowserComponent::checkWindowAssociation()
  210334. {
  210335. }
  210336. void WebBrowserComponent::reloadLastURL()
  210337. {
  210338. }
  210339. void WebBrowserComponent::parentHierarchyChanged()
  210340. {
  210341. }
  210342. void WebBrowserComponent::resized()
  210343. {
  210344. }
  210345. void WebBrowserComponent::visibilityChanged()
  210346. {
  210347. }
  210348. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210349. {
  210350. return true;
  210351. }
  210352. #endif
  210353. #endif
  210354. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210355. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210356. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210357. // compiled on its own).
  210358. #if JUCE_INCLUDED_FILE
  210359. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210360. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210361. #endif
  210362. #undef log
  210363. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210364. #define log(a) Logger::writeToLog (a)
  210365. #else
  210366. #define log(a)
  210367. #endif
  210368. #undef OK
  210369. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210370. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210371. {
  210372. if (err == noErr)
  210373. return true;
  210374. Logger::writeToLog ("CoreAudio error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  210375. jassertfalse
  210376. return false;
  210377. }
  210378. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210379. #else
  210380. #define OK(a) (a == noErr)
  210381. #endif
  210382. class CoreAudioInternal : public Timer
  210383. {
  210384. public:
  210385. CoreAudioInternal (AudioDeviceID id)
  210386. : inputLatency (0),
  210387. outputLatency (0),
  210388. callback (0),
  210389. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210390. audioProcID (0),
  210391. #endif
  210392. inputDevice (0),
  210393. isSlaveDevice (false),
  210394. deviceID (id),
  210395. started (false),
  210396. sampleRate (0),
  210397. bufferSize (512),
  210398. numInputChans (0),
  210399. numOutputChans (0),
  210400. callbacksAllowed (true),
  210401. numInputChannelInfos (0),
  210402. numOutputChannelInfos (0)
  210403. {
  210404. jassert (deviceID != 0);
  210405. updateDetailsFromDevice();
  210406. AudioObjectPropertyAddress pa;
  210407. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210408. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210409. pa.mElement = kAudioObjectPropertyElementWildcard;
  210410. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210411. }
  210412. ~CoreAudioInternal()
  210413. {
  210414. AudioObjectPropertyAddress pa;
  210415. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210416. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210417. pa.mElement = kAudioObjectPropertyElementWildcard;
  210418. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210419. stop (false);
  210420. delete inputDevice;
  210421. }
  210422. void allocateTempBuffers()
  210423. {
  210424. const int tempBufSize = bufferSize + 4;
  210425. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210426. tempInputBuffers.calloc (numInputChans + 2);
  210427. tempOutputBuffers.calloc (numOutputChans + 2);
  210428. int i, count = 0;
  210429. for (i = 0; i < numInputChans; ++i)
  210430. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210431. for (i = 0; i < numOutputChans; ++i)
  210432. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210433. }
  210434. // returns the number of actual available channels
  210435. void fillInChannelInfo (const bool input)
  210436. {
  210437. int chanNum = 0;
  210438. UInt32 size;
  210439. AudioObjectPropertyAddress pa;
  210440. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210441. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210442. pa.mElement = kAudioObjectPropertyElementMaster;
  210443. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210444. {
  210445. HeapBlock <AudioBufferList> bufList;
  210446. bufList.calloc (size, 1);
  210447. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210448. {
  210449. const int numStreams = bufList->mNumberBuffers;
  210450. for (int i = 0; i < numStreams; ++i)
  210451. {
  210452. const AudioBuffer& b = bufList->mBuffers[i];
  210453. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210454. {
  210455. String name;
  210456. {
  210457. char channelName [256];
  210458. zerostruct (channelName);
  210459. UInt32 nameSize = sizeof (channelName);
  210460. UInt32 channelNum = chanNum + 1;
  210461. pa.mSelector = kAudioDevicePropertyChannelName;
  210462. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210463. name = String::fromUTF8 (channelName, nameSize);
  210464. }
  210465. if (input)
  210466. {
  210467. if (activeInputChans[chanNum])
  210468. {
  210469. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210470. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210471. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210472. ++numInputChannelInfos;
  210473. }
  210474. if (name.isEmpty())
  210475. name << "Input " << (chanNum + 1);
  210476. inChanNames.add (name);
  210477. }
  210478. else
  210479. {
  210480. if (activeOutputChans[chanNum])
  210481. {
  210482. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210483. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210484. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210485. ++numOutputChannelInfos;
  210486. }
  210487. if (name.isEmpty())
  210488. name << "Output " << (chanNum + 1);
  210489. outChanNames.add (name);
  210490. }
  210491. ++chanNum;
  210492. }
  210493. }
  210494. }
  210495. }
  210496. }
  210497. void updateDetailsFromDevice()
  210498. {
  210499. stopTimer();
  210500. if (deviceID == 0)
  210501. return;
  210502. const ScopedLock sl (callbackLock);
  210503. Float64 sr;
  210504. UInt32 size = sizeof (Float64);
  210505. AudioObjectPropertyAddress pa;
  210506. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210507. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210508. pa.mElement = kAudioObjectPropertyElementMaster;
  210509. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210510. sampleRate = sr;
  210511. UInt32 framesPerBuf;
  210512. size = sizeof (framesPerBuf);
  210513. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210514. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210515. {
  210516. bufferSize = framesPerBuf;
  210517. allocateTempBuffers();
  210518. }
  210519. bufferSizes.clear();
  210520. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210521. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210522. {
  210523. HeapBlock <AudioValueRange> ranges;
  210524. ranges.calloc (size, 1);
  210525. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210526. {
  210527. bufferSizes.add ((int) ranges[0].mMinimum);
  210528. for (int i = 32; i < 2048; i += 32)
  210529. {
  210530. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210531. {
  210532. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210533. {
  210534. bufferSizes.addIfNotAlreadyThere (i);
  210535. break;
  210536. }
  210537. }
  210538. }
  210539. if (bufferSize > 0)
  210540. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210541. }
  210542. }
  210543. if (bufferSizes.size() == 0 && bufferSize > 0)
  210544. bufferSizes.add (bufferSize);
  210545. sampleRates.clear();
  210546. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210547. String rates;
  210548. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210549. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210550. {
  210551. HeapBlock <AudioValueRange> ranges;
  210552. ranges.calloc (size, 1);
  210553. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210554. {
  210555. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210556. {
  210557. bool ok = false;
  210558. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210559. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210560. ok = true;
  210561. if (ok)
  210562. {
  210563. sampleRates.add (possibleRates[i]);
  210564. rates << possibleRates[i] << ' ';
  210565. }
  210566. }
  210567. }
  210568. }
  210569. if (sampleRates.size() == 0 && sampleRate > 0)
  210570. {
  210571. sampleRates.add (sampleRate);
  210572. rates << sampleRate;
  210573. }
  210574. log ("sr: " + rates);
  210575. inputLatency = 0;
  210576. outputLatency = 0;
  210577. UInt32 lat;
  210578. size = sizeof (lat);
  210579. pa.mSelector = kAudioDevicePropertyLatency;
  210580. pa.mScope = kAudioDevicePropertyScopeInput;
  210581. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210582. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210583. inputLatency = (int) lat;
  210584. pa.mScope = kAudioDevicePropertyScopeOutput;
  210585. size = sizeof (lat);
  210586. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210587. outputLatency = (int) lat;
  210588. log ("lat: " + String (inputLatency) + " " + String (outputLatency));
  210589. inChanNames.clear();
  210590. outChanNames.clear();
  210591. inputChannelInfo.calloc (numInputChans + 2);
  210592. numInputChannelInfos = 0;
  210593. outputChannelInfo.calloc (numOutputChans + 2);
  210594. numOutputChannelInfos = 0;
  210595. fillInChannelInfo (true);
  210596. fillInChannelInfo (false);
  210597. }
  210598. const StringArray getSources (bool input)
  210599. {
  210600. StringArray s;
  210601. HeapBlock <OSType> types;
  210602. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210603. for (int i = 0; i < num; ++i)
  210604. {
  210605. AudioValueTranslation avt;
  210606. char buffer[256];
  210607. avt.mInputData = &(types[i]);
  210608. avt.mInputDataSize = sizeof (UInt32);
  210609. avt.mOutputData = buffer;
  210610. avt.mOutputDataSize = 256;
  210611. UInt32 transSize = sizeof (avt);
  210612. AudioObjectPropertyAddress pa;
  210613. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210614. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210615. pa.mElement = kAudioObjectPropertyElementMaster;
  210616. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210617. {
  210618. DBG (buffer);
  210619. s.add (buffer);
  210620. }
  210621. }
  210622. return s;
  210623. }
  210624. int getCurrentSourceIndex (bool input) const
  210625. {
  210626. OSType currentSourceID = 0;
  210627. UInt32 size = sizeof (currentSourceID);
  210628. int result = -1;
  210629. AudioObjectPropertyAddress pa;
  210630. pa.mSelector = kAudioDevicePropertyDataSource;
  210631. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210632. pa.mElement = kAudioObjectPropertyElementMaster;
  210633. if (deviceID != 0)
  210634. {
  210635. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210636. {
  210637. HeapBlock <OSType> types;
  210638. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210639. for (int i = 0; i < num; ++i)
  210640. {
  210641. if (types[num] == currentSourceID)
  210642. {
  210643. result = i;
  210644. break;
  210645. }
  210646. }
  210647. }
  210648. }
  210649. return result;
  210650. }
  210651. void setCurrentSourceIndex (int index, bool input)
  210652. {
  210653. if (deviceID != 0)
  210654. {
  210655. HeapBlock <OSType> types;
  210656. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210657. if (((unsigned int) index) < (unsigned int) num)
  210658. {
  210659. AudioObjectPropertyAddress pa;
  210660. pa.mSelector = kAudioDevicePropertyDataSource;
  210661. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210662. pa.mElement = kAudioObjectPropertyElementMaster;
  210663. OSType typeId = types[index];
  210664. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210665. }
  210666. }
  210667. }
  210668. const String reopen (const BigInteger& inputChannels,
  210669. const BigInteger& outputChannels,
  210670. double newSampleRate,
  210671. int bufferSizeSamples)
  210672. {
  210673. String error;
  210674. log ("CoreAudio reopen");
  210675. callbacksAllowed = false;
  210676. stopTimer();
  210677. stop (false);
  210678. activeInputChans = inputChannels;
  210679. activeInputChans.setRange (inChanNames.size(),
  210680. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210681. false);
  210682. activeOutputChans = outputChannels;
  210683. activeOutputChans.setRange (outChanNames.size(),
  210684. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210685. false);
  210686. numInputChans = activeInputChans.countNumberOfSetBits();
  210687. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210688. // set sample rate
  210689. AudioObjectPropertyAddress pa;
  210690. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210691. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210692. pa.mElement = kAudioObjectPropertyElementMaster;
  210693. Float64 sr = newSampleRate;
  210694. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210695. {
  210696. error = "Couldn't change sample rate";
  210697. }
  210698. else
  210699. {
  210700. // change buffer size
  210701. UInt32 framesPerBuf = bufferSizeSamples;
  210702. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210703. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210704. {
  210705. error = "Couldn't change buffer size";
  210706. }
  210707. else
  210708. {
  210709. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210710. // correctly report their new settings until some random time in the future, so
  210711. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210712. // to make sure we're using the correct numbers..
  210713. updateDetailsFromDevice();
  210714. sampleRate = newSampleRate;
  210715. bufferSize = bufferSizeSamples;
  210716. if (sampleRates.size() == 0)
  210717. error = "Device has no available sample-rates";
  210718. else if (bufferSizes.size() == 0)
  210719. error = "Device has no available buffer-sizes";
  210720. else if (inputDevice != 0)
  210721. error = inputDevice->reopen (inputChannels,
  210722. outputChannels,
  210723. newSampleRate,
  210724. bufferSizeSamples);
  210725. }
  210726. }
  210727. callbacksAllowed = true;
  210728. return error;
  210729. }
  210730. bool start (AudioIODeviceCallback* cb)
  210731. {
  210732. if (! started)
  210733. {
  210734. callback = 0;
  210735. if (deviceID != 0)
  210736. {
  210737. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210738. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, this)))
  210739. #else
  210740. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, this, &audioProcID)))
  210741. #endif
  210742. {
  210743. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210744. {
  210745. started = true;
  210746. }
  210747. else
  210748. {
  210749. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210750. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210751. #else
  210752. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210753. audioProcID = 0;
  210754. #endif
  210755. }
  210756. }
  210757. }
  210758. }
  210759. if (started)
  210760. {
  210761. const ScopedLock sl (callbackLock);
  210762. callback = cb;
  210763. }
  210764. if (inputDevice != 0)
  210765. return started && inputDevice->start (cb);
  210766. else
  210767. return started;
  210768. }
  210769. void stop (bool leaveInterruptRunning)
  210770. {
  210771. {
  210772. const ScopedLock sl (callbackLock);
  210773. callback = 0;
  210774. }
  210775. if (started
  210776. && (deviceID != 0)
  210777. && ! leaveInterruptRunning)
  210778. {
  210779. OK (AudioDeviceStop (deviceID, audioIOProc));
  210780. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210781. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210782. #else
  210783. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210784. audioProcID = 0;
  210785. #endif
  210786. started = false;
  210787. { const ScopedLock sl (callbackLock); }
  210788. // wait until it's definately stopped calling back..
  210789. for (int i = 40; --i >= 0;)
  210790. {
  210791. Thread::sleep (50);
  210792. UInt32 running = 0;
  210793. UInt32 size = sizeof (running);
  210794. AudioObjectPropertyAddress pa;
  210795. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210796. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210797. pa.mElement = kAudioObjectPropertyElementMaster;
  210798. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210799. if (running == 0)
  210800. break;
  210801. }
  210802. const ScopedLock sl (callbackLock);
  210803. }
  210804. if (inputDevice != 0)
  210805. inputDevice->stop (leaveInterruptRunning);
  210806. }
  210807. double getSampleRate() const
  210808. {
  210809. return sampleRate;
  210810. }
  210811. int getBufferSize() const
  210812. {
  210813. return bufferSize;
  210814. }
  210815. void audioCallback (const AudioBufferList* inInputData,
  210816. AudioBufferList* outOutputData)
  210817. {
  210818. int i;
  210819. const ScopedLock sl (callbackLock);
  210820. if (callback != 0)
  210821. {
  210822. if (inputDevice == 0)
  210823. {
  210824. for (i = numInputChans; --i >= 0;)
  210825. {
  210826. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210827. float* dest = tempInputBuffers [i];
  210828. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210829. + info.dataOffsetSamples;
  210830. const int stride = info.dataStrideSamples;
  210831. if (stride != 0) // if this is zero, info is invalid
  210832. {
  210833. for (int j = bufferSize; --j >= 0;)
  210834. {
  210835. *dest++ = *src;
  210836. src += stride;
  210837. }
  210838. }
  210839. }
  210840. }
  210841. if (! isSlaveDevice)
  210842. {
  210843. if (inputDevice == 0)
  210844. {
  210845. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210846. numInputChans,
  210847. tempOutputBuffers,
  210848. numOutputChans,
  210849. bufferSize);
  210850. }
  210851. else
  210852. {
  210853. jassert (inputDevice->bufferSize == bufferSize);
  210854. // Sometimes the two linked devices seem to get their callbacks in
  210855. // parallel, so we need to lock both devices to stop the input data being
  210856. // changed while inside our callback..
  210857. const ScopedLock sl2 (inputDevice->callbackLock);
  210858. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210859. inputDevice->numInputChans,
  210860. tempOutputBuffers,
  210861. numOutputChans,
  210862. bufferSize);
  210863. }
  210864. for (i = numOutputChans; --i >= 0;)
  210865. {
  210866. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210867. const float* src = tempOutputBuffers [i];
  210868. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210869. + info.dataOffsetSamples;
  210870. const int stride = info.dataStrideSamples;
  210871. if (stride != 0) // if this is zero, info is invalid
  210872. {
  210873. for (int j = bufferSize; --j >= 0;)
  210874. {
  210875. *dest = *src++;
  210876. dest += stride;
  210877. }
  210878. }
  210879. }
  210880. }
  210881. }
  210882. else
  210883. {
  210884. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210885. {
  210886. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210887. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210888. + info.dataOffsetSamples;
  210889. const int stride = info.dataStrideSamples;
  210890. if (stride != 0) // if this is zero, info is invalid
  210891. {
  210892. for (int j = bufferSize; --j >= 0;)
  210893. {
  210894. *dest = 0.0f;
  210895. dest += stride;
  210896. }
  210897. }
  210898. }
  210899. }
  210900. }
  210901. // called by callbacks
  210902. void deviceDetailsChanged()
  210903. {
  210904. if (callbacksAllowed)
  210905. startTimer (100);
  210906. }
  210907. void timerCallback()
  210908. {
  210909. stopTimer();
  210910. log ("CoreAudio device changed callback");
  210911. const double oldSampleRate = sampleRate;
  210912. const int oldBufferSize = bufferSize;
  210913. updateDetailsFromDevice();
  210914. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210915. {
  210916. callbacksAllowed = false;
  210917. stop (false);
  210918. updateDetailsFromDevice();
  210919. callbacksAllowed = true;
  210920. }
  210921. }
  210922. CoreAudioInternal* getRelatedDevice() const
  210923. {
  210924. UInt32 size = 0;
  210925. ScopedPointer <CoreAudioInternal> result;
  210926. AudioObjectPropertyAddress pa;
  210927. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210928. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210929. pa.mElement = kAudioObjectPropertyElementMaster;
  210930. if (deviceID != 0
  210931. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210932. && size > 0)
  210933. {
  210934. HeapBlock <AudioDeviceID> devs;
  210935. devs.calloc (size, 1);
  210936. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210937. {
  210938. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210939. {
  210940. if (devs[i] != deviceID && devs[i] != 0)
  210941. {
  210942. result = new CoreAudioInternal (devs[i]);
  210943. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210944. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210945. if (thisIsInput != otherIsInput
  210946. || (inChanNames.size() + outChanNames.size() == 0)
  210947. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210948. break;
  210949. result = 0;
  210950. }
  210951. }
  210952. }
  210953. }
  210954. return result.release();
  210955. }
  210956. juce_UseDebuggingNewOperator
  210957. int inputLatency, outputLatency;
  210958. BigInteger activeInputChans, activeOutputChans;
  210959. StringArray inChanNames, outChanNames;
  210960. Array <double> sampleRates;
  210961. Array <int> bufferSizes;
  210962. AudioIODeviceCallback* callback;
  210963. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210964. AudioDeviceIOProcID audioProcID;
  210965. #endif
  210966. CoreAudioInternal* inputDevice;
  210967. bool isSlaveDevice;
  210968. private:
  210969. CriticalSection callbackLock;
  210970. AudioDeviceID deviceID;
  210971. bool started;
  210972. double sampleRate;
  210973. int bufferSize;
  210974. HeapBlock <float> audioBuffer;
  210975. int numInputChans, numOutputChans;
  210976. bool callbacksAllowed;
  210977. struct CallbackDetailsForChannel
  210978. {
  210979. int streamNum;
  210980. int dataOffsetSamples;
  210981. int dataStrideSamples;
  210982. };
  210983. int numInputChannelInfos, numOutputChannelInfos;
  210984. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210985. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210986. CoreAudioInternal (const CoreAudioInternal&);
  210987. CoreAudioInternal& operator= (const CoreAudioInternal&);
  210988. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210989. const AudioTimeStamp* inNow,
  210990. const AudioBufferList* inInputData,
  210991. const AudioTimeStamp* inInputTime,
  210992. AudioBufferList* outOutputData,
  210993. const AudioTimeStamp* inOutputTime,
  210994. void* device)
  210995. {
  210996. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210997. return noErr;
  210998. }
  210999. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211000. {
  211001. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211002. switch (pa->mSelector)
  211003. {
  211004. case kAudioDevicePropertyBufferSize:
  211005. case kAudioDevicePropertyBufferFrameSize:
  211006. case kAudioDevicePropertyNominalSampleRate:
  211007. case kAudioDevicePropertyStreamFormat:
  211008. case kAudioDevicePropertyDeviceIsAlive:
  211009. intern->deviceDetailsChanged();
  211010. break;
  211011. case kAudioDevicePropertyBufferSizeRange:
  211012. case kAudioDevicePropertyVolumeScalar:
  211013. case kAudioDevicePropertyMute:
  211014. case kAudioDevicePropertyPlayThru:
  211015. case kAudioDevicePropertyDataSource:
  211016. case kAudioDevicePropertyDeviceIsRunning:
  211017. break;
  211018. }
  211019. return noErr;
  211020. }
  211021. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211022. {
  211023. AudioObjectPropertyAddress pa;
  211024. pa.mSelector = kAudioDevicePropertyDataSources;
  211025. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211026. pa.mElement = kAudioObjectPropertyElementMaster;
  211027. UInt32 size = 0;
  211028. if (deviceID != 0
  211029. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211030. {
  211031. types.calloc (size, 1);
  211032. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211033. return size / (int) sizeof (OSType);
  211034. }
  211035. return 0;
  211036. }
  211037. };
  211038. class CoreAudioIODevice : public AudioIODevice
  211039. {
  211040. public:
  211041. CoreAudioIODevice (const String& deviceName,
  211042. AudioDeviceID inputDeviceId,
  211043. const int inputIndex_,
  211044. AudioDeviceID outputDeviceId,
  211045. const int outputIndex_)
  211046. : AudioIODevice (deviceName, "CoreAudio"),
  211047. inputIndex (inputIndex_),
  211048. outputIndex (outputIndex_),
  211049. isOpen_ (false),
  211050. isStarted (false)
  211051. {
  211052. internal = 0;
  211053. CoreAudioInternal* device = 0;
  211054. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211055. {
  211056. jassert (inputDeviceId != 0);
  211057. device = new CoreAudioInternal (inputDeviceId);
  211058. }
  211059. else
  211060. {
  211061. device = new CoreAudioInternal (outputDeviceId);
  211062. if (inputDeviceId != 0)
  211063. {
  211064. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211065. device->inputDevice = secondDevice;
  211066. secondDevice->isSlaveDevice = true;
  211067. }
  211068. }
  211069. internal = device;
  211070. AudioObjectPropertyAddress pa;
  211071. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211072. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211073. pa.mElement = kAudioObjectPropertyElementWildcard;
  211074. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211075. }
  211076. ~CoreAudioIODevice()
  211077. {
  211078. AudioObjectPropertyAddress pa;
  211079. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211080. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211081. pa.mElement = kAudioObjectPropertyElementWildcard;
  211082. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211083. delete internal;
  211084. }
  211085. const StringArray getOutputChannelNames()
  211086. {
  211087. return internal->outChanNames;
  211088. }
  211089. const StringArray getInputChannelNames()
  211090. {
  211091. if (internal->inputDevice != 0)
  211092. return internal->inputDevice->inChanNames;
  211093. else
  211094. return internal->inChanNames;
  211095. }
  211096. int getNumSampleRates()
  211097. {
  211098. return internal->sampleRates.size();
  211099. }
  211100. double getSampleRate (int index)
  211101. {
  211102. return internal->sampleRates [index];
  211103. }
  211104. int getNumBufferSizesAvailable()
  211105. {
  211106. return internal->bufferSizes.size();
  211107. }
  211108. int getBufferSizeSamples (int index)
  211109. {
  211110. return internal->bufferSizes [index];
  211111. }
  211112. int getDefaultBufferSize()
  211113. {
  211114. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211115. if (getBufferSizeSamples(i) >= 512)
  211116. return getBufferSizeSamples(i);
  211117. return 512;
  211118. }
  211119. const String open (const BigInteger& inputChannels,
  211120. const BigInteger& outputChannels,
  211121. double sampleRate,
  211122. int bufferSizeSamples)
  211123. {
  211124. isOpen_ = true;
  211125. if (bufferSizeSamples <= 0)
  211126. bufferSizeSamples = getDefaultBufferSize();
  211127. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211128. isOpen_ = lastError.isEmpty();
  211129. return lastError;
  211130. }
  211131. void close()
  211132. {
  211133. isOpen_ = false;
  211134. internal->stop (false);
  211135. }
  211136. bool isOpen()
  211137. {
  211138. return isOpen_;
  211139. }
  211140. int getCurrentBufferSizeSamples()
  211141. {
  211142. return internal != 0 ? internal->getBufferSize() : 512;
  211143. }
  211144. double getCurrentSampleRate()
  211145. {
  211146. return internal != 0 ? internal->getSampleRate() : 0;
  211147. }
  211148. int getCurrentBitDepth()
  211149. {
  211150. return 32; // no way to find out, so just assume it's high..
  211151. }
  211152. const BigInteger getActiveOutputChannels() const
  211153. {
  211154. return internal != 0 ? internal->activeOutputChans : BigInteger();
  211155. }
  211156. const BigInteger getActiveInputChannels() const
  211157. {
  211158. BigInteger chans;
  211159. if (internal != 0)
  211160. {
  211161. chans = internal->activeInputChans;
  211162. if (internal->inputDevice != 0)
  211163. chans |= internal->inputDevice->activeInputChans;
  211164. }
  211165. return chans;
  211166. }
  211167. int getOutputLatencyInSamples()
  211168. {
  211169. if (internal == 0)
  211170. return 0;
  211171. // this seems like a good guess at getting the latency right - comparing
  211172. // this with a round-trip measurement, it gets it to within a few millisecs
  211173. // for the built-in mac soundcard
  211174. return internal->outputLatency + internal->getBufferSize() * 2;
  211175. }
  211176. int getInputLatencyInSamples()
  211177. {
  211178. if (internal == 0)
  211179. return 0;
  211180. return internal->inputLatency + internal->getBufferSize() * 2;
  211181. }
  211182. void start (AudioIODeviceCallback* callback)
  211183. {
  211184. if (internal != 0 && ! isStarted)
  211185. {
  211186. if (callback != 0)
  211187. callback->audioDeviceAboutToStart (this);
  211188. isStarted = true;
  211189. internal->start (callback);
  211190. }
  211191. }
  211192. void stop()
  211193. {
  211194. if (isStarted && internal != 0)
  211195. {
  211196. AudioIODeviceCallback* const lastCallback = internal->callback;
  211197. isStarted = false;
  211198. internal->stop (true);
  211199. if (lastCallback != 0)
  211200. lastCallback->audioDeviceStopped();
  211201. }
  211202. }
  211203. bool isPlaying()
  211204. {
  211205. if (internal->callback == 0)
  211206. isStarted = false;
  211207. return isStarted;
  211208. }
  211209. const String getLastError()
  211210. {
  211211. return lastError;
  211212. }
  211213. int inputIndex, outputIndex;
  211214. juce_UseDebuggingNewOperator
  211215. private:
  211216. CoreAudioInternal* internal;
  211217. bool isOpen_, isStarted;
  211218. String lastError;
  211219. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211220. {
  211221. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211222. switch (pa->mSelector)
  211223. {
  211224. case kAudioHardwarePropertyDevices:
  211225. intern->deviceDetailsChanged();
  211226. break;
  211227. case kAudioHardwarePropertyDefaultOutputDevice:
  211228. case kAudioHardwarePropertyDefaultInputDevice:
  211229. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211230. break;
  211231. }
  211232. return noErr;
  211233. }
  211234. CoreAudioIODevice (const CoreAudioIODevice&);
  211235. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211236. };
  211237. class CoreAudioIODeviceType : public AudioIODeviceType
  211238. {
  211239. public:
  211240. CoreAudioIODeviceType()
  211241. : AudioIODeviceType ("CoreAudio"),
  211242. hasScanned (false)
  211243. {
  211244. }
  211245. ~CoreAudioIODeviceType()
  211246. {
  211247. }
  211248. void scanForDevices()
  211249. {
  211250. hasScanned = true;
  211251. inputDeviceNames.clear();
  211252. outputDeviceNames.clear();
  211253. inputIds.clear();
  211254. outputIds.clear();
  211255. UInt32 size;
  211256. AudioObjectPropertyAddress pa;
  211257. pa.mSelector = kAudioHardwarePropertyDevices;
  211258. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211259. pa.mElement = kAudioObjectPropertyElementMaster;
  211260. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211261. {
  211262. HeapBlock <AudioDeviceID> devs;
  211263. devs.calloc (size, 1);
  211264. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211265. {
  211266. static bool alreadyLogged = false;
  211267. const int num = size / (int) sizeof (AudioDeviceID);
  211268. for (int i = 0; i < num; ++i)
  211269. {
  211270. char name [1024];
  211271. size = sizeof (name);
  211272. pa.mSelector = kAudioDevicePropertyDeviceName;
  211273. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211274. {
  211275. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211276. if (! alreadyLogged)
  211277. log ("CoreAudio device: " + nameString);
  211278. const int numIns = getNumChannels (devs[i], true);
  211279. const int numOuts = getNumChannels (devs[i], false);
  211280. if (numIns > 0)
  211281. {
  211282. inputDeviceNames.add (nameString);
  211283. inputIds.add (devs[i]);
  211284. }
  211285. if (numOuts > 0)
  211286. {
  211287. outputDeviceNames.add (nameString);
  211288. outputIds.add (devs[i]);
  211289. }
  211290. }
  211291. }
  211292. alreadyLogged = true;
  211293. }
  211294. }
  211295. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211296. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211297. }
  211298. const StringArray getDeviceNames (bool wantInputNames) const
  211299. {
  211300. jassert (hasScanned); // need to call scanForDevices() before doing this
  211301. if (wantInputNames)
  211302. return inputDeviceNames;
  211303. else
  211304. return outputDeviceNames;
  211305. }
  211306. int getDefaultDeviceIndex (bool forInput) const
  211307. {
  211308. jassert (hasScanned); // need to call scanForDevices() before doing this
  211309. AudioDeviceID deviceID;
  211310. UInt32 size = sizeof (deviceID);
  211311. // if they're asking for any input channels at all, use the default input, so we
  211312. // get the built-in mic rather than the built-in output with no inputs..
  211313. AudioObjectPropertyAddress pa;
  211314. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211315. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211316. pa.mElement = kAudioObjectPropertyElementMaster;
  211317. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211318. {
  211319. if (forInput)
  211320. {
  211321. for (int i = inputIds.size(); --i >= 0;)
  211322. if (inputIds[i] == deviceID)
  211323. return i;
  211324. }
  211325. else
  211326. {
  211327. for (int i = outputIds.size(); --i >= 0;)
  211328. if (outputIds[i] == deviceID)
  211329. return i;
  211330. }
  211331. }
  211332. return 0;
  211333. }
  211334. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  211335. {
  211336. jassert (hasScanned); // need to call scanForDevices() before doing this
  211337. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211338. if (d == 0)
  211339. return -1;
  211340. return asInput ? d->inputIndex
  211341. : d->outputIndex;
  211342. }
  211343. bool hasSeparateInputsAndOutputs() const { return true; }
  211344. AudioIODevice* createDevice (const String& outputDeviceName,
  211345. const String& inputDeviceName)
  211346. {
  211347. jassert (hasScanned); // need to call scanForDevices() before doing this
  211348. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211349. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211350. String deviceName (outputDeviceName);
  211351. if (deviceName.isEmpty())
  211352. deviceName = inputDeviceName;
  211353. if (index >= 0)
  211354. return new CoreAudioIODevice (deviceName,
  211355. inputIds [inputIndex],
  211356. inputIndex,
  211357. outputIds [outputIndex],
  211358. outputIndex);
  211359. return 0;
  211360. }
  211361. juce_UseDebuggingNewOperator
  211362. private:
  211363. StringArray inputDeviceNames, outputDeviceNames;
  211364. Array <AudioDeviceID> inputIds, outputIds;
  211365. bool hasScanned;
  211366. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211367. {
  211368. int total = 0;
  211369. UInt32 size;
  211370. AudioObjectPropertyAddress pa;
  211371. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211372. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211373. pa.mElement = kAudioObjectPropertyElementMaster;
  211374. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211375. {
  211376. HeapBlock <AudioBufferList> bufList;
  211377. bufList.calloc (size, 1);
  211378. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211379. {
  211380. const int numStreams = bufList->mNumberBuffers;
  211381. for (int i = 0; i < numStreams; ++i)
  211382. {
  211383. const AudioBuffer& b = bufList->mBuffers[i];
  211384. total += b.mNumberChannels;
  211385. }
  211386. }
  211387. }
  211388. return total;
  211389. }
  211390. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211391. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211392. };
  211393. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211394. {
  211395. return new CoreAudioIODeviceType();
  211396. }
  211397. #undef log
  211398. #endif
  211399. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211400. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211401. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211402. // compiled on its own).
  211403. #if JUCE_INCLUDED_FILE
  211404. #if JUCE_MAC
  211405. #undef log
  211406. #define log(a) Logger::writeToLog(a)
  211407. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211408. {
  211409. if (err == noErr)
  211410. return true;
  211411. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  211412. jassertfalse
  211413. return false;
  211414. }
  211415. #undef OK
  211416. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211417. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211418. {
  211419. String result;
  211420. CFStringRef str = 0;
  211421. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211422. if (str != 0)
  211423. {
  211424. result = PlatformUtilities::cfStringToJuceString (str);
  211425. CFRelease (str);
  211426. str = 0;
  211427. }
  211428. MIDIEntityRef entity = 0;
  211429. MIDIEndpointGetEntity (endpoint, &entity);
  211430. if (entity == 0)
  211431. return result; // probably virtual
  211432. if (result.isEmpty())
  211433. {
  211434. // endpoint name has zero length - try the entity
  211435. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211436. if (str != 0)
  211437. {
  211438. result += PlatformUtilities::cfStringToJuceString (str);
  211439. CFRelease (str);
  211440. str = 0;
  211441. }
  211442. }
  211443. // now consider the device's name
  211444. MIDIDeviceRef device = 0;
  211445. MIDIEntityGetDevice (entity, &device);
  211446. if (device == 0)
  211447. return result;
  211448. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211449. if (str != 0)
  211450. {
  211451. const String s (PlatformUtilities::cfStringToJuceString (str));
  211452. CFRelease (str);
  211453. // if an external device has only one entity, throw away
  211454. // the endpoint name and just use the device name
  211455. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211456. {
  211457. result = s;
  211458. }
  211459. else if (! result.startsWithIgnoreCase (s))
  211460. {
  211461. // prepend the device name to the entity name
  211462. result = (s + " " + result).trimEnd();
  211463. }
  211464. }
  211465. return result;
  211466. }
  211467. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211468. {
  211469. String result;
  211470. // Does the endpoint have connections?
  211471. CFDataRef connections = 0;
  211472. int numConnections = 0;
  211473. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211474. if (connections != 0)
  211475. {
  211476. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211477. if (numConnections > 0)
  211478. {
  211479. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211480. for (int i = 0; i < numConnections; ++i, ++pid)
  211481. {
  211482. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211483. MIDIObjectRef connObject;
  211484. MIDIObjectType connObjectType;
  211485. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211486. if (err == noErr)
  211487. {
  211488. String s;
  211489. if (connObjectType == kMIDIObjectType_ExternalSource
  211490. || connObjectType == kMIDIObjectType_ExternalDestination)
  211491. {
  211492. // Connected to an external device's endpoint (10.3 and later).
  211493. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211494. }
  211495. else
  211496. {
  211497. // Connected to an external device (10.2) (or something else, catch-all)
  211498. CFStringRef str = 0;
  211499. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211500. if (str != 0)
  211501. {
  211502. s = PlatformUtilities::cfStringToJuceString (str);
  211503. CFRelease (str);
  211504. }
  211505. }
  211506. if (s.isNotEmpty())
  211507. {
  211508. if (result.isNotEmpty())
  211509. result += ", ";
  211510. result += s;
  211511. }
  211512. }
  211513. }
  211514. }
  211515. CFRelease (connections);
  211516. }
  211517. if (result.isNotEmpty())
  211518. return result;
  211519. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211520. return getEndpointName (endpoint, false);
  211521. }
  211522. const StringArray MidiOutput::getDevices()
  211523. {
  211524. StringArray s;
  211525. const ItemCount num = MIDIGetNumberOfDestinations();
  211526. for (ItemCount i = 0; i < num; ++i)
  211527. {
  211528. MIDIEndpointRef dest = MIDIGetDestination (i);
  211529. if (dest != 0)
  211530. {
  211531. String name (getConnectedEndpointName (dest));
  211532. if (name.isEmpty())
  211533. name = "<error>";
  211534. s.add (name);
  211535. }
  211536. else
  211537. {
  211538. s.add ("<error>");
  211539. }
  211540. }
  211541. return s;
  211542. }
  211543. int MidiOutput::getDefaultDeviceIndex()
  211544. {
  211545. return 0;
  211546. }
  211547. static MIDIClientRef globalMidiClient;
  211548. static bool hasGlobalClientBeenCreated = false;
  211549. static bool makeSureClientExists()
  211550. {
  211551. if (! hasGlobalClientBeenCreated)
  211552. {
  211553. String name ("JUCE");
  211554. if (JUCEApplication::getInstance() != 0)
  211555. name = JUCEApplication::getInstance()->getApplicationName();
  211556. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211557. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211558. CFRelease (appName);
  211559. }
  211560. return hasGlobalClientBeenCreated;
  211561. }
  211562. class MidiPortAndEndpoint
  211563. {
  211564. public:
  211565. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211566. : port (port_), endPoint (endPoint_)
  211567. {
  211568. }
  211569. ~MidiPortAndEndpoint()
  211570. {
  211571. if (port != 0)
  211572. MIDIPortDispose (port);
  211573. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211574. MIDIEndpointDispose (endPoint);
  211575. }
  211576. MIDIPortRef port;
  211577. MIDIEndpointRef endPoint;
  211578. };
  211579. MidiOutput* MidiOutput::openDevice (int index)
  211580. {
  211581. MidiOutput* mo = 0;
  211582. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211583. {
  211584. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211585. CFStringRef pname;
  211586. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211587. {
  211588. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  211589. if (makeSureClientExists())
  211590. {
  211591. MIDIPortRef port;
  211592. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211593. {
  211594. mo = new MidiOutput();
  211595. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  211596. }
  211597. }
  211598. CFRelease (pname);
  211599. }
  211600. }
  211601. return mo;
  211602. }
  211603. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211604. {
  211605. MidiOutput* mo = 0;
  211606. if (makeSureClientExists())
  211607. {
  211608. MIDIEndpointRef endPoint;
  211609. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211610. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211611. {
  211612. mo = new MidiOutput();
  211613. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  211614. }
  211615. CFRelease (name);
  211616. }
  211617. return mo;
  211618. }
  211619. MidiOutput::~MidiOutput()
  211620. {
  211621. delete (MidiPortAndEndpoint*) internal;
  211622. }
  211623. void MidiOutput::reset()
  211624. {
  211625. }
  211626. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211627. {
  211628. return false;
  211629. }
  211630. void MidiOutput::setVolume (float leftVol, float rightVol)
  211631. {
  211632. }
  211633. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211634. {
  211635. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211636. if (message.isSysEx())
  211637. {
  211638. const int maxPacketSize = 256;
  211639. int pos = 0, bytesLeft = message.getRawDataSize();
  211640. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211641. HeapBlock <MIDIPacketList> packets;
  211642. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211643. packets->numPackets = numPackets;
  211644. MIDIPacket* p = packets->packet;
  211645. for (int i = 0; i < numPackets; ++i)
  211646. {
  211647. p->timeStamp = 0;
  211648. p->length = jmin (maxPacketSize, bytesLeft);
  211649. memcpy (p->data, message.getRawData() + pos, p->length);
  211650. pos += p->length;
  211651. bytesLeft -= p->length;
  211652. p = MIDIPacketNext (p);
  211653. }
  211654. if (mpe->port != 0)
  211655. MIDISend (mpe->port, mpe->endPoint, packets);
  211656. else
  211657. MIDIReceived (mpe->endPoint, packets);
  211658. }
  211659. else
  211660. {
  211661. MIDIPacketList packets;
  211662. packets.numPackets = 1;
  211663. packets.packet[0].timeStamp = 0;
  211664. packets.packet[0].length = message.getRawDataSize();
  211665. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211666. if (mpe->port != 0)
  211667. MIDISend (mpe->port, mpe->endPoint, &packets);
  211668. else
  211669. MIDIReceived (mpe->endPoint, &packets);
  211670. }
  211671. }
  211672. const StringArray MidiInput::getDevices()
  211673. {
  211674. StringArray s;
  211675. const ItemCount num = MIDIGetNumberOfSources();
  211676. for (ItemCount i = 0; i < num; ++i)
  211677. {
  211678. MIDIEndpointRef source = MIDIGetSource (i);
  211679. if (source != 0)
  211680. {
  211681. String name (getConnectedEndpointName (source));
  211682. if (name.isEmpty())
  211683. name = "<error>";
  211684. s.add (name);
  211685. }
  211686. else
  211687. {
  211688. s.add ("<error>");
  211689. }
  211690. }
  211691. return s;
  211692. }
  211693. int MidiInput::getDefaultDeviceIndex()
  211694. {
  211695. return 0;
  211696. }
  211697. struct MidiPortAndCallback
  211698. {
  211699. MidiInput* input;
  211700. MidiPortAndEndpoint* portAndEndpoint;
  211701. MidiInputCallback* callback;
  211702. MemoryBlock pendingData;
  211703. int pendingBytes;
  211704. double pendingDataTime;
  211705. bool active;
  211706. void processSysex (const uint8*& d, int& size, const double time)
  211707. {
  211708. if (*d == 0xf0)
  211709. {
  211710. pendingBytes = 0;
  211711. pendingDataTime = time;
  211712. }
  211713. pendingData.ensureSize (pendingBytes + size, false);
  211714. uint8* totalMessage = (uint8*) pendingData.getData();
  211715. uint8* dest = totalMessage + pendingBytes;
  211716. while (size > 0)
  211717. {
  211718. if (pendingBytes > 0 && *d >= 0x80)
  211719. {
  211720. if (*d >= 0xfa || *d == 0xf8)
  211721. {
  211722. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211723. ++d;
  211724. --size;
  211725. }
  211726. else
  211727. {
  211728. if (*d == 0xf7)
  211729. {
  211730. *dest++ = *d++;
  211731. pendingBytes++;
  211732. --size;
  211733. }
  211734. break;
  211735. }
  211736. }
  211737. else
  211738. {
  211739. *dest++ = *d++;
  211740. pendingBytes++;
  211741. --size;
  211742. }
  211743. }
  211744. if (totalMessage [pendingBytes - 1] == 0xf7)
  211745. {
  211746. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211747. pendingBytes = 0;
  211748. }
  211749. else
  211750. {
  211751. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211752. }
  211753. }
  211754. };
  211755. namespace CoreMidiCallbacks
  211756. {
  211757. static CriticalSection callbackLock;
  211758. static VoidArray activeCallbacks;
  211759. }
  211760. static void midiInputProc (const MIDIPacketList* pktlist,
  211761. void* readProcRefCon,
  211762. void* srcConnRefCon)
  211763. {
  211764. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211765. const double originalTime = time;
  211766. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211767. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211768. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211769. {
  211770. const MIDIPacket* packet = &pktlist->packet[0];
  211771. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211772. {
  211773. const uint8* d = (const uint8*) (packet->data);
  211774. int size = packet->length;
  211775. while (size > 0)
  211776. {
  211777. time = originalTime;
  211778. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211779. {
  211780. mpc->processSysex (d, size, time);
  211781. }
  211782. else
  211783. {
  211784. int used = 0;
  211785. const MidiMessage m (d, size, used, 0, time);
  211786. if (used <= 0)
  211787. {
  211788. jassertfalse // malformed midi message
  211789. break;
  211790. }
  211791. else
  211792. {
  211793. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211794. }
  211795. size -= used;
  211796. d += used;
  211797. }
  211798. }
  211799. packet = MIDIPacketNext (packet);
  211800. }
  211801. }
  211802. }
  211803. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211804. {
  211805. MidiInput* mi = 0;
  211806. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211807. {
  211808. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211809. if (endPoint != 0)
  211810. {
  211811. CFStringRef pname;
  211812. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211813. {
  211814. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  211815. if (makeSureClientExists())
  211816. {
  211817. MIDIPortRef port;
  211818. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211819. mpc->active = false;
  211820. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211821. {
  211822. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211823. {
  211824. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211825. mpc->callback = callback;
  211826. mpc->pendingBytes = 0;
  211827. mpc->pendingData.ensureSize (128);
  211828. mi = new MidiInput (getDevices() [index]);
  211829. mpc->input = mi;
  211830. mi->internal = mpc;
  211831. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211832. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211833. }
  211834. else
  211835. {
  211836. OK (MIDIPortDispose (port));
  211837. }
  211838. }
  211839. }
  211840. }
  211841. CFRelease (pname);
  211842. }
  211843. }
  211844. return mi;
  211845. }
  211846. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211847. {
  211848. MidiInput* mi = 0;
  211849. if (makeSureClientExists())
  211850. {
  211851. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211852. mpc->active = false;
  211853. MIDIEndpointRef endPoint;
  211854. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211855. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211856. {
  211857. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211858. mpc->callback = callback;
  211859. mpc->pendingBytes = 0;
  211860. mpc->pendingData.ensureSize (128);
  211861. mi = new MidiInput (deviceName);
  211862. mpc->input = mi;
  211863. mi->internal = mpc;
  211864. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211865. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211866. }
  211867. CFRelease (name);
  211868. }
  211869. return mi;
  211870. }
  211871. MidiInput::MidiInput (const String& name_)
  211872. : name (name_)
  211873. {
  211874. }
  211875. MidiInput::~MidiInput()
  211876. {
  211877. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211878. mpc->active = false;
  211879. {
  211880. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211881. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211882. }
  211883. if (mpc->portAndEndpoint->port != 0)
  211884. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211885. delete mpc->portAndEndpoint;
  211886. delete mpc;
  211887. }
  211888. void MidiInput::start()
  211889. {
  211890. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211891. ((MidiPortAndCallback*) internal)->active = true;
  211892. }
  211893. void MidiInput::stop()
  211894. {
  211895. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211896. ((MidiPortAndCallback*) internal)->active = false;
  211897. }
  211898. #undef log
  211899. #else
  211900. MidiOutput::~MidiOutput()
  211901. {
  211902. }
  211903. void MidiOutput::reset()
  211904. {
  211905. }
  211906. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211907. {
  211908. return false;
  211909. }
  211910. void MidiOutput::setVolume (float leftVol, float rightVol)
  211911. {
  211912. }
  211913. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211914. {
  211915. }
  211916. const StringArray MidiOutput::getDevices()
  211917. {
  211918. return StringArray();
  211919. }
  211920. MidiOutput* MidiOutput::openDevice (int index)
  211921. {
  211922. return 0;
  211923. }
  211924. const StringArray MidiInput::getDevices()
  211925. {
  211926. return StringArray();
  211927. }
  211928. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211929. {
  211930. return 0;
  211931. }
  211932. #endif
  211933. #endif
  211934. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211935. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211936. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211937. // compiled on its own).
  211938. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  211939. #if ! JUCE_QUICKTIME
  211940. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  211941. #endif
  211942. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211943. class QTCameraDeviceInteral;
  211944. END_JUCE_NAMESPACE
  211945. @interface QTCaptureCallbackDelegate : NSObject
  211946. {
  211947. @public
  211948. CameraDevice* owner;
  211949. QTCameraDeviceInteral* internal;
  211950. int64 firstPresentationTime;
  211951. int64 averageTimeOffset;
  211952. }
  211953. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211954. - (void) dealloc;
  211955. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211956. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211957. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211958. fromConnection: (QTCaptureConnection*) connection;
  211959. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211960. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211961. fromConnection: (QTCaptureConnection*) connection;
  211962. @end
  211963. BEGIN_JUCE_NAMESPACE
  211964. class QTCameraDeviceInteral
  211965. {
  211966. public:
  211967. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211968. {
  211969. const ScopedAutoReleasePool pool;
  211970. session = [[QTCaptureSession alloc] init];
  211971. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211972. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211973. input = 0;
  211974. audioInput = 0;
  211975. audioDevice = 0;
  211976. fileOutput = 0;
  211977. imageOutput = 0;
  211978. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211979. internalDev: this];
  211980. NSError* err = 0;
  211981. [device retain];
  211982. [device open: &err];
  211983. if (err == 0)
  211984. {
  211985. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211986. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211987. [session addInput: input error: &err];
  211988. if (err == 0)
  211989. {
  211990. resetFile();
  211991. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211992. [imageOutput setDelegate: callbackDelegate];
  211993. if (err == 0)
  211994. {
  211995. [session startRunning];
  211996. return;
  211997. }
  211998. }
  211999. }
  212000. openingError = nsStringToJuce ([err description]);
  212001. DBG (openingError);
  212002. }
  212003. ~QTCameraDeviceInteral()
  212004. {
  212005. [session stopRunning];
  212006. [session removeOutput: imageOutput];
  212007. [session release];
  212008. [input release];
  212009. [device release];
  212010. [audioDevice release];
  212011. [audioInput release];
  212012. [fileOutput release];
  212013. [imageOutput release];
  212014. [callbackDelegate release];
  212015. }
  212016. void resetFile()
  212017. {
  212018. [fileOutput recordToOutputFileURL: nil];
  212019. [session removeOutput: fileOutput];
  212020. [fileOutput release];
  212021. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212022. [session removeInput: audioInput];
  212023. [audioInput release];
  212024. audioInput = 0;
  212025. [audioDevice release];
  212026. audioDevice = 0;
  212027. [fileOutput setDelegate: callbackDelegate];
  212028. }
  212029. void addDefaultAudioInput()
  212030. {
  212031. NSError* err = nil;
  212032. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212033. if ([audioDevice open: &err])
  212034. [audioDevice retain];
  212035. else
  212036. audioDevice = nil;
  212037. if (audioDevice != 0)
  212038. {
  212039. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212040. [session addInput: audioInput error: &err];
  212041. }
  212042. }
  212043. void addListener (CameraImageListener* listenerToAdd)
  212044. {
  212045. const ScopedLock sl (listenerLock);
  212046. if (listeners.size() == 0)
  212047. [session addOutput: imageOutput error: nil];
  212048. listeners.addIfNotAlreadyThere (listenerToAdd);
  212049. }
  212050. void removeListener (CameraImageListener* listenerToRemove)
  212051. {
  212052. const ScopedLock sl (listenerLock);
  212053. listeners.removeValue (listenerToRemove);
  212054. if (listeners.size() == 0)
  212055. [session removeOutput: imageOutput];
  212056. }
  212057. void callListeners (CIImage* frame, int w, int h)
  212058. {
  212059. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212060. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212061. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212062. CGContextFlush (image.context);
  212063. const ScopedLock sl (listenerLock);
  212064. for (int i = listeners.size(); --i >= 0;)
  212065. {
  212066. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212067. if (l != 0)
  212068. l->imageReceived (image);
  212069. }
  212070. }
  212071. QTCaptureDevice* device;
  212072. QTCaptureDeviceInput* input;
  212073. QTCaptureDevice* audioDevice;
  212074. QTCaptureDeviceInput* audioInput;
  212075. QTCaptureSession* session;
  212076. QTCaptureMovieFileOutput* fileOutput;
  212077. QTCaptureDecompressedVideoOutput* imageOutput;
  212078. QTCaptureCallbackDelegate* callbackDelegate;
  212079. String openingError;
  212080. VoidArray listeners;
  212081. CriticalSection listenerLock;
  212082. };
  212083. END_JUCE_NAMESPACE
  212084. @implementation QTCaptureCallbackDelegate
  212085. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212086. internalDev: (QTCameraDeviceInteral*) d
  212087. {
  212088. [super init];
  212089. owner = owner_;
  212090. internal = d;
  212091. firstPresentationTime = 0;
  212092. averageTimeOffset = 0;
  212093. return self;
  212094. }
  212095. - (void) dealloc
  212096. {
  212097. [super dealloc];
  212098. }
  212099. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212100. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212101. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212102. fromConnection: (QTCaptureConnection*) connection
  212103. {
  212104. if (internal->listeners.size() > 0)
  212105. {
  212106. const ScopedAutoReleasePool pool;
  212107. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212108. CVPixelBufferGetWidth (videoFrame),
  212109. CVPixelBufferGetHeight (videoFrame));
  212110. }
  212111. }
  212112. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212113. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212114. fromConnection: (QTCaptureConnection*) connection
  212115. {
  212116. const Time now (Time::getCurrentTime());
  212117. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212118. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212119. #else
  212120. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212121. #endif
  212122. int64 presentationTime = (hosttime != nil)
  212123. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  212124. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  212125. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  212126. if (firstPresentationTime == 0)
  212127. {
  212128. firstPresentationTime = presentationTime;
  212129. averageTimeOffset = timeDiff;
  212130. }
  212131. else
  212132. {
  212133. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212134. }
  212135. }
  212136. @end
  212137. BEGIN_JUCE_NAMESPACE
  212138. class QTCaptureViewerComp : public NSViewComponent
  212139. {
  212140. public:
  212141. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212142. {
  212143. const ScopedAutoReleasePool pool;
  212144. captureView = [[QTCaptureView alloc] init];
  212145. [captureView setCaptureSession: internal->session];
  212146. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212147. setView (captureView);
  212148. }
  212149. ~QTCaptureViewerComp()
  212150. {
  212151. setView (0);
  212152. [captureView setCaptureSession: nil];
  212153. [captureView release];
  212154. }
  212155. QTCaptureView* captureView;
  212156. };
  212157. CameraDevice::CameraDevice (const String& name_, int index)
  212158. : name (name_)
  212159. {
  212160. isRecording = false;
  212161. internal = new QTCameraDeviceInteral (this, index);
  212162. }
  212163. CameraDevice::~CameraDevice()
  212164. {
  212165. stopRecording();
  212166. delete static_cast <QTCameraDeviceInteral*> (internal);
  212167. internal = 0;
  212168. }
  212169. Component* CameraDevice::createViewerComponent()
  212170. {
  212171. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  212172. }
  212173. const String CameraDevice::getFileExtension()
  212174. {
  212175. return ".mov";
  212176. }
  212177. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212178. {
  212179. stopRecording();
  212180. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212181. d->callbackDelegate->firstPresentationTime = 0;
  212182. file.deleteFile();
  212183. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212184. // out wrong, so we'll put some audio in there too..,
  212185. d->addDefaultAudioInput();
  212186. [d->session addOutput: d->fileOutput error: nil];
  212187. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212188. for (;;)
  212189. {
  212190. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212191. if (connection == 0)
  212192. break;
  212193. QTCompressionOptions* options = 0;
  212194. NSString* mediaType = [connection mediaType];
  212195. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212196. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212197. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212198. : @"QTCompressionOptions240SizeH264Video"];
  212199. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212200. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212201. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212202. }
  212203. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212204. isRecording = true;
  212205. }
  212206. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212207. {
  212208. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212209. if (d->callbackDelegate->firstPresentationTime != 0)
  212210. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212211. return Time();
  212212. }
  212213. void CameraDevice::stopRecording()
  212214. {
  212215. if (isRecording)
  212216. {
  212217. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  212218. isRecording = false;
  212219. }
  212220. }
  212221. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212222. {
  212223. if (listenerToAdd != 0)
  212224. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  212225. }
  212226. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212227. {
  212228. if (listenerToRemove != 0)
  212229. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  212230. }
  212231. const StringArray CameraDevice::getAvailableDevices()
  212232. {
  212233. const ScopedAutoReleasePool pool;
  212234. StringArray results;
  212235. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212236. for (int i = 0; i < (int) [devs count]; ++i)
  212237. {
  212238. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212239. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212240. }
  212241. return results;
  212242. }
  212243. CameraDevice* CameraDevice::openDevice (int index,
  212244. int minWidth, int minHeight,
  212245. int maxWidth, int maxHeight)
  212246. {
  212247. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212248. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  212249. return d.release();
  212250. return 0;
  212251. }
  212252. #endif
  212253. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212254. #endif
  212255. #endif
  212256. END_JUCE_NAMESPACE
  212257. #endif
  212258. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212259. #endif
  212260. #endif